public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: mtosatti@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: x86 emulator: move string instruction completion check into separate function
Date: Tue, 24 Aug 2010 16:20:33 +0300	[thread overview]
Message-ID: <20100824132033.GB10499@redhat.com> (raw)
In-Reply-To: <4C73C4F8.9030809@redhat.com>

On Tue, Aug 24, 2010 at 04:11:20PM +0300, Avi Kivity wrote:
>  On 08/24/2010 02:30 PM, Gleb Natapov wrote:
> >Signed-off-by: Gleb Natapov<gleb@redhat.com>
> >---
> >  arch/x86/kvm/emulate.c |   42 +++++++++++++++++++++++++++++-------------
> >  1 files changed, 29 insertions(+), 13 deletions(-)
> >
> >diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> >index f9f8353..d34d706 100644
> >--- a/arch/x86/kvm/emulate.c
> >+++ b/arch/x86/kvm/emulate.c
> >@@ -2921,6 +2921,32 @@ done:
> >  	return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
> >  }
> >
> >+static bool string_inst_completed(struct x86_emulate_ctxt *ctxt)
> 
> s/inst/insn/.
> 
> >+{
> >+	struct decode_cache *c =&ctxt->decode;
> >+
> >+	/* All REP prefixes have the same first termination condition */
> >+	if (address_mask(c, c->regs[VCPU_REGS_RCX]) == 0)
> >+		return true;
> 
> This is checked during the beginning of the instruction, not after
> completion.  Why is it here?  it will just be duplicated.
> 
SDM describes REP instruction algorithm this way:

WHILE CountReg ≠ 0
  DO
       Service pending interrupts (if any);
       Execute associated string instruction;
       CountReg ← (CountReg – 1);
       IF CountReg = 0
            THEN exit WHILE loop; FI;
       IF (Repeat prefix is REPZ or REPE) and (ZF = 0)
       or (Repeat prefix is REPNZ or REPNE) and (ZF = 1)
            THEN exit WHILE loop; FI;
  OD;

So CountReg is checked at the beginning and after each iteration.
Practically it will save us one return to a guest and exit back
to emulator at the end of rep instruction (not a big deal).

> >+
> >+	/* The second termination condition only applies for REPE
> >+	 * and REPNE. Test if the repeat string operation prefix is
> >+	 * REPE/REPZ or REPNE/REPNZ and if it's the case it tests the
> >+	 * corresponding termination condition according to:
> >+	 * 	- if REPE/REPZ and ZF = 0 then done
> >+	 * 	- if REPNE/REPNZ and ZF = 1 then done
> >+	 */
> >+	if (((c->b == 0xa6) || (c->b == 0xa7) ||
> >+	     (c->b == 0xae) || (c->b == 0xaf))
> >+	&&  (((c->rep_prefix == REPE_PREFIX)&&
> >+		 ((ctxt->eflags&  EFLG_ZF) == 0))
> >+		|| ((c->rep_prefix == REPNE_PREFIX)&&
> >+		    ((ctxt->eflags&  EFLG_ZF) == EFLG_ZF))))
> >+		return true;
> >+
> >+	return false;
> >+}
> >+
> 
> -- 
> error compiling committee.c: too many arguments to function

--
			Gleb.

  reply	other threads:[~2010-08-24 13:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-24 11:30 [PATCH 1/3] KVM: x86 emulator: Rename variable that shadows another local variable Gleb Natapov
2010-08-24 11:30 ` [PATCH 2/3] KVM: x86 emulator: move string instruction completion check into separate function Gleb Natapov
2010-08-24 13:11   ` Avi Kivity
2010-08-24 13:20     ` Gleb Natapov [this message]
2010-08-24 13:24       ` Avi Kivity
2010-08-24 11:30 ` [PATCH 3/3] KVM: x86 emulator: get rid of "restart" in emulation context Gleb Natapov
2010-08-24 13:13   ` Avi Kivity
2010-08-24 13:37     ` Gleb Natapov
2010-08-24 13:41       ` Avi Kivity
2010-08-24 13:52         ` Gleb Natapov
2010-08-24 14:01           ` Avi Kivity
2010-08-24 14:06             ` Gleb Natapov
2010-08-24 14:28               ` Avi Kivity
2010-08-24 14:46                 ` Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100824132033.GB10499@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox