[PATCH v2] math: New generic fmaf implementation

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Nov 26 16:25:15 GMT 2025



On 26/11/25 13:09, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
> Code looks good, just some missing/inaccurate comments:
> 
>> The original implementation adds some tests to handle underflow in
>> corner cases; however, it fails on the arm32 target. To fix it, I
>> kept the current implementation as a fallback to correctly raise
>> the expected exceptions.
> 
> This comment isn't right since Arm implements IEEE underflow correctly.
> It's also no longer relevant since we use the same fallback path now.

Oops, I forgot to rephrase it.

> 
>> Performance-wise, it shows large improvements:
> 
> Great to see even larger speedups!
> 
> +  uint64_t u = asuint64 (result);
> +  if (__glibc_likely ((u & 0xfffffff) != 0))
> +    return result;
>  
> This needs a comment (if not exact or at round to even boundary, the
> result is correct in all rounding modes).
> 
> -  union ieee754_double u;
> +  if ((u & 0x10000000) == 0
> +      && ((u >> MANTISSA_WIDTH) & 0x7ff) > EXPONENT_BIAS - 126)
> +    return result;
>  
> Here too since this is the case where the double result appears exact when
> it might not be and thus we won't set the underflow flag if denormal.
> 
> -  libc_feholdexcept_setround (&env, FE_TOWARDZERO);
> +  if (result - xy == z && result - z == xy)
> +    return result;
>  
> And here (return if result is exact in all rounding modes).
> 
> +  /*
> +   * If result is inexact, and exactly halfway between two float values,
> +   * we need to adjust the low-order bit in the direction of the error.
> +   */
> 
> This comment also needs updating. It appears to be an exact float or halfway
> case that is actually inexact and thus needs adjusting for rounding.


Ack.
> 
> Cheers,
> Wilco



More information about the Libc-alpha mailing list