From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 9C66A3858C24 for ; Mon, 1 Apr 2024 14:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C66A3858C24 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 9C66A3858C24 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=1711980209; cv=none; b=g6cgEi+VnSrLWNyhvUBK/JiEVZ6kdp9TsquYOtiNGco+LXp85jKqBM7Rtem/VksO9/XG3cQXYRpTPk8qYSsbehQ7nVKcEfsKQomMw6GMp8ew/t9JrC4rfvNlxBC8mL7FaatQmzoBsaYbp6bal6EaGrHKOEFJZqj3xUSuCyWQuZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711980209; c=relaxed/simple; bh=bDD0u1Ak1APhxh8+jrFmN0+RWFh/mDhjr5H4rklSxhs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KOeQ9xsFEFj05dqWRsZI29HgA7grrR84ur05kkFJiwKhmOu3ZMRLg1FYkWX+Pk5DAzMwOMY05kCnGK0EqXFcMRfS5pQFJ+AmAMdceY3lsWGIvtr63iBDgcOYla1TgCmuUae9k0ScOY9RKjM9ah256lqzTuHOdEWtA0Kr342RRJc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-61448d00c59so17049917b3.0 for ; Mon, 01 Apr 2024 07:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711980207; x=1712585007; 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=Ze7m6SVP+H0beYLLXXP4/Wc2lD/AnGWBsyemG/SFHGk=; b=egC65zBzogQx92WPEmwjZp5Nv61rV9s4P1EVeWTa5gV8Xi7hgE934xCBVnf7yEiyuT +dRKd9ekgMUeFtObXjawuW/UCa/GiJKF81ir4a/J8w7T9D5Zi0+e/TFNQCcDu50kh+jw /VRtKrAXLexqd7r2Nh5aTyhPIH5ZYx8Ftid5fA0oEC+jcHGIf3OZZqlK6HhbuPUCOvo/ /f6grhiwSYrZWDoG1u9lxXCf+/WEIycWjk6fFVNCZNGw/55AOyCvHNGZZg2X1mab8+DR 6VkVGV+C2n6hmPflLbuTP2At1tDioC84bRHjqqbOlmgSSbHkiTvjXZklnk0EwRMS9ZaJ 3YRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711980207; x=1712585007; 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=Ze7m6SVP+H0beYLLXXP4/Wc2lD/AnGWBsyemG/SFHGk=; b=X+A0phbIIrnSEIa5gK231FNJAHRvWhJ49xSWte0AnT+uekA84xtEcwQUAqCRguuVgU 44JZ0FhAM2QQRdtpHWSsMtrGvNIbSbiT5zHm0uAU2azPlTRkugvXEhxdoz3eqCH2I5eX ZOa/SKDdb4sTbdM1FwyHL26jdjeqN3jLfZQXl/4SbiZJFGLJqyo35PhIJOFxcWK6tFbZ eXuRI1NhQXdWjy4liE2grf6aXq0KEjg6iNHu1J6n82/FhkcUFh3CcNQu6WHRZOp2httY 5Vt9boRjsuazpS2Yg8yk/XOa5y8ouRVhDptrKJ2DgXXvNOg9mKLRNICyNW18l5ukazS5 I+xg== X-Gm-Message-State: AOJu0YwYmmXaMe0cGe9nrJeOjubGVyuWPnK6sg2X8kVQxQWVc59GhOi5 m3G336BAsAHSZ05wxQhyjiY3tcIgNeT3C04Z3f/9UUFo4xpljwoZIXogYNjfPLQEnVEDzCRhaly 6BVxBrReZ8YEX828+i8Fwdu9tPbw= X-Google-Smtp-Source: AGHT+IGiqPhtOTKXSsbAsxgY8KoljArJGwW0So6XL6aPk35k+j7angHD1gs+RtVtLvEAPi/vqGTR/m5hiaH5LEZl+SQ= X-Received: by 2002:a81:8542:0:b0:611:903:49fe with SMTP id v63-20020a818542000000b00611090349femr9009312ywf.49.1711980205447; Mon, 01 Apr 2024 07:03:25 -0700 (PDT) MIME-Version: 1.0 References: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> <20231228172026.2013007-7-adhemerval.zanella@linaro.org> In-Reply-To: <20231228172026.2013007-7-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Mon, 1 Apr 2024 07:02:49 -0700 Message-ID: Subject: Re: [PATCH 06/12] 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-Spam-Status: No, score=-3019.9 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-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 7ae107170c..dfe24a8c03 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..dffc02e91f > --- /dev/null > +++ b/math/test-round-except-2.c > @@ -0,0 +1,67 @@ > +/* Test round 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; = \ > + /* 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..cd43c964ab > --- /dev/null > +++ b/math/test-round-except.c > @@ -0,0 +1,85 @@ > +/* Test round 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; = \ > + /* 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 > --=20 H.J.