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/wasm/wasm-macro-gen.h" | 5 #include "src/wasm/wasm-macro-gen.h" |
6 | 6 |
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 27 matching lines...) Expand all Loading... |
38 // Store SIMD value in a local variable, use extract lane to check lane values | 38 // Store SIMD value in a local variable, use extract lane to check lane values |
39 // This test is not a test for ExtractLane as Splat does not create | 39 // This test is not a test for ExtractLane as Splat does not create |
40 // interesting SIMD values. | 40 // interesting SIMD values. |
41 // | 41 // |
42 // SetLocal(1, I32x4Splat(Local(0))); | 42 // SetLocal(1, I32x4Splat(Local(0))); |
43 // For each lane index | 43 // For each lane index |
44 // if(Local(0) != I32x4ExtractLane(Local(1), index) | 44 // if(Local(0) != I32x4ExtractLane(Local(1), index) |
45 // return 0 | 45 // return 0 |
46 // | 46 // |
47 // return 1 | 47 // return 1 |
48 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 48 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
49 byte lane_val = 0; | 49 byte lane_val = 0; |
50 byte simd = r.AllocateLocal(kAstS128); | 50 byte simd = r.AllocateLocal(kAstS128); |
51 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( | 51 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( |
52 WASM_GET_LOCAL(lane_val))), | 52 WASM_GET_LOCAL(lane_val))), |
53 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), | 53 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), |
54 WASM_RETURN1(WASM_ONE))); | 54 WASM_RETURN1(WASM_ONE))); |
55 | 55 |
56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } | 56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } |
57 } | 57 } |
58 | 58 |
59 WASM_EXEC_TEST(I32x4ReplaceLane) { | 59 WASM_EXEC_TEST(I32x4ReplaceLane) { |
60 FLAG_wasm_simd_prototype = true; | 60 FLAG_wasm_simd_prototype = true; |
61 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | 61 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
62 MachineType::Int32()); | |
63 byte old_val = 0; | 62 byte old_val = 0; |
64 byte new_val = 1; | 63 byte new_val = 1; |
65 byte simd = r.AllocateLocal(kAstS128); | 64 byte simd = r.AllocateLocal(kAstS128); |
66 BUILD(r, WASM_BLOCK( | 65 BUILD(r, WASM_BLOCK( |
67 WASM_SET_LOCAL(simd, | 66 WASM_SET_LOCAL(simd, |
68 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))), | 67 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))), |
69 WASM_SET_LOCAL( | 68 WASM_SET_LOCAL( |
70 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd), | 69 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd), |
71 WASM_GET_LOCAL(new_val))), | 70 WASM_GET_LOCAL(new_val))), |
72 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, | 71 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, |
(...skipping 12 matching lines...) Expand all Loading... |
85 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), | 84 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), |
86 WASM_GET_LOCAL(new_val))), | 85 WASM_GET_LOCAL(new_val))), |
87 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), | 86 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), |
88 WASM_RETURN1(WASM_ONE))); | 87 WASM_RETURN1(WASM_ONE))); |
89 | 88 |
90 CHECK_EQ(1, r.Call(1, 2)); | 89 CHECK_EQ(1, r.Call(1, 2)); |
91 } | 90 } |
92 | 91 |
93 WASM_EXEC_TEST(I32x4Add) { | 92 WASM_EXEC_TEST(I32x4Add) { |
94 FLAG_wasm_simd_prototype = true; | 93 FLAG_wasm_simd_prototype = true; |
95 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | 94 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
96 MachineType::Int32(), MachineType::Int32()); | |
97 byte a = 0; | 95 byte a = 0; |
98 byte b = 1; | 96 byte b = 1; |
99 byte expected = 2; | 97 byte expected = 2; |
100 byte simd0 = r.AllocateLocal(kAstS128); | 98 byte simd0 = r.AllocateLocal(kAstS128); |
101 byte simd1 = r.AllocateLocal(kAstS128); | 99 byte simd1 = r.AllocateLocal(kAstS128); |
102 BUILD(r, | 100 BUILD(r, |
103 WASM_BLOCK( | 101 WASM_BLOCK( |
104 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 102 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
105 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 103 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
106 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0), | 104 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0), |
107 WASM_GET_LOCAL(simd1))), | 105 WASM_GET_LOCAL(simd1))), |
108 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), | 106 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), |
109 WASM_RETURN1(WASM_ONE))); | 107 WASM_RETURN1(WASM_ONE))); |
110 | 108 |
111 FOR_INT32_INPUTS(i) { | 109 FOR_INT32_INPUTS(i) { |
112 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); } | 110 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); } |
113 } | 111 } |
114 } | 112 } |
115 | 113 |
116 WASM_EXEC_TEST(I32x4Sub) { | 114 WASM_EXEC_TEST(I32x4Sub) { |
117 FLAG_wasm_simd_prototype = true; | 115 FLAG_wasm_simd_prototype = true; |
118 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | 116 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
119 MachineType::Int32(), MachineType::Int32()); | |
120 byte a = 0; | 117 byte a = 0; |
121 byte b = 1; | 118 byte b = 1; |
122 byte expected = 2; | 119 byte expected = 2; |
123 byte simd0 = r.AllocateLocal(kAstS128); | 120 byte simd0 = r.AllocateLocal(kAstS128); |
124 byte simd1 = r.AllocateLocal(kAstS128); | 121 byte simd1 = r.AllocateLocal(kAstS128); |
125 BUILD(r, | 122 BUILD(r, |
126 WASM_BLOCK( | 123 WASM_BLOCK( |
127 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 124 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
128 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 125 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
129 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0), | 126 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0), |
130 WASM_GET_LOCAL(simd1))), | 127 WASM_GET_LOCAL(simd1))), |
131 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), | 128 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), |
132 WASM_RETURN1(WASM_ONE))); | 129 WASM_RETURN1(WASM_ONE))); |
133 | 130 |
134 FOR_INT32_INPUTS(i) { | 131 FOR_INT32_INPUTS(i) { |
135 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); } | 132 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); } |
136 } | 133 } |
137 } | 134 } |
OLD | NEW |