aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2015-10-07 08:09:45 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2015-10-07 08:09:45 +0000
commitd01db77a06a80459acf79e963c55e3b94106eeb3 (patch)
tree26df13af657839b7995fa4de21f93310ada1c766 /gcc/real.c
parent5b5dce39b8c076c185ce1fa19d4800d6129f3f53 (diff)
downloadgcc-d01db77a06a80459acf79e963c55e3b94106eeb3.zip
gcc-d01db77a06a80459acf79e963c55e3b94106eeb3.tar.gz
gcc-d01db77a06a80459acf79e963c55e3b94106eeb3.tar.bz2
Cache reals for 1/4, 1/6 and 1/9
We have a global 1/2 and a cached 1/3, but recalculate 1/4, 1/6 and 1/9 each time we need them. That seems a bit arbitrary and makes the folding code more noisy (especially once it's moved to match.pd). This patch caches the other three constants too. Bootstrapped & regression-tested on x86_64-linux-gnu. gcc/ * real.h (dconst_quarter, dconst_sixth, dconst_ninth): New macros. (dconst_quarter_ptr, dconst_sixth_ptr, dconst_ninth_ptr): Declare. * real.c (CACHED_FRACTION): New helper macro. (dconst_third_ptr): Use it. (dconst_quarter_ptr, dconst_sixth_ptr, dconst_ninth_ptr): New. * builtins.c (fold_builtin_sqrt): Use dconst_quarter and dconst_sixth. (fold_builtin_cbrt): Use dconst_sixth and dconst_ninth. From-SVN: r228561
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 49d6739..f633ffd 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -2395,21 +2395,26 @@ dconst_e_ptr (void)
return &value;
}
-/* Returns the special REAL_VALUE_TYPE corresponding to 1/3. */
-
-const REAL_VALUE_TYPE *
-dconst_third_ptr (void)
-{
- static REAL_VALUE_TYPE value;
-
- /* Initialize mathematical constants for constant folding builtins.
- These constants need to be given to at least 160 bits precision. */
- if (value.cl == rvc_zero)
- {
- real_arithmetic (&value, RDIV_EXPR, &dconst1, real_digit (3));
- }
- return &value;
-}
+/* Returns a cached REAL_VALUE_TYPE corresponding to 1/n, for various n. */
+
+#define CACHED_FRACTION(NAME, N) \
+ const REAL_VALUE_TYPE * \
+ NAME (void) \
+ { \
+ static REAL_VALUE_TYPE value; \
+ \
+ /* Initialize mathematical constants for constant folding builtins. \
+ These constants need to be given to at least 160 bits \
+ precision. */ \
+ if (value.cl == rvc_zero) \
+ real_arithmetic (&value, RDIV_EXPR, &dconst1, real_digit (N)); \
+ return &value; \
+ }
+
+CACHED_FRACTION (dconst_third_ptr, 3)
+CACHED_FRACTION (dconst_quarter_ptr, 4)
+CACHED_FRACTION (dconst_sixth_ptr, 6)
+CACHED_FRACTION (dconst_ninth_ptr, 9)
/* Returns the special REAL_VALUE_TYPE corresponding to sqrt(2). */