From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by sourceware.org (Postfix) with ESMTPS id D7EB8384640D for ; Wed, 3 Apr 2024 12:55:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7EB8384640D 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 D7EB8384640D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712148958; cv=none; b=Wvh6CuVL8LBq5KqmOghs3qYNEM0jKGMFb2FMUPgjt1EHHXpJTCBP12xGK2Se4zsxs1tbIzh6P+7wMVysfCJ1mVVHeBFAncZ9Vw7aQvfzr7/ftS1ZKalXbsbSc7mteIJ7tf6iA89af/l+KOB0CrHIhHZz0mMUOm5DC4iR5BNUJe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712148958; c=relaxed/simple; bh=GeTm4oQhHZjhYx2liEWHjuTaM8snLdn6k2AwP/Yl5rM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=OhAFbu7tKXMQxdsdlaoY5LEg8qmuV3//Kp9U+kP2CSQwWEbK2viKrNQ2gXqqEyAiDerlBT7hfJ7AV/O8U79QlVquKZpspch8jQNbu14SOLKNHWZNt3VCWBZxNbFaNzkUrcckoTnruOv3H7cSxsygw0dPDMArim5VUdBQ3FW7gyM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-dcc71031680so5814334276.2 for ; Wed, 03 Apr 2024 05:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712148954; x=1712753754; 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=7g2fLsXwnvwX4xhIk/LatusG0ZJb/lbiARvKEna4qKw=; b=dVEFLiJ9H5y17aXEhmJsWzNWTa0fCx2HxYal3bs86W7i++181rgUL653f5DHNVYo3n KX9tncfcw7LxadBUhoVkUFIbM+iDYyx8E0baEQByWv5UAp2eOVTYyz9UjDVn05z6BwKK ATVjSFJJj4UGvY3uySh6Le/CuWnCGzn/UdZ4Tg1dyCwtQExGIV71QJ2u5A8rvKO49A3b ohmOQO8vKCh4NIUmvrO0c+FVrJz7hkwwtFEp47IL0CZpBb2pJNwKzgnOG9dhGhcTElLG c/kNkDiIHBpCE0pmKt56paFN4fmp4uULt0606loQEmLKTZD/202UdAMg+s4YPj3e5JAd QxJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712148954; x=1712753754; 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=7g2fLsXwnvwX4xhIk/LatusG0ZJb/lbiARvKEna4qKw=; b=reNjiwTP7Kedbxfj2RocfAfyfzOrjpGny4thvYZ0GgeDCljfNYUr/m7BxpPCmaruPq Jlypk0ZFzQZwTtItdCw4fcrBhJ3flB7TfhFdQ9RonSSDis+BOsVwPhoJgqnUobza+DiP t4RKMvpd7hgQ3RrHQ92t7QtkMtOx749jr+rLjbI5RF/Lbmdi3cUyQjhj1EVTRmQSWXGI ouX/wtqVXbstzSJVqlhG5QCpHoxv5Z2hOeIqsClbWniCxyLhe027o2fCZg13jU0k7zzU 4v7ok3UDePEiHcn2A39a1rlSmxDkdfOE+oRFwRIPlCf4dQQsr9MI6HCIVMhSizSB+ru5 PZew== X-Gm-Message-State: AOJu0Ywg070WRcyMYBuInpMa+YKvi5/XDjeWETcWqJshcgCmGVJ38GVk ZH6D+9+OXyqBUqcUMM7+ffuVt24jGAKUTrTziZ6zVY0VQRrZZHAGpYDEJiisEsHXy5/VTUocpjv UpzJgtXpcTXZGx9Ag49F+1baytZwoWch/ X-Google-Smtp-Source: AGHT+IEwUWF+U1Ltx1UmxYTrNJZPY2ZQogJ9dCb9r744S6DX3sW3BtfkbEjteHwZA0yCyjWJM6IZjn4ig+xAiDklgG0= X-Received: by 2002:a25:16c4:0:b0:dcd:4d96:741f with SMTP id 187-20020a2516c4000000b00dcd4d96741fmr13452105ybw.10.1712148954092; Wed, 03 Apr 2024 05:55:54 -0700 (PDT) MIME-Version: 1.0 References: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> <20240403121150.1018799-3-adhemerval.zanella@linaro.org> In-Reply-To: <20240403121150.1018799-3-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Wed, 3 Apr 2024 05:55:18 -0700 Message-ID: Subject: Re: [PATCH v2 02/10] 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.3 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 | 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 1017026d23..8ab2582d69 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..d99e835909 > --- /dev/null > +++ b/math/test-floor-except-2.c > @@ -0,0 +1,67 @@ > +/* Test floor 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; = \ > + /* 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..a957c059e2 > --- /dev/null > +++ b/math/test-floor-except.c > @@ -0,0 +1,85 @@ > +/* Test floor 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; = \ > + /* 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 > LGTM. Reviewed-by: H.J. Lu Thanks. --=20 H.J.