[Mesa-dev] [PATCH 12/16] glsl: Add log and log2 to get_range

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


The spec states that log / log2 of x <= 0 is undefined.
Just set the range to 0 if this is the case.
---
 src/glsl/opt_minmax.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index ad8c88a..0638a12 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -346,6 +346,20 @@ get_range(ir_rvalue *rval)
          }
          return minmax_range(low, high);
 
+      case ir_unop_log:
+      case ir_unop_log2:
+         r0 = get_range(expr->operands[0]);
+         if (is_greater_than_or_equal_one(r0.low))
+            low = new(mem_ctx) ir_constant(0.0f);
+         if (is_less_than_or_equal_one(r0.high))
+            high = new(mem_ctx) ir_constant(0.0f);
+         // Result is undefined, so we can set the range to whatever
+         if (is_less_than_or_equal_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