qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Morel <pmorel@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: cornelia.huck@de.ibm.com, pbonzini@redhat.com,
	pmorel@linux.vnet.ibm.com, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH 1/7] int128: use unsigned 128 bit arithmetic
Date: Thu,  5 Nov 2015 17:18:53 +0100	[thread overview]
Message-ID: <1446740339-31366-2-git-send-email-pmorel@linux.vnet.ibm.com> (raw)
In-Reply-To: <1446740339-31366-1-git-send-email-pmorel@linux.vnet.ibm.com>

Let's change Int128 definition to UInt128,
modify the internal element to uint64_t and
the arithmetic functions accordingly.

Signed-off-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 include/qemu/int128.h |   95 +++++++++++++++++++++++--------------------------
 1 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index fb782aa..c0465a2 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -5,64 +5,64 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-typedef struct Int128 Int128;
+typedef struct UInt128 UInt128;
 
-struct Int128 {
+struct UInt128 {
     uint64_t lo;
-    int64_t hi;
+    uint64_t hi;
 };
 
-static inline Int128 int128_make64(uint64_t a)
+static inline UInt128 uint128_from_64(uint64_t a)
 {
-    return (Int128) { a, 0 };
+    return (UInt128) { a, 0 };
 }
 
-static inline uint64_t int128_get64(Int128 a)
+static inline uint64_t uint128_to_64(UInt128 a)
 {
     assert(!a.hi);
     return a.lo;
 }
 
-static inline Int128 int128_zero(void)
+static inline UInt128 uint128_zero(void)
 {
-    return int128_make64(0);
+    return uint128_from_64(0);
 }
 
-static inline Int128 int128_one(void)
+static inline UInt128 uint128_one(void)
 {
-    return int128_make64(1);
+    return uint128_from_64(1);
 }
 
-static inline Int128 int128_2_64(void)
+static inline UInt128 uint128_2_64(void)
 {
-    return (Int128) { 0, 1 };
+    return (UInt128) { UINT64_MAX, 0 };
 }
 
-static inline Int128 int128_exts64(int64_t a)
+static inline UInt128 uint128_exts64(int64_t a)
 {
-    return (Int128) { .lo = a, .hi = (a < 0) ? -1 : 0 };
+    return (UInt128) { .lo = a, .hi = (a < 0) ? -1 : 0 };
 }
 
-static inline Int128 int128_and(Int128 a, Int128 b)
+static inline UInt128 uint128_and(UInt128 a, UInt128 b)
 {
-    return (Int128) { a.lo & b.lo, a.hi & b.hi };
+    return (UInt128) { a.lo & b.lo, a.hi & b.hi };
 }
 
-static inline Int128 int128_rshift(Int128 a, int n)
+static inline UInt128 uint128_rshift(UInt128 a, unsigned int n)
 {
-    int64_t h;
+    uint64_t h;
     if (!n) {
         return a;
     }
     h = a.hi >> (n & 63);
     if (n >= 64) {
-        return (Int128) { h, h >> 63 };
+        return (UInt128) { h, h >> 63 };
     } else {
-        return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
+        return (UInt128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
     }
 }
 
-static inline Int128 int128_add(Int128 a, Int128 b)
+static inline UInt128 uint128_add(UInt128 a, UInt128 b)
 {
     uint64_t lo = a.lo + b.lo;
 
@@ -72,78 +72,73 @@ 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 (UInt128) { lo, a.hi + b.hi + (lo < a.lo) };
 }
 
-static inline Int128 int128_neg(Int128 a)
+static inline UInt128 uint128_neg(UInt128 a)
 {
     uint64_t lo = -a.lo;
-    return (Int128) { lo, ~(uint64_t)a.hi + !lo };
+    return (UInt128) { lo, ~a.hi + !lo };
 }
 
-static inline Int128 int128_sub(Int128 a, Int128 b)
+static inline UInt128 uint128_sub(UInt128 a, UInt128 b)
 {
-    return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };
+    return (UInt128){ a.lo - b.lo, a.hi - b.hi - (a.lo < b.lo) };
 }
 
-static inline bool int128_nonneg(Int128 a)
-{
-    return a.hi >= 0;
-}
-
-static inline bool int128_eq(Int128 a, Int128 b)
+static inline bool uint128_eq(UInt128 a, UInt128 b)
 {
     return a.lo == b.lo && a.hi == b.hi;
 }
 
-static inline bool int128_ne(Int128 a, Int128 b)
+static inline bool uint128_ne(UInt128 a, UInt128 b)
 {
-    return !int128_eq(a, b);
+    return !uint128_eq(a, b);
 }
 
-static inline bool int128_ge(Int128 a, Int128 b)
+static inline bool uint128_ge(UInt128 a, UInt128 b)
 {
     return a.hi > b.hi || (a.hi == b.hi && a.lo >= b.lo);
 }
 
-static inline bool int128_lt(Int128 a, Int128 b)
+static inline bool uint128_lt(UInt128 a, UInt128 b)
 {
-    return !int128_ge(a, b);
+    return !uint128_ge(a, b);
 }
 
-static inline bool int128_le(Int128 a, Int128 b)
+static inline bool uint128_le(UInt128 a, UInt128 b)
 {
-    return int128_ge(b, a);
+    return uint128_ge(b, a);
 }
 
-static inline bool int128_gt(Int128 a, Int128 b)
+static inline bool uint128_gt(UInt128 a, UInt128 b)
 {
-    return !int128_le(a, b);
+    return !uint128_le(a, b);
 }
 
-static inline bool int128_nz(Int128 a)
+static inline bool uint128_nz(UInt128 a)
 {
     return a.lo || a.hi;
 }
 
-static inline Int128 int128_min(Int128 a, Int128 b)
+static inline UInt128 uint128_min(UInt128 a, UInt128 b)
 {
-    return int128_le(a, b) ? a : b;
+    return uint128_le(a, b) ? a : b;
 }
 
-static inline Int128 int128_max(Int128 a, Int128 b)
+static inline UInt128 uint128_max(UInt128 a, UInt128 b)
 {
-    return int128_ge(a, b) ? a : b;
+    return uint128_ge(a, b) ? a : b;
 }
 
-static inline void int128_addto(Int128 *a, Int128 b)
+static inline void uint128_addto(UInt128 *a, UInt128 b)
 {
-    *a = int128_add(*a, b);
+    *a = uint128_add(*a, b);
 }
 
-static inline void int128_subfrom(Int128 *a, Int128 b)
+static inline void uint128_subfrom(UInt128 *a, UInt128 b)
 {
-    *a = int128_sub(*a, b);
+    *a = uint128_sub(*a, b);
 }
 
 #endif
-- 
1.7.1

  reply	other threads:[~2015-11-05 16:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 16:18 [Qemu-devel] [PATCH 0/7] int128: reparing broken 128 bit memory calculations Pierre Morel
2015-11-05 16:18 ` Pierre Morel [this message]
2015-11-05 16:18 ` [Qemu-devel] [PATCH 2/7] memory: modify memory size for an unsigned 128bit int Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 3/7] 128bit: adapt core files for unsigned 128bits Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 4/7] 128bit: adapt sparc mmu_helper for UInt128 Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 5/7] 128bit: adapt VFIO for UInt128 arithmetic Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 6/7] 128bit: adapt Virtio " Pierre Morel
2015-11-05 16:18 ` [Qemu-devel] [PATCH 7/7] 128bits: some HW components use 128bit arithmetic Pierre Morel
2015-11-05 16:32 ` [Qemu-devel] [PATCH 0/7] int128: reparing broken 128 bit memory calculations Paolo Bonzini
2015-11-06  8:36   ` Pierre Morel
2015-11-06 16:33     ` Paolo Bonzini
     [not found]       ` <56408B28.8070408@linux.vnet.ibm.com>
2015-11-09 12:20         ` Paolo Bonzini
2015-11-10  9:08           ` Pierre Morel
2015-11-10 12:12             ` Pierre Morel

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=1446740339-31366-2-git-send-email-pmorel@linux.vnet.ibm.com \
    --to=pmorel@linux.vnet.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.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).