From patchwork Fri Nov 29 13:17:39 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: 846131 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp860767wrp; Fri, 29 Nov 2024 05:30:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWhLU603SrvnxICYb0XffOLom1s0jr8nLdEcp++rGioLwdKlxLXRaKJI3/KigKFAmj60nQuYg==@linaro.org X-Google-Smtp-Source: AGHT+IHpFaEwdVMDKKY1nqcSlh+INvoZiTnX60QaAScx/gbDepG3f4by/gqQhUAiV7WsdnJCNSdh X-Received: by 2002:a05:6512:b26:b0:539:905c:15ab with SMTP id 2adb3069b0e04-53df00dce7fmr7614034e87.32.1732887052460; Fri, 29 Nov 2024 05:30:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732887052; cv=pass; d=google.com; s=arc-20240605; b=Odk4+TfbHk6N+nRaN9DcVaOVnfnIsd3zzhJF0NN7ptWdhmOwywc+S/LtYbe1wLLEgL 2F2ef1h6enU9C4g8AuepwSb8qFYexCeaeZq4O0cEYRtYAc7R9jVIVS9y3aLn1eLcRgYv k+zcZejW+YRlp6JPUfE7GpzoiVWR7QiEqwotCckHL7chXUewvpCRdTTJ+ZHs7Jb6horL q/M7WAtLJUMQUxjVz8GJ2N1/m/bl0Sjsb+uAWXDDyit20xi8fKqvJ0v79nrMC40/+j7b jROP25qieSSSMWCOxce51ZUhznUUQHDJ/rnkawiBpeBqjpByjiXMPHVaRumuwY2jEB9S Cnvw== 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:dkim-filter:arc-filter:dmarc-filter :delivered-to; bh=XU+QCzM6gng/TQfDkz/Ntzlvp2wcFYsmFC86KL2fhxg=; fh=sFucH9KQW8Y8eMoQXaNIgycLDa7roysdjTHpHLIprh4=; b=Qz0f/amTEU8SkuX+Y0lwe1r90y5hlwTd0gsrxp33MAbyXWXHddWG/Cmr0T5ABcNzBv QZScGwXG4iihEyFBI9I1FH6aSixHpCKC7M4WhUyj/1JrKgkI1fhBxfMVfyqg64K518eZ 0RxwOHbVBCME76QMSv3YXatOeu2LnWBeRE2HrcqpX+7byXuoV0dA07gljC8KLj7B5Te+ HUtYAOYpyDfkeQXtxN+aGq6xMVzbCU+ufecfVnLjdah+P5llkkJi9MpHXBJLYjLRZPGH wb2e/LgwZdmaxOklLnASXkhUoi8h5sXiapXcgTsy6mtzgmue8ZIe0AjbSBe6y7SNnIvP n2rQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=toQjfYxT; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id 2adb3069b0e04-53df6496d01si1407742e87.381.2024.11.29.05.30.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 05:30:52 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=toQjfYxT; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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 583793858C56 for ; Fri, 29 Nov 2024 13:30:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by sourceware.org (Postfix) with ESMTPS id C1B9A3858D35 for ; Fri, 29 Nov 2024 13:21:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B9A3858D35 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 C1B9A3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::641 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732886490; cv=none; b=dr72S5mQVHL6AKeIi/9hMAGuPyKKjRydF/bBXjL1A50sQzDEy2pfH9Ru80pWCLYR0B9zC4gzpPqW7SEZBSHf2wQk8F8yPG7ltK2NrX3yeFBCUNMXHmCeqReFB+IZlgltX5UzPhLG5AUwyYP/dS08+ycIBwm4rgDbFT4Hfxarwqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732886490; c=relaxed/simple; bh=i3GKny0oPxNEcMNSsPr1ggVkCVDKIPjMRWpk1XhFij8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K8cbwcyZ8DQCgCd/SxaFvr/UoG4MvoDqLN47RZWzX1l6sccPqfwdTwOSrbV6sVSRMxO/hQR5RiKdFwXeTzusZCYLxEGl1l8NWGuvUb4cJz+LwHuuph1vRF/eXtxz/uKF3E5S2PcohFbY19X3ibh/T2RISrx3AIuRVKbqYJPgHQA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1B9A3858D35 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=toQjfYxT Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-21532055aebso11574155ad.3 for ; Fri, 29 Nov 2024 05:21:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732886483; x=1733491283; 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=XU+QCzM6gng/TQfDkz/Ntzlvp2wcFYsmFC86KL2fhxg=; b=toQjfYxTkQo//4irF8RYYl5zafk9ykDnRbLmDYTodbtaHAKO6ETvqYGCWCvsibmUs+ fkLqIn0rVz33Hx+blUo16avCydvTadrGlLiMNf+bCqZpZ02jlQyljRWJepcXLAstO98W CtOm3jPLxgIOedPB/vJ5/wlMPPS17il9VuHVEyBkEwh00s+T+VMKrhOJraI2+c6CLV8Y rU71SniYF6ytXYkNcA8FIt+VpIjOucjEe7h87I6wtKfdTRYwsiwNcZ/WhKh+s1X2JMHd 2lvZj5fsL1g/f26jDm2hNlB840kVWsck5pbrwacsilkNNS3vtd37vnz7AaemcZDdxMRj i0LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732886483; x=1733491283; 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=XU+QCzM6gng/TQfDkz/Ntzlvp2wcFYsmFC86KL2fhxg=; b=Q4CXHc6YPYK6Xe1hiW+jgc2PHgGNaEfMU63kx31CEtaGBxWZaFd4QmbZPcTnTKo+JI H84IGm/kqsmqHbO0GVQAGpt9RnLbPDI4jBGrvAZND4Xz/70tDKItToRGqcbRnMMtI6NP n+JcCnNi/NUez+M0yrBlMflRVWDysX8TDgp3yRuoZAhuIn2Do0s2ZNxGDo9Yn1n5Y+cZ lqYr6DVyClhn/HDSIKQNdmwHB351Qh/4sDVmKwo2W+FrYlWjJ65IbJa0Oz369gWiRvez T2CPLgRw12i5bcfkvuw90YRIAqYOz7KCTO6C0ex3AYj1iao7Zi09lisecfPgy67Q7OlS LiFw== X-Gm-Message-State: AOJu0YyH7ASHohf+VRmdMjMbYZNR9M/IsjBuAqGDP4VvOM+S/NccakLr XcMg8RIImuLIcuyvuWEU9poK792bpSSnLFjNYTC06NXMxED0duNfEqBUvHXIpPEnSFfDHvD59Ad TB7gBEaA2 X-Gm-Gg: ASbGncv3TfOgSfO7enrgInFNELP1ivKjptTh0P33o84oFm0mMTFtZiSjgg1XpzFbPOo xeysHsC6GdISDOeDInGkbJTryDvRVNrDrwUDblTLBRx9k/pk6U8vVYoG1eCsHKRDtEiURXV6g0Y SvUhxWHocPGK3OErbwHMx5M33suBqkzVN1PX3Bu/z28wJoTTPLRsI/Tp2G7ZqF/aBfExiEg9cX7 ypySReFoZXgz0ALiSmO0ZibG0wGFB/8yzjSUJcSFwWK9pebtcDUT4E4h73c7ts= X-Received: by 2002:a17:903:1cf:b0:20b:8776:4906 with SMTP id d9443c01a7336-21501b58e10mr129500045ad.37.1732886481194; Fri, 29 Nov 2024 05:21:21 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:68c8:3143:6603:ad16:715e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2153d5f66d5sm14472255ad.201.2024.11.29.05.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 05:21:20 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH 15/23] math: Use acoshf from CORE-MATH Date: Fri, 29 Nov 2024 10:17:39 -0300 Message-ID: <20241129132032.476978-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241129132032.476978-1-adhemerval.zanella@linaro.org> References: <20241129132032.476978-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 acoshf. 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 61.2471 58.7742 4.04% x86_64-v2 62.6519 59.0523 5.75% x86_64-v3 58.7408 50.1393 14.64% aarch64 24.8580 21.3317 14.19% power10 17.0469 13.1345 22.95% reciprocal-throughput master patched improvement x86_64 16.1618 15.1864 6.04% x86_64-v2 15.7729 14.7563 6.45% x86_64-v3 14.1669 11.9568 15.60% aarch64 10.911 9.5486 12.49% power10 6.38196 5.06734 20.60% 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/e_acoshf.S | 101 ----------- sysdeps/ieee754/flt-32/e_acoshf.c | 230 ++++++++++++++++++++----- sysdeps/loongarch/lp64/libm-test-ulps | 4 - sysdeps/m68k/m680x0/fpu/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, 194 insertions(+), 225 deletions(-) delete mode 100644 sysdeps/i386/fpu/e_acoshf.S diff --git a/SHARED-FILES b/SHARED-FILES index 3d32f0f3b6..c29c1c8106 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -298,3 +298,7 @@ sysdeps/ieee754/flt-32/e_acosf.c: (src/binary32/acos/acosf.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_acoshf.c: + (src/binary32/acosh/acoshf.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 a593a4f8cb..902740f848 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -27,7 +27,6 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_advsimd": @@ -36,7 +35,6 @@ float: 2 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_sve": @@ -45,12 +43,10 @@ float: 2 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index aac2e31951..d26fcb40c9 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index b80f97b5ed..0057716df0 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 3 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 3 -float: 3 Function: "asin": double: 1 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index de1fdd9b1e..2fa0c82346 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -6,7 +6,6 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index a2e6549e65..968efaf299 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index 3e7b07e81a..ebde72f4d7 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -14,19 +14,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": float: 1 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index 58bd5eaa15..73b6a2042a 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -14,19 +14,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": float: 1 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index ecef024df5..8a84b303b7 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/i386/fpu/e_acoshf.S b/sysdeps/i386/fpu/e_acoshf.S deleted file mode 100644 index 6eda9dc584..0000000000 --- a/sysdeps/i386/fpu/e_acoshf.S +++ /dev/null @@ -1,101 +0,0 @@ -/* ix87 specific implementation of arcsinh. - Copyright (C) 1996-2024 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 -#include - - .section .rodata.cst8,"aM",@progbits,8 - - .p2align 3 - .type one,@object -one: .double 1.0 - ASM_SIZE_DIRECTIVE(one) - .type limit,@object -limit: .double 0.29 - ASM_SIZE_DIRECTIVE(limit) - -#ifdef PIC -#define MO(op) op##@GOTOFF(%edx) -#else -#define MO(op) op -#endif - - .text -ENTRY(__ieee754_acoshf) - movl 4(%esp), %ecx - cmpl $0x3f800000, %ecx - jl 5f // < 1 => invalid - fldln2 // log(2) - flds 4(%esp) // x : log(2) - cmpl $0x47000000, %ecx - ja 3f // x > 2^14 -#ifdef PIC - LOAD_PIC_REG (dx) -#endif - cmpl $0x40000000, %ecx - ja 4f // x > 2 - - // 1 <= x <= 2 => y = log1p(x-1+sqrt(2*(x-1)+(x-1)^2)) - fsubl MO(one) // x-1 : log(2) - fabs // acosh(1) is +0 in all rounding modes - fld %st // x-1 : x-1 : log(2) - fmul %st(1) // (x-1)^2 : x-1 : log(2) - fadd %st(1) // x-1+(x-1)^2 : x-1 : log(2) - fadd %st(1) // 2*(x-1)+(x-1)^2 : x-1 : log(2) - fsqrt // sqrt(2*(x-1)+(x-1)^2) : x-1 : log(2) - faddp // x-1+sqrt(2*(x-1)+(x-1)^2) : log(2) - fcoml MO(limit) - fnstsw - sahf - ja 2f - fyl2xp1 // log1p(x-1+sqrt(2*(x-1)+(x-1)^2)) - ret - -2: faddl MO(one) // x+sqrt(2*(x-1)+(x-1)^2) : log(2) - fyl2x // log(x+sqrt(2*(x-1)+(x-1)^2)) - ret - - // x > 2^14 => y = log(x) + log(2) - .align ALIGNARG(4) -3: fyl2x // log(x) - fldln2 // log(2) : log(x) - faddp // log(x)+log(2) - ret - - // 2^28 > x > 2 => y = log(2*x - 1/(x+sqrt(x*x-1))) - .align ALIGNARG(4) -4: fld %st // x : x : log(2) - fadd %st, %st(1) // x : 2*x : log(2) - fld %st // x : x : 2*x : log(2) - fmul %st(1) // x^2 : x : 2*x : log(2) - fsubl MO(one) // x^2-1 : x : 2*x : log(2) - fsqrt // sqrt(x^2-1) : x : 2*x : log(2) - faddp // x+sqrt(x^2-1) : 2*x : log(2) - fdivrl MO(one) // 1/(x+sqrt(x^2-1)) : 2*x : log(2) - fsubrp // 2*x+1/(x+sqrt(x^2)-1) : log(2) - fyl2x // log(2*x+1/(x+sqrt(x^2-1))) - ret - - // x < 1 (or -NaN) => NaN - .align ALIGNARG(4) -5: flds 4(%esp) - fsub %st - fdiv %st, %st(0) - ret -END(__ieee754_acoshf) -libm_alias_finite (__ieee754_acoshf, __acoshf) diff --git a/sysdeps/ieee754/flt-32/e_acoshf.c b/sysdeps/ieee754/flt-32/e_acoshf.c index 2237af4ba4..c92e66d604 100644 --- a/sysdeps/ieee754/flt-32/e_acoshf.c +++ b/sysdeps/ieee754/flt-32/e_acoshf.c @@ -1,49 +1,199 @@ -/* e_acoshf.c -- float version of e_acosh.c. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#if defined(LIBM_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: e_acoshf.c,v 1.5 1995/05/12 04:57:20 jtc Exp $"; -#endif +/* Correctly-rounded inverse hyperbolic cosine function for binary32 format. + +Copyright (c) 2023-2024 Alexei Sibidanov. + +The original version of this file was copied from the CORE-MATH +project (file src/binary32/acosh/acoshf.c, revision 927eb45). + +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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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. +*/ #include -#include +#include #include +#include "math_config.h" -static const float -one = 1.0, -ln2 = 6.9314718246e-01; /* 0x3f317218 */ +static __attribute__ ((noinline)) float +as_special (float x) +{ + uint32_t t = asuint (x); + if (t == 0x3f800000u) + return 0.0f; + if ((t << 1) > 0xff000000u) + return x + x; /* nan */ + if (t == 0x7f800000u) + return x; /* inf */ + return __math_invalidf (x); +} -float __ieee754_acoshf(float x) +float +__ieee754_acoshf (float x) { - float t; - int32_t hx; - GET_FLOAT_WORD(hx,x); - if(hx<0x3f800000) { /* x < 1 */ - return (x-x)/(x-x); - } else if(hx >=0x4d800000) { /* x > 2**28 */ - if(hx >=0x7f800000) { /* x is inf of NaN */ - return x+x; - } else - return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */ - } else if (hx==0x3f800000) { - return 0.0; /* acosh(1) = 0 */ - } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ - t=x*x; - return __ieee754_logf((float)2.0*x-one/(x+sqrtf(t-one))); - } else { /* 1> 12); + int j = (m + (UINT64_C(1) << (52 - 8))) >> (52 - 7); + int e = (tp >> 52) - 0x3ff; + double w = asdouble (m | UINT64_C(0x3ff) << 52); + double z = w * ix[j] - 1.0; + static const double c[] = + { + 0x1.0000000066947p+0, -0x1.00007f053d8cbp-1, 0x1.555280111d914p-2 + }; + double z2 = z * z; + double r = ((lix[128] * e + lix[j]) + z * c[0]) + + z2 * (c[1] + z * c[2]); + if (__glibc_unlikely (((asuint64 (r) + 259000) & INT64_C(0xfffffff)) + < 260000)) + { + static const double cp[] = + { + 0x1p+0, -0x1p-1, + 0x1.55555555030bcp-2, -0x1.ffffffff2b4e5p-3, + 0x1.999b5076a42f2p-3, -0x1.55570c45a647dp-3 + }; + z2 = z * z; + double c0 = cp[0] + z * cp[1]; + double c2 = cp[2] + z * cp[3]; + double c4 = cp[4] + z * cp[5]; + c0 += z2 * (c2 + z2 * c4); + const double ln2l = 0x1.7f7d1cf79abcap-20; + const double ln2h = 0x1.62e4p-1; + double Lh = ln2h * e; + double Ll = ln2l * e; + r = fma (z, c0, Ll + lix[j]) + Lh; + if (__glibc_unlikely ((asuint64 (r) & UINT64_C(0xfffffff)) == 0)) + { + double h = fma (z, c0, Ll + lix[j]) + (Lh - r); + r = r + 64.0 * h; + } } + return r; + } + else + return as_special (x); } libm_alias_finite (__ieee754_acoshf, __acoshf) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 67bf2d2f9f..63fd07fbe0 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/m68k/m680x0/fpu/libm-test-ulps b/sysdeps/m68k/m680x0/fpu/libm-test-ulps index 50080f46b3..73019999e0 100644 --- a/sysdeps/m68k/m680x0/fpu/libm-test-ulps +++ b/sysdeps/m68k/m680x0/fpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acosh": double: 1 -float: 1 ldouble: 1 Function: "acosh_downward": double: 2 -float: 1 ldouble: 1 Function: "acosh_towardzero": double: 2 -float: 1 ldouble: 1 Function: "acosh_upward": double: 2 -float: 1 ldouble: 1 Function: "asin": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index c93ebfa21b..a9e3f3a318 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -5,7 +5,6 @@ Function: "acos": Function: "acosh": double: 2 -float: 2 Function: "asin": float: 1 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index d23762642b..fc0d001750 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index aece335d6b..855b48e800 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 862ab6b559..0cc7beccfc 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index 3c364480f4..a0c3179fc3 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -15,19 +15,15 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_downward": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "acosh_upward": double: 2 -float: 2 Function: "asin": double: 1 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index 135853f213..05facea37f 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -23,25 +23,21 @@ ldouble: 2 Function: "acosh": double: 2 -float: 2 float128: 4 ldouble: 2 Function: "acosh_downward": double: 2 -float: 2 float128: 3 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 float128: 2 ldouble: 5 Function: "acosh_upward": double: 2 -float: 2 float128: 3 ldouble: 4 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index 44cf9983dc..f553da0caa 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 2 Function: "acosh": double: 2 -float: 2 ldouble: 1 Function: "acosh_downward": double: 2 -float: 2 ldouble: 2 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 5 Function: "acosh_upward": double: 2 -float: 2 ldouble: 4 Function: "add_ldouble": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 8d3b048e84..3bf997c5d8 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 2 Function: "asin": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index a1d85be3b6..f85d9caf03 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index 7a3d526d69..b788f5730b 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index d1e5b05531..d46c722ea1 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -8,11 +8,9 @@ double: 1 Function: "acosh": double: 2 -float: 2 Function: "acosh_towardzero": double: 2 -float: 2 Function: "asin": float: 1 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 6a70b6f5ea..8faf5357df 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -19,22 +19,18 @@ ldouble: 1 Function: "acosh": double: 2 -float: 2 ldouble: 4 Function: "acosh_downward": double: 2 -float: 2 ldouble: 3 Function: "acosh_towardzero": double: 2 -float: 2 ldouble: 2 Function: "acosh_upward": double: 2 -float: 2 ldouble: 3 Function: "asin": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index ff532cea1e..85d5e8fcd8 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -43,25 +43,21 @@ float: 1 Function: "acosh": double: 2 -float: 2 float128: 4 ldouble: 3 Function: "acosh_downward": double: 2 -float: 2 float128: 3 ldouble: 4 Function: "acosh_towardzero": double: 2 -float: 2 float128: 2 ldouble: 4 Function: "acosh_upward": double: 2 -float: 2 float128: 3 ldouble: 3