aboutsummaryrefslogtreecommitdiff
path: root/include/qemu
diff options
context:
space:
mode:
authorLucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>2022-05-25 10:49:50 -0300
committerDaniel Henrique Barboza <danielhb413@gmail.com>2022-06-20 08:38:58 -0300
commit4724bbd28475210d25e0c949a7f424550487b187 (patch)
tree0e1bd80eb2f3defa702031f7240601d0504c441b /include/qemu
parent9a1f0866a3caf0f98ff588ba84da4fa6be2dc39c (diff)
downloadqemu-4724bbd28475210d25e0c949a7f424550487b187.zip
qemu-4724bbd28475210d25e0c949a7f424550487b187.tar.gz
qemu-4724bbd28475210d25e0c949a7f424550487b187.tar.bz2
host-utils: Implemented unsigned 256-by-128 division
Based on already existing QEMU implementation, created an unsigned 256 bit by 128 bit division needed to implement the vector divide extended unsigned instruction from PowerISA3.1 Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220525134954.85056-5-lucas.araujo@eldorado.org.br> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/host-utils.h2
-rw-r--r--include/qemu/int128.h38
2 files changed, 40 insertions, 0 deletions
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index f19bd29..9767af7 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -32,6 +32,7 @@
#include "qemu/compiler.h"
#include "qemu/bswap.h"
+#include "qemu/int128.h"
#ifdef CONFIG_INT128
static inline void mulu64(uint64_t *plow, uint64_t *phigh,
@@ -849,4 +850,5 @@ static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1,
#endif
}
+Int128 divu256(Int128 *plow, Int128 *phigh, Int128 divisor);
#endif
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index ef71f56..d2b76ca 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -128,11 +128,21 @@ static inline bool int128_ge(Int128 a, Int128 b)
return a >= b;
}
+static inline bool int128_uge(Int128 a, Int128 b)
+{
+ return ((__uint128_t)a) >= ((__uint128_t)b);
+}
+
static inline bool int128_lt(Int128 a, Int128 b)
{
return a < b;
}
+static inline bool int128_ult(Int128 a, Int128 b)
+{
+ return (__uint128_t)a < (__uint128_t)b;
+}
+
static inline bool int128_le(Int128 a, Int128 b)
{
return a <= b;
@@ -177,6 +187,15 @@ static inline Int128 bswap128(Int128 a)
#endif
}
+static inline int clz128(Int128 a)
+{
+ if (a >> 64) {
+ return __builtin_clzll(a >> 64);
+ } else {
+ return (a) ? __builtin_clzll((uint64_t)a) + 64 : 128;
+ }
+}
+
static inline Int128 int128_divu(Int128 a, Int128 b)
{
return (__uint128_t)a / (__uint128_t)b;
@@ -373,11 +392,21 @@ static inline bool int128_ge(Int128 a, Int128 b)
return a.hi > b.hi || (a.hi == b.hi && a.lo >= b.lo);
}
+static inline bool int128_uge(Int128 a, Int128 b)
+{
+ return (uint64_t)a.hi > (uint64_t)b.hi || (a.hi == b.hi && a.lo >= b.lo);
+}
+
static inline bool int128_lt(Int128 a, Int128 b)
{
return !int128_ge(a, b);
}
+static inline bool int128_ult(Int128 a, Int128 b)
+{
+ return !int128_uge(a, b);
+}
+
static inline bool int128_le(Int128 a, Int128 b)
{
return int128_ge(b, a);
@@ -418,6 +447,15 @@ static inline Int128 bswap128(Int128 a)
return int128_make128(bswap64(a.hi), bswap64(a.lo));
}
+static inline int clz128(Int128 a)
+{
+ if (a.hi) {
+ return __builtin_clzll(a.hi);
+ } else {
+ return (a.lo) ? __builtin_clzll(a.lo) + 64 : 128;
+ }
+}
+
Int128 int128_divu(Int128, Int128);
Int128 int128_remu(Int128, Int128);
Int128 int128_divs(Int128, Int128);