summaryrefslogtreecommitdiff
path: root/base/intmath.hh
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2003-10-14 18:04:28 -0400
committerNathan Binkert <binkertn@umich.edu>2003-10-14 18:04:28 -0400
commit722f9bc3c851ca02a68e6f3df972d4a94d6aa15f (patch)
tree274ccc71ed94242fe1870cf67745e6424f65668c /base/intmath.hh
parentacf025a463498b24fe6a8d90abf9cbc3bae98119 (diff)
parentf8d850195bfb57650faa519764229d85445c2274 (diff)
downloadgem5-722f9bc3c851ca02a68e6f3df972d4a94d6aa15f.tar.xz
Merge zizzer.eecs.umich.edu:/m5/Bitkeeper/m5
into zans.eecs.umich.edu:/z/binkertn/research/m5/latest --HG-- extra : convert_revision : d5ba96b559be93774e82692099675b6d1f525221
Diffstat (limited to 'base/intmath.hh')
-rw-r--r--base/intmath.hh46
1 files changed, 41 insertions, 5 deletions
diff --git a/base/intmath.hh b/base/intmath.hh
index a17492728..ca1cce1e0 100644
--- a/base/intmath.hh
+++ b/base/intmath.hh
@@ -29,6 +29,10 @@
#ifndef __INTMATH_HH__
#define __INTMATH_HH__
+#include <assert.h>
+
+#include "sim/host.hh"
+
// Returns the prime number one less than n.
int PrevPrime(int n);
@@ -68,12 +72,10 @@ IsPowerOf2(T n)
return n != 0 && LeastSigBit(n) == n;
}
-template <class T>
inline int
-FloorLog2(T x)
+FloorLog2(uint32_t x)
{
- if (x == 0)
- return -1;
+ assert(x > 0);
int y = 0;
@@ -86,11 +88,45 @@ FloorLog2(T x)
return y;
}
+inline int
+FloorLog2(uint64_t x)
+{
+ assert(x > 0);
+
+ int y = 0;
+
+ if (x & ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
+ if (x & ULL(0x00000000ffff0000)) { y += 16; x >>= 16; }
+ if (x & ULL(0x000000000000ff00)) { y += 8; x >>= 8; }
+ if (x & ULL(0x00000000000000f0)) { y += 4; x >>= 4; }
+ if (x & ULL(0x000000000000000c)) { y += 2; x >>= 2; }
+ if (x & ULL(0x0000000000000002)) { y += 1; }
+
+ return y;
+}
+
+inline int
+FloorLog2(int32_t x)
+{
+ assert(x > 0);
+ return FloorLog2(x);
+}
+
+inline int
+FloorLog2(int64_t x)
+{
+ assert(x > 0);
+ return FloorLog2(x);
+}
+
template <class T>
inline int
CeilLog2(T n)
{
- return FloorLog2(n - 1) + 1;
+ if (n == 1)
+ return 0;
+
+ return FloorLog2(n - (T)1) + 1;
}
template <class T>