From patchwork Wed Apr 3 12:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 785429 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp282219wro; Wed, 3 Apr 2024 05:12:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLURcMRD1U+cLMA3+L8itu6vI8vdXkuDMX+GdE1rxDDdlegVHURMYkbdJP0dSf5fFlILTBtNA33yGHFayMooaq X-Google-Smtp-Source: AGHT+IHrFvzxZfWabdE1mZP2Nb5m5B5yCiBD197xa+FpyBd4rVsRKu6PNqNWZ5+rHLkeHS6DjA9b X-Received: by 2002:a05:620a:3184:b0:78a:2e68:7737 with SMTP id bi4-20020a05620a318400b0078a2e687737mr3798531qkb.18.1712146332077; Wed, 03 Apr 2024 05:12:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712146332; cv=pass; d=google.com; s=arc-20160816; b=1CuNqqm6AsuRN3+de4/+7/JO8GBFYZnkx7lh7yhwawyDttwgPwR8dQSz4xVM/71zbf 5/28MSF4iKa/Nt8BmD4REmtZIlx91XQM3VQEOBgjLHzkHBWCikKiJ8Bsc0T5a6biIdI4 xzO0zduw8OiZZYyQedUqR5O0gJf7ag/JH5t9uakpLRWcXkm5rJy2jEH7smQUWcjfRxjZ 1PSPfxzSsjwbgRialKnEPrU1bCWs0Jb8K+yEyVSboI+FtASr/LIQHbT6XfkMQuks7zFL DiQB1tszGT/+BDGBNywFMNeDaeloAOQtIsoB8wjn3oYzdxSsslzUIhP8b+/8i+J2KfDY CEgw== 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=yBnoKiREZAyF9WtfBKTXBXVceZfthbag9bfH0AMnsjE=; fh=+6orIzRLXQY2FWXAtGF+abYflc8V+YPKzsYFuX0DJM4=; b=mT/1WwSgldi8fEtHFCP1Js8LUe/eFarMD9eCFfdJZfRjX+aZ0UIc0ZzVryBm43XxqW NpQL7CAftowXfN8VP67yyVMJHh3Fy30XcZyghL7d2dLmn3lkaGe09Stb10TEgSlmHA/N bp8bV40F4XXmHjQ0MAkKwVXDjddcguAekl4kmpQ4/ey6QHonmXnOrdznvGIIn3TF7UwS 8eo6W0L+9PluCDxJtRKKVaoS1bXN8lH1OQ8dbww6pnA6v2nAZh2uoXEm7QqE0lOdk+2F 7VYnZImFGOutkKGmf3Ln7mivxR4k1lB/PiN1OAK/FJtqKHX0MSBdodE3SrTfcWHIRJ/6 z64Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i2EzMC5v; 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 t4-20020a05620a0b0400b0078a15896c19si14112139qkg.213.2024.04.03.05.12.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:12 -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=i2EzMC5v; 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 A7E163846410 for ; Wed, 3 Apr 2024 12:12:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id D7EC63847725 for ; Wed, 3 Apr 2024 12:11:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7EC63847725 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 D7EC63847725 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146320; cv=none; b=wXCF0C8iMEqZKo5zqNEgtIzmttqg7U1IhqpHifKMSFG9IoSjRBa56REJpqJrGodjf5qgfqTZHNdXyNzdjRsT06yAjGLsFoNrjQZ0/ordPhbOT/A4F1RlYi72tJQ2VmJuk7aWv/3Zsq68Mq3IGQBPLzgrpCWm0OPCFThIi+PCeDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146320; c=relaxed/simple; bh=eN0lZB1bJCCwhPaRpSK8cFENwqHODXINub32tPEfFuQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=p6/9+YR3bJE3tp10oBb6RQR6B8srfw5AP85YH/EOeAUYcdS9XphT/pkEJt7tb3lFwHB8gkAHKY93M0j/H+4trhdT9RNvtTfs9t51dAp7PR+DJybuxvGmUi0PK8v+OVOXEo8SYTn6DN3VIqyjetLwf0niiwQetsLf0oK3kuzzKCc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5f034b4dcecso654507a12.1 for ; Wed, 03 Apr 2024 05:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146316; x=1712751116; 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=yBnoKiREZAyF9WtfBKTXBXVceZfthbag9bfH0AMnsjE=; b=i2EzMC5v6DraL1S/tBebeGW1J1ky95JDJZpFYj0TgRDJxsekHr96CT+vijgECkER8+ nVpaTSWj2Q2mJoVSssvGIHsU+G9pWY5DHhuHDdzj+FoEPdxXD3OFNlYvVmo0lhPjIS76 9sXp1kMuw3ljGfJFyjutEGavqCTjQNywSrif+YTj/Q70aK2J2aVbBQzGoyXw86JEtEZi mFS8JrQ4Ezy9KVo86RzxgcbBWl3MWRdWJJUZZzu+1atT0f7K82eZ2BXHC3oUkwbkX3KB PvhS7UvJliVrwdpAvwYGIWPu1BcNSYUdXBdJnHZc+o0osPPDRvhvqAoa7Cwh8baN1IPB NDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146316; x=1712751116; 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=yBnoKiREZAyF9WtfBKTXBXVceZfthbag9bfH0AMnsjE=; b=k0UcJ1wSCQb/6v+QBL4r6IROLgusvtSJJiYqGwrr6PpvYwj5oMNwgYdSGXiGmdw5jQ ixajjjoRoRUh8JW6uRAjOStEt7UWyLSvLdQa6frvEKeSbfSN9IXoVmiYzCFmhufbKGxl b91JJ/BTYsMTwsvLHUGjJHkbjla99MN5rkFrJKbUpHbxdhltROy1Aubp5+Uabi9xJ5Up l/d9kH1Fsl0EF8JyKUhPtx/EjH8M1yOyZ0pMeOmkPNpweUfsxcdL0qu0aYA7vHD+6ANh j4vhr/4VFkVetPN5azNjelus35ZSZRGlv3Ya0ff3LAtm1OW3j4uOq1A23sJWjdZX/zQq /6IA== X-Gm-Message-State: AOJu0Yy2oboDAcR2rdChjbshzqWezBQ2w+DsFJ0SkGDIJH3LhulQuNec jDyq3LylTWFKCh7mFtzZ6wdLCa4tyMjHWILzhG5vhvn+VTWdNf3M0pV1PnMQr0q9ED83GxI17Jf M X-Received: by 2002:a17:90a:b884:b0:29b:c31:1fe1 with SMTP id o4-20020a17090ab88400b0029b0c311fe1mr3313750pjr.10.1712146316183; Wed, 03 Apr 2024 05:11:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:11:55 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 01/10] math: Add test to check if ceil raise inexact floating-point exception Date: Wed, 3 Apr 2024 09:11:41 -0300 Message-Id: <20240403121150.1018799-2-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.0 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 | 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 121a709121..1017026d23 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..394a272d89 --- /dev/null +++ b/math/test-ceil-except-2.c @@ -0,0 +1,67 @@ +/* Test ceil 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; \ + /* 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..f7627506f7 --- /dev/null +++ b/math/test-ceil-except.c @@ -0,0 +1,85 @@ +/* Test ceil 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; \ + /* 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