Add adjust_sp_imm instruction. Note: This enables using rsp and rbp as normal registers. Which is... wrong.

This commit is contained in:
Tyler McMullen
2017-11-27 15:32:28 -08:00
committed by Jakob Stoklund Olesen
parent 32509ebacd
commit ffab87318e
9 changed files with 32 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ RegSpill = InstructionFormat(
VALUE, ('src', regunit), ('dst', entities.stack_slot))
RegFill = InstructionFormat(
VALUE, ('src', entities.stack_slot), ('dst', regunit))
AdjustSpImm = InstructionFormat(offset32)
Trap = InstructionFormat(trapcode)
CondTrap = InstructionFormat(VALUE, trapcode)

View File

@@ -544,6 +544,14 @@ copy_special = Instruction(
ins=(src, dst),
other_side_effects=True)
Offset = Operand('Offset', offset32, 'Offset from current stack pointer')
adjust_sp_imm = Instruction(
'adjust_sp_imm', r"""
Adds an immediate offset value to the stack pointer register.
""",
ins=(Offset,),
other_side_effects=True)
regspill = Instruction(
'regspill', r"""
Temporarily divert ``x`` from ``src`` to ``SS``.

View File

@@ -234,7 +234,10 @@ I64.enc(x86.pop.i64, *r.popq.rex(0x58))
I64.enc(x86.pop.i64, *r.popq(0x58))
# Copy Special
I64.enc(base.copy_special, *r.copysp.rex(0x89))
I64.enc(base.copy_special, *r.copysp.rex(0x89, w=1))
# Adjust SP Imm
I64.enc(base.adjust_sp_imm, *r.adjustsp.rex(0x81, w=1))
#
# Float loads and stores.

View File

@@ -10,7 +10,7 @@ from base.formats import Trap, Call, IndirectCall, Store, Load
from base.formats import IntCompare, FloatCompare, IntCond, FloatCond
from base.formats import Jump, Branch, BranchInt, BranchFloat
from base.formats import Ternary, FuncAddr, UnaryGlobalVar
from base.formats import RegMove, RegSpill, RegFill, CopySpecial
from base.formats import RegMove, RegSpill, RegFill, CopySpecial, AdjustSpImm
from .registers import GPR, ABCD, FPR, GPR8, FPR8, FLAG, StackGPR32, StackFPR32
from .defs import supported_floatccs
@@ -493,6 +493,15 @@ copysp = TailRecipe(
modrm_rr(dst, src, sink);
''')
adjustsp = TailRecipe(
'adjustsp', AdjustSpImm, size=5, ins=(), outs=(),
emit='''
PUT_OP(bits, rex1(4), sink);
modrm_r_bits(4, bits, sink);
let offset: i32 = offset.into();
sink.put4(offset as u32);
''')
# XX+rd id with Abs4 function relocation.
fnaddr4 = TailRecipe(