From patchwork Wed Mar 25 19:22:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 132301 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5E2F74BB3BA0 for ; Wed, 25 Mar 2026 19:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E2F74BB3BA0 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=VIgQ4A7Q X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-vk1-xa2c.google.com (mail-vk1-xa2c.google.com [IPv6:2607:f8b0:4864:20::a2c]) by sourceware.org (Postfix) with ESMTPS id 0D8534BB58E0 for ; Wed, 25 Mar 2026 19:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D8534BB58E0 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 0D8534BB58E0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774466666; cv=none; b=UlG/CaZ4JmP86Ch+uZyxiQVeMjbU3TccdB//dxvXS+iQvOqNRKQ5yCxr1X7GnbAfXK/CFsSlZVRq+L2pc/6Z7kQT6HigHiwZDNt1wWk6qeV5p9qpq1cqssNlejEfou7ZTFe4Epv47rWdYQV1ILxNGu2dIoZpiEQ1T8VOCF/Ay3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774466666; c=relaxed/simple; bh=xoAdhNVrXaWnkWwFkiE1lVEUtgtgr9DXYIbtwUOqoaA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EXCziDEnOtSptiqp192uj3E5//wyj0UCgZTlDi7dLf+BJmlhgxHMQ3GoJHfjhzmFQhXnX4tQy/YlFh+0+BPFXPwz2xaJHs5q3R2wHyhu0tHNA4yU3BcW8cibCA/1WyLtOuOpDRH/nX8YLCVnmxVkJA5avQN0AqN7dwtT/y5zLZA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D8534BB58E0 Received: by mail-vk1-xa2c.google.com with SMTP id 71dfb90a1353d-56cfe7b2344so108761e0c.2 for ; Wed, 25 Mar 2026 12:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774466665; x=1775071465; 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=QEAxk0LyS18Qigpp6rMmTHnzXyQxA1N+oshSNMdTCmg=; b=VIgQ4A7QBJf7gl85V8wRCm7RKyIiD2wHCxfaK5UmBUDCpF6ATptCguivouM/Aw/4RS C7Xl57vyvwb8QiXsvOi+239ysTEeqSsjs+0WW7rt3AgZ5o2SHqLQQGhKAm9T5aFXeRv8 UufxEui0m0sTPlRoaVsS86yTBbG2XLhueMhiJcEoKMDBRLJ5Ly2HcrF43RTh7cDJihOR NUmw6HvXmVCYy/fl4ChdtLnFyWSF14oEFKhUOT4/tXoJ44NwILvOyg/d9kHxogyxqMyq ia5ZhDDgSPKMM1kxayK/ijRWYwEOGVNCbh6aVLYVoglLSVEHTLfPQN7O3pgbuUJ2176i F17A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774466665; x=1775071465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QEAxk0LyS18Qigpp6rMmTHnzXyQxA1N+oshSNMdTCmg=; b=ogCpVBO26hfCuGvmield4R5Bi9/kGjnhvoBjGxPCl3F3Ac4zt0L6i1f1Gvq8Va3ZpE f1EYLavr73vD1OwmHCeSAqJmhpOn9gTmVoz0a7thZ8G+hsEtJ/J1XFW6+NojGMzN6cHq P4V07SvebkPU5uwUAyAu0lJLi47HIrk00Oq6YZ4ARTzjUk5iTmQ0nQnaAJh2vz/OxEkX oe33Wc3pYWtlk+r9Mb7YwiqQqUYCfXhcYTfYHvmyZR4M635kMrTlUdjhKCZzzM0vKB6s sRE41Rl4VhIlqkzF/uOPGJTN18/5l5iHaDMvRyE2Y4Qmm0QGmrle4f/hC634bhMd2jqq 4t6g== X-Gm-Message-State: AOJu0YyxAj9V5h/ZiBOtkK2wGAudI1G7TpruL4tjykHCNZEwa9beLuNU NmlZBAN+0HS8V9M2bgjeMgu638lyYwmVwc89hDDYeS0YwIo7WfbqRiHhcWd0Vj8O5ozmAOlP6Tq +1C5V X-Gm-Gg: ATEYQzyKXt8vjVPKsFIlZYfaTnGaAwYw6N8Y+u8RXRiZPbzmLg/mcDYTbK4ytNwNli3 LetnhtZ7QRjiE9LjTMtKNvX5Nw4bAgIYgXtcDawf/llc/wSvqF6h833gwAa3G+/FDG34XNYMFPf cI6O8k8esxFBEam3uqXVPoHlFLATxt6Dcpuh1pP5cS3JPUXYrBULu2LyBl+DvP7MiARn7b2X+nq GbuHlvnD94aMklCr5z8W73wn7IuV6lMwXH0gbSp29hZBAp0x5/r2ZII2GBNA+1plPvygfidK0RB XCaJId7D5+miGZZoOC3+ynipnKZfcJTP4eU1pTzojmX9wCn5/qBOZwEdxvNAXw8ofuiMk88oSOy lfy1A9tsrpu0TNXWfjH1TotGRotK0Gf1huuWIMWWAudkO33iHp+0CQ9I3Vkmnl4aRyBVzsMkoSR 9Fh4AnKnaNg9Tvi3BBd07xcuAzPAhL9XI2ZZE= X-Received: by 2002:a05:6122:8ce:b0:56c:d623:8967 with SMTP id 71dfb90a1353d-56d220be51cmr2367252e0c.15.1774466664434; Wed, 25 Mar 2026 12:24:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:90ea:f31d:ca7d:f8dd:c20b]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-56d31d394fcsm1040021e0c.12.2026.03.25.12.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 12:24:23 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Paul Zimmermann , DJ Delorie Subject: [PATCH 8/8] math: Remove unused definitions for sinf/cosf/sincosf implementation Date: Wed, 25 Mar 2026 16:22:26 -0300 Message-ID: <20260325192357.1284741-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260325192357.1284741-1-adhemerval.zanella@linaro.org> References: <20260325192357.1284741-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org The reduce_large function has been moved to reduce_aux.h, since it is no longer used in the sinf/cosf/sincosf implementation. The __inv_pio4 is also moved to a new TU (reduce_aux_data). The x86-specific sincosf_poly.h is no longer required. Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, and powerpc64le-linux-gnu. --- math/Makefile | 1 + sysdeps/ieee754/flt-32/reduce_aux.h | 38 ++++- .../flt-32/reduce_aux_data.c} | 39 +---- sysdeps/ieee754/flt-32/s_sincosf.h | 95 ----------- sysdeps/ieee754/flt-32/s_sincosf_data.c | 157 ++++++++++-------- sysdeps/ieee754/flt-32/s_sincosf_data.h | 2 + .../ieee754/flt-32/s_sincosf_data_generic.c | 103 ------------ sysdeps/ieee754/flt-32/sincosf_poly.h | 87 ---------- sysdeps/x86/fpu/sincosf_poly.h | 111 ------------- 9 files changed, 133 insertions(+), 500 deletions(-) rename sysdeps/{x86/fpu/s_sincosf_data.c => ieee754/flt-32/reduce_aux_data.c} (57%) delete mode 100644 sysdeps/ieee754/flt-32/s_sincosf.h delete mode 100644 sysdeps/ieee754/flt-32/s_sincosf_data_generic.c delete mode 100644 sysdeps/ieee754/flt-32/sincosf_poly.h delete mode 100644 sysdeps/x86/fpu/sincosf_poly.h diff --git a/math/Makefile b/math/Makefile index eaea4c77b9..69995406bd 100644 --- a/math/Makefile +++ b/math/Makefile @@ -386,6 +386,7 @@ type-float-routines := \ e_powf_log2_data \ e_sincoshf_data \ math_errf \ + reduce_aux_data \ s_asincosf_data \ s_asincoshf_data \ s_asincospif_data \ diff --git a/sysdeps/ieee754/flt-32/reduce_aux.h b/sysdeps/ieee754/flt-32/reduce_aux.h index b20c4c0c03..3dd77518ff 100644 --- a/sysdeps/ieee754/flt-32/reduce_aux.h +++ b/sysdeps/ieee754/flt-32/reduce_aux.h @@ -21,7 +21,43 @@ #include #include -#include +#include "math_config.h" + +/* 2PI * 2^-64. */ +static const double pi63 = 0x1.921FB54442D18p-62; + +/* Table with 4/PI to 192 bit precision. */ +extern const uint32_t __inv_pio4[] attribute_hidden; + +/* Reduce the range of XI to a multiple of PI/2 using fast integer arithmetic. + XI is a reinterpreted float and must be >= 2.0f (the sign bit is ignored). + Return the modulo between -PI/4 and PI/4 and store the quadrant in NP. + Reduction uses a table of 4/PI with 192 bits of precision. A 32x96->128 bit + multiply computes the exact 2.62-bit fixed-point modulo. Since the result + can have at most 29 leading zeros after the binary point, the double + precision result is accurate to 33 bits. */ +static inline double +reduce_large (uint32_t xi, int *np) +{ + const uint32_t *arr = &__inv_pio4[(xi >> 26) & 15]; + int shift = (xi >> 23) & 7; + uint64_t n, res0, res1, res2; + + xi = (xi & 0xffffff) | 0x800000; + xi <<= shift; + + res0 = xi * arr[0]; + res1 = (uint64_t)xi * arr[4]; + res2 = (uint64_t)xi * arr[8]; + res0 = (res2 >> 32) | (res0 << 32); + res0 += res1; + + n = (res0 + (1ULL << 61)) >> 62; + res0 -= n << 62; + double x = (int64_t)res0; + *np = n; + return x * pi63; +} /* Return h and update n such that: Now x - pi/4 - alpha = h + n*pi/2 mod (2*pi). */ diff --git a/sysdeps/x86/fpu/s_sincosf_data.c b/sysdeps/ieee754/flt-32/reduce_aux_data.c similarity index 57% rename from sysdeps/x86/fpu/s_sincosf_data.c rename to sysdeps/ieee754/flt-32/reduce_aux_data.c index 8e96ecb86e..62abd44d11 100644 --- a/sysdeps/x86/fpu/s_sincosf_data.c +++ b/sysdeps/ieee754/flt-32/reduce_aux_data.c @@ -18,42 +18,7 @@ #include #include -#include -#include - -/* The constants and polynomials for sine and cosine. The 2nd entry - computes -cos (x) rather than cos (x) to get negation for free. */ -const sincos_t __sincosf_table[2] = -{ - { - { 1.0, -1.0, -1.0, 1.0 }, -#if TOINT_INTRINSICS - 0x1.45F306DC9C883p-1, -#else - 0x1.45F306DC9C883p+23, -#endif - 0x1.921FB54442D18p0, - 0x1p0, - -0x1.ffffffd0c621cp-2, - { -0x1.555545995a603p-3, 0x1.55553e1068f19p-5 }, - { 0x1.1107605230bc4p-7, -0x1.6c087e89a359dp-10 }, - { -0x1.994eb3774cf24p-13, 0x1.99343027bf8c3p-16 } - }, - { - { 1.0, -1.0, -1.0, 1.0 }, -#if TOINT_INTRINSICS - 0x1.45F306DC9C883p-1, -#else - 0x1.45F306DC9C883p+23, -#endif - 0x1.921FB54442D18p0, - -0x1p0, - 0x1.ffffffd0c621cp-2, - { -0x1.555545995a603p-3, -0x1.55553e1068f19p-5 }, - { 0x1.1107605230bc4p-7, 0x1.6c087e89a359dp-10 }, - { -0x1.994eb3774cf24p-13, -0x1.99343027bf8c3p-16 } - } -}; +#include "math_config.h" /* Table with 4/PI to 192 bit precision. To avoid unaligned accesses only 8 new bits are added per entry, making the table 4 times larger. */ @@ -66,5 +31,3 @@ const uint32_t __inv_pio4[24] = 0x34ddc0db, 0xddc0db62, 0xc0db6295, 0xdb629599, 0x6295993c, 0x95993c43, 0x993c4390, 0x3c439041 }; - -#include diff --git a/sysdeps/ieee754/flt-32/s_sincosf.h b/sysdeps/ieee754/flt-32/s_sincosf.h deleted file mode 100644 index 553bac9eac..0000000000 --- a/sysdeps/ieee754/flt-32/s_sincosf.h +++ /dev/null @@ -1,95 +0,0 @@ -/* Used by sinf, cosf and sincosf functions. - Copyright (C) 2018-2026 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 -#include "math_config.h" -#include - -/* 2PI * 2^-64. */ -static const double pi63 = 0x1.921FB54442D18p-62; -/* PI / 4. */ -static const float pio4 = 0x1.921FB6p-1f; - -/* Polynomial data (the cosine polynomial is negated in the 2nd entry). */ -extern const sincos_t __sincosf_table[2] attribute_hidden; - -/* Table with 4/PI to 192 bit precision. */ -extern const uint32_t __inv_pio4[] attribute_hidden; - -/* Top 12 bits of the float representation with the sign bit cleared. */ -static inline uint32_t -abstop12 (float x) -{ - return (asuint (x) >> 20) & 0x7ff; -} - -/* Fast range reduction using single multiply-subtract. Return the modulo of - X as a value between -PI/4 and PI/4 and store the quadrant in NP. - The values for PI/2 and 2/PI are accessed via P. Since PI/2 as a double - is accurate to 55 bits and the worst-case cancellation happens at 6 * PI/4, - the result is accurate for |X| <= 120.0. */ -static inline double -reduce_fast (double x, const sincos_t *p, int *np) -{ - double r; -#if TOINT_INTRINSICS - /* Use fast round and lround instructions when available. */ - r = x * p->hpi_inv; - *np = converttoint (r); - return x - roundtoint (r) * p->hpi; -#else - /* Use scaled float to int conversion with explicit rounding. - hpi_inv is prescaled by 2^24 so the quadrant ends up in bits 24..31. - This avoids inaccuracies introduced by truncating negative values. */ - r = x * p->hpi_inv; - int n = ((int32_t)r + 0x800000) >> 24; - *np = n; - return x - n * p->hpi; -#endif -} - -/* Reduce the range of XI to a multiple of PI/2 using fast integer arithmetic. - XI is a reinterpreted float and must be >= 2.0f (the sign bit is ignored). - Return the modulo between -PI/4 and PI/4 and store the quadrant in NP. - Reduction uses a table of 4/PI with 192 bits of precision. A 32x96->128 bit - multiply computes the exact 2.62-bit fixed-point modulo. Since the result - can have at most 29 leading zeros after the binary point, the double - precision result is accurate to 33 bits. */ -static inline double -reduce_large (uint32_t xi, int *np) -{ - const uint32_t *arr = &__inv_pio4[(xi >> 26) & 15]; - int shift = (xi >> 23) & 7; - uint64_t n, res0, res1, res2; - - xi = (xi & 0xffffff) | 0x800000; - xi <<= shift; - - res0 = xi * arr[0]; - res1 = (uint64_t)xi * arr[4]; - res2 = (uint64_t)xi * arr[8]; - res0 = (res2 >> 32) | (res0 << 32); - res0 += res1; - - n = (res0 + (1ULL << 61)) >> 62; - res0 -= n << 62; - double x = (int64_t)res0; - *np = n; - return x * pi63; -} diff --git a/sysdeps/ieee754/flt-32/s_sincosf_data.c b/sysdeps/ieee754/flt-32/s_sincosf_data.c index 8c914a8bf6..2a85b687dd 100644 --- a/sysdeps/ieee754/flt-32/s_sincosf_data.c +++ b/sysdeps/ieee754/flt-32/s_sincosf_data.c @@ -1,76 +1,103 @@ -/* Compute sine and cosine of argument. - Copyright (C) 2018-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. +/* Correctly-rounded sine of binary32 value. + +Copyright (c) 2022-2026 Alexei Sibidanov. + +The original version of this file was copied from the CORE-MATH +project (file src/binary32/cosh/coshf.c, revision 8ea8ea35. - 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. +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 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. +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 the GNU C 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. +*/ -#include -#include -#include "math_config.h" -#include "s_sincosf.h" +#include -/* The constants and polynomials for sine and cosine. The 2nd entry - computes -cos (x) rather than cos (x) to get negation for free. */ -const sincos_t __sincosf_table[2] = +const uint64_t __sinf_ipi[] = { - { - { 1.0, -1.0, -1.0, 1.0 }, -#if TOINT_INTRINSICS - 0x1.45F306DC9C883p-1, -#else - 0x1.45F306DC9C883p+23, -#endif - 0x1.921FB54442D18p0, - 0x1p0, - -0x1.ffffffd0c621cp-2, - 0x1.55553e1068f19p-5, - -0x1.6c087e89a359dp-10, - 0x1.99343027bf8c3p-16, - -0x1.555545995a603p-3, - 0x1.1107605230bc4p-7, - -0x1.994eb3774cf24p-13 - }, - { - { 1.0, -1.0, -1.0, 1.0 }, -#if TOINT_INTRINSICS - 0x1.45F306DC9C883p-1, -#else - 0x1.45F306DC9C883p+23, -#endif - 0x1.921FB54442D18p0, - -0x1p0, - 0x1.ffffffd0c621cp-2, - -0x1.55553e1068f19p-5, - 0x1.6c087e89a359dp-10, - -0x1.99343027bf8c3p-16, - -0x1.555545995a603p-3, - 0x1.1107605230bc4p-7, - -0x1.994eb3774cf24p-13 - } + 0xfe5163abdebbc562, 0xdb6295993c439041, 0xfc2757d1f534ddc0, + 0xa2f9836e4e441529 }; -/* Table with 4/PI to 192 bit precision. To avoid unaligned accesses - only 8 new bits are added per entry, making the table 4 times larger. */ -const uint32_t __inv_pio4[24] = +const double __sinf_b[] = { - 0xa2, 0xa2f9, 0xa2f983, 0xa2f9836e, - 0xf9836e4e, 0x836e4e44, 0x6e4e4415, 0x4e441529, - 0x441529fc, 0x1529fc27, 0x29fc2757, 0xfc2757d1, - 0x2757d1f5, 0x57d1f534, 0xd1f534dd, 0xf534ddc0, - 0x34ddc0db, 0xddc0db62, 0xc0db6295, 0xdb629599, - 0x6295993c, 0x95993c43, 0x993c4390, 0x3c439041 + 0x1.3bd3cc9be45dcp-6, -0x1.03c1f081b0833p-14, 0x1.55d3c6fc9ac1fp-24, + -0x1.e1d3ff281b40dp-35 +}; +const double __sinf_a[] = +{ + 0x1.921fb54442d17p-3, -0x1.4abbce6256a39p-10, 0x1.466bc5a518c16p-19, + -0x1.32bdc61074ff6p-29 +}; +const double __sinf_tb[] = +{ + 0x0p+0, 0x1.8f8b83c69a60bp-3, 0x1.87de2a6aea963p-2, + 0x1.1c73b39ae68c8p-1, 0x1.6a09e667f3bcdp-1, 0x1.a9b66290ea1a3p-1, + 0x1.d906bcf328d46p-1, 0x1.f6297cff75cbp-1, 0x1p+0, + 0x1.f6297cff75cbp-1, 0x1.d906bcf328d46p-1, 0x1.a9b66290ea1a3p-1, + 0x1.6a09e667f3bcdp-1, 0x1.1c73b39ae68c8p-1, 0x1.87de2a6aea963p-2, + 0x1.8f8b83c69a60bp-3, 0x0p+0, -0x1.8f8b83c69a60bp-3, + -0x1.87de2a6aea963p-2, -0x1.1c73b39ae68c8p-1, -0x1.6a09e667f3bcdp-1, + -0x1.a9b66290ea1a3p-1, -0x1.d906bcf328d46p-1, -0x1.f6297cff75cbp-1, + -0x1p+0, -0x1.f6297cff75cbp-1, -0x1.d906bcf328d46p-1, + -0x1.a9b66290ea1a3p-1, -0x1.6a09e667f3bcdp-1, -0x1.1c73b39ae68c8p-1, + -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3 }; -#include +const double __cosf_tb[] = +{ + 0x1p+0, 0x1.f6297cff75cbp-1, 0x1.d906bcf328d46p-1, + 0x1.a9b66290ea1a3p-1, 0x1.6a09e667f3bcdp-1, 0x1.1c73b39ae68c8p-1, + 0x1.87de2a6aea963p-2, 0x1.8f8b83c69a60bp-3, 0x0p+0, + -0x1.8f8b83c69a60bp-3, -0x1.87de2a6aea963p-2, -0x1.1c73b39ae68c8p-1, + -0x1.6a09e667f3bcdp-1, -0x1.a9b66290ea1a3p-1, -0x1.d906bcf328d46p-1, + -0x1.f6297cff75cbp-1, -0x1p+0, -0x1.f6297cff75cbp-1, + -0x1.d906bcf328d46p-1, -0x1.a9b66290ea1a3p-1, -0x1.6a09e667f3bcdp-1, + -0x1.1c73b39ae68c8p-1, -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3, + 0x0p+0, 0x1.8f8b83c69a60bp-3, 0x1.87de2a6aea963p-2, + 0x1.1c73b39ae68c8p-1, 0x1.6a09e667f3bcdp-1, 0x1.a9b66290ea1a3p-1, + 0x1.d906bcf328d46p-1, 0x1.f6297cff75cbp-1 +}; + +const sincosf_database_t __sinf_st[] = +{ + { { 0x1.33333p+13 }, -0x1.63f4bap-2, -0x1p-27 }, + { { 0x1.75b8a2p-1 }, 0x1.55688ap-1, -0x1p-26 }, + { { 0x1.4f0654p+0 }, 0x1.ee836cp-1, -0x1p-26 }, + { { 0x1.2d97c8p+3 }, -0x1.99bc5ap-26, -0x1p-51 }, +}; + +const sincosf_database_t __cosf_st[] = +{ + { { 0x1.2d97c8p+2 }, 0x1.99bc5cp-27, -0x1p-52 }, + { { 0x1.4555p+51 }, 0x1.115d7ep-1, -0x1p-26 }, + { { 0x1.48a858p+54 }, 0x1.f48148p-2, 0x1p-27 }, + { { 0x1.3170fp+63 }, 0x1.fe2976p-1, 0x1p-26 }, + { { 0x1.2b9622p+67 }, 0x1.f0285ep-1, -0x1p-26 }, +}; + +const sincosf2_database_t __sincosf_st[] = +{ + { { 0x1.33333p+13 }, -0x1.63f4bap-2, -0x1p-27, -0x1.e01216p-1, -0x1p-26 }, + { { 0x1.75b8a2p-1 }, 0x1.55688ap-1, -0x1p-26, 0x1.7d8e1ep-1, 0x1p-26 }, + { { 0x1.4f0654p+0 }, 0x1.ee836cp-1, -0x1p-26, 0x1.09558p-2, -0x1p-27 }, + { { 0x1.2d97c8p+3 }, -0x1.99bc5ap-26, -0x1p-51, -0x1p+0, 0x1p-25 }, + { { 0x1.2d97c8p+2 }, -0x1p+0, 0x1p-25, 0x1.99bc5cp-27, -0x1p-52 }, + { { 0x1.4555p+51 }, -0x1.b0ea44p-1, 0x1p-26, 0x1.115d7ep-1, -0x1p-26 }, + { { 0x1.48a858p+54 }, 0x1.beac8cp-1, 0x1p-26, 0x1.f48148p-2, 0x1p-27 }, + { { 0x1.3170fp+63 }, 0x1.5ac1eep-4, -0x1p-30, 0x1.fe2976p-1, 0x1p-26 }, + { { 0x1.2b9622p+67 }, -0x1.f983c2p-3, 0x1p-28, 0x1.f0285ep-1, -0x1p-26 }, +}; diff --git a/sysdeps/ieee754/flt-32/s_sincosf_data.h b/sysdeps/ieee754/flt-32/s_sincosf_data.h index 354e9b6a88..ca7164de52 100644 --- a/sysdeps/ieee754/flt-32/s_sincosf_data.h +++ b/sysdeps/ieee754/flt-32/s_sincosf_data.h @@ -19,6 +19,8 @@ #ifndef _S_SINCOSF_DATA_H #define _S_SINCOSF_DATA_H +#include + extern const uint64_t __sinf_ipi[] attribute_hidden; #define IPI __sinf_ipi diff --git a/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c b/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c deleted file mode 100644 index 2a85b687dd..0000000000 --- a/sysdeps/ieee754/flt-32/s_sincosf_data_generic.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Correctly-rounded sine of binary32 value. - -Copyright (c) 2022-2026 Alexei Sibidanov. - -The original version of this file was copied from the CORE-MATH -project (file src/binary32/cosh/coshf.c, revision 8ea8ea35. - -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 - -const uint64_t __sinf_ipi[] = -{ - 0xfe5163abdebbc562, 0xdb6295993c439041, 0xfc2757d1f534ddc0, - 0xa2f9836e4e441529 -}; - -const double __sinf_b[] = -{ - 0x1.3bd3cc9be45dcp-6, -0x1.03c1f081b0833p-14, 0x1.55d3c6fc9ac1fp-24, - -0x1.e1d3ff281b40dp-35 -}; -const double __sinf_a[] = -{ - 0x1.921fb54442d17p-3, -0x1.4abbce6256a39p-10, 0x1.466bc5a518c16p-19, - -0x1.32bdc61074ff6p-29 -}; -const double __sinf_tb[] = -{ - 0x0p+0, 0x1.8f8b83c69a60bp-3, 0x1.87de2a6aea963p-2, - 0x1.1c73b39ae68c8p-1, 0x1.6a09e667f3bcdp-1, 0x1.a9b66290ea1a3p-1, - 0x1.d906bcf328d46p-1, 0x1.f6297cff75cbp-1, 0x1p+0, - 0x1.f6297cff75cbp-1, 0x1.d906bcf328d46p-1, 0x1.a9b66290ea1a3p-1, - 0x1.6a09e667f3bcdp-1, 0x1.1c73b39ae68c8p-1, 0x1.87de2a6aea963p-2, - 0x1.8f8b83c69a60bp-3, 0x0p+0, -0x1.8f8b83c69a60bp-3, - -0x1.87de2a6aea963p-2, -0x1.1c73b39ae68c8p-1, -0x1.6a09e667f3bcdp-1, - -0x1.a9b66290ea1a3p-1, -0x1.d906bcf328d46p-1, -0x1.f6297cff75cbp-1, - -0x1p+0, -0x1.f6297cff75cbp-1, -0x1.d906bcf328d46p-1, - -0x1.a9b66290ea1a3p-1, -0x1.6a09e667f3bcdp-1, -0x1.1c73b39ae68c8p-1, - -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3 -}; - -const double __cosf_tb[] = -{ - 0x1p+0, 0x1.f6297cff75cbp-1, 0x1.d906bcf328d46p-1, - 0x1.a9b66290ea1a3p-1, 0x1.6a09e667f3bcdp-1, 0x1.1c73b39ae68c8p-1, - 0x1.87de2a6aea963p-2, 0x1.8f8b83c69a60bp-3, 0x0p+0, - -0x1.8f8b83c69a60bp-3, -0x1.87de2a6aea963p-2, -0x1.1c73b39ae68c8p-1, - -0x1.6a09e667f3bcdp-1, -0x1.a9b66290ea1a3p-1, -0x1.d906bcf328d46p-1, - -0x1.f6297cff75cbp-1, -0x1p+0, -0x1.f6297cff75cbp-1, - -0x1.d906bcf328d46p-1, -0x1.a9b66290ea1a3p-1, -0x1.6a09e667f3bcdp-1, - -0x1.1c73b39ae68c8p-1, -0x1.87de2a6aea963p-2, -0x1.8f8b83c69a60bp-3, - 0x0p+0, 0x1.8f8b83c69a60bp-3, 0x1.87de2a6aea963p-2, - 0x1.1c73b39ae68c8p-1, 0x1.6a09e667f3bcdp-1, 0x1.a9b66290ea1a3p-1, - 0x1.d906bcf328d46p-1, 0x1.f6297cff75cbp-1 -}; - -const sincosf_database_t __sinf_st[] = -{ - { { 0x1.33333p+13 }, -0x1.63f4bap-2, -0x1p-27 }, - { { 0x1.75b8a2p-1 }, 0x1.55688ap-1, -0x1p-26 }, - { { 0x1.4f0654p+0 }, 0x1.ee836cp-1, -0x1p-26 }, - { { 0x1.2d97c8p+3 }, -0x1.99bc5ap-26, -0x1p-51 }, -}; - -const sincosf_database_t __cosf_st[] = -{ - { { 0x1.2d97c8p+2 }, 0x1.99bc5cp-27, -0x1p-52 }, - { { 0x1.4555p+51 }, 0x1.115d7ep-1, -0x1p-26 }, - { { 0x1.48a858p+54 }, 0x1.f48148p-2, 0x1p-27 }, - { { 0x1.3170fp+63 }, 0x1.fe2976p-1, 0x1p-26 }, - { { 0x1.2b9622p+67 }, 0x1.f0285ep-1, -0x1p-26 }, -}; - -const sincosf2_database_t __sincosf_st[] = -{ - { { 0x1.33333p+13 }, -0x1.63f4bap-2, -0x1p-27, -0x1.e01216p-1, -0x1p-26 }, - { { 0x1.75b8a2p-1 }, 0x1.55688ap-1, -0x1p-26, 0x1.7d8e1ep-1, 0x1p-26 }, - { { 0x1.4f0654p+0 }, 0x1.ee836cp-1, -0x1p-26, 0x1.09558p-2, -0x1p-27 }, - { { 0x1.2d97c8p+3 }, -0x1.99bc5ap-26, -0x1p-51, -0x1p+0, 0x1p-25 }, - { { 0x1.2d97c8p+2 }, -0x1p+0, 0x1p-25, 0x1.99bc5cp-27, -0x1p-52 }, - { { 0x1.4555p+51 }, -0x1.b0ea44p-1, 0x1p-26, 0x1.115d7ep-1, -0x1p-26 }, - { { 0x1.48a858p+54 }, 0x1.beac8cp-1, 0x1p-26, 0x1.f48148p-2, 0x1p-27 }, - { { 0x1.3170fp+63 }, 0x1.5ac1eep-4, -0x1p-30, 0x1.fe2976p-1, 0x1p-26 }, - { { 0x1.2b9622p+67 }, -0x1.f983c2p-3, 0x1p-28, 0x1.f0285ep-1, -0x1p-26 }, -}; diff --git a/sysdeps/ieee754/flt-32/sincosf_poly.h b/sysdeps/ieee754/flt-32/sincosf_poly.h deleted file mode 100644 index ee862919e8..0000000000 --- a/sysdeps/ieee754/flt-32/sincosf_poly.h +++ /dev/null @@ -1,87 +0,0 @@ -/* Used by sinf, cosf and sincosf functions. - Copyright (C) 2018-2026 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 - . */ - -/* The constants and polynomials for sine and cosine. */ -typedef struct -{ - double sign[4]; /* Sign of sine in quadrants 0..3. */ - double hpi_inv; /* 2 / PI ( * 2^24 if !TOINT_INTRINSICS). */ - double hpi; /* PI / 2. */ - double c0, c1, c2, c3, c4; /* Cosine polynomial. */ - double s1, s2, s3; /* Sine polynomial. */ -} sincos_t; - -/* Compute the sine and cosine of inputs X and X2 (X squared), using the - polynomial P and store the results in SINP and COSP. N is the quadrant, - if odd the cosine and sine polynomials are swapped. */ -static inline void -sincosf_poly (double x, double x2, const sincos_t *p, int n, float *sinp, - float *cosp) -{ - double x3, x4, x5, x6, s, c, c1, c2, s1; - - x4 = x2 * x2; - x3 = x2 * x; - c2 = p->c3 + x2 * p->c4; - s1 = p->s2 + x2 * p->s3; - - /* Swap sin/cos result based on quadrant. */ - float *tmp = (n & 1 ? cosp : sinp); - cosp = (n & 1 ? sinp : cosp); - sinp = tmp; - - c1 = p->c0 + x2 * p->c1; - x5 = x3 * x2; - x6 = x4 * x2; - - s = x + x3 * p->s1; - c = c1 + x4 * p->c2; - - *sinp = s + x5 * s1; - *cosp = c + x6 * c2; -} - -/* Return the sine of inputs X and X2 (X squared) using the polynomial P. - N is the quadrant, and if odd the cosine polynomial is used. */ -static inline float -sinf_poly (double x, double x2, const sincos_t *p, int n) -{ - double x3, x4, x6, x7, s, c, c1, c2, s1; - - if ((n & 1) == 0) - { - x3 = x * x2; - s1 = p->s2 + x2 * p->s3; - - x7 = x3 * x2; - s = x + x3 * p->s1; - - return s + x7 * s1; - } - else - { - x4 = x2 * x2; - c2 = p->c3 + x2 * p->c4; - c1 = p->c0 + x2 * p->c1; - - x6 = x4 * x2; - c = c1 + x4 * p->c2; - - return c + x6 * c2; - } -} diff --git a/sysdeps/x86/fpu/sincosf_poly.h b/sysdeps/x86/fpu/sincosf_poly.h deleted file mode 100644 index 211d36efa5..0000000000 --- a/sysdeps/x86/fpu/sincosf_poly.h +++ /dev/null @@ -1,111 +0,0 @@ -/* Used by sinf, cosf and sincosf functions. X86-64 version. - Copyright (C) 2018-2026 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 - . */ - -typedef double v2df_t __attribute__ ((vector_size (2 * sizeof (double)))); - -#ifdef __SSE2_MATH__ -typedef float v4sf_t __attribute__ ((vector_size (4 * sizeof (float)))); - -static inline void -v2df_to_sf (v2df_t v2df, float *f0p, float *f1p) -{ - v4sf_t v4sf = __builtin_ia32_cvtpd2ps (v2df); - *f0p = v4sf[0]; - *f1p = v4sf[1]; -} -#else -static inline void -v2df_to_sf (v2df_t v2df, float *f0p, float *f1p) -{ - *f0p = (float) v2df[0]; - *f1p = (float) v2df[1]; -} -#endif - -/* The constants and polynomials for sine and cosine. */ -typedef struct -{ - double sign[4]; /* Sign of sine in quadrants 0..3. */ - double hpi_inv; /* 2 / PI ( * 2^24 if !TOINT_INTRINSICS). */ - double hpi; /* PI / 2. */ - /* Cosine polynomial: c0, c1, c2, c3, c4. - Sine polynomial: s1, s2, s3. */ - double c0, c1; - v2df_t s1c2, s2c3, s3c4; -} sincos_t; - -/* Compute the sine and cosine of inputs X and X2 (X squared), using the - polynomial P and store the results in SINP and COSP. N is the quadrant, - if odd the cosine and sine polynomials are swapped. */ -static inline void -sincosf_poly (double x, double x2, const sincos_t *p, int n, float *sinp, - float *cosp) -{ - v2df_t vx2x2 = { x2, x2 }; - v2df_t vxx2 = { x, x2 }; - v2df_t vx3x4, vs1c2; - - vx3x4 = vx2x2 * vxx2; - vs1c2 = p->s2c3 + vx2x2 * p->s3c4; - - /* Swap sin/cos result based on quadrant. */ - if (n & 1) - { - float *tmp = cosp; - cosp = sinp; - sinp = tmp; - } - - double c1 = p->c0 + x2 * p->c1; - v2df_t vxc1 = { x, c1 }; - v2df_t vx5x6 = vx3x4 * vx2x2; - - v2df_t vsincos = vxc1 + vx3x4 * p->s1c2; - vsincos = vsincos + vx5x6 * vs1c2; - v2df_to_sf (vsincos, sinp, cosp); -} - -/* Return the sine of inputs X and X2 (X squared) using the polynomial P. - N is the quadrant, and if odd the cosine polynomial is used. */ -static inline float -sinf_poly (double x, double x2, const sincos_t *p, int n) -{ - double x3, x4, x6, x7, s, c, c1, c2, s1; - - if ((n & 1) == 0) - { - x3 = x * x2; - s1 = p->s2c3[0] + x2 * p->s3c4[0]; - - x7 = x3 * x2; - s = x + x3 * p->s1c2[0]; - - return s + x7 * s1; - } - else - { - x4 = x2 * x2; - c2 = p->s2c3[1] + x2 * p->s3c4[1]; - c1 = p->c0 + x2 * p->c1; - - x6 = x4 * x2; - c = c1 + x4 * p->s1c2[1]; - - return c + x6 * c2; - } -}