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 "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 maxLanes = 4> | |
| 1969 void SetVectorByLanes(T* v, ...) { | |
| 1970 va_list vl; | |
| 1971 va_start(vl, v); | |
| 1972 #if defined(V8_TARGET_BIG_ENDIAN) | |
| 1973 for (int lane = maxLanes - 1; lane >= 0; lane--) { | |
| 1974 v[lane] = static_cast<T>(va_arg(vl, T)); | |
| 1975 } | |
| 1976 #else | |
| 1977 for (int lane = 0; lane < maxLanes; lane++) { | |
| 1978 v[lane] = static_cast<T>(va_arg(vl, T)); | |
| 1979 } | |
| 1980 #endif | |
| 1981 va_end(vl); | |
| 1982 } | |
| 1983 | |
| 1984 // has to specialize float to get rid of error | |
| 1985 template <> | |
| 1986 void SetVectorByLanes<float>(float* v, ...) { | |
| 1987 va_list vl; | |
| 1988 va_start(vl, v); | |
| 1989 const int maxLanes = 4; | |
| 1990 #if defined(V8_TARGET_BIG_ENDIAN) | |
| 1991 for (int lane = maxLanes - 1; lane >= 0; lane--) { | |
| 1992 v[lane] = static_cast<float>(va_arg(vl, double)); | |
| 1993 } | |
| 1994 #else | |
| 1995 for (int lane = 0; lane < maxLanes; lane++) { | |
| 1996 v[lane] = static_cast<float>(va_arg(vl, double)); | |
| 1997 } | |
| 1998 #endif | |
| 1999 va_end(vl); | |
| 2000 } | |
| 2001 | |
| 2002 template <int vSize = 16, typename T> | |
| 2003 T GetScalarByLanes(T* v, int lane) { | |
| 2004 #if defined(V8_TARGET_BIG_ENDIAN) | |
| 2005 const int kElems = vSize / sizeof(T); | |
|
Clemens Hammacher
2017/04/28 09:45:48
You can make this (and the others) constexpr, move
| |
| 2006 const int index = kElems - 1 - lane; | |
| 2007 #else | |
| 2008 const int index = lane; | |
| 2009 #endif | |
| 2010 DCHECK(index >= 0 && index < static_cast<int>(vSize / sizeof(T))); | |
| 2011 return v[index]; | |
| 2012 } | |
| 2013 | |
| 1967 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { | 2014 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { |
| 1968 FLAG_wasm_simd_prototype = true; | 2015 FLAG_wasm_simd_prototype = true; |
| 1969 WasmRunner<int32_t> r(kExecuteCompiled); | 2016 WasmRunner<int32_t> r(kExecuteCompiled); |
| 1970 BUILD(r, WASM_IF_ELSE_I( | 2017 BUILD(r, WASM_IF_ELSE_I( |
| 1971 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( | 2018 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( |
| 1972 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), | 2019 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), |
| 1973 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), | 2020 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), |
| 1974 WASM_I32V(1), WASM_I32V(0))); | 2021 WASM_I32V(1), WASM_I32V(0))); |
| 1975 CHECK_EQ(1, r.Call()); | 2022 CHECK_EQ(1, r.Call()); |
| 1976 } | 2023 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2101 WASM_F32(25.5)), | 2148 WASM_F32(25.5)), |
| 2102 WASM_SET_LOCAL(0, WASM_I32V(0))), | 2149 WASM_SET_LOCAL(0, WASM_I32V(0))), |
| 2103 WASM_GET_LOCAL(0)); | 2150 WASM_GET_LOCAL(0)); |
| 2104 CHECK_EQ(1, r.Call()); | 2151 CHECK_EQ(1, r.Call()); |
| 2105 } | 2152 } |
| 2106 | 2153 |
| 2107 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) { | 2154 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) { |
| 2108 FLAG_wasm_simd_prototype = true; | 2155 FLAG_wasm_simd_prototype = true; |
| 2109 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 2156 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
| 2110 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); | 2157 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); |
| 2111 *(global) = 0; | 2158 SetVectorByLanes(global, 0, 1, 2, 3); |
| 2112 *(global + 1) = 1; | |
| 2113 *(global + 2) = 2; | |
| 2114 *(global + 3) = 3; | |
| 2115 r.AllocateLocal(kWasmI32); | 2159 r.AllocateLocal(kWasmI32); |
| 2116 BUILD( | 2160 BUILD( |
| 2117 r, WASM_SET_LOCAL(1, WASM_I32V(1)), | 2161 r, WASM_SET_LOCAL(1, WASM_I32V(1)), |
| 2118 WASM_IF(WASM_I32_NE(WASM_I32V(0), | 2162 WASM_IF(WASM_I32_NE(WASM_I32V(0), |
| 2119 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), | 2163 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), |
| 2120 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2164 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2121 WASM_IF(WASM_I32_NE(WASM_I32V(1), | 2165 WASM_IF(WASM_I32_NE(WASM_I32V(1), |
| 2122 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), | 2166 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), |
| 2123 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2167 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2124 WASM_IF(WASM_I32_NE(WASM_I32V(2), | 2168 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); | 2181 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); |
| 2138 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), | 2182 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), | 2183 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), |
| 2140 WASM_I32V(34))), | 2184 WASM_I32V(34))), |
| 2141 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), | 2185 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), |
| 2142 WASM_I32V(45))), | 2186 WASM_I32V(45))), |
| 2143 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 2187 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
| 2144 WASM_I32V(56))), | 2188 WASM_I32V(56))), |
| 2145 WASM_I32V(1)); | 2189 WASM_I32V(1)); |
| 2146 CHECK_EQ(1, r.Call(0)); | 2190 CHECK_EQ(1, r.Call(0)); |
| 2147 CHECK_EQ(*global, 23); | 2191 CHECK_EQ(GetScalarByLanes(global, 0), 23); |
| 2148 CHECK_EQ(*(global + 1), 34); | 2192 CHECK_EQ(GetScalarByLanes(global, 1), 34); |
| 2149 CHECK_EQ(*(global + 2), 45); | 2193 CHECK_EQ(GetScalarByLanes(global, 2), 45); |
| 2150 CHECK_EQ(*(global + 3), 56); | 2194 CHECK_EQ(GetScalarByLanes(global, 3), 56); |
| 2151 } | 2195 } |
| 2152 | 2196 |
| 2153 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) { | 2197 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) { |
| 2154 FLAG_wasm_simd_prototype = true; | 2198 FLAG_wasm_simd_prototype = true; |
| 2155 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 2199 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
| 2156 float* global = r.module().AddGlobal<float>(kWasmS128); | 2200 float* global = r.module().AddGlobal<float>(kWasmS128); |
| 2157 *(global) = 0.0; | 2201 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); | 2202 r.AllocateLocal(kWasmI32); |
| 2162 BUILD( | 2203 BUILD( |
| 2163 r, WASM_SET_LOCAL(1, WASM_I32V(1)), | 2204 r, WASM_SET_LOCAL(1, WASM_I32V(1)), |
| 2164 WASM_IF(WASM_F32_NE(WASM_F32(0.0), | 2205 WASM_IF(WASM_F32_NE(WASM_F32(0.0), |
| 2165 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), | 2206 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), |
| 2166 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2207 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2167 WASM_IF(WASM_F32_NE(WASM_F32(1.5), | 2208 WASM_IF(WASM_F32_NE(WASM_F32(1.5), |
| 2168 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), | 2209 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), |
| 2169 WASM_SET_LOCAL(1, WASM_I32V(0))), | 2210 WASM_SET_LOCAL(1, WASM_I32V(0))), |
| 2170 WASM_IF(WASM_F32_NE(WASM_F32(2.25), | 2211 WASM_IF(WASM_F32_NE(WASM_F32(2.25), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2183 float* global = r.module().AddGlobal<float>(kWasmS128); | 2224 float* global = r.module().AddGlobal<float>(kWasmS128); |
| 2184 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), | 2225 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), | 2226 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), |
| 2186 WASM_F32(45.5))), | 2227 WASM_F32(45.5))), |
| 2187 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), | 2228 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), |
| 2188 WASM_F32(32.25))), | 2229 WASM_F32(32.25))), |
| 2189 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 2230 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
| 2190 WASM_F32(65.0))), | 2231 WASM_F32(65.0))), |
| 2191 WASM_I32V(1)); | 2232 WASM_I32V(1)); |
| 2192 CHECK_EQ(1, r.Call(0)); | 2233 CHECK_EQ(1, r.Call(0)); |
| 2193 CHECK_EQ(*global, 13.5); | 2234 CHECK_EQ(GetScalarByLanes(global, 0), 13.5f); |
| 2194 CHECK_EQ(*(global + 1), 45.5); | 2235 CHECK_EQ(GetScalarByLanes(global, 1), 45.5f); |
| 2195 CHECK_EQ(*(global + 2), 32.25); | 2236 CHECK_EQ(GetScalarByLanes(global, 2), 32.25f); |
| 2196 CHECK_EQ(*(global + 3), 65.0); | 2237 CHECK_EQ(GetScalarByLanes(global, 3), 65.0f); |
| 2197 } | 2238 } |
| 2198 | 2239 |
| 2199 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) { | 2240 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) { |
| 2200 FLAG_wasm_simd_prototype = true; | 2241 FLAG_wasm_simd_prototype = true; |
| 2201 WasmRunner<int32_t> r(kExecuteCompiled); | 2242 WasmRunner<int32_t> r(kExecuteCompiled); |
| 2202 int32_t* memory = r.module().AddMemoryElems<int32_t>(4); | 2243 int32_t* memory = r.module().AddMemoryElems<int32_t>(4); |
| 2203 | 2244 |
| 2204 BUILD(r, | 2245 BUILD(r, |
| 2205 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO, | 2246 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO, |
| 2206 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)), | 2247 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)), |
| 2207 WASM_SIMD_I32x4_EXTRACT_LANE( | 2248 WASM_SIMD_I32x4_EXTRACT_LANE( |
| 2208 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); | 2249 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); |
| 2209 | 2250 |
| 2210 FOR_INT32_INPUTS(i) { | 2251 FOR_INT32_INPUTS(i) { |
| 2211 int32_t expected = *i; | 2252 int32_t expected = *i; |
| 2212 r.module().WriteMemory(&memory[0], expected); | 2253 r.module().WriteMemory(&memory[0], expected); |
| 2213 CHECK_EQ(expected, r.Call()); | 2254 CHECK_EQ(expected, r.Call()); |
| 2214 } | 2255 } |
| 2215 } | 2256 } |
| 2216 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 2257 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
| OLD | NEW |