From patchwork Thu Dec 28 17:20:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 758600 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp4114950wrw; Thu, 28 Dec 2023 09:21:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFi0dmayVqYbA7K5e3YBmrlX+wE5Oko/s8mE5lFBDaHv3Etlc1lx5m3aolmKqDDCpCOYmmI X-Received: by 2002:a05:622a:254:b0:427:f8c2:5bee with SMTP id c20-20020a05622a025400b00427f8c25beemr1628225qtx.129.1703784110620; Thu, 28 Dec 2023 09:21:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703784110; cv=pass; d=google.com; s=arc-20160816; b=PvKGNFTTn7K3Y8Z7A61+y663ltoRBunw1UJIFQcjKf7nXB1JASn5NCQJAsuhaR1BPU n4OVbaFO6MaJlPhzlq8F7tWhBn9tOJR8Bln5gvGsfx2E9syBHg8Wjiy8rH477pLGiAIF bcugfEpkjJiVN6W+X1dWV3SPpUKap/8ia83cZ2DBju3ZV/x0HunWifSG6J5gd3Yf3rdD CnNbW6fRuOr+4z8BTKZoWnnzESOh+KEdLYQyYOSHG1w48c5K8L2OY0eKqSVbHwoBTKms ljfO5Ynrbei8ZNMM9KUgc3PWZ4rbysu2i2eJSuTTZJi7WeBNyX5P+Hh62Xzedtzypmqj axsg== 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=vfEZIsPGLvLl4/X3BIN733T0zrZmwn4k8C+goMzfFGc=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=FswiKoAT8bDZrnJ00vxpxscB6FNqLk7ot9kHg5H80XtLiHD40aQ2lXxn1BcnKCeyVU 4bltn4NZI9BmI4CXBHHXPe4VxcZbtfbyUdWjnzUao4al6uVWB7B7xR8mh3bVUqdCAB41 f1a/j3OiNr0tjQRebsUsW01u9QOVDwmS1jLnNdjmhQdZekU0szB35d/l2eHdkB/g1JZn DP2JA2NuqIBjvvMCv61vJr6rveK+SwuRmi+xZhvciAlKCDIIV3Zx4jtVOGptQ9KE/FsV jugI8nOoooUXp4VmVXoB3tclsio684gL0kuaWxKwQLax4jjGmJp6PhQFAtwH5NLYIUhK 936w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gww5hQCH; 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 c13-20020a05622a024d00b0042775bb6607si17501848qtx.774.2023.12.28.09.21.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:21:50 -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=gww5hQCH; 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 30B7838582BF for ; Thu, 28 Dec 2023 17:21:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id B9453385843E for ; Thu, 28 Dec 2023 17:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9453385843E 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 B9453385843E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784039; cv=none; b=wmcJGmvmRv1qLriau1oeQwVeN8VAcd5B4Kn3S00t/6+H8hEl9HjKzMo8zowOOjsou0UsgfBB0jxqelRiIQ2bYffJL7eWnCSjc93qRoL8jkqe8zuPDu+5a9uzIUik+df0C4pAJyaO7jVOQY5IzI0c5LnnLlZ63xcNC0e+cbRmQ0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784039; c=relaxed/simple; bh=m9fTcXt2h+YDHnP5Nqh91hW5rgCc2fhNFFiV/dORuHs=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JYDDSnRH2/hygIrLMLxjWB3kexDmMm5jo/OLzGrmH8cuB4XKZloh74IsRvjTXrgpvEcZISo6OAyUedu3iTYS5nlbT6lSoSG4h2YXeFha/lfrt6rL94PrPDYWOI2Q1Hb8EFhR4KNytvW2052xP2MAh1uxA3PGujAkCclwUNjRuoA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6d9bf6f24f3so1163590b3a.2 for ; Thu, 28 Dec 2023 09:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703784035; x=1704388835; 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=vfEZIsPGLvLl4/X3BIN733T0zrZmwn4k8C+goMzfFGc=; b=gww5hQCH2O92c/gHFvQCb3zntcGm+UV5+JtAWhLzUo3tAW3DmH9d79h/fFiQtlniTX nwrGq4Kq2nDwVAMjQQQHhA4yDT1B3YSjmpp9YiUZJTlwxh7uuoVGOj5OCVsMiKWtZs5z qnQFxrH1hLZQ3a5JeI46MMVOQJbCCniQ90cmFpR8MMJXqI0jBX/fa0pC/ffjx6uIg4vf NSCB75MHnz1EB8VFqY19SsVEIVt3LNyTlm/GhcWOk9VVDoBXCDhxGBsz/Nxb4eCFhuUo 6/0vSIWU6tTr1syQ34jnTYaPHVoBDOTFg6SLuMyXBzChJq107ScOVJ5y1g/YnQ4Wsj+c m5Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703784035; x=1704388835; 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=vfEZIsPGLvLl4/X3BIN733T0zrZmwn4k8C+goMzfFGc=; b=ZSYDH+37QTpuTEz0urCylonDGwT98+12FRHQOSyb54AACLqAfgVOaauFvU9JP08vqY sCAZxlJmBhQ5Gkf0COeQGEy3Eq0mEaLXA0dct9z2x4K0lV1D7uaACnKB9J4xA6QtsG9P 4LiYbPDlKyQ52596bbBSqKvqJYJR14VUlq9R7C8TfK744Earrrjt9MbuyTEV0sPsQNmV 8Eefpsbalp/T4XeUBdP+jCvFU9NZq/LtbVKsYJDLtlwkcqunoV3tCMXuF9Fkfir++Zp8 JxbT2Icfh0rYk3XJEzbQhWV2UJnce5xX1F9HWs6tPJoF2jZw7imDzLOWxuoAn+Lp+XDW +TPQ== X-Gm-Message-State: AOJu0YzSXPkdlh5N6BcNKQ5eTpdfvxVfdDwgsAIDE2ThZ8xCIqZKzVQ0 p2s8xzyCV8zp37InJgXLXyA50arQIM4ZJK7tB12u36Dy/nk= X-Received: by 2002:a62:a518:0:b0:6d9:cdf5:cc45 with SMTP id v24-20020a62a518000000b006d9cdf5cc45mr2547665pfm.63.1703784035200; Thu, 28 Dec 2023 09:20:35 -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.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:34 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 03/12] math: Add test to check if ceil raise inexact floating-point exception Date: Thu, 28 Dec 2023 14:20:17 -0300 Message-Id: <20231228172026.2013007-4-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.2 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 | 5 +++ math/test-ceil-except-2.c | 67 ++++++++++++++++++++++++++++++ math/test-ceil-except.c | 85 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 math/test-ceil-except-2.c create mode 100644 math/test-ceil-except.c diff --git a/math/Makefile b/math/Makefile index 5a912c55bd..4fc7842313 100644 --- a/math/Makefile +++ b/math/Makefile @@ -498,6 +498,8 @@ tests = \ bug-nextafter \ bug-nexttoward \ bug-tgmath1 \ + test-ceil-except \ + test-ceil-except-2 \ test-femode \ test-femode-traps \ test-fenv basic-test \ @@ -989,6 +991,9 @@ CFLAGS-test-fe-snans-always-signal.c += $(config-cflags-signaling-nans) CFLAGS-test-nan-const.c += -fno-builtin +CFLAGS-test-ceil-except.c += -fno-builtin +CFLAGS-test-ceil-except-2.c += -fno-builtin + include ../Rules gen-all-calls = $(gen-libm-calls) $(gen-calls) diff --git a/math/test-ceil-except-2.c b/math/test-ceil-except-2.c new file mode 100644 index 0000000000..c25956a402 --- /dev/null +++ b/math/test-ceil-except-2.c @@ -0,0 +1,67 @@ +/* Test ceil 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; \ + /* ceil must work when traps on "inexact" are enabled. */ \ + b = ceil ## 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-ceil-except.c b/math/test-ceil-except.c new file mode 100644 index 0000000000..cd0717a96f --- /dev/null +++ b/math/test-ceil-except.c @@ -0,0 +1,85 @@ +/* Test ceil 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; \ + /* ceil must not clear already-raised exceptions. */ \ + feraiseexcept (FE_ALL_EXCEPT); \ + b = ceil ## 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 = ceil ## 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