From patchwork Wed Dec 4 16:37:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 847313 Delivered-To: patch@linaro.org Received: by 2002:a5d:434d:0:b0:385:e875:8a9e with SMTP id u13csp434412wrr; Wed, 4 Dec 2024 09:04:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0hPgvkudd9QvgL8b7959NFjsrAb3fkctHwsfNdH6OjnjwoRq8GjGcKqt9iAjfZs7Dg+bsog==@linaro.org X-Google-Smtp-Source: AGHT+IG+ZjkNPOrVhMy9etR1lYwF6W5DdKBb5ty1Bvyankb0vCNrgo96/c+yRpLmrercCacekFZd X-Received: by 2002:a05:6214:d84:b0:6d4:1b2b:c82b with SMTP id 6a1803df08f44-6d8b73ec502mr116814996d6.38.1733331884982; Wed, 04 Dec 2024 09:04:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733331884; cv=pass; d=google.com; s=arc-20240605; b=iOIpSZ+9Oj/Qc+Vrn9J7yseTIYpqr86eSz7w02fuzEqn6Vx97a01gqmgIR+ER8x74n COXhDLpOj/K02b/D3GoLkv7vjMyRPWMY++bwVE50Hihp2i0c64Z2LmQn3axudC0kh2LO j2uMBiv3tssXkPutE/eQv1j6Ttrv/5hmGiICktVGos2C6tvgeV8bY9mKRz735KfV/p3Q aVE3ioWAAe8ic1p/X5eIs2siW+G21DxBTU9EfHqyevfLng6tvKbPB5XKjJOwj4dsjjnw e0oJ3rnZYlcglQ5ybgjyShlfkJvPoNbIMSt36gI4qlGSBJNBN2wdIw7aMG2McsAcxqJN NQlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to :dkim-filter; bh=i+7jBswUt+cCTIA8bTOPh+FIM+tkAcBYaSH1AEZNlA4=; fh=4rGS/xMpTpKARYPd8/6tK882DGKOrg862WI4oHDxNB4=; b=TnvFaa9WfhnZahojxk9JO3/95mtQOEE1rp4nsdFT9ufDuVjoWfcR84y1xNBrWRlae1 kEC422xwDUgUAm8jesaEjSfaYLM3XGpmlH+e5kT5WQwvnUv6w17iGDzxPQs9IqmluiGi ZTkULpk8QGl0o2Ug8QJ1S7UsWjHv9jTAcrhSRCEksJ2xWHgE/krksnD1JFGvI/wNi/qY 2IYiZgGCwQV9ArHJl5FssWFkdZi5CqLG/iVwq2zMzaDlZUsgyH4bTZufRn0zQC3tNiqt 5FEL199W3UJLL9rhevPH9pSn4eZVwjXKeRiAYGdveHnVNl5Dcf9gPbwbSqRUSZ07nIv1 VZVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DG6346Lm; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 6a1803df08f44-6d882e0ec19si144936216d6.481.2024.12.04.09.04.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 09:04:44 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DG6346Lm; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8909A3858D35 for ; Wed, 4 Dec 2024 17:04:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8909A3858D35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=DG6346Lm X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id B4D2F385841F for ; Wed, 4 Dec 2024 16:41:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4D2F385841F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4D2F385841F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330479; cv=none; b=j8hDcnn5dcr92rQQ6GlkwGOTa74Labe7/xdAtjzecGW5uSb7eFDSV0z2zB4/L+yxDX7PD1YuKVXY4Vi8Mr5Fw0DhzAhmV6Ut+lSLebSq5+aDlHnJ4Ez6HM3c3kHCQ6D9M7Fcn0JA/8j6rA4n3ij7hiYFH0rYYR6tVoRaAyQ0cDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330479; c=relaxed/simple; bh=hWOO9Kt0KDYzU1DXIj/s9r1M/XexlM92QSLJv7sqi1Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Qfed9GmIhjtP1ELjo3qpJxYjQ45GhBNVAdsOgN0I5FqM3lJfz76Eu4l1wRoYQpro2e4d1YDIEqLqBN62Otr6DGWkDyJ7fl/CUMasDRpIQIYWCzT+lC4n6TmvWu695sZMZuqxk+K6bpwH807A3aW6TdjY6TT4ZrfjTh9lFdzajO0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-215853ed047so42338655ad.2 for ; Wed, 04 Dec 2024 08:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733330448; x=1733935248; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i+7jBswUt+cCTIA8bTOPh+FIM+tkAcBYaSH1AEZNlA4=; b=DG6346Lms9CIZihCJk+OddAgSbBkZeBvmzkCtZyQr8Nnx2V+C5puWghpo7zDyxaOLQ i6Wy4NVWs3SxHJRFQy4wtXNAdyOONsqooL91+iC9xQkMU0R+7RySxFIn+b8E3lwhDPt8 m6+lAQjN8PdCRcpaeBx/RF3muM3E8fL4O4KLLHm5yxPg2RIKqYf/AlwNs3UXJuc/khss IZD6TNBauGIUSWfNosjXMJkRdraWJtWUAzLimRpNrOr6n7OaAbyw8c0GOUOJNWBVZZVW OAlj1ro+JnPD0IwbYkLdLJvYlKMrZQWySWm1rlxe0zwGnwQgZkSO6Z+3wT7KfwBC0riJ rihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330448; x=1733935248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i+7jBswUt+cCTIA8bTOPh+FIM+tkAcBYaSH1AEZNlA4=; b=JUL+mw3u/Km2EtkUf5c19z4OEOWIfgrq8ZPl+30nkvPfzmpVd6xHfg8YFoHcaA49c4 uX9q/CzCEbfpDLRZziO+meDGhY0zq/nwfuIF/oCXRoBfWY2t42QkPk1YnGrk8L433D3E I7ss06rD3CcL0cIzqrLRxPzxq7d8aqUGQzG+Zd7JPISOVMPHuDVNWFapVO6pcmr9oJhm l64u2FB8bhw1U/pQAdis6OT9nAL91zHbHGD4uxDsN3WjVui97v07lLm7gyXsNvE6FKe+ 87mJdAXHvr/lkCmUZ/wdtDBBQBlwHVJefbO169xmD/kyg5dVhLgFvXrfFS2FIdvPPs1P oyzA== X-Gm-Message-State: AOJu0YzdeD7YdEwTl1cNfXrif+4PP3X2hJWoQ7P8BoSZ70MULvYF/29o TeYkoQFQZm0XExBWq4I30PPAiT4jns6wfDpugiXhJqYMxhdgornrc6hgTAf0OhK8lDz+8hMQxhS s X-Gm-Gg: ASbGncvn+Xbg0WXX774Ay2Z5hJk3KByTbrm+hg/+BW4gp+ht8tNsIsM78gc4pYZGxMz i17B9rvuiK8QUDGWsbtY9mmlkKwiFx9PX1Mo8xStc938lyd0iLvCEUPUB81B/T2AjJ2O3w8kqq0 4Eqwr67fN0u8qbyUj2PQQ78w11WtmjzDT3qqJOXDO9L1/ouA5asZnEfGW9NlyR3uPfRjmamU1Nu fCf4981GHgDD1Qe3m8xguTDRwWBCR2OnJKsV6+NNY62wfY7kR4intuW51bDPA== X-Received: by 2002:a17:902:cec7:b0:215:3661:747e with SMTP id d9443c01a7336-215bcfc5c76mr72316865ad.8.1733330448203; Wed, 04 Dec 2024 08:40:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:2d1:40a3:b587:af7c:a5cd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521967714sm114029225ad.140.2024.12.04.08.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:47 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Joseph Myers , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH v2 24/25] math: Use sinhf from CORE-MATH Date: Wed, 4 Dec 2024 13:37:59 -0300 Message-ID: <20241204163949.1408676-25-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204163949.1408676-1-adhemerval.zanella@linaro.org> References: <20241204163949.1408676-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 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~patch=linaro.org@sourceware.org The CORE-MATH implementation is correctly rounded (for any rounding mode) and shows slight better performance to the generic sinhf. The code was adapted to glibc style and to use the definition of math_config.h (to handle errno, overflow, and underflow). Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1, gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1): Latency master patched improvement x86_64 52.6819 49.1489 6.71% x86_64v2 49.1162 42.9447 12.57% x86_64v3 46.9732 39.9157 15.02% i686 141.1470 129.6410 8.15% aarch64 (Neoverse) 20.8539 17.1288 17.86% power10 14.5258 9.1906 36.73% reciprocal-throughput master patched improvement x86_64 27.5553 23.9395 13.12% x86_64v2 21.6423 20.3219 6.10% x86_64v3 21.4842 16.0224 25.42% i686 87.9709 86.1626 2.06% aarch64 (Neoverse) 15.1919 12.2744 19.20% power10 7.2188 5.2611 27.12% Signed-off-by: Alexei Sibidanov Signed-off-by: Paul Zimmermann Signed-off-by: Adhemerval Zanella --- SHARED-FILES | 4 + sysdeps/aarch64/libm-test-ulps | 4 - sysdeps/alpha/fpu/libm-test-ulps | 4 - sysdeps/arc/fpu/libm-test-ulps | 4 - sysdeps/arc/nofpu/libm-test-ulps | 1 - sysdeps/arm/libm-test-ulps | 4 - sysdeps/csky/fpu/libm-test-ulps | 4 - sysdeps/csky/nofpu/libm-test-ulps | 4 - sysdeps/hppa/fpu/libm-test-ulps | 4 - sysdeps/i386/fpu/libm-test-ulps | 4 - .../i386/i686/fpu/multiarch/libm-test-ulps | 4 - sysdeps/ieee754/flt-32/e_sinhf.c | 171 ++++++++++++------ sysdeps/loongarch/lp64/libm-test-ulps | 4 - sysdeps/microblaze/libm-test-ulps | 1 - sysdeps/mips/mips32/libm-test-ulps | 4 - sysdeps/mips/mips64/libm-test-ulps | 4 - sysdeps/or1k/fpu/libm-test-ulps | 4 - sysdeps/or1k/nofpu/libm-test-ulps | 4 - sysdeps/powerpc/fpu/libm-test-ulps | 4 - sysdeps/powerpc/nofpu/libm-test-ulps | 4 - sysdeps/riscv/nofpu/libm-test-ulps | 4 - sysdeps/riscv/rvd/libm-test-ulps | 4 - sysdeps/s390/fpu/libm-test-ulps | 4 - sysdeps/sh/libm-test-ulps | 2 - sysdeps/sparc/fpu/libm-test-ulps | 4 - sysdeps/x86_64/fpu/libm-test-ulps | 4 - 26 files changed, 124 insertions(+), 139 deletions(-) diff --git a/SHARED-FILES b/SHARED-FILES index 320e0b3be9..3bd4e7fb4a 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -326,3 +326,7 @@ sysdeps/ieee754/flt-32/e_coshf.c: (src/binary32/cosh/coshf.c in CORE-MATH) - the code was adapted to use glibc code style and internal functions to handle errno, overflow, and underflow. +sysdeps/ieee754/flt-32/e_sinhf.c: + (src/binary32/sinh/sinhf.c in CORE-MATH) + - the code was adapted to use glibc code style and internal + functions to handle errno, overflow, and underflow. diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps index 3800832125..0044e8e42a 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -1498,7 +1498,6 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_advsimd": @@ -1507,7 +1506,6 @@ float: 1 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_sve": @@ -1516,12 +1514,10 @@ float: 1 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index 5eeb6ae3b3..7d5fcc7f2e 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -1287,22 +1287,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index d7945e601e..ec42c5eac9 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -1029,19 +1029,15 @@ float: 1 Function: "sinh": double: 3 -float: 3 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan": double: 1 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index ca7cfb7fa4..15b2b82187 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -248,7 +248,6 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "tanh": double: 2 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index 86da11ec35..0cc3f02296 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -1026,19 +1026,15 @@ float: 2 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index d8aad8c4ba..3824f00415 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -950,19 +950,15 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index 8ecb31b9a4..34f5eb52a2 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -981,19 +981,15 @@ float: 2 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 2 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 00720f0cd1..8cff252cd7 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -1055,19 +1055,15 @@ float: 2 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan": double: 1 diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index 55318ff3de..60c2860aa8 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -1571,25 +1571,21 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinh_downward": double: 3 -float: 3 float128: 3 ldouble: 5 Function: "sinh_towardzero": double: 3 -float: 2 float128: 3 ldouble: 4 Function: "sinh_upward": double: 4 -float: 3 float128: 4 ldouble: 5 diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index 30deb15091..7589d0385b 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -1576,25 +1576,21 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinh_downward": double: 3 -float: 3 float128: 3 ldouble: 5 Function: "sinh_towardzero": double: 3 -float: 2 float128: 3 ldouble: 4 Function: "sinh_upward": double: 4 -float: 3 float128: 4 ldouble: 5 diff --git a/sysdeps/ieee754/flt-32/e_sinhf.c b/sysdeps/ieee754/flt-32/e_sinhf.c index d3998e8336..c007c7d174 100644 --- a/sysdeps/ieee754/flt-32/e_sinhf.c +++ b/sysdeps/ieee754/flt-32/e_sinhf.c @@ -1,62 +1,131 @@ -/* e_sinhf.c -- float version of e_sinh.c. - */ +/* Correctly-rounded hyperbolic sine function for binary32 value. -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ +Copyright (c) 2022-2024 Alexei Sibidanov. -#include -#include -#include -#include -#include -#include +The original version of this file was copied from the CORE-MATH +project (file src/binary32/sinh/sinhf.c, revision 572ecec). -static const float one = 1.0, shuge = 1.0e37; +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -float -__ieee754_sinhf(float x) -{ - float t,w,h; - int32_t ix,jx; +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - GET_FLOAT_WORD(jx,x); - ix = jx&0x7fffffff; +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ - /* x is INF or NaN */ - if(__builtin_expect(ix>=0x7f800000, 0)) return x+x; +#include +#include +#include +#include +#include "math_config.h" - h = 0.5; - if (jx<0) h = -h; - /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ - if (ix < 0x41b00000) { /* |x|<22 */ - if (__builtin_expect(ix<0x31800000, 0)) { /* |x|<2**-28 */ - math_check_force_underflow (x); - if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ - } - t = __expm1f(fabsf(x)); - if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one)); - return h*(t+t/(t+one)); +float +__ieee754_sinhf (float x) +{ + static const double c[] = + { + 1, 0x1.62e42fef4c4e7p-6, 0x1.ebfd1b232f475p-13, 0x1.c6b19384ecd93p-20 + }; + static const double ch[] = + { + 1, 0x1.62e42fefa39efp-6, 0x1.ebfbdff82c58fp-13, + 0x1.c6b08d702e0edp-20, 0x1.3b2ab6fb92e5ep-27, 0x1.5d886e6d54203p-35, + 0x1.430976b8ce6efp-43 + }; + static const uint64_t tb[] = + { + 0x3fe0000000000000, 0x3fe059b0d3158574, 0x3fe0b5586cf9890f, + 0x3fe11301d0125b51, 0x3fe172b83c7d517b, 0x3fe1d4873168b9aa, + 0x3fe2387a6e756238, 0x3fe29e9df51fdee1, 0x3fe306fe0a31b715, + 0x3fe371a7373aa9cb, 0x3fe3dea64c123422, 0x3fe44e086061892d, + 0x3fe4bfdad5362a27, 0x3fe5342b569d4f82, 0x3fe5ab07dd485429, + 0x3fe6247eb03a5585, 0x3fe6a09e667f3bcd, 0x3fe71f75e8ec5f74, + 0x3fe7a11473eb0187, 0x3fe82589994cce13, 0x3fe8ace5422aa0db, + 0x3fe93737b0cdc5e5, 0x3fe9c49182a3f090, 0x3fea5503b23e255d, + 0x3feae89f995ad3ad, 0x3feb7f76f2fb5e47, 0x3fec199bdd85529c, + 0x3fecb720dcef9069, 0x3fed5818dcfba487, 0x3fedfc97337b9b5f, + 0x3feea4afa2a490da, 0x3fef50765b6e4540 + }; + static const struct + { + uint32_t uarg; + float rh, rl; + } st = { 0x74250bfeu, 0x1.250bfep-11, 0x1p-36 }; + const double iln2 = 0x1.71547652b82fep+5; + double z = x; + uint32_t ux = asuint (x) << 1; + if (__glibc_unlikely (ux > 0x8565a9f8u)) + { /* |x| >~ 89.4 */ + float sgn = copysignf (2.0f, x); + if (ux >= 0xff000000u) + { + if (ux << 8) + return x + x; /* nan */ + return copysignf (INFINITY, x); /* +-inf */ } - - /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x42b17180) return h*__ieee754_expf(fabsf(x)); - - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = __ieee754_expf((float)0.5*fabsf(x)); - t = h*w; - return t*w; + float r = math_narrow_eval (sgn * 0x1.fffffep127f); + return r; + } + if (__glibc_unlikely (ux < 0x7c000000u)) + { /* |x| < 0.125 */ + if (__glibc_unlikely (ux <= 0x74250bfeu)) + { /* |x| <= 0x1.250bfep-11 */ + if (__glibc_unlikely (ux < 0x66000000u)) /* |x| < 0x1p-24 */ + return fmaf (x, fabsf (x), x); + if (__glibc_unlikely (st.uarg == asuint (ux))) + { + float sgn = copysignf (1.0f, x); + return sgn * st.rh + sgn * st.rl; + } + return (x * 0x1.555556p-3f) * (x * x) + x; } - - /* |x| > overflowthresold, sinh(x) overflow */ - return math_narrow_eval (x*shuge); + static const double cp[] = + { + 0x1.5555555555555p-3, 0x1.11111111146e1p-7, + 0x1.a01a00930dda6p-13, 0x1.71f92198aa6e9p-19 + }; + double z2 = z * z; + double z4 = z2 * z2; + return z + (z2 * z) + * ((cp[0] + z2 * cp[1]) + z4 * (cp[2] + z2 * (cp[3]))); + } + double a = iln2 * z; + double ia = roundeven_finite (a); + double h = a - ia; + double h2 = h * h; + int64_t jp = asuint64 (ia + 0x1.8p52); + int64_t jm = -jp; + double sp = asdouble (tb[jp & 31] + ((jp >> 5) << 52)); + double sm = asdouble (tb[jm & 31] + ((jm >> 5) << 52)); + double te = c[0] + h2 * c[2]; + double to = (c[1] + h2 * c[3]); + double rp = sp * (te + h * to); + double rm = sm * (te - h * to); + double r = rp - rm; + float ub = r; + double lb = r - 1.52e-10 * r; + if (__glibc_unlikely (ub != lb)) + { + const double iln2h = 0x1.7154765p+5; + const double iln2l = 0x1.5c17f0bbbe88p-26; + h = (iln2h * z - ia) + iln2l * z; + h2 = h * h; + te = ch[0] + h2 * ch[2] + (h2 * h2) * (ch[4] + h2 * ch[6]); + to = ch[1] + h2 * (ch[3] + h2 * ch[5]); + r = sp * (te + h * to) - sm * (te - h * to); + ub = r; + } + return ub; } libm_alias_finite (__ieee754_sinhf, __sinhf) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 930399cea7..1e57c6a4df 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -1293,22 +1293,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index 4814a60c55..0f0e1fb35d 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -230,7 +230,6 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "tanh": double: 2 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index 3f96870ac6..58223df3b4 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -1029,19 +1029,15 @@ float: 2 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index 095ba5500d..efa76ec249 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -1305,22 +1305,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 5553317139..5900e6d6d9 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -963,19 +963,15 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 3 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index 64d07e5406..ce17452ba3 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -953,19 +953,15 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "sinh_downward": double: 3 -float: 3 Function: "sinh_towardzero": double: 2 -float: 2 Function: "sinh_upward": double: 3 -float: 3 Function: "tan_downward": double: 1 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index e612e40093..0468a85fcc 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -1659,25 +1659,21 @@ ldouble: 7 Function: "sinh": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinh_downward": double: 3 -float: 3 float128: 3 ldouble: 6 Function: "sinh_towardzero": double: 3 -float: 2 float128: 3 ldouble: 6 Function: "sinh_upward": double: 3 -float: 3 float128: 4 ldouble: 6 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index 4d34e06205..769c14e81d 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -1402,22 +1402,18 @@ ldouble: 7 Function: "sinh": double: 2 -float: 2 ldouble: 3 Function: "sinh_downward": double: 3 -float: 3 ldouble: 6 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 6 Function: "sinh_upward": double: 3 -float: 3 ldouble: 6 Function: "sqrt": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 4943c1b08b..3ce20f4bb1 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -1234,22 +1234,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 2 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index bf6478fe7d..98146886d9 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -1292,22 +1292,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index c2f820efc3..c7803128b0 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -1291,22 +1291,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index b24ceaa903..3c07cd1317 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -477,11 +477,9 @@ float: 1 Function: "sinh": double: 2 -float: 2 Function: "sinh_towardzero": double: 3 -float: 2 Function: "tan_towardzero": double: 1 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 209d4d2768..747f73fcfd 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -1305,22 +1305,18 @@ ldouble: 3 Function: "sinh": double: 2 -float: 2 ldouble: 2 Function: "sinh_downward": double: 3 -float: 3 ldouble: 3 Function: "sinh_towardzero": double: 3 -float: 2 ldouble: 3 Function: "sinh_upward": double: 3 -float: 3 ldouble: 4 Function: "tan": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index 2e02a0fe1f..20219d3a5d 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -2057,25 +2057,21 @@ float: 1 Function: "sinh": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "sinh_downward": double: 3 -float: 3 float128: 3 ldouble: 5 Function: "sinh_towardzero": double: 3 -float: 2 float128: 3 ldouble: 4 Function: "sinh_upward": double: 3 -float: 3 float128: 4 ldouble: 5