From patchwork Thu Feb 13 19:35:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 864837 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1f8a:b0:38f:210b:807b with SMTP id hj10csp21769wrb; Thu, 13 Feb 2025 11:42:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUUO65Y01srA2VXSYYMEJffoW5SCnY1XZZpR1KDVoZVW1RczWeX+2Z+sPjK1VkiieyE0dv5qg==@linaro.org X-Google-Smtp-Source: AGHT+IGhNX9GSqvPhY7fLqiZbKGbNQlunvQyoGpO4m5jKlu8XvRnr4tXbgXCIg9u0mEExGA4gBVj X-Received: by 2002:a05:620a:4884:b0:7c0:8175:3651 with SMTP id af79cd13be357-7c08175375dmr232816485a.43.1739475750368; Thu, 13 Feb 2025 11:42:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1739475750; cv=pass; d=google.com; s=arc-20240605; b=i4hAfFexeYbcRg7Mh1ofmidILO3iMJxxSSut5nP9JSyNINAgXkBKL3nUHLvJ4L9H9C y8DBJ8koC8y4QROp/c8djFTnreSjReTHRIz2W3pPcFHUPR9Esn76gzPvwsmMSFxrInqK TjBx7RWf8pseIAGk9A+yTWuNclZca6ObXv4s14EIPLsJxZb2NPLR5CDo4kMIst4B5+5m Umeo4v9HbPgT/b+2qAUK+l6EZ78n36MVOStLoiEpsczbR/FyUX+p8iilA//v+kYT5zwM vNjHE4xREJw71BIFvolJqJEX2HnmwyVm+LUIMLk8S4PmIVxtNMNJccf27USqqJvUmHcH 8uVw== 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=xKgBr9gVvks5ndCD4MpeatQgQnB7PXAtH5E3+pc5X4M=; fh=ePm/olesskOIJSEHC0fDGlPq/ahiqJ2eRb/zEUaK+C4=; b=Xp7Ball1SyXzdk5MxncNZwWyh8mKIB3WQAWYFBsqchlltH90E4UJqb+5bTWTMJRQiN Kj6BneOBiRVpjqPlQcXgEOUqxuNtjLamu7h2Uv1fxoS13IaBZGc/YNz3SUlHbzEzvDdT Q5mGTbI93WoMCQdaqLjUeck0hW0KJcRHeGf/VEJ1tULWcpjthyQSlEbniKmcP9DXbe/Y nRmcep6pWZlEWkL1HKoZvqsrhXWVSKALgxfpYhXMV3LVa4dGo0Ga4vcUhD+lyTE9PZj4 NVm/+/fRzSP7mgL5jDSjXSHo9Z/bTiFIoJnkXMPLVynOThBc1hIrRASzVS4F+W+vJEZd rpmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Up7ubuWw; 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-7c07c81d543si177841385a.145.2025.02.13.11.42.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 11:42:30 -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=Up7ubuWw; 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 B66FE3858C2B for ; Thu, 13 Feb 2025 19:42:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B66FE3858C2B 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=Up7ubuWw X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 409713858C41 for ; Thu, 13 Feb 2025 19:37:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 409713858C41 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 409713858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::236 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739475471; cv=none; b=H2WXrLeY0ChCzj23sN11n039zGaZJzQNdgQUWT7MbBT1EEP8yAv6K9JrCQ/fB+oYsTMF1FcRM3GSjMKR0BG8cCKTSLL4dzPXV9bmmo6O26jzxuBksoKJtVGQCcrHXw6xYSTLwJqw9iZ2QiggbHJe1J5OqH2t9WftnLok03Ug/mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739475471; c=relaxed/simple; bh=cuyPHaNeGyQcFWekNbhU58227PgAyMVrZq8GQXvg7Is=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i4kQkm0Hq3K21ulkqv2Dp/FqgT3JRLaOfPp1CT6miZ4N3Io7UPfoLuQDDDEm/WquWOIS/JafbYdeRslWoB2EXrEcZTV/uaDkqUbVvhx2NJ0+8IVLUwhZCl1bcn/zse3TaIfx/1KoBdmj56uUIiDmUYM+l48Jlc+ZUD0MwdhoKeQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 409713858C41 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3f3a97b3e26so764790b6e.2 for ; Thu, 13 Feb 2025 11:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739475470; x=1740080270; 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=xKgBr9gVvks5ndCD4MpeatQgQnB7PXAtH5E3+pc5X4M=; b=Up7ubuWwC4XxYcjZ1Jvl9JDH7CLBAytPj1tmwujdj6p6x8oV3mtPZUjb+cTZOgSYRA YoeLXKce9hljxN9LLfdJ+V/zJ2qmryaWZUzNSw6cYaMCNVxvJKmRMZMPa3fX0ga+2rp6 gBRZ2395cEdhnxgQsobUqeSBPyJ3KLUHikBxjiF7nOnJpTrL9UQiEBsYdZql4nua2HpK MvsaXI4D5KF2KbYKgYorWY7mZcEqoQqeFYJ1oVJDJHFyprpwuSx1MGMYj39XOEkGbL7E o+E7T3dgbyxvivwe1pn8N14VLD2yWnnjx2n5xJ4RpxmYcDkKSpO94PyAzwNioq9YbPRi jDiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739475470; x=1740080270; 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=xKgBr9gVvks5ndCD4MpeatQgQnB7PXAtH5E3+pc5X4M=; b=AsXvcARFs9a46I4FfnXNheTO3rCik1JqdnkbK626vr1/UOj+TEhAb+XONkPgEzBYkW LTJ5QlBLBx2266wTWwz6z1SnlygK58t5qti82d1/f9d9+GZXO4Rb5jca8ILGyNauWh0y swpGytySCwbtlpOvGgEU5/cGYD3Pw2KP7IcqJJGSFrFL3txJ05o6qHkG/fZdaD6r4aoE EmiOjvcoaGybV7yRiEI8TTz7a7GZmhAk7ZQjtfXrCrjXkxw9WKydmIjGBuF5G/EiTfLX g90CYRUuzwoWOkPA2WVgQF2e/1At9lfTA99qO43cbET7bZyL1JMkKpv5ViDueAuohYTh ftHw== X-Gm-Message-State: AOJu0YzR3UZPKEutungYsiTo4WMnxRrQ0ovbchK2nILnQrF/F8vCRLBC rUsmZaTkf9KuR4aBzTJEeJTuJgP/uoedEwwEuhw1ocUbWPQyXD0oeo7kZr0DDxURldyJdSXBmQt D X-Gm-Gg: ASbGncvAJC6EkKdla8ttlYJans7XWbExwzr4S071G/nGDvEZRJCdMgTgTXCPU51byJP qnFlZIH2+tNaQnhHVIeE+rjnDP3xaMWTLyRFW/anthzG26Up9trNzvPm7L6HPYv6rI8+amz2Dkl A4msegGrjtBOx40LYOyuCXDDyzRP+QytAwAz05vR4F9FyvVsSsqJuYfJ9tjFpX2I0vKauDL4IUT 562I2itoEPlDzIg4TCvtzN5PIFdFDguCPElbNTpWvvA/ACuxT1YjRwYgCBDETSWQVjlTEH4poRg 7+GnE19Sam2RKUDsgzeFW0BjJ0pR X-Received: by 2002:a05:6808:3090:b0:3f3:b38f:30a4 with SMTP id 5614622812f47-3f3cd728920mr5438829b6e.29.1739475470047; Thu, 13 Feb 2025 11:37:50 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:5d67:f7e1:d030:f4d6:f917]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f3daa1a4b8sm787005b6e.49.2025.02.13.11.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 11:37:49 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "Andreas K . Huettel" , Paul Zimmermann , Alexei Sibidanov , DJ Delorie Subject: [PATCH v2 3/3] math: Consolidate acosf and asinf internal tables Date: Thu, 13 Feb 2025 16:35:45 -0300 Message-ID: <20250213193737.3784065-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213193737.3784065-1-adhemerval.zanella@linaro.org> References: <20250213193737.3784065-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 libm size improvement built with gcc-14, "--enable-stack-protector=strong --enable-bind-now=yes --enable-fortify-source=2": Before: 582292 844 12 583148 8e5ec aarch64-linux-gnu/math/libm.so 975133 1076 12 976221 ee55d x86_64-linux-gnu/math/libm.so 1203586 5608 368 1209562 1274da powerpc64le-linux-gnu/math/libm.so After: 581972 844 12 582828 8e4ac aarch64-linux-gnu/math/libm.so 974941 1076 12 976029 ee49d x86_64-linux-gnu/math/libm.so 1203394 5608 368 1209370 12741a powerpc64le-linux-gnu/math/libm.so Reviewed-by: Andreas K. Huettel --- math/Makefile | 1 + sysdeps/ieee754/flt-32/e_acosf.c | 19 ++--------- sysdeps/ieee754/flt-32/e_asinf.c | 19 ++--------- sysdeps/ieee754/flt-32/s_asincosf_data.c | 43 ++++++++++++++++++++++++ sysdeps/ieee754/flt-32/s_asincosf_data.h | 35 +++++++++++++++++++ 5 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 sysdeps/ieee754/flt-32/s_asincosf_data.c create mode 100644 sysdeps/ieee754/flt-32/s_asincosf_data.h diff --git a/math/Makefile b/math/Makefile index 43e0e365eb..6dab60095b 100644 --- a/math/Makefile +++ b/math/Makefile @@ -368,6 +368,7 @@ type-float-routines := \ e_powf_log2_data \ e_sincoshf_data \ math_errf \ + s_asincosf_data \ s_asincoshf_data \ s_asincospif_data \ s_sincosf_data \ diff --git a/sysdeps/ieee754/flt-32/e_acosf.c b/sysdeps/ieee754/flt-32/e_acosf.c index a5a4de4fc2..820e929864 100644 --- a/sysdeps/ieee754/flt-32/e_acosf.c +++ b/sysdeps/ieee754/flt-32/e_acosf.c @@ -30,6 +30,7 @@ SOFTWARE. #include #include #include "math_config.h" +#include "s_asincosf_data.h" static __attribute__ ((noinline)) float as_special (float x) @@ -110,33 +111,19 @@ __ieee754_acosf (float x) /* 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); + r = (pi2 - xs) - (xs * x2) * poly12 (x2, C0); } 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); + r = o[t >> 31] + s * poly12 (z, C1); } return r; } diff --git a/sysdeps/ieee754/flt-32/e_asinf.c b/sysdeps/ieee754/flt-32/e_asinf.c index 944bf6f5ce..c6972d2122 100644 --- a/sysdeps/ieee754/flt-32/e_asinf.c +++ b/sysdeps/ieee754/flt-32/e_asinf.c @@ -28,6 +28,7 @@ SOFTWARE. #include #include #include "math_config.h" +#include "s_asincosf_data.h" static __attribute__ ((noinline)) float as_special (float x) @@ -95,16 +96,9 @@ __ieee754_asinf (float x) } 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); + double c0 = poly12 (z2, C0); r = z + (z * z2) * c0; } else @@ -116,14 +110,7 @@ __ieee754_asinf (float 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 = pi2 - s * poly12 (z, C1); r = copysign (r, xs); } return r; diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.c b/sysdeps/ieee754/flt-32/s_asincosf_data.c new file mode 100644 index 0000000000..0399ecc975 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.c @@ -0,0 +1,43 @@ +/* Common data for asinf/acosf implementations. + +Copyright (c) 2023-2024 Alexei Sibidanov. + +The original version of this file was copied from the CORE-MATH +project (file src/binary32/asin/asinf.c, revision bc385c2). + +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 "s_asincosf_data.h" + +const double __asincosf_c0[] = + { + 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 + }; + +const double __asincosf_c1[] = + { + 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 + }; diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.h b/sysdeps/ieee754/flt-32/s_asincosf_data.h new file mode 100644 index 0000000000..c3f9ed5a27 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.h @@ -0,0 +1,35 @@ +/* Common data for asinf/acosf implementations. + +Copyright (c) 2023-2024 Alexei Sibidanov. + +The original version of this file was copied from the CORE-MATH +project (file src/binary32/asin/asinf.c, revision bc385c2). + +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. +*/ + +#ifndef _S_ASINCOSF_DATA_H +#define _S_ASINCOSF_DATA_H + +extern const double __asincosf_c0[] attribute_hidden; +#define C0 __asincosf_c0 +extern const double __asincosf_c1[] attribute_hidden; +#define C1 __asincosf_c1 + +#endif