Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <cmath> | |
|
gdeepti
2017/02/28 09:50:49
Header not needed here, already included in cctest
aseemgarg
2017/02/28 12:54:07
Done.
| |
| 5 #include "src/assembler-inl.h" | 6 #include "src/assembler-inl.h" |
| 6 #include "src/wasm/wasm-macro-gen.h" | 7 #include "src/wasm/wasm-macro-gen.h" |
| 7 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
| 8 #include "test/cctest/compiler/value-helper.h" | 9 #include "test/cctest/compiler/value-helper.h" |
| 9 #include "test/cctest/wasm/wasm-run-utils.h" | 10 #include "test/cctest/wasm/wasm-run-utils.h" |
| 10 | 11 |
| 11 using namespace v8::base; | 12 using namespace v8::base; |
| 12 using namespace v8::internal; | 13 using namespace v8::internal; |
| 13 using namespace v8::internal::compiler; | 14 using namespace v8::internal::compiler; |
| 14 using namespace v8::internal::wasm; | 15 using namespace v8::internal::wasm; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 template <typename T> | 206 template <typename T> |
| 206 T Xor(T a, T b) { | 207 T Xor(T a, T b) { |
| 207 return a ^ b; | 208 return a ^ b; |
| 208 } | 209 } |
| 209 | 210 |
| 210 template <typename T> | 211 template <typename T> |
| 211 T Not(T a) { | 212 T Not(T a) { |
| 212 return ~a; | 213 return ~a; |
| 213 } | 214 } |
| 214 | 215 |
| 216 template <typename T> | |
| 217 T Sqrt(T a) { | |
| 218 return std::sqrt(a); | |
| 219 } | |
| 220 | |
| 215 } // namespace | 221 } // namespace |
| 216 | 222 |
| 217 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | 223 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 |
| 218 #define SIMD_LOWERING_TARGET 1 | 224 #define SIMD_LOWERING_TARGET 1 |
| 219 #else | 225 #else |
| 220 #define SIMD_LOWERING_TARGET 0 | 226 #define SIMD_LOWERING_TARGET 0 |
| 221 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | 227 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 |
| 222 | 228 |
| 223 // TODO(gdeepti): These are tests using sample values to verify functional | 229 // 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 | 230 // 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 Loading... | |
| 372 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd), | 378 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd), |
| 373 WASM_GET_LOCAL(new_val))), | 379 WASM_GET_LOCAL(new_val))), |
| 374 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val), | 380 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val), |
| 375 WASM_SET_LOCAL(simd, | 381 WASM_SET_LOCAL(simd, |
| 376 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), | 382 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), |
| 377 WASM_GET_LOCAL(new_val))), | 383 WASM_GET_LOCAL(new_val))), |
| 378 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE); | 384 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE); |
| 379 | 385 |
| 380 CHECK_EQ(1, r.Call(3.14159f, -1.5f)); | 386 CHECK_EQ(1, r.Call(3.14159f, -1.5f)); |
| 381 } | 387 } |
| 382 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | |
| 383 | 388 |
| 384 #if V8_TARGET_ARCH_ARM | |
| 385 // Tests both signed and unsigned conversion. | 389 // Tests both signed and unsigned conversion. |
| 386 WASM_EXEC_COMPILED_TEST(F32x4FromInt32x4) { | 390 WASM_EXEC_COMPILED_TEST(F32x4FromInt32x4) { |
| 387 FLAG_wasm_simd_prototype = true; | 391 FLAG_wasm_simd_prototype = true; |
| 388 WasmRunner<int32_t, int32_t, float, float> r(kExecuteCompiled); | 392 WasmRunner<int32_t, int32_t, float, float> r(kExecuteCompiled); |
| 389 byte a = 0; | 393 byte a = 0; |
| 390 byte expected_signed = 1; | 394 byte expected_signed = 1; |
| 391 byte expected_unsigned = 2; | 395 byte expected_unsigned = 2; |
| 392 byte simd0 = r.AllocateLocal(kWasmS128); | 396 byte simd0 = r.AllocateLocal(kWasmS128); |
| 393 byte simd1 = r.AllocateLocal(kWasmS128); | 397 byte simd1 = r.AllocateLocal(kWasmS128); |
| 394 byte simd2 = r.AllocateLocal(kWasmS128); | 398 byte simd2 = r.AllocateLocal(kWasmS128); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 416 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected), WASM_ONE); | 420 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected), WASM_ONE); |
| 417 | 421 |
| 418 FOR_FLOAT32_INPUTS(i) { | 422 FOR_FLOAT32_INPUTS(i) { |
| 419 if (std::isnan(*i)) continue; | 423 if (std::isnan(*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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |