Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1426913002: [Interpreter] Merges ToBoolean and JumpIfTrue/False bytecodes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch and used the new Repeat_32 macro for tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2f547721abd82aa375d34d877eaa9655d642a8da..6289d91999edbe354ef84e28d0b1769a0bdfca9c 100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -410,6 +410,18 @@ TEST(LogicalExpressions) {
B(LdaSmi8), U8(3), //
B(Return)},
0},
+ {"var x = 0; return (x == 1) || 3;",
+ 1 * kPointerSize,
+ 1,
+ 12,
+ {B(LdaZero), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(1), //
+ B(TestEqual), R(0), //
+ B(JumpIfTrue), U8(4), //
+ B(LdaSmi8), U8(3), //
+ B(Return)},
+ 0},
{"var x = 0; return x && 3;",
1 * kPointerSize,
1,
@@ -421,6 +433,18 @@ TEST(LogicalExpressions) {
B(LdaSmi8), U8(3), //
B(Return)},
0},
+ {"var x = 0; return (x == 0) && 3;",
+ 1 * kPointerSize,
+ 1,
+ 11,
+ {B(LdaZero), //
+ B(Star), R(0), //
+ B(LdaZero), //
+ B(TestEqual), R(0), //
+ B(JumpIfFalse), U8(4), //
+ B(LdaSmi8), U8(3), //
+ B(Return)},
+ 0},
{"var x = 0; return x || (1, 2, 3);",
1 * kPointerSize,
1,
@@ -495,6 +519,54 @@ TEST(LogicalExpressions) {
B(Return)}, //
1,
{260, 0, 0, 0}},
+ {"var x = 1; var a = 2, b = 3; return (x > 3) || ("
+ REPEAT_32(SPACE, "a = 1, b = 2, ")
+ "3);",
+ 3 * kPointerSize,
+ 1,
+ 277,
+ {B(LdaSmi8), U8(1), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(2), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(3), //
+ B(Star), R(2), //
+ B(LdaSmi8), U8(3), //
+ B(TestGreaterThan), R(0), //
+ B(JumpIfTrueConstant), U8(0), //
+ REPEAT_32(COMMA, //
+ B(LdaSmi8), U8(1), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(2), //
+ B(Star), R(2)), //
+ B(LdaSmi8), U8(3), //
+ B(Return)},
+ 1,
+ {260, 0, 0, 0}},
+ {"var x = 0; var a = 2, b = 3; return (x < 5) && ("
+ REPEAT_32(SPACE, "a = 1, b = 2, ")
+ "3);",
+ 3 * kPointerSize,
+ 1,
+ 276,
+ {B(LdaZero), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(2), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(3), //
+ B(Star), R(2), //
+ B(LdaSmi8), U8(5), //
+ B(TestLessThan), R(0), //
+ B(JumpIfFalseConstant), U8(0), //
+ REPEAT_32(COMMA, //
+ B(LdaSmi8), U8(1), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(2), //
+ B(Star), R(2)), //
+ B(LdaSmi8), U8(3), //
+ B(Return)},
+ 1,
+ {260, 0, 0, 0}},
{"return 0 && 3;",
0 * kPointerSize,
1,
@@ -1528,33 +1600,31 @@ TEST(IfConditions) {
{"function f() { if (0) { return 1; } else { return -1; } } f()",
0,
1,
- 14,
- {B(LdaZero), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(7), //
- B(LdaSmi8), U8(1), //
- B(Return), //
- B(Jump), U8(5), //
- B(LdaSmi8), U8(-1), //
- B(Return), //
- B(LdaUndefined), //
- B(Return)}, //
+ 13,
+ {B(LdaZero), //
+ B(JumpIfToBooleanFalse), U8(7), //
+ B(LdaSmi8), U8(1), //
+ B(Return), //
+ B(Jump), U8(5), //
+ B(LdaSmi8), U8(-1), //
+ B(Return), //
+ B(LdaUndefined), //
+ B(Return)}, //
0,
{unused, unused, unused, unused, unused, unused}},
{"function f() { if ('lucky') { return 1; } else { return -1; } } f();",
0,
1,
- 15,
- {B(LdaConstant), U8(0), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(7), //
- B(LdaSmi8), U8(1), //
- B(Return), //
- B(Jump), U8(5), //
- B(LdaSmi8), U8(-1), //
- B(Return), //
- B(LdaUndefined), //
- B(Return)}, //
+ 14,
+ {B(LdaConstant), U8(0), //
+ B(JumpIfToBooleanFalse), U8(7), //
+ B(LdaSmi8), U8(1), //
+ B(Return), //
+ B(Jump), U8(5), //
+ B(LdaSmi8), U8(-1), //
+ B(Return), //
+ B(LdaUndefined), //
+ B(Return)}, //
1,
{helper.factory()->NewStringFromStaticChars("lucky"), unused, unused,
unused, unused, unused}},
@@ -1638,6 +1708,36 @@ TEST(IfConditions) {
helper.factory()->NewNumberFromInt(200),
helper.factory()->NewNumberFromInt(263),
helper.factory()->NewNumberFromInt(-200), unused, unused}},
+ {"function f() { var a = 0; var b = 0; if (a) { "
+ REPEAT_32(SPACE, "b = a; a = b; ")
+ " return 200; } else { return -200; } } f()",
+ 2 * kPointerSize,
+ 1,
+ 276,
+ {
+ B(LdaZero), //
+ B(Star), R(0), //
+ B(LdaZero), //
+ B(Star), R(1), //
+ B(Ldar), R(0), //
+ B(JumpIfToBooleanFalseConstant), U8(1), //
+ REPEAT_32(COMMA, //
+ B(Ldar), R(0), //
+ B(Star), R(1), //
+ B(Ldar), R(1), //
+ B(Star), R(0)), //
+ B(LdaConstant), U8(0), //
+ B(Return), //
+ B(Jump), U8(5), //
+ B(LdaConstant), U8(2), //
+ B(Return), //
+ B(LdaUndefined), //
+ B(Return)}, //
+ 3,
+ {helper.factory()->NewNumberFromInt(200),
+ helper.factory()->NewNumberFromInt(263),
+ helper.factory()->NewNumberFromInt(-200), unused, unused, unused}},
+
{"function f(a, b) {\n"
" if (a == b) { return 1; }\n"
" if (a === b) { return 1; }\n"
@@ -2007,7 +2107,88 @@ TEST(BasicLoops) {
B(Return), //
},
0},
- };
+ {"var x = 10;"
+ "var y = 1;"
+ "while (x) {"
+ " y = y * 12;"
+ " x = x - 1;"
+ "}"
+ "return y;",
+ 2 * kPointerSize,
+ 1,
+ 29,
+ {
+ B(LdaSmi8), U8(10), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(1), //
+ B(Star), R(1), //
+ B(Jump), U8(14), //
+ B(LdaSmi8), U8(12), //
+ B(Mul), R(1), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(1), //
+ B(Sub), R(0), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(JumpIfToBooleanTrue), U8(-14), //
+ B(Ldar), R(1), //
+ B(Return), //
+ },
+ 0},
+ {"var x = 10;"
+ "var y = 1;"
+ "do {"
+ " y = y * 12;"
+ " x = x - 1;"
+ "} while(x);"
+ "return y;",
+ 2 * kPointerSize,
+ 1,
+ 27,
+ {
+ B(LdaSmi8), U8(10), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(1), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(12), //
+ B(Mul), R(1), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(1), //
+ B(Sub), R(0), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(JumpIfToBooleanTrue), U8(-14), //
+ B(Ldar), R(1), //
+ B(Return), //
+ },
+ 0},
+ {"var y = 1;"
+ "for (var x = 10; x; --x) {"
+ " y = y * 12;"
+ "}"
+ "return y;",
+ 2 * kPointerSize,
+ 1,
+ 29,
+ {
+ B(LdaSmi8), U8(1), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(10), //
+ B(Star), R(1), //
+ B(Jump), U8(14), //
+ B(LdaSmi8), U8(12), //
+ B(Mul), R(0), //
+ B(Star), R(0), //
+ B(Ldar), R(1), //
+ B(ToNumber), //
+ B(Dec), //
+ B(Star), R(1), //
+ B(Ldar), R(1), //
+ B(JumpIfToBooleanTrue), U8(-14), //
+ B(Ldar), R(0), //
+ B(Return), //
+ },
+ 0}};
for (size_t i = 0; i < arraysize(snippets); i++) {
Handle<BytecodeArray> bytecode_array =
@@ -3108,15 +3289,14 @@ TEST(Throw) {
{"if ('test') { throw 'Error'; };",
0,
1,
- 10,
+ 9,
{
- B(LdaConstant), U8(0), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(5), //
- B(LdaConstant), U8(1), //
- B(Throw), //
- B(LdaUndefined), //
- B(Return), //
+ B(LdaConstant), U8(0), //
+ B(JumpIfToBooleanFalse), U8(5), //
+ B(LdaConstant), U8(1), //
+ B(Throw), //
+ B(LdaUndefined), //
+ B(Return), //
},
2,
{"test", "Error"}},
@@ -4304,33 +4484,30 @@ TEST(Conditional) {
{"return 1 ? 2 : 3;",
0,
1,
- 12,
+ 11,
{
- B(LdaSmi8), U8(1), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(6), //
- B(LdaSmi8), U8(2), //
- B(Jump), U8(4), //
- B(LdaSmi8), U8(3), //
- B(Return), //
+ B(LdaSmi8), U8(1), //
+ B(JumpIfToBooleanFalse), U8(6), //
+ B(LdaSmi8), U8(2), //
+ B(Jump), U8(4), //
+ B(LdaSmi8), U8(3), //
+ B(Return), //
}},
{"return 1 ? 2 ? 3 : 4 : 5;",
0,
1,
- 21,
- {
- B(LdaSmi8), U8(1), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(15), //
- B(LdaSmi8), U8(2), //
- B(ToBoolean), //
- B(JumpIfFalse), U8(6), //
- B(LdaSmi8), U8(3), //
- B(Jump), U8(4), //
- B(LdaSmi8), U8(4), //
- B(Jump), U8(4), //
- B(LdaSmi8), U8(5), //
- B(Return), //
+ 19,
+ {
+ B(LdaSmi8), U8(1), //
+ B(JumpIfToBooleanFalse), U8(14), //
+ B(LdaSmi8), U8(2), //
+ B(JumpIfToBooleanFalse), U8(6), //
+ B(LdaSmi8), U8(3), //
+ B(Jump), U8(4), //
+ B(LdaSmi8), U8(4), //
+ B(Jump), U8(4), //
+ B(LdaSmi8), U8(5), //
+ B(Return), //
}},
};
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698