Commit 7b3875d1 authored by aseemgarg's avatar aseemgarg Committed by Commit bot

[wasm] fix Simd ExtractLane to take immediate instead of param

BUG=v8:4124
TEST:test-run-wasm-simd
R=titzer@chromium.org,bradnelson@chromium.org,gdeepti@chromium.org

Review-Url: https://codereview.chromium.org/2300753005
Cr-Commit-Position: refs/heads/master@{#39288}
parent 20d427a1
......@@ -2903,9 +2903,6 @@ Node* WasmGraphBuilder::DefaultS128Value() {
Node* WasmGraphBuilder::SimdOp(wasm::WasmOpcode opcode,
const NodeVector& inputs) {
switch (opcode) {
case wasm::kExprI32x4ExtractLane:
return graph()->NewNode(jsgraph()->machine()->Int32x4ExtractLane(),
inputs[0], inputs[1]);
case wasm::kExprI32x4Splat:
return graph()->NewNode(jsgraph()->machine()->CreateInt32x4(), inputs[0],
inputs[0], inputs[0], inputs[0]);
......@@ -2914,6 +2911,17 @@ Node* WasmGraphBuilder::SimdOp(wasm::WasmOpcode opcode,
}
}
Node* WasmGraphBuilder::SimdExtractLane(wasm::WasmOpcode opcode, uint8_t lane,
Node* input) {
switch (opcode) {
case wasm::kExprI32x4ExtractLane:
return graph()->NewNode(jsgraph()->machine()->Int32x4ExtractLane(), input,
Int32Constant(lane));
default:
return graph()->NewNode(UnsupportedOpcode(opcode), nullptr);
}
}
static void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
Isolate* isolate, Handle<Code> code,
const char* message, uint32_t index,
......
......@@ -198,6 +198,7 @@ class WasmGraphBuilder {
Node* DefaultS128Value();
Node* SimdOp(wasm::WasmOpcode opcode, const NodeVector& inputs);
Node* SimdExtractLane(wasm::WasmOpcode opcode, uint8_t lane, Node* input);
private:
static const int kDefaultBufferSize = 16;
......
......@@ -386,8 +386,12 @@ class WasmDecoder : public Decoder {
FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_SIMD_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE)
#undef DECLARE_OPCODE_CASE
#define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name:
FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE)
#undef DECLARE_OPCODE_CASE
return 1;
default:
UNREACHABLE();
return 0;
......@@ -456,7 +460,10 @@ class WasmDecoder : public Decoder {
ReturnArityOperand operand(this, pc);
return 1 + operand.length;
}
#define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name:
FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 2; }
FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 3; }
#undef DECLARE_OPCODE_CASE
default:
return 1;
}
......@@ -1275,7 +1282,7 @@ class WasmFullDecoder : public WasmDecoder {
opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index);
TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix,
simd_index, WasmOpcodes::ShortOpcodeName(opcode));
DecodeSimdOpcode(opcode);
len += DecodeSimdOpcode(opcode);
break;
}
default:
......@@ -1406,15 +1413,36 @@ class WasmFullDecoder : public WasmDecoder {
return 1 + operand.length;
}
void DecodeSimdOpcode(WasmOpcode opcode) {
FunctionSig* sig = WasmOpcodes::Signature(opcode);
compiler::NodeVector inputs(sig->parameter_count(), zone_);
for (size_t i = sig->parameter_count(); i > 0; i--) {
Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1));
inputs[i - 1] = val.node;
unsigned DecodeSimdOpcode(WasmOpcode opcode) {
unsigned len = 0;
switch (opcode) {
case kExprI32x4ExtractLane: {
uint8_t lane = this->checked_read_u8(pc_, 2, "lane number");
if (lane < 0 || lane > 3) {
error(pc_, pc_ + 2, "invalid extract lane value");
}
TFNode* input = Pop(0, LocalType::kSimd128).node;
TFNode* node = BUILD(SimdExtractLane, opcode, lane, input);
Push(LocalType::kWord32, node);
len++;
break;
}
default: {
FunctionSig* sig = WasmOpcodes::Signature(opcode);
if (sig != nullptr) {
compiler::NodeVector inputs(sig->parameter_count(), zone_);
for (size_t i = sig->parameter_count(); i > 0; i--) {
Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1));
inputs[i - 1] = val.node;
}
TFNode* node = BUILD(SimdOp, opcode, inputs);
Push(GetReturnType(sig), node);
} else {
error(pc_, pc_, "invalid simd opcode");
}
}
}
TFNode* node = BUILD(SimdOp, opcode, inputs);
Push(GetReturnType(sig), node);
return len;
}
void DispatchToTargets(Control* next_block, const Value& val) {
......
......@@ -589,8 +589,8 @@ class LocalDeclEncoder {
// Simd Operations.
//------------------------------------------------------------------------------
#define WASM_SIMD_I32x4_SPLAT(x) x, kSimdPrefix, kExprI32x4Splat & 0xff
#define WASM_SIMD_I32x4_EXTRACT_LANE(x, y) \
x, y, kSimdPrefix, kExprI32x4ExtractLane & 0xff
#define WASM_SIMD_I32x4_EXTRACT_LANE(lane, x) \
x, kSimdPrefix, kExprI32x4ExtractLane & 0xff, static_cast<byte>(lane)
#define SIG_ENTRY_v_v kWasmFunctionTypeForm, 0, 0
#define SIZEOF_SIG_ENTRY_v_v 3
......
......@@ -100,7 +100,7 @@ static void InitSigTables() {
#define SET_SIG_TABLE(name, opcode, sig) \
simd_index = opcode & 0xff; \
kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1;
FOREACH_SIMD_OPCODE(SET_SIG_TABLE)
FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE)
#undef SET_SIG_TABLE
}
......
This diff is collapsed.
......@@ -29,24 +29,21 @@ WASM_EXEC_TEST(Splat) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstS128);
BUILD(r,
WASM_BLOCK(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0),
WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_GET_LOCAL(1), WASM_I8(0))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0),
WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_GET_LOCAL(1), WASM_I8(1))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0),
WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_GET_LOCAL(1), WASM_I8(2))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0),
WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_GET_LOCAL(1), WASM_I8(3))),
WASM_RETURN1(WASM_ZERO)),
WASM_RETURN1(WASM_ONE)));
WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
1, WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
2, WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_ZERO)),
WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
3, WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_ZERO)),
WASM_RETURN1(WASM_ONE)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment