From: "Zhang, Haozhong" Subject: Re: [PATCH v4 05/10] x86: Add functions for 64-bit integer arithmetic Date: Tue, 16 Feb 2016 17:02:20 +0800 Message-ID: <20160216090220.GB5459@hz-desktop.sh.intel.com> References: <1453067939-9121-1-git-send-email-haozhong.zhang@intel.com> <1453067939-9121-6-git-send-email-haozhong.zhang@intel.com> <56B4B38702000078000CF09F@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: <56B4B38702000078000CF09F@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: "Tian, Kevin" , Keir Fraser , Suravee Suthikulpanit , Andrew Cooper , "xen-devel@lists.xen.org" , Aravind Gopalakrishnan , "Nakajima, Jun" , Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org On 02/05/16 21:36, Jan Beulich wrote: > >>> On 17.01.16 at 22:58, wrote: > > 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. > > Thanks, but it puzzles me that the other one didn't get converted > as well. Anyway, I'm not going to make this a requirement, since > at least it appears to match Linux'es variant. > I can't remember why I didn't rewrite mul_u64_u32_div(), especially when it can be easily implemented as static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) { u64 quotient, remainder; asm volatile ( "mulq %3; divq %4" : "=a" (quotient), "=d" (remainder) : "0" (a), "rm" ((u64) mul), "c" ((u64) divisor) ); return quotient; } I'll modify it in the next version. > > +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) ); > > SHRD formally is a 3-operand instruction, and the fact that gas' > AT&T syntax supports a 2-operand "alias" is, well, odd. Please > let's use the specification mandated 3-operand form properly, > to avoid surprises with e.g. clang. > OK, I'll change it to the 3-operand form. Haozhong