[pypy-svn] r37085 - in pypy/dist/pypy/jit/codegen: i386 test
arigo at codespeak.net
arigo at codespeak.net
Sun Jan 21 01:23:26 CET 2007
Author: arigo
Date: Sun Jan 21 01:23:21 2007
New Revision: 37085
Modified:
pypy/dist/pypy/jit/codegen/i386/rgenop.py
pypy/dist/pypy/jit/codegen/test/operation_tests.py
pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
Log:
(pedronis, arigo)
Implement all the operations that the old backend was implementing.
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 Sun Jan 21 01:23:21 2007
@@ -102,14 +102,14 @@
self.emit(mc, srcop)
class OpIntIsTrue(OpCompare1):
- opname = 'int_is_true', 'ptr_nonzero'
+ opname = 'int_is_true', 'ptr_nonzero', 'uint_is_true'
cc_result = Conditions['NE']
@staticmethod
def emit(mc, x):
mc.CMP(x, imm8(0))
-class OpIntIsNull(OpIntIsTrue):
- opname = 'ptr_iszero'
+class OpIntIsZero(OpIntIsTrue):
+ opname = 'ptr_iszero', 'bool_not'
cc_result = Conditions['E']
class Op2(Operation):
@@ -425,11 +425,11 @@
cc_result = Conditions['LE']
class OpIntEq(OpCompare2):
- opname = 'int_eq', 'char_eq', 'unichar_eq', 'ptr_eq'
+ opname = 'int_eq', 'char_eq', 'unichar_eq', 'ptr_eq', 'uint_eq'
cc_result = Conditions['E']
class OpIntNe(OpCompare2):
- opname = 'int_ne', 'char_ne', 'unichar_ne', 'ptr_ne'
+ opname = 'int_ne', 'char_ne', 'unichar_ne', 'ptr_ne', 'uint_ne'
cc_result = Conditions['NE']
class OpIntGt(OpCompare2):
@@ -440,6 +440,22 @@
opname = 'int_ge', 'char_ge'
cc_result = Conditions['GE']
+class OpUIntLt(OpCompare2):
+ opname = 'uint_lt'
+ cc_result = Conditions['B']
+
+class OpUIntLe(OpCompare2):
+ opname = 'uint_le'
+ cc_result = Conditions['BE']
+
+class OpUIntGt(OpCompare2):
+ opname = 'uint_gt'
+ cc_result = Conditions['A']
+
+class OpUIntGe(OpCompare2):
+ opname = 'uint_ge'
+ cc_result = Conditions['AE']
+
class JumpIf(Operation):
clobbers_cc = False
result_kind = RK_NO_RESULT
@@ -914,13 +930,31 @@
OPCLASSES1['cast_unichar_to_int'] = None
OPCLASSES1['cast_int_to_char'] = None
OPCLASSES1['cast_int_to_unichar'] = None
+OPCLASSES1['cast_ptr_to_int'] = None
+OPCLASSES1['cast_int_to_ptr'] = None
+OPCLASSES1['cast_uint_to_int'] = None
+OPCLASSES1['cast_bool_to_uint'] = None
+OPCLASSES1['cast_int_to_uint'] = None
+
+# special cases
+#OPCLASSES1['bool_not'] = genop_bool_not XXX do something about it
@specialize.memo()
-def getMissingBackendOperation(opname):
- class MissingBackendOperation(Exception):
- pass
- MissingBackendOperation.__name__ += '_' + opname
- return MissingBackendOperation
+def getopclass1(opname):
+ try:
+ return OPCLASSES1[opname]
+ except KeyError:
+ raise MissingBackendOperation(opname)
+
+ at specialize.memo()
+def getopclass2(opname):
+ try:
+ return OPCLASSES2[opname]
+ except KeyError:
+ raise MissingBackendOperation(opname)
+
+class MissingBackendOperation(Exception):
+ pass
def setup_conditions():
@@ -1352,10 +1386,7 @@
@specialize.arg(1)
def genop1(self, opname, gv_arg):
- try:
- cls = OPCLASSES1[opname]
- except KeyError:
- raise getMissingBackendOperation(opname)()
+ cls = getopclass1(opname)
if cls is None: # identity
return gv_arg
op = cls(gv_arg)
@@ -1364,10 +1395,7 @@
@specialize.arg(1)
def genop2(self, opname, gv_arg1, gv_arg2):
- try:
- cls = OPCLASSES2[opname]
- except KeyError:
- raise getMissingBackendOperation(opname)()
+ cls = getopclass2(opname)
op = cls(gv_arg1, gv_arg2)
self.operations.append(op)
return op
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 Sun Jan 21 01:23:21 2007
@@ -2,6 +2,7 @@
from pypy.translator.translator import TranslationContext, graphof
from pypy.jit.codegen import graph2rgenop
from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.rarithmetic import r_uint, intmask
from ctypes import cast, c_void_p, CFUNCTYPE, c_int, c_float
from pypy import conftest
@@ -97,6 +98,29 @@
assert fp(-12, -12) == fn(-12, -12), op
assert fp(-12, -13) == fn(-12, -13), op
+ def test_unsigned_comparison(self):
+ for op, fn in [('int(x < y)', lambda x, y: int(x < y)),
+ ('int(x <= y)', lambda x, y: int(x <= y)),
+ ('int(x == y)', lambda x, y: int(x == y)),
+ ('int(x != y)', lambda x, y: int(x != y)),
+ ('int(x > y)', lambda x, y: int(x > y)),
+ ('int(x >= y)', lambda x, y: int(x >= y)),
+ ]:
+ fp = self.rgen(fn, [r_uint, r_uint])
+ print op
+ assert fp(r_uint(12), r_uint(11)) == fn(r_uint(12), r_uint(11))
+ assert fp(r_uint(12), r_uint(12)) == fn(r_uint(12), r_uint(12))
+ assert fp(r_uint(12), r_uint(13)) == fn(r_uint(12), r_uint(13))
+ assert fp(r_uint(-12), r_uint(11)) == fn(r_uint(-12), r_uint(11))
+ assert fp(r_uint(-12), r_uint(12)) == fn(r_uint(-12), r_uint(12))
+ assert fp(r_uint(-12), r_uint(13)) == fn(r_uint(-12), r_uint(13))
+ assert fp(r_uint(12), r_uint(-11)) == fn(r_uint(12), r_uint(-11))
+ assert fp(r_uint(12), r_uint(-12)) == fn(r_uint(12), r_uint(-12))
+ assert fp(r_uint(12), r_uint(-13)) == fn(r_uint(12), r_uint(-13))
+ assert fp(r_uint(-12), r_uint(-11)) == fn(r_uint(-12), r_uint(-11))
+ assert fp(r_uint(-12), r_uint(-12)) == fn(r_uint(-12), r_uint(-12))
+ assert fp(r_uint(-12), r_uint(-13)) == fn(r_uint(-12), r_uint(-13))
+
def test_char_comparison(self):
for op, fn in [('int(chr(x) < chr(y))', lambda x, y: int(chr(x) < chr(y))),
('int(chr(x) <= chr(y))', lambda x, y: int(chr(x) <= chr(y))),
@@ -297,3 +321,14 @@
return bool(s1) + bool(s2)*10 + (s1==s2)*100 + (s1!=s2)*1000
fp = self.rgen(fn, [])
assert fp() == 111
+
+ def test_is_true(self):
+ for op, fn in [('bool(x)', lambda x: bool(x)),
+ ('not x', lambda x: llop.bool_not(lltype.Bool,
+ bool(x))),
+ ]:
+ for typ in [int, r_uint, bool]:
+ fp = self.rgen(fn, [typ], bool)
+ assert fp(typ(12)) == fn(typ(12)), (op, typ)
+ assert fp(typ(0)) == fn(typ(0)), (op, typ)
+ assert fp(typ(-1)) == fn(typ(-1)), (op, typ)
Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py (original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py Sun Jan 21 01:23:21 2007
@@ -1120,3 +1120,26 @@
res = fnptr(17)
assert res == 17
+
+ def test_bool_not_direct(self):
+ rgenop = self.RGenOp()
+ signed_kind = rgenop.kindToken(lltype.Signed)
+ bool_kind = rgenop.kindToken(lltype.Bool)
+ sigtoken = rgenop.sigToken(FUNC)
+ builder, gv_callable, [gv_x] = rgenop.newgraph(sigtoken, "bool_not")
+ builder.start_writing()
+ gv_cond = builder.genop2("int_lt", gv_x, rgenop.genconst(10))
+ gv_neg = builder.genop1("bool_not", gv_cond)
+ builder2 = builder.jump_if_true(gv_neg, [])
+ builder.finish_and_return(sigtoken, rgenop.genconst(111))
+
+ builder2.start_writing()
+ builder2.finish_and_return(sigtoken, rgenop.genconst(168))
+ builder.end()
+
+ fnptr = self.cast(gv_callable, 1)
+
+ res = fnptr(17)
+ assert res == 168
+ res = fnptr(7)
+ assert res == 111
More information about the Pypy-commit
mailing list