[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/18] include/qemu/int128.h: define struct Int128 according to th
From: |
David Gibson |
Subject: |
[PULL 15/18] include/qemu/int128.h: define struct Int128 according to the host endianness |
Date: |
Fri, 27 Aug 2021 17:09:43 +1000 |
From: Matheus Ferst <matheus.ferst@eldorado.org.br>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
Message-Id: <20210826141446.2488609-2-matheus.ferst@eldorado.org.br>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
include/qemu/int128.h | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 64500385e3..17436d851d 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -162,24 +162,37 @@ static inline Int128 bswap128(Int128 a)
typedef struct Int128 Int128;
+/*
+ * We guarantee that the in-memory byte representation of an
+ * Int128 is that of a host-endian-order 128-bit integer
+ * (whether using this struct or the __int128_t version of the type).
+ * Some code using this type relies on this (eg when copying it into
+ * guest memory or a gdb protocol buffer, or by using Int128 in
+ * a union with other integer types).
+ */
struct Int128 {
+#ifdef HOST_WORDS_BIGENDIAN
+ int64_t hi;
+ uint64_t lo;
+#else
uint64_t lo;
int64_t hi;
+#endif
};
static inline Int128 int128_make64(uint64_t a)
{
- return (Int128) { a, 0 };
+ return (Int128) { .lo = a, .hi = 0 };
}
static inline Int128 int128_makes64(int64_t a)
{
- return (Int128) { a, a >> 63 };
+ return (Int128) { .lo = a, .hi = a >> 63 };
}
static inline Int128 int128_make128(uint64_t lo, uint64_t hi)
{
- return (Int128) { lo, hi };
+ return (Int128) { .lo = lo, .hi = hi };
}
static inline uint64_t int128_get64(Int128 a)
@@ -210,22 +223,22 @@ static inline Int128 int128_one(void)
static inline Int128 int128_2_64(void)
{
- return (Int128) { 0, 1 };
+ return int128_make128(0, 1);
}
static inline Int128 int128_exts64(int64_t a)
{
- return (Int128) { .lo = a, .hi = (a < 0) ? -1 : 0 };
+ return int128_make128(a, (a < 0) ? -1 : 0);
}
static inline Int128 int128_and(Int128 a, Int128 b)
{
- return (Int128) { a.lo & b.lo, a.hi & b.hi };
+ return int128_make128(a.lo & b.lo, a.hi & b.hi);
}
static inline Int128 int128_or(Int128 a, Int128 b)
{
- return (Int128) { a.lo | b.lo, a.hi | b.hi };
+ return int128_make128(a.lo | b.lo, a.hi | b.hi);
}
static inline Int128 int128_rshift(Int128 a, int n)
--
2.31.1
- [PULL 09/18] ppc/pnv: powerpc_excp: Do not discard HDECR exception when entering power-saving mode, (continued)
- [PULL 09/18] ppc/pnv: powerpc_excp: Do not discard HDECR exception when entering power-saving mode, David Gibson, 2021/08/27
- [PULL 07/18] ppc: Add a POWER10 DD2 CPU, David Gibson, 2021/08/27
- [PULL 08/18] ppc/pnv: Change the POWER10 machine to support DD2 only, David Gibson, 2021/08/27
- [PULL 10/18] ppc/pnv: Use a simple incrementing index for the chip-id, David Gibson, 2021/08/27
- [PULL 13/18] ppc/xive: Export PQ get/set routines, David Gibson, 2021/08/27
- [PULL 12/18] ppc/pnv: add a chip topology index for POWER10, David Gibson, 2021/08/27
- [PULL 11/18] ppc/pnv: Distribute RAM among the chips, David Gibson, 2021/08/27
- [PULL 06/18] ppc/pnv: update skiboot to commit 820d43c0a775., David Gibson, 2021/08/27
- [PULL 17/18] include/qemu/int128.h: introduce bswap128s, David Gibson, 2021/08/27
- [PULL 14/18] ppc/xive: Export xive_presenter_notify(), David Gibson, 2021/08/27
- [PULL 15/18] include/qemu/int128.h: define struct Int128 according to the host endianness,
David Gibson <=
- [PULL 16/18] target/ppc: fix vextu[bhw][lr]x helpers, David Gibson, 2021/08/27
- [PULL 18/18] target/ppc: fix vector registers access in gdbstub for little-endian, David Gibson, 2021/08/27
- Re: [PULL 00/18] ppc-for-6.2 queue 20210827, Peter Maydell, 2021/08/28