diff options
author | Julius Werner <jwerner@chromium.org> | 2024-02-06 22:38:14 -0800 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2024-02-08 13:13:58 +0000 |
commit | b50602007656962ab6717d63d2f9d83e5c00dacf (patch) | |
tree | 16fa6d7f0b2d2f2a9c6d57671928243365673bce /src/commonlib | |
parent | 3edf840ad15154d38769c0115811906284762b11 (diff) |
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>
Diffstat (limited to 'src/commonlib')
-rw-r--r-- | src/commonlib/bsd/gcd.c | 4 | ||||
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/gcd.h | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/commonlib/bsd/gcd.c b/src/commonlib/bsd/gcd.c index 92b601e8d0..fbc8103a32 100644 --- a/src/commonlib/bsd/gcd.c +++ b/src/commonlib/bsd/gcd.c @@ -4,9 +4,9 @@ #include <commonlib/bsd/helpers.h> #include <stdint.h> -uint32_t gcd32(uint32_t a, uint32_t b) +uint64_t gcd(uint64_t a, uint64_t b) { - uint32_t c; + uint64_t c; if (a == 0 || b == 0) return MAX(a, b); diff --git a/src/commonlib/bsd/include/commonlib/bsd/gcd.h b/src/commonlib/bsd/include/commonlib/bsd/gcd.h index 20949ded09..de02eb56a0 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/gcd.h +++ b/src/commonlib/bsd/include/commonlib/bsd/gcd.h @@ -5,6 +5,6 @@ #include <stdint.h> -uint32_t gcd32(uint32_t a, uint32_t b); +uint64_t gcd(uint64_t a, uint64_t b); #endif /* _COMMONLIB_BSD_GCD_H_ */ |