[pypy-svn] r31696 - in pypy/dist/pypy/jit: codegen/i386 codegen/i386/test timeshifter/test

arigo at codespeak.net arigo at codespeak.net
Sat Aug 26 20:14:48 CEST 2006


Author: arigo
Date: Sat Aug 26 20:14:45 2006
New Revision: 31696

Modified:
   pypy/dist/pypy/jit/codegen/i386/ri386genop.py
   pypy/dist/pypy/jit/codegen/i386/test/test_timeshift.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
(michael, arigo)

getfield() support in ri386genop.  Support for non-integer arguments to
the ll_functions.



Modified: pypy/dist/pypy/jit/codegen/i386/ri386genop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386genop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386genop.py	Sat Aug 26 20:14:45 2006
@@ -230,6 +230,12 @@
         self.mc.MOVZX(eax, al)
         return self.push(eax)
 
+    def op_getfield(self, (gv_ptr, gv_offset), gv_RESTYPE):
+        assert isinstance(gv_offset, IntConst)
+        offset = gv_offset.value
+        self.mc.MOV(edx, gv_ptr.operand(self))
+        return self.push(mem(edx, offset))
+
 
 class Link(CodeGenLink):
 
@@ -343,6 +349,11 @@
 
     constPrebuiltGlobal = genconst
 
+    def constFieldName(T, name):
+        return IntConst(llmemory.offsetof(T, name))
+    constFieldName._annspecialcase_ = 'specialize:memo'
+    constFieldName = staticmethod(constFieldName)
+
     def gencallableconst(self, name, block, gv_FUNCTYPE):
         prologue = self.newblock()
         #prologue.mc.BREAKPOINT()

Modified: pypy/dist/pypy/jit/codegen/i386/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_timeshift.py	Sat Aug 26 20:14:45 2006
@@ -19,22 +19,29 @@
         RGenOp = self.RGenOp
         SEPLINE = self.SEPLINE
         ml_generate_code = self.ml_generate_code
-        argcolors = unrolling_iterable(self.argcolors)
+        argcolors = list(self.argcolors)
+        if hasattr(self.ll_function, 'convert_arguments'):
+            decoders = self.ll_function.convert_arguments
+            assert len(decoders) == len(argcolors)
+        else:
+            decoders = [int] * len(argcolors)
+        argcolors_decoders = zip(argcolors, decoders)
+        argcolors_decoders = unrolling_iterable(argcolors_decoders)
 
         def ll_main(argv):
             i = 1
             mainargs = ()
             residualargs = ()
-            for color in argcolors:
+            for color, decoder in argcolors_decoders:
                 try:
                     if color == 'green':
-                        llvalue = int(argv[i])
+                        llvalue = decoder(argv[i])
                         mainargs += (llvalue,)
                         i = i + 1
                     else:
                         is_const = argv[i] == '-const'
                         i += 1
-                        llvalue = int(argv[i])
+                        llvalue = decoder(argv[i])
                         mainargs += (is_const, llvalue)
                         residualargs += (llvalue,)
                         i += 1 
@@ -69,6 +76,7 @@
         self.main_cbuilder= cbuilder
         
     def timeshift(self, ll_function, values, opt_consts=[], *args, **kwds):
+        self.ll_function = ll_function
         self.timeshift_cached(ll_function, values, *args, **kwds)
 
         mainargs = []

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Sat Aug 26 20:14:45 2006
@@ -58,6 +58,12 @@
         del cls._cache_order
 
     def timeshift_cached(self, ll_function, values, inline=None, policy=None):
+        # decode the 'values' if they are specified as strings
+        if hasattr(ll_function, 'convert_arguments'):
+            assert len(ll_function.convert_arguments) == len(values)
+            values = [decoder(value) for decoder, value in zip(
+                                        ll_function.convert_arguments, values)]
+
         key = ll_function, inline, policy
         try:
             cache, argtypes = self._cache[key]
@@ -439,16 +445,24 @@
         S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
                                           ('world', lltype.Signed),
                             hints={'immutable': True})
+
         def ll_function(s):
             return s.hello * s.world
-        s1 = lltype.malloc(S)
-        s1.hello = 6
-        s1.world = 7
-        res = self.timeshift(ll_function, [s1], [])
+
+        def build_S(string):
+            items = string.split(',')
+            assert len(items) == 2
+            s1 = lltype.malloc(S)
+            s1.hello = int(items[0])
+            s1.world = int(items[1])
+            return s1
+        ll_function.convert_arguments = [build_S]
+
+        res = self.timeshift(ll_function, ["6,7"], [])
         assert res == 42
         self.check_insns({'getfield': 2, 'int_mul': 1})
-        res = self.timeshift(ll_function, [s1], [0])
-        assert res == 42
+        res = self.timeshift(ll_function, ["8,9"], [0])
+        assert res == 72
         self.check_insns({})
 
     def test_simple_array(self):



More information about the Pypy-commit mailing list