cregit-Linux how code gets into the kernel

Release 4.8 lib/gcd.c

Directory: lib
#include <linux/kernel.h>
#include <linux/gcd.h>
#include <linux/export.h>

 * This implements the binary GCD algorithm. (Often attributed to Stein,
 * but as Knuth has noted, appears in a first-century Chinese math text.)
 * This is faster than the division-based algorithm even on x86, which
 * has decent hardware division.


/* If __ffs is available, the even/odd algorithm benchmarks slower. */

unsigned long gcd(unsigned long a, unsigned long b) { unsigned long r = a | b; if (!a || !b) return r; b >>= __ffs(b); if (b == 1) return r & -r; for (;;) { a >>= __ffs(a); if (a == 1) return r & -r; if (a == b) return a << __ffs(r); if (a < b) swap(a, b); a -= b; } }


zeng zhaoxiuzeng zhaoxiu7972.48%150.00%
florian fainelliflorian fainelli3027.52%150.00%

#else /* If normalization is done by loops, the even/odd algorithm is a win. */
unsigned long gcd(unsigned long a, unsigned long b) { unsigned long r = a | b; if (!a || !b) return r; /* Isolate lsbit of r */ r &= -r; while (!(b & r)) b >>= 1; if (b == r) return r; for (;;) { while (!(a & r)) a >>= 1; if (a == r) return r; if (a == b) return a; if (a < b) swap(a, b); a -= b; a >>= 1; if (a & r) a += b; a >>= 1; } }


zeng zhaoxiuzeng zhaoxiu11283.58%133.33%
florian fainelliflorian fainelli1511.19%133.33%
davidlohr buesodavidlohr bueso75.22%133.33%

#endif EXPORT_SYMBOL_GPL(gcd);

Overall Contributors

zeng zhaoxiuzeng zhaoxiu21176.17%125.00%
florian fainelliflorian fainelli5820.94%125.00%
davidlohr buesodavidlohr bueso72.53%125.00%
paul gortmakerpaul gortmaker10.36%125.00%
Directory: lib
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.