summaryrefslogtreecommitdiff
path: root/src/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-07-21 20:09:21 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-07-28 15:46:28 -0700
commitffcec135997545b4dc2b3393ccb02558083373a0 (patch)
tree87bbe7efa0b243a271f471afe312beaa848efd8c /src/glsl/ir_constant_expression.cpp
parent4b1d77ea966771dc5fbdac90dfec1b6066afe3f8 (diff)
ir_constant_expression: Extract dot product calculation for reuse.
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r--src/glsl/ir_constant_expression.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 799bd4a60b..c4a416aa35 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -39,6 +39,18 @@
#include "ir_visitor.h"
#include "glsl_types.h"
+static float
+dot(ir_constant *op0, ir_constant *op1)
+{
+ assert(op0->type->is_float() && op1->type->is_float());
+
+ float result = 0;
+ for (unsigned c = 0; c < op0->type->components(); c++)
+ result += op0->value.f[c] * op1->value.f[c];
+
+ return result;
+}
+
ir_constant *
ir_expression::constant_expression_value()
{
@@ -326,14 +338,9 @@ ir_expression::constant_expression_value()
break;
case ir_binop_dot:
- assert(op[0]->type->is_vector() && op[1]->type->is_vector());
- assert(op[0]->type->is_float() && op[1]->type->is_float());
- data.f[0] = 0;
- for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[0] += op[0]->value.f[c] * op[1]->value.f[c];
- }
-
+ data.f[0] = dot(op[0], op[1]);
break;
+
case ir_binop_min:
assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
for (unsigned c = 0, c0 = 0, c1 = 0;