[pypy-svn] r75009 - in pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86: . test

jcreigh at codespeak.net jcreigh at codespeak.net
Tue Jun 1 21:36:04 CEST 2010


Author: jcreigh
Date: Tue Jun  1 21:36:02 2010
New Revision: 75009

Added:
   pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/test/test_regloc.py
Modified:
   pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/regloc.py
   pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/rx86.py
Log:
add hack to encode the immediates of instructions with 16-bit operands correctly

Modified: pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/regloc.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/regloc.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/regloc.py	Tue Jun  1 21:36:02 2010
@@ -178,6 +178,17 @@
 
         return INSN
 
+    def _16_bit_binaryop(name):
+        def INSN(self, loc1, loc2):
+            # Select 16-bit operand mode
+            self.writechar('\x66')
+            # XXX: Hack to let immediate() in rx86 know to do a 16-bit encoding
+            self._use_16_bit_immediate = True
+            getattr(self, name)(loc1, loc2)
+            self._use_16_bit_immediate = False
+
+        return INSN
+
     AND = _binaryop('AND')
     OR  = _binaryop('OR')
     XOR = _binaryop('XOR')
@@ -193,8 +204,10 @@
     NEG = _unaryop('NEG')
 
     CMP = _binaryop('CMP')
+    CMP16 = _16_bit_binaryop('CMP')
     MOV = _binaryop('MOV')
     MOV8 = _binaryop('MOV8')
+    MOV16 = _16_bit_binaryop('MOV')
     MOVZX8 = _binaryop('MOVZX8')
     MOVZX16 = _binaryop('MOVZX16')
 
@@ -214,16 +227,6 @@
 
     CALL = _unaryop('CALL')
 
-    def MOV16(self, dest_loc, src_loc):
-        # Select 16-bit operand mode
-        self.writechar('\x66')
-        self.MOV(dest_loc, src_loc)
-
-    def CMP16(self, a_loc, b_loc):
-        # Select 16-bit operand mode
-        self.writechar('\x66')
-        self.CMP(a_loc, b_loc)
-
 def imm(x):
     # XXX: ri386 migration shim
     if isinstance(x, ConstInt):

Modified: pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/rx86.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/rx86.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/rx86.py	Tue Jun  1 21:36:02 2010
@@ -116,7 +116,10 @@
     elif width == 'q' and mc.WORD == 8:
         mc.writeimm64(immediate)
     else:
-        mc.writeimm32(immediate)
+        if mc._use_16_bit_immediate:
+            mc.writeimm16(immediate)
+        else:
+            mc.writeimm32(immediate)
     return 0
 
 def immediate(argnum, width='i'):
@@ -385,6 +388,9 @@
 class AbstractX86CodeBuilder(object):
     """Abstract base class."""
 
+    # Used by the 16-bit version of instructions
+    _use_16_bit_immediate = False
+
     def writechar(self, char):
         raise NotImplementedError
 

Added: pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/test/test_regloc.py
==============================================================================
--- (empty file)
+++ pypy/branch/x86-64-jit-backend/pypy/jit/backend/x86/test/test_regloc.py	Tue Jun  1 21:36:02 2010
@@ -0,0 +1,15 @@
+from pypy.jit.backend.x86.regloc import *
+from pypy.jit.backend.x86.test.test_rx86 import CodeBuilder32, assert_encodes_as
+
+class LocationCodeBuilder32(CodeBuilder32, LocationCodeBuilder):
+    pass
+
+cb32 = LocationCodeBuilder32
+
+def test_mov_16():
+    assert_encodes_as(cb32, "MOV16", (ecx, ebx), '\x66\x89\xD9')
+    assert_encodes_as(cb32, "MOV16", (ecx, ImmedLoc(12345)), '\x66\xB9\x39\x30')
+
+def test_cmp_16():
+    assert_encodes_as(cb32, "CMP16", (ecx, ebx), '\x66\x39\xD9')
+    assert_encodes_as(cb32, "CMP16", (ecx, ImmedLoc(12345)), '\x66\x81\xF9\x39\x30')



More information about the Pypy-commit mailing list