From patchwork Mon Aug 9 10:01:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 118347 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 o79A3fEx027700 for ; Mon, 9 Aug 2010 10:03:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756043Ab0HIKDi (ORCPT ); Mon, 9 Aug 2010 06:03:38 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:56854 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755958Ab0HIKDi (ORCPT ); Mon, 9 Aug 2010 06:03:38 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 011141700BD; Mon, 9 Aug 2010 18:03:36 +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 o79A0U63028498; Mon, 9 Aug 2010 18:00:30 +0800 Received: from [10.167.141.76] (unknown [10.167.141.76]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 9995310C1F6; Mon, 9 Aug 2010 18:04:29 +0800 (CST) Message-ID: <4C5FD1E9.1030906@cn.fujitsu.com> Date: Mon, 09 Aug 2010 18:01:13 +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] test: add test for bsf/bsr instruction 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, 09 Aug 2010 10:03:41 +0000 (UTC) diff --git a/x86/emulator.c b/x86/emulator.c index aef5d90..348d548 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -462,6 +462,69 @@ void test_setcc(void *mem) report("setnle r/m8", *memb == 0); } +void test_bsfbsr(void *mem) +{ + unsigned long *memq = mem, rax; + + asm volatile("movw $0xC000, (%[memq])\n\t" + "bsfw (%[memq]), %%ax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsfw r/m, reg", rax == 14); + + asm volatile("movl $0xC0000000, (%[memq])\n\t" + "bsfl (%[memq]), %%eax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsfl r/m, reg", rax == 30); + + asm volatile("movq $0xC00000000000, %%rax\n\t" + "movq %%rax, (%[memq])\n\t" + "bsfq (%[memq]), %%rax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsfq r/m, reg", rax == 46); + + asm volatile("movq $0, %%rax\n\t" + "movq %%rax, (%[memq])\n\t" + "bsfq (%[memq]), %%rax\n\t" + "jnz 1f\n\t" + "movl $1, %[rax]\n\t" + "1:\n\t" + :[rax]"=m"(rax) + :[memq]"r"(memq)); + report("bsfq r/m, reg", rax == 1); + + asm volatile("movw $0xC000, (%[memq])\n\t" + "bsrw (%[memq]), %%ax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsrw r/m, reg", rax == 15); + + asm volatile("movl $0xC0000000, (%[memq])\n\t" + "bsrl (%[memq]), %%eax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsrl r/m, reg", rax == 31); + + asm volatile("movq $0xC00000000000, %%rax\n\t" + "movq %%rax, (%[memq])\n\t" + "bsrq (%[memq]), %%rax\n\t" + ::[memq]"r"(memq)); + asm ("mov %%rax, %[rax]": [rax]"=m"(rax)); + report("bsrq r/m, reg", rax == 47); + + asm volatile("movq $0, %%rax\n\t" + "movq %%rax, (%[memq])\n\t" + "bsrq (%[memq]), %%rax\n\t" + "jnz 1f\n\t" + "movl $1, %[rax]\n\t" + "1:\n\t" + :[rax]"=m"(rax) + :[memq]"r"(memq)); + report("bsrq r/m, reg", rax == 1); +} + int main() { void *mem; @@ -495,6 +558,7 @@ int main() test_incdecnotneg(mem); test_btc(mem); test_setcc(mem); + test_bsfbsr(mem); printf("\nSUMMARY: %d tests, %d failures\n", tests, fails); return fails ? 1 : 0;