From patchwork Wed Apr 28 17:31:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 51218 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 227ABB7D43 for ; Thu, 29 Apr 2010 05:28:49 +1000 (EST) Received: from localhost ([127.0.0.1]:36167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Cvn-0000Wk-VE for incoming@patchwork.ozlabs.org; Wed, 28 Apr 2010 15:28:24 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7C1s-0000QS-5J for qemu-devel@nongnu.org; Wed, 28 Apr 2010 14:30:36 -0400 Received: from [140.186.70.92] (port=46650 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7C1Y-0000GX-9v for qemu-devel@nongnu.org; Wed, 28 Apr 2010 14:30:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7C1R-0004RL-Mg for qemu-devel@nongnu.org; Wed, 28 Apr 2010 14:30:16 -0400 Received: from are.twiddle.net ([75.149.56.221]:36480) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7C1R-0004Qa-Bu for qemu-devel@nongnu.org; Wed, 28 Apr 2010 14:30:09 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id 0269CDD3; Wed, 28 Apr 2010 11:30:06 -0700 (PDT) Message-Id: In-Reply-To: References: From: Richard Henderson Date: Wed, 28 Apr 2010 10:31:18 -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 05/22] tcg-i386: Tidy bswap operations. 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_BSWAP. Factor opcode emission to separate functions. Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.c | 52 ++++++++++++++++++++++-------------------------- 1 files changed, 24 insertions(+), 28 deletions(-) diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c index 75b9915..094b2da 100644 --- a/tcg/i386/tcg-target.c +++ b/tcg/i386/tcg-target.c @@ -163,6 +163,7 @@ 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_MOVZBL (0xb6 | P_EXT) #define OPC_MOVZWL (0xb7 | P_EXT) #define OPC_MOVSBL (0xbe | P_EXT) @@ -339,6 +340,18 @@ static inline void tcg_out_ext16s(TCGContext *s, int dest, int src) tcg_out_modrm(s, OPC_MOVSWL, dest, src); } +static inline void tcg_out_bswap32(TCGContext *s, int reg) +{ + tcg_out_opc(s, OPC_BSWAP + reg); +} + +static inline void tcg_out_rolw_8(TCGContext *s, int reg) +{ + tcg_out8(s, 0x66); + tcg_out_modrm(s, 0xc1, 0, reg); + tcg_out8(s, 8); +} + static inline void tgen_arithi(TCGContext *s, int c, int r0, int32_t val, int cf) { if (!cf && ((c == ARITH_ADD && val == 1) || (c == ARITH_SUB && val == -1))) { @@ -745,22 +758,14 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, /* movzwl */ tcg_out_modrm_offset(s, OPC_MOVZWL, data_reg, r0, GUEST_BASE); if (bswap) { - /* rolw $8, data_reg */ - tcg_out8(s, 0x66); - tcg_out_modrm(s, 0xc1, 0, data_reg); - tcg_out8(s, 8); + tcg_out_rolw_8(s, data_reg); } break; case 1 | 4: /* movswl */ tcg_out_modrm_offset(s, OPC_MOVSWL, data_reg, r0, GUEST_BASE); if (bswap) { - /* rolw $8, data_reg */ - tcg_out8(s, 0x66); - tcg_out_modrm(s, 0xc1, 0, data_reg); - tcg_out8(s, 8); - - /* movswl data_reg, data_reg */ + tcg_out_rolw_8(s, data_reg); tcg_out_modrm(s, OPC_MOVSWL, data_reg, data_reg); } break; @@ -768,8 +773,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, /* movl (r0), data_reg */ tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE); if (bswap) { - /* bswap */ - tcg_out_opc(s, (0xc8 + data_reg) | P_EXT); + tcg_out_bswap32(s, data_reg); } break; case 3: @@ -786,11 +790,10 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, GUEST_BASE + 4); } else { tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE + 4); - tcg_out_opc(s, (0xc8 + data_reg) | P_EXT); + tcg_out_bswap32(s, data_reg); tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, GUEST_BASE); - /* bswap */ - tcg_out_opc(s, (0xc8 + data_reg2) | P_EXT); + tcg_out_bswap32(s, data_reg2); } break; default: @@ -970,9 +973,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, case 1: if (bswap) { tcg_out_mov(s, r1, data_reg); - tcg_out8(s, 0x66); /* rolw $8, %ecx */ - tcg_out_modrm(s, 0xc1, 0, r1); - tcg_out8(s, 8); + tcg_out_rolw_8(s, r1); data_reg = r1; } /* movw */ @@ -982,8 +983,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, case 2: if (bswap) { tcg_out_mov(s, r1, data_reg); - /* bswap data_reg */ - tcg_out_opc(s, (0xc8 + r1) | P_EXT); + tcg_out_bswap32(s, r1); data_reg = r1; } /* movl */ @@ -992,12 +992,10 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, case 3: if (bswap) { tcg_out_mov(s, r1, data_reg2); - /* bswap data_reg */ - tcg_out_opc(s, (0xc8 + r1) | P_EXT); + tcg_out_bswap32(s, r1); tcg_out_modrm_offset(s, 0x89, r1, r0, GUEST_BASE); tcg_out_mov(s, r1, data_reg); - /* bswap data_reg */ - tcg_out_opc(s, (0xc8 + r1) | P_EXT); + tcg_out_bswap32(s, r1); tcg_out_modrm_offset(s, 0x89, r1, r0, GUEST_BASE + 4); } else { tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE); @@ -1195,12 +1193,10 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_bswap16_i32: - tcg_out8(s, 0x66); - tcg_out_modrm(s, 0xc1, SHIFT_ROL, args[0]); - tcg_out8(s, 8); + tcg_out_rolw_8(s, args[0]); break; case INDEX_op_bswap32_i32: - tcg_out_opc(s, (0xc8 + args[0]) | P_EXT); + tcg_out_bswap32(s, args[0]); break; case INDEX_op_neg_i32: