]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Remove the SVID error handling from tgammaf
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 5 Nov 2025 11:10:01 +0000 (08:10 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 5 Nov 2025 13:19:37 +0000 (10:19 -0300)
It improves latency for about 1.5% and throughput for about 2-4%.

Tested on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
32 files changed:
math/Versions
math/w_tgammaf_compat.c
sysdeps/generic/math_private_calls.h
sysdeps/ieee754/flt-32/e_gammaf_r.c
sysdeps/ieee754/flt-32/math_config.h
sysdeps/ieee754/flt-32/math_errf.c
sysdeps/ieee754/flt-32/w_tgammaf.c [new file with mode: 0644]
sysdeps/mach/hurd/i386/libm.abilist
sysdeps/unix/sysv/linux/aarch64/libm.abilist
sysdeps/unix/sysv/linux/alpha/libm.abilist
sysdeps/unix/sysv/linux/arm/be/libm.abilist
sysdeps/unix/sysv/linux/arm/le/libm.abilist
sysdeps/unix/sysv/linux/hppa/libm.abilist
sysdeps/unix/sysv/linux/i386/libm.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist
sysdeps/unix/sysv/linux/microblaze/be/libm.abilist
sysdeps/unix/sysv/linux/microblaze/le/libm.abilist
sysdeps/unix/sysv/linux/mips/mips32/libm.abilist
sysdeps/unix/sysv/linux/mips/mips64/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist
sysdeps/unix/sysv/linux/sh/be/libm.abilist
sysdeps/unix/sysv/linux/sh/le/libm.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist
sysdeps/unix/sysv/linux/x86_64/64/libm.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist

index 3afbc427b9dca3927958b4d2785e783cdfa38507..d6ad34f4593a3506deade53a6a7edfd9ab1d01c6 100644 (file)
@@ -707,5 +707,6 @@ libm {
     y0f;
     y1f;
     ynf;
+    tgammaf;
   }
 }
index 253d0c8b6634154e7cffd4e86e82fae3d6159d70..b63d6462610df4f20192e5de1bfdc8cef407fb16 100644 (file)
 #include <math_private.h>
 #include <math-svid-compat.h>
 #include <libm-alias-float.h>
+#include <shlib-compat.h>
 
-#if LIBM_SVID_COMPAT
+#if LIBM_SVID_COMPAT && SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_43)
 float
-__tgammaf(float x)
+__tgammaf_svid(float x)
 {
-       float y = __ieee754_gammaf_r(x, NULL);
+       float y = __tgammaf(x);
 
        if(__glibc_unlikely (!isfinite (y) || y == 0)
           && (isfinite (x) || (isinf (x) && x < 0.0f))
@@ -43,5 +44,5 @@ __tgammaf(float x)
        }
        return y;
 }
-libm_alias_float (__tgamma, tgamma)
+compat_symbol (libm, __tgammaf_svid, tgammaf, GLIBC_2_1);
 #endif
index 62ced4efb3dd37be1aa957b55520224f71be3338..097a5de673d5b106558623fa76b2e33fad62b956 100644 (file)
@@ -36,7 +36,9 @@ extern _Mdouble_ __MSUF (__ieee754_exp10) (_Mdouble_);
 extern _Mdouble_ __MSUF (__ieee754_exp2) (_Mdouble_);
 extern _Mdouble_ __MSUF (__ieee754_fmod) (_Mdouble_, _Mdouble_);
 extern _Mdouble_ __MSUF (__ieee754_gamma) (_Mdouble_);
+#if !defined __MATH_DECLARING_FLOAT
 extern _Mdouble_ __MSUF_R (__ieee754_gamma) (_Mdouble_, int *);
+#endif
 extern _Mdouble_ __MSUF (__ieee754_hypot) (_Mdouble_, _Mdouble_);
 extern _Mdouble_ __MSUF (__ieee754_j0) (_Mdouble_);
 extern _Mdouble_ __MSUF (__ieee754_j1) (_Mdouble_);
index 66e8caee0be4a2e1549c907fb83d3bee549a553f..2e16412775389615404cac84edcf03f029618d01 100644 (file)
@@ -25,31 +25,23 @@ SOFTWARE.
  */
 
 /* Changes with respect to the original CORE-MATH code:
-   - removed the dealing with errno
-     (this is done in the wrapper math/w_tgammaf_compat.c)
    - usage of math_narrow_eval to deal with underflow/overflow
-   - deal with signgamp
  */
 
+#include <array_length.h>
 #include <math.h>
 #include <float.h>
 #include <stdint.h>
 #include <stddef.h>
+#include <libm-alias-float.h>
+#include <math-svid-compat.h>
 #include <libm-alias-finite.h>
 #include <math-narrow-eval.h>
 #include "math_config.h"
 
 float
