mips.md: New reciprocal square root patterns that match sqrt(1.0/x) in addition to...
authorRoger Sayle <roger@eyesopen.com>
Tue, 10 Aug 2004 17:43:02 +0000 (17:43 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Tue, 10 Aug 2004 17:43:02 +0000 (17:43 +0000)
* config/mips/mips.md: New reciprocal square root patterns that
match sqrt(1.0/x) in addition to the existing 1.0/sqrt(x) insns.

* gcc.dg/mips-rsqrt-1.c: New test case.
* gcc.dg/mips-rsqrt-2.c: New test case.
* gcc.dg/mips-rsqrt-3.c: New test case.

From-SVN: r85759

gcc/ChangeLog
gcc/config/mips/mips.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/mips-rsqrt-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/mips-rsqrt-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/mips-rsqrt-3.c [new file with mode: 0644]

index 6ec2c5d359ac17f95fc5d4f3eab5d8d60c9a54d8..3a28b7c0e07af5a69e919bd4253b3053b47c9b8c 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-10  Roger Sayle  <roger@eyesopen.com>
+
+       * config/mips/mips.md: New reciprocal square root patterns that
+       match sqrt(1.0/x) in addition to the existing 1.0/sqrt(x) insns.
+
 2004-08-10  Paul Brook  <paul@codesourcery.com>
 
        * config/arm/arm-protos.h (arm_set_return_address,
index 7c6771dd74996d6d93630ae2edb28d095c9d7133..ac4c4b9473ec11330088a58ba201bcb3302504df 100644 (file)
         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
                       (const_int 8)
                       (const_int 4)))])
+
+;; This pattern works around the early SB-1 rev2 core "F1" erratum (see
+;; "divdf3" comment for details).
+(define_insn ""
+  [(set (match_operand:DF 0 "register_operand" "=f")
+       (sqrt:DF (div:DF (match_operand:DF 1 "const_float_1_operand" "")
+                        (match_operand:DF 2 "register_operand" "f"))))]
+  "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && flag_unsafe_math_optimizations"
+{
+  if (TARGET_FIX_SB1)
+    return "rsqrt.d\t%0,%2\;mov.d\t%0,%0";
+  else
+    return "rsqrt.d\t%0,%2";
+}
+  [(set_attr "type"    "frsqrt")
+   (set_attr "mode"    "DF")
+   (set (attr "length")
+        (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
+                      (const_int 8)
+                      (const_int 4)))])
+
+;; This pattern works around the early SB-1 rev2 core "F1" erratum (see
+;; "divdf3" comment for details).
+(define_insn ""
+  [(set (match_operand:SF 0 "register_operand" "=f")
+       (sqrt:SF (div:SF (match_operand:SF 1 "const_float_1_operand" "")
+                        (match_operand:SF 2 "register_operand" "f"))))]
+  "ISA_HAS_FP4 && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
+{
+  if (TARGET_FIX_SB1)
+    return "rsqrt.s\t%0,%2\;mov.s\t%0,%0";
+  else
+    return "rsqrt.s\t%0,%2";
+}
+  [(set_attr "type"    "frsqrt")
+   (set_attr "mode"    "SF")
+   (set (attr "length")
+        (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
+                      (const_int 8)
+                      (const_int 4)))])
 \f
 ;;
 ;;  ....................
index 7011c1262b966cf35f4f22ae929c09dae4cc20ad..2dda1e5af0a2c4ce35799c344fec6ebb333498ea 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-10  Roger Sayle  <roger@eyesopen.com>
+
+       * gcc.dg/mips-rsqrt-1.c: New test case.
+       * gcc.dg/mips-rsqrt-2.c: New test case.
+       * gcc.dg/mips-rsqrt-3.c: New test case.
+
 2004-08-10  Paul Brook  <paul@codesourcery.com>
 
        * gfortran.dg/der_io_1.f90: New test.
diff --git a/gcc/testsuite/gcc.dg/mips-rsqrt-1.c b/gcc/testsuite/gcc.dg/mips-rsqrt-1.c
new file mode 100644 (file)
index 0000000..1f742b2
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile { target "mips*-*-*" } } */
+/* { dg-options "-O2 -ffast-math -mips4" } */
+/* { dg-final { scan-assembler "rsqrt.d" } } */
+/* { dg-final { scan-assembler "rsqrt.s" } } */
+
+extern double sqrt(double);
+extern float sqrtf(float);
+
+double foo(double x)
+{
+  return 1.0/sqrt(x);
+}
+
+float bar(float x)
+{
+  return 1.0f/sqrtf(x);
+}
+
diff --git a/gcc/testsuite/gcc.dg/mips-rsqrt-2.c b/gcc/testsuite/gcc.dg/mips-rsqrt-2.c
new file mode 100644 (file)
index 0000000..5c014ab
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile { target "mips*-*-*" } } */
+/* { dg-options "-O2 -ffast-math -mips4" } */
+/* { dg-final { scan-assembler "rsqrt.d" } } */
+/* { dg-final { scan-assembler "rsqrt.s" } } */
+
+extern double sqrt(double);
+extern float sqrtf(float);
+
+double foo(double x)
+{
+  return sqrt(1.0/x);
+}
+
+float bar(float x)
+{
+  return sqrtf(1.0f/x);
+}
+
diff --git a/gcc/testsuite/gcc.dg/mips-rsqrt-3.c b/gcc/testsuite/gcc.dg/mips-rsqrt-3.c
new file mode 100644 (file)
index 0000000..870a5c9
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile { target "mips*-*-*" } } */
+/* { dg-options "-O2 -mips4" } */
+/* { dg-final { scan-assembler-not "rsqrt.d" } } */
+/* { dg-final { scan-assembler-not "rsqrt.s" } } */
+
+extern double sqrt(double);
+extern float sqrtf(float);
+
+double foo(double x)
+{
+  return 1.0/sqrt(x);
+}
+
+double bar(double x)
+{
+  return sqrt(1.0/x);
+}
+
+float foof(float x)
+{
+  return 1.0f/sqrtf(x);
+}
+
+float barf(float x)
+{
+  return sqrtf(1.0f/x);
+}
+