cregit-Linux how code gets into the kernel

Release 4.9 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 !defined(CONFIG_CPU_NO_EFFICIENT_FFS) && !defined(CPU_NO_EFFICIENT_FFS)

/* 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; } }

Contributors

PersonTokensPropCommitsCommitProp
zeng zhaoxiuzeng zhaoxiu7972.48%150.00%
florian fainelliflorian fainelli3027.52%150.00%
Total109100.00%2100.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; } }

Contributors

PersonTokensPropCommitsCommitProp
zeng zhaoxiuzeng zhaoxiu11283.58%133.33%
florian fainelliflorian fainelli1511.19%133.33%
davidlohr buesodavidlohr bueso75.22%133.33%
Total134100.00%3100.00%

#endif EXPORT_SYMBOL_GPL(gcd);

Overall Contributors

PersonTokensPropCommitsCommitProp
zeng zhaoxiuzeng zhaoxiu21176.17%125.00%
florian fainelliflorian fainelli5820.94%125.00%
davidlohr buesodavidlohr bueso72.53%125.00%
paul gortmakerpaul gortmaker10.36%125.00%
Total277100.00%4100.00%
Directory: lib