Skip to contentSkip to conversation

emulator: test shld, shrd

PATCH New Avi Kivity 1 participant 1 message Sep 13, 2011 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 emulator: test shld, shrd

Used to be broken in multiple ways.

---
 x86/emulator.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
x86/emulator.c +11 -0
index d4f0363..73079f8 100644
@@ -642,6 +642,16 @@ static void test_rip_relative(unsigned *mem, char *insn_ram)
     report("movb $imm, 0(%rip)", *mem == 0x10000);
 }
 
+static void test_shld_shrd(u32 *mem)
+{
+    *mem = 0x12345678;
+    asm("shld %2, %1, %0" : "+m"(*mem) : "r"(0xaaaaaaaaU), "c"((u8)3));
+    report("shld (cl)", *mem == ((0x12345678 << 3) | 5));
+    *mem = 0x12345678;
+    asm("shrd %2, %1, %0" : "+m"(*mem) : "r"(0x55555555U), "c"((u8)3));
+    report("shrd (cl)", *mem == ((0x12345678 >> 3) | (5u << 29)));
+}
+
 int main()
 {
 	void *mem;
@@ -684,6 +694,7 @@ int main()
 	test_div(mem);
 	test_sse(mem);
 	test_rip_relative(mem, insn_ram);
+	test_shld_shrd(mem);
 
 	printf("\nSUMMARY: %d tests, %d failures\n", tests, fails);
 	return fails ? 1 : 0;
Signature · 1 line
1.7.6.1