Commit 7ed3c4d7 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Remove non-standard kExprI8Const bytecode

R=clemensh@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2595733003
Cr-Commit-Position: refs/heads/master@{#42141}
parent 9c7b8726
......@@ -1067,7 +1067,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
void VisitPropertyAndEmitIndex(Property* expr, AsmType** atype) {
Expression* obj = expr->obj();
*atype = typer_->TypeOf(obj);
int size = (*atype)->ElementSizeInBytes();
int32_t size = (*atype)->ElementSizeInBytes();
if (size == 1) {
// Allow more general expression in byte arrays than the spec
// strictly permits.
......@@ -1095,9 +1095,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
1 << static_cast<int>(
binop->right()->AsLiteral()->raw_value()->AsNumber()));
// Mask bottom bits to match asm.js behavior.
byte mask = static_cast<byte>(~(size - 1));
RECURSE(Visit(binop->left()));
current_function_builder_->EmitWithU8(kExprI8Const, mask);
current_function_builder_->EmitI32Const(~(size - 1));
current_function_builder_->Emit(kExprI32And);
return;
}
......@@ -1236,7 +1235,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
// if set_local(tmp, x) < 0
Visit(call->arguments()->at(0));
current_function_builder_->EmitTeeLocal(tmp.index());
byte code[] = {WASM_I8(0)};
byte code[] = {WASM_ZERO};
current_function_builder_->EmitCode(code, sizeof(code));
current_function_builder_->Emit(kExprI32LtS);
current_function_builder_->EmitWithU8(kExprIf, kLocalI32);
......
......@@ -422,8 +422,6 @@ class WasmDecoder : public Decoder {
MemoryIndexOperand operand(decoder, pc);
return 1 + operand.length;
}
case kExprI8Const:
return 2;
case kExprF32Const:
return 5;
case kExprF64Const:
......@@ -993,12 +991,6 @@ class WasmFullDecoder : public WasmDecoder {
EndControl();
break;
}
case kExprI8Const: {
ImmI8Operand operand(this, pc_);
Push(kWasmI32, BUILD(Int32Constant, operand.value));
len = 1 + operand.length;
break;
}
case kExprI32Const: {
ImmI32Operand operand(this, pc_);
Push(kWasmI32, BUILD(Int32Constant, operand.value));
......
......@@ -1355,12 +1355,6 @@ class ThreadImpl : public WasmInterpreter::Thread {
blocks_.pop_back();
break;
}
case kExprI8Const: {
ImmI8Operand operand(&decoder, code->at(pc));
Push(pc, WasmVal(operand.value));
len = 1 + operand.length;
break;
}
case kExprI32Const: {
ImmI32Operand operand(&decoder, code->at(pc));
Push(pc, WasmVal(operand.value));
......
......@@ -140,9 +140,8 @@
// Misc expressions.
//------------------------------------------------------------------------------
#define WASM_ID(...) __VA_ARGS__
#define WASM_ZERO kExprI8Const, 0
#define WASM_ONE kExprI8Const, 1
#define WASM_I8(val) kExprI8Const, static_cast<byte>(val)
#define WASM_ZERO kExprI32Const, 0
#define WASM_ONE kExprI32Const, 1
#define I32V_MIN(length) -(1 << (6 + (7 * ((length) - 1))))
#define I32V_MAX(length) ((1 << (6 + (7 * ((length) - 1)))) - 1)
......@@ -447,15 +446,15 @@ class LocalDeclEncoder {
#define WASM_WHILE(x, y) \
kExprLoop, kLocalVoid, x, kExprIf, kLocalVoid, y, kExprBr, DEPTH_1, \
kExprEnd, kExprEnd
#define WASM_INC_LOCAL(index) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, 1, kExprI32Add, \
#define WASM_INC_LOCAL(index) \
kExprGetLocal, static_cast<byte>(index), kExprI32Const, 1, kExprI32Add, \
kExprTeeLocal, static_cast<byte>(index)
#define WASM_INC_LOCAL_BYV(index, count) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, \
kExprGetLocal, static_cast<byte>(index), kExprI32Const, \
static_cast<byte>(count), kExprI32Add, kExprTeeLocal, \
static_cast<byte>(index)
#define WASM_INC_LOCAL_BY(index, count) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, \
kExprGetLocal, static_cast<byte>(index), kExprI32Const, \
static_cast<byte>(count), kExprI32Add, kExprSetLocal, \
static_cast<byte>(index)
#define WASM_UNOP(opcode, x) x, static_cast<byte>(opcode)
......
......@@ -122,10 +122,10 @@ void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode,
}
void WasmFunctionBuilder::EmitI32Const(int32_t value) {
// TODO(titzer): variable-length signed and unsigned i32 constants.
if (-128 <= value && value <= 127) {
EmitWithU8(kExprI8Const, static_cast<byte>(value));
if (-64 <= value && value <= 63) {
EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F));
} else {
// TODO(titzer): variable-length signed and unsigned i32 constants.
byte code[] = {WASM_I32V_5(value)};
EmitCode(code, sizeof(code));
}
......
......@@ -78,8 +78,7 @@ const WasmCodePosition kNoCodePosition = -1;
V(I32Const, 0x41, _) \
V(I64Const, 0x42, _) \
V(F32Const, 0x43, _) \
V(F64Const, 0x44, _) \
V(I8Const, 0xcb, _ /* TODO(titzer): V8 specific, remove */)
V(F64Const, 0x44, _)
// Load memory expressions.
#define FOREACH_LOAD_MEM_OPCODE(V) \
......
......@@ -263,7 +263,6 @@ void wasm::PrintWasmText(const WasmModule *module,
os << #str ".const " << static_cast<cast_type>(operand.value); \
break; \
}
CASE_CONST(I8, i8, int32_t)
CASE_CONST(I32, i32, int32_t)
CASE_CONST(I64, i64, int64_t)
CASE_CONST(F32, f32, float)
......
......@@ -1188,15 +1188,15 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
byte* memory = r.module().AddMemoryElems<byte>(16);
byte code[] = {
kExprI8Const, 8, // --
kExprI8Const, 0, // --
kExprI32Const, 8, // --
kExprI32Const, 0, // --
loads[m], // --
ZERO_ALIGNMENT, // --
ZERO_OFFSET, // --
kExprI64StoreMem, // --
ZERO_ALIGNMENT, // --
ZERO_OFFSET, // --
kExprI8Const, 0, // --
kExprI32Const, 0, // --
loads[m], // --
ZERO_ALIGNMENT, // --
ZERO_OFFSET, // --
......@@ -1316,7 +1316,7 @@ WASM_EXEC_TEST(LoadMemI64) {
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0)));
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
......@@ -1336,7 +1336,7 @@ WASM_EXEC_TEST(LoadMemI64_alignment) {
r.module().RandomizeMemory(1111);
BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment));
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, alignment));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
......@@ -1359,17 +1359,16 @@ WASM_EXEC_TEST(MemI64_Sum) {
uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems);
const byte kSum = r.AllocateLocal(kWasmI64);
BUILD(
r,
WASM_WHILE(
WASM_GET_LOCAL(0),
WASM_BLOCK(
WASM_SET_LOCAL(kSum,
WASM_I64_ADD(WASM_GET_LOCAL(kSum),
BUILD(r, WASM_WHILE(
WASM_GET_LOCAL(0),
WASM_BLOCK(
WASM_SET_LOCAL(
kSum, WASM_I64_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Int64(),
WASM_GET_LOCAL(0)))),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))),
WASM_GET_LOCAL(1));
WASM_SET_LOCAL(
0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(8))))),
WASM_GET_LOCAL(1));
// Run 4 trials.
for (int i = 0; i < 3; i++) {
......@@ -1510,7 +1509,7 @@ static void CompileCallIndirectMany(ValueType param) {
for (byte p = 0; p < num_params; p++) {
ADD_CODE(code, kExprGetLocal, p);
}
ADD_CODE(code, kExprI8Const, 0);
ADD_CODE(code, kExprI32Const, 0);
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
......@@ -1562,7 +1561,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Load the arguments.
for (int i = 0; i < num_params; i++) {
int offset = (i + 1) * kElemSize;
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I32V_2(offset)));
}
// Call the selector function.
......
......@@ -30,20 +30,21 @@ TEST(Run_WasmInt8Const_i) {
WasmRunner<int32_t> r(kExecuteInterpreted);
const byte kExpectedValue = 109;
// return(kExpectedValue)
BUILD(r, WASM_I8(kExpectedValue));
BUILD(r, WASM_I32V_2(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
TEST(Run_WasmIfElse) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(10)));
CHECK_EQ(10, r.Call(0));
CHECK_EQ(9, r.Call(1));
}
TEST(Run_WasmIfReturn) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I32V_2(77))),
WASM_I32V_2(65));
CHECK_EQ(65, r.Call(0));
CHECK_EQ(77, r.Call(1));
}
......@@ -54,7 +55,7 @@ TEST(Run_WasmNopsN) {
for (int nops = 0; nops < kMaxNops; nops++) {
byte expected = static_cast<byte>(20 + nops);
memset(code, kExprNop, sizeof(code));
code[nops] = kExprI8Const;
code[nops] = kExprI32Const;
code[nops + 1] = expected;
WasmRunner<int32_t> r(kExecuteInterpreted);
......@@ -64,13 +65,13 @@ TEST(Run_WasmNopsN) {
}
TEST(Run_WasmConstsN) {
const int kMaxConsts = 10;
const int kMaxConsts = 5;
byte code[kMaxConsts * 3];
int32_t expected = 0;
for (int count = 1; count < kMaxConsts; count++) {
for (int i = 0; i < count; i++) {
byte val = static_cast<byte>(count * 10 + i);
code[i * 3] = kExprI8Const;
code[i * 3] = kExprI32Const;
code[i * 3 + 1] = val;
if (i == (count - 1)) {
code[i * 3 + 2] = kExprNop;
......@@ -95,7 +96,7 @@ TEST(Run_WasmBlocksN) {
memset(code, kExprNop, sizeof(code));
code[0] = kExprBlock;
code[1] = kLocalI32;
code[2 + nops] = kExprI8Const;
code[2 + nops] = kExprI32Const;
code[2 + nops + 1] = expected;
code[2 + nops + 2] = kExprEnd;
......@@ -108,6 +109,7 @@ TEST(Run_WasmBlocksN) {
TEST(Run_WasmBlockBreakN) {
const int kMaxNops = 10;
const int kExtra = 6;
int run = 0;
byte code[kMaxNops + kExtra];
for (int nops = 0; nops < kMaxNops; nops++) {
// Place the break anywhere within the block.
......@@ -117,8 +119,8 @@ TEST(Run_WasmBlockBreakN) {
code[1] = kLocalI32;
code[sizeof(code) - 1] = kExprEnd;
int expected = nops * 11 + index;
code[2 + index + 0] = kExprI8Const;
int expected = run++;
code[2 + index + 0] = kExprI32Const;
code[2 + index + 1] = static_cast<byte>(expected);
code[2 + index + 2] = kExprBr;
code[2 + index + 3] = 0;
......@@ -133,10 +135,12 @@ TEST(Run_WasmBlockBreakN) {
TEST(Run_Wasm_nested_ifs_i) {
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
BUILD(
r,
WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14))));
CHECK_EQ(11, r.Call(1, 1));
CHECK_EQ(12, r.Call(1, 0));
......
......@@ -75,7 +75,7 @@ TEST(Run_WasmModule_Return114) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f);
byte code[] = {WASM_I8(kReturnValue)};
byte code[] = {WASM_I32V_2(kReturnValue)};
f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kReturnValue);
}
......@@ -101,7 +101,7 @@ TEST(Run_WasmModule_CallAdd) {
ExportAsMain(f2);
byte code2[] = {
WASM_CALL_FUNCTION(f1->func_index(), WASM_I8(77), WASM_I8(22))};
WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))};
f2->EmitCode(code2, sizeof(code2));
TestModule(&zone, builder, 99);
}
......@@ -120,7 +120,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) {
ExportAsMain(f);
byte code[] = {
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))};
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))};
f->EmitCode(code, sizeof(code));
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0);
......@@ -146,8 +146,9 @@ TEST(Run_WasmModule_CheckMemoryIsZero) {
WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)),
WASM_IF_ELSE(
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I8(11))};
WASM_BRV(3, WASM_I32V_1(-1)),
WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I32V_1(11))};
f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 11);
}
......@@ -168,11 +169,11 @@ TEST(Run_WasmModule_CallMain_recursive) {
byte code[] = {
WASM_SET_LOCAL(localIndex,
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)),
WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_1(5)),
WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
WASM_INC_LOCAL(localIndex)),
WASM_CALL_FUNCTION0(0)),
WASM_I8(55))};
WASM_I32V_1(55))};
f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 55);
}
......@@ -441,7 +442,8 @@ TEST(Run_WasmModule_MemSize_GrowMem) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_DROP, WASM_MEMORY_SIZE};
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP,
WASM_MEMORY_SIZE};
f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kExpectedValue);
}
......@@ -589,7 +591,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)),
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)),
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value))};
f->EmitCode(code, sizeof(code));
......@@ -659,7 +661,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP,
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP,
WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0),
WASM_I32V(value)),
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))};
......
This diff is collapsed.
......@@ -13,8 +13,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("foo", kSig_i_v)
.addBody([
kExprI32Const, 0x00,
kExprI8Const, 0xcb,
kExprI8Const, 0xff,
kExprI32Const, 0x0b,
kExprI32Const, 0x0f,
kExprBrTable, 0xcb, 0xcb, 0xcb, 0x00, 0x00, 0xcb, 0x00 // entries=1238475
])
.exportFunc();
......
// Copyright 2016 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
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
var wire_bytes = readbuffer("test/mjsunit/regress/wasm/665402.wasm");
var module = new WebAssembly.Module(wire_bytes);
assertTrue(module != undefined);
......@@ -11,12 +11,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder();
builder.addFunction("test", kSig_i_iii)
.addBody([
kExprI8Const, 0xcb,
kExprI32Const, 0x0b,
kExprI32Clz,
kExprI32Clz,
kExprI32Clz,
kExprI32Const, 0x67,
kExprI8Const, 0x67,
kExprI32Const, 0x07,
kExprI32Clz,
kExprI32Clz,
kExprI32Clz,
......@@ -407,7 +407,7 @@ kExprNop,
kExprI64DivU,
kExprUnreachable,
kExprI32GeS,
kExprI8Const, 0xcb,
kExprI32Const, 0x0b,
])
.exportFunc();
var module = builder.instantiate();
......
......@@ -66,7 +66,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function RelationBetweenModuleAndClone() {
let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, 42])
.addBody([kExprI32Const, 42])
.exportFunc();
var wire_bytes = builder.toBuffer();
......@@ -83,7 +83,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function SerializeAfterInstantiation() {
let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, 42])
.addBody([kExprI32Const, 42])
.exportFunc();
var wire_bytes = builder.toBuffer()
......
......@@ -9,12 +9,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testExportedMain() {
print("TestExportedMain...");
var kReturnValue = 88;
var kReturnValue = 44;
var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([
kExprI8Const,
kExprI32Const,
kReturnValue,
kExprReturn
])
......@@ -30,13 +30,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testExportedTwice() {
print("TestExportedTwice...");
var kReturnValue = 99;
var kReturnValue = 45;
var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([
kExprI8Const,
kExprI32Const,
kReturnValue,
kExprReturn
])
......@@ -56,13 +56,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testEmptyName() {
print("TestEmptyName...");
var kReturnValue = 93;
var kReturnValue = 46;
var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([
kExprI8Const,
kExprI32Const,
kReturnValue,
kExprReturn
])
......@@ -78,13 +78,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testNumericName() {
print("TestNumericName...");
var kReturnValue = 93;
var kReturnValue = 47;
var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v)
.addBody([
kExprI8Const,
kExprI32Const,
kReturnValue,
kExprReturn
])
......
......@@ -247,7 +247,7 @@ function testCallBinopVoid(type, func, check) {
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallFunction, 0, // --
kExprI8Const, 99 // --
kExprI32Const, 33 // --
]) // --
.exportFunc()
......@@ -258,7 +258,7 @@ function testCallBinopVoid(type, func, check) {
for (var i = 0; i < 100000; i += 10003.1) {
var a = 22.5 + i, b = 10.5 + i;
var r = main(a, b);
assertEquals(99, r);
assertEquals(33, r);
assertEquals(2, passed_length);
var expected_a, expected_b;
switch (type) {
......@@ -299,7 +299,7 @@ testCallBinopVoid(kWasmF64);
builder.addImport("", "print", makeSig_v_x(kWasmF64));
builder.addFunction("main", makeSig_v_x(kWasmF64))
.addBody([
kExprI8Const, 97, // --
kExprI32Const, 37, // --
kExprCallFunction, 0, // --
kExprGetLocal, 0, // --
kExprCallFunction, 1 // --
......
......@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder();
var f = builder.addFunction("nine", kSig_i_v)
.addBody([kExprI8Const, 9])
.addBody([kExprI32Const, 9])
.exportFunc();
var func = builder.instantiate().exports.nine;
......
......@@ -190,7 +190,7 @@ function testCallBinopVoid(type, func, check) {
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallFunction, 0, // --
kExprI8Const, 99, // --
kExprI32Const, 39, // --
])
.exportFunc("main");
......@@ -201,7 +201,7 @@ function testCallBinopVoid(type, func, check) {
for (var i = 0; i < 100000; i += 10003.1) {
var a = 22.5 + i, b = 10.5 + i;
var r = main(a, b);
assertEquals(99, r);
assertEquals(39, r);
assertEquals(2, passed_length);
var expected_a, expected_b;
switch (type) {
......@@ -243,9 +243,9 @@ function testCallPrint() {
builder.addImport("q", "print", makeSig_r_x(kWasmF64, kWasmF64));
builder.addFunction("main", makeSig_r_x(kWasmF64, kWasmF64))
.addBody([
kExprI8Const, 97, // --
kExprI32Const, 27, // --
kExprCallFunction, 0, // --
kExprGetLocal, 0, // --
kExprGetLocal, 0, // --
kExprCallFunction, 1 // --
])
.exportFunc();
......
......@@ -7,13 +7,13 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
let kReturnValue = 117;
let kReturnValue = 17;
let buffer = (() => {
let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, kReturnValue])
.addBody([kExprI32Const, kReturnValue])
.exportFunc();
return builder.toBuffer();
......
......@@ -8,11 +8,11 @@ load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function BasicTest() {
var kReturnValue = 107;
var kReturnValue = 15;
var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_i)
.addBody([kExprI8Const, kReturnValue])
.addBody([kExprI32Const, kReturnValue])
.exportFunc();
var main = builder.instantiate().exports.main;
......
......@@ -17,23 +17,23 @@ function genModule(memory) {
.addBody([
// main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0;
// TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc
/**/ kExprLoop, kWasmStmt, // --
/**/ kExprLoop, kWasmStmt, // --
/* */ kExprGetLocal, 0, // --
/* */ kExprIf, kWasmStmt, // --
/* */ kExprIf, kWasmStmt, // --
/* */ kExprGetLocal, 0, // --
/* */ kExprI32LoadMem, 0, 0, // --
/* */ kExprIf, kWasmStmt, // --
/* */ kExprI8Const, 255, // --
/* */ kExprIf, kWasmStmt, // --
/* */ kExprI32Const, 127, // --
/* */ kExprReturn, // --
/* */ kExprEnd, // --
/* */ kExprGetLocal, 0, // --
/* */ kExprI8Const, 4, // --
/* */ kExprI32Const, 4, // --
/* */ kExprI32Sub, // --
/* */ kExprSetLocal, 0, // --
/* */ kExprBr, 1, // --
/* */ kExprEnd, // --
/* */ kExprEnd, // --
/**/ kExprI8Const, 0 // --
/**/ kExprI32Const, 0 // --
])
.exportFunc();
var module = builder.instantiate(null, memory);
......
......@@ -33,7 +33,7 @@ assertVerifies(kSig_v_v, [kExprNop]);
assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
(function testInvalidIndex() {
print("testInvalidIndex");
......@@ -69,14 +69,14 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 66, kExprI32StoreMem, 0, 0]);
.addBody([kExprI32Const, 0, kExprI32Const, 55, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index);
var module = builder.instantiate();
var memory = module.exports.memory.buffer;
var view = new Int8Array(memory);
assertEquals(66, view[0]);
assertEquals(55, view[0]);
})();
(function testRun2() {
......@@ -86,7 +86,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 22, kExprI8Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]);
.addBody([kExprI32Const, 0, kExprI32Const, 22, kExprI32Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index);
......
......@@ -17,7 +17,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder();
builder.addMemory(1, 2, false);
builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 11])
.addBody([kExprI32Const, 11])
.exportAs("blarg");
var buffer = builder.toBuffer(debug);
......@@ -29,7 +29,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder();
var index = builder.addImport("", "print", makeSig_v_x(kWasmI32));
builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 13, kExprCallFunction, index])
.addBody([kExprI32Const, 13, kExprCallFunction, index])
.exportAs("main");
var buffer = builder.toBuffer(debug);
......@@ -121,7 +121,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder();
builder.addMemory(1, 2, false);
builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 17])
.addBody([kExprI32Const, 17])
.exportAs("blarg");
var buffer = builder.toBuffer(debug);
......@@ -147,7 +147,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder();
var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32));
builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 19, kExprCallFunction, index])
.addBody([kExprI32Const, 19, kExprCallFunction, index])
.exportAs("main");
var buffer = builder.toBuffer(debug);
......
......@@ -167,7 +167,6 @@ let kExprI32Const = 0x41;
let kExprI64Const = 0x42;
let kExprF32Const = 0x43;
let kExprF64Const = 0x44;
let kExprI8Const = 0xcb;
let kExprI32LoadMem = 0x28;
let kExprI64LoadMem = 0x29;
let kExprF32LoadMem = 0x2a;
......
......@@ -163,10 +163,10 @@ TEST_F(ControlTransferTest, SimpleIfElse_v1) {
0, // @1
kExprIf, // @2
kLocalVoid, // @3
kExprI8Const, // @4
kExprI32Const, // @4
0, // @5
kExprElse, // @6
kExprI8Const, // @7
kExprI32Const, // @7
0, // @8
kExprEnd // @9
};
......@@ -260,39 +260,39 @@ TEST_F(ControlTransferTest, Br1) {
TEST_F(ControlTransferTest, Br_v1a) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
};
EXPECT_PC_DELTAS({4, 3});
}
TEST_F(ControlTransferTest, Br_v1b) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
};
EXPECT_PC_DELTAS({4, 3});
}
TEST_F(ControlTransferTest, Br_v1c) {
byte code[] = {
kExprI8Const, // @0
0, // @1
kExprBlock, // @2
kLocalVoid, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
kExprI32Const, // @0
0, // @1
kExprBlock, // @2
kLocalVoid, // @3
kExprBr, // @4
0, // @5
kExprEnd // @6
};
EXPECT_PC_DELTAS({4, 3});
}
......@@ -383,80 +383,80 @@ TEST_F(ControlTransferTest, SimpleLoopExit2) {
TEST_F(ControlTransferTest, BrTable0) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprBrTable, // @4
0, // @5
U32V_1(0), // @6
kExprEnd // @7
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprBrTable, // @4
0, // @5
U32V_1(0), // @6
kExprEnd // @7
};
EXPECT_PC_DELTAS({4, 4});
}
TEST_F(ControlTransferTest, BrTable0_v1a) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprI8Const, // @4
0, // @5
kExprBrTable, // @6
0, // @7
U32V_1(0), // @8
kExprEnd // @9
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprI32Const, // @4
0, // @5
kExprBrTable, // @6
0, // @7
U32V_1(0), // @8
kExprEnd // @9
};
EXPECT_PC_DELTAS({6, 4});
}
TEST_F(ControlTransferTest, BrTable0_v1b) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprI8Const, // @4
0, // @5
kExprBrTable, // @6
0, // @7
U32V_1(0), // @8
kExprEnd // @9
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprI32Const, // @4
0, // @5
kExprBrTable, // @6
0, // @7
U32V_1(0), // @8
kExprEnd // @9
};
EXPECT_PC_DELTAS({6, 4});
}
TEST_F(ControlTransferTest, BrTable1) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprI8Const, // @2
0, // @3
kExprBrTable, // @4
1, // @5
U32V_1(0), // @6
U32V_1(0), // @7
kExprEnd // @8
kExprBlock, // @0
kLocalVoid, // @1
kExprI32Const, // @2
0, // @3
kExprBrTable, // @4
1, // @5
U32V_1(0), // @6
U32V_1(0), // @7
kExprEnd // @8
};
EXPECT_PC_DELTAS({4, 5}, {5, 4});
}
TEST_F(ControlTransferTest, BrTable2) {
byte code[] = {
kExprBlock, // @0
kLocalVoid, // @1
kExprBlock, // @2
kLocalVoid, // @3
kExprI8Const, // @4
0, // @5
kExprBrTable, // @6
2, // @7
U32V_1(0), // @8
U32V_1(0), // @9
U32V_1(1), // @10
kExprEnd, // @11
kExprEnd // @12
kExprBlock, // @0
kLocalVoid, // @1
kExprBlock, // @2
kLocalVoid, // @3
kExprI32Const, // @4
0, // @5
kExprBrTable, // @6
2, // @7
U32V_1(0), // @8
U32V_1(0), // @9
U32V_1(1), // @10
kExprEnd, // @11
kExprEnd // @12
};
EXPECT_PC_DELTAS({6, 6}, {7, 5}, {8, 5});
}
......
......@@ -112,7 +112,7 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) {
TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) {
num_locals = 65000;
for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) {
byte code[] = {WASM_LOOP(WASM_I8(11), kExprSetLocal, U32V_3(i))};
byte code[] = {WASM_LOOP(WASM_I32V_1(11), kExprSetLocal, U32V_3(i))};
BitVector* assigned = Analyze(code, code + arraysize(code));
for (int j = 0; j < assigned->length(); j++) {
......@@ -140,8 +140,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) {
byte code[] = {
WASM_LOOP(WASM_IF(
WASM_GET_LOCAL(0),
WASM_BRV(0, WASM_SET_LOCAL(
3, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))))),
WASM_BRV(0, WASM_SET_LOCAL(3, WASM_I32_SUB(WASM_GET_LOCAL(0),
WASM_I32V_1(1)))))),
WASM_GET_LOCAL(0)};
BitVector* assigned = Analyze(code, code + arraysize(code));
......@@ -164,8 +164,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) {
kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Float32(),
WASM_GET_LOCAL(kIter)))),
WASM_SET_LOCAL(kIter,
WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))),
WASM_SET_LOCAL(
kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I32V_1(4))))),
WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)),
WASM_GET_LOCAL(kIter))};
......
......@@ -22,8 +22,8 @@ TEST_F(WasmMacroGenTest, Constants) {
EXPECT_SIZE(2, WASM_ONE);
EXPECT_SIZE(2, WASM_ZERO);
EXPECT_SIZE(2, WASM_I8(122));
EXPECT_SIZE(2, WASM_I8(254));
EXPECT_SIZE(2, WASM_I32V_1(-22));
EXPECT_SIZE(2, WASM_I32V_1(54));
EXPECT_SIZE(2, WASM_I32V_1(1));
EXPECT_SIZE(3, WASM_I32V_2(200));
......@@ -84,7 +84,7 @@ TEST_F(WasmMacroGenTest, Statements) {
}
TEST_F(WasmMacroGenTest, MacroStatements) {
EXPECT_SIZE(11, WASM_WHILE(WASM_I8(0), WASM_NOP));
EXPECT_SIZE(11, WASM_WHILE(WASM_ZERO, WASM_NOP));
EXPECT_SIZE(7, WASM_INC_LOCAL(0));
EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3));
......
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