All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] test: Add test for xadd instruction
@ 2010-08-12 13:44 Wei Yongjun
  2010-08-17  9:34 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2010-08-12 13:44 UTC (permalink / raw)
  To: Avi Kivity, kvm

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

diff --git a/x86/emulator.c b/x86/emulator.c
index 348d548..c4579ab 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -360,6 +360,56 @@ void test_xchg(void *mem)
 	       rax == 0x123456789abcdef && *memq == 0xfedcba9876543210);
 }
 
+void test_xadd(void *mem)
+{
+	unsigned long *memq = mem;
+	unsigned long rax;
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xadd %%al, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xadd reg, r/m (1)",
+	       rax == 0xfedcba98765432ef && *memq == 0x123456789abcdff);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xadd %%ax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xadd reg, r/m (2)",
+	       rax == 0xfedcba987654cdef && *memq == 0x123456789abffff);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xadd %%eax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xadd reg, r/m (3)",
+	       rax == 0x89abcdef && *memq == 0x1234567ffffffff);
+
+	asm volatile("mov $0x123456789abcdef, %%rax\n\t"
+		     "mov %%rax, (%[memq])\n\t"
+		     "mov $0xfedcba9876543210, %%rax\n\t"
+		     "xadd %%rax, (%[memq])\n\t"
+		     "mov %%rax, %[rax]\n\t"
+		     : [rax]"=r"(rax)
+		     : [memq]"r"(memq)
+		     : "memory");
+	report("xadd reg, r/m (4)",
+	       rax == 0x123456789abcdef && *memq == 0xffffffffffffffff);
+}
+
 void test_btc(void *mem)
 {
 	unsigned int *a = mem;
@@ -548,6 +598,7 @@ int main()
 	test_pop(mem);
 
 	test_xchg(mem);
+	test_xadd(mem);
 
 	test_cr8();
 
-- 
1.7.0.4



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

end of thread, other threads:[~2010-08-17  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-12 13:44 [PATCH] test: Add test for xadd instruction Wei Yongjun
2010-08-17  9:34 ` 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.