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 2446C385840E for ; Fri, 24 Nov 2023 16:22:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2446C385840E 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 2446C385840E 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=1700842926; cv=none; b=q6HLP52hP7YpgLALmyDFcLd79XOrolpE6TA5HZ1XbuEetD2/MuVp9QUyaROMFcVznXmKsJB8gqiVoLyfGrgedE4/GdUlLCgWHggFo+ugkEHJA5CHBTjanCdxTDPvbuMZy3GwPoMlcPsek0fNzzqjGklwNMVUXfXmcP+jsQ1aYTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700842926; c=relaxed/simple; bh=C0dMAHrrAaL7bCoLal+JhMDQxES7x8kdsfYklqaoRDs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=rQ8Wk2/vfgqtWBneHdJRMtb0O9VDSEmrujfBKwYdMnHsJk1eFvwKXuC0xSbIDFpzlPLdY2Jcu1ce1+AbAirQZ0aCcjP7q8ZhnCt+IAneoWfQvKvb/ZR8lsGASO2jqRWt/BcK6EwYT4YScpfRA1k+7BaN4pPou8DgGp6Vg9d+krk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700842924; 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=Dsl1Vn8s33L7p1rAWSzzoZXWa9pU0gpxqmOojwwvo7g=; b=WKWtcBxwTm2483PnWCKAG+ES4rBTIyERxfYzaVzrZiPGi+d4z7fpYuDiwZG40HHxXCiXQ+ rtqh/oT16sdBGsk+7pfor/8yZNrfj/gc3QeHMswox6Ol4vmn3iwU72HVxJqQOqqFejf5x4 jOwO7tDvo18Klbx7dX/lO5f3pMiN1to= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-OoG8cianPmGRHGNTaWwzoA-1; Fri, 24 Nov 2023 11:22:03 -0500 X-MC-Unique: OoG8cianPmGRHGNTaWwzoA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-66da680f422so24422686d6.3 for ; Fri, 24 Nov 2023 08:22:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700842923; x=1701447723; 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=Dsl1Vn8s33L7p1rAWSzzoZXWa9pU0gpxqmOojwwvo7g=; b=AYV+cutBvrfwXLap7I9l2oiyNhTKElVtjsetX9IDYlPGElXgo5KTaS1qMx8sAjRxW8 Ux4bAASrWdgkErWrnbmal9M6L8gA1ozZxm3vOeFLeK8vOIuXoSSJ/WZjkAdE0XrCjOLE xU+ubSW7WFHBaWSNqXaWJ+P4u/PuhukCtKrYrfEo1s8I7Iep04+sriaK4mrLOZhkqZvO Ae8HJqbl4xneskXofo6PeW0eDwkHyeVYgXJzpiGrIqseIE8TfqhQqxq++HiJtzIGjayY h4gUNtuI6zbHrOEPBLJNhfTy7aoi2U/0z6f57VZadd2FdAI02K9GGgtjyajr5ZqyWOX8 VyBQ== X-Gm-Message-State: AOJu0YzvZe/tH4ncGrkKVzg+K7y7LrUH6GXKVcg/vXj+RlIXJ16GfAGw l7Q1c7f3WuL1Q4lzIlahdIje/nlNKtm9tP8BUDD9VXVRdQnDoyMgB919jTgWeo90uUF+stDcYPY B0M3boBNVmqMBOcyCzCRyB/ssaNlF698= X-Received: by 2002:ad4:42a5:0:b0:677:f606:1b7e with SMTP id e5-20020ad442a5000000b00677f6061b7emr3748876qvr.31.1700842922808; Fri, 24 Nov 2023 08:22:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4GdYyqxXz3EFapz9a9k9VdoudibAc+anfUCjNUxlBunaoreIJ1hg5XCkMh5+Iiid1fnu5Ow== X-Received: by 2002:ad4:42a5:0:b0:677:f606:1b7e with SMTP id e5-20020ad442a5000000b00677f6061b7emr3748850qvr.31.1700842922362; Fri, 24 Nov 2023 08:22:02 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id g12-20020a0562140acc00b0067a1a8e35aesm475856qvi.97.2023.11.24.08.22.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Nov 2023 08:22:01 -0800 (PST) Message-ID: Date: Fri, 24 Nov 2023 11:22:00 -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> <0f892926-e336-f08d-c96e-0ad38d4ce75a@redhat.com> From: Carlos O'Donell Organization: Red Hat In-Reply-To: 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/24/23 07:28, Adhemerval Zanella Netto wrote: > It won't fail on powerpc (I actually tested using the gcc compile farm), because > EXCEPTION_TESTS (float) won't be checked: > > volatile double a = 1.0; > volatile double b = a + a; > math_force_eval (b); // It will trigger the exception > volatile long double al = 1.0L; > volatile long double bl = al + al; > math_force_eval (bl); > > if (ret == 0) // ret will -1 here (this very fix) OK. Agreed. > puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); > else if (!EXCEPTION_SET_FORCES_TRAP) // EXCEPTION_SET_FORCES_TRAP is set to 1 OK. Agreed. > { > puts ("fesetexcept (FE_ALL_EXCEPT) failed"); > if (EXCEPTION_TESTS (float)) > { > puts ("failure of fesetexcept was unexpected"); > result = 1; Where do we set EXCEPTION_TESTS (float) to zero for POWER? sysdeps/generic/math-tests-exceptions.h:#define EXCEPTION_TESTS_float 1 sysdeps/generic/math-tests-exceptions.h:#define EXCEPTION_TESTS_double 1 sysdeps/generic/math-tests-exceptions.h:#define EXCEPTION_TESTS_long_double 1 sysdeps/generic/math-tests-exceptions.h:#define EXCEPTION_TESTS_float128 1 > } > else > puts ("failure of fesetexcept OK"); > } > >> >> 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++; >> } > > I think this is essentially what you think my proposed change is incomplete, > I assume that EXCEPTION_SET_FORCES_TRAP is a hit since I think it might be > possible that either kernel might paper over this limitation (by some instruction > emulation to hide the exception signal) or a new chip revision might eventually > fix it (as i686 did with SSE2). > > Maybe it would be better to assume that EXCEPTION_SET_FORCES_TRAP is a failure > expectation and trigger a regression is function succeeds. Correct, if the function succeeds then it is a failure, it's likely someone broke the conditional and now we have a function that is back to raising traps by accident like it was before. It is a regression of bug 30988 if it succeeds. > >> 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? > > No really, the whole point of the test is to check: > > int exc_before = fegetexcept (); > ret = fesetexcept (FE_ALL_EXCEPT); > int exc_after = fegetexcept (); > > Will not change the exception mask (exc_before == exc_after) *and* not generate > any trap (which you abort the process). Also, for i686 we need to trigger some > math operations after the fesetexcept to check no exception will be triggered. > > Now, if ret is 0 everything works as expected. If ret is -1, it would depend > whether the architecture has EXCEPTION_SET_FORCES_TRAP: > > * if is not set, it will depend whether the architectures allows setting > the exception for the specific float type (EXCEPTION_TESTS (float), which > is expanded to the constants defined by math-tests-exceptions.h). Some > architectures does not support exceptions at all (riscv), or it depends > of the ABI (arc, arm, loongarch, and ork1 in soft-fp mode). Agreed. > > * if it is set (powerpc and i386/x87) it means that there is no extra > checks requires, since the failure for these architectures *is* > expected. Agreed. Though EXCEPTION_TESTS is still relevant here to avoid regression. > > So assuming EXCEPTION_SET_FORCES_TRAP is a hard indication, I think this > below would be suffice: > > if (ret == 0) > puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); > else if (!EXCEPTION_SET_FORCES_TRAP) > { > puts ("fesetexcept (FE_ALL_EXCEPT) failed"); > if (EXCEPTION_TESTS (float)) > { > puts ("failure of fesetexcept was unexpected"); > result = 1; > } > else > puts ("failure of fesetexcept OK"); > } > else > { > if (ret == 0) > puts ("unexpected fesetexcept success"); > result = ret != -1; > } > Pasted below from downthread correction: > Oops, the above does not make sense: > > if (ret == 0) > { > if (EXCEPTION_SET_FORCES_TRAP) > { > puts ("unexpected fesetexcept success"); > result = 1; Yes, this catches a POWER target regression for bug 30988. For the sake of completeness and the use of internal macro APIs it is conceivable that EXCEPTION_TESTS could be used to check if the test should even be checked (like my suggestion does). I consider it a simplification that you are applying target knowledge from other files in the tree to skip that check i.e. you know there is no EXCEPTION_SET_FORCES_TRAP true target that is also EXCEPTION_TESTS true target. Is it correct to apply that simplification to this code? Or should the code handle both EXCEPTION_SET_FORCES_TRAP and EXCEPTION_TESTS permutations in a generic fashion? > } > } > else if (!EXCEPTION_SET_FORCES_TRAP) OK. This is all other architecture failure paths. > { > puts ("fesetexcept (FE_ALL_EXCEPT) failed"); OK. > if (EXCEPTION_TESTS (float)) > { > puts ("failure of fesetexcept was unexpected"); > result = 1; OK. This is the failure path for all targets that can do these operations. > } > else > puts ("failure of fesetexcept OK"); OK. Because it shouldn't be tested e.g. np-fpu targets. > } -- Cheers, Carlos.