[Mesa-dev] [PATCH 06/11] glsl: Optimize exp(x) * exp(y) == exp(x*y)
thomashelland90 at gmail.com
thomashelland90 at gmail.com
Thu Aug 7 13:51:07 PDT 2014
From: Thomas Helland <thomashelland90 at gmail.com>
And it's exp2() equivalent.
Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
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 141b930..0e21ff8 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.3
More information about the mesa-dev
mailing list