-__ieee754_gammaf_r (float x, int *signgamp)
+__tgammaf (float x)
 {
-  /* The wrapper in math/w_tgamma_template.c expects *signgamp to be set to a
-     non-negative value if the returned value is gamma(x), and to a negative
-     value if it is -gamma(x).
-     Since the code here directly computes gamma(x), we set it to 1.
-  */
-  if (signgamp != NULL)
-    *signgamp = 1;
-
   /* List of exceptional cases. Each entry contains the 32-bit encoding u of x,
      a binary32 approximation f of gamma(x), and a correction term df.  */
   static const struct
@@ -92,27 +84,22 @@ __ieee754_gammaf_r (float x, int *signgamp)
       uint64_t rt = asuint64 (f);
       if (((rt + 2) & 0xfffffff) < 4)
        {
-         for (unsigned i = 0; i < sizeof (tb) / sizeof (tb[0]); i++)
+         for (unsigned i = 0; i < array_length (tb); i++)
            if (t == tb[i].u)
              return tb[i].f + tb[i].df;
        }
+      if (isinf (r))
+       return __math_erangef (r);
       return r;
     }
   float fx = floorf (x);
   if (__glibc_unlikely (x >= 0x1.18522p+5f))
-    {
-      /* Overflow case.  The original CORE-MATH code returns
-        0x1p127f * 0x1p127f, but apparently some compilers replace this
-        by +Inf.  */
-      return math_narrow_eval (x * 0x1p127f);
-    }
+    return __math_oflowf (0);
   /* compute k only after the overflow check, otherwise the case to integer
      might overflow */
   int k = fx;
   if (__glibc_unlikely (fx == x))
     { /* x is integer */
-      if (x == 0.0f)
-       return 1.0f / x;
       if (x < 0.0f)
        return __math_invalidf (0.0f);
       double t0 = 1, x0 = 1;
@@ -121,12 +108,10 @@ __ieee754_gammaf_r (float x, int *signgamp)
       return t0;
     }
   if (__glibc_unlikely (x < -42.0f))
-    { /* negative non-integer */
-      /* For x < -42, x non-integer, |gamma(x)| < 2^-151.  */
-      static const float sgn[2] = { 0x1p-127f, -0x1p-127f };
-      /* Underflows always happens */
-      return math_narrow_eval (0x1p-127f * sgn[k & 1]);
-    }
+    /* negative non-integer */
+    /* For x < -42, x non-integer, |gamma(x)| < 2^-151.  */
+    /* Underflows always happens */
+    return __math_uflowf (k & 1);
   /* The array c[] stores a degree-15 polynomial approximation for
      gamma(x).  */
   static const double c[] =
@@ -164,13 +149,22 @@ __ieee754_gammaf_r (float x, int *signgamp)
   f *= w;
   uint64_t rt = asuint64 (f);
   float r = f;
+  if (__glibc_unlikely (r == 0))
+    return __math_uflowf (rt >> 63);
   /* Deal with exceptional cases.  */
   if (__glibc_unlikely (((rt + 2) & 0xfffffff) < 8))
     {
-      for (unsigned j = 0; j < sizeof (tb) / sizeof (tb[0]); j++)
+      for (unsigned j = 0; j < array_length (tb); j++)
        if (t == tb[j].u)
          return tb[j].f + tb[j].df;
     }
   return r;
 }
-libm_alias_finite (__ieee754_gammaf_r, __gammaf_r)
+
+#if LIBM_SVID_COMPAT
+versioned_symbol (libm, __tgammaf, tgammaf, GLIBC_2_43);
+libm_alias_float_other (__tgamma, tgamma)
+#else
+libm_alias_float (__tgamma, tgamma)
+#endif
+libm_alias_finite (__tgammaf, __gammaf_r)
index 230aee591ce7d67d647b4fe3f3145896f7a4d189..e927bdb2f93e2aeae8e8941d1469b55c069baf26 100644 (file)
@@ -225,6 +225,7 @@ attribute_hidden float __math_invalidf (float);
 attribute_hidden int __math_invalidf_i (int);
 attribute_hidden long int __math_invalidf_li (long int);
 attribute_hidden float __math_edomf (float x);
+attribute_hidden float __math_erangef (float x);
 
 /* Shared between expf, exp2f, exp10f, and powf.  */
 #define EXP2F_TABLE_BITS 5
index 244e38a4ce1c43033d0a59dab9998750402cbd73..45e7394be2fd2eebc6f79c0f8089839def41ea9b 100644 (file)
@@ -54,6 +54,12 @@ __math_edomf (float y)
   return with_errnof (y, EDOM);
 }
 
+attribute_hidden float
+__math_erangef (float y)
+{
+  return with_errnof (y, ERANGE);
+}
+
 /* NOINLINE prevents fenv semantics breaking optimizations.  */
 NOINLINE static float
 xflowf (uint32_t sign, float y)
