[pypy-svn] r71789 - in pypy/trunk/pypy/jit/backend/llsupport: . test

arigo at codespeak.net arigo at codespeak.net
Fri Mar 5 10:01:41 CET 2010


Author: arigo
Date: Fri Mar  5 10:01:40 2010
New Revision: 71789

Modified:
   pypy/trunk/pypy/jit/backend/llsupport/gc.py
   pypy/trunk/pypy/jit/backend/llsupport/test/test_gc.py
Log:
Avoid one pass in compress_callshape() by computing
the encoded "unsigned char" numbers directly.


Modified: pypy/trunk/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/trunk/pypy/jit/backend/llsupport/gc.py	Fri Mar  5 10:01:40 2010
@@ -252,51 +252,51 @@
             lltype.free(oldgcmap, flavor='raw')
 
     def get_basic_shape(self):
-        return [self.LOC_EBP_PLUS  | 4,     # return addr: at   4(%ebp)
-                self.LOC_EBP_MINUS | 4,     # saved %ebx:  at  -4(%ebp)
-                self.LOC_EBP_MINUS | 8,     # saved %esi:  at  -8(%ebp)
-                self.LOC_EBP_MINUS | 12,    # saved %edi:  at -12(%ebp)
-                self.LOC_EBP_PLUS  | 0,     # saved %ebp:  at    (%ebp)
-                0]
+        return [chr(self.LOC_EBP_PLUS  | 4),    # return addr: at   4(%ebp)
+                chr(self.LOC_EBP_MINUS | 4),    # saved %ebx:  at  -4(%ebp)
+                chr(self.LOC_EBP_MINUS | 8),    # saved %esi:  at  -8(%ebp)
+                chr(self.LOC_EBP_MINUS | 12),   # saved %edi:  at -12(%ebp)
+                chr(self.LOC_EBP_PLUS  | 0),    # saved %ebp:  at    (%ebp)
+                chr(0)]
+
+    def _encode_num(self, shape, number):
+        assert number >= 0
+        flag = 0
+        while number >= 0x80:
+            shape.append(chr((number & 0x7F) | flag))
+            flag = 0x80
+            number >>= 7
+        shape.append(chr(number | flag))
 
     def add_ebp_offset(self, shape, offset):
         assert (offset & 3) == 0
         if offset >= 0:
-            encoded = self.LOC_EBP_PLUS | offset
+            num = self.LOC_EBP_PLUS | offset
         else:
-            encoded = self.LOC_EBP_MINUS | (-offset)
-        shape.append(encoded)
+            num = self.LOC_EBP_MINUS | (-offset)
+        self._encode_num(shape, num)
 
     def add_ebx(self, shape):
-        shape.append(self.LOC_REG | 4)
+        shape.append(chr(self.LOC_REG | 4))
 
     def add_esi(self, shape):
-        shape.append(self.LOC_REG | 8)
+        shape.append(chr(self.LOC_REG | 8))
 
     def add_edi(self, shape):
-        shape.append(self.LOC_REG | 12)
+        shape.append(chr(self.LOC_REG | 12))
 
     def add_ebp(self, shape):
-        shape.append(self.LOC_REG | 16)
+        shape.append(chr(self.LOC_REG | 16))
 
     def compress_callshape(self, shape):
-        # Similar to compress_callshape() in trackgcroot.py.  XXX a bit slowish
-        result = []
-        for loc in shape:
-            assert loc >= 0
-            flag = 0
-            while loc >= 0x80:
-                result.append(int(loc & 0x7F) | flag)
-                flag = 0x80
-                loc >>= 7
-            result.append(int(loc) | flag)
+        # Similar to compress_callshape() in trackgcroot.py.
         # XXX so far, we always allocate a new small array (we could regroup
         # them inside bigger arrays) and we never try to share them.
-        length = len(result)
+        length = len(shape)
         compressed = lltype.malloc(self.CALLSHAPE_ARRAY, length,
                                    flavor='raw')
         for i in range(length):
-            compressed[length-1-i] = rffi.cast(rffi.UCHAR, result[i])
+            compressed[length-1-i] = rffi.cast(rffi.UCHAR, shape[i])
         return llmemory.cast_ptr_to_adr(compressed)
 
 

Modified: pypy/trunk/pypy/jit/backend/llsupport/test/test_gc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llsupport/test/test_gc.py	(original)
+++ pypy/trunk/pypy/jit/backend/llsupport/test/test_gc.py	Fri Mar  5 10:01:40 2010
@@ -65,27 +65,32 @@
         return -4*(4+n)
     gcrootmap = GcRootMap_asmgcc()
     num1 = frame_pos(-5)
+    num1a = num1|2
     num2 = frame_pos(55)
+    num2a = ((-num2|3) >> 7) | 128
+    num2b = (-num2|3) & 127
     shape = gcrootmap.get_basic_shape()
     gcrootmap.add_ebp_offset(shape, num1)
     gcrootmap.add_ebp_offset(shape, num2)
-    assert shape == [6, 7, 11, 15, 2, 0, num1|2, -num2|3]
+    assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a])
     gcrootmap.add_ebx(shape)
-    assert shape == [6, 7, 11, 15, 2, 0, num1|2, -num2|3, 4]
+    assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a,
+                              4])
     gcrootmap.add_esi(shape)
-    assert shape == [6, 7, 11, 15, 2, 0, num1|2, -num2|3, 4, 8]
+    assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a,
+                              4, 8])
     gcrootmap.add_edi(shape)
-    assert shape == [6, 7, 11, 15, 2, 0, num1|2, -num2|3, 4, 8, 12]
+    assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a,
+                              4, 8, 12])
     gcrootmap.add_ebp(shape)
-    assert shape == [6, 7, 11, 15, 2, 0, num1|2, -num2|3, 4, 8, 12, 16]
+    assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a,
+                              4, 8, 12, 16])
     #
     shapeaddr = gcrootmap.compress_callshape(shape)
     PCALLSHAPE = lltype.Ptr(GcRootMap_asmgcc.CALLSHAPE_ARRAY)
     p = llmemory.cast_adr_to_ptr(shapeaddr, PCALLSHAPE)
-    num2a = ((-num2|3) >> 7) | 128
-    num2b = (-num2|3) & 127
     for i, expected in enumerate([16, 12, 8, 4,
-                                  num2a, num2b, num1|2, 0, 2, 15, 11, 7, 6]):
+                                  num2a, num2b, num1a, 0, 2, 15, 11, 7, 6]):
         assert p[i] == expected
     #
     retaddr = rffi.cast(llmemory.Address, 1234567890)



More information about the Pypy-commit mailing list