From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by sourceware.org (Postfix) with ESMTPS id 0722A3858D20 for ; Mon, 1 Apr 2024 14:02:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0722A3858D20 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 0722A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711980137; cv=none; b=RPM/YCjmsVClDDzMGajq4jYykxyFz/oUUOpNk3fJX6vGApnxGBgeree2PskiGUH8wQaXILCLwd646ewHhykP5Rpb4Ho7uz/IrnjrgSDVF5uS040EA0Im3+qw4pF4RLv1Zkhxnu7IFAXk1aIwqoC3BJ2v8rgxxoXoMkg44S89Tbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711980137; c=relaxed/simple; bh=o8/Dy3aCKz960ZgJQWLtWcuJXkFkHX6zRfYEjJesqTw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=fxyEoFqpj7vloZy6gJ8ZMyP+FJ+jEcTkJjf2X98gD2BV/411kVQ44qre4UxK2vuqyWZoY/jipm+egM/srlSTK69XGcHivV2wsmMuuB60tsttULYs328w+/R05+dxx75ZAMKyJlycmfEIBIljq4XqvN7e6eyZifQy3FMSXoJXxnY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-6145a4c79cfso26883677b3.0 for ; Mon, 01 Apr 2024 07:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711980134; x=1712584934; 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=OihaUO30yq9jZ+RjPGQpsccg3dIuyhJs75Ee8keveDk=; b=JkHcK8ZLUOlfykdRZb92PIgguxh+5b7kSzYFrcrdantssq/o18MTkAtaUWtMBehqjz xtPzNI9XEKusoJpC4ioxl5ymuMuPUyRoVWlUbfzUcTBq7aYKxti03/A6WXBNiJaFaSE0 rORAZ3kAbf+QtHH8yXU/3H7R63Tus8h9GHaXIkHFYnePGb1Ka0bhDzPOY1i5YOjQDUTY mZBCLUIa6R0HvjjRVfnhESWfIjQ0SeYlPh3U3hdu5dHSt036NYIWkOwLpSUuj2gBOQmB np7uPlAey2jH4zXHc5UWIav0yoH1SpROUsRCfWRjnxYlTzdhm+UoTBnTKeDD8M/x7LH7 zq4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711980134; x=1712584934; 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=OihaUO30yq9jZ+RjPGQpsccg3dIuyhJs75Ee8keveDk=; b=uUavxR1Gt9EFQL4j/9JdiBe0vfBkjpHa80PCZmzvitz/k33RIsE534yeKlIXvlZImy RvNhaQEYBbhFp2UGQqeuBQchy54cIVD6omFOBkdis2LSaKHMI+iMIbp/YOmONEwEOwvY GAKTTB61u6GtRjAozs6Gj6iXUTI9/HwK13KXOzM7bIVCVylxJA2sXopv8fHXvs302XjH wkdFgyN2gkXXFA7ZjEElyH9KRKsCnQpKZL4t1Mu40+gPbPGAiEgm6gvKG19j7KHH06ez rEYZ8plPFk2ymwWBNnwQaDQloeDl6Uii4y1J7up4SefFxP3boiTXCOWOBXOZ2hY0szK4 UcwA== X-Gm-Message-State: AOJu0Yz6A8m3PXt47FV/mxGzBWInmNUSe4XS8ldZwRnH/Ehqm9ZrOaNi LJICQ9kJ7nM5uocgpkty4tWu5QzHlBSv8uiUK5Qv5H9QwpADd5knCrafgCjed5nQPu6LYBxpMZ9 UM8iw+JwPI2/J6dL5Cfk+mx6d5DVfWHbn X-Google-Smtp-Source: AGHT+IEXaQE5YbUBDehFF2UXHepXDa3WcbQ52EK4l35EvqYhdXQ0mAyqDU+JkHryUwSgU0t/KPpr7qpqpUh8LodNBj8= X-Received: by 2002:a81:8384:0:b0:608:fa76:948e with SMTP id t126-20020a818384000000b00608fa76948emr9407021ywf.11.1711980134052; Mon, 01 Apr 2024 07:02:14 -0700 (PDT) MIME-Version: 1.0 References: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> <20231228172026.2013007-4-adhemerval.zanella@linaro.org> In-Reply-To: <20231228172026.2013007-4-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Mon, 1 Apr 2024 07:01:38 -0700 Message-ID: Subject: Re: [PATCH 03/12] math: Add test to check if ceil 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.6 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 | 5 +++ > math/test-ceil-except-2.c | 67 ++++++++++++++++++++++++++++++ > math/test-ceil-except.c | 85 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 157 insertions(+) > create mode 100644 math/test-ceil-except-2.c > create mode 100644 math/test-ceil-except.c > > diff --git a/math/Makefile b/math/Makefile > index 5a912c55bd..4fc7842313 100644 > --- a/math/Makefile > +++ b/math/Makefile > @@ -498,6 +498,8 @@ tests =3D \ > bug-nextafter \ > bug-nexttoward \ > bug-tgmath1 \ > + test-ceil-except \ > + test-ceil-except-2 \ > test-femode \ > test-femode-traps \ > test-fenv basic-test \ > @@ -989,6 +991,9 @@ CFLAGS-test-fe-snans-always-signal.c +=3D $(config-cf= lags-signaling-nans) > > 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 > + > include ../Rules > > gen-all-calls =3D $(gen-libm-calls) $(gen-calls) > diff --git a/math/test-ceil-except-2.c b/math/test-ceil-except-2.c > new file mode 100644 > index 0000000000..c25956a402 > --- /dev/null > +++ b/math/test-ceil-except-2.c > @@ -0,0 +1,67 @@ > +/* Test ceil 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; = \ > + /* ceil must work when traps on "inexact" are enabled. */ \ > + b =3D ceil ## 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-ceil-except.c b/math/test-ceil-except.c > new file mode 100644 > index 0000000000..cd0717a96f > --- /dev/null > +++ b/math/test-ceil-except.c > @@ -0,0 +1,85 @@ > +/* Test ceil 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; = \ > + /* ceil must not clear already-raised exceptions. */ \ > + feraiseexcept (FE_ALL_EXCEPT); \ > + b =3D ceil ## 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 ceil ## 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.