This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: initialize dconsts lazily, improve GCC startup time


On 25/03/2008, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
>  +/* Returns the special REAL_VALUE_TYPE enumerated by E.  */
>  +
>  +const REAL_VALUE_TYPE *
>  +get_real_const (enum real_value_const e)
>  +{
>  +  static REAL_VALUE_TYPE value[rv_max];
>  +
>  +  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[e].cl == rvc_zero)
>  +    switch (e)
>  +    {
>  +    case rv_e:
>  +      {
>  +       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[e];
>  +}
>  +

I don't want to sound bikesheding, so feel free to ignore my comments
if you can't bother to change your patch. Why use a switch + enum
type? This seems too complex and without any speed benefit. Wouldn't
it be better to use inline or macro for each constant?

That is in real.h for example for dconstsqrt2:

#define dconst_sqrt2 get_real_dconst_sqrt2()

static inline const REAL_VALUE_TYPE *
get_real_dconst_sqrt2 (void)
{
  static REAL_VALUE_TYPE value = rvc_zero;

  if (value == 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;
}

Moreover, I think we can use __builtin_expect for the condition and
mark the function as pure.

Also, dconst_x is more readable and seems more robust and consistent
than a mix of dconstx and get_real_const (rv_x).

Cheers,

Manuel.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]