From patchwork Tue Oct 21 03:02:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 122317 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF58B3858D21 for ; Tue, 21 Oct 2025 03:05:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF58B3858D21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1761015912; bh=6EgTcOqx81LKRxGmASy7AXBByJ//FATOFXxOVuBGEE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bCRCFFOrkTlvmqjD3ctQCUI+5kzKrwmfUEl9ZTxnkJiSrY1r52omeZBS/UHzYoLGg Djx4N+ivfaJnpiZmYS/hDK63wLAfwEoniKsh5w5hVCMK3CGq6fpbMaZsV7ryroG/Aa Z+ToxrwfTCFkdSWxRGrBgHKMpftm/BJ8tX76/YWQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from heron.birch.relay.mailchannels.net (heron.birch.relay.mailchannels.net [23.83.209.82]) by sourceware.org (Postfix) with ESMTPS id ABEE53858D29 for ; Tue, 21 Oct 2025 03:02:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABEE53858D29 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ABEE53858D29 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.209.82 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1761015754; cv=pass; b=clERYpVe+lTt+YuQtEm7CADnNkcj52A2yb3XXpx/xPv6Siz0zsUmDX7RsZNUF2X6ojF0GCj78RRox21uzo6eyKb43fj/A1sBUXwjOViYj8PlCZCUA0YZP95be109/AqzsIRNi7ttTet6oMbq3JPnPTKQo4or7FZHD2qJQCN3IqI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1761015754; c=relaxed/simple; bh=Ch085U/LswL60kg+rT1K5NdGAXqxaUB9m1QAFSB7Y4c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dYVhafLbuhDtkRTYZS0AIeI5o/AQXUAK05m+JyDNjlyaW4cvp4qhYtsXnjG5NYx3b/MUvg/tBfe7Zj4s5ABT7MK5KMfEorIw7tlBkenZiP8l9DSc+gHJ1swUF8IhVKnJ5RAgjF+xoUu115vfjRAlVDPjS9q57xV1Yeu+UFvLcG0= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABEE53858D29 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 44DDD5024E7; Tue, 21 Oct 2025 03:02:31 +0000 (UTC) Received: from pdx1-sub0-mail-a201.dreamhost.com (100-121-167-245.trex-nlb.outbound.svc.cluster.local [100.121.167.245]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id AF9AE5021B3; Tue, 21 Oct 2025 03:02:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1761015746; a=rsa-sha256; cv=none; b=Ri5SnIHnF7FTFl6Og5F9rk6KDuJDuAgIl2VhoKl0i8ldyu8K9k5PH+g1ntvdazYRfyrSQZ draHtANNbIfod4N64De2ze7COJEDnGquMIWnMDnD34H+x/8jn8eAJ99YW+HWnk/iyLRp5u KuAHK8t00M6uAu3zP/ERkrc5sdkSe3VUTNTV8cMsLEqM82rJSIIpZApoCaB+9DlSLarSoh AyLzon0o88nv6/WYCmvj/JbW11yvBw90pwvXD4F9aS8pVZsaIYLISX0/6Bc7yKCw7KtWtt 5j+U7O5pLOR8epcmXn4I84a23tqL1fE2pTq+sPA0QrNjoeX+ssTGsm0KrAE8iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1761015746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EgTcOqx81LKRxGmASy7AXBByJ//FATOFXxOVuBGEE0=; b=aBrxogylaL/j1t7Lcqu1lpdfVS9PixuA2oajkGTYl0vkT060ATqvmBlsl5jvrRV0XF//0o ezQcAotAs1nDl3mY7zooAWkE1VcS0V/kK1UGlcKA1DNHmeofEqZqsMNbkpvJbqxqmX4Z0X Rr3KnUOh6HGM4hpOsrQYFo1iBF9+FmAncDeud0D0Cof506JXbBkZidq0uoXZI7dJXYuRMi a7Dye2Shldvt4QE+sDo52X8Nv9Cl9r/crY/JlXy1pPbp8pPkCFPNb9O7MBTjDQvQK4DV1z d+Jlg2w4hp1cwoMTG4A35TtIiEN3DoxonzaAGDVMPO/sa7y1fOO0u5MW792kQA== ARC-Authentication-Results: i=1; rspamd-6c854d7645-7xtt8; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Thoughtful-Juvenile: 509efacf38e8a8cd_1761015750879_803803005 X-MC-Loop-Signature: 1761015750879:2606276358 X-MC-Ingress-Time: 1761015750879 Received: from pdx1-sub0-mail-a201.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.121.167.245 (trex/7.1.3); Tue, 21 Oct 2025 03:02:30 +0000 Received: from fedora.redhat.com (unknown [38.23.181.90]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a201.dreamhost.com (Postfix) with ESMTPSA id 4crHCQ0xvKzHv; Mon, 20 Oct 2025 20:02:26 -0700 (PDT) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: josmyers@redhat.com, Paul.Zimmermann@inria.fr Subject: [PATCH 1/2] test-powl: Port to libsupport Date: Mon, 20 Oct 2025 23:02:13 -0400 Message-ID: <20251021030219.189346-2-siddhesh@sourceware.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251021030219.189346-1-siddhesh@sourceware.org> References: <20251021030219.189346-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1165.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, LOCAL_AUTHENTICATION_FAIL_DMARC, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 Use test-driver.c instead of test-skeleton.c Signed-off-by: Siddhesh Poyarekar --- math/test-powl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/math/test-powl.c b/math/test-powl.c index 4c02d73d60..2c716043b8 100644 --- a/math/test-powl.c +++ b/math/test-powl.c @@ -20,12 +20,13 @@ #include #include #include +#include -static int -do_test (void) +/* Smoke test for bz12775, which discovered a typo in the x86_64 powl + implementation. */ +static void +do_test_bz12775 (void) { - int result = 0; - #if LDBL_MANT_DIG == 64 { long double x = 1e-20; @@ -39,13 +40,18 @@ do_test (void) if (fabsl (x - 1e-30) > 1e-10) { printf ("powl (1e-20, 1.5): wrong result: %Lg\n", x); - result = 1; + support_record_failure (); } } #endif +} + +static int +do_test (void) +{ + do_test_bz12775 (); - return result; + return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include From patchwork Tue Oct 21 03:02:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 122316 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 150903858C50 for ; Tue, 21 Oct 2025 03:03:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 150903858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1761015823; bh=z/yan0zCe5SB7pW4rjUIinMLllB2XORfdnaiA9BB8vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=D6+BaTfnEXVa+agXPvtSyMHzv6qI4e/b6pJBS6/M2QsmCVmGLUTOl0oy7dS1ywGI6 Yv8l+J2M0Id36l0EUGLZece6MatBQDquLY049qObxWdOUOzwkIu/exIAdoUvgsU2fi nywLskZjVlaKBbyPEOZO8b+hsQdD4Y2KkNblcFl8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from coral.ash.relay.mailchannels.net (coral.ash.relay.mailchannels.net [23.83.222.39]) by sourceware.org (Postfix) with ESMTPS id E32033858D21 for ; Tue, 21 Oct 2025 03:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E32033858D21 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E32033858D21 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.222.39 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1761015753; cv=pass; b=bvQAWB3Dspp6nMUtOujQvnImjcexD4fmnuurMUO7KYmzSdA4lMHQNtnhDK2LYSquykarL5KgxLtqMNqb4JacATeBVfONV9hmLybIYP5y++lrKbBXQGvYWkOWncjoe+W6D9qxqiCIrOpPgLYJxcWh9Ux361UXir6TG6lGPDxjdxE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1761015753; c=relaxed/simple; bh=MPHuME5xKf3V5GHWkA0dTiPYlyUCZPDajYVCMk1xQPE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nxklD+VVVFCd/J9wmw34+NSVMs1jpz6T50xCKkI71gnOlSHFzapL1+Ptfvj5jYWlNdXyN1gvP6fmhPGIGwePJD3UVqKYZI4p32TN4T6fqc9kGmdui+DgWwswwxUDvvQ8NNDRfJMzSOu3HipxkkQxqABmb5ZYvnGSSh8/hFU2R1E= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E32033858D21 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id B1EA0742487; Tue, 21 Oct 2025 03:02:31 +0000 (UTC) Received: from pdx1-sub0-mail-a201.dreamhost.com (trex-green-0.trex.outbound.svc.cluster.local [100.121.87.184]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 54EC7742102; Tue, 21 Oct 2025 03:02:27 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1761015747; a=rsa-sha256; cv=none; b=e15r2gGSORdm4KMtVgmfA+pWwNm4q4/6lrPMCWcj+YG2g/A8qKxoDZsQIFUw5dH9FX8E/h /bCnLhTnfaf9TQiG8mzf8BO4BUwAVQKwzhHsM2NkbL+RIJruHVooGLgKkelWaIprD7Yu70 xLdqMmnyhOBwYwPtA1ydqLu01MJuzyP6RJrk/kFPBWwthC1anbusneZcAUZVb2UrhOoMPw yYzsF6zDDQFGLzTC1oz1yD6WJ5OAvZJQqkg98G9cD0X6qAHrIi05apnCHksAL3xa5m/+Q0 0kvu6QrVSyKHiGtk4fQ1qkGZNnCT/p4hPqrn0JoUu/HXS4RKvo8u3AdAzMH1ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1761015747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z/yan0zCe5SB7pW4rjUIinMLllB2XORfdnaiA9BB8vk=; b=xNmKhn42sW2IKfTgnMFbLdKtsPFbg56N5F0lkYYomE/scNjOt9o4FkdlaaJ4b0h83+/TDH xrZpZf/T0omwgD4rK0FTwQW9xITttll2MRR2uMLdjsvbFTamGhb0+IW2krQAnrfHs7kMWl EMPhLyGVeXjPulxAlnlk1GPmOjc4pWlb9ElQ61BUpDnA3FNFmMUKZOHM5wIYDhPcUA3X2u HJryNmngWR88v3W9S5auT1PXq/ORY53Ht+sdfA8hY0zgC5MGxrMrCnbo3UM9Or57smtdOa V5PPRwXc2uzZNUcqWmVwnNmGEPfZZN1GBNFOzPYDmjTfwqa6Qh6DiwXlZst9mw== ARC-Authentication-Results: i=1; rspamd-6c854d7645-q465b; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Stretch-Lonely: 4bf897563520d5af_1761015751577_2043952308 X-MC-Loop-Signature: 1761015751577:1175189689 X-MC-Ingress-Time: 1761015751576 Received: from pdx1-sub0-mail-a201.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.121.87.184 (trex/7.1.3); Tue, 21 Oct 2025 03:02:31 +0000 Received: from fedora.redhat.com (unknown [38.23.181.90]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a201.dreamhost.com (Postfix) with ESMTPSA id 4crHCQ5sJNz3Z; Mon, 20 Oct 2025 20:02:26 -0700 (PDT) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: josmyers@redhat.com, Paul.Zimmermann@inria.fr Subject: [PATCH 2/2] Simplify powl computation for small integral y [BZ #33411] Date: Mon, 20 Oct 2025 23:02:14 -0400 Message-ID: <20251021030219.189346-3-siddhesh@sourceware.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251021030219.189346-1-siddhesh@sourceware.org> References: <20251021030219.189346-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1165.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, LOCAL_AUTHENTICATION_FAIL_DMARC, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 powl implementation for x86_64 ends up multiplying X once more than necessary and then throwing away that result. This results in an overflow flag being set in cases where there is no overflow. Simplify the relevant portion by special casing the -3 to 3 range and simply multiplying repetitively. Resolves: BZ #33411 Signed-off-by: Siddhesh Poyarekar --- math/test-powl.c | 22 +++++++++++-- sysdeps/x86_64/fpu/e_powl.S | 61 +++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/math/test-powl.c b/math/test-powl.c index 2c716043b8..25253d51d7 100644 --- a/math/test-powl.c +++ b/math/test-powl.c @@ -16,10 +16,11 @@ License along with the GNU C Library; if not, see . */ -#include -#include +#include #include #include +#include +#include #include /* Smoke test for bz12775, which discovered a typo in the x86_64 powl @@ -46,10 +47,27 @@ do_test_bz12775 (void) #endif } +/* Make sure that a long double ^ 1 does not set the overflow flag. For + context see BZ #33411. */ +static void +do_test_overflow (void) +{ + long double x = 1.090748135619415929463e+2466L; + + feclearexcept( FE_ALL_EXCEPT ); + + long double res = powl (x, 1.L); + int flags = fetestexcept( FE_ALL_EXCEPT ); + + TEST_VERIFY (res == x); + TEST_COMPARE (flags & FE_OVERFLOW, 0); +} + static int do_test (void) { do_test_bz12775 (); + do_test_overflow (); return 0; } diff --git a/sysdeps/x86_64/fpu/e_powl.S b/sysdeps/x86_64/fpu/e_powl.S index 620ef765a7..5695e1a9a6 100644 --- a/sysdeps/x86_64/fpu/e_powl.S +++ b/sysdeps/x86_64/fpu/e_powl.S @@ -144,40 +144,47 @@ ENTRY(__ieee754_powl) fcomip %st(1), %st // 4 : y : x fstp %st(0) // y : x jnc 3f - mov -8(%rsp),%eax - mov -4(%rsp),%edx - orl $0, %edx + + /* Here onwards, it's just integral y in range [-3, 3]. */ + movq -8(%rsp),%rax + orq $0, %rax fstp %st(0) // x jns 4f // y >= 0, jump fdivrl MO(one) // 1/x (now referred to as x) - negl %eax - adcl $0, %edx - negl %edx + negq %rax 4: fldl MO(one) // 1 : x - fxch - /* If y is even, take the absolute value of x. Otherwise, - ensure all intermediate values that might overflow have the - sign of x. */ + /* y range is further reduced to [0, 3]. Simply walk through the + options. */ + test %eax, %eax + jnz 5f + fstp %st(1) // 1 + jmp 7f + + /* y == 1. */ +5: movl %eax, %ecx + xorl $1, %ecx + fstp %st(0) // x + jz 7f + + /* y == 2. */ testb $1, %al jnz 6f - fabs - -6: shrdl $1, %edx, %eax - jnc 5f - fxch - fabs - fmul %st(1) // x : ST*x - fxch -5: fld %st // x : x : ST*x - fabs // |x| : x : ST*x - fmulp // |x|*x : ST*x - shrl $1, %edx - movl %eax, %ecx - orl %edx, %ecx - jnz 6b - fstp %st(0) // ST*x - LDBL_CHECK_FORCE_UFLOW_NONNAN + fabs // |x| + fld %st // |x| : |x| + fmulp %st(1) // |x| * |x| + jmp 7f + + /* y == 3. Special cased because x * x and |x| * |x| decay towards + infinity faster compared to x * |x|. */ +6: fld %st // x : x + fabs // |x| : x + fxch // x : |x| + fld %st(1) // |x| : x : |x| + fmulp // |x| * x : |x| + fmulp // |x| * x * |x| + +7: LDBL_CHECK_FORCE_UFLOW_NONNAN ret /* y is ±NAN */