Re: [PATCH] log2: make is_power_of_2() integer constant expression when possible
From: Chris Wilson
Date: Fri Mar 01 2019 - 08:08:19 EST
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@xxxxxxxxxxxxxxxxxx>
> Signed-off-by: Jani Nikula <jani.nikula@xxxxxxxxx>
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@xxxxxxxxxxxxxxxxxx>
-Chris