From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7891) id 4904E3853D54; Tue, 29 Nov 2022 08:00:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4904E3853D54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669708853; bh=xANMuAPKG+LAWUyK/WIxSuAEDXYKuljGcojmGh8s8SM=; h=From:To:Subject:Date:From; b=ykllt3OqCvJc968tLcEeMxRtjKozH5D/nm48tbIe1deEjqY/I6Rvx5o2n2tIVUKCr VIuN6G2xm/VYM+K5OQLs0SQ2LcBa//8/0kMOBMcS9cqCBK9YDFJzeQWsOwhYWAj/+P TDYrXohbpPwvIgeGPwHixXHk10heG9ZI0fo3BcGQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Yinyu Cai To: glibc-cvs@sourceware.org Subject: [glibc] Use GCC builtins for lrint functions if desired. X-Act-Checkin: glibc X-Git-Author: Xiaolin Tang X-Git-Refname: refs/heads/master X-Git-Oldrev: 948652e4f82f5aedbe882178ae158990bde63c79 X-Git-Newrev: 2b23ab1feab5a59bcc1931666663b2a8eac3fdbc Message-Id: <20221129080053.4904E3853D54@sourceware.org> Date: Tue, 29 Nov 2022 08:00:53 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2b23ab1feab5a59bcc1931666663b2a8eac3fdbc commit 2b23ab1feab5a59bcc1931666663b2a8eac3fdbc Author: Xiaolin Tang 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 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 #include #include +#include #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 #include #include - -static const double two52[2] = -{ - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ -}; +#include 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 #include #include - -static const float two23[2] = -{ - 8.3886080000e+06, /* 0x4B000000 */ - -8.3886080000e+06, /* 0xCB000000 */ -}; +#include 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 #include #include +#include -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)