X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fu64.h;h=af8441f52e57cb3dea9b57ffc7feaba7be81a924;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=9da52b438ef9d43fdd519cd5a331700cf3dc2afe;hpb=3030c5b5e0a5199e16b05927da72c43c42f211c3;p=gnulib.git diff --git a/lib/u64.h b/lib/u64.h index 9da52b438..af8441f52 100644 --- a/lib/u64.h +++ b/lib/u64.h @@ -1,6 +1,6 @@ /* uint64_t-like operations that work even on hosts lacking uint64_t - Copyright (C) 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2006, 2009-2013 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 @@ -17,9 +17,16 @@ /* Written by Paul Eggert. */ -#include #include +#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)) @@ -31,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)) @@ -54,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; @@ -64,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; @@ -73,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; @@ -91,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; @@ -101,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; @@ -111,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; @@ -121,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; @@ -139,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; @@ -157,3 +175,5 @@ u64shr (u64 x, int n) } #endif + +_GL_INLINE_HEADER_END