[pypy-svn] r53376 - in pypy/branch/jit-hotpath/pypy/jit/rainbow: . test

arigo at codespeak.net arigo at codespeak.net
Sat Apr 5 10:13:56 CEST 2008


Author: arigo
Date: Sat Apr  5 10:13:55 2008
New Revision: 53376

Modified:
   pypy/branch/jit-hotpath/pypy/jit/rainbow/fallback.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
Log:
* Make a fast path version of load_int().
* Add a test that needs more than 127 (actually more than 255) variables,
  to check the load_int() logic.


Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/fallback.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/fallback.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/fallback.py	Sat Apr  5 10:13:55 2008
@@ -6,7 +6,7 @@
 from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
 from pypy.jit.timeshifter import rvalue, rcontainer
 from pypy.jit.timeshifter.greenkey import empty_key, GreenKey
-from pypy.jit.rainbow.interpreter import SIGN_EXTEND2, arguments
+from pypy.jit.rainbow.interpreter import arguments
 
 
 class FallStoreBackMemo(object):
@@ -205,14 +205,21 @@
 
     def load_byte(self):
         pc = self.pc
-        assert pc >= 0
         result = ord(self.bytecode.code[pc])
         self.pc = pc + 1
         return result
 
     def load_int(self):
-        result = 0
-        shift = 0
+        pc = self.pc
+        result = ord(self.bytecode.code[pc])
+        self.pc = pc + 1
+        if result > 0x7F:
+            result = self._load_larger_int(result)
+        return result
+
+    def _load_larger_int(self, result):    # slow path
+        result = result & 0x7F
+        shift = 7
         pc = self.pc
         while 1:
             byte = ord(self.bytecode.code[pc])
@@ -223,10 +230,10 @@
                 break
         self.pc = pc
         return intmask(result)
+    _load_larger_int._dont_inline_ = True
 
     def load_4byte(self):
         pc = self.pc
