From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by sourceware.org (Postfix) with ESMTPS id 2C1033858401 for ; Wed, 3 Apr 2024 12:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C1033858401 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 2C1033858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712148918; cv=none; b=WA5xOmCuNCBNcpWzC5JuwGqsWI8flyxFFM4ER042scLSMBBwxSW2XJnbQzi3tyMgiC500e5pDzOAv7myKZvUsDXiDQscJWpiUphLzBRaeH6KCpHAvWUrqwoxqF5mN/Wlz4wvrLSV8VQUO5hHMRaDe+eq7mmhW4xe7m+bUdESeAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712148918; c=relaxed/simple; bh=/BGeFg34XgQftEHv9F7yJ+2iLaW+9Jg+LAZZnFvar7M=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=oecusTVWk6mLCQzC7sjXT8GwsLZOCJvaTL9W2Kvrq6nUNJhOoNB3QVtKOmlS68TYgL91EN/WkAmuvNijhKn0I7G+WuTdnex/U42ohIApMuXTo1rH61vWI5CCpXuhZwMHskWmNbl2irRzvThBANCga+zbUZwN4sZhCbwQ3s8Eiv0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-6153e169066so15105167b3.3 for ; Wed, 03 Apr 2024 05:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712148914; x=1712753714; 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=tYSnZc+w6nYX6o5jjPxEXLMbsHV9wMg7L5t3dd+lBCE=; b=Mqu8od7HGDz8bLc34DAerF838NeQGBdroDgXVNSU0DrlqmJUU3ERbkvRT5n2RHIgF+ FsUvV26av+hENxediT0Tm4Tbqf3PzM5tHGeJ/1BAn+fhin/Q4QiA7sML4GXSRbO4kGIc BktSmnMbgOadCFutMg8jurQ8Y0RM4LrUSi1IVCzE5I5mOz+me4ahqcA8fgdqAYCVhe5s fEry0K38frVBwBP47haTU3cuMY/LqgmuY8vekussNhjin7T60/r+tmElwFHQTs/X2wVA VFK1OhbxfdtXF6VtuCbqrnCitl9Hx/MQj9muHY3FAmQFBV8QI5ZlKFOwNU4ah7LixHkL B3Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712148914; x=1712753714; 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=tYSnZc+w6nYX6o5jjPxEXLMbsHV9wMg7L5t3dd+lBCE=; b=DW9ezkg/lBebQpdclHlzW+7dG5GRXdjfucdtIUt4TWTBr8DcyO82mZA0jzLBMb20l7 IISLTPHb+BPtTAdoDsUF2dDnwZcPOpojH4eRUBj4Z6e9RFlecEE1r5AdmyNeoS5nqVgE iEsXwUSWDDYclOYco0lyNHEmJaAIocGjwzLDijjV9qLIP5RofYOhwzir17+G/6ur9nqU XkZ+pMitqD4qtQ8oYEXJfphkH99DXbws9F81WD/nXS3mMrNzZ3aPxFir/LQmomZKx5GN bcjHsvTtvTLq4Y+XWrt5SkkC3El6nHYtE84ApcxyNn8FKr/Ht4Xs4aXacNPN+EjdW7Vf hg0w== X-Gm-Message-State: AOJu0YxGl1XH++TlKv5ulteLdXpChFs4vCclhck0uEz2rGW4i9rSU7Fp SbicgKTp58QJJHUOcoF6FiUhgz83GwdOUiPUCUmOjEJkBv8U10nXPYWA48bhJwnMt8LqwubbQE3 GAS5iy9Kg4UoEvbytcOwjV7HAyMI= X-Google-Smtp-Source: AGHT+IFnka6SbUH7syQlFzLFOeTOge68J2+eMOijQmNJ/DF1l///TMn1hZkazcHvXWBkSTmmX887825JDLukxsjjf7I= X-Received: by 2002:a81:af59:0:b0:615:1386:a1ba with SMTP id x25-20020a81af59000000b006151386a1bamr6714811ywj.3.1712148914451; Wed, 03 Apr 2024 05:55:14 -0700 (PDT) MIME-Version: 1.0 References: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> <20240403121150.1018799-2-adhemerval.zanella@linaro.org> In-Reply-To: <20240403121150.1018799-2-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Wed, 3 Apr 2024 05:54:38 -0700 Message-ID: Subject: Re: [PATCH v2 01/10] 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.8 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 Wed, Apr 3, 2024 at 5:11=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 121a709121..1017026d23 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..394a272d89 > --- /dev/null > +++ b/math/test-ceil-except-2.c > @@ -0,0 +1,67 @@ > +/* Test ceil 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; = \ > + /* 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..f7627506f7 > --- /dev/null > +++ b/math/test-ceil-except.c > @@ -0,0 +1,85 @@ > +/* Test ceil 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; = \ > + /* 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 > LGTM. Reviewed-by: H.J. Lu Thanks. --=20 H.J.