From patchwork Thu Jan 24 04:03:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 215257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2626C2C007C for ; Thu, 24 Jan 2013 16:57:37 +1100 (EST) Received: from localhost ([::1]:39715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyE5t-0006Ao-9W for incoming@patchwork.ozlabs.org; Wed, 23 Jan 2013 23:07:17 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyE3j-0002tY-Ps for qemu-devel@nongnu.org; Wed, 23 Jan 2013 23:05:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyE3d-0004TW-G3 for qemu-devel@nongnu.org; Wed, 23 Jan 2013 23:05:03 -0500 Received: from mail-da0-f44.google.com ([209.85.210.44]:62551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyE3c-0004T9-WE for qemu-devel@nongnu.org; Wed, 23 Jan 2013 23:04:57 -0500 Received: by mail-da0-f44.google.com with SMTP id z20so4028048dae.31 for ; Wed, 23 Jan 2013 20:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=kG7LgPbxuUrkViB5iIUrgD9GNbGeEnv9EP+icy1ZQt8=; b=gADLOldTAWEzf/J8IEHh4u7CTgP1mYFTPB0IhM69qdG0N/BPa9A+B4xDQbee+NYVnN Mr7xjQc5XUlT7Qqwul4Eo8Q/HKlegkYToqI6Vfbtqa7b9ycRI9/kOJSMaLM17QdfD6/p UvN1ufT/+Y6HEcnqfQ6kSB2wqp9rCErhWGHv/seQnB2+6PZ95RQBr+ujpCvZppIZ+brY /mJ45IcaFNvL+8/wtzHKJdBE2dimczz0M4bqGzEoW/uA10+UUTelgd8nft2pdjsORHe1 0a9yLQkHdhqbT5CEbkrWfvF8+hxzOY2qklJJ0ha+dNIGYn7Xp+IRfrqe7QhwRVz6g3CM cbVQ== X-Received: by 10.68.224.227 with SMTP id rf3mr1379132pbc.108.1359000296280; Wed, 23 Jan 2013 20:04:56 -0800 (PST) Received: from anchor.twiddle.home (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id ot3sm14027480pbb.38.2013.01.23.20.04.54 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 23 Jan 2013 20:04:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 23 Jan 2013 20:03:27 -0800 Message-Id: <1359000221-19834-44-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1359000221-19834-1-git-send-email-rth@twiddle.net> References: <1359000221-19834-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.44 Cc: Blue Swirl , Paolo Bonzini Subject: [Qemu-devel] [PATCH 43/57] target-i386: Tidy prefix parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Avoid duplicating switch statement between 32 and 64-bit modes. Signed-off-by: Richard Henderson --- target-i386/translate.c | 134 +++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 82 deletions(-) diff --git a/target-i386/translate.c b/target-i386/translate.c index 2616a5c..91d3957 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -4272,44 +4272,44 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, next_byte: b = cpu_ldub_code(env, s->pc); s->pc++; - /* check prefixes */ + /* Collect prefixes. */ + switch (b) { + case 0xf3: + prefixes |= PREFIX_REPZ; + goto next_byte; + case 0xf2: + prefixes |= PREFIX_REPNZ; + goto next_byte; + case 0xf0: + prefixes |= PREFIX_LOCK; + goto next_byte; + case 0x2e: + s->override = R_CS; + goto next_byte; + case 0x36: + s->override = R_SS; + goto next_byte; + case 0x3e: + s->override = R_DS; + goto next_byte; + case 0x26: + s->override = R_ES; + goto next_byte; + case 0x64: + s->override = R_FS; + goto next_byte; + case 0x65: + s->override = R_GS; + goto next_byte; + case 0x66: + prefixes |= PREFIX_DATA; + goto next_byte; + case 0x67: + prefixes |= PREFIX_ADR; + goto next_byte; #ifdef TARGET_X86_64 - if (CODE64(s)) { - switch (b) { - case 0xf3: - prefixes |= PREFIX_REPZ; - goto next_byte; - case 0xf2: - prefixes |= PREFIX_REPNZ; - goto next_byte; - case 0xf0: - prefixes |= PREFIX_LOCK; - goto next_byte; - case 0x2e: - s->override = R_CS; - goto next_byte; - case 0x36: - s->override = R_SS; - goto next_byte; - case 0x3e: - s->override = R_DS; - goto next_byte; - case 0x26: - s->override = R_ES; - goto next_byte; - case 0x64: - s->override = R_FS; - goto next_byte; - case 0x65: - s->override = R_GS; - goto next_byte; - case 0x66: - prefixes |= PREFIX_DATA; - goto next_byte; - case 0x67: - prefixes |= PREFIX_ADR; - goto next_byte; - case 0x40 ... 0x4f: + case 0x40 ... 0x4f: + if (CODE64(s)) { /* REX prefix */ rex_w = (b >> 3) & 1; rex_r = (b & 0x4) << 1; @@ -4318,58 +4318,28 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, x86_64_hregs = 1; /* select uniform byte register addressing */ goto next_byte; } + break; +#endif + } + + /* Post-process prefixes. */ + if (prefixes & PREFIX_DATA) { + dflag ^= 1; + } + if (prefixes & PREFIX_ADR) { + aflag ^= 1; + } +#ifdef TARGET_X86_64 + if (CODE64(s)) { if (rex_w == 1) { /* 0x66 is ignored if rex.w is set */ dflag = 2; - } else { - if (prefixes & PREFIX_DATA) - dflag ^= 1; } - if (!(prefixes & PREFIX_ADR)) + if (!(prefixes & PREFIX_ADR)) { aflag = 2; - } else -#endif - { - switch (b) { - case 0xf3: - prefixes |= PREFIX_REPZ; - goto next_byte; - case 0xf2: - prefixes |= PREFIX_REPNZ; - goto next_byte; - case 0xf0: - prefixes |= PREFIX_LOCK; - goto next_byte; - case 0x2e: - s->override = R_CS; - goto next_byte; - case 0x36: - s->override = R_SS; - goto next_byte; - case 0x3e: - s->override = R_DS; - goto next_byte; - case 0x26: - s->override = R_ES; - goto next_byte; - case 0x64: - s->override = R_FS; - goto next_byte; - case 0x65: - s->override = R_GS; - goto next_byte; - case 0x66: - prefixes |= PREFIX_DATA; - goto next_byte; - case 0x67: - prefixes |= PREFIX_ADR; - goto next_byte; } - if (prefixes & PREFIX_DATA) - dflag ^= 1; - if (prefixes & PREFIX_ADR) - aflag ^= 1; } +#endif s->prefix = prefixes; s->aflag = aflag;