[pypy-svn] r70214 - in pypy/trunk/pypy/jit/backend/x86: . test

arigo at codespeak.net arigo at codespeak.net
Sun Dec 20 11:35:01 CET 2009


Author: arigo
Date: Sun Dec 20 11:34:59 2009
New Revision: 70214

Modified:
   pypy/trunk/pypy/jit/backend/x86/assembler.py
   pypy/trunk/pypy/jit/backend/x86/regalloc.py
   pypy/trunk/pypy/jit/backend/x86/test/test_regalloc.py
Log:
Argh.  We allocate 8KB of space for float constants, and we forget
about it between each block of code.  This means that most blocks
(loops and branches) consumed 8KB of extra space for nothing.


Modified: pypy/trunk/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/assembler.py	Sun Dec 20 11:34:59 2009
@@ -75,6 +75,7 @@
     mc = None
     mc2 = None
     mc_size = MachineCodeBlockWrapper.MC_DEFAULT_SIZE
+    _float_constants = None
 
     def __init__(self, cpu, translate_support_code=False,
                             failargs_limit=1000):

Modified: pypy/trunk/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/regalloc.py	Sun Dec 20 11:34:59 2009
@@ -52,7 +52,28 @@
             print "convert_to_imm: got a %s" % c
             raise AssertionError
 
-BASE_CONSTANT_SIZE = 1000
+
+class FloatConstants(object):
+    BASE_CONSTANT_SIZE = 1000
+
+    def __init__(self):
+        self.cur_array_free = 0
+
+    def _get_new_array(self):
+        n = self.BASE_CONSTANT_SIZE
+        self.cur_array = lltype.malloc(rffi.CArray(lltype.Float), n,
+                                       flavor='raw')
+        self.cur_array_free = n
+    _get_new_array._dont_inline_ = True
+
+    def record_float(self, floatval):
+        if self.cur_array_free == 0:
+            self._get_new_array()
+        arr = self.cur_array
+        n = self.cur_array_free - 1
+        arr[n] = floatval
+        self.cur_array_free = n
+        return rffi.cast(lltype.Signed, arr) + n * 8
 
 
 class X86XMMRegisterManager(RegisterManager):
@@ -63,29 +84,19 @@
     save_around_call_regs = all_regs
     reg_width = 2
 
-    def new_const_array(self):
-        return lltype.malloc(rffi.CArray(lltype.Float), BASE_CONSTANT_SIZE,
-                             flavor='raw')
-
     def __init__(self, longevity, frame_manager=None, assembler=None):
         RegisterManager.__init__(self, longevity, frame_manager=frame_manager,
                                  assembler=assembler)
-        self.constant_arrays = [self.new_const_array()]
-        self.constant_array_counter = 0
+        if assembler is None:
+            self.float_constants = FloatConstants()
+        else:
+            if assembler._float_constants is None:
+                assembler._float_constants = FloatConstants()
+            self.float_constants = assembler._float_constants
 
     def convert_to_imm(self, c):
-        if self.constant_array_counter >= BASE_CONSTANT_SIZE:
-            self.constant_arrays.append(self.new_const_array())
-            self.constant_array_counter = 0
-        res = self.constant_array_counter
-        self.constant_array_counter += 1
-        arr = self.constant_arrays[-1]
-        arr[res] = c.getfloat()
-        return self.get_addr_of_const_float(-1, res)
-
-    def get_addr_of_const_float(self, num_arr, num_pos):
-        arr = self.constant_arrays[num_arr]
-        return heap64(rffi.cast(lltype.Signed, arr) + num_pos * WORD * 2)
+        adr = self.float_constants.record_float(c.getfloat())
+        return heap64(adr)
         
     def after_call(self, v):
         # the result is stored in st0, but we don't have this around,

Modified: pypy/trunk/pypy/jit/backend/x86/test/test_regalloc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/test/test_regalloc.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/test/test_regalloc.py	Sun Dec 20 11:34:59 2009
@@ -9,7 +9,7 @@
 from pypy.jit.backend.llsupport.descr import GcCache
 from pypy.jit.backend.x86.runner import CPU
 from pypy.jit.backend.x86.regalloc import RegAlloc, WORD, X86RegisterManager,\
-     BASE_CONSTANT_SIZE
+     FloatConstants
 from pypy.jit.metainterp.test.oparser import parse
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.annlowlevel import llhelper
@@ -503,6 +503,7 @@
 
     def test_float_overflow_const_list(self):
         ops = ['[f0]']
+        BASE_CONSTANT_SIZE = FloatConstants.BASE_CONSTANT_SIZE
         for i in range(BASE_CONSTANT_SIZE * 2):
             ops.append('f%d = float_add(f%d, 3.5)' % (i + 1, i))
         ops.append('finish(f%d)' % (BASE_CONSTANT_SIZE * 2))



More information about the Pypy-commit mailing list