From patchwork Thu Dec 28 17:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 758603 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp4115177wrw; Thu, 28 Dec 2023 09:22:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7PxnaXDx7wQayDfqowuIO7iYHPrYY4OvU255Ojbmg7ko9u3Us+donXrzINg3brLxMgho8 X-Received: by 2002:a05:6808:f10:b0:3b9:e7f5:39b8 with SMTP id m16-20020a0568080f1000b003b9e7f539b8mr15397176oiw.36.1703784142641; Thu, 28 Dec 2023 09:22:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703784142; cv=pass; d=google.com; s=arc-20160816; b=qlHZeFXA54JatPD3QDfIhWI4nk7I6Lh8/NwcTGRDuM+oEwbebV/dxuIljRtBfPH5kd 9Z23JtFtaOx6ktkCiOicfdhY+WjUq0LfhcaC8lw7T80k7G1+MUHNBmkrQbkqx9ACRAn1 uDgjSaoDIM3VoR77F00Osx/V9Y5C/MJ+58lt7BUvueRkX+0JRgfx4TgNi25LnD0FLPFI BvCcdEzg6JfQ7h88S8uBmnpmABkgRCb79SzdmkF2kJetq3FnC0BTj9al9iYU0F/FTZ0Q DEAl20xkHz/KzuK2iae0Q3r4Hn79hgFIaGFJ0SM54sKN4XuPcuHoIAxmpDzhiNa7VBdE FXOQ== 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=jYCR0Es9t9c5ayU2ClkHYO27pEUSNvGDcJ87yJNQxaE=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=asTma2jOSapT9cqo8h5JwbDA3ur5hRwQJ7lWpdrFfb8Wfeu6wMF8eCXzbjercuwc5E HGLj4N4utsatouftavWJhNVk0RwwnRP9tWMU9x8/X7q7BqVkB6srM3CcT7XLIek24J6C u5CbFSERjnFtyThJgf1wAloK/M7nmD7bdNFMwETk4ZGS39BilxqrbgRh5XWq/J5UjGC7 kZAD7LSagl0rav0TfcHaF19e+xPFg6ZE/2X+tYpWzwTxkNb8e9ut7DIb8W1l75SV9cZZ nRMumaXlyHsmYvs9Gkb58No+/tpYSb2J3B8v7ubUCHumMOsAUtnt4WddKDB+tAG4FLBX 9idA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ArIHerb8; 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 w8-20020a05622a190800b00419628da454si17621575qtc.177.2023.12.28.09.22.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:22:22 -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=ArIHerb8; 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 3D529385829D for ; Thu, 28 Dec 2023 17:22:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by sourceware.org (Postfix) with ESMTPS id AA3AC3858C36 for ; Thu, 28 Dec 2023 17:20:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA3AC3858C36 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 AA3AC3858C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784044; cv=none; b=glUrAtWwnH98HNZs+b3oyteM3qeUCbVtNqsiOOQQODPFigwqlY2hgZXXMjVIc7CqgsAXm7h4myMyL/Iv/yGkJnWI6pKm20vPmqDOl6myOLq1wPsI9s1jGIl0fed3fIMdJBDkYLEtUADgRN/uk4fSqlA8uSW+oBl+dASLR3neD6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784044; c=relaxed/simple; bh=BHsfWGMLCtderjDLsmqkIZqsyGo5HVhwwXD4ZWsLGH8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=MKizTBTbnNAV2UM8DDGHep+rsMX0UC5XMx+T/xzcYxlV9AtZLhEVOMqLXt8UKQYqA32aYgfIL2g4xYbdIBR+HM0SpNWZnA7yBI9GjYzXyl8vvjx6xXb/plqBeIJdIWcLcXh3wAUubCUW6tZ2vAmy4n3QE7eclvJ0fG1GRLTtVH8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-594965fbb3cso2032994eaf.1 for ; Thu, 28 Dec 2023 09:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703784038; x=1704388838; 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=jYCR0Es9t9c5ayU2ClkHYO27pEUSNvGDcJ87yJNQxaE=; b=ArIHerb8OyRYHuUZ+iuemwksf4zBamvfHcEBIkPTn47QhmnkfDDINQbOTI30OMpeO9 z3sn/EJe46sV6jTSRpCoL26wvhUMVao0Thbwrtw5SWPSfO4i0af9hC1/UpqQMxg8vs70 HI1zQQvqJ7vUsLQp3rpvYlRFz6moTs5DKbflm3nEvHk1IvHtZYAypSRm1EfvcoxaP1wk o0s3Mjn9BDlA6dvm+enGBO8/W8PVU/BXhmoAcLI80AUbau7j9ySNFSII9r4Q3tEpWIh9 JdbyieFpvoMGFFOaFvqk8k272/LQWg5drH5F8+kq/VcaCEyT+LBlLCvBOtw+zSTK1HnW gwoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703784038; x=1704388838; 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=jYCR0Es9t9c5ayU2ClkHYO27pEUSNvGDcJ87yJNQxaE=; b=obzQxm3coRLa1YwHZ0U6JuFn7KCdpHcq05b11vSePLo4T3hxKAO6PiZYnBvHeQsY6h vXCdaYHJpPIuQEJZwR/ShVWf58xQNe6K7M83kjkhB7hZXT6hSJ2TpQ2Kxy11M/mUUXSF xoD5sKYCZ40HKFbRRcIuiq4BBeiZxmfOvDqm9yUNv39V/02zG0sTWakWWK872Q3Jn/HT TOnZLUFj0wR2A8OSe6Lc6hem1BhxWrxdVXwd9VcuYNqQ5Q06PcwV42t+TZULsM3h8LJt XO8DVgG9JoJolUV0L6FnuN/rOX0ZfUwpZ/hi9JbK3HEYmQsVoqG7aczERueWoNs5NRPb ksSQ== X-Gm-Message-State: AOJu0Yx7FzZQ1XdapOjHXAtExtYCZibQb6k2I9Cl2O0M4WH2aejzFdfA WXqUNHDiFWelnJhfbDMauSeMym+ikILpMwT181KONqilRSg= X-Received: by 2002:a05:6359:4c06:b0:172:f31a:6bfb with SMTP id kj6-20020a0563594c0600b00172f31a6bfbmr14104588rwc.51.1703784038309; Thu, 28 Dec 2023 09:20:38 -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.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:37 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 05/12] math: Add test to check if trunc raise inexact floating-point exception Date: Thu, 28 Dec 2023 14:20:19 -0300 Message-Id: <20231228172026.2013007-6-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.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, 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-trunc-except-2.c | 67 ++++++++++++++++++++++++++++++ math/test-trunc-except.c | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 math/test-trunc-except-2.c create mode 100644 math/test-trunc-except.c diff --git a/math/Makefile b/math/Makefile index 19e234874a..7ae107170c 100644 --- a/math/Makefile +++ b/math/Makefile @@ -541,6 +541,8 @@ tests = \ test-tgmath-int \ test-tgmath-ret \ test-tgmath2 \ + test-trunc-except \ + test-trunc-except-2 \ tst-CMPLX \ tst-CMPLX2 \ tst-definitions \ @@ -997,6 +999,8 @@ 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 +CFLAGS-test-trunc-except.c += -fno-builtin +CFLAGS-test-trunc-except-2.c += -fno-builtin include ../Rules diff --git a/math/test-trunc-except-2.c b/math/test-trunc-except-2.c new file mode 100644 index 0000000000..29716efc0b --- /dev/null +++ b/math/test-trunc-except-2.c @@ -0,0 +1,67 @@ +/* Test trunc 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; \ + /* trunc must work when traps on "inexact" are enabled. */ \ + b = trunc ## 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-trunc-except.c b/math/test-trunc-except.c new file mode 100644 index 0000000000..c9e341de0d --- /dev/null +++ b/math/test-trunc-except.c @@ -0,0 +1,85 @@ +/* Test trunc 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; \ + /* trunc must not clear already-raised exceptions. */ \ + feraiseexcept (FE_ALL_EXCEPT); \ + b = trunc ## 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 = trunc ## 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