diff mbox

[RFC,v2,3/6] KVM: emulate: cleanup decode_rm

Message ID 1397174612-17373-4-git-send-email-bsd@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bandan Das April 11, 2014, 12:03 a.m. UTC
Remove the if conditional - that will help us avoid
an "else initialize to 0" Also, rearrange operators
for slightly better code.

Signed-off-by: Bandan Das <bsd@redhat.com>
---
 arch/x86/kvm/emulate.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Paolo Bonzini April 13, 2014, 12:51 p.m. UTC | #1
Il 10/04/2014 20:03, Bandan Das ha scritto:
> -	if (ctxt->rex_prefix) {
> -		ctxt->modrm_reg = (ctxt->rex_prefix & 4) << 1;	/* REX.R */
> -		index_reg = (ctxt->rex_prefix & 2) << 2; /* REX.X */
> -		ctxt->modrm_rm = base_reg = (ctxt->rex_prefix & 1) << 3; /* REG.B */
> -	}
> +	index_reg = (ctxt->rex_prefix << 2) & 8; /* REX.X */
> +	base_reg = (ctxt->rex_prefix << 3) & 8; /* REG.B */

This is REX.B (preexisting typo), and please leave REX.R here too for 
clarity.

Also, the function is "decode_modrm", not "decode_rm" (in the commit 
message).

Otherwise the series seems okay from a somewhat cursory review.

Paolo

>
> -	ctxt->modrm_mod |= (ctxt->modrm & 0xc0) >> 6;
> -	ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3;
> -	ctxt->modrm_rm |= (ctxt->modrm & 0x07);
> +	ctxt->modrm_mod = (ctxt->modrm & 0xc0) >> 6;
> +	ctxt->modrm_reg = ((ctxt->rex_prefix << 1) & 8) | /* REX.R */
> +		((ctxt->modrm & 0x38) >> 3);
> +	ctxt->modrm_rm = base_reg | (ctxt->modrm & 0x07);
>  	ctxt->modrm_seg = VCPU_SREG_DS;
>

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index a6d9892..9cbaba2 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1064,19 +1064,17 @@  static int decode_modrm(struct x86_emulate_ctxt *ctxt,
 			struct operand *op)
 {
 	u8 sib;
-	int index_reg = 0, base_reg = 0, scale;
+	int index_reg, base_reg, scale;
 	int rc = X86EMUL_CONTINUE;
 	ulong modrm_ea = 0;
 
-	if (ctxt->rex_prefix) {
-		ctxt->modrm_reg = (ctxt->rex_prefix & 4) << 1;	/* REX.R */
-		index_reg = (ctxt->rex_prefix & 2) << 2; /* REX.X */
-		ctxt->modrm_rm = base_reg = (ctxt->rex_prefix & 1) << 3; /* REG.B */
-	}
+	index_reg = (ctxt->rex_prefix << 2) & 8; /* REX.X */
+	base_reg = (ctxt->rex_prefix << 3) & 8; /* REG.B */
 
-	ctxt->modrm_mod |= (ctxt->modrm & 0xc0) >> 6;
-	ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3;
-	ctxt->modrm_rm |= (ctxt->modrm & 0x07);
+	ctxt->modrm_mod = (ctxt->modrm & 0xc0) >> 6;
+	ctxt->modrm_reg = ((ctxt->rex_prefix << 1) & 8) | /* REX.R */
+		((ctxt->modrm & 0x38) >> 3);
+	ctxt->modrm_rm = base_reg | (ctxt->modrm & 0x07);
 	ctxt->modrm_seg = VCPU_SREG_DS;
 
 	if (ctxt->modrm_mod == 3) {