[pypy-svn] r40569 - in pypy/dist/pypy/rpython: . lltypesystem test
mwh at codespeak.net
mwh at codespeak.net
Fri Mar 16 10:23:15 CET 2007
Author: mwh
Date: Fri Mar 16 10:23:12 2007
New Revision: 40569
Modified:
pypy/dist/pypy/rpython/lltypesystem/opimpl.py
pypy/dist/pypy/rpython/rbool.py
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/test/test_rint.py
Log:
fix my int division/modulo code to not emit 'cast_primitive' ops.
add tests for long long division, and fix things here and there
to make it work.
Modified: pypy/dist/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/opimpl.py Fri Mar 16 10:23:12 2007
@@ -182,6 +182,22 @@
r -= y
return r
+def op_llong_floordiv(x, y):
+ assert isinstance(x, r_longlong)
+ assert isinstance(y, r_longlong)
+ r = x/y
+ if x^y < 0 and x%y != 0:
+ r += 1
+ return r
+
+def op_llong_mod(x, y):
+ assert isinstance(x, r_longlong)
+ assert isinstance(y, r_longlong)
+ r = x%y
+ if x^y < 0 and x%y != 0:
+ r -= y
+ return r
+
def op_same_as(x):
return x
Modified: pypy/dist/pypy/rpython/rbool.py
==============================================================================
--- pypy/dist/pypy/rpython/rbool.py (original)
+++ pypy/dist/pypy/rpython/rbool.py Fri Mar 16 10:23:12 2007
@@ -44,8 +44,11 @@
log.debug('explicit cast_bool_to_uint')
return llops.genop('cast_bool_to_uint', [v], resulttype=Unsigned)
if r_from.lowleveltype == Bool and r_to.lowleveltype == Signed:
- log.debug('explicit cast_bool_to_int')
return llops.genop('cast_bool_to_int', [v], resulttype=Signed)
+ if r_from.lowleveltype == Bool:
+ from pypy.rpython.rint import signed_repr
+ v_int = llops.genop('cast_bool_to_int', [v], resulttype=Signed)
+ return llops.convertvar(v_int, signed_repr, r_to)
return NotImplemented
class __extend__(pairtype(IntegerRepr, BoolRepr)):
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Fri Mar 16 10:23:12 2007
@@ -204,18 +204,21 @@
# correction in the right cases.
# paper and pencil are encouraged for this :)
+ from pypy.rpython.rbool import bool_repr
+ c_zero = inputconst(repr.lowleveltype, hop.args_s[0].knowntype(0))
+
if func in ('floordiv', 'floordiv_ovf'):
# return (x/y) - (((x^y)<0)&((x%y)!=0));
v_xor = hop.genop(prefix + 'xor', vlist,
resulttype=repr)
- v_xor_le = hop.genop(prefix + 'le', [v_xor, inputconst(repr.lowleveltype, 0)],
+ v_xor_le = hop.genop(prefix + 'le', [v_xor, c_zero],
resulttype=Bool)
- v_xor_le = hop.genop('cast_primitive', [v_xor_le], resulttype=repr)
+ v_xor_le = hop.llops.convertvar(v_xor_le, bool_repr, repr)
v_mod = hop.genop(prefix + 'mod', vlist,
resulttype=repr)
- v_mod_ne = hop.genop(prefix + 'ne', [v_mod, inputconst(repr.lowleveltype, 0)],
+ v_mod_ne = hop.genop(prefix + 'ne', [v_mod, c_zero],
resulttype=Bool)
- v_mod_ne = hop.genop('cast_primitive', [v_mod_ne], resulttype=repr)
+ v_mod_ne = hop.llops.convertvar(v_mod_ne, bool_repr, repr)
v_corr = hop.genop(prefix + 'and', [v_xor_le, v_mod_ne],
resulttype=repr)
v_res = hop.genop(prefix + 'sub', [v_res, v_corr],
@@ -224,12 +227,12 @@
# return r + y*(((x^y)<0)&(r!=0));
v_xor = hop.genop(prefix + 'xor', vlist,
resulttype=repr)
- v_xor_le = hop.genop(prefix + 'le', [v_xor, inputconst(repr.lowleveltype, 0)],
+ v_xor_le = hop.genop(prefix + 'le', [v_xor, c_zero],
resulttype=Bool)
- v_xor_le = hop.genop('cast_primitive', [v_xor_le], resulttype=repr)
- v_mod_ne = hop.genop(prefix + 'ne', [v_res, inputconst(repr.lowleveltype, 0)],
+ v_xor_le = hop.llops.convertvar(v_xor_le, bool_repr, repr)
+ v_mod_ne = hop.genop(prefix + 'ne', [v_res, c_zero],
resulttype=Bool)
- v_mod_ne = hop.genop('cast_primitive', [v_mod_ne], resulttype=repr)
+ v_mod_ne = hop.llops.convertvar(v_mod_ne, bool_repr, repr)
v_corr1 = hop.genop(prefix + 'and', [v_xor_le, v_mod_ne],
resulttype=repr)
v_corr = hop.genop(prefix + 'mul', [v_corr1, vlist[1]],
Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py (original)
+++ pypy/dist/pypy/rpython/test/test_rint.py Fri Mar 16 10:23:12 2007
@@ -231,6 +231,8 @@
if not y: continue
res = self.interpret(d, [x, y])
assert res == d(x, y)
+ res = self.interpret(d, [r_longlong(x), r_longlong(y)])
+ assert res == d(x, y)
def m(x, y):
return x%y
@@ -241,7 +243,9 @@
if not y: continue
res = self.interpret(m, [x, y])
assert res == m(x, y)
-
+ res = self.interpret(m, [r_longlong(x), r_longlong(y)])
+ assert res == m(x, y)
+
class TestLLtype(BaseTestRint, LLRtypeMixin):
pass
More information about the Pypy-commit
mailing list