[Mesa-dev] [PATCH 19/56] glsl: Use find_msb_uint to implement ir_unop_find_lsb

Matt Turner mattst88 at gmail.com
Wed Jul 20 01:40:44 UTC 2016


On Tue, Jul 19, 2016 at 12:24 PM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> (X & -X) calculates a value with only the least significant bit of X
> set.  Since there is only one bit set, the LSB is the MSB.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/glsl/ir_constant_expression.cpp | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
> index 5f4cae2..71afb33 100644
> --- a/src/compiler/glsl/ir_constant_expression.cpp
> +++ b/src/compiler/glsl/ir_constant_expression.cpp
> @@ -1560,16 +1560,15 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
>
>     case ir_unop_find_lsb:
>        for (unsigned c = 0; c < components; c++) {
> -         if (op[0]->value.i[c] == 0)
> -            data.i[c] = -1;
> -         else {
> -            unsigned pos = 0;
> -            unsigned v = op[0]->value.u[c];
> -
> -            for (; !(v & 1); v >>= 1) {
> -               pos++;
> -            }
> -            data.u[c] = pos;
> +         switch (op[0]->type->base_type) {
> +         case GLSL_TYPE_UINT:
> +            data.i[c] = find_msb_uint(op[0]->value.u[c] & -int(op[0]->value.u[c]));

The int cast looks a bit weird (and unnecessary, right?)

I'd drop it unless there's a good reason to keep it.


More information about the mesa-dev mailing list