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. */
18 * gcd - calculate and return the greatest common divisor of 2 unsigned longs
22 unsigned long gcd(unsigned long a
, unsigned long b
)
24 unsigned long r
= a
| b
;
48 /* If normalization is done by loops, the even/odd algorithm is a win. */
49 unsigned long gcd(unsigned long a
, unsigned long b
)
51 unsigned long r
= a
| b
;
56 /* Isolate lsbit of r */
84 EXPORT_SYMBOL_GPL(gcd
);