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 X-Patchwork-Id: 740657 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp1335031wrv; Fri, 3 Nov 2023 05:24:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE942Pn2Fe309G2GB+lb3N4/1SbK8Wm/2h07ZMOaCz0DNE/I51Giqz9Qy2A8MtturMxHIxK X-Received: by 2002:a05:620a:172b:b0:777:74b9:219f with SMTP id az43-20020a05620a172b00b0077774b9219fmr27894554qkb.8.1699014283229; Fri, 03 Nov 2023 05:24:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1699014283; cv=pass; d=google.com; s=arc-20160816; b=pbSw8K6LErTJspyJjxPy+n2O6g6gqepxmy0g3hvtUiRcd7dPUfcqpFtt+b8YCrUA0A rn+JenGRKe+A1qJKZaVLfOxwD6ErRT0i6D9X+JJ+Gq1S0rUd6GNAG7JHCgMnIjE44vmH B4YYEPmve2gQn6TSDHN+4eT65lZ6P+GiKxKnRr//Fvfv1Fa2JDtsYbO1xDUA+MsQZvhE J22dSqoWQlPQplRgzo7U8KQCRqaB18kAuJ3C94fWin+iuSPCwCA+CMmDJwFsKY3zi/Gr 5wWGiPWo4k32fUHLCpDTgmm2iPMlPIENXHNHjKTjVOSINhZjC/ukwstQ7hu5Z3RJ6xk1 kFHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; fh=01HD8dtuIqmy9rV/eMJuvD8dAGq4TXBqBjIxWaMzNQI=; b=oHuwIc9w+y/woTHIRtz4NY1MHNtiRmgbuNR94+xmA/c4gNTUyuC8joz4+xBvj8gSJa PcGU2XZafFftFDRa5AbSI0vlsNF1fpuTRh1IvLvlvkab7V0AkeN4WpS6xgpBemN/KKtX q01HhnQBcZiAwSF2M0CsYE286F4MHTGZsxVAC0St0w66Apwxaxi0Dnfb4psRAP4ra34D UvmF+MWswpiPKRdZBR3E2t+kv06jzWePI2TJHI1cdDt2yZ7gGr/I4+y8rPmbmMB7835V k1IBIMv6mW9Nfi+fhWuDI5UUDSZ4FgU1PPbSaeMfaQRotXFk287YxquQtr77lSBoRGdc Odbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qOUBqvnk; 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 qr19-20020a05620a391300b007706c5a23f6si1570477qkn.175.2023.11.03.05.24.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:43 -0700 (PDT) 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=qOUBqvnk; 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 56B0F3858C35 for ; Fri, 3 Nov 2023 12:24:42 +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-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+patch=linaro.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)