public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org, Bruno Haible <bruno@clisp.org>
Subject: Re: [PATCH v2 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
Date: Mon, 6 Nov 2023 11:19:44 -0500	[thread overview]
Message-ID: <fd092e5f-38bf-241f-d2dd-c28d6a2e5f29@redhat.com> (raw)
In-Reply-To: <20231106132713.953501-6-adhemerval.zanella@linaro.org>

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 <carlos@redhat.com>

> 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 <support/test-driver.c>
> 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.


  reply	other threads:[~2023-11-06 16:20 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 13:27 [PATCH v2 0/7] Multiple floating-point environment fixes Adhemerval Zanella
2023-11-06 13:27 ` [PATCH v2 1/7] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) Adhemerval Zanella
2023-11-06 16:08   ` Carlos O'Donell
2023-11-06 16:50     ` Adhemerval Zanella Netto
2023-11-06 17:02       ` Carlos O'Donell
2023-11-06 17:11         ` Adhemerval Zanella Netto
2023-11-06 17:37           ` Adhemerval Zanella Netto
2023-11-06 17:38           ` Carlos O'Donell
2023-11-06 17:56             ` Adhemerval Zanella Netto
2023-11-06 20:46               ` Adhemerval Zanella Netto
2023-11-23 21:47                 ` Carlos O'Donell
2023-11-24 12:28                   ` Adhemerval Zanella Netto
2023-11-24 12:37                     ` Adhemerval Zanella Netto
2023-11-24 16:22                     ` Carlos O'Donell
2023-11-24 17:53                       ` Adhemerval Zanella Netto
2023-11-24 18:15                         ` Carlos O'Donell
2023-11-24 18:46                           ` Adhemerval Zanella Netto
2023-11-27 13:46                             ` Adhemerval Zanella Netto
2023-12-19 14:57                               ` Carlos O'Donell
2023-11-06 13:27 ` [PATCH v2 2/7] i686: Do not raise exception traps on fesetexcept (BZ 30989) Adhemerval Zanella
2023-11-06 16:14   ` Carlos O'Donell
2023-11-06 13:27 ` [PATCH v2 3/7] x86: Do not raises floating-point exception traps on fesetexceptflag (BZ 30990) Adhemerval Zanella
2023-11-06 16:16   ` Carlos O'Donell
2023-11-06 13:27 ` [PATCH v2 4/7] manual: Clarify undefined behavior of feenableexcept (BZ 31019) Adhemerval Zanella
2023-11-06 16:17   ` Carlos O'Donell
2023-11-06 13:27 ` [PATCH v2 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022) Adhemerval Zanella
2023-11-06 16:19   ` Carlos O'Donell [this message]
2023-11-06 13:27 ` [PATCH v2 6/7] alpha: Fix fesetexceptflag (BZ 30998) Adhemerval Zanella
2023-11-06 16:54   ` Carlos O'Donell
2023-11-06 17:36     ` Bruno Haible
2023-11-06 18:15       ` Carlos O'Donell
2023-11-06 13:27 ` [PATCH v2 7/7] hppa: Fix undefined behaviour in feclearexcept (BZ 30983) Adhemerval Zanella
2023-11-06 16:57   ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd092e5f-38bf-241f-d2dd-c28d6a2e5f29@redhat.com \
    --to=carlos@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bruno@clisp.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).