blob: 592ad7ea7072d8a002d3d75a2ce62342db571386 [file] [log] [blame]
Jan Vounge4da26f2014-07-15 17:52:39 -07001//===- subzero/crosstest/test_bitmanip_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 cross testing bit manipulation intrinsics.
11//
12//===----------------------------------------------------------------------===//
13
14/* crosstest.py --test=test_bitmanip.cpp --test=test_bitmanip_intrin.ll \
15 --driver=test_bitmanip_main.cpp --prefix=Subzero_ --output=test_bitmanip */
16
17#include <stdint.h>
18
19#include <climits>
20#include <iostream>
21
22// Include test_bitmanip.h twice - once normally, and once within the
23// Subzero_ namespace, corresponding to the llc and Subzero translated
24// object files, respectively.
25#include "test_bitmanip.h"
26namespace Subzero_ {
27#include "test_bitmanip.h"
28}
29
30volatile uint64_t Values[] = {
Jan Voung7fa813b2014-07-18 13:01:08 -070031 0, 1,
32 0x7e, 0x7f,
33 0x80, 0x81,
34 0xfe, 0xff,
35 0x7ffe, 0x7fff,
36 0x8000, 0x8001,
37 0xfffe, 0xffff,
38 0xc0de, 0xabcd,
39 0xdcba, 0x007fffff /*Max subnormal + */,
40 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */,
41 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/,
42 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/,
43 0x7ffffffe, 0x7fffffff,
44 0x80000000, 0x80000001,
45 0xfffffffe, 0xffffffff,
46 0x12345678, 0xabcd1234,
47 0x1234dcba, 0x100000000ll,
48 0x100000001ll, 0x123456789abcdef1ll,
49 0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */,
50 0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */,
51 0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/,
52 0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/,
53 0x7ffffffffffffffell, 0x7fffffffffffffffll,
54 0x8000000000000000ll, 0x8000000000000001ll,
55 0xfffffffffffffffell, 0xffffffffffffffffll};
Jan Vounge4da26f2014-07-15 17:52:39 -070056
57const static size_t NumValues = sizeof(Values) / sizeof(*Values);
58
59template <typename Type>
60void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
61 typedef Type (*FuncType)(Type);
62 static struct {
63 const char *Name;
64 FuncType FuncLlc;
65 FuncType FuncSz;
66 } Funcs[] = {
67#define X(inst) \
68 { \
69 STR(inst), test_##inst, Subzero_::test_##inst \
70 }, \
71 { \
72 STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst \
73 }, \
74 { \
75 STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst \
76 },
77 BMI_OPS
78#undef X
79 };
80 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
81
82 for (size_t f = 0; f < NumFuncs; ++f) {
83 for (size_t i = 0; i < NumValues; ++i) {
84 Type Value = static_cast<Type>(Values[i]);
85 ++TotalTests;
86 Type ResultSz = Funcs[f].FuncSz(Value);
87 Type ResultLlc = Funcs[f].FuncLlc(Value);
88 if (ResultSz == ResultLlc) {
89 ++Passes;
90 } else {
91 ++Failures;
92 std::cout << "test_" << Funcs[f].Name
93 << (CHAR_BIT * sizeof(Type)) << "("
94 << static_cast<uint64_t>(Value)
95 << "): sz=" << static_cast<uint64_t>(ResultSz)
96 << " llc=" << static_cast<uint64_t>(ResultLlc)
97 << "\n";
98 }
99 }
100 }
101}
102
Jan Voung7fa813b2014-07-18 13:01:08 -0700103template <typename Type>
104void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
Jan Voung3b43b892014-09-24 13:32:39 -0700105 typedef Type (*FuncType)(Type);
106 static struct {
107 const char *Name;
108 FuncType FuncLlc;
109 FuncType FuncSz;
110 } Funcs[] = {
111 {"bswap", test_bswap, Subzero_::test_bswap},
112 {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
113 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
114 for (size_t f = 0; f < NumFuncs; ++f) {
115 for (size_t i = 0; i < NumValues; ++i) {
116 Type Value = static_cast<Type>(Values[i]);
117 ++TotalTests;
118 Type ResultSz = Funcs[f].FuncSz(Value);
119 Type ResultLlc = Funcs[f].FuncLlc(Value);
120 if (ResultSz == ResultLlc) {
121 ++Passes;
122 } else {
123 ++Failures;
124 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
125 << "(" << static_cast<uint64_t>(Value)
126 << "): sz=" << static_cast<uint64_t>(ResultSz)
127 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n";
128 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700129 }
130 }
131}
132
Jan Vounge4da26f2014-07-15 17:52:39 -0700133int main(int argc, char **argv) {
134 size_t TotalTests = 0;
135 size_t Passes = 0;
136 size_t Failures = 0;
137
138 testBitManip<uint32_t>(TotalTests, Passes, Failures);
139 testBitManip<uint64_t>(TotalTests, Passes, Failures);
Jan Voung7fa813b2014-07-18 13:01:08 -0700140 testByteSwap<uint16_t>(TotalTests, Passes, Failures);
141 testByteSwap<uint32_t>(TotalTests, Passes, Failures);
142 testByteSwap<uint64_t>(TotalTests, Passes, Failures);
Jan Vounge4da26f2014-07-15 17:52:39 -0700143
144 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
145 << " Failures=" << Failures << "\n";
146 return Failures;
147}