diff options
author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-08-28 23:28:10 +0000 |
---|---|---|
committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-08-28 23:28:10 +0000 |
commit | 0eca9ed813c0088d97e0e19127520e4f3bd7d75a (patch) | |
tree | 71277b74012a1b584da05dd3902fbe3fbbfb19f8 | |
parent | 5b7d0bf98861448d2f704d1868efe945907087ec (diff) |
Driver to test IsPowerOf2. Could be extended for other library routines.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@408 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | tools/tests/testPow2.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/tests/testPow2.cpp b/tools/tests/testPow2.cpp new file mode 100644 index 0000000000..25f0ecd3a6 --- /dev/null +++ b/tools/tests/testPow2.cpp @@ -0,0 +1,46 @@ +/* -*-c++-*- */ + +#include <stdio.h> +#include <stdlib.h> +#include "/home/vadve/vadve/Research/DynOpt/LLVM/llvm/include/llvm/Support/MathExtras.h" + +inline void +testPow(int C, bool isPow) +{ + unsigned pow = 0; + bool testIsPow = IsPowerOf2(C, pow); + if (isPow != testIsPow) + printf("ERROR: IsPowerOf2() says \t%d %s a power of 2 = %d\n", + C, (isPow? "IS" : "IS NOT"), pow); + +#undef PRINT_CORRECT_RESULTS +#ifdef PRINT_CORRECT_RESULTS + else + printf("CORRECT: IsPowerOf2() says \t%d %s a power of 2 = %d\n", + C, (isPow? "IS" : "IS NOT"), pow); +#endif PRINT_CORRECT_RESULTS +} + +int +main(int argc, char** argv) +{ + unsigned L = (argc > 1)? atoi(argv[1]) : 16; + unsigned C = 1; + + testPow(0, false); + + for (unsigned i = 1; i < L; i++, C = C << 1) + { + testPow(C, true); + testPow(-C, true); + for (unsigned j = C+1; j < (C << 1); j++) + { + testPow(j, false); + testPow(-j, false); + } + } + + return 0; +} + + |