From 236573882e12373869637236ccf6eb93ecfeec7e Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Tue, 10 Aug 2004 17:43:02 +0000 Subject: [PATCH] mips.md: New reciprocal square root patterns that match sqrt(1.0/x) in addition to the... * 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 | 5 ++++ gcc/config/mips/mips.md | 40 +++++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/gcc.dg/mips-rsqrt-1.c | 18 +++++++++++++ gcc/testsuite/gcc.dg/mips-rsqrt-2.c | 18 +++++++++++++ gcc/testsuite/gcc.dg/mips-rsqrt-3.c | 28 ++++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/mips-rsqrt-1.c create mode 100644 gcc/testsuite/gcc.dg/mips-rsqrt-2.c create mode 100644 gcc/testsuite/gcc.dg/mips-rsqrt-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6ec2c5d359a..3a28b7c0e07 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-08-10 Roger Sayle + + * 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 * config/arm/arm-protos.h (arm_set_return_address, diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index 7c6771dd749..ac4c4b9473e 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -2203,6 +2203,46 @@ (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)))]) ;; ;; .................... diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7011c1262b9..2dda1e5af0a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-08-10 Roger Sayle + + * 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 * 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 index 00000000000..1f742b2fe4b --- /dev/null +++ b/gcc/testsuite/gcc.dg/mips-rsqrt-1.c @@ -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 index 00000000000..5c014abc180 --- /dev/null +++ b/gcc/testsuite/gcc.dg/mips-rsqrt-2.c @@ -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 index 00000000000..870a5c9aa6a --- /dev/null +++ b/gcc/testsuite/gcc.dg/mips-rsqrt-3.c @@ -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); +} + -- 2.30.2