diff --git a/sysdeps/ieee754/flt-32/w_tgammaf.c b/sysdeps/ieee754/flt-32/w_tgammaf.c
new file mode 100644 (file)
index 0000000..1cc8931
--- /dev/null
@@ -0,0 +1 @@
+/* Not needed.  */
index 95aeaacda6463e449a094ddd91a19c9bd8bb3a97..20da81158498cbfc88d3ac469e065b963ce6378a 100644 (file)
@@ -1335,6 +1335,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 4e203bf5a4a79329cfda3ea6b9dffd98c4fed56e..17a71db73def4e420951e5a8ec7d1a8d80aab374 100644 (file)
@@ -1301,6 +1301,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 3d587a92a616816029a3952260bac9cc21e5e838..ec439daa5de9bf3fc1a1ef5dae1e8f93f0137596 100644 (file)
@@ -1460,6 +1460,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 635490118faaa9173617cf9aef18bd76ea327f96..24e1adc4b5d415719bd2e962ed9dc7c85837d908 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 635490118faaa9173617cf9aef18bd76ea327f96..24e1adc4b5d415719bd2e962ed9dc7c85837d908 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 3e9cb9fd3eb4ca86f1e232851a4c44e17b1ea90a..b8e75bce1e39f7bc23136a2fe4f0df090ae7948c 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index b76820ffad943ce25c0ba98f4231ab75d07551f5..6d0400dcc10d22af4787d404c7d8c45f1b8748b3 100644 (file)
@@ -1342,6 +1342,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 635490118faaa9173617cf9aef18bd76ea327f96..24e1adc4b5d415719bd2e962ed9dc7c85837d908 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 67156d74fa51b37471f0a3a2bd083335d4f0963f..fcb3e6f3698b1d09b32872dc70e590a20c7afff7 100644 (file)
@@ -997,6 +997,7 @@ GLIBC_2.43 lgammaf_r F
 GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 86744483ed9e3802e96dbcc46d134f38cc7fa724..06c935c595ae792f31ac596b0ff1ed35915171cb 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 86744483ed9e3802e96dbcc46d134f38cc7fa724..06c935c595ae792f31ac596b0ff1ed35915171cb 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 24e19f31f724a3cb09fccdf88d1da4e27f917820..ac514efdcd481bf011688ce3ced5a2901e79db1d 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 0e2c6c646476aeedb03acc0aa2fd7b7815275fa5..713065cd6537f8f72e5be66e0e29aec0fbbb3161 100644 (file)
@@ -1301,6 +1301,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 1dfe3281c26b7b576ef02b913df6807d7e66cd30..64af459283082f617a5818da0f5639670f032b27 100644 (file)
@@ -1113,6 +1113,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index bc167e6424bdf3134980e9e73dbdf893cb88eab9..c9b6b2be850a5525a8e9e44ee974230bbee177d4 100644 (file)
@@ -1105,12 +1105,14 @@ GLIBC_2.43 coshf F
 GLIBC_2.43 j0f F
 GLIBC_2.43 j1f F
 GLIBC_2.43 jnf F
+GLIBC_2.43 lgammaf F
 GLIBC_2.43 lgammaf_r F
 GLIBC_2.43 log10f F
 GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index d123eeef26cdb23d853028a6679f19ccd92a96bc..a7a949ec86fa22e514f70bac1fc591921055e29c 100644 (file)
@@ -1106,6 +1106,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index ca9f3cd4b92a2c7b557f23f83c2e329b6962018c..5f6dd0a606beabb0b6e5992ca5d16707af170a07 100644 (file)
@@ -1490,6 +1490,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index f36d31952b9a206d574afaca3f5ef41f81a620e3..9c3a54a6dbcf50afe636c43dba65710d6af6aaa5 100644 (file)
@@ -1404,6 +1404,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 355df9f489a8a92adc9617de9cb9be40fbc8d9e9..0c6fd6ef6580884baeac306648c4fd5ea737046c 100644 (file)
@@ -1404,6 +1404,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 9b626d9580ab1799884b3fa0445a223d32bcddbb..24c81ef25a1c3b895bd50db255f36c47ff2187f5 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 9b626d9580ab1799884b3fa0445a223d32bcddbb..24c81ef25a1c3b895bd50db255f36c47ff2187f5 100644 (file)
@@ -966,6 +966,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 7ddd3c4b5ec38a077bc015eef5d48c48b1a16560..064ca0f7c6e2e6d255fe937cdd8590c37c967467 100644 (file)
@@ -1411,6 +1411,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index 5cd12dfb195844e8c994b4e7eeb6905411853350..a5717fe5461a5e14f61981e0f3fa29b54cf52309 100644 (file)
@@ -1301,6 +1301,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index eb267367f198260c25237e4cb2a2a9e90ab839eb..d3dff0e42bbccbd671a9dc93aa31bac516776790 100644 (file)
@@ -1334,6 +1334,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F
index d1fea5ad569321454551b15aada87c7dec58b50f..387d97597ece2c5d8ddfd7c3d0c9dfe507f79782 100644 (file)
@@ -1334,6 +1334,7 @@ GLIBC_2.43 remainder F
 GLIBC_2.43 remainderf F
 GLIBC_2.43 sinhf F
 GLIBC_2.43 sqrtf F
+GLIBC_2.43 tgammaf F
 GLIBC_2.43 y0f F
 GLIBC_2.43 y1f F
 GLIBC_2.43 ynf F