math: Remove the SVID error handling from lgammaf/lgammaf_r

It improves latency throughput for about 2%.

Tested on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
This commit is contained in:
Adhemerval Zanella 2025-11-05 08:10:00 -03:00
parent c0be0b4527
commit de0e623434
33 changed files with 104 additions and 18 deletions

View File

@ -697,6 +697,8 @@ libm {
j0f;
j1f;
jnf;
lgammaf;
lgammaf_r;
log10f;
remainder;
remainderf;

View File

@ -34,10 +34,17 @@
old glibc.
Users of this file define USE_AS_COMPAT to 0 when building the main
version of lgamma, 1 when building the compatibility version. */
version of lgamma, 1 when building the compatibility version that
handles signgam visibility, and 2 when building the compatibility
that handles SVID support). */
#if USE_AS_COMPAT <= 1
#define LGAMMA_OLD_VER GLIBC_2_0
#define LGAMMA_NEW_VER GLIBC_2_23
#elif USE_AS_COMPAT == 2
#define LGAMMA_OLD_VER GLIBC_2_23
#define LGAMMA_NEW_VER GLIBC_2_43
#endif
#define HAVE_LGAMMA_COMPAT SHLIB_COMPAT (libm, LGAMMA_OLD_VER, LGAMMA_NEW_VER)
/* Whether to build this version at all. */
@ -45,8 +52,10 @@
(LIBM_SVID_COMPAT && (HAVE_LGAMMA_COMPAT || !USE_AS_COMPAT))
/* The name to use for this version. */
#if USE_AS_COMPAT
#if USE_AS_COMPAT == 1
# define LGFUNC(FUNC) FUNC ## _compat
#elif USE_AS_COMPAT == 2
# define LGFUNC(FUNC) FUNC ## _compat2
#else
# define LGFUNC(FUNC) FUNC
#endif
@ -54,7 +63,7 @@
/* If there is a compatibility version, gamma (not an ISO C function,
so never a problem for it to set signgam) points directly to it
rather than having separate versions. */
#define GAMMA_ALIAS (USE_AS_COMPAT ? HAVE_LGAMMA_COMPAT : !HAVE_LGAMMA_COMPAT)
#define GAMMA_ALIAS (USE_AS_COMPAT == 1 ? HAVE_LGAMMA_COMPAT : !HAVE_LGAMMA_COMPAT)
/* How to call the underlying lgamma_r function. */
#define CALL_LGAMMA(TYPE, FUNC, ARG) \

View File

@ -1,2 +1,2 @@
#define USE_AS_COMPAT 0
#define USE_AS_COMPAT 2
#include <w_lgammaf_main.c>

View File

@ -33,12 +33,7 @@ LGFUNC (__lgammaf) (float x)
return y;
}
# if USE_AS_COMPAT
compat_symbol (libm, __lgammaf_compat, lgammaf, LGAMMA_OLD_VER);
# else
versioned_symbol (libm, __lgammaf, lgammaf, LGAMMA_NEW_VER);
libm_alias_float_other (__lgamma, lgamma)
# endif
compat_symbol (libm, LGFUNC (__lgammaf), lgammaf, LGAMMA_OLD_VER);
# if GAMMA_ALIAS
strong_alias (LGFUNC (__lgammaf), __gammaf)
weak_alias (__gammaf, gammaf)

View File

