Messages in this thread | | | From | Chris Wilson <> | Subject | Re: [PATCH] log2: make is_power_of_2() integer constant expression when possible | Date | Fri, 01 Mar 2019 13:07:58 +0000 |
| |
Quoting Jani Nikula (2019-03-01 12:52:07) > While is_power_of_2() is an inline function and likely gets optimized > for compile time constant arguments, it still doesn't produce an integer > constant expression that could be used in, say, static data > initialization or case labels. > > Make is_power_of_2() an integer constant expression when possible, > otherwise using the inline function to avoid multiple evaluation of the > parameter. > > Cc: Chris Wilson <chris@chris-wilson.co.uk> > Signed-off-by: Jani Nikula <jani.nikula@intel.com>
It does what it says on the tin and allows for
static const is_pot = is_power_of_two(32);
or in the actual case of interest,
BUILD_BUG_ON(is_power_of_two(x) ? test1(x) : test2(x)).
The only question remains can build_bug.h include ilog2.h and use this macro instead of having its own copy? Or that may be overkill for a single commonplace macro.
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> -Chris
| |