[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 09/25] qemu/bswap: Introduce LD_CONVERT() macro
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 09/25] qemu/bswap: Introduce LD_CONVERT() macro |
Date: |
Tue, 18 May 2021 20:36:39 +0200 |
To be able to add more load/store operations,
introduce the LD_CONVERT() macro.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/qemu/bswap.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 4e2bd2e97ee..c2fd4f31d20 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -434,18 +434,37 @@ static inline void stq_be_p(void *ptr, uint64_t v)
stq_he_p(ptr, be_bswap(v, 64));
}
+#define LD_CONVERT_UNALIGNED(bits, rtype, vtype, size)\
+static inline rtype ld ## size ## _he_p(const void *ptr)\
+{\
+ vtype r;\
+ __builtin_memcpy(&r, ptr, sizeof(r));\
+ return r;\
+}
+
#define ST_CONVERT_UNALIGNED(bits, vtype, size)\
static inline void st ## size ## _he_p(void *ptr, vtype v)\
{\
__builtin_memcpy(ptr, &v, sizeof(v));\
}
+#define LD_CONVERT_END(endian, bits, rtype, vtype, size)\
+static inline rtype ld ## size ## _ ## endian ## _p(const void *ptr)\
+{\
+ return (vtype)glue(endian, _bswap)(ld ## size ## _he_p(ptr), bits);\
+}
+
#define ST_CONVERT_END(endian, bits, vtype, size)\
static inline void st ## size ## _ ## endian ## _p(void *ptr, vtype v)\
{\
st ## size ## _he_p(ptr, glue(endian, _bswap)(v, bits));\
}
+#define LD_CONVERT(bits, rtype, vtype, size)\
+ LD_CONVERT_UNALIGNED(bits, rtype, vtype, size)\
+ LD_CONVERT_END(le, bits, rtype, vtype, size)\
+ LD_CONVERT_END(be, bits, rtype, vtype, size)
+
#define ST_CONVERT(bits, vtype, size)\
ST_CONVERT_UNALIGNED(bits, vtype, size)\
ST_CONVERT_END(le, bits, vtype, size)\
--
2.26.3
- [RFC PATCH 00/25] exec: Add load/store API for aligned pointers, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 01/25] exec/memory_ldst_cached: Sort declarations, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 03/25] exec/memory_ldst: Use correct type sizes, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 02/25] exec/memory_ldst_phys: Sort declarations, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 04/25] exec/memory_ldst_phys: Use correct type sizes, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 05/25] exec/memory_ldst_cached: Use correct type size, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 06/25] exec/memory: Use correct type size, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 08/25] qemu/bswap: Use ST_CONVERT() macro to emit 16-bit load/store functions, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 07/25] qemu/bswap: Introduce ST_CONVERT() macro, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 09/25] qemu/bswap: Introduce LD_CONVERT() macro,
Philippe Mathieu-Daudé <=
- [RFC PATCH 10/25] qemu/bswap: Use LD_CONVERT macro to emit 16-bit signed load/store code, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 11/25] qemu/bswap: Use LD_CONVERT macro to emit 16-bit unsigned load/store code, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 12/25] qemu/bswap: Use LDST_CONVERT macro to emit 32-bit load/store functions, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 13/25] qemu/bswap: Use LDST_CONVERT macro to emit 64-bit load/store functions, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 14/25] qemu/bswap: Introduce load/store for aligned pointer, Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 16/25] exec/memory: Add methods for aligned pointer access (physical memory), Philippe Mathieu-Daudé, 2021/05/18
- [RFC PATCH 15/25] exec/memory: Add methods for aligned pointer access (address space), Philippe Mathieu-Daudé, 2021/05/18