Commit a9b8a567 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Implement polymorphic checking, matching the reference interpreter.

R=rossberg@chromium.org, bradnelson@chromium.org
BUG=chromium:682659

Review-Url: https://codereview.chromium.org/2670673002
Cr-Commit-Position: refs/heads/master@{#42904}
parent a62322aa
......@@ -104,6 +104,7 @@ struct Control {
SsaEnv* false_env; // false environment (only for if).
TryInfo* try_info; // Information used for compiling try statements.
int32_t previous_catch; // The previous Control (on the stack) with a catch.
bool unreachable; // The current block has been ended.
// Values merged into the end of this control construct.
MergeValues merge;
......@@ -116,28 +117,28 @@ struct Control {
// Named constructors.
static Control Block(const byte* pc, size_t stack_depth, SsaEnv* end_env,
int32_t previous_catch) {
return {pc, kControlBlock, stack_depth, end_env,
nullptr, nullptr, previous_catch, {0, {NO_VALUE}}};
return {pc, kControlBlock, stack_depth, end_env, nullptr,
nullptr, previous_catch, false, {0, {NO_VALUE}}};
}
static Control If(const byte* pc, size_t stack_depth, SsaEnv* end_env,
SsaEnv* false_env, int32_t previous_catch) {
return {pc, kControlIf, stack_depth, end_env,
false_env, nullptr, previous_catch, {0, {NO_VALUE}}};
return {pc, kControlIf, stack_depth, end_env, false_env,
nullptr, previous_catch, false, {0, {NO_VALUE}}};
}
static Control Loop(const byte* pc, size_t stack_depth, SsaEnv* end_env,
int32_t previous_catch) {
return {pc, kControlLoop, stack_depth, end_env,
nullptr, nullptr, previous_catch, {0, {NO_VALUE}}};
return {pc, kControlLoop, stack_depth, end_env, nullptr,
nullptr, previous_catch, false, {0, {NO_VALUE}}};
}
static Control Try(const byte* pc, size_t stack_depth, SsaEnv* end_env,
Zone* zone, SsaEnv* catch_env, int32_t previous_catch) {
DCHECK_NOT_NULL(catch_env);
TryInfo* try_info = new (zone) TryInfo(catch_env);
return {pc, kControlTry, stack_depth, end_env,
nullptr, try_info, previous_catch, {0, {NO_VALUE}}};
return {pc, kControlTry, stack_depth, end_env, nullptr,
try_info, previous_catch, false, {0, {NO_VALUE}}};
}
};
......@@ -744,9 +745,7 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
if (ssa_env_->go()) {
MergeValuesInto(c);
}
FallThruTo(c);
stack_.resize(c->stack_depth);
DCHECK_NOT_NULL(c->try_info);
......@@ -810,8 +809,8 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
FallThruTo(c);
// Switch to environment for false branch.
stack_.resize(c->stack_depth);
// Switch to environment for false branch.
SetEnv("if_else:false", c->false_env);
c->false_env = nullptr; // record that an else is already seen
break;
......@@ -825,7 +824,8 @@ class WasmFullDecoder : public WasmDecoder {
Control* c = &control_.back();
if (c->is_loop()) {
// A loop just leaves the values on the stack.
TypeCheckLoopFallThru(c);
TypeCheckFallThru(c);
if (c->unreachable) PushEndValues(c);
PopControl();
SetEnv("loop:end", ssa_env_);
break;
......@@ -834,7 +834,7 @@ class WasmFullDecoder : public WasmDecoder {
if (c->false_env != nullptr) {
// End the true branch of a one-armed if.
Goto(c->false_env, c->end_env);
if (ssa_env_->go() && stack_.size() != c->stack_depth) {
if (!c->unreachable && stack_.size() != c->stack_depth) {
error("end of if expected empty stack");
stack_.resize(c->stack_depth);
}
......@@ -857,16 +857,7 @@ class WasmFullDecoder : public WasmDecoder {
}
FallThruTo(c);
SetEnv(name, c->end_env);
// Push the end values onto the stack.
stack_.resize(c->stack_depth);
if (c->merge.arity == 1) {
stack_.push_back(c->merge.vals.first);
} else {
for (unsigned i = 0; i < c->merge.arity; i++) {
stack_.push_back(c->merge.vals.array[i]);
}
}
PushEndValues(c);
if (control_.size() == 1) {
// If at the last (implicit) control, check we are at end.
......@@ -880,6 +871,8 @@ class WasmFullDecoder : public WasmDecoder {
TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "(implicit) return");
DoReturn();
TRACE("\n");
} else {
TypeCheckFallThru(c);
}
}
PopControl();
......@@ -888,17 +881,8 @@ class WasmFullDecoder : public WasmDecoder {
case kExprSelect: {
Value cond = Pop(2, kWasmI32);
Value fval = Pop();
Value tval = Pop();
if (tval.type == kWasmStmt || tval.type != fval.type) {
if (tval.type != kWasmEnd && fval.type != kWasmEnd) {
error("type mismatch in select");
break;
}
}
Value tval = Pop(0, fval.type);
if (build()) {
DCHECK(tval.type != kWasmEnd);
DCHECK(fval.type != kWasmEnd);
DCHECK(cond.type != kWasmEnd);
TFNode* controls[2];
builder_->BranchNoHint(cond.node, &controls[0], &controls[1]);
TFNode* merge = builder_->Merge(2, controls);
......@@ -907,7 +891,7 @@ class WasmFullDecoder : public WasmDecoder {
Push(tval.type, phi);
ssa_env_->control = merge;
} else {
Push(tval.type, nullptr);
Push(tval.type == kWasmVar ? fval.type : tval.type, nullptr);
}
break;
}
......@@ -1229,6 +1213,35 @@ class WasmFullDecoder : public WasmDecoder {
#if DEBUG
if (FLAG_trace_wasm_decoder) {
PrintF(" ");
for (size_t i = 0; i < control_.size(); ++i) {
Control* c = &control_[i];
enum ControlKind {
kControlIf,
kControlBlock,
kControlLoop,
kControlTry
};
switch (c->kind) {
case kControlIf:
PrintF("I");
break;
case kControlBlock:
PrintF("B");
break;
case kControlLoop:
PrintF("L");
break;
case kControlTry:
PrintF("T");
break;
default:
break;
}
PrintF("%u", c->merge.arity);
if (c->unreachable) PrintF("*");
}
PrintF(" | ");
for (size_t i = 0; i < stack_.size(); ++i) {
Value& val = stack_[i];
WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc);
......@@ -1258,6 +1271,7 @@ class WasmFullDecoder : public WasmDecoder {
default:
break;
}
if (val.node == nullptr) PrintF("?");
}
PrintF("\n");
}
......@@ -1269,11 +1283,9 @@ class WasmFullDecoder : public WasmDecoder {
void EndControl() {
ssa_env_->Kill(SsaEnv::kControlEnd);
if (control_.empty()) {
stack_.clear();
} else {
DCHECK_LE(control_.back().stack_depth, stack_.size());
if (!control_.empty()) {
stack_.resize(control_.back().stack_depth);
control_.back().unreachable = true;
}
}
......@@ -1439,11 +1451,23 @@ class WasmFullDecoder : public WasmDecoder {
}
void Push(ValueType type, TFNode* node) {
if (type != kWasmStmt && type != kWasmEnd) {
if (type != kWasmStmt) {
stack_.push_back({pc_, node, type});
}
}
void PushEndValues(Control* c) {
stack_.resize(c->stack_depth);
if (c->merge.arity == 1) {
stack_.push_back(c->merge.vals.first);
} else {
for (unsigned i = 0; i < c->merge.arity; i++) {
stack_.push_back(c->merge.vals.array[i]);
}
}
DCHECK_EQ(c->stack_depth + c->merge.arity, stack_.size());
}
void PushReturns(FunctionSig* sig, TFNode** rets) {
for (size_t i = 0; i < sig->return_count(); i++) {
// When verifying only, then {rets} will be null, so push null.
......@@ -1458,12 +1482,10 @@ class WasmFullDecoder : public WasmDecoder {
Value Pop(int index, ValueType expected) {
Value val = Pop();
if (val.type != expected) {
if (val.type != kWasmEnd) {
error(pc_, val.pc, "%s[%d] expected type %s, found %s of type %s",
SafeOpcodeNameAt(pc_), index, WasmOpcodes::TypeName(expected),
SafeOpcodeNameAt(val.pc), WasmOpcodes::TypeName(val.type));
}
if (val.type != expected && val.type != kWasmVar && expected != kWasmVar) {
error(pc_, val.pc, "%s[%d] expected type %s, found %s of type %s",
SafeOpcodeNameAt(pc_), index, WasmOpcodes::TypeName(expected),
SafeOpcodeNameAt(val.pc), WasmOpcodes::TypeName(val.type));
}
return val;
}
......@@ -1471,9 +1493,9 @@ class WasmFullDecoder : public WasmDecoder {
Value Pop() {
size_t limit = control_.empty() ? 0 : control_.back().stack_depth;
if (stack_.size() <= limit) {
Value val = {pc_, nullptr, kWasmEnd};
if (ssa_env_->go()) {
// Popping past the current control start in reachable code.
// Popping past the current control start in reachable code.
Value val = {pc_, nullptr, kWasmVar};
if (!control_.back().unreachable) {
error(pc_, pc_, "%s found empty stack", SafeOpcodeNameAt(pc_));
}
return val;
......@@ -1490,17 +1512,17 @@ class WasmFullDecoder : public WasmDecoder {
int startrel(const byte* ptr) { return static_cast<int>(ptr - start_); }
void BreakTo(unsigned depth) {
if (!ssa_env_->go()) return;
Control* c = &control_[control_.size() - depth - 1];
if (c->is_loop()) {
// This is the inner loop block, which does not have a value.
Goto(ssa_env_, c->end_env);
} else {
// Merge the value(s) into the end of the block.
if (c->stack_depth + c->merge.arity > stack_.size()) {
size_t expected = c->stack_depth + c->merge.arity;
if (!c->unreachable && stack_.size() < expected) {
error(
pc_, pc_,
"expected at least %d values on the stack for br to @%d, found %d",
"expected at least %u values on the stack for br to @%d, found %d",
c->merge.arity, startrel(c->pc),
static_cast<int>(stack_.size() - c->stack_depth));
return;
......@@ -1510,37 +1532,40 @@ class WasmFullDecoder : public WasmDecoder {
}
void FallThruTo(Control* c) {
if (!ssa_env_->go()) return;
// Merge the value(s) into the end of the block.
int arity = static_cast<int>(c->merge.arity);
if (c->stack_depth + arity != stack_.size()) {
error(pc_, pc_, "expected %d elements on the stack for fallthru to @%d",
arity, startrel(c->pc));
size_t expected = c->stack_depth + c->merge.arity;
if (stack_.size() == expected ||
(c->unreachable && stack_.size() < expected)) {
MergeValuesInto(c);
c->unreachable = false;
return;
}
MergeValuesInto(c);
error(pc_, pc_, "expected %u elements on the stack for fallthru to @%d",
c->merge.arity, startrel(c->pc));
}
inline Value& GetMergeValueFromStack(Control* c, int i) {
inline Value& GetMergeValueFromStack(Control* c, size_t i) {
return stack_[stack_.size() - c->merge.arity + i];
}
void TypeCheckLoopFallThru(Control* c) {
if (!ssa_env_->go()) return;
void TypeCheckFallThru(Control* c) {
// Fallthru must match arity exactly.
int arity = static_cast<int>(c->merge.arity);
if (c->stack_depth + arity != stack_.size()) {
if (c->stack_depth + arity < stack_.size() ||
(!c->unreachable && c->stack_depth + arity != stack_.size())) {
error(pc_, pc_, "expected %d elements on the stack for fallthru to @%d",
arity, startrel(c->pc));
return;
}
// Typecheck the values left on the stack.
for (unsigned i = 0; i < c->merge.arity; i++) {
size_t avail = stack_.size() - c->stack_depth;
for (size_t i = avail >= c->merge.arity ? 0 : c->merge.arity - avail;
i < c->merge.arity; i++) {
Value& val = GetMergeValueFromStack(c, i);
Value& old =
c->merge.arity == 1 ? c->merge.vals.first : c->merge.vals.array[i];
if (val.type != old.type) {
error(pc_, pc_, "type error in merge[%d] (expected %s, got %s)", i,
error(pc_, pc_, "type error in merge[%zu] (expected %s, got %s)", i,
WasmOpcodes::TypeName(old.type), WasmOpcodes::TypeName(val.type));
return;
}
......@@ -1550,23 +1575,25 @@ class WasmFullDecoder : public WasmDecoder {
void MergeValuesInto(Control* c) {
SsaEnv* target = c->end_env;
bool first = target->state == SsaEnv::kUnreachable;
bool reachable = ssa_env_->go();
Goto(ssa_env_, target);
for (unsigned i = 0; i < c->merge.arity; i++) {
size_t avail = stack_.size() - c->stack_depth;
for (size_t i = avail >= c->merge.arity ? 0 : c->merge.arity - avail;
i < c->merge.arity; i++) {
Value& val = GetMergeValueFromStack(c, i);
Value& old =
c->merge.arity == 1 ? c->merge.vals.first : c->merge.vals.array[i];
if (val.type != old.type) {
error(pc_, pc_, "type error in merge[%d] (expected %s, got %s)", i,
if (val.type != old.type && val.type != kWasmVar) {
error(pc_, pc_, "type error in merge[%zu] (expected %s, got %s)", i,
WasmOpcodes::TypeName(old.type), WasmOpcodes::TypeName(val.type));
return;
}
if (builder_) {
if (builder_ && reachable) {
DCHECK_NOT_NULL(val.node);
old.node =
first ? val.node : CreateOrMergeIntoPhi(old.type, target->control,
old.node, val.node);
} else {
old.node = nullptr;
}
}
}
......@@ -1591,13 +1618,13 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
}
PrintF(" env = %p, state = %c, reason = %s", static_cast<void*>(env),
PrintF("{set_env = %p, state = %c, reason = %s", static_cast<void*>(env),
state, reason);
if (env && env->control) {
PrintF(", control = ");
compiler::WasmGraphBuilder::PrintDebugName(env->control);
}
PrintF("\n");
PrintF("}");
}
#endif
ssa_env_ = env;
......
......@@ -36,8 +36,7 @@ const ValueType kWasmI64 = MachineRepresentation::kWord64;
const ValueType kWasmF32 = MachineRepresentation::kFloat32;
const ValueType kWasmF64 = MachineRepresentation::kFloat64;
const ValueType kWasmS128 = MachineRepresentation::kSimd128;
// We use kTagged here because kNone is already used by kWasmStmt.
const ValueType kWasmEnd = MachineRepresentation::kTagged;
const ValueType kWasmVar = MachineRepresentation::kTagged;
typedef Signature<ValueType> FunctionSig;
std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
......@@ -649,10 +648,9 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
return 's';
case kWasmStmt:
return 'v';
case kWasmEnd:
return 'x';
case kWasmVar:
return '*';
default:
UNREACHABLE();
return '?';
}
}
......@@ -671,8 +669,8 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
return "s128";
case kWasmStmt:
return "<stmt>";
case kWasmEnd:
return "<end>";
case kWasmVar:
return "<var>";
default:
return "<unknown>";
}
......
......@@ -36,21 +36,21 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))),
WASM_F32(9.5)),
WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0))));
WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))),
WASM_F32(9.5)),
WASM_I32V(1), WASM_I32V(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0))));
BUILD(r, WASM_IF_ELSE_I(
WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
WASM_I32V(1), WASM_I32V(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -58,10 +58,10 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
WASM_F32_REINTERPRET_I32(WASM_I32V(15))),
WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0))));
WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
WASM_F32_REINTERPRET_I32(WASM_I32V(15))),
WASM_I32V(1), WASM_I32V(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -69,14 +69,14 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(
WASM_IF_ELSE_I(
WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_ADD(
WASM_SIMD_I32x4_SPLAT(WASM_I32V(32)),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(19)))),
WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(32)),
WASM_F32_REINTERPRET_I32(WASM_I32V(19)))),
WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0))));
WASM_I32V(1), WASM_I32V(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -84,14 +84,14 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(
WASM_IF_ELSE_I(
WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_ADD(
WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)),
WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))),
WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)),
WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))),
WASM_RETURN1(WASM_I32V(1)), WASM_RETURN1(WASM_I32V(0))));
WASM_I32V(1), WASM_I32V(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -99,9 +99,9 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_RETURN1(
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)))));
BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); }
}
......@@ -109,12 +109,10 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
WASM_I32V(53))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0)))));
BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
WASM_I32V(53))),
WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); }
}
......@@ -123,15 +121,13 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmF32);
r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(65.25))),
WASM_SET_LOCAL(
0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)),
WASM_RETURN1(WASM_I32V(1))),
WASM_RETURN1(WASM_I32V(0))));
BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
WASM_F32(65.25))),
WASM_SET_LOCAL(0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)),
WASM_RETURN1(WASM_I32V(1))),
WASM_I32V(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -140,12 +136,10 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) {
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmI32);
r.AllocateLocal(kWasmS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)))));
BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); }
}
......@@ -158,21 +152,21 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
*(global + 2) = 2;
*(global + 3) = 3;
r.AllocateLocal(kWasmI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(WASM_I32_NE(WASM_I32V(0), WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(1), WASM_SIMD_I32x4_EXTRACT_LANE(
1, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(2), WASM_SIMD_I32x4_EXTRACT_LANE(
2, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(3), WASM_SIMD_I32x4_EXTRACT_LANE(
3, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
BUILD(
r, WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(WASM_I32_NE(WASM_I32V(0),
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(1),
WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(2),
WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_I32V(3),
WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_GET_LOCAL(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
}
......@@ -180,15 +174,14 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(
1, WASM_GET_GLOBAL(0), WASM_I32V(34))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(
2, WASM_GET_GLOBAL(0), WASM_I32V(45))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(
3, WASM_GET_GLOBAL(0), WASM_I32V(56))),
WASM_RETURN1(WASM_I32V(1))));
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
WASM_I32V(34))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
WASM_I32V(45))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
WASM_I32V(56))),
WASM_I32V(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
CHECK_EQ(*global, 23);
CHECK_EQ(*(global + 1), 34);
......@@ -205,21 +198,21 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
*(global + 2) = 2.25;
*(global + 3) = 3.5;
r.AllocateLocal(kWasmI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(WASM_F32(0.0), WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(1.5), WASM_SIMD_F32x4_EXTRACT_LANE(
1, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(2.25), WASM_SIMD_F32x4_EXTRACT_LANE(
2, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(3.5), WASM_SIMD_F32x4_EXTRACT_LANE(
3, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
BUILD(
r, WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(WASM_F32(0.0),
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(1.5),
WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(2.25),
WASM_SIMD_F32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_F32(3.5),
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_GET_LOCAL(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
}
......@@ -227,15 +220,14 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
float* global = r.module().AddGlobal<float>(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(
1, WASM_GET_GLOBAL(0), WASM_F32(45.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(
2, WASM_GET_GLOBAL(0), WASM_F32(32.25))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_GLOBAL(0), WASM_F32(65.0))),
WASM_RETURN1(WASM_I32V(1))));
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
WASM_F32(45.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
WASM_F32(32.25))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
WASM_F32(65.0))),
WASM_I32V(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
CHECK_EQ(*global, 13.5);
CHECK_EQ(*(global + 1), 45.5);
......@@ -248,38 +240,33 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) {
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmI32);
r.AllocateLocal(kWasmS128);
BUILD(
r,
WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
WASM_I32V(53))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_I32V(23))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)),
WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
WASM_I32V(58)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
WASM_I32V(28)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
BUILD(r,
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
WASM_I32V(53))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_I32V(23))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(
WASM_SET_LOCAL(
1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(1),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)), WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
WASM_I32V(58)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
WASM_I32V(28)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -288,26 +275,22 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) {
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kWasmI32);
r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(19.5))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)),
WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_F32(27.25)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_F32(25.5)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
WASM_F32(19.5))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(
WASM_SET_LOCAL(
1, WASM_SIMD_F32x4_ADD(WASM_GET_LOCAL(1),
WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)), WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_F32(27.25)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_F32(25.5)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -191,10 +191,9 @@ WASM_EXEC_TEST(F32x4Splat) {
WasmRunner<int32_t, float> r(kExecuteCompiled);
byte lane_val = 0;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(
WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, lane_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r,
WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, lane_val), WASM_ONE);
FOR_FLOAT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
}
......@@ -205,29 +204,23 @@ WASM_EXEC_TEST(F32x4ReplaceLane) {
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd,
WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(
simd, WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, old_val, old_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, old_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(simd,
WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE);
CHECK_EQ(1, r.Call(3.14159, -1.5));
}
......@@ -242,15 +235,12 @@ WASM_EXEC_TEST(F32x4FromInt32x4) {
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
byte simd2 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd1, WASM_SIMD_F32x4_FROM_I32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected_signed),
WASM_SET_LOCAL(
simd2, WASM_SIMD_F32x4_FROM_U32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd2, expected_unsigned),
WASM_RETURN1(WASM_ONE)));
BUILD(
r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_FROM_I32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected_signed),
WASM_SET_LOCAL(simd2, WASM_SIMD_F32x4_FROM_U32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd2, expected_unsigned), WASM_ONE);
FOR_INT32_INPUTS(i) {
CHECK_EQ(1, r.Call(*i, static_cast<float>(*i),
......@@ -267,22 +257,21 @@ WASM_EXEC_TEST(S32x4Select) {
byte src1 = r.AllocateLocal(kWasmS128);
byte src2 = r.AllocateLocal(kWasmS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_SPLAT(WASM_ZERO)),
WASM_SET_LOCAL(src1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val1))),
WASM_SET_LOCAL(src2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val2))),
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE(
1, WASM_GET_LOCAL(mask), WASM_I32V(-1))),
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE(
2, WASM_GET_LOCAL(mask), WASM_I32V(-1))),
WASM_SET_LOCAL(mask, WASM_SIMD_S32x4_SELECT(WASM_GET_LOCAL(mask),
WASM_GET_LOCAL(src1),
WASM_GET_LOCAL(src2))),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 0),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 1),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 2),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 3),
WASM_RETURN1(WASM_ONE)));
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_SPLAT(WASM_ZERO)),
WASM_SET_LOCAL(src1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val1))),
WASM_SET_LOCAL(src2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val2))),
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE(
1, WASM_GET_LOCAL(mask), WASM_I32V(-1))),
WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE(
2, WASM_GET_LOCAL(mask), WASM_I32V(-1))),
WASM_SET_LOCAL(mask, WASM_SIMD_S32x4_SELECT(WASM_GET_LOCAL(mask),
WASM_GET_LOCAL(src1),
WASM_GET_LOCAL(src2))),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 0),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 1),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 2),
WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 3), WASM_ONE);
CHECK_EQ(1, r.Call(0x1234, 0x5678));
}
......@@ -293,12 +282,10 @@ void RunF32x4UnOpTest(WasmOpcode simd_op, FloatUnOp expected_op) {
byte a = 0;
byte expected = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd,
WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, expected), WASM_ONE);
FOR_FLOAT32_INPUTS(i) {
if (std::isnan(*i)) continue;
......@@ -317,14 +304,12 @@ void RunF32x4BinOpTest(WasmOpcode simd_op, FloatBinOp expected_op) {
byte expected = 2;
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1,
WASM_SIMD_BINOP(simd_op & 0xffu, WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected), WASM_ONE);
FOR_FLOAT32_INPUTS(i) {
if (std::isnan(*i)) continue;
......@@ -351,14 +336,12 @@ void RunF32x4CompareOpTest(WasmOpcode simd_op, FloatCompareOp expected_op) {
byte expected = 2;
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1,
WASM_SIMD_BINOP(simd_op & 0xffu, WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
FOR_FLOAT32_INPUTS(i) {
if (std::isnan(*i)) continue;
......@@ -392,10 +375,9 @@ WASM_EXEC_TEST(I32x4Splat) {
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
byte lane_val = 0;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(
WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r,
WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
}
......@@ -406,29 +388,23 @@ WASM_EXEC_TEST(I32x4ReplaceLane) {
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd,
WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(
simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val,
old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(simd,
WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
CHECK_EQ(1, r.Call(1, 2));
}
......@@ -441,10 +417,9 @@ WASM_EXEC_TEST(I16x8Splat) {
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
byte lane_val = 0;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(
WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r,
WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val), WASM_ONE);
FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
}
......@@ -455,49 +430,46 @@ WASM_EXEC_TEST(I16x8ReplaceLane) {
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, old_val,
old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
new_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
new_val, new_val, old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, old_val, old_val,
old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, old_val,
old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
new_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val), WASM_ONE);
CHECK_EQ(1, r.Call(1, 2));
}
......@@ -508,10 +480,9 @@ WASM_EXEC_TEST(I8x16Splat) {
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
byte lane_val = 0;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(
WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r,
WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(lane_val))),
WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val), WASM_ONE);
FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
}
......@@ -522,119 +493,101 @@ WASM_EXEC_TEST(I8x16ReplaceLane) {
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, old_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(8, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(9, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, old_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(10, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, old_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(11, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, old_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(12, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
old_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(13, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, old_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(14, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val,
new_val, new_val, old_val),
WASM_SET_LOCAL(
simd, WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(old_val))),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
old_val, old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, old_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, old_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, old_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, old_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(8, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, old_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(9, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
old_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(10, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
new_val, old_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(11, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
new_val, new_val, old_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(12, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, old_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(13, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, old_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(14, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, new_val,
new_val, new_val, new_val, new_val, new_val, old_val),
WASM_SET_LOCAL(simd,
WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd),
WASM_GET_LOCAL(new_val))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val), WASM_ONE);
CHECK_EQ(1, r.Call(1, 2));
}
......@@ -689,15 +642,12 @@ WASM_EXEC_TEST(I32x4FromFloat32x4) {
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
byte simd2 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd1, WASM_SIMD_I32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
WASM_SET_LOCAL(
simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned),
WASM_RETURN1(WASM_ONE)));
BUILD(
r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
WASM_SET_LOCAL(simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE);
FOR_FLOAT32_INPUTS(i) {
int32_t signed_value = ConvertToInt(*i, false);
......@@ -712,12 +662,10 @@ void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) {
byte a = 0;
byte expected = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd,
WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
}
......@@ -733,14 +681,12 @@ void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
byte expected = 2;
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1,
WASM_SIMD_BINOP(simd_op & 0xffu, WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
......@@ -788,12 +734,10 @@ void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) {
byte a = 0;
byte expected = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd,
WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
}
......@@ -808,14 +752,12 @@ void RunI16x8BinOpTest(WasmOpcode simd_op, Int16BinOp expected_op) {
byte expected = 2;
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1,
WASM_SIMD_BINOP(simd_op & 0xffu, WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected), WASM_ONE);
FOR_INT16_INPUTS(i) {
FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
......@@ -862,12 +804,10 @@ void RunI8x16UnOpTest(WasmOpcode simd_op, Int8UnOp expected_op) {
byte a = 0;
byte expected = 1;
byte simd = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(
simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd,
WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE);
FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
}
......@@ -882,14 +822,12 @@ void RunI8x16BinOpTest(WasmOpcode simd_op, Int8BinOp expected_op) {
byte expected = 2;
byte simd0 = r.AllocateLocal(kWasmS128);
byte simd1 = r.AllocateLocal(kWasmS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected),
WASM_RETURN1(WASM_ONE)));
BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
WASM_SET_LOCAL(simd1,
WASM_SIMD_BINOP(simd_op & 0xffu, WASM_GET_LOCAL(simd0),
WASM_GET_LOCAL(simd1))),
WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected), WASM_ONE);
FOR_INT8_INPUTS(i) {
FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
......
......@@ -727,7 +727,7 @@ WASM_EXEC_TEST(Return12) {
WASM_EXEC_TEST(Return17) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK(RET_I8(17)));
BUILD(r, WASM_BLOCK(RET_I8(17)), WASM_ZERO);
CHECK_EQ(17, r.Call());
}
......@@ -836,11 +836,10 @@ WASM_EXEC_TEST(BrIf_strict) {
WASM_EXEC_TEST(Br_height) {
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(0)),
WASM_RETURN1(WASM_I32V_1(9)),
WASM_I32V_1(7), WASM_I32V_1(7)),
WASM_BRV(0, WASM_I32V_1(8))));
BUILD(r, WASM_BLOCK_I(
WASM_BLOCK(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)),
WASM_RETURN1(WASM_I32V_1(9))),
WASM_BRV(0, WASM_I32V_1(8))));
for (int32_t i = 0; i < 5; i++) {
int32_t expected = i != 0 ? 8 : 9;
......@@ -1277,7 +1276,8 @@ WASM_EXEC_TEST(Block_IfElse_P_return) {
BUILD(r, // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
RET_I8(81), // --
RET_I8(82))); // --
RET_I8(82)), // --
WASM_ZERO); // --
FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 81 : 82;
CHECK_EQ(expected, r.Call(*i));
......@@ -1298,7 +1298,7 @@ WASM_EXEC_TEST(Block_If_P_assign) {
WASM_EXEC_TEST(DanglingAssign) {
WasmRunner<int32_t, int32_t> r(execution_mode);
// { return 0; p0 = 0; }
BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
BUILD(r, WASM_BLOCK_I(RET_I8(99), WASM_TEE_LOCAL(0, WASM_ZERO)));
CHECK_EQ(99, r.Call(1));
}
......@@ -1764,7 +1764,7 @@ WASM_EXEC_TEST(MemF64_Mul) {
WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) {
WasmRunner<int32_t, int32_t> r(execution_mode);
// Only build the graph and compile, don't run.
BUILD(r, WASM_INFINITE_LOOP);
BUILD(r, WASM_INFINITE_LOOP, WASM_ZERO);
}
WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
......@@ -1807,24 +1807,33 @@ TEST(Build_Wasm_Unreachable3) {
TEST(Build_Wasm_UnreachableIf1) {
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
BUILD(r, WASM_UNREACHABLE,
WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_GET_LOCAL(0), WASM_DROP)),
WASM_ZERO);
}
TEST(Build_Wasm_UnreachableIf2) {
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE,
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
}
WASM_EXEC_TEST(Unreachable_Load) {
WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().AddMemory(0L);
r.module().AddMemory(8);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)),
WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
CHECK_EQ(11, r.Call(11));
CHECK_EQ(21, r.Call(21));
}
WASM_EXEC_TEST(BrV_Fallthrough) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BLOCK(WASM_BRV(1, WASM_I32V_1(42))),
WASM_I32V_1(22)));
CHECK_EQ(42, r.Call());
}
WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I32V_1(45));
......@@ -1834,9 +1843,10 @@ WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0),
WASM_BRV(1, WASM_I32V_1(45)),
WASM_INFINITE_LOOP)));
BUILD(r, WASM_BLOCK_I(
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(45)),
WASM_INFINITE_LOOP),
WASM_ZERO));
// Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(1));
}
......
......@@ -264,7 +264,7 @@ TEST(WasmStepInAndOut) {
WASM_SET_LOCAL(
0, WASM_BINOP(kExprI32Sub, WASM_GET_LOCAL(0), WASM_ONE)),
WASM_CALL_FUNCTION(runner.function_index(), WASM_GET_LOCAL(0)),
WASM_BR(1)));
WASM_DROP, WASM_BR(1)));
Isolate* isolate = runner.main_isolate();
Handle<JSFunction> main_fun_wrapper =
......
......@@ -39,7 +39,8 @@ let nop = kExprNop;
let iadd = kExprI32Add;
let unr = kExprUnreachable;
let ret = kExprReturn;
let br0 = [kExprBr, 0]
let br0 = [kExprBr, 0];
let brt = [kExprBrTable, 0, 0];
let f32 = [kExprF32Const, 0, 0, 0, 0];
let zero = [kExprI32Const, 0];
let if_else_empty = [kExprIf, kWasmStmt, kExprElse, kExprEnd];
......@@ -51,7 +52,7 @@ let block_block_unr = [kExprBlock, kWasmStmt, kExprBlock, kWasmStmt, kExprUnreac
let drop = kExprDrop;
run(V, "U", [unr]);
run(V, "U U", [unr, unr]);
run(V, 'U U', [unr, unr]);
run(V, "(if 0 () else ())", [...zero, ...if_else_empty]);
run(V, "(if 0 U)", [...zero, ...if_unr]);
run(V, "(if 0 U U)", [...zero, ...if_else_unr]);
......@@ -64,26 +65,33 @@ run(V, "(block U)", [...block_unr]);
run(V, "(loop U)", [...loop_unr]);
run(V, "(if 0 U U)", [...zero, ...if_else_unr]);
run(V, "U nop", [unr, nop]);
run(V, "U iadd drop", [unr, iadd, drop]);
run(V, "br0 iadd drop", [br0, iadd, drop]);
run(V, "ret iadd drop", [ret, iadd, drop]);
run(V, "br0 iadd", [br0, iadd]);
run(V, "ret iadd", [ret, iadd]);
run(V, "0 0 br0 iadd", [...zero, ...zero, br0, iadd]);
run(V, "0 0 ret iadd", [...zero, ...zero, ret, iadd]);
run(V, "(block U) iadd drop", [...block_unr, iadd, drop]);
run(V, "(block (block U)) iadd drop", [...block_block_unr, iadd, drop]);
run(V, "(loop U) iadd drop", [...loop_unr, iadd]);
run(V, "(if 0 U U) iadd drop", [...zero, ...if_else_unr, iadd, drop]);
run(V, "U 0 0 iadd drop", [unr, ...zero, ...zero, iadd, drop]);
run(V, 'U nop', [unr, nop]);
run(V, 'U iadd drop', [unr, iadd, drop]);
run(V, 'br0 iadd drop', [...br0, iadd, drop]);
run(V, '0 brt iadd drop', [...zero, ...brt, iadd, drop]);
run(V, 'ret iadd drop', [ret, iadd, drop]);
run(V, 'U 0 0 iadd drop', [unr, ...zero, ...zero, iadd, drop]);
run(V, 'br0 0 0 iadd drop', [...br0, ...zero, ...zero, iadd, drop]);
run(V, '0 brt 0 0 iadd drop', [...zero, ...brt, ...zero, ...zero, iadd, drop]);
run(V, 'ret 0 0 iadd drop', [ret, ...zero, ...zero, iadd, drop]);
run(I, 'br0 iadd', [...br0, iadd]);
run(I, '0 brt iadd', [...zero, ...brt, iadd]);
run(I, 'ret iadd', [ret, iadd]);
run(I, '0 0 br0 iadd', [...zero, ...zero, ...br0, iadd]);
run(I, '0 0 ret iadd', [...zero, ...zero, ret, iadd]);
run(I, '(block U) iadd drop', [...block_unr, iadd, drop]);
run(I, '(block (block U)) iadd drop', [...block_block_unr, iadd, drop]);
run(I, '(loop U) iadd drop', [...loop_unr, iadd]);
run(I, '(if 0 U U) iadd drop', [...zero, ...if_else_unr, iadd, drop]);
run(V, 'U 0 0 iadd drop', [unr, ...zero, ...zero, iadd, drop]);
run(V, "(block U) 0 0 iadd drop", [...block_unr, ...zero, ...zero, iadd, drop]);
run(V, "(loop U) 0 0 iadd drop", [...loop_unr, ...zero, ...zero, iadd, drop]);
run(V, "(block (block U)) 0 0 iadd drop", [...block_block_unr, ...zero, ...zero, iadd, drop]);
run(V, "0 0 U iadd drop", [...zero, ...zero, unr, iadd, drop]);
run(V, '0 0 U iadd drop', [...zero, ...zero, unr, iadd, drop]);
run(V, "0 0 (block U) iadd drop", [...zero, ...zero, ...block_unr, iadd, drop]);
run(V, "0 0 (loop U) iadd drop", [...zero, ...zero, ...loop_unr, iadd, drop]);
run(V, "0 0 (block (block U)) iadd drop", [...zero, ...zero, ...block_block_unr, iadd, drop]);
......@@ -96,10 +104,10 @@ run(I, "(block U) 0f 0 iadd drop", [...block_unr, ...f32, ...zero, iadd, drop]);
run(I, "(loop U) 0f 0 iadd drop", [...loop_unr, ...f32, ...zero, iadd, drop]);
run(I, "(block (block U)) 0f 0 iadd drop", [...block_block_unr, ...f32, ...zero, iadd, drop]);
run(V, "0f U iadd drop", [...f32, unr, iadd, drop]);
run(V, "0f 0 U iadd drop", [...f32, ...zero, unr, iadd, drop]);
run(V, '0f U iadd drop', [...f32, unr, iadd, drop]);
run(V, '0f 0 U iadd drop', [...f32, ...zero, unr, iadd, drop]);
run(I, "0f 0 (block U) iadd drop", [...f32, ...zero, ...block_unr, iadd, drop]);
run(V, "0f U 0 iadd drop", [...f32, unr, ...zero, iadd, drop]);
run(V, '0f U 0 iadd drop', [...f32, unr, ...zero, iadd, drop]);
run(I, "0 U 0f iadd drop", [...zero, unr, ...zero, ...f32, iadd, drop]);
run(I, "0f (block U) 0 iadd drop", [...f32, ...block_unr, ...zero, iadd, drop]);
run(I, "0 (block U) 0f iadd drop", [...zero, ...block_unr, ...f32, iadd, drop]);
......@@ -671,7 +671,7 @@ TEST_F(FunctionBodyDecoderTest, Block3_continue) {
}
TEST_F(FunctionBodyDecoderTest, NestedBlock_return) {
EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))));
EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))), WASM_ZERO);
}
TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
......@@ -861,13 +861,18 @@ TEST_F(FunctionBodyDecoderTest, Loop2_break) {
EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1)));
}
TEST_F(FunctionBodyDecoderTest, InfiniteLoop) {
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)));
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO)));
TEST_F(FunctionBodyDecoderTest, InfiniteLoop1) {
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO);
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO);
EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BRV(1, WASM_ZERO)));
}
TEST_F(FunctionBodyDecoderTest, InfiniteLoop2) {
EXPECT_FAILURE(i_i, WASM_LOOP(WASM_BR(0), WASM_ZERO), WASM_ZERO);
}
TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) {
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP));
EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BR(0), WASM_NOP));
}
TEST_F(FunctionBodyDecoderTest, LoopType) {
......@@ -926,25 +931,45 @@ TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
}
TEST_F(FunctionBodyDecoderTest, Unreachable1) {
EXPECT_VERIFIES(v_v, kExprUnreachable);
EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable);
EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO));
EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO));
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
EXPECT_VERIFIES(v_v, WASM_UNREACHABLE);
EXPECT_VERIFIES(v_v, WASM_UNREACHABLE, WASM_UNREACHABLE);
EXPECT_VERIFIES(i_i, WASM_UNREACHABLE, WASM_ZERO);
}
TEST_F(FunctionBodyDecoderTest, Unreachable2) {
EXPECT_FAILURE(v_v, B2(WASM_UNREACHABLE, WASM_ZERO));
EXPECT_FAILURE(v_v, B2(WASM_BR(0), WASM_ZERO));
}
TEST_F(FunctionBodyDecoderTest, Unreachable_binop) {
TEST_F(FunctionBodyDecoderTest, UnreachableLoop1) {
EXPECT_FAILURE(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
EXPECT_FAILURE(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_NOP));
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_NOP));
}
TEST_F(FunctionBodyDecoderTest, Unreachable_binop1) {
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
}
TEST_F(FunctionBodyDecoderTest, Unreachable_select) {
TEST_F(FunctionBodyDecoderTest, Unreachable_binop2) {
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_F32(0.0), WASM_UNREACHABLE));
EXPECT_FAILURE(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_F32(0.0)));
}
TEST_F(FunctionBodyDecoderTest, Unreachable_select1) {
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO));
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE));
}
TEST_F(FunctionBodyDecoderTest, Unreachable_select2) {
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_F32(0.0), WASM_UNREACHABLE, WASM_ZERO));
EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_F32(0.0), WASM_ZERO));
EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_F32(0.0)));
}
TEST_F(FunctionBodyDecoderTest, If1) {
EXPECT_VERIFIES(
i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8)));
......@@ -2133,15 +2158,20 @@ TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br2) {
}
}
TEST_F(FunctionBodyDecoderTest, BrUnreachable) {
static byte code[] = {WASM_GET_LOCAL(0), kExprBrTable, 0,
BR_TARGET(0), kExprSetLocal, 0};
EXPECT_VERIFIES_C(v_i, code);
TEST_F(FunctionBodyDecoderTest, BrUnreachable1) {
EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0));
}
TEST_F(FunctionBodyDecoderTest, BrUnreachable2) {
EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0),
WASM_NOP);
EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0),
WASM_ZERO);
}
TEST_F(FunctionBodyDecoderTest, Brv1) {
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO)));
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO))));
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP_I(WASM_BRV(2, WASM_ZERO))));
}
TEST_F(FunctionBodyDecoderTest, Brv1_type) {
......
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