From 1bc218edf7404a09c1e095b63dcc56facc107294 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 21 Sep 2009 13:16:31 +0000 Subject: [PATCH] Correct three bugs in bemit_incsp(): Offset 0 must emit no code, get_signed_imm_size() returns size in byte, not bits, IncSP -128 is a 4 byte offset, because the value gets negated (i.e. addl $128, %esp is emitted). [r26564] --- ir/be/ia32/ia32_emitter.c | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/ir/be/ia32/ia32_emitter.c b/ir/be/ia32/ia32_emitter.c index 5b4ed531a..35511371b 100644 --- a/ir/be/ia32/ia32_emitter.c +++ b/ir/be/ia32/ia32_emitter.c @@ -2845,27 +2845,32 @@ static void bemit_return(const ir_node *node) static void bemit_incsp(const ir_node *node) { - const arch_register_t *reg = get_out_reg(node, 0); - int offs = be_get_IncSP_offset(node); - unsigned size = get_signed_imm_size(offs); - unsigned char w = size == 1 ? 2 : 0; + int offs; + const arch_register_t *reg; + unsigned size; + unsigned ext; + + offs = be_get_IncSP_offset(node); + if (offs == 0) + return; - bemit8(0x81 | w); if (offs > 0) { + ext = 5; /* sub */ + } else { + ext = 0; /* add */ + offs = -offs; + } - bemit_modru(reg, 5); /* sub */ - if (size == 8) { - bemit8(offs); - } else { - bemit32(offs); - } - } else if (offs < 0) { - bemit_modru(reg, 0); /* add */ - if (size == 8) { - bemit8(-offs); - } else { - bemit32(-offs); - } + size = get_signed_imm_size(offs); + bemit8(size == 1 ? 0x83 : 0x81); + + reg = get_out_reg(node, 0); + bemit_modru(reg, ext); + + if (size == 1) { + bemit8(offs); + } else { + bemit32(offs); } } -- 2.20.1