From patchwork Wed Apr 3 12:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 785433 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp282810wro; Wed, 3 Apr 2024 05:13:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkRpkgeq5Wq8G5enuRmUKj7RuArUCKRO7zOThJwD5j/DJUaG+BcXJJhbn++xu4esJwBiyWhPmd3/LRAof+i69O X-Google-Smtp-Source: AGHT+IER78DhoZ8dkdahFcj4NuWtzNBW9Hqw7DQ323ey0lJm+WjDz87nQZZWdJp4ZE1InCzNMoPc X-Received: by 2002:a0c:a609:0:b0:699:29e0:10b4 with SMTP id s9-20020a0ca609000000b0069929e010b4mr1667492qva.13.1712146414225; Wed, 03 Apr 2024 05:13:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712146414; cv=pass; d=google.com; s=arc-20160816; b=NbSECN649uTMh3kG5iJArKTWGo9GCN20Hgp7x8Y8916Kpy/A3QbO6E0ErpzNHhGWIm CGGKhAjnP8uRq96mF5l6fhmzWzITWi5HEgZox1JRoK+fhpzTSyHrvQLJHVTUVNs1+wCE dJgtla4N/yUaCS4TgMLMYauaH8p6vCTGtUtMRIEFTybfcIYok7y4fk1NtFpzEnjHQD8i HstnGtO/ZPXxgp3ObmNv4M2LczjCwPqohW0DJ1yHsMzaWLA6Cwnj4gbYs+odneWBNK9s 5e64K0XPoKS3aDNnIn4gIFZmKbCqMPsnHjST2Hv7QJJPLHQLGcGeI8NujNft7waiDVgO lweg== 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=2Wmvo2Adv4jQNImqTSnIjebzrJ3rq6/wUO8Oni2XBzY=; fh=+6orIzRLXQY2FWXAtGF+abYflc8V+YPKzsYFuX0DJM4=; b=Yda+iY2GeU5CmI5Ox+vfrDQRRHAzeHAJ2tWiP4rfLjiZ25tzdcYgO1L9QAHncJrp7d SkHeyWtYfuqsRZIi1nvM+kwW7jIG/di4o39rV2TT2tri8vwktbobaofPLldBYJ65riVZ b6aij/yQtAoBUyVavhnK98FBloIulstO2bguNFVYblvvojmIdTMtvLBUX+raaDIvvTF0 TDrE/nDBQhkn5OHN0ChLFw3Oh4yJ2vhz/PW+ZRKASu/R9IoOl33jWi1+BgPLQTtYAPlO riJw3AnptvOjZwGjBElqKh/aHo806ukF+qJ2daXzNgPhlWf9sjzUPBs9ONJTrAfhrOfO sJTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LkOvmSc3; 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 cn7-20020ad44a67000000b0069921262cafsi2775823qvb.225.2024.04.03.05.13.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:13:34 -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=LkOvmSc3; 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 C83673846424 for ; Wed, 3 Apr 2024 12:13:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 5DC21384772F for ; Wed, 3 Apr 2024 12:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DC21384772F 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 5DC21384772F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146321; cv=none; b=O3g0oXMM3w6CnHzQxKdk4kWUF+WRXFtWt/EbrWyUXW8fnfnpvUVx1BzEaaeb0ycbKmGtiMth45wFXvtE475PXU9wQkha8hiOs6gB0OQKNBllU6njOCANK67/BuDM4s+uXhostx5RfM/F5+vBNQ4p1iyo+TsS6tbfADdf7DjobIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146321; c=relaxed/simple; bh=vsQl7O/WiQ0wDy3oyjyrsGReBYl6UuGhJ4sbZFY0r7Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YxFIzVV4StG5/LbxF3ff9FQoW2A/Pv1U9/zK+P946GxqSzpb1rIHK1YIfhrVuivxlRjXa/AMXSS5acxbfX4VzYSx2XEVZWfKYlcueF2TPVsp/LVmxbOlwxw94C98hin6c2FnPJzVHEzZPWfs+2mCAi87IxVplvw7hbwTCHW7Ykw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5c66b093b86so706142a12.0 for ; Wed, 03 Apr 2024 05:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146318; x=1712751118; 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=2Wmvo2Adv4jQNImqTSnIjebzrJ3rq6/wUO8Oni2XBzY=; b=LkOvmSc3aXHKdMnB0N56IjEVkVVa2DuSRPC/m6nB2YfqfuWzn79rcGY2KOLKiomD0H 0Pvq7ygYIFCAWgo/x+dfrGzN1cWBtQbf5jKzJSxvMZs9uhwXVN6t8WnKREbO562yBVsF 5kequGootNzaKOO2+cyT8zLvk9ii1urRso44yhhnhAhQKd2aXE0Ak77gtKvndZIWKl/n 38wOPyFL9rvYz76IaizIccJ8hHE90Tx+6s8W0vOu4hFDpBD7xx9H0WdyK+/Hv35O02zu cxX2xTLg71tnn24vSXfFdvgG9PNQlzS1BXGubfW6A7duIrGPg1YKD3Q02COpfEPZSgwK NdGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146318; x=1712751118; 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=2Wmvo2Adv4jQNImqTSnIjebzrJ3rq6/wUO8Oni2XBzY=; b=J4HXdZC8F79Hlw4y7fc/+Q8sosvRdYi6tPcfTLLX+xt9phVcJ5T9A8awGFrwe+OE4w zVfONfbHDufRuGtFkccdHY/K4QfoYSKGy3zPkKZTnD4+j0CziYBniR5BYyQ5TnI8/fJQ 1nvWLHaU7gf/9zxMkLm+huhpwNkvKhmV6m/pFnpKjVOzYGBhWRW0rzAJgM2FNsrho9DQ kQiXx+NbjbY3TWysDc4g5U2EFkJQua1ifCeMsyIHosDoc6H/atyDWKw+BlzayHF7wK+6 MAF6d2cKzaVPcGBTiqebMAZ/AUN+i65KkKz2q9uwqgoqQzQr5rd6j7V/GtgJr6fuYWOE /Kmw== X-Gm-Message-State: AOJu0YwBNd6xdaXS7c1tkS9psoiVPMboWhWvIwX+0aUdMUxlDtC5NuK0 sehe7m+u0ZWu+eCDUdFyBv+n2aoCplyg4nHi8UGLd7lqgps9qv/zYIUCkIStZdp+AbqZftfTWDf Z X-Received: by 2002:a17:90a:df85:b0:2a0:8d17:948d with SMTP id p5-20020a17090adf8500b002a08d17948dmr3140791pjv.1.1712146317820; Wed, 03 Apr 2024 05:11:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:11:57 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 02/10] math: Add test to check if floor raise inexact floating-point exception Date: Wed, 3 Apr 2024 09:11:42 -0300 Message-Id: <20240403121150.1018799-3-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.3 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-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 1017026d23..8ab2582d69 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..d99e835909 --- /dev/null +++ b/math/test-floor-except-2.c @@ -0,0 +1,67 @@ +/* Test floor 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; \ + /* 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..a957c059e2 --- /dev/null +++ b/math/test-floor-except.c @@ -0,0 +1,85 @@ +/* Test floor 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; \ + /* 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