From: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
To: gcc-patches@gcc.gnu.org
Cc: Uros Bizjak <ubizjak@gmail.com>
Subject: Use i386/crtfastmath.c on Solaris 2/x86
Date: Tue, 31 May 2011 14:01:00 -0000 [thread overview]
Message-ID: <yddaae3rra6.fsf@manam.CeBiTec.Uni-Bielefeld.DE> (raw)
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 <ro@CeBiTec.Uni-Bielefeld.DE>
gcc:
* config/i386/crtfastmath.c [!__x86_64__ && __sun__ && __svr4__]:
Include <signal.h>, <ucontext.h>.
(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 <signal.h>
+#include <ucontext.h>
+
+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
\f
-#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)
;;
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
next reply other threads:[~2011-05-31 12:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-31 14:01 Rainer Orth [this message]
2011-05-31 14:23 ` Uros Bizjak
2011-06-01 14:51 ` Rainer Orth
2011-06-01 17:24 ` Richard Henderson
2011-06-01 17:29 ` Rainer Orth
2011-06-01 18:06 ` Richard Henderson
2011-06-03 17:39 ` Rainer Orth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=yddaae3rra6.fsf@manam.CeBiTec.Uni-Bielefeld.DE \
--to=ro@cebitec.uni-bielefeld.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=ubizjak@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).