From 234a22803ddb28c02cb116ea1a92498d2c32f7d5 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 26 Feb 2021 13:45:41 -0500 Subject: [PATCH] qemu/int128: Add int128_lshift Add left-shift to match the existing right-shift. Backports 5be4dd043f5beb5e7587d1ef8dd4e3716ec05639 --- qemu/include/qemu/int128.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qemu/include/qemu/int128.h b/qemu/include/qemu/int128.h index 159cb13f..8330cf76 100644 --- a/qemu/include/qemu/int128.h +++ b/qemu/include/qemu/int128.h @@ -70,6 +70,11 @@ static inline Int128 int128_add(Int128 a, Int128 b) return a + b; } +static inline Int128 int128_lshift(Int128 a, int n) +{ + return a << n; +} + static inline Int128 int128_neg(Int128 a) { return -a; @@ -226,6 +231,17 @@ static inline Int128 int128_rshift(Int128 a, int n) } } +static inline Int128 int128_lshift(Int128 a, int n) +{ + uint64_t l = a.lo << (n & 63); + if (n >= 64) { + return int128_make128(0, l); + } else if (n > 0) { + return int128_make128(l, (a.hi << n) | (a.lo >> (64 - n))); + } + return a; +} + static inline Int128 int128_add(Int128 a, Int128 b) { uint64_t lo = a.lo + b.lo;