diff options
author | Xiaolin Tang <tangxiaolin@loongson.cn> | 2022-11-23 11:44:56 +0800 |
---|---|---|
committer | caiyinyu <caiyinyu@loongson.cn> | 2022-11-29 16:00:28 +0800 |
commit | 2b23ab1feab5a59bcc1931666663b2a8eac3fdbc (patch) | |
tree | 037d70b1f7a836854162a9f86c2ed62a834130c7 | |
parent | 948652e4f82f5aedbe882178ae158990bde63c79 (diff) | |
download | glibc-2b23ab1feab5a59bcc1931666663b2a8eac3fdbc.tar.gz glibc-2b23ab1feab5a59bcc1931666663b2a8eac3fdbc.tar.xz glibc-2b23ab1feab5a59bcc1931666663b2a8eac3fdbc.zip |
Use GCC builtins for lrint functions if desired.
This patch is using the corresponding GCC builtin for lrintf, lrint, lrintl and lrintf128 if the USE_FUNCTION_BUILTIN macros are defined to one in math-use-builtins-function.h. Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
-rw-r--r-- | sysdeps/generic/math-use-builtins-lrint.h | 4 | ||||
-rw-r--r-- | sysdeps/generic/math-use-builtins.h | 1 | ||||
-rw-r--r-- | sysdeps/ieee754/dbl-64/s_lrint.c | 18 | ||||
-rw-r--r-- | sysdeps/ieee754/float128/float128_private.h | 2 | ||||
-rw-r--r-- | sysdeps/ieee754/flt-32/s_lrintf.c | 18 | ||||
-rw-r--r-- | sysdeps/ieee754/ldbl-128/s_lrintl.c | 17 |
6 files changed, 43 insertions, 17 deletions
diff --git a/sysdeps/generic/math-use-builtins-lrint.h b/sysdeps/generic/math-use-builtins-lrint.h new file mode 100644 index 0000000000..e80418be9e --- /dev/null +++ b/sysdeps/generic/math-use-builtins-lrint.h @@ -0,0 +1,4 @@ +#define USE_LRINT_BUILTIN 0 +#define USE_LRINTF_BUILTIN 0 +#define USE_LRINTL_BUILTIN 0 +#define USE_LRINTF128_BUILTIN 0 diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index 6bd424d900..3acec1d538 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -37,5 +37,6 @@ #include <math-use-builtins-fmax.h> #include <math-use-builtins-fmin.h> #include <math-use-builtins-fabs.h> +#include <math-use-builtins-lrint.h> #endif /* MATH_USE_BUILTINS_H */ diff --git a/sysdeps/ieee754/dbl-64/s_lrint.c b/sysdeps/ieee754/dbl-64/s_lrint.c index d4272916cd..24385038ef 100644 --- a/sysdeps/ieee754/dbl-64/s_lrint.c +++ b/sysdeps/ieee754/dbl-64/s_lrint.c @@ -25,17 +25,22 @@ #include <math_private.h> #include <libm-alias-double.h> #include <fix-fp-int-convert-overflow.h> - -static const double two52[2] = -{ - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ -}; +#include <math-use-builtins.h> long int __lrint (double x) { +#if USE_LRINT_BUILTIN + return __builtin_lrint (x); +#else + /* Use generic implementation. */ + static const double two52[2] = + { + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ + }; + int32_t j0; uint32_t i0, i1; double w; @@ -119,6 +124,7 @@ __lrint (double x) } return sx ? -result : result; +#endif /* ! USE_LRINT_BUILTIN */ } libm_alias_double (__lrint, lrint) diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h index f9655df0df..a452ced89a 100644 --- a/sysdeps/ieee754/float128/float128_private.h +++ b/sysdeps/ieee754/float128/float128_private.h @@ -161,6 +161,8 @@ #define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN #undef USE_FMAL_BUILTIN #define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN +#undef USE_LRINTL_BUILTIN +#define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN /* IEEE function renames. */ #define __ieee754_acoshl __ieee754_acoshf128 diff --git a/sysdeps/ieee754/flt-32/s_lrintf.c b/sysdeps/ieee754/flt-32/s_lrintf.c index 7438b272b2..50d044dd8d 100644 --- a/sysdeps/ieee754/flt-32/s_lrintf.c +++ b/sysdeps/ieee754/flt-32/s_lrintf.c @@ -25,17 +25,22 @@ #include <math_private.h> #include <libm-alias-float.h> #include <fix-fp-int-convert-overflow.h> - -static const float two23[2] = -{ - 8.3886080000e+06, /* 0x4B000000 */ - -8.3886080000e+06, /* 0xCB000000 */ -}; +#include <math-use-builtins.h> long int __lrintf (float x) { +#if USE_LRINTF_BUILTIN + return __builtin_lrintf (x); +#else + /* Use generic implementation. */ + static const float two23[2] = + { + 8.3886080000e+06, /* 0x4B000000 */ + -8.3886080000e+06, /* 0xCB000000 */ + }; + int32_t j0; uint32_t i0; float w; @@ -82,6 +87,7 @@ __lrintf (float x) } return sx ? -result : result; +#endif /* ! USE_LRINTF_BUILTIN */ } libm_alias_float (__lrint, lrint) diff --git a/sysdeps/ieee754/ldbl-128/s_lrintl.c b/sysdeps/ieee754/ldbl-128/s_lrintl.c index e8ec02dc6f..ecb604a650 100644 --- a/sysdeps/ieee754/ldbl-128/s_lrintl.c +++ b/sysdeps/ieee754/ldbl-128/s_lrintl.c @@ -24,16 +24,22 @@ #include <math_private.h> #include <libm-alias-ldouble.h> #include <fix-fp-int-convert-overflow.h> +#include <math-use-builtins.h> -static const _Float128 two112[2] = -{ - L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */ - L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */ -}; long int __lrintl (_Float128 x) { +#if USE_LRINTL_BUILTIN + return __builtin_lrintl (x); +#else + /* Use generic implementation. */ + static const _Float128 two112[2] = + { + L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */ + L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */ + }; + int32_t j0; uint64_t i0,i1; _Float128 w; @@ -131,6 +137,7 @@ __lrintl (_Float128 x) } return sx ? -result : result; +#endif /* ! USE_LRINTL_BUILTIN */ } libm_alias_ldouble (__lrint, lrint) |