summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2022-03-23 19:57:17 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2022-04-06 10:50:37 +0200
commite03b56863d2bca3e649e81531c1b0299524481ae (patch)
treeb46f7db9476a07f55f4aba6851fb0b832519fda7 /include
parent3f6c2e8b79504e20bec8628f0f1accf3bc6d85b6 (diff)
Replace config-time define HOST_WORDS_BIGENDIAN
Replace a config-time define with a compile time condition define (compatible with clang and gcc) that must be declared prior to its usage. This avoids having a global configure time define, but also prevents from bad usage, if the config header wasn't included before. This can help to make some code independent from qemu too. gcc supports __BYTE_ORDER__ from about 4.6 and clang from 3.2. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> [ For the s390x parts I'm involved in ] Acked-by: Halil Pasic <pasic@linux.ibm.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220323155743.1585078-7-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/exec/cpu-all.h7
-rw-r--r--include/exec/cpu-common.h2
-rw-r--r--include/exec/memop.h2
-rw-r--r--include/exec/memory.h2
-rw-r--r--include/fpu/softfloat-types.h2
-rw-r--r--include/hw/core/cpu.h2
-rw-r--r--include/hw/i386/intel_iommu.h6
-rw-r--r--include/hw/i386/x86-iommu.h4
-rw-r--r--include/hw/virtio/virtio-access.h6
-rw-r--r--include/hw/virtio/virtio-gpu-bswap.h2
-rw-r--r--include/libdecnumber/dconfig.h2
-rw-r--r--include/net/eth.h2
-rw-r--r--include/qemu/bswap.h8
-rw-r--r--include/qemu/host-utils.h2
-rw-r--r--include/qemu/int128.h2
-rw-r--r--include/ui/qemu-pixman.h2
16 files changed, 27 insertions, 26 deletions
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index c0f0fab28a..f77070da5f 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -34,13 +34,14 @@
/* some important defines:
*
- * HOST_WORDS_BIGENDIAN : if defined, the host cpu is big endian and
+ * HOST_BIG_ENDIAN : whether the host cpu is big endian and
* otherwise little endian.
*
- * TARGET_WORDS_BIGENDIAN : same for target cpu
+ * TARGET_WORDS_BIGENDIAN : if defined, the host cpu is big endian and otherwise
+ * little endian.
*/
-#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN != defined(TARGET_WORDS_BIGENDIAN)
#define BSWAP_NEEDED
#endif
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 50a7d2912e..c7d50fac95 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -46,7 +46,7 @@ enum device_endian {
DEVICE_LITTLE_ENDIAN,
};
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
#define DEVICE_HOST_ENDIAN DEVICE_BIG_ENDIAN
#else
#define DEVICE_HOST_ENDIAN DEVICE_LITTLE_ENDIAN
diff --git a/include/exec/memop.h b/include/exec/memop.h
index 2a885f3917..44f923ed46 100644
--- a/include/exec/memop.h
+++ b/include/exec/memop.h
@@ -28,7 +28,7 @@ typedef enum MemOp {
MO_SIGN = 0x08, /* Sign-extended, otherwise zero-extended. */
MO_BSWAP = 0x10, /* Host reverse endian. */
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
MO_LE = MO_BSWAP,
MO_BE = 0,
#else
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 4d5997e6bb..e40653f0d1 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2931,7 +2931,7 @@ static inline MemOp devend_memop(enum device_endian end)
QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
-#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN != defined(TARGET_WORDS_BIGENDIAN)
/* Swap if non-host endianness or native (target) endianness */
return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
#else
diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h
index 8abd9ab4ec..7a6ea881d8 100644
--- a/include/fpu/softfloat-types.h
+++ b/include/fpu/softfloat-types.h
@@ -103,7 +103,7 @@ typedef struct {
#define make_floatx80(exp, mant) ((floatx80) { mant, exp })
#define make_floatx80_init(exp, mant) { .low = mant, .high = exp }
typedef struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint64_t high, low;
#else
uint64_t low, high;
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 136973655c..b0e2e5b9d2 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -187,7 +187,7 @@ struct CPUClass {
typedef union IcountDecr {
uint32_t u32;
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint16_t high;
uint16_t low;
#else
diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h
index 3b5ac869db..bfa982a419 100644
--- a/include/hw/i386/intel_iommu.h
+++ b/include/hw/i386/intel_iommu.h
@@ -145,7 +145,7 @@ enum {
/* Interrupt Remapping Table Entry Definition */
union VTD_IR_TableEntry {
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint32_t __reserved_1:8; /* Reserved 1 */
uint32_t vector:8; /* Interrupt Vector */
uint32_t irte_mode:1; /* IRTE Mode */
@@ -172,7 +172,7 @@ union VTD_IR_TableEntry {
#endif
uint32_t dest_id; /* Destination ID */
uint16_t source_id; /* Source-ID */
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint64_t __reserved_2:44; /* Reserved 2 */
uint64_t sid_vtype:2; /* Source-ID Validation Type */
uint64_t sid_q:2; /* Source-ID Qualifier */
@@ -191,7 +191,7 @@ union VTD_IR_TableEntry {
/* Programming format for MSI/MSI-X addresses */
union VTD_IR_MSIAddress {
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint32_t __head:12; /* Should always be: 0x0fee */
uint32_t index_l:15; /* Interrupt index bit 14-0 */
uint32_t int_mode:1; /* Interrupt format */
diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h
index 5ba0c056d6..7637edb430 100644
--- a/include/hw/i386/x86-iommu.h
+++ b/include/hw/i386/x86-iommu.h
@@ -87,7 +87,7 @@ struct X86IOMMUIrq {
struct X86IOMMU_MSIMessage {
union {
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint32_t __addr_head:12; /* 0xfee */
uint32_t dest:8;
uint32_t __reserved:8;
@@ -108,7 +108,7 @@ struct X86IOMMU_MSIMessage {
};
union {
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint16_t trigger_mode:1;
uint16_t level:1;
uint16_t __resved:3;
diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h
index 6818a23a2d..90cbb77782 100644
--- a/include/hw/virtio/virtio-access.h
+++ b/include/hw/virtio/virtio-access.h
@@ -149,7 +149,7 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
{
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
#else
return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
@@ -215,7 +215,7 @@ static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s)
static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s)
{
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
return virtio_access_is_big_endian(vdev) ? s : bswap32(s);
#else
return virtio_access_is_big_endian(vdev) ? bswap32(s) : s;
@@ -229,7 +229,7 @@ static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s)
static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s)
{
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
return virtio_access_is_big_endian(vdev) ? s : bswap64(s);
#else
return virtio_access_is_big_endian(vdev) ? bswap64(s) : s;
diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
index 5faac0d8d5..9124108485 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -29,7 +29,7 @@ virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr)
static inline void
virtio_gpu_bswap_32(void *ptr, size_t size)
{
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
size_t i;
struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *) ptr;
diff --git a/include/libdecnumber/dconfig.h b/include/libdecnumber/dconfig.h
index 0f7dccef1f..2bc0ba7f14 100644
--- a/include/libdecnumber/dconfig.h
+++ b/include/libdecnumber/dconfig.h
@@ -28,7 +28,7 @@
02110-1301, USA. */
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
#define WORDS_BIGENDIAN 1
#else
#define WORDS_BIGENDIAN 0
diff --git a/include/net/eth.h b/include/net/eth.h
index 7767ae880e..6e699b0d7a 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -159,7 +159,7 @@ struct tcp_hdr {
u_short th_dport; /* destination port */
uint32_t th_seq; /* sequence number */
uint32_t th_ack; /* acknowledgment number */
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
u_char th_off : 4, /* data offset */
th_x2:4; /* (unused) */
#else
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 2d3bb8bbed..9dff7c7dbb 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -84,7 +84,7 @@ static inline void bswap64s(uint64_t *s)
*s = bswap64(*s);
}
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
#define be_bswap(v, size) (v)
#define le_bswap(v, size) glue(bswap, size)(v)
#define be_bswaps(v, size)
@@ -188,7 +188,7 @@ CPU_CONVERT(le, 64, uint64_t)
* a compile-time constant if you pass in a constant. So this can be
* used to initialize static variables.
*/
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
# define const_le32(_x) \
((((_x) & 0x000000ffU) << 24) | \
(((_x) & 0x0000ff00U) << 8) | \
@@ -211,7 +211,7 @@ typedef union {
typedef union {
float64 d;
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
struct {
uint32_t upper;
uint32_t lower;
@@ -235,7 +235,7 @@ typedef union {
typedef union {
float128 q;
-#if defined(HOST_WORDS_BIGENDIAN)
+#if HOST_BIG_ENDIAN
struct {
uint32_t upmost;
uint32_t upper;
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index ca979dc6cc..f19bd29105 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -88,7 +88,7 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
union {
uint64_t ll;
struct {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
uint32_t high, low;
#else
uint32_t low, high;
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 2c4064256c..37e07fd6dd 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -205,7 +205,7 @@ typedef struct Int128 Int128;
* a union with other integer types).
*/
struct Int128 {
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
int64_t hi;
uint64_t lo;
#else
diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
index 806ddcd7cd..0c775604d1 100644
--- a/include/ui/qemu-pixman.h
+++ b/include/ui/qemu-pixman.h
@@ -19,7 +19,7 @@
* feeding libjpeg / libpng and writing screenshots.
*/
-#ifdef HOST_WORDS_BIGENDIAN
+#if HOST_BIG_ENDIAN
# define PIXMAN_BE_r8g8b8 PIXMAN_r8g8b8
# define PIXMAN_BE_x8r8g8b8 PIXMAN_x8r8g8b8
# define PIXMAN_BE_a8r8g8b8 PIXMAN_a8r8g8b8