blob: acde64ea9928fee734ae8c9a746be61a9f5f22e2 [file] [log] [blame]
Jim Stichnoth0933c0c2015-06-12 10:41:16 -07001//===- 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"
24namespace Subzero_ {
25#include "test_strengthreduce.h"
26}
27
John Porto1d235422015-08-12 12:37:53 -070028#ifdef X8664_STACK_HACK
29extern "C" int wrapped_main(int argc, char *argv[]) {
30#else // !defined(X8664_STACK_HACK)
31int main(int argc, char *argv[]) {
32#endif // X8664_STACK_HACK
Jim Stichnoth0933c0c2015-06-12 10:41:16 -070033 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}