aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2025-03-07 19:15:26 +0000
committerJoseph Myers <josmyers@redhat.com>2025-03-07 19:15:26 +0000
commit77261698b4e938020a1b2032709a54d942ba330f (patch)
tree6d7b1dd547ad3ed168503f308f627327a4f69b89
parentee3b1d15da412be19583085f81c220653b270c1f (diff)
downloadglibc-77261698b4e938020a1b2032709a54d942ba330f.tar.xz
glibc-77261698b4e938020a1b2032709a54d942ba330f.zip
Implement C23 rsqrt
C23 adds various <math.h> function families originally defined in TS 18661-4. Add the rsqrt functions (1/sqrt(x)). The test inputs are taken from those for sqrt. Tested for x86_64 and x86, and with build-many-glibcs.py.
-rw-r--r--NEWS7
-rw-r--r--manual/math.texi13
-rw-r--r--math/Makefile6
-rw-r--r--math/Versions6
-rw-r--r--math/auto-libm-test-in68
-rw-r--r--math/auto-libm-test-out-rsqrt3375
-rw-r--r--math/bits/mathcalls.h5
-rw-r--r--math/gen-auto-libm-tests.c3
-rwxr-xr-xmath/gen-tgmath-tests.py1
-rw-r--r--math/libm-test-rsqrt.inc58
-rw-r--r--math/s_rsqrt_template.c29
-rw-r--r--math/test-tgmath.c12
-rw-r--r--math/tgmath.h4
-rw-r--r--sysdeps/i386/i686/fpu/multiarch/libm-test-ulps18
-rw-r--r--sysdeps/ieee754/ldbl-128ibm-compat/Versions3
-rw-r--r--sysdeps/ieee754/ldbl-opt/Makefile2
-rw-r--r--sysdeps/ieee754/ldbl-opt/nldbl-rsqrt.c8
-rw-r--r--sysdeps/mach/hurd/i386/libm.abilist8
-rw-r--r--sysdeps/mach/hurd/x86_64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/alpha/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/arc/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/arm/be/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/arm/le/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/csky/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/hppa/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/i386/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/loongarch/lp64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/microblaze/be/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/microblaze/le/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/mips/mips32/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/mips/mips64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/or1k/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist9
-rw-r--r--sysdeps/unix/sysv/linux/riscv/rv32/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/riscv/rv64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/sh/be/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/sh/le/libm.abilist6
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/64/libm.abilist8
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist8
-rw-r--r--sysdeps/x86_64/fpu/libm-test-ulps24
50 files changed, 3865 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index e2e40e141c..29d3d47b64 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,12 @@ Version 2.42
Major new features:
- [Add new features here]
+* The following ISO C23 function families (introduced in TS
+ 18661-4:2015) are now supported in <math.h>. Each family includes
+ functions for float, double, long double, _FloatN and _FloatNx, and a
+ type-generic macro in <tgmath.h>.
+
+ - Power and absolute-value functions: rsqrt.
Deprecated and removed features, and other changes affecting compatibility:
diff --git a/manual/math.texi b/manual/math.texi
index def85a973d..439f608360 100644
--- a/manual/math.texi
+++ b/manual/math.texi
@@ -790,6 +790,19 @@ If @var{x} is negative, @code{sqrt} signals a domain error.
Mathematically, it should return a complex number.
@end deftypefun
+@deftypefun double rsqrt (double @var{x})
+@deftypefunx float rsqrtf (float @var{x})
+@deftypefunx {long double} rsqrtl (long double @var{x})
+@deftypefunx _FloatN rsqrtfN (_Float@var{N} @var{x})
+@deftypefunx _FloatNx rsqrtfNx (_Float@var{N}x @var{x})
+@standards{TS 18661-4:2015, math.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+These functions return the reciprocal of the nonnegative square root of @var{x}.
+If @var{x} is negative, @code{rsqrt} signals a domain error.
+
+The @code{rsqrt} functions are from TS 18661-4:2015.
+@end deftypefun
+
@cindex cube root function
@deftypefun double cbrt (double @var{x})
@deftypefunx float cbrtf (float @var{x})
diff --git a/math/Makefile b/math/Makefile
index 6dab60095b..7aabf355b4 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -139,6 +139,7 @@ gen-libm-calls = \
s_log2p1F \
s_nanF \
s_nextdownF \
+ s_rsqrtF \
s_significandF \
s_sinpiF \
s_tanpiF \
@@ -682,6 +683,7 @@ libm-test-funcs-auto = \
log1p \
log2p1 \
pow \
+ rsqrt \
sin \
sincos \
sinh \
@@ -1017,6 +1019,7 @@ tgmath3-macros = \
rint \
round \
roundeven \
+ rsqrt \
scalb \
scalbln \
scalbn \
@@ -1462,6 +1465,7 @@ CFLAGS-s_remquo.c += -fno-builtin-remquol
CFLAGS-s_rint.c += -fno-builtin-rintl
CFLAGS-s_round.c += -fno-builtin-roundl
CFLAGS-s_roundeven.c += -fno-builtin-roundevenl
+CFLAGS-s_rsqrt.c += -fno-builtin-rsqrtl
CFLAGS-w_scalb.c += -fno-builtin-scalbl
CFLAGS-w_scalbln.c += -fno-builtin-scalblnl
CFLAGS-s_scalbn.c += -fno-builtin-scalbnl
@@ -1596,6 +1600,7 @@ CFLAGS-s_remquo.c += -fno-builtin-remquof32x -fno-builtin-remquof64
CFLAGS-s_rint.c += -fno-builtin-rintf32x -fno-builtin-rintf64
CFLAGS-s_round.c += -fno-builtin-roundf32x -fno-builtin-roundf64
CFLAGS-s_roundeven.c += -fno-builtin-roundevenf32x -fno-builtin-roundevenf64
+CFLAGS-s_rsqrt.c += -fno-builtin-rsqrtf32x -fno-builtin-rsqrtf64
CFLAGS-w_scalbln.c += -fno-builtin-scalblnf32x -fno-builtin-scalblnf64
CFLAGS-s_scalbn.c += -fno-builtin-scalbnf32x -fno-builtin-scalbnf64
CFLAGS-s_setpayload.c += -fno-builtin-setpayloadf32x -fno-builtin-setpayloadf64
@@ -1721,6 +1726,7 @@ CFLAGS-s_remquof.c += -fno-builtin-remquof32
CFLAGS-s_rintf.c += -fno-builtin-rintf32
CFLAGS-s_roundf.c += -fno-builtin-roundf32
CFLAGS-s_roundevenf.c += -fno-builtin-roundevenf32
+CFLAGS-s_rsqrtf.c += -fno-builtin-rsqrtf32
CFLAGS-w_scalblnf.c += -fno-builtin-scalblnf32
CFLAGS-s_scalbnf.c += -fno-builtin-scalbnf32
CFLAGS-s_setpayloadf.c += -fno-builtin-setpayloadf32
diff --git a/math/Versions b/math/Versions
index e4fbef3f6d..34cdf2f8e8 100644
--- a/math/Versions
+++ b/math/Versions
@@ -671,4 +671,10 @@ libm {
sinpif64x; sinpif128;
tanpif64x; tanpif128;
}
+ GLIBC_2.42 {
+ # Functions not involving _Float64x or _Float128, for all configurations.
+ rsqrt; rsqrtf; rsqrtl; rsqrtf32; rsqrtf64; rsqrtf32x;
+ # Functions involving _Float64x or _Float128, for some configurations.
+ rsqrtf64x; rsqrtf128;
+ }
}
diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 7dd9cde9c9..989ce5d736 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -8151,6 +8151,74 @@ pow 0x1.059c76p+0 0x1.ff80bep+11
pow 0x1.7ac7cp+5 23
pow -0x1.7ac7cp+5 23
+rsqrt 2209
+rsqrt 4
+rsqrt 2
+rsqrt 0.25
+rsqrt 6642.25
+rsqrt 15190.5625
+rsqrt 0.75
+rsqrt 0x1.fffffffffffffp+1023
+rsqrt 0x1.ffffffffffffbp+1023
+rsqrt 0x1.ffffffffffff7p+1023
+rsqrt 0x1.ffffffffffff3p+1023
+rsqrt 0x1.fffffffffffefp+1023
+rsqrt 0x1.fffffffffffebp+1023
+rsqrt 0x1.fffffffffffe7p+1023
+rsqrt 0x1.fffffffffffe3p+1023
+rsqrt 0x1.fffffffffffdfp+1023
+rsqrt 0x1.fffffffffffdbp+1023
+rsqrt 0x1.fffffffffffd7p+1023
+rsqrt 0x1.0000000000003p-1022
+rsqrt 0x1.0000000000007p-1022
+rsqrt 0x1.000000000000bp-1022
+rsqrt 0x1.000000000000fp-1022
+rsqrt 0x1.0000000000013p-1022
+rsqrt 0x1.0000000000017p-1022
+rsqrt 0x1.000000000001bp-1022
+rsqrt 0x1.000000000001fp-1022
+rsqrt 0x1.0000000000023p-1022
+rsqrt 0x1.0000000000027p-1022
+rsqrt 0x1.000000000002bp-1022
+rsqrt 0x1.000000000002fp-1022
+rsqrt 0x1.0000000000033p-1022
+rsqrt 0x1.0000000000037p-1022
+rsqrt 0x1.7167bc36eaa3bp+6
+rsqrt 0x1.7570994273ad7p+6
+rsqrt 0x1.7dae969442fe6p+6
+rsqrt 0x1.7f8444fcf67e5p+6
+rsqrt 0x1.8364650e63a54p+6
+rsqrt 0x1.85bedd274edd8p+6
+rsqrt 0x1.8609cf496ab77p+6
+rsqrt 0x1.873849c70a375p+6
+rsqrt 0x1.8919c962cbaaep+6
+rsqrt 0x1.8de4493e22dc6p+6
+rsqrt 0x1.924829a17a288p+6
+rsqrt 0x1.92702cd992f12p+6
+rsqrt 0x1.92b763a8311fdp+6
+rsqrt 0x1.947da013c7293p+6
+rsqrt 0x1.9536091c494d2p+6
+rsqrt 0x1.61b04c6p-1019
+rsqrt 0x1.93789f1p-1018
+rsqrt 0x1.a1989b4p-1018
+rsqrt 0x1.f93bc9p-1018
+rsqrt 0x1.2f675e3p-1017
+rsqrt 0x1.a158508p-1017
+rsqrt 0x1.cd31f078p-1017
+rsqrt 0x1.33b43b08p-1016
+rsqrt 0x1.6e66a858p-1016
+rsqrt 0x1.8661cbf8p-1016
+rsqrt 0x1.bbb221b4p-1016
+rsqrt 0x1.c4942f3cp-1016
+rsqrt 0x1.dbb258c8p-1016
+rsqrt 0x1.57103ea4p-1015
+rsqrt 0x1.9b294f88p-1015
+rsqrt 0x1.0000000000001p+0
+rsqrt 0x1.fffffffffffffp-1
+rsqrt max
+rsqrt min
+rsqrt min_subnorm
+
sin 0
sin -0
sin pi/6
diff --git a/math/auto-libm-test-out-rsqrt b/math/auto-libm-test-out-rsqrt
new file mode 100644
index 0000000000..cc28e827c3
--- /dev/null
+++ b/math/auto-libm-test-out-rsqrt
@@ -0,0 +1,3375 @@
+rsqrt 2209
+= rsqrt downward binary32 0x8.a1p+8 : 0x5.726208p-8 : inexact
+= rsqrt tonearest binary32 0x8.a1p+8 : 0x5.726208p-8 : inexact
+= rsqrt towardzero binary32 0x8.a1p+8 : 0x5.726208p-8 : inexact
+= rsqrt upward binary32 0x8.a1p+8 : 0x5.72621p-8 : inexact
+= rsqrt downward binary64 0x8.a1p+8 : 0x5.72620ae4c415cp-8 : inexact
+= rsqrt tonearest binary64 0x8.a1p+8 : 0x5.72620ae4c415cp-8 : inexact
+= rsqrt towardzero binary64 0x8.a1p+8 : 0x5.72620ae4c415cp-8 : inexact
+= rsqrt upward binary64 0x8.a1p+8 : 0x5.72620ae4c416p-8 : inexact
+= rsqrt downward intel96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt tonearest intel96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt towardzero intel96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt upward intel96 0x8.a1p+8 : 0x5.72620ae4c415c99p-8 : inexact
+= rsqrt downward m68k96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt tonearest m68k96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt towardzero m68k96 0x8.a1p+8 : 0x5.72620ae4c415c988p-8 : inexact
+= rsqrt upward m68k96 0x8.a1p+8 : 0x5.72620ae4c415c99p-8 : inexact
+= rsqrt downward binary128 0x8.a1p+8 : 0x5.72620ae4c415c9882b931057262p-8 : inexact
+= rsqrt tonearest binary128 0x8.a1p+8 : 0x5.72620ae4c415c9882b931057262p-8 : inexact
+= rsqrt towardzero binary128 0x8.a1p+8 : 0x5.72620ae4c415c9882b931057262p-8 : inexact
+= rsqrt upward binary128 0x8.a1p+8 : 0x5.72620ae4c415c9882b9310572624p-8 : inexact
+= rsqrt downward ibm128 0x8.a1p+8 : 0x5.72620ae4c415c9882b93105726p-8 : inexact
+= rsqrt tonearest ibm128 0x8.a1p+8 : 0x5.72620ae4c415c9882b93105726p-8 : inexact
+= rsqrt towardzero ibm128 0x8.a1p+8 : 0x5.72620ae4c415c9882b93105726p-8 : inexact
+= rsqrt upward ibm128 0x8.a1p+8 : 0x5.72620ae4c415c9882b93105728p-8 : inexact
+rsqrt 4
+= rsqrt downward binary32 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest binary32 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero binary32 0x4p+0 : 0x8p-4 :
+= rsqrt upward binary32 0x4p+0 : 0x8p-4 :
+= rsqrt downward binary64 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest binary64 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero binary64 0x4p+0 : 0x8p-4 :
+= rsqrt upward binary64 0x4p+0 : 0x8p-4 :
+= rsqrt downward intel96 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest intel96 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero intel96 0x4p+0 : 0x8p-4 :
+= rsqrt upward intel96 0x4p+0 : 0x8p-4 :
+= rsqrt downward m68k96 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest m68k96 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero m68k96 0x4p+0 : 0x8p-4 :
+= rsqrt upward m68k96 0x4p+0 : 0x8p-4 :
+= rsqrt downward binary128 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest binary128 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero binary128 0x4p+0 : 0x8p-4 :
+= rsqrt upward binary128 0x4p+0 : 0x8p-4 :
+= rsqrt downward ibm128 0x4p+0 : 0x8p-4 :
+= rsqrt tonearest ibm128 0x4p+0 : 0x8p-4 :
+= rsqrt towardzero ibm128 0x4p+0 : 0x8p-4 :
+= rsqrt upward ibm128 0x4p+0 : 0x8p-4 :
+rsqrt 2
+= rsqrt downward binary32 0x2p+0 : 0xb.504f3p-4 : inexact
+= rsqrt tonearest binary32 0x2p+0 : 0xb.504f3p-4 : inexact
+= rsqrt towardzero binary32 0x2p+0 : 0xb.504f3p-4 : inexact
+= rsqrt upward binary32 0x2p+0 : 0xb.504f4p-4 : inexact
+= rsqrt downward binary64 0x2p+0 : 0xb.504f333f9de6p-4 : inexact
+= rsqrt tonearest binary64 0x2p+0 : 0xb.504f333f9de68p-4 : inexact
+= rsqrt towardzero binary64 0x2p+0 : 0xb.504f333f9de6p-4 : inexact
+= rsqrt upward binary64 0x2p+0 : 0xb.504f333f9de68p-4 : inexact
+= rsqrt downward intel96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt tonearest intel96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt towardzero intel96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt upward intel96 0x2p+0 : 0xb.504f333f9de6485p-4 : inexact
+= rsqrt downward m68k96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt tonearest m68k96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt towardzero m68k96 0x2p+0 : 0xb.504f333f9de6484p-4 : inexact
+= rsqrt upward m68k96 0x2p+0 : 0xb.504f333f9de6485p-4 : inexact
+= rsqrt downward binary128 0x2p+0 : 0xb.504f333f9de6484597d89b3754a8p-4 : inexact
+= rsqrt tonearest binary128 0x2p+0 : 0xb.504f333f9de6484597d89b3754a8p-4 : inexact
+= rsqrt towardzero binary128 0x2p+0 : 0xb.504f333f9de6484597d89b3754a8p-4 : inexact
+= rsqrt upward binary128 0x2p+0 : 0xb.504f333f9de6484597d89b3754bp-4 : inexact
+= rsqrt downward ibm128 0x2p+0 : 0xb.504f333f9de6484597d89b3754p-4 : inexact
+= rsqrt tonearest ibm128 0x2p+0 : 0xb.504f333f9de6484597d89b3754p-4 : inexact
+= rsqrt towardzero ibm128 0x2p+0 : 0xb.504f333f9de6484597d89b3754p-4 : inexact
+= rsqrt upward ibm128 0x2p+0 : 0xb.504f333f9de6484597d89b3758p-4 : inexact
+rsqrt 0.25
+= rsqrt downward binary32 0x4p-4 : 0x2p+0 :
+= rsqrt tonearest binary32 0x4p-4 : 0x2p+0 :
+= rsqrt towardzero binary32 0x4p-4 : 0x2p+0 :
+= rsqrt upward binary32 0x4p-4 : 0x2p+0 :
+= rsqrt downward binary64 0x4p-4 : 0x2p+0 :
+= rsqrt tonearest binary64 0x4p-4 : 0x2p+0 :
+= rsqrt towardzero binary64 0x4p-4 : 0x2p+0 :
+= rsqrt upward binary64 0x4p-4 : 0x2p+0 :
+= rsqrt downward intel9