From patchwork Sun Jan 17 21:58:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 8051011 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8484A9F818 for ; Sun, 17 Jan 2016 22:04:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4532F2025B for ; Sun, 17 Jan 2016 22:04:18 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A0106205B4 for ; Sun, 17 Jan 2016 22:03:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aKvN5-0003Qc-2d; Sun, 17 Jan 2016 22:00:27 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aKvN3-0003Q7-8O for xen-devel@lists.xen.org; Sun, 17 Jan 2016 22:00:25 +0000 Received: from [193.109.254.147] by server-15.bemta-14.messagelabs.com id 1D/96-10115-8FE0C965; Sun, 17 Jan 2016 22:00:24 +0000 X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1453068023!17380157!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49553 invoked from network); 17 Jan 2016 22:00:23 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-9.tower-27.messagelabs.com with SMTP; 17 Jan 2016 22:00:23 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 17 Jan 2016 14:00:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,309,1449561600"; d="scan'208";a="862676840" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.26]) by orsmga001.jf.intel.com with ESMTP; 17 Jan 2016 14:00:20 -0800 From: Haozhong Zhang To: xen-devel@lists.xen.org, Jan Beulich , Boris Ostrovsky , Kevin Tian Date: Mon, 18 Jan 2016 05:58:54 +0800 Message-Id: <1453067939-9121-6-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1453067939-9121-1-git-send-email-haozhong.zhang@intel.com> References: <1453067939-9121-1-git-send-email-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Keir Fraser , Suravee Suthikulpanit , Andrew Cooper , Aravind Gopalakrishnan , Jun Nakajima Subject: [Xen-devel] [PATCH v4 05/10] x86: Add functions for 64-bit integer arithmetic X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds several functions to take multiplication, division and shifting involving 64-bit integers. Signed-off-by: Haozhong Zhang Reviewed-by: Boris Ostrovsky --- Changes in v4: (addressing Jan Beulich's comments) * Rewrite mul_u64_u64_shr() in assembly. xen/include/asm-x86/math64.h | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 xen/include/asm-x86/math64.h diff --git a/xen/include/asm-x86/math64.h b/xen/include/asm-x86/math64.h new file mode 100644 index 0000000..2ddec62 --- /dev/null +++ b/xen/include/asm-x86/math64.h @@ -0,0 +1,47 @@ +#ifndef __X86_MATH64 +#define __X86_MATH64 + +/* + * (a * mul) / divisor + * + * This function is derived from Linux kernel + * (mul_u64_u32_div() in include/linux/math64.h) + */ +static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) +{ + union { + u64 ll; + struct { + u32 low, high; + } l; + } u, rl, rh; + + u.ll = a; + rl.ll = (u64)u.l.low * mul; + rh.ll = (u64)u.l.high * mul + rl.l.high; + + /* Bits 32-63 of the result will be in rh.l.low. */ + rl.l.high = do_div(rh.ll, divisor); + + /* Bits 0-31 of the result will be in rl.l.low. */ + do_div(rl.ll, divisor); + + rl.l.high = rh.l.low; + return rl.ll; +} + +/* + * (a * mul) >> n + */ +static inline u64 mul_u64_u64_shr(u64 a, u64 mul, unsigned int n) +{ + u64 hi, lo; + + asm volatile ( "mulq %2; shrdq %1,%0" + : "=a" (lo), "=d" (hi) + : "rm" (mul), "0" (a), "c" (n) ); + + return lo; +} + +#endif