From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org, cota@braap.org
Subject: [Qemu-devel] [PATCH v7 04/35] int128: Use __int128 if available
Date: Wed, 19 Oct 2016 10:21:36 -0700 [thread overview]
Message-ID: <1476897727-791-5-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1476897727-791-1-git-send-email-rth@twiddle.net>
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>
---
include/qemu/int128.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++++-
tests/test-int128.c | 22 ++++----
2 files changed, 145 insertions(+), 12 deletions(-)
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 52aaf99..64a7aca 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -1,6 +1,138 @@
#ifndef INT128_H
#define INT128_H
+#ifdef CONFIG_INT128
+
+typedef __int128_t Int128;
+
+static inline Int128 int128_make64(uint64_t a)
+{
+ return a;
+}
+
+static inline uint64_t int128_get64(Int128 a)
+{
+ uint64_t r = a;
+ assert(r == a);
+ return r;
+}
+
+static inline uint64_t int128_getlo(Int128 a)
+{
+ return a;
+}
+
+static inline int64_t int128_gethi(Int128 a)
+{
+ return a >> 64;
+}
+
+static inline Int128 int128_zero(void)
+{
+ return 0;
+}
+
+static inline Int128 int128_one(void)
+{
+ return 1;
+}
+
+static inline Int128 int128_2_64(void)
+{
+ return (Int128)1 << 64;
+}
+
+static inline Int128 int128_exts64(int64_t a)
+{
+ return a;
+}
+
+static inline Int128 int128_and(Int128 a, Int128 b)
+{
+ return a & b;
+}
+
+static inline Int128 int128_rshift(Int128 a, int n)
+{
+ return a >> n;
+}
+
+static inline Int128 int128_add(Int128 a, Int128 b)
+{
+ return a + b;
+}
+
+static inline Int128 int128_neg(Int128 a)
+{
+ return -a;
+}
+
+static inline Int128 int128_sub(Int128 a, Int128 b)
+{
+ return a - b;
+}
+
+static inline bool int128_nonneg(Int128 a)
+{
+ return a >= 0;
+}
+
+static inline bool int128_eq(Int128 a, Int128 b)
+{
+ return a == b;
+}
+
+static inline bool int128_ne(Int128 a, Int128 b)
+{
+ return a != b;
+}
+
+static inline bool int128_ge(Int128 a, Int128 b)
+{
+ return a >= b;
+}
+
+static inline bool int128_lt(Int128 a, Int128 b)
+{
+ return a < b;
+}
+
+static inline bool int128_le(Int128 a, Int128 b)
+{
+ return a <= b;
+}
+
+static inline bool int128_gt(Int128 a, Int128 b)
+{
+ return a > b;
+}
+
+static inline bool int128_nz(Int128 a)
+{
+ return a != 0;
+}
+
+static inline Int128 int128_min(Int128 a, Int128 b)
+{
+ return a < b ? a : b;
+}
+
+static inline Int128 int128_max(Int128 a, Int128 b)
+{
+ return a > b ? a : b;
+}
+
+static inline void int128_addto(Int128 *a, Int128 b)
+{
+ *a += b;
+}
+
+static inline void int128_subfrom(Int128 *a, Int128 b)
+{
+ *a -= b;
+}
+
+#else /* !CONFIG_INT128 */
typedef struct Int128 Int128;
@@ -153,4 +285,5 @@ static inline void int128_subfrom(Int128 *a, Int128 b)
*a = int128_sub(*a, b);
}
-#endif
+#endif /* CONFIG_INT128 */
+#endif /* INT128_H */
diff --git a/tests/test-int128.c b/tests/test-int128.c
index 4390123..b86a3c7 100644
--- a/tests/test-int128.c
+++ b/tests/test-int128.c
@@ -41,7 +41,7 @@ static Int128 expand(uint32_t x)
uint64_t l, h;
l = expand16(x & 65535);
h = expand16(x >> 16);
- return (Int128) {l, h};
+ return (Int128) int128_make128(l, h);
};
static void test_and(void)
@@ -54,8 +54,8 @@ static void test_and(void)
Int128 b = expand(tests[j]);
Int128 r = expand(tests[i] & tests[j]);
Int128 s = int128_and(a, b);
- g_assert_cmpuint(r.lo, ==, s.lo);
- g_assert_cmpuint(r.hi, ==, s.hi);
+ g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s));
+ g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s));
}
}
}
@@ -70,8 +70,8 @@ static void test_add(void)
Int128 b = expand(tests[j]);
Int128 r = expand(tests[i] + tests[j]);
Int128 s = int128_add(a, b);
- g_assert_cmpuint(r.lo, ==, s.lo);
- g_assert_cmpuint(r.hi, ==, s.hi);
+ g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s));
+ g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s));
}
}
}
@@ -86,8 +86,8 @@ static void test_sub(void)
Int128 b = expand(tests[j]);
Int128 r = expand(tests[i] - tests[j]);
Int128 s = int128_sub(a, b);
- g_assert_cmpuint(r.lo, ==, s.lo);
- g_assert_cmpuint(r.hi, ==, s.hi);
+ g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s));
+ g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s));
}
}
}
@@ -100,8 +100,8 @@ static void test_neg(void)
Int128 a = expand(tests[i]);
Int128 r = expand(-tests[i]);
Int128 s = int128_neg(a);
- g_assert_cmpuint(r.lo, ==, s.lo);
- g_assert_cmpuint(r.hi, ==, s.hi);
+ g_assert_cmpuint(int128_getlo(r), ==, int128_getlo(s));
+ g_assert_cmpuint(int128_gethi(r), ==, int128_gethi(s));
}
}
@@ -180,8 +180,8 @@ test_rshift_one(uint32_t x, int n, uint64_t h, uint64_t l)
{
Int128 a = expand(x);
Int128 r = int128_rshift(a, n);
- g_assert_cmpuint(r.lo, ==, l);
- g_assert_cmpuint(r.hi, ==, h);
+ g_assert_cmpuint(int128_getlo(r), ==, l);
+ g_assert_cmpuint(int128_gethi(r), ==, h);
}
static void test_rshift(void)
--
2.7.4
next prev parent reply other threads:[~2016-10-19 17:22 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-19 17:21 [Qemu-devel] [PATCH v7 00/35] cmpxchg-based emulation of atomics Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 01/35] atomics: add atomic_xor Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 02/35] atomics: add atomic_op_fetch variants Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 03/35] exec: Avoid direct references to Int128 parts Richard Henderson
2016-10-19 17:21 ` Richard Henderson [this message]
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 05/35] int128: Add int128_make128 Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 07/35] linux-user: enable parallel code generation on clone Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 08/35] cputlb: Replace SHIFT with DATA_SIZE Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 09/35] cputlb: Move probe_write out of softmmu_template.h Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 10/35] cputlb: Remove includes from softmmu_template.h Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 11/35] cputlb: Move most of iotlb code out of line Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 12/35] cputlb: Tidy some macros Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 13/35] tcg: Add atomic helpers Richard Henderson
2016-10-20 10:49 ` Alex Bennée
2016-10-20 14:38 ` Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 14/35] tcg: Add atomic128 helpers Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 15/35] tcg: Add CONFIG_ATOMIC64 Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 16/35] tcg: Emit barriers with parallel_cpus Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 17/35] target-i386: emulate LOCK'ed cmpxchg using cmpxchg helpers Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 18/35] target-i386: emulate LOCK'ed OP instructions using atomic helpers Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 19/35] target-i386: emulate LOCK'ed INC using atomic helper Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 20/35] target-i386: emulate LOCK'ed NOT " Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 21/35] target-i386: emulate LOCK'ed NEG using cmpxchg helper Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 22/35] target-i386: emulate LOCK'ed XADD using atomic helper Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 23/35] target-i386: emulate LOCK'ed BTX ops using atomic helpers Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 24/35] target-i386: emulate XCHG using atomic helper Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 25/35] target-i386: remove helper_lock() Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 26/35] tests: add atomic_add-bench Richard Henderson
2016-10-19 17:21 ` [Qemu-devel] [PATCH v7 27/35] target-arm: Rearrange aa32 load and store functions Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 28/35] target-arm: emulate LL/SC using cmpxchg helpers Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 29/35] target-arm: emulate SWP with atomic_xchg helper Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 30/35] target-arm: emulate aarch64's LL/SC using cmpxchg helpers Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 31/35] linux-user: remove handling of ARM's EXCP_STREX Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 32/35] linux-user: remove handling of aarch64's EXCP_STREX Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 33/35] target-arm: remove EXCP_STREX + cpu_exclusive_{test, info} Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 34/35] target-alpha: Introduce MMU_PHYS_IDX Richard Henderson
2016-10-19 17:22 ` [Qemu-devel] [PATCH v7 35/35] target-alpha: Emulate LL/SC using cmpxchg helpers Richard Henderson
2016-10-19 18:05 ` [Qemu-devel] [PATCH v7 06/35] tcg: Add EXCP_ATOMIC Richard Henderson
2016-10-20 8:50 ` [Qemu-devel] [PATCH v7 00/35] cmpxchg-based emulation of atomics Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1476897727-791-5-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=alex.bennee@linaro.org \
--cc=cota@braap.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).