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 A1F1B3858D1E for ; Thu, 23 Nov 2023 21:47:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1F1B3858D1E 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 A1F1B3858D1E 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=1700776046; cv=none; b=ZQ7zsop/+aPy0KLfSggTrn6YGitr5komktZn6BlgdrhbPhV4mkeF2cSrsh9pZKVbUKCxdNzfll/ppbjx4LdauDVpsiTciMoOJY5t1x/qY+4gDTAPUtwkqdh+Iyum4r+X1+gNCMPBXqRxcoIUcC3vJzaSE+nwwH8nTAJ2nkyLugI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700776046; c=relaxed/simple; bh=ZFT3FmCEidXTAkoB2nRiDzw716BH25GRRJo1bzNxYLE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=QJRHXqC1qS8owBjVjEnD15HWIoMZgUmvCOCnlUHU9lDsg/LAzbFxMORVo3nG0sXgLew0F8HDj4PMOhrZbTmvqfwRY36dp7q9PlwBHZgPHQNzYM4t1gCAPEAbBOt8nXC60SMuUDPVo3NyIdUG+YFO9CFxcs6P22FpAAIJ1/dF2JI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700776043; 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=h/wI4Wu6JEmn9wxcn0qNzb/GRhVkcjhhrO8oFFtOTIg=; b=C+yQp6Im/GFFBVZd15tBBEmtZf0CqFgMehSLz+1cBycpmCuGPxI4KrLqpqCGe29zZATkJW p7qdYFuHkwZTucTMMXjGqfoqwXpdrmxohyIo3mMTW9SLi/cch6C0nG+ABfr7Lnb2WSp//e sUc8sz0hJ1iMK7d6uGaJMh/IebuLxps= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-qkj7DDHmPwKCkPFe1JQKlg-1; Thu, 23 Nov 2023 16:47:22 -0500 X-MC-Unique: qkj7DDHmPwKCkPFe1JQKlg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-77d7178e312so89761385a.0 for ; Thu, 23 Nov 2023 13:47:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700776041; x=1701380841; 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=h/wI4Wu6JEmn9wxcn0qNzb/GRhVkcjhhrO8oFFtOTIg=; b=Npa8q4lpwHHTn6iBtcyw2BxiqXJdgu1MuRH/HR+ObvlHsR1Z+n0W50s4K/fRDKWyYr Sb6LHGY3f6tKqdHpjXRoZLchY9wKA6PEY+q3x29966+ZcIENuSyYnn+tr9gv5xfmrVJN xsx6aZLJT5WPtTdT4eQuB++kgo8eaHJlgCZ2Fn9eEP6DWS8nvSIj45aX/xn3pZbYGySH lbBYpAuGgamJwWl1oCXKxa7Ly+vm+SwoneBQ5h7Mc6H7bbmkLIQv/eVnAjEzoRPnAZL1 NqfEkibduMBnUjtI5zNGvfjSl2NAV/fuQfX6D1jU1CgW6WpkLkovC9oA3bbqOq79VpGr MUog== X-Gm-Message-State: AOJu0YzbG03jRkoltmxBiBFezLoI0cKY9nyLYTNK12ryY+iKRm05Kbdg D2MZD91E0Q/kXD3DO/+6C4rLhfJPsto0+MZP7Bi0k89RU+APXQRqgLQ5c2W8BxGVRSxVMVTUTy4 Dl8jof6+SRawF+k+QGEqwzv8554gtnnk= X-Received: by 2002:a05:620a:1d08:b0:778:8ec4:e046 with SMTP id dl8-20020a05620a1d0800b007788ec4e046mr860616qkb.29.1700776041493; Thu, 23 Nov 2023 13:47:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3eqMdqsBbwFuKTIBEDqbkri3jVX82w87kwaq2mrR3eKRev80zY1toieD3n8Dr5Vtt7pjcQg== X-Received: by 2002:a05:620a:1d08:b0:778:8ec4:e046 with SMTP id dl8-20020a05620a1d0800b007788ec4e046mr860600qkb.29.1700776041030; Thu, 23 Nov 2023 13:47:21 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id po4-20020a05620a384400b0077d64224789sm747588qkn.36.2023.11.23.13.47.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Nov 2023 13:47:20 -0800 (PST) Message-ID: <0f892926-e336-f08d-c96e-0ad38d4ce75a@redhat.com> Date: Thu, 23 Nov 2023 16:47:19 -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 Netto , libc-alpha@sourceware.org, Bruno Haible References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> <20231106132713.953501-2-adhemerval.zanella@linaro.org> <6130f4c9-dab2-6f8e-5bc5-902b5a48e2dc@redhat.com> <5e031d35-5d3e-49a7-b354-809bb4a1dc8f@linaro.org> <6e4ff3c5-8504-79a4-8865-0239b0cd7185@redhat.com> <8aaf2565-5310-44aa-a331-6d12b26d2274@linaro.org> <3052e518-dac2-4b23-a070-787db5e13bf2@linaro.org> <6e52fa2f-9198-4a0a-9c77-80a1eccbd347@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <6e52fa2f-9198-4a0a-9c77-80a1eccbd347@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: 7bit X-Spam-Status: No, score=-12.6 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,RCVD_IN_SORBS_WEB,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 15:46, Adhemerval Zanella Netto wrote: > > > On 06/11/23 14:56, Adhemerval Zanella Netto wrote: >> >> >> On 06/11/23 14:38, Carlos O'Donell wrote: >>> On 11/6/23 12:11, Adhemerval Zanella Netto wrote: >>>> >>>> >>>> On 06/11/23 14:02, Carlos O'Donell wrote: >>>>> On 11/6/23 11:50, Adhemerval Zanella Netto wrote: >>>>>> >>>>>> >>>>>> On 06/11/23 13:08, Carlos O'Donell wrote: >>>>>>> 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 */ >>>>>>> } >>>>>> >>>>>> The '!EXCEPTION_SET_FORCES_TRAP && ret == 0' or 'EXCEPTION_SET_FORCES_TRAP && ret == 1' >>>>>> checks are not really meaningful: either the function succeeds and return 0, or it fails >>>>>> for some reason. And for failure, EXCEPTION_SET_FORCES_TRAP really means an expected >>>>>> failure. >>>>> >>>>> Sure. >>>>> >>>>>> So if the function succeeds and no trap is generated (which terminates the process >>>>>> as default on Linux) we are fine. Otherwise, it check if the failure is expected >>>>>> (EXCEPTION_SET_FORCES_TRAP). >>>>>> >>>>> >>>>> So we go from UNSUPPORTED to... ? >>>>> >>>> >>>> I though about that, but the test also checks fegetexceptflag (a better option would >>>> to split the test in two, so only the fesetexceptflag is unsupported on ppc32). >>>> >>> >>> Perhaps the best option is to just keep the UNSUPPORTED status? >>> >> >> Fair enough. > > Revising the patch, I recalled that I explicitly removed the UNSUPPORTED > so the test can now check if the fesetexcept does fails with -1 for > !EXCEPTION_SET_FORCES_TRAP. I am not sure if adding it back is an improvement, > it means that it won't actually check if BZ#30988 is really fixed. My apologies that we have gone around in a circle. Let me start again. And for the public record and your review I'll write down my assumptions. (a) Previously calling fesetexcept() (ISO/IEC 60559) or fesetexceptflag() (ISO C) on POWER would raise a trap because the hardware can only raise the flag if it *also* forces a trap. (b) In Bug 30988 (a) is raised as an ISO/IEC 60559 and ISO C conformance issue. And the fix is to return an error from fesetexcept() or fesetexceptflag() if the hardware cannot raise a flag without *also* forcing a trap (which fails to comply with the standard definition). (c) In your patch 1/7 you want to remove the "return 77;" for the EXCEPTION_SET_FORCES_TRAP path because it can now be tested. Given (c) my expectation is that we *actively* test for the failure. Your test changes look they will cause POWER to now fail the test, particularly since 'EXCEPTION_TESTS (float)' for POWER will always be true because we want to test exceptions (it's just that our expectations are different). Let me sketch out what I was expecting for both test cases: diff --git a/math/test-fesetexcept-traps.c b/math/test-fesetexcept-traps.c index 71b6e45b33..5ea295a5b8 100644 --- a/math/test-fesetexcept-traps.c +++ b/math/test-fesetexcept-traps.c @@ -23,46 +23,97 @@ static int do_test (void) { - int result = 0; + int errors = 0; + int ret; fedisableexcept (FE_ALL_EXCEPT); - int ret = feenableexcept (FE_ALL_EXCEPT); + ret = feenableexcept (FE_ALL_EXCEPT); if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (ret == -1)) { - puts ("feenableexcept (FE_ALL_EXCEPT) not supported, cannot test"); + puts ("UNSUPPORTED: feenableexcept (FE_ALL_EXCEPT) not supported, cannot test"); return 77; } else if (ret != 0) { - puts ("feenableexcept (FE_ALL_EXCEPT) failed"); - result = 1; - return result; + puts ("FAIL: feenableexcept (FE_ALL_EXCEPT)"); + errors++; + return errors; } - if (EXCEPTION_SET_FORCES_TRAP) + if (!EXCEPTION_SET_FORCES_TRAP) { - puts ("setting exceptions traps, cannot test on this architecture"); - return 77; + /* Verify fesetexcept does not cause exception traps. */ + ret = fesetexcept (FE_ALL_EXCEPT); + if (ret == 0) + puts ("PASS: fesetexcept (FE_ALL_EXCEPT)"); + else + { + /* Some architectures are expected to fail. */ + if (EXCEPTION_TESTS (float)) + puts ("PASS: fesetexcept (FE_ALL_EXCEPT) " + "failed as expected because testing is disabled"); + else + { + puts ("FAIL: fesetexcept (FE_ALL_EXCEPT)"); + errors++; + } + } + ret = feclearexcept (FE_ALL_EXCEPT); + if (ret == 0) + puts ("PASS: feclearexcept (FE_ALL_EXCEPT)"); + else + { + /* Some architectures are expected to fail. */ + if (EXCEPTION_TESTS (float)) + { + puts ("PASS: feclearexcept (FE_ALL_EXCEPT) " + "failed as expected because testing is disabled"); + } + else + { + puts ("FAIL: feclearexcept (FE_ALL_EXCEPT) failed"); + errors++; + } + } } - /* Verify fesetexcept does not cause exception traps. */ - ret = fesetexcept (FE_ALL_EXCEPT); - if (ret == 0) - puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); else { - puts ("fesetexcept (FE_ALL_EXCEPT) failed"); - if (EXCEPTION_TESTS (float)) + /* Verify fesetexcept fails because the hardware cannot set the + exceptions without also raising them. */ + ret = fesetexcept (FE_ALL_EXCEPT); + if (ret == 0) { - puts ("failure of fesetexcept was unexpected"); - result = 1; + puts ("FAIL: fesetexcept (FE_ALL_EXCEPT) succeeded unexpectedly"); + errors++; } else - puts ("failure of fesetexcept OK"); + { + if (EXCEPTION_TESTS (float)) + puts ("PASS: fesetexcept (FE_ALL_EXCEPT) " + "failed as expected because testing is disabled"); + else + puts ("PASS: fesetexcept (FE_ALL_EXCEPT) failed as expected"); + } + ret = feclearexcept (FE_ALL_EXCEPT); + if (ret == 0) + puts ("PASS: feclearexcept (FE_ALL_EXCEPT)"); + else + { + /* Some architectures are expected to fail. */ + if (EXCEPTION_TESTS (float)) + { + puts ("PASS: feclearexcept (FE_ALL_EXCEPT) " + "failed as expected because testing is disabled"); + } + else + { + puts ("FAIL: feclearexcept (FE_ALL_EXCEPT) failed"); + errors++; + } + } } - feclearexcept (FE_ALL_EXCEPT); - return result; + return errors; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include --- My point is that by changing the implementation we need to test a whole different set of conditions now and the test needs expanding, likewise with test-fexcept-traps.c. We need two testing paths with different expectations? -- Cheers, Carlos.