On 08/13/2014 01:59 AM, Dylan Baker wrote:
On Tuesday, July 29, 2014 12:36:39 PM Petri Latvala wrote:
tests/minmax/create_test_cases.py generates the following tests:

multiple_min*.opt_test:
  Construct a tree of min expressions for all permutations of a var_ref
  and three constants. They should all optimize to a single min with
  the variable and the smallest constant.
multiple_max*.opt_test:
  Same as above, for max.
mid3opt*.opt_test:
  Test that code generated from a mid3() for two constants and a
  var_ref optimizes to a single max and a single min.
mixed_vectors*.opt_test:
  Test that the optimization pass doesn't modify expression trees with
  constant vectors where some components compare as less, some as
  greater.

Signed-off-by: Petri Latvala <petri.latv...@intel.com>
---
  src/glsl/tests/minmax/.gitignore           |   3 +
  src/glsl/tests/minmax/create_test_cases.py | 151 +++++++++++++++++++++++++++++
  2 files changed, 154 insertions(+)
  create mode 100644 src/glsl/tests/minmax/.gitignore
  create mode 100644 src/glsl/tests/minmax/create_test_cases.py

diff --git a/src/glsl/tests/minmax/.gitignore b/src/glsl/tests/minmax/.gitignore
new file mode 100644
index 0000000..e98df62
--- /dev/null
+++ b/src/glsl/tests/minmax/.gitignore
@@ -0,0 +1,3 @@
+*.opt_test
+*.expected
+*.out
diff --git a/src/glsl/tests/minmax/create_test_cases.py 
b/src/glsl/tests/minmax/create_test_cases.py
new file mode 100644
index 0000000..4f78980
--- /dev/null
+++ b/src/glsl/tests/minmax/create_test_cases.py
@@ -0,0 +1,151 @@
+# coding=utf-8
+#
+# Copyright © 2014 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+import os
+import os.path
+import re
+import subprocess
+import sys
+import itertools
This comment applies to all the patches.
You're importing a bunch of modules you're not using, you should remove
any that are not used.

In this file os.path, re, and subprocess are not used.

Oh, yes, leftovers from the refactoring. Fix inc.

+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+from sexps import *
+from test_case_generator import *
+
+def test_multiple_max():
+    doc_string = """Test that multiple constants in multiple max expressions are reduced to a 
single max."""
What is this? If it's a docstring it's not assigned, it's just a triple
quoted string at the start of the function or class. Fix this for the
other functions as well

I followed the convention from the jump lowering tests. It's the string printed to the generated test script. I'll fix the single-line strings to normal quotes.

+
+    operands = [const_float(1),
+                const_float(2),
+                const_float(3),
+                ['var_ref', 'a']]
+
+    c = 1
+    for ops in itertools.permutations(operands):
+        maxtree1 = reduce(lambda a, b: max_(a, b, 'float'), ops)
+        maxtree2 = reduce(lambda a, b: max_(b, a, 'float'), ops)
+
+        expected = max_(const_float(3), ['var_ref', 'a'], 'float')
+
+        input_sexp = make_test_case('main', 'void', (
+                assign_x('b', maxtree1) +
+                assign_x('c', maxtree2)
+                ))
+        expected_sexp = make_test_case('main', 'void', (
+                assign_x('b', expected) +
+                assign_x('c', expected)
+                ))
+
+        create_test_case(doc_string, input_sexp, expected_sexp, 
'multiple_max{0}'.format(c), 'do_minmax_prune')
+        c += 1
+
+def test_multiple_min():
+    doc_string = """Test that multiple constants in multiple min expressions are reduced to a 
single min."""
+
+    operands = [const_float(1),
+                const_float(2),
+                const_float(3),
+                ['var_ref', 'a']]
+
+    c = 1
+    for ops in itertools.permutations(operands):
+        mintree1 = reduce(lambda a, b: min_(a, b, 'float'), ops)
+        mintree2 = reduce(lambda a, b: min_(b, a, 'float'), ops)
+
+        expected = min_(const_float(1), ['var_ref', 'a'], 'float')
+
+        input_sexp = make_test_case('main', 'void', (
+                assign_x('b', mintree1) +
+                assign_x('c', mintree2)
+                ))
+        expected_sexp = make_test_case('main', 'void', (
+                assign_x('b', expected) +
+                assign_x('c', expected)
+                ))
+
+        create_test_case(doc_string, input_sexp, expected_sexp, 
'multiple_min{0}'.format(c), 'do_minmax_prune')
+        c += 1
                have a look at enumerate for a more pythonic way to handle the
                incrementing of c.

Ah, right, thanks.

+
+def test_two_constant_mid3():
+    doc_string = """Test that code generated from a mid3() call with two 
parameters as constants
+are reduced to a single min and max"""
+
+    operands = [const_float(1),
+                const_float(3),
+                ['var_ref', 'a']]
+
+    # The builtin function call mid3(x, y, z) generates max(min(x, y), 
max(min(x, z), min(y, z))).
+    # All permutations of these parameters should optimize to max(min(var_ref 
a, 3), 1)
+
+    c = 1
+    for ops in itertools.permutations(operands):
+        x = ops[0]
+        y = ops[1]
+        z = ops[2]
+
+        exprtree = maxf(minf(x, y), maxf(minf(x, z), minf(y, z)))
+        expected = maxf(minf(['var_ref', 'a'], const_float(3)), const_float(1))
+
+        input_sexp = make_test_case('main', 'void', (
+                assign_x('b', exprtree)
+                ))
+        expect_sexp = make_test_case('main', 'void', (
+                assign_x('b', expected)
+                ))
+
+        create_test_case(doc_string, input_sexp, expect_sexp, 
'mid3opt{0}'.format(c), 'do_minmax_prune')
+        c += 1
+
+def test_mixed_vectors():
+    doc_string = """Test that a min/max tree of vectors is kept unchanged when 
constant vectors
+have some components less, some greater than another constant vector."""
+
+    operands = [const_vec4(1, 3, 1, 3),
+                const_vec4(3, 1, 3, 1),
+                const_vec4(2, 2, 2, 2),
+                ['var_ref', 'a']]
+
+    c = 1
+    for ops in itertools.permutations(operands):
+        mintree1 = reduce(lambda a, b: min_(a, b, 'vec4'), ops)
+        mintree2 = reduce(lambda a, b: min_(b, a, 'vec4'), ops)
+
+        expected = min_(const_float(1), ['var_ref', 'a'], 'float')
+
+        input_sexp = make_test_case('main', 'void', (
+                declare('vec4', 'a', 'in') +
+                declare('vec4', 'b', 'out') +
+                declare('vec4', 'c', 'out') +
+                assign('b', 'xyzw', reduce(lambda a, b: min_(a, b, 'vec4'), 
ops)) +
+                assign('c', 'xyzw', reduce(lambda a, b: min_(b, a, 'vec4'), 
ops))
+                ))
+        expected_sexp = input_sexp
+
+        create_test_case(doc_string, input_sexp, expected_sexp, 
'mixed_vectors{0}'.format(c), 'do_minmax_prune')
+        c += 1
+
+if __name__ == '__main__':
+    test_multiple_max()
+    test_multiple_min()
+    test_two_constant_mid3()
+    test_mixed_vectors()
--
2.0.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to