1 //===- 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"
26 #include "xdefs.h"
27
28 namespace Subzero_ {
29 #include "test_bitmanip.h"
30 }
31
32 volatile uint64 Values[] = {0,
33 1,
34 0x7e,
35 0x7f,
36 0x80,
37 0x81,
38 0xfe,
39 0xff,
40 0x7ffe,
41 0x7fff,
42 0x8000,
43 0x8001,
44 0xfffe,
45 0xffff,
46 0xc0de,
47 0xabcd,
48 0xdcba,
49 0x007fffff /*Max subnormal + */,
50 0x00800000 /*Min+ */,
51 0x7f7fffff /*Max+ */,
52 0x7f800000 /*+Inf*/,
53 0xff800000 /*-Inf*/,
54 0x7fa00000 /*SNaN*/,
55 0x7fc00000 /*QNaN*/,
56 0x7ffffffe,
57 0x7fffffff,
58 0x80000000,
59 0x80000001,
60 0xfffffffe,
61 0xffffffff,
62 0x12345678,
63 0xabcd1234,
64 0x1234dcba,
65 0x100000000ll,
66 0x100000001ll,
67 0x123456789abcdef1ll,
68 0x987654321ab1fedcll,
69 0x000fffffffffffffll /*Max subnormal + */,
70 0x0010000000000000ll /*Min+ */,
71 0x7fefffffffffffffll /*Max+ */,
72 0x7ff0000000000000ll /*+Inf*/,
73 0xfff0000000000000ll /*-Inf*/,
74 0x7ff0000000000001ll /*SNaN*/,
75 0x7ff8000000000000ll /*QNaN*/,
76 0x7ffffffffffffffell,
77 0x7fffffffffffffffll,
78 0x8000000000000000ll,
79 0x8000000000000001ll,
80 0xfffffffffffffffell,
81 0xffffffffffffffffll};
82
83 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
84
85 template <typename Type>
testBitManip(size_t & TotalTests,size_t & Passes,size_t & Failures)86 void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
87 typedef Type (*FuncType)(Type);
88 static struct {
89 const char *Name;
90 FuncType FuncLlc;
91 FuncType FuncSz;
92 } Funcs[] = {
93 #define X(inst) \
94 {STR(inst), test_##inst, Subzero_::test_##inst}, \
95 {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
96 {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
97 BMI_OPS
98 #undef X
99 };
100 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
101
102 for (size_t f = 0; f < NumFuncs; ++f) {
103 for (size_t i = 0; i < NumValues; ++i) {
104 Type Value = static_cast<Type>(Values[i]);
105 ++TotalTests;
106 Type ResultSz = Funcs[f].FuncSz(Value);
107 Type ResultLlc = Funcs[f].FuncLlc(Value);
108 if (ResultSz == ResultLlc) {
109 ++Passes;
110 } else {
111 ++Failures;
112 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
113 << "(" << static_cast<uint64>(Value)
114 << "): sz=" << static_cast<uint64>(ResultSz)
115 << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
116 }
117 }
118 }
119 }
120
121 template <typename Type>
testByteSwap(size_t & TotalTests,size_t & Passes,size_t & Failures)122 void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
123 typedef Type (*FuncType)(Type);
124 static struct {
125 const char *Name;
126 FuncType FuncLlc;
127 FuncType FuncSz;
128 } Funcs[] = {
129 {"bswap", test_bswap, Subzero_::test_bswap},
130 {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
131 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
132 for (size_t f = 0; f < NumFuncs; ++f) {
133 for (size_t i = 0; i < NumValues; ++i) {
134 Type Value = static_cast<Type>(Values[i]);
135 ++TotalTests;
136 Type ResultSz = Funcs[f].FuncSz(Value);
137 Type ResultLlc = Funcs[f].FuncLlc(Value);
138 if (ResultSz == ResultLlc) {
139 ++Passes;
140 } else {
141 ++Failures;
142 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
143 << "(" << static_cast<uint64>(Value)
144 << "): sz=" << static_cast<uint64>(ResultSz)
145 << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
146 }
147 }
148 }
149 }
150
main(int argc,char * argv[])151 int main(int argc, char *argv[]) {
152 size_t TotalTests = 0;
153 size_t Passes = 0;
154 size_t Failures = 0;
155
156 testBitManip<uint32_t>(TotalTests, Passes, Failures);
157 testBitManip<uint64>(TotalTests, Passes, Failures);
158 testByteSwap<uint16_t>(TotalTests, Passes, Failures);
159 testByteSwap<uint32_t>(TotalTests, Passes, Failures);
160 testByteSwap<uint64>(TotalTests, Passes, Failures);
161
162 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
163 << " Failures=" << Failures << "\n";
164 return Failures;
165 }
166