From patchwork Wed Dec 4 16:37:55 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: 847312 Delivered-To: patch@linaro.org Received: by 2002:a5d:434d:0:b0:385:e875:8a9e with SMTP id u13csp432678wrr; Wed, 4 Dec 2024 09:02:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPR63z7/xvGG91pmz1ushoNWA6T7Q27UIWG0kFBJb00zJWpjFsc4JnJMUZeA+PMMAOT2Sd0w==@linaro.org X-Google-Smtp-Source: AGHT+IHy4vu+MAzavMNZIXEtIGa6IL/5jxe4HoE/UxxrUxk0kzc6+TLYM3fYNjOHzd0Gzl01pP89 X-Received: by 2002:a05:6122:2511:b0:515:4fab:301a with SMTP id 71dfb90a1353d-515bf3092e6mr10000467e0c.5.1733331756756; Wed, 04 Dec 2024 09:02:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733331756; cv=pass; d=google.com; s=arc-20240605; b=TojHGDAceWZEp1xkpzyIfTuWRSFDZl5p+cdKnjcNUymrbFjdQCAr6p5Tk6HrgLGp/8 zGpctYfQmoQRzx0o1GXcZscM0VcPOF8E0UFbcKMPA53i7aSczIyFdPdEGr1wcCQdkaO+ RmOhq61TpTfdQJrtOSrDhc3juAfap0H9tYUyAW2QLhSXv9xzWyzURKM7ugGfKkndjc1A mm3R9fzXyN+k/M7MUzL4NmxTFLYI7V3wp4ySFJKgkNfMiIISxSGmvfd8ETRp0Cgmcbg8 fPq5p4Yqwj48Amj1OZdETkVDbvxl+HJWPLBivsZuUdllFKcQvTDCMut12gnzy0EDQ6Kp uhfQ== 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=64qVRHyOb+22SiTt3KZgjBYFXldw7oeO2ddz4P62H+U=; fh=4rGS/xMpTpKARYPd8/6tK882DGKOrg862WI4oHDxNB4=; b=DaFhcyPfchKxNFgIB5YsbaAcDjyunpAlPKRneVHpKZI0hh7XV2+mWnY3tB9n0Cxdai 9Hq9zvE+lSljEaTAtNxvLFBxbHtMrEps9a6rgiQkUTDqAzAQ0SYLXgH5rZJ7QnhVAVO7 8EHs8ZGN8Zyn/53y5U16VMg/8BnWfIrDHJqp8O7mN6chRkTZyOHPs20FPlf5fqPUTz0S SsRCIRUf7gSImp8qt6zt5XWdn3pqB1aT01InwxrM26DjmWtRd7+0glowKXhOOgomK+GT cfNh13Shpw7Umx9gKpNZZYyBVnTHN3UOciNqtNIgYcrj/0FjGME8HhgUvY09HWWnvFMg 2c3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GqQvdVxe; 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 71dfb90a1353d-515cf288ff9si1511867e0c.254.2024.12.04.09.02.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 09:02:36 -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=GqQvdVxe; 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 4AF423858C50 for ; Wed, 4 Dec 2024 17:02:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AF423858C50 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=GqQvdVxe X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 3A2363858402 for ; Wed, 4 Dec 2024 16:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A2363858402 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 3A2363858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330468; cv=none; b=SrTaBhExlmSucZvgKWokdf/VYLgjiH+tm7LhcG7zoUAHlY95XbSiC61PiMM3xnjxwxo7RyRyQqScMQocE6EM3m0WcmMAuDfb28XRUwYwu+hT4DO0BcopPd9T/mCfRDnRUexT5mSH2GvXxDrEeE06b4Lwrf4dgjHvKZmyW+wIfwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733330468; c=relaxed/simple; bh=AgAuR94MKYn8/Vr+2cAxAT2PlAWawqlRdYmiJ0wOTWs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bd6NbPRmrN2JhjQJH7qf2VshdqTrLDXb7j4O9sXZpXs7rhHS8j+O38D8jcqqn96xjw/b3L/KqkI+Xf9y+yMUYsx5lOM9p+l8pmUJefZIxVudFK4Xl8lAseDD91K7wIKRz9VPqVamNOqRZ8CXT329gb21xjG4Zk7EJpJ/hQarNPg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A2363858402 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-215c4000c20so21003405ad.3 for ; Wed, 04 Dec 2024 08:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733330439; x=1733935239; 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=64qVRHyOb+22SiTt3KZgjBYFXldw7oeO2ddz4P62H+U=; b=GqQvdVxe2NzfeBgOc/QvCyCJACijWrmG/uwnC8cdizeUM82bR78tEejj/RxVlhs7GE TmbGKcEXVjI/XjJrnOteN8zRK8AHVSoO7F418E64BHgvwouHmZ+47H4dvllFtpRMgj9j dxnLtwCGMKq1iFzayf5VoN0aSACtKRYEmN4g8WFkjFHyE3YZEtNWi7vaSI+6CISuTkAc s026xYdzXfM/vrB8xkukDz7NQeSTAYdUFNv0JozJytz3I9c6+3FB9gwQikN3w14hdny7 TGFLgrRBvKjebjoHS3awzgsqLwve6b3i86s0uCjNhSEaQrL7g+pYM8BTbjqNSsqlcsn3 ok6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330439; x=1733935239; 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=64qVRHyOb+22SiTt3KZgjBYFXldw7oeO2ddz4P62H+U=; b=f/ShTVdU0ntUdjDwq/YBhcDYdMt2r61NqQciWS+jYOU7M2RycQJ5wp0//4u6bVTDcb tO5Dw/PdrBh4hzCIYOrJrDOfMhDaNccvM1gCYmU9cfyyRP/u2rddtWuzUw8h/Vk4sVqb GWw3Hn5WVB3uax0boTssgDGloDwyyCkfAiTmTb4NpgTFX0GfCQF7nG+iXg8U+8HG837u uSZ12Xk116fMfHbXGX+YyjsK2E/FuAhqbjYYLXDSdovJCqEgphwAUKb49Yih05STze19 zXuYBZkNNMz666u7T5/+vjWR25SKvDnX/8kUU9q6inRLnEcGOnsp5dLhIEhCd00TeJZW hvgA== X-Gm-Message-State: AOJu0Yydam6Ar46boHUctBKuUsgrKMGTYJh2GBxwwG6gunG3XxFrOwXB lMqihnsT/NFDWfSnloeCUB+vt4/tV6D3OEU3lUpbPN/pI4doVxkp+a/FUIvQtF5x5Qvbcgy2cKp 5 X-Gm-Gg: ASbGncuEI+ZbxUI+Y6THNaRsfw+t8/VAvz4qsX9fC8aqK1eV7604V21YpqnyymqQw0+ HW8KH4e95rN3hQvDxbAUo48EMhsDCyIMQlgCbMTGyfOu/g7knwdWn3nlcQsBmZAJti0OBuw9ybl sZz4dIuJRUtp6pH6ZHNXGxZlpsHoplUHddfcUFAmk0AAy+tRtl3yt/HZsxmniPKHdZ6vXub78Q3 6eusYOHF3rTsIELO9HEdq6uIUJj+p9ep0cO+2iZ9IntZs2fWuoi8rUGRJcP/w== X-Received: by 2002:a17:902:e80f:b0:215:5c2e:a2ec with SMTP id d9443c01a7336-215bd1c9de4mr80798675ad.16.1733330439051; Wed, 04 Dec 2024 08:40:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:38 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: DJ Delorie , Joseph Myers , Alexei Sibidanov , Paul Zimmermann Subject: [PATCH v2 20/25] math: Use atanf from CORE-MATH Date: Wed, 4 Dec 2024 13:37:55 -0300 Message-ID: <20241204163949.1408676-21-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 atanf. 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 56.8265 53.6842 5.53% x86_64v2 54.8177 53.6842 2.07% x86_64v3 46.2915 48.7034 -5.21% i686 158.3760 108.9560 31.20% aarch64 (Neoverse) 21.687 20.5893 5.06% power10 13.1903 13.5012 -2.36% reciprocal-throughput master patched improvement x86_64 16.6787 16.7601 -0.49% x86_64v2 16.6983 16.7601 -0.37% x86_64v3 16.2268 12.1391 25.19% i686 138.6840 36.0640 74.00% aarch64 (Neoverse) 11.8012 10.3565 12.24% power10 5.3212 4.2894 19.39% Signed-off-by: Alexei Sibidanov Signed-off-by: Paul Zimmermann Signed-off-by: Adhemerval Zanella --- SHARED-FILES | 4 + sysdeps/aarch64/libm-test-ulps | 8 +- 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 | 8 +- sysdeps/csky/fpu/libm-test-ulps | 4 - sysdeps/csky/nofpu/libm-test-ulps | 4 - sysdeps/hppa/fpu/libm-test-ulps | 4 - sysdeps/i386/fpu/libm-test-ulps | 3 - sysdeps/i386/fpu/s_atanf.S | 30 --- .../i386/i686/fpu/multiarch/libm-test-ulps | 3 - sysdeps/ieee754/flt-32/s_atanf.c | 186 +++++++++--------- sysdeps/loongarch/lp64/libm-test-ulps | 8 +- 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 | 8 +- 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 | 8 +- 27 files changed, 109 insertions(+), 217 deletions(-) delete mode 100644 sysdeps/i386/fpu/s_atanf.S diff --git a/SHARED-FILES b/SHARED-FILES index 18b3244e44..b9627afdfe 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -310,3 +310,7 @@ sysdeps/ieee754/flt-32/s_asinhf.c: (src/binary32/asinh/asinhf.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/s_atanf.c: + (src/binary32/atan/atanf.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 5e17a4b2c3..44934af245 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -99,7 +99,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -135,7 +134,6 @@ float: 1 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_sve": @@ -144,12 +142,10 @@ float: 1 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": @@ -218,7 +214,7 @@ ldouble: 6 Function: Real part of "cacos_towardzero": double: 3 -float: 2 +float: 3 ldouble: 3 Function: Imaginary part of "cacos_towardzero": @@ -263,7 +259,7 @@ ldouble: 5 Function: Imaginary part of "cacosh_towardzero": double: 3 -float: 2 +float: 3 ldouble: 3 Function: Real part of "cacosh_upward": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index 708299915d..f9c1cf7cf5 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index 1c34bd36d6..37b0efae66 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": double: 7 @@ -71,15 +70,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 2 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index 58fc499f53..8d283f0627 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -15,7 +15,6 @@ double: 2 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index a20cb5bcc3..bb4ee0f2e4 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 @@ -70,15 +69,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 @@ -126,7 +122,7 @@ float: 3 Function: Real part of "cacos_towardzero": double: 3 -float: 2 +float: 3 Function: Imaginary part of "cacos_towardzero": double: 5 @@ -162,7 +158,7 @@ float: 3 Function: Imaginary part of "cacosh_towardzero": double: 3 -float: 2 +float: 3 Function: Real part of "cacosh_upward": double: 4 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index 2b7b5cfc92..9d3fcf693d 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -48,7 +48,6 @@ Function: "asinh_upward": double: 3 Function: "atan": -float: 1 Function: "atan2": float: 1 @@ -67,15 +66,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index 0eb62de8b2..1bab8effc7 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -48,7 +48,6 @@ Function: "asinh_upward": double: 3 Function: "atan": -float: 1 Function: "atan2": float: 1 @@ -67,15 +66,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 40ae1806d4..8de00f442b 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 @@ -70,15 +69,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index d1a20a1a98..31286ea178 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -109,19 +109,16 @@ ldouble: 1 Function: "atan_downward": double: 1 -float: 1 float128: 2 ldouble: 1 Function: "atan_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 1 float128: 2 ldouble: 1 diff --git a/sysdeps/i386/fpu/s_atanf.S b/sysdeps/i386/fpu/s_atanf.S deleted file mode 100644 index 4a8f5e3600..0000000000 --- a/sysdeps/i386/fpu/s_atanf.S +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Public domain. - */ - -#include -#include -#include - -RCSID("$NetBSD: s_atanf.S,v 1.3 1995/05/08 23:51:33 jtc Exp $") - -DEFINE_FLT_MIN - -#ifdef PIC -# define MO(op) op##@GOTOFF(%ecx) -#else -# define MO(op) op -#endif - - .text -ENTRY(__atanf) -#ifdef PIC - LOAD_PIC_REG (cx) -#endif - flds 4(%esp) - fld1 - fpatan - FLT_CHECK_FORCE_UFLOW - ret -END (__atanf) -libm_alias_float (__atan, atan) diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index 4e65110265..0a872570d1 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -109,19 +109,16 @@ ldouble: 1 Function: "atan_downward": double: 1 -float: 1 float128: 2 ldouble: 1 Function: "atan_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 1 float128: 2 ldouble: 1 diff --git a/sysdeps/ieee754/flt-32/s_atanf.c b/sysdeps/ieee754/flt-32/s_atanf.c index 3dbf5c5bb7..7a5cf4d5b1 100644 --- a/sysdeps/ieee754/flt-32/s_atanf.c +++ b/sysdeps/ieee754/flt-32/s_atanf.c @@ -1,102 +1,106 @@ -/* s_atanf.c -- float version of s_atan.c. - */ +/* Correctly-rounded arc-tangent of binary32 value. -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ +Copyright (c) 2022-2024 Alexei Sibidanov. -#if defined(LIBM_SCCS) && !defined(lint) -static char rcsid[] = "$NetBSD: s_atanf.c,v 1.4 1995/05/10 20:46:47 jtc Exp $"; -#endif +The original version of this file was copied from the CORE-MATH +project (file src/binary32/atan/atanf.c, revision 01a29dc). -#include -#include -#include -#include -#include +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: -static const float atanhi[] = { - 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ - 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ - 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */ - 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */ -}; +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -static const float atanlo[] = { - 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */ - 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */ - 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */ - 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ -}; +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. +*/ -static const float aT[] = { - 3.3333334327e-01, /* 0x3eaaaaaa */ - -2.0000000298e-01, /* 0xbe4ccccd */ - 1.4285714924e-01, /* 0x3e124925 */ - -1.1111110449e-01, /* 0xbde38e38 */ - 9.0908870101e-02, /* 0x3dba2e6e */ - -7.6918758452e-02, /* 0xbd9d8795 */ - 6.6610731184e-02, /* 0x3d886b35 */ - -5.8335702866e-02, /* 0xbd6ef16b */ - 4.9768779427e-02, /* 0x3d4bda59 */ - -3.6531571299e-02, /* 0xbd15a221 */ - 1.6285819933e-02, /* 0x3c8569d7 */ -}; - -static const float -one = 1.0, -huge = 1.0e30; +#include +#include +#include +#include "math_config.h" -float __atanf(float x) +float +__atanf (float x) { - float w,s1,s2,z; - int32_t ix,hx,id; - - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x4c000000) { /* if |x| >= 2^25 */ - if(ix>0x7f800000) - return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; - } if (ix < 0x3ee00000) { /* |x| < 0.4375 */ - if (ix < 0x31000000) { /* |x| < 2^-29 */ - math_check_force_underflow (x); - if(huge+x>one) return x; /* raise inexact */ - } - id = -1; - } else { - x = fabsf(x); - if (ix < 0x3f980000) { /* |x| < 1.1875 */ - if (ix < 0x3f300000) { /* 7/16 <=|x|<11/16 */ - id = 0; x = ((float)2.0*x-one)/((float)2.0+x); - } else { /* 11/16<=|x|< 19/16 */ - id = 1; x = (x-one)/(x+one); - } - } else { - if (ix < 0x401c0000) { /* |x| < 2.4375 */ - id = 2; x = (x-(float)1.5)/(one+(float)1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; x = -(float)1.0/x; - } - }} - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); - if (id<0) return x - x*(s1+s2); - else { - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return (hx<0)? -z:z; + const double pi2 = 0x1.921fb54442d18p+0; + uint32_t t = asuint (x); + int e = (t >> 23) & 0xff; + bool gt = e >= 127; + uint32_t ta = t & 0x7fffffff; + if (__glibc_unlikely (ta >= 0x4c700518u)) /* |x| > 0x1.e00a3p+25 */ + { + if (ta > 0x7f800000u) + return x + x; /* nan */ + return copysign (pi2, (double) x); + } + if (__glibc_unlikely (e < 127 - 13)) + { + if (__glibc_unlikely (e < 127 - 25)) + { + if (!(t << 1)) + return x; + return fmaf (-x, fabsf (x), x); } + return fmaf (-0x1.5555555555555p-2f * x, x * x, x); + } + /* now |x| >= 0x1p-13 */ + double z = x; + if (gt) + z = 1 / z; /* gt is non-zero for |x| >= 1 */ + double z2 = z * z; + double z4 = z2 * z2; + double z8 = z4 * z4; + /* polynomials generated using rminimax + (https://gitlab.inria.fr/sfilip/rminimax) with the following command: + ./ratapprox --function="atan(x)" --dom=[0.000122070,1] + --num=[x,x^3,x^5,x^7,x^9,x^11,x^13] --den=[1,x^2,x^4,x^6,x^8,x^10,x^12] + --output=atanf.sollya --log (see output atanf.sollya) The coefficient + cd[0] was slightly reduced from the original value 0x1.51eccde075d67p-2 to + avoid an exceptional case for |x| = 0x1.1ad646p-4 and rounding to nearest. + */ + static const double cn[] = + { + 0x1.51eccde075d67p-2, 0x1.a76bb5637f2f2p-1, 0x1.81e0eed20de88p-1, + 0x1.376c8ca67d11dp-2, 0x1.aec7b69202ac6p-5, 0x1.9561899acc73ep-9, + 0x1.bf9fa5b67e6p-16 + }; + static const double cd[] = + { + 0x1.51eccde075d66p-2, 0x1.dfbdd7b392d28p-1, 0x1p+0, + 0x1.fd22bf0e89b54p-2, 0x1.d91ff8b576282p-4, 0x1.653ea99fc9bbp-7, + 0x1.1e7fcc202340ap-12 + }; + double cn0 = cn[0] + z2 * cn[1]; + double cn2 = cn[2] + z2 * cn[3]; + double cn4 = cn[4] + z2 * cn[5]; + double cn6 = cn[6]; + cn0 += z4 * cn2; + cn4 += z4 * cn6; + cn0 += z8 * cn4; + cn0 *= z; + double cd0 = cd[0] + z2 * cd[1]; + double cd2 = cd[2] + z2 * cd[3]; + double cd4 = cd[4] + z2 * cd[5]; + double cd6 = cd[6]; + cd0 += z4 * cd2; + cd4 += z4 * cd6; + cd0 += z8 * cd4; + double r = cn0 / cd0; + if (!gt) + return r; /* for |x| < 1, (float) r is correctly rounded */ + + /* now |x| >= 1 */ + r = copysign (0x1.0fdaa22168c23p-7, z) - r + copysign (0x1.9p0, z); + return r; } libm_alias_float (__atan, atan) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index b24bc582ea..ff1cf6b2e4 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": @@ -162,7 +158,7 @@ ldouble: 6 Function: Real part of "cacos_towardzero": double: 3 -float: 2 +float: 3 ldouble: 3 Function: Imaginary part of "cacos_towardzero": @@ -207,7 +203,7 @@ ldouble: 5 Function: Imaginary part of "cacosh_towardzero": double: 3 -float: 2 +float: 3 ldouble: 3 Function: Real part of "cacosh_upward": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index b7e73db063..5dce4c8f89 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -12,7 +12,6 @@ Function: "asinh": double: 1 Function: "atan": -float: 1 Function: "atan2": float: 1 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index ca4eac5090..9046a17170 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 @@ -70,15 +69,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index 30e8d46c68..1525e55eb5 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index dd972b3063..6edadaed89 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 @@ -70,15 +69,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index 4263ce7aa5..aff536b890 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -51,7 +51,6 @@ double: 3 Function: "atan": double: 1 -float: 1 Function: "atan2": float: 2 @@ -70,15 +69,12 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atan_upward": double: 1 -float: 2 Function: "atanh": double: 2 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index e5aa59fca1..342054bb72 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -87,7 +87,6 @@ ldouble: 7 Function: "atan": double: 1 -float: 1 float128: 1 ldouble: 1 @@ -116,19 +115,16 @@ ldouble: 3 Function: "atan_downward": double: 1 -float: 2 float128: 2 ldouble: 1 Function: "atan_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 float128: 2 ldouble: 2 @@ -202,7 +198,7 @@ ldouble: 8 Function: Real part of "cacos_towardzero": double: 3 -float: 2 +float: 3 float128: 3 ldouble: 7 @@ -256,7 +252,7 @@ ldouble: 8 Function: Imaginary part of "cacosh_towardzero": double: 3 -float: 2 +float: 3 float128: 3 ldouble: 7 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index 939468399c..c7242e5fec 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -71,7 +71,6 @@ ldouble: 7 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -95,17 +94,14 @@ ldouble: 3 Function: "atan_downward": double: 1 -float: 2 ldouble: 1 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 7c89f7915b..4fa17a3da2 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index e1c1a6aee5..0e3fb96ee5 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index f36f0e3f5a..921ff284af 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index 4bd1ff1f98..b429f42d89 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -24,7 +24,6 @@ Function: "asinh_towardzero": double: 2 Function: "atan": -float: 1 Function: "atan2": float: 1 @@ -35,7 +34,6 @@ float: 2 Function: "atan_towardzero": double: 1 -float: 1 Function: "atanh": double: 2 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 0cbfc5be76..ee7eea81f9 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -67,7 +67,6 @@ ldouble: 4 Function: "atan": double: 1 -float: 1 ldouble: 1 Function: "atan2": @@ -91,17 +90,14 @@ ldouble: 2 Function: "atan_downward": double: 1 -float: 2 ldouble: 2 Function: "atan_towardzero": double: 1 -float: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 ldouble: 2 Function: "atanh": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index 5f9afc7f6e..1589403c1c 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -160,7 +160,6 @@ float: 1 Function: "atan": double: 1 -float: 1 float128: 1 ldouble: 1 @@ -209,19 +208,16 @@ float: 2 Function: "atan_downward": double: 1 -float: 2 float128: 2 ldouble: 1 Function: "atan_towardzero": double: 1 -float: 1 float128: 1 ldouble: 1 Function: "atan_upward": double: 1 -float: 2 float128: 2 ldouble: 1 @@ -335,7 +331,7 @@ ldouble: 6 Function: Real part of "cacos_towardzero": double: 3 -float: 2 +float: 3 float128: 3 ldouble: 2 @@ -389,7 +385,7 @@ ldouble: 5 Function: Imaginary part of "cacosh_towardzero": double: 3 -float: 2 +float: 3 float128: 3 ldouble: 2