[pypy-svn] r72202 - in pypy/branch/jit-newx86/pypy/jit/backend/newx86: . test

arigo at codespeak.net arigo at codespeak.net
Sat Mar 13 16:56:05 CET 2010


Author: arigo
Date: Sat Mar 13 16:56:03 2010
New Revision: 72202

Added:
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/   (props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/__init__.py   (contents, props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/assembler.py   (contents, props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/runner.py   (contents, props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/rx86.py
      - copied, changed from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/rx86.py
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/   (props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/__init__.py   (contents, props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_runner.py   (contents, props changed)
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86.py
      - copied, changed from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86.py
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_32_auto_encoding.py
      - copied, changed from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_32_auto_encoding.py
   pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_64_auto_encoding.py
      - copied, changed from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_64_auto_encoding.py
Log:
Add again rx86.py and associated test files.  This time, rx86 was
modified to generate code in the other order, i.e. starting from the
end.


Added: pypy/branch/jit-newx86/pypy/jit/backend/newx86/__init__.py
==============================================================================

Added: pypy/branch/jit-newx86/pypy/jit/backend/newx86/assembler.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/assembler.py	Sat Mar 13 16:56:03 2010
@@ -0,0 +1,18 @@
+from pypy.jit.backend.newx86.rx86 import R
+
+
+class Assembler386(object):
+
+    def __init__(self, cpu):
+        self.cpu = cpu
+        self.locations = {}
+
+    def compile_loop(self, inputargs, operations, looptoken):
+        xxx
+
+
+def is_reg(loc):
+    return loc >= 0
+
+def is_stack(loc):
+    return loc < 0

Added: pypy/branch/jit-newx86/pypy/jit/backend/newx86/runner.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/runner.py	Sat Mar 13 16:56:03 2010
@@ -0,0 +1,20 @@
+from pypy.jit.backend.llsupport.llmodel import AbstractLLCPU
+from pypy.jit.backend.newx86.assembler import Assembler386
+
+
+class CPU(AbstractLLCPU):
+
+    def __init__(self, rtyper, stats, opts=None, translate_support_code=False,
+                 gcdescr=None):
+        AbstractLLCPU.__init__(self, rtyper, stats, opts,
+                               translate_support_code, gcdescr)
+        if opts is not None:
+            self.failargs_limit = opts.failargs_limit
+        else:
+            self.failargs_limit = 1000
+
+    def compile_loop(self, inputargs, operations, looptoken):
+        """Assemble the given loop, and update looptoken to point to
+        the compiled loop in assembler."""
+        assembler = Assembler386(self)
+        assembler.compile_loop(inputargs, operations, looptoken)

Copied: pypy/branch/jit-newx86/pypy/jit/backend/newx86/rx86.py (from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/rx86.py)
==============================================================================
--- pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/rx86.py	(original)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/rx86.py	Sat Mar 13 16:56:03 2010
@@ -98,7 +98,7 @@
 
 def encode_relative(mc, target, _, orbyte):
     assert orbyte == 0
-    offset = target - (mc.tell() + 4)
+    offset = target - mc.tell()
     mc.writeimm32(offset)
     return 0
 
@@ -111,11 +111,11 @@
 @specialize.arg(2)
 def encode_stack_bp(mc, offset, force_32bits, orbyte):
     if not force_32bits and single_byte(offset):
-        mc.writechar(chr(0x40 | orbyte | R.ebp))
         mc.writeimm8(offset)
+        mc.writechar(chr(0x40 | orbyte | R.ebp))
     else:
-        mc.writechar(chr(0x80 | orbyte | R.ebp))
         mc.writeimm32(offset)
+        mc.writechar(chr(0x80 | orbyte | R.ebp))
     return 0
 
 def stack_bp(argnum, force_32bits=False):
@@ -127,16 +127,16 @@
 def encode_stack_sp(mc, offset, _, orbyte):
     SIB = chr((R.esp<<3) | R.esp)    #   use [esp+(no index)+offset]
     if offset == 0:
-        mc.writechar(chr(0x04 | orbyte))
         mc.writechar(SIB)
+        mc.writechar(chr(0x04 | orbyte))
     elif single_byte(offset):
-        mc.writechar(chr(0x44 | orbyte))
-        mc.writechar(SIB)
         mc.writeimm8(offset)
-    else:
-        mc.writechar(chr(0x84 | orbyte))
         mc.writechar(SIB)
+        mc.writechar(chr(0x44 | orbyte))
+    else:
         mc.writeimm32(offset)
+        mc.writechar(SIB)
+        mc.writechar(chr(0x84 | orbyte))
     return 0
 
 def stack_sp(argnum):
@@ -160,16 +160,16 @@
             no_offset = False
     # end of 64-bits special cases
     if no_offset:
-        mc.writechar(chr(0x00 | orbyte | reg1))
         if SIB >= 0: mc.writechar(chr(SIB))
+        mc.writechar(chr(0x00 | orbyte | reg1))
     elif single_byte(offset):
-        mc.writechar(chr(0x40 | orbyte | reg1))
-        if SIB >= 0: mc.writechar(chr(SIB))
         mc.writeimm8(offset)
-    else:
-        mc.writechar(chr(0x80 | orbyte | reg1))
         if SIB >= 0: mc.writechar(chr(SIB))
+        mc.writechar(chr(0x40 | orbyte | reg1))
+    else:
         mc.writeimm32(offset)
+        if SIB >= 0: mc.writechar(chr(SIB))
+        mc.writechar(chr(0x80 | orbyte | reg1))
     return 0
 
 def rex_mem_reg_plus_const(mc, (reg, offset), _):
@@ -201,16 +201,16 @@
             no_offset = False
     # end of 64-bits special case
     if no_offset:
-        mc.writechar(chr(0x04 | orbyte))
         mc.writechar(SIB)
+        mc.writechar(chr(0x04 | orbyte))
     elif single_byte(offset):
-        mc.writechar(chr(0x44 | orbyte))
-        mc.writechar(SIB)
         mc.writeimm8(offset)
-    else:
-        mc.writechar(chr(0x84 | orbyte))
         mc.writechar(SIB)
+        mc.writechar(chr(0x44 | orbyte))
+    else:
         mc.writeimm32(offset)
+        mc.writechar(SIB)
+        mc.writechar(chr(0x84 | orbyte))
     return 0
 
 def rex_mem_reg_plus_scaled_reg_plus_const(mc,
@@ -250,20 +250,17 @@
 
 def insn(*encoding):
     def encode(mc, *args):
-        rexbyte = 0
-        if mc.WORD == 8:
-            # compute the REX byte, if any
-            for encode_step, arg, extra, rex_step in encoding_steps:
-                if rex_step:
-                    if arg is not None:
-                        arg = args[arg-1]
-                    rexbyte |= rex_step(mc, arg, extra)
-        args = (rexbyte,) + args
         # emit the bytes of the instruction
+        rexbyte = 0
         orbyte = 0
         for encode_step, arg, extra, rex_step in encoding_steps:
             if arg is not None:
-                arg = args[arg]
+                if arg == 0:
+                    arg = rexbyte
+                else:
+                    arg = args[arg-1]
+            if rex_step and mc.WORD == 8:
+                rexbyte |= rex_step(mc, arg, extra)
             orbyte = encode_step(mc, arg, extra, orbyte)
         assert orbyte == 0
     #
@@ -275,6 +272,7 @@
         else:
             assert type(step) is tuple and len(step) == 4
             encoding_steps.append(step)
+    encoding_steps.reverse()
     encoding_steps = unrolling_iterable(encoding_steps)
     return encode
 
@@ -286,13 +284,13 @@
 def common_modes(group):
     base = group * 8
     char = chr(0xC0 | base)
-    INSN_ri8 = insn(rex_w, '\x83', register(1), char, immediate(2,'b'))
-    INSN_ri32= insn(rex_w, '\x81', register(1), char, immediate(2))
-    INSN_rr = insn(rex_w, chr(base+1), register(2,8), register(1,1), '\xC0')
-    INSN_br = insn(rex_w, chr(base+1), register(2,8), stack_bp(1))
-    INSN_rb = insn(rex_w, chr(base+3), register(1,8), stack_bp(2))
-    INSN_bi8 = insn(rex_w, '\x83', orbyte(base), stack_bp(1), immediate(2,'b'))
-    INSN_bi32= insn(rex_w, '\x81', orbyte(base), stack_bp(1), immediate(2))
+    INSN_ri8 = insn(rex_w, '\x83', char, register(1), immediate(2,'b'))
+    INSN_ri32= insn(rex_w, '\x81', char, register(1), immediate(2))
+    INSN_rr = insn(rex_w, chr(base+1), '\xC0', register(2,8), register(1,1))
+    INSN_br = insn(rex_w, chr(base+1), stack_bp(1), register(2,8))
+    INSN_rb = insn(rex_w, chr(base+3), stack_bp(2), register(1,8))
+    INSN_bi8 = insn(rex_w, '\x83', stack_bp(1), orbyte(base), immediate(2,'b'))
+    INSN_bi32= insn(rex_w, '\x81', stack_bp(1), orbyte(base), immediate(2))
 
     def INSN_ri(mc, reg, immed):
         if single_byte(immed):
@@ -323,38 +321,38 @@
         self.writechar(chr(imm & 0xFF))
 
     def writeimm16(self, imm):
-        self.writechar(chr(imm & 0xFF))
         self.writechar(chr((imm >> 8) & 0xFF))
+        self.writechar(chr(imm & 0xFF))
 
     def writeimm32(self, imm):
         assert fits_in_32bits(imm)
-        self.writechar(chr(imm & 0xFF))
-        self.writechar(chr((imm >> 8) & 0xFF))
-        self.writechar(chr((imm >> 16) & 0xFF))
         self.writechar(chr((imm >> 24) & 0xFF))
+        self.writechar(chr((imm >> 16) & 0xFF))
+        self.writechar(chr((imm >> 8) & 0xFF))
+        self.writechar(chr(imm & 0xFF))
 
     # ------------------------------ MOV ------------------------------
 
-    MOV_ri = insn(rex_w, register(1), '\xB8', immediate(2, 'q'))
-    MOV_rr = insn(rex_w, '\x89', register(2,8), register(1), '\xC0')
-    MOV_br = insn(rex_w, '\x89', register(2,8), stack_bp(1))
-    MOV_rb = insn(rex_w, '\x8B', register(1,8), stack_bp(2))
+    MOV_ri = insn(rex_w, '\xB8', register(1), immediate(2, 'q'))
+    MOV_rr = insn(rex_w, '\x89', '\xC0', register(2,8), register(1))
+    MOV_br = insn(rex_w, '\x89', stack_bp(1), register(2,8))
+    MOV_rb = insn(rex_w, '\x8B', stack_bp(2), register(1,8))
 
     # "MOV reg1, [reg2+offset]" and the opposite direction
-    MOV_rm = insn(rex_w, '\x8B', register(1,8), mem_reg_plus_const(2))
-    MOV_mr = insn(rex_w, '\x89', register(2,8), mem_reg_plus_const(1))
-    MOV_mi = insn(rex_w, '\xC7', orbyte(0<<3), mem_reg_plus_const(1),
-                                               immediate(2, 'i'))
+    MOV_rm = insn(rex_w, '\x8B', mem_reg_plus_const(2), register(1,8))
+    MOV_mr = insn(rex_w, '\x89', mem_reg_plus_const(1), register(2,8))
+    MOV_mi = insn(rex_w, '\xC7', mem_reg_plus_const(1), orbyte(0<<3),
+                                 immediate(2, 'i'))
 
     # "MOV reg1, [reg2+reg3*scale+offset]" and the opposite direction
-    MOV_ra = insn(rex_w, '\x8B', register(1,8),
-                                 mem_reg_plus_scaled_reg_plus_const(2))
-    MOV_ar = insn(rex_w, '\x89', register(2,8),
-                                 mem_reg_plus_scaled_reg_plus_const(1))
+    MOV_ra = insn(rex_w, '\x8B', mem_reg_plus_scaled_reg_plus_const(2),
+                                 register(1,8))
+    MOV_ar = insn(rex_w, '\x89', mem_reg_plus_scaled_reg_plus_const(1),
+                                 register(2,8))
 
     # "MOV reg1, [immediate2]" and the opposite direction
-    MOV_rj = insn(rex_w, '\x8B', register(1,8), '\x05', immediate(2))
-    MOV_jr = insn(rex_w, '\x89', register(2,8), '\x05', immediate(1))
+    MOV_rj = insn(rex_w, '\x8B', '\x05', register(1,8), immediate(2))
+    MOV_jr = insn(rex_w, '\x89', '\x05', register(2,8), immediate(1))
 
     # ------------------------------ Arithmetic ------------------------------
 
@@ -370,34 +368,33 @@
     NOP = insn('\x90')
     RET = insn('\xC3')
 
-    PUSH_r = insn(rex_nw, register(1), '\x50')
-    POP_r = insn(rex_nw, register(1), '\x58')
+    PUSH_r = insn(rex_nw, '\x50', register(1))
+    POP_r = insn(rex_nw, '\x58', register(1))
 
-    LEA_rb = insn(rex_w, '\x8D', register(1,8), stack_bp(2))
-    LEA32_rb = insn(rex_w, '\x8D', register(1,8),stack_bp(2,force_32bits=True))
+    LEA_rb = insn(rex_w, '\x8D', stack_bp(2), register(1,8))
+    LEA32_rb = insn(rex_w, '\x8D', stack_bp(2,force_32bits=True),register(1,8))
 
     CALL_l = insn('\xE8', relative(1))
-    CALL_r = insn(rex_nw, '\xFF', register(1), chr(0xC0 | (2<<3)))
-    CALL_b = insn('\xFF', orbyte(2<<3), stack_bp(1))
+    CALL_r = insn(rex_nw, '\xFF', chr(0xC0 | (2<<3)), register(1))
+    CALL_b = insn('\xFF', stack_bp(1), orbyte(2<<3))
 
-    XCHG_rm = insn(rex_w, '\x87', register(1,8), mem_reg_plus_const(2))
+    XCHG_rm = insn(rex_w, '\x87', mem_reg_plus_const(2), register(1,8))
 
     JMP_l = insn('\xE9', relative(1))
-    J_il = insn('\x0F', immediate(1,'o'), '\x80', relative(2))
-    SET_ir = insn('\x0F', immediate(1,'o'),'\x90', register(2), '\xC0')
+    J_il = insn('\x0F\x80', immediate(1,'o'), relative(2))
+    SET_ir = insn('\x0F\x90', immediate(1,'o'), '\xC0', register(2))
 
     # ------------------------------ SSE2 ------------------------------
 
-    MOVSD_rr = xmminsn('\xF2', rex_nw, '\x0F\x10', register(1,8), register(2),
-                                                              '\xC0')
-    MOVSD_rb = xmminsn('\xF2', rex_nw, '\x0F\x10', register(1,8), stack_bp(2))
-    MOVSD_br = xmminsn('\xF2', rex_nw, '\x0F\x11', register(2,8), stack_bp(1))
-    MOVSD_rs = xmminsn('\xF2', rex_nw, '\x0F\x10', register(1,8), stack_sp(2))
-    MOVSD_sr = xmminsn('\xF2', rex_nw, '\x0F\x11', register(2,8), stack_sp(1))
-    MOVSD_rm = xmminsn('\xF2', rex_nw, '\x0F\x10', register(1,8),
-                                                     mem_reg_plus_const(2))
-    MOVSD_mr = xmminsn('\xF2', rex_nw, '\x0F\x11', register(2,8),
-                                                     mem_reg_plus_const(1))
+    MOVSD_rr = xmminsn('\xF2', rex_nw,'\x0F\x10\xC0',register(1,8),register(2))
+    MOVSD_rb = xmminsn('\xF2', rex_nw, '\x0F\x10', stack_bp(2), register(1,8))
+    MOVSD_br = xmminsn('\xF2', rex_nw, '\x0F\x11', stack_bp(1), register(2,8))
+    MOVSD_rs = xmminsn('\xF2', rex_nw, '\x0F\x10', stack_sp(2), register(1,8))
+    MOVSD_sr = xmminsn('\xF2', rex_nw, '\x0F\x11', stack_sp(1), register(2,8))
+    MOVSD_rm = xmminsn('\xF2', rex_nw, '\x0F\x10', mem_reg_plus_const(2),
+                                                   register(1,8))
+    MOVSD_mr = xmminsn('\xF2', rex_nw, '\x0F\x11', mem_reg_plus_const(1),
+                                                   register(2,8))
 
     # ------------------------------------------------------------
 
@@ -429,18 +426,18 @@
     WORD = 8
 
     def writeimm64(self, imm):
-        self.writechar(chr(imm & 0xFF))
-        self.writechar(chr((imm >> 8) & 0xFF))
-        self.writechar(chr((imm >> 16) & 0xFF))
-        self.writechar(chr((imm >> 24) & 0xFF))
-        self.writechar(chr((imm >> 32) & 0xFF))
-        self.writechar(chr((imm >> 40) & 0xFF))
-        self.writechar(chr((imm >> 48) & 0xFF))
         self.writechar(chr((imm >> 56) & 0xFF))
+        self.writechar(chr((imm >> 48) & 0xFF))
+        self.writechar(chr((imm >> 40) & 0xFF))
+        self.writechar(chr((imm >> 32) & 0xFF))
+        self.writechar(chr((imm >> 24) & 0xFF))
+        self.writechar(chr((imm >> 16) & 0xFF))
+        self.writechar(chr((imm >> 8) & 0xFF))
+        self.writechar(chr(imm & 0xFF))
 
     # MOV_ri from the parent class is not wrong, but here is a better encoding
     # for the common case where the immediate fits in 32 bits
-    _MOV_ri32 = insn(rex_w, '\xC7', register(1), '\xC0', immediate(2, 'i'))
+    _MOV_ri32 = insn(rex_w, '\xC7\xC0', register(1), immediate(2, 'i'))
 
     def MOV_ri(self, reg, immed):
         if fits_in_32bits(immed):
@@ -455,8 +452,8 @@
         if fits_in_32bits(offset):
             AbstractX86CodeBuilder.CALL_l(self, target)
         else:
-            AbstractX86CodeBuilder.MOV_ri(self, R.eax, target)
             AbstractX86CodeBuilder.CALL_r(self, R.eax)
+            AbstractX86CodeBuilder.MOV_ri(self, R.eax, target)
 
     # unsupported -- must use e.g. MOV tmpreg, immed64; MOV reg, [tmpreg]
     def MOV_rj(self, reg, mem_immed):

Added: pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/__init__.py
==============================================================================

Added: pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_runner.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_runner.py	Sat Mar 13 16:56:03 2010
@@ -0,0 +1,16 @@
+import py
+from pypy.jit.backend.newx86.runner import CPU
+from pypy.jit.backend.test.runner_test import LLtypeBackendTest
+
+class FakeStats(object):
+    pass
+
+# ____________________________________________________________
+
+class TestX86(LLtypeBackendTest):
+
+    # for the individual tests see
+    # ====> ../../test/runner_test.py
+    
+    def setup_method(self, meth):
+        self.cpu = CPU(rtyper=None, stats=FakeStats())

Copied: pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86.py (from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86.py)
==============================================================================
--- pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86.py	(original)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86.py	Sat Mar 13 16:56:03 2010
@@ -1,5 +1,5 @@
 import py, struct
-from pypy.jit.backend.x86.rx86 import *
+from pypy.jit.backend.newx86.rx86 import *
 globals().update(R.__dict__)
 
 class CodeBuilderMixin(object):
@@ -11,10 +11,11 @@
         self.buffer.append(c)    # append a character
 
     def getvalue(self):
-        return ''.join(self.buffer)
+        buf = self.buffer[::-1]
+        return ''.join(buf)
 
     def tell(self):
-        return 0x76543210 + len(self.buffer)
+        return 0x76543210 - len(self.buffer)
 
 
 class CodeBuilder32(CodeBuilderMixin, X86_32_CodeBuilder):
@@ -42,40 +43,40 @@
 
 def test_mov_rm():
     s = CodeBuilder32()
-    s.MOV_rm(edx, (edi, 0))
-    s.MOV_rm(edx, (edi, -128))
     s.MOV_rm(edx, (edi, 128))
+    s.MOV_rm(edx, (edi, -128))
+    s.MOV_rm(edx, (edi, 0))
     assert s.getvalue() == '\x8B\x17\x8B\x57\x80\x8B\x97\x80\x00\x00\x00'
 
 def test_mov_mr():
     s = CodeBuilder32()
-    s.MOV_mr((edi, 0), edx)
-    s.MOV_mr((edi, -128), edx)
     s.MOV_mr((edi, 128), edx)
+    s.MOV_mr((edi, -128), edx)
+    s.MOV_mr((edi, 0), edx)
     assert s.getvalue() == '\x89\x17\x89\x57\x80\x89\x97\x80\x00\x00\x00'
 
 def test_mov_ra():
     s = CodeBuilder32()
-    s.MOV_ra(edx, (esi, edi, 2, 0))
-    s.MOV_ra(edx, (esi, edi, 2, -128))
     s.MOV_ra(edx, (esi, edi, 2, 128))
+    s.MOV_ra(edx, (esi, edi, 2, -128))
+    s.MOV_ra(edx, (esi, edi, 2, 0))
     assert s.getvalue() == ('\x8B\x14\xBE' +
                             '\x8B\x54\xBE\x80' +
                             '\x8B\x94\xBE\x80\x00\x00\x00')
 
 def test_mov_ar():
     s = CodeBuilder32()
-    s.MOV_ar((esi, edi, 2, 0), edx)
-    s.MOV_ar((esi, edi, 2, -128), edx)
     s.MOV_ar((esi, edi, 2, 128), edx)
+    s.MOV_ar((esi, edi, 2, -128), edx)
+    s.MOV_ar((esi, edi, 2, 0), edx)
     assert s.getvalue() == ('\x89\x14\xBE' +
                             '\x89\x54\xBE\x80' +
                             '\x89\x94\xBE\x80\x00\x00\x00')
 
 def test_nop_add_rr():
     s = CodeBuilder32()
-    s.NOP()
     s.ADD_rr(eax, eax)
+    s.NOP()
     assert s.getvalue() == '\x90\x01\xC0'
 
 def test_lea_rb():
@@ -91,19 +92,19 @@
 def test_call_l(s=None):
     s = s or CodeBuilder32()
     s.CALL_l(0x01234567)
-    ofs = 0x01234567 - (0x76543210+5)
+    ofs = 0x01234567 - 0x76543210
     assert s.getvalue() == '\xE8' + struct.pack("<i", ofs)
 
 def test_jmp_l():
     s = CodeBuilder32()
     s.JMP_l(0x01234567)
-    ofs = 0x01234567 - (0x76543210+5)
+    ofs = 0x01234567 - 0x76543210
     assert s.getvalue() == '\xE9' + struct.pack("<i", ofs)
 
 def test_j_il():
     s = CodeBuilder32()
     s.J_il(5, 0x01234567)
-    ofs = 0x01234567 - (0x76543210+6)
+    ofs = 0x01234567 - 0x76543210
     assert s.getvalue() == '\x0F\x85' + struct.pack("<i", ofs)
 
 def test_set_ir():
@@ -117,16 +118,16 @@
 
 def test_mov_ri_64():
     s = CodeBuilder64()
-    s.MOV_ri(ecx, -2)
     s.MOV_ri(r12, 0x80000042)
+    s.MOV_ri(ecx, -2)
     assert s.getvalue() == ('\x48\xC7\xC1\xFE\xFF\xFF\xFF' +
                             '\x49\xBC\x42\x00\x00\x80\x00\x00\x00\x00')
 
 def test_mov_rm_64():
     s = CodeBuilder64()
-    s.MOV_rm(edx, (edi, 0))
-    s.MOV_rm(edx, (r12, 0))
     s.MOV_rm(edx, (r13, 0))
+    s.MOV_rm(edx, (r12, 0))
+    s.MOV_rm(edx, (edi, 0))
     assert s.getvalue() == '\x48\x8B\x17\x49\x8b\x14\x24\x49\x8b\x55\x00'
 
 def test_mov_rm_negative_64():

Copied: pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_32_auto_encoding.py (from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_32_auto_encoding.py)
==============================================================================
--- pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_32_auto_encoding.py	(original)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_32_auto_encoding.py	Sat Mar 13 16:56:03 2010
@@ -1,6 +1,6 @@
 import os, random, struct
 import py
-from pypy.jit.backend.x86 import rx86
+from pypy.jit.backend.newx86 import rx86
 from pypy.rlib.rarithmetic import intmask
 from pypy.tool.udir import udir
 
@@ -12,22 +12,27 @@
 class CodeCheckerMixin(object):
     def __init__(self, expected):
         self.expected = expected
-        self.index = 0
-
-    def begin(self, op):
-        self.op = op
-        self.instrindex = self.index
+        self.index = len(expected)
+        self.insn = []
 
     def writechar(self, char):
-        if char != self.expected[self.index:self.index+1]:
-            print self.op
-            print "\x09from rx86.py:", hexdump(self.expected[self.instrindex:self.index] + char)+"..."
-            print "\x09from 'as':   ", hexdump(self.expected[self.instrindex:self.index+15])+"..."
+        self.insn.append(char)
+
+    def stop(self, op):
+        got = ''.join(self.insn[::-1])
+        end = self.index
+        start = max(end - len(self.insn), 0)
+        expected = self.expected[start:end]
+        if got != expected:
+            print op
+            print "\x09from rx86.py: ", hexdump(got)
+            print "\x09from 'as':    ", hexdump(expected)
             raise Exception("Differs")
-        self.index += 1
+        self.index = start
+        self.insn = []
 
     def done(self):
-        assert len(self.expected) == self.index
+        assert self.index == 0
 
 def hexdump(s):
     return ' '.join(["%02X" % ord(c) for c in s])
@@ -244,10 +249,11 @@
         ilist = self.make_all_tests(methname, argmodes)
         oplist, as_code = self.run_test(methname, instrname, argmodes, ilist)
         cc = self.get_code_checker_class()(as_code)
-        for op, args in zip(oplist, ilist):
+        for i in range(len(oplist)-1, -1, -1):
+            op = oplist[i]
             if op:
-                cc.begin(op)
-                getattr(cc, methname)(*args)
+                getattr(cc, methname)(*ilist[i])
+                cc.stop(op)
         cc.done()
 
     def setup_class(cls):

Copied: pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_64_auto_encoding.py (from r72201, pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_64_auto_encoding.py)
==============================================================================
--- pypy/branch/remove-ri386-multimethod-2/pypy/jit/backend/x86/test/test_rx86_64_auto_encoding.py	(original)
+++ pypy/branch/jit-newx86/pypy/jit/backend/newx86/test/test_rx86_64_auto_encoding.py	Sat Mar 13 16:56:03 2010
@@ -1,6 +1,6 @@
 import random
-from pypy.jit.backend.x86 import rx86
-from pypy.jit.backend.x86.test import test_rx86_32_auto_encoding
+from pypy.jit.backend.newx86 import rx86
+from pypy.jit.backend.newx86.test import test_rx86_32_auto_encoding
 
 
 class TestRx86_64(test_rx86_32_auto_encoding.TestRx86_32):



More information about the Pypy-commit mailing list