Lines Matching +full:a +full:- +full:b
1 // SPDX-License-Identifier: GPL-2.0-only
8 * but as Knuth has noted, appears in a first-century Chinese math text.)
10 * This is faster than the division-based algorithm even on x86, which
19 * gcd - calculate and return the greatest common divisor of 2 unsigned longs
20 * @a: first value
21 * @b: second value
23 unsigned long gcd(unsigned long a, unsigned long b) in gcd() argument
25 unsigned long r = a | b; in gcd()
27 if (!a || !b) in gcd()
30 b >>= __ffs(b); in gcd()
31 if (b == 1) in gcd()
32 return r & -r; in gcd()
35 a >>= __ffs(a); in gcd()
36 if (a == 1) in gcd()
37 return r & -r; in gcd()
38 if (a == b) in gcd()
39 return a << __ffs(r); in gcd()
41 if (a < b) in gcd()
42 swap(a, b); in gcd()
43 a -= b; in gcd()
49 /* If normalization is done by loops, the even/odd algorithm is a win. */
50 unsigned long gcd(unsigned long a, unsigned long b) in gcd() argument
52 unsigned long r = a | b; in gcd()
54 if (!a || !b) in gcd()
58 r &= -r; in gcd()
60 while (!(b & r)) in gcd()
61 b >>= 1; in gcd()
62 if (b == r) in gcd()
66 while (!(a & r)) in gcd()
67 a >>= 1; in gcd()
68 if (a == r) in gcd()
70 if (a == b) in gcd()
71 return a; in gcd()
73 if (a < b) in gcd()
74 swap(a, b); in gcd()
75 a -= b; in gcd()
76 a >>= 1; in gcd()
77 if (a & r) in gcd()
78 a += b; in gcd()
79 a >>= 1; in gcd()