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

Side by Side Diff: crosstest/test_cast_main.cpp

Issue 1273153002: Subzero. Native 64-bit int arithmetic on x86-64. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fixes tests & make format Created 5 years, 4 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_cast.cpp ('k') | crosstest/test_fcmp_main.cpp » ('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 --test=test_cast_vectors.ll \
16 --driver=test_cast_main.cpp --prefix=Subzero_ --output=test_cast */ 16 --driver=test_cast_main.cpp --prefix=Subzero_ --output=test_cast */
17 17
18 #include <cfloat> 18 #include <cfloat>
19 #include <cstring> 19 #include <cstring>
20 #include <iostream> 20 #include <iostream>
21 #include <stdint.h> 21 #include <stdint.h>
22 22
23 #include "test_arith.def" 23 #include "test_arith.def"
24 #include "vectors.h" 24 #include "vectors.h"
25 #include "xdefs.h"
25 26
26 // Include test_cast.h twice - once normally, and once within the 27 // Include test_cast.h twice - once normally, and once within the
27 // Subzero_ namespace, corresponding to the llc and Subzero translated 28 // Subzero_ namespace, corresponding to the llc and Subzero translated
28 // object files, respectively. 29 // object files, respectively.
29 #include "test_cast.h" 30 #include "test_cast.h"
30 namespace Subzero_ { 31 namespace Subzero_ {
31 #include "test_cast.h" 32 #include "test_cast.h"
32 } 33 }
33 34
34 #define XSTR(s) STR(s) 35 #define XSTR(s) STR(s)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 template <typename FromType> 76 template <typename FromType>
76 void testValue(FromType Val, size_t &TotalTests, size_t &Passes, 77 void testValue(FromType Val, size_t &TotalTests, size_t &Passes,
77 size_t &Failures, const char *FromTypeString) { 78 size_t &Failures, const char *FromTypeString) {
78 COMPARE(cast, FromType, bool, Val, FromTypeString); 79 COMPARE(cast, FromType, bool, Val, FromTypeString);
79 COMPARE(cast, FromType, uint8_t, Val, FromTypeString); 80 COMPARE(cast, FromType, uint8_t, Val, FromTypeString);
80 COMPARE(cast, FromType, myint8_t, Val, FromTypeString); 81 COMPARE(cast, FromType, myint8_t, Val, FromTypeString);
81 COMPARE(cast, FromType, uint16_t, Val, FromTypeString); 82 COMPARE(cast, FromType, uint16_t, Val, FromTypeString);
82 COMPARE(cast, FromType, int16_t, Val, FromTypeString); 83 COMPARE(cast, FromType, int16_t, Val, FromTypeString);
83 COMPARE(cast, FromType, uint32_t, Val, FromTypeString); 84 COMPARE(cast, FromType, uint32_t, Val, FromTypeString);
84 COMPARE(cast, FromType, int32_t, Val, FromTypeString); 85 COMPARE(cast, FromType, int32_t, Val, FromTypeString);
85 COMPARE(cast, FromType, uint64_t, Val, FromTypeString); 86 COMPARE(cast, FromType, uint64, Val, FromTypeString);
86 COMPARE(cast, FromType, int64_t, Val, FromTypeString); 87 COMPARE(cast, FromType, int64, Val, FromTypeString);
87 COMPARE(cast, FromType, float, Val, FromTypeString); 88 COMPARE(cast, FromType, float, Val, FromTypeString);
88 COMPARE(cast, FromType, double, Val, FromTypeString); 89 COMPARE(cast, FromType, double, Val, FromTypeString);
89 } 90 }
90 91
91 template <typename FromType, typename ToType> 92 template <typename FromType, typename ToType>
92 void testVector(size_t &TotalTests, size_t &Passes, size_t &Failures, 93 void testVector(size_t &TotalTests, size_t &Passes, size_t &Failures,
93 const char *FromTypeString, const char *ToTypeString) { 94 const char *FromTypeString, const char *ToTypeString) {
94 const static size_t NumElementsInType = Vectors<FromType>::NumElements; 95 const static size_t NumElementsInType = Vectors<FromType>::NumElements;
95 PRNG Index; 96 PRNG Index;
96 static const float NegInf = -1.0 / 0.0; 97 static const float NegInf = -1.0 / 0.0;
97 static const float PosInf = 1.0 / 0.0; 98 static const float PosInf = 1.0 / 0.0;
98 static const float Nan = 0.0 / 0.0; 99 static const float Nan = 0.0 / 0.0;
99 static const float NegNan = -0.0 / 0.0; 100 static const float NegNan = -0.0 / 0.0;
100 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); 101 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
101 static const size_t NumValues = sizeof(Values) / sizeof(*Values); 102 static const size_t NumValues = sizeof(Values) / sizeof(*Values);
102 const size_t MaxTestsPerFunc = 20000; 103 const size_t MaxTestsPerFunc = 20000;
103 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { 104 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
104 // Initialize the test vectors. 105 // Initialize the test vectors.
105 FromType Value; 106 FromType Value;
106 for (size_t j = 0; j < NumElementsInType; ++j) { 107 for (size_t j = 0; j < NumElementsInType; ++j) {
107 Value[j] = Values[Index() % NumValues]; 108 Value[j] = Values[Index() % NumValues];
108 } 109 }
109 COMPARE_VEC(cast, FromType, ToType, Value, FromTypeString, ToTypeString); 110 COMPARE_VEC(cast, FromType, ToType, Value, FromTypeString, ToTypeString);
110 } 111 }
111 } 112 }
112 113
113 int main(int argc, char **argv) { 114 #ifdef X8664_STACK_HACK
115 extern "C" int wrapped_main(int argc, char *argv[]) {
116 #else // !defined(X8664_STACK_HACK)
117 int main(int argc, char *argv[]) {
118 #endif // X8664_STACK_HACK
114 size_t TotalTests = 0; 119 size_t TotalTests = 0;
115 size_t Passes = 0; 120 size_t Passes = 0;
116 size_t Failures = 0; 121 size_t Failures = 0;
117 122
118 volatile bool ValsUi1[] = {false, true}; 123 volatile bool ValsUi1[] = {false, true};
119 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1); 124 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1);
120 volatile uint8_t ValsUi8[] = {0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff}; 125 volatile uint8_t ValsUi8[] = {0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff};
121 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8); 126 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8);
122 127
123 volatile myint8_t ValsSi8[] = {0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff}; 128 volatile myint8_t ValsSi8[] = {0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff};
(...skipping 16 matching lines...) Expand all
140 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; 145 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff};
141 static const size_t NumValsUi32 = sizeof(ValsUi32) / sizeof(*ValsUi32); 146 static const size_t NumValsUi32 = sizeof(ValsUi32) / sizeof(*ValsUi32);
142 147
143 volatile size_t ValsSi32[] = {0, 1, 0x7e, 0x7f, 148 volatile size_t ValsSi32[] = {0, 1, 0x7e, 0x7f,
144 0x80, 0x81, 0xfe, 0xff, 149 0x80, 0x81, 0xfe, 0xff,
145 0x7ffe, 0x7fff, 0x8000, 0x8001, 150 0x7ffe, 0x7fff, 0x8000, 0x8001,
146 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 151 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff,
147 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; 152 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff};
148 static const size_t NumValsSi32 = sizeof(ValsSi32) / sizeof(*ValsSi32); 153 static const size_t NumValsSi32 = sizeof(ValsSi32) / sizeof(*ValsSi32);
149 154
150 volatile uint64_t ValsUi64[] = { 155 volatile uint64 ValsUi64[] = {
151 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 156 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001,
152 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001, 157 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001,
153 0xfffffffe, 0xffffffff, 0x100000000ull, 0x100000001ull, 158 0xfffffffe, 0xffffffff, 0x100000000ull, 0x100000001ull,
154 0x7ffffffffffffffeull, 0x7fffffffffffffffull, 0x8000000000000000ull, 159 0x7ffffffffffffffeull, 0x7fffffffffffffffull, 0x8000000000000000ull,
155 0x8000000000000001ull, 0xfffffffffffffffeull, 0xffffffffffffffffull}; 160 0x8000000000000001ull, 0xfffffffffffffffeull, 0xffffffffffffffffull};
156 static const size_t NumValsUi64 = sizeof(ValsUi64) / sizeof(*ValsUi64); 161 static const size_t NumValsUi64 = sizeof(ValsUi64) / sizeof(*ValsUi64);
157 162
158 volatile int64_t ValsSi64[] = { 163 volatile int64 ValsSi64[] = {
159 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 164 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001,
160 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001, 165 0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001,
161 0xfffffffe, 0xffffffff, 0x100000000ll, 0x100000001ll, 166 0xfffffffe, 0xffffffff, 0x100000000ll, 0x100000001ll,
162 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, 167 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll,
163 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll}; 168 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll};
164 static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64); 169 static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64);
165 170
166 static const double NegInf = -1.0 / 0.0; 171 static const double NegInf = -1.0 / 0.0;
167 static const double PosInf = 1.0 / 0.0; 172 static const double PosInf = 1.0 / 0.0;
168 static const double Nan = 0.0 / 0.0; 173 static const double Nan = 0.0 / 0.0;
(...skipping 27 matching lines...) Expand all
196 for (size_t i = 0; i < NumValsUi32; ++i) { 201 for (size_t i = 0; i < NumValsUi32; ++i) {
197 uint32_t Val = ValsUi32[i]; 202 uint32_t Val = ValsUi32[i];
198 testValue<uint32_t>(Val, TotalTests, Passes, Failures, "uint32_t"); 203 testValue<uint32_t>(Val, TotalTests, Passes, Failures, "uint32_t");
199 COMPARE(castBits, uint32_t, float, Val, "uint32_t"); 204 COMPARE(castBits, uint32_t, float, Val, "uint32_t");
200 } 205 }
201 for (size_t i = 0; i < NumValsSi32; ++i) { 206 for (size_t i = 0; i < NumValsSi32; ++i) {
202 int32_t Val = ValsSi32[i]; 207 int32_t Val = ValsSi32[i];
203 testValue<int32_t>(Val, TotalTests, Passes, Failures, "int32_t"); 208 testValue<int32_t>(Val, TotalTests, Passes, Failures, "int32_t");
204 } 209 }
205 for (size_t i = 0; i < NumValsUi64; ++i) { 210 for (size_t i = 0; i < NumValsUi64; ++i) {
206 uint64_t Val = ValsUi64[i]; 211 uint64 Val = ValsUi64[i];
207 testValue<uint64_t>(Val, TotalTests, Passes, Failures, "uint64_t"); 212 testValue<uint64>(Val, TotalTests, Passes, Failures, "uint64");
208 COMPARE(castBits, uint64_t, double, Val, "uint64_t"); 213 COMPARE(castBits, uint64, double, Val, "uint64");
209 } 214 }
210 for (size_t i = 0; i < NumValsSi64; ++i) { 215 for (size_t i = 0; i < NumValsSi64; ++i) {
211 int64_t Val = ValsSi64[i]; 216 int64 Val = ValsSi64[i];
212 testValue<int64_t>(Val, TotalTests, Passes, Failures, "int64_t"); 217 testValue<int64>(Val, TotalTests, Passes, Failures, "int64");
213 } 218 }
214 for (size_t i = 0; i < NumValsF32; ++i) { 219 for (size_t i = 0; i < NumValsF32; ++i) {
215 for (unsigned j = 0; j < 2; ++j) { 220 for (unsigned j = 0; j < 2; ++j) {
216 float Val = ValsF32[i]; 221 float Val = ValsF32[i];
217 if (j > 0) 222 if (j > 0)
218 Val = -Val; 223 Val = -Val;
219 testValue<float>(Val, TotalTests, Passes, Failures, "float"); 224 testValue<float>(Val, TotalTests, Passes, Failures, "float");
220 COMPARE(castBits, float, uint32_t, Val, "float"); 225 COMPARE(castBits, float, uint32_t, Val, "float");
221 } 226 }
222 } 227 }
223 for (size_t i = 0; i < NumValsF64; ++i) { 228 for (size_t i = 0; i < NumValsF64; ++i) {
224 for (unsigned j = 0; j < 2; ++j) { 229 for (unsigned j = 0; j < 2; ++j) {
225 double Val = ValsF64[i]; 230 double Val = ValsF64[i];
226 if (j > 0) 231 if (j > 0)
227 Val = -Val; 232 Val = -Val;
228 testValue<double>(Val, TotalTests, Passes, Failures, "double"); 233 testValue<double>(Val, TotalTests, Passes, Failures, "double");
229 COMPARE(castBits, double, uint64_t, Val, "double"); 234 COMPARE(castBits, double, uint64, Val, "double");
230 } 235 }
231 } 236 }
232 testVector<v4ui32, v4f32>(TotalTests, Passes, Failures, "v4ui32", "v4f32"); 237 testVector<v4ui32, v4f32>(TotalTests, Passes, Failures, "v4ui32", "v4f32");
233 testVector<v4si32, v4f32>(TotalTests, Passes, Failures, "v4si32", "v4f32"); 238 testVector<v4si32, v4f32>(TotalTests, Passes, Failures, "v4si32", "v4f32");
234 testVector<v4f32, v4si32>(TotalTests, Passes, Failures, "v4f32", "v4si32"); 239 testVector<v4f32, v4si32>(TotalTests, Passes, Failures, "v4f32", "v4si32");
235 testVector<v4f32, v4ui32>(TotalTests, Passes, Failures, "v4f32", "v4ui32"); 240 testVector<v4f32, v4ui32>(TotalTests, Passes, Failures, "v4f32", "v4ui32");
236 241
237 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 242 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
238 << " Failures=" << Failures << "\n"; 243 << " Failures=" << Failures << "\n";
239 return Failures; 244 return Failures;
240 } 245 }
OLDNEW
« no previous file with comments | « crosstest/test_cast.cpp ('k') | crosstest/test_fcmp_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698