Author: Armin Rigo <[email protected]>
Branch:
Changeset: r65432:3e7495dc4215
Date: 2013-07-17 12:42 +0200
http://bitbucket.org/pypy/pypy/changeset/3e7495dc4215/
Log: int_lshift, uint_rshift
diff --git a/pypy/module/__pypy__/interp_intop.py
b/pypy/module/__pypy__/interp_intop.py
--- a/pypy/module/__pypy__/interp_intop.py
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -1,6 +1,7 @@
from pypy.interpreter.gateway import unwrap_spec
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib.rarithmetic import r_uint, intmask
@unwrap_spec(n=int, m=int)
@@ -22,3 +23,13 @@
@unwrap_spec(n=int, m=int)
def int_mod(space, n, m):
return space.wrap(llop.int_mod(lltype.Signed, n, m))
+
+@unwrap_spec(n=int, m=int)
+def int_lshift(space, n, m):
+ return space.wrap(llop.int_lshift(lltype.Signed, n, m))
+
+@unwrap_spec(n=int, m=int)
+def uint_rshift(space, n, m):
+ n = r_uint(n)
+ x = llop.uint_rshift(lltype.Unsigned, n, m)
+ return space.wrap(intmask(x))
diff --git a/pypy/module/__pypy__/test/test_intop.py
b/pypy/module/__pypy__/test/test_intop.py
--- a/pypy/module/__pypy__/test/test_intop.py
+++ b/pypy/module/__pypy__/test/test_intop.py
@@ -60,3 +60,37 @@
assert intop.int_mod(-41, -3) == -2
assert intop.int_mod(-sys.maxint, -1) == 0
assert intop.int_mod(sys.maxint, -1) == 0
+
+ def test_int_lshift(self):
+ import sys
+ from __pypy__ import intop
+ if sys.maxint == 2**31-1:
+ bits = 32
+ else:
+ bits = 64
+ assert intop.int_lshift(42, 3) == 42 << 3
+ assert intop.int_lshift(0, 3333) == 0
+ assert intop.int_lshift(1, bits-2) == 1 << (bits-2)
+ assert intop.int_lshift(1, bits-1) == -sys.maxint-1 == (-1) << (bits-1)
+ assert intop.int_lshift(-1, bits-2) == (-1) << (bits-2)
+ assert intop.int_lshift(-1, bits-1) == -sys.maxint-1
+ assert intop.int_lshift(sys.maxint // 3, 2) == (
+ self.intmask((sys.maxint // 3) << 2))
+ assert intop.int_lshift(-sys.maxint // 3, 2) == (
+ self.intmask((-sys.maxint // 3) << 2))
+
+ def test_uint_rshift(self):
+ import sys
+ from __pypy__ import intop
+ if sys.maxint == 2**31-1:
+ bits = 32
+ else:
+ bits = 64
+ N = 1 << bits
+ assert intop.uint_rshift(42, 3) == 42 >> 3
+ assert intop.uint_rshift(-42, 3) == (N-42) >> 3
+ assert intop.uint_rshift(0, 3333) == 0
+ assert intop.uint_rshift(-1, 0) == -1
+ assert intop.uint_rshift(-1, 1) == sys.maxint
+ assert intop.uint_rshift(-1, bits-2) == 3
+ assert intop.uint_rshift(-1, bits-1) == 1
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit