From patchwork Wed Apr 3 12:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 785431 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp282494wro; Wed, 3 Apr 2024 05:12:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIyT/uB7AXtKIcInprzyBOHWx3JPcuh4ixZRMHbLvuwsgnpqbaUrmtoWkqxnqK9jhFzrCK7tWR+c4iV3M1JuqK X-Google-Smtp-Source: AGHT+IGhGmxlZYbyTmxhqoMh8ibnAjM/OisB+yejmV5S7TOYm5DW4j2XWP9wHYUBBlZSmlP+LrMV X-Received: by 2002:a05:6870:c6a4:b0:22e:7d53:3982 with SMTP id cv36-20020a056870c6a400b0022e7d533982mr3432618oab.57.1712146371513; Wed, 03 Apr 2024 05:12:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712146371; cv=pass; d=google.com; s=arc-20160816; b=C0ByvHmdGcoX5x+gM0gbgKPDOi/8Q4migntxhvZyWrIZj9qgG0y17ENUzEePR96sSl /8bpQdjIPHhI6/8Io5UhLfQp1aUvDDY9T6Yj3kFxd2TRL+NPvFeC7MOjOkTOvGUPsjNf 1cFWu68epqgB0ZqAJTlH74g31Vz46R1Ms/R3jnABSfaRHvfovkq6NcmB/IZEeq226FTG KNt5hGNMqrEioC0HUOL5kyVB1kftU6KrpCTofXRmANO8RRN+2KblQBfBT5Jjbf5Rg9vs AeMqLxH0OO9o1Nu4KHi11NQnzAx++bl2zTmMDzQefXgdqjdFlFvYQUlvI/AUOu9guo+L JmpQ== 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:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=YuaDTYelRPiHDzZYji8KBqMrTg4A0gZWeICeGTV8ZhY=; fh=+6orIzRLXQY2FWXAtGF+abYflc8V+YPKzsYFuX0DJM4=; b=uGqvuy9y83vjZ5/QY3siZ0JkH+ooNmXfvrMEoZAmbI3WtpqLQdib3O3sVIz3Ohc6Mx zpw2vL70ZZJMv/c7gGk8nme9KmP1wIhrYlkd9IlV8uyyZhLEzZ2uBw0mZVV48tCDQ5n2 7eVlRXviRH+dNnUxV9nYvZ4v2kb5+xHbxjVyy0wwbLCaQ+zExHvuFkBSEldYtsSYk46V Vyuv5yndzRiujZv2lJhlhvxQjt8m32XAP26ciFd0EdJHldy13o9Ot/y5behEzmNG/YL4 BTwGq/H5VSqcN5Bwz65dnCDadOCkDiQSug5F7jzuOhhDF7XuaAHV8VD0Ad+JNC+5BAy6 v/PA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KjiI7uO7; 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 z14-20020a05622a060e00b0043174f5f443si247327qta.270.2024.04.03.05.12.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:51 -0700 (PDT) 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=KjiI7uO7; 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 209C5384772F for ; Wed, 3 Apr 2024 12:12:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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-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 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 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. Reviewed-by: H.J. Lu --- 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