31 #ifndef __BASE_INTMATH_HH__ 32 #define __BASE_INTMATH_HH__ 43 warn(
"Warning, power() function is quite slow for large exponents\n");
49 uint64_t old_result = 0;
50 for (
int x = 1;
x <
e;
x++) {
53 if (old_result > result)
54 warn(
"power() overflowed!\n");
67 if (x & 0xffff0000) { y += 16; x >>= 16; }
68 if (x & 0x0000ff00) { y += 8; x >>= 8; }
69 if (x & 0x000000f0) { y += 4; x >>= 4; }
70 if (x & 0x0000000c) { y += 2; x >>= 2; }
71 if (x & 0x00000002) { y += 1; }
84 if (x &
ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
86 if (x & 0xffff0000) { y += 16; x >>= 16; }
87 if (x & 0x0000ff00) { y += 8; x >>= 8; }
88 if (x & 0x000000f0) { y += 4; x >>= 4; }
89 if (x & 0x0000000c) { y += 2; x >>= 2; }
90 if (x & 0x00000002) { y += 1; }
102 if (x &
ULL(0xffffffff00000000)) { y += 32; x >>= 32; }
103 if (x &
ULL(0x00000000ffff0000)) { y += 16; x >>= 16; }
104 if (x &
ULL(0x000000000000ff00)) { y += 8; x >>= 8; }
105 if (x &
ULL(0x00000000000000f0)) { y += 4; x >>= 4; }
106 if (x &
ULL(0x000000000000000c)) { y += 2; x >>= 2; }
107 if (x &
ULL(0x0000000000000002)) { y += 1; }
151 template <
class T,
class U>
155 return (a + b - 1) /
b;
166 template <
class T,
class U>
171 T
mask = (T)align - 1;
172 return (val + mask) & ~mask;
183 template <
class T,
class U>
188 T
mask = (T)align - 1;
192 #endif // __BASE_INTMATH_HH__
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
void align(const scfx_rep &lhs, const scfx_rep &rhs, int &new_wp, int &len_mant, scfx_mant_ref &lhs_mant, scfx_mant_ref &rhs_mant)
uint64_t power(uint32_t n, uint32_t e)
bool isPowerOf2(const T &n)
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
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)