[pypy-svn] pypy jit-longlong: Change the {uint, longlong, ulonglong}_{l, r}shift operations:

arigo commits-noreply at bitbucket.org
Thu Jan 6 21:35:50 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40429:b1dc7c7117a9
Date: 2011-01-06 21:22 +0100
http://bitbucket.org/pypy/pypy/changeset/b1dc7c7117a9/

Log:	Change the {uint,longlong,ulonglong}_{l,r}shift operations: now they
	take a second argument (the shift count) which is always a regular
	int.

diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -265,8 +265,8 @@
     'uint_ge':              LLOp(canfold=True),
     'uint_and':             LLOp(canfold=True),
     'uint_or':              LLOp(canfold=True),
-    'uint_lshift':          LLOp(canfold=True),
-    'uint_rshift':          LLOp(canfold=True),
+    'uint_lshift':          LLOp(canfold=True),  # args (r_uint, int)
+    'uint_rshift':          LLOp(canfold=True),  # args (r_uint, int)
     'uint_xor':             LLOp(canfold=True),
 
     'float_is_true':        LLOp(canfold=True),  # it really means "x != 0.0"
@@ -308,8 +308,8 @@
     'llong_ge':             LLOp(canfold=True),
     'llong_and':            LLOp(canfold=True),
     'llong_or':             LLOp(canfold=True),
-    'llong_lshift':         LLOp(canfold=True),
-    'llong_rshift':         LLOp(canfold=True),
+    'llong_lshift':         LLOp(canfold=True),  # args (r_longlong, int)
+    'llong_rshift':         LLOp(canfold=True),  # args (r_longlong, int)
     'llong_xor':            LLOp(canfold=True),
 
     'ullong_is_true':       LLOp(canfold=True),
@@ -330,8 +330,8 @@
     'ullong_ge':            LLOp(canfold=True),
     'ullong_and':           LLOp(canfold=True),
     'ullong_or':            LLOp(canfold=True),
-    'ullong_lshift':        LLOp(canfold=True),
-    'ullong_rshift':        LLOp(canfold=True),
+    'ullong_lshift':        LLOp(canfold=True),  # args (r_ulonglong, int)
+    'ullong_rshift':        LLOp(canfold=True),  # args (r_ulonglong, int)
     'ullong_xor':           LLOp(canfold=True),
 
     'cast_primitive':       LLOp(canfold=True),

diff --git a/pypy/rpython/test/test_rint.py b/pypy/rpython/test/test_rint.py
--- a/pypy/rpython/test/test_rint.py
+++ b/pypy/rpython/test/test_rint.py
@@ -4,7 +4,7 @@
 from pypy.annotation import model as annmodel
 from pypy.rpython.test import snippet
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
-from pypy.rlib.rarithmetic import ovfcheck, r_int64
+from pypy.rlib.rarithmetic import ovfcheck, r_int64, intmask
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
 
@@ -231,6 +231,24 @@
             res = self.interpret(f, [r_int64(-1)<<(r_longlong.BITS-1)])
             assert res == 0
 
+    def test_lshift_rshift(self):
+        for name, f in [('_lshift', lambda x, y: x << y),
+                        ('_rshift', lambda x, y: x >> y)]:
+            for inttype in (int, r_uint, r_int64, r_ulonglong):
+                res = self.interpret(f, [inttype(2147483647), 12])
+                if inttype is int:
+                    assert res == intmask(f(2147483647, 12))
+                else:
+                    assert res == inttype(f(2147483647, 12))
+                #
+                # check that '*_[lr]shift' take an inttype and an
+                # int as arguments, without the need for a
+                # 'cast_int_to_{uint,longlong,...}'
+                _, _, graph = self.gengraph(f, [inttype, int])
+                block = graph.startblock
+                assert len(block.operations) == 1
+                assert block.operations[0].opname.endswith(name)
+
     div_mod_iteration_count = 1000
     def test_div_mod(self):
         import random

diff --git a/pypy/rpython/lltypesystem/opimpl.py b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -271,6 +271,36 @@
         r -= y
     return r
 
+def op_uint_lshift(x, y):
+    assert isinstance(x, r_uint)
+    assert isinstance(y, int)
+    return r_uint(x << y)
+
+def op_uint_rshift(x, y):
+    assert isinstance(x, r_uint)
+    assert isinstance(y, int)
+    return r_uint(x >> y)
+
+def op_llong_lshift(x, y):
+    assert isinstance(x, r_longlong_arg)
+    assert isinstance(y, int)
+    return r_longlong_result(x << y)
+
+def op_llong_rshift(x, y):
+    assert isinstance(x, r_longlong_arg)
+    assert isinstance(y, int)
+    return r_longlong_result(x >> y)
+
+def op_ullong_lshift(x, y):
+    assert isinstance(x, r_ulonglong)
+    assert isinstance(y, int)
+    return r_ulonglong(x << y)
+
+def op_ullong_rshift(x, y):
+    assert isinstance(x, r_ulonglong)
+    assert isinstance(y, int)
+    return r_ulonglong(x >> y)
+
 def op_same_as(x):
     return x
 

diff --git a/pypy/rpython/rint.py b/pypy/rpython/rint.py
--- a/pypy/rpython/rint.py
+++ b/pypy/rpython/rint.py
@@ -196,7 +196,11 @@
         repr = signed_repr
     else:
         repr = r_result
-    vlist = hop.inputargs(repr, repr)
+    if func.startswith(('lshift', 'rshift')):
+        repr2 = signed_repr
+    else:
+        repr2 = repr
+    vlist = hop.inputargs(repr, repr2)
     hop.exception_is_here()
 
     prefix = repr.opprefix


More information about the Pypy-commit mailing list