summaryrefslogtreecommitdiff
path: root/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-04-01 18:35:42 -1000
committerIan Romanick <ian.d.romanick@intel.com>2010-04-02 11:22:41 -0700
commitd251b92f8d32b28a91085d5b1f557c1f4756a2f2 (patch)
tree03883caf50ace10c25c283a89d5d00f6ee76539c /ir_constant_expression.cpp
parentd98da9738ee791edae5ee6650e7a3ac08b6c26ca (diff)
Add some more operations to ir_constant_expression.cpp.
Diffstat (limited to 'ir_constant_expression.cpp')
-rw-r--r--ir_constant_expression.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp
index e8820a0f87..69a3613080 100644
--- a/ir_constant_expression.cpp
+++ b/ir_constant_expression.cpp
@@ -153,6 +153,46 @@ ir_constant_visitor::visit(ir_expression *ir)
for (c = 0; c < ir->operands[0]->type->components(); c++)
b[c] = !op[0]->value.b[c];
break;
+ case ir_binop_add:
+ if (ir->operands[0]->type == ir->operands[1]->type) {
+ type = ir->operands[0]->type;
+ for (c = 0; c < ir->operands[0]->type->components(); c++) {
+ switch (ir->operands[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ u[c] = op[0]->value.u[c] + op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ i[c] = op[0]->value.i[c] + op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ f[c] = op[0]->value.f[c] + op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ break;
+ case ir_binop_sub:
+ if (ir->operands[0]->type == ir->operands[1]->type) {
+ type = ir->operands[0]->type;
+ for (c = 0; c < ir->operands[0]->type->components(); c++) {
+ switch (ir->operands[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ u[c] = op[0]->value.u[c] - op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ i[c] = op[0]->value.i[c] - op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ f[c] = op[0]->value.f[c] - op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ break;
case ir_binop_mul:
if (ir->operands[0]->type == ir->operands[1]->type &&
!ir->operands[0]->type->is_matrix()) {
@@ -174,12 +214,38 @@ ir_constant_visitor::visit(ir_expression *ir)
}
}
break;
+ case ir_binop_div:
+ if (ir->operands[0]->type == ir->operands[1]->type) {
+ type = ir->operands[0]->type;
+ for (c = 0; c < ir->operands[0]->type->components(); c++) {
+ switch (ir->operands[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ u[c] = op[0]->value.u[c] / op[1]->value.u[c];
+ break;
+ case GLSL_TYPE_INT:
+ i[c] = op[0]->value.i[c] / op[1]->value.i[c];
+ break;
+ case GLSL_TYPE_FLOAT:
+ f[c] = op[0]->value.f[c] / op[1]->value.f[c];
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ break;
case ir_binop_logic_and:
type = ir->operands[0]->type;
assert(type->base_type == GLSL_TYPE_BOOL);
for (c = 0; c < ir->operands[0]->type->components(); c++)
b[c] = op[0]->value.b[c] && op[1]->value.b[c];
break;
+ case ir_binop_logic_xor:
+ type = ir->operands[0]->type;
+ assert(type->base_type == GLSL_TYPE_BOOL);
+ for (c = 0; c < ir->operands[0]->type->components(); c++)
+ b[c] = op[0]->value.b[c] ^ op[1]->value.b[c];
+ break;
case ir_binop_logic_or:
type = ir->operands[0]->type;
assert(type->base_type == GLSL_TYPE_BOOL);