aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus Ferst <matheus.ferst@eldorado.org.br>2021-08-26 11:56:55 -0300
committerDavid Gibson <david@gibson.dropbear.id.au>2021-08-27 12:43:11 +1000
commit2484cd9c777f6877b178901bcb26663c411fc231 (patch)
tree296e7ff09d3e24ccb99ac48ccc0874c7e0f18e6c
parentf297c4c605e5f4412d12c4d7241df62326f47542 (diff)
downloadqemu-2484cd9c777f6877b178901bcb26663c411fc231.zip
qemu-2484cd9c777f6877b178901bcb26663c411fc231.tar.gz
qemu-2484cd9c777f6877b178901bcb26663c411fc231.tar.bz2
include/qemu/int128.h: introduce bswap128s
Changes the current bswap128 implementation to use __builtin_bswap128 when available, adds a bswap128 implementation for !CONFIG_INT128 builds, and introduces bswap128s based on bswap128. Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br> Message-Id: <20210826145656.2507213-2-matheus.ferst@eldorado.org.br> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--include/qemu/int128.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 17436d8..2ac0746 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -1,9 +1,9 @@
#ifndef INT128_H
#define INT128_H
-#ifdef CONFIG_INT128
#include "qemu/bswap.h"
+#ifdef CONFIG_INT128
typedef __int128_t Int128;
static inline Int128 int128_make64(uint64_t a)
@@ -155,7 +155,11 @@ static inline void int128_subfrom(Int128 *a, Int128 b)
static inline Int128 bswap128(Int128 a)
{
+#if __has_builtin(__builtin_bswap128)
+ return __builtin_bswap128(a);
+#else
return int128_make128(bswap64(int128_gethi(a)), bswap64(int128_getlo(a)));
+#endif
}
#else /* !CONFIG_INT128 */
@@ -350,5 +354,16 @@ static inline void int128_subfrom(Int128 *a, Int128 b)
*a = int128_sub(*a, b);
}
+static inline Int128 bswap128(Int128 a)
+{
+ return int128_make128(bswap64(a.hi), bswap64(a.lo));
+}
+
#endif /* CONFIG_INT128 */
+
+static inline void bswap128s(Int128 *s)
+{
+ *s = bswap128(*s);
+}
+
#endif /* INT128_H */