From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0847C385773A for ; Mon, 6 Nov 2023 16:08:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0847C385773A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0847C385773A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699286931; cv=none; b=hZE639tnprOD50df+VYq+gXQjRY8GdSPytAjlqoI550aYjnbjj2yGrpQhfgRrzoXJun5hpQ6nk/VLU3JDcjAy9A/+U7M5JEOB+47cs8KjirAMM5bNk3RGMFrwUn79YMeBw0Q2mcaNAbNmD1FGfGGlfM5oVD6hdxdu1iE9+BB5s8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699286931; c=relaxed/simple; bh=OtyW2uYS++wbnv6V1pPRIJfmB4wwgXTyORQL6+44WcI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Qj11+Zn2gp6EObxSDYwxYDnrneOL8w1WEH1PTQ/8DKM76VoCOALG3EeLuEZGOq9bmdoGh6pvPgEcqCKkdMKVxV3AOj+9HK91b5OCCiktGle8ZzpSgqhXeZuRDSC4VN7OPX7d8MojptWu4UH2mz9ClpI3RQemQwZzKa1F8GZSfjI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699286929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7XteXSr+NRPfdYy/uud2Nmyp3E2h20yUmxFLqoiNac=; b=Y1VBxBm3Prtzc3x0l+s2Vep58YCburYPObIO6i5NbQ9OV00/q5XLwfdHUnCZ8nfwnEUy2M 81n0t7+OQyDqv3Oppf1kPqpiMxMXwCNMJAqDCTZcV5AnASqm572wCNldY0TyAmXnUjo8Xw kaCiLi95A3ljEQv3TouarnkcqGjkZ98= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-YnRfbLa4Pl6HJsG0fT4HAA-1; Mon, 06 Nov 2023 11:08:48 -0500 X-MC-Unique: YnRfbLa4Pl6HJsG0fT4HAA-1 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6d345756155so3178772a34.3 for ; Mon, 06 Nov 2023 08:08:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699286927; x=1699891727; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T7XteXSr+NRPfdYy/uud2Nmyp3E2h20yUmxFLqoiNac=; b=Y+kQzI9XJM1HzGAsRcq8v7L9OMLY1z5L4jkFNd6UYkC+UDF6EGILTam1S0km12vWLQ ze5/x8U76fn73KJSfmJBj3bA1noXPwDdETzjfglGRxzs57+LN/z1LiJcZ5wwL/ZOOIKA WFGgid8OTNEbKu7a0XgKlQdkxMV6gnkFDeMl/w0dNDWs1oEj1zpSv19q0GKgObdRh2b2 QPtpEBqDsN8QMczOmjLPzUFBudZPZKehY6xpA3RsS3q1j6DozMWAVm2Ui6QqdPJ5HR+y Elmp1jc+D7RPu2velYIbZnccTESuLkUtXOKxLfi5PK1uq7NG7jTtiqow3gu5vIdxC5lM qU1w== X-Gm-Message-State: AOJu0Yzzo+w+LOP1gCPklHGNL8tbxBqaZ/xgF2qZYlpLL5RCl/FmW3Iw R2byRdD0ZHEr25W+iXWI3/blPTmFHMFRfLFQCTr2dDQX2L3/zTdMU7yjeE8/98SpCuIxZHYkiNq bn9dcBUD+WyyGTcOZvo88eaaCRRCx X-Received: by 2002:a05:6830:3499:b0:6bd:152f:990e with SMTP id c25-20020a056830349900b006bd152f990emr40298167otu.5.1699286926861; Mon, 06 Nov 2023 08:08:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0u3B4LIvYLhfsNeRn0xNqKF16ia0s6IZZN6OyHX/dWwX08wmhVQ0WLNzxuODBY6yr/hRS/g== X-Received: by 2002:a05:6830:3499:b0:6bd:152f:990e with SMTP id c25-20020a056830349900b006bd152f990emr40298147otu.5.1699286926622; Mon, 06 Nov 2023 08:08:46 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id b17-20020ac844d1000000b00419b67d2823sm3516606qto.34.2023.11.06.08.08.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 08:08:46 -0800 (PST) Message-ID: <6130f4c9-dab2-6f8e-5bc5-902b5a48e2dc@redhat.com> Date: Mon, 6 Nov 2023 11:08:45 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2 1/7] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) To: Adhemerval Zanella , libc-alpha@sourceware.org, Bruno Haible References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> <20231106132713.953501-2-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20231106132713.953501-2-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 11/6/23 08:27, Adhemerval Zanella wrote: > 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. OK. I reviewed ISO C 2x (n3096), and I agree this is permissible and preferable. > > 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. Changes test from UNSUPPORTED to PASS when we should test more now that with C2x we're saying the behaviour will result in a non-zero return... then we should test for that. > --- > 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) We can check for a non-zero return if EXCEPTION_SET_FORCES_TRAP? e.g. if (!EXCEPTION_SET_FORCES_TRAP) { if (ret == 0) puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); else /* fail */ } else { if (ret == 0) /* fail */ else /* pass */ } > 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) Likewise. We can test more now. > { > 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) -- Cheers, Carlos.