Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: test/cctest/wasm/test-run-wasm-simd.cc

Issue 2838943002: [wasm] Implement 128-bit endian swap for simd type (Closed)
Patch Set: address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); } 1963 WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); }
1964 1964
1965 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); } 1965 WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); }
1966 1966
1967 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); } 1967 WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); }
1968 1968
1969 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); } 1969 WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); }
1970 #endif // !V8_TARGET_ARCH_ARM 1970 #endif // !V8_TARGET_ARCH_ARM
1971 1971
1972 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 1972 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
1973
1973 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { 1974 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) {
1974 FLAG_wasm_simd_prototype = true; 1975 FLAG_wasm_simd_prototype = true;
1975 WasmRunner<int32_t> r(kExecuteCompiled); 1976 WasmRunner<int32_t> r(kExecuteCompiled);
1976 BUILD(r, WASM_IF_ELSE_I( 1977 BUILD(r, WASM_IF_ELSE_I(
1977 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( 1978 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
1978 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))), 1979 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
1979 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))), 1980 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
1980 WASM_I32V(1), WASM_I32V(0))); 1981 WASM_I32V(1), WASM_I32V(0)));
1981 CHECK_EQ(1, r.Call()); 1982 CHECK_EQ(1, r.Call());
1982 } 1983 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 WASM_SET_LOCAL(0, WASM_I32V(0))), 2110 WASM_SET_LOCAL(0, WASM_I32V(0))),
2110 WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)), 2111 WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
2111 WASM_F32(25.5)), 2112 WASM_F32(25.5)),
2112 WASM_SET_LOCAL(0, WASM_I32V(0))), 2113 WASM_SET_LOCAL(0, WASM_I32V(0))),
2113 WASM_GET_LOCAL(0)); 2114 WASM_GET_LOCAL(0));
2114 CHECK_EQ(1, r.Call()); 2115 CHECK_EQ(1, r.Call());
2115 } 2116 }
2116 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 2117 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
2117 2118
2118 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 2119 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64
2120
2121 template <typename T, int numLanes = 4>
2122 void SetVectorByLanes(T* v, const std::array<T, numLanes>& arr) {
2123 for (int lane = 0; lane < numLanes; lane++) {
2124 const T& value = arr[lane];
2125 #if defined(V8_TARGET_BIG_ENDIAN)
2126 v[numLanes - 1 - lane] = value;
2127 #else
2128 v[lane] = value;
2129 #endif
2130 }
2131 }
2132
2133 template <typename T>
2134 const T& GetScalar(T* v, int lane) {
2135 constexpr int kElems = kSimd128Size / sizeof(T);
2136 #if defined(V8_TARGET_BIG_ENDIAN)
2137 const int index = kElems - 1 - lane;
2138 #else
2139 const int index = lane;
2140 #endif
2141 USE(kElems);
2142 DCHECK(index >= 0 && index < kElems);
2143 return v[index];
2144 }
2145
2119 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) { 2146 WASM_EXEC_COMPILED_TEST(SimdI32x4GetGlobal) {
2120 FLAG_wasm_simd_prototype = true; 2147 FLAG_wasm_simd_prototype = true;
2121 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); 2148 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
2122 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); 2149 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128);
2123 *(global) = 0; 2150 SetVectorByLanes(global, {{0, 1, 2, 3}});
2124 *(global + 1) = 1;
2125 *(global + 2) = 2;
2126 *(global + 3) = 3;
2127 r.AllocateLocal(kWasmI32); 2151 r.AllocateLocal(kWasmI32);
2128 BUILD( 2152 BUILD(
2129 r, WASM_SET_LOCAL(1, WASM_I32V(1)), 2153 r, WASM_SET_LOCAL(1, WASM_I32V(1)),
2130 WASM_IF(WASM_I32_NE(WASM_I32V(0), 2154 WASM_IF(WASM_I32_NE(WASM_I32V(0),
2131 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), 2155 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
2132 WASM_SET_LOCAL(1, WASM_I32V(0))), 2156 WASM_SET_LOCAL(1, WASM_I32V(0))),
2133 WASM_IF(WASM_I32_NE(WASM_I32V(1), 2157 WASM_IF(WASM_I32_NE(WASM_I32V(1),
2134 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), 2158 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
2135 WASM_SET_LOCAL(1, WASM_I32V(0))), 2159 WASM_SET_LOCAL(1, WASM_I32V(0))),
2136 WASM_IF(WASM_I32_NE(WASM_I32V(2), 2160 WASM_IF(WASM_I32_NE(WASM_I32V(2),
(...skipping 12 matching lines...) Expand all
2149 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128); 2173 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128);
2150 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))), 2174 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
2151 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), 2175 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
2152 WASM_I32V(34))), 2176 WASM_I32V(34))),
2153 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), 2177 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
2154 WASM_I32V(45))), 2178 WASM_I32V(45))),
2155 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), 2179 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
2156 WASM_I32V(56))), 2180 WASM_I32V(56))),
2157 WASM_I32V(1)); 2181 WASM_I32V(1));
2158 CHECK_EQ(1, r.Call(0)); 2182 CHECK_EQ(1, r.Call(0));
2159 CHECK_EQ(*global, 23); 2183 CHECK_EQ(GetScalar(global, 0), 23);
2160 CHECK_EQ(*(global + 1), 34); 2184 CHECK_EQ(GetScalar(global, 1), 34);
2161 CHECK_EQ(*(global + 2), 45); 2185 CHECK_EQ(GetScalar(global, 2), 45);
2162 CHECK_EQ(*(global + 3), 56); 2186 CHECK_EQ(GetScalar(global, 3), 56);
2163 } 2187 }
2164 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 2188 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64
2165 2189
2166 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 2190 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
2167 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) { 2191 WASM_EXEC_COMPILED_TEST(SimdF32x4GetGlobal) {
2168 FLAG_wasm_simd_prototype = true; 2192 FLAG_wasm_simd_prototype = true;
2169 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); 2193 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
2170 float* global = r.module().AddGlobal<float>(kWasmS128); 2194 float* global = r.module().AddGlobal<float>(kWasmS128);
2171 *(global) = 0.0; 2195 SetVectorByLanes<float>(global, {{0.0, 1.5, 2.25, 3.5}});
2172 *(global + 1) = 1.5;
2173 *(global + 2) = 2.25;
2174 *(global + 3) = 3.5;
2175 r.AllocateLocal(kWasmI32); 2196 r.AllocateLocal(kWasmI32);
2176 BUILD( 2197 BUILD(
2177 r, WASM_SET_LOCAL(1, WASM_I32V(1)), 2198 r, WASM_SET_LOCAL(1, WASM_I32V(1)),
2178 WASM_IF(WASM_F32_NE(WASM_F32(0.0), 2199 WASM_IF(WASM_F32_NE(WASM_F32(0.0),
2179 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))), 2200 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
2180 WASM_SET_LOCAL(1, WASM_I32V(0))), 2201 WASM_SET_LOCAL(1, WASM_I32V(0))),
2181 WASM_IF(WASM_F32_NE(WASM_F32(1.5), 2202 WASM_IF(WASM_F32_NE(WASM_F32(1.5),
2182 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))), 2203 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
2183 WASM_SET_LOCAL(1, WASM_I32V(0))), 2204 WASM_SET_LOCAL(1, WASM_I32V(0))),
2184 WASM_IF(WASM_F32_NE(WASM_F32(2.25), 2205 WASM_IF(WASM_F32_NE(WASM_F32(2.25),
(...skipping 12 matching lines...) Expand all
2197 float* global = r.module().AddGlobal<float>(kWasmS128); 2218 float* global = r.module().AddGlobal<float>(kWasmS128);
2198 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))), 2219 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
2199 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0), 2220 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
2200 WASM_F32(45.5))), 2221 WASM_F32(45.5))),
2201 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0), 2222 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
2202 WASM_F32(32.25))), 2223 WASM_F32(32.25))),
2203 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), 2224 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
2204 WASM_F32(65.0))), 2225 WASM_F32(65.0))),
2205 WASM_I32V(1)); 2226 WASM_I32V(1));
2206 CHECK_EQ(1, r.Call(0)); 2227 CHECK_EQ(1, r.Call(0));
2207 CHECK_EQ(*global, 13.5); 2228 CHECK_EQ(GetScalar(global, 0), 13.5f);
2208 CHECK_EQ(*(global + 1), 45.5); 2229 CHECK_EQ(GetScalar(global, 1), 45.5f);
2209 CHECK_EQ(*(global + 2), 32.25); 2230 CHECK_EQ(GetScalar(global, 2), 32.25f);
2210 CHECK_EQ(*(global + 3), 65.0); 2231 CHECK_EQ(GetScalar(global, 3), 65.0f);
2211 } 2232 }
2212 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 2233 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
2213 2234
2214 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 2235 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64
2215 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) { 2236 WASM_EXEC_COMPILED_TEST(SimdLoadStoreLoad) {
2216 FLAG_wasm_simd_prototype = true; 2237 FLAG_wasm_simd_prototype = true;
2217 WasmRunner<int32_t> r(kExecuteCompiled); 2238 WasmRunner<int32_t> r(kExecuteCompiled);
2218 int32_t* memory = r.module().AddMemoryElems<int32_t>(4); 2239 int32_t* memory = r.module().AddMemoryElems<int32_t>(4);
2219 2240
2220 BUILD(r, 2241 BUILD(r,
2221 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO, 2242 WASM_STORE_MEM(MachineType::Simd128(), WASM_ZERO,
2222 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)), 2243 WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)),
2223 WASM_SIMD_I32x4_EXTRACT_LANE( 2244 WASM_SIMD_I32x4_EXTRACT_LANE(
2224 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO))); 2245 0, WASM_LOAD_MEM(MachineType::Simd128(), WASM_ZERO)));
2225 2246
2226 FOR_INT32_INPUTS(i) { 2247 FOR_INT32_INPUTS(i) {
2227 int32_t expected = *i; 2248 int32_t expected = *i;
2228 r.module().WriteMemory(&memory[0], expected); 2249 r.module().WriteMemory(&memory[0], expected);
2229 CHECK_EQ(expected, r.Call()); 2250 CHECK_EQ(expected, r.Call());
2230 } 2251 }
2231 } 2252 }
2232 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64 2253 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET || V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698