Files
concrete/compiler/include/zamalang/Support/math.h

21 lines
393 B
C++

#ifndef ZAMALANG_SUPPORT_MATH_H_
#define ZAMALANG_SUPPORT_MATH_H_
// Calculates (T)ceil(log2f(v))
// TODO: Replace with some fancy bit twiddling hack
template <typename T> static T ceilLog2(const T v) {
T tmp = v;
T log2 = 0;
while (tmp >>= 1)
log2++;
// If more than MSB set, round to next highest power of 2
if (v & ~((T)1 << log2))
log2 += 1;
return log2;
}
#endif