summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2016-07-12 18:07:51 -0700
committerIan Romanick <[email protected]>2016-08-30 16:28:01 -0700
commitfe153309a81e2ef3b46d76306053fec9bcba508e (patch)
treef9033b388e4b108f1b9155be4150060f49aabf31
parent54ec6e1b8b65004f3aa2acd3eb45b849d24ad8f6 (diff)
glsl: Extract ir_triop_bitfield_extract implementation to a separate function
Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
-rw-r--r--src/compiler/glsl/ir_constant_expression.cpp66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index 442db760045..d415b5d448c 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -537,6 +537,38 @@ ldexp_flush_subnormal(double x, int exp)
return !isnormal(result) ? copysign(0.0, x) : result;
}
+static uint32_t
+bitfield_extract_uint(uint32_t value, int offset, int bits)
+{
+ if (bits == 0)
+ return 0;
+ else if (offset < 0 || bits < 0)
+ return 0; /* Undefined, per spec. */
+ else if (offset + bits > 32)
+ return 0; /* Undefined, per spec. */
+ else {
+ value <<= 32 - bits - offset;
+ value >>= 32 - bits;
+ return value;
+ }
+}
+
+static int32_t
+bitfield_extract_int(int32_t value, int offset, int bits)
+{
+ if (bits == 0)
+ return 0;
+ else if (offset < 0 || bits < 0)
+ return 0; /* Undefined, per spec. */
+ else if (offset + bits > 32)
+ return 0; /* Undefined, per spec. */
+ else {
+ value <<= 32 - bits - offset;
+ value >>= 32 - bits;
+ return value;
+ }
+}
+
ir_constant *
ir_expression::constant_expression_value(struct hash_table *variable_context)
{
@@ -1605,34 +1637,20 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
memcpy(&data.u[0], &op[0]->value.d[0], sizeof(double));
break;
- case ir_triop_bitfield_extract: {
+ case ir_triop_bitfield_extract:
for (unsigned c = 0; c < components; c++) {
- int offset = op[1]->value.i[c];
- int bits = op[2]->value.i[c];
-
- if (bits == 0)
- data.u[c] = 0;
- else if (offset < 0 || bits < 0)
- data.u[c] = 0; /* Undefined, per spec. */
- else if (offset + bits > 32)
- data.u[c] = 0; /* Undefined, per spec. */
- else {
- if (op[0]->type->base_type == GLSL_TYPE_INT) {
- /* int so that the right shift will sign-extend. */
- int value = op[0]->value.i[c];
- value <<= 32 - bits - offset;
- value >>= 32 - bits;
- data.i[c] = value;
- } else {
- unsigned value = op[0]->value.u[c];
- value <<= 32 - bits - offset;
- value >>= 32 - bits;
- data.u[c] = value;
- }
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = bitfield_extract_uint(op[0]->value.u[c], op[1]->value.i[c], op[2]->value.i[c]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = bitfield_extract_int(op[0]->value.i[c], op[1]->value.i[c], op[2]->value.i[c]);
+ break;
+ default:
+ assert(0);
}
}
break;
- }
case ir_binop_ldexp:
for (unsigned c = 0; c < op[0]->type->components(); c++) {