From patchwork Wed Apr 3 12:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 785430 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp282449wro; Wed, 3 Apr 2024 05:12:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU3tHYiUK1fFZIld/vzTeiXYGvTa9aVtiwNcWPBAwb4AhmKN6/N0J/3ho03qsDZRLNJleobUAiibKKObHHCLC39 X-Google-Smtp-Source: AGHT+IFq+/osRj8lHJoJXzC1dx/dVI4QKlBcG3XLgpz86nzWfb3w4Set4PiJK7ifsJzcS6dMWjec X-Received: by 2002:a0c:9c0a:0:b0:690:c629:348d with SMTP id v10-20020a0c9c0a000000b00690c629348dmr11452761qve.36.1712146363934; Wed, 03 Apr 2024 05:12:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712146363; cv=pass; d=google.com; s=arc-20160816; b=FyDBGErNpzKR+dAfS6huIaQoV0ZW+ACJrbyVXgeeq4yoF/yXC9Ewo+khoK3aS2wnom PmFJ1w/pB+H/clNz5urDXIrsSkNAxRVmqVLNuaXJx4vvqilgfJEpozsWwWjZZ3aw91mH BoIXkMGTIXvqXQxVdzfsaDXF6hWBRJ/4/wCLTTfcUP525rVkQkT+7STxbamJaQCX9dzU LCNM5wJNpIKzyTYqGxHbI9CjGGwrDU8xIgjBHvGuWTzxVtsd16EcUuLpcVEyrYmuXD0x r+F+E7jjpyTtChfA37GU+F/uEUzUJGWAqXzxYjlydeFm1X+ZX5zXuC3ims/QnMtp8YnV hOfQ== 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=sJVUwPw+o65swr4NFl6cBc/HD+KLB28CZeANdJyKx8E=; fh=+6orIzRLXQY2FWXAtGF+abYflc8V+YPKzsYFuX0DJM4=; b=gRDfDDaG+7Nyv0AbN5KC3wYrDosvKdtWjuqv7QAzDZg2eacK8+RJJHKJQaM73ueweb ZpaMJNvpzCb81xe6oY3yxsp4NOPX5ce3DcQuQTRNwK7GV4XjZ7YrcXnERQbTYJaRTODD UAp8zbuStbTXGgemFrSBdIOTIwNb/m3wLSInCpAKMhwIYmdcv++eykmyrbfc7Zxg6+M4 XvJg1rB07cRN9ilQMHIY3Wfl7EHx9FXWxlCWpQUmjiih1gJSYVdcyILPjvfY97XyNk0s 3A3vrGY17dL6o83ig3nEnNQ1/FmuLS2TdgQRhfbvcupb5Er0uNO7+x6IlqrDNEVfJ8po hRNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PiGa3x6U; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c4-20020a056214004400b0069693c5d18esi14023612qvr.224.2024.04.03.05.12.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PiGa3x6U; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 22B193846070 for ; Wed, 3 Apr 2024 12:12:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 45CD4384645B for ; Wed, 3 Apr 2024 12:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45CD4384645B 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 45CD4384645B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146323; cv=none; b=h1CRmOSMbptCIa7+XDse8fmmuNcFzFuuHhGLdg1KzSE3tC03KDsyxtr3+cFw8o7FyNLpSTtxn8CiRwvVVmruVOelZwe+npDfD/gWdTg3fylD48fYx91kKkq5uEQM0skhRHIZVPJAbDO8Z+OsBlTnMLiKv+ZudUdCzc9VoE4/qfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146323; c=relaxed/simple; bh=sxputx73PIDlJw0P7KhCzWKPQQe3kMVUggcSiA1MGNM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=maZ5gJ7h76hhbLYed87mKZJSYFs75JF4VLEjNHEj9PiJeCagsTuuUfdv2Y5ANoyHEpOyeXp/spwNhXf6E+D+Z6R0G890gCRX4TaW0TQh4p0nmmq9OHAqpeu4OYhF9j2l35MLNPETZg6f/v3QAYPkbgVUD3dpu1KQABmyRyjNAYA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2a266edbeb0so1157945a91.1 for ; Wed, 03 Apr 2024 05:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146319; x=1712751119; 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=sJVUwPw+o65swr4NFl6cBc/HD+KLB28CZeANdJyKx8E=; b=PiGa3x6Uu838gD4qjIrIWdLZ8xDR1cFtLg7LArFLQ7zuoHwUpoM8jM8s5/udqhHWFN Q8H2PvoBoYNQgUKnKerl/svc1IHpo7Bp1MgQw+unhoz/oDFbnCTtnedLu3J3gafit3A5 S7kprlYde4olGMzhfwjQGZkDdckSClnGS70M6A8wi6GMv06fv632el6SyC0gcdUS67uD PtWq4+ehaznpIr4Er8bDLFE2VXUjfLDH7YCuQOF3qgxsB7FHN5D7ANfjnMeZj2gUOl0a 8cyJqm3lbzZG+LiVtgzpCICl6Q9/yrtibnFfyQwaoRNUzIAX0RjWF4Nw5jSm8pSj6/0W JvvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146319; x=1712751119; 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=sJVUwPw+o65swr4NFl6cBc/HD+KLB28CZeANdJyKx8E=; b=kuRrHRjWmO4QR+hIXXP8vX2SbwVb35AtmvBwLYSdphnoYN87Mxve4Te+GPtimDy5ts tOFt0LMiHDm3U4q3rVbLRIyTI7AeC5s+4WVt5ViZkV6VgDJ5odkdjlp3j9ZofZLrKOnJ lFo+mD6YB270jkUigz9vREpX8zverBLYFRXBB2qWvSmrCdtSxESvdHNf2JZXMX7FIL1u KFr3TKGjFP0iGopVX9Pz60JemAIX94pCpzUWFAYviA5o54O13ryh5nh/D93fE92M+v5f TQJDSZzyRM8gzTrjeY++tWerhDLf5UF9xPmH5N/zz9QUdQ14nSkMWF+tlL3wPPS9lFG4 OrDA== X-Gm-Message-State: AOJu0Ywb/4dCdb8ixUfkGLwIXvTnmDk16b5RvJ+wfXfwqwpjDHsp2wpk pgH+iqsPLGJ3m4nzfdyTtxMLUhz00k0Cq4eA1H9W+pWB/8UIZeUKcbXHaPAC+1HlDqCCgSukkZ9 r X-Received: by 2002:a17:90a:49cf:b0:2a2:7356:674a with SMTP id l15-20020a17090a49cf00b002a27356674amr3128986pjm.45.1712146319502; Wed, 03 Apr 2024 05:11:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:11:58 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 03/10] math: Add test to check if trunc raise inexact floating-point exception Date: Wed, 3 Apr 2024 09:11:43 -0300 Message-Id: <20240403121150.1018799-4-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.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 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-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 8ab2582d69..32e3001ec6 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..8933c6ab41 --- /dev/null +++ b/math/test-trunc-except-2.c @@ -0,0 +1,67 @@ +/* Test trunc 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; \ + /* 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..ff909d79ed --- /dev/null +++ b/math/test-trunc-except.c @@ -0,0 +1,85 @@ +/* Test trunc 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; \ + /* 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