[v2,4/5] math: Optimize frexpl (intel96) with fast path for normal numbers

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Nov 6 17:35:01 GMT 2025


Hi Osama,

A few comments on this similar to the v2 ldbl-128 version:

+  uint32_t se, hx, lx;
+  GET_LDOUBLE_WORDS (se, hx, lx, x);
+  uint32_t ex = 0x7fff & se;

Swap operands.

+  /* Fast path for normal numbers.  */
+  if (__glibc_likely ((ex - 1U) < 0x7ffe))

No need for 1U here.

+    {
+      *eptr = ex - EXPONENT_BIAS + 1;
+      se = se - (ex - FREXPL_EXP);

It's better to do the same as for ldbl-128:

ex -= EXPONENT_BIAS - 1;
*eptr = ex;
SET_LDOUBLE_EXP (x, se - ex);

+      SET_LDOUBLE_EXP (x, se);
+      return x;
+    }
+
+  /* Handle zero, infinity, and NaN.  */
+  if (__glibc_likely (ex == 0x7fff || ((ex | hx | lx) == 0)))
+    {
+      *eptr = 0;
+      return x + x;
+    }

OK

+  /* Subnormal.  */
+  x *= two65;
+  GET_LDOUBLE_EXP (se, x);
+  ex = se & 0x7fff;
+  *eptr = ex - EXPONENT_BIAS - 65 + 1;
+  se = (se & SIGN_MASK) | FREXPL_EXP;

This is clearer without FREXPL_EXP:

ex = (se & 0x7fff) - EXPONENT_BIAS + 1;
*eptr = ex - 65;
SET_LDOUBLE_EXP (x, se - ex);


+  SET_LDOUBLE_EXP (x, se);
+  return x;

Cheers,
Wilco


More information about the Libc-alpha mailing list