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 "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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val, | 745 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val, |
746 new_val, new_val, new_val, new_val, new_val, new_val, | 746 new_val, new_val, new_val, new_val, new_val, new_val, |
747 new_val, new_val, new_val, new_val, new_val, old_val), | 747 new_val, new_val, new_val, new_val, new_val, old_val), |
748 WASM_SET_LOCAL(simd, | 748 WASM_SET_LOCAL(simd, |
749 WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd), | 749 WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd), |
750 WASM_GET_LOCAL(new_val))), | 750 WASM_GET_LOCAL(new_val))), |
751 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val), WASM_ONE); | 751 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val), WASM_ONE); |
752 | 752 |
753 CHECK_EQ(1, r.Call(1, 2)); | 753 CHECK_EQ(1, r.Call(1, 2)); |
754 } | 754 } |
| 755 #endif // V8_TARGET_ARCH_ARM |
755 | 756 |
| 757 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
756 // Determines if conversion from float to int will be valid. | 758 // Determines if conversion from float to int will be valid. |
757 bool CanRoundToZeroAndConvert(double val, bool unsigned_integer) { | 759 bool CanRoundToZeroAndConvert(double val, bool unsigned_integer) { |
758 const double max_uint = static_cast<double>(0xffffffffu); | 760 const double max_uint = static_cast<double>(0xffffffffu); |
759 const double max_int = static_cast<double>(kMaxInt); | 761 const double max_int = static_cast<double>(kMaxInt); |
760 const double min_int = static_cast<double>(kMinInt); | 762 const double min_int = static_cast<double>(kMinInt); |
761 | 763 |
762 // Check for NaN. | 764 // Check for NaN. |
763 if (val != val) { | 765 if (val != val) { |
764 return false; | 766 return false; |
765 } | 767 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed), | 811 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed), |
810 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), | 812 WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), |
811 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE); | 813 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE); |
812 | 814 |
813 FOR_FLOAT32_INPUTS(i) { | 815 FOR_FLOAT32_INPUTS(i) { |
814 int32_t signed_value = ConvertToInt(*i, false); | 816 int32_t signed_value = ConvertToInt(*i, false); |
815 int32_t unsigned_value = ConvertToInt(*i, true); | 817 int32_t unsigned_value = ConvertToInt(*i, true); |
816 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value)); | 818 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value)); |
817 } | 819 } |
818 } | 820 } |
819 #endif // V8_TARGET_ARCH_ARM | |
820 | 821 |
821 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | |
822 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) { | 822 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) { |
823 FLAG_wasm_simd_prototype = true; | 823 FLAG_wasm_simd_prototype = true; |
824 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 824 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
825 byte a = 0; | 825 byte a = 0; |
826 byte expected = 1; | 826 byte expected = 1; |
827 byte simd = r.AllocateLocal(kWasmS128); | 827 byte simd = r.AllocateLocal(kWasmS128); |
828 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))), |
829 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))), |
830 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); | 830 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); |
831 | 831 |
(...skipping 29 matching lines...) Expand all Loading... |
861 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } | 861 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } |
862 | 862 |
863 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 863 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
864 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } | 864 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } |
865 | 865 |
866 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } | 866 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } |
867 | 867 |
868 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } | 868 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } |
869 | 869 |
870 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } | 870 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } |
871 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | |
872 | 871 |
873 #if V8_TARGET_ARCH_ARM | |
874 WASM_EXEC_COMPILED_TEST(I32x4Min) { | 872 WASM_EXEC_COMPILED_TEST(I32x4Min) { |
875 RunI32x4BinOpTest(kExprI32x4MinS, Minimum); | 873 RunI32x4BinOpTest(kExprI32x4MinS, Minimum); |
876 } | 874 } |
877 | 875 |
878 WASM_EXEC_COMPILED_TEST(I32x4Max) { | 876 WASM_EXEC_COMPILED_TEST(I32x4Max) { |
879 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); | 877 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); |
880 } | 878 } |
881 | 879 |
882 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { | 880 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { |
883 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); | 881 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); |
884 } | 882 } |
885 | 883 |
886 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { | 884 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { |
887 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); | 885 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); |
888 } | 886 } |
| 887 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
889 | 888 |
890 | 889 #if V8_TARGET_ARCH_ARM |
891 | |
892 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { | 890 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { |
893 FLAG_wasm_simd_prototype = true; | 891 FLAG_wasm_simd_prototype = true; |
894 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 892 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
895 byte a = 0; | 893 byte a = 0; |
896 byte b = 1; | 894 byte b = 1; |
897 byte expected = 2; | 895 byte expected = 2; |
898 byte simd0 = r.AllocateLocal(kWasmS128); | 896 byte simd0 = r.AllocateLocal(kWasmS128); |
899 byte simd1 = r.AllocateLocal(kWasmS128); | 897 byte simd1 = r.AllocateLocal(kWasmS128); |
900 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 898 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
901 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 899 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); | 940 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); |
943 } | 941 } |
944 | 942 |
945 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { | 943 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { |
946 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); | 944 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); |
947 } | 945 } |
948 | 946 |
949 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { | 947 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { |
950 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); | 948 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); |
951 } | 949 } |
| 950 #endif // V8_TARGET_ARCH_ARM |
952 | 951 |
| 952 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
953 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, | 953 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, |
954 int shift) { | 954 int shift) { |
955 FLAG_wasm_simd_prototype = true; | 955 FLAG_wasm_simd_prototype = true; |
956 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 956 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
957 byte a = 0; | 957 byte a = 0; |
958 byte expected = 1; | 958 byte expected = 1; |
959 byte simd = r.AllocateLocal(kWasmS128); | 959 byte simd = r.AllocateLocal(kWasmS128); |
960 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 960 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
961 WASM_SET_LOCAL( | 961 WASM_SET_LOCAL( |
962 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), | 962 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
963 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); | 963 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); |
964 | 964 |
965 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } | 965 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
966 } | 966 } |
967 | 967 |
968 WASM_EXEC_COMPILED_TEST(I32x4Shl) { | 968 WASM_EXEC_COMPILED_TEST(I32x4Shl) { |
969 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1); | 969 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1); |
970 } | 970 } |
971 | 971 |
972 WASM_EXEC_COMPILED_TEST(I32x4ShrS) { | 972 WASM_EXEC_COMPILED_TEST(I32x4ShrS) { |
973 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1); | 973 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1); |
974 } | 974 } |
975 | 975 |
976 WASM_EXEC_COMPILED_TEST(I32x4ShrU) { | 976 WASM_EXEC_COMPILED_TEST(I32x4ShrU) { |
977 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1); | 977 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1); |
978 } | 978 } |
| 979 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
| 980 |
| 981 #if V8_TARGET_ARCH_ARM |
979 | 982 |
980 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) { | 983 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) { |
981 FLAG_wasm_simd_prototype = true; | 984 FLAG_wasm_simd_prototype = true; |
982 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 985 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
983 byte a = 0; | 986 byte a = 0; |
984 byte expected = 1; | 987 byte expected = 1; |
985 byte simd = r.AllocateLocal(kWasmS128); | 988 byte simd = r.AllocateLocal(kWasmS128); |
986 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), | 989 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), |
987 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), | 990 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), |
988 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); | 991 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 1564 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
1562 WASM_F32(65.0))), | 1565 WASM_F32(65.0))), |
1563 WASM_I32V(1)); | 1566 WASM_I32V(1)); |
1564 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 1567 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
1565 CHECK_EQ(*global, 13.5); | 1568 CHECK_EQ(*global, 13.5); |
1566 CHECK_EQ(*(global + 1), 45.5); | 1569 CHECK_EQ(*(global + 1), 45.5); |
1567 CHECK_EQ(*(global + 2), 32.25); | 1570 CHECK_EQ(*(global + 2), 32.25); |
1568 CHECK_EQ(*(global + 3), 65.0); | 1571 CHECK_EQ(*(global + 3), 65.0); |
1569 } | 1572 } |
1570 #endif // SIMD_LOWERING_TARGET | 1573 #endif // SIMD_LOWERING_TARGET |
OLD | NEW |