public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Daniel Cederman <cederman@gaisler.com>, libc-alpha@sourceware.org
Cc: daniel@gaisler.com, andreas@gaisler.com
Subject: Re: [PATCH] sparc: Prevent stfsr from directly following floating-point instruction
Date: Fri, 12 Jan 2024 11:38:34 -0300	[thread overview]
Message-ID: <77658cde-97f2-4017-aba9-8d062a6cddba@linaro.org> (raw)
In-Reply-To: <20240112092628.2464455-2-cederman@gaisler.com>



On 12/01/24 06:26, Daniel Cederman wrote:
> On LEON, if the stfsr instruction is immediately following a floating-point
> operation instruction in a running program, with no other instruction in
> between the two, the stfsr might behave as if the order was reversed
> between the two instructions and the stfsr occurred before the
> floating-point operation.
> 
> Add a nop instruction before the stfsr to prevent this from happening.
> 
> Signed-off-by: Daniel Cederman <cederman@gaisler.com>

You might want to check if __builtin_store_fsr gcc builtin is also subject
to this issue (it used on atomic floating point support as well).

> ---
>  sysdeps/sparc/fpu/fenv_private.h | 6 +++++-
>  sysdeps/sparc/fpu/fpu_control.h  | 6 +++++-
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/sparc/fpu/fenv_private.h b/sysdeps/sparc/fpu/fenv_private.h
> index da7c7fe332..a02af80d04 100644
> --- a/sysdeps/sparc/fpu/fenv_private.h
> +++ b/sysdeps/sparc/fpu/fenv_private.h
> @@ -8,7 +8,11 @@
>  # define __fenv_stfsr(X)   __asm__ __volatile__ ("stx %%fsr,%0" : "=m" (X))
>  # define __fenv_ldfsr(X)   __asm__ __volatile__ ("ldx %0,%%fsr" : : "m" (X))
>  #else
> -# define __fenv_stfsr(X)   __asm__ __volatile__ ("st %%fsr,%0" : "=m" (X))
> +# ifdef __leon__
> +#  define __fenv_stfsr(X)   __asm__ __volatile__ ("nop; st %%fsr,%0" : "=m" (X))
> +# else
> +#  define __fenv_stfsr(X)   __asm__ __volatile__ ("st %%fsr,%0" : "=m" (X))
> +# endif
>  # define __fenv_ldfsr(X)   __asm__ __volatile__ ("ld %0,%%fsr" : : "m" (X))
>  #endif
>  

I think it would be better to use _FPU_GETCW/_FPU_SETCW here, this will me
the fix only required at fpu_control.h:

#include <fpu_control.h>
[...]
#define __fenv_stfsr(X)   _FPU_GETCW (X)
#define __fenv_ldfsr(X)   _FPU_SETCW (X)
[...]

> diff --git a/sysdeps/sparc/fpu/fpu_control.h b/sysdeps/sparc/fpu/fpu_control.h
> index dd18789573..9313743f86 100644
> --- a/sysdeps/sparc/fpu/fpu_control.h
> +++ b/sysdeps/sparc/fpu/fpu_control.h
> @@ -61,7 +61,11 @@ typedef unsigned long int fpu_control_t;
>  # define _FPU_GETCW(cw) __asm__ __volatile__ ("stx %%fsr,%0" : "=m" (*&cw))
>  # define _FPU_SETCW(cw) __asm__ __volatile__ ("ldx %0,%%fsr" : : "m" (*&cw))
>  #else
> -# define _FPU_GETCW(cw) __asm__ __volatile__ ("st %%fsr,%0" : "=m" (*&cw))
> +# ifdef __leon__

Please also add a brief comment on why the nop is required.

> +#  define _FPU_GETCW(cw) __asm__ __volatile__ ("nop; st %%fsr,%0" : "=m" (*&cw))
> +# else
> +#  define _FPU_GETCW(cw) __asm__ __volatile__ ("st %%fsr,%0" : "=m" (*&cw))
> +# endif
>  # define _FPU_SETCW(cw) __asm__ __volatile__ ("ld %0,%%fsr" : : "m" (*&cw))
>  #endif
>  

  reply	other threads:[~2024-01-12 14:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12  9:26 [PATCH] sparc: Do not test preservation of NaN payloads for LEON Daniel Cederman
2024-01-12  9:26 ` [PATCH] sparc: Prevent stfsr from directly following floating-point instruction Daniel Cederman
2024-01-12 14:38   ` Adhemerval Zanella Netto [this message]
2024-01-15  9:37     ` Daniel Cederman
2024-01-12  9:26 ` [PATCH] sparc: Force calculation that raises exception Daniel Cederman
2024-01-12 16:45   ` Adhemerval Zanella Netto
2024-01-15  9:41     ` Daniel Cederman
2024-01-15 11:47       ` Adhemerval Zanella Netto
2024-01-12  9:26 ` [PATCH] sparc: Treat the version field in the FPU control word as reserved Daniel Cederman
2024-01-12 17:42   ` Adhemerval Zanella Netto
2024-02-15  9:31     ` Daniel Cederman
2024-02-19 14:55       ` Adhemerval Zanella Netto
2024-01-12  9:26 ` [PATCH] sparc: Fix llrint and llround missing exceptions on SPARC32 Daniel Cederman
2024-01-12 18:05   ` Adhemerval Zanella Netto
2024-01-15 14:38     ` Daniel Cederman
2024-01-15 17:52       ` Adhemerval Zanella Netto
2024-01-12  9:26 ` [PATCH] sparc: Remove unwind information from signal return stub functions Daniel Cederman
2024-01-15 13:41   ` Adhemerval Zanella Netto
2024-01-15 14:22     ` Daniel Cederman
2024-01-15 16:57       ` Adhemerval Zanella Netto
2024-01-16 15:37 ` [PATCH] sparc: Do not test preservation of NaN payloads for LEON Adhemerval Zanella Netto

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=77658cde-97f2-4017-aba9-8d062a6cddba@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=andreas@gaisler.com \
    --cc=cederman@gaisler.com \
    --cc=daniel@gaisler.com \
    --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).