[Mesa-dev] [PATCH 10/10] glsl: Optimize some more pow() special cases
thomashelland90 at gmail.com
thomashelland90 at gmail.com
Mon Jul 14 15:22:39 PDT 2014
From: Thomas Helland <thomashelland90 at gmail.com>
Specifically x^-1 = rcp(x)
. 0^x = 0
. x^0 = 1
Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
src/glsl/opt_algebraic.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index fba9de6..1382067 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -662,6 +662,21 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
if (is_vec_one(op_const[1]))
return ir->operands[0];
+ /* x^-1 == rcp(x) */
+ if (is_vec_negative_one(op_const[1]))
+ return new(mem_ctx) ir_expression(ir_unop_rcp,
+ ir->operands[0]->type,
+ ir->operands[0],
+ NULL);
+
+ /* 0^x == 0 */
+ if (is_vec_zero(op_const[0]))
+ return ir_constant::zero(ir, ir->type);
+
+ /* x^0 == 1 */
+ if (is_vec_zero(op_const[1]))
+ return new(mem_ctx) ir_constant(1.0f, 1);
+
/* pow(2,x) == exp2(x) */
if (is_vec_two(op_const[0]))
return expr(ir_unop_exp2, ir->operands[1]);
--
2.0.0
More information about the mesa-dev
mailing list