diff mbox series

[RFC,04/15] qemu/int128: Add int128_shr

Message ID 20201021045149.1582203-5-richard.henderson@linaro.org
State New
Headers show
Series softfloat: alternate conversion of float128_addsub | expand

Commit Message

Richard Henderson Oct. 21, 2020, 4:51 a.m. UTC
Add unsigned right shift as an operation.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/qemu/int128.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 167f13ae10..c53002039a 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -68,6 +68,11 @@  static inline Int128 int128_sar(Int128 a, int n)
     return a >> n;
 }
 
+static inline Int128 int128_shr(Int128 a, int n)
+{
+    return (__uint128_t)a >> n;
+}
+
 static inline Int128 int128_shl(Int128 a, int n)
 {
     return a << n;
@@ -232,6 +237,17 @@  static inline Int128 int128_sar(Int128 a, int n)
     }
 }
 
+static inline Int128 int128_shr(Int128 a, int n)
+{
+    uint64_t h = (uint64_t)a.hi >> (n & 63);
+    if (n >= 64) {
+        return int128_make64(h);
+    } else if (n > 0) {
+        return int128_make128((a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h);
+    }
+    return a;
+}
+
 static inline Int128 int128_shl(Int128 a, int n)
 {
     uint64_t l = a.lo << (n & 63);