[pypy-svn] r68143 - in pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86: . test

arigo at codespeak.net arigo at codespeak.net
Sun Oct 4 16:55:01 CEST 2009


Author: arigo
Date: Sun Oct  4 16:54:59 2009
New Revision: 68143

Modified:
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/assembler.py
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/codebuf.py
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/jump.py
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/ri386.py
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386.py
   pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py
Log:
Add some more instructions.  Start converting assembler.py,
but I should soon throw away these changes and start from
a fresh copy from trunk.


Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/assembler.py	Sun Oct  4 16:54:59 2009
@@ -10,12 +10,12 @@
 from pypy.jit.backend.x86.regalloc import (RegAlloc, WORD, REGS, TempBox,
                                            lower_byte, stack_pos)
 from pypy.rlib.objectmodel import we_are_translated, specialize
-from pypy.jit.backend.x86 import codebuf
-from pypy.jit.backend.x86.ri386 import *
+from pypy.jit.backend.x86 import codebuf, ri386
+from pypy.jit.backend.x86.ri386 import WORD
+from pypy.jit.backend.x86.ri386 import eax, ecx, edx, ebx, esp, ebp, esi, edi
 from pypy.jit.metainterp.resoperation import rop
 
 
-
 # our calling convention - we pass first 6 args in registers
 # and the rest stays on the stack
 
@@ -59,9 +59,8 @@
     method.func_name = name
     return method
 
-for name in dir(codebuf.MachineCodeBlock):
-    if name.upper() == name:
-        setattr(MachineCodeBlockWrapper, name, _new_method(name))
+for name in ri386.all_instructions:
+    setattr(MachineCodeBlockWrapper, name, _new_method(name))
 
 class ExecutableToken386(object):
     _x86_loop_code = 0
@@ -177,28 +176,28 @@
 
     def _patchable_stackadjust(self):
         # stack adjustment LEA
-        self.mc.LEA(esp, fixedsize_ebp_ofs(0))
+        self.mc.LEA32_rs(esp, 0)
         return self.mc.tell() - 4
 
     def _patch_stackadjust(self, adr_lea, stack_depth):
         # patch stack adjustment LEA
         # possibly align, e.g. for Mac OS X        
         mc = codebuf.InMemoryCodeBuilder(adr_lea, adr_lea + 4)
-        mc.write(packimm32(-(stack_depth + RET_BP - 2) * WORD))
+        mc.writeimm32(-(stack_depth + RET_BP - 2) * WORD)
         mc.done()
 
     def _assemble_bootstrap_code(self, inputargs, arglocs):
-        self.mc.PUSH(ebp)
-        self.mc.MOV(ebp, esp)
-        self.mc.PUSH(ebx)
-        self.mc.PUSH(esi)
-        self.mc.PUSH(edi)
+        self.mc.PUSH_r(ebp)
+        self.mc.MOV_rr(ebp, esp)
+        self.mc.PUSH_r(ebx)
+        self.mc.PUSH_r(esi)
+        self.mc.PUSH_r(edi)
         # NB. exactly 4 pushes above; if this changes, fix stack_pos().
         # You must also keep _get_callshape() in sync.
         adr_stackadjust = self._patchable_stackadjust()
         for i in range(len(arglocs)):
             loc = arglocs[i]
-            if not isinstance(loc, REG):
+            if is_stack(loc):
                 if inputargs[i].type == REF:
                     # This uses XCHG to put zeroes in fail_boxes_ptr after
                     # reading them
@@ -825,3 +824,9 @@
         return heap(reg_or_imm1.value + offset)
     else:
         return mem(reg_or_imm1, offset)
+
+def is_reg(loc):
+    return loc >= 0
+
+def is_stack(loc):
+    return loc < 0

Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/codebuf.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/codebuf.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/codebuf.py	Sun Oct  4 16:54:59 2009
@@ -3,6 +3,7 @@
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.jit.backend.x86.ri386 import I386CodeBuilder
 from pypy.rlib.rmmap import PTR, alloc, free
+from pypy.rlib.debug import ll_assert
 
 
 class InMemoryCodeBuilder(I386CodeBuilder):
@@ -18,15 +19,11 @@
         self._size = map_size
         self._pos = 0
 
-    def overwrite(self, pos, data):
-        assert pos + len(data) <= self._size
-        for c in data:
-            self._data[pos] = c
-            pos += 1
-        return pos
-
-    def write(self, data):
-        self._pos = self.overwrite(self._pos, data)
+    def writechar(self, char):
+        pos = self._pos
+        ll_assert(pos < self._size, "buffer overflow in codebuf.py")
+        self._data[pos] = char
+        self._pos = pos + 1
 
     def get_relative_pos(self):
         return self._pos

Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/jump.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/jump.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/jump.py	Sun Oct  4 16:54:59 2009
@@ -2,15 +2,15 @@
 from pypy.tool.pairtype import extendabletype
 from pypy.jit.backend.x86.ri386 import *
 
-class __extend__(REG):
-    __metaclass__ = extendabletype
-    def _getregkey(self):
-        return ~self.op
-
-class __extend__(MODRM):
-    __metaclass__ = extendabletype
-    def _getregkey(self):
-        return self.position
+##class __extend__(REG):
+##    __metaclass__ = extendabletype
+##    def _getregkey(self):
+##        return ~self.op
+
+##class __extend__(MODRM):
+##    __metaclass__ = extendabletype
+##    def _getregkey(self):
+##        return self.position
 
 
 def remap_stack_layout(assembler, src_locations, dst_locations, tmpreg):

Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/ri386.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/ri386.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/ri386.py	Sun Oct  4 16:54:59 2009
@@ -65,8 +65,8 @@
     return -128 <= value < 128
 
 @specialize.arg(2)
