blob: 0569b82e6ccbea7c23d509d8196b3a0fc3902717 [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 -070028int main(int argc, char *argv[]) {
Jim Stichnoth0933c0c2015-06-12 10:41:16 -070029 size_t TotalTests = 0;
30 size_t Passes = 0;
31 size_t Failures = 0;
32 static int32_t Values[] = {-100, -50, 0, 1, 8, 123, 0x33333333, 0x77777777};
33 for (size_t i = 0; i < sizeof(Values) / sizeof(*Values); ++i) {
34 int32_t SVal = Values[i];
35 int32_t ResultLlcS, ResultSzS;
36 uint32_t UVal = (uint32_t)Values[i];
37 int32_t ResultLlcU, ResultSzU;
38
39#define X(constant, suffix) \
40 ResultLlcS = multiplyByConst##suffix(UVal); \
41 ResultSzS = Subzero_::multiplyByConst##suffix(UVal); \
42 if (ResultLlcS == ResultSzS) { \
43 ++Passes; \
44 } else { \
45 ++Failures; \
46 std::cout << "multiplyByConstS" STR(suffix) "(" << SVal \
47 << "): sz=" << ResultSzS << " llc=" << ResultLlcS << "\n"; \
48 } \
49 ResultLlcU = multiplyByConst##suffix(UVal); \
50 ResultSzU = Subzero_::multiplyByConst##suffix(UVal); \
51 if (ResultLlcU == ResultSzU) { \
52 ++Passes; \
53 } else { \
54 ++Failures; \
55 std::cout << "multiplyByConstU" STR(suffix) "(" << UVal \
56 << "): sz=" << ResultSzU << " llc=" << ResultLlcU << "\n"; \
57 }
58 CONST_TABLE
59#undef X
60 }
61
62 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
63 << " Failures=" << Failures << "\n";
64 return Failures;
65}