ir_constant_expression: Add support for ir_unop_sign.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 9 Jul 2010 06:11:14 +0000 (23:11 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 14 Jul 2010 22:50:27 +0000 (15:50 -0700)
src/glsl/ir_constant_expression.cpp

index 06d7dd8..5ba6264 100644 (file)
@@ -262,6 +262,24 @@ ir_constant_visitor::visit(ir_expression *ir)
       }
       break;
 
+   case ir_unop_sign:
+      for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) {
+        switch (ir->type->base_type) {
+        case GLSL_TYPE_UINT:
+           data.u[c] = op[0]->value.i[c] > 0;
+           break;
+        case GLSL_TYPE_INT:
+           data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0);
+           break;
+        case GLSL_TYPE_FLOAT:
+           data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0));
+           break;
+        default:
+           assert(0);
+        }
+      }
+      break;
+
    case ir_unop_rcp:
       assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
       for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) {