-def encode_stack(mc, arg, allow_single_byte, orbyte):
-    if allow_single_byte and single_byte(arg):
+def encode_stack(mc, arg, force_32bits, orbyte):
+    if not force_32bits and single_byte(arg):
         mc.writechar(chr(0x40 | ebp | orbyte))
         mc.writeimm8(arg)
     else:
@@ -74,8 +74,8 @@
         mc.writeimm32(arg)
     return 0
 
-def stack(argnum, allow_single_byte=True):
-    return encode_stack, argnum, allow_single_byte
+def stack(argnum, force_32bits=False):
+    return encode_stack, argnum, force_32bits
 
 # ____________________________________________________________
 
@@ -153,3 +153,14 @@
 
     NOP = insn('\x90')
     RET = insn('\xC3')
+
+    PUSH_r = insn(register(1), '\x50')
+
+    LEA_rs = insn('\x8D', register(1,8), stack(2))
+    LEA32_rs = insn('\x8D', register(1,8), stack(2, force_32bits=True))
+
+# ____________________________________________________________
+
+all_instructions = [name for name in I386CodeBuilder.__dict__
+                    if name.split('_')[0].isupper()]
+all_instructions.sort()

Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386.py	Sun Oct  4 16:54:59 2009
@@ -6,7 +6,7 @@
         self.buffer = []
 
     def writechar(self, c):
-        self.buffer.append(c)    # extend the list of characters
+        self.buffer.append(c)    # append a character
 
     def getvalue(self):
         return ''.join(self.buffer)
@@ -42,3 +42,13 @@
     s.NOP()
     s.ADD_rr(eax, eax)
     assert s.getvalue() == '\x90\x01\xC0'
+
+def test_lea_rs():
+    s = CodeBuilder()
+    s.LEA_rs(ecx, -36)
+    assert s.getvalue() == '\x8D\x4D\xDC'
+
+def test_lea32_rs():
+    s = CodeBuilder()
+    s.LEA32_rs(ecx, -36)
+    assert s.getvalue() == '\x8D\x8D\xDC\xFF\xFF\xFF'

Modified: pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py
==============================================================================
--- pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py	(original)
+++ pypy/branch/remove-ri386-multimethod/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py	Sun Oct  4 16:54:59 2009
@@ -3,8 +3,8 @@
 from pypy.jit.backend.x86 import ri386
 from pypy.tool.udir import udir
 
-INPUTNAME = str(udir.join('checkfile.s'))
-FILENAME = str(udir.join('checkfile.tmp'))
+INPUTNAME = str(udir.join('checkfile_%s.s'))
+FILENAME = str(udir.join('checkfile_%s.o'))
 BEGIN_TAG = '<<<ri386-test-begin>>>'
 END_TAG =   '<<<ri386-test-end>>>'
 
@@ -77,10 +77,7 @@
     return regnames[regnum]
 
 def assembler_operand_stack(position):
-    if position == 0:
-        return '(%ebp)'
-    else:
-        return '%d(%%ebp)' % position
+    return '%d(%%ebp)' % position
 
 def assembler_operand_imm(value):
     return '$%d' % value
@@ -91,11 +88,11 @@
     'i': assembler_operand_imm,
     }
 
-def run_test(instrname, argmodes, args_lists):
+def run_test(methname, instrname, argmodes, args_lists):
     global labelcount
     labelcount = 0
     oplist = []
-    g = open(INPUTNAME, 'w')
+    g = open(INPUTNAME % methname, 'w')
     g.write('\x09.string "%s"\n' % BEGIN_TAG)
     for args in args_lists:
         suffix = ""
@@ -132,9 +129,9 @@
         oplist.append(op)
     g.write('\t.string "%s"\n' % END_TAG)
     g.close()
-    os.system('as "%s" -o "%s"' % (INPUTNAME, FILENAME))
+    os.system('as "%s" -o "%s"' % (INPUTNAME % methname, FILENAME % methname))
     try:
-        f = open(FILENAME, 'rb')
+        f = open(FILENAME % methname, 'rb')
     except IOError:
         raise Exception("Assembler error")
     data = f.read()
@@ -227,7 +224,7 @@
         instrname, argmodes = methname, ''
     print "Testing %s with argmodes=%r" % (instrname, argmodes)
     ilist = make_all_tests(methname, argmodes)
-    oplist, as_code = run_test(instrname, argmodes, ilist)
+    oplist, as_code = run_test(methname, instrname, argmodes, ilist)
     cc = CodeChecker(as_code)
     for op, args in zip(oplist, ilist):
         if op:
@@ -246,12 +243,10 @@
     def do_test(name):
         if name in ('CMOVPE', 'CMOVPO'):
             py.test.skip("why doesn't 'as' know about CMOVPE/CMOVPO?")
+        if name.split('_')[0][-1].isdigit():
+            print "artificial instruction: %r" % (name,)
+            return
         complete_test(name)
 
-    for name in all_instructions:
+    for name in ri386.all_instructions:
         yield do_test, name
-
-
-all_instructions = [name for name in ri386.I386CodeBuilder.__dict__
-                    if name.split('_')[0].isupper()]
-all_instructions.sort()



More information about the Pypy-commit mailing list