1 #include <linux/kernel.h>
3 #include <linux/export.h>
6 * This implements the binary GCD algorithm. (Often attributed to Stein,
7 * but as Knuth has noted, appears in a first-century Chinese math text.)
9 * This is faster than the division-based algorithm even on x86, which
10 * has decent hardware division.
13 #if !defined(CONFIG_CPU_NO_EFFICIENT_FFS) && !defined(CPU_NO_EFFICIENT_FFS)
15 /* If __ffs is available, the even/odd algorithm benchmarks slower. */
16 unsigned long gcd(unsigned long a, unsigned long b)
18 unsigned long r = a | b;
42 /* If normalization is done by loops, the even/odd algorithm is a win. */
43 unsigned long gcd(unsigned long a, unsigned long b)
45 unsigned long r = a | b;
50 /* Isolate lsbit of r */
78 EXPORT_SYMBOL_GPL(gcd);