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 #include "src/wasm/wasm-module.h" | 6 #include "src/wasm/wasm-module.h" |
7 | 7 |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 #include "test/cctest/compiler/value-helper.h" | 9 #include "test/cctest/compiler/value-helper.h" |
10 #include "test/cctest/wasm/wasm-run-utils.h" | 10 #include "test/cctest/wasm/wasm-run-utils.h" |
11 #include "test/common/wasm/test-signatures.h" | 11 #include "test/common/wasm/test-signatures.h" |
12 | 12 |
13 using namespace v8::base; | 13 using namespace v8::base; |
14 using namespace v8::internal; | 14 using namespace v8::internal; |
15 using namespace v8::internal::compiler; | 15 using namespace v8::internal::compiler; |
16 using namespace v8::internal::wasm; | 16 using namespace v8::internal::wasm; |
17 | 17 |
18 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) { | 18 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) { |
19 FLAG_wasm_simd_prototype = true; | 19 FLAG_wasm_simd_prototype = true; |
20 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 20 WasmRunner<int32_t> r(kExecuteCompiled); |
21 BUILD(r, | 21 BUILD(r, |
22 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)))); | 22 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)))); |
23 FOR_INT32_INPUTS(i) { CHECK_EQ(5, r.Call()); } | 23 FOR_INT32_INPUTS(i) { CHECK_EQ(5, r.Call()); } |
24 } | 24 } |
25 | 25 |
26 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) { | 26 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) { |
27 FLAG_wasm_simd_prototype = true; | 27 FLAG_wasm_simd_prototype = true; |
28 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 28 WasmRunner<int32_t> r(kExecuteCompiled); |
29 BUILD(r, WASM_SIMD_I32x4_EXTRACT_LANE( | 29 BUILD(r, WASM_SIMD_I32x4_EXTRACT_LANE( |
30 0, WASM_SIMD_I32x4_ADD(WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)), | 30 0, WASM_SIMD_I32x4_ADD(WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)), |
31 WASM_SIMD_I32x4_SPLAT(WASM_I32V(6))))); | 31 WASM_SIMD_I32x4_SPLAT(WASM_I32V(6))))); |
32 FOR_INT32_INPUTS(i) { CHECK_EQ(11, r.Call()); } | 32 FOR_INT32_INPUTS(i) { CHECK_EQ(11, r.Call()); } |
33 } | 33 } |
34 | 34 |
35 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) { | 35 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) { |
36 FLAG_wasm_simd_prototype = true; | 36 FLAG_wasm_simd_prototype = true; |
37 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 37 WasmRunner<int32_t> r(kExecuteCompiled); |
38 BUILD(r, | 38 BUILD(r, |
39 WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( | 39 WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( |
40 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))), | 40 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))), |
41 WASM_F32(9.5)), | 41 WASM_F32(9.5)), |
42 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); | 42 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); |
43 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 43 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
44 } | 44 } |
45 | 45 |
46 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) { | 46 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) { |
47 FLAG_wasm_simd_prototype = true; | 47 FLAG_wasm_simd_prototype = true; |
48 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 48 WasmRunner<int32_t> r(kExecuteCompiled); |
49 BUILD(r, | 49 BUILD(r, |
50 WASM_IF_ELSE(WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 50 WASM_IF_ELSE(WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
51 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), | 51 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), |
52 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), | 52 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), |
53 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); | 53 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); |
54 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 54 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
55 } | 55 } |
56 | 56 |
57 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) { | 57 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) { |
58 FLAG_wasm_simd_prototype = true; | 58 FLAG_wasm_simd_prototype = true; |
59 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 59 WasmRunner<int32_t> r(kExecuteCompiled); |
60 BUILD(r, | 60 BUILD(r, |
61 WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( | 61 WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( |
62 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))), | 62 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))), |
63 WASM_F32_REINTERPRET_I32(WASM_I32V(15))), | 63 WASM_F32_REINTERPRET_I32(WASM_I32V(15))), |
64 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); | 64 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); |
65 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 65 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
66 } | 66 } |
67 | 67 |
68 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) { | 68 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) { |
69 FLAG_wasm_simd_prototype = true; | 69 FLAG_wasm_simd_prototype = true; |
70 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 70 WasmRunner<int32_t> r(kExecuteCompiled); |
71 BUILD(r, | 71 BUILD(r, |
72 WASM_IF_ELSE( | 72 WASM_IF_ELSE( |
73 WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( | 73 WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE( |
74 0, WASM_SIMD_F32x4_ADD( | 74 0, WASM_SIMD_F32x4_ADD( |
75 WASM_SIMD_I32x4_SPLAT(WASM_I32V(32)), | 75 WASM_SIMD_I32x4_SPLAT(WASM_I32V(32)), |
76 WASM_SIMD_I32x4_SPLAT(WASM_I32V(19)))), | 76 WASM_SIMD_I32x4_SPLAT(WASM_I32V(19)))), |
77 WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(32)), | 77 WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(32)), |
78 WASM_F32_REINTERPRET_I32(WASM_I32V(19)))), | 78 WASM_F32_REINTERPRET_I32(WASM_I32V(19)))), |
79 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); | 79 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); |
80 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 80 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
81 } | 81 } |
82 | 82 |
83 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) { | 83 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) { |
84 FLAG_wasm_simd_prototype = true; | 84 FLAG_wasm_simd_prototype = true; |
85 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 85 WasmRunner<int32_t> r(kExecuteCompiled); |
86 BUILD(r, | 86 BUILD(r, |
87 WASM_IF_ELSE( | 87 WASM_IF_ELSE( |
88 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 88 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
89 0, WASM_SIMD_I32x4_ADD( | 89 0, WASM_SIMD_I32x4_ADD( |
90 WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)), | 90 WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)), |
91 WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))), | 91 WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))), |
92 WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)), | 92 WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)), |
93 WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))), | 93 WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))), |
94 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); | 94 WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0)))); |
95 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 95 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
96 } | 96 } |
97 | 97 |
98 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) { | 98 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) { |
99 FLAG_wasm_simd_prototype = true; | 99 FLAG_wasm_simd_prototype = true; |
100 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 100 WasmRunner<int32_t> r(kExecuteCompiled); |
101 r.AllocateLocal(kAstS128); | 101 r.AllocateLocal(kAstS128); |
102 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), | 102 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), |
103 WASM_RETURN1( | 103 WASM_RETURN1( |
104 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1))))); | 104 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0))))); |
105 FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); } | 105 FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); } |
106 } | 106 } |
107 | 107 |
108 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) { | 108 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) { |
109 FLAG_wasm_simd_prototype = true; | 109 FLAG_wasm_simd_prototype = true; |
110 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 110 WasmRunner<int32_t> r(kExecuteCompiled); |
111 r.AllocateLocal(kAstS128); | 111 r.AllocateLocal(kAstS128); |
112 BUILD(r, | 112 BUILD(r, |
113 WASM_BLOCK( | 113 WASM_BLOCK( |
114 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), | 114 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), |
115 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1), | 115 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0), |
116 WASM_I32V(53))), | 116 WASM_I32V(53))), |
117 WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1))))); | 117 WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0))))); |
118 FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); } | 118 FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); } |
119 } | 119 } |
120 | 120 |
121 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) { | 121 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) { |
122 FLAG_wasm_simd_prototype = true; | 122 FLAG_wasm_simd_prototype = true; |
123 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 123 WasmRunner<int32_t> r(kExecuteCompiled); |
124 r.AllocateLocal(kAstF32); | 124 r.AllocateLocal(kAstF32); |
125 r.AllocateLocal(kAstS128); | 125 r.AllocateLocal(kAstS128); |
126 BUILD(r, WASM_BLOCK( | 126 BUILD(r, WASM_BLOCK( |
127 WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))), | 127 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))), |
128 WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE( | 128 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE( |
129 3, WASM_GET_LOCAL(2), WASM_F32(65.25))), | 129 3, WASM_GET_LOCAL(1), WASM_F32(65.25))), |
130 WASM_SET_LOCAL( | 130 WASM_SET_LOCAL( |
131 1, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2))), | 131 0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))), |
132 WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(1), WASM_F32(65.25)), | 132 WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)), |
133 WASM_RETURN1(WASM_I32V(1))), | 133 WASM_RETURN1(WASM_I32V(1))), |
134 WASM_RETURN1(WASM_I32V(0)))); | 134 WASM_RETURN1(WASM_I32V(0)))); |
135 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 135 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
136 } | 136 } |
137 | 137 |
138 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) { | 138 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) { |
139 FLAG_wasm_simd_prototype = true; | 139 FLAG_wasm_simd_prototype = true; |
140 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 140 WasmRunner<int32_t> r(kExecuteCompiled); |
141 r.AllocateLocal(kAstI32); | 141 r.AllocateLocal(kAstI32); |
142 r.AllocateLocal(kAstS128); | 142 r.AllocateLocal(kAstS128); |
143 BUILD(r, | 143 BUILD(r, |
144 WASM_BLOCK( | 144 WASM_BLOCK( |
145 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_EXTRACT_LANE( | 145 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE( |
146 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))), | 146 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))), |
147 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(1))), | 147 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))), |
148 WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2))))); | 148 WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1))))); |
149 FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); } | 149 FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); } |
150 } | 150 } |
151 | 151 |
152 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) { | 152 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) { |
153 FLAG_wasm_simd_prototype = true; | 153 FLAG_wasm_simd_prototype = true; |
154 TestingModule module(kExecuteCompiled); | 154 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
155 int32_t* global = module.AddGlobal<int32_t>(kAstS128); | 155 int32_t* global = r.module().AddGlobal<int32_t>(kAstS128); |
156 *(global) = 0; | 156 *(global) = 0; |
157 *(global + 1) = 1; | 157 *(global + 1) = 1; |
158 *(global + 2) = 2; | 158 *(global + 2) = 2; |
159 *(global + 3) = 3; | 159 *(global + 3) = 3; |
160 WasmRunner<int32_t> r(&module, MachineType::Int32()); | |
161 r.AllocateLocal(kAstI32); | 160 r.AllocateLocal(kAstI32); |
162 BUILD(r, WASM_BLOCK( | 161 BUILD(r, WASM_BLOCK( |
163 WASM_SET_LOCAL(1, WASM_I32V(1)), | 162 WASM_SET_LOCAL(1, WASM_I32V(1)), |
164 WASM_IF(WASM_I32_NE(WASM_I32V(0), WASM_SIMD_I32x4_EXTRACT_LANE( | 163 WASM_IF(WASM_I32_NE(WASM_I32V(0), WASM_SIMD_I32x4_EXTRACT_LANE( |
165 0, WASM_GET_GLOBAL(0))), | 164 0, WASM_GET_GLOBAL(0))), |
166 WASM_SET_LOCAL(1, WASM_I32V(0))), | 165 WASM_SET_LOCAL(1, WASM_I32V(0))), |
167 WASM_IF(WASM_I32_NE(WASM_I32V(1), WASM_SIMD_I32x4_EXTRACT_LANE( | 166 WASM_IF(WASM_I32_NE(WASM_I32V(1), WASM_SIMD_I32x4_EXTRACT_LANE( |
168 1, WASM_GET_GLOBAL(0))), | 167 1, WASM_GET_GLOBAL(0))), |
169 WASM_SET_LOCAL(1, WASM_I32V(0))), | 168 WASM_SET_LOCAL(1, WASM_I32V(0))), |
170 WASM_IF(WASM_I32_NE(WASM_I32V(2), WASM_SIMD_I32x4_EXTRACT_LANE( | 169 WASM_IF(WASM_I32_NE(WASM_I32V(2), WASM_SIMD_I32x4_EXTRACT_LANE( |
171 2, WASM_GET_GLOBAL(0))), | 170 2, WASM_GET_GLOBAL(0))), |
172 WASM_SET_LOCAL(1, WASM_I32V(0))), | 171 WASM_SET_LOCAL(1, WASM_I32V(0))), |
173 WASM_IF(WASM_I32_NE(WASM_I32V(3), WASM_SIMD_I32x4_EXTRACT_LANE( | 172 WASM_IF(WASM_I32_NE(WASM_I32V(3), WASM_SIMD_I32x4_EXTRACT_LANE( |
174 3, WASM_GET_GLOBAL(0))), | 173 3, WASM_GET_GLOBAL(0))), |
175 WASM_SET_LOCAL(1, WASM_I32V(0))), | 174 WASM_SET_LOCAL(1, WASM_I32V(0))), |
176 WASM_RETURN1(WASM_GET_LOCAL(1)))); | 175 WASM_RETURN1(WASM_GET_LOCAL(1)))); |
177 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 176 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
178 } | 177 } |
179 | 178 |
180 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) { | 179 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) { |
181 FLAG_wasm_simd_prototype = true; | 180 FLAG_wasm_simd_prototype = true; |
182 TestingModule module(kExecuteCompiled); | 181 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
183 int32_t* global = module.AddGlobal<int32_t>(kAstS128); | 182 int32_t* global = r.module().AddGlobal<int32_t>(kAstS128); |
184 WasmRunner<int32_t> r(&module, MachineType::Int32()); | |
185 BUILD(r, WASM_BLOCK( | 183 BUILD(r, WASM_BLOCK( |
186 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), | 184 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), |
187 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( | 185 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( |
188 1, WASM_GET_GLOBAL(0), WASM_I32V(34))), | 186 1, WASM_GET_GLOBAL(0), WASM_I32V(34))), |
189 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( | 187 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( |
190 2, WASM_GET_GLOBAL(0), WASM_I32V(45))), | 188 2, WASM_GET_GLOBAL(0), WASM_I32V(45))), |
191 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( | 189 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE( |
192 3, WASM_GET_GLOBAL(0), WASM_I32V(56))), | 190 3, WASM_GET_GLOBAL(0), WASM_I32V(56))), |
193 WASM_RETURN1(WASM_I32V(1)))); | 191 WASM_RETURN1(WASM_I32V(1)))); |
194 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 192 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
195 CHECK_EQ(*global, 23); | 193 CHECK_EQ(*global, 23); |
196 CHECK_EQ(*(global + 1), 34); | 194 CHECK_EQ(*(global + 1), 34); |
197 CHECK_EQ(*(global + 2), 45); | 195 CHECK_EQ(*(global + 2), 45); |
198 CHECK_EQ(*(global + 3), 56); | 196 CHECK_EQ(*(global + 3), 56); |
199 } | 197 } |
200 | 198 |
201 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) { | 199 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) { |
202 FLAG_wasm_simd_prototype = true; | 200 FLAG_wasm_simd_prototype = true; |
203 TestingModule module(kExecuteCompiled); | 201 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
204 float* global = module.AddGlobal<float>(kAstS128); | 202 float* global = r.module().AddGlobal<float>(kAstS128); |
205 *(global) = 0.0; | 203 *(global) = 0.0; |
206 *(global + 1) = 1.5; | 204 *(global + 1) = 1.5; |
207 *(global + 2) = 2.25; | 205 *(global + 2) = 2.25; |
208 *(global + 3) = 3.5; | 206 *(global + 3) = 3.5; |
209 WasmRunner<int32_t> r(&module, MachineType::Int32()); | |
210 r.AllocateLocal(kAstI32); | 207 r.AllocateLocal(kAstI32); |
211 BUILD(r, WASM_BLOCK( | 208 BUILD(r, WASM_BLOCK( |
212 WASM_SET_LOCAL(1, WASM_I32V(1)), | 209 WASM_SET_LOCAL(1, WASM_I32V(1)), |
213 WASM_IF(WASM_F32_NE(WASM_F32(0.0), WASM_SIMD_F32x4_EXTRACT_LANE( | 210 WASM_IF(WASM_F32_NE(WASM_F32(0.0), WASM_SIMD_F32x4_EXTRACT_LANE( |
214 0, WASM_GET_GLOBAL(0))), | 211 0, WASM_GET_GLOBAL(0))), |
215 WASM_SET_LOCAL(1, WASM_I32V(0))), | 212 WASM_SET_LOCAL(1, WASM_I32V(0))), |
216 WASM_IF(WASM_F32_NE(WASM_F32(1.5), WASM_SIMD_F32x4_EXTRACT_LANE( | 213 WASM_IF(WASM_F32_NE(WASM_F32(1.5), WASM_SIMD_F32x4_EXTRACT_LANE( |
217 1, WASM_GET_GLOBAL(0))), | 214 1, WASM_GET_GLOBAL(0))), |
218 WASM_SET_LOCAL(1, WASM_I32V(0))), | 215 WASM_SET_LOCAL(1, WASM_I32V(0))), |
219 WASM_IF(WASM_F32_NE(WASM_F32(2.25), WASM_SIMD_F32x4_EXTRACT_LANE( | 216 WASM_IF(WASM_F32_NE(WASM_F32(2.25), WASM_SIMD_F32x4_EXTRACT_LANE( |
220 2, WASM_GET_GLOBAL(0))), | 217 2, WASM_GET_GLOBAL(0))), |
221 WASM_SET_LOCAL(1, WASM_I32V(0))), | 218 WASM_SET_LOCAL(1, WASM_I32V(0))), |
222 WASM_IF(WASM_F32_NE(WASM_F32(3.5), WASM_SIMD_F32x4_EXTRACT_LANE( | 219 WASM_IF(WASM_F32_NE(WASM_F32(3.5), WASM_SIMD_F32x4_EXTRACT_LANE( |
223 3, WASM_GET_GLOBAL(0))), | 220 3, WASM_GET_GLOBAL(0))), |
224 WASM_SET_LOCAL(1, WASM_I32V(0))), | 221 WASM_SET_LOCAL(1, WASM_I32V(0))), |
225 WASM_RETURN1(WASM_GET_LOCAL(1)))); | 222 WASM_RETURN1(WASM_GET_LOCAL(1)))); |
226 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 223 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
227 } | 224 } |
228 | 225 |
229 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) { | 226 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) { |
230 FLAG_wasm_simd_prototype = true; | 227 FLAG_wasm_simd_prototype = true; |
231 TestingModule module(kExecuteCompiled); | 228 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
232 float* global = module.AddGlobal<float>(kAstS128); | 229 float* global = r.module().AddGlobal<float>(kAstS128); |
233 WasmRunner<int32_t> r(&module, MachineType::Int32()); | |
234 BUILD(r, WASM_BLOCK( | 230 BUILD(r, WASM_BLOCK( |
235 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), | 231 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), |
236 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( | 232 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( |
237 1, WASM_GET_GLOBAL(0), WASM_F32(45.5))), | 233 1, WASM_GET_GLOBAL(0), WASM_F32(45.5))), |
238 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( | 234 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( |
239 2, WASM_GET_GLOBAL(0), WASM_F32(32.25))), | 235 2, WASM_GET_GLOBAL(0), WASM_F32(32.25))), |
240 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( | 236 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE( |
241 3, WASM_GET_GLOBAL(0), WASM_F32(65.0))), | 237 3, WASM_GET_GLOBAL(0), WASM_F32(65.0))), |
242 WASM_RETURN1(WASM_I32V(1)))); | 238 WASM_RETURN1(WASM_I32V(1)))); |
243 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 239 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
244 CHECK_EQ(*global, 13.5); | 240 CHECK_EQ(*global, 13.5); |
245 CHECK_EQ(*(global + 1), 45.5); | 241 CHECK_EQ(*(global + 1), 45.5); |
246 CHECK_EQ(*(global + 2), 32.25); | 242 CHECK_EQ(*(global + 2), 32.25); |
247 CHECK_EQ(*(global + 3), 65.0); | 243 CHECK_EQ(*(global + 3), 65.0); |
248 } | 244 } |
249 | 245 |
250 WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) { | 246 WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) { |
251 FLAG_wasm_simd_prototype = true; | 247 FLAG_wasm_simd_prototype = true; |
252 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 248 WasmRunner<int32_t> r(kExecuteCompiled); |
253 r.AllocateLocal(kAstI32); | 249 r.AllocateLocal(kAstI32); |
254 r.AllocateLocal(kAstS128); | 250 r.AllocateLocal(kAstS128); |
255 BUILD( | 251 BUILD( |
256 r, | 252 r, |
257 WASM_BLOCK( | 253 WASM_BLOCK( |
258 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), | 254 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))), |
259 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(2), | 255 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1), |
260 WASM_I32V(53))), | 256 WASM_I32V(53))), |
261 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(2), | 257 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1), |
262 WASM_I32V(23))), | 258 WASM_I32V(23))), |
263 WASM_SET_LOCAL(1, WASM_I32V(0)), | 259 WASM_SET_LOCAL(0, WASM_I32V(0)), |
264 WASM_LOOP(WASM_SET_LOCAL(2, WASM_SIMD_I32x4_ADD( | 260 WASM_LOOP(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_ADD( |
265 WASM_GET_LOCAL(2), | 261 WASM_GET_LOCAL(1), |
266 WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))), | 262 WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))), |
267 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(5)), | 263 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)), |
268 WASM_BR(1))), | 264 WASM_BR(1))), |
269 WASM_SET_LOCAL(1, WASM_I32V(1)), | 265 WASM_SET_LOCAL(0, WASM_I32V(1)), |
270 WASM_IF( | 266 WASM_IF( |
271 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)), | 267 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)), |
272 WASM_I32V(36)), | 268 WASM_I32V(36)), |
273 WASM_SET_LOCAL(1, WASM_I32V(0))), | 269 WASM_SET_LOCAL(0, WASM_I32V(0))), |
274 WASM_IF( | 270 WASM_IF( |
275 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2)), | 271 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)), |
276 WASM_I32V(58)), | 272 WASM_I32V(58)), |
277 WASM_SET_LOCAL(1, WASM_I32V(0))), | 273 WASM_SET_LOCAL(0, WASM_I32V(0))), |
278 WASM_IF( | 274 WASM_IF( |
279 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(2)), | 275 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)), |
280 WASM_I32V(28)), | 276 WASM_I32V(28)), |
281 WASM_SET_LOCAL(1, WASM_I32V(0))), | 277 WASM_SET_LOCAL(0, WASM_I32V(0))), |
282 WASM_IF( | 278 WASM_IF( |
283 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)), | 279 WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)), |
284 WASM_I32V(36)), | 280 WASM_I32V(36)), |
285 WASM_SET_LOCAL(1, WASM_I32V(0))), | 281 WASM_SET_LOCAL(0, WASM_I32V(0))), |
286 WASM_RETURN1(WASM_GET_LOCAL(1)))); | 282 WASM_RETURN1(WASM_GET_LOCAL(0)))); |
287 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 283 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
288 } | 284 } |
289 | 285 |
290 WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) { | 286 WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) { |
291 FLAG_wasm_simd_prototype = true; | 287 FLAG_wasm_simd_prototype = true; |
292 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 288 WasmRunner<int32_t> r(kExecuteCompiled); |
293 r.AllocateLocal(kAstI32); | 289 r.AllocateLocal(kAstI32); |
294 r.AllocateLocal(kAstS128); | 290 r.AllocateLocal(kAstS128); |
295 BUILD(r, WASM_BLOCK( | 291 BUILD(r, WASM_BLOCK( |
296 WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))), | 292 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))), |
297 WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE( | 293 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE( |
298 3, WASM_GET_LOCAL(2), WASM_F32(19.5))), | 294 3, WASM_GET_LOCAL(1), WASM_F32(19.5))), |
299 WASM_SET_LOCAL(1, WASM_I32V(0)), | 295 WASM_SET_LOCAL(0, WASM_I32V(0)), |
300 WASM_LOOP( | 296 WASM_LOOP( |
301 WASM_SET_LOCAL(2, WASM_SIMD_F32x4_ADD( | 297 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_ADD( |
302 WASM_GET_LOCAL(2), | 298 WASM_GET_LOCAL(1), |
303 WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))), | 299 WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))), |
304 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(3)), | 300 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)), |
305 WASM_BR(1))), | 301 WASM_BR(1))), |
306 WASM_SET_LOCAL(1, WASM_I32V(1)), | 302 WASM_SET_LOCAL(0, WASM_I32V(1)), |
307 WASM_IF(WASM_F32_NE( | 303 WASM_IF(WASM_F32_NE( |
308 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)), | 304 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)), |
309 WASM_F32(27.25)), | 305 WASM_F32(27.25)), |
310 WASM_SET_LOCAL(1, WASM_I32V(0))), | 306 WASM_SET_LOCAL(0, WASM_I32V(0))), |
311 WASM_IF(WASM_F32_NE( | 307 WASM_IF(WASM_F32_NE( |
312 WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)), | 308 WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)), |
313 WASM_F32(25.5)), | 309 WASM_F32(25.5)), |
314 WASM_SET_LOCAL(1, WASM_I32V(0))), | 310 WASM_SET_LOCAL(0, WASM_I32V(0))), |
315 WASM_RETURN1(WASM_GET_LOCAL(1)))); | 311 WASM_RETURN1(WASM_GET_LOCAL(0)))); |
316 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } | 312 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); } |
317 } | 313 } |
OLD | NEW |