Re: [patch V2] lib: GCD: add binary GCD algorithm

2016-04-28 Thread Peter Zijlstra
On Wed, Apr 27, 2016 at 12:20:33PM -0400, George Spelvin wrote: > The frequent "if (USE_FFS)" conditions seem to clutter the code. > Would it be easier to read if the two variants were just separated? > The function is short enough that the duplication isn't too severe. Yes please, this is _MUCH_

Re: [patch V2] lib: GCD: add binary GCD algorithm

2016-04-27 Thread Andrew Morton
On Wed, 27 Apr 2016 16:05:50 +0800 zengzhao...@163.com wrote: > From: Zhaoxiu Zeng > > Because some architectures (alpha, armv6, etc.) don't provide hardware > division, > the mod operation is slow! Binary GCD algorithm uses simple arithmetic > operations, > it replaces division with arithmeti

Re: [patch V2] lib: GCD: add binary GCD algorithm

2016-04-27 Thread George Spelvin
I replicated your results in 32- and 64-bit x86: - If __ffs (gcc's __builtin_ctz) is available, the basic (non-even/odd) binary GCD algorithm is faster than the divsion-based or even/odd. - If shifting down has to be done in a loop, the even/odd binary algorithm is fastest. I tried a few va