From patchwork Mon Aug 23 07:15:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 123451 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7N7GweG012369 for ; Mon, 23 Aug 2010 07:16:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333Ab0HWHQ4 (ORCPT ); Mon, 23 Aug 2010 03:16:56 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:62931 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752105Ab0HWHQz (ORCPT ); Mon, 23 Aug 2010 03:16:55 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 3C085170184; Mon, 23 Aug 2010 15:16:53 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o7N7DZOP027629; Mon, 23 Aug 2010 15:13:35 +0800 Received: from [10.167.141.76] (unknown [10.167.141.76]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 19CC714C021; Mon, 23 Aug 2010 15:18:01 +0800 (CST) Message-ID: <4C722003.1090401@cn.fujitsu.com> Date: Mon, 23 Aug 2010 15:15:15 +0800 From: Wei Yongjun User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100528 Thunderbird/3.0.5 MIME-Version: 1.0 To: Avi Kivity CC: kvm@vger.kernel.org Subject: [PATCH] KVM: x86 emulator: simplify BSF/BSR instruction emulation Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 23 Aug 2010 07:16:58 +0000 (UTC) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7d99cbe..77da7b6 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3727,30 +3727,16 @@ twobyte_insn: btc: /* btc */ emulate_2op_SrcV_nobyte("btc", c->src, c->dst, ctxt->eflags); break; - case 0xbc: { /* bsf */ - u8 zf; - __asm__ ("bsf %2, %0; setz %1" - : "=r"(c->dst.val), "=q"(zf) - : "r"(c->src.val)); - ctxt->eflags &= ~X86_EFLAGS_ZF; - if (zf) { - ctxt->eflags |= X86_EFLAGS_ZF; - c->dst.type = OP_NONE; /* Disable writeback. */ - } + case 0xbc: /* bsf */ + emulate_2op_SrcV_nobyte("bsf", c->src, c->dst, ctxt->eflags); + if (ctxt->eflags & X86_EFLAGS_ZF) + c->dst.type = OP_NONE; /* Disable writeback. */ break; - } - case 0xbd: { /* bsr */ - u8 zf; - __asm__ ("bsr %2, %0; setz %1" - : "=r"(c->dst.val), "=q"(zf) - : "r"(c->src.val)); - ctxt->eflags &= ~X86_EFLAGS_ZF; - if (zf) { - ctxt->eflags |= X86_EFLAGS_ZF; - c->dst.type = OP_NONE; /* Disable writeback. */ - } + case 0xbd: /* bsr */ + emulate_2op_SrcV_nobyte("bsr", c->src, c->dst, ctxt->eflags); + if (ctxt->eflags & X86_EFLAGS_ZF) + c->dst.type = OP_NONE; /* Disable writeback. */ break; - } case 0xbe ... 0xbf: /* movsx */ c->dst.bytes = c->op_bytes; c->dst.val = (c->d & ByteOp) ? (s8) c->src.val :