cpu-exec: simplify icount code

Use MIN instead of an "if" statement.  Move "tb" assignment where
the value is actually used.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Paolo Bonzini 2015-01-26 12:12:22 +01:00 committed by Michael Tokarev
parent a7fa2e9783
commit 52851b7e3d

View File

@ -499,22 +499,17 @@ int cpu_exec(CPUArchState *env)
case TB_EXIT_ICOUNT_EXPIRED: case TB_EXIT_ICOUNT_EXPIRED:
{ {
/* Instruction counter expired. */ /* Instruction counter expired. */
int insns_left; int insns_left = cpu->icount_decr.u32;
tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
insns_left = cpu->icount_decr.u32;
if (cpu->icount_extra && insns_left >= 0) { if (cpu->icount_extra && insns_left >= 0) {
/* Refill decrementer and continue execution. */ /* Refill decrementer and continue execution. */
cpu->icount_extra += insns_left; cpu->icount_extra += insns_left;
if (cpu->icount_extra > 0xffff) { insns_left = MIN(0xffff, cpu->icount_extra);
insns_left = 0xffff;
} else {
insns_left = cpu->icount_extra;
}
cpu->icount_extra -= insns_left; cpu->icount_extra -= insns_left;
cpu->icount_decr.u16.low = insns_left; cpu->icount_decr.u16.low = insns_left;
} else { } else {
if (insns_left > 0) { if (insns_left > 0) {
/* Execute remaining instructions. */ /* Execute remaining instructions. */
tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
cpu_exec_nocache(env, insns_left, tb); cpu_exec_nocache(env, insns_left, tb);
align_clocks(&sc, cpu); align_clocks(&sc, cpu);
} }