From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 224E41F44D for ; Wed, 3 Apr 2024 12:58:00 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fyJGG26f; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66BB73847718 for ; Wed, 3 Apr 2024 12:57:59 +0000 (GMT) Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by sourceware.org (Postfix) with ESMTPS id 836743846410 for ; Wed, 3 Apr 2024 12:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 836743846410 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 836743846410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712149028; cv=none; b=Twqvg5j92i86y1XM1ysDnoVlVHhxdobECiOvwLr9JvMC8S2v+or1+glx0DjBuIQffuLeZktqIyysSp+/1Jn56rLXi3M6olv2KMwN8Aq+UQwMqYBGXLdA749WSaB726K3bxmSrpGCq+hMqi5FCXnUavCZnrQKcZ2dIcnSWXk83vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712149028; c=relaxed/simple; bh=wS8jpBxOTfKxUaqXTOempULh1YbajezaOggVChwvvTU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=vs3k25a1Tl/O6FghFufQjE+Mfj4uPBdzCV7HjfAeNkHGC9LxA06FK5mkK+MU7laqgZxuo9fKtSGv0eshkL8OIMn2kwysDmj2hcVsRUW7IbJxRh6VQocrgqIFhuPiD2nWDjAj9PS271gikyjS2UQA9rxhJWomtxwvOb/rfwJt4KA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-6152be7c58bso17209867b3.0 for ; Wed, 03 Apr 2024 05:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712149026; x=1712753826; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0PQWsIPLV88oN0Rtj1L7JPntioErVbKPcsQNEhxaj3Q=; b=fyJGG26fZLVhi6w0Keb2a/VS7n8HzmiMcWpGxnmep04rhLWZm+mItcuOIzWpXlbVWv lz8DdLVcXgv0vHNPB3QVWJbANvi/Ygztze6oEVmpFb4V5NutcX42xpQxFZ9Hu2jiJEWD OaT8JSkHVC9oOhgxlzDdbeV8Hp77uUDyNk+CA7kOyexE0uhi0YF89DIglqlVOQx4PotV aIzxIr8+19nahO2QptlvvRACXb5WqqCUULyfa+uPckNH3IgUq19aNkoPd+nTZbu06VxC hiOyc/j0xSe6e+BCmAa2Q7GWWU7F8lAG4aGoku6NMQOJxKYqiEXP7L5umTIGqVn/T0Np GU6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712149026; x=1712753826; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0PQWsIPLV88oN0Rtj1L7JPntioErVbKPcsQNEhxaj3Q=; b=CFtgHCTOr2sf4ZSXPTQLRznTY7zAGbMf49ZXZzmwo1WegERhTIuY9CnQ8oC9W9ONtl VbhdfnntI6tvCLTJMeLAyikn8ChlgSvBAEsPhDRwnH9Jv9QlPsho3orI51NwHXCuakWM oNBtqBqpw/lESsBbsXSFC4l4gQajvLvhUHHzKsntxzQw3DJu6X7cihxRmcaBgXjwGU3K 3wCwhUwVrPn0XCyH0cZ9477krhOaN3LFthG9d/cTjR7J1e2W+uFw4ztmcGw3wdUdouIj E+OR9i738EPoGWyY9zh2TKLpkgR4oF9tYFl5mHJWIeIV4Oi7yxyZfBP6R3PIoaxa8nQ5 8n1A== X-Gm-Message-State: AOJu0YwKcUbVts9VyEEdyxeE24iPVG4pXl+BPFefzuFNE7onNYv19PCB x6GbbSuL3HDOQQL1jE/7CJzd7s/soqhBo4Xhmuczt7ZHSTBk4J4OKsXy+oP5NpPTJZmW65EK2bx vGpyKJvleuFC3YbzCmdHOFm9fNvb91GUD X-Google-Smtp-Source: AGHT+IFN+kR1cuS8vwsfvBYOVKb4fzE+iIhB5ikh7AVFpiokpehfkXsU10pRKfpkRxwRGt5Wv6DD0nEiQmitXfrAZLM= X-Received: by 2002:a25:1941:0:b0:dc2:3936:5fa5 with SMTP id 62-20020a251941000000b00dc239365fa5mr11578898ybz.51.1712149025722; Wed, 03 Apr 2024 05:57:05 -0700 (PDT) MIME-Version: 1.0 References: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> <20240403121150.1018799-5-adhemerval.zanella@linaro.org> In-Reply-To: <20240403121150.1018799-5-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Wed, 3 Apr 2024 05:56:29 -0700 Message-ID: Subject: Re: [PATCH v2 04/10] math: Add test to check if round raise inexact floating-point exception To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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+e=80x24.org@sourceware.org On Wed, Apr 3, 2024 at 5:12=E2=80=AFAM Adhemerval Zanella wrote: > > It is not allowed anymore on ISO C23. > --- > math/Makefile | 4 ++ > math/test-round-except-2.c | 67 ++++++++++++++++++++++++++++++ > math/test-round-except.c | 85 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 156 insertions(+) > create mode 100644 math/test-round-except-2.c > create mode 100644 math/test-round-except.c > > diff --git a/math/Makefile b/math/Makefile > index 32e3001ec6..35a148a66c 100644 > --- a/math/Makefile > +++ b/math/Makefile > @@ -530,6 +530,8 @@ tests =3D \ > test-nearbyint-except \ > test-nearbyint-except-2 \ > test-powl \ > + test-round-except \ > + test-round-except-2 \ > test-signgam-uchar \ > test-signgam-uchar-init \ > test-signgam-uint \ > @@ -1001,6 +1003,8 @@ CFLAGS-test-floor-except.c +=3D -fno-builtin > CFLAGS-test-floor-except-2.c +=3D -fno-builtin > CFLAGS-test-trunc-except.c +=3D -fno-builtin > CFLAGS-test-trunc-except-2.c +=3D -fno-builtin > +CFLAGS-test-round-except.c +=3D -fno-builtin > +CFLAGS-test-round-except-2.c +=3D -fno-builtin > > include ../Rules > > diff --git a/math/test-round-except-2.c b/math/test-round-except-2.c > new file mode 100644 > index 0000000000..5281b919b0 > --- /dev/null > +++ b/math/test-round-except-2.c > @@ -0,0 +1,67 @@ > +/* Test round functions do not disable exception traps. > + Copyright (C) 2024 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > + > +#ifndef FE_INEXACT > +# define FE_INEXACT 0 > +#endif > + > +#define TEST_FUNC(NAME, FLOAT, SUFFIX) \ > +static int \ > +NAME (void) \ > +{ \ > + int result =3D 0; = \ > + volatile FLOAT a, b __attribute__ ((unused)); = \ > + a =3D 1.5; = \ > + /* round must work when traps on "inexact" are enabled. */ \ > + b =3D round ## SUFFIX (a); = \ > + /* And it must have left those traps enabled. */ \ > + if (fegetexcept () =3D=3D FE_INEXACT) = \ > + puts ("PASS: " #FLOAT); \ > + else \ > + { \ > + puts ("FAIL: " #FLOAT); \ > + result =3D 1; = \ > + } \ > + return result; \ > +} > + > +TEST_FUNC (float_test, float, f) > +TEST_FUNC (double_test, double, ) > +TEST_FUNC (ldouble_test, long double, l) > + > +static int > +do_test (void) > +{ > + if (feenableexcept (FE_INEXACT) =3D=3D -1) > + { > + puts ("enabling FE_INEXACT traps failed, cannot test"); > + return 77; > + } > + int result =3D float_test (); > + feenableexcept (FE_INEXACT); > + result |=3D double_test (); > + feenableexcept (FE_INEXACT); > + result |=3D ldouble_test (); > + return result; > +} > + > +#include > diff --git a/math/test-round-except.c b/math/test-round-except.c > new file mode 100644 > index 0000000000..c4515daf89 > --- /dev/null > +++ b/math/test-round-except.c > @@ -0,0 +1,85 @@ > +/* Test round functions do not clear exceptions. > + Copyright (C) 2024 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > + > +#include > + > +#ifndef FE_INVALID > +# define FE_INVALID 0 > +#endif > + > +static bool any_supported =3D false; > + > +#define TEST_FUNC(NAME, FLOAT, SUFFIX) \ > +static int \ > +NAME (void) \ > +{ \ > + int result =3D 0; = \ > + if (!EXCEPTION_TESTS (FLOAT)) = \ > + return 0; \ > + any_supported =3D true; = \ > + volatile FLOAT a, b __attribute__ ((unused)); = \ > + a =3D 1.0; = \ > + /* round must not clear already-raised exceptions. */ \ > + feraiseexcept (FE_ALL_EXCEPT); \ > + b =3D round ## SUFFIX (a); = \ > + if (fetestexcept (FE_ALL_EXCEPT) =3D=3D FE_ALL_EXCEPT) = \ > + puts ("PASS: " #FLOAT); \ > + else \ > + { \ > + puts ("FAIL: " #FLOAT); \ > + result =3D 1; = \ > + } \ > + /* But it mustn't lose exceptions from sNaN arguments. */ \ > + if (SNAN_TESTS (FLOAT)) \ > + { \ > + static volatile FLOAT snan =3D __builtin_nans ## SUFFIX (""); = \ > + volatile FLOAT c __attribute__ ((unused)); \ > + feclearexcept (FE_ALL_EXCEPT); \ > + c =3D round ## SUFFIX (snan); = \ > + if (fetestexcept (FE_INVALID) =3D=3D FE_INVALID) = \ > + puts ("PASS: " #FLOAT " sNaN"); \ > + else \ > + { \ > + puts ("FAIL: " #FLOAT " sNaN"); \ > + result =3D 1; = \ > + } \ > + } \ > + return result; \ > +} > + > +TEST_FUNC (float_test, float, f) > +TEST_FUNC (double_test, double, ) > +TEST_FUNC (ldouble_test, long double, l) > + > +static int > +do_test (void) > +{ > + int result =3D float_test (); > + result |=3D double_test (); > + result |=3D ldouble_test (); > + if (!any_supported) > + return 77; > + return result; > +} > + > +#include > -- > 2.34.1 > LGTM. Reviewed-by: H.J. Lu Thanks. --=20 H.J.