From patchwork Thu Nov 2 19:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740479 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp1024669wrv; Thu, 2 Nov 2023 12:55:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkjXF9luxZTgIOsmstFzUZs5KBzmhqCBz6uMf+4Qsg9vFpQpsfuqZh7XO+LGDA9AFskz7l X-Received: by 2002:a05:620a:28c8:b0:77a:b77:bcb3 with SMTP id l8-20020a05620a28c800b0077a0b77bcb3mr22803117qkp.5.1698954953502; Thu, 02 Nov 2023 12:55:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698954953; cv=pass; d=google.com; s=arc-20160816; b=SFbetuPVOv2+p2c9O1sNdli8wg/TIRRhQKeLfF9gtrPaXSM+GY/8A0lMYfNUWaesHp 8CMsXLhSX14O2z6pyHXO3pZGoTCxb716nWJiwyVY+56ATyHbmoJqNMO0LSEoBXKje/ze m00tK0kVWjm7iEPIZlldlaPbZkV64Umvsb2VEeJB/OvAGFM+4d8bUmKHpLSAnllECM1q fMpT0YaPV228/UQT2/2dgnTttLAsq68yH6st3xh3K+jOMzoxtz3JDpkmrcyW2XPpdUlK qYe7SgthRWutpJ7E5lle3Hp8BDs4kVkZpP8xk22eTSQQRa0PFmyeOuCNAZQawtFkLf5w wM1A== 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=0/Th0rnzat0ccCHU/rtl8Xp1F0v7DR7JO8hig3VmBqO3Bom2CfAlitUyYkJmbIweqG WTdHiRD8/x2aT09fOy1vdFBi8FEll9SIzYOVFR80Bxg3C29T9WScOzQ4GEVU8L0evhIA LN6jQP7fH7yWpTvVzSl05g0wv5re1C1JTOt3EihGLGarRjhojR8hNPXcvOs4YZFwuiCb RpSa5KcZ+ncMGCXdkggPKuc+XxTXQ4l4Udr8XHSS+oRv5KLPTws3LEOKP1CDvnIwDbZu xS72chGOTKze2/SNBlY42vUf8g/OvzpAhYHN8m6XVuBnUIiO8eD/feXh44jJ07HVHtUw 7NBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DbMSwxdR; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id ro21-20020a05620a399500b007741fee2a52si144177qkn.403.2023.11.02.12.55.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:55:53 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DbMSwxdR; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 2550E385841B for ; Thu, 2 Nov 2023 19:55:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 028863858D32 for ; Thu, 2 Nov 2023 19:55:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 028863858D32 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 028863858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698954947; cv=none; b=qQWOdl93ODKeu8Rr4BJ43m5oy0jOiIU6OYFG//rpE43PS2vHi8jFb7pCrs3z/7dgNq8i1N+9Ik2GfOQ82tlkpfCk3J3KJcVagyPtTsWnV6YUAxdLC8Qq9yMlMoRrc6UAqnKMvvkKBoG743ifkWWs/+e6luQShMlBADFcOfBULeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698954947; c=relaxed/simple; bh=BoHvN498rhA/tBAAwfSg43+0rL0NtgPiLxrEzE2+mgk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=c+p6S16r/t7jS7s4aOqvhQinvKEsLajRwVvFZPHXbsRvToyc3ncTJcreyYcLmkbGsQ9NsEFdYMoaUosbBYfX6h9JEb1Zs3s99e+kTYMBTXIsb5bpeFVwFKBWXyBjgLV5b/EG2EOUdQXsKWKbfqAYJKBiCRIPA8X0jKfqHMZiZcM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5a7afd45199so16677427b3.0 for ; Thu, 02 Nov 2023 12:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698954937; x=1699559737; 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=DbMSwxdRceNYDdOsUR6MMaEt7wr6HMf1XH8dXaETEPcBfONfsw4UohHAoOFVXGPFau 0TrK9WQIHcDezgOEVYM94GnC/QBKGYxyYJIkn03ZSn18Eq8Csm1DG+WteOCtGyHQGbSF mc+TffCVLfa6LiPJDc+EmvxIhYKn/490tFyNV4y+VgRHU/1eZK8XKMqM5Q0fZw1gVURO GJvK/FaexqPsHiPp23xMtypgvDWBZq8BUpPIlEmXT26Fx31PzH4ZLZyVzIXIga+QsX3q kC1K6MT0Ug9TSaZyYzm2HSqBfodu+HLWbmlc//gECPz9baGnOKEaGaUOWOnb2EwVqtA3 dWuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698954937; x=1699559737; 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=mf4cdu7PU0T3SEwq7H0sLEXuEGqaPT5xISZ0RUY+kXtMxz5NeNDdYEa8Lf7WvMMh2T Zs4IqxgxRUT/5LOsq7k7i4BzWHroGetQYCRZX14jF6EpoIwpF0Yzei3aMtBXFNFGONzJ 1sReutrratRNPRgoq4eQhCjoRN1VVszjMtx3aygN3neFcN8cRNxCEHTv/q+b+jDDLAc8 gaXPHr+g6qTaRFaqJ3VdPVnPbsVtp2pY2NtO7MsXu4LdeT9jZlGahSj6o+HG0y/5/eKb UEsK0iaEjQZ88Cm2ve2S1gpmt67lwiAzJ9PCwkKl0W3TQrH2dgeivyapy6LyQCejBEa0 9E+A== X-Gm-Message-State: AOJu0YxEWHWe1duD6v9u1MjojrEkntk3Ja7OfeGtf8VJocTe+Fbykqn3 PLOxXQOfRWRNahRfh+npKzdgzEZHekH8bfsUyZNG2w== X-Received: by 2002:a81:6e08:0:b0:592:9235:4bcc with SMTP id j8-20020a816e08000000b0059292354bccmr702622ywc.50.1698954937548; Thu, 02 Nov 2023 12:55:37 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:eca9:ef98:8277:b817]) by smtp.gmail.com with ESMTPSA id s15-20020a81bf4f000000b0059adc0c4392sm105222ywk.140.2023.11.02.12.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:55:36 -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: Thu, 2 Nov 2023 16:55:25 -0300 Message-Id: <20231102195531.2692153-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102195531.2692153-1-adhemerval.zanella@linaro.org> References: <20231102195531.2692153-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+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)