This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: eliminate uses of real_sqrt in builtins.c
- From: "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Feb 2007 14:57:53 -0500 (EST)
- Subject: [PATCH]: eliminate uses of real_sqrt in builtins.c
I realized with my last patch, I'm introducing more uses of real_sqrt and
I'm thinking we want to go in the other direction. Since all we really
want in these cases is the square root of two, I added that to our list of
constants. I took the opportunity to delete dconstpi which is no longer
used on mainline, and present that as a peace offering to those who
dislike adding more startup cruft. :-)
I copied the first N digits of sqrt(2) from here:
http://www.ibiblio.org/pub/docs/books/gutenberg/etext94/2sqrt10a.txt
Note the folding transformation uses dconstsqrt2, while the testcases
(which all pass) compare the result with __builtin_sqrt(2) which uses MPFR
to resolve. So they are consistent at least up to the precision of long
double (128 bits on my box).
Bootstrapped on sparc-sun-solaris2.10 in conjunction with my previous
patch to cabs, which is necessary for a clean apply:
http://gcc.gnu.org/ml/gcc-patches/2007-02/msg00272.html
There were no regressions. With these removed, there's only one use of
real_sqrt left in simplify-rtx.c.
Okay for mainline?
Thanks,
--Kaveh
2007-02-02 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* emit-rtl.c (dconstpi): Delete.
(dconstsqrt2): New.
(init_emit_once): Delete dconstpi and init dconstsqrt2.
* real.h (dconstpi): Delete.
(dconstsqrt2): New.
* builtins.c (fold_builtin_cabs): Use dconstsqrt2.
(fold_builtin_hypot): Likewise.
diff -rup orig/egcc-SVN20070202/gcc/emit-rtl.c egcc-SVN20070202/gcc/emit-rtl.c
--- orig/egcc-SVN20070202/gcc/emit-rtl.c 2007-02-01 20:02:48.000000000 -0500
+++ egcc-SVN20070202/gcc/emit-rtl.c 2007-02-02 20:21:50.285384653 -0500
@@ -105,7 +105,7 @@ REAL_VALUE_TYPE dconstm1;
REAL_VALUE_TYPE dconstm2;
REAL_VALUE_TYPE dconsthalf;
REAL_VALUE_TYPE dconstthird;
-REAL_VALUE_TYPE dconstpi;
+REAL_VALUE_TYPE dconstsqrt2;
REAL_VALUE_TYPE dconste;
/* All references to the following fixed hard registers go through
@@ -5181,8 +5181,8 @@ init_emit_once (int line_numbers)
/* Initialize mathematical constants for constant folding builtins.
These constants need to be given to at least 160 bits precision. */
- real_from_string (&dconstpi,
- "3.1415926535897932384626433832795028841971693993751058209749445923078");
+ real_from_string (&dconstsqrt2,
+ "1.4142135623730950488016887242096980785696718753769480731766797379907");
real_from_string (&dconste,
"2.7182818284590452353602874713526624977572470936999595749669676277241");
diff -rup orig/egcc-SVN20070202/gcc/real.h egcc-SVN20070202/gcc/real.h
--- orig/egcc-SVN20070202/gcc/real.h 2007-01-18 20:02:49.000000000 -0500
+++ egcc-SVN20070202/gcc/real.h 2007-02-02 20:21:50.288190410 -0500
@@ -387,7 +387,7 @@ extern REAL_VALUE_TYPE dconstm1;
extern REAL_VALUE_TYPE dconstm2;
extern REAL_VALUE_TYPE dconsthalf;
extern REAL_VALUE_TYPE dconstthird;
-extern REAL_VALUE_TYPE dconstpi;
+extern REAL_VALUE_TYPE dconstsqrt2;
extern REAL_VALUE_TYPE dconste;
/* Function to return a real value (not a tree node)
diff -rup orig/egcc-SVN20070202/gcc/builtins.c egcc-SVN20070202/gcc/builtins.c
--- orig/egcc-SVN20070202/gcc/builtins.c 2007-02-02 20:24:00.207385898 -0500
+++ egcc-SVN20070202/gcc/builtins.c 2007-02-02 20:25:04.303651679 -0500
@@ -7158,13 +7158,12 @@ fold_builtin_cabs (tree arglist, tree ty
if (flag_unsafe_math_optimizations
&& operand_equal_p (real, imag, OEP_PURE_SAME))
{
- REAL_VALUE_TYPE sqrt2;
-
- real_sqrt (&sqrt2, TYPE_MODE (type), &dconst2);
+ const REAL_VALUE_TYPE sqrt2_trunc
+ = real_value_truncate (TYPE_MODE (type), dconstsqrt2);
STRIP_NOPS (real);
return fold_build2 (MULT_EXPR, type,
fold_build1 (ABS_EXPR, type, real),
- build_real (type, sqrt2));
+ build_real (type, sqrt2_trunc));
}
}
@@ -8059,12 +8058,11 @@ fold_builtin_hypot (tree fndecl, tree ar
if (flag_unsafe_math_optimizations
&& operand_equal_p (arg0, arg1, OEP_PURE_SAME))
{
- REAL_VALUE_TYPE sqrt2;
-
- real_sqrt (&sqrt2, TYPE_MODE (type), &dconst2);
+ const REAL_VALUE_TYPE sqrt2_trunc
+ = real_value_truncate (TYPE_MODE (type), dconstsqrt2);
return fold_build2 (MULT_EXPR, type,
fold_build1 (ABS_EXPR, type, arg0),
- build_real (type, sqrt2));
+ build_real (type, sqrt2_trunc));
}
return NULL_TREE;