Mesa (master): glsl: Implement constant expr evaluation for bitwise logic ops

Kenneth Graunke kwg at kemper.freedesktop.org
Fri Oct 15 07:20:51 UTC 2010


Module: Mesa
Branch: master
Commit: 4761d0d22ba79fa34adf679007498287e9fedca2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4761d0d22ba79fa34adf679007498287e9fedca2

Author: Chad Versace <chad at chad-versace.us>
Date:   Sat Oct  9 21:27:41 2010 -0700

glsl: Implement constant expr evaluation for bitwise logic ops

Implement by adding the following cases to
ir_exporession::constant_expression_value():
    - ir_binop_bit_and
    - ir_binop_bit_or
    - ir_binop_bit_xor

---

 src/glsl/ir_constant_expression.cpp |   54 +++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index b250a16..048c020 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -728,6 +728,60 @@ ir_expression::constant_expression_value()
        }
        break;
 
+   case ir_binop_bit_and:
+      for (unsigned c = 0, c0 = 0, c1 = 0;
+           c < components;
+           c0 += c0_inc, c1 += c1_inc, c++) {
+
+          switch (op[0]->type->base_type) {
+          case GLSL_TYPE_INT:
+              data.i[c] = op[0]->value.i[c0] & op[1]->value.i[c1];
+              break;
+          case GLSL_TYPE_UINT:
+              data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1];
+              break;
+          default:
+              assert(0);
+          }
+      }
+      break;
+
+   case ir_binop_bit_or:
+      for (unsigned c = 0, c0 = 0, c1 = 0;
+           c < components;
+           c0 += c0_inc, c1 += c1_inc, c++) {
+
+          switch (op[0]->type->base_type) {
+          case GLSL_TYPE_INT:
+              data.i[c] = op[0]->value.i[c0] | op[1]->value.i[c1];
+              break;
+          case GLSL_TYPE_UINT:
+              data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1];
+              break;
+          default:
+              assert(0);
+          }
+      }
+      break;
+
+   case ir_binop_bit_xor:
+      for (unsigned c = 0, c0 = 0, c1 = 0;
+           c < components;
+           c0 += c0_inc, c1 += c1_inc, c++) {
+
+          switch (op[0]->type->base_type) {
+          case GLSL_TYPE_INT:
+              data.i[c] = op[0]->value.i[c0] ^ op[1]->value.i[c1];
+              break;
+          case GLSL_TYPE_UINT:
+              data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1];
+              break;
+          default:
+              assert(0);
+          }
+      }
+      break;
+
    default:
       /* FINISHME: Should handle all expression types. */
       return NULL;




More information about the mesa-commit mailing list