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

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Jun 11 13:40:49 GMT 2025


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.

+#if USE_TRUNCF_BUILTIN
+  if (is_inf (t))
+    {
+      *iptr = x;
+      return copysign (0.0, x);
+    }

Should be copysignf (0.0f, x);

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

Extra ';'

+      uint32_t i = 0x007fffff >> e;

Would MANTISSA_MASK be clearer?

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

And here.

Cheers,
Wilco


More information about the Libc-alpha mailing list