From daf0782b7754e225c9063f9fbf5195b4b4a3c7e3 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Thu, 22 Oct 2020 21:47:17 -0700 Subject: Implement v128.{load,store}{8,16,32,64}_lane instructions (#3278) These instructions are proposed in https://github.com/WebAssembly/simd/pull/350. This PR implements them throughout Binaryen except in the C/JS APIs and in the fuzzer, where it leaves TODOs instead. Right now these instructions are just being implemented for prototyping so adding them to the APIs isn't critical and they aren't generally available to be fuzzed in Wasm engines. --- src/wasm/wasm-s-parser.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index c4de76987..4e06a75bb 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1300,8 +1300,12 @@ static size_t parseMemAttributes(Element& s, size_t i = 1; offset = 0; align = fallbackAlign; + // Parse "align=X" and "offset=X" arguments, bailing out on anything else. while (!s[i]->isList()) { const char* str = s[i]->c_str(); + if (strncmp(str, "align", 5) != 0 && strncmp(str, "offset", 6) != 0) { + return i; + } const char* eq = strchr(str, '='); if (!eq) { throw ParseException( @@ -1592,6 +1596,45 @@ Expression* SExpressionWasmBuilder::makeSIMDLoad(Element& s, SIMDLoadOp op) { return ret; } +Expression* +SExpressionWasmBuilder::makeSIMDLoadStoreLane(Element& s, + SIMDLoadStoreLaneOp op) { + auto* ret = allocator.alloc(); + ret->op = op; + Address defaultAlign; + size_t lanes; + switch (op) { + case LoadLaneVec8x16: + case StoreLaneVec8x16: + defaultAlign = 1; + lanes = 16; + break; + case LoadLaneVec16x8: + case StoreLaneVec16x8: + defaultAlign = 2; + lanes = 8; + break; + case LoadLaneVec32x4: + case StoreLaneVec32x4: + defaultAlign = 4; + lanes = 4; + break; + case LoadLaneVec64x2: + case StoreLaneVec64x2: + defaultAlign = 8; + lanes = 2; + break; + default: + WASM_UNREACHABLE("Unexpected SIMDLoadStoreLane op"); + } + size_t i = parseMemAttributes(s, ret->offset, ret->align, defaultAlign); + ret->index = parseLaneIndex(s[i++], lanes); + ret->ptr = parseExpression(s[i++]); + ret->vec = parseExpression(s[i]); + ret->finalize(); + return ret; +} + Expression* SExpressionWasmBuilder::makeMemoryInit(Element& s) { auto ret = allocator.alloc(); ret->segment = atoi(s[1]->str().c_str()); -- cgit v1.2.3