[PATCH v2 5/5] math: Optimize frexpl (binary128) with fast path for normal numbers

Wilco Dijkstra Wilco.Dijkstra@arm.com
Tue Nov 4 21:36:55 GMT 2025


Hi Osama,

A few additional comments:

> +  uint64_t hx, lx;
> +  GET_LDOUBLE_WORDS64 (hx, lx, x);
> +  uint64_t ex = 0x7fff & (hx >> 48);

I'd swap that around for clarity.

> +
> +  /* Fast path for normal numbers.  */
> +  if (__glibc_likely ((ex - 1U) < 0x7ffe))
> +    {
> +      *eptr = ex - EXPONENT_BIAS + 1;
> +      hx = hx - ((ex - FREXPL_EXP_VALUE) << 48);

This is simpler and doesn't require FREXPL_EXP_VALUE:

ex -= EXPONENT_BIAS - 1;
*eptr = ex;
hx = hx - (ex << 48);

> +      SET_LDOUBLE_MSW64 (x, hx);
> +      return x;
> +    }
> +
> +  /* Handle zero, infinity, and NaN.  */
> +  uint64_t ix = hx & 0x7fffffffffffffffULL;
> +  if (__glibc_likely (ix >= 0x7fff000000000000ULL || ((ix | lx) == 0)))

ex == 0x7fff || ((hx << 1) | lx) == 0) is simpler and avoids all the huge immediates.

> +    {
> +      *eptr = 0;
> +      return x + x;
> +    }
> +
> +  /* Subnormal.  */
> +  x *= two114;
> +  GET_LDOUBLE_MSW64 (hx, x);
> +  ex = 0x7fff & (hx >> 48);

swap immediate

> +  *eptr = ex - EXPONENT_BIAS - 114 + 1;
> +  hx = hx - ((ex - FREXPL_EXP_VALUE) << 48);

This feels a bit clearer:

ex -= EXPONENT_BIAS - 1;
*eptr = ex - 114;
hx = hx - (ex << 48);

> +  SET_LDOUBLE_MSW64 (x, hx);
> +  return x;
>  }

Cheers,
Wilco


More information about the Libc-alpha mailing list