@ -20,11 +20,12 @@
#include <math_private.h>
#include <math-svid-compat.h>
#include <libm-alias-float.h>
#include <shlib-compat.h>
#if LIBM_SVID_COMPAT
float
__lgammaf_r(float x, int *signgamp)
__lgammaf_r_svidf(float x, int *signgamp)
{
float y = __ieee754_lgammaf_r(x,signgamp);
if(__builtin_expect(!isfinite(y), 0)
@ -36,5 +37,5 @@ __lgammaf_r(float x, int *signgamp)
return y;
}
libm_alias_float_r (__lgamma, lgamma, _r)
compat_symbol (libm, __lgammaf_r_svidf, lgammaf_r, GLIBC_2_0);
#endif

View File

@ -36,6 +36,8 @@ SOFTWARE.
#include <math.h>
#include <libm-alias-finite.h>
#include <limits.h>
#include <libm-alias-float.h>
#include <math-svid-compat.h>
#include <math-narrow-eval.h>
#include "math_config.h"
@ -108,7 +110,7 @@ as_ln (double x)
}
float
__ieee754_lgammaf_r (float x, int *signgamp)
__lgammaf_r (float x, int *signgamp)
{
static const struct
{
@ -161,7 +163,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
if (x <= 0.0f)
{
*signgamp = asuint (x) >> 31 ? -1 : 1;
return 1.0f / 0.0f;
return __math_divzerof (0);
}
if (x == 1.0f || x == 2.0f)
{
@ -206,10 +208,11 @@ __ieee754_lgammaf_r (float x, int *signgamp)
if (ax > 0x1.afc1ap+1f)
{
if (__glibc_unlikely (x > 0x1.895f1cp+121f))
return math_narrow_eval (0x1p127f * 0x1p127f);
return __math_oflowf (0);
/* |x|>=2**23, must be -integer */
if (__glibc_unlikely (x < 0.0f && ax > 0x1p+23f))
return ax / 0.0f;
return __math_divzerof (0);
double lz = as_ln (z);
f = (z - 0.5) * (lz - 1) + 0x1.acfe390c97d69p-2;
if (ax < 0x1.0p+20f)
@ -271,7 +274,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
{
int ni = floorf (-2 * x);
if ((ni & 1) == 0 && ni == -2 * x)
return 1.0f / 0.0f;
return __math_divzerof (0);
}
const double c0 = 0x1.3cc0e6a0106b3p+2;
static const double rd[] =
@ -363,4 +366,13 @@ __ieee754_lgammaf_r (float x, int *signgamp)
}
return r;
}
libm_alias_finite (__ieee754_lgammaf_r, __lgammaf_r)
strong_alias (__lgammaf_r, __ieee754_lgammaf_r)
libm_alias_finite (__lgammaf_r, __lgammaf_r)
#if LIBM_SVID_COMPAT
versioned_symbol (libm, __lgammaf_r, lgammaf_r, GLIBC_2_43);
# if __HAVE_FLOAT32 && !__HAVE_DISTINCT_FLOAT32
weak_alias (__lgammaf_r, lgammaf32_r)
# endif
#else
libm_alias_float_r (__lgamma, lgamma, _r)
#endif

View File

@ -0,0 +1,17 @@
#include <math-svid-compat.h>
#include <math.h>
#include <libm-alias-float.h>
float
__lgammaf (float x)
{
return __lgammaf_r (x, &__signgam);
}
#if LIBM_SVID_COMPAT
versioned_symbol (libm, __lgammaf, lgammaf, GLIBC_2_43);
libm_alias_float_other (__lgamma, lgamma)
#else
libm_alias_float (__lgamma, lgamma)
strong_alias (__lgammaf, __gammaf)
weak_alias (__gammaf, gammaf)
#endif

View File

@ -0,0 +1 @@
/* Not needed. */

View File

@ -1328,6 +1328,8 @@ GLIBC_2.43 fmodf 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

View File

@ -1294,6 +1294,8 @@ 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

View File

@ -1453,6 +1453,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -1335,6 +1335,8 @@ GLIBC_2.43 fmodf 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -992,6 +992,8 @@ GLIBC_2.43 fmodf 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 remainder F
GLIBC_2.43 remainderf F
GLIBC_2.43 sqrtf F

View File

@ -959,6 +959,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -1294,6 +1294,8 @@ 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

View File

@ -1106,6 +1106,8 @@ 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

View File

@ -1105,6 +1105,7 @@ GLIBC_2.43 coshf F
GLIBC_2.43 j0f F
GLIBC_2.43 j1f F
GLIBC_2.43 jnf F
GLIBC_2.43 lgammaf_r F
GLIBC_2.43 log10f F
GLIBC_2.43 remainder F
GLIBC_2.43 remainderf F

View File

@ -1099,6 +1099,8 @@ 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

View File

@ -1483,6 +1483,8 @@ 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

View File

@ -1397,6 +1397,8 @@ 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

View File

@ -1397,6 +1397,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -959,6 +959,8 @@ 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

View File

@ -1404,6 +1404,8 @@ 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

View File

@ -1294,6 +1294,8 @@ 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

View File

@ -1327,6 +1327,8 @@ 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

View File

@ -1327,6 +1327,8 @@ 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