From patchwork Tue Oct 22 11:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?546L5Y2a5Z6a?= X-Patchwork-Id: 99318 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 88727385843D for ; Tue, 22 Oct 2024 11:18:48 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 8978F3858D20 for ; Tue, 22 Oct 2024 11:18:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8978F3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bytedance.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8978F3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729595903; cv=none; b=mvT9jpA5ynSh7A8oKIaafiZv8fHT4Ojf2kg9HllsWuqfpyT5Z7moibWIjGEIpwMs2CmPHFU8INKA3gc+zFKz7tUaGK/1LwsTpNaA1noXFrWZeSCLpT4jmmO9AqiZ0v/q/JNsLCNW5/ZlvyZg080koxbf1pc2sxkCROhdB1A+01o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729595903; c=relaxed/simple; bh=NX1Rz2gQrIklf3j0fkODYOw1QAVT7bJpOLm0y93ZbmI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=r0E8Opy54mJyO1+cfUfALvEzGdvOtMXD3SHPjid/+9+JQxXsveM5JPfABUVlZHS53YmKmrCV6T4Vo7/OmijD5Au3m433nGFLMnIZo2CfQ8uOd/W6I7uxXJmbUCuzg9XYp5FXjg9zAk4xMjPsA0URkqZc+qVjSbgXsy+bnzplros= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2e2e2d09decso4545698a91.1 for ; Tue, 22 Oct 2024 04:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729595897; x=1730200697; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Yp4QbHWo4tM3dnABe+/NRDVTvVW7eU31xsitmItJ6I4=; b=a/khCxmBrOhnQcTjlgp9L+MrcWKO9nCTmJ/MTd3tETvto7Gca/+9Tp15XbS75VKktm 6LMHiGemL0Xv4xXJ93wXFPHXeGEZInMnY1fkXCVFoEf/37GXaEuNj3iZEARF5wcxuiFH ZRkfAWAuAKllIaUZuKZJmJjRAS3jvfGr9uKg0bZPSRB+NFV0isSNFCrzMs2Ks+FmJDyi O7O1ocUa24s7n2NzmIuaIoFsfpBMv+V96EpVwVb/8Q/0pfpYRisJ2fNRmr0FMDLZctow zSrt8+GTMcB7mlPsV2ESYa6w1xKb19clBgsTjgCc+wUzs/ZEN/+foE7ZQdecUsrCh88Z rz4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729595897; x=1730200697; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yp4QbHWo4tM3dnABe+/NRDVTvVW7eU31xsitmItJ6I4=; b=knaJej3Ynt6wrr5VfitGIVfCkZLD5sp4cDiZVcK1tr/KAyPDhTchLF1O0uqPCQe0rV rfGpw2AbtOnUU0FJBzR0TnihDnnCEjZBg7elm1mT4XAyfBtWpHu0Z7CUnkjtd9X7Kyph ejswIJTkZ+ZFU/FnpU0GJB2JsVmZIwrK6sJv3tANUYBr0g9Kw3HTnKckYpZ4l84DLSQL 8wJ0lTyq+kl6E4u82WO1ElvE3sDkjdzWXjNqWbAvpcu+5ruIuTKdpkzcVIHmlZUUE6So J/AyV9cGEy7JHCt+n2mcNgitfrhSHbhs9NY99C+NRWm4+9CTMDB8W24iNowm7YMAQkJA 2Fbw== X-Gm-Message-State: AOJu0Yx7n7bZNN9qAyL6EB1ncS8/uboNytcfZ41+NQYuWcC6WhXmaA1w rD57/Ji2NdO0xL/k49SXWMTzIvI5By11vcMaB4g8hkNhDK+XHNqP4DqDcUchHg040qyXnen5B1z P X-Google-Smtp-Source: AGHT+IHZhQk4nqnEnrCTZMC88ZyCSANFy8xT8oLpR+riuHqQFrqe0iIc1og9hIniueoqtAzxfinpEw== X-Received: by 2002:a17:90b:3b4a:b0:2da:8edf:ddc with SMTP id 98e67ed59e1d1-2e5dbab40bemr4048059a91.19.1729595896895; Tue, 22 Oct 2024 04:18:16 -0700 (PDT) Received: from n37-101-252.byted.org ([180.184.84.173]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5ad5106f8sm5818992a91.49.2024.10.22.04.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 04:18:16 -0700 (PDT) From: wangboyao@bytedance.com To: libc-alpha@sourceware.org Cc: wangboyao@bytedance.com Subject: [PATCH v2] RISCV: Add builtin for some riscv version function Date: Tue, 22 Oct 2024 19:18:06 +0800 Message-Id: <20241022111806.1222506-1-wangboyao@bytedance.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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.30 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 From: wangboyao Some functions in glibc, particularly those in the math library, can be more efficient when using the compiler’s built-in functions, especially in cases where certain extensions (Zfa) are supported. Signed-off-by: wangboyao --- sysdeps/riscv/math-use-builtins-ceil.h | 4 ++++ sysdeps/riscv/math-use-builtins-ffs.h | 2 ++ sysdeps/riscv/math-use-builtins-floor.h | 4 ++++ sysdeps/riscv/math-use-builtins-nearbyint.h | 4 ++++ sysdeps/riscv/math-use-builtins-rint.h | 4 ++++ sysdeps/riscv/math-use-builtins-round.h | 4 ++++ sysdeps/riscv/math-use-builtins-roundeven.h | 4 ++++ sysdeps/riscv/math-use-builtins-trunc.h | 4 ++++ sysdeps/riscv/rv64/rvd/s_ceil.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_floor.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_nearbyint.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_rint.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_round.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_roundeven.c | 5 +++++ sysdeps/riscv/rv64/rvd/s_trunc.c | 5 +++++ sysdeps/riscv/rvf/s_ceilf.c | 5 +++++ sysdeps/riscv/rvf/s_floorf.c | 5 +++++ sysdeps/riscv/rvf/s_nearbyintf.c | 5 +++++ sysdeps/riscv/rvf/s_rintf.c | 5 +++++ sysdeps/riscv/rvf/s_roundevenf.c | 5 +++++ sysdeps/riscv/rvf/s_roundf.c | 5 +++++ sysdeps/riscv/rvf/s_truncf.c | 5 +++++ 22 files changed, 100 insertions(+) create mode 100644 sysdeps/riscv/math-use-builtins-ceil.h create mode 100644 sysdeps/riscv/math-use-builtins-ffs.h create mode 100644 sysdeps/riscv/math-use-builtins-floor.h create mode 100644 sysdeps/riscv/math-use-builtins-nearbyint.h create mode 100644 sysdeps/riscv/math-use-builtins-rint.h create mode 100644 sysdeps/riscv/math-use-builtins-round.h create mode 100644 sysdeps/riscv/math-use-builtins-roundeven.h create mode 100644 sysdeps/riscv/math-use-builtins-trunc.h diff --git a/sysdeps/riscv/math-use-builtins-ceil.h b/sysdeps/riscv/math-use-builtins-ceil.h new file mode 100644 index 0000000000..17d6452e51 --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-ceil.h @@ -0,0 +1,4 @@ +#define USE_CEIL_BUILTIN 1 +#define USE_CEILF_BUILTIN 1 +#define USE_CEILL_BUILTIN 0 +#define USE_CEILF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-ffs.h b/sysdeps/riscv/math-use-builtins-ffs.h new file mode 100644 index 0000000000..a83bb15414 --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-ffs.h @@ -0,0 +1,2 @@ +#define USE_FFS_BUILTIN 1 +#define USE_FFSLL_BUILTIN 1 diff --git a/sysdeps/riscv/math-use-builtins-floor.h b/sysdeps/riscv/math-use-builtins-floor.h new file mode 100644 index 0000000000..553c0674af --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-floor.h @@ -0,0 +1,4 @@ +#define USE_FLOOR_BUILTIN 1 +#define USE_FLOORF_BUILTIN 1 +#define USE_FLOORL_BUILTIN 0 +#define USE_FLOORF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-nearbyint.h b/sysdeps/riscv/math-use-builtins-nearbyint.h new file mode 100644 index 0000000000..a2590c920f --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-nearbyint.h @@ -0,0 +1,4 @@ +#define USE_NEARBYINT_BUILTIN 1 +#define USE_NEARBYINTF_BUILTIN 1 +#define USE_NEARBYINTL_BUILTIN 0 +#define USE_NEARBYINTF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-rint.h b/sysdeps/riscv/math-use-builtins-rint.h new file mode 100644 index 0000000000..45c3307692 --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-rint.h @@ -0,0 +1,4 @@ +#define USE_RINT_BUILTIN 1 +#define USE_RINTF_BUILTIN 1 +#define USE_RINTL_BUILTIN 0 +#define USE_RINTF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-round.h b/sysdeps/riscv/math-use-builtins-round.h new file mode 100644 index 0000000000..f6083d7d0a --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-round.h @@ -0,0 +1,4 @@ +#define USE_ROUND_BUILTIN 1 +#define USE_ROUNDF_BUILTIN 1 +#define USE_ROUNDL_BUILTIN 0 +#define USE_ROUNDF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-roundeven.h b/sysdeps/riscv/math-use-builtins-roundeven.h new file mode 100644 index 0000000000..b7f51730d6 --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-roundeven.h @@ -0,0 +1,4 @@ +#define USE_ROUNDEVEN_BUILTIN 1 +#define USE_ROUNDEVENF_BUILTIN 1 +#define USE_ROUNDEVENL_BUILTIN 0 +#define USE_ROUNDEVENF128_BUILTIN 0 diff --git a/sysdeps/riscv/math-use-builtins-trunc.h b/sysdeps/riscv/math-use-builtins-trunc.h new file mode 100644 index 0000000000..4fc6da42b6 --- /dev/null +++ b/sysdeps/riscv/math-use-builtins-trunc.h @@ -0,0 +1,4 @@ +#define USE_TRUNC_BUILTIN 1 +#define USE_TRUNCF_BUILTIN 1 +#define USE_TRUNCL_BUILTIN 0 +#define USE_TRUNCF128_BUILTIN 0 diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c b/sysdeps/riscv/rv64/rvd/s_ceil.c index dfa853f7fc..8651739959 100644 --- a/sysdeps/riscv/rv64/rvd/s_ceil.c +++ b/sysdeps/riscv/rv64/rvd/s_ceil.c @@ -21,10 +21,14 @@ #include #include #include +#include double __ceil (double x) { +#if USE_CEIL_BUILTIN + return __builtin_ceil (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -48,6 +52,7 @@ __ceil (double x) } return x; +#endif /* ! USE_CEIL_BUILTIN */ } libm_alias_double (__ceil, ceil) diff --git a/sysdeps/riscv/rv64/rvd/s_floor.c b/sysdeps/riscv/rv64/rvd/s_floor.c index f294651147..957d4792ff 100644 --- a/sysdeps/riscv/rv64/rvd/s_floor.c +++ b/sysdeps/riscv/rv64/rvd/s_floor.c @@ -21,10 +21,14 @@ #include #include #include +#include double __floor (double x) { +#if USE_FLOOR_BUILTIN + return __builtin_floor (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -48,6 +52,7 @@ __floor (double x) } return x; +#endif /* ! USE_FLOOR_BUILTIN */ } libm_alias_double (__floor, floor) diff --git a/sysdeps/riscv/rv64/rvd/s_nearbyint.c b/sysdeps/riscv/rv64/rvd/s_nearbyint.c index ddc512d460..b55d3d0f2f 100644 --- a/sysdeps/riscv/rv64/rvd/s_nearbyint.c +++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c @@ -20,10 +20,14 @@ #include #include #include +#include double __nearbyint (double x) { +#if USE_NEARBYINT_BUILTIN + return __builtin_nearbyint (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -47,6 +51,7 @@ __nearbyint (double x) } return x; +#endif /* ! USE_NEARBYINT_BUILTIN */ } libm_alias_double (__nearbyint, nearbyint) diff --git a/sysdeps/riscv/rv64/rvd/s_rint.c b/sysdeps/riscv/rv64/rvd/s_rint.c index 45bea32671..7c4d23f32c 100644 --- a/sysdeps/riscv/rv64/rvd/s_rint.c +++ b/sysdeps/riscv/rv64/rvd/s_rint.c @@ -21,10 +21,14 @@ #include #include #include +#include double __rint (double x) { +#if USE_RINT_BUILTIN + return __builtin_rint (x); +#else bool nan; double mag; @@ -48,6 +52,7 @@ __rint (double x) } return x; +#endif /* ! USE_RINT_BUILTIN */ } libm_alias_double (__rint, rint) diff --git a/sysdeps/riscv/rv64/rvd/s_round.c b/sysdeps/riscv/rv64/rvd/s_round.c index bd01fcc8c9..0964f94de6 100644 --- a/sysdeps/riscv/rv64/rvd/s_round.c +++ b/sysdeps/riscv/rv64/rvd/s_round.c @@ -21,10 +21,14 @@ #include #include #include +#include double __round (double x) { +#if USE_ROUND_BUILTIN + return __builtin_round (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -48,6 +52,7 @@ __round (double x) } return x; +#endif /* ! USE_ROUND_BUILTIN */ } libm_alias_double (__round, round) diff --git a/sysdeps/riscv/rv64/rvd/s_roundeven.c b/sysdeps/riscv/rv64/rvd/s_roundeven.c index 108c7dc970..ea888d7555 100644 --- a/sysdeps/riscv/rv64/rvd/s_roundeven.c +++ b/sysdeps/riscv/rv64/rvd/s_roundeven.c @@ -21,10 +21,14 @@ #include #include #include +#include double __roundeven (double x) { +#if USE_ROUNDEVEN_BUILTIN + return __builtin_roundeven (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -48,6 +52,7 @@ __roundeven (double x) } return x; +#endif /* ! USE_ROUNDEVEN_BUILTIN */ } libm_alias_double (__roundeven, roundeven) diff --git a/sysdeps/riscv/rv64/rvd/s_trunc.c b/sysdeps/riscv/rv64/rvd/s_trunc.c index 779c7d26b3..82c6196ef0 100644 --- a/sysdeps/riscv/rv64/rvd/s_trunc.c +++ b/sysdeps/riscv/rv64/rvd/s_trunc.c @@ -21,10 +21,14 @@ #include #include #include +#include double __trunc (double x) { + #if USE_TRUNC_BUILTIN + return __builtin_trunc (x); + #else int flags = riscv_getflags (); bool nan = isnan (x); double mag = fabs (x); @@ -48,6 +52,7 @@ __trunc (double x) } return x; + #endif /* ! USE_TRUNC_BUILTIN */ } libm_alias_double (__trunc, trunc) diff --git a/sysdeps/riscv/rvf/s_ceilf.c b/sysdeps/riscv/rvf/s_ceilf.c index d19f17e16b..ab49a8dfbd 100644 --- a/sysdeps/riscv/rvf/s_ceilf.c +++ b/sysdeps/riscv/rvf/s_ceilf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __ceilf (float x) { +#if USE_CEILF_BUILTIN + return __builtin_ceilf (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -48,6 +52,7 @@ __ceilf (float x) } return x; +#endif /* ! USE_CEILF_BUILTIN */ } libm_alias_float (__ceil, ceil) diff --git a/sysdeps/riscv/rvf/s_floorf.c b/sysdeps/riscv/rvf/s_floorf.c index efe104c7e0..daf708fe56 100644 --- a/sysdeps/riscv/rvf/s_floorf.c +++ b/sysdeps/riscv/rvf/s_floorf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __floorf (float x) { +#if USE_FLOORF_BUILTIN + return __builtin_floorf (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -48,6 +52,7 @@ __floorf (float x) } return x; +#endif /* ! USE_FLOORF_BUILTIN */ } libm_alias_float (__floor, floor) diff --git a/sysdeps/riscv/rvf/s_nearbyintf.c b/sysdeps/riscv/rvf/s_nearbyintf.c index 4abaaa2551..487ca659da 100644 --- a/sysdeps/riscv/rvf/s_nearbyintf.c +++ b/sysdeps/riscv/rvf/s_nearbyintf.c @@ -20,10 +20,14 @@ #include #include #include +#include float __nearbyintf (float x) { +#if USE_NEARBYINTF_BUILTIN + return __builtin_nearbyintf (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -47,6 +51,7 @@ __nearbyintf (float x) } return x; +#endif /* ! USE_NEARBYINT_BUILTIN */ } libm_alias_float (__nearbyint, nearbyint) diff --git a/sysdeps/riscv/rvf/s_rintf.c b/sysdeps/riscv/rvf/s_rintf.c index f70d1b3db3..a82629a015 100644 --- a/sysdeps/riscv/rvf/s_rintf.c +++ b/sysdeps/riscv/rvf/s_rintf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __rintf (float x) { +#if USE_RINTF_BUILTIN + return __builtin_rintf (x); +#else bool nan; float mag; @@ -48,6 +52,7 @@ __rintf (float x) } return x; +#endif /* ! USE_RINTF_BUILTIN */ } libm_alias_float (__rint, rint) diff --git a/sysdeps/riscv/rvf/s_roundevenf.c b/sysdeps/riscv/rvf/s_roundevenf.c index 99018c050e..813d11f92d 100644 --- a/sysdeps/riscv/rvf/s_roundevenf.c +++ b/sysdeps/riscv/rvf/s_roundevenf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __roundevenf (float x) { +#if USE_ROUNDEVENF_BUILTIN + return __builtin_roundevenf (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -48,6 +52,7 @@ __roundevenf (float x) } return x; +#endif /* ! USE_ROUNDEVENF_BUILTIN */ } libm_alias_float (__roundeven, roundeven) diff --git a/sysdeps/riscv/rvf/s_roundf.c b/sysdeps/riscv/rvf/s_roundf.c index 735e7e9de9..db299e0a41 100644 --- a/sysdeps/riscv/rvf/s_roundf.c +++ b/sysdeps/riscv/rvf/s_roundf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __roundf (float x) { +#if USE_ROUNDF_BUILTIN + return __builtin_roundf (x); +#else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -48,6 +52,7 @@ __roundf (float x) } return x; +#endif /* ! USE_ROUNDF_BUILTIN */ } libm_alias_float (__round, round) diff --git a/sysdeps/riscv/rvf/s_truncf.c b/sysdeps/riscv/rvf/s_truncf.c index 0774f7cbd6..e2d99b20a8 100644 --- a/sysdeps/riscv/rvf/s_truncf.c +++ b/sysdeps/riscv/rvf/s_truncf.c @@ -21,10 +21,14 @@ #include #include #include +#include float __truncf (float x) { + #if USE_TRUNCF_BUILTIN + return __builtin_truncf (x); + #else int flags = riscv_getflags (); bool nan = isnan (x); float mag = fabsf (x); @@ -48,6 +52,7 @@ __truncf (float x) } return x; + #endif /* ! USE_TRUNCF_BUILTIN */ } libm_alias_float (__trunc, trunc)