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 Netto X-Patchwork-Id: 1919289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=LkOvmSc3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V8kDn1YX6z1yZJ for ; Wed, 3 Apr 2024 23:13:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63F6B384474D for ; Wed, 3 Apr 2024 12:13:43 +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-Google-Smtp-Source: AGHT+IFNABA38P/0QZuAbqQKOziUgDZT2cSfU5lQbFEToaS18dXF2pBVh8ELp4RwVre8CIGaEXZAdw== 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+incoming=patchwork.ozlabs.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