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

jcreigh at codespeak.net jcreigh at codespeak.net
Tue Aug 3 18:25:33 CEST 2010


Author: jcreigh
Date: Tue Aug  3 18:25:31 2010
New Revision: 76447

Modified:
   pypy/trunk/pypy/jit/backend/x86/regloc.py
   pypy/trunk/pypy/jit/backend/x86/rx86.py
   pypy/trunk/pypy/jit/backend/x86/test/test_regloc.py
   pypy/trunk/pypy/jit/backend/x86/test/test_rx86.py
Log:
Fix JIT test failure related to jumping from a large "negative" address to a large "positive" address, or vice versa

Modified: pypy/trunk/pypy/jit/backend/x86/regloc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/regloc.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/regloc.py	Tue Aug  3 18:25:31 2010
@@ -4,6 +4,7 @@
 from pypy.jit.backend.x86.arch import WORD
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.objectmodel import specialize
+from pypy.rlib.rarithmetic import intmask
 
 #
 # This module adds support for "locations", which can be either in a Const,
@@ -252,7 +253,7 @@
                 if code == possible_code:
                     val = getattr(loc, "value_" + possible_code)()
                     if possible_code == 'i':
-                        offset = val - (self.tell() + 5)
+                        offset = intmask(val - (self.tell() + 5))
                         if rx86.fits_in_32bits(offset):
                             _rx86_getattr(self, name + "_l")(val)
                         else:

Modified: pypy/trunk/pypy/jit/backend/x86/rx86.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/rx86.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/rx86.py	Tue Aug  3 18:25:31 2010
@@ -2,6 +2,7 @@
 from pypy.rlib.objectmodel import ComputedIntSymbolic, we_are_translated
 from pypy.rlib.objectmodel import specialize
 from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.rarithmetic import intmask
 from pypy.rpython.lltypesystem import rffi
 
 BYTE_REG_FLAG = 0x20
@@ -138,7 +139,7 @@
 
 def encode_relative(mc, target, _, orbyte):
     assert orbyte == 0
-    offset = target - (mc.tell() + 4)
+    offset = intmask(target - (mc.tell() + 4))
     mc.writeimm32(offset)
     return 0
 

Modified: pypy/trunk/pypy/jit/backend/x86/test/test_regloc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/test/test_regloc.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/test/test_regloc.py	Tue Aug  3 18:25:31 2010
@@ -1,7 +1,9 @@
+import struct
 from pypy.jit.backend.x86.regloc import *
 from pypy.jit.backend.x86.test.test_rx86 import CodeBuilder32, CodeBuilder64, assert_encodes_as
 from pypy.jit.backend.x86.assembler import heap
-from pypy.jit.backend.x86.arch import IS_X86_64
+from pypy.jit.backend.x86.arch import IS_X86_64, IS_X86_32
+from pypy.rlib.rarithmetic import intmask
 import py.test
 
 class LocationCodeBuilder32(CodeBuilder32, LocationCodeBuilder):
@@ -21,6 +23,27 @@
     assert_encodes_as(cb32, "CMP16", (ecx, ebx), '\x66\x39\xD9')
     assert_encodes_as(cb32, "CMP16", (ecx, ImmedLoc(12345)), '\x66\x81\xF9\x39\x30')
 
+def test_jmp_wraparound():
+    if not IS_X86_32:
+        py.test.skip()
+
+    pos_addr = intmask(0x7FFFFF00)
+    neg_addr = intmask(0x800000BB)
+
+    # JMP to "negative" address from "positive" address
+    s = cb32()
+    s.base_address = pos_addr
+    s.JMP(ImmedLoc(neg_addr))
+    expected_ofs = neg_addr - (pos_addr+5)
+    assert s.getvalue() == '\xE9' + struct.pack("<i", expected_ofs)
+
+    # JMP to a "positive" address from a "negative" address
+    s = cb32()
+    s.base_address = neg_addr
+    s.JMP(ImmedLoc(pos_addr))
+    expected_ofs = pos_addr - (neg_addr+5)
+    assert s.getvalue() == '\xE9' + struct.pack("<i", expected_ofs)
+
 def test_reuse_scratch_register():
     if not IS_X86_64:
         py.test.skip()

Modified: pypy/trunk/pypy/jit/backend/x86/test/test_rx86.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/test/test_rx86.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/test/test_rx86.py	Tue Aug  3 18:25:31 2010
@@ -5,6 +5,7 @@
 class CodeBuilderMixin(object):
     def __init__(self):
         self.buffer = []
+        self.base_address = 0x76543210
 
     def writechar(self, c):
         assert isinstance(c, str) and len(c) == 1
@@ -14,7 +15,7 @@
         return ''.join(self.buffer)
 
     def tell(self):
-        return 0x76543210 + len(self.buffer)
+        return self.base_address + len(self.buffer)
 
 def assert_encodes_as(code_builder_cls, insn_name, args, expected_encoding):
     s = code_builder_cls()



More information about the Pypy-commit mailing list