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

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

Issue 2764413003: [WASM] Fix failing WASM SIMD tests. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \ 384 #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \
385 x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane) 385 x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane)
386 #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \ 386 #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \
387 x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane) 387 x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane)
388 388
389 #define WASM_SIMD_F32x4_FROM_I32x4(x) x, WASM_SIMD_OP(kExprF32x4SConvertI32x4) 389 #define WASM_SIMD_F32x4_FROM_I32x4(x) x, WASM_SIMD_OP(kExprF32x4SConvertI32x4)
390 #define WASM_SIMD_F32x4_FROM_U32x4(x) x, WASM_SIMD_OP(kExprF32x4UConvertI32x4) 390 #define WASM_SIMD_F32x4_FROM_U32x4(x) x, WASM_SIMD_OP(kExprF32x4UConvertI32x4)
391 #define WASM_SIMD_I32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4SConvertF32x4) 391 #define WASM_SIMD_I32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4SConvertF32x4)
392 #define WASM_SIMD_U32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4UConvertF32x4) 392 #define WASM_SIMD_U32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4UConvertF32x4)
393 393
394 // Skip FP operations on extremely large or extremely small values, which may 394 // Skip FP tests involving extremely large or extremely small values, which
395 // cause tests to fail due to non-IEEE-754 arithmetic on some platforms. 395 // may fail due to non-IEEE-754 SIMD arithmetic on some platforms.
396 bool SkipFPTestInput(float x) { 396 bool SkipFPValue(float x) {
397 float abs_x = std::fabs(x); 397 float abs_x = std::fabs(x);
398 const float kSmallFloatThreshold = 1.0e-32f; 398 const float kSmallFloatThreshold = 1.0e-32f;
399 const float kLargeFloatThreshold = 1.0e32f; 399 const float kLargeFloatThreshold = 1.0e32f;
400 return abs_x != 0.0f && // 0 or -0 are fine. 400 return abs_x != 0.0f && // 0 or -0 are fine.
401 (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold); 401 (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold);
402 } 402 }
403 403
404 // Skip tests where the expected value is a NaN. Our WASM test code can't 404 // Skip tests where the expected value is a NaN, since our WASM test code
405 // deal with NaNs. 405 // doesn't handle NaNs. Also skip extreme values.
406 bool SkipFPExpectedValue(float x) { return std::isnan(x); } 406 bool SkipFPExpectedValue(float x) { return std::isnan(x) || SkipFPValue(x); }
407 407
408 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 408 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
409 WASM_EXEC_COMPILED_TEST(F32x4Splat) { 409 WASM_EXEC_COMPILED_TEST(F32x4Splat) {
410 FLAG_wasm_simd_prototype = true; 410 FLAG_wasm_simd_prototype = true;
411 411
412 WasmRunner<int32_t, float> r(kExecuteCompiled); 412 WasmRunner<int32_t, float> r(kExecuteCompiled);
413 byte lane_val = 0; 413 byte lane_val = 0;
414 byte simd = r.AllocateLocal(kWasmS128); 414 byte simd = r.AllocateLocal(kWasmS128);
415 BUILD(r, 415 BUILD(r,
416 WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))), 416 WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 byte a = 0; 480 byte a = 0;
481 byte low = 1; 481 byte low = 1;
482 byte high = 2; 482 byte high = 2;
483 byte simd = r.AllocateLocal(kWasmS128); 483 byte simd = r.AllocateLocal(kWasmS128);
484 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 484 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
485 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), 485 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
486 WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(simd, low, high), 486 WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(simd, low, high),
487 WASM_RETURN1(WASM_ONE)); 487 WASM_RETURN1(WASM_ONE));
488 488
489 FOR_FLOAT32_INPUTS(i) { 489 FOR_FLOAT32_INPUTS(i) {
490 if (SkipFPTestInput(*i)) continue; 490 if (SkipFPValue(*i)) continue;
491 float expected = expected_op(*i); 491 float expected = expected_op(*i);
492 if (SkipFPExpectedValue(expected)) continue; 492 if (SkipFPExpectedValue(expected)) continue;
493 float abs_error = std::abs(expected) * error; 493 float abs_error = std::abs(expected) * error;
494 CHECK_EQ(1, r.Call(*i, expected - abs_error, expected + abs_error)); 494 CHECK_EQ(1, r.Call(*i, expected - abs_error, expected + abs_error));
495 } 495 }
496 } 496 }
497 497
498 WASM_EXEC_COMPILED_TEST(F32x4Abs) { RunF32x4UnOpTest(kExprF32x4Abs, std::abs); } 498 WASM_EXEC_COMPILED_TEST(F32x4Abs) { RunF32x4UnOpTest(kExprF32x4Abs, std::abs); }
499 WASM_EXEC_COMPILED_TEST(F32x4Neg) { RunF32x4UnOpTest(kExprF32x4Neg, Negate); } 499 WASM_EXEC_COMPILED_TEST(F32x4Neg) { RunF32x4UnOpTest(kExprF32x4Neg, Negate); }
500 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 500 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
(...skipping 23 matching lines...) Expand all
524 byte expected = 2; 524 byte expected = 2;
525 byte simd0 = r.AllocateLocal(kWasmS128); 525 byte simd0 = r.AllocateLocal(kWasmS128);
526 byte simd1 = r.AllocateLocal(kWasmS128); 526 byte simd1 = r.AllocateLocal(kWasmS128);
527 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 527 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
528 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))), 528 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
529 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0), 529 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
530 WASM_GET_LOCAL(simd1))), 530 WASM_GET_LOCAL(simd1))),
531 WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected), WASM_RETURN1(WASM_ONE)); 531 WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected), WASM_RETURN1(WASM_ONE));
532 532
533 FOR_FLOAT32_INPUTS(i) { 533 FOR_FLOAT32_INPUTS(i) {
534 if (SkipFPTestInput(*i)) continue; 534 if (SkipFPValue(*i)) continue;
535 FOR_FLOAT32_INPUTS(j) { 535 FOR_FLOAT32_INPUTS(j) {
536 if (SkipFPTestInput(*j)) continue; 536 if (SkipFPValue(*j)) continue;
537 float expected = expected_op(*i, *j); 537 float expected = expected_op(*i, *j);
538 if (SkipFPExpectedValue(expected)) continue; 538 if (SkipFPExpectedValue(expected)) continue;
539 CHECK_EQ(1, r.Call(*i, *j, expected)); 539 CHECK_EQ(1, r.Call(*i, *j, expected));
540 } 540 }
541 } 541 }
542 } 542 }
543 543
544 WASM_EXEC_COMPILED_TEST(F32x4Add) { RunF32x4BinOpTest(kExprF32x4Add, Add); } 544 WASM_EXEC_COMPILED_TEST(F32x4Add) { RunF32x4BinOpTest(kExprF32x4Add, Add); }
545 WASM_EXEC_COMPILED_TEST(F32x4Sub) { RunF32x4BinOpTest(kExprF32x4Sub, Sub); } 545 WASM_EXEC_COMPILED_TEST(F32x4Sub) { RunF32x4BinOpTest(kExprF32x4Sub, Sub); }
546 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); } 546 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); }
(...skipping 30 matching lines...) Expand all
577 byte simd1 = r.AllocateLocal(kWasmS128); 577 byte simd1 = r.AllocateLocal(kWasmS128);
578 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 578 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
579 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))), 579 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
580 WASM_SET_LOCAL(simd1, 580 WASM_SET_LOCAL(simd1,
581 WASM_SIMD_MATERIALIZE_BOOLS( 581 WASM_SIMD_MATERIALIZE_BOOLS(
582 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0), 582 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
583 WASM_GET_LOCAL(simd1)))), 583 WASM_GET_LOCAL(simd1)))),
584 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE); 584 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
585 585
586 FOR_FLOAT32_INPUTS(i) { 586 FOR_FLOAT32_INPUTS(i) {
587 if (SkipFPTestInput(*i)) continue; 587 if (SkipFPValue(*i)) continue;
588 FOR_FLOAT32_INPUTS(j) { 588 FOR_FLOAT32_INPUTS(j) {
589 if (SkipFPTestInput(*j)) continue; 589 if (SkipFPValue(*j)) continue;
590 float diff = *i - *j; 590 float diff = *i - *j;
591 if (SkipFPExpectedValue(diff)) continue; 591 if (SkipFPExpectedValue(diff)) continue;
592 CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); 592 CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j)));
593 } 593 }
594 } 594 }
595 } 595 }
596 596
597 WASM_EXEC_COMPILED_TEST(F32x4Eq) { RunF32x4CompareOpTest(kExprF32x4Eq, Equal); } 597 WASM_EXEC_COMPILED_TEST(F32x4Eq) { RunF32x4CompareOpTest(kExprF32x4Eq, Equal); }
598 598
599 WASM_EXEC_COMPILED_TEST(F32x4Ne) { 599 WASM_EXEC_COMPILED_TEST(F32x4Ne) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 byte simd1 = r.AllocateLocal(kWasmS128); 901 byte simd1 = r.AllocateLocal(kWasmS128);
902 byte simd2 = r.AllocateLocal(kWasmS128); 902 byte simd2 = r.AllocateLocal(kWasmS128);
903 BUILD( 903 BUILD(
904 r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 904 r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
905 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), 905 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
906 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed), 906 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
907 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), 907 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
908 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE); 908 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE);
909 909
910 FOR_FLOAT32_INPUTS(i) { 910 FOR_FLOAT32_INPUTS(i) {
911 if (SkipFPTestInput(*i)) continue; 911 if (SkipFPValue(*i)) continue;
912 int32_t signed_value = ConvertToInt(*i, false); 912 int32_t signed_value = ConvertToInt(*i, false);
913 int32_t unsigned_value = ConvertToInt(*i, true); 913 int32_t unsigned_value = ConvertToInt(*i, true);
914 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value)); 914 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value));
915 } 915 }
916 } 916 }
917 917
918 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) { 918 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) {
919 FLAG_wasm_simd_prototype = true; 919 FLAG_wasm_simd_prototype = true;
920 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); 920 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
921 byte a = 0; 921 byte a = 0;
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 WASM_SIMD_I32x4_EXTRACT_LANE( 1855 WASM_SIMD_I32x4_EXTRACT_LANE(
1856 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); 1856 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)));
1857 1857
1858 FOR_INT32_INPUTS(i) { 1858 FOR_INT32_INPUTS(i) {
1859 int32_t expected = *i; 1859 int32_t expected = *i;
1860 r.module().WriteMemory(&memory[0], expected); 1860 r.module().WriteMemory(&memory[0], expected);
1861 CHECK_EQ(expected, r.Call()); 1861 CHECK_EQ(expected, r.Call());
1862 } 1862 }
1863 } 1863 }
1864 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 1864 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698