glsl: Add constant evaluation of ir_binop_bfm.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Matt Turner 2014-01-23 15:39:43 -08:00
parent c59a605c70
commit 3ea64f9093
1 changed files with 17 additions and 0 deletions

View File

@ -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. */
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]);