[pypy-svn] r77305 - in pypy/branch/jit-str/pypy/jit/backend: test x86

arigo at codespeak.net arigo at codespeak.net
Thu Sep 23 17:20:14 CEST 2010


Author: arigo
Date: Thu Sep 23 17:20:13 2010
New Revision: 77305

Modified:
   pypy/branch/jit-str/pypy/jit/backend/test/runner_test.py
   pypy/branch/jit-str/pypy/jit/backend/x86/assembler.py
   pypy/branch/jit-str/pypy/jit/backend/x86/codebuf.py
   pypy/branch/jit-str/pypy/jit/backend/x86/regalloc.py
Log:
Test and code for COPYSTRCONTENT in the x86 backend.


Modified: pypy/branch/jit-str/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/jit-str/pypy/jit/backend/test/runner_test.py	Thu Sep 23 17:20:13 2010
@@ -814,6 +814,17 @@
         r = self.execute_operation(rop.STRGETITEM, [s_box, BoxInt(4)], 'int')
         assert r.value == 153
 
+    def test_copystrcontent(self):
+        s_box = self.alloc_string("abcdef")
+        for srcstart_box in [BoxInt(2), ConstInt(2)]:
+            for dststart_box in [BoxInt(3), ConstInt(3)]:
+                for length_box in [BoxInt(4), ConstInt(4)]:
+                    r_box = self.alloc_string("!???????!")
+                    self.execute_operation(rop.COPYSTRCONTENT,
+                                           [s_box, r_box, srcstart_box,
+                                            dststart_box, length_box], 'void')
+                    assert self.look_string(r_box) == "!??cdef?!"
+
     def test_do_unicode_basic(self):
         u = self.cpu.bh_newunicode(5)
         self.cpu.bh_unicodesetitem(u, 4, 123)
@@ -1197,6 +1208,10 @@
         s_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
         return s_box
 
+    def look_string(self, string_box):
+        s = string_box.getref(lltype.Ptr(rstr.STR))
+        return ''.join(s.chars)
+
     def alloc_unicode(self, unicode):
         u = rstr.mallocunicode(len(unicode))
         for i in range(len(unicode)):

Modified: pypy/branch/jit-str/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/jit-str/pypy/jit/backend/x86/assembler.py	Thu Sep 23 17:20:13 2010
@@ -181,6 +181,7 @@
         self.malloc_fixedsize_slowpath1 = 0
         self.malloc_fixedsize_slowpath2 = 0
         self.pending_guard_tokens = None
+        self.memcpy_addr = 0
         self.setup_failure_recovery()
         self._debug = False
         self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i')
@@ -212,6 +213,7 @@
                 ll_new_unicode = gc_ll_descr.get_funcptr_for_newunicode()
                 self.malloc_unicode_func_addr = rffi.cast(lltype.Signed,
                                                           ll_new_unicode)
+            self.memcpy_addr = self.cpu.cast_ptr_to_int(codebuf.memcpy_fn)
             self.mc = MachineCodeBlockWrapper(self, self.mc_size, self.cpu.profile_agent)
             self._build_failure_recovery(False)
             self._build_failure_recovery(True)
@@ -712,8 +714,8 @@
         self.regalloc_perform_with_guard(None, guard_op, faillocs, arglocs,
                                          resloc, current_depths)
 
-    def load_effective_addr(self, sizereg, baseofs, scale, result):
-        self.mc.LEA(result, addr_add(imm(0), sizereg, baseofs, scale))
+    def load_effective_addr(self, sizereg, baseofs, scale, result, frm=imm(0)):
+        self.mc.LEA(result, addr_add(frm, sizereg, baseofs, scale))
 
     def _unaryop(asmop):
         def genop_unary(self, op, arglocs, resloc):

Modified: pypy/branch/jit-str/pypy/jit/backend/x86/codebuf.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/backend/x86/codebuf.py	(original)
+++ pypy/branch/jit-str/pypy/jit/backend/x86/codebuf.py	Thu Sep 23 17:20:13 2010
@@ -1,6 +1,6 @@
 
 import os, sys
-from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.jit.backend.x86.rx86 import X86_32_CodeBuilder, X86_64_CodeBuilder
 from pypy.jit.backend.x86.regloc import LocationCodeBuilder
@@ -158,6 +158,12 @@
 
 # ____________________________________________________________
 
+memcpy_fn = rffi.llexternal('memcpy', [llmemory.Address, llmemory.Address,
+                                       rffi.SIZE_T], lltype.Void,
+                            sandboxsafe=True, _nowrapper=True)
+
+# ____________________________________________________________
+
 if sys.platform == 'win32':
     ensure_sse2_floats = lambda : None
 else:

Modified: pypy/branch/jit-str/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/jit-str/pypy/jit/backend/x86/regalloc.py	Thu Sep 23 17:20:13 2010
@@ -936,6 +936,39 @@
 
     consider_unicodegetitem = consider_strgetitem
 
+    def consider_copystrcontent(self, op):
+        # compute the source address
+        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.args[2], op.args)
+        self.rm.possibly_free_var(op.args[0])
+        self.rm.possibly_free_var(op.args[2])
+        srcaddr_box = TempBox()
+        srcaddr_loc = self.rm.force_allocate_reg(srcaddr_box)
+        self._gen_address_inside_string(base_loc, ofs_loc, srcaddr_loc)
+        # compute the destination address
+        base_loc = self.rm.make_sure_var_in_reg(op.args[1], op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.args[3], op.args)
+        self.rm.possibly_free_var(op.args[1])
+        self.rm.possibly_free_var(op.args[3])
+        dstaddr_box = TempBox()
+        dstaddr_loc = self.rm.force_allocate_reg(dstaddr_box)
+        self._gen_address_inside_string(base_loc, ofs_loc, dstaddr_loc)
+        # call memcpy()
+        length_loc = self.loc(op.args[4])
+        self.assembler._emit_call(imm(self.assembler.memcpy_addr),
+                                  [dstaddr_loc, srcaddr_loc, length_loc])
+        self.rm.possibly_free_var(op.args[4])
+        self.rm.possibly_free_var(dstaddr_box)
+        self.rm.possibly_free_var(srcaddr_box)
+
+    def _gen_address_inside_string(self, baseloc, ofsloc, resloc):
+        cpu = self.assembler.cpu
+        ofs_items, itemsize, _ = symbolic.get_array_token(rstr.STR,
+                                                  self.translate_support_code)
+        assert itemsize == 1
+        self.assembler.load_effective_addr(ofsloc, ofs_items, 0,
+                                           resloc, baseloc)
+
     def consider_jump(self, op):
         assembler = self.assembler
         assert self.jump_target_descr is None



More information about the Pypy-commit mailing list