[PATCH 0/5] math: Optimize frexp functions with fast path

Osama Abdelkader osama.abdelkader@gmail.com
Tue Oct 21 22:05:17 GMT 2025


This patch series optimizes the frexp family of functions by adding a fast
path for normal floating-point numbers, which represent the vast majority of
real-world usage.

The optimization uses a single unsigned comparison (ex - 1) < MAX_NORMAL_EXP
to identify normal numbers and returns immediately via bit manipulation,
avoiding branches and floating-point operations.

Following feedback from Adhemerval Zanella, the implementation:
- Uses asuint64()/asdouble() and asuint()/asfloat() from math_config.h
- Uses symbolic constants (MANTISSA_MASK, SIGN_MASK, EXPONENT_BIAS, etc.)
- Splits the changes into separate patches per precision type

Following Paul's request, benchmarks are included to quantify the
performance improvements.

Benchmark results on Intel Core i9-13900H (13th Gen):

  Function     Baseline    Optimized   Speedup
  --------     --------    ---------   -------
  frexp        6.778 ns    6.210 ns    1.09x (8.4% faster)
  frexpf       5.858 ns    5.878 ns    Neutral (within noise)
  frexpl       25.543 ns   24.402 ns   1.05x (4.5% faster)

The optimization provides measurable improvements for double (8.4%) and
long double (4.5%) precision, with no regression for float. All existing
tests pass, maintaining exact correctness for edge cases.

Suggested-by: Wilco Dijkstra <wilco.dijkstra@arm.com>

Osama Abdelkader (5):
  benchtests: Add benchmarks for frexp functions
  math: Optimize frexpf (binary32) with fast path for normal numbers
  math: Optimize frexp (binary64) with fast path for normal numbers
  math: Optimize frexpl (intel96) with fast path for normal numbers
  math: Optimize frexpl (binary128) with fast path for normal numbers

 benchtests/Makefile                 |  6 +++++
 benchtests/frexp-inputs             | 26 +++++++++++++++++++
 benchtests/frexpf-inputs            | 26 +++++++++++++++++++
 benchtests/frexpl-inputs            | 26 +++++++++++++++++++
 sysdeps/ieee754/dbl-64/s_frexp.c    | 39 ++++++++++++++++-------------
 sysdeps/ieee754/flt-32/s_frexpf.c   | 37 ++++++++++++++++-----------
 sysdeps/ieee754/ldbl-128/s_frexpl.c | 38 ++++++++++++++++++++--------
 sysdeps/ieee754/ldbl-96/s_frexpl.c  | 35 ++++++++++++++++++--------
 8 files changed, 180 insertions(+), 53 deletions(-)
 create mode 100644 benchtests/frexp-inputs
 create mode 100644 benchtests/frexpf-inputs
 create mode 100644 benchtests/frexpl-inputs

-- 
2.43.0



More information about the Libc-alpha mailing list