real.h (dconst_e, [...]): Declare.

2008-08-18  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	* real.h (dconst_e, dconst_third, dconst_sqrt2, dconst_e_ptr,
	dconst_third_ptr, dconst_sqrt2_ptr): Declare.
	(enum real_value_const): Delete.
	(get_real_const): Delete.
	* real.c (get_real_const): Delete.
	(dconst_e_ptr): Define.
	(dconst_third_ptr): Define.
	(dconst_sqrt2_ptr): Define.
	* builtins.c: Update all callers.

From-SVN: r139202
parent e4658728
2008-08-18 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* real.h (dconst_e, dconst_third, dconst_sqrt2, dconst_e_ptr,
dconst_third_ptr, dconst_sqrt2_ptr): Declare.
(enum real_value_const): Delete.
(get_real_const): Delete.
* real.c (get_real_const): Delete.
(dconst_e_ptr): Define.
(dconst_third_ptr): Define.
(dconst_sqrt2_ptr): Define.
* builtins.c: Update all callers.
2008-08-18 Richard Guenther <rguenther@suse.de> 2008-08-18 Richard Guenther <rguenther@suse.de>
* tree-ssa-reassoc.c (reassociate_bb): Properly reset the * tree-ssa-reassoc.c (reassociate_bb): Properly reset the
......
...@@ -7515,8 +7515,7 @@ fold_builtin_cabs (tree arg, tree type, tree fndecl) ...@@ -7515,8 +7515,7 @@ fold_builtin_cabs (tree arg, tree type, tree fndecl)
&& operand_equal_p (real, imag, OEP_PURE_SAME)) && operand_equal_p (real, imag, OEP_PURE_SAME))
{ {
const REAL_VALUE_TYPE sqrt2_trunc const REAL_VALUE_TYPE sqrt2_trunc
= real_value_truncate (TYPE_MODE (type), = real_value_truncate (TYPE_MODE (type), dconst_sqrt2 ());
*get_real_const (rv_sqrt2));
STRIP_NOPS (real); STRIP_NOPS (real);
return fold_build2 (MULT_EXPR, type, return fold_build2 (MULT_EXPR, type,
fold_build1 (ABS_EXPR, type, real), fold_build1 (ABS_EXPR, type, real),
...@@ -7599,7 +7598,7 @@ fold_builtin_sqrt (tree arg, tree type) ...@@ -7599,7 +7598,7 @@ fold_builtin_sqrt (tree arg, tree type)
tree tree_root; tree tree_root;
/* The inner root was either sqrt or cbrt. */ /* The inner root was either sqrt or cbrt. */
REAL_VALUE_TYPE dconstroot = REAL_VALUE_TYPE dconstroot =
BUILTIN_SQRT_P (fcode) ? dconsthalf : *get_real_const (rv_third); BUILTIN_SQRT_P (fcode) ? dconsthalf : dconst_third ();
/* Adjust for the outer root. */ /* Adjust for the outer root. */
SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1); SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1);
...@@ -7652,7 +7651,7 @@ fold_builtin_cbrt (tree arg, tree type) ...@@ -7652,7 +7651,7 @@ fold_builtin_cbrt (tree arg, tree type)
{ {
tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg), 0); tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg), 0);
const REAL_VALUE_TYPE third_trunc = const REAL_VALUE_TYPE third_trunc =
real_value_truncate (TYPE_MODE (type), *get_real_const (rv_third)); real_value_truncate (TYPE_MODE (type), dconst_third ());
arg = fold_build2 (MULT_EXPR, type, arg = fold_build2 (MULT_EXPR, type,
CALL_EXPR_ARG (arg, 0), CALL_EXPR_ARG (arg, 0),
build_real (type, third_trunc)); build_real (type, third_trunc));
...@@ -7668,7 +7667,7 @@ fold_builtin_cbrt (tree arg, tree type) ...@@ -7668,7 +7667,7 @@ fold_builtin_cbrt (tree arg, tree type)
{ {
tree arg0 = CALL_EXPR_ARG (arg, 0); tree arg0 = CALL_EXPR_ARG (arg, 0);
tree tree_root; tree tree_root;
REAL_VALUE_TYPE dconstroot = *get_real_const (rv_third); REAL_VALUE_TYPE dconstroot = dconst_third ();
SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1); SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1);
dconstroot = real_value_truncate (TYPE_MODE (type), dconstroot); dconstroot = real_value_truncate (TYPE_MODE (type), dconstroot);
...@@ -7691,8 +7690,7 @@ fold_builtin_cbrt (tree arg, tree type) ...@@ -7691,8 +7690,7 @@ fold_builtin_cbrt (tree arg, tree type)
REAL_VALUE_TYPE dconstroot; REAL_VALUE_TYPE dconstroot;
real_arithmetic (&dconstroot, MULT_EXPR, real_arithmetic (&dconstroot, MULT_EXPR,
get_real_const (rv_third), dconst_third_ptr (), dconst_third_ptr ());
get_real_const (rv_third));
dconstroot = real_value_truncate (TYPE_MODE (type), dconstroot); dconstroot = real_value_truncate (TYPE_MODE (type), dconstroot);
tree_root = build_real (type, dconstroot); tree_root = build_real (type, dconstroot);
return build_call_expr (powfn, 2, arg0, tree_root); return build_call_expr (powfn, 2, arg0, tree_root);
...@@ -7711,8 +7709,7 @@ fold_builtin_cbrt (tree arg, tree type) ...@@ -7711,8 +7709,7 @@ fold_builtin_cbrt (tree arg, tree type)
{ {
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg), 0); tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg), 0);
const REAL_VALUE_TYPE dconstroot const REAL_VALUE_TYPE dconstroot
= real_value_truncate (TYPE_MODE (type), = real_value_truncate (TYPE_MODE (type), dconst_third ());
*get_real_const (rv_third));
tree narg01 = fold_build2 (MULT_EXPR, type, arg01, tree narg01 = fold_build2 (MULT_EXPR, type, arg01,
build_real (type, dconstroot)); build_real (type, dconstroot));
return build_call_expr (powfn, 2, arg00, narg01); return build_call_expr (powfn, 2, arg00, narg01);
...@@ -8260,7 +8257,7 @@ fold_builtin_logarithm (tree fndecl, tree arg, ...@@ -8260,7 +8257,7 @@ fold_builtin_logarithm (tree fndecl, tree arg,
if (flag_unsafe_math_optimizations && func == mpfr_log) if (flag_unsafe_math_optimizations && func == mpfr_log)
{ {
const REAL_VALUE_TYPE e_truncated = const REAL_VALUE_TYPE e_truncated =
real_value_truncate (TYPE_MODE (type), *get_real_const (rv_e)); real_value_truncate (TYPE_MODE (type), dconst_e ());
if (real_dconstp (arg, &e_truncated)) if (real_dconstp (arg, &e_truncated))
return build_real (type, dconst1); return build_real (type, dconst1);
} }
...@@ -8293,9 +8290,8 @@ fold_builtin_logarithm (tree fndecl, tree arg, ...@@ -8293,9 +8290,8 @@ fold_builtin_logarithm (tree fndecl, tree arg,
{ {
CASE_FLT_FN (BUILT_IN_EXP): CASE_FLT_FN (BUILT_IN_EXP):
/* Prepare to do logN(exp(exponent) -> exponent*logN(e). */ /* Prepare to do logN(exp(exponent) -> exponent*logN(e). */
x = build_real (type, x = build_real (type, real_value_truncate (TYPE_MODE (type),
real_value_truncate (TYPE_MODE (type), dconst_e ()));
*get_real_const (rv_e)));
exponent = CALL_EXPR_ARG (arg, 0); exponent = CALL_EXPR_ARG (arg, 0);
break; break;
CASE_FLT_FN (BUILT_IN_EXP2): CASE_FLT_FN (BUILT_IN_EXP2):
...@@ -8322,7 +8318,7 @@ fold_builtin_logarithm (tree fndecl, tree arg, ...@@ -8322,7 +8318,7 @@ fold_builtin_logarithm (tree fndecl, tree arg,
/* Prepare to do logN(cbrt(x) -> (1/3)*logN(x). */ /* Prepare to do logN(cbrt(x) -> (1/3)*logN(x). */
x = CALL_EXPR_ARG (arg, 0); x = CALL_EXPR_ARG (arg, 0);
exponent = build_real (type, real_value_truncate (TYPE_MODE (type), exponent = build_real (type, real_value_truncate (TYPE_MODE (type),
*get_real_const (rv_third))); dconst_third ()));
break; break;
CASE_FLT_FN (BUILT_IN_POW): CASE_FLT_FN (BUILT_IN_POW):
/* Prepare to do logN(pow(x,exponent) -> exponent*logN(x). */ /* Prepare to do logN(pow(x,exponent) -> exponent*logN(x). */
...@@ -8382,7 +8378,7 @@ fold_builtin_hypot (tree fndecl, tree arg0, tree arg1, tree type) ...@@ -8382,7 +8378,7 @@ fold_builtin_hypot (tree fndecl, tree arg0, tree arg1, tree type)
&& operand_equal_p (arg0, arg1, OEP_PURE_SAME)) && operand_equal_p (arg0, arg1, OEP_PURE_SAME))
{ {
const REAL_VALUE_TYPE sqrt2_trunc const REAL_VALUE_TYPE sqrt2_trunc
= real_value_truncate (TYPE_MODE (type), *get_real_const (rv_sqrt2)); = real_value_truncate (TYPE_MODE (type), dconst_sqrt2 ());
return fold_build2 (MULT_EXPR, type, return fold_build2 (MULT_EXPR, type,
fold_build1 (ABS_EXPR, type, arg0), fold_build1 (ABS_EXPR, type, arg0),
build_real (type, sqrt2_trunc)); build_real (type, sqrt2_trunc));
...@@ -8448,8 +8444,7 @@ fold_builtin_pow (tree fndecl, tree arg0, tree arg1, tree type) ...@@ -8448,8 +8444,7 @@ fold_builtin_pow (tree fndecl, tree arg0, tree arg1, tree type)
if (flag_unsafe_math_optimizations) if (flag_unsafe_math_optimizations)
{ {
const REAL_VALUE_TYPE dconstroot const REAL_VALUE_TYPE dconstroot
= real_value_truncate (TYPE_MODE (type), = real_value_truncate (TYPE_MODE (type), dconst_third ());
*get_real_const (rv_third));
if (REAL_VALUES_EQUAL (c, dconstroot)) if (REAL_VALUES_EQUAL (c, dconstroot))
{ {
...@@ -8516,8 +8511,7 @@ fold_builtin_pow (tree fndecl, tree arg0, tree arg1, tree type) ...@@ -8516,8 +8511,7 @@ fold_builtin_pow (tree fndecl, tree arg0, tree arg1, tree type)
if (tree_expr_nonnegative_p (arg)) if (tree_expr_nonnegative_p (arg))
{ {
const REAL_VALUE_TYPE dconstroot const REAL_VALUE_TYPE dconstroot
= real_value_truncate (TYPE_MODE (type), = real_value_truncate (TYPE_MODE (type), dconst_third ());
*get_real_const (rv_third));
tree narg1 = fold_build2 (MULT_EXPR, type, arg1, tree narg1 = fold_build2 (MULT_EXPR, type, arg1,
build_real (type, dconstroot)); build_real (type, dconstroot));
return build_call_expr (fndecl, 2, arg, narg1); return build_call_expr (fndecl, 2, arg, narg1);
......
...@@ -2225,47 +2225,62 @@ times_pten (REAL_VALUE_TYPE *r, int exp) ...@@ -2225,47 +2225,62 @@ times_pten (REAL_VALUE_TYPE *r, int exp)
do_divide (r, r, &pten); do_divide (r, r, &pten);
} }
/* Returns the special REAL_VALUE_TYPE enumerated by E. */ /* Returns the special REAL_VALUE_TYPE corresponding to 'e'. */
const REAL_VALUE_TYPE * const REAL_VALUE_TYPE *
get_real_const (enum real_value_const e) dconst_e_ptr (void)
{ {
static REAL_VALUE_TYPE value[rv_max]; static REAL_VALUE_TYPE value;
gcc_assert (e < rv_max); /* Initialize mathematical constants for constant folding builtins.
These constants need to be given to at least 160 bits precision. */
if (value.cl == rvc_zero)
{
mpfr_t m;
mpfr_init2 (m, SIGNIFICAND_BITS);
mpfr_set_ui (m, 1, GMP_RNDN);
mpfr_exp (m, m, GMP_RNDN);
real_from_mpfr (&value, m, NULL_TREE, GMP_RNDN);
mpfr_clear (m);
}
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. /* Initialize mathematical constants for constant folding builtins.
These constants need to be given to at least 160 bits precision. */ These constants need to be given to at least 160 bits precision. */
if (value[e].cl == rvc_zero) if (value.cl == rvc_zero)
switch (e)
{ {
case rv_e: real_arithmetic (&value, RDIV_EXPR, &dconst1, real_digit (3));
{
mpfr_t m;
mpfr_init2 (m, SIGNIFICAND_BITS);
mpfr_set_ui (m, 1, GMP_RNDN);
mpfr_exp (m, m, GMP_RNDN);
real_from_mpfr (&value[e], m, NULL_TREE, GMP_RNDN);
mpfr_clear (m);
}
break;
case rv_third:
real_arithmetic (&value[e], RDIV_EXPR, &dconst1, real_digit (3));
break;
case rv_sqrt2:
{
mpfr_t m;
mpfr_init2 (m, SIGNIFICAND_BITS);
mpfr_sqrt_ui (m, 2, GMP_RNDN);
real_from_mpfr (&value[e], m, NULL_TREE, GMP_RNDN);
mpfr_clear (m);
}
break;
default:
gcc_unreachable();
} }
return &value;
}
/* Returns the special REAL_VALUE_TYPE corresponding to sqrt(2). */
return &value[e]; const REAL_VALUE_TYPE *
dconst_sqrt2_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)
{
mpfr_t m;
mpfr_init2 (m, SIGNIFICAND_BITS);
mpfr_sqrt_ui (m, 2, GMP_RNDN);
real_from_mpfr (&value, m, NULL_TREE, GMP_RNDN);
mpfr_clear (m);
}
return &value;
} }
/* Fills R with +Inf. */ /* Fills R with +Inf. */
......
...@@ -409,16 +409,18 @@ extern REAL_VALUE_TYPE dconst2; ...@@ -409,16 +409,18 @@ extern REAL_VALUE_TYPE dconst2;
extern REAL_VALUE_TYPE dconstm1; extern REAL_VALUE_TYPE dconstm1;
extern REAL_VALUE_TYPE dconsthalf; extern REAL_VALUE_TYPE dconsthalf;
/* Enumerate the special constant values we need. */ #define dconst_e() (*dconst_e_ptr ())
enum real_value_const { #define dconst_third() (*dconst_third_ptr ())
rv_e, #define dconst_sqrt2() (*dconst_sqrt2_ptr ())
rv_third,
rv_sqrt2, /* Function to return the real value special constant 'e'. */
rv_max extern const REAL_VALUE_TYPE * dconst_e_ptr (void);
};
/* Returns the special REAL_VALUE_TYPE corresponding to 1/3. */
extern const REAL_VALUE_TYPE * dconst_third_ptr (void);
/* Function to return a real value special constant. */ /* Returns the special REAL_VALUE_TYPE corresponding to sqrt(2). */
extern const REAL_VALUE_TYPE * get_real_const (enum real_value_const); extern const REAL_VALUE_TYPE * dconst_sqrt2_ptr (void);
/* Function to return a real value (not a tree node) /* Function to return a real value (not a tree node)
from a given integer constant. */ from a given integer constant. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment