From patchwork Fri Nov 3 12:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740658 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp1335062wrv; Fri, 3 Nov 2023 05:24:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7b5/KDtcTcmXkARNt2jHZvOJPOSlHt9CcOnzBEh4gur1SYyh/LFFp8m9W3Sd3eX1/GVdS X-Received: by 2002:a05:6871:590:b0:1e9:8b78:899c with SMTP id u16-20020a056871059000b001e98b78899cmr25714757oan.55.1699014288231; Fri, 03 Nov 2023 05:24:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1699014288; cv=pass; d=google.com; s=arc-20160816; b=PvgfK9G5mYm7tFg9OkOIqaqLED3vqoYq3WFZuhlTiR2ARclrfsX8p/wvBPhk6E7S5T a4i1nUnkEq8RfRz+OeV/PRbA2xAnFAWF4E5cmU0DXlBnQtH4ajfrhlu7xmnSLQlau1gV D/wOICzZfpeqGiOt0ho/P0nTdkPE8gzD4f2W8TwxWSqRyGWZdRz9JiiHoVHxRAHDEAQS iWxKda1zhwP4IAiXugSv0mEbwuychkp4aO1cmMG+Uij/VVKEk6SlnwiohM9fFRfzbryp 3GrF9GyzlTuSwfRKHyBV/hdPUqvqDXL5uyfTJvi7/stUCyI6o7zlpApHarCKULgrPWb2 k+BA== 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=Fw8OjC8TmSkRlpBI6Ab8Qf0yVbpnIlKkitjWNn3IYh8=; fh=01HD8dtuIqmy9rV/eMJuvD8dAGq4TXBqBjIxWaMzNQI=; b=WDxSYyzZMauC/I7fo3KiSfFhPSvu94+zAXgkCb3zqDgcH2OvH62NZIM8sJAE7zX3y2 yALJse8ZMQVaqx3SrvQ5rrbtKa53wx7iAnpq1olUZz7Lgmb5fG5vv9CvgClxKErjL2/H D+5UwRjAOYnTDn24tI9/DByl7/CBJDIufQay9jifKRtc3HhFslZX2UL47Bq+W/6IZ2sB 4pFsQEYKExGL0NkgFIHnWXpLlQxf+16xq1u2BEuHJPjJjLWGLynatGDRzISWh5wqKScI Ti6Dx6JLfGRSHD6fMQmgwBbSuwm5xxbOHiFJ/DWdi4RikPX20bYFeu0C0xRrbJFxVuTY JVzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wdvzlQVp; 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 v17-20020ac85791000000b0041986d97773si1422718qta.580.2023.11.03.05.24.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:48 -0700 (PDT) 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=wdvzlQVp; 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 CAF233858C35 for ; Fri, 3 Nov 2023 12:24:47 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 325BE3858C5E for ; Fri, 3 Nov 2023 12:24:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 325BE3858C5E 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 325BE3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014275; cv=none; b=XYvj3TOiyai7fCBfMKkLTtzTrSVyBxqvrHg/iYsrvhizifsM5Oga6VrqAsM4wpozSZ3ZuBto/EMHS7hIA1jEZEAjBWug9AkpKqVqjpOwa8xqgs5Mdgm4N8PQNP++GiuN1PJ8NekPToDt4kJIyJbPi/b0+xrCgP2Q6qxR0vavcC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699014275; c=relaxed/simple; bh=hzXMA5hCYdtstoznVspPGxlk+2UCYkVseVesn28Zra8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EsiJFpcuJetTFTf1iv56NHMcLrSMMAO4SMOigUlmw5pL743jYna/iyZLahDrF0/kX+Rl2wQrT2DCFOF/DocoL/5i+/Lsb32cMIhKM+9G5H8BdPgEcdsvh/0UpzBNpukGcj+9B0UI/sMzb1P5q8SFHDS/s+M4gUmluYZ3iJ2iWyo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-7781bc3783fso121643485a.1 for ; Fri, 03 Nov 2023 05:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699014271; x=1699619071; 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=Fw8OjC8TmSkRlpBI6Ab8Qf0yVbpnIlKkitjWNn3IYh8=; b=wdvzlQVpudfVG1zPgLKOW/OdUCpFZw8zfDUL2EFyOBvEQAS5gAAZzY0KMuZID8inh4 LSGX9i6Jz3xO9gzf9hW/3BuZ5pm7F0ckLadFTaUfqmOwKOaoqTMmmDwXdJMcveyknEWk 4xRnJ4ohKdMI0iduKp+bAdhLIFNVBKPKM+NXa9hlH+j7oYNiYPa58yyyoOQ97/UQHDjV 2+JAnrKfQXu6QU985s7ms/rvo8hM17o/cFTBBrxaXxczK6CRvqiFyfbvucQCBXDu6tuF bWoRQhSL/BX3AevfRPoa8p5TjQdgBryL0qoKnSDSiclraT8opC/YOID7g+SZZYlyRbi0 BwUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699014271; x=1699619071; 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=Fw8OjC8TmSkRlpBI6Ab8Qf0yVbpnIlKkitjWNn3IYh8=; b=TPMByfS46yDQTdyadjWpHXEFzmZglywt08Ell8l4Xg+9F9ZRepzVMF1gFjZtMNv4H3 i1g2AffPmfiCBNtD3LFWpN/BA/ig3LFnoSGYuHDBsYFZPfRQ7QLRV6g2UKvgV0eDcqJ9 nTvsvwM1D/fd4+gRlkXFxsG3GdMXrBzXWzB1jMC9gzttM569vBh0c+8tIN/wcsbMWjGv PLDwA33OYgxW3bVfVnsA85ojKjboh7aEdxsRJarVV2WigOCdOw0O4hSDoUVRkfyCbRwI P49hwiak3p3rmWfK/wMaVP7E2kyRrr3p9UQfYOo7T1OnAF6GtV6rIUbpGW22O9X1SHa1 wS5g== X-Gm-Message-State: AOJu0YzeHo/ONpbufgqd0lWwhgpKm6nSnRCobwRjsu3rIUmHxfQaIECA MEi+NfRE91QYH4Tgdvclmfh1gjIuoCH0YFvCIZTN+w== X-Received: by 2002:a05:620a:400a:b0:778:a62a:2c4b with SMTP id h10-20020a05620a400a00b00778a62a2c4bmr24592641qko.47.1699014271596; Fri, 03 Nov 2023 05:24:31 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:dd81:f992:f726:338a]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm693833qkl.0.2023.11.03.05.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 05:24:31 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022) Date: Fri, 3 Nov 2023 09:24:14 -0300 Message-Id: <20231103122416.2724355-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 libc_feupdateenv_riscv should check for FE_DFL_ENV, similar to libc_fesetenv_riscv. Also extend the test-fenv.c to test fenvupdate. Checked on riscv under qemu-system. --- math/test-fenv.c | 132 ++++++++++++++++++++++++++++--- sysdeps/riscv/rvf/fenv_private.h | 6 +- 2 files changed, 127 insertions(+), 11 deletions(-) diff --git a/math/test-fenv.c b/math/test-fenv.c index 0af7141ba7..734e0a219d 100644 --- a/math/test-fenv.c +++ b/math/test-fenv.c @@ -196,6 +196,30 @@ set_single_exc (const char *test_name, int fe_exc, fexcept_t exception) feclearexcept (exception); test_exceptions (str, ALL_EXC ^ fe_exc, 0); } + +static void +update_single_exc (const char *test_name, const fenv_t *envp, int fe_exc, + int fe_exc_clear, fexcept_t exception) +{ + char str[200]; + /* The standard allows the inexact exception to be set together with the + underflow and overflow exceptions. So ignore the inexact flag if the + others are raised. */ + int ignore_inexact = (fe_exc & (UNDERFLOW_EXC | OVERFLOW_EXC)) != 0; + + strcpy (str, test_name); + strcat (str, ": set flag, with rest not set"); + feclearexcept (FE_ALL_EXCEPT); + feraiseexcept (exception); + feupdateenv (envp); + test_exceptions (str, fe_exc, ignore_inexact); + + strcpy (str, test_name); + strcat (str, ": clear flag, rest also unset"); + feclearexcept (exception); + feupdateenv (envp); + test_exceptions (str, fe_exc_clear, ignore_inexact); +} #endif static void @@ -233,22 +257,32 @@ fe_tests (void) } #if FE_ALL_EXCEPT +static const char * +funcname (int (*func)(const fenv_t *)) +{ + if (func == fesetenv) + return "fesetenv"; + else if (func == feupdateenv) + return "feupdateenv"; + __builtin_unreachable (); +} + /* Test that program aborts with no masked interrupts */ static void -feenv_nomask_test (const char *flag_name, int fe_exc) +feenv_nomask_test (const char *flag_name, int fe_exc, int (*func)(const fenv_t *)) { # if defined FE_NOMASK_ENV int status; pid_t pid; if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) - && fesetenv (FE_NOMASK_ENV) != 0) + && func (FE_NOMASK_ENV) != 0) { printf ("Test: not testing FE_NOMASK_ENV, it isn't implemented.\n"); return; } - printf ("Test: after fesetenv (FE_NOMASK_ENV) processes will abort\n"); + printf ("Test: after %s (FE_NOMASK_ENV) processes will abort\n", funcname (func)); printf (" when feraiseexcept (%s) is called.\n", flag_name); pid = fork (); if (pid == 0) @@ -295,12 +329,12 @@ feenv_nomask_test (const char *flag_name, int fe_exc) /* Test that program doesn't abort with default environment */ static void -feenv_mask_test (const char *flag_name, int fe_exc) +feenv_mask_test (const char *flag_name, int fe_exc, int (*func)(const fenv_t *)) { int status; pid_t pid; - printf ("Test: after fesetenv (FE_DFL_ENV) processes will not abort\n"); + printf ("Test: after %s (FE_DFL_ENV) processes will not abort\n", funcname (func)); printf (" when feraiseexcept (%s) is called.\n", flag_name); pid = fork (); if (pid == 0) @@ -313,7 +347,7 @@ feenv_mask_test (const char *flag_name, int fe_exc) setrlimit (RLIMIT_CORE, &core_limit); #endif - fesetenv (FE_DFL_ENV); + func (FE_DFL_ENV); feraiseexcept (fe_exc); exit (2); } @@ -615,10 +649,18 @@ feenable_test (const char *flag_name, int fe_exc) static void fe_single_test (const char *flag_name, int fe_exc) { - feenv_nomask_test (flag_name, fe_exc); - feenv_mask_test (flag_name, fe_exc); + feenv_nomask_test (flag_name, fe_exc, fesetenv); + feenv_mask_test (flag_name, fe_exc, fesetenv); feenable_test (flag_name, fe_exc); } + + +static void +feupdate_single_test (const char *flag_name, int fe_exc) +{ + feenv_nomask_test (flag_name, fe_exc, feupdateenv); + feenv_mask_test (flag_name, fe_exc, feupdateenv); +} #endif @@ -646,6 +688,73 @@ feenv_tests (void) fesetenv (FE_DFL_ENV); } +#if FE_ALL_EXCEPT +static void +feupdateenv_single_test (const char *test_name, int fe_exc, + fexcept_t exception) +{ + char str[100]; + fenv_t env; + int res; + + snprintf (str, sizeof str, "feupdateenv %s and FL_DFL_ENV", test_name); + update_single_exc (str, FE_DFL_ENV, fe_exc, NO_EXC, exception); + + feraiseexcept (FE_ALL_EXCEPT); + res = fegetenv (&env); + if (res != 0) + { + printf ("fegetenv failed: %d\n", res); + ++count_errors; + return; + } + + snprintf (str, sizeof str, "feupdateenv %s and FE_ALL_EXCEPT", test_name); + update_single_exc (str, &env, ALL_EXC, ALL_EXC, exception); +} +#endif + +static void +feupdateenv_tests (void) +{ + /* We might have some exceptions still set. */ + feclearexcept (FE_ALL_EXCEPT); + +#ifdef FE_DIVBYZERO + feupdate_single_test ("FE_DIVBYZERO", FE_DIVBYZERO); +#endif +#ifdef FE_INVALID + feupdate_single_test ("FE_INVALID", FE_INVALID); +#endif +#ifdef FE_INEXACT + feupdate_single_test ("FE_INEXACT", FE_INEXACT); +#endif +#ifdef FE_UNDERFLOW + feupdate_single_test ("FE_UNDERFLOW", FE_UNDERFLOW); +#endif +#ifdef FE_OVERFLOW + feupdate_single_test ("FE_OVERFLOW", FE_OVERFLOW); +#endif + +#ifdef FE_DIVBYZERO + feupdateenv_single_test ("DIVBYZERO", DIVBYZERO_EXC, FE_DIVBYZERO); +#endif +#ifdef FE_INVALID + feupdateenv_single_test ("INVALID", INVALID_EXC, FE_INVALID); +#endif +#ifdef FE_INEXACT + feupdateenv_single_test ("INEXACT", INEXACT_EXC, FE_INEXACT); +#endif +#ifdef FE_UNDERFLOW + feupdateenv_single_test ("UNDERFLOW", UNDERFLOW_EXC, FE_UNDERFLOW); +#endif +#ifdef FE_OVERFLOW + feupdateenv_single_test ("OVERFLOW", OVERFLOW_EXC, FE_OVERFLOW); +#endif + + feupdateenv (FE_DFL_ENV); +} + static void feholdexcept_tests (void) @@ -766,13 +875,14 @@ initial_tests (void) #endif } -int -main (void) +static int +do_test (void) { initial_tests (); fe_tests (); feenv_tests (); feholdexcept_tests (); + feupdateenv_tests (); if (count_errors) { @@ -782,3 +892,5 @@ main (void) printf ("\n All tests passed successfully.\n"); return 0; } + +#include diff --git a/sysdeps/riscv/rvf/fenv_private.h b/sysdeps/riscv/rvf/fenv_private.h index 40e23661b7..c91d871160 100644 --- a/sysdeps/riscv/rvf/fenv_private.h +++ b/sysdeps/riscv/rvf/fenv_private.h @@ -123,7 +123,11 @@ libc_feupdateenv_test_riscv (const fenv_t *envp, int ex) static __always_inline void libc_feupdateenv_riscv (const fenv_t *envp) { - _FPU_SETCW (*envp | riscv_getflags ()); + long int env = (long int) envp - (long int) FE_DFL_ENV; + if (env != 0) + env = *envp; + + _FPU_SETCW (env | riscv_getflags ()); } #define libc_feupdateenv libc_feupdateenv_riscv