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

Side by Side 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, 1 month 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 1 * kPointerSize, 403 1 * kPointerSize,
404 1, 404 1,
405 10, 405 10,
406 {B(LdaZero), // 406 {B(LdaZero), //
407 B(Star), R(0), // 407 B(Star), R(0), //
408 B(Ldar), R(0), // 408 B(Ldar), R(0), //
409 B(JumpIfToBooleanTrue), U8(4), // 409 B(JumpIfToBooleanTrue), U8(4), //
410 B(LdaSmi8), U8(3), // 410 B(LdaSmi8), U8(3), //
411 B(Return)}, 411 B(Return)},
412 0}, 412 0},
413 {"var x = 0; return (x == 1) || 3;",
414 1 * kPointerSize,
415 1,
416 12,
417 {B(LdaZero), //
418 B(Star), R(0), //
419 B(LdaSmi8), U8(1), //
420 B(TestEqual), R(0), //
421 B(JumpIfTrue), U8(4), //
422 B(LdaSmi8), U8(3), //
423 B(Return)},
424 0},
413 {"var x = 0; return x && 3;", 425 {"var x = 0; return x && 3;",
414 1 * kPointerSize, 426 1 * kPointerSize,
415 1, 427 1,
416 10, 428 10,
417 {B(LdaZero), // 429 {B(LdaZero), //
418 B(Star), R(0), // 430 B(Star), R(0), //
419 B(Ldar), R(0), // 431 B(Ldar), R(0), //
420 B(JumpIfToBooleanFalse), U8(4), // 432 B(JumpIfToBooleanFalse), U8(4), //
421 B(LdaSmi8), U8(3), // 433 B(LdaSmi8), U8(3), //
422 B(Return)}, 434 B(Return)},
423 0}, 435 0},
436 {"var x = 0; return (x == 0) && 3;",
437 1 * kPointerSize,
438 1,
439 11,
440 {B(LdaZero), //
441 B(Star), R(0), //
442 B(LdaZero), //
443 B(TestEqual), R(0), //
444 B(JumpIfFalse), U8(4), //
445 B(LdaSmi8), U8(3), //
446 B(Return)},
447 0},
424 {"var x = 0; return x || (1, 2, 3);", 448 {"var x = 0; return x || (1, 2, 3);",
425 1 * kPointerSize, 449 1 * kPointerSize,
426 1, 450 1,
427 10, 451 10,
428 {B(LdaZero), // 452 {B(LdaZero), //
429 B(Star), R(0), // 453 B(Star), R(0), //
430 B(Ldar), R(0), // 454 B(Ldar), R(0), //
431 B(JumpIfToBooleanTrue), U8(4), // 455 B(JumpIfToBooleanTrue), U8(4), //
432 B(LdaSmi8), U8(3), // 456 B(LdaSmi8), U8(3), //
433 B(Return)}, 457 B(Return)},
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 B(JumpIfToBooleanFalseConstant), U8(0), // 512 B(JumpIfToBooleanFalseConstant), U8(0), //
489 REPEAT_32(COMMA, // 513 REPEAT_32(COMMA, //
490 B(LdaSmi8), U8(1), // 514 B(LdaSmi8), U8(1), //
491 B(Star), R(1), // 515 B(Star), R(1), //
492 B(LdaSmi8), U8(2), // 516 B(LdaSmi8), U8(2), //
493 B(Star), R(2)), // 517 B(Star), R(2)), //
494 B(LdaSmi8), U8(3), // 518 B(LdaSmi8), U8(3), //
495 B(Return)}, // 519 B(Return)}, //
496 1, 520 1,
497 {260, 0, 0, 0}}, 521 {260, 0, 0, 0}},
522 {"var x = 1; var a = 2, b = 3; return (x > 3) || ("
523 REPEAT_32(SPACE, "a = 1, b = 2, ")
524 "3);",
525 3 * kPointerSize,
526 1,
527 277,
528 {B(LdaSmi8), U8(1), //
529 B(Star), R(0), //
530 B(LdaSmi8), U8(2), //
531 B(Star), R(1), //
532 B(LdaSmi8), U8(3), //
533 B(Star), R(2), //
534 B(LdaSmi8), U8(3), //
535 B(TestGreaterThan), R(0), //
536 B(JumpIfTrueConstant), U8(0), //
537 REPEAT_32(COMMA, //
538 B(LdaSmi8), U8(1), //
539 B(Star), R(1), //
540 B(LdaSmi8), U8(2), //
541 B(Star), R(2)), //
542 B(LdaSmi8), U8(3), //
543 B(Return)},
544 1,
545 {260, 0, 0, 0}},
546 {"var x = 0; var a = 2, b = 3; return (x < 5) && ("
547 REPEAT_32(SPACE, "a = 1, b = 2, ")
548 "3);",
549 3 * kPointerSize,
550 1,
551 276,
552 {B(LdaZero), //
553 B(Star), R(0), //
554 B(LdaSmi8), U8(2), //
555 B(Star), R(1), //
556 B(LdaSmi8), U8(3), //
557 B(Star), R(2), //
558 B(LdaSmi8), U8(5), //
559 B(TestLessThan), R(0), //
560 B(JumpIfFalseConstant), U8(0), //
561 REPEAT_32(COMMA, //
562 B(LdaSmi8), U8(1), //
563 B(Star), R(1), //
564 B(LdaSmi8), U8(2), //
565 B(Star), R(2)), //
566 B(LdaSmi8), U8(3), //
567 B(Return)},
568 1,
569 {260, 0, 0, 0}},
498 {"return 0 && 3;", 570 {"return 0 && 3;",
499 0 * kPointerSize, 571 0 * kPointerSize,
500 1, 572 1,
501 2, 573 2,
502 {B(LdaZero), // 574 {B(LdaZero), //
503 B(Return)}, 575 B(Return)},
504 0}, 576 0},
505 {"return 1 || 3;", 577 {"return 1 || 3;",
506 0 * kPointerSize, 578 0 * kPointerSize,
507 1, 579 1,
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 TEST(IfConditions) { 1593 TEST(IfConditions) {
1522 InitializedHandleScope handle_scope; 1594 InitializedHandleScope handle_scope;
1523 BytecodeGeneratorHelper helper; 1595 BytecodeGeneratorHelper helper;
1524 1596
1525 Handle<Object> unused = helper.factory()->undefined_value(); 1597 Handle<Object> unused = helper.factory()->undefined_value();
1526 1598
1527 ExpectedSnippet<Handle<Object>> snippets[] = { 1599 ExpectedSnippet<Handle<Object>> snippets[] = {
1528 {"function f() { if (0) { return 1; } else { return -1; } } f()", 1600 {"function f() { if (0) { return 1; } else { return -1; } } f()",
1529 0, 1601 0,
1530 1, 1602 1,
1531 14, 1603 13,
1532 {B(LdaZero), // 1604 {B(LdaZero), //
1533 B(ToBoolean), // 1605 B(JumpIfToBooleanFalse), U8(7), //
1534 B(JumpIfFalse), U8(7), // 1606 B(LdaSmi8), U8(1), //
1535 B(LdaSmi8), U8(1), // 1607 B(Return), //
1536 B(Return), // 1608 B(Jump), U8(5), //
1537 B(Jump), U8(5), // 1609 B(LdaSmi8), U8(-1), //
1538 B(LdaSmi8), U8(-1), // 1610 B(Return), //
1539 B(Return), // 1611 B(LdaUndefined), //
1540 B(LdaUndefined), // 1612 B(Return)}, //
1541 B(Return)}, //
1542 0, 1613 0,
1543 {unused, unused, unused, unused, unused, unused}}, 1614 {unused, unused, unused, unused, unused, unused}},
1544 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", 1615 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();",
1545 0, 1616 0,
1546 1, 1617 1,
1547 15, 1618 14,
1548 {B(LdaConstant), U8(0), // 1619 {B(LdaConstant), U8(0), //
1549 B(ToBoolean), // 1620 B(JumpIfToBooleanFalse), U8(7), //
1550 B(JumpIfFalse), U8(7), // 1621 B(LdaSmi8), U8(1), //
1551 B(LdaSmi8), U8(1), // 1622 B(Return), //
1552 B(Return), // 1623 B(Jump), U8(5), //
1553 B(Jump), U8(5), // 1624 B(LdaSmi8), U8(-1), //
1554 B(LdaSmi8), U8(-1), // 1625 B(Return), //
1555 B(Return), // 1626 B(LdaUndefined), //
1556 B(LdaUndefined), // 1627 B(Return)}, //
1557 B(Return)}, //
1558 1, 1628 1,
1559 {helper.factory()->NewStringFromStaticChars("lucky"), unused, unused, 1629 {helper.factory()->NewStringFromStaticChars("lucky"), unused, unused,
1560 unused, unused, unused}}, 1630 unused, unused, unused}},
1561 {"function f() { if (false) { return 1; } else { return -1; } } f();", 1631 {"function f() { if (false) { return 1; } else { return -1; } } f();",
1562 0, 1632 0,
1563 1, 1633 1,
1564 13, 1634 13,
1565 {B(LdaFalse), // 1635 {B(LdaFalse), //
1566 B(JumpIfFalse), U8(7), // 1636 B(JumpIfFalse), U8(7), //
1567 B(LdaSmi8), U8(1), // 1637 B(LdaSmi8), U8(1), //
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 B(Jump), U8(5), // 1701 B(Jump), U8(5), //
1632 B(LdaConstant), U8(3), // 1702 B(LdaConstant), U8(3), //
1633 B(Return), // 1703 B(Return), //
1634 B(LdaUndefined), // 1704 B(LdaUndefined), //
1635 B(Return)}, // 1705 B(Return)}, //
1636 4, 1706 4,
1637 {helper.factory()->NewHeapNumber(0.01), 1707 {helper.factory()->NewHeapNumber(0.01),
1638 helper.factory()->NewNumberFromInt(200), 1708 helper.factory()->NewNumberFromInt(200),
1639 helper.factory()->NewNumberFromInt(263), 1709 helper.factory()->NewNumberFromInt(263),
1640 helper.factory()->NewNumberFromInt(-200), unused, unused}}, 1710 helper.factory()->NewNumberFromInt(-200), unused, unused}},
1711 {"function f() { var a = 0; var b = 0; if (a) { "
1712 REPEAT_32(SPACE, "b = a; a = b; ")
1713 " return 200; } else { return -200; } } f()",
1714 2 * kPointerSize,
1715 1,
1716 276,
1717 {
1718 B(LdaZero), //
1719 B(Star), R(0), //
1720 B(LdaZero), //
1721 B(Star), R(1), //
1722 B(Ldar), R(0), //
1723 B(JumpIfToBooleanFalseConstant), U8(1), //
1724 REPEAT_32(COMMA, //
1725 B(Ldar), R(0), //
1726 B(Star), R(1), //
1727 B(Ldar), R(1), //
1728 B(Star), R(0)), //
1729 B(LdaConstant), U8(0), //
1730 B(Return), //
1731 B(Jump), U8(5), //
1732 B(LdaConstant), U8(2), //
1733 B(Return), //
1734 B(LdaUndefined), //
1735 B(Return)}, //
1736 3,
1737 {helper.factory()->NewNumberFromInt(200),
1738 helper.factory()->NewNumberFromInt(263),
1739 helper.factory()->NewNumberFromInt(-200), unused, unused, unused}},
1740
1641 {"function f(a, b) {\n" 1741 {"function f(a, b) {\n"
1642 " if (a == b) { return 1; }\n" 1742 " if (a == b) { return 1; }\n"
1643 " if (a === b) { return 1; }\n" 1743 " if (a === b) { return 1; }\n"
1644 " if (a < b) { return 1; }\n" 1744 " if (a < b) { return 1; }\n"
1645 " if (a > b) { return 1; }\n" 1745 " if (a > b) { return 1; }\n"
1646 " if (a <= b) { return 1; }\n" 1746 " if (a <= b) { return 1; }\n"
1647 " if (a >= b) { return 1; }\n" 1747 " if (a >= b) { return 1; }\n"
1648 " if (a in b) { return 1; }\n" 1748 " if (a in b) { return 1; }\n"
1649 " if (a instanceof b) { return 1; }\n" 1749 " if (a instanceof b) { return 1; }\n"
1650 " return 0;\n" 1750 " return 0;\n"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 B(LdaSmi8), U8(1), // 2100 B(LdaSmi8), U8(1), //
2001 B(Add), R(0), // 2101 B(Add), R(0), //
2002 B(Star), R(0), // 2102 B(Star), R(0), //
2003 B(Jump), U8(5), // 2103 B(Jump), U8(5), //
2004 B(LdaTrue), // 2104 B(LdaTrue), //
2005 B(JumpIfTrue), U8(-31), // 2105 B(JumpIfTrue), U8(-31), //
2006 B(Ldar), R(0), // 2106 B(Ldar), R(0), //
2007 B(Return), // 2107 B(Return), //
2008 }, 2108 },
2009 0}, 2109 0},
2010 }; 2110 {"var x = 10;"
2111 "var y = 1;"
2112 "while (x) {"
2113 " y = y * 12;"
2114 " x = x - 1;"
2115 "}"
2116 "return y;",
2117 2 * kPointerSize,
2118 1,
2119 29,
2120 {
2121 B(LdaSmi8), U8(10), //
2122 B(Star), R(0), //
2123 B(LdaSmi8), U8(1), //
2124 B(Star), R(1), //
2125 B(Jump), U8(14), //
2126 B(LdaSmi8), U8(12), //
2127 B(Mul), R(1), //
2128 B(Star), R(1), //
2129 B(LdaSmi8), U8(1), //
2130 B(Sub), R(0), //
2131 B(Star), R(0), //
2132 B(Ldar), R(0), //
2133 B(JumpIfToBooleanTrue), U8(-14), //
2134 B(Ldar), R(1), //
2135 B(Return), //
2136 },
2137 0},
2138 {"var x = 10;"
2139 "var y = 1;"
2140 "do {"
2141 " y = y * 12;"
2142 " x = x - 1;"
2143 "} while(x);"
2144 "return y;",
2145 2 * kPointerSize,
2146 1,
2147 27,
2148 {
2149 B(LdaSmi8), U8(10), //
2150 B(Star), R(0), //
2151 B(LdaSmi8), U8(1), //
2152 B(Star), R(1), //
2153 B(LdaSmi8), U8(12), //
2154 B(Mul), R(1), //
2155 B(Star), R(1), //
2156 B(LdaSmi8), U8(1), //
2157 B(Sub), R(0), //
2158 B(Star), R(0), //
2159 B(Ldar), R(0), //
2160 B(JumpIfToBooleanTrue), U8(-14), //
2161 B(Ldar), R(1), //
2162 B(Return), //
2163 },
2164 0},
2165 {"var y = 1;"
2166 "for (var x = 10; x; --x) {"
2167 " y = y * 12;"
2168 "}"
2169 "return y;",
2170 2 * kPointerSize,
2171 1,
2172 29,
2173 {
2174 B(LdaSmi8), U8(1), //
2175 B(Star), R(0), //
2176 B(LdaSmi8), U8(10), //
2177 B(Star), R(1), //
2178 B(Jump), U8(14), //
2179 B(LdaSmi8), U8(12), //
2180 B(Mul), R(0), //
2181 B(Star), R(0), //
2182 B(Ldar), R(1), //
2183 B(ToNumber), //
2184 B(Dec), //
2185 B(Star), R(1), //
2186 B(Ldar), R(1), //
2187 B(JumpIfToBooleanTrue), U8(-14), //
2188 B(Ldar), R(0), //
2189 B(Return), //
2190 },
2191 0}};
2011 2192
2012 for (size_t i = 0; i < arraysize(snippets); i++) { 2193 for (size_t i = 0; i < arraysize(snippets); i++) {
2013 Handle<BytecodeArray> bytecode_array = 2194 Handle<BytecodeArray> bytecode_array =
2014 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2195 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2015 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2196 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2016 } 2197 }
2017 } 2198 }
2018 2199
2019 2200
2020 TEST(UnaryOperators) { 2201 TEST(UnaryOperators) {
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 3, 3282 3,
3102 { 3283 {
3103 B(LdaConstant), U8(0), // 3284 B(LdaConstant), U8(0), //
3104 B(Throw), // 3285 B(Throw), //
3105 }, 3286 },
3106 1, 3287 1,
3107 {"Error"}}, 3288 {"Error"}},
3108 {"if ('test') { throw 'Error'; };", 3289 {"if ('test') { throw 'Error'; };",
3109 0, 3290 0,
3110 1, 3291 1,
3111 10, 3292 9,
3112 { 3293 {
3113 B(LdaConstant), U8(0), // 3294 B(LdaConstant), U8(0), //
3114 B(ToBoolean), // 3295 B(JumpIfToBooleanFalse), U8(5), //
3115 B(JumpIfFalse), U8(5), // 3296 B(LdaConstant), U8(1), //
3116 B(LdaConstant), U8(1), // 3297 B(Throw), //
3117 B(Throw), // 3298 B(LdaUndefined), //
3118 B(LdaUndefined), // 3299 B(Return), //
3119 B(Return), //
3120 }, 3300 },
3121 2, 3301 2,
3122 {"test", "Error"}}, 3302 {"test", "Error"}},
3123 }; 3303 };
3124 3304
3125 for (size_t i = 0; i < arraysize(snippets); i++) { 3305 for (size_t i = 0; i < arraysize(snippets); i++) {
3126 Handle<BytecodeArray> bytecode_array = 3306 Handle<BytecodeArray> bytecode_array =
3127 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3307 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3128 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3308 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3129 } 3309 }
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4297 4477
4298 4478
4299 TEST(Conditional) { 4479 TEST(Conditional) {
4300 InitializedHandleScope handle_scope; 4480 InitializedHandleScope handle_scope;
4301 BytecodeGeneratorHelper helper; 4481 BytecodeGeneratorHelper helper;
4302 4482
4303 ExpectedSnippet<int> snippets[] = { 4483 ExpectedSnippet<int> snippets[] = {
4304 {"return 1 ? 2 : 3;", 4484 {"return 1 ? 2 : 3;",
4305 0, 4485 0,
4306 1, 4486 1,
4307 12, 4487 11,
4308 { 4488 {
4309 B(LdaSmi8), U8(1), // 4489 B(LdaSmi8), U8(1), //
4310 B(ToBoolean), // 4490 B(JumpIfToBooleanFalse), U8(6), //
4311 B(JumpIfFalse), U8(6), // 4491 B(LdaSmi8), U8(2), //
4312 B(LdaSmi8), U8(2), // 4492 B(Jump), U8(4), //
4313 B(Jump), U8(4), // 4493 B(LdaSmi8), U8(3), //
4314 B(LdaSmi8), U8(3), // 4494 B(Return), //
4315 B(Return), //
4316 }}, 4495 }},
4317 {"return 1 ? 2 ? 3 : 4 : 5;", 4496 {"return 1 ? 2 ? 3 : 4 : 5;",
4318 0, 4497 0,
4319 1, 4498 1,
4320 21, 4499 19,
4321 { 4500 {
4322 B(LdaSmi8), U8(1), // 4501 B(LdaSmi8), U8(1), //
4323 B(ToBoolean), // 4502 B(JumpIfToBooleanFalse), U8(14), //
4324 B(JumpIfFalse), U8(15), // 4503 B(LdaSmi8), U8(2), //
4325 B(LdaSmi8), U8(2), // 4504 B(JumpIfToBooleanFalse), U8(6), //
4326 B(ToBoolean), // 4505 B(LdaSmi8), U8(3), //
4327 B(JumpIfFalse), U8(6), // 4506 B(Jump), U8(4), //
4328 B(LdaSmi8), U8(3), // 4507 B(LdaSmi8), U8(4), //
4329 B(Jump), U8(4), // 4508 B(Jump), U8(4), //
4330 B(LdaSmi8), U8(4), // 4509 B(LdaSmi8), U8(5), //
4331 B(Jump), U8(4), // 4510 B(Return), //
4332 B(LdaSmi8), U8(5), //
4333 B(Return), //
4334 }}, 4511 }},
4335 }; 4512 };
4336 4513
4337 for (size_t i = 0; i < arraysize(snippets); i++) { 4514 for (size_t i = 0; i < arraysize(snippets); i++) {
4338 Handle<BytecodeArray> bytecode_array = 4515 Handle<BytecodeArray> bytecode_array =
4339 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 4516 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
4340 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 4517 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
4341 } 4518 }
4342 } 4519 }
4343 4520
4344 } // namespace interpreter 4521 } // namespace interpreter
4345 } // namespace internal 4522 } // namespace internal
4346 } // namespace v8 4523 } // namespace v8
OLDNEW
« 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