From patchwork Tue May 31 12:25:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 98026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id ABEC5B6F68 for ; Tue, 31 May 2011 22:26:00 +1000 (EST) Received: (qmail 3017 invoked by alias); 31 May 2011 12:25:54 -0000 Received: (qmail 2980 invoked by uid 22791); 31 May 2011 12:25:52 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, TW_MX, TW_TM, TW_XC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from snape.CeBiTec.Uni-Bielefeld.DE (HELO smtp-relay.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 May 2011 12:25:16 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id F05E029C; Tue, 31 May 2011 14:25:14 +0200 (CEST) Received: from smtp-relay.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id RYhZECQY9I2q; Tue, 31 May 2011 14:25:11 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (manam.CeBiTec.Uni-Bielefeld.DE [129.70.161.120]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 9804529B; Tue, 31 May 2011 14:25:11 +0200 (CEST) Received: (from ro@localhost) by manam.CeBiTec.Uni-Bielefeld.DE (8.14.4+Sun/8.14.4/Submit) id p4VCP5wY020814; Tue, 31 May 2011 14:25:05 +0200 (MEST) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak Subject: Use i386/crtfastmath.c on Solaris 2/x86 Date: Tue, 31 May 2011 14:25:05 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I had long meant to support -fast-math on Solaris 2/x86. While working on the Solaris toplevel libgcc move, I've done it with the following patch. The only complication is that I need to make sure that SSE insns are only used if the host supports them. Bootstrapped without regressions on i386-pc-solaris2.8, i386-pc-solaris2.9, i386-pc-solaris2.11, and sparc-sun-solaris2.11. The libgcc part depends on the toplevel libgcc patch, so actually applying this patch will have to wait until that one is in. Ok for mainline? Rainer 2011-05-28 Rainer Orth gcc: * config/i386/crtfastmath.c [!__x86_64__ && __sun__ && __svr4__]: Include , . (sigill_caught): Define. (sigill_hdlr): New function. (set_fast_math) [!__x86_64__ && __sun__ && __svr4__]: Check if SSE insns can be executed. * config/sol2.h (ENDFILE_SPEC): Use crtfastmath.o if -ffast-math etc. * config/sparc/sol2.h (ENDFILE_SPEC): Remove. libgcc: * config.host (i[34567]86-*-solaris2*): Add i386/t-crtfm to tmake_file. Add crtfastmath.o to extra_parts. diff --git a/gcc/config/i386/crtfastmath.c b/gcc/config/i386/crtfastmath.c --- a/gcc/config/i386/crtfastmath.c +++ b/gcc/config/i386/crtfastmath.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. + * Copyright (C) 2005, 2007, 2009, 2011 Free Software Foundation, Inc. * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -30,6 +30,26 @@ #include "cpuid.h" #endif +#if !defined __x86_64 && defined __sun__ && defined __svr4__ +#include +#include + +static volatile sig_atomic_t sigill_caught; + +static void +sigill_hdlr (int sig __attribute((unused)), + siginfo_t *sip __attribute__((unused)), + ucontext_t *ucp) +{ + sigill_caught = 1; + /* Set PC to the instruction after the faulting one to skip over it, + otherwise we enter an infinite loop. 4 is the size of the stmxcsr + instruction. */ + ucp->uc_mcontext.gregs[EIP] += 4; + setcontext (ucp); +} +#endif + static void __attribute__((constructor)) #ifndef __x86_64__ /* The i386 ABI only requires 4-byte stack alignment, so this is necessary @@ -45,6 +65,32 @@ set_fast_math (void) if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) return; +#if defined __sun__ && defined __svr4__ + /* Solaris 2 before Solaris 9 4/04 cannot execute SSE instructions even + if the CPU supports them. Programs receive SIGILL instead, so check + for that at runtime. */ + + if (edx & bit_SSE) + { + struct sigaction act, oact; + + act.sa_handler = sigill_hdlr; + sigemptyset (&act.sa_mask); + /* Need to set SA_SIGINFO so a ucontext_t * is passed to the handler. */ + act.sa_flags = SA_SIGINFO; + sigaction (SIGILL, &act, &oact); + + /* We need a single SSE instruction here so the handler can safely skip + over it. */ + __asm__ volatile ("movss %xmm2,%xmm1"); + + sigaction (SIGILL, &oact, NULL); + + if (sigill_caught) + return; + } +#endif /* __sun__ && __svr4__ */ + if (edx & bit_SSE) { unsigned int mxcsr = __builtin_ia32_stmxcsr (); diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -141,7 +141,9 @@ along with GCC; see the file COPYING3. %{p|pg:-ldl} -lc}" #undef ENDFILE_SPEC -#define ENDFILE_SPEC "crtend.o%s crtn.o%s" +#define ENDFILE_SPEC \ + "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ + crtend.o%s crtn.o%s" /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us. */ #undef STARTFILE_SPEC diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h --- a/gcc/config/sparc/sol2.h +++ b/gcc/config/sparc/sol2.h @@ -117,11 +117,6 @@ along with GCC; see the file COPYING3. #define NO_DBX_BNSYM_ENSYM 1 -#undef ENDFILE_SPEC -#define ENDFILE_SPEC \ - "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ - crtend.o%s crtn.o%s" - /* Select a format to encode pointers in exception handling data. CODE is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is true if the symbol may be affected by dynamic relocations. diff --git a/libgcc/config.host b/libgcc/config.host --- a/libgcc/config.host +++ b/libgcc/config.host @@ -338,6 +338,8 @@ i[34567]86-*-rtems*) tmake_file="${tmake_file} t-crtin i386/t-softfp i386/t-crtstuff t-rtems" ;; i[34567]86-*-solaris2*) + tmake_file="$tmake_file i386/t-crtfm" + extra_parts="$extra_parts crtfastmath.o" ;; i[4567]86-wrs-vxworks|i[4567]86-wrs-vxworksae) ;;