All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] test: add test for bsf/bsr instruction
@ 2010-08-09 10:01 Wei Yongjun
  2010-08-15 11:53 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2010-08-09 10:01 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

This patch add test for bsf/bsr instruction.

Signed-off-by: Wei Yongjun<yjwei@cn.fujitsu.com>
---
 x86/emulator.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

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;
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-15 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-09 10:01 [PATCH] test: add test for bsf/bsr instruction Wei Yongjun
2010-08-15 11:53 ` Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.