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

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: stuff 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
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
17 #include <cstring> 18 #include <cstring>
18 #include <iostream> 19 #include <iostream>
19 #include <stdint.h> 20 #include <stdint.h>
20 21
22 #include "vectors.h"
23
21 // Include test_cast.h twice - once normally, and once within the 24 // Include test_cast.h twice - once normally, and once within the
22 // Subzero_ namespace, corresponding to the llc and Subzero translated 25 // Subzero_ namespace, corresponding to the llc and Subzero translated
23 // object files, respectively. 26 // object files, respectively.
24 #include "test_cast.h" 27 #include "test_cast.h"
25 namespace Subzero_ { 28 namespace Subzero_ {
26 #include "test_cast.h" 29 #include "test_cast.h"
27 } 30 }
28 31
29 #define XSTR(s) STR(s) 32 #define XSTR(s) STR(s)
30 #define STR(s) #s 33 #define STR(s) #s
(...skipping 10 matching lines...) Expand all
41 std::cout << std::fixed << XSTR(Func) << "<" << FromString \ 44 std::cout << std::fixed << XSTR(Func) << "<" << FromString \
42 << ", " XSTR(ToCName) ">(" << Input << "): "; \ 45 << ", " XSTR(ToCName) ">(" << Input << "): "; \
43 if (sizeof(ToCName) == 1) \ 46 if (sizeof(ToCName) == 1) \
44 std::cout << "sz=" << (int)ResultSz << " llc=" << (int)ResultLlc; \ 47 std::cout << "sz=" << (int)ResultSz << " llc=" << (int)ResultLlc; \
45 else \ 48 else \
46 std::cout << "sz=" << ResultSz << " llc=" << ResultLlc; \ 49 std::cout << "sz=" << ResultSz << " llc=" << ResultLlc; \
47 std::cout << "\n"; \ 50 std::cout << "\n"; \
48 } \ 51 } \
49 } while (0) 52 } while (0)
50 53
54 #define COMPARE_VEC(Func, FromCName, ToCName, Input, FromString, ToString) \
55 do { \
56 ToCName ResultSz, ResultLlc; \
57 ResultLlc = Func<FromCName, ToCName>(Input); \
58 ResultSz = Subzero_::Func<FromCName, ToCName>(Input); \
59 ++TotalTests; \
60 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ToCName))) { \
61 ++Passes; \
62 } else { \
63 ++Failures; \
64 std::cout << std::fixed << XSTR(Func) << "<" << FromString << ", " \
65 << ToString << ">(" << vectAsString<FromCName>(Input) \
66 << "): "; \
67 std::cout << "sz=" << vectAsString<ToCName>(ResultSz) \
68 << " llc=" << vectAsString<ToCName>(ResultLlc); \
69 std::cout << "\n"; \
70 } \
71 } while (0)
72
51 template <typename FromType> 73 template <typename FromType>
52 void testValue(FromType Val, size_t &TotalTests, size_t &Passes, 74 void testValue(FromType Val, size_t &TotalTests, size_t &Passes,
53 size_t &Failures, const char *FromTypeString) { 75 size_t &Failures, const char *FromTypeString) {
54 COMPARE(cast, FromType, bool, Val, FromTypeString); 76 COMPARE(cast, FromType, bool, Val, FromTypeString);
55 COMPARE(cast, FromType, uint8_t, Val, FromTypeString); 77 COMPARE(cast, FromType, uint8_t, Val, FromTypeString);
56 COMPARE(cast, FromType, myint8_t, Val, FromTypeString); 78 COMPARE(cast, FromType, myint8_t, Val, FromTypeString);
57 COMPARE(cast, FromType, uint16_t, Val, FromTypeString); 79 COMPARE(cast, FromType, uint16_t, Val, FromTypeString);
58 COMPARE(cast, FromType, int16_t, Val, FromTypeString); 80 COMPARE(cast, FromType, int16_t, Val, FromTypeString);
59 COMPARE(cast, FromType, uint32_t, Val, FromTypeString); 81 COMPARE(cast, FromType, uint32_t, Val, FromTypeString);
60 COMPARE(cast, FromType, int32_t, Val, FromTypeString); 82 COMPARE(cast, FromType, int32_t, Val, FromTypeString);
61 COMPARE(cast, FromType, uint64_t, Val, FromTypeString); 83 COMPARE(cast, FromType, uint64_t, Val, FromTypeString);
62 COMPARE(cast, FromType, int64_t, Val, FromTypeString); 84 COMPARE(cast, FromType, int64_t, Val, FromTypeString);
63 COMPARE(cast, FromType, float, Val, FromTypeString); 85 COMPARE(cast, FromType, float, Val, FromTypeString);
64 COMPARE(cast, FromType, double, Val, FromTypeString); 86 COMPARE(cast, FromType, double, Val, FromTypeString);
65 } 87 }
66 88
89 template <typename FromType, typename ToType>
90 void testVector(size_t &TotalTests, size_t &Passes, size_t &Failures,
91 const char *FromTypeString, const char *ToTypeString) {
92 const static size_t NumElementsInType = Vectors<FromType>::NumElements;
93 PRNG Index;
94 volatile float Values[] = {
Jim Stichnoth 2014/10/07 21:57:47 How about creating this array using FP_VALUE_ARRAY
jvoung (off chromium) 2014/10/07 22:55:54 Good idea -- done.
95 0, 1, 1.4,
96 1.5, 1.6, -1.4,
97 -1.5, -1.6, 0x7e,
98 0x7f, 0x80, 0x81,
99 0xfe, 0xff, 0x7ffe,
100 0x7fff, 0x8000, 0x8001,
101 0xfffe, 0xffff, 0x7ffffffe,
102 0x7fffffff, 0x80000000, 0x80000001,
103 0xfffffffe, 0xffffffff, 0x100000000ll,
104 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
105 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
106 0xffffffffffffffffll
107 };
108 static const size_t NumValues = sizeof(Values) / sizeof(*Values);
109 const size_t MaxTestsPerFunc = 20000;
110 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
111 // Initialize the test vectors.
112 FromType Value;
113 for (size_t j = 0; j < NumElementsInType; ++j) {
114 Value[j] = Values[Index() % NumValues];
115 }
116 COMPARE_VEC(cast, FromType, ToType, Value, FromTypeString, ToTypeString);
117 }
118 }
119
67 int main(int argc, char **argv) { 120 int main(int argc, char **argv) {
68 size_t TotalTests = 0; 121 size_t TotalTests = 0;
69 size_t Passes = 0; 122 size_t Passes = 0;
70 size_t Failures = 0; 123 size_t Failures = 0;
71 124
72 volatile bool ValsUi1[] = { false, true }; 125 volatile bool ValsUi1[] = { false, true };
73 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1); 126 static const size_t NumValsUi1 = sizeof(ValsUi1) / sizeof(*ValsUi1);
74 volatile uint8_t ValsUi8[] = { 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff }; 127 volatile uint8_t ValsUi8[] = { 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff };
75 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8); 128 static const size_t NumValsUi8 = sizeof(ValsUi8) / sizeof(*ValsUi8);
76 129
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 265 }
213 for (size_t i = 0; i < NumValsF64; ++i) { 266 for (size_t i = 0; i < NumValsF64; ++i) {
214 for (unsigned j = 0; j < 2; ++j) { 267 for (unsigned j = 0; j < 2; ++j) {
215 double Val = ValsF64[i]; 268 double Val = ValsF64[i];
216 if (j > 0) 269 if (j > 0)
217 Val = -Val; 270 Val = -Val;
218 testValue<double>(Val, TotalTests, Passes, Failures, "double"); 271 testValue<double>(Val, TotalTests, Passes, Failures, "double");
219 COMPARE(castBits, double, uint64_t, Val, "double"); 272 COMPARE(castBits, double, uint64_t, Val, "double");
220 } 273 }
221 } 274 }
275 testVector<v4ui32, v4f32>(TotalTests, Passes, Failures, "v4ui32", "v4f32");
276 testVector<v4si32, v4f32>(TotalTests, Passes, Failures, "v4si32", "v4f32");
277 testVector<v4f32, v4si32>(TotalTests, Passes, Failures, "v4f32", "v4si32");
278 testVector<v4f32, v4ui32>(TotalTests, Passes, Failures, "v4f32", "v4ui32");
222 279
223 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 280 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
224 << " Failures=" << Failures << "\n"; 281 << " Failures=" << Failures << "\n";
225 return Failures; 282 return Failures;
226 } 283 }
OLDNEW
« no previous file with comments | « crosstest/runtests.sh ('k') | crosstest/test_cast_vectors.ll » ('j') | pydir/szbuild.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698