[Mesa-dev] [PATCH 05/10] nir: Use well-known power-of-two test instead of util_bitscan

Matt Turner mattst88 at gmail.com
Fri Nov 10 22:54:07 UTC 2017


On Fri, Nov 10, 2017 at 2:32 PM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> This prevents the next change from breaking the build, and I felt that
> it was different enough from the rest of that patch to stand on its own.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/nir/nir_validate.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
> index 9bf8c70..ca191d2 100644
> --- a/src/compiler/nir/nir_validate.c
> +++ b/src/compiler/nir/nir_validate.c
> @@ -979,8 +979,9 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state)
>
>     validate_assert(state, is_global == nir_variable_is_global(var));
>
> -   /* Must have exactly one mode set */
> -   validate_assert(state, util_bitcount(var->data.mode) == 1);
> +   /* Must have exactly one mode set (i.e., is a power of two) */
> +   validate_assert(state, (var->data.mode != 0 &&
> +                           !(var->data.mode & (var->data.mode - 1))));

We actually have two functions in Mesa for this: util_is_power_of_two
and _mesa_is_pow_two. Not sure which one is available to this code,
but assuming one is, we should use it.


More information about the mesa-dev mailing list