[PATCH-for-10.1 v7 7/8] qemu: Declare all load/store helper in 'qemu/bswap.h'

2025-07-08 Thread Philippe Mathieu-Daudé
Restrict "exec/tswap.h" to the tswap*() methods,
move the load/store helpers with the other ones
declared in "qemu/bswap.h".

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/exec/tswap.h | 70 --
 include/qemu/bswap.h | 73 
 include/system/memory.h  |  1 -
 include/user/abitypes.h  |  1 -
 target/ppc/mmu-hash64.h  |  2 -
 hw/acpi/bios-linker-loader.c |  2 -
 hw/arm/allwinner-r40.c   |  1 -
 hw/arm/boot.c|  2 +
 hw/arm/npcm7xx.c |  2 +-
 hw/block/hd-geometry.c   |  1 -
 hw/char/riscv_htif.c |  1 -
 hw/cxl/cxl-events.c  |  2 -
 hw/display/artist.c  |  1 +
 hw/display/ati.c |  1 +
 hw/net/can/ctucan_core.c |  1 -
 hw/net/lan9118.c |  1 +
 hw/net/rtl8139.c |  1 +
 hw/net/vmxnet3.c |  1 -
 hw/pci-host/gt64120.c|  1 +
 hw/pci-host/pnv_phb3.c   |  1 +
 hw/pci-host/pnv_phb4.c   |  1 +
 hw/pci-host/ppce500.c|  1 -
 hw/pci-host/sh_pci.c |  1 -
 hw/s390x/s390-pci-inst.c |  1 +
 hw/sensor/lsm303dlhc_mag.c   |  1 -
 hw/smbios/smbios.c   |  1 +
 hw/vfio/migration-multifd.c  |  1 -
 hw/virtio/virtio-pci.c   |  1 +
 hw/vmapple/virtio-blk.c  |  1 -
 target/arm/cpu.c |  1 -
 target/i386/tcg/system/excp_helper.c |  1 -
 target/i386/xsave_helper.c   |  1 -
 target/riscv/vector_helper.c |  1 -
 tests/tcg/plugins/mem.c  |  1 +
 34 files changed, 87 insertions(+), 93 deletions(-)

diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index 55ffa633598..72219e2c431 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -69,74 +69,4 @@ static inline void tswap64s(uint64_t *s)
 }
 }
 
-/* Return ld{word}_{le,be}_p following target endianness. */
-#define LOAD_IMPL(word, args...)\
-do {\
-if (target_big_endian()) {  \
-return glue(glue(ld, word), _be_p)(args);   \
-} else {\
-return glue(glue(ld, word), _le_p)(args);   \
-}   \
-} while (0)
-
-static inline int lduw_p(const void *ptr)
-{
-LOAD_IMPL(uw, ptr);
-}
-
-static inline int ldsw_p(const void *ptr)
-{
-LOAD_IMPL(sw, ptr);
-}
-
-static inline int ldl_p(const void *ptr)
-{
-LOAD_IMPL(l, ptr);
-}
-
-static inline uint64_t ldq_p(const void *ptr)
-{
-LOAD_IMPL(q, ptr);
-}
-
-static inline uint64_t ldn_p(const void *ptr, int sz)
-{
-LOAD_IMPL(n, ptr, sz);
-}
-
-#undef LOAD_IMPL
-
-/* Call st{word}_{le,be}_p following target endianness. */
-#define STORE_IMPL(word, args...)   \
-do {\
-if (target_big_endian()) {  \
-glue(glue(st, word), _be_p)(args);  \
-} else {\
-glue(glue(st, word), _le_p)(args);  \
-}   \
-} while (0)
-
-
-static inline void stw_p(void *ptr, uint16_t v)
-{
-STORE_IMPL(w, ptr, v);
-}
-
-static inline void stl_p(void *ptr, uint32_t v)
-{
-STORE_IMPL(l, ptr, v);
-}
-
-static inline void stq_p(void *ptr, uint64_t v)
-{
-STORE_IMPL(q, ptr, v);
-}
-
-static inline void stn_p(void *ptr, int sz, uint64_t v)
-{
-STORE_IMPL(n, ptr, sz, v);
-}
-
-#undef STORE_IMPL
-
 #endif  /* TSWAP_H */
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 9a117645360..39ba64046a6 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -1,6 +1,8 @@
 #ifndef BSWAP_H
 #define BSWAP_H
 
