xref: /aosp_15_r20/external/coreboot/src/commonlib/bsd/gcd.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #include <commonlib/bsd/gcd.h>
4 #include <commonlib/bsd/helpers.h>
5 #include <stdint.h>
6 
gcd(uint64_t a,uint64_t b)7 uint64_t gcd(uint64_t a, uint64_t b)
8 {
9 	uint64_t c;
10 
11 	if (a == 0 || b == 0)
12 		return MAX(a, b);
13 
14 	c = a % b;
15 
16 	while (c > 0) {
17 		a = b;
18 		b = c;
19 		c = a % b;
20 	}
21 
22 	return b;
23 }
24