From patchwork Fri Nov 18 11:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60822 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67FCA383F2D2 for ; Fri, 18 Nov 2022 11:29:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 3280B384F488 for ; Fri, 18 Nov 2022 11:29:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3280B384F488 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.5]) by gateway (Coremail) with SMTP id _____8BxGdiNbHdjFpoIAA--.22805S3; Fri, 18 Nov 2022 19:29:17 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxXuCJbHdjdn4WAA--.58440S6; Fri, 18 Nov 2022 19:29:17 +0800 (CST) From: Xiaolin Tang To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, caiyinyu@loongson.cn, xry111@xry111.site Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, Xiaolin Tang Subject: [PATCH 4/9] Use GCC builtins for llrint functions if desired. Date: Fri, 18 Nov 2022 19:29:07 +0800 Message-Id: <20221118112912.2501774-5-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221118112912.2501774-1-tangxiaolin@loongson.cn> References: <20221118112912.2501774-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxXuCJbHdjdn4WAA--.58440S6 X-CM-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wI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jOdb8UUUUU= X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 --- 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(-) create mode 100644 sysdeps/generic/math-use-builtins-llrint.h 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)