[pypy-svn] r31496 - in pypy/dist/pypy/jit/codegen/i386: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 22 18:48:31 CEST 2006
Author: arigo
Date: Tue Aug 22 18:48:28 2006
New Revision: 31496
Modified:
pypy/dist/pypy/jit/codegen/i386/ri386.py
pypy/dist/pypy/jit/codegen/i386/ri386setup.py
pypy/dist/pypy/jit/codegen/i386/test/test_ri386.py
Log:
(pedronis, arigo)
Reintroduced some support for REL32, used in jumps and calls.
Modified: pypy/dist/pypy/jit/codegen/i386/ri386.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386.py Tue Aug 22 18:48:28 2006
@@ -46,6 +46,10 @@
class MODRM8(MODRM):
pass
+class REL32(OPERAND):
+ def __init__(self, absolute_target):
+ self.absolute_target = absolute_target
+
class MISSING(OPERAND):
pass
@@ -78,6 +82,7 @@
imm32 = IMM32
imm8 = IMM8
imm16 = IMM16
+rel32 = REL32
def memregister(register):
assert register.width == 4
@@ -159,5 +164,8 @@
def write(self, data):
raise NotImplementedError
+ def tell(self):
+ raise NotImplementedError
+
import ri386setup # side-effect: add methods to AbstractCodeBuilder
Modified: pypy/dist/pypy/jit/codegen/i386/ri386setup.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386setup.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386setup.py Tue Aug 22 18:48:28 2006
@@ -40,6 +40,8 @@
IMM16: [(IMM16, None)], # only for RET
IMM8: [(IMM8, None), (IMM32, None)],
+ REL32: [(REL32, None)],
+
MODRM: [(MODRM, None)],
MODRM8: [(MODRM8, None)],
@@ -100,6 +102,15 @@
lines.append('builder.write(%s(arg%d.value))' % (packer, self.op))
return False
+class relative(operand):
+ def eval(self, lines, has_orbyte):
+ assert not has_orbyte, "malformed bytecode"
+ assert self.width == 'i', "only REL32 supported at the moment"
+ lines.append('offset = arg%d.absolute_target - (builder.tell()+4)' % (
+ self.op,))
+ lines.append('builder.write(packimm32(offset))')
+ return False
+
def consolidate(code1):
for i in range(len(code1)-1, 0, -1):
@@ -277,16 +288,16 @@
RET.mode0(['\xC3'])
RET.mode1(IMM16, ['\xC2', immediate(1,'h')])
-#CALL = Instruction()
-#CALL.mode1(REL32, ['\xE8', immediate(1)])
-#CALL.mode1(MODRM, ['\xFF', orbyte(2<<3), modrm(1)])
-#CALL.indirect = 1
+CALL = Instruction()
+CALL.mode1(REL32, ['\xE8', relative(1)])
+CALL.mode1(MODRM, ['\xFF', orbyte(2<<3), modrm(1)])
+CALL.indirect = 1
-#JMP = Instruction()
+JMP = Instruction()
#JMP.mode1(REL8, ['\xEB', immediate(1,'b')])
-#JMP.mode1(REL32, ['\xE9', immediate(1)])
-#JMP.mode1(MODRM, ['\xFF', orbyte(4<<3), modrm(1)])
-#JMP.indirect = 1
+JMP.mode1(REL32, ['\xE9', relative(1)])
+JMP.mode1(MODRM, ['\xFF', orbyte(4<<3), modrm(1)])
+JMP.indirect = 1
PUSH = Instruction()
PUSH.mode1(IMM8, ['\x6A', immediate(1,'b')])
@@ -396,7 +407,7 @@
instr.indirect = indirect
#define_cond('J', 1, (REL8,), [None,'\x70', immediate(1,'b')])
-#define_cond('J', 1, (REL32,), ['\x0F', None,'\x80', immediate(1)])
+define_cond('J', 1, (REL32,), ['\x0F', None,'\x80', relative(1)])
define_cond('SET', 0, (MODRM8,), ['\x0F', None,'\x90',orbyte(0<<3),modrm(1,'b')])
define_cond('CMOV',0,(REG,MODRM),['\x0F', None,'\x40', register(1,8), modrm(2)])
# note: CMOVxx are Pentium-class instructions, unknown to the 386 and 486
Modified: pypy/dist/pypy/jit/codegen/i386/test/test_ri386.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_ri386.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_ri386.py Tue Aug 22 18:48:28 2006
@@ -9,6 +9,9 @@
for c in data:
self.buffer.append(c) # extend the list of characters
+ def tell(self):
+ return len(self.buffer)
+
def getvalue(self):
return ''.join(self.buffer)
@@ -47,6 +50,8 @@
# mov eax, [8*ecx]
yield check, '\x89\x04\xcd\x00\x00\x00\x00', \
'MOV', memSIB(None,ecx,3,0), eax
+ # call +17
+ yield check, '\xE8\x11\x00\x00\x00', 'CALL', rel32(22)
def test_translate():
More information about the Pypy-commit
mailing list