[pypy-svn] pypy numpy-exp: Improve the test and fix it by adding specialization left and right

fijal commits-noreply at bitbucket.org
Sun Feb 13 16:16:03 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-exp
Changeset: r41879:bbad36eb3203
Date: 2011-02-11 23:46 +0200
http://bitbucket.org/pypy/pypy/changeset/bbad36eb3203/

Log:	Improve the test and fix it by adding specialization left and right

diff --git a/pypy/jit/metainterp/test/test_ztranslation.py b/pypy/jit/metainterp/test/test_ztranslation.py
--- a/pypy/jit/metainterp/test/test_ztranslation.py
+++ b/pypy/jit/metainterp/test/test_ztranslation.py
@@ -2,7 +2,7 @@
 from pypy.jit.metainterp.warmspot import rpython_ll_meta_interp, ll_meta_interp
 from pypy.jit.backend.llgraph import runner
 from pypy.rlib.jit import JitDriver, OPTIMIZER_FULL, unroll_parameters
-from pypy.rlib.jit import PARAMETERS, dont_look_inside
+from pypy.rlib.jit import PARAMETERS, dont_look_inside, hint
 from pypy.jit.metainterp.jitprof import Profiler
 from pypy.rpython.lltypesystem import lltype, llmemory
 
@@ -24,16 +24,21 @@
         # - string concatenation, slicing and comparison
 
         class Frame(object):
-            _virtualizable2_ = ['i']
+            _virtualizable2_ = ['l[*]']
 
             def __init__(self, i):
-                self.i = i
+                self = hint(self, fresh_virtualizable=True,
+                            access_directly=True)
+                self.l = [i]
 
         class OtherFrame(object):
-            _virtualizable2_ = ['i']
+            _virtualizable2_ = ['i', 'l[*]']
 
             def __init__(self, i):
+                self = hint(self, fresh_virtualizable=True,
+                            access_directly=True)
                 self.i = i
+                self.l = [float(i)]
 
         class JitCellCache:
             entry = None
@@ -58,40 +63,46 @@
             jitdriver.set_param("trace_eagerness", 2)
             total = 0
             frame = Frame(i)
-            while frame.i > 3:
+            while frame.l[0] > 3:
                 jitdriver.can_enter_jit(frame=frame, total=total)
                 jitdriver.jit_merge_point(frame=frame, total=total)
-                total += frame.i
-                if frame.i >= 20:
-                    frame.i -= 2
-                frame.i -= 1
+                total += frame.l[0]
+                if frame.l[0] >= 20:
+                    frame.l[0] -= 2
+                frame.l[0] -= 1
             return total * 10
         #
-        myjitdriver2 = JitDriver(greens = ['g'], reds = ['m', 's', 'f'],
+        myjitdriver2 = JitDriver(greens = ['g'],
+                                 reds = ['m', 's', 'f', 'float_s'],
                                  virtualizables = ['f'])
         def f2(g, m, x):
             s = ""
             f = OtherFrame(x)
+            float_s = 0.0
             while m > 0:
-                myjitdriver2.can_enter_jit(g=g, m=m, f=f, s=s)
-                myjitdriver2.jit_merge_point(g=g, m=m, f=f, s=s)
+                myjitdriver2.can_enter_jit(g=g, m=m, f=f, s=s, float_s=float_s)
+                myjitdriver2.jit_merge_point(g=g, m=m, f=f, s=s,
+                                             float_s=float_s)
                 s += 'xy'
                 if s[:2] == 'yz':
                     return -666
                 m -= 1
                 f.i += 3
+                float_s += f.l[0]
             return f.i
         #
         def main(i, j):
             return f(i) - f2(i+j, i, j)
         res = ll_meta_interp(main, [40, 5], CPUClass=self.CPUClass,
-                             type_system=self.type_system)
+                             type_system=self.type_system,
+                             listops=True)
         assert res == main(40, 5)
         res = rpython_ll_meta_interp(main, [40, 5],
                                      CPUClass=self.CPUClass,
                                      type_system=self.type_system,
                                      optimizer=OPTIMIZER_FULL,
-                                     ProfilerClass=Profiler)
+                                     ProfilerClass=Profiler,
+                                     listops=True)
         assert res == main(40, 5)
 
     def test_external_exception_handling_translates(self):
@@ -132,7 +143,7 @@
                                      type_system=self.type_system,
                                      optimizer=OPTIMIZER_FULL,
                                      ProfilerClass=Profiler)
-        assert res == main(40)        
+        assert res == main(40)
 
 class TestTranslationLLtype(TranslationTest):
 

diff --git a/pypy/jit/metainterp/typesystem.py b/pypy/jit/metainterp/typesystem.py
--- a/pypy/jit/metainterp/typesystem.py
+++ b/pypy/jit/metainterp/typesystem.py
@@ -5,7 +5,7 @@
 from pypy.rpython.annlowlevel import cast_instance_to_base_obj
 from pypy.jit.metainterp import history
 from pypy.jit.codewriter import heaptracker
-from pypy.rlib.objectmodel import r_dict
+from pypy.rlib.objectmodel import r_dict, specialize
 
 def deref(T):
     if isinstance(T, lltype.Ptr):
@@ -97,12 +97,15 @@
     def cast_to_baseclass(self, value):
         return lltype.cast_opaque_ptr(lltype.Ptr(rclass.OBJECT), value)
 
+    @specialize.ll()
     def getlength(self, array):
         return len(array)
 
+    @specialize.ll()
     def getarrayitem(self, array, i):
         return array[i]
 
+    @specialize.ll()
     def setarrayitem(self, array, i, newvalue):
         array[i] = newvalue
 
@@ -201,12 +204,15 @@
     def cast_to_baseclass(self, value):
         return ootype.cast_from_object(ootype.ROOT, value)
 
+    @specialize.ll()
     def getlength(self, array):
         return array.ll_length()
 
+    @specialize.ll()
     def getarrayitem(self, array, i):
         return array.ll_getitem_fast(i)
 
+    @specialize.ll()
     def setarrayitem(self, array, i, newvalue):
         array.ll_setitem_fast(i, newvalue)
 


More information about the Pypy-commit mailing list