From: Ben Pfaff Date: Thu, 1 Nov 2012 00:12:38 +0000 (-0700) Subject: util: Group functions for bitwise tests. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=openvswitch;a=commitdiff_plain;h=fe9d0898828728fc6ce4667527c21beb8fa25ac2 util: Group functions for bitwise tests. This only moves code around for more logical grouping. Signed-off-by: Ben Pfaff --- diff --git a/lib/util.h b/lib/util.h index a1f4bd74..c087b53f 100644 --- a/lib/util.h +++ b/lib/util.h @@ -96,22 +96,6 @@ is_pow2(uintmax_t x) return IS_POW2(x); } -/* Returns the rightmost 1-bit in 'x' (e.g. 01011000 => 00001000), or 0 if 'x' - * is 0. */ -static inline uintmax_t -rightmost_1bit(uintmax_t x) -{ - return x & -x; -} - -/* Returns 'x' with its rightmost 1-bit changed to a zero (e.g. 01011000 => - * 01010000), or 0 if 'x' is 0. */ -static inline uintmax_t -zero_rightmost_1bit(uintmax_t x) -{ - return x & (x - 1); -} - #ifndef MIN #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #endif @@ -242,6 +226,8 @@ char *xreadlink(const char *filename); char *follow_symlinks(const char *filename); void ignore(bool x OVS_UNUSED); + +/* Bitwise tests. */ /* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. * @@ -270,6 +256,22 @@ int log_2_floor(uint32_t); int log_2_ceil(uint32_t); int popcount(uint32_t); +/* Returns the rightmost 1-bit in 'x' (e.g. 01011000 => 00001000), or 0 if 'x' + * is 0. */ +static inline uintmax_t +rightmost_1bit(uintmax_t x) +{ + return x & -x; +} + +/* Returns 'x' with its rightmost 1-bit changed to a zero (e.g. 01011000 => + * 01010000), or 0 if 'x' is 0. */ +static inline uintmax_t +zero_rightmost_1bit(uintmax_t x) +{ + return x & (x - 1); +} + bool is_all_zeros(const uint8_t *, size_t); bool is_all_ones(const uint8_t *, size_t); void bitwise_copy(const void *src, unsigned int src_len, unsigned int src_ofs,