[Mesa-dev] [PATCH 08/10] glsl: Optimize exp(x)*exp(y) == exp(x+y)

thomashelland90 at gmail.com thomashelland90 at gmail.com
Mon Jul 14 15:22:37 PDT 2014


From: Thomas Helland <thomashelland90 at gmail.com>

And it's exp2() equivalent.

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
 src/glsl/opt_algebraic.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index e2abf5f..2361d0f 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -470,6 +470,17 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       if (is_vec_negative_one(op_const[1]))
          return neg(ir->operands[0]);
 
+      if (op_expr[0] && op_expr[1]) {
+         /* exp(x) * exp(y) == exp(x+y) */
+         if (op_expr[0]->operation == ir_unop_exp &&
+             op_expr[1]->operation == ir_unop_exp)
+            return exp(add(op_expr[0]->operands[0], op_expr[1]->operands[0]));
+         /* exp2(x) * exp2(y) == exp2(x+y) */
+         if (op_expr[0]->operation == ir_unop_exp2 &&
+             op_expr[1]->operation == ir_unop_exp2)
+            return new (mem_ctx) ir_expression(ir_unop_exp2,
+                   add(op_expr[0]->operands[0], op_expr[1]->operands[0]));
+      }
 
       /* Reassociate multiplication of constants so that we can do
        * constant folding.
-- 
2.0.0



More information about the mesa-dev mailing list