| 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 "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
| 7 #include "test/cctest/compiler/value-helper.h" | 7 #include "test/cctest/compiler/value-helper.h" |
| 8 #include "test/cctest/wasm/wasm-run-utils.h" | 8 #include "test/cctest/wasm/wasm-run-utils.h" |
| 9 #include "test/common/wasm/wasm-macro-gen.h" | 9 #include "test/common/wasm/wasm-macro-gen.h" |
| 10 | 10 |
| (...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); } | 1957 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); } |
| 1958 | 1958 |
| 1959 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); } | 1959 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); } |
| 1960 | 1960 |
| 1961 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); } | 1961 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); } |
| 1962 | 1962 |
| 1963 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); } | 1963 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); } |
| 1964 #endif // !V8_TARGET_ARCH_ARM | 1964 #endif // !V8_TARGET_ARCH_ARM |
| 1965 | 1965 |
| 1966 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 1966 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
| 1967 |
| 1968 template <typename T, int numLanes = 4> |
| 1969 void SetVectorByLanes(T* v, const std::array<T, numLanes>& arr) { |
| 1970 for (int lane = 0; lane < numLanes; lane++) { |
| 1971 const T& value = arr[lane]; |
| 1972 #if defined(V8_TARGET_BIG_ENDIAN) |
| 1973 v[numLanes - 1 - lane] = value; |
| 1974 #else |
| 1975 v[lane] = value; |
| 1976 #endif |
| 1977 } |
| 1978 } |
| 1979 |
| 1980 template <typename T> |
| 1981 const T& GetScalar(T* v, int lane) { |
| 1982 constexpr int kElems = kSimd128Size / sizeof(T); |
| 1983 #if defined(V8_TARGET_BIG_ENDIAN) |
| 1984 const int index = kElems - 1 - lane; |
| 1985 #else |
| 1986 const int index = lane; |
| 1987 #endif |
| 1988 USE(kElems); |
| 1989 DCHECK(index >= 0 && index < kElems); |
| 1990 return v[index]; |
| 1991 } |
| 1992 |
| 1967 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { | 1993 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { |
| 1968 FLAG_wasm_simd_prototype = true; | 1994 FLAG_wasm_simd_prototype = true; |
| 1969 WasmRunner<int32_t> r(kExecuteCompiled); | 1995 WasmRunner<int32_t> r(kExecuteCompiled); |
| 1970 BUILD(r, WASM_IF_ELSE_I( | 1996 BUILD(r, WASM_IF_ELSE_I( |
| 1971 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 1997 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
| 1972 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), | 1998 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), |
| 1973 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), | 1999 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), |
| 1974 WASM_I32V(1), WASM_I32V(0))); | 2000 WASM_I32V(1), WASM_I32V(0))); |
| 1975 CHECK_EQ(1, r.Call()); | 2001 CHECK_EQ(1, r.Call()); |
| 1976 } | 2002 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 WASM_F32(25.5)), | 2127 WASM_F32(25.5)), |
| 2102 WASM_SET_LOCAL(0, WASM_I32V(0))), | 2128 WASM_SET_LOCAL(0, WASM_I32V(0))), |
| 2103 WASM_GET_LOCAL(0)); | 2129 WASM_GET_LOCAL(0)); |
| 2104 CHECK_EQ(1, r.Call()); | 2130 CHECK_EQ(1, r.Call()); |
| 2105 } | 2131 } |
| 2106 | 2132 |
| 2107 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) { | 2133 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) { |
| 2108 FLAG_wasm_simd_prototype = true; | 2134 FLAG_wasm_simd_prototype = true; |
| 2109 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 2135 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
| 2110 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); | 2136 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); |
| 2111 *(global) = 0; | 2137 SetVectorByLanes(global, {{0, 1, 2, 3}}); |
| 2112 *(global + 1) = 1; | |
| 2113 *(global + 2) = 2; | |
| 2114 *(global + 3) = 3; | |
| 2115 r.AllocateLocal(kWasmI32); | 2138 r.AllocateLocal(kWasmI32); |
| 2116 BUILD( | 2139 BUILD( |
| 2117 r, WASM_SET_LOCAL(1, WASM_I32V(1)), | 2140 r, WASM_SET_LOCAL(1, WASM_I32V(1)), |
| 2118 WASM_IF(WASM_I32_NE(WASM_I32V(0), | 2141 WASM_IF(WASM_I32_NE(WASM_I32V(0), |
| 2119 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), | 2142 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), |
| 2120 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2143 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2121 WASM_IF(WASM_I32_NE(WASM_I32V(1), | 2144 WASM_IF(WASM_I32_NE(WASM_I32V(1), |
| 2122 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), | 2145 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), |
| 2123 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2146 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2124 WASM_IF(WASM_I32_NE(WASM_I32V(2), | 2147 WASM_IF(WASM_I32_NE(WASM_I32V(2), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2137 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); | 2160 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); |
| 2138 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), | 2161 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), |
| 2139 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), | 2162 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), |
| 2140 WASM_I32V(34))), | 2163 WASM_I32V(34))), |
| 2141 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), | 2164 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), |
| 2142 WASM_I32V(45))), | 2165 WASM_I32V(45))), |
| 2143 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 2166 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
| 2144 WASM_I32V(56))), | 2167 WASM_I32V(56))), |
| 2145 WASM_I32V(1)); | 2168 WASM_I32V(1)); |
| 2146 CHECK_EQ(1, r.Call(0)); | 2169 CHECK_EQ(1, r.Call(0)); |
| 2147 CHECK_EQ(*global, 23); | 2170 CHECK_EQ(GetScalar(global, 0), 23); |
| 2148 CHECK_EQ(*(global + 1), 34); | 2171 CHECK_EQ(GetScalar(global, 1), 34); |
| 2149 CHECK_EQ(*(global + 2), 45); | 2172 CHECK_EQ(GetScalar(global, 2), 45); |
| 2150 CHECK_EQ(*(global + 3), 56); | 2173 CHECK_EQ(GetScalar(global, 3), 56); |
| 2151 } | 2174 } |
| 2152 | 2175 |
| 2153 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) { | 2176 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) { |
| 2154 FLAG_wasm_simd_prototype = true; | 2177 FLAG_wasm_simd_prototype = true; |
| 2155 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 2178 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
| 2156 float* global = r.module().AddGlobal<float>(kWasmS128); | 2179 float* global = r.module().AddGlobal<float>(kWasmS128); |
| 2157 *(global) = 0.0; | 2180 SetVectorByLanes<float>(global, {{0.0, 1.5, 2.25, 3.5}}); |
| 2158 *(global + 1) = 1.5; | |
| 2159 *(global + 2) = 2.25; | |
| 2160 *(global + 3) = 3.5; | |
| 2161 r.AllocateLocal(kWasmI32); | 2181 r.AllocateLocal(kWasmI32); |
| 2162 BUILD( | 2182 BUILD( |
| 2163 r, WASM_SET_LOCAL(1, WASM_I32V(1)), | 2183 r, WASM_SET_LOCAL(1, WASM_I32V(1)), |
| 2164 WASM_IF(WASM_F32_NE(WASM_F32(0.0), | 2184 WASM_IF(WASM_F32_NE(WASM_F32(0.0), |
| 2165 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), | 2185 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), |
| 2166 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2186 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2167 WASM_IF(WASM_F32_NE(WASM_F32(1.5), | 2187 WASM_IF(WASM_F32_NE(WASM_F32(1.5), |
| 2168 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), | 2188 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), |
| 2169 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2189 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2170 WASM_IF(WASM_F32_NE(WASM_F32(2.25), | 2190 WASM_IF(WASM_F32_NE(WASM_F32(2.25), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2183 float* global = r.module().AddGlobal<float>(kWasmS128); | 2203 float* global = r.module().AddGlobal<float>(kWasmS128); |
| 2184 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), | 2204 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), |
| 2185 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), | 2205 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), |
| 2186 WASM_F32(45.5))), | 2206 WASM_F32(45.5))), |
| 2187 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), | 2207 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), |
| 2188 WASM_F32(32.25))), | 2208 WASM_F32(32.25))), |
| 2189 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 2209 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
| 2190 WASM_F32(65.0))), | 2210 WASM_F32(65.0))), |
| 2191 WASM_I32V(1)); | 2211 WASM_I32V(1)); |
| 2192 CHECK_EQ(1, r.Call(0)); | 2212 CHECK_EQ(1, r.Call(0)); |
| 2193 CHECK_EQ(*global, 13.5); | 2213 CHECK_EQ(GetScalar(global, 0), 13.5f); |
| 2194 CHECK_EQ(*(global + 1), 45.5); | 2214 CHECK_EQ(GetScalar(global, 1), 45.5f); |
| 2195 CHECK_EQ(*(global + 2), 32.25); | 2215 CHECK_EQ(GetScalar(global, 2), 32.25f); |
| 2196 CHECK_EQ(*(global + 3), 65.0); | 2216 CHECK_EQ(GetScalar(global, 3), 65.0f); |
| 2197 } | 2217 } |
| 2198 | 2218 |
| 2199 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) { | 2219 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) { |
| 2200 FLAG_wasm_simd_prototype = true; | 2220 FLAG_wasm_simd_prototype = true; |
| 2201 WasmRunner<int32_t> r(kExecuteCompiled); | 2221 WasmRunner<int32_t> r(kExecuteCompiled); |
| 2202 int32_t* memory = r.module().AddMemoryElems<int32_t>(4); | 2222 int32_t* memory = r.module().AddMemoryElems<int32_t>(4); |
| 2203 | 2223 |
| 2204 BUILD(r, | 2224 BUILD(r, |
| 2205 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO, | 2225 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO, |
| 2206 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)), | 2226 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)), |
| 2207 WASM_SIMD_I32x4_EXTRACT_LANE( | 2227 WASM_SIMD_I32x4_EXTRACT_LANE( |
| 2208 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); | 2228 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); |
| 2209 | 2229 |
| 2210 FOR_INT32_INPUTS(i) { | 2230 FOR_INT32_INPUTS(i) { |
| 2211 int32_t expected = *i; | 2231 int32_t expected = *i; |
| 2212 r.module().WriteMemory(&memory[0], expected); | 2232 r.module().WriteMemory(&memory[0], expected); |
| 2213 CHECK_EQ(expected, r.Call()); | 2233 CHECK_EQ(expected, r.Call()); |
| 2214 } | 2234 } |
| 2215 } | 2235 } |
| 2216 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 2236 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
| OLD | NEW |