From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haozhong Zhang Subject: Re: [PATCH v3 07/13] x86: Add functions for 64-bit integer arithmetic Date: Fri, 8 Jan 2016 21:48:52 +0800 Message-ID: <20160108134852.GD16393@hz-desktop.sh.intel.com> References: <1451531020-29964-1-git-send-email-haozhong.zhang@intel.com> <1451531020-29964-8-git-send-email-haozhong.zhang@intel.com> <568F90BD02000078000C4BFE@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <568F90BD02000078000C4BFE@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Kevin Tian , Keir Fraser , Suravee Suthikulpanit , Andrew Cooper , xen-devel@lists.xen.org, Aravind Gopalakrishnan , Jun Nakajima , Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org On 01/08/16 02:34, Jan Beulich wrote: > >>> On 31.12.15 at 04:03, wrote: > > --- /dev/null > > +++ b/xen/include/asm-x86/math64.h > > @@ -0,0 +1,105 @@ > > +#ifndef __X86_MATH64 > > +#define __X86_MATH64 > > + > > +/* > > + * Functions defined in this file are derived from Linux kernel > > + * (include/linux/math64.h). > > + */ > > This is not true. At least mul64() doesn't exist in Linux (as of 4.4-rc8). > My fault. I took them from my KVM patches and didn't notice they were refactored a little when merging. > > +static inline void mul64(u64 *lo, u64 *hi, u64 a, u64 b) > > +{ > > + typedef union { > > + u64 ll; > > + struct { > > + u32 low, high; > > + } l; > > + } LL; > > + LL rl, rm, rn, rh, a0, b0; > > + u64 c; > > + > > + a0.ll = a; > > + b0.ll = b; > > + > > + rl.ll = (u64)a0.l.low * b0.l.low; > > + rm.ll = (u64)a0.l.low * b0.l.high; > > + rn.ll = (u64)a0.l.high * b0.l.low; > > + rh.ll = (u64)a0.l.high * b0.l.high; > > + > > + c = (u64)rl.l.high + rm.l.low + rn.l.low; > > + rl.l.high = c; > > + c >>= 32; > > + c = c + rm.l.high + rn.l.high + rh.l.low; > > + rh.l.low = c; > > + rh.l.high += (u32)(c >> 32); > > + > > + *lo = rl.ll; > > + *hi = rh.ll; > > +} > > For this one in particular, but likely also for the others: If this was > put in include/xen/math64.h I might buy it. As an x86-specific > implementation this could (and should) be done with a single asm() > statement using the MUL instruction (I didn't check whether gcc > also offers a built-in, which then could be used generically). > gcc does provide a 128-bit integer type __int128. If my memory is correct, it can be used for above mul64, but can not be compiled in Xen if being used for division. Anyway, as above functions are x86-specific so far, I'll reimplement them by assembly in the next version. Haozhong