summaryrefslogtreecommitdiff
path: root/src/base/intmath.hh
diff options
context:
space:
mode:
authorMahyar Samani <msamani@ucdavis.edu>2019-11-05 12:01:14 -0800
committerMahyar Samani <msamani@ucdavis.edu>2019-11-20 00:52:01 +0000
commit92d04b102a018af12b1779d4e588d9df5026f459 (patch)
tree05835ea3079d5fdb9b0689ff913aab59228f6ef1 /src/base/intmath.hh
parentd40f0bc579fb8b10da7181d3a144cd3e9a0a0e59 (diff)
downloadgem5-92d04b102a018af12b1779d4e588d9df5026f459.tar.xz
tests, base: Removed dead code from base/intmath
The below list of functions were dead code and are now deleted. intmath.prevPrime, intmath.isPrime, intmath.leastSigBit, intmath.floorPow2, intmath.ceilPow2, intmath.isHex, intmath.isOct, intmath.isDec, intmath.hex2Int. The source file intmath.cc is now effectively useless and deleted. Change-Id: I28e4350056b8d03e02fecd5c7f7f9c62bc2df7ce Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22584 Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/base/intmath.hh')
-rw-r--r--src/base/intmath.hh92
1 files changed, 18 insertions, 74 deletions
diff --git a/src/base/intmath.hh b/src/base/intmath.hh
index ee5cf66c8..449a49ca8 100644
--- a/src/base/intmath.hh
+++ b/src/base/intmath.hh
@@ -36,31 +36,6 @@
#include "base/logging.hh"
#include "base/types.hh"
-// Returns the prime number one less than n.
-int prevPrime(int n);
-
-// Determine if a number is prime
-template <class T>
-inline bool
-isPrime(const T& n)
-{
- T i;
-
- if (n == 2 || n == 3)
- return true;
-
- // Don't try every odd number to prove if it is a prime.
- // Toggle between every 2nd and 4th number.
- // (This is because every 6th odd number is divisible by 3.)
- for (i = 5; i*i <= n; i += 6) {
- if (((n % i) == 0 ) || ((n % (i + 2)) == 0) ) {
- return false;
- }
- }
-
- return true;
-}
-
inline uint64_t
power(uint32_t n, uint32_t e)
{
@@ -172,20 +147,6 @@ isPowerOf2(const T& n)
return n != 0 && floorLog2(n) == ceilLog2(n);
}
-template <class T>
-inline T
-floorPow2(const T& n)
-{
- return (T)1 << floorLog2(n);
-}
-
-template <class T>
-inline T
-ceilPow2(const T& n)
-{
- return (T)1 << ceilLog2(n);
-}
-
template <class T, class U>
inline T
divCeil(const T& a, const U& b)
@@ -193,55 +154,38 @@ divCeil(const T& a, const U& b)
return (a + b - 1) / b;
}
+/**
+ * This function is used to align addresses in memory.
+ *
+ * @param val is the address to be aligned.
+ * @param align is the alignment. Can only be a power of 2.
+ * @return The aligned address. The smallest number divisible
+ * by @param align which is greater than or equal to @param val.
+*/
template <class T, class U>
inline T
roundUp(const T& val, const U& align)
{
+ assert(isPowerOf2(align));
T mask = (T)align - 1;
return (val + mask) & ~mask;
}
+/**
+ * This function is used to align addresses in memory.
+ *
+ * @param val is the address to be aligned.
+ * @param align is the alignment. Can only be a power of 2.
+ * @return The aligned address. The biggest number divisible
+ * by @param align which is less than or equal to @param val.
+*/
template <class T, class U>
inline T
roundDown(const T& val, const U& align)
{
+ assert(isPowerOf2(align));
T mask = (T)align - 1;
return val & ~mask;
}
-inline bool
-isHex(char c)
-{
- return (c >= '0' && c <= '9') ||
- (c >= 'A' && c <= 'F') ||
- (c >= 'a' && c <= 'f');
-}
-
-inline bool
-isOct(char c)
-{
- return c >= '0' && c <= '7';
-}
-
-inline bool
-isDec(char c)
-{
- return c >= '0' && c <= '9';
-}
-
-inline int
-hex2Int(char c)
-{
- if (c >= '0' && c <= '9')
- return (c - '0');
-
- if (c >= 'A' && c <= 'F')
- return (c - 'A') + 10;
-
- if (c >= 'a' && c <= 'f')
- return (c - 'a') + 10;
-
- return 0;
-}
-
#endif // __BASE_INTMATH_HH__