diff --git a/include/Support/MathExtras.h b/include/Support/MathExtras.h index d5209854877..c1384d3eff5 100644 --- a/include/Support/MathExtras.h +++ b/include/Support/MathExtras.h @@ -29,6 +29,13 @@ inline unsigned log2(uint64_t C) { return getPow; } +inline unsigned log2(unsigned C) { + unsigned getPow; + for (getPow = 0; C > 1; ++getPow) + C >>= 1; + return getPow; +} + inline bool isPowerOf2(int64_t C, unsigned &getPow) { if (C < 0) C = -C; if (C > 0 && C == (C & ~(C - 1))) { diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index d5209854877..c1384d3eff5 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -29,6 +29,13 @@ inline unsigned log2(uint64_t C) { return getPow; } +inline unsigned log2(unsigned C) { + unsigned getPow; + for (getPow = 0; C > 1; ++getPow) + C >>= 1; + return getPow; +} + inline bool isPowerOf2(int64_t C, unsigned &getPow) { if (C < 0) C = -C; if (C > 0 && C == (C & ~(C - 1))) {