From patchwork Tue Oct 24 11:37:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 737534 Delivered-To: patch@linaro.org Received: by 2002:adf:dd81:0:b0:32d:baff:b0ca with SMTP id x1csp1978007wrl; Tue, 24 Oct 2023 04:37:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG90IiqWO8jtykBXeDIMOC532xrV2ijUL5H3UTQ6BOc8YyNOd62Kc3EIbj1fpvO6fJnjiTt X-Received: by 2002:a05:6808:1586:b0:3ae:5c48:6f41 with SMTP id t6-20020a056808158600b003ae5c486f41mr14774220oiw.28.1698147454834; Tue, 24 Oct 2023 04:37:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698147454; cv=pass; d=google.com; s=arc-20160816; b=CIlY8Gpr1gogYVysI1ROxGh8OJWBhpaXcBkoVgqYnw2WjWx5FdlYferVk5nC3JJiYb JzjZQ1MSZ0rNCIWpC7dv9MX1+KzjJi+P3bDKU7YRa/+Qwv/vI76Vz3ET6ZfssgP8tCFX Tb0d9xTmZIkhXllDEIyaZoDISGE5ycAA2mIXG5sc3+FkMGFNNiVOXT/ITr1aj5DOS2Zc v16JfHsbHnOj+9U4/oZuobDicWtYPNwBPZhZNOIv8+CfbD+MiJlyY6dVOGoCM6GXhdon sk6CbvX/oQEvdOL6fL+qotIceRB7tyzl7Pndt3LfkmnCARsCgDyFtJo/wUYQzrx8UEGJ LjIw== 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:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; fh=Rk9vnpDApgYog/EhmGDFyutcQpHXbdLZmc0l8HNU7lw=; b=urjpAvsrO5b8TH8EGehE8cSQ/IGRx4pu4lymAqvsChiwupwGcepJMfoxKbctx4Dw1d CsAwH6q9xGH0glJl1U0RKPT1KlYby0WFtGw1yGJOUncsSeppVBgbiJSv74hKe9oBTIoa pofHT0ZtbwtPEwPE/tx3/5KiYKzT2EmIqFCajPesBau3A9QkaNSbWsI4TkJif1nSR6JP b3cAQ5Evp4VRZNHYpIsDlgUw1xtjaeCUHXI+8yeROUJIpYbc4umb81og0chjN8KMJkDW Wg1iFC+wYXrjNEJTX0vEIBBdlIY53Gbl73fcFFV7xpfox9X9Fol2nWMs3obYERGgS/rB pGrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=unUOqII5; 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 v9-20020a05622a144900b004181d34928esi7202633qtx.373.2023.10.24.04.37.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 04:37:34 -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=unUOqII5; 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 7B96C3858433 for ; Tue, 24 Oct 2023 11:37:34 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id A64823858C50 for ; Tue, 24 Oct 2023 11:37:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A64823858C50 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 A64823858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698147448; cv=none; b=QpGKTMrpLX/0fswDsb09XUaHBUh3tdUFRCP9XQRaGqPNATIxgyV729vh8bXI9tTxHMc/QYXI3ql2Wwt+RQX4AFgl8tSZshCc8X3X9Hecax8tuOMQACFIYCExuTkmB617R/+8kFZDrWZ4yYXL585iM0q4ulne2/P+CaTQF8ED/7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698147448; c=relaxed/simple; bh=BoHvN498rhA/tBAAwfSg43+0rL0NtgPiLxrEzE2+mgk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=L2i2pfy/oK8FpEZyRZ5lBAiFLwowZi6aaucDLfFeCthDLpa/XJMkQ1he4vKjrF+acL3x8Yy8e0UOMmgpMVpmjywYxhMr8p9Zvy5meRYdKd885OapqQsvEMz3EP+yUP6L62PcxFJD1aAfY9cIbIt6PuHDyFO9YUZRsS9D7eYJ6ag= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5b8f68ba4e5so112844a12.1 for ; Tue, 24 Oct 2023 04:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698147445; x=1698752245; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=unUOqII56St3bNkRekE9UyerBJNve2LMk49G1qvwN/d7L4noaopXZJqS8LntdFvDaT zbjx3X5XejjnIS5W/02ZetCPvPHjIwrxEPrM35wKXRn1rmd2vnhvxrncUcCU5qOvhWTA d5JjhnIPv3+vBJnsByaQ1CFMloN4JoqCYH7k4+ga+zzczMjUN2VxIttE83/cCIARCEeq F5WZWIemUITmeYCBy0RvjHrKwt428QzcX8f87Xg/Fy40SLp+Aap00wyIxWmwW9qGe9ue n0SU/6QPPwJnpZrHCkJCIgRs/zyayjCa3De0txPkJo4GWdxekAzzjB2rpYgbUy/HiYkb h8Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698147445; x=1698752245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOvdAysXA05qPpMnEVH8JkFq4y3flQAfl9BCWlDaPAI=; b=LBN0OrPyVj9jikRZNkUAKhzXbVQAhwvkBxD6Cnr//Cxw+OQuMafnOsKfVqWpaQiAcd mHaf72oCZeoY4BSTkUrq666Nptg5UWxN7iTDzUtldlIsjmyF65I0MEMfZM5WaXbmnS+/ L46QR+kt5yzCw+gnva1q/tdCOHSokBpO932k2A/P7V47yYaWb6CPo3FhvjD9itnrlVIb EIdSlhMahUyXsTchxKIOnMj3jDU1NrhUtKK++EPtyTzRgb0MxTt0DQv7NqVWjsIPeE+H swb7UxcBJhNh9DneLogRfcRw9ZK+p2B6+uhI4OtT2MDx0URn1uTRZ5D4qyDlBUwmIrC9 1EFQ== X-Gm-Message-State: AOJu0YzFAlXs7EaTg58Qdxv/gB9OBl475229z+iEi8y3nIXHV3kN4crX UnD5VMBSzkDkM+lDZ1GLerMlwx0dAeeBcvbscvmviQ== X-Received: by 2002:a05:6a20:7287:b0:17b:2b7e:923c with SMTP id o7-20020a056a20728700b0017b2b7e923cmr2651299pzk.16.1698147445144; Tue, 24 Oct 2023 04:37:25 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:a647:44d5:84b0:a3f2:fe73]) by smtp.gmail.com with ESMTPSA id k28-20020aa79d1c000000b006bde2480806sm7506663pfp.47.2023.10.24.04.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 04:37:24 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Bruno Haible Subject: [PATCH v2 1/3] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) Date: Tue, 24 Oct 2023 08:37:14 -0300 Message-Id: <20231024113716.3911015-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024113716.3911015-1-adhemerval.zanella@linaro.org> References: <20231024113716.3911015-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 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)