diff mbox

[v2,04/27] int128: Use __int128 if available

Message ID 1467392693-22715-5-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson July 1, 2016, 5:04 p.m. UTC
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 include/qemu/int128.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 134 insertions(+), 1 deletion(-)

Comments

Alex Bennée Aug. 11, 2016, 10:45 a.m. UTC | #1
Richard Henderson <rth@twiddle.net> writes:

> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  include/qemu/int128.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 134 insertions(+), 1 deletion(-)
>
> diff --git a/include/qemu/int128.h b/include/qemu/int128.h
> index 52aaf99..08f1db1 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 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 */

This breaks the tests/test-int128.c compile. This is mainly because the
test itself assumes details of the internals of the Int128 structure
however the expand() function will also need fixing if using GCC
__int128's.

--
Alex Bennée
diff mbox

Patch

diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 52aaf99..08f1db1 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 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 */