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 Netto X-Patchwork-Id: 758601 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp4115000wrw; Thu, 28 Dec 2023 09:21:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IELx59JMiO2Tq8P1+vNM6AyndOjN0XAt/292DFulrWOrQ+v8o6EmVayvATcqQODnDOAVH7C X-Received: by 2002:a05:622a:13d4:b0:427:a33e:8b97 with SMTP id p20-20020a05622a13d400b00427a33e8b97mr15073783qtk.5.1703784116209; Thu, 28 Dec 2023 09:21:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703784116; cv=pass; d=google.com; s=arc-20160816; b=MWC2yKU8dqBGFcaU1hVOQu8v8MocWbWNIbjS1o+hgfmahRYlvxyEJlHg7sguBUM2Gb S8zNtmGP9JhXA+8t7Ug1njtLP8TyVtvykgi31kYThj2hnw6XbPEuNoq6PpQ31HkPQR/K LAJb+I+/ajQMXyWBQsLJScuLxiwW1VonfhZRJS62o26MwsysfgmAYb//WpoV8HcFyY2T I4hG3CZJHITmKtlbW1W+4sG99u5QD0Y0JniaR23sikQox0wR7mNL3eCIpgGQmJET+mTA 5+BKrRRNttT6NNjiSsDZkhMvhgVeU7OVr5imJtvEc9/LPNrT9kNyoJnaV+7MuECD0+k9 hyxg== 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=R/imacu5+KSGgiyc9Jl0JvYjneQJ+wlkM+brgCqe4fI=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=KhfBccXfeWoKBGQAu2jy83rOZduai032mSVlRe1RN+yJjqu4BKa2vLGyISvMATbZ/B TkB1kfRbVLhH+EKt680zrfnty105P/SyEPbQSHp1/LAZUP4dElEoiwYGqDICd/y9YPje 98P8R0pRF2wg2sPSLozuo3TWGvAzrEEZC0h3eZl12lxJMIz04L8SlU6KockiXXYR6e3L eOZkmj6mqYPekLerxvYVVBeWHaUiJWWWIYVJz78qNChKfgR3RqIZuP/1CkT8vsNK/HBh Ug3ReQA7aK7RKuQjmwAEbb/kvd81RUQKFxYCzSUxrc1Xjiw6Fpj1Ws8gCH4f+bJEWJQ1 ugiw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="D0BBR/r5"; 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 t20-20020a05622a149400b00427921cdd07si16559140qtx.407.2023.12.28.09.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:21:56 -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="D0BBR/r5"; 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 C6CDC38582A5 for ; Thu, 28 Dec 2023 17:21:55 +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-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+patch=linaro.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