From patchwork Fri Nov 3 12:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qOUBqvnk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKgg35Knz1yQ4 for ; Fri, 3 Nov 2023 23:24:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 798293858296 for ; Fri, 3 Nov 2023 12:24:45 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 8343C3858CDA for ; Fri, 3 Nov 2023 12:24:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8343C3858CDA 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 8343C3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014272; cv=none; b=wgSr5a75DMr7ud7ywxvX9Bpjk03DHy4E73V2i7ZOqSzTpmfb16b3BnyVgNttNsgzAD/XXZ7XnHbMAMXpwCaTQR7JMjn+ic0z8ytxHJKpsl+jwwnMXotPXw7jT6Ol98WKAknaPOrQoxfpx0/YeOLPrBn4rEVpO06CR1viwLcZs7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014272; c=relaxed/simple; bh=BoHvN498rhA/tBAAwfSg43+0rL0NtgPiLxrEzE2+mgk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=hkf/81nw6cvIbJsEENmexuJoP8B3Yka/4p2wTH2LPp10vOxUNzu72pB3ul0pB1/UrWG0fy8VbEJkdPnKDZH3Pg4LS+5op/7yPLetfBZtTHaReoBalv0fschFLskZooQAseKbLw94IXny4Ixi7dtN5HXmMCsW3rbhKY1z41yua2g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b56b618217so1134380b6e.0 for ; Fri, 03 Nov 2023 05:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014263; x=1699619063; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=qOUBqvnkt8nzznAjzzjVhsFQD662OAPhPYYU2mMvRsLwwse0qTVogvtQG0gm7MtFd8 FbyhjPQCdV1pYTd2mw5mxO83AzbyVH+d9VetPFqKNzT5IqiHEwFUPMAqyI+a+1Q7+AV+ nlc/woeZnEc4ZtCH9qg7hBHFtFiI6Hc0UVsQWRoy+byNc2APyjBSE7ARiPEgv6fvIFDg OE3vt1QWkBsgcXIS37J/cUMshJhETqVqaNon2GxoqArW5dMX+Frd5vFQ7qfvc+ki/FR5 Rl9nEX72D7vYfKiR53A4Y9rUegPJUlnsl6jQIOVgTwH8eZavr8zb/Y95lPCj2IkcmIGn O58w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014263; x=1699619063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=E6R33ziK240UcPFY/AK4uyjmNVLHGM+6hI6xssklXjW6cCIEx0YRwtlQvA8B5doAmo e/T/ywxmkP/vwBh6hvPoCsnMEKN2kXEg6nXdXgIz/1ZMTtW/lIznS7pELlS9HjX8Jbyf WblSyb9DPXj4Qh22dTmS8pTUZg8LGTm3/OEGK/V0iSneD58UfaPFqoWK8AAxAjHeR0i2 zq3jORKshvbMk8sPFU7WLR2beQKjYSkzGzBmPe/I3WuVDh2Sid9uSEkjqoyCCo6GWMWL FzL1rhYINdRxKhmBKp1bfGXZI52GvMqpqplg6ASJFpb7eoq+exsMzczlKJdqTB81ap9I NSoQ== X-Gm-Message-State: AOJu0YwJaMhMegQu5uCW6idA4fdoF/tuR37IWSH0Y22eIK+mQCs709zT 0Jcc6duIzpqjaffmdSKkfDgz3IKkU+Akg/cnRTnk2A== X-Google-Smtp-Source: AGHT+IFObn40+laLKeYOtj7y1s3BJIv6S37mIP82tFnktillmrEhXuaDjwwdgYxq55RCTXBtHw1ogA== X-Received: by 2002:aca:b05:0:b0:3af:e67d:8295 with SMTP id 5-20020aca0b05000000b003afe67d8295mr23563611oil.40.1699014263034; Fri, 03 Nov 2023 05:24:23 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:22 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 1/7] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) Date: Fri, 3 Nov 2023 09:24:10 -0300 Message-Id: <20231103122416.2724355-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org According to ISO C23 (7.6.4.4), fesetexcept is supposed to set floating-point exception flags without raising a trap (unlike feraiseexcept, which is supposed to raise a trap if feenableexcept was called with the appropriate argument). This is a side-effect of how we implement the GNU extension feenableexcept, where feenableexcept/fesetenv/fesetmode/feupdateenv might issue prctl (PR_SET_FPEXC, PR_FP_EXC_PRECISE) depending of the argument. And on PR_FP_EXC_PRECISE, setting a floating-point exception flag triggers a trap. To make the both functions follow the C23, fesetexcept and fesetexceptflag now fail if the argument may trigger a trap. The math tests now check for an value different than 0, instead of bail out as unsupported for EXCEPTION_SET_FORCES_TRAP. Checked on powerpc64le-linux-gnu. --- math/test-fesetexcept-traps.c | 11 ++++------- math/test-fexcept-traps.c | 11 ++++------- sysdeps/powerpc/fpu/fesetexcept.c | 5 +++++ sysdeps/powerpc/fpu/fsetexcptflg.c | 9 ++++++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/math/test-fesetexcept-traps.c b/math/test-fesetexcept-traps.c index 71b6e45b33..96f6c4752f 100644 --- a/math/test-fesetexcept-traps.c +++ b/math/test-fesetexcept-traps.c @@ -39,16 +39,13 @@ do_test (void) return result; } - if (EXCEPTION_SET_FORCES_TRAP) - { - puts ("setting exceptions traps, cannot test on this architecture"); - return 77; - } - /* Verify fesetexcept does not cause exception traps. */ + /* Verify fesetexcept does not cause exception traps. For architectures + where setting the exception might result in traps the function should + return a nonzero value. */ ret = fesetexcept (FE_ALL_EXCEPT); if (ret == 0) puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); - else + else if (!EXCEPTION_SET_FORCES_TRAP) { puts ("fesetexcept (FE_ALL_EXCEPT) failed"); if (EXCEPTION_TESTS (float)) diff --git a/math/test-fexcept-traps.c b/math/test-fexcept-traps.c index 9701c3c320..9b8f583ae6 100644 --- a/math/test-fexcept-traps.c +++ b/math/test-fexcept-traps.c @@ -63,14 +63,11 @@ do_test (void) result = 1; } - if (EXCEPTION_SET_FORCES_TRAP) - { - puts ("setting exceptions traps, cannot test on this architecture"); - return 77; - } - /* The test is that this does not cause exception traps. */ + /* The test is that this does not cause exception traps. For architectures + where setting the exception might result in traps the function should + return a nonzero value. */ ret = fesetexceptflag (&saved, FE_ALL_EXCEPT); - if (ret != 0) + if (ret != 0 && !EXCEPTION_SET_FORCES_TRAP) { puts ("fesetexceptflag failed"); result = 1; diff --git a/sysdeps/powerpc/fpu/fesetexcept.c b/sysdeps/powerpc/fpu/fesetexcept.c index 609a148a95..2850156d3a 100644 --- a/sysdeps/powerpc/fpu/fesetexcept.c +++ b/sysdeps/powerpc/fpu/fesetexcept.c @@ -31,6 +31,11 @@ fesetexcept (int excepts) & FE_INVALID_SOFTWARE)); if (n.l != u.l) { + if (n.l & fenv_exceptions_to_reg (excepts)) + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 + does not allow it. */ + return -1; + fesetenv_register (n.fenv); /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ diff --git a/sysdeps/powerpc/fpu/fsetexcptflg.c b/sysdeps/powerpc/fpu/fsetexcptflg.c index 2b22f913c0..6517e8ea03 100644 --- a/sysdeps/powerpc/fpu/fsetexcptflg.c +++ b/sysdeps/powerpc/fpu/fsetexcptflg.c @@ -44,7 +44,14 @@ __fesetexceptflag (const fexcept_t *flagp, int excepts) This may cause floating-point exceptions if the restored state requests it. */ if (n.l != u.l) - fesetenv_register (n.fenv); + { + if (n.l & fenv_exceptions_to_reg (excepts)) + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 + does not allow it. */ + return -1; + + fesetenv_register (n.fenv); + } /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ if (flag & FE_INVALID) From patchwork Fri Nov 3 12:24:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UYfAoR0R; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKh3117Zz1yQ4 for ; Fri, 3 Nov 2023 23:25:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B88D23856975 for ; Fri, 3 Nov 2023 12:25:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 5458D3858C41 for ; Fri, 3 Nov 2023 12:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5458D3858C41 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 5458D3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::729 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014276; cv=none; b=QOIK23hGYGPdBlv9UpOuxiGJetFZ1J2J7ZZSR/vR1AI/GsJtPOdDE7ZCnzDOKShRaTChIfI0fbkfxGckKwi3cu498+LP5BBnBwn/2Wg1kfaLzHZttddYnQDjDb2wS9+ByjJbFdDlCiFU569LgqOiR9sE9Mo+RzbUNlH6Dh8p2Mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014276; c=relaxed/simple; bh=Tl/wbB2GCBTttl5IJGjM/4/upVxLAhwHvIgVt5uBijo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PFUXGMBJosre7s7SWiWZFUMgTqrdL+JHjsXkR2CIokuHOICyQme+8Mf77MrijxleC+k9c3WSMe6ecD9kv4g9R4S1RD2bZq32frAb0iSD63hqtD4tYa+X/reuoT0CqZbfh+SoWU2Lg/5Gc0i1kdfUPQAPYxSWIEqQgwEawbRTtrU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-77896da2118so110952185a.1 for ; Fri, 03 Nov 2023 05:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014265; x=1699619065; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8ujOWCJ4a4246lq6dUQMnVl3c7/GQti81/iYWZLRcvg=; b=UYfAoR0RHDYleHgUKpgELBmWc4/H8KACGflSoxMtpyxtFsm01FYcSHuiVr1u+B6Zzl h7PDBSkyzMHUKYe5KEoRhTamgWUFHLYQBL5pIR1AR3yRehwdlx8OPQtoCDauJ6f+LFse lddZt4p8QYabaz7gw69RdguphW6TbqxouYQbDGeqRe7Iv0hww+rJDu5tPEEaJHFLQt7t FlVX+LW+dn+zQIgJRYlU9wxCZYz8TDFo4IXBcrgp6hL9xTAjWmthribES9jasgoWJkHz OmLabB7N/hBDtYtWn+lrOYcutgqpU1hDqxT/n6CoGiCnfC6aTh27Gx0UjRy5AwrfqxGv 6SsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014265; x=1699619065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ujOWCJ4a4246lq6dUQMnVl3c7/GQti81/iYWZLRcvg=; b=vYDE40lmh+cX0q3/S4Ef+gW+gdFsCgUdRb1PEJj1DxnveZaRJKRiZQVFxpc2yERC0r zkMAZseK7Of6kSHSRSLN6kKXZDxNYCDl/yN4dski3ok2+9Ia1Z9cYnEVr1sZGM2QQNIp y7s3gh607w/0sng3B+elSEtIkTh++gzwjRE7mKiQxUZrFGdSDPnyyPAtcNSx1zZWZlfX G49xfBWo8WE1OY1K9pG4SD4eV/PKI583YKbJgOElGbtASSTeALQK5LSPUOv1XIKr4PLQ jU7B45CTK2iNaDpAsvXUrKdZG2L/7zX8KwFYwTLHYgU8HsFkDYTQzk4knABJVcOpCQEl 94kg== X-Gm-Message-State: AOJu0YxWWtNFxxvrcBTOfvTZfFpxbj0OxJ6x/2DVOLirnYGrVl7tD7mm 6A08MBPNqvg72zalPSPLizyJshltw6HwBiyXlWUCBw== X-Google-Smtp-Source: AGHT+IFfPfxqJKLgZoydqzsP2yWtCHKwOJV5cs/a9KWL3d1/dRj1GNAQkyurVIsQmcP6KItO3fTWUQ== X-Received: by 2002:a05:620a:4785:b0:77a:1d5b:2cc8 with SMTP id dt5-20020a05620a478500b0077a1d5b2cc8mr17698599qkb.44.1699014264892; Fri, 03 Nov 2023 05:24:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:24 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 2/7] i686: Do not raise exception traps on fesetexcept (BZ 30989) Date: Fri, 3 Nov 2023 09:24:11 -0300 Message-Id: <20231103122416.2724355-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org According to ISO C23 (7.6.4.4), fesetexcept is supposed to set floating-point exception flags without raising a trap (unlike feraiseexcept, which is supposed to raise a trap if feenableexcept was called with the appropriate argument). The flags can be set in the 387 unit or in the SSE unit. To set a flag, it is sufficient to do it in the SSE unit, because that is guaranteed to not trap. However, on i386 CPUs that have only a 387 unit, set the flags in the 387, as long as this cannot trap. Checked on i686-linux-gnu. --- math/test-fesetexcept-traps.c | 28 ++++++++++++--- sysdeps/i386/fpu/fesetexcept.c | 46 +++++++++++++++++++++--- sysdeps/i386/fpu/math-tests-trap-force.h | 29 +++++++++++++++ sysdeps/x86/fpu/test-fenv-sse-2.c | 23 +++--------- 4 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 sysdeps/i386/fpu/math-tests-trap-force.h diff --git a/math/test-fesetexcept-traps.c b/math/test-fesetexcept-traps.c index 96f6c4752f..8a5c0bca80 100644 --- a/math/test-fesetexcept-traps.c +++ b/math/test-fesetexcept-traps.c @@ -19,6 +19,7 @@ #include #include #include +#include static int do_test (void) @@ -41,8 +42,28 @@ do_test (void) /* Verify fesetexcept does not cause exception traps. For architectures where setting the exception might result in traps the function should - return a nonzero value. */ - ret = fesetexcept (FE_ALL_EXCEPT); + return a nonzero value. + Also check if the function does not alter the exception mask. */ + { + int exc_before = fegetexcept (); + ret = fesetexcept (FE_ALL_EXCEPT); + int exc_after = fegetexcept (); + if (exc_before != exc_after) + { + puts ("fesetexcept (FE_ALL_EXCEPT) changed the exceptions mask"); + return 1; + } + } + + /* Execute some floating-point operations, since on some CPUs exceptions + triggers a trap only at the next floating-point instruction. */ + volatile double a = 1.0; + volatile double b = a + a; + math_force_eval (b); + volatile long double al = 1.0L; + volatile long double bl = al + al; + math_force_eval (bl); + if (ret == 0) puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); else if (!EXCEPTION_SET_FORCES_TRAP) @@ -61,5 +82,4 @@ do_test (void) return result; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include diff --git a/sysdeps/i386/fpu/fesetexcept.c b/sysdeps/i386/fpu/fesetexcept.c index 18949e982a..2e9580207c 100644 --- a/sysdeps/i386/fpu/fesetexcept.c +++ b/sysdeps/i386/fpu/fesetexcept.c @@ -17,15 +17,53 @@ . */ #include +#include int fesetexcept (int excepts) { - fenv_t temp; + /* The flags can be set in the 387 unit or in the SSE unit. To set a flag, + it is sufficient to do it in the SSE unit, because that is guaranteed to + not trap. However, on i386 CPUs that have only a 387 unit, set the flags + in the 387, as long as this cannot trap. */ - __asm__ ("fnstenv %0" : "=m" (*&temp)); - temp.__status_word |= excepts & FE_ALL_EXCEPT; - __asm__ ("fldenv %0" : : "m" (*&temp)); + excepts &= FE_ALL_EXCEPT; + + if (CPU_FEATURE_USABLE (SSE)) + { + /* And now similarly for SSE. */ + unsigned int mxcsr; + __asm__ ("stmxcsr %0" : "=m" (*&mxcsr)); + + /* Set relevant flags. */ + mxcsr |= excepts; + + /* Put the new data in effect. */ + __asm__ ("ldmxcsr %0" : : "m" (*&mxcsr)); + } + else + { + fenv_t temp; + + /* Note: fnstenv masks all floating-point exceptions until the fldenv + or fldcw below. */ + __asm__ ("fnstenv %0" : "=m" (*&temp)); + + /* Set relevant flags. */ + temp.__status_word |= excepts; + + if ((~temp.__control_word) & excepts) + { + /* Setting the exception flags may trigger a trap (at the next + floating-point instruction, but that does not matter). + ISO C23 (7.6.4.4) does not allow it. */ + __asm__ volatile ("fldcw %0" : : "m" (*&temp.__control_word)); + return -1; + } + + /* Store the new status word (along with the rest of the environment). */ + __asm__ ("fldenv %0" : : "m" (*&temp)); + } return 0; } diff --git a/sysdeps/i386/fpu/math-tests-trap-force.h b/sysdeps/i386/fpu/math-tests-trap-force.h new file mode 100644 index 0000000000..f41e1ffc2d --- /dev/null +++ b/sysdeps/i386/fpu/math-tests-trap-force.h @@ -0,0 +1,29 @@ +/* Configuration for math tests: support for setting exception flags + without causing enabled traps. i686 version. + Copyright (C) 2023 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 + . */ + +#ifndef I386_FPU_MATH_TESTS_TRAP_FORCE_H +#define I386_FPU_MATH_TESTS_TRAP_FORCE_H 1 + +#include + +/* Setting exception flags in FPU Status Register results in enabled traps for + those exceptions being taken. */ +#define EXCEPTION_SET_FORCES_TRAP !CPU_FEATURE_USABLE (SSE) + +#endif /* math-tests-trap-force.h. */ diff --git a/sysdeps/x86/fpu/test-fenv-sse-2.c b/sysdeps/x86/fpu/test-fenv-sse-2.c index f3e820b6ed..7a0503790f 100644 --- a/sysdeps/x86/fpu/test-fenv-sse-2.c +++ b/sysdeps/x86/fpu/test-fenv-sse-2.c @@ -22,17 +22,8 @@ #include #include #include - -static bool -have_sse2 (void) -{ - unsigned int eax, ebx, ecx, edx; - - if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) - return false; - - return (edx & bit_SSE2) != 0; -} +#include +#include static uint32_t get_sse_mxcsr (void) @@ -164,13 +155,9 @@ sse_tests (void) static int do_test (void) { - if (!have_sse2 ()) - { - puts ("CPU does not support SSE2, cannot test"); - return 0; - } + if (!CPU_FEATURE_USABLE (SSE2)) + FAIL_UNSUPPORTED ("CPU does not support SSE2"); return sse_tests (); } -#define TEST_FUNCTION do_test () -#include +#include From patchwork Fri Nov 3 12:24:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ORXHbVE6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKhK3t2fz1yQ5 for ; Fri, 3 Nov 2023 23:25:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E728D3858298 for ; Fri, 3 Nov 2023 12:25:12 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 463003858C50 for ; Fri, 3 Nov 2023 12:24:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 463003858C50 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 463003858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014276; cv=none; b=vH3NR8UpDlxeQg22ppZIpCq/4Rm9IvXlKaYrpGRQl3vkZM/HTE0Dfn3YMjCKcEuev1+1gi6bxcTItDCGpsvMrrC42mCHUZU2JmgmFAjkRF4OSgYEh+qOBo/9hbVewiH7G0L8wsdbsKlivbtdjTWZ9Y+eGCjwVwf2rYhdNh9v4k4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014276; c=relaxed/simple; bh=hfDMehSrfWPelTn8gQqgqYIK4BflGb+l5n5qAH2yda0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=naukFRltddPJijozKymU/ZKW5ZyAnHuLZoCdo56dv48ctDNqD+rB6gO6UX5gh4YrDf+UuEzpoc5DVCHYtei/qpaX/KI3hT7MwkMOWtH04NM2xf6MiFhXjKiAgESQV8x38tj68xHZ7H4HGzvFlqyWjJQ7yjI5hiF3AnHqwvqxd5o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-778940531dbso118879285a.0 for ; Fri, 03 Nov 2023 05:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014268; x=1699619068; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eftPKld3emM/oawcIawQye0ZqEe6js4ZoXRzoUmLenU=; b=ORXHbVE6XkJWoTw3FmXtG9RI0m2nYvR8S0P26VuPKLU528iv3iDalArTafbiQcDFFn KSoSGntpSYd52/57GWlXun+pJC6taGtyKfXbPh62+EBcnET9zmdu1xohSQKWqFg5pRZh o1f6thF0LWnGx68FB6asvyRD8F05ctf6PMhmcFgTjXjDlQBnSNm2Qd60ZklKRV6yMQ3e pd7GnMdFOS2L19GfUq4hjnbrIaE9E3/nzVLS0of8bSenHuVMMCXZbdPQdg2Ydbo3eUnm F59CifE3BbSQM8Kp4IPTR5hsc3oF6njyZRWLl+PvJE/wSh+sBbU+nPXaOYkR5WwopJUZ fxQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014268; x=1699619068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eftPKld3emM/oawcIawQye0ZqEe6js4ZoXRzoUmLenU=; b=D3EV2ahIERqr64zTMcl/EIrudNgJp39h7iCRwOJhn8Rp+jHNFT1qJlmpQCZR2+y5JZ 1FzBwV6CVATO4rLRUlcy2ObGrhqJjbOHM1ksoD4czRNg4bCYXcAdLFtYT3WRVDpVwmEd OUA9gq0Z7YEwRjbebJNLw0NbmNx0SfoK/yXfEv3b/EsgF4uPbLyc9NhUilTMPh1XSvva N/rQ2mB9tZZbGuFS+wRFizlVgy4LiCqVytBt6XKHX9sORaOMtUqywgWRurHKjjSJDetM h6MXFsfpeeQ0ay8/Qg654lR693HilvbeZirQNiOvDAgCy7f0DEc5VT/xaJgSDj7knSmZ PALw== X-Gm-Message-State: AOJu0YwDQUtcggCzAV7my+Si1E3lCJjI+xD7omTydGP7KmZSYG4WeJ0I 7LIegJakw3a95nnSzIbFtrn4ktnhmpKgNvsIlLOqQg== X-Google-Smtp-Source: AGHT+IG2xUB/Ywuxlukk9W5mT4F6AzNpQUD0RVXEuRgFmt+4ikso5N6JJwr/0fM2GnKwAgs2y6axzQ== X-Received: by 2002:a05:620a:4109:b0:775:9bc3:c492 with SMTP id j9-20020a05620a410900b007759bc3c492mr24203796qko.7.1699014267793; Fri, 03 Nov 2023 05:24:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:27 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 3/7] x86: Do not raises floating-point exception traps on fesetexceptflag (BZ 30990) Date: Fri, 3 Nov 2023 09:24:12 -0300 Message-Id: <20231103122416.2724355-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org From: Bruno Haible According to ISO C23 (7.6.4.4), fesetexcept is supposed to set floating-point exception flags without raising a trap (unlike feraiseexcept, which is supposed to raise a trap if feenableexcept was called with the appropriate argument). The flags can be set in the 387 unit or in the SSE unit. When we need to clear a flag, we need to do so in both units, due to the way fetestexcept is implemented. When we need to set a flag, it is sufficient to do it in the SSE unit, because that is guaranteed to not trap. However, on i386 CPUs that have only a 387 unit, set the flags in the 387, as long as this cannot trap. Co-authored-by: Adhemerval Zanella --- math/test-fexcept-traps.c | 22 ++++++++++- sysdeps/i386/fpu/fsetexcptflg.c | 63 ++++++++++++++++++++----------- sysdeps/x86_64/fpu/fsetexcptflg.c | 24 +++++++----- 3 files changed, 77 insertions(+), 32 deletions(-) diff --git a/math/test-fexcept-traps.c b/math/test-fexcept-traps.c index 9b8f583ae6..13aff229c3 100644 --- a/math/test-fexcept-traps.c +++ b/math/test-fexcept-traps.c @@ -19,6 +19,7 @@ #include #include #include +#include static int do_test (void) @@ -66,7 +67,26 @@ do_test (void) /* The test is that this does not cause exception traps. For architectures where setting the exception might result in traps the function should return a nonzero value. */ - ret = fesetexceptflag (&saved, FE_ALL_EXCEPT); + { + int exc_before = fegetexcept (); + ret = fesetexceptflag (&saved, FE_ALL_EXCEPT); + int exc_after = fegetexcept (); + if (exc_before != exc_after) + { + puts ("fesetexceptflag (FE_ALL_EXCEPT) changed the exceptions mask"); + return 1; + } + } + + /* Execute some floating-point operations, since on some CPUs exceptions + triggers a trap only at the next floating-point instruction. */ + volatile double a = 1.0; + volatile double b = a + a; + math_force_eval (b); + volatile long double al = 1.0L; + volatile long double bl = al + al; + math_force_eval (bl); + if (ret != 0 && !EXCEPTION_SET_FORCES_TRAP) { puts ("fesetexceptflag failed"); diff --git a/sysdeps/i386/fpu/fsetexcptflg.c b/sysdeps/i386/fpu/fsetexcptflg.c index e724b7d6fd..480165cff9 100644 --- a/sysdeps/i386/fpu/fsetexcptflg.c +++ b/sysdeps/i386/fpu/fsetexcptflg.c @@ -17,42 +17,63 @@ . */ #include -#include -#include #include -#include int __fesetexceptflag (const fexcept_t *flagp, int excepts) { - fenv_t temp; + /* The flags can be set in the 387 unit or in the SSE unit. When we need to + clear a flag, we need to do so in both units, due to the way fetestexcept + is implemented. + When we need to set a flag, it is sufficient to do it in the SSE unit, + because that is guaranteed to not trap. However, on i386 CPUs that have + only a 387 unit, set the flags in the 387, as long as this cannot trap. */ - /* Get the current environment. We have to do this since we cannot - separately set the status word. */ - __asm__ ("fnstenv %0" : "=m" (*&temp)); + fenv_t temp; - temp.__status_word &= ~(excepts & FE_ALL_EXCEPT); - temp.__status_word |= *flagp & excepts & FE_ALL_EXCEPT; + excepts &= FE_ALL_EXCEPT; - /* Store the new status word (along with the rest of the environment. - Possibly new exceptions are set but they won't get executed unless - the next floating-point instruction. */ - __asm__ ("fldenv %0" : : "m" (*&temp)); + /* Get the current x87 FPU environment. We have to do this since we + cannot separately set the status word. + Note: fnstenv masks all floating-point exceptions until the fldenv + or fldcw below. */ + __asm__ ("fnstenv %0" : "=m" (*&temp)); - /* If the CPU supports SSE, we set the MXCSR as well. */ if (CPU_FEATURE_USABLE (SSE)) { - unsigned int xnew_exc; + unsigned int mxcsr; + + /* Clear relevant flags. */ + temp.__status_word &= ~(excepts & ~ *flagp); - /* Get the current MXCSR. */ - __asm__ ("stmxcsr %0" : "=m" (*&xnew_exc)); + /* Store the new status word (along with the rest of the environment). */ + __asm__ ("fldenv %0" : : "m" (*&temp)); - /* Set the relevant bits. */ - xnew_exc &= ~(excepts & FE_ALL_EXCEPT); - xnew_exc |= *flagp & excepts & FE_ALL_EXCEPT; + /* And now similarly for SSE. */ + __asm__ ("stmxcsr %0" : "=m" (*&mxcsr)); + + /* Clear or set relevant flags. */ + mxcsr ^= (mxcsr ^ *flagp) & excepts; /* Put the new data in effect. */ - __asm__ ("ldmxcsr %0" : : "m" (*&xnew_exc)); + __asm__ ("ldmxcsr %0" : : "m" (*&mxcsr)); + } + else + { + /* Clear or set relevant flags. */ + temp.__status_word ^= (temp.__status_word ^ *flagp) & excepts; + + if ((~temp.__control_word) & temp.__status_word & excepts) + { + /* Setting the exception flags may trigger a trap (at the next + floating-point instruction, but that does not matter). + ISO C 23 § 7.6.4.5 does not allow it. */ + __asm__ volatile ("fldcw %0" : : "m" (*&temp.__control_word)); + return -1; + } + + /* Store the new status word (along with the rest of the environment). */ + __asm__ ("fldenv %0" : : "m" (*&temp)); } /* Success. */ diff --git a/sysdeps/x86_64/fpu/fsetexcptflg.c b/sysdeps/x86_64/fpu/fsetexcptflg.c index a3ac1dea01..2ce2b509f2 100644 --- a/sysdeps/x86_64/fpu/fsetexcptflg.c +++ b/sysdeps/x86_64/fpu/fsetexcptflg.c @@ -22,30 +22,34 @@ int fesetexceptflag (const fexcept_t *flagp, int excepts) { + /* The flags can be set in the 387 unit or in the SSE unit. + When we need to clear a flag, we need to do so in both units, + due to the way fetestexcept() is implemented. + When we need to set a flag, it is sufficient to do it in the SSE unit, + because that is guaranteed to not trap. */ + fenv_t temp; unsigned int mxcsr; - /* XXX: Do we really need to set both the exception in both units? - Shouldn't it be enough to set only the SSE unit? */ + excepts &= FE_ALL_EXCEPT; /* Get the current x87 FPU environment. We have to do this since we cannot separately set the status word. */ __asm__ ("fnstenv %0" : "=m" (*&temp)); - temp.__status_word &= ~(excepts & FE_ALL_EXCEPT); - temp.__status_word |= *flagp & excepts & FE_ALL_EXCEPT; + /* Clear relevant flags. */ + temp.__status_word &= ~(excepts & ~ *flagp); - /* Store the new status word (along with the rest of the environment. - Possibly new exceptions are set but they won't get executed unless - the next floating-point instruction. */ + /* Store the new status word (along with the rest of the environment). */ __asm__ ("fldenv %0" : : "m" (*&temp)); - /* And now the same for SSE. */ + /* And now similarly for SSE. */ __asm__ ("stmxcsr %0" : "=m" (*&mxcsr)); - mxcsr &= ~(excepts & FE_ALL_EXCEPT); - mxcsr |= *flagp & excepts & FE_ALL_EXCEPT; + /* Clear or set relevant flags. */ + mxcsr ^= (mxcsr ^ *flagp) & excepts; + /* Put the new data in effect. */ __asm__ ("ldmxcsr %0" : : "m" (*&mxcsr)); /* Success. */ From patchwork Fri Nov 3 12:24:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Mk6nnrtl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKgZ6bgcz1yQ4 for ; Fri, 3 Nov 2023 23:24:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2B5C3858C30 for ; Fri, 3 Nov 2023 12:24:40 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 666143858D28 for ; Fri, 3 Nov 2023 12:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 666143858D28 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 666143858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::230 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014272; cv=none; b=a5hPfuos2Hpfxgk+gaVwKhaZpB5lPtzeFD2wcvXVC7AgbkzulwIUxSEYInc9c14zAKxiKwNuKjkinOdVIamdMCnpU2fpKzMv9O0bpBcUY6HblzMtVNgBEMMMTSUKPE+5F8EZsQJ26JY4m7uE/aciM2yhejUE3kdra6AVtX3E0js= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014272; c=relaxed/simple; bh=gQVXZEj8J6vg6gI0WcjVJPrupinV1eFHtmgVoBcq9LQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wW6IFK8fHgD776z6sIsz0FDMDARmjkCnXnEpcASykUmlyc5DIg2XSYCGQnSCuC9vM0ADenZ5rqaoZQlKBa/Ji2jIISh2MyA97oLzpXjl+q8hiJCXj8CpojU2gjwKslY+/+eAPtFQaGWhelGkCl9wXHRfGpud9wl7x8G6v3JHeHI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b2e44c7941so1200178b6e.2 for ; Fri, 03 Nov 2023 05:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014269; x=1699619069; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lk7Ud3IwIA6lCoWuWbkAHIpuAdPuSnUehSUEPHsUfL0=; b=Mk6nnrtltJGOrEmGT9vZtatQTI/8NxNf/LvoicroYRO7SmzymcUskz3cS7c+14fPBC 6fv6jdUMmKTSJO1L9vKPUsyCvzNzY/3dlEcsoOH5LofDqPab5Ie21Q5Jpk3rSVrjYZ4w /S9/Vmpt7WTOGaXYAjSQBKRAFKDH8ajQRskr2VaLGKHWQfkpmo+JSLzzT8ADN21XU3Bz jcWBYGIzzfdDPj5B5P1evKE661C+v/h8cGjFbwd/hKChS/zRlhnU4cG70fkAcrXJwn5B cDv4Qlj8B7BFGRmuAczoRwgNx9RVYZjN2zBT8tXXibIeKfiKNx7pbStp1OjUCo9NuFgY /C/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014269; x=1699619069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lk7Ud3IwIA6lCoWuWbkAHIpuAdPuSnUehSUEPHsUfL0=; b=pvk0vSzgtcHHDqQsFjZXQGrJTCpaSee0IqmWQGl8MiaYjS1kUOf+gCX+FCIwEIIfBU vCVmOu4fp/xjzRQwRBiPb+b3mneRiRSsjk0Wr5WmFyxZKrRkX0STu/bW7myNgAbVJhOw 8eiqfNsqM0iAMRx4ttMjImEa1lN3U+60YKlT6nyWza90WeZl7AWZjvdC0EVR64oG1g2g gvaCXWcXtzTF/Fg5QEJXf/yxJz4zNi+qa/Ti7bZpWbGFdDt4zGCy/gQN9sbathkQ8zsQ a6MyHCC4cRmFlP1gx9vOT4R+Hdsn5iByU7hX8aQIv15EP75WKPqAIwtage0oW4PHe0rG WZpw== X-Gm-Message-State: AOJu0Ywz2gKiUozoJTZEQNeCILrjZigVZcFPxtcGpR9TpqGL1qpKNsYW qAxTIwbPt+3EjQWPANxZwa2APW+hVhI2eSYVJHMVHg== X-Google-Smtp-Source: AGHT+IH1mJhUfvzNMl3Wb2pTwmANpc8GtS7AMTOPCtSfuORtzORpD0oHfrwihuQe/1BOQLbcekraqA== X-Received: by 2002:a05:6808:f89:b0:3b2:e9ae:5d4f with SMTP id o9-20020a0568080f8900b003b2e9ae5d4fmr25356108oiw.24.1699014269723; Fri, 03 Nov 2023 05:24:29 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:29 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 4/7] manual: Clarify undefined behavior of feenableexcept (BZ 31019) Date: Fri, 3 Nov 2023 09:24:13 -0300 Message-Id: <20231103122416.2724355-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org From: Bruno Haible * manual/arith.texi (Control Functions): Explain undefined behavior of feenableexcept in a special case. --- manual/arith.texi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manual/arith.texi b/manual/arith.texi index fa7110e992..68c6446a5b 100644 --- a/manual/arith.texi +++ b/manual/arith.texi @@ -1176,6 +1176,12 @@ enabled, the status of the other exceptions is not changed. The function returns the previous enabled exceptions in case the operation was successful, @code{-1} otherwise. + +Note: Enabling traps for an exception for which the exception flag is +currently already set (@pxref{Status bit operations}) has undefined +consequences: it may or may not trigger a trap immediately. +@c It triggers a trap immediately on powerpc*, at the next floating- +@c instruction on i386, and not at all on the other CPUs. @end deftypefun @deftypefun int fedisableexcept (int @var{excepts}) From patchwork Fri Nov 3 12:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=wdvzlQVp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKgn2xC3z1yQ4 for ; Fri, 3 Nov 2023 23:24:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BC28385697D for ; Fri, 3 Nov 2023 12:24:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 325BE3858C5E for ; Fri, 3 Nov 2023 12:24:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 325BE3858C5E 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 325BE3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014275; cv=none; b=XYvj3TOiyai7fCBfMKkLTtzTrSVyBxqvrHg/iYsrvhizifsM5Oga6VrqAsM4wpozSZ3ZuBto/EMHS7hIA1jEZEAjBWug9AkpKqVqjpOwa8xqgs5Mdgm4N8PQNP++GiuN1PJ8NekPToDt4kJIyJbPi/b0+xrCgP2Q6qxR0vavcC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014275; c=relaxed/simple; bh=hzXMA5hCYdtstoznVspPGxlk+2UCYkVseVesn28Zra8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EsiJFpcuJetTFTf1iv56NHMcLrSMMAO4SMOigUlmw5pL743jYna/iyZLahDrF0/kX+Rl2wQrT2DCFOF/DocoL/5i+/Lsb32cMIhKM+9G5H8BdPgEcdsvh/0UpzBNpukGcj+9B0UI/sMzb1P5q8SFHDS/s+M4gUmluYZ3iJ2iWyo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-7781bc3783fso121643485a.1 for ; Fri, 03 Nov 2023 05:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014271; x=1699619071; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Fw8OjC8TmSkRlpBI6Ab8Qf0yVbpnIlKkitjWNn3IYh8=; b=wdvzlQVpudfVG1zPgLKOW/OdUCpFZw8zfDUL2EFyOBvEQAS5gAAZzY0KMuZID8inh4 LSGX9i6Jz3xO9gzf9hW/3BuZ5pm7F0ckLadFTaUfqmOwKOaoqTMmmDwXdJMcveyknEWk 4xRnJ4ohKdMI0iduKp+bAdhLIFNVBKPKM+NXa9hlH+j7oYNiYPa58yyyoOQ97/UQHDjV 2+JAnrKfQXu6QU985s7ms/rvo8hM17o/cFTBBrxaXxczK6CRvqiFyfbvucQCBXDu6tuF bWoRQhSL/BX3AevfRPoa8p5TjQdgBryL0qoKnSDSiclraT8opC/YOID7g+SZZYlyRbi0 BwUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014271; x=1699619071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fw8OjC8TmSkRlpBI6Ab8Qf0yVbpnIlKkitjWNn3IYh8=; b=TPMByfS46yDQTdyadjWpHXEFzmZglywt08Ell8l4Xg+9F9ZRepzVMF1gFjZtMNv4H3 i1g2AffPmfiCBNtD3LFWpN/BA/ig3LFnoSGYuHDBsYFZPfRQ7QLRV6g2UKvgV0eDcqJ9 nTvsvwM1D/fd4+gRlkXFxsG3GdMXrBzXWzB1jMC9gzttM569vBh0c+8tIN/wcsbMWjGv PLDwA33OYgxW3bVfVnsA85ojKjboh7aEdxsRJarVV2WigOCdOw0O4hSDoUVRkfyCbRwI P49hwiak3p3rmWfK/wMaVP7E2kyRrr3p9UQfYOo7T1OnAF6GtV6rIUbpGW22O9X1SHa1 wS5g== X-Gm-Message-State: AOJu0YzeHo/ONpbufgqd0lWwhgpKm6nSnRCobwRjsu3rIUmHxfQaIECA MEi+NfRE91QYH4Tgdvclmfh1gjIuoCH0YFvCIZTN+w== X-Google-Smtp-Source: AGHT+IFO30NPdDcxjVIWqrtOkB7PyOUKgyR7y+wPUn+ltlVOysPlfiDwoEm8vTArI0AnF7ZJ1WweqQ== X-Received: by 2002:a05:620a:400a:b0:778:a62a:2c4b with SMTP id h10-20020a05620a400a00b00778a62a2c4bmr24592641qko.47.1699014271596; Fri, 03 Nov 2023 05:24:31 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:31 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022) Date: Fri, 3 Nov 2023 09:24:14 -0300 Message-Id: <20231103122416.2724355-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org libc_feupdateenv_riscv should check for FE_DFL_ENV, similar to libc_fesetenv_riscv. Also extend the test-fenv.c to test fenvupdate. Checked on riscv under qemu-system. --- math/test-fenv.c | 132 ++++++++++++++++++++++++++++--- sysdeps/riscv/rvf/fenv_private.h | 6 +- 2 files changed, 127 insertions(+), 11 deletions(-) diff --git a/math/test-fenv.c b/math/test-fenv.c index 0af7141ba7..734e0a219d 100644 --- a/math/test-fenv.c +++ b/math/test-fenv.c @@ -196,6 +196,30 @@ set_single_exc (const char *test_name, int fe_exc, fexcept_t exception) feclearexcept (exception); test_exceptions (str, ALL_EXC ^ fe_exc, 0); } + +static void +update_single_exc (const char *test_name, const fenv_t *envp, int fe_exc, + int fe_exc_clear, fexcept_t exception) +{ + char str[200]; + /* The standard allows the inexact exception to be set together with the + underflow and overflow exceptions. So ignore the inexact flag if the + others are raised. */ + int ignore_inexact = (fe_exc & (UNDERFLOW_EXC | OVERFLOW_EXC)) != 0; + + strcpy (str, test_name); + strcat (str, ": set flag, with rest not set"); + feclearexcept (FE_ALL_EXCEPT); + feraiseexcept (exception); + feupdateenv (envp); + test_exceptions (str, fe_exc, ignore_inexact); + + strcpy (str, test_name); + strcat (str, ": clear flag, rest also unset"); + feclearexcept (exception); + feupdateenv (envp); + test_exceptions (str, fe_exc_clear, ignore_inexact); +} #endif static void @@ -233,22 +257,32 @@ fe_tests (void) } #if FE_ALL_EXCEPT +static const char * +funcname (int (*func)(const fenv_t *)) +{ + if (func == fesetenv) + return "fesetenv"; + else if (func == feupdateenv) + return "feupdateenv"; + __builtin_unreachable (); +} + /* Test that program aborts with no masked interrupts */ static void -feenv_nomask_test (const char *flag_name, int fe_exc) +feenv_nomask_test (const char *flag_name, int fe_exc, int (*func)(const fenv_t *)) { # if defined FE_NOMASK_ENV int status; pid_t pid; if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) - && fesetenv (FE_NOMASK_ENV) != 0) + && func (FE_NOMASK_ENV) != 0) { printf ("Test: not testing FE_NOMASK_ENV, it isn't implemented.\n"); return; } - printf ("Test: after fesetenv (FE_NOMASK_ENV) processes will abort\n"); + printf ("Test: after %s (FE_NOMASK_ENV) processes will abort\n", funcname (func)); printf (" when feraiseexcept (%s) is called.\n", flag_name); pid = fork (); if (pid == 0) @@ -295,12 +329,12 @@ feenv_nomask_test (const char *flag_name, int fe_exc) /* Test that program doesn't abort with default environment */ static void -feenv_mask_test (const char *flag_name, int fe_exc) +feenv_mask_test (const char *flag_name, int fe_exc, int (*func)(const fenv_t *)) { int status; pid_t pid; - printf ("Test: after fesetenv (FE_DFL_ENV) processes will not abort\n"); + printf ("Test: after %s (FE_DFL_ENV) processes will not abort\n", funcname (func)); printf (" when feraiseexcept (%s) is called.\n", flag_name); pid = fork (); if (pid == 0) @@ -313,7 +347,7 @@ feenv_mask_test (const char *flag_name, int fe_exc) setrlimit (RLIMIT_CORE, &core_limit); #endif - fesetenv (FE_DFL_ENV); + func (FE_DFL_ENV); feraiseexcept (fe_exc); exit (2); } @@ -615,10 +649,18 @@ feenable_test (const char *flag_name, int fe_exc) static void fe_single_test (const char *flag_name, int fe_exc) { - feenv_nomask_test (flag_name, fe_exc); - feenv_mask_test (flag_name, fe_exc); + feenv_nomask_test (flag_name, fe_exc, fesetenv); + feenv_mask_test (flag_name, fe_exc, fesetenv); feenable_test (flag_name, fe_exc); } + + +static void +feupdate_single_test (const char *flag_name, int fe_exc) +{ + feenv_nomask_test (flag_name, fe_exc, feupdateenv); + feenv_mask_test (flag_name, fe_exc, feupdateenv); +} #endif @@ -646,6 +688,73 @@ feenv_tests (void) fesetenv (FE_DFL_ENV); } +#if FE_ALL_EXCEPT +static void +feupdateenv_single_test (const char *test_name, int fe_exc, + fexcept_t exception) +{ + char str[100]; + fenv_t env; + int res; + + snprintf (str, sizeof str, "feupdateenv %s and FL_DFL_ENV", test_name); + update_single_exc (str, FE_DFL_ENV, fe_exc, NO_EXC, exception); + + feraiseexcept (FE_ALL_EXCEPT); + res = fegetenv (&env); + if (res != 0) + { + printf ("fegetenv failed: %d\n", res); + ++count_errors; + return; + } + + snprintf (str, sizeof str, "feupdateenv %s and FE_ALL_EXCEPT", test_name); + update_single_exc (str, &env, ALL_EXC, ALL_EXC, exception); +} +#endif + +static void +feupdateenv_tests (void) +{ + /* We might have some exceptions still set. */ + feclearexcept (FE_ALL_EXCEPT); + +#ifdef FE_DIVBYZERO + feupdate_single_test ("FE_DIVBYZERO", FE_DIVBYZERO); +#endif +#ifdef FE_INVALID + feupdate_single_test ("FE_INVALID", FE_INVALID); +#endif +#ifdef FE_INEXACT + feupdate_single_test ("FE_INEXACT", FE_INEXACT); +#endif +#ifdef FE_UNDERFLOW + feupdate_single_test ("FE_UNDERFLOW", FE_UNDERFLOW); +#endif +#ifdef FE_OVERFLOW + feupdate_single_test ("FE_OVERFLOW", FE_OVERFLOW); +#endif + +#ifdef FE_DIVBYZERO + feupdateenv_single_test ("DIVBYZERO", DIVBYZERO_EXC, FE_DIVBYZERO); +#endif +#ifdef FE_INVALID + feupdateenv_single_test ("INVALID", INVALID_EXC, FE_INVALID); +#endif +#ifdef FE_INEXACT + feupdateenv_single_test ("INEXACT", INEXACT_EXC, FE_INEXACT); +#endif +#ifdef FE_UNDERFLOW + feupdateenv_single_test ("UNDERFLOW", UNDERFLOW_EXC, FE_UNDERFLOW); +#endif +#ifdef FE_OVERFLOW + feupdateenv_single_test ("OVERFLOW", OVERFLOW_EXC, FE_OVERFLOW); +#endif + + feupdateenv (FE_DFL_ENV); +} + static void feholdexcept_tests (void) @@ -766,13 +875,14 @@ initial_tests (void) #endif } -int -main (void) +static int +do_test (void) { initial_tests (); fe_tests (); feenv_tests (); feholdexcept_tests (); + feupdateenv_tests (); if (count_errors) { @@ -782,3 +892,5 @@ main (void) printf ("\n All tests passed successfully.\n"); return 0; } + +#include diff --git a/sysdeps/riscv/rvf/fenv_private.h b/sysdeps/riscv/rvf/fenv_private.h index 40e23661b7..c91d871160 100644 --- a/sysdeps/riscv/rvf/fenv_private.h +++ b/sysdeps/riscv/rvf/fenv_private.h @@ -123,7 +123,11 @@ libc_feupdateenv_test_riscv (const fenv_t *envp, int ex) static __always_inline void libc_feupdateenv_riscv (const fenv_t *envp) { - _FPU_SETCW (*envp | riscv_getflags ()); + long int env = (long int) envp - (long int) FE_DFL_ENV; + if (env != 0) + env = *envp; + + _FPU_SETCW (env | riscv_getflags ()); } #define libc_feupdateenv libc_feupdateenv_riscv From patchwork Fri Nov 3 12:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qp3lf9Hh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKhg5tj3z1yQx for ; Fri, 3 Nov 2023 23:25:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D46F3858C78 for ; Fri, 3 Nov 2023 12:25:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id BA9D73858C01 for ; Fri, 3 Nov 2023 12:24:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA9D73858C01 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 BA9D73858C01 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014285; cv=none; b=e2YLmK3+JYHnGcEBo9CfCTJ3jSJY6/VlCe2/VTlepeHeQWcdITsfy5a3LsDXVTGbjYpzPhjaZ/EpnjJJHS2OWORLqJRHJhQLvxdTpSff3Vpw+pm8fFEuJJ85HgAWWLgqc/5KYkAgf9oCouBj22Sq6Diu7EJ3q2Y9LhedYMxsUzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014285; c=relaxed/simple; bh=U3TO7U68zV/VH1gLF1OEP+gE10yWlon2iqsc+5Y+0PU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CW/pMlp6w8/TaPSrfVaAUDml0dIkOJwtnKBRPJlR7siBVBkAYUgWfT0lGPUYFLCS7xy3Ibq//sPJk+VQ9QCOLfkwaprXuRJhg8GroNUYxv7KWxAYftNwrH47rgTkoHU5E2PV1OG3gFUYuqS7CKDSclXW5ytlJBIXAgFoL6KFu10= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7789aed0e46so114617685a.0 for ; Fri, 03 Nov 2023 05:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014273; x=1699619073; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ifhyVU0xuLEi9GZ7tRCQR01OfHuW0wdjDKCoj9nK3Cw=; b=qp3lf9Hh3DxeGzgQLilIXVrRIXf1Leg0+7lPrBFMVR5lg6GYwB0jdLRF72yeDdGpAN ADnLQoi95fVaeTytNbr7mgMvB9zMnGlLNIOZUKIT7BHao7n6MqvoNanEDWx13RmtmBL/ nY7AYjRp2gp58/Ogeg3RNo8QLGTv/aHz4ItV8tMVvyPUbn3H7AhPpaXzLnham1TYnsKj x6gQdmYdcaWs9EcfCR3ystZFAMTRrIaG4F6lEnEQTCgFzqcmFDkGBM7P8dRR8eork/SP eG+xtn0yCcVKCsvcBghpng6FXUO7DhmkQcyuy2iEm1xbrI7fYTmjpXqwEf1So1HZvsoq zpTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014273; x=1699619073; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ifhyVU0xuLEi9GZ7tRCQR01OfHuW0wdjDKCoj9nK3Cw=; b=qbtnL7wZMIyY1Mk8gzWky5esyn267d5bQFFYXRXkZDBgz1ueKWoWEk+1ceu97dFHoR V9+cMGGQ7A5k3vSQQRmlbxaWzfU/04kjx0uwfzJD5R4ylLMh3BzB20RSn6XobZcRepkQ PjHz8G7gpb4adAgZ7n7ltMAZOUUpf+1Ohbi3DJbTDWQ1HVtKcu+YzkHAbrWd7tZbQ34z QPMvN8UVsjvko27sg2+TIDFW5Sed2Hn5YUlp22OM03+qhYop+hZ68tKWrscN9+XgJvyt R25SJOtCAKLlUy8KgOnB2HLheNyeM2qgDRbB+68dYWVBXCPK9AhOUCz/3rJwluSg+EtM fVMw== X-Gm-Message-State: AOJu0Yw2zLFoEU+vhXThhPuDUUx/vWrYClfr4J/Y0ZPGbYGuY19lH0Mf j0afw1p1mfJXwWes3IoDVOwntl5UOfYV2ceuqDM3QA== X-Google-Smtp-Source: AGHT+IHqmW6Tyh3emKDEsWe8YD5HxHhbweD4BuVUcokoVOcWQA38dOQnbeNrdlbFvS4CfchSWDcepg== X-Received: by 2002:a05:620a:1446:b0:778:903a:f832 with SMTP id i6-20020a05620a144600b00778903af832mr18399623qkl.78.1699014273544; Fri, 03 Nov 2023 05:24:33 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 6/7] alpha: Fix fesetexceptflag (BZ 30998) Date: Fri, 3 Nov 2023 09:24:15 -0300 Message-Id: <20231103122416.2724355-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org From: Bruno Haible It clears some exception flags that are outside the EXCEPTS argument. It fixes math/test-fexcept on qemu-user. --- sysdeps/alpha/fpu/fsetexcptflg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/alpha/fpu/fsetexcptflg.c b/sysdeps/alpha/fpu/fsetexcptflg.c index 70f3666a6e..63eb06845d 100644 --- a/sysdeps/alpha/fpu/fsetexcptflg.c +++ b/sysdeps/alpha/fpu/fsetexcptflg.c @@ -27,7 +27,7 @@ __fesetexceptflag (const fexcept_t *flagp, int excepts) tmp = __ieee_get_fp_control (); /* Set all the bits that were called for. */ - tmp = (tmp & ~SWCR_STATUS_MASK) | (*flagp & excepts & SWCR_STATUS_MASK); + tmp ^= (tmp ^ *flagp) & excepts & SWCR_STATUS_MASK; /* And store it back. */ __ieee_set_fp_control (tmp); From patchwork Fri Nov 3 12:24:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1858892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Doipox+/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SMKhG5m5Qz1yQ5 for ; Fri, 3 Nov 2023 23:25:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B52D038618D0 for ; Fri, 3 Nov 2023 12:25:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id C6FF0385842E for ; Fri, 3 Nov 2023 12:24:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6FF0385842E 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 C6FF0385842E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::731 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014285; cv=none; b=iC9S42eAOC/NN4G7MTgat+hF7kLl24g1kDCjMI+p+dc/wFyoiWEXM3kB6azWZ/bBLzpFXkdTXdblpebhsQfAZGccDilDXV/JQtRGTx4MtoK473kaXYQfULO8bJUvWnWhgXoRsG777swbQXtDVuCoYh0duSXmyApj2Lz1mqcQfw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014285; c=relaxed/simple; bh=X2wiZ3laELaKsR0jgcmuy/E0a1j+Y6CXbQpJCpc45wA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=nMTia3kMHu3OuU/+96827WCwJUUKMFi/IxFJwIUifz+x0W322HmYj3XlbtXSBnwvopzQi2uLW466v03uyc/zwXc7TXK45ALDvX5/5YtdrESbgS6Rq1r9clwHWInY56uwXGflKcp0BGxeQz5b6YdUCOQzik2xf08XQ6MPgFwdgbw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-77a453eb01cso115134585a.0 for ; Fri, 03 Nov 2023 05:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014275; x=1699619075; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6jWpJtYgU4AupWiGBpR3CkeP70iQINh300sZdk4guoA=; b=Doipox+/yoOv8wHW4S6MqWwfe62yt+cLtJZTB8BeJ381LbwaJCJOyTZeXlXgeEcOoh ij7gN6bw4+vcoD9r8NfQ9+gfTbntsfM2yMB2Jot2pXnOYYGCYsUjN33vdXyk0vit2GFd YWPLZKPm51H/04s/qF3aCZd5Jwzu89Fb6/U+QfzSbqY5yHgpJJaJTE/S9osFcSr5guRm 5H8vCU58WkZyDG7nEFW7SgxAez+LN4iKnEGYVYRCD2+cnXLCPDfSfJxj1gwRXsHD4u/U Pqzra2rL1Ih9eZsdwcxpGydaJ5Azuqpi9UeSGLZUxj/oYWp/MPlQj8q8OK691ngZ30Re Q7zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014275; x=1699619075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6jWpJtYgU4AupWiGBpR3CkeP70iQINh300sZdk4guoA=; b=K69DBUqd7vUzrNasfll0qpoyFEGreqIxqnVcmMnSvdkBH/7+Ki5HPqpnCIxwh9u4oV jRGY+iBSnQDdwF6jFGOtdY+clQRAuQPiSxSUr+fQ+O146fVOJoSfUtsrW3bZacndn6c2 Hkxdumi4cqTPPoaoC0k/0JhO8upiSbJ/3Xdqo7ozXSTqv5YkaUotwk0ocUI50kzfzbKF FAm1POY7i1Ghis2oKk/0bxxS50EaDtgCpSuGOnkOH6xlmppDfdI7BuofWpslQr9a8X7Z v+aqgo1jio8OxbZmhdMNVwzb21BySMZkk/xBQQ+EWQiRIMW+KX+qeiB2ZHo8sgmYuI7e 87wQ== X-Gm-Message-State: AOJu0YwenkOoZBV/v170RgqNgqwo1Z6uEltNSkVC4SWN+bWnXksBz3mi dwfzJFWTXTKJTmmkZmKM+TxwZ4ztFt2cVKNNKPGkiA== X-Google-Smtp-Source: AGHT+IGZSgRK57EX9sAgEgqm355RHP8Tr0llG5WtZSGvIuSr4Aj5YYmTNTVIg2g+D0F09Y2UFLTXWA== X-Received: by 2002:a05:620a:2a01:b0:778:8b8a:37e with SMTP id o1-20020a05620a2a0100b007788b8a037emr25457419qkp.21.1699014275434; Fri, 03 Nov 2023 05:24:35 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:34 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 7/7] hppa: Fix undefined behaviour in feclearexcept (BZ 30983) Date: Fri, 3 Nov 2023 09:24:16 -0300 Message-Id: <20231103122416.2724355-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org From: Bruno Haible The expression (excepts & FE_ALL_EXCEPT) << 27 produces a signed integer overflow when 'excepts' is specified as FE_INVALID (= 0x10), because - excepts is of type 'int', - FE_ALL_EXCEPT is of type 'int', - thus (excepts & FE_ALL_EXCEPT) is (int) 0x10, - 'int' is 32 bits wide. The patched code produces the same instruction sequence as previosuly. --- sysdeps/hppa/fpu/fclrexcpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/hppa/fpu/fclrexcpt.c b/sysdeps/hppa/fpu/fclrexcpt.c index 055fb04ccc..46caf39ec1 100644 --- a/sysdeps/hppa/fpu/fclrexcpt.c +++ b/sysdeps/hppa/fpu/fclrexcpt.c @@ -26,7 +26,7 @@ feclearexcept (int excepts) /* Get the current status word. */ __asm__ ("fstd %%fr0,0(%1)" : "=m" (s.l) : "r" (&s.l) : "%r0"); /* Clear all the relevant bits. */ - s.sw[0] &= ~((excepts & FE_ALL_EXCEPT) << 27); + s.sw[0] &= ~(((unsigned int) excepts & FE_ALL_EXCEPT) << 27); __asm__ ("fldd 0(%0),%%fr0" : : "r" (&s.l), "m" (s.l) : "%r0"); /* Success. */