From patchwork Wed Dec 4 16:37:51 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: 847305 Delivered-To: patch@linaro.org Received: by 2002:a5d:434d:0:b0:385:e875:8a9e with SMTP id u13csp426529wrr; Wed, 4 Dec 2024 08:50:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUP2GPzZ+pOx8mT6pFLb758XiLpkSysR2Tf4DNuNfoIqqsF3MmbMnkra8/Toi3iYDmbmX1qmQ==@linaro.org X-Google-Smtp-Source: AGHT+IH/lnl8YKou26m+NLPp9dPlKxrmV4qKn893Srwul9VnNMfzPxNncGV31HETbMXFhJp52HJY X-Received: by 2002:ac8:5889:0:b0:460:38f5:8753 with SMTP id d75a77b69052e-46727a2624cmr867601cf.26.1733331045620; Wed, 04 Dec 2024 08:50:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733331045; cv=pass; d=google.com; s=arc-20240605; b=ePhXPoppPRrLHZNfcRhzxxseHv+qJ9qYrX8TyAYIgu12lD3CmnT9x3ezxt1S3EQuVz OgdWlEa7Vvw5bJD8Ftr3fjYbmweEd83ybl/KdiBg9hpPLyTgkKgdWiy8LGQFDd/G2FAU E1s+fYu+d/bu3Llx/NCo2KIyUHzg2wmUiW39s6qlFo4HrzyvlfB/Q8N9NZ7YQgSsIE+s g+ug5blVWs6azI6mJjsdLKObG85ZLoKw6Jfyn4dctfzyBHYMO/i60B/IRGIqiS7iFhZ1 LHbf1xNcm1gvHKz/GyagQIErEsYVsrzp2b6J6d6ItmfEDr3bE6oKHaNGtXmx4EeZSvG5 uNRw== 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=ZSHkfv3oPyOSjNxFp1VuLd20ofk6xnajhxdJaFejWCY=; fh=4rGS/xMpTpKARYPd8/6tK882DGKOrg862WI4oHDxNB4=; b=Cl9grQO6a6Eva5TJvUM9U3GDLaw7V1O26v5VPTUx289I7/lxQdg26oaVmwMc3c7Q3R yaY2m9hm9bWdUF2YtEzRzx3uMJHPSi8ZimJl85HEzgGnD7NaMkChUkktNVzMmswF4KSx C4ol+Yl1kaHjCfJ/4DYWivKYqimHoqXB7OcHG11FjOHoAZNDC+c9+fHBrTqBtmXka9IL wajmYrWwcJiVDLCWGa1/fbb90MsNtKaZ2cR+R+HCzdAI5HAyZIQBEmDkTCk9kzNrC2Rm QALHLmCtjDRpWyNiegDVAJmCxOw93Od/AwyJ+dBRzfeQdGGjAKp1ukkVJG071gYFmVN8 4PKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=egijOYTT; 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 af79cd13be357-7b68493fcecsi2045700985a.192.2024.12.04.08.50.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:50:45 -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=egijOYTT; 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 288163858C42 for ; Wed, 4 Dec 2024 16:50:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 288163858C42 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=egijOYTT X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id AE7F63858CDA for ; Wed, 4 Dec 2024 16:41:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE7F63858CDA 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 AE7F63858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330463; cv=none; b=brutzO3qGjBU3pJWrxHsffrcKLiQcEc+SVxuFIMhACJjTkPeFMt85CB6m5qIyj8vPmDOgT/NBlsVVFwtXxqITfZZp8giihI/NEY+ownCPqO4j8mVlTgwrFzJVQtCGRPgBX0sjmPkjVIiisFMMpLvhAvW2O0vaq/eW0Mz72XawMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330463; c=relaxed/simple; bh=QxmK9pdyOS24KOn9ELA/XzdhZx3P8nt9AnYuvNv66K4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V3EkInh4Trw1N0WewcFdVu75Yu92LVJKcN/bacpu/h8uZnTJ2l4gvUlM320+dxnYPve3tA/4yDSYgZcayXc/ji8L8tDmE/UkYUusj/3Q85XrlhFqxXmSoDx+3u7nkT6ZC8VdYTZqAhdtRUlRNyxnExUE7Og2TcluaZnVmP2n+tQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-215666ea06aso9815275ad.0 for ; Wed, 04 Dec 2024 08:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733330430; x=1733935230; 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=ZSHkfv3oPyOSjNxFp1VuLd20ofk6xnajhxdJaFejWCY=; b=egijOYTTK9rucd0b6xhnm8/D1AOuJ/qFZ+F2QFtboNZnQxsmltfgsu7v7m8fiJA5nl Fsv3TKgHKLRmAXvpc1rArJSFRdk1uJCmUaw0LCGLpxaIsx0agTOVfT+txWNgZamwyX83 JJv1eNmJf/vBkTXARU8HE0RGf+5SNj4kPuS3XgPeNGsgRfxsmQy/V49qEzNo4tniGsfn pEoMq6/tB4KPtpIIWu6aVZSL6Gc/4c8KFVAh0Sn0QY5T3aKvyU5seIGkDysj7kq4dNnh xqjLW+YfKlzGLExxauZ7wa6qBpa1q5SApACr4XUIbqLX101CkOxgdje0JW2dmQpmTklh 5oEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330430; x=1733935230; 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=ZSHkfv3oPyOSjNxFp1VuLd20ofk6xnajhxdJaFejWCY=; b=LGC6gmHKItNuGZNeRnlrXbFhhnsVUxIflo22r4dhTBSk82kqk+sOGiPv6Sn45O8uZ3 BOo7ssTwS1kvPCcf4Vtl0mrMtyhGwEA1ETxZkeYKlb8BS45Y3cgy1xf+PEUum5N7gcd/ Ej72/vAKlTjE3sspuG4TsxjvWdIfjBaazQh0ZY8moLhTtZh/5rTh2vy8BC0Aj0amjSNv WkWWvL3/l8WYfGlSDZWOcEfT5EMqwGBUFcvdrrabVP3nMfiUJhjjW9gWSfZaALdKVFP0 xBNdlQWSC/0dn/Q/uVcHxxjQ17jj/1JIY94FRW5ODV3gL7xQUbvWTnyq8rEGuEDwXaNf pDDA== X-Gm-Message-State: AOJu0Yz/3pwrBQiBeT5VffYpFXFhkqwkNMagJaHyahYSwlmbOhZzX8M7 5iiBnPh214f8qylf/zsC2Xn3EEuxd67aEMaBOdyJ2c59wccj1DrebuIQLDVWPzLsaFL7Te1vVyH z X-Gm-Gg: ASbGncs1W6g9T0xXfQHs7tn3hqZG/LM3ZyTz9qTjZwwKsCwazLePaXtVaCDb4QWyxpu 4SjjfJpg/nuSutr9nuQWK2ahgDve353vpWWYW4uoefsWbm4kIDnmZ1zp5pSrWHKsRMLKFHIx4f2 rwubKKTk4rsIk6IG/uh4qWLRSXzZqceQPlnz+BRqVJwlrQ+w/9Yo4wSUoA5XgfwCry4sSdq15+N KXb7YGUo9Vla8fuUb1a8h+BwwHOzrfXHBzr+YwVEbqOkdJm7NyTpJqeLXAn+w== X-Received: by 2002:a17:903:2444:b0:215:a303:24e9 with SMTP id d9443c01a7336-215f3c5b017mr467755ad.3.1733330430304; Wed, 04 Dec 2024 08:40:30 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:29 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Joseph Myers , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH v2 16/25] math: Use acosf from CORE-MATH Date: Wed, 4 Dec 2024 13:37:51 -0300 Message-ID: <20241204163949.1408676-17-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 acosf. 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.5098 36.6312 30.24% x86_64v2 53.0217 37.3091 29.63% x86_64v3 42.8501 32.3977 24.39% i686 207.3960 109.4000 47.25% aarch64 21.3694 13.7871 35.48% power10 14.5542 7.2891 49.92% reciprocal-throughput master patched improvement x86_64 14.1487 15.9508 -12.74% x86_64v2 14.3293 16.1899 -12.98% x86_64v3 13.6563 12.6161 7.62% i686 158.4060 45.7354 71.13% aarch64 12.5515 9.19233 26.76% power10 5.7868 3.3487 42.13% 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_acosf.S | 23 --- sysdeps/ieee754/flt-32/e_acosf.c | 195 +++++++++++++++++--------- 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 - 25 files changed, 132 insertions(+), 170 deletions(-) delete mode 100644 sysdeps/i386/fpu/e_acosf.S diff --git a/SHARED-FILES b/SHARED-FILES index 9f4de81b66..3d32f0f3b6 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -294,3 +294,7 @@ sysdeps/ieee754/flt-32/s_tanf.c: functions to handle errno, overflow, and underflow. It was changed to use an internal wrapper for 128 bit unsigned integer operations for ABIs that do not support the type natively. +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. diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps index 89b166b71b..a593a4f8cb 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -3,7 +3,6 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_advsimd": @@ -12,7 +11,6 @@ float: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_sve": @@ -21,12 +19,10 @@ float: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index 0f7628b75b..aac2e31951 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index 4d4b22db47..b80f97b5ed 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 3 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index 4faf784aad..de1fdd9b1e 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -3,7 +3,6 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index c80122de79..a2e6549e65 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index d67cfe1785..3e7b07e81a 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -2,19 +2,15 @@ # Maximal error of functions: Function: "acos": -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index 6cdf9fd034..58bd5eaa15 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -2,19 +2,15 @@ # Maximal error of functions: Function: "acos": -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 9ed2204d38..ecef024df5 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/i386/fpu/e_acosf.S b/sysdeps/i386/fpu/e_acosf.S deleted file mode 100644 index 435dcd9f67..0000000000 --- a/sysdeps/i386/fpu/e_acosf.S +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Public domain. - */ - -#include -#include - -RCSID("$NetBSD: $") - -/* acos = atan (sqrt(1 - x^2) / x) */ -ENTRY(__ieee754_acosf) - flds 4(%esp) /* x */ - fld %st - fmul %st(0) /* x^2 */ - fld1 - fsubp /* 1 - x^2 */ - fsqrt /* sqrt (1 - x^2) */ - fabs - fxch %st(1) - fpatan - ret -END (__ieee754_acosf) -libm_alias_finite (__ieee754_acosf, __acosf) diff --git a/sysdeps/ieee754/flt-32/e_acosf.c b/sysdeps/ieee754/flt-32/e_acosf.c index e3b3bbc928..cba01221dc 100644 --- a/sysdeps/ieee754/flt-32/e_acosf.c +++ b/sysdeps/ieee754/flt-32/e_acosf.c @@ -1,78 +1,139 @@ -/* e_acosf.c -- float version of e_acos.c. - */ +/* Correctly-rounded arc-cosine 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) 2023-2024 Alexei Sibidanov. +The original version of this file was copied from the CORE-MATH +project (file src/binary32/acos/acosf.c, revision 61d7bef). + +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.0000000000e+00, /* 0x3F800000 */ -pi = 3.1415925026e+00, /* 0x40490fda */ -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ -pS1 = -3.2556581497e-01, /* 0xbea6b090 */ -pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ -pS3 = -4.0055535734e-02, /* 0xbd241146 */ -pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ -pS5 = 3.4793309169e-05, /* 0x3811ef08 */ -qS1 = -2.4033949375e+00, /* 0xc019d139 */ -qS2 = 2.0209457874e+00, /* 0x4001572d */ -qS3 = -6.8828397989e-01, /* 0xbf303361 */ -qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ +static __attribute__ ((noinline)) float +as_special (float x) +{ + const float pih = 0x1.921fb6p+1; + const float pil = -0x1p-24f; + uint32_t t = asuint (x); + if (t == (0x7fu << 23)) + return 0.0f; /* x=1 */ + if (t == (0x17fu << 23)) + return pih + pil; /* x=-1 */ + uint32_t ax = t << 1; + if (ax > (0xffu << 24)) + return x + x; /* nan */ + return __math_invalidf (0.0); +} + +static inline double +poly12 (double z, const double *c) +{ + double z2 = z * z, z4 = z2 * z2; + double c0 = c[0] + z * c[1]; + double c2 = c[2] + z * c[3]; + double c4 = c[4] + z * c[5]; + double c6 = c[6] + z * c[7]; + double c8 = c[8] + z * c[9]; + double c10 = c[10] + z * c[11]; + c0 += c2 * z2; + c4 += c6 * z2; + c8 += z2 * c10; + c0 += z4 * (c4 + z4 * c8); + return c0; +} float -__ieee754_acosf(float x) +__ieee754_acosf (float x) { - float z,p,q,r,w,s,c,df; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix==0x3f800000) { /* |x|==1 */ - if(hx>0) return 0.0; /* acos(1) = 0 */ - else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ - } else if(ix>0x3f800000) { /* |x| >= 1 */ - return (x-x)/(x-x); /* acos(|x|>1) is NaN */ - } - if(ix<0x3f000000) { /* |x| < 0.5 */ - if(ix<=0x32800000) return pio2_hi+pio2_lo;/*if|x|<=2**-26*/ - z = x*x; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - return pio2_hi - (x - (pio2_lo-x*r)); - } else if (hx<0) { /* x < -0.5 */ - z = (one+x)*(float)0.5; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - s = sqrtf(z); - r = p/q; - w = r*s-pio2_lo; - return pi - (float)2.0*(s+w); - } else { /* x > 0.5 */ - int32_t idf; - z = (one-x)*(float)0.5; - s = sqrtf(z); - df = s; - GET_FLOAT_WORD(idf,df); - SET_FLOAT_WORD(df,idf&0xfffff000); - c = (z-df*df)/(s+df); - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - w = r*s+c; - return (float)2.0*(df+w); - } + const double pi2 = 0x1.921fb54442d18p+0; + static const double o[] = { 0, 0x1.921fb54442d18p+1 }; + double xs = x; + double r; + uint32_t t = asuint (x); + uint32_t ax = t << 1; + if (__glibc_unlikely (ax >= 0x7f<<24)) + return as_special (x); + if (__glibc_likely (ax < 0x7ec2a1dcu)) /* |x| < 0x1.c2a1dcp-1 */ + { + static const double b[] = + { + 0x1.fffffffd9ccb8p-1, 0x1.5555c94838007p-3, 0x1.32ded4b7c20fap-4, + 0x1.8566df703309ep-5, -0x1.980c959bec9a3p-6, 0x1.56fbb04998344p-1, + -0x1.403d8e4c49f52p+2, 0x1.b06c3e9f311eap+4, -0x1.9ea97c4e2c21fp+6, + 0x1.200b8261cc61bp+8, -0x1.2274c2799a5c7p+9, 0x1.a558a59cc19d3p+9, + -0x1.aca4b6a529ffp+9, 0x1.228744703f813p+9, -0x1.d7dbb0b322228p+7, + 0x1.5c2018c0c0105p+5 + }; + /* Avoid spurious underflow exception. */ + if (__glibc_unlikely (ax <= 0x40000000u)) /* |x| < 2^-63 */ + return (float) pi2; + double z = xs; + double z2 = z * z; + double z4 = z2 * z2; + double z8 = z4 * z4; + double z16 = z8 * z8; + r = z * ((((b[0] + z2 * b[1]) + z4 * (b[2] + z2 * b[3])) + + z8 * ((b[4] + z2 * b[5]) + z4 * (b[6] + z2 * b[7]))) + + z16 * (((b[8] + z2 * b[9]) + z4 * (b[10] + z2 * b[11])) + + z8 + * ((b[12] + z2 * b[13])+ z4 * (b[14] + z2 * b[15])))); + float ub = 0x1.921fb54574191p+0 - r; + float lb = 0x1.921fb543118ap+0 - r; + if (ub == lb) + return ub; + } + /* accurate path */ + if (ax < (0x7eu << 24)) + { + static const double c[] = + { + 0x1.555555555529cp-3, 0x1.333333337e0ddp-4, 0x1.6db6db3b4465ep-5, + 0x1.f1c72e13ac306p-6, 0x1.6e89cebe06bc4p-6, 0x1.1c6dcf5289094p-6, + 0x1.c6dbbcc7c6315p-7, 0x1.8f8dc2615e996p-7, 0x1.a5833b7bf15e8p-8, + 0x1.43f44ace1665cp-6, -0x1.0fb17df881c73p-6, 0x1.07520c026b2d6p-5 + }; + if (t == 0x328885a3u) + return 0x1.921fb6p+0f + 0x1p-25; + if (t == 0x39826222u) + return 0x1.920f6ap+0f + 0x1p-25; + double x2 = xs * xs; + r = (pi2 - xs) - (xs * x2) * poly12 (x2, c); + } + else + { + static const double c[] = + { + 0x1.6a09e667f3bcbp+0, 0x1.e2b7dddff2db9p-4, 0x1.b27247ab42dbcp-6, + 0x1.02995cc4e0744p-7, 0x1.5ffb0276ec8eap-9, 0x1.033885a928decp-10, + 0x1.911f2be23f8c7p-12, 0x1.4c3c55d2437fdp-13, 0x1.af477e1d7b461p-15, + 0x1.abd6bdff67dcbp-15, -0x1.1717e86d0fa28p-16, 0x1.6ff526de46023p-16 + }; + double bx = fabs (xs); + double z = 1.0 - bx; + double s = copysign (sqrt (z), xs); + r = o[t >> 31] + s * poly12 (z, c); + } + return r; } libm_alias_finite (__ieee754_acosf, __acosf) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 03fa6a410a..67bf2d2f9f 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index c96652a022..c93ebfa21b 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -2,7 +2,6 @@ # Maximal error of functions: Function: "acos": -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index 17034d44ba..d23762642b 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index a757f69a9a..aece335d6b 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 115a73ef26..862ab6b559 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index e130fd8a1d..3c364480f4 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -3,19 +3,15 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 Function: "acos_downward": double: 1 -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acos_upward": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index adaa10fb56..135853f213 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -3,25 +3,21 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 float128: 1 ldouble: 3 Function: "acos_towardzero": double: 1 -float: 1 float128: 1 ldouble: 3 Function: "acos_upward": double: 1 -float: 1 float128: 1 ldouble: 2 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index 2c44e39c2c..44cf9983dc 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 3 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 3 Function: "acos_upward": double: 1 -float: 1 ldouble: 2 Function: "acosh": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 84b9e15f43..8d3b048e84 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index b9446e5a7c..a1d85be3b6 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index 62d3f145fc..7a3d526d69 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index a6d271eb3f..d1e5b05531 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -2,11 +2,9 @@ # Maximal error of functions: Function: "acos": -float: 1 Function: "acos_towardzero": double: 1 -float: 1 Function: "acosh": double: 2 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 9276ff9726..6a70b6f5ea 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -3,22 +3,18 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 ldouble: 1 Function: "acos_downward": double: 1 -float: 1 ldouble: 1 Function: "acos_towardzero": double: 1 -float: 1 ldouble: 1 Function: "acos_upward": double: 1 -float: 1 ldouble: 1 Function: "acosh": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index f4360598a9..ff532cea1e 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -3,25 +3,21 @@ # Maximal error of functions: Function: "acos": double: 1 -float: 1 float128: 1 ldouble: 2 Function: "acos_downward": double: 1 -float: 1 float128: 1 ldouble: 2 Function: "acos_towardzero": double: 1 -float: 1 float128: 1 ldouble: 2 Function: "acos_upward": double: 1 -float: 1 float128: 1 ldouble: 2