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

Side by Side Diff: crosstest/test_cast_main.cpp

Issue 639543002: Add cross test for vector itofp and fptoi casts. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: share more Created 6 years, 2 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.def ('k') | crosstest/test_cast_vectors.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/crosstest/test_cast_main.cpp - Driver for tests ------------===// 1 //===- subzero/crosstest/test_cast_main.cpp - Driver for tests ------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Driver for crosstesting cast operations. 10 // Driver for crosstesting cast operations.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 /* crosstest.py --test=test_cast.cpp --test=test_cast_to_u1.ll \ 14 /* crosstest.py --test=test_cast.cpp --test=test_cast_to_u1.ll \
15 --test=test_cast_vectors.ll \
15 --driver=test_cast_main.cpp --prefix=Subzero_ --output=test_cast */ 16 --driver=test_cast_main.cpp --prefix=Subzero_ --output=test_cast */
16 17
18 #include <cfloat>
17 #include <cstring> 19 #include <cstring>
18 #include <iostream> 20 #include <iostream>
19 #include <stdint.h> 21 #include <stdint.h>
20 22
23 #include "test_arith.def"
24 #include "vectors.h"
25
21 // Include test_cast.h twice - once normally, and once within the 26 // Include test_cast.h twice - once normally, and once within the
22 // Subzero_ namespace, corresponding to the llc and Subzero translated 27 // Subzero_ namespace, corresponding to the llc and Subzero translated
23 // object files, respectively. 28 // object files, respectively.
24 #include "test_cast.h" 29 #include "test_cast.h"
25 namespace Subzero_ { 30 namespace Subzero_ {
26 #include "test_cast.h" 31 #include "test_cast.h"
27 } 32 }
28 33
29 #define XSTR(s) STR(s) 34 #define XSTR(s) STR(s)
30 #define STR(s) #s 35 #define STR(s) #s
(...skipping 10 matching lines...) Expand all
41 std::cout << std::fixed << XSTR(Func) << "<" << FromString \ 46 std::cout << std::fixed << XSTR(Func) << "<" << FromString \
42 << ", " XSTR(ToCName) ">(" << Input << "): "; \ 47 << ", " XSTR(ToCName) ">(" << Input << "): "; \
43 if (sizeof(ToCName) == 1) \ 48 if (sizeof(ToCName) == 1) \
44 std::cout << "sz=" << (int)ResultSz << " llc=" << (int)ResultLlc; \ 49 std::cout << "sz=" << (int)ResultSz << " llc=" << (int)ResultLlc; \
45 else \ 50 else \
46 std::cout << "sz=" << ResultSz << " llc=" << ResultLlc; \ 51 std::cout << "sz=" << ResultSz << " llc=" << ResultLlc; \
47 std::cout << "\n"; \ 52 std::cout << "\n"; \
48 } \ 53 } \
49 } while (0) 54 } while (0)
50 55
56 #define COMPARE_VEC(Func, FromCName, ToCName, Input, FromString, ToString) \
57 do { \
58 ToCName ResultSz, ResultLlc; \
59 ResultLlc = Func<FromCName, ToCName>(Input); \
60 ResultSz = Subzero_::Func<FromCName, ToCName>(Input); \
61 ++TotalTests; \
62 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ToCName))) { \
63 ++Passes; \
64 } else { \
65 ++Failures; \
66 std::cout << std::fixed << XSTR(Func) << "<" << FromString << ", " \
67 << ToString << ">(" << vectAsString<FromCName>(Input) \
68 << "): "; \
69 std::cout << "sz=" << vectAsString<ToCName>(ResultSz) \
70 << " llc=" << vectAsString<ToCName>(ResultLlc); \
71 std::cout << "\n"; \
72 } \
73 } while (0)
74
51 template <typename FromType> 75 template <typename FromType>
52 void testValue(FromType Val, size_t &TotalTests, size_t &Passes, 76 void testValue(FromType Val, size_t &TotalTests, size_t &Passes,
53 size_t &Failures, const char *FromTypeString) { 77 size_t &Failures, const char *FromTypeString) {
54 COMPARE(cast, FromType, bool, Val, FromTypeString); 78 COMPARE(cast, FromType, bool, Val, FromTypeString);
55 COMPARE(cast, FromType, uint8_t, Val, FromTypeString); 79 COMPARE(cast, FromType, uint8_t, Val, FromTypeString);
56 COMPARE(cast, FromType, myint8_t, Val, FromTypeString); 80 COMPARE(cast, FromType, myint8_t, Val, FromTypeString);
57 COMPARE(cast, FromType, uint16_t, Val, FromTypeString); 81 COMPARE(cast, FromType, uint16_t, Val, FromTypeString);
58 COMPARE(cast, FromType, int16_t, Val, FromTypeString); 82 COMPARE(cast, FromType, int16_t, Val, FromTypeString);
59 COMPARE(cast, FromType, uint32_t, Val, FromTypeString); 83 COMPARE(cast, FromType, uint32_t, Val, FromTypeString);
60 COMPARE(cast, FromType, int32_t, Val, FromTypeString); 84 COMPARE(cast, FromType, int32_t, Val, FromTypeString);
61 COMPARE(cast, FromType, uint64_t, Val, FromTypeString); 85 COMPARE(cast, FromType, uint64_t, Val, FromTypeString);
62 COMPARE(cast, FromType, int64_t, Val, FromTypeString); 86 COMPARE(cast, FromType, int64_t, Val, FromTypeString);
63 COMPARE(cast, FromType, float, Val, FromTypeString); 87 COMPARE(cast, FromType, float, Val, FromTypeString);
64 COMPARE(cast, FromType, double, Val, FromTypeString); 88 COMPARE(cast, FromType, double, Val, FromTypeString);
65 } 89 }
66 90
91 template <typename FromType, typename ToType>
92 void testVector(size_t &TotalTests, size_t &Passes, size_t &Failures,
93 const char *FromTypeString, const char *ToTypeString) {
94 const static size_t NumElementsInType = Vectors<FromType>::NumElements;
95 PRNG Index;
96 static const float NegInf = -1.0 / 0.0;
97 static const float PosInf = 1.0 / 0.0;
98 static const float Nan = 0.0 / 0.0;
99 static const float NegNan = -0.0 / 0.0;
100 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
101 static const size_t NumValues = sizeof(Values) / sizeof(*Values);
102 const size_t MaxTestsPerFunc = 20000;
103 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
104 // Initialize the test vectors.
105 FromType Value;
106 for (size_t j = 0; j < NumElementsInType; ++j) {
107 Value[j] = Values[Index() % NumValues];
108 }
109 COMPARE_VEC(cast, FromType, ToType, Value, FromTypeString, ToTypeString);
110 }
111 }
112
67 int main(int argc, char **argv) { 113 int main(int argc, char **argv) {
68 size_t TotalTests = 0; 114 size_t TotalTests = 0;
69 size_t Passes = 0; 115 size_t Passes = 0;
70 size_t Failures = 0; 116 size_t Failures = 0;
71 117
72 volatile bool ValsUi1[] = { false, true }; 118 volatile bool ValsUi1[] = { false, true };
73 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1); 119 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1);
74 volatile uint8_t ValsUi8[] = { 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff }; 120 volatile uint8_t ValsUi8[] = { 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff };
75 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8); 121 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8);
76 122
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 0x7fff, 0x8000, 0x8001, 170 0x7fff, 0x8000, 0x8001,
125 0xfffe, 0xffff, 0x7ffffffe, 171 0xfffe, 0xffff, 0x7ffffffe,
126 0x7fffffff, 0x80000000, 0x80000001, 172 0x7fffffff, 0x80000000, 0x80000001,
127 0xfffffffe, 0xffffffff, 0x100000000ll, 173 0xfffffffe, 0xffffffff, 0x100000000ll,
128 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll, 174 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
129 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell, 175 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
130 0xffffffffffffffffll 176 0xffffffffffffffffll
131 }; 177 };
132 static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64); 178 static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64);
133 179
134 volatile float ValsF32[] = { 180 static const double NegInf = -1.0 / 0.0;
135 0, 1, 1.4, 181 static const double PosInf = 1.0 / 0.0;
136 1.5, 1.6, -1.4, 182 static const double Nan = 0.0 / 0.0;
137 -1.5, -1.6, 0x7e, 183 static const double NegNan = -0.0 / 0.0;
138 0x7f, 0x80, 0x81, 184 volatile float ValsF32[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
139 0xfe, 0xff, 0x7ffe,
140 0x7fff, 0x8000, 0x8001,
141 0xfffe, 0xffff, 0x7ffffffe,
142 0x7fffffff, 0x80000000, 0x80000001,
143 0xfffffffe, 0xffffffff, 0x100000000ll,
144 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
145 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
146 0xffffffffffffffffll
147 };
148 static const size_t NumValsF32 = sizeof(ValsF32) / sizeof(*ValsF32); 185 static const size_t NumValsF32 = sizeof(ValsF32) / sizeof(*ValsF32);
149 186
150 volatile double ValsF64[] = { 187 volatile double ValsF64[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
151 0, 1, 1.4,
152 1.5, 1.6, -1.4,
153 -1.5, -1.6, 0x7e,
154 0x7f, 0x80, 0x81,
155 0xfe, 0xff, 0x7ffe,
156 0x7fff, 0x8000, 0x8001,
157 0xfffe, 0xffff, 0x7ffffffe,
158 0x7fffffff, 0x80000000, 0x80000001,
159 0xfffffffe, 0xffffffff, 0x100000000ll,
160 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
161 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
162 0xffffffffffffffffll
163 };
164 static const size_t NumValsF64 = sizeof(ValsF64) / sizeof(*ValsF64); 188 static const size_t NumValsF64 = sizeof(ValsF64) / sizeof(*ValsF64);
165 189
166 for (size_t i = 0; i < NumValsUi1; ++i) { 190 for (size_t i = 0; i < NumValsUi1; ++i) {
167 bool Val = ValsUi1[i]; 191 bool Val = ValsUi1[i];
168 testValue<bool>(Val, TotalTests, Passes, Failures, "bool"); 192 testValue<bool>(Val, TotalTests, Passes, Failures, "bool");
169 } 193 }
170 for (size_t i = 0; i < NumValsUi8; ++i) { 194 for (size_t i = 0; i < NumValsUi8; ++i) {
171 uint8_t Val = ValsUi8[i]; 195 uint8_t Val = ValsUi8[i];
172 testValue<uint8_t>(Val, TotalTests, Passes, Failures, "uint8_t"); 196 testValue<uint8_t>(Val, TotalTests, Passes, Failures, "uint8_t");
173 } 197 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 236 }
213 for (size_t i = 0; i < NumValsF64; ++i) { 237 for (size_t i = 0; i < NumValsF64; ++i) {
214 for (unsigned j = 0; j < 2; ++j) { 238 for (unsigned j = 0; j < 2; ++j) {
215 double Val = ValsF64[i]; 239 double Val = ValsF64[i];
216 if (j > 0) 240 if (j > 0)
217 Val = -Val; 241 Val = -Val;
218 testValue<double>(Val, TotalTests, Passes, Failures, "double"); 242 testValue<double>(Val, TotalTests, Passes, Failures, "double");
219 COMPARE(castBits, double, uint64_t, Val, "double"); 243 COMPARE(castBits, double, uint64_t, Val, "double");
220 } 244 }
221 } 245 }
246 testVector<v4ui32, v4f32>(TotalTests, Passes, Failures, "v4ui32", "v4f32");
247 testVector<v4si32, v4f32>(TotalTests, Passes, Failures, "v4si32", "v4f32");
248 testVector<v4f32, v4si32>(TotalTests, Passes, Failures, "v4f32", "v4si32");
249 testVector<v4f32, v4ui32>(TotalTests, Passes, Failures, "v4f32", "v4ui32");
222 250
223 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 251 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
224 << " Failures=" << Failures << "\n"; 252 << " Failures=" << Failures << "\n";
225 return Failures; 253 return Failures;
226 } 254 }
OLDNEW
« no previous file with comments | « crosstest/test_arith.def ('k') | crosstest/test_cast_vectors.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698