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

Side by Side Diff: crosstest/test_arith_main.cpp

Issue 384443003: Add scalar lowering for sqrt intrinsic. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: whitespace Created 6 years, 5 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.h ('k') | crosstest/test_arith_sqrt.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 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ 1 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \
2 --driver=test_arith_main.cpp --prefix=Subzero_ --output=test_arith */ 2 --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \
3 --prefix=Subzero_ --output=test_arith */
3 4
4 #include <stdint.h> 5 #include <stdint.h>
5 6
6 #include <cfloat> 7 #include <cfloat>
7 #include <cstring> // memcmp 8 #include <cstring> // memcmp
8 #include <iostream> 9 #include <iostream>
9 10
10 // Include test_arith.h twice - once normally, and once within the 11 // Include test_arith.h twice - once normally, and once within the
11 // Subzero_ namespace, corresponding to the llc and Subzero translated 12 // Subzero_ namespace, corresponding to the llc and Subzero translated
12 // object files, respectively. 13 // object files, respectively.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 117 }
117 } 118 }
118 } 119 }
119 } 120 }
120 121
121 template <typename Type> 122 template <typename Type>
122 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { 123 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
123 static const Type NegInf = -1.0 / 0.0; 124 static const Type NegInf = -1.0 / 0.0;
124 static const Type PosInf = 1.0 / 0.0; 125 static const Type PosInf = 1.0 / 0.0;
125 static const Type Nan = 0.0 / 0.0; 126 static const Type Nan = 0.0 / 0.0;
127 static const Type NegNan = -0.0 / 0.0;
126 volatile Type Values[] = { 128 volatile Type Values[] = {
127 0, 1, 0x7e, 129 0, 1, 0x7e,
128 0x7f, 0x80, 0x81, 130 0x7f, 0x80, 0x81,
129 0xfe, 0xff, 0x7ffe, 131 0xfe, 0xff, 0x7ffe,
130 0x7fff, 0x8000, 0x8001, 132 0x7fff, 0x8000, 0x8001,
131 0xfffe, 0xffff, 0x7ffffffe, 133 0xfffe, 0xffff, 0x7ffffffe,
132 0x7fffffff, 0x80000000, 0x80000001, 134 0x7fffffff, 0x80000000, 0x80000001,
133 0xfffffffe, 0xffffffff, 0x100000000ll, 135 0xfffffffe, 0xffffffff, 0x100000000ll,
134 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll, 136 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
135 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell, 137 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
136 0xffffffffffffffffll, NegInf, PosInf, 138 0xffffffffffffffffll, NegInf, PosInf,
137 Nan, FLT_MIN, FLT_MAX, 139 Nan, NegNan, -0.0,
140 FLT_MIN, FLT_MAX,
138 DBL_MIN, DBL_MAX 141 DBL_MIN, DBL_MAX
139 }; 142 };
140 const static size_t NumValues = sizeof(Values) / sizeof(*Values); 143 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
141 typedef Type (*FuncType)(Type, Type); 144 typedef Type (*FuncType)(Type, Type);
142 static struct { 145 static struct {
143 const char *Name; 146 const char *Name;
144 FuncType FuncLlc; 147 FuncType FuncLlc;
145 FuncType FuncSz; 148 FuncType FuncSz;
146 } Funcs[] = { 149 } Funcs[] = {
147 #define X(inst, op, func) \ 150 #define X(inst, op, func) \
(...skipping 18 matching lines...) Expand all
166 } else { 169 } else {
167 ++Failures; 170 ++Failures;
168 std::cout << std::fixed << "test" << Funcs[f].Name 171 std::cout << std::fixed << "test" << Funcs[f].Name
169 << (8 * sizeof(Type)) << "(" << Value1 << ", " << Value2 172 << (8 * sizeof(Type)) << "(" << Value1 << ", " << Value2
170 << "): sz=" << ResultSz << " llc=" << ResultLlc 173 << "): sz=" << ResultSz << " llc=" << ResultLlc
171 << std::endl; 174 << std::endl;
172 } 175 }
173 } 176 }
174 } 177 }
175 } 178 }
179 for (size_t i = 0; i < NumValues; ++i) {
180 Type Value = Values[i];
181 ++TotalTests;
182 Type ResultSz = Subzero_::mySqrt(Value);
183 Type ResultLlc = mySqrt(Value);
184 // Compare results using memcmp() in case they are both NaN.
185 if (!memcmp(&ResultSz, &ResultLlc, sizeof(Type))) {
186 ++Passes;
187 } else {
188 ++Failures;
189 std::cout << std::fixed << "test_sqrt"
190 << (8 * sizeof(Type)) << "(" << Value
191 << "): sz=" << ResultSz << " llc=" << ResultLlc
192 << std::endl;
193 }
194 }
176 } 195 }
177 196
178 int main(int argc, char **argv) { 197 int main(int argc, char **argv) {
179 size_t TotalTests = 0; 198 size_t TotalTests = 0;
180 size_t Passes = 0; 199 size_t Passes = 0;
181 size_t Failures = 0; 200 size_t Failures = 0;
182 201
183 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); 202 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures);
184 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); 203 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures);
185 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); 204 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures);
186 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); 205 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures);
187 testsFp<float>(TotalTests, Passes, Failures); 206 testsFp<float>(TotalTests, Passes, Failures);
188 testsFp<double>(TotalTests, Passes, Failures); 207 testsFp<double>(TotalTests, Passes, Failures);
189 208
190 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 209 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
191 << " Failures=" << Failures << "\n"; 210 << " Failures=" << Failures << "\n";
192 return Failures; 211 return Failures;
193 } 212 }
OLDNEW
« no previous file with comments | « crosstest/test_arith.h ('k') | crosstest/test_arith_sqrt.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698