commonlib: Change GCD function to always use 64 bits

It seems that we have some applications where we need to calculate a GCD
in 64 bits. Now, we could instantiate the algorithm multiple times for
different bit width combinations to be able to use the most efficient
one for each problem... but considering that the function usually only
gets called once per callsite per stage, and that software emulation of
64-bit division on 32-bit systems doesn't take *that* long either, we
would probably usually be paying more time loading the second instance
of the function than we save with faster divisions. So let's just make
things easy and always do it in 64-bit and then nobody has to spend time
thinking on which version to call.

Change-Id: I028361444c4048a0d76ba4f80c7334a9d9983c87
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/80319
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yidi Lin <yidilin@google.com>
diff --git a/tests/commonlib/bsd/gcd-test.c b/tests/commonlib/bsd/gcd-test.c
index 13fad86..852a3fd 100644
--- a/tests/commonlib/bsd/gcd-test.c
+++ b/tests/commonlib/bsd/gcd-test.c
@@ -3,24 +3,29 @@
 #include <commonlib/bsd/gcd.h>
 #include <tests/test.h>
 
-static void test_gcd32(void **state)
+static void test_gcd(void **state)
 {
-	assert_int_equal(gcd32(17, 11), 1);
-	assert_int_equal(gcd32(64, 36), 4);
-	assert_int_equal(gcd32(90, 123), 3);
-	assert_int_equal(gcd32(65536, 339584), 128);
-	assert_int_equal(gcd32(1, 1), 1);
-	assert_int_equal(gcd32(1, 123), 1);
-	assert_int_equal(gcd32(123, 1), 1);
-	assert_int_equal(gcd32(1, UINT32_MAX), 1);
-	assert_int_equal(gcd32(UINT32_MAX, 1), 1);
-	assert_int_equal(gcd32(UINT32_MAX, UINT32_MAX), UINT32_MAX);
+	assert_int_equal(gcd(17, 11), 1);
+	assert_int_equal(gcd(64, 36), 4);
+	assert_int_equal(gcd(90, 123), 3);
+	assert_int_equal(gcd(65536, 339584), 128);
+	assert_int_equal(gcd(1, 1), 1);
+	assert_int_equal(gcd(1, 123), 1);
+	assert_int_equal(gcd(123, 1), 1);
+	assert_int_equal(gcd(1, UINT32_MAX), 1);
+	assert_int_equal(gcd(UINT32_MAX, 1), 1);
+	assert_int_equal(gcd(UINT32_MAX, UINT32_MAX), UINT32_MAX);
+	assert_int_equal(gcd(1, UINT64_MAX), 1);
+	assert_int_equal(gcd(UINT64_MAX, 1), 1);
+	assert_int_equal(gcd(UINT64_MAX, UINT64_MAX), UINT64_MAX);
+	assert_int_equal(gcd((uint64_t)UINT32_MAX + 1, UINT64_MAX / 2 + 1),
+			 (uint64_t)UINT32_MAX + 1);
 }
 
 int main(void)
 {
 	const struct CMUnitTest tests[] = {
-		cmocka_unit_test(test_gcd32),
+		cmocka_unit_test(test_gcd),
 	};
 
 	return cb_run_group_tests(tests, NULL, NULL);