31 #ifndef __BASE_INTMATH_HH__
32 #define __BASE_INTMATH_HH__
55 for (i = 5; i*i <=
n; i += 6) {
56 if (((n % i) == 0 ) || ((n % (i + 2)) == 0) ) {
82 warn(
"Warning, power() function is quite slow for large exponents\n");
88 uint64_t old_result = 0;
89 for (
int x = 1;
x <
e;
x++) {
92 if (old_result > result)
93 warn(
"power() overflowed!\n");
106 if (x & 0xffff0000) { y += 16; x >>= 16; }
107 if (x & 0x0000ff00) { y += 8; x >>= 8; }
108 if (x & 0x000000f0) { y += 4; x >>= 4; }
109 if (x & 0x0000000c) { y += 2; x >>= 2; }
110 if (x & 0x00000002) { y += 1; }
122 #if defined(__LP64__)
123 if (x &
ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
125 if (x & 0xffff0000) { y += 16; x >>= 16; }
126 if (x & 0x0000ff00) { y += 8; x >>= 8; }
127 if (x & 0x000000f0) { y += 4; x >>= 4; }
128 if (x & 0x0000000c) { y += 2; x >>= 2; }
129 if (x & 0x00000002) { y += 1; }
141 if (x &
ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
142 if (x &
ULL(0x00000000ffff0000)) { y += 16; x >>= 16; }
143 if (x &
ULL(0x000000000000ff00)) { y += 8; x >>= 8; }
144 if (x &
ULL(0x00000000000000f0)) { y += 4; x >>= 4; }
145 if (x &
ULL(0x000000000000000c)) { y += 2; x >>= 2; }
146 if (x &
ULL(0x0000000000000002)) { y += 1; }
196 template <
class T,
class U>
200 return (a + b - 1) /
b;
203 template <
class T,
class U>
207 T
mask = (T)align - 1;
208 return (val + mask) & ~mask;
211 template <
class T,
class U>
215 T
mask = (T)align - 1;
222 return (c >=
'0' && c <=
'9') ||
223 (c >=
'A' && c <=
'F') ||
224 (c >=
'a' && c <=
'f');
230 return c >=
'0' && c <=
'7';
236 return c >=
'0' && c <=
'9';
242 if (c >=
'0' && c <=
'9')
245 if (c >=
'A' && c <=
'F')
246 return (c -
'A') + 10;
248 if (c >=
'a' && c <=
'f')
249 return (c -
'a') + 10;
254 #endif // __BASE_INTMATH_HH__
T roundUp(const T &val, const U &align)
uint64_t power(uint32_t n, uint32_t e)
bool isPowerOf2(const T &n)
T roundDown(const T &val, const U &align)
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
#define ULL(N)
uint64_t constant
int floorLog2(unsigned x)
T divCeil(const T &a, const U &b)
T leastSigBit(const T &n)