Jim Stichnoth | 0933c0c | 2015-06-12 10:41:16 -0700 | [diff] [blame] | 1 | //===- subzero/crosstest/test_strengthreduce_main.cpp - Driver for tests --===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Driver for crosstesting arithmetic strength-reducing optimizations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | /* crosstest.py --test=test_strengthreduce.cpp \ |
| 15 | --driver=test_strengthreduce_main.cpp \ |
| 16 | --prefix=Subzero_ --clang-opt=0 --output=test_strengthreduce */ |
| 17 | |
| 18 | #include <iostream> |
| 19 | |
| 20 | // Include test_strengthreduce.h twice - once normally, and once |
| 21 | // within the Subzero_ namespace, corresponding to the llc and Subzero |
| 22 | // translated object files, respectively. |
| 23 | #include "test_strengthreduce.h" |
| 24 | namespace Subzero_ { |
| 25 | #include "test_strengthreduce.h" |
| 26 | } |
| 27 | |
John Porto | 1d23542 | 2015-08-12 12:37:53 -0700 | [diff] [blame] | 28 | #ifdef X8664_STACK_HACK |
| 29 | extern "C" int wrapped_main(int argc, char *argv[]) { |
| 30 | #else // !defined(X8664_STACK_HACK) |
| 31 | int main(int argc, char *argv[]) { |
| 32 | #endif // X8664_STACK_HACK |
Jim Stichnoth | 0933c0c | 2015-06-12 10:41:16 -0700 | [diff] [blame] | 33 | size_t TotalTests = 0; |
| 34 | size_t Passes = 0; |
| 35 | size_t Failures = 0; |
| 36 | static int32_t Values[] = {-100, -50, 0, 1, 8, 123, 0x33333333, 0x77777777}; |
| 37 | for (size_t i = 0; i < sizeof(Values) / sizeof(*Values); ++i) { |
| 38 | int32_t SVal = Values[i]; |
| 39 | int32_t ResultLlcS, ResultSzS; |
| 40 | uint32_t UVal = (uint32_t)Values[i]; |
| 41 | int32_t ResultLlcU, ResultSzU; |
| 42 | |
| 43 | #define X(constant, suffix) \ |
| 44 | ResultLlcS = multiplyByConst##suffix(UVal); \ |
| 45 | ResultSzS = Subzero_::multiplyByConst##suffix(UVal); \ |
| 46 | if (ResultLlcS == ResultSzS) { \ |
| 47 | ++Passes; \ |
| 48 | } else { \ |
| 49 | ++Failures; \ |
| 50 | std::cout << "multiplyByConstS" STR(suffix) "(" << SVal \ |
| 51 | << "): sz=" << ResultSzS << " llc=" << ResultLlcS << "\n"; \ |
| 52 | } \ |
| 53 | ResultLlcU = multiplyByConst##suffix(UVal); \ |
| 54 | ResultSzU = Subzero_::multiplyByConst##suffix(UVal); \ |
| 55 | if (ResultLlcU == ResultSzU) { \ |
| 56 | ++Passes; \ |
| 57 | } else { \ |
| 58 | ++Failures; \ |
| 59 | std::cout << "multiplyByConstU" STR(suffix) "(" << UVal \ |
| 60 | << "): sz=" << ResultSzU << " llc=" << ResultLlcU << "\n"; \ |
| 61 | } |
| 62 | CONST_TABLE |
| 63 | #undef X |
| 64 | } |
| 65 | |
| 66 | std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 67 | << " Failures=" << Failures << "\n"; |
| 68 | return Failures; |
| 69 | } |