[Mesa-dev] [PATCH 1/2] glsl: Add constant evaluation of ir_binop_bfm.

Ian Romanick idr at freedesktop.org
Mon Jan 27 14:15:22 PST 2014


On 01/27/2014 01:02 PM, Matt Turner wrote:
> ---
>  src/glsl/ir_constant_expression.cpp | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
> index f811fd1..7fa5a09 100644
> --- a/src/glsl/ir_constant_expression.cpp
> +++ b/src/glsl/ir_constant_expression.cpp
> @@ -1397,6 +1397,23 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
>        break;
>     }
>  
> +   case ir_binop_bfm: {
> +      int bits = op[0]->value.i[0];
> +      int offset = op[1]->value.i[0];
> +
> +      for (unsigned c = 0; c < components; c++) {
> +         if (bits == 0)
> +            data.u[c] = op[0]->value.u[c];
> +         else if (offset < 0 || bits < 0)
> +            data.u[c] = 0; /* Undefined for bitfieldInsert, per spec. */
> +         else if (offset + bits > 32)
> +            data.u[c] = 0; /* Undefined for bitfieldInsert, per spec. */

In the front end we ought to generate a warning.  That would obviously
be a separate patch.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> +         else
> +            data.u[c] = ((1 << bits) - 1) << offset;
> +      }
> +      break;
> +   }
> +
>     case ir_binop_ldexp:
>        for (unsigned c = 0; c < components; c++) {
>           data.f[c] = ldexp(op[0]->value.f[c], op[1]->value.i[c]);
> 



More information about the mesa-dev mailing list