summaryrefslogtreecommitdiff
path: root/lib/u64.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/u64.h')
-rw-r--r--lib/u64.h53
1 files changed, 36 insertions, 17 deletions
diff --git a/lib/u64.h b/lib/u64.h
index 1d581ec..1ece978 100644
--- a/lib/u64.h
+++ b/lib/u64.h
@@ -1,11 +1,11 @@
/* uint64_t-like operations that work even on hosts lacking uint64_t
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009-2016 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,14 +13,20 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert. */
-#include <stddef.h>
#include <stdint.h>
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_U64_INLINE
+# define _GL_U64_INLINE _GL_INLINE
+#endif
+
/* Return X rotated left by N bits, where 0 < N < 64. */
#define u64rol(x, n) u64or (u64shl (x, n), u64shr (x, 64 - n))
@@ -32,6 +38,7 @@ 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 u64size(x) u64lo (x)
# define u64lt(x, y) ((x) < (y))
# define u64and(x, y) ((x) & (y))
# define u64or(x, y) ((x) | (y))
@@ -55,7 +62,7 @@ typedef struct { uint32_t lo, hi; } u64;
/* Given the high and low-order 32-bit quantities HI and LO, return a u64
value representing (HI << 32) + LO. */
-static inline u64
+_GL_U64_INLINE u64
u64hilo (uint32_t hi, uint32_t lo)
{
u64 r;
@@ -65,7 +72,7 @@ u64hilo (uint32_t hi, uint32_t lo)
}
/* Return a u64 value representing LO. */
-static inline u64
+_GL_U64_INLINE u64
u64lo (uint32_t lo)
{
u64 r;
@@ -74,15 +81,25 @@ u64lo (uint32_t lo)
return r;
}
+/* Return a u64 value representing SIZE. */
+_GL_U64_INLINE u64
+u64size (size_t size)
+{
+ u64 r;
+ r.hi = size >> 31 >> 1;
+ r.lo = size;
+ return r;
+}
+
/* Return X < Y. */
-static inline int
+_GL_U64_INLINE int
u64lt (u64 x, u64 y)
{
return x.hi < y.hi || (x.hi == y.hi && x.lo < y.lo);
}
/* Return X & Y. */
-static inline u64
+_GL_U64_INLINE u64
u64and (u64 x, u64 y)
{
u64 r;
@@ -92,7 +109,7 @@ u64and (u64 x, u64 y)
}
/* Return X | Y. */
-static inline u64
+_GL_U64_INLINE u64
u64or (u64 x, u64 y)
{
u64 r;
@@ -102,7 +119,7 @@ u64or (u64 x, u64 y)
}
/* Return X ^ Y. */
-static inline u64
+_GL_U64_INLINE u64
u64xor (u64 x, u64 y)
{
u64 r;
@@ -112,7 +129,7 @@ u64xor (u64 x, u64 y)
}
/* Return X + Y. */
-static inline u64
+_GL_U64_INLINE u64
u64plus (u64 x, u64 y)
{
u64 r;
@@ -122,7 +139,7 @@ u64plus (u64 x, u64 y)
}
/* Return X << N. */
-static inline u64
+_GL_U64_INLINE u64
u64shl (u64 x, int n)
{
u64 r;
@@ -140,7 +157,7 @@ u64shl (u64 x, int n)
}
/* Return X >> N. */
-static inline u64
+_GL_U64_INLINE u64
u64shr (u64 x, int n)
{
u64 r;
@@ -158,3 +175,5 @@ u64shr (u64 x, int n)
}
#endif
+
+_GL_INLINE_HEADER_END