[pypy-svn] r69063 - in pypy/trunk/pypy/jit/backend/x86: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Nov 8 15:52:07 CET 2009
Author: arigo
Date: Sun Nov 8 15:52:06 2009
New Revision: 69063
Modified:
pypy/trunk/pypy/jit/backend/x86/assembler.py
pypy/trunk/pypy/jit/backend/x86/codebuf.py
pypy/trunk/pypy/jit/backend/x86/ri386.py
pypy/trunk/pypy/jit/backend/x86/ri386setup.py
pypy/trunk/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py
Log:
In class MODRM, replace the 'extradata' string with a list of characters.
Should help a bit because we can e.g. build a list of 4 characters easily,
whereas making a string from 4 characters leads to a mess of mallocs.
Modified: pypy/trunk/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/assembler.py Sun Nov 8 15:52:06 2009
@@ -864,7 +864,7 @@
loc_mask = arglocs[1]
mc = self.mc._mc
mc.TEST(loc_cond, loc_mask)
- mc.write('\x74\x00') # JZ after_the_call
+ mc.write(constlistofchars('\x74\x00')) # JZ after_the_call
jz_location = mc.get_relative_pos()
# the following is supposed to be the slow path, so whenever possible
# we choose the most compact encoding over the most efficient one.
@@ -884,7 +884,7 @@
# patch the JZ above
offset = mc.get_relative_pos() - jz_location
assert 0 < offset <= 127
- mc.overwrite(jz_location-1, chr(offset))
+ mc.overwrite(jz_location-1, [chr(offset)])
def not_implemented_op_discard(self, op, arglocs):
msg = "not implemented operation: %s" % op.getopname()
@@ -920,7 +920,7 @@
mc.MOV(eax, heap(nursery_free_adr))
mc.LEA(edx, addr_add(eax, imm(size)))
mc.CMP(edx, heap(nursery_top_adr))
- mc.write('\x76\x00') # JNA after the block
+ mc.write(constlistofchars('\x76\x00')) # JNA after the block
jmp_adr = mc.get_relative_pos()
mc.PUSH(imm(size))
mc.CALL(rel32(slowpath_addr))
@@ -932,7 +932,7 @@
mc.ADD(esp, imm(4))
offset = mc.get_relative_pos() - jmp_adr
assert 0 < offset <= 127
- mc.overwrite(jmp_adr-1, chr(offset))
+ mc.overwrite(jmp_adr-1, [chr(offset)])
mc.MOV(addr_add(eax, imm(0)), imm(tid))
mc.MOV(heap(nursery_free_adr), edx)
Modified: pypy/trunk/pypy/jit/backend/x86/codebuf.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/codebuf.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/codebuf.py Sun Nov 8 15:52:06 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 make_sure_not_resized
class InMemoryCodeBuilder(I386CodeBuilder):
@@ -18,18 +19,19 @@
self._size = map_size
self._pos = 0
- def overwrite(self, pos, data):
- assert pos + len(data) <= self._size
- for c in data:
+ def overwrite(self, pos, listofchars):
+ make_sure_not_resized(listofchars)
+ assert pos + len(listofchars) <= self._size
+ for c in listofchars:
self._data[pos] = c
pos += 1
return pos
- def write(self, data):
- self._pos = self.overwrite(self._pos, data)
+ def write(self, listofchars):
+ self._pos = self.overwrite(self._pos, listofchars)
def writechr(self, n):
- # purely for performance: don't convert chr(n) to a str
+ # purely for performance: don't make the one-element list [chr(n)]
pos = self._pos
assert pos + 1 <= self._size
self._data[pos] = chr(n)
Modified: pypy/trunk/pypy/jit/backend/x86/ri386.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/ri386.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/ri386.py Sun Nov 8 15:52:06 2009
@@ -1,5 +1,6 @@
from pypy.rlib.rarithmetic import intmask
from pypy.rlib.objectmodel import ComputedIntSymbolic, we_are_translated
+from pypy.rlib.debug import make_sure_not_resized
class OPERAND(object):
_attrs_ = []
@@ -112,6 +113,7 @@
def __init__(self, byte, extradata):
self.byte = byte
self.extradata = extradata
+ make_sure_not_resized(extradata)
def lowest8bits(self):
return MODRM8(self.byte, self.extradata)
@@ -282,7 +284,7 @@
def memregister(register):
assert register.width == 4
- return MODRM(0xC0 | register.op, '')
+ return MODRM(0xC0 | register.op, constlistofchars(''))
def mem(basereg, offset=0):
return memSIB(basereg, None, 0, offset)
@@ -307,11 +309,11 @@
def memregister8(register):
assert register.width == 1
- return MODRM8(0xC0 | register.op, '')
+ return MODRM8(0xC0 | register.op, constlistofchars(''))
def memregister64(register):
assert register.width == 8
- return MODRM64(0xC0 | register.op, '')
+ return MODRM64(0xC0 | register.op, constlistofchars(''))
def mem8(basereg, offset=0):
return memSIB8(basereg, None, 0, offset)
@@ -328,17 +330,17 @@
if index is None:
return cls(0x05, packimm32(offset))
if scaleshift > 0:
- return cls(0x04, chr((scaleshift<<6) | (index.op<<3) | 0x05) +
+ return cls(0x04, [chr((scaleshift<<6) | (index.op<<3) | 0x05)] +
packimm32(offset))
base = index
index = None
if index is not None:
- SIB = chr((scaleshift<<6) | (index.op<<3) | base.op)
+ SIB = [chr((scaleshift<<6) | (index.op<<3) | base.op)]
elif base is esp:
- SIB = '\x24'
+ SIB = constlistofchars('\x24')
elif offset == 0 and base is not ebp:
- return cls(base.op, '')
+ return cls(base.op, constlistofchars(''))
elif single_byte(offset):
return cls(0x40 | base.op, packimm8(offset))
else:
@@ -358,19 +360,25 @@
return -128 <= value < 128
def packimm32(i):
- return (chr(i & 0xFF) +
- chr((i >> 8) & 0xFF) +
- chr((i >> 16) & 0xFF) +
- chr((i >> 24) & 0xFF))
+ lst = [chr(i & 0xFF),
+ chr((i >> 8) & 0xFF),
+ chr((i >> 16) & 0xFF),
+ chr((i >> 24) & 0xFF)]
+ make_sure_not_resized(lst)
+ return lst
def packimm8(i):
if i < 0:
i += 256
- return chr(i)
+ lst = [chr(i)]
+ make_sure_not_resized(lst)
+ return lst
def packimm16(i):
- return (chr(i & 0xFF) +
- chr((i >> 8) & 0xFF))
+ lst = [chr(i & 0xFF),
+ chr((i >> 8) & 0xFF)]
+ make_sure_not_resized(lst)
+ return lst
def unpack(s):
assert len(s) in (1, 2, 4)
@@ -388,6 +396,11 @@
a = intmask(a)
return a
+def constlistofchars(s):
+ assert isinstance(s, str)
+ return [c for c in s]
+constlistofchars._annspecialcase_ = 'specialize:memo'
+
missing = MISSING()
# __________________________________________________________
@@ -395,11 +408,11 @@
class I386CodeBuilder(object):
- def write(self, data):
+ def write(self, listofchars):
raise NotImplementedError
def writechr(self, n):
- self.write(chr(n))
+ self.write([chr(n)])
def tell(self):
raise NotImplementedError
Modified: pypy/trunk/pypy/jit/backend/x86/ri386setup.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/ri386setup.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/ri386setup.py Sun Nov 8 15:52:06 2009
@@ -164,7 +164,7 @@
op = op[1:]
if op:
if len(op) > 1:
- lines.append('builder.write(%r)' % (op,))
+ lines.append('builder.write(constlistofchars(%r))' % (op,))
else:
lines.append('builder.writechr(%d)' % (ord(op),))
else:
@@ -180,6 +180,7 @@
'packimm32': packimm32,
'packimm8': packimm8,
'packimm16': packimm16,
+ 'constlistofchars': constlistofchars,
}
exec compile2(source) in miniglobals
return miniglobals['encode']
Modified: pypy/trunk/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/test/test_ri386_auto_encoding.py Sun Nov 8 15:52:06 2009
@@ -256,7 +256,8 @@
self.op = op
self.instrindex = self.index
- def write(self, data):
+ def write(self, listofchars):
+ data = ''.join(listofchars)
end = self.index+len(data)
if data != self.expected[self.index:end]:
print self.op
More information about the Pypy-commit
mailing list