From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754031AbdBHRyF (ORCPT ); Wed, 8 Feb 2017 12:54:05 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:54458 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbdBHRxq (ORCPT ); Wed, 8 Feb 2017 12:53:46 -0500 Date: Wed, 8 Feb 2017 18:52:53 +0100 (CET) From: Thomas Gleixner To: Andy Lutomirski cc: Vitaly Kuznetsov , X86 ML , Ingo Molnar , "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , "linux-kernel@vger.kernel.org" , devel@linuxdriverproject.org, Linux Virtualization Subject: Re: [PATCH RFC 2/2] x86/vdso: Add VCLOCK_HVCLOCK vDSO clock read method In-Reply-To: Message-ID: References: <20170208170744.7632-1-vkuznets@redhat.com> <20170208170744.7632-3-vkuznets@redhat.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 8 Feb 2017, Andy Lutomirski wrote: > > +#ifdef CONFIG_HYPERV_CLOCK > > +/* (a * b) >> 64 implementation */ > > +static inline u64 mul64x64_hi(u64 a, u64 b) > > +{ > > + u64 a_lo, a_hi, b_lo, b_hi, p1, p2; > > + > > + a_lo = (u32)a; > > + a_hi = a >> 32; > > + b_lo = (u32)b; > > + b_hi = b >> 32; > > + p1 = a_lo * b_hi; > > + p2 = a_hi * b_lo; > > + > > + return a_hi * b_hi + (p1 >> 32) + (p2 >> 32) + > > + ((((a_lo * b_lo) >> 32) + (u32)p1 + (u32)p2) >> 32); > > + > > +} > > Unless GCC is waaay more clever than I think, this is hugely > suboptimal on 64-bit. x86 can do this in a single instruction, and > gcc can express it cleanly using __uint128_t. I wouldn't be terribly > surprised if the 32-bit generated code was fine, too. We already have that: mul_u64_u64_shr() which can be replaced by an arch specific implementation. Nobody bothered to do that for x86 yet, but we definitely don't want to open code it another time Thanks, tglx