From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7891) id 8A13938532ED; Tue, 29 Nov 2022 08:01:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A13938532ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669708863; bh=m8lq6TTioIi6NjGkeIOGphDocPZjJ1DH2SusLx9a82g=; h=From:To:Subject:Date:From; b=GsKDiSlreuimxqKSx1hPHsXBlbSK86JJ8dO/URt1lX8FVyDosxJoa74p+ciiW3ZWO NVIuuxdr2obZQM5GF64QFHHGydRm6KLg/C+zn+xSOcDNm09U+RQ2IJaPqHC6AIT9F+ +u45OSnTSFQb171upMIOJIj8vIguMjeY5iM1fH3I= 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 llrint functions if desired. X-Act-Checkin: glibc X-Git-Author: Xiaolin Tang X-Git-Refname: refs/heads/master X-Git-Oldrev: e1697a540c49d5bd35e84b22fcd537c14f71a4e9 X-Git-Newrev: a1981ecbfd4aec84dea26936d91c8ed9164f8b13 Message-Id: <20221129080103.8A13938532ED@sourceware.org> Date: Tue, 29 Nov 2022 08:01:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a1981ecbfd4aec84dea26936d91c8ed9164f8b13 commit a1981ecbfd4aec84dea26936d91c8ed9164f8b13 Author: Xiaolin Tang Date: Wed Nov 23 11:44:58 2022 +0800 Use GCC builtins for llrint functions if desired. This patch is using the corresponding GCC builtin for llrintf, llrint, llrintl and llrintf128 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-llrint.h | 4 ++++ sysdeps/generic/math-use-builtins.h | 1 + sysdeps/ieee754/dbl-64/s_llrint.c | 18 ++++++++++++------ sysdeps/ieee754/float128/float128_private.h | 2 ++ sysdeps/ieee754/flt-32/s_llrintf.c | 18 ++++++++++++------ sysdeps/ieee754/ldbl-128/s_llrintl.c | 17 ++++++++++++----- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/sysdeps/generic/math-use-builtins-llrint.h b/sysdeps/generic/math-use-builtins-llrint.h new file mode 100644 index 0000000000..ced6a327a1 --- /dev/null +++ b/sysdeps/generic/math-use-builtins-llrint.h @@ -0,0 +1,4 @@ +#define USE_LLRINT_BUILTIN 0 +#define USE_LLRINTF_BUILTIN 0 +#define USE_LLRINTL_BUILTIN 0 +#define USE_LLRINTF128_BUILTIN 0 diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index 3acec1d538..dddeaa4ea8 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -38,5 +38,6 @@ #include #include #include +#include #endif /* MATH_USE_BUILTINS_H */ diff --git a/sysdeps/ieee754/dbl-64/s_llrint.c b/sysdeps/ieee754/dbl-64/s_llrint.c index dc8d9948df..88c8ec3624 100644 --- a/sysdeps/ieee754/dbl-64/s_llrint.c +++ b/sysdeps/ieee754/dbl-64/s_llrint.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 long int __llrint (double x) { +#if USE_LLRINT_BUILTIN + return __builtin_llrint (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 i1, i0; long long int result; @@ -95,6 +100,7 @@ __llrint (double x) } return sx ? -result : result; +#endif /* ! USE_LLRINT_BUILTIN */ } libm_alias_double (__llrint, llrint) diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h index a452ced89a..3bb5fffa74 100644 --- a/sysdeps/ieee754/float128/float128_private.h +++ b/sysdeps/ieee754/float128/float128_private.h @@ -163,6 +163,8 @@ #define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN #undef USE_LRINTL_BUILTIN #define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN +#undef USE_LLRINTL_BUILTIN +#define USE_LLRINTL_BUILTIN USE_LLRINTF128_BUILTIN /* IEEE function renames. */ #define __ieee754_acoshl __ieee754_acoshf128 diff --git a/sysdeps/ieee754/flt-32/s_llrintf.c b/sysdeps/ieee754/flt-32/s_llrintf.c index 226b8261d3..79e3c385d1 100644 --- a/sysdeps/ieee754/flt-32/s_llrintf.c +++ b/sysdeps/ieee754/flt-32/s_llrintf.c @@ -25,17 +25,22 @@ #include #include #include - -static const float two23[2] = -{ - 8.3886080000e+06, /* 0x4B000000 */ - -8.3886080000e+06, /* 0xCB000000 */ -}; +#include long long int __llrintf (float x) { +#if USE_LLRINTF_BUILTIN + return __builtin_llrintf (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 @@ __llrintf (float x) } return sx ? -result : result; +#endif /* ! USE_LLRINTF_BUILTIN */ } libm_alias_float (__llrint, llrint) diff --git a/sysdeps/ieee754/ldbl-128/s_llrintl.c b/sysdeps/ieee754/ldbl-128/s_llrintl.c index 79d3937cc9..3a5635d509 100644 --- a/sysdeps/ieee754/ldbl-128/s_llrintl.c +++ b/sysdeps/ieee754/ldbl-128/s_llrintl.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 long int __llrintl (_Float128 x) { +#if USE_LLRINTL_BUILTIN + return __builtin_round (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; @@ -102,6 +108,7 @@ __llrintl (_Float128 x) } return sx ? -result : result; +#endif /* ! USE_LLRINTL_BUILTIN */ } libm_alias_ldouble (__llrint, llrint)