[pypy-commit] pypy unsigned-dtypes: jit support for uint_mod

hakanardo noreply at buildbot.pypy.org
Thu Sep 8 20:51:00 CEST 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: unsigned-dtypes
Changeset: r47169:c13e01ca3ae7
Date: 2011-09-08 20:50 +0200
http://bitbucket.org/pypy/pypy/changeset/c13e01ca3ae7/

Log:	jit support for uint_mod

diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -440,6 +440,7 @@
     rewrite_op_ullong_mod_zer      = _do_builtin_call
     rewrite_op_gc_identityhash = _do_builtin_call
     rewrite_op_gc_id           = _do_builtin_call
+    rewrite_op_uint_mod        = _do_builtin_call
 
     # ----------
     # getfield/setfield/mallocs etc.
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -366,6 +366,9 @@
         raise ZeroDivisionError
     return llop.ullong_mod(lltype.SignedLongLong, xll, yll)
 
+def _ll_2_uint_mod(xll, yll):
+    return llop.uint_mod(lltype.Unsigned, xll, yll)
+
 
 # libffi support
 # --------------
diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -2953,6 +2953,19 @@
         res = self.meta_interp(f, [32])
         assert res == f(32)
         self.check_loops(arraylen_gc=2)
+
+    def test_ulonglong_mod(self):
+        myjitdriver = JitDriver(greens = [], reds = ['sa', 'n', 'i'])
+        def f(n):
+            sa = i = rffi.cast(rffi.ULONGLONG, 1)
+            while i < rffi.cast(rffi.ULONGLONG, n):
+                myjitdriver.jit_merge_point(sa=sa, n=n, i=i)
+                sa += sa % i
+                i += 1
+        res = self.meta_interp(f, [32])
+        assert res == f(32)
+
+                
         
 class TestOOtype(BasicTests, OOJitMixin):
 
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -2,7 +2,7 @@
 from pypy.module.micronumpy import interp_ufuncs, signature
 from pypy.module.micronumpy.compile import (numpy_compile, FakeSpace,
     FloatObject)
-from pypy.module.micronumpy.interp_dtype import W_Float64Dtype, W_Int64Dtype
+from pypy.module.micronumpy.interp_dtype import W_Float64Dtype, W_Int64Dtype, W_UInt64Dtype
 from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray,
     SingleDimSlice, scalar_w)
 from pypy.rlib.nonconst import NonConstant
@@ -15,6 +15,7 @@
         cls.space = FakeSpace()
         cls.float64_dtype = cls.space.fromcache(W_Float64Dtype)
         cls.int64_dtype = cls.space.fromcache(W_Int64Dtype)
+        cls.uint64_dtype = cls.space.fromcache(W_UInt64Dtype)
 
     def test_add(self):
         def f(i):
@@ -303,6 +304,26 @@
                           'int_lt': 1, 'guard_true': 1, 'jump': 1})
         assert result == 11.0
 
+    def test_uint64_mod(self):
+        space = self.space
+        float64_dtype = self.float64_dtype
+        uint64_dtype = self.uint64_dtype
+
+        def f(n):
+            if NonConstant(False):
+                dtype = uint64_dtype
+            else:
+                dtype = float64_dtype
+            ar = SingleDimArray(n, dtype=dtype)
+            for i in range(n):
+                ar.get_concrete().setitem(i, uint64_dtype.box(7))
+            v = ar.descr_mod(space, ar).descr_sum(space)
+            assert isinstance(v, FloatObject)
+            return v.floatval
+
+        result = self.meta_interp(f, [5], listops=True, backendopt=True)
+        assert result == f(5)
+
 class TestTranslation(object):
     def test_compile(self):
         x = numpy_compile('aa+f*f/a-', 10)


More information about the pypy-commit mailing list