+#include "qemu/target-info.h"
+
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
 #undef  bswap32
@@ -432,4 +434,75 @@ DO_STN_LDN_P(be)
 #undef le_bswaps
 #undef be_bswaps
 
+
+/* Return ld{word}_{le,be}_p following target endianness. */
+#define LOAD_IMPL(word, args...)\
+do {\
+if (target_big_endian()) {  \
+return glue(glue(ld, word), _be_p)(args);   \
+} else {\
+return glue(glue(ld, word), _le_p)(args);   \
+}   \
+} while (0)
+
+static inline int lduw_p(const void *ptr)
+{
+LOAD_IMPL(uw, ptr);
+}
+
+static inline int ldsw_p(const void *ptr)
+{
+LOAD_IMPL(sw, ptr);
+}
+
+static inline int ldl_p(const void *ptr)
+{
+LOAD_IMPL(l, ptr);
+}
+
+static inline uint64_t ldq_p(const void *ptr)
+{
+LOAD_IMPL(q, ptr);
+}
+
+static inline uint64_t ldn_p(const void *ptr, int sz)
+{
+LOAD_IMPL(n, ptr, sz);
+}
+
+#undef LOAD_IMPL
+
+/* Call st{word}_{le,be}

Re: [PATCH-for-10.1 v7 7/8] qemu: Declare all load/store helper in 'qemu/bswap.h'

2025-07-08 Thread Pierrick Bouvier

On 7/8/25 10:19 AM, Philippe Mathieu-Daudé wrote:

Restrict "exec/tswap.h" to the tswap*() methods,
move the load/store helpers with the other ones
declared in "qemu/bswap.h".

Signed-off-by: Philippe Mathieu-Daudé 
---
  include/exec/tswap.h | 70 --
  include/qemu/bswap.h | 73 
  include/system/memory.h  |  1 -
  include/user/abitypes.h  |  1 -
  target/ppc/mmu-hash64.h  |  2 -
  hw/acpi/bios-linker-loader.c |  2 -
  hw/arm/allwinner-r40.c   |  1 -
  hw/arm/boot.c|  2 +
  hw/arm/npcm7xx.c |  2 +-
  hw/block/hd-geometry.c   |  1 -
  hw/char/riscv_htif.c |  1 -
  hw/cxl/cxl-events.c  |  2 -
  hw/display/artist.c  |  1 +
  hw/display/ati.c |  1 +
  hw/net/can/ctucan_core.c |  1 -
  hw/net/lan9118.c |  1 +
  hw/net/rtl8139.c |  1 +
  hw/net/vmxnet3.c |  1 -
  hw/pci-host/gt64120.c|  1 +
  hw/pci-host/pnv_phb3.c   |  1 +
  hw/pci-host/pnv_phb4.c   |  1 +
  hw/pci-host/ppce500.c|  1 -
  hw/pci-host/sh_pci.c |  1 -
  hw/s390x/s390-pci-inst.c |  1 +
  hw/sensor/lsm303dlhc_mag.c   |  1 -
  hw/smbios/smbios.c   |  1 +
  hw/vfio/migration-multifd.c  |  1 -
  hw/virtio/virtio-pci.c   |  1 +
  hw/vmapple/virtio-blk.c  |  1 -
  target/arm/cpu.c |  1 -
  target/i386/tcg/system/excp_helper.c |  1 -
  target/i386/xsave_helper.c   |  1 -
  target/riscv/vector_helper.c |  1 -
  tests/tcg/plugins/mem.c  |  1 +
  34 files changed, 87 insertions(+), 93 deletions(-)


Reviewed-by: Pierrick Bouvier