[pypy-svn] r36847 - in pypy/dist/pypy/jit/codegen: . i386 test

arigo at codespeak.net arigo at codespeak.net
Tue Jan 16 19:49:06 CET 2007


Author: arigo
Date: Tue Jan 16 19:49:03 2007
New Revision: 36847

Modified:
   pypy/dist/pypy/jit/codegen/graph2rgenop.py
   pypy/dist/pypy/jit/codegen/i386/rgenop.py
   pypy/dist/pypy/jit/codegen/test/operation_tests.py
Log:
More operation_tests: pointer comparisons


Modified: pypy/dist/pypy/jit/codegen/graph2rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/graph2rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/graph2rgenop.py	Tue Jan 16 19:49:03 2007
@@ -69,6 +69,9 @@
                                                        var2gv(op.args[0]),
                                                        var2gv(op.args[1]),
                                                        var2gv(op.args[2]))
+            elif op.opname == 'same_as':
+                token = rgenop.kindToken(op.args[0])
+                gv_result = builder.genop_same_as(token, var2gv(op.args[0]))
             elif len(op.args) == 1:
                 gv_result = builder.genop1(op.opname, var2gv(op.args[0]))
             elif len(op.args) == 2:

Modified: pypy/dist/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/rgenop.py	Tue Jan 16 19:49:03 2007
@@ -102,12 +102,16 @@
         self.emit(mc, srcop)
 
 class OpIntIsTrue(OpCompare1):
-    opname = 'int_is_true'
+    opname = 'int_is_true', 'ptr_nonzero'
     cc_result = Conditions['NE']
     @staticmethod
     def emit(mc, x):
         mc.CMP(x, imm8(0))
 
+class OpIntIsNull(OpIntIsTrue):
+    opname = 'ptr_iszero'
+    cc_result = Conditions['E']
+
 class Op2(Operation):
     def __init__(self, x, y):
         self.x = x
@@ -413,11 +417,11 @@
     cc_result = Conditions['LE']
 
 class OpIntEq(OpCompare2):
-    opname = 'int_eq', 'char_eq', 'unichar_eq'
+    opname = 'int_eq', 'char_eq', 'unichar_eq', 'ptr_eq'
     cc_result = Conditions['E']
 
 class OpIntNe(OpCompare2):
-    opname = 'int_ne', 'char_ne', 'unichar_ne'
+    opname = 'int_ne', 'char_ne', 'unichar_ne', 'ptr_ne'
     cc_result = Conditions['NE']
 
 class OpIntGt(OpCompare2):

Modified: pypy/dist/pypy/jit/codegen/test/operation_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/operation_tests.py	(original)
+++ pypy/dist/pypy/jit/codegen/test/operation_tests.py	Tue Jan 16 19:49:03 2007
@@ -267,3 +267,28 @@
                 for operand1 in range(-32, 33):
                     res = fp(operand1)
                     assert res == eval(op, {'x': operand1, 'y': constant})
+
+    def test_ptr_comparison(self):
+        S = lltype.GcStruct('S')
+        T = lltype.GcStruct('T', ('s', lltype.Ptr(S)))
+
+        def fn():
+            s1 = lltype.malloc(S)
+            s2 = lltype.malloc(S)
+            return bool(s1) + bool(s2)*10 + (s1==s2)*100 + (s1!=s2)*1000
+        fp = self.rgen(fn, [])
+        assert fp() == 1011
+
+        def fn():
+            s1 = lltype.malloc(S)
+            s2 = lltype.malloc(T).s    # null
+            return bool(s1) + bool(s2)*10 + (s1==s2)*100 + (s1!=s2)*1000
+        fp = self.rgen(fn, [])
+        assert fp() == 1001
+
+        def fn():
+            s1 = lltype.malloc(S)
+            s2 = s1
+            return bool(s1) + bool(s2)*10 + (s1==s2)*100 + (s1!=s2)*1000
+        fp = self.rgen(fn, [])
+        assert fp() == 111



More information about the Pypy-commit mailing list