[PATCH v2 2/4] math: Optimize fma call on log2pf1
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Oct 14 13:42:34 GMT 2025
On 14/10/25 10:18, Wilco Dijkstra wrote:
> Hi Adhemerval,
>
>> +++ b/sysdeps/ieee754/flt-32/s_log2p1f.c
>> @@ -231,7 +231,12 @@ __log2p1f (float x)
>> int j = (m + ((int64_t) 1 << (52 - 8))) >> (52 - 7), k = j > 53;
>> e += k;
>> double xd = asdouble (m | (uint64_t) 0x3ff << 52);
>> - z = fma (xd, ix[j], -1.0);
>> +#ifndef __FP_FAST_FMA
>> + if (__glibc_unlikely (x == -0x1.da285cp-5f))
>> + z = fma (xd, ix[j], -1.0);
>> + else
>> +#endif
>> + z = xd * ix[j] - 1.0;
>
> This relies on fp contraction on targets with FMA. I think it's best to do
> the same as in previous patch, reverse the if condition and use fma in
> the else part.
Indeed, are you ok with the following:
#ifndef __FP_FAST_FMA
/* The fma is required only for x == -0x1.da285cp-5f in FE_TONEAREST
to provide correctly rounded results. */
if (__glibc_likely (x != -0x1.da285cp-5f))
z = xd * ix[j] - 1.0;
else
#endif
z = fma (xd, ix[j], -1.0);
?
More information about the Libc-alpha
mailing list