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

Side by Side Diff: test/cctest/wasm/test-run-wasm-simd.cc

Issue 2726453003: [wasm]implement simd lowering for simple F32x4 and I32x4 unops (Closed)
Patch Set: comments Created 3 years, 9 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
« src/compiler/wasm-compiler.cc ('K') | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/assembler-inl.h" 5 #include "src/assembler-inl.h"
6 #include "src/wasm/wasm-macro-gen.h" 6 #include "src/wasm/wasm-macro-gen.h"
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/value-helper.h" 8 #include "test/cctest/compiler/value-helper.h"
9 #include "test/cctest/wasm/wasm-run-utils.h" 9 #include "test/cctest/wasm/wasm-run-utils.h"
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 template <typename T> 205 template <typename T>
206 T Xor(T a, T b) { 206 T Xor(T a, T b) {
207 return a ^ b; 207 return a ^ b;
208 } 208 }
209 209
210 template <typename T> 210 template <typename T>
211 T Not(T a) { 211 T Not(T a) {
212 return ~a; 212 return ~a;
213 } 213 }
214 214
215 template <typename T>
216 T Sqrt(T a) {
217 return std::sqrt(a);
218 }
219
215 } // namespace 220 } // namespace
216 221
217 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 222 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
218 #define SIMD_LOWERING_TARGET 1 223 #define SIMD_LOWERING_TARGET 1
219 #else 224 #else
220 #define SIMD_LOWERING_TARGET 0 225 #define SIMD_LOWERING_TARGET 0
221 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 226 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
222 227
223 // TODO(gdeepti): These are tests using sample values to verify functional 228 // TODO(gdeepti): These are tests using sample values to verify functional
224 // correctness of opcodes, add more tests for a range of values and macroize 229 // correctness of opcodes, add more tests for a range of values and macroize
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd), 377 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
373 WASM_GET_LOCAL(new_val))), 378 WASM_GET_LOCAL(new_val))),
374 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val), 379 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val),
375 WASM_SET_LOCAL(simd, 380 WASM_SET_LOCAL(simd,
376 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), 381 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
377 WASM_GET_LOCAL(new_val))), 382 WASM_GET_LOCAL(new_val))),
378 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE); 383 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE);
379 384
380 CHECK_EQ(1, r.Call(3.14159f, -1.5f)); 385 CHECK_EQ(1, r.Call(3.14159f, -1.5f));
381 } 386 }
382 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
383 387
384 #if V8_TARGET_ARCH_ARM
385 // Tests both signed and unsigned conversion. 388 // Tests both signed and unsigned conversion.
386 WASM_EXEC_COMPILED_TEST(F32x4FromInt32x4) { 389 WASM_EXEC_COMPILED_TEST(F32x4FromInt32x4) {
387 FLAG_wasm_simd_prototype = true; 390 FLAG_wasm_simd_prototype = true;
388 WasmRunner<int32_t, int32_t, float, float> r(kExecuteCompiled); 391 WasmRunner<int32_t, int32_t, float, float> r(kExecuteCompiled);
389 byte a = 0; 392 byte a = 0;
390 byte expected_signed = 1; 393 byte expected_signed = 1;
391 byte expected_unsigned = 2; 394 byte expected_unsigned = 2;
392 byte simd0 = r.AllocateLocal(kWasmS128); 395 byte simd0 = r.AllocateLocal(kWasmS128);
393 byte simd1 = r.AllocateLocal(kWasmS128); 396 byte simd1 = r.AllocateLocal(kWasmS128);
394 byte simd2 = r.AllocateLocal(kWasmS128); 397 byte simd2 = r.AllocateLocal(kWasmS128);
(...skipping 15 matching lines...) Expand all
410 WasmRunner<int32_t, float, float> r(kExecuteCompiled); 413 WasmRunner<int32_t, float, float> r(kExecuteCompiled);
411 byte a = 0; 414 byte a = 0;
412 byte expected = 1; 415 byte expected = 1;
413 byte simd = r.AllocateLocal(kWasmS128); 416 byte simd = r.AllocateLocal(kWasmS128);
414 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 417 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
415 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), 418 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
416 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected), WASM_ONE); 419 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected), WASM_ONE);
417 420
418 FOR_FLOAT32_INPUTS(i) { 421 FOR_FLOAT32_INPUTS(i) {
419 if (std::isnan(*i)) continue; 422 if (std::isnan(*i)) continue;
423 if (std::isnan(expected_op(*i))) continue;
420 CHECK_EQ(1, r.Call(*i, expected_op(*i))); 424 CHECK_EQ(1, r.Call(*i, expected_op(*i)));
421 } 425 }
422 } 426 }
423 427
424 WASM_EXEC_COMPILED_TEST(F32x4Abs) { RunF32x4UnOpTest(kExprF32x4Abs, std::abs); } 428 WASM_EXEC_COMPILED_TEST(F32x4Abs) { RunF32x4UnOpTest(kExprF32x4Abs, std::abs); }
425 WASM_EXEC_COMPILED_TEST(F32x4Neg) { RunF32x4UnOpTest(kExprF32x4Neg, Negate); } 429 WASM_EXEC_COMPILED_TEST(F32x4Neg) { RunF32x4UnOpTest(kExprF32x4Neg, Negate); }
426 #endif // V8_TARGET_ARCH_ARM 430 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
431
432 #if SIMD_LOWERING_TARGET
433 WASM_EXEC_COMPILED_TEST(F32x4Sqrt) { RunF32x4UnOpTest(kExprF32x4Sqrt, Sqrt); }
434 #endif // SIMD_LOWERING_TARGET
427 435
428 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 436 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
429 void RunF32x4BinOpTest(WasmOpcode simd_op, FloatBinOp expected_op, 437 void RunF32x4BinOpTest(WasmOpcode simd_op, FloatBinOp expected_op,
430 bool skip_zero_inputs = false) { 438 bool skip_zero_inputs = false) {
431 FLAG_wasm_simd_prototype = true; 439 FLAG_wasm_simd_prototype = true;
432 WasmRunner<int32_t, float, float, float> r(kExecuteCompiled); 440 WasmRunner<int32_t, float, float, float> r(kExecuteCompiled);
433 byte a = 0; 441 byte a = 0;
434 byte b = 1; 442 byte b = 1;
435 byte expected = 2; 443 byte expected = 2;
436 byte simd0 = r.AllocateLocal(kWasmS128); 444 byte simd0 = r.AllocateLocal(kWasmS128);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed), 809 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
802 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), 810 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
803 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE); 811 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE);
804 812
805 FOR_FLOAT32_INPUTS(i) { 813 FOR_FLOAT32_INPUTS(i) {
806 int32_t signed_value = ConvertToInt(*i, false); 814 int32_t signed_value = ConvertToInt(*i, false);
807 int32_t unsigned_value = ConvertToInt(*i, true); 815 int32_t unsigned_value = ConvertToInt(*i, true);
808 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value)); 816 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value));
809 } 817 }
810 } 818 }
819 #endif // V8_TARGET_ARCH_ARM
811 820
821 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
812 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) { 822 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) {
813 FLAG_wasm_simd_prototype = true; 823 FLAG_wasm_simd_prototype = true;
814 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); 824 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
815 byte a = 0; 825 byte a = 0;
816 byte expected = 1; 826 byte expected = 1;
817 byte simd = r.AllocateLocal(kWasmS128); 827 byte simd = r.AllocateLocal(kWasmS128);
818 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 828 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
819 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), 829 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
820 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); 830 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
821 831
822 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); } 832 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
823 } 833 }
824 834
825 WASM_EXEC_COMPILED_TEST(I32x4Neg) { RunI32x4UnOpTest(kExprI32x4Neg, Negate); } 835 WASM_EXEC_COMPILED_TEST(I32x4Neg) { RunI32x4UnOpTest(kExprI32x4Neg, Negate); }
826 836
827 WASM_EXEC_COMPILED_TEST(S128Not) { RunI32x4UnOpTest(kExprS128Not, Not); } 837 WASM_EXEC_COMPILED_TEST(S128Not) { RunI32x4UnOpTest(kExprS128Not, Not); }
828 #endif // V8_TARGET_ARCH_ARM 838 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
829 839
830 void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { 840 void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
831 FLAG_wasm_simd_prototype = true; 841 FLAG_wasm_simd_prototype = true;
832 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); 842 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
833 byte a = 0; 843 byte a = 0;
834 byte b = 1; 844 byte b = 1;
835 byte expected = 2; 845 byte expected = 2;
836 byte simd0 = r.AllocateLocal(kWasmS128); 846 byte simd0 = r.AllocateLocal(kWasmS128);
837 byte simd1 = r.AllocateLocal(kWasmS128); 847 byte simd1 = r.AllocateLocal(kWasmS128);
838 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 848 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), 1561 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
1552 WASM_F32(65.0))), 1562 WASM_F32(65.0))),
1553 WASM_I32V(1)); 1563 WASM_I32V(1));
1554 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } 1564 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
1555 CHECK_EQ(*global, 13.5); 1565 CHECK_EQ(*global, 13.5);
1556 CHECK_EQ(*(global + 1), 45.5); 1566 CHECK_EQ(*(global + 1), 45.5);
1557 CHECK_EQ(*(global + 2), 32.25); 1567 CHECK_EQ(*(global + 2), 32.25);
1558 CHECK_EQ(*(global + 3), 65.0); 1568 CHECK_EQ(*(global + 3), 65.0);
1559 } 1569 }
1560 #endif // SIMD_LOWERING_TARGET 1570 #endif // SIMD_LOWERING_TARGET
OLDNEW
« src/compiler/wasm-compiler.cc ('K') | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698