From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, David Hildenbrand <david@redhat.com>,
Peter Xu <peterx@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Mark Burton" <mburton@qti.qualcomm.com>
Subject: [PATCH 1/2] include/exec: Make ld*_p and st*_p functions available for generic code, too
Date: Wed, 17 May 2023 09:42:21 +0200 [thread overview]
Message-ID: <20230517074222.766683-2-thuth@redhat.com> (raw)
In-Reply-To: <20230517074222.766683-1-thuth@redhat.com>
This will allow to move more code into the target independent source set.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/exec/cpu-all.h | 25 ----------------
include/exec/tswap.h | 66 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 25 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index ad824fee52..0daa4c06e5 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -55,31 +55,6 @@
#define bswaptls(s) bswap64s(s)
#endif
-/* Target-endianness CPU memory access functions. These fit into the
- * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
- */
-#if TARGET_BIG_ENDIAN
-#define lduw_p(p) lduw_be_p(p)
-#define ldsw_p(p) ldsw_be_p(p)
-#define ldl_p(p) ldl_be_p(p)
-#define ldq_p(p) ldq_be_p(p)
-#define stw_p(p, v) stw_be_p(p, v)
-#define stl_p(p, v) stl_be_p(p, v)
-#define stq_p(p, v) stq_be_p(p, v)
-#define ldn_p(p, sz) ldn_be_p(p, sz)
-#define stn_p(p, sz, v) stn_be_p(p, sz, v)
-#else
-#define lduw_p(p) lduw_le_p(p)
-#define ldsw_p(p) ldsw_le_p(p)
-#define ldl_p(p) ldl_le_p(p)
-#define ldq_p(p) ldq_le_p(p)
-#define stw_p(p, v) stw_le_p(p, v)
-#define stl_p(p, v) stl_le_p(p, v)
-#define stq_p(p, v) stq_le_p(p, v)
-#define ldn_p(p, sz) ldn_le_p(p, sz)
-#define stn_p(p, sz, v) stn_le_p(p, sz, v)
-#endif
-
/* MMU memory access macros */
#if defined(CONFIG_USER_ONLY)
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index 68944a880b..2774820bbe 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -69,4 +69,70 @@ static inline void tswap64s(uint64_t *s)
}
}
+/*
+ * Target-endianness CPU memory access functions. These fit into the
+ * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
+ */
+
+static inline int lduw_p(const void *ptr)
+{
+ return (uint16_t)tswap16(lduw_he_p(ptr));
+}
+
+static inline int ldsw_p(const void *ptr)
+{
+ return (int16_t)tswap16(lduw_he_p(ptr));
+}
+
+static inline int ldl_p(const void *ptr)
+{
+ return tswap32(ldl_he_p(ptr));
+}
+
+static inline uint64_t ldq_p(const void *ptr)
+{
+ return tswap64(ldq_he_p(ptr));
+}
+
+static inline uint64_t ldn_p(const void *ptr, int sz)
+{
+ if (target_needs_bswap()) {
+#if HOST_BIG_ENDIAN
+ return ldn_le_p(ptr, sz);
+#else
+ return ldn_be_p(ptr, sz);
+#endif
+ } else {
+ return ldn_he_p(ptr, sz);
+ }
+}
+
+static inline void stw_p(void *ptr, uint16_t v)
+{
+ stw_he_p(ptr, tswap16(v));
+}
+
+static inline void stl_p(void *ptr, uint32_t v)
+{
+ stl_he_p(ptr, tswap32(v));
+}
+
+static inline void stq_p(void *ptr, uint64_t v)
+{
+ stq_he_p(ptr, tswap64(v));
+}
+
+static inline void stn_p(void *ptr, int sz, uint64_t v)
+{
+ if (target_needs_bswap()) {
+#if HOST_BIG_ENDIAN
+ stn_le_p(ptr, sz, v);
+#else
+ stn_be_p(ptr, sz, v);
+#endif
+ } else {
+ stn_he_p(ptr, sz, v);
+ }
+}
+
#endif /* TSWAP_H */
--
2.31.1
next prev parent reply other threads:[~2023-05-17 7:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 7:42 [PATCH 0/2] Make ioport.c target-independent Thomas Huth
2023-05-17 7:42 ` Thomas Huth [this message]
2023-05-17 10:18 ` [PATCH 1/2] include/exec: Make ld*_p and st*_p functions available for generic code, too Philippe Mathieu-Daudé
2023-05-17 10:38 ` Thomas Huth
2023-05-17 13:20 ` Richard Henderson
2023-05-17 7:42 ` [PATCH 2/2] softmmu: Move ioport.c into the target-independent source set Thomas Huth
2023-05-17 13:23 ` Richard Henderson
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=20230517074222.766683-2-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=david@redhat.com \
--cc=mburton@qti.qualcomm.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 NNTP newsgroup(s).