From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E204D3858CDA for ; Mon, 6 Nov 2023 16:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E204D3858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E204D3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699287605; cv=none; b=VTixZ8YrRg7YBp5p+elk8k6wfjUute70Oj24QrM10Zge3EfHtkoHC0xIJPYBj+VpvfjROwSGP0R79ERTq7uVqZykp1zo8i2Ma0A2Qq7cEfmYB6lbUwUKcW855xJs742AbvF4Qz8R/AUFOeP30YvBnq9k0GST30cjPAx+zeMvWaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699287605; c=relaxed/simple; bh=3fmZpqp8OkSrkSDgHsXRr5UPVHBVtMrv09LUPPPP3fM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XVuBuVzfRPBAk7QyvwwTQ7RT//rkoCWc6SfHxeE9ZhRP8lGDiDQn0RIN/3hwzGznafqxIFYsSpW10tbpCYUvteJlRxALBVx2D9xsC286iwkyzQqkTQgQ27GVsc/ow1zAPIOGAVJii53JNytLCB+QaWaOn0zXcaTDaCBTrZp+3KI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699287603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=67X2L9giOjtQS5SF6hxT90V7hDWCXDBeXT/vU4ybQ7M=; b=i5VY6yEZMMH8F1XTU0Uc2VTv+XfR+whC0U3c8GJB4fid5Nvn+4vfKG84h3pNgWkihGwl6q D4YZlAmRlep+Hg8NyIjlWMLq+m95JsrZOchdwVUT/zlTZOhTbZ5TBcOjRcnGSz7cT49qAB yw2zEuW4kCTylJywgTeS2JSqohETiFM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-ldjaW6qyO_Wgza2pzB8pyQ-1; Mon, 06 Nov 2023 11:19:47 -0500 X-MC-Unique: ldjaW6qyO_Wgza2pzB8pyQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-41cc25beccaso52292811cf.1 for ; Mon, 06 Nov 2023 08:19:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699287586; x=1699892386; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=67X2L9giOjtQS5SF6hxT90V7hDWCXDBeXT/vU4ybQ7M=; b=dbPVMWLwoMngUFPoRMUI98w1Ki+ZgtKgJBNFd3JRQQVwXKx3I+GZLVbr6wdwRqcGpo OTMrAJeHN9KpjjjtWY5Mx0knWCkgNKTk7Vvh0cbPjr6ytx2fw7xpUrH9QDNNV2mhSJRr qng6RXwKhk1CWvBoLE+ld9B0NblE5l2veudzhx/+obH3Pfc6QgHoNeRAt2tVE7zn/Ybc zgFcUWNXhfRpXVzyc35YASSLNK9FSzwiuc7Y72NptHSJ+gu/3REDsqJ863/NDjHiNITM b9kvgJtvZURpYjCZPCTlSGzNG54/V4p3elCGC5jnu3SJ9b7SmQ0lTIycfjM8PQOo3SIH Fd+A== X-Gm-Message-State: AOJu0YzlWo/fc3XhPaB2Qa62wHGOblzw849wUUpqRMg18ctJfhiuFYWy RAUIWkqvkZbcpr1dwDmOKBGhRTY+vB756xdu0EDDJvXCAJHLpWtYnMq86aYpGGKg/i8QQXF+LiS hJmWr1skiGJrHFjKkJP17 X-Received: by 2002:ac8:7dd0:0:b0:41c:dd22:e7bf with SMTP id c16-20020ac87dd0000000b0041cdd22e7bfmr32844002qte.42.1699287585863; Mon, 06 Nov 2023 08:19:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOIpW3Nyc9uYWPxI3v509dTkZkKGGxpX0d5wywyjhSzNwjrMtevh1+QziqeeZ6tqjKrNewPQ== X-Received: by 2002:ac8:7dd0:0:b0:41c:dd22:e7bf with SMTP id c16-20020ac87dd0000000b0041cdd22e7bfmr32843986qte.42.1699287585534; Mon, 06 Nov 2023 08:19:45 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id jx8-20020a05622a810800b004198ae7f841sm3523865qtb.90.2023.11.06.08.19.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 08:19:45 -0800 (PST) Message-ID: Date: Mon, 6 Nov 2023 11:19:44 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022) To: Adhemerval Zanella , libc-alpha@sourceware.org, Bruno Haible References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> <20231106132713.953501-6-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20231106132713.953501-6-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 11/6/23 08:27, Adhemerval Zanella wrote: > libc_feupdateenv_riscv should check for FE_DFL_ENV, similar to > libc_fesetenv_riscv. > > Also extend the test-fenv.c to test fenvupdate. > LGTM. Thanks for extending the tests. Reviewed-by: Carlos O'Donell > Checked on riscv under qemu-system. > --- > math/test-fenv.c | 131 ++++++++++++++++++++++++++++--- > sysdeps/riscv/rvf/fenv_private.h | 8 +- > 2 files changed, 124 insertions(+), 15 deletions(-) > > diff --git a/math/test-fenv.c b/math/test-fenv.c > index 0af7141ba7..63dceddb10 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, int 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,72 @@ feenv_tests (void) > fesetenv (FE_DFL_ENV); > } > > +#if FE_ALL_EXCEPT > +static void > +feupdateenv_single_test (const char *test_name, int fe_exc, int 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 +874,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 +891,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..d8d65458b2 100644 > --- a/sysdeps/riscv/rvf/fenv_private.h > +++ b/sysdeps/riscv/rvf/fenv_private.h > @@ -93,10 +93,7 @@ libc_fetestexcept_riscv (int ex) > static __always_inline void > libc_fesetenv_riscv (const fenv_t *envp) > { > - long int env = (long int) envp - (long int) FE_DFL_ENV; > - if (env != 0) > - env = *envp; > - > + long int env = (envp != FE_DFL_ENV ? *envp : 0); > _FPU_SETCW (env); > } > > @@ -123,7 +120,8 @@ 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 = (envp != FE_DFL_ENV ? *envp : 0); > + _FPU_SETCW (env | riscv_getflags ()); > } > > #define libc_feupdateenv libc_feupdateenv_riscv -- Cheers, Carlos.