mirror of
https://sourceware.org/git/glibc.git
synced 2026-10-24 01:33:52 +03:00
math: Remove the SVID error handling from tgammaf
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>
This commit is contained in:
@@ -707,5 +707,6 @@ libm {
|
||||
y0f;
|
||||
y1f;
|
||||
ynf;
|
||||
tgammaf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
#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
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
1
sysdeps/ieee754/flt-32/w_tgammaf.c
Normal file
1
sysdeps/ieee754/flt-32/w_tgammaf.c
Normal file
@@ -0,0 +1 @@
|
||||
/* Not needed. */
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user