[Mesa-dev] [PATCH v2 05/11] glsl: Optimize log(x) + log(y) == log(x*y)

thomashelland90 at gmail.com thomashelland90 at gmail.com
Thu Aug 7 13:51:06 PDT 2014


From: Thomas Helland <thomashelland90 at gmail.com>

And the log2() equivalent.

v1 -> v2: Correct trailing whitespace

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 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 42a70e3..141b930 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.3



More information about the mesa-dev mailing list