Index: test/cctest/interpreter/test-bytecode-generator.cc |
diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc |
index 142fc5922fe934adce959f678b700956b734dd88..6e4b517634fccb19c74f9aa1e3b4947e325e820c 100644 |
--- a/test/cctest/interpreter/test-bytecode-generator.cc |
+++ b/test/cctest/interpreter/test-bytecode-generator.cc |
@@ -74,6 +74,8 @@ class BytecodeGeneratorHelper { |
#define B(x) static_cast<uint8_t>(Bytecode::k##x) |
#define U8(x) static_cast<uint8_t>((x) & 0xff) |
#define R(x) static_cast<uint8_t>(-(x) & 0xff) |
+#define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x)) |
+#define THIS(n) A(0, n) |
#define _ static_cast<uint8_t>(0x5a) |
#if defined(V8_TARGET_LITTLE_ENDIAN) |
#define U16(x) static_cast<uint8_t>((x) & 0xff), \ |
@@ -122,7 +124,7 @@ static void CheckConstant(Handle<Object> expected, Object* actual) { |
template <typename T> |
-static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, |
+static void CheckBytecodeArrayEqual(const ExpectedSnippet<T>& expected, |
Handle<BytecodeArray> actual, |
bool has_unknown = false) { |
CHECK_EQ(actual->frame_size(), expected.frame_size); |
@@ -235,20 +237,18 @@ TEST(PrimitiveExpressions) { |
0 |
}, |
{"var x = 0; return x + 3;", |
- 2 * kPointerSize, |
+ kPointerSize, |
1, |
- 12, |
+ 8, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
- B(Ldar), R(0), // Easy to spot r1 not really needed here. |
- B(Star), R(1), // Dead store. |
B(LdaSmi8), U8(3), // |
- B(Add), R(1), // |
+ B(Add), R(0), // |
B(Return) // |
}, |
0 |
- }}; |
+ }}; |
for (size_t i = 0; i < arraysize(snippets); i++) { |
Handle<BytecodeArray> bytecode_array = |
@@ -264,27 +264,31 @@ TEST(Parameters) { |
ExpectedSnippet<int> snippets[] = { |
{"function f() { return this; }", |
- 0, 1, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, |
+ 0, 1, 3, {B(Ldar), THIS(1), B(Return)}, 0}, |
{"function f(arg1) { return arg1; }", |
- 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, |
+ 0, 2, 3, {B(Ldar), A(1, 2), B(Return)}, 0}, |
{"function f(arg1) { return this; }", |
- 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex - 1), B(Return)}, 0}, |
+ 0, 2, 3, {B(Ldar), THIS(2), B(Return)}, 0}, |
{"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", |
- 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 3), B(Return)}, 0}, |
+ 0, 8, 3, {B(Ldar), A(4, 8), B(Return)}, 0}, |
{"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", |
- 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 7), B(Return)}, 0}, |
+ 0, |
+ 8, |
+ 3, |
+ {B(Ldar), THIS(8), B(Return)}, |
+ 0}, |
{"function f(arg1) { arg1 = 1; }", |
0, 2, 6, |
- {B(LdaSmi8), U8(1), // |
- B(Star), R(helper.kLastParamIndex), // |
- B(LdaUndefined), // |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), A(1, 2), // |
+ B(LdaUndefined), // |
B(Return)}, |
0}, |
{"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", |
0, 5, 6, |
- {B(LdaSmi8), U8(1), // |
- B(Star), R(helper.kLastParamIndex - 2), // |
- B(LdaUndefined), // |
+ {B(LdaSmi8), U8(1), // |
+ B(Star), A(2, 5), // |
+ B(LdaUndefined), // |
B(Return)}, |
0}, |
}; |
@@ -454,104 +458,88 @@ TEST(PropertyLoads) { |
ExpectedSnippet<const char*> snippets[] = { |
{"function f(a) { return a.name; }\nf({name : \"test\"})", |
- 1 * kPointerSize, |
+ 0, |
2, |
- 10, |
+ 6, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(Return), // |
}, |
1, |
{"name"}}, |
{"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})", |
- 1 * kPointerSize, |
+ 0, |
2, |
- 10, |
+ 6, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(Return) // |
}, |
1, |
{"key"}}, |
{"function f(a) { return a[100]; }\nf({100 : \"test\"})", |
- 1 * kPointerSize, |
+ 0, |
2, |
- 10, |
+ 6, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(100), // |
- B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(LdaSmi8), U8(100), // |
+ B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(Return) // |
}, |
0}, |
{"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")", |
- 1 * kPointerSize, |
+ 0, |
3, |
- 10, |
+ 6, |
{ |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(Ldar), A(1, 2), // |
+ B(KeyedLoadICSloppy), A(1, 3), U8(vector->GetIndex(slot1)), // |
+ B(Return) // |
}, |
0}, |
{"function f(a) { var b = a.name; return a[-124]; }\n" |
"f({\"-124\" : \"test\", name : 123 })", |
- 2 * kPointerSize, |
+ kPointerSize, |
2, |
- 21, |
+ 13, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(0), // |
- B(LoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(-124), // |
- B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(-124), // |
+ B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot2)), // |
+ B(Return), // |
}, |
1, |
{"name"}}, |
{"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})", |
- 1 * kPointerSize, |
+ 0, |
2, |
- 12, |
+ 8, |
{ |
// TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" |
// expression, or any other unused literal expression. |
- B(LdaConstant), U8(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(1), // |
- B(LoadICStrict), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LdaConstant), U8(1), // |
+ B(LoadICStrict), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(Return), // |
}, |
2, |
{"use strict", "name"}}, |
{"function f(a, b) { \"use strict\"; return a[b]; }\n" |
"f({arg : \"test\"}, \"arg\")", |
- 1 * kPointerSize, |
+ 0, |
3, |
- 12, |
+ 8, |
{ |
// TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" |
// expression, or any other unused literal expression. |
- B(LdaConstant), U8(0), // |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(Ldar), A(2, 3), // |
+ B(KeyedLoadICStrict), A(1, 3), U8(vector->GetIndex(slot1)), // |
+ B(Return), // |
}, |
1, |
{"use strict"}}}; |
@@ -577,126 +565,109 @@ TEST(PropertyStores) { |
ExpectedSnippet<const char*> snippets[] = { |
{"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", |
- 2 * kPointerSize, |
+ kPointerSize, |
2, |
- 16, |
+ 12, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(1), // |
- B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
2, |
{"name", "val"}}, |
{"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})", |
- 2 * kPointerSize, |
+ kPointerSize, |
2, |
- 16, |
+ 12, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(1), // |
- B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
2, |
{"key", "val"}}, |
{"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})", |
- 2 * kPointerSize, |
+ kPointerSize, |
2, |
- 16, |
+ 12, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaSmi8), U8(100), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(0), // |
- B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaSmi8), U8(100), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(0), // |
+ B(KeyedStoreICSloppy), A(1, 2), R(0), // |
+ U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
1, |
{"val"}}, |
{"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")", |
- 2 * kPointerSize, |
+ 0, |
3, |
- 16, |
+ 8, |
{ |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(0), // |
- B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(KeyedStoreICSloppy), A(1, 3), A(2, 3), // |
+ U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
1, |
{"val"}}, |
{"function f(a) { a.name = a[-124]; }\n" |
"f({\"-124\" : \"test\", name : 123 })", |
- 3 * kPointerSize, |
+ kPointerSize, |
2, |
- 23, |
+ 15, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(0), // |
- B(Star), R(1), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(2), // |
- B(LdaSmi8), U8(-124), // |
- B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), // |
- B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot2)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(-124), // |
+ B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), // |
+ B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot2)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
1, |
{"name"}}, |
{"function f(a) { \"use strict\"; a.name = \"val\"; }\n" |
"f({name : \"test\"})", |
- 2 * kPointerSize, |
+ kPointerSize, |
2, |
- 18, |
+ 14, |
{ |
// TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" |
// expression, or any other unused literal expression. |
- B(LdaConstant), U8(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaConstant), U8(1), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(2), // |
- B(StoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LdaConstant), U8(1), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(2), // |
+ B(StoreICStrict), A(1, 2), R(0), U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
3, |
{"use strict", "name", "val"}}, |
{"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n" |
"f({arg : \"test\"}, \"arg\")", |
- 2 * kPointerSize, |
+ 0, |
3, |
- 18, |
+ 10, |
{ |
// TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" |
// expression, or any other unused literal expression. |
- B(LdaConstant), U8(0), // |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(1), // |
- B(LdaConstant), U8(1), // |
- B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // |
- B(LdaUndefined), // |
- B(Return) // |
+ B(LdaConstant), U8(0), // |
+ B(LdaConstant), U8(1), // |
+ B(KeyedStoreICStrict), A(1, 3), A(2, 3), // |
+ U8(vector->GetIndex(slot1)), // |
+ B(LdaUndefined), // |
+ B(Return), // |
}, |
2, |
{"use strict", "val"}}}; |
@@ -730,13 +701,13 @@ TEST(PropertyCall) { |
2, |
16, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
+ B(Ldar), A(1, 2), // |
B(Star), R(1), // |
B(LdaConstant), U8(0), // |
B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // |
B(Star), R(0), // |
B(Call), R(0), R(1), U8(0), // |
- B(Return) // |
+ B(Return), // |
}, |
1, |
{"func"}}, |
@@ -745,14 +716,14 @@ TEST(PropertyCall) { |
4, |
24, |
{ |
- B(Ldar), R(helper.kLastParamIndex - 2), // |
+ B(Ldar), A(1, 4), // |
B(Star), R(1), // |
B(LdaConstant), U8(0), // |
B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // |
B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
+ B(Ldar), A(2, 4), // |
B(Star), R(2), // |
- B(Ldar), R(helper.kLastParamIndex), // |
+ B(Ldar), A(3, 4), // |
B(Star), R(3), // |
B(Call), R(0), R(1), U8(2), // |
B(Return) // |
@@ -762,22 +733,20 @@ TEST(PropertyCall) { |
{"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", |
4 * kPointerSize, |
3, |
- 30, |
+ 26, |
{ |
- B(Ldar), R(helper.kLastParamIndex - 1), // |
+ B(Ldar), A(1, 3), // |
B(Star), R(1), // |
B(LdaConstant), U8(0), // |
B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // |
B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(2), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(Add), R(2), // |
+ B(Ldar), A(2, 3), // |
+ B(Add), A(2, 3), // |
B(Star), R(2), // |
- B(Ldar), R(helper.kLastParamIndex), // |
+ B(Ldar), A(2, 3), // |
B(Star), R(3), // |
B(Call), R(0), R(1), U8(2), // |
- B(Return) // |
+ B(Return), // |
}, |
1, |
{"func"}}}; |
@@ -1039,7 +1008,7 @@ TEST(CallRuntime) { |
2, |
10, |
{ |
- B(Ldar), R(helper.kLastParamIndex), // |
+ B(Ldar), A(1, 2), // |
B(Star), R(0), // |
B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), // |
B(Return) // |
@@ -1126,38 +1095,34 @@ TEST(IfConditions) { |
{unused, unused, unused, unused}}, |
{"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" |
"f(99);", |
- kPointerSize, |
+ 0, |
2, |
- 19, |
- {B(Ldar), R(helper.kLastParamIndex), // |
- B(Star), R(0), // |
- B(LdaZero), // |
- B(TestLessThanOrEqual), R(0), // |
- B(JumpIfFalse), U8(7), // |
- B(LdaConstant), U8(0), // |
- B(Return), // |
- B(Jump), U8(5), // |
- B(LdaConstant), U8(1), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return)}, // |
+ 15, |
+ {B(LdaZero), // |
+ B(TestLessThanOrEqual), A(1, 2), // |
+ B(JumpIfFalse), U8(7), // |
+ B(LdaConstant), U8(0), // |
+ B(Return), // |
+ B(Jump), U8(5), // |
+ B(LdaConstant), U8(1), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, // |
2, |
{helper.factory()->NewNumberFromInt(200), |
helper.factory()->NewNumberFromInt(-200), unused, unused}}, |
{"function f(a, b) { if (a in b) { return 200; } }" |
"f('prop', { prop: 'yes'});", |
- kPointerSize, |
+ 0, |
3, |
- 15, |
- {B(Ldar), R(helper.kLastParamIndex - 1), // |
- B(Star), R(0), // |
- B(Ldar), R(helper.kLastParamIndex), // |
- B(TestIn), R(0), // |
- B(JumpIfFalse), U8(5), // |
- B(LdaConstant), U8(0), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return)}, // |
+ 11, |
+ {B(Ldar), A(2, 3), // |
+ B(TestIn), A(1, 3), // |
+ B(JumpIfFalse), U8(5), // |
+ B(LdaConstant), U8(0), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, // |
1, |
{helper.factory()->NewNumberFromInt(200), unused, unused, unused}}, |
{"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " |
@@ -1165,28 +1130,29 @@ TEST(IfConditions) { |
X X X X X X X X X X X X X X X X X X X X X X X X |
#undef X |
" return 200; } else { return -200; } } f(0.001)", |
- 3 * kPointerSize, |
+ 2 * kPointerSize, |
2, |
- 218, |
- {B(LdaZero), // |
- B(Star), R(0), // |
- B(LdaZero), // |
- B(Star), R(1), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
- B(LdaConstant), U8(0), // |
- B(TestEqualStrict), R(2), // |
- B(JumpIfFalseConstant), U8(2), // |
-#define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0), |
- X X X X X X X X X X X X X X X X X X X X X X X X |
+ 214, |
+ { |
+#define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0) |
+ B(LdaZero), // |
+ B(Star), R(0), // |
+ B(LdaZero), // |
+ B(Star), R(1), // |
+ B(LdaConstant), U8(0), // |
+ B(TestEqualStrict), R(0), // |
+ B(JumpIfFalseConstant), U8(2), // |
+ X, X, X, X, X, X, X, X, X, X, // |
+ X, X, X, X, X, X, X, X, X, X, // |
+ X, X, X, X, // |
+ B(LdaConstant), U8(1), // |
+ B(Return), // |
+ B(Jump), U8(5), // |
+ B(LdaConstant), U8(3), // |
+ B(Return), // |
+ B(LdaUndefined), // |
+ B(Return)}, // |
#undef X |
- B(LdaConstant), U8(1), // |
- B(Return), // |
- B(Jump), U8(5), // |
- B(LdaConstant), U8(3), // |
- B(Return), // |
- B(LdaUndefined), // |
- B(Return)}, // |
4, |
{helper.factory()->NewHeapNumber(0.01), |
helper.factory()->NewNumberFromInt(200), |
@@ -1201,22 +1167,18 @@ TEST(IfConditions) { |
" if (a >= b) { return 1; }\n" |
" if (a in b) { return 1; }\n" |
" if (a instanceof b) { return 1; }\n" |
- " /* if (a != b) { return 1; } */" // TODO(oth) Ast visitor yields |
- " /* if (a !== b) { return 1; } */" // UNARY NOT, rather than !=/!==. |
" return 0;\n" |
"} f(1, 1);", |
- kPointerSize, |
+ 0, |
3, |
- 106, |
+ 74, |
{ |
#define IF_CONDITION_RETURN(condition) \ |
- B(Ldar), R(helper.kLastParamIndex - 1), \ |
- B(Star), R(0), \ |
- B(Ldar), R(helper.kLastParamIndex), \ |
- B(condition), R(0), \ |
- B(JumpIfFalse), U8(5), \ |
- B(LdaSmi8), U8(1), \ |
- B(Return), |
+ B(Ldar), A(2, 3), \ |
+ B(condition), A(1, 3), \ |
+ B(JumpIfFalse), U8(5), \ |
+ B(LdaSmi8), U8(1), \ |
+ B(Return), |
IF_CONDITION_RETURN(TestEqual) // |
IF_CONDITION_RETURN(TestEqualStrict) // |
IF_CONDITION_RETURN(TestLessThan) // |
@@ -1225,9 +1187,9 @@ TEST(IfConditions) { |
IF_CONDITION_RETURN(TestGreaterThanOrEqual) // |
IF_CONDITION_RETURN(TestIn) // |
IF_CONDITION_RETURN(TestInstanceOf) // |
+ B(LdaZero), // |
+ B(Return)}, // |
#undef IF_CONDITION_RETURN |
- B(LdaZero), // |
- B(Return)}, // |
0, |
{unused, unused, unused, unused}}, |
}; |
@@ -1299,34 +1261,28 @@ TEST(BasicLoops) { |
{"var x = 0;" |
"var y = 1;" |
"while (x < 10) {" |
- " y = y * 10;" |
+ " y = y * 12;" |
" x = x + 1;" |
"}" |
"return y;", |
- 3 * kPointerSize, |
+ 2 * kPointerSize, |
1, |
- 42, |
+ 30, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
B(LdaSmi8), U8(1), // |
B(Star), R(1), // |
- B(Jump), U8(22), // |
- B(Ldar), R(1), // |
- B(Star), R(2), // |
- B(LdaSmi8), U8(10), // |
- B(Mul), R(2), // |
+ B(Jump), U8(14), // |
+ B(LdaSmi8), U8(12), // |
+ B(Mul), R(1), // |
B(Star), R(1), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(2), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(10), // |
- B(TestLessThan), R(2), // |
- B(JumpIfTrue), U8(-28), // |
+ B(TestLessThan), R(0), // |
+ B(JumpIfTrue), U8(-16), // |
B(Ldar), R(1), // |
B(Return), // |
}, |
@@ -1341,52 +1297,40 @@ TEST(BasicLoops) { |
" i = i + 1;" |
"}" |
"return i;", |
- 2 * kPointerSize, |
+ 1 * kPointerSize, |
1, |
- 80, |
+ 56, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
- B(Jump), U8(71), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(47), // |
B(LdaZero), // |
- B(TestLessThan), R(1), // |
+ B(TestLessThan), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(60), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(40), // |
B(LdaSmi8), U8(3), // |
- B(TestEqual), R(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(51), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(35), // |
B(LdaSmi8), U8(4), // |
- B(TestEqual), R(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(39), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(27), // |
B(LdaSmi8), U8(10), // |
- B(TestEqual), R(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(24), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(16), // |
B(LdaSmi8), U8(5), // |
- B(TestEqual), R(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(15), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(11), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(1), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
B(LdaTrue), // |
- B(JumpIfTrue), U8(-70), // |
+ B(JumpIfTrue), U8(-46), // |
B(Ldar), R(0), // |
- B(Return) // |
+ B(Return), // |
}, |
0}, |
{"var x = 0; var y = 1;" |
@@ -1397,43 +1341,33 @@ TEST(BasicLoops) { |
" x = x + 1;" |
"} while (x < 10);" |
"return y;", |
- 3 * kPointerSize, |
+ 2 * kPointerSize, |
1, |
- 64, |
+ 44, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
B(LdaSmi8), U8(1), // |
B(Star), R(1), // |
- B(Ldar), R(1), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(10), // |
- B(Mul), R(2), // |
+ B(Mul), R(1), // |
B(Star), R(1), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(5), // |
- B(TestEqual), R(2), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(34), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
+ B(Jump), U8(22), // |
B(LdaSmi8), U8(6), // |
- B(TestEqual), R(2), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(12), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
+ B(Jump), U8(8), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(2), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(10), // |
- B(TestLessThan), R(2), // |
- B(JumpIfTrue), U8(-52), // |
+ B(TestLessThan), R(0), // |
+ B(JumpIfTrue), U8(-32), // |
B(Ldar), R(1), // |
- B(Return) // |
+ B(Return), // |
}, |
0}, |
{"var x = 0; " |
@@ -1441,25 +1375,20 @@ TEST(BasicLoops) { |
" if (x == 1) break;" |
" x = x + 1;" |
"}", |
- 2 * kPointerSize, |
+ 1 * kPointerSize, |
1, |
- 29, |
+ 21, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
- B(LdaSmi8), // |
- U8(1), // |
- B(TestEqual), R(1), // |
+ B(LdaSmi8), U8(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(14), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(10), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(1), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
- B(Jump), U8(-22), // |
+ B(Jump), U8(-14), // |
B(LdaUndefined), // |
B(Return), // |
}, |
@@ -1469,31 +1398,25 @@ TEST(BasicLoops) { |
" u = u + 1;" |
" continue;" |
"}", |
- 3 * kPointerSize, |
+ 2 * kPointerSize, |
1, |
- 42, |
+ 30, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
B(LdaZero), // |
B(Star), R(1), // |
- B(Jump), U8(24), // |
- B(Ldar), R(0), // |
- B(Star), R(2), // |
+ B(Jump), U8(16), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(2), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
B(Jump), U8(2), // |
- B(Ldar), R(1), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(2), // |
+ B(Add), R(1), // |
B(Star), R(1), // |
- B(Ldar), R(1), // |
- B(Star), R(2), // |
B(LdaSmi8), U8(100), // |
- B(TestLessThan), R(2), // |
- B(JumpIfTrue), U8(-30), // |
+ B(TestLessThan), R(1), // |
+ B(JumpIfTrue), U8(-18), // |
B(LdaUndefined), // |
B(Return), // |
}, |
@@ -1508,38 +1431,30 @@ TEST(BasicLoops) { |
" break;" |
"}" |
"return i;", |
- 2 * kPointerSize, |
+ 1 * kPointerSize, |
1, |
- 57, |
+ 41, |
{ |
B(LdaZero), // |
B(Star), R(0), // |
- B(Jump), U8(48), // |
- B(Jump), U8(24), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(32), // |
+ B(Jump), U8(16), // |
B(LdaSmi8), U8(2), // |
- B(TestEqual), R(1), // |
+ B(TestEqual), R(0), // |
B(JumpIfFalse), U8(4), // |
- B(Jump), U8(22), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(Jump), U8(14), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(1), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
B(LdaSmi8), U8(3), // |
- B(TestLessThan), R(1), // |
- B(JumpIfTrue), U8(-30), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
+ B(TestLessThan), R(0), // |
+ B(JumpIfTrue), U8(-18), // |
B(LdaSmi8), U8(1), // |
- B(Add), R(1), // |
+ B(Add), R(0), // |
B(Star), R(0), // |
B(Jump), U8(5), // |
B(LdaTrue), // |
- B(JumpIfTrue), U8(-47), // |
+ B(JumpIfTrue), U8(-31), // |
B(Ldar), R(0), // |
B(Return), // |
}, |
@@ -1564,26 +1479,22 @@ TEST(UnaryOperators) { |
" x = x + 10;" |
"}" |
"return x;", |
- 2 * kPointerSize, |
+ kPointerSize, |
1, |
- 29, |
+ 21, |
{ |
- B(LdaZero), // |
- B(Star), R(0), // |
- B(Jump), U8(12), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(10), // |
- B(Add), R(1), // |
- B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
- B(LdaSmi8), U8(10), // |
- B(TestEqual), R(1), // |
- B(LogicalNot), // |
- B(JumpIfTrue), U8(-19), // |
- B(Ldar), R(0), // |
- B(Return), // |
+ B(LdaZero), // |
+ B(Star), R(0), // |
+ B(Jump), U8(8), // |
+ B(LdaSmi8), U8(10), // |
+ B(Add), R(0), // |
+ B(Star), R(0), // |
+ B(LdaSmi8), U8(10), // |
+ B(TestEqual), R(0), // |
+ B(LogicalNot), // |
+ B(JumpIfTrue), U8(-11), // |
+ B(Ldar), R(0), // |
+ B(Return), // |
}, |
0}, |
{"var x = false;" |
@@ -1591,36 +1502,32 @@ TEST(UnaryOperators) { |
" x = !x;" |
"} while(x == false);" |
"return x;", |
- 2 * kPointerSize, |
+ kPointerSize, |
1, |
- 20, |
+ 16, |
{ |
- B(LdaFalse), // |
- B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(LogicalNot), // |
- B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
- B(LdaFalse), // |
- B(TestEqual), R(1), // |
- B(JumpIfTrue), U8(-12), // |
- B(Ldar), R(0), // |
- B(Return), // |
+ B(LdaFalse), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(LogicalNot), // |
+ B(Star), R(0), // |
+ B(LdaFalse), // |
+ B(TestEqual), R(0), // |
+ B(JumpIfTrue), U8(-8), // |
+ B(Ldar), R(0), // |
+ B(Return), // |
}, |
0}, |
{"var x = 101;" |
"return void(x * 3);", |
- 2 * kPointerSize, |
+ kPointerSize, |
1, |
- 14, |
+ 10, |
{ |
B(LdaSmi8), U8(101), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(Star), R(1), // |
B(LdaSmi8), U8(3), // |
- B(Mul), R(1), // |
+ B(Mul), R(0), // |
B(LdaUndefined), // |
B(Return), // |
}, |
@@ -1628,16 +1535,14 @@ TEST(UnaryOperators) { |
{"var x = 1234;" |
"var y = void (x * x - 1);" |
"return y;", |
- 4 * kPointerSize, |
+ 3 * kPointerSize, |
1, |
- 24, |
+ 20, |
{ |
B(LdaConstant), U8(0), // |
B(Star), R(0), // |
B(Ldar), R(0), // |
- B(Star), R(3), // |
- B(Ldar), R(0), // |
- B(Mul), R(3), // |
+ B(Mul), R(0), // |
B(Star), R(2), // |
B(LdaSmi8), U8(1), // |
B(Sub), R(2), // |
@@ -1650,14 +1555,14 @@ TEST(UnaryOperators) { |
{1234}}, |
{"var x = 13;" |
"return typeof(x);", |
- 1 * kPointerSize, |
+ kPointerSize, |
1, |
8, |
{ |
B(LdaSmi8), U8(13), // |
B(Star), R(0), // |
- B(Ldar), R(0), // |
- B(TypeOf), // |
+ B(Ldar), R(0), // TODO(oth): Ldar R(X) following Star R(X) |
+ B(TypeOf), // could be culled in bytecode array builder. |
B(Return), // |
}, |
0}, |