On Thu, Oct 1, 2015 at 3:59 PM, Bernd Schmidt <bschm...@redhat.com> wrote: > On 10/01/2015 03:51 PM, Richard Sandiford wrote: >> >> 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. OK to install? > > > Looks reasonable enough.
Given /* 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; } I wonder if it makes sense to have template<int a, int b> const REAL_VALUE_TYPE & dconst (void) { static REAL_VALUE_TYPE value; if (value.cl == rvc_zero) real_arithmetic (&value, RDIV_EXPR, real_digit (a), real_digit (b)); return value; } instead which allows us to use dconst<1,2>() in place of dconst_half () and allows arbitrary extra cached constants to be added (well, double-check that, but I think the function static should be a .comdat). Richard. > > Bernd