Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math

Peter Zijlstra
2016-12-09T04:49:03Z

On Fri, Dec 09, 2016 at 05:08:26AM +0100, Ingo Molnar wrote:
> > +#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
> > +static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr, u64 delta)
> > +{
> > + unsigned __int128 nsec;
> > +
> > + nsec = ((unsigned __int128)delta * tkr->mult) + tkr->xtime_nsec;
> > + return (u64) (nsec >> tkr->shift);
> > +}
>
> Actually, 128-bit multiplication shouldn't be too horrible - at least on 64-bit
> architectures. (128-bit division is another matter, but there's no division here.)

IIRC there are 64bit architectures that do not have a 64x64->128 mult,
only a 64x64->64 mult instruction. Its not immediately apparent using
__int128 will generate optimal code for those, nor is it a given GCC
will not require libgcc functions for those.