From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 75BF63858C32 for ; Mon, 1 Apr 2024 14:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75BF63858C32 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 75BF63858C32 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=1711980181; cv=none; b=GOydo5G1xh5WkOizCXPfNFoZ5g2cAHW0HXY8o2xqIiOwinHPHSuv+jjt+bGxGDmC3c3ewEjwhFI5/hLqDleD7StU4WqvKWiRUm7+Teyl/xx5XzDZlZ0BPYPr3UZ1nlkBhN8QvcYYifWdlJDTcRw+IiTMrP4CFv3BjQBtSST2CmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711980181; c=relaxed/simple; bh=y0Dj1XncMcGDaPROE9s/SiQbVgLmbqEL+nd5OZLDuSI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=kGvQlShfncFRz1Ubo3kii3DuUkJeaXuth2+xzUYQPoF9ozVKyZgbqZRgdB6AJkEnyc+XcUbwQQdI8MKiE2mVK3gYcm8xK3RUsbI62HszAly9iePoRx670z14mVDrtPGcw0xYRtOe62AvWlAmw7wQRdbdqsp69gb+BYthTMiYT8s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-61471853539so7101107b3.0 for ; Mon, 01 Apr 2024 07:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711980170; x=1712584970; 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=KRGE0MVhXIWCO/v5h+CUMCOLeYZznS+bXcyelow5b4o=; b=jx1h/aDsZYy0Do6jEu4GJ3JuNB0TUobWLgOfQoyabyAabalMkPKYy63WLNGBzsc+ii m8dOPXKUp+P2fqoI42yOwrRQ0Zqo+Poq0c016j+bIhBYOOqTwFbudIcRkKQwZzuy0EJX 7MJ+41rvfqD18VpO2rVnZoNA+LYOtnaDvdKcxbVBZn2VcZStwTpNWsLz/IiBF6Ow/HF5 jh8ZE2RBRngsdCG7AvZlNZCh4GCfvSK5DcDuXzWhiRipeT81fERgDj+z3bDREDoAWogX 3HzQ8X+M0/tVZyF9Mo6EvTQFNJKnvP7HwuSWmLhUpIbHAwezOubFc0huDXHmxJmXuaPq OW5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711980170; x=1712584970; 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=KRGE0MVhXIWCO/v5h+CUMCOLeYZznS+bXcyelow5b4o=; b=ov7J/C9fX87kXUkNCn6ENlOOcei5BGi3bS7a83AACG5C0OH3ENjTY9ooHVSkfBc8x9 m7IEqfzGUu88WvPoMGTYZOk93tnG/08zSQdr8Zm7/M+8N2NZSzW8UYUj2h+YMKdxNoGA P4Wmz+NHDfeA6hzDr5utrF/dIReYAv/EBTjvf4gXIv8nTEAMyPhJLDK+NVz+VgGfEusf QQDyuo1lQwLpxh9N6Zjn5ebZWZWCnUB3aVqPzvFmkORd+HzKkU6/+s1v0mL9d2+ZN1FT 3Q4YRP6VhwrOJ7J1cCue08xwx4pUYxCoQiAY7o8um4/UAnfpZqIGPcCidutj+lB4xAue dxOA== X-Gm-Message-State: AOJu0YxhbSKURj9g0HP8LCSL5kSbz8HmWpaNfe17Q9WqZ8BQf+jjSd6E dq6d4Kq93OJhcI1ElrZjuuNlGuIrWQhY1pMawQQQCqKVDeNjymi6zW7RJa9udnwXtgTD4NvuKYU cvodP2jN863GLEfTJY0IJaGzgDX4= X-Google-Smtp-Source: AGHT+IGOAJsXGhckMozXRC2tKplt59HAx8xZIng2Rb8kHtTcTtdMGFAfmp32K6MZbtPR3gc0atKoN6T1Q7G/fgftdH4= X-Received: by 2002:a25:b793:0:b0:dc2:1dd0:1d1b with SMTP id n19-20020a25b793000000b00dc21dd01d1bmr7336277ybh.19.1711980169714; Mon, 01 Apr 2024 07:02:49 -0700 (PDT) MIME-Version: 1.0 References: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> <20231228172026.2013007-5-adhemerval.zanella@linaro.org> In-Reply-To: <20231228172026.2013007-5-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Mon, 1 Apr 2024 07:02:13 -0700 Message-ID: Subject: Re: [PATCH 04/12] math: Add test to check if floor 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-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 Thu, Dec 28, 2023 at 9:22=E2=80=AFAM Adhemerval Zanella wrote: > > It is not allowed anymore on ISO C23. > --- > math/Makefile | 4 ++ > math/test-floor-except-2.c | 67 ++++++++++++++++++++++++++++++ > math/test-floor-except.c | 85 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 156 insertions(+) > create mode 100644 math/test-floor-except-2.c > create mode 100644 math/test-floor-except.c > > diff --git a/math/Makefile b/math/Makefile > index 4fc7842313..19e234874a 100644 > --- a/math/Makefile > +++ b/math/Makefile > @@ -512,6 +512,8 @@ tests =3D \ > test-fetestexceptflag \ > test-fexcept \ > test-fexcept-traps \ > + test-floor-except \ > + test-floor-except-2 \ > test-flt-eval-method \ > test-fp-ilogb-constants \ > test-fp-llogb-constants \ > @@ -993,6 +995,8 @@ CFLAGS-test-nan-const.c +=3D -fno-builtin > > CFLAGS-test-ceil-except.c +=3D -fno-builtin > CFLAGS-test-ceil-except-2.c +=3D -fno-builtin > +CFLAGS-test-floor-except.c +=3D -fno-builtin > +CFLAGS-test-floor-except-2.c +=3D -fno-builtin > > include ../Rules > > diff --git a/math/test-floor-except-2.c b/math/test-floor-except-2.c > new file mode 100644 > index 0000000000..01b22f984b > --- /dev/null > +++ b/math/test-floor-except-2.c > @@ -0,0 +1,67 @@ > +/* Test floor functions do not disable exception traps. > + Copyright (C) 2023 Free Software Foundation, Inc. 2024 > + 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; = \ > + /* floor must work when traps on "inexact" are enabled. */ \ > + b =3D floor ## 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-floor-except.c b/math/test-floor-except.c > new file mode 100644 > index 0000000000..fe77866ddc > --- /dev/null > +++ b/math/test-floor-except.c > @@ -0,0 +1,85 @@ > +/* Test floor functions do not clear exceptions. > + Copyright (C) 2015-2023 Free Software Foundation, Inc. Just 2024. > + 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; = \ > + /* floor must not clear already-raised exceptions. */ \ > + feraiseexcept (FE_ALL_EXCEPT); \ > + b =3D floor ## 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 floor ## 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 > --=20 H.J.