Author: Richard Plangger <r...@pasra.at>
Branch: vecopt
Changeset: r78703:4fead7c7623f
Date: 2015-07-29 11:46 +0200
http://bitbucket.org/pypy/pypy/changeset/4fead7c7623f/

Log:    bool(0.1) return True, in the jit bool(0.1) transforms to
        cast_float_to_int which is wrong, updated the jtransform.py to emit
        float_is_true instead (similar to the issue with cast int -> bool
        added implementation for both float_ne, float_eq as vector
        operations

diff --git a/pypy/module/micronumpy/test/test_compile.py 
b/pypy/module/micronumpy/test/test_compile.py
--- a/pypy/module/micronumpy/test/test_compile.py
+++ b/pypy/module/micronumpy/test/test_compile.py
@@ -272,6 +272,14 @@
         """)
         assert interp.results[0].value == 3
 
+    def test_any(self):
+        interp = self.run("""
+        a = [0,0,0,0,0.1,0,0,0,0]
+        b = any(a)
+        b -> 0
+        """)
+        assert interp.results[0].value == 1
+
     def test_where(self):
         interp = self.run('''
         a = [1, 0, 3, 0]
diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -580,7 +580,7 @@
 
     def define_float_any():
         return """
-        a = [0,0,0,0,0,0,0,0.9,0,0,0]
+        a = [0,0,0,0,0,0,0,0.1,0,0,0]
         any(a)
         """
 
diff --git a/rpython/jit/backend/x86/rx86.py b/rpython/jit/backend/x86/rx86.py
--- a/rpython/jit/backend/x86/rx86.py
+++ b/rpython/jit/backend/x86/rx86.py
@@ -768,6 +768,8 @@
 
     PTEST_xx = xmminsn('\x66', rex_nw, '\x0F\x38\x17', register(1,8), 
register(2), '\xC0')
     PBLENDW_xxi = xmminsn('\x66', rex_nw, '\x0F\x3A\x0E', register(1,8), 
register(2), '\xC0', immediate(3, 'b'))
+    CMPPD_xxi = xmminsn('\x66', rex_nw, '\x0F\xC2', register(1,8), 
register(2), '\xC0', immediate(3, 'b'))
+    CMPPS_xxi = xmminsn(        rex_nw, '\x0F\xC2', register(1,8), 
register(2), '\xC0', immediate(3, 'b'))
 
     # ------------------------------------------------------------
 
diff --git a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py 
b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
--- a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
+++ b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
@@ -389,7 +389,8 @@
            instrname.find('EXTRACT') != -1 or \
            instrname.find('SRLDQ') != -1 or \
            instrname.find('SHUF') != -1 or \
-           instrname.find('PBLEND') != -1:
+           instrname.find('PBLEND') != -1 or \
+           instrname.find('CMPP') != -1:
             realargmodes = []
             for mode in argmodes:
                 if mode == 'i':
diff --git a/rpython/jit/backend/x86/vector_ext.py 
b/rpython/jit/backend/x86/vector_ext.py
--- a/rpython/jit/backend/x86/vector_ext.py
+++ b/rpython/jit/backend/x86/vector_ext.py
@@ -289,6 +289,43 @@
         elif size == 8:
             self.mc.XORPD(src, heap(self.float_const_neg_addr))
 
+    def genop_guard_vec_float_eq(self, op, guard_op, guard_token, arglocs, 
resloc):
+        lhsloc, rhsloc, sizeloc = arglocs
+        self.genop_vec_float_eq(op, arglocs, lhsloc) # yields one bits if they 
are equal
+        self.mc.PTEST(lhsloc, lhsloc)
+        guard_opnum = guard_op.getopnum()
+        if guard_opnum == rop.GUARD_TRUE:
+            self.implement_guard(guard_token, 'NZ')
+        else:
+            self.implement_guard(guard_token, 'Z')
+
+    def genop_vec_float_eq(self, op, arglocs, resloc):
+        _, rhsloc, sizeloc = arglocs
+        size = sizeloc.value
+        if size == 4:
+            self.mc.CMPPS_xxi(resloc.value, rhsloc.value, 0) # 0 means equal
+        else:
+            self.mc.CMPPD_xxi(resloc.value, rhsloc.value, 0)
+
+    def genop_guard_vec_float_ne(self, op, guard_op, guard_token, arglocs, 
resloc):
+        lhsloc, rhsloc, sizeloc = arglocs
+        self.genop_vec_float_ne(op, arglocs, lhsloc) # yields one bits if they 
are equal
+        self.mc.PTEST(lhsloc, lhsloc)
+        guard_opnum = guard_op.getopnum()
+        if guard_opnum == rop.GUARD_TRUE:
+            self.implement_guard(guard_token, 'NZ')
+        else:
+            self.implement_guard(guard_token, 'Z')
+
+    def genop_vec_float_ne(self, op, arglocs, resloc):
+        _, rhsloc, sizeloc = arglocs
+        size = sizeloc.value
+        # b(100) == 1 << 2 means not equal
+        if size == 4:
+            self.mc.CMPPS_xxi(resloc.value, rhsloc.value, 1 << 2)
+        else:
+            self.mc.CMPPD_xxi(resloc.value, rhsloc.value, 1 << 2)
+
     def genop_vec_int_signext(self, op, arglocs, resloc):
         srcloc, sizeloc, tosizeloc = arglocs
         size = sizeloc.value
@@ -556,7 +593,20 @@
         result = self.xrm.force_result_in_reg(op.result, op.getarg(0), args)
         self.perform(op, [source, imm(size)], result)
 
-    consider_vec_float_eq = consider_vec_logic
+    def consider_vec_float_eq(self, op, guard_op):
+        lhs = op.getarg(0)
+        assert isinstance(lhs, BoxVector)
+        size = lhs.item_size
+        args = op.getarglist()
+        lhsloc = self.xrm.force_result_in_reg(op.result, op.getarg(0), args)
+        rhsloc = self.make_sure_var_in_reg(op.getarg(1), args)
+        if guard_op:
+            self.perform_with_guard(op, guard_op, [lhsloc, rhsloc, imm(size)], 
None)
+        else:
+            self.perform(op, [lhsloc, rhsloc, imm(size)], lhsloc)
+
+    consider_vec_float_ne = consider_vec_float_eq
+
     consider_vec_int_and = consider_vec_logic
     consider_vec_int_or = consider_vec_logic
     consider_vec_int_xor = consider_vec_logic
diff --git a/rpython/jit/codewriter/jtransform.py 
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -1178,7 +1178,12 @@
             else:
                 v1 = v_arg
             sizesign = rffi.size_and_sign(v_result.concretetype)
-            if sizesign <= rffi.size_and_sign(lltype.Signed):
+            if v_result.concretetype is lltype.Bool:
+                op = self.rewrite_operation(
+                        SpaceOperation('float_is_true', [v1], v_result)
+                )
+                ops.append(op)
+            elif sizesign <= rffi.size_and_sign(lltype.Signed):
                 # cast to a type that fits in an int: either the size is
                 # smaller, or it is equal and it is not unsigned
                 v2 = varoftype(lltype.Signed)
diff --git a/rpython/jit/codewriter/test/test_flatten.py 
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -858,6 +858,12 @@
             cast_int_to_float %i0 -> %f0
             float_return %f0
         """, transform=True)
+        def f(n):
+            return rffi.cast(lltype.Bool, n)
+        self.encoding_test(f, [0.1], """
+            float_ne %f0, $0.0 -> %i0
+            int_return %i0
+        """, transform=True)
 
         # Casts to lltype.SingleFloat
         def g(n):
diff --git a/rpython/jit/metainterp/optimizeopt/schedule.py 
b/rpython/jit/metainterp/optimizeopt/schedule.py
--- a/rpython/jit/metainterp/optimizeopt/schedule.py
+++ b/rpython/jit/metainterp/optimizeopt/schedule.py
@@ -750,6 +750,7 @@
     rop.VEC_FLOAT_ABS:   FLOAT_SINGLE_ARG_OP_TO_VOP,
     rop.VEC_FLOAT_NEG:   FLOAT_SINGLE_ARG_OP_TO_VOP,
     rop.VEC_FLOAT_EQ:    OpToVectorOp((PT_FLOAT_GENERIC,PT_FLOAT_GENERIC), 
INT_RES),
+    rop.VEC_FLOAT_NE:    OpToVectorOp((PT_FLOAT_GENERIC,PT_FLOAT_GENERIC), 
INT_RES),
     rop.VEC_INT_IS_TRUE: OpToVectorOp((PT_INT_GENERIC,PT_INT_GENERIC), 
PT_INT_GENERIC),
 
     rop.VEC_RAW_LOAD:         LOAD_TRANS,
diff --git a/rpython/jit/metainterp/resoperation.py 
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -496,7 +496,8 @@
     'VEC_FLOAT_NEG/1',
     'VEC_FLOAT_ABS/1',
     '_VEC_ARITHMETIC_LAST',
-    'VEC_FLOAT_EQ/2',
+    'VEC_FLOAT_EQ/2b',
+    'VEC_FLOAT_NE/2b',
     'VEC_INT_IS_TRUE/1b',
 
     '_VEC_CAST_FIRST',
@@ -806,6 +807,7 @@
     rop.FLOAT_ABS: rop.VEC_FLOAT_ABS,
     rop.FLOAT_NEG: rop.VEC_FLOAT_NEG,
     rop.FLOAT_EQ:  rop.VEC_FLOAT_EQ,
+    rop.FLOAT_NE:  rop.VEC_FLOAT_NE,
     rop.INT_IS_TRUE: rop.VEC_INT_IS_TRUE,
 
     # casts
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to