[PATCH v2 0/4] math: Make rsqrt and rsqrtf correctly rounded

Adhemerval Zanella adhemerval.zanella@linaro.org
Thu Sep 24 17:59:22 GMT 2026


The generic rsqrt and rsqrtf compute 1/sqrt(x) in the same precision,
which rounds twice and shows up to 1 ulp for rounding to nearest (for
about 26% of the inputs) and up to 2 ulp for the directed roundings.
This series makes both correctly rounded in all rounding modes.

The first two patches add named workloads to the rsqrt and rsqrtf
benchtests, since the current inputs only cover [0.5,2) and report a
single mean.

For rsqrtf, evaluating 1.0 / sqrt ((double) x) is a straightforward way
to get the correctly rounded result, and it was checked exhaustively for
all binary32 inputs in all rounding modes.  I did not use the CORE-MATH
rsqrtf, since it trades some latency for larger code (three magic
constants for the hard cases, plus a FENV_ACCESS dependency).

For rsqrt, I used the CORE-MATH implementation and adapt to glibc.

On aarch64 (Neoverse-N1), rsqrtf keeps the same throughput with about
50% higher latency.  rsqrt is 51-63% slower in throughput and 33-53%
slower in latency.  This is the cost of correct rounding over a plain
square root and division.

Checked on aarch64-linux-gnu, x86_64-linux-gnu, powerpc64-linux-gnu,
and loongarch64-linux-gnuf64.

Changes from v1:
* Fixed on i686 check-localplt regression.

Adhemerval Zanella (4):
  benchtests: Add workloads to rsqrtf
  benchtests: Add workloads to rsqrt
  math: Make rsqrtf correctly rounded
  math: Use rsqrt from CORE-MATH

 NEWS                                      |    3 +-
 SHARED-FILES                              |    2 +
 benchtests/rsqrt-inputs                   | 2008 ++++++++++++++++++++-
 benchtests/rsqrtf-inputs                  | 2008 ++++++++++++++++++++-
 sysdeps/i386/Makefile                     |    2 +
 sysdeps/i386/fpu/math-use-builtins-sqrt.h |   12 +-
 sysdeps/ieee754/dbl-64/libm-test-ulps     |   12 +
 sysdeps/ieee754/dbl-64/s_rsqrt.c          |  144 ++
 sysdeps/ieee754/flt-32/libm-test-ulps     |   12 +
 sysdeps/ieee754/flt-32/s_rsqrtf.c         |   30 +
 10 files changed, 4228 insertions(+), 5 deletions(-)
 create mode 100644 sysdeps/ieee754/dbl-64/s_rsqrt.c
 create mode 100644 sysdeps/ieee754/flt-32/s_rsqrtf.c

-- 
2.53.0



More information about the Libc-alpha mailing list