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 <ch...@chris-wilson.co.uk> > Signed-off-by: Jani Nikula <jani.nik...@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 <ch...@chris-wilson.co.uk> -Chris