Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: crosstest/test_arith_main.cpp

Issue 265703002: Add Om1 lowering with no optimizations (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Merge changed from Karl's committed CL Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crosstest/test_arith_frem.ll ('k') | crosstest/test_cast.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \
2 --driver=test_arith_main.cpp --prefix=Subzero_ --output=test_arith */
3
4 #include <stdint.h>
5
6 #include <cfloat>
7 #include <cstring> // memcmp
8 #include <iostream>
9
10 // Include test_arith.h twice - once normally, and once within the
11 // Subzero_ namespace, corresponding to the llc and Subzero translated
12 // object files, respectively.
13 #include "test_arith.h"
14 namespace Subzero_ {
15 #include "test_arith.h"
16 }
17
18 volatile unsigned Values[] = { 0x0, 0x1, 0x7ffffffe, 0x7fffffff,
19 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff,
20 0x7e, 0x7f, 0x80, 0x81,
21 0xfe, 0xff, 0x100, 0x101,
22 0x7ffe, 0x7fff, 0x8000, 0x8001,
23 0xfffe, 0xffff, 0x10000, 0x10001, };
24 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
25
26 template <typename TypeUnsigned, typename TypeSigned>
27 void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
28 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned);
29 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned);
30 static struct {
31 const char *Name;
32 FuncTypeUnsigned FuncLlc;
33 FuncTypeUnsigned FuncSz;
34 bool ExcludeDivExceptions; // for divide related tests
35 } Funcs[] = {
36 #define X(inst, op, isdiv) \
37 { \
38 STR(inst), (FuncTypeUnsigned)test##inst, \
39 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \
40 } \
41 ,
42 UINTOP_TABLE
43 #undef X
44 #define X(inst, op, isdiv) \
45 { \
46 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)test##inst, \
47 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::test##inst, isdiv \
48 } \
49 ,
50 SINTOP_TABLE
51 #undef X
52 };
53 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
54
55 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) {
56 // This is the "normal" version of the loop nest, for 32-bit or
57 // narrower types.
58 for (size_t f = 0; f < NumFuncs; ++f) {
59 for (size_t i = 0; i < NumValues; ++i) {
60 for (size_t j = 0; j < NumValues; ++j) {
61 TypeUnsigned Value1 = Values[i];
62 TypeUnsigned Value2 = Values[j];
63 // Avoid HW divide-by-zero exception.
64 if (Funcs[f].ExcludeDivExceptions && Value2 == 0)
65 continue;
66 // Avoid HW overflow exception (on x86-32). TODO: adjust
67 // for other architectures.
68 if (Funcs[f].ExcludeDivExceptions && Value1 == 0x80000000 &&
69 Value2 == 0xffffffff)
70 continue;
71 ++TotalTests;
72 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2);
73 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
74 if (ResultSz == ResultLlc) {
75 ++Passes;
76 } else {
77 ++Failures;
78 std::cout << "test" << Funcs[f].Name << (8 * sizeof(TypeUnsigned))
79 << "(" << Value1 << ", " << Value2
80 << "): sz=" << (unsigned)ResultSz
81 << " llc=" << (unsigned)ResultLlc << std::endl;
82 }
83 }
84 }
85 }
86 } else {
87 // This is the 64-bit version. Test values are synthesized from
88 // the 32-bit values in Values[].
89 for (size_t f = 0; f < NumFuncs; ++f) {
90 for (size_t iLo = 0; iLo < NumValues; ++iLo) {
91 for (size_t iHi = 0; iHi < NumValues; ++iHi) {
92 for (size_t jLo = 0; jLo < NumValues; ++jLo) {
93 for (size_t jHi = 0; jHi < NumValues; ++jHi) {
94 TypeUnsigned Value1 =
95 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo];
96 TypeUnsigned Value2 =
97 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo];
98 // Avoid HW divide-by-zero exception.
99 if (Funcs[f].ExcludeDivExceptions && Value2 == 0)
100 continue;
101 ++TotalTests;
102 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2);
103 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
104 if (ResultSz == ResultLlc) {
105 ++Passes;
106 } else {
107 ++Failures;
108 std::cout << "test" << Funcs[f].Name
109 << (8 * sizeof(TypeUnsigned)) << "(" << Value1 << ", "
110 << Value2 << "): sz=" << (unsigned)ResultSz
111 << " llc=" << (unsigned)ResultLlc << std::endl;
112 }
113 }
114 }
115 }
116 }
117 }
118 }
119 }
120
121 template <typename Type>
122 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
123 static const Type NegInf = -1.0 / 0.0;
124 static const Type PosInf = 1.0 / 0.0;
125 static const Type Nan = 0.0 / 0.0;
126 volatile Type Values[] = {
127 0, 1, 0x7e,
128 0x7f, 0x80, 0x81,
129 0xfe, 0xff, 0x7ffe,
130 0x7fff, 0x8000, 0x8001,
131 0xfffe, 0xffff, 0x7ffffffe,
132 0x7fffffff, 0x80000000, 0x80000001,
133 0xfffffffe, 0xffffffff, 0x100000000ll,
134 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
135 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
136 0xffffffffffffffffll, NegInf, PosInf,
137 Nan, FLT_MIN, FLT_MAX,
138 DBL_MIN, DBL_MAX
139 };
140 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
141 typedef Type (*FuncType)(Type, Type);
142 static struct {
143 const char *Name;
144 FuncType FuncLlc;
145 FuncType FuncSz;
146 } Funcs[] = {
147 #define X(inst, op, func) \
148 { STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \
149 ,
150 FPOP_TABLE
151 #undef X
152 };
153 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
154
155 for (size_t f = 0; f < NumFuncs; ++f) {
156 for (size_t i = 0; i < NumValues; ++i) {
157 for (size_t j = 0; j < NumValues; ++j) {
158 Type Value1 = Values[i];
159 Type Value2 = Values[j];
160 ++TotalTests;
161 Type ResultSz = Funcs[f].FuncSz(Value1, Value2);
162 Type ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
163 // Compare results using memcmp() in case they are both NaN.
164 if (!memcmp(&ResultSz, &ResultLlc, sizeof(Type))) {
165 ++Passes;
166 } else {
167 ++Failures;
168 std::cout << std::fixed << "test" << Funcs[f].Name
169 << (8 * sizeof(Type)) << "(" << Value1 << ", " << Value2
170 << "): sz=" << ResultSz << " llc=" << ResultLlc
171 << std::endl;
172 }
173 }
174 }
175 }
176 }
177
178 int main(int argc, char **argv) {
179 size_t TotalTests = 0;
180 size_t Passes = 0;
181 size_t Failures = 0;
182
183 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures);
184 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures);
185 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures);
186 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures);
187 testsFp<float>(TotalTests, Passes, Failures);
188 testsFp<double>(TotalTests, Passes, Failures);
189
190 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
191 << " Failures=" << Failures << "\n";
192 return Failures;
193 }
OLDNEW
« no previous file with comments | « crosstest/test_arith_frem.ll ('k') | crosstest/test_cast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698