+++ b/include/qemu/host-utils.h
@@ -29,6 +29,33 @@
#include "qemu/bswap.h"
#ifdef CONFIG_INT128
+static inline void urshift(uint64_t *plow, uint64_t *phigh, uint32_t shift)
+{
+ __uint128_t val = ((__uint128_t)*phigh << 64) | *plow;
+ val >>= (shift & 127);
+ *phigh = val >> 64;
+ *plow = val & 0xffffffffffffffff;
+}
+
+static inline void ulshift(uint64_t *plow, uint64_t *phigh,
+ uint32_t shift, bool *overflow)
+{
+ __uint128_t val = ((__uint128_t)*phigh << 64) | *plow;
+
+ if (shift == 0) {
+ return;
+ }
+
+ if (shift > 127 || (val >> (128 - (shift & 127))) != 0) {
+ *overflow = true;
+ }
+
+ val <<= (shift & 127);
+
+ *phigh = val >> 64;
+ *plow = val & 0xffffffffffffffff;
+}
+