From: Avi Kivity Subject: [PATCH 3/6] Add IMUL tests Date: Sun, 22 Aug 2010 15:18:41 +0300 Message-ID: <1282479524-3791-4-git-send-email-avi@redhat.com> References: <1282479524-3791-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:61699 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752292Ab0HVMSp (ORCPT ); Sun, 22 Aug 2010 08:18:45 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7MCIja6027378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 22 Aug 2010 08:18:45 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7MCIijD027713 for ; Sun, 22 Aug 2010 08:18:45 -0400 In-Reply-To: <1282479524-3791-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: IMUL REG, R/M IMUL REG, R/M, IMM8 IMUL REG, R/M, IMM Signed-off-by: Avi Kivity --- x86/emulator.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/x86/emulator.c b/x86/emulator.c index d30ca8e..b0d15c0 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -535,6 +535,47 @@ void test_bsfbsr(void *mem) report("bsrq r/m, reg", rax == 1); } +static void test_imul(ulong *mem) +{ + ulong a; + + *mem = 51; a = 0x1234567812345678UL; + asm ("imulw %1, %%ax" : "+a"(a) : "m"(*mem)); + report("imul ax, mem", a == 0x12345678123439e8); + + *mem = 51; a = 0x1234567812345678UL; + asm ("imull %1, %%eax" : "+a"(a) : "m"(*mem)); + report("imul eax, mem", a == 0xa06d39e8); + + *mem = 51; a = 0x1234567812345678UL; + asm ("imulq %1, %%rax" : "+a"(a) : "m"(*mem)); + report("imul rax, mem", a == 0xA06D39EBA06D39E8UL); + + *mem = 0x1234567812345678UL; a = 0x8765432187654321L; + asm ("imulw $51, %1, %%ax" : "+a"(a) : "m"(*mem)); + report("imul ax, mem, imm8", a == 0x87654321876539e8); + + *mem = 0x1234567812345678UL; + asm ("imull $51, %1, %%eax" : "+a"(a) : "m"(*mem)); + report("imul eax, mem, imm8", a == 0xa06d39e8); + + *mem = 0x1234567812345678UL; + asm ("imulq $51, %1, %%rax" : "+a"(a) : "m"(*mem)); + report("imul rax, mem, imm8", a == 0xA06D39EBA06D39E8UL); + + *mem = 0x1234567812345678UL; a = 0x8765432187654321L; + asm ("imulw $311, %1, %%ax" : "+a"(a) : "m"(*mem)); + report("imul ax, mem, imm", a == 0x8765432187650bc8); + + *mem = 0x1234567812345678UL; + asm ("imull $311, %1, %%eax" : "+a"(a) : "m"(*mem)); + report("imul eax, mem, imm", a == 0x1d950bc8); + + *mem = 0x1234567812345678UL; + asm ("imulq $311, %1, %%rax" : "+a"(a) : "m"(*mem)); + report("imul rax, mem, imm", a == 0x1D950BDE1D950BC8L); +} + int main() { void *mem; @@ -570,6 +611,7 @@ int main() test_incdecnotneg(mem); test_btc(mem); test_bsfbsr(mem); + test_imul(mem); printf("\nSUMMARY: %d tests, %d failures\n", tests, fails); return fails ? 1 : 0; -- 1.7.1