From: Daniel Cederman <cederman@gaisler.com>
To: libc-alpha@sourceware.org
Cc: daniel@gaisler.com, andreas@gaisler.com
Subject: [PATCH] sparc: Prevent stfsr from directly following floating-point instruction
Date: Fri, 12 Jan 2024 10:26:24 +0100 [thread overview]
Message-ID: <20240112092628.2464455-2-cederman@gaisler.com> (raw)
In-Reply-To: <20240112092628.2464455-1-cederman@gaisler.com>
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>
---
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
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__
+# 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
--
2.40.1
next prev parent reply other threads:[~2024-01-12 9:26 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 ` Daniel Cederman [this message]
2024-01-12 14:38 ` [PATCH] sparc: Prevent stfsr from directly following floating-point instruction Adhemerval Zanella Netto
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=20240112092628.2464455-2-cederman@gaisler.com \
--to=cederman@gaisler.com \
--cc=andreas@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).