From patchwork Fri Nov 29 13:17:40 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: 846139 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp871297wrp; Fri, 29 Nov 2024 05:46:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhut3BdjaV8c4kfP+FzkaV4EwCvvk/nHNWIilZ2VvJ2EOcx3Fbq/vj7g/xaKsOR01v+5ijoQ==@linaro.org X-Google-Smtp-Source: AGHT+IElau2rK+z/mWDKAG4x5BIEiGyioJ4Iv1hqqgKAcKeOb2gKMbws0y2Ql6t82f5+/fhLDdcX X-Received: by 2002:a05:6359:420a:b0:1ca:9793:ed68 with SMTP id e5c5f4694b2df-1cab169cfe2mr530179755d.23.1732887995591; Fri, 29 Nov 2024 05:46:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732887995; cv=pass; d=google.com; s=arc-20240605; b=ZqVUvUT0Q+qllGHp/ko2Limn3LDyA1AAPmcBql5SHKkbKtqy4T4i0ZJrhgKJN90utK Th4wVw2oGkQU89a6k3GxCNBPb4/q1xCjOLugXffjjSADmrdEKL4PpXPkxgKuXd6eMBPE VPpxn3nhXipnTMLlx7yD6KYL3TPNGtwp7mL0Tt5hNDK+zR6q6KdB8cgE4zOWuF2pyD3b ZyjM0Ohga4RnYGjKRLtYzEIU7s9i8PD28EWDdDG9spfuB/Zklr8hLaJp/GiKWu1DjFGV Ro7BQqaFE7RE92CM6dlxCDbWPPpqqFFxIEnjoW3EYNZU0JS8DAkPF2P+wrztgfeffUpg 4MyQ== 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:dkim-filter; bh=hCcL9hWffHV417BGRJGyWTb09wnfTLxu9MKoMsF9cEY=; fh=sFucH9KQW8Y8eMoQXaNIgycLDa7roysdjTHpHLIprh4=; b=f6s5l9qcJgGmud6qvfmnRVfdhizCPAlyVSg+Yq330ocxjxSSLEo2m7QHJMbaLThSOX 6hh8LyHAr5z6+i1uZHNB0XjRWMTCzW9WgQcJY7JPPI4ub7BBewIfNug9VZGFM9KyVajK h9AIvObGoemEOK208ZzTxCA53NHCQWHHRNay9ClhMEg1tPBWrR2InyhdgEhfAUO9kq9G tDg/HeOPAJRdMabG9Lx1Q0AB6JP/GnrzgXTx7a1pTfwTG7pdcESZ0vix4OiqBvM/Rv75 45SxJ0d8cyCr2Ure6SaVMh/MYZFKkWLR48KnJtpC0keS8lA3dPklSDsryiBv1HQ4MY8X /M1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iSK0GWoL; 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 a1e0cc1a2514c-85b82a98b14si1393440241.61.2024.11.29.05.46.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 05:46:35 -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=iSK0GWoL; 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 203F63858D37 for ; Fri, 29 Nov 2024 13:46:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 203F63858D37 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=iSK0GWoL X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by sourceware.org (Postfix) with ESMTPS id 7EBC13858CD1 for ; Fri, 29 Nov 2024 13:21:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EBC13858CD1 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 7EBC13858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::642 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732886487; cv=none; b=WBGUljQuApbUlt6qGEkCS8ruCiuCj1nNGn4jrkN36JctPOipXsUp6sPMm0xbPVD/jI8zhzNbBmvqfkFperGAEvizDiajK1cPN+695z2pAggffHFPYhO4J7SzyaDFuL7c5VAYExx+3A8ZRWcp9vBfOyQR9tgrwG5VHw2ubQGhDWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732886487; c=relaxed/simple; bh=ZyfBDZrfFL5hmP0gMC27zgMppoI33IyKJ1RJO2VyBsg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tUsdRLoRmV5eokR3YcvrxiA1AFxa0sAPYzsvUVJpOBezHwdlRk6Rsxc1uoalAvPyFbo7xlJBspsfLXSkGFGKO5IRkgRo8YsWoGEkEMcT0XhHI8MObO7EATEw5D9kWksJXN+WdcFm8AObeF//8yHBP5XbtVUb+PZ8ZPHjbebqwME= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EBC13858CD1 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-21532055aebso11575205ad.3 for ; Fri, 29 Nov 2024 05:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732886486; x=1733491286; 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=hCcL9hWffHV417BGRJGyWTb09wnfTLxu9MKoMsF9cEY=; b=iSK0GWoLwUYnQ5kN14oz7zfdGpBSmOASQGKrUGyP4Mtwux4KILBUgRUIbrGlpNd9nl ReqjC7+ONuid4s5sLEQYDMNCw4DzNMXZduc7Eocuyy4si4b3VjcqRKhKXV9PrGVPnWio vg8JruX1bH5g1sLlg5NBW7KdJISs+3qCt/P5wu6oUS+ef/Bw7+MK1+vL+Mb3+Sd21+Y2 7z4OAP/cn3hJDWAbxRX3ixVbU69zp9rOtigEWYcfeX3IuM1vo+5+chxCz4d/K+hh7W7m se8gQxzE6KaJqE0sECglU4bu0VMkMx84D9t+Tel67X9EySYsgHYv1TH8HtKc7Vk1JZkx NXCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732886486; x=1733491286; 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=hCcL9hWffHV417BGRJGyWTb09wnfTLxu9MKoMsF9cEY=; b=sFfCPdUIOFdK144mRO9iLHk1i4EJr6lUlmdCSCosOc4BHGH7kZ9DljzBCbSBH5g6k2 kFMAxQsGPoHMRQQYJsS/dh7bOeWqylN4CP26QdGd0hI/tYXCaSe2t0ngFUcRFmP3/hUq ISERfBaxPuKxwU2niZp3WMCOkk8BCbs/CQ/V+vCyJ4ki5C7OH6SePrHwo1yRxRVoDqKF wxfj3g/PsP1HnCLXwDSAHi6UwNFZMjJ19wJquMT28fxIBgKCJMQdC1l+Z6c/zep4sjoG JcGvRpEfUncjAbfjhFqn4P+S52buLDHtGM9F/2qDBLdr2XLXj2+AUKarEyeBPC9cqdV5 WZeg== X-Gm-Message-State: AOJu0YzriKu1g9LlFLc7jb9fFOg67WKZ/D7t3zPisq9l3erNEAgD2M1E FjwHA0Huwpp7knntjbc9wJJP2fDno1GHze7WUd5DXYiCM2dvtmpAtDCrESdkR92oicrBDI3uxRZ FJiM4wS98 X-Gm-Gg: ASbGncupJnV2zSIqm67a3A6lbtR2LkggBc4u6G8IcXIObAulb65/hWuCrmOAuPl0d9t J1syDPloySDjHahMYQywj7ZK+YmPqER7pUUF5+gy8Zv8qow4uVuw2n3dVeq4tKBcvxwMFNRm0/9 sGHGp1ql/p+2HJMJ3ig/eSG2xpzKjeyc2/prxvmbWr3d5jOzLBFFhSFPmdIW8w+R2gwOfOMBLTV p7zQ1bS4WoQYUnk3xAL7CtMJ4VFJiuHDZ4HPloSwLFE2hz96oN3g/R4tGRCNPQ= X-Received: by 2002:a17:903:181:b0:212:5eb7:9cb3 with SMTP id d9443c01a7336-21501d5830fmr150254415ad.56.1732886485514; Fri, 29 Nov 2024 05:21:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 05:21:25 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH 16/23] math: Use asinf from CORE-MATH Date: Fri, 29 Nov 2024 10:17:40 -0300 Message-ID: <20241129132032.476978-17-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 asinf. 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 42.8237 35.2460 17.70% x86_64v2 43.3711 35.9406 17.13% x86_64v3 35.0335 30.5744 12.73% i686 213.8780 104.4710 51.15% aarch64 (Neoverse) 17.2937 13.6025 21.34% power10 12.0227 7.4241 38.25% reciprocal-throughput master patched improvement x86_64 13.6770 15.5231 -13.50% x86_64v2 13.8722 16.0446 -15.66% x86_64v3 13.6211 13.2753 2.54% i686 186.7670 45.4388 75.67% aarch64 (Neoverse) 9.96089 9.39285 5.70% power10 4.9862 3.7819 24.15% 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_asinf.S | 38 ---- sysdeps/i386/fpu/libm-test-ulps | 1 - .../i386/i686/fpu/multiarch/libm-test-ulps | 1 - sysdeps/ieee754/flt-32/e_asinf.c | 210 ++++++++++-------- 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 - 27 files changed, 122 insertions(+), 212 deletions(-) delete mode 100644 sysdeps/i386/fpu/e_asinf.S diff --git a/SHARED-FILES b/SHARED-FILES index c29c1c8106..6a6ff76b31 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -302,3 +302,7 @@ 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. +sysdeps/ieee754/flt-32/e_asinf.c: + (src/binary32/asin/asinf.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 902740f848..fabbc2b840 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -51,7 +51,6 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_advsimd": @@ -60,7 +59,6 @@ float: 2 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_sve": @@ -69,12 +67,10 @@ float: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index d26fcb40c9..cda6ece49e 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index 0057716df0..3c08593d99 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -27,19 +27,15 @@ double: 3 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 2 -float: 1 Function: "asinh": double: 3 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index 2fa0c82346..c3548a9807 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -9,7 +9,6 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index 968efaf299..7c8ff19bec 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -27,19 +27,15 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 2 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index ebde72f4d7..b04ed2a161 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -25,19 +25,15 @@ Function: "acosh_upward": double: 2 Function: "asin": -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 1 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index 73b6a2042a..612bd19eda 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -25,19 +25,15 @@ Function: "acosh_upward": double: 2 Function: "asin": -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 1 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 8a84b303b7..323d2ee993 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -27,19 +27,15 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 2 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/i386/fpu/e_asinf.S b/sysdeps/i386/fpu/e_asinf.S deleted file mode 100644 index 774feab607..0000000000 --- a/sysdeps/i386/fpu/e_asinf.S +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Public domain. - */ - -#include -#include -#include - -RCSID("$NetBSD: $") - - .section .rodata.cst4,"aM",@progbits,4 - -DEFINE_FLT_MIN - -#ifdef PIC -# define MO(op) op##@GOTOFF(%ecx) -#else -# define MO(op) op -#endif - - .text - -/* asin = atan (x / sqrt(1 - x^2)) */ -ENTRY(__ieee754_asinf) -#ifdef PIC - LOAD_PIC_REG (cx) -#endif - flds 4(%esp) /* x */ - fld %st - fmul %st(0) /* x^2 */ - fld1 - fsubp /* 1 - x^2 */ - fsqrt /* sqrt (1 - x^2) */ - fpatan - FLT_CHECK_FORCE_UFLOW - ret -END (__ieee754_asinf) -libm_alias_finite (__ieee754_asinf, __asinf) diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index c06da68b45..3acdc76bec 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -56,7 +56,6 @@ ldouble: 1 Function: "asin_upward": double: 1 -float: 1 float128: 2 ldouble: 1 diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index 43ffbd7978..e49c91b36c 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -56,7 +56,6 @@ ldouble: 1 Function: "asin_upward": double: 1 -float: 1 float128: 2 ldouble: 1 diff --git a/sysdeps/ieee754/flt-32/e_asinf.c b/sysdeps/ieee754/flt-32/e_asinf.c index d9f446d1b1..944bf6f5ce 100644 --- a/sysdeps/ieee754/flt-32/e_asinf.c +++ b/sysdeps/ieee754/flt-32/e_asinf.c @@ -1,105 +1,131 @@ -/* e_asinf.c -- float version of e_asin.c. - */ +/* Correctly-rounded arc-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) 2023-2024 Alexei Sibidanov. -/* - Modifications for single precision expansion are - Copyright (C) 2001 Stephen L. Moshier - and are incorporated herein by permission of the author. The author - reserves the right to distribute this material elsewhere under different - copying permissions. These modifications are distributed here under - the following terms: +The original version of this file was copied from the CORE-MATH +project (file src/binary32/asin/asinf.c, revision bc385c2). - This 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. +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: - This 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. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see - . */ +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. +*/ -#if defined(LIBM_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: e_asinf.c,v 1.5 1995/05/12 04:57:25 jtc Exp $"; -#endif - -#include -#include -#include -#include +#include +#include #include +#include "math_config.h" -static const float -one = 1.0000000000e+00, /* 0x3F800000 */ -huge = 1.000e+30, - -pio2_hi = 1.57079637050628662109375f, -pio2_lo = -4.37113900018624283e-8f, -pio4_hi = 0.785398185253143310546875f, +static __attribute__ ((noinline)) float +as_special (float x) +{ + uint32_t ax = asuint (x) << 1; + if (ax > (0xffu << 24)) + return x + x; /* nan */ + return __math_invalidf (0.0); +} -/* asin x = x + x^3 p(x^2) - -0.5 <= x <= 0.5; - Peak relative error 4.8e-9 */ -p0 = 1.666675248e-1f, -p1 = 7.495297643e-2f, -p2 = 4.547037598e-2f, -p3 = 2.417951451e-2f, -p4 = 4.216630880e-2f; +static double +poly12 (double z, const double *c) +{ + double z2 = z * z; + double 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_asinf(float x) +float +__ieee754_asinf (float x) { - float t,w,p,q,c,r,s; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix==0x3f800000) { - /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - } else if(ix> 0x3f800000) { /* |x|>= 1 */ - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ - } else if (ix<0x3f000000) { /* |x|<0.5 */ - if(ix<0x32000000) { /* if |x| < 2**-27 */ - math_check_force_underflow (x); - if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else { - t = x*x; - w = t * (p0 + t * (p1 + t * (p2 + t * (p3 + t * p4)))); - return x+x*w; - } - } - /* 1> |x|>= 0.5 */ - w = one-fabsf(x); - t = w*0.5f; - p = t * (p0 + t * (p1 + t * (p2 + t * (p3 + t * p4)))); - s = sqrtf(t); - if(ix>=0x3F79999A) { /* if |x| > 0.975 */ - t = pio2_hi-(2.0f*(s+s*p)-pio2_lo); - } else { - int32_t iw; - w = s; - GET_FLOAT_WORD(iw,w); - SET_FLOAT_WORD(w,iw&0xfffff000); - c = (t-w*w)/(s+w); - r = p; - p = 2.0f*s*r-(pio2_lo-2.0f*c); - q = pio4_hi-2.0f*w; - t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; + const double pi2 = 0x1.921fb54442d18p+0; + double xs = x; + double r; + uint32_t ax = asuint (x) << 1; + if (__glibc_unlikely (ax > 0x7f << 24)) + return as_special(x); + if (__glibc_likely (ax < 0x7ec29000u)) + { + if (__glibc_unlikely (ax < 115 << 24)) + return fmaf (x, 0x1p-25, x); + static const double b[] = + { + 0x1.0000000000005p+0, 0x1.55557aeca105dp-3, 0x1.3314ec3db7d12p-4, + 0x1.775738a5a6f92p-5, 0x1.5d5f7ce1c8538p-8, 0x1.605c6d58740fp-2, + -0x1.5728b732d73c6p+1, 0x1.f152170f151ebp+3, -0x1.f962ea3ca992ep+5, + 0x1.71971e17375ap+7, -0x1.860512b4ba23p+8, 0x1.26a3b8d4bdb14p+9, + -0x1.36f2ea5698b51p+9, 0x1.b3d722aebfa2ep+8, -0x1.6cf89703b1289p+7, + 0x1.1518af6a65e2dp+5 + }; + 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 = r; + float lb = r - z * 0x1.efa8ebp-31; + if (ub == lb) + return ub; + } + 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 + }; + double z = xs; + double z2 = z * z; + double c0 = poly12 (z2, c); + r = z + (z * z2) * c0; + } + else + { + if (__glibc_unlikely (ax == 0x7e55688au)) + return copysignf (0x1.75b8a2p-1f, x) + copysignf (0x1p-26f, x); + if (__glibc_unlikely (ax == 0x7e107434u)) + return copysignf (0x1.1f4b64p-1f, x) + copysignf (0x1p-26f, x); + double bx = fabs (xs); + double z = 1.0 - bx; + double s = sqrt (z); + 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 + }; + r = pi2 - s * poly12 (z, c); + r = copysign (r, xs); + } + return r; } libm_alias_finite (__ieee754_asinf, __asinf) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 63fd07fbe0..67beca8ff6 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index a9e3f3a318..a0e8b5bd50 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -7,7 +7,6 @@ Function: "acosh": double: 2 Function: "asin": -float: 1 Function: "asinh": double: 1 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index fc0d001750..7eca3dc8df 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -27,19 +27,15 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 2 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index 855b48e800..4cabe88af1 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 0cc7beccfc..f95e138864 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -27,19 +27,15 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 2 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index a0c3179fc3..d2ab340913 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -27,19 +27,15 @@ double: 2 Function: "asin": double: 1 -float: 1 Function: "asin_downward": double: 1 -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asin_upward": double: 1 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index 05facea37f..d5854a9e82 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -47,25 +47,21 @@ float: 1 Function: "asin": double: 1 -float: 1 float128: 1 ldouble: 2 Function: "asin_downward": double: 1 -float: 1 float128: 2 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 float128: 2 ldouble: 2 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index f553da0caa..d03d25e54a 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -39,22 +39,18 @@ float: 1 Function: "asin": double: 1 -float: 1 ldouble: 2 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 3bf997c5d8..edaa91a4c1 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 2 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 1 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index f85d9caf03..4db2d0231b 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index b788f5730b..2198c93808 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index d46c722ea1..e225f78936 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -13,11 +13,9 @@ Function: "acosh_towardzero": double: 2 Function: "asin": -float: 1 Function: "asin_towardzero": double: 1 -float: 1 Function: "asinh": double: 2 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 8faf5357df..832510e5a5 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -35,22 +35,18 @@ ldouble: 3 Function: "asin": double: 1 -float: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 ldouble: 2 Function: "asinh": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index 85d5e8fcd8..a61e29a0e4 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -83,25 +83,21 @@ float: 2 Function: "asin": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "asin_downward": double: 1 -float: 1 float128: 2 ldouble: 2 Function: "asin_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "asin_upward": double: 2 -float: 1 float128: 2 ldouble: 1