From b50602007656962ab6717d63d2f9d83e5c00dacf Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Tue, 6 Feb 2024 22:38:14 -0800 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/80319 Reviewed-by: Nico Huber Tested-by: build bot (Jenkins) Reviewed-by: Yidi Lin --- tests/commonlib/bsd/gcd-test.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'tests/commonlib/bsd') diff --git a/tests/commonlib/bsd/gcd-test.c b/tests/commonlib/bsd/gcd-test.c index 13fad86ec4..852a3fd93d 100644 --- a/tests/commonlib/bsd/gcd-test.c +++ b/tests/commonlib/bsd/gcd-test.c @@ -3,24 +3,29 @@ #include #include -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); -- cgit v1.2.3