summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2016-07-12 17:40:48 -0700
committerIan Romanick <[email protected]>2016-08-30 16:28:01 -0700
commit6d5fe1815c96b849aaf08f31c11d9ad4fe2b4769 (patch)
tree69ec322fda71fccbac55c4d79782874be33a215a /src/compiler/glsl/ir_constant_expression.cpp
parent5c24750a49b7c39f35600b25ece05f908d59f170 (diff)
glsl: Use find_msb_uint to implement ir_unop_find_lsb
(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. v2: Remove extra int() cast. Suggested by Matt. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/compiler/glsl/ir_constant_expression.cpp')
-rw-r--r--src/compiler/glsl/ir_constant_expression.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index 5376316d5df..a032ac6d4d5 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] & -op[0]->value.u[c]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = find_msb_uint(op[0]->value.i[c] & -op[0]->value.i[c]);
+ break;
+ default:
+ assert(0);
}
}
break;