-        assert pc >= 0
         result = ((ord(self.bytecode.code[pc + 0]) << 24) |
                   (ord(self.bytecode.code[pc + 1]) << 16) |
                   (ord(self.bytecode.code[pc + 2]) <<  8) |

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	Sat Apr  5 10:13:55 2008
@@ -1,4 +1,4 @@
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_uint
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.objectmodel import we_are_translated, CDefinedIntSymbolic, noop
 from pypy.rlib.debug import debug_print
@@ -75,8 +75,6 @@
         dump.dump_bytecode(self, file=file)
         print >> file
 
-SIGN_EXTEND2 = 1 << 15
-
 class STOP(object):
     pass
 STOP = STOP()
@@ -255,7 +253,7 @@
         self.queue = rtimeshift.DispatchQueue(bytecode.num_mergepoints)
         rtimeshift.enter_frame(self.jitstate, self.queue)
         self.frame = self.jitstate.frame
-        self.frame.pc = 0
+        self.frame.pc = r_uint(0)
         self.frame.bytecode = bytecode
         self.frame.local_boxes = redargs
         self.frame.local_green = greenargs
@@ -362,8 +360,16 @@
         return self.frame.bytecode
 
     def load_int(self):
-        result = 0
-        shift = 0
+        pc = self.frame.pc
+        result = ord(self.frame.bytecode.code[pc])
+        self.frame.pc = pc + 1
+        if result > 0x7F:
+            result = self._load_larger_int(result)
+        return result
+
+    def _load_larger_int(self, result):    # slow path
+        result = result & 0x7F
+        shift = 7
         pc = self.frame.pc
         while 1:
             byte = ord(self.frame.bytecode.code[pc])
@@ -374,20 +380,19 @@
                 break
         self.frame.pc = pc
         return intmask(result)
+    _load_larger_int._dont_inline_ = True
 
     def load_4byte(self):
         pc = self.frame.pc
-        assert pc >= 0
-        result = ((ord(self.frame.bytecode.code[pc + 0]) << 24) |
-                  (ord(self.frame.bytecode.code[pc + 1]) << 16) |
-                  (ord(self.frame.bytecode.code[pc + 2]) <<  8) |
-                  (ord(self.frame.bytecode.code[pc + 3]) <<  0))
+        result = ((r_uint(ord(self.frame.bytecode.code[pc + 0])) << 24) |
+                  (r_uint(ord(self.frame.bytecode.code[pc + 1])) << 16) |
+                  (r_uint(ord(self.frame.bytecode.code[pc + 2])) <<  8) |
+                  (r_uint(ord(self.frame.bytecode.code[pc + 3])) <<  0))
         self.frame.pc = pc + 4
-        return intmask(result)
+        return result
 
     def load_bool(self):
         pc = self.frame.pc
-        assert pc >= 0
         result = ord(self.frame.bytecode.code[pc])
         self.frame.pc = pc + 1
         return bool(result)
@@ -899,7 +904,7 @@
     def hp_direct_call(self, greenargs, redargs, targetbytecode):
         frame = rtimeshift.VirtualFrame(self.frame, None)
         self.frame = self.jitstate.frame = frame
-        frame.pc = 0
+        frame.pc = r_uint(0)
         frame.bytecode = targetbytecode
         frame.local_boxes = redargs
         frame.local_green = greenargs

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	Sat Apr  5 10:13:55 2008
@@ -1934,6 +1934,97 @@
         res = self.interpret(main2, [5, 6], policy=StopAtXPolicy(g))
         assert res == 11
 
+
+    def test_manymanyvars(self):
+
+        def h(i00, i01, i02, i03, i04, i05, i06, i07, i08, i09,
+              i10, i11, i12, i13, i14, i15, i16, i17, i18, i19,
+              i20, i21, i22, i23, i24, i25, i26, i27, i28, i29,
+              i30, i31, i32, i33, i34, i35, i36, i37, i38, i39,
+              i40, i41, i42, i43, i44, i45, i46, i47, i48, i49,
+              i50, i51, i52, i53, i54, i55, i56, i57, i58, i59,
+              i60, i61, i62, i63, i64, i65, i66, i67, i68, i69,
+              i70, i71, i72, i73, i74, i75, i76, i77, i78, i79,
+              i80, i81, i82, i83, i84, i85, i86, i87, i88, i89,
+              i90, i91, i92, i93, i94, i95, i96, i97, i98, i99,
+              j00, j01, j02, j03, j04, j05, j06, j07, j08, j09,
+              j10, j11, j12, j13, j14, j15, j16, j17, j18, j19,
+              j20, j21, j22, j23, j24, j25, j26, j27, j28, j29,
+              j30, j31, j32, j33, j34, j35, j36, j37, j38, j39,
+              j40, j41, j42, j43, j44, j45, j46, j47, j48, j49,
+              j50, j51, j52, j53, j54, j55, j56, j57, j58, j59,
+              j60, j61, j62, j63, j64, j65, j66, j67, j68, j69,
+              j70, j71, j72, j73, j74, j75, j76, j77, j78, j79,
+              j80, j81, j82, j83, j84, j85, j86, j87, j88, j89,
+              j90, j91, j92, j93, j94, j95, j96, j97, j98, j99):
+            return (i00*0 + i01*1 + i02*2 + i03*3 + i04*4 +
+                    i05*5 + i06*6 + i07*7 + i08*8 + i09*9 +
+                    i10*10 + i11*11 + i12*12 + i13*13 + i14*14 +
+                    i15*15 + i16*16 + i17*17 + i18*18 + i19*19 +
+                    i20*20 + i21*21 + i22*22 + i23*23 + i24*24 +
+                    i25*25 + i26*26 + i27*27 + i28*28 + i29*29 +
+                    i30*30 + i31*31 + i32*32 + i33*33 + i34*34 +
+                    i35*35 + i36*36 + i37*37 + i38*38 + i39*39 +
+                    i40*40 + i41*41 + i42*42 + i43*43 + i44*44 +
+                    i45*45 + i46*46 + i47*47 + i48*48 + i49*49 +
+                    i50*50 + i51*51 + i52*52 + i53*53 + i54*54 +
+                    i55*55 + i56*56 + i57*57 + i58*58 + i59*59 +
+                    i60*60 + i61*61 + i62*62 + i63*63 + i64*64 +
+                    i65*65 + i66*66 + i67*67 + i68*68 + i69*69 +
+                    i70*70 + i71*71 + i72*72 + i73*73 + i74*74 +
+                    i75*75 + i76*76 + i77*77 + i78*78 + i79*79 +
+                    i80*80 + i81*81 + i82*82 + i83*83 + i84*84 +
+                    i85*85 + i86*86 + i87*87 + i88*88 + i89*89 +
+                    i90*90 + i91*91 + i92*92 + i93*93 + i94*94 +
+                    i95*95 + i96*96 + i97*97 + i98*98 + i99*99 +
+                    j00*0 + j01*1 + j02*2 + j03*3 + j04*4 +
+                    j05*5 + j06*6 + j07*7 + j08*8 + j09*9 +
+                    j10*10 + j11*11 + j12*12 + j13*13 + j14*14 +
+                    j15*15 + j16*16 + j17*17 + j18*18 + j19*19 +
+                    j20*20 + j21*21 + j22*22 + j23*23 + j24*24 +
+                    j25*25 + j26*26 + j27*27 + j28*28 + j29*29 +
+                    j30*30 + j31*31 + j32*32 + j33*33 + j34*34 +
+                    j35*35 + j36*36 + j37*37 + j38*38 + j39*39 +
+                    j40*40 + j41*41 + j42*42 + j43*43 + j44*44 +
+                    j45*45 + j46*46 + j47*47 + j48*48 + j49*49 +
+                    j50*50 + j51*51 + j52*52 + j53*53 + j54*54 +
+                    j55*55 + j56*56 + j57*57 + j58*58 + j59*59 +
+                    j60*60 + j61*61 + j62*62 + j63*63 + j64*64 +
+                    j65*65 + j66*66 + j67*67 + j68*68 + j69*69 +
+                    j70*70 + j71*71 + j72*72 + j73*73 + j74*74 +
+                    j75*75 + j76*76 + j77*77 + j78*78 + j79*79 +
+                    j80*80 + j81*81 + j82*82 + j83*83 + j84*84 +
+                    j85*85 + j86*86 + j87*87 + j88*88 + j89*89 +
+                    j90*90 + j91*91 + j92*92 + j93*93 + j94*94 +
+                    j95*95 + j96*96 + j97*97 + j98*98 + j99*99)
+
+        def f(n):
+            return h(
+                n+0, n+1, n+2, n+3, n+4, n+5, n+6, n+7, n+8, n+9,
+                n+10, n+11, n+12, n+13, n+14, n+15, n+16, n+17, n+18, n+19,
+                n+20, n+21, n+22, n+23, n+24, n+25, n+26, n+27, n+28, n+29,
+                n+30, n+31, n+32, n+33, n+34, n+35, n+36, n+37, n+38, n+39,
+                n+40, n+41, n+42, n+43, n+44, n+45, n+46, n+47, n+48, n+49,
+                n+50, n+51, n+52, n+53, n+54, n+55, n+56, n+57, n+58, n+59,
+                n+60, n+61, n+62, n+63, n+64, n+65, n+66, n+67, n+68, n+69,
+                n+70, n+71, n+72, n+73, n+74, n+75, n+76, n+77, n+78, n+79,
+                n+80, n+81, n+82, n+83, n+84, n+85, n+86, n+87, n+88, n+89,
+                n+90, n+91, n+92, n+93, n+94, n+95, n+96, n+97, n+98, n+99,
+                n-0, n-1, n-2, n-3, n-4, n-5, n-6, n-7, n-8, n-9,
+                n-10, n-11, n-12, n-13, n-14, n-15, n-16, n-17, n-18, n-19,
+                n-20, n-21, n-22, n-23, n-24, n-25, n-26, n-27, n-28, n-29,
+                n-30, n-31, n-32, n-33, n-34, n-35, n-36, n-37, n-38, n-39,
+                n-40, n-41, n-42, n-43, n-44, n-45, n-46, n-47, n-48, n-49,
+                n-50, n-51, n-52, n-53, n-54, n-55, n-56, n-57, n-58, n-59,
+                n-60, n-61, n-62, n-63, n-64, n-65, n-66, n-67, n-68, n-69,
+                n-70, n-71, n-72, n-73, n-74, n-75, n-76, n-77, n-78, n-79,
+                n-80, n-81, n-82, n-83, n-84, n-85, n-86, n-87, n-88, n-89,
+                n-90, n-91, n-92, n-93, n-94, n-95, n-96, n-97, n-98, n-99)
+
+        res = self.interpret(f, [42])
+        assert res == f(42)
+
+
 class TestLLType(SimpleTests):
     type_system = "lltype"
 



More information about the Pypy-commit mailing list