From patchwork Wed Dec 4 16:37:52 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: 847311 Delivered-To: patch@linaro.org Received: by 2002:a5d:434d:0:b0:385:e875:8a9e with SMTP id u13csp430002wrr; Wed, 4 Dec 2024 08:59:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqZUFT/3VHJUmXlBG5reWxVTe4Smnfj6vsGmF4ztWKZRTch6+/+6dGuvOIVtVsbJx92O3i6g==@linaro.org X-Google-Smtp-Source: AGHT+IGt+vpPBBt3D+ZkPcVBUw0XHtWwgR52AiLDhSLf9IAiAdVnT23RAbPn4uiuWFxWtb0vsARB X-Received: by 2002:a05:622a:d:b0:463:4bb6:bfe2 with SMTP id d75a77b69052e-4670c75e541mr113651091cf.50.1733331558003; Wed, 04 Dec 2024 08:59:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733331557; cv=pass; d=google.com; s=arc-20240605; b=O04ri17HJIiiCj9+rw8KiK67A4xDmAUMK7ZhvfqfNEA7qzPutY3DQCduJgTJITUlqV hknQ5fvmUxufTuCvsKne5C+IzSosfNUEDkNHUZ2YGwwZU0ZXeoFH1whbp3ORoCQCk2is miQGlVfoeg6dIYXG17vu52P5jc0SqlIT8s4f8+sJgCK1qYvjCqiJ2mQGgtSYWXkIOPvz 9eImUqoDAsgcUKiqofrxoCt2Kyvqm2A7tbk0KS5kp2GmBs6QyEKtlldxoa+SUPZ8DO1N UF4IGhHD5XJUdg92rY0kqAvQyI+NriVkt4iZ44LoPWdd1HUqnWcHnc4KNkA9ZOAQ0iyL IaMQ== 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=Cuqbqe8tYtMou25rtav5jO08ZUICBz8JsnaFdbgEzaM=; fh=4rGS/xMpTpKARYPd8/6tK882DGKOrg862WI4oHDxNB4=; b=AC+AQkUbZ2IlgdGhR2yQc9+yO67UdgTjuB02eTz5DGVSi3LvY3gYPX/tTBuljX6fZm 9bi5HwRCxNTxNLhYH0/PSptL1Fv/d/voamreVLjerB4d6sPjDb4n7J7CK7gqC+txvrU0 qFqmnDY+RdRhqABL1IEhz7W8iQDsuU2N2N/BwlFUMBe4jLD3LRJFFx9a0XbifCwTj2EB mkrgK5LYE1aSSQibZhYCd9MqWplJrwTIyx37lo9UUUR5uwh9mSbGY2Q02gfvcxTeyagQ TNKgqNBkcpO9etHDxD2uIqc8GvQOjdGmpopLO83WaXiSdfAufoflsPLGUFjKTRQWt9d7 q4aA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jmq3w6xa; 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 d75a77b69052e-466c406bd30si173670181cf.213.2024.12.04.08.59.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:59:17 -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=jmq3w6xa; 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 8C30F3858CD9 for ; Wed, 4 Dec 2024 16:59:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C30F3858CD9 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=jmq3w6xa X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 32F083858414 for ; Wed, 4 Dec 2024 16:41:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32F083858414 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 32F083858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330465; cv=none; b=JjYLNmg5H7+uFNuo/ZMyIr+wuWT59cfZL7oSNpBijHC9e1VKqIDIht0pVRrFUIJ7VxWYmpSO6Otub7mpL3JMy8AD+naRxOf8D9XEXb0/cfhZX80+BQjKVjDlOJv34TMUs7uBItlkbAUU944DBQtpMagveHN5QndLjcSBaQFvpD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330465; c=relaxed/simple; bh=jW5ldRJKy8PSqjh0LcFbHiPzPG/uk/1HBwK7kZlAkoI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qFo+ReUqr7YVsztEbiQMuL78GvR9zOsqhLzz/LFfVQqLpBi6GUutKqWZiDbEf/3pG0Q/cWB/uNccDKTHdPiEd37CWzAyWBf+8ljxwkX8blsgX4QaFM/vaF3IcaXifjGfk5bZZ7bon85L9Vi9K8967rVz8zPUKpDbDEGTlF5m8VQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2156e078563so34262195ad.2 for ; Wed, 04 Dec 2024 08:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733330433; x=1733935233; 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=Cuqbqe8tYtMou25rtav5jO08ZUICBz8JsnaFdbgEzaM=; b=jmq3w6xaR8wSaDXKiiF72JGsfdeBfY48ClpYtWLCpbD38INj/8yB8rm1bZgt1wFnyS yhaiMDoGeqNmwjdwOXfE5govWL71XOXXioIgqGWjZfK4KsrwTnLFtqtEuVGZbcN8rRzV UVh1Tn/k9gBtLVfyW10gReBbjTLKYHo/ENWSyGhR4qkN+ZnTd4kNTGszOp71jQlZFzEJ zsvmHM46s3+4FIWmMXpM7Xt2FMqIGt7XkGt40vSA77iaGgApBvOZ+tBrLa698JlULM/3 DRwCgF4b9DfjwDSijc4t4AN9L3euN4o3UBzbvp4lo0JnbSoeLTQbyurOTTT1teCwX6eY uyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330433; x=1733935233; 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=Cuqbqe8tYtMou25rtav5jO08ZUICBz8JsnaFdbgEzaM=; b=JZ8aV8fWKEXlrVrvt8212lL1Bd8LKgKAkQAlq0bfF6umTUWSnuhJHT8McPCwf7djP1 uEs42gyPMnrxKp6Y6HyDZsLE+iwDGPsXj6aemtAa049FKFhaPqXbKWDRaHTlW4LN1XXC IKVkRaftREVB+U7SImpywHEOlGNU2gLm4BTRX45jppwyMYlpRcbRWD5gvwPsRrjKObYj CEDatz3VncoRd9aMy04vkelKLFlEfBp3Noe6NOD6DsfWW7XSX70X5lDx9LDvZE3mNqZI fUL8QIakI7tLEY58ZgpduIGkDJz7tDUzz1tIcZOVQFLxqvyWlbMRss7Nf0ee8zKntRD3 sSWA== X-Gm-Message-State: AOJu0YxWTB4f3JtOJyPk3YuIVWcbDsMRcmq8Pir7aAO7CTkcxgeJXZBe vabhNteRakEXDfweFZb4ctdIr4tIksZJGcmxvDozRuCFGDFT6ZI+y1KmG9HlIH92/f0BccczqEw k X-Gm-Gg: ASbGncsPGyT6jDvXLLujJpg5wjJQFDv8KNJ7/pTXY3+8Re8ApTHfo922NQCwXhD0Io2 MhfeVhiJe90ItIcih/IuECgN38C9u5PNEMU5E5MdyRuTLoQvFO9HOfmk2Pc49+lp3S/G+kSowgY Fl6ETuidBLOhoJIYvLLKGVLa+jWLTdIJBsYj3mXMGtFBIDMDnIRuv8hDWhrzm2lrSaCBKW33NLq ZA0/aNhHMura05IM3LK5tgxg91hfHpc/IFAtyySwSDxopZrJSTzxjr89jSwKg== X-Received: by 2002:a17:902:d507:b0:215:9a73:6c45 with SMTP id d9443c01a7336-215bd1cf589mr85006585ad.22.1733330432506; Wed, 04 Dec 2024 08:40:32 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:32 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Joseph Myers , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH v2 17/25] math: Use acoshf from CORE-MATH Date: Wed, 4 Dec 2024 13:37:52 -0300 Message-ID: <20241204163949.1408676-18-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 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 | 232 ++++++++++++++++++++----- 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, 196 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..37e5e2071b 100644 --- a/sysdeps/ieee754/flt-32/e_acoshf.c +++ b/sysdeps/ieee754/flt-32/e_acoshf.c @@ -1,49 +1,201 @@ -/* 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