From patchwork Thu Dec 28 17:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 82930 X-Patchwork-Delegate: hjl.tools@gmail.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E50CC38582B1 for ; Thu, 28 Dec 2023 17:22:15 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 54E873858282 for ; Thu, 28 Dec 2023 17:20:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54E873858282 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 54E873858282 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784042; cv=none; b=bNcfJvgDJX4waOgLdk8Cz6Ma8J62ZKR5H0ilqKkJOjn2q4XNJB+K0lWDAPsMOGvbeFbGEXZZRmwta6GHwd9w3y4hpopxUAiERaJ8HWs9hIEPaiLo5F6oJ1UNt0G6rZAfclK8WzDcp9BHnQIKLiKnpGIXunxukOJxvHhpP0dRRHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784042; c=relaxed/simple; bh=0Lx1BUvKNpjpegvnNvDiRteHtbH/ad96hxjvyKtSttM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=aWGuUl/XwtTx5sf4t8ACkWc3AM3nO3AS0cGHf2jXf0DWKwxKLj8j38cG333vfa09t8UxLAEgjbKtPtU7Xslsu9HMy+qeaKDxXws5+33Q2nkI7jiWadsdIuvQswOQmxxJ9DCW6r+5qKiAZ/qYkfhNPOj/sTkoron6E4lumoAlKAg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6d9aa51571fso3074092b3a.3 for ; Thu, 28 Dec 2023 09:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703784037; x=1704388837; 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=R/imacu5+KSGgiyc9Jl0JvYjneQJ+wlkM+brgCqe4fI=; b=D0BBR/r5aMAMG4TA++GOm3/X492vTMNa4SmlN02+HVcF3wVnlGnwYYzchoTDeX3BQb Mvx748fOLzStjYVxsndVcY5J3gI/AnVI26FJxQVwyOG5AC/z/A7mFNsZN1BqbKPG6KV4 bRmaz6sx05D5zTOUe4mu/LVd1TnNVpCvddyiWzYtOkGnv5aFn7zlakeCa2WzZuZEyCCi fEhSWn0cHeamJCYYqtJCwOklYy3FXPye5Cv1DPfEho06QG6T1SlKzSLQykDOzRkisLJU Qn2h14enYxGEnEx/31or6YIh8PEDMC/ls98smvxXEnq35I71mojWIuUL/Dy2LeqEknxa iWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703784037; x=1704388837; 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=R/imacu5+KSGgiyc9Jl0JvYjneQJ+wlkM+brgCqe4fI=; b=T14p8cZsjvnPbE3zpynO+aiextnGdIZbsG8bhRuTm8yifa6h3PC+r+N+4kz+sCX4qK lSIedp4Sksa3vGI5W9OEa9yhODOQBVzrvuLK1Y3olaNv+RD3HL0CRadgSDv0EmNodjZ0 fxFpzazcYI/WEAE00bufqVG9BdnskpJfxmr5K9rcJJMsq/AVP6bqiDp84ZxqeAH1na/2 mGKsjEKwMKP3bqnWo4i6QGnsSwzR8UytAuc6Diiw//Md4q0XnbZRdTlgHZJrpJ8ypHKd n62Em6SuDQo5X0XXW11lRxQgCI1/R7LGlHl+/wQV2S4FSaMNwKz1Z+s7DpG9DP9R/YAq eBAA== X-Gm-Message-State: AOJu0YwHkLNpTueOofFAuK/x+uhEUj5td+up9m9ZFzEbIHFDsVesj0Tt sWWIYzUqmn8wcDHqneMaM8yK6heLBZHY+eACi7dL35bOrw8= X-Google-Smtp-Source: AGHT+IE3UovchsoAaOVJmXqwVxxRKyxZB1Ghz8aV1OmV2yXuFb8fgV5RABfc1uWMtaY8w97QP0RBQw== X-Received: by 2002:a05:6a00:1254:b0:6d9:c784:9c8f with SMTP id u20-20020a056a00125400b006d9c7849c8fmr7263700pfi.36.1703784036807; Thu, 28 Dec 2023 09:20:36 -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.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:36 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 04/12] math: Add test to check if floor raise inexact floating-point exception Date: Thu, 28 Dec 2023 14:20:18 -0300 Message-Id: <20231228172026.2013007-5-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+patchwork=sourceware.org@sourceware.org It is not allowed anymore on ISO C23. --- math/Makefile | 4 ++ math/test-floor-except-2.c | 67 ++++++++++++++++++++++++++++++ math/test-floor-except.c | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 math/test-floor-except-2.c create mode 100644 math/test-floor-except.c diff --git a/math/Makefile b/math/Makefile index 4fc7842313..19e234874a 100644 --- a/math/Makefile +++ b/math/Makefile @@ -512,6 +512,8 @@ tests = \ test-fetestexceptflag \ test-fexcept \ test-fexcept-traps \ + test-floor-except \ + test-floor-except-2 \ test-flt-eval-method \ test-fp-ilogb-constants \ test-fp-llogb-constants \ @@ -993,6 +995,8 @@ CFLAGS-test-nan-const.c += -fno-builtin CFLAGS-test-ceil-except.c += -fno-builtin CFLAGS-test-ceil-except-2.c += -fno-builtin +CFLAGS-test-floor-except.c += -fno-builtin +CFLAGS-test-floor-except-2.c += -fno-builtin include ../Rules diff --git a/math/test-floor-except-2.c b/math/test-floor-except-2.c new file mode 100644 index 0000000000..01b22f984b --- /dev/null +++ b/math/test-floor-except-2.c @@ -0,0 +1,67 @@ +/* Test floor 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; \ + /* floor must work when traps on "inexact" are enabled. */ \ + b = floor ## 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-floor-except.c b/math/test-floor-except.c new file mode 100644 index 0000000000..fe77866ddc --- /dev/null +++ b/math/test-floor-except.c @@ -0,0 +1,85 @@ +/* Test floor 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; \ + /* floor must not clear already-raised exceptions. */ \ + feraiseexcept (FE_ALL_EXCEPT); \ + b = floor ## 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 = floor ## 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