chiark / gitweb /
u64.h: Provide u64get{lo,hi} and u64not
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 Sep 2019 03:45:18 +0000 (04:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 2 Jan 2020 00:42:03 +0000 (00:42 +0000)
These are for the benefit of fake-mLib-bits.h.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
u64.h

diff --git a/u64.h b/u64.h
index 0d35c55428a8dcdf1444cdd5af8926337f78e1a0..25f4d0a64edcaa05d07bcd5f91991a1659681514 100644 (file)
--- a/u64.h
+++ b/u64.h
@@ -31,10 +31,13 @@ typedef uint64_t u64;
 # define u64hilo(hi, lo) ((u64) (((u64) (hi) << 32) + (lo)))
 # define u64init(hi, lo) u64hilo (hi, lo)
 # define u64lo(x) ((u64) (x))
+# define u64getlo(x) ((x)&0xffffffffu)
+# define u64gethi(x) (((u64) (x) >> 32) & 0xffffffffu)
 # define u64lt(x, y) ((x) < (y))
 # define u64and(x, y) ((x) & (y))
 # define u64or(x, y) ((x) | (y))
 # define u64xor(x, y) ((x) ^ (y))
+# define u64not(x) (~(x))
 # define u64plus(x, y) ((x) + (y))
 # define u64shl(x, n) ((x) << (n))
 # define u64shr(x, n) ((x) >> (n))
@@ -73,6 +76,10 @@ u64lo (uint32_t lo)
   return r;
 }
 
+/* Return the high and low halves of X. */
+# define u64getlo(x) ((x).lo)
+# define u64gethi(x) ((x).hi)
+
 /* Return X < Y.  */
 static inline int
 u64lt (u64 x, u64 y)
@@ -110,6 +117,16 @@ u64xor (u64 x, u64 y)
   return r;
 }
 
+/* Return ~X.  */
+static inline u64
+u64not (u64 x)
+{
+  u64 r;
+  r.hi = ~x.hi;
+  r.lo = ~x.lo;
+  return r;
+}
+
 /* Return X + Y.  */
 static inline u64
 u64plus (u64 x, u64 y)