public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] Use GCC builtins for lrint functions if desired.
@ 2022-11-29 8:00 Yinyu Cai
0 siblings, 0 replies; only message in thread
From: Yinyu Cai @ 2022-11-29 8:00 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2b23ab1feab5a59bcc1931666663b2a8eac3fdbc
commit 2b23ab1feab5a59bcc1931666663b2a8eac3fdbc
Author: Xiaolin Tang <tangxiaolin@loongson.cn>
Date: Wed Nov 23 11:44:56 2022 +0800
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>
Diff:
---
sysdeps/generic/math-use-builtins-lrint.h | 4 ++++
sysdeps/generic/math-use-builtins.h | 1 +
sysdeps/ieee754/dbl-64/s_lrint.c | 18 ++++++++++++------
sysdeps/ieee754/float128/float128_private.h | 2 ++
sysdeps/ieee754/flt-32/s_lrintf.c | 18 ++++++++++++------
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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-29 8:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29 8:00 [glibc] Use GCC builtins for lrint functions if desired Yinyu Cai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).