diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-27 09:50:26 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-31 08:53:04 +0200 |
commit | 62c1a1b5b238f27e589ef45c648e5229e19224ad (patch) | |
tree | 241d68905e2d96b5ea2fc1517ac76e9f77d5090a /shared | |
parent | d550eef02d8ff9a94cb57ba90cd0edeebc6e3f1f (diff) | |
download | NetworkManager-62c1a1b5b238f27e589ef45c648e5229e19224ad.tar.gz |
shared: move nm_utils_is_power_of_two() to nm-stdaux and add nm_utils_is_power_of_two_or_zero()
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 10 | ||||
-rw-r--r-- | shared/nm-std-aux/nm-std-aux.h | 21 |
2 files changed, 21 insertions, 10 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index a8a5360548..551cd92f16 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1017,16 +1017,6 @@ nm_g_variant_take_ref (GVariant *v) /*****************************************************************************/ -/* Determine whether @x is a power of two (@x being an integer type). - * Basically, this returns TRUE, if @x has exactly one bit set. - * For negative values and zero, this always returns FALSE. */ -#define nm_utils_is_power_of_two(x) ({ \ - typeof(x) __x = (x); \ - \ - ( (__x > ((typeof(__x)) 0)) \ - && ((__x & (__x - (((typeof(__x)) 1)))) == ((typeof(__x)) 0))); \ - }) - #define NM_DIV_ROUND_UP(x, y) \ ({ \ const typeof(x) _x = (x); \ diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h index 01409cefbb..b3f80bbd65 100644 --- a/shared/nm-std-aux/nm-std-aux.h +++ b/shared/nm-std-aux/nm-std-aux.h @@ -193,6 +193,27 @@ ((_A) > (_B)) ? (_A) : (_B), \ ((void) 0))) +/* Determine whether @x is a power of two (@x being an integer type). + * Basically, this returns TRUE, if @x has exactly one bit set. + * For negative values and zero, this always returns FALSE. */ +#define nm_utils_is_power_of_two(x) \ + ({ \ + typeof(x) _x2 = (x); \ + const typeof(_x2) _X_0 = ((typeof(_x2)) 0); \ + const typeof(_x2) _X_1 = ((typeof(_x2)) 1); \ + \ + ( (_x2 > _X_0) \ + && ((_x2 & (_x2 - _X_1)) == _X_0)); \ + }) + +#define nm_utils_is_power_of_two_or_zero(x) \ + ({ \ + typeof (x) _x1 = (x); \ + \ + ( (_x1 == 0) \ + || nm_utils_is_power_of_two (_x1)); \ + }) + /*****************************************************************************/ #define NM_SWAP(a, b) \ |