X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fbase%2Fintmath.hh;h=c6ad329cc52c36dce9dc8ebba70289b628c05911;hb=ebd62eff3c98564b175e7acc69bbdc7e823da059;hp=ee5cf66c84d8fafd9c9531444d5539f34338ae67;hpb=732c47ffd328feb71d14aaf6ae823f80167c47ff;p=gem5.git diff --git a/src/base/intmath.hh b/src/base/intmath.hh index ee5cf66c8..c6ad329cc 100644 --- a/src/base/intmath.hh +++ b/src/base/intmath.hh @@ -24,8 +24,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Nathan Binkert */ #ifndef __BASE_INTMATH_HH__ @@ -36,31 +34,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 -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) { @@ -159,6 +132,7 @@ template inline int ceilLog2(const T& n) { + assert(n > 0); if (n == 1) return 0; @@ -172,20 +146,6 @@ isPowerOf2(const T& n) return n != 0 && floorLog2(n) == ceilLog2(n); } -template -inline T -floorPow2(const T& n) -{ - return (T)1 << floorLog2(n); -} - -template -inline T -ceilPow2(const T& n) -{ - return (T)1 << ceilLog2(n); -} - template inline T divCeil(const T& a, const U& b) @@ -193,55 +153,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 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 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__