From patchwork Thu Mar 13 17:29:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil K Pandey X-Patchwork-Id: 107843 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 3461E3857C6C for ; Thu, 13 Mar 2025 17:29:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3461E3857C6C X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by sourceware.org (Postfix) with ESMTPS id 8F0563857C6C for ; Thu, 13 Mar 2025 17:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F0563857C6C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F0563857C6C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741886943; cv=none; b=D8b/cr9GsiwdiXh/OSHcTuM0M6K0DpU7FaBI16h9oKmFMpUikv1GjktXps91qmVAY1FWvApPN4P3b1jclqEcZpn4ZuQOvfLBdefu0SDPMCXddYKMTvICt5Vc0YQwF8slNXfO7hmawYdntbKvSvFhbt0aUJ4LfByx68EHrEZj6U0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741886943; c=relaxed/simple; bh=/rRCwDxgSZ/qHadbuqrPpsbhVwgFmYaWvm47E/+CXAM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LC/N4ZHGZ6Hkzx/QrQtV/I9lPHMmkWGwuBbVpto3ncbnU56iaZ4DOJ93rM+KxbD6UowclEP6bWB8vbmA7yAnNXBPQbSpdOsfI65x7TFff5kN0CdEdsf/j0/HRGEGfrt5au7hCMkIXv98qpHD6w3OziAsZE8GMH7LCKw4UGJzPcA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F0563857C6C X-CSE-ConnectionGUID: zayEhhpGRGeBUgSDVLn43Q== X-CSE-MsgGUID: LbUE0WNuRoGbGMmu46zU6w== X-IronPort-AV: E=McAfee;i="6700,10204,11372"; a="46807076" X-IronPort-AV: E=Sophos;i="6.14,245,1736841600"; d="scan'208";a="46807076" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2025 10:29:02 -0700 X-CSE-ConnectionGUID: Z67lJfPQT7q1MHlq/BXwnA== X-CSE-MsgGUID: ks1JCdnARhKM7g6llTLB7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,245,1736841600"; d="scan'208";a="158166572" Received: from scymds03.sc.intel.com ([10.148.94.166]) by orviesa001.jf.intel.com with ESMTP; 13 Mar 2025 10:29:02 -0700 Received: from gskx-1.sc.intel.com (gskx-1.sc.intel.com [172.25.149.211]) by scymds03.sc.intel.com (Postfix) with ESMTP id 6199C2E8 for ; Thu, 13 Mar 2025 10:29:02 -0700 (PDT) From: Sunil K Pandey To: libc-alpha@sourceware.org Subject: [PATCH v3] x86_64: Add sinh with FMA Date: Thu, 13 Mar 2025 10:29:02 -0700 Message-ID: <20250313172902.895272-1-skpgkp2@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <06693fda-ac6e-43b1-bd2d-00ca7f31888b@linaro.org> References: <06693fda-ac6e-43b1-bd2d-00ca7f31888b@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, LOCAL_AUTHENTICATION_FAIL_DMARC, LOCAL_AUTHENTICATION_FAIL_SPF, NML_ADSP_CUSTOM_MED, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=no 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 On SPR, it improves sinh bench performance by: Before After Improvement reciprocal-throughput 14.2017 11.815 17% latency 36.4917 35.2114 4% Reviewed-by: H.J. Lu --- benchtests/sinh-inputs | 1 + sysdeps/ieee754/dbl-64/e_sinh.c | 8 ++++++ sysdeps/x86_64/fpu/multiarch/Makefile | 2 ++ sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c | 12 ++++++++ sysdeps/x86_64/fpu/multiarch/e_sinh.c | 35 +++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh.c diff --git a/benchtests/sinh-inputs b/benchtests/sinh-inputs index 7b1ac46a39..2fcb2fabf8 100644 --- a/benchtests/sinh-inputs +++ b/benchtests/sinh-inputs @@ -1,6 +1,7 @@ ## args: double ## ret: double ## includes: math.h +## name: workload-random 0x1.bcb6129b5ff2bp8 -0x1.63057386325ebp9 0x1.62f1d7dc4e8bfp9 diff --git a/sysdeps/ieee754/dbl-64/e_sinh.c b/sysdeps/ieee754/dbl-64/e_sinh.c index b4b5857ddd..3f787967f9 100644 --- a/sysdeps/ieee754/dbl-64/e_sinh.c +++ b/sysdeps/ieee754/dbl-64/e_sinh.c @@ -41,6 +41,11 @@ static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $"; static const double one = 1.0, shuge = 1.0e307; +#ifndef SECTION +# define SECTION +#endif + +SECTION double __ieee754_sinh (double x) { @@ -90,4 +95,7 @@ __ieee754_sinh (double x) /* |x| > overflowthresold, sinh(x) overflow */ return math_narrow_eval (x * shuge); } + +#ifndef __ieee754_sinh libm_alias_finite (__ieee754_sinh, __sinh) +#endif diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile index a198315f1c..61ff78efa3 100644 --- a/sysdeps/x86_64/fpu/multiarch/Makefile +++ b/sysdeps/x86_64/fpu/multiarch/Makefile @@ -5,6 +5,7 @@ CFLAGS-e_exp-fma.c = -mfma -mavx2 CFLAGS-e_log-fma.c = -mfma -mavx2 CFLAGS-e_log2-fma.c = -mfma -mavx2 CFLAGS-e_pow-fma.c = -mfma -mavx2 +CFLAGS-e_sinh-fma.c = -mfma -mavx2 CFLAGS-s_atan-fma.c = -mfma -mavx2 CFLAGS-s_expm1-fma.c = -mfma -mavx2 CFLAGS-s_log1p-fma.c = -mfma -mavx2 @@ -69,6 +70,7 @@ libm-sysdep_routines += \ e_logf-fma \ e_pow-fma \ e_powf-fma \ + e_sinh-fma \ s_atan-avx \ s_atan-fma \ s_ceil-sse4_1 \ diff --git a/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c b/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c new file mode 100644 index 0000000000..e0e1e39a7a --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c @@ -0,0 +1,12 @@ +#define __ieee754_sinh __ieee754_sinh_fma +#define __ieee754_exp __ieee754_exp_fma +#define __expm1 __expm1_fma + +/* NB: __expm1 may be expanded to __expm1_fma in the following + prototypes. */ +extern long double __expm1l (long double); +extern long double __expm1f128 (long double); + +#define SECTION __attribute__ ((section (".text.fma"))) + +#include diff --git a/sysdeps/x86_64/fpu/multiarch/e_sinh.c b/sysdeps/x86_64/fpu/multiarch/e_sinh.c new file mode 100644 index 0000000000..3d3c18ccdf --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/e_sinh.c @@ -0,0 +1,35 @@ +/* Multiple versions of sinh. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#if MINIMUM_X86_ISA_LEVEL < AVX2_X86_ISA_LEVEL +# include + +extern double __redirect_ieee754_sinh (double); + +# define SYMBOL_NAME ieee754_sinh +# include "ifunc-fma.h" + +libc_ifunc_redirected (__redirect_ieee754_sinh, __ieee754_sinh, + IFUNC_SELECTOR ()); + +libm_alias_finite (__ieee754_sinh, __sinh) + +# define __ieee754_sinh __ieee754_sinh_sse2 +#endif +#include