From patchwork Mon Nov 6 13:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 741391 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1083584wrr; Mon, 6 Nov 2023 05:27:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwYtif6DoAnuIjffLFPf1ZW46xVEdpb70BmCu1/0yn/UkjOd/W8RqKaC0TPlXG9FiwQN+f X-Received: by 2002:a05:6214:1cc2:b0:675:7b22:4f74 with SMTP id g2-20020a0562141cc200b006757b224f74mr7301184qvd.18.1699277246985; Mon, 06 Nov 2023 05:27:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699277246; cv=pass; d=google.com; s=arc-20160816; b=LwGCxzL9EP4GTTnflsr/Kik3DjLi1uxg4lJXZB9LPAvQPPUpm85lGqObl2kpkPwgkq IzSJJK9oc6ezOVUWKqbrjRMRs0GLLWl8A0mgvgpPU+EHAw5C1ckXtNAuwOSchFFRuaiP 5QPz6ySGWm1Hj/nTvMqi2hJ4A0Xgc6Mj2mtbDqJgpXb/HOdSyL+avvst+ZGLa5rm6gF9 wUZR+Q06OvKx6WXam2XUr5FxC0yoOFqS0k8Se5jsqDq5UgD9Y8J2cpzw6gQ/OztiPIWi OFjG8swGqRr+OuM28K1rFJvxpiEm6l6Ix6tpd9UM1ZM8I0r3UZaqICADOt8/O5/lTGyj RS8A== 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=Gxu1uFIigfZRlzisyOcxli0snlDvLdq/i9NAZItQo2GrtQMiTFwljWQofUxfJl1OuF Lxxf8JXuY50YuY+uM2JeWPoGsMkFRZCAKn3Qj7hGkVAY6u70PR95M7XHnP4TNVPzI7P/ OYT8pWlTcVYZv8WtRWWcQxEa+7N4Ofqcq/gEj5PVR5TP2E9dId+jOQ9Fa6mkdpPjMs+t 1gtwyykmzIxTYJ//HB+aihwPBOPQOGUpLznWAs0k3MmqyGvAdrddiw49ZMNDQDhJ8mmU WhHXKsFwqw9XuNMM75+Puc1sOZ6JtYp2544INuWrwt/9LhQu9vGV0RkHtuVJxmC2BgGs 0C5Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S7kVDzyB; 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 u3-20020a0ced23000000b0066fccf78119si5547663qvq.295.2023.11.06.05.27.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 05:27:26 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S7kVDzyB; 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 A08B2385701C for ; Mon, 6 Nov 2023 13:27:26 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by sourceware.org (Postfix) with ESMTPS id 50C5A3858D33 for ; Mon, 6 Nov 2023 13:27:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50C5A3858D33 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 50C5A3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699277241; cv=none; b=bgkcvils2Nudg77xZDaophXA8XCHf5PmlurAVQRREXsIvd2PZtB4IVtJ3mfEaPlq03eCxj5N4chFpnKJkWAhNylkqxaDrVCPQdGH0jCmzRuhZ+Ei2sIYtUJSKs4a9K+C2MvYsgHq4Xjzci7IDGXgEHNsGffJ5o5fZynPOs4QdSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699277241; c=relaxed/simple; bh=BoHvN498rhA/tBAAwfSg43+0rL0NtgPiLxrEzE2+mgk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=eBdWej3KqMymIOtuh6Ea3waDREZJJbMPkIUDaIDxinL+ePgeggb8MEA7Nml2WGsIxtAmz4Uzo+hJuFPhDCtEBDHwb0f/chEiM38ZfuwJJod/6OovfpfaXLDJHGcTH5A1Yvjk0cd4GY5L0zmbLxt4oEJX5AUKFNNausaRoOnkWhg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vk1-xa33.google.com with SMTP id 71dfb90a1353d-4a18f724d47so1397256e0c.3 for ; Mon, 06 Nov 2023 05:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699277239; x=1699882039; 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=S7kVDzyBZwkKG3XCrk9FPbmwZTARuihweLzhJfeznNwAE8a0uGlD/Ll1r4BoJ61r2y dy/MlVHk1rbP7ILYX3fyWFkxS62rbw8kr0AcV2+ind5Cm+wW/qvpoi7hjhT1560ZVbxG h3B/t4GkJeXR2o+DgvT9aRpbo6bWZ9G6f5giYo4PmapJhxT7AzdvvOBb0u273KUaCplK WOqYApfcgwgoykQNhRdXHpbTgTqmwAaVshJbQPl1M7AXL4DlA/lDMMBcHiz6hejwYcpJ oTXSclQeMJBz4YQTTHq6Ie4a53HThp50W3frZF85FtaFxUtPbehIFw3AggIDncbDKXuw 5x/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699277239; x=1699882039; 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=Tg6ITE/V9+ndUmY2Ka28VA8J22uVJmu8DUy2eNXJEf0uAb07o78ywUjQ3RGYR6oxwZ DLkRvuqwM6fH/7j2mi5rvoQVQFqnfbxo/3xrcYIj7IO01kOl7d5WYy+lWgQVjCNDiDAU FNJYkn9f4C5W08L3odVKesGVQF7uB811uJAF/xPG/OP1d4N9ZRS7FQHePfaRcmKiFTCL 9WHWQXPi5xdQ5GoY4u1Wgqbyxb88yv3HtOM9AhRwuDB6ZD+XDIgB8yk3pZB9QvzIgZaY DCp/cMFUleZbnostmxFnP0ocR8y47t5HrMsQEWtFt2QtWJhV7XVI4shOumynyYy9G0qL rMDw== X-Gm-Message-State: AOJu0YwtDANd6TBFHT887UbBznIOJLmgPEmI8nyM4BoEgqC5tEad61jU sSem8Z10limTZwqCQyCcuDhi9hJzc1hgN+Gw23hXHQ== X-Received: by 2002:a1f:9d04:0:b0:4ac:6a9d:c49b with SMTP id g4-20020a1f9d04000000b004ac6a9dc49bmr701679vke.14.1699277238884; Mon, 06 Nov 2023 05:27:18 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:a715:c1a0:7281:6384:2ee9]) by smtp.gmail.com with ESMTPSA id k3-20020a05620a142300b0076f12fcb0easm3272722qkj.2.2023.11.06.05.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 05:27:18 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH v2 1/7] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) Date: Mon, 6 Nov 2023 10:27:07 -0300 Message-Id: <20231106132713.953501-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106132713.953501-1-adhemerval.zanella@linaro.org> References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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. Reviewed-by: Carlos O'Donell --- 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)