From patchwork Tue Dec 15 04:08:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 67471 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF4QSLi016846 for ; Tue, 15 Dec 2009 04:26:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759202AbZLOEIq (ORCPT ); Mon, 14 Dec 2009 23:08:46 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756331AbZLOEIn (ORCPT ); Mon, 14 Dec 2009 23:08:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32835 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932534AbZLOEHa (ORCPT ); Mon, 14 Dec 2009 23:07:30 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBF47Se9031625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Dec 2009 23:07:28 -0500 Received: from localhost.localdomain (vpn-9-100.rdu.redhat.com [10.11.9.100]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBF46m9A031119; Mon, 14 Dec 2009 23:07:26 -0500 From: Zachary Amsden To: kvm@vger.kernel.org Cc: Zachary Amsden , Avi Kivity , Marcelo Tosatti , Joerg Roedel , linux-kernel@vger.kernel.org, Dor Laor Subject: [PATCH RFC: kvm tsc virtualization 16/20] Fix 32-bit mult_precise Date: Mon, 14 Dec 2009 18:08:43 -1000 Message-Id: <1260850127-9766-17-git-send-email-zamsden@redhat.com> In-Reply-To: <1260850127-9766-16-git-send-email-zamsden@redhat.com> References: <1260850127-9766-1-git-send-email-zamsden@redhat.com> <1260850127-9766-2-git-send-email-zamsden@redhat.com> <1260850127-9766-3-git-send-email-zamsden@redhat.com> <1260850127-9766-4-git-send-email-zamsden@redhat.com> <1260850127-9766-5-git-send-email-zamsden@redhat.com> <1260850127-9766-6-git-send-email-zamsden@redhat.com> <1260850127-9766-7-git-send-email-zamsden@redhat.com> <1260850127-9766-8-git-send-email-zamsden@redhat.com> <1260850127-9766-9-git-send-email-zamsden@redhat.com> <1260850127-9766-10-git-send-email-zamsden@redhat.com> <1260850127-9766-11-git-send-email-zamsden@redhat.com> <1260850127-9766-12-git-send-email-zamsden@redhat.com> <1260850127-9766-13-git-send-email-zamsden@redhat.com> <1260850127-9766-14-git-send-email-zamsden@redhat.com> <1260850127-9766-15-git-send-email-zamsden@redhat.com> <1260850127-9766-16-git-send-email-zamsden@redhat.com> Organization: Frobozz Magic Timekeeping Company X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7e2ba3e..792c895 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -803,15 +803,27 @@ static void compute_best_multiplier(unsigned long a, unsigned long b, *s = shift; } -static inline unsigned long mult_precise(unsigned long val, unsigned long mult, - int shift) +static inline u64 mult_precise(u64 val, unsigned long mult, int shift) { +#if (BITS_PER_LONG == 64) unsigned long top, bot; - __asm__ ( "mul %3; shrd %1, %0" : + __asm__ ( "mulq %3; shrdq %1, %0" : "=&a" (bot), "=&d" (top) : "0" (mult), "rm" (val), "c" (shift)); return bot; +#else + unsigned long ltop, lbot; + unsigned long htop, hbot; + + __asm__ ( "mull %3; shrd %1, %0" : + "=&a" (lbot), "=&d" (ltop) : + "0" (mult), "rm" (long)(val), "c" (shift)); + __asm__ ( "mull %3; shrd %1, %0" : + "=&a" (hbot), "=&d" (htop) : + "0" (mult), "rm" (long)(val >> 32), "c" (shift)); + return (u64)lbot + ((u64)ltop + (u64)hbot) << 32; +#endif } static inline u64 compute_ref_tsc(void)