[Mesa-dev] [PATCH 11/16] glsl: Add ir_binop_pow to get_range

Thomas Helland thomashelland90 at gmail.com
Sun Nov 16 17:51:56 PST 2014


The spec states that pow is undefined for x < 0.
Just set the range to correspond to a constant 0
if this is the case.
---
 src/glsl/opt_minmax.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index 9852dd9..ad8c88a 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -335,6 +335,17 @@ get_range(ir_rvalue *rval)
             high = add(r0.high, r1.high)->constant_expression_value();
          return minmax_range(low, high);
 
+      case ir_binop_pow:
+         r0 = get_range(expr->operands[0]);
+         if (is_greater_than_or_equal_zero(r0.low))
+            low = new(mem_ctx) ir_constant(0.0f);
+         // Result is undefined so we can set the range to bikeshed.
+         if (is_less_than_zero(r0.high)) {
+            low = new(mem_ctx) ir_constant(0.0f);
+            high = new(mem_ctx) ir_constant(0.0f);
+         }
+         return minmax_range(low, high);
+
       default:
          break;
       }
-- 
2.0.3



More information about the mesa-dev mailing list