[PATCH 3/7] math: Simplify and optimize modff implementation

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Jun 13 15:02:26 GMT 2025



On 11/06/25 10:40, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
>> Refactor the generic implementation to use math_config.h definitions,
>> and add an alternative one if the ABI supports truncf instructions
>> (gated through math-use-builtins-trunc.h).
>>
>> The generic implementation generates similar code for x86_64, while
>> the optimization path aarch64 (where truncf is supported as a builtin)
>> through frintz), the improvements are:
> 
> A few comments:
> 
> +get_exponent (uint32_t x)
> +{
> +  return (int)(x >> MANTISSA_WIDTH & 0xff) - EXPONENT_BIAS;
> 
> I think extra parenthesis around the shift would make it clearer.

Ack.

> 
> +#if USE_TRUNCF_BUILTIN
> +  if (is_inf (t))
> +    {
> +      *iptr = x;
> +      return copysign (0.0, x);
> +    }
> 
> Should be copysignf (0.0f, x);

Ack.

> 
> +	  /* |x|<1 -> *iptr = +-0 */
> +	  *iptr = asfloat (t & SIGN_MASK);;
> 
> Extra ';'

Ack.

> 
> +      uint32_t i = 0x007fffff >> e;
> 
> Would MANTISSA_MASK be clearer?

Ack.

> 
> +  /* Set invalid operation for sNaN.  */
> +  *iptr = x * 1.0f;
> +  if ((e == 0x80) && (t & 0x7fffffu))
> 
> And here.

Ack.

> 
> Cheers,
> Wilco



More information about the Libc-alpha mailing list