From patchwork Thu Dec 28 17:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 758602 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp4115081wrw; Thu, 28 Dec 2023 09:22:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF117YlkF6IPiT79bt6Brjy46Opeg8mS1au6uHD/7PTOlT2WgJlL72Fd7oPamaxMtGuPFRF X-Received: by 2002:a05:622a:448:b0:423:f8f1:dfda with SMTP id o8-20020a05622a044800b00423f8f1dfdamr12910193qtx.25.1703784127522; Thu, 28 Dec 2023 09:22:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703784127; cv=pass; d=google.com; s=arc-20160816; b=WHq6iel7dBBWPHQxrqTjlwPiVDsDhR1V7x0AySWPxnzEo6R16K33M6IgyU/nqRoyoj phJkqzMSDVZPbpJFZgh+ZKQ6RqBg6Six6Y1eYeam+EmgwPGW4DT+jHeyJt3hqBk9rFGM c2n4EaErxkNdPmjQ0UmBosJj6Fk/cIpLr9iN+csXXRERJTABdwAVbit01Dlxvg+U/DTZ smHeBy/4vMjO/UUXpnNerIP5StGB36HmLar5KWkDFYRYxTIXjQjLLTuD092Ueb5UCW2e wKAJwQGGbiJhyFBcyU4Z9O+cL+wxh/vFBpJYb994gAp4rVV0QRby4XV7PaIhKcdIFbG+ D3Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=G7DAyBPI7iRaNkh70Jq9qwomvSbfKt3p52V+XD56U4Y=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=BVZ7sCmyUFfSO9bmOBWXTyGeE3+fdAFEJIAbqKYD2z89O0qa9kuhD1CUtRNW+hUCfy iDoPPgujmiJRFKTzbJeAeIUk61WdkeSfNcVsC0s/98N4dxcYyXwMnRKvRm4vNXfAzNk8 hfDiVW4Cynp0Su0gfCRdyXFdCIVUVabeKco2Riry1WJJbSESYrMp5MZWOAfe6F3W21Yd Yso1n/ewLOK3fh0Dms6N8yecekPYfBvwnBrt7uEzhKfc9VoPe/kBUIIOLiHPPSsEOVoY 8DdjXbVrN7Vdyijfy12AFEPM/Fq+41ec1Hjj/95akiUBGYfdp1hYAgwgiKweARzJoMvG 9eZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C/uLHaEr"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e10-20020ac84e4a000000b0042775d5bfbdsi16840340qtw.616.2023.12.28.09.22.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:22:07 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C/uLHaEr"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64D8938582B5 for ; Thu, 28 Dec 2023 17:22:06 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 432AD385828A for ; Thu, 28 Dec 2023 17:20:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 432AD385828A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 432AD385828A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784044; cv=none; b=epLeJeG6PuC3P3fzIaZrZsM3y13xgZdLgsYD4/DmuR0qoehksDR02fA6Wc4E/l3TcLs6jqqyGdlV4W7n6k0KRCsMcEX/lCf/2SUbRxUDp7k+fizTwJqIrx1Ul4yWCxslYIVJk0WQ/0fxq0bBmIP1nrcRyQBVl0ustEqwWhWgSLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784044; c=relaxed/simple; bh=7LbP0bZAu0KPhjphY2MiUjWs3zO1ol6lJ3u9fop6GiU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gLMA9PWh/9w7WsWoF2cU5UobxKKaLQBmPqshD7MaeEw0MBwI7mVmpc7gHliCiZd8K9DPr3vBqkA7mi4kAvedDjdrDklraLaIIYOz7awLr1a2r50J9YD6UEl9baUdhF9P41G3Dr+hDRCGIqnk4NHPPuNl6+rL9B1o6lPRWg5s/ac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6d9b267007fso1235078b3a.3 for ; Thu, 28 Dec 2023 09:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703784040; x=1704388840; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=G7DAyBPI7iRaNkh70Jq9qwomvSbfKt3p52V+XD56U4Y=; b=C/uLHaErfdqusaP2ZYoc2bwjhQwhouOLaEfXmOAQ331UGQW0epkhMN03WqqgNVnsho SypYA9nr/TgNjAot+/BLcEsX5+OnTS/SXgWgzQT9aIMVUIgWg4J0IUNBf/AQHSBy9j7B 86/TiWLzPt2P4nvxdSkAB+/hyjbHlTeinsmwb4cbi7NeoB7HmlFuBGKuEPerOo/rvFhX 6FkeF8mH/oXD9YHxxwxWvE55U3KYg8BtfAX6dBtXPk5WkE9OJQRRiluka7OJHgzpxGk7 F1zzhCTrriSR5n9xH+qTr2RA4jx0L1dtV5e9Qwx15CIGDc4usR/68uwt7dHHUT07QIvC AgJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703784040; x=1704388840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G7DAyBPI7iRaNkh70Jq9qwomvSbfKt3p52V+XD56U4Y=; b=TyDotLdjgmOj06zbBAwPrdS8bE6MxFbqzc9znc7+gXmPuNZzoceIzcLemb9n1vN3SY OJTk9AEE6zI/vSXY7K4LRInPiPEj8sdZLPnYjxB1uAkjQY0aoEAiC5URtwzh1LMhk4Ek D2xFyo4l6RkOW/2iK3tWl8XgrWR4gIHIVgy3bxxyUM7M7jtHCQnpPKHrBKCbCfQ/77Ow pJLQX28IXF7zxZ3hBmFWmMo5ysIlbRjiGgkOJcffxkvHn8Un62bEuHH1sg4Eatm5muwU BXOnzEhSpqPkheUY7BfDi6h35jTWR4cL0ID43Y9yhRYae6jz1wSrZ0d7a7w1aVTQIn/f ytOQ== X-Gm-Message-State: AOJu0Ywl7jnSIaDstAvChSBz42rD9xfA+JdVBAZI6Mhfmsd2q3MF9Ivg iyNEmg33I+RKC2UzLfXbJcuv+nJSu90ytEqjW7Oc+LOGCQ8= X-Received: by 2002:a05:6a00:1acb:b0:6d9:ed3e:af5b with SMTP id f11-20020a056a001acb00b006d9ed3eaf5bmr2960269pfv.2.1703784039799; Thu, 28 Dec 2023 09:20:39 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:bd9:84dc:8a87:ea0:57d7]) by smtp.gmail.com with ESMTPSA id q7-20020aa79827000000b006d9a94a03a8sm9593839pfl.77.2023.12.28.09.20.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:39 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 06/12] math: Add test to check if round raise inexact floating-point exception Date: Thu, 28 Dec 2023 14:20:20 -0300 Message-Id: <20231228172026.2013007-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> References: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org 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 = \ 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 += -fno-builtin CFLAGS-test-floor-except-2.c += -fno-builtin CFLAGS-test-trunc-except.c += -fno-builtin CFLAGS-test-trunc-except-2.c += -fno-builtin +CFLAGS-test-round-except.c += -fno-builtin +CFLAGS-test-round-except-2.c += -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. + 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 = 0; \ + volatile FLOAT a, b __attribute__ ((unused)); \ + a = 1.5; \ + /* round must work when traps on "inexact" are enabled. */ \ + b = round ## SUFFIX (a); \ + /* And it must have left those traps enabled. */ \ + if (fegetexcept () == FE_INEXACT) \ + puts ("PASS: " #FLOAT); \ + else \ + { \ + puts ("FAIL: " #FLOAT); \ + result = 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) == -1) + { + puts ("enabling FE_INEXACT traps failed, cannot test"); + return 77; + } + int result = float_test (); + feenableexcept (FE_INEXACT); + result |= double_test (); + feenableexcept (FE_INEXACT); + result |= 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. + 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 = false; + +#define TEST_FUNC(NAME, FLOAT, SUFFIX) \ +static int \ +NAME (void) \ +{ \ + int result = 0; \ + if (!EXCEPTION_TESTS (FLOAT)) \ + return 0; \ + any_supported = true; \ + volatile FLOAT a, b __attribute__ ((unused)); \ + a = 1.0; \ + /* round must not clear already-raised exceptions. */ \ + feraiseexcept (FE_ALL_EXCEPT); \ + b = round ## SUFFIX (a); \ + if (fetestexcept (FE_ALL_EXCEPT) == FE_ALL_EXCEPT) \ + puts ("PASS: " #FLOAT); \ + else \ + { \ + puts ("FAIL: " #FLOAT); \ + result = 1; \ + } \ + /* But it mustn't lose exceptions from sNaN arguments. */ \ + if (SNAN_TESTS (FLOAT)) \ + { \ + static volatile FLOAT snan = __builtin_nans ## SUFFIX (""); \ + volatile FLOAT c __attribute__ ((unused)); \ + feclearexcept (FE_ALL_EXCEPT); \ + c = round ## SUFFIX (snan); \ + if (fetestexcept (FE_INVALID) == FE_INVALID) \ + puts ("PASS: " #FLOAT " sNaN"); \ + else \ + { \ + puts ("FAIL: " #FLOAT " sNaN"); \ + result = 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 = float_test (); + result |= double_test (); + result |= ldouble_test (); + if (!any_supported) + return 77; + return result; +} + +#include