[Mesa-dev] [PATCH v2 07/11] glsl: Optimize some more pow() special cases

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


From: Thomas Helland <thomashelland90 at gmail.com>

Specifically x^-1 = rcp(x)
.            0^x  = 0
.            x^0  = 1

v1 -> v2: Correct indentation

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 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 0e21ff8..0ecadbe 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -656,6 +656,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.3



More information about the mesa-dev mailing list