From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id B20FF3846420 for ; Wed, 3 Apr 2024 12:12:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B20FF3846420 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 B20FF3846420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146325; cv=none; b=VWvD7Xd2/A+VPTZZf5Nh+I6i+ua4bodEsggYmfP8oRi2z434o5X1cKSKeCM3Hi5/7qH4pRgmTLuJIFJxyRruEWME28oRMeSGvn/lYnX7dBXiLbFcejocb1dme+TYP+JfWZxuz+vaMge4Cbg8SWrtBe5gNQq1rc+vSccsTQLmLlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146325; c=relaxed/simple; bh=RbJ+I2e43wuJhH9S2TMtsBJuBVaz1sg7KhFF8nnzBU4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=DDh0AWiw4Nu2ZqAq039O6kUwa+GuquvyLaNSQVBaxMLVp+sWu+TROpB9onA/DBNb5kgAkFd1fYUeLTh7u7PWx+sjB553CfNTsetu0wAYOYbm2Xmz27NHkIR3akyF7QFPwC0HxTn91YZcl5i8PDNxtVYSWzX3Pq/HPxbl8WgTcqE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so3494212a12.0 for ; Wed, 03 Apr 2024 05:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146321; x=1712751121; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YuaDTYelRPiHDzZYji8KBqMrTg4A0gZWeICeGTV8ZhY=; b=KjiI7uO7EMK8QoTrgmPmC7dfUoXO5JhgIAxnJcfXbspHZlFwGHKzTP9JO4hxtkFzSH 8T/AgG0ennsov6QBir3IH6ixZXz4w0MWrHJV1aj3zzsKb7wI/rfNaEXKD9hZ2+MWI/0n A1owl2tR3DUwG/nkWPsMP84fdFhUVbGNtmyG44B2dN/eZKNQznK2dzYJxYav6uE4stQ6 nwV+MG5sT01TMo114tkOxSE69/mnTIg1AtHE97OfJmF3jxtFPCb3ka+pdITYDzWa5Din HyMShEemlbZvlZqFuJGTCd6vcSHyJCJdydqWfCUCytEN2ZxKFB+jwWJ6BZcAOdwdaW5Q lCvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146321; x=1712751121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YuaDTYelRPiHDzZYji8KBqMrTg4A0gZWeICeGTV8ZhY=; b=ZBpd9vrPaeWQ0kWObj/KHK6WF9NzpS+4R7MQECqaAmHT5KZzK4VnR5PJFlKR7JVVSn k/WYTcqPxYmitldkIpLlZ9j8ll+WoNYbjNj0WLgMPJqLia21rMk9pIXQbIbcgSi78+5a uLe3pZH0RX2JMpkJo9MvB+5d9sqjA/J9p4hop9/51VMGI64nwa3ok1T7LJghaCF2/t/F hK7Hbfmwf1L4BRWZXkEgBL+qQp+HYqX8/PHUXzT6WHMplMnPqdi7TVvE4B1Eu3AmTszF LzIU+GryLyiOx4t8rwsHIlX58pp/jPwSP2Zotyi/6faAhB+fS0Q8obtucUJhl/7hCQG6 7Z7Q== X-Gm-Message-State: AOJu0YyjX/QM2kPKItadH+wrT1olyZPSmnGfVdNWtyunxmujrcweJM07 Yi1Vop+AuLeeF/8t6amkCjLVkYIjimfP3RuITGMWBN2vEC/RUyD40iihi1VjmoUZ95zOlvw+gKQ w X-Google-Smtp-Source: AGHT+IFw0PY5lxPPiiDW1nYX+2HDGKEkRzgEbOvc8kT4YCcr5zfZs9EYQ3G6JwYxjY19MBSMBXlFGg== X-Received: by 2002:a17:90b:1b45:b0:2a2:9f46:439 with SMTP id nv5-20020a17090b1b4500b002a29f460439mr1145070pjb.9.1712146321340; Wed, 03 Apr 2024 05:12:01 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:b18e:12db:8f9c:da5:36ce]) by smtp.gmail.com with ESMTPSA id q6-20020a17090a938600b0029ffcf1df72sm13574141pjo.38.2024.04.03.05.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:00 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 04/10] math: Add test to check if round raise inexact floating-point exception Date: Wed, 3 Apr 2024 09:11:44 -0300 Message-Id: <20240403121150.1018799-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> References: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 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 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: 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 32e3001ec6..35a148a66c 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..5281b919b0 --- /dev/null +++ b/math/test-round-except-2.c @@ -0,0 +1,67 @@ +/* Test round 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 = 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..c4515daf89 --- /dev/null +++ b/math/test-round-except.c @@ -0,0 +1,85 @@ +/* Test round 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 = 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 -- 2.34.1