Reland "[wasm] Support encoding s128 simd types in exceptions."

This is a reland of 9c2c8f15f8

Original change's description:
> [wasm] Support encoding s128 simd types in exceptions.
> 
> This adds support for having simd type values (i.e. s128) stored in an
> exception. It is the natural combination of the simd propsal and the
> exception handling proposal.
> 
> R=clemensh@chromium.org
> TEST=mjsunit/wasm/exceptions-simd
> BUG=v8:8390
> 
> Change-Id: I01079f82a6ba4d9152de4dae63e3db1584ca7cd8
> Reviewed-on: https://chromium-review.googlesource.com/c/1363141
> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
> Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#58098}

Bug: v8:8390
Change-Id: I333c50cd766055f74b023df626d0fd90fdef3bac
Reviewed-on: https://chromium-review.googlesource.com/c/1370024
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58122}
This commit is contained in:
Michael Starzinger 2018-12-10 10:59:29 +01:00 committed by Commit Bot
parent 126b2cc438
commit 0c0d4c3934
6 changed files with 91 additions and 5 deletions

View File

@ -2466,7 +2466,7 @@ void InstructionSelector::VisitWord32AtomicPairCompareExchange(Node* node) {
void InstructionSelector::VisitS128Zero(Node* node) {
ArmOperandGenerator g(this);
Emit(kArmS128Zero, g.DefineAsRegister(node), g.DefineAsRegister(node));
Emit(kArmS128Zero, g.DefineAsRegister(node));
}
#define SIMD_VISIT_SPLAT(Type) \

View File

@ -3009,7 +3009,7 @@ void InstructionSelector::VisitInt64AbsWithOverflow(Node* node) {
void InstructionSelector::VisitS128Zero(Node* node) {
Arm64OperandGenerator g(this);
Emit(kArm64S128Zero, g.DefineAsRegister(node), g.DefineAsRegister(node));
Emit(kArm64S128Zero, g.DefineAsRegister(node));
}
#define SIMD_VISIT_SPLAT(Type) \

View File

@ -2628,7 +2628,7 @@ VISIT_ATOMIC_BINOP(Xor)
void InstructionSelector::VisitS128Zero(Node* node) {
X64OperandGenerator g(this);
Emit(kX64S128Zero, g.DefineAsRegister(node), g.DefineAsRegister(node));
Emit(kX64S128Zero, g.DefineAsRegister(node));
}
#define VISIT_SIMD_SPLAT(Type) \

View File

@ -1080,6 +1080,15 @@ void SimdScalarLowering::LowerNode(Node* node) {
ReplaceNode(node, rep_node, num_lanes);
break;
}
case IrOpcode::kS128Zero: {
DCHECK_EQ(0, node->InputCount());
Node* rep_node[kNumLanes32];
for (int i = 0; i < kNumLanes32; ++i) {
rep_node[i] = mcgraph_->Int32Constant(0);
}
ReplaceNode(node, rep_node, kNumLanes32);
break;
}
case IrOpcode::kS128Not: {
DCHECK_EQ(1, node->InputCount());
Node** rep = GetReplacementsWithType(node->InputAt(0), rep_type);

View File

@ -2101,8 +2101,8 @@ uint32_t WasmGraphBuilder::GetExceptionEncodedSize(
encoded_size += 4;
break;
case wasm::kWasmS128:
// TODO(mstarzinger): Implement and test this case.
UNIMPLEMENTED();
DCHECK_EQ(8, ComputeEncodedElementSize(sig->GetParam(i)));
encoded_size += 8;
break;
case wasm::kWasmAnyRef:
encoded_size += 1;
@ -2151,6 +2151,20 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
BuildEncodeException32BitValue(values_array, &index, lower32);
break;
}
case wasm::kWasmS128:
BuildEncodeException32BitValue(
values_array, &index,
graph()->NewNode(m->I32x4ExtractLane(0), value));
BuildEncodeException32BitValue(
values_array, &index,
graph()->NewNode(m->I32x4ExtractLane(1), value));
BuildEncodeException32BitValue(
values_array, &index,
graph()->NewNode(m->I32x4ExtractLane(2), value));
BuildEncodeException32BitValue(
values_array, &index,
graph()->NewNode(m->I32x4ExtractLane(3), value));
break;
case wasm::kWasmAnyRef:
STORE_FIXED_ARRAY_SLOT_ANY(values_array, index, value);
++index;
@ -2269,6 +2283,20 @@ Node** WasmGraphBuilder::GetExceptionValues(
BuildDecodeException64BitValue(values_array, &index));
break;
}
case wasm::kWasmS128:
value = graph()->NewNode(
mcgraph()->machine()->I32x4Splat(),
BuildDecodeException32BitValue(values_array, &index));
value = graph()->NewNode(
mcgraph()->machine()->I32x4ReplaceLane(1), value,
BuildDecodeException32BitValue(values_array, &index));
value = graph()->NewNode(
mcgraph()->machine()->I32x4ReplaceLane(2), value,
BuildDecodeException32BitValue(values_array, &index));
value = graph()->NewNode(
mcgraph()->machine()->I32x4ReplaceLane(3), value,
BuildDecodeException32BitValue(values_array, &index));
break;
case wasm::kWasmAnyRef:
value = LOAD_FIXED_ARRAY_SLOT_ANY(values_array, index);
++index;

View File

@ -0,0 +1,49 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --experimental-wasm-eh --experimental-wasm-simd --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
load("test/mjsunit/wasm/exceptions-utils.js");
(function TestThrowS128Default() {
var builder = new WasmModuleBuilder();
var kSig_v_s = makeSig([kWasmS128], []);
var except = builder.addException(kSig_v_s);
builder.addFunction("throw_simd", kSig_v_v)
.addLocals({s128_count: 1})
.addBody([
kExprGetLocal, 0,
kExprThrow, 0,
])
.exportFunc();
var instance = builder.instantiate();
assertWasmThrows(instance, except, [0, 0, 0, 0, 0, 0, 0, 0],
() => instance.exports.throw_simd());
})();
(function TestThrowCatchS128Default() {
var builder = new WasmModuleBuilder();
var kSig_v_s = makeSig([kWasmS128], []);
var except = builder.addException(kSig_v_s);
builder.addFunction("throw_catch_simd", kSig_i_v)
.addLocals({s128_count: 1})
.addBody([
kExprTry, kWasmI32,
kExprGetLocal, 0,
kExprThrow, 0,
kExprCatch, except,
// TODO(mstarzinger): Actually return some compressed form of the s128
// value here to make sure it is extracted properly from the exception.
kExprDrop,
kExprI32Const, 1,
kExprEnd,
])
.exportFunc();
var instance = builder.instantiate();
assertEquals(1, instance.exports.throw_catch_simd());
})();