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

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


From: Thomas Helland <thomashelland90 at gmail.com>

And the log2() equivalent.

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

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index deaa49e..e2abf5f 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -380,6 +380,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
             return expr;
       }
 
+      /* log(x) + log(y) == log(x*y) */
+      if (op_expr[0] && op_expr[0]->operation == ir_unop_log && 
+          op_expr[1] && op_expr[1]->operation == ir_unop_log)
+         return new(mem_ctx) ir_expression(
+            ir_unop_log, mul(op_expr[0]->operands[0], op_expr[1]->operands[0]) );
+
+      /* log2(x) + log2(y) == log2(x*y) */
+      if (op_expr[0] && op_expr[0]->operation == ir_unop_log2 && 
+          op_expr[1] && op_expr[1]->operation == ir_unop_log2)
+         return new(mem_ctx) ir_expression(
+            ir_unop_log2, mul(op_expr[0]->operands[0], op_expr[1]->operands[0]) );
+
       /* Replace (-x + y) * a + x and commutative variations with lrp(x, y, a).
        *
        * (-x + y) * a + x
-- 
2.0.0



More information about the mesa-dev mailing list