From patchwork Wed Apr 14 15:26:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 50186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 29D9CB7D27 for ; Thu, 15 Apr 2010 07:14:18 +1000 (EST) Received: from localhost ([127.0.0.1]:46914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O29uZ-0004OJ-1j for incoming@patchwork.ozlabs.org; Wed, 14 Apr 2010 17:14:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O29XX-0004rx-65 for qemu-devel@nongnu.org; Wed, 14 Apr 2010 16:50:27 -0400 Received: from [140.186.70.92] (port=35472 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O29XL-0004eV-5W for qemu-devel@nongnu.org; Wed, 14 Apr 2010 16:50:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O29XG-0001QL-HK for qemu-devel@nongnu.org; Wed, 14 Apr 2010 16:50:14 -0400 Received: from are.twiddle.net ([75.149.56.221]:41952) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O29XG-0001QH-7B for qemu-devel@nongnu.org; Wed, 14 Apr 2010 16:50:10 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id A377AA61; Wed, 14 Apr 2010 13:50:09 -0700 (PDT) Message-Id: <5abfe2948de7d91b2760746476abbbc716bcb924.1271277329.git.rth@twiddle.net> In-Reply-To: References: From: Richard Henderson Date: Wed, 14 Apr 2010 08:26:50 -0700 To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: aurelien@aurel32.net Subject: [Qemu-devel] [PATCH 09/21] tcg-i386: Tidy jumps. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Define OPC_JCC*, OC_JMP*, and EXT_JMPN_Ev. Use them throughout. Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.c | 58 +++++++++++++++++++++++++++--------------------- 1 files changed, 33 insertions(+), 25 deletions(-) diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c index 5829c5b..9d728f5 100644 --- a/tcg/i386/tcg-target.c +++ b/tcg/i386/tcg-target.c @@ -164,6 +164,10 @@ static inline int tcg_target_const_match(tcg_target_long val, #define P_EXT 0x100 /* 0x0f opcode prefix */ #define OPC_BSWAP (0xc8 | P_EXT) +#define OPC_JCC_long (0x80 | P_EXT) /* ... plus condition code */ +#define OPC_JCC_short (0x70) /* ... plus condition code */ +#define OPC_JMP_long (0xe9) +#define OPC_JMP_short (0xeb) #define OPC_MOVB_EvGv (0x88) /* stores, more or less */ #define OPC_MOVL_EvGv (0x89) /* stores, more or less */ #define OPC_MOVL_GvEv (0x8b) /* loads, more or less */ @@ -175,6 +179,7 @@ static inline int tcg_target_const_match(tcg_target_long val, #define OPC_SHIFT_Ib (0xc1) #define OPC_SHIFT_cl (0xd3) +/* Group 1 opcode extensions for 0x80-0x83. */ #define ARITH_ADD 0 #define ARITH_OR 1 #define ARITH_ADC 2 @@ -184,12 +189,17 @@ static inline int tcg_target_const_match(tcg_target_long val, #define ARITH_XOR 6 #define ARITH_CMP 7 +/* Group 2 opcode extensions for 0xc0, 0xc1, 0xd0-0xd3. */ #define SHIFT_ROL 0 #define SHIFT_ROR 1 #define SHIFT_SHL 4 #define SHIFT_SHR 5 #define SHIFT_SAR 7 +/* Group 5 opcode extensions for 0xff. */ +#define EXT_JMPN_Ev 4 + +/* Condition codes to be added to OPC_JCC_{long,short}. */ #define JCC_JMP (-1) #define JCC_JO 0x0 #define JCC_JNO 0x1 @@ -403,9 +413,9 @@ static void tcg_out_jxx(TCGContext *s, int opc, int label_index, int small) val1 = val - 2; if ((int8_t)val1 == val1) { if (opc == -1) { - tcg_out8(s, 0xeb); + tcg_out8(s, OPC_JMP_short); } else { - tcg_out8(s, 0x70 + opc); + tcg_out8(s, OPC_JCC_short + opc); } tcg_out8(s, val1); } else { @@ -413,28 +423,26 @@ static void tcg_out_jxx(TCGContext *s, int opc, int label_index, int small) tcg_abort(); } if (opc == -1) { - tcg_out8(s, 0xe9); + tcg_out8(s, OPC_JMP_long); tcg_out32(s, val - 5); } else { - tcg_out8(s, 0x0f); - tcg_out8(s, 0x80 + opc); + tcg_out_opc(s, OPC_JCC_long + opc); tcg_out32(s, val - 6); } } } else if (small) { if (opc == -1) { - tcg_out8(s, 0xeb); + tcg_out8(s, OPC_JMP_short); } else { - tcg_out8(s, 0x70 + opc); + tcg_out8(s, OPC_JCC_short + opc); } tcg_out_reloc(s, s->code_ptr, R_386_PC8, label_index, -1); s->code_ptr += 1; } else { if (opc == -1) { - tcg_out8(s, 0xe9); + tcg_out8(s, OPC_JMP_long); } else { - tcg_out8(s, 0x0f); - tcg_out8(s, 0x80 + opc); + tcg_out_opc(s, OPC_JCC_long + opc); } tcg_out_reloc(s, s->code_ptr, R_386_PC32, label_index, -4); s->code_ptr += 4; @@ -677,12 +685,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, #if TARGET_LONG_BITS == 32 /* je label1 */ - tcg_out8(s, 0x70 + JCC_JE); + tcg_out8(s, OPC_JCC_short + JCC_JE); label1_ptr = s->code_ptr; s->code_ptr++; #else /* jne label3 */ - tcg_out8(s, 0x70 + JCC_JNE); + tcg_out8(s, OPC_JCC_short + JCC_JNE); label3_ptr = s->code_ptr; s->code_ptr++; @@ -690,7 +698,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, tcg_out_modrm_offset(s, 0x3b, addr_reg2, r1, 4); /* je label1 */ - tcg_out8(s, 0x70 + JCC_JE); + tcg_out8(s, OPC_JCC_short + JCC_JE); label1_ptr = s->code_ptr; s->code_ptr++; @@ -738,7 +746,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, } /* jmp label2 */ - tcg_out8(s, 0xeb); + tcg_out8(s, OPC_JMP_short); label2_ptr = s->code_ptr; s->code_ptr++; @@ -870,12 +878,12 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, #if TARGET_LONG_BITS == 32 /* je label1 */ - tcg_out8(s, 0x70 + JCC_JE); + tcg_out8(s, OPC_JCC_short + JCC_JE); label1_ptr = s->code_ptr; s->code_ptr++; #else /* jne label3 */ - tcg_out8(s, 0x70 + JCC_JNE); + tcg_out8(s, OPC_JCC_short + JCC_JNE); label3_ptr = s->code_ptr; s->code_ptr++; @@ -883,7 +891,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, tcg_out_modrm_offset(s, 0x3b, addr_reg2, r1, 4); /* je label1 */ - tcg_out8(s, 0x70 + JCC_JE); + tcg_out8(s, OPC_JCC_short + JCC_JE); label1_ptr = s->code_ptr; s->code_ptr++; @@ -953,7 +961,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, #endif /* jmp label2 */ - tcg_out8(s, 0xeb); + tcg_out8(s, OPC_JMP_short); label2_ptr = s->code_ptr; s->code_ptr++; @@ -1026,19 +1034,18 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, switch(opc) { case INDEX_op_exit_tb: tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_EAX, args[0]); - tcg_out8(s, 0xe9); /* jmp tb_ret_addr */ + tcg_out8(s, OPC_JMP_long); /* jmp tb_ret_addr */ tcg_out32(s, tb_ret_addr - s->code_ptr - 4); break; case INDEX_op_goto_tb: if (s->tb_jmp_offset) { /* direct jump method */ - tcg_out8(s, 0xe9); /* jmp im */ + tcg_out8(s, OPC_JMP_long); /* jmp im */ s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf; tcg_out32(s, 0); } else { /* indirect jump method */ - /* jmp Ev */ - tcg_out_modrm_offset(s, 0xff, 4, -1, + tcg_out_modrm_offset(s, 0xff, EXT_JMPN_Ev, -1, (tcg_target_long)(s->tb_next + args[0])); } s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf; @@ -1053,10 +1060,11 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_jmp: if (const_args[0]) { - tcg_out8(s, 0xe9); + tcg_out8(s, OPC_JMP_long); tcg_out32(s, args[0] - (tcg_target_long)s->code_ptr - 4); } else { - tcg_out_modrm(s, 0xff, 4, args[0]); + /* jmp *reg */ + tcg_out_modrm(s, 0xff, EXT_JMPN_Ev, args[0]); } break; case INDEX_op_br: @@ -1381,7 +1389,7 @@ void tcg_target_qemu_prologue(TCGContext *s) stack_addend = frame_size - push_size; tcg_out_addi(s, TCG_REG_ESP, -stack_addend); - tcg_out_modrm(s, 0xff, 4, TCG_REG_EAX); /* jmp *%eax */ + tcg_out_modrm(s, 0xff, EXT_JMPN_Ev, TCG_REG_EAX); /* jmp *%eax */ /* TB epilogue */ tb_ret_addr = s->code_ptr;