X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=include%2Flinux%2Flog2.h;h=99922bedfcc90acaef644369aee3d5e126b7d46d;hb=5986a2ec35836a878350c54af4bd91b1de6abc59;hp=d02e1a547a7e9deb1e8bc21857780bdc2c7693c0;hpb=13d7d84e078f49f08b657a3fba0d7a0b7b44ba65;p=linux-2.6 diff --git a/include/linux/log2.h b/include/linux/log2.h index d02e1a547a..99922bedfc 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -43,6 +43,17 @@ int __ilog2_u64(u64 n) } #endif +/* + * Determine whether some value is a power of two, where zero is + * *not* considered a power of two. + */ + +static inline __attribute__((const)) +bool is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + /* * round up to nearest power of two */