From patchwork Wed Nov 23 03:45:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 61009 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 6E841384F034 for ; Wed, 23 Nov 2022 03:46:02 +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 54FE73853D4B for ; Wed, 23 Nov 2022 03:45:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54FE73853D4B 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 _____8DxvutGl31jsygAAA--.485S3; Wed, 23 Nov 2022 11:45:10 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxTuBCl31jzH8YAA--.63991S8; Wed, 23 Nov 2022 11:45:09 +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 v2 06/10] Use GCC builtins for logb functions if desired. Date: Wed, 23 Nov 2022 11:45:00 +0800 Message-Id: <20221123034504.1249579-7-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221123034504.1249579-1-tangxiaolin@loongson.cn> References: <20221123034504.1249579-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxTuBCl31jzH8YAA--.63991S8 X-CM-SenderInfo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_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 logbf, logb, logbl and logbf128 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-logb.h | 4 ++++ sysdeps/generic/math-use-builtins.h | 1 + sysdeps/ieee754/dbl-64/s_logb.c | 5 +++++ sysdeps/ieee754/float128/float128_private.h | 2 ++ sysdeps/ieee754/flt-32/s_logbf.c | 5 +++++ sysdeps/ieee754/ldbl-128/s_logbl.c | 6 ++++++ 6 files changed, 23 insertions(+) create mode 100644 sysdeps/generic/math-use-builtins-logb.h diff --git a/sysdeps/generic/math-use-builtins-logb.h b/sysdeps/generic/math-use-builtins-logb.h new file mode 100644 index 0000000000..e816a7e0a1 --- /dev/null +++ b/sysdeps/generic/math-use-builtins-logb.h @@ -0,0 +1,4 @@ +#define USE_LOGB_BUILTIN 0 +#define USE_LOGBF_BUILTIN 0 +#define USE_LOGBL_BUILTIN 0 +#define USE_LOGBF128_BUILTIN 0 diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index dddeaa4ea8..c59612a878 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -39,5 +39,6 @@ #include #include #include +#include #endif /* MATH_USE_BUILTINS_H */ diff --git a/sysdeps/ieee754/dbl-64/s_logb.c b/sysdeps/ieee754/dbl-64/s_logb.c index 82cabd206a..dd74d5f08c 100644 --- a/sysdeps/ieee754/dbl-64/s_logb.c +++ b/sysdeps/ieee754/dbl-64/s_logb.c @@ -21,10 +21,14 @@ #include #include #include +#include double __logb (double x) { +#if USE_LOGB_BUILTIN + return __builtin_logb (x); +#else int64_t ix, ex; EXTRACT_WORDS64 (ix, x); @@ -42,6 +46,7 @@ __logb (double x) if (FIX_INT_FP_CONVERT_ZERO && ex == 1023) return 0.0; return (double) (ex - 1023); +#endif /* !USE_LOGB_BUILTIN */ } #ifndef __logb libm_alias_double (__logb, logb) diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h index 3bb5fffa74..78107b1525 100644 --- a/sysdeps/ieee754/float128/float128_private.h +++ b/sysdeps/ieee754/float128/float128_private.h @@ -165,6 +165,8 @@ #define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN #undef USE_LLRINTL_BUILTIN #define USE_LLRINTL_BUILTIN USE_LLRINTF128_BUILTIN +#undef USE_LOGBL_BUILTIN +#define USE_LOGBL_BUILTIN USE_LOGBF128_BUILTIN /* IEEE function renames. */ #define __ieee754_acoshl __ieee754_acoshf128 diff --git a/sysdeps/ieee754/flt-32/s_logbf.c b/sysdeps/ieee754/flt-32/s_logbf.c index a06f975797..b027e7b9c2 100644 --- a/sysdeps/ieee754/flt-32/s_logbf.c +++ b/sysdeps/ieee754/flt-32/s_logbf.c @@ -16,10 +16,14 @@ #include #include #include +#include float __logbf (float x) { +#if USE_LOGBF_BUILTIN + return __builtin_logbf (x); +#else int32_t ix, rix; GET_FLOAT_WORD (ix, x); @@ -37,5 +41,6 @@ __logbf (float x) if (FIX_INT_FP_CONVERT_ZERO && rix == 127) return 0.0f; return (float) (rix - 127); +#endif /* ! USE_LOGBF_BUILTIN */ } libm_alias_float (__logb, logb) diff --git a/sysdeps/ieee754/ldbl-128/s_logbl.c b/sysdeps/ieee754/ldbl-128/s_logbl.c index 1c56eda499..59b08aa295 100644 --- a/sysdeps/ieee754/ldbl-128/s_logbl.c +++ b/sysdeps/ieee754/ldbl-128/s_logbl.c @@ -25,10 +25,15 @@ static char rcsid[] = "$NetBSD: $"; #include #include #include +#include _Float128 __logbl (_Float128 x) { +#if USE_LOGBL_BUILTIN + return __builtin_logbl (x); +#else + /* Use generic implementation. */ int64_t lx, hx, ex; GET_LDOUBLE_WORDS64 (hx, lx, x); @@ -49,6 +54,7 @@ __logbl (_Float128 x) ex -= ma - 16; } return (_Float128) (ex - 16383); +#endif /* ! USE_LOGBL_BUILTIN */ } libm_alias_ldouble (__logb, logb)