diff options
author | Mahyar Samani <msamani@ucdavis.edu> | 2019-11-05 11:54:35 -0800 |
---|---|---|
committer | Mahyar Samani <msamani@ucdavis.edu> | 2019-11-14 08:31:52 +0000 |
commit | 732c47ffd328feb71d14aaf6ae823f80167c47ff (patch) | |
tree | 56291105aa8c62b18561b0060b0d07101c72858e /src/base/intmath.hh | |
parent | 7f25332af078d0843b8f9e343def59c22d12c6a0 (diff) | |
download | gem5-732c47ffd328feb71d14aaf6ae823f80167c47ff.tar.xz |
tests, base: Removed ambiguity from base/intmath.hh
The function intmath.leastSigBit is ambiguous given
its name. It does not return the value of the least
significant bit, or the position of the least significant
set bit, but instead 2 to the power of the position of
the least significant set bit. It has thereby been removed
and the function intmath.isPowerOf2 has been refactored to
not require intmath.leastSigBit.
Change-Id: I22479c666cdd059865b8c73b70b5388f98a4584d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22583
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/base/intmath.hh')
-rw-r--r-- | src/base/intmath.hh | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/base/intmath.hh b/src/base/intmath.hh index 0b22ba0db..ee5cf66c8 100644 --- a/src/base/intmath.hh +++ b/src/base/intmath.hh @@ -61,20 +61,6 @@ isPrime(const T& n) return true; } -template <class T> -inline T -leastSigBit(const T& n) -{ - return n & ~(n - 1); -} - -template <class T> -inline bool -isPowerOf2(const T& n) -{ - return n != 0 && leastSigBit(n) == n; -} - inline uint64_t power(uint32_t n, uint32_t e) { @@ -180,6 +166,13 @@ ceilLog2(const T& n) } template <class T> +inline bool +isPowerOf2(const T& n) +{ + return n != 0 && floorLog2(n) == ceilLog2(n); +} + +template <class T> inline T floorPow2(const T& n) { |