cregit-Linux how code gets into the kernel

Release 4.12 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 Zhaoxiu7972.48%150.00%
Florian 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 Zhaoxiu11283.58%133.33%
Florian Fainelli1511.19%133.33%
Davidlohr Bueso A75.22%133.33%
Total134100.00%3100.00%

#endif EXPORT_SYMBOL_GPL(gcd);

Overall Contributors

PersonTokensPropCommitsCommitProp
Zeng Zhaoxiu21176.17%125.00%
Florian Fainelli5820.94%125.00%
Davidlohr Bueso A72.53%125.00%
Paul Gortmaker10.36%125.00%
Total277100.00%4100.00%
Directory: lib
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.