From patchwork Thu Aug 12 13:44:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 119270 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 o7CDkuZT023958 for ; Thu, 12 Aug 2010 13:46:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759978Ab0HLNqy (ORCPT ); Thu, 12 Aug 2010 09:46:54 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:53537 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752001Ab0HLNqx (ORCPT ); Thu, 12 Aug 2010 09:46:53 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 4EAEE1700BD; Thu, 12 Aug 2010 21:46:43 +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 o7CDhRqF020197; Thu, 12 Aug 2010 21:43:27 +0800 Received: from [10.167.141.76] (unknown [10.167.141.76]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 3E3FF10C1F6; Thu, 12 Aug 2010 21:47:32 +0800 (CST) Message-ID: <4C63FAA1.5010705@cn.fujitsu.com> Date: Thu, 12 Aug 2010 21:44:01 +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 , kvm@vger.kernel.org Subject: [PATCH] test: Add test for xadd 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]); Thu, 12 Aug 2010 13:46:57 +0000 (UTC) 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();