aboutsummaryrefslogtreecommitdiff
path: root/include/qemu/int128.h
diff options
context:
space:
mode:
authorRichard Henderson <rth@twiddle.net>2016-06-29 16:57:26 -0700
committerRichard Henderson <rth@twiddle.net>2016-10-26 08:29:00 -0700
commit1edaeee0955fba7d834b7c8f4e372e7eae030745 (patch)
treea03b0bdb05135823412b7296c66924ac62b1ac41 /include/qemu/int128.h
parent0846beb36641e8f0c3ee55a5bb84d468b653c852 (diff)
downloadqemu-1edaeee0955fba7d834b7c8f4e372e7eae030745.zip
qemu-1edaeee0955fba7d834b7c8f4e372e7eae030745.tar.gz
qemu-1edaeee0955fba7d834b7c8f4e372e7eae030745.tar.bz2
int128: Add int128_make128
Allows Int128 to be used more generally, rather than having to begin with 64-bit inputs and accumulate. Reviewed-by: Emilio G. Cota <cota@braap.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
Diffstat (limited to 'include/qemu/int128.h')
-rw-r--r--include/qemu/int128.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 64a7aca..d4c6e44 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -10,6 +10,11 @@ static inline Int128 int128_make64(uint64_t a)
return a;
}
+static inline Int128 int128_make128(uint64_t lo, uint64_t hi)
+{
+ return (__uint128_t)hi << 64 | lo;
+}
+
static inline uint64_t int128_get64(Int128 a)
{
uint64_t r = a;
@@ -146,6 +151,11 @@ static inline Int128 int128_make64(uint64_t a)
return (Int128) { a, 0 };
}
+static inline Int128 int128_make128(uint64_t lo, uint64_t hi)
+{
+ return (Int128) { lo, hi };
+}
+
static inline uint64_t int128_get64(Int128 a)
{
assert(!a.hi);
@@ -195,9 +205,9 @@ static inline Int128 int128_rshift(Int128 a, int n)
}
h = a.hi >> (n & 63);
if (n >= 64) {
- return (Int128) { h, h >> 63 };
+ return int128_make128(h, h >> 63);
} else {
- return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
+ return int128_make128((a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h);
}
}
@@ -211,18 +221,18 @@ static inline Int128 int128_add(Int128 a, Int128 b)
*
* So the carry is lo < a.lo.
*/
- return (Int128) { lo, (uint64_t)a.hi + b.hi + (lo < a.lo) };
+ return int128_make128(lo, (uint64_t)a.hi + b.hi + (lo < a.lo));
}
static inline Int128 int128_neg(Int128 a)
{
uint64_t lo = -a.lo;
- return (Int128) { lo, ~(uint64_t)a.hi + !lo };
+ return int128_make128(lo, ~(uint64_t)a.hi + !lo);
}
static inline Int128 int128_sub(Int128 a, Int128 b)
{
- return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };
+ return int128_make128(a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo));
}
static inline bool int128_nonneg(Int128 a)