[Mesa-dev] [PATCH 18/22] glsl: Add ir_unop_rcp to get_range

Thomas Helland thomashelland90 at gmail.com
Sat Jan 3 11:18:23 PST 2015


V2: Put in alphabetic order
    Rework to use new IS_CONSTANT macro
    Reduce code duplication by combining pos only and neg only variation
---
 src/glsl/opt_minmax.cpp | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index 0901c95..0bfa340 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -410,6 +410,35 @@ get_range(ir_rvalue *rval)
 
          return minmax_range(low, high);
 
+      case ir_unop_rcp:
+         r0 = get_range(expr->operands[0]);
+
+         // If operand is guaranteed positive only or negative only
+         // then high = 1/low and low = 1/high
+         if (IS_CONSTANT(r0.low, >, 0.0f) ||
+             (IS_CONSTANT(r0.low, <, 0.0f) && IS_CONSTANT(r0.high, <, 0.0f))) {
+            ir_expression *h = new(mem_ctx) ir_expression(ir_unop_rcp, r0.low);
+            high = h->constant_expression_value();
+            if (r0.high) {
+               ir_expression *l =
+                     new(mem_ctx) ir_expression(ir_unop_rcp, r0.high);
+               low = l->constant_expression_value();
+            }
+         }
+
+         // If low range is negative and high range is positive
+         // then low = 1/low and high = 1/high
+         if (IS_CONSTANT(r0.low, <, 0.0f) && IS_CONSTANT(r0.high, >, 0.0f)) {
+            ir_expression *h =
+                  new(mem_ctx) ir_expression(ir_unop_rcp, r0.high);
+            high = h->constant_expression_value();
+            ir_expression *l =
+                  new(mem_ctx) ir_expression(ir_unop_rcp, r0.low);
+            low = l->constant_expression_value();
+         }
+
+         return minmax_range(low, high);
+
       case ir_unop_saturate:
          r0 = minmax_range(new(mem_ctx) ir_constant(0.0f),
                            new(mem_ctx) ir_constant(1.0f));
-- 
2.2.1



More information about the mesa-dev mailing list