aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2002-03-29 15:24:20 -0800
committerRichard Henderson <rth@gcc.gnu.org>2002-03-29 15:24:20 -0800
commit30c99a84e097d6d8f55921361b7d3c5c20e3835b (patch)
treea15cc507a152b1fe5af92175843a37d8425c9986
parent4d6ac5424e9c34988954c62da68b39dd5374a095 (diff)
downloadgcc-30c99a84e097d6d8f55921361b7d3c5c20e3835b.zip
gcc-30c99a84e097d6d8f55921361b7d3c5c20e3835b.tar.gz
gcc-30c99a84e097d6d8f55921361b7d3c5c20e3835b.tar.bz2
i386.c (x86_arch_always_fancy_math_387): New.
* config/i386/i386.c (x86_arch_always_fancy_math_387): New. (override_options): Disable NO_FANCY_MATH_387 if the arch allows. * config/i386/i386.h (x86_arch_always_fancy_math_387): New. * config/i386/i386.md (sqrtxf2, sqrtextendsfxf2, sinxf2): Fix conditional. * docs/invoke.texi: Update -mno-fancy-math-387 docs. From-SVN: r51584
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/config/i386/i386.c6
-rw-r--r--gcc/config/i386/i386.h1
-rw-r--r--gcc/config/i386/i386.md6
-rw-r--r--gcc/doc/invoke.texi9
-rw-r--r--gcc/testsuite/gcc.dg/i386-387-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/i386-387-2.c10
7 files changed, 45 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3d0da36..101f6a8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2002-03-29 Richard Henderson <rth@redhat.com>
+
+ * config/i386/i386.c (x86_arch_always_fancy_math_387): New.
+ (override_options): Disable NO_FANCY_MATH_387 if the arch allows.
+ * config/i386/i386.h (x86_arch_always_fancy_math_387): New.
+ * config/i386/i386.md (sqrtxf2, sqrtextendsfxf2, sinxf2): Fix
+ conditional.
+ * docs/invoke.texi: Update -mno-fancy-math-387 docs.
+
2002-03-29 Dale Johannesen <dalej@apple.com>
* loop.c (combine_movables): Do allow combination of pseudos.
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 95873e2..8e9df35 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -393,6 +393,7 @@ const int x86_accumulate_outgoing_args = m_ATHLON | m_PENT4 | m_PPRO;
const int x86_prologue_using_move = m_ATHLON | m_PENT4 | m_PPRO;
const int x86_epilogue_using_move = m_ATHLON | m_PENT4 | m_PPRO;
const int x86_decompose_lea = m_PENT4;
+const int x86_arch_always_fancy_math_387 = m_PENT|m_PPRO|m_ATHLON|m_PENT4;
/* In case the avreage insn count for single function invocation is
lower than this constant, emit fast (but longer) prologue and
@@ -1118,6 +1119,11 @@ override_options ()
if (flag_unsafe_math_optimizations)
target_flags &= ~MASK_IEEE_FP;
+ /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
+ since the insns won't need emulation. */
+ if (x86_arch_always_fancy_math_387 & (1 << ix86_arch))
+ target_flags &= ~MASK_NO_FANCY_MATH_387;
+
if (TARGET_64BIT)
{
if (TARGET_ALIGN_DOUBLE)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 9435913..ad2956d 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -222,6 +222,7 @@ extern const int x86_add_esp_4, x86_add_esp_8, x86_sub_esp_4, x86_sub_esp_8;
extern const int x86_partial_reg_dependency, x86_memory_mismatch_stall;
extern const int x86_accumulate_outgoing_args, x86_prologue_using_move;
extern const int x86_epilogue_using_move, x86_decompose_lea;
+extern const int x86_arch_always_fancy_math_387;
extern int x86_prefetch_sse;
#define TARGET_USE_LEAVE (x86_use_leave & CPUMASK)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 27a352d..8b3ee78 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -14701,7 +14701,7 @@
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:DF 1 "register_operand" "0"))))]
- "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387"
+ "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
@@ -14721,7 +14721,7 @@
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:SF 1 "register_operand" "0"))))]
- "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387"
+ "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
@@ -14768,7 +14768,7 @@
(define_insn "sinxf2"
[(set (match_operand:XF 0 "register_operand" "=f")
(unspec:XF [(match_operand:XF 1 "register_operand" "0")] 1))]
- "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387
+ "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387
&& flag_unsafe_math_optimizations"
"fsin"
[(set_attr "type" "fpspc")
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b1e6d5d..c26d183 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7366,9 +7366,12 @@ in ordinary CPU registers instead.
@opindex mno-fancy-math-387
Some 387 emulators do not support the @code{sin}, @code{cos} and
@code{sqrt} instructions for the 387. Specify this option to avoid
-generating those instructions. This option is the default on FreeBSD@.
-As of revision 2.6.1, these instructions are not generated unless you
-also use the @option{-funsafe-math-optimizations} switch.
+generating those instructions. This option is the default on FreeBSD,
+OpenBSD and NetBSD@. This option is overridden when @option{-march}
+indicates that the target cpu will always have an FPU and so the
+instruction will not need emulation. As of revision 2.6.1, these
+instructions are not generated unless you also use the
+@option{-funsafe-math-optimizations} switch.
@item -malign-double
@itemx -mno-align-double
diff --git a/gcc/testsuite/gcc.dg/i386-387-1.c b/gcc/testsuite/gcc.dg/i386-387-1.c
new file mode 100644
index 0000000..2c9334b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/i386-387-1.c
@@ -0,0 +1,10 @@
+/* Verify that -mno-fancy-math-387 works. */
+/* { dg-do compile { target "i?86-*-*" } } */
+/* { dg-options "-O -ffast-math -mfpmath=387 -mno-fancy-math-387" } */
+/* { dg-final { scan-assembler "call\tsin" } } */
+/* { dg-final { scan-assembler "call\tcos" } } */
+/* { dg-final { scan-assembler "call\tsqrt" } } */
+
+double f1(double x) { return __builtin_sin(x); }
+double f2(double x) { return __builtin_cos(x); }
+double f3(double x) { return __builtin_sqrt(x); }
diff --git a/gcc/testsuite/gcc.dg/i386-387-2.c b/gcc/testsuite/gcc.dg/i386-387-2.c
new file mode 100644
index 0000000..2456ca0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/i386-387-2.c
@@ -0,0 +1,10 @@
+/* Verify that -march overrides -mno-fancy-math-387. */
+/* { dg-do compile { target "i?86-*-*" } } */
+/* { dg-options "-O -ffast-math -mfpmath=387 -march=i686 -mno-fancy-math-387" } */
+/* { dg-final { scan-assembler "fsin" } } */
+/* { dg-final { scan-assembler "fcos" } } */
+/* { dg-final { scan-assembler "fsqrt" } } */
+
+double f1(double x) { return __builtin_sin(x); }
+double f2(double x) { return __builtin_cos(x); }
+double f3(double x) { return __builtin_sqrt(x); }