This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Cache reals for 1/4, 1/6 and 1/9
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, richard dot sandiford at arm dot com
- Date: Fri, 2 Oct 2015 10:11:32 +0200
- Subject: Re: Cache reals for 1/4, 1/6 and 1/9
- Authentication-results: sourceware.org; auth=none
- References: <87twqay9vr dot fsf at e105548-lin dot cambridge dot arm dot com> <560D3C58 dot 1050805 at redhat dot com>
On Thu, Oct 1, 2015 at 3:59 PM, Bernd Schmidt <bschmidt@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