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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1392933002: [Interpreter] Reduce temporary register usage in generated bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. 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 unified diff | Download patch
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SNPrintF(program, "%s\n%s();", function, kFunctionName); 67 SNPrintF(program, "%s\n%s();", function, kFunctionName);
68 return MakeBytecode(program.start(), kFunctionName); 68 return MakeBytecode(program.start(), kFunctionName);
69 } 69 }
70 }; 70 };
71 71
72 72
73 // Helper macros for handcrafting bytecode sequences. 73 // Helper macros for handcrafting bytecode sequences.
74 #define B(x) static_cast<uint8_t>(Bytecode::k##x) 74 #define B(x) static_cast<uint8_t>(Bytecode::k##x)
75 #define U8(x) static_cast<uint8_t>((x) & 0xff) 75 #define U8(x) static_cast<uint8_t>((x) & 0xff)
76 #define R(x) static_cast<uint8_t>(-(x) & 0xff) 76 #define R(x) static_cast<uint8_t>(-(x) & 0xff)
77 #define A(x, n) R(helper.kLastParamIndex - (n) + 1 + (x))
78 #define THIS(n) A(0, n)
77 #define _ static_cast<uint8_t>(0x5a) 79 #define _ static_cast<uint8_t>(0x5a)
78 #if defined(V8_TARGET_LITTLE_ENDIAN) 80 #if defined(V8_TARGET_LITTLE_ENDIAN)
79 #define U16(x) static_cast<uint8_t>((x) & 0xff), \ 81 #define U16(x) static_cast<uint8_t>((x) & 0xff), \
80 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff) 82 static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff)
81 #elif defined(V8_TARGET_BIG_ENDIAN) 83 #elif defined(V8_TARGET_BIG_ENDIAN)
82 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ 84 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \
83 static_cast<uint8_t>((x) & 0xff) 85 static_cast<uint8_t>((x) & 0xff)
84 #else 86 #else
85 #error Unknown byte ordering 87 #error Unknown byte ordering
86 #endif 88 #endif
(...skipping 28 matching lines...) Expand all
115 CHECK(String::cast(actual)->Equals(*expected_string)); 117 CHECK(String::cast(actual)->Equals(*expected_string));
116 } 118 }
117 119
118 120
119 static void CheckConstant(Handle<Object> expected, Object* actual) { 121 static void CheckConstant(Handle<Object> expected, Object* actual) {
120 CHECK(actual == *expected || expected->StrictEquals(actual)); 122 CHECK(actual == *expected || expected->StrictEquals(actual));
121 } 123 }
122 124
123 125
124 template <typename T> 126 template <typename T>
125 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, 127 static void CheckBytecodeArrayEqual(const ExpectedSnippet<T>& expected,
126 Handle<BytecodeArray> actual, 128 Handle<BytecodeArray> actual,
127 bool has_unknown = false) { 129 bool has_unknown = false) {
128 CHECK_EQ(actual->frame_size(), expected.frame_size); 130 CHECK_EQ(actual->frame_size(), expected.frame_size);
129 CHECK_EQ(actual->parameter_count(), expected.parameter_count); 131 CHECK_EQ(actual->parameter_count(), expected.parameter_count);
130 CHECK_EQ(actual->length(), expected.bytecode_length); 132 CHECK_EQ(actual->length(), expected.bytecode_length);
131 if (expected.constant_count != -1) { 133 if (expected.constant_count != -1) {
132 if (expected.constant_count == 0) { 134 if (expected.constant_count == 0) {
133 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array()); 135 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array());
134 } else { 136 } else {
135 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count); 137 CHECK_EQ(actual->constant_pool()->length(), expected.constant_count);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 6, 230 6,
229 { 231 {
230 B(LdaZero), // 232 B(LdaZero), //
231 B(Star), R(0), // 233 B(Star), R(0), //
232 B(Ldar), R(0), // 234 B(Ldar), R(0), //
233 B(Return) // 235 B(Return) //
234 }, 236 },
235 0 237 0
236 }, 238 },
237 {"var x = 0; return x + 3;", 239 {"var x = 0; return x + 3;",
238 2 * kPointerSize, 240 kPointerSize,
239 1, 241 1,
240 12, 242 8,
241 { 243 {
242 B(LdaZero), // 244 B(LdaZero), //
243 B(Star), R(0), // 245 B(Star), R(0), //
244 B(Ldar), R(0), // Easy to spot r1 not really needed here.
245 B(Star), R(1), // Dead store.
246 B(LdaSmi8), U8(3), // 246 B(LdaSmi8), U8(3), //
247 B(Add), R(1), // 247 B(Add), R(0), //
248 B(Return) // 248 B(Return) //
249 }, 249 },
250 0 250 0
251 }}; 251 }};
252 252
253 for (size_t i = 0; i < arraysize(snippets); i++) { 253 for (size_t i = 0; i < arraysize(snippets); i++) {
254 Handle<BytecodeArray> bytecode_array = 254 Handle<BytecodeArray> bytecode_array =
255 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 255 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
256 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 256 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
257 } 257 }
258 } 258 }
259 259
260 260
261 TEST(Parameters) { 261 TEST(Parameters) {
262 InitializedHandleScope handle_scope; 262 InitializedHandleScope handle_scope;
263 BytecodeGeneratorHelper helper; 263 BytecodeGeneratorHelper helper;
264 264
265 ExpectedSnippet<int> snippets[] = { 265 ExpectedSnippet<int> snippets[] = {
266 {"function f() { return this; }", 266 {"function f() { return this; }",
267 0, 1, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 267 0, 1, 3, {B(Ldar), THIS(1), B(Return)}, 0},
268 {"function f(arg1) { return arg1; }", 268 {"function f(arg1) { return arg1; }",
269 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 269 0, 2, 3, {B(Ldar), A(1, 2), B(Return)}, 0},
270 {"function f(arg1) { return this; }", 270 {"function f(arg1) { return this; }",
271 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex - 1), B(Return)}, 0}, 271 0, 2, 3, {B(Ldar), THIS(2), B(Return)}, 0},
272 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", 272 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
273 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 3), B(Return)}, 0}, 273 0, 8, 3, {B(Ldar), A(4, 8), B(Return)}, 0},
274 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", 274 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }",
275 0, 8, 3, {B(Ldar), R(helper.kLastParamIndex - 7), B(Return)}, 0}, 275 0,
276 8,
277 3,
278 {B(Ldar), THIS(8), B(Return)},
279 0},
276 {"function f(arg1) { arg1 = 1; }", 280 {"function f(arg1) { arg1 = 1; }",
277 0, 2, 6, 281 0, 2, 6,
278 {B(LdaSmi8), U8(1), // 282 {B(LdaSmi8), U8(1), //
279 B(Star), R(helper.kLastParamIndex), // 283 B(Star), A(1, 2), //
280 B(LdaUndefined), // 284 B(LdaUndefined), //
281 B(Return)}, 285 B(Return)},
282 0}, 286 0},
283 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", 287 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }",
284 0, 5, 6, 288 0, 5, 6,
285 {B(LdaSmi8), U8(1), // 289 {B(LdaSmi8), U8(1), //
286 B(Star), R(helper.kLastParamIndex - 2), // 290 B(Star), A(2, 5), //
287 B(LdaUndefined), // 291 B(LdaUndefined), //
288 B(Return)}, 292 B(Return)},
289 0}, 293 0},
290 }; 294 };
291 295
292 for (size_t i = 0; i < arraysize(snippets); i++) { 296 for (size_t i = 0; i < arraysize(snippets); i++) {
293 Handle<BytecodeArray> bytecode_array = 297 Handle<BytecodeArray> bytecode_array =
294 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 298 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
295 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 299 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
296 } 300 }
297 } 301 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 451
448 FeedbackVectorSpec feedback_spec(&zone); 452 FeedbackVectorSpec feedback_spec(&zone);
449 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); 453 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
450 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); 454 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot();
451 455
452 Handle<i::TypeFeedbackVector> vector = 456 Handle<i::TypeFeedbackVector> vector =
453 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 457 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
454 458
455 ExpectedSnippet<const char*> snippets[] = { 459 ExpectedSnippet<const char*> snippets[] = {
456 {"function f(a) { return a.name; }\nf({name : \"test\"})", 460 {"function f(a) { return a.name; }\nf({name : \"test\"})",
457 1 * kPointerSize, 461 0,
458 2, 462 2,
459 10, 463 6,
460 { 464 {
461 B(Ldar), R(helper.kLastParamIndex), // 465 B(LdaConstant), U8(0), //
462 B(Star), R(0), // 466 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
463 B(LdaConstant), U8(0), // 467 B(Return), //
464 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
465 B(Return) //
466 }, 468 },
467 1, 469 1,
468 {"name"}}, 470 {"name"}},
469 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})", 471 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})",
470 1 * kPointerSize, 472 0,
471 2, 473 2,
472 10, 474 6,
473 { 475 {
474 B(Ldar), R(helper.kLastParamIndex), // 476 B(LdaConstant), U8(0), //
475 B(Star), R(0), // 477 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
476 B(LdaConstant), U8(0), // 478 B(Return) //
477 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
478 B(Return) //
479 }, 479 },
480 1, 480 1,
481 {"key"}}, 481 {"key"}},
482 {"function f(a) { return a[100]; }\nf({100 : \"test\"})", 482 {"function f(a) { return a[100]; }\nf({100 : \"test\"})",
483 1 * kPointerSize, 483 0,
484 2, 484 2,
485 10, 485 6,
486 { 486 {
487 B(Ldar), R(helper.kLastParamIndex), // 487 B(LdaSmi8), U8(100), //
488 B(Star), R(0), // 488 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
489 B(LdaSmi8), U8(100), // 489 B(Return) //
490 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
491 B(Return) //
492 }, 490 },
493 0}, 491 0},
494 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")", 492 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")",
495 1 * kPointerSize, 493 0,
496 3, 494 3,
497 10, 495 6,
498 { 496 {
499 B(Ldar), R(helper.kLastParamIndex - 1), // 497 B(Ldar), A(1, 2), //
500 B(Star), R(0), // 498 B(KeyedLoadICSloppy), A(1, 3), U8(vector->GetIndex(slot1)), //
501 B(Ldar), R(helper.kLastParamIndex), // 499 B(Return) //
502 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), //
503 B(Return) //
504 }, 500 },
505 0}, 501 0},
506 {"function f(a) { var b = a.name; return a[-124]; }\n" 502 {"function f(a) { var b = a.name; return a[-124]; }\n"
507 "f({\"-124\" : \"test\", name : 123 })", 503 "f({\"-124\" : \"test\", name : 123 })",
508 2 * kPointerSize, 504 kPointerSize,
509 2, 505 2,
510 21, 506 13,
511 { 507 {
512 B(Ldar), R(helper.kLastParamIndex), // 508 B(LdaConstant), U8(0), //
513 B(Star), R(1), // 509 B(LoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
514 B(LdaConstant), U8(0), // 510 B(Star), R(0), //
515 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // 511 B(LdaSmi8), U8(-124), //
516 B(Star), R(0), // 512 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot2)), //
517 B(Ldar), R(helper.kLastParamIndex), // 513 B(Return), //
518 B(Star), R(1), //
519 B(LdaSmi8), U8(-124), //
520 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
521 B(Return) //
522 }, 514 },
523 1, 515 1,
524 {"name"}}, 516 {"name"}},
525 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})", 517 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})",
526 1 * kPointerSize, 518 0,
527 2, 519 2,
528 12, 520 8,
529 { 521 {
530 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 522 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
531 // expression, or any other unused literal expression. 523 // expression, or any other unused literal expression.
532 B(LdaConstant), U8(0), // 524 B(LdaConstant), U8(0), //
533 B(Ldar), R(helper.kLastParamIndex), // 525 B(LdaConstant), U8(1), //
534 B(Star), R(0), // 526 B(LoadICStrict), A(1, 2), U8(vector->GetIndex(slot1)), //
535 B(LdaConstant), U8(1), // 527 B(Return), //
536 B(LoadICStrict), R(0), U8(vector->GetIndex(slot1)), //
537 B(Return) //
538 }, 528 },
539 2, 529 2,
540 {"use strict", "name"}}, 530 {"use strict", "name"}},
541 {"function f(a, b) { \"use strict\"; return a[b]; }\n" 531 {"function f(a, b) { \"use strict\"; return a[b]; }\n"
542 "f({arg : \"test\"}, \"arg\")", 532 "f({arg : \"test\"}, \"arg\")",
543 1 * kPointerSize, 533 0,
544 3, 534 3,
545 12, 535 8,
546 { 536 {
547 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 537 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
548 // expression, or any other unused literal expression. 538 // expression, or any other unused literal expression.
549 B(LdaConstant), U8(0), // 539 B(LdaConstant), U8(0), //
550 B(Ldar), R(helper.kLastParamIndex - 1), // 540 B(Ldar), A(2, 3), //
551 B(Star), R(0), // 541 B(KeyedLoadICStrict), A(1, 3), U8(vector->GetIndex(slot1)), //
552 B(Ldar), R(helper.kLastParamIndex), // 542 B(Return), //
553 B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), //
554 B(Return) //
555 }, 543 },
556 1, 544 1,
557 {"use strict"}}}; 545 {"use strict"}}};
558 for (size_t i = 0; i < arraysize(snippets); i++) { 546 for (size_t i = 0; i < arraysize(snippets); i++) {
559 Handle<BytecodeArray> bytecode_array = 547 Handle<BytecodeArray> bytecode_array =
560 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 548 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
561 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 549 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
562 } 550 }
563 } 551 }
564 552
565 553
566 TEST(PropertyStores) { 554 TEST(PropertyStores) {
567 InitializedHandleScope handle_scope; 555 InitializedHandleScope handle_scope;
568 BytecodeGeneratorHelper helper; 556 BytecodeGeneratorHelper helper;
569 Zone zone; 557 Zone zone;
570 558
571 FeedbackVectorSpec feedback_spec(&zone); 559 FeedbackVectorSpec feedback_spec(&zone);
572 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); 560 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot();
573 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); 561 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
574 562
575 Handle<i::TypeFeedbackVector> vector = 563 Handle<i::TypeFeedbackVector> vector =
576 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 564 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
577 565
578 ExpectedSnippet<const char*> snippets[] = { 566 ExpectedSnippet<const char*> snippets[] = {
579 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", 567 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})",
580 2 * kPointerSize, 568 kPointerSize,
581 2, 569 2,
582 16, 570 12,
583 { 571 {
584 B(Ldar), R(helper.kLastParamIndex), // 572 B(LdaConstant), U8(0), //
585 B(Star), R(0), // 573 B(Star), R(0), //
586 B(LdaConstant), U8(0), // 574 B(LdaConstant), U8(1), //
587 B(Star), R(1), // 575 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
588 B(LdaConstant), U8(1), // 576 B(LdaUndefined), //
589 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 577 B(Return), //
590 B(LdaUndefined), //
591 B(Return) //
592 }, 578 },
593 2, 579 2,
594 {"name", "val"}}, 580 {"name", "val"}},
595 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})", 581 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})",
596 2 * kPointerSize, 582 kPointerSize,
597 2, 583 2,
598 16, 584 12,
599 { 585 {
600 B(Ldar), R(helper.kLastParamIndex), // 586 B(LdaConstant), U8(0), //
601 B(Star), R(0), // 587 B(Star), R(0), //
602 B(LdaConstant), U8(0), // 588 B(LdaConstant), U8(1), //
603 B(Star), R(1), // 589 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
604 B(LdaConstant), U8(1), // 590 B(LdaUndefined), //
605 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 591 B(Return), //
606 B(LdaUndefined), //
607 B(Return) //
608 }, 592 },
609 2, 593 2,
610 {"key", "val"}}, 594 {"key", "val"}},
611 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})", 595 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})",
612 2 * kPointerSize, 596 kPointerSize,
613 2, 597 2,
614 16, 598 12,
615 { 599 {
616 B(Ldar), R(helper.kLastParamIndex), // 600 B(LdaSmi8), U8(100), //
617 B(Star), R(0), // 601 B(Star), R(0), //
618 B(LdaSmi8), U8(100), // 602 B(LdaConstant), U8(0), //
619 B(Star), R(1), // 603 B(KeyedStoreICSloppy), A(1, 2), R(0), //
620 B(LdaConstant), U8(0), // 604 U8(vector->GetIndex(slot1)), //
621 B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), // 605 B(LdaUndefined), //
622 B(LdaUndefined), // 606 B(Return), //
623 B(Return) //
624 }, 607 },
625 1, 608 1,
626 {"val"}}, 609 {"val"}},
627 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")", 610 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")",
628 2 * kPointerSize, 611 0,
629 3, 612 3,
630 16, 613 8,
631 { 614 {
632 B(Ldar), R(helper.kLastParamIndex - 1), // 615 B(LdaConstant), U8(0), //
633 B(Star), R(0), // 616 B(KeyedStoreICSloppy), A(1, 3), A(2, 3), //
634 B(Ldar), R(helper.kLastParamIndex), // 617 U8(vector->GetIndex(slot1)), //
635 B(Star), R(1), // 618 B(LdaUndefined), //
636 B(LdaConstant), U8(0), // 619 B(Return), //
637 B(KeyedStoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot1)), //
638 B(LdaUndefined), //
639 B(Return) //
640 }, 620 },
641 1, 621 1,
642 {"val"}}, 622 {"val"}},
643 {"function f(a) { a.name = a[-124]; }\n" 623 {"function f(a) { a.name = a[-124]; }\n"
644 "f({\"-124\" : \"test\", name : 123 })", 624 "f({\"-124\" : \"test\", name : 123 })",
645 3 * kPointerSize, 625 kPointerSize,
646 2, 626 2,
647 23, 627 15,
648 { 628 {
649 B(Ldar), R(helper.kLastParamIndex), // 629 B(LdaConstant), U8(0), //
650 B(Star), R(0), // 630 B(Star), R(0), //
651 B(LdaConstant), U8(0), // 631 B(LdaSmi8), U8(-124), //
652 B(Star), R(1), // 632 B(KeyedLoadICSloppy), A(1, 2), U8(vector->GetIndex(slot1)), //
653 B(Ldar), R(helper.kLastParamIndex), // 633 B(StoreICSloppy), A(1, 2), R(0), U8(vector->GetIndex(slot2)), //
654 B(Star), R(2), // 634 B(LdaUndefined), //
655 B(LdaSmi8), U8(-124), // 635 B(Return), //
656 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), //
657 B(StoreICSloppy), R(0), R(1), U8(vector->GetIndex(slot2)), //
658 B(LdaUndefined), //
659 B(Return) //
660 }, 636 },
661 1, 637 1,
662 {"name"}}, 638 {"name"}},
663 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n" 639 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n"
664 "f({name : \"test\"})", 640 "f({name : \"test\"})",
665 2 * kPointerSize, 641 kPointerSize,
666 2, 642 2,
667 18, 643 14,
668 { 644 {
669 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 645 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
670 // expression, or any other unused literal expression. 646 // expression, or any other unused literal expression.
671 B(LdaConstant), U8(0), // 647 B(LdaConstant), U8(0), //
672 B(Ldar), R(helper.kLastParamIndex), // 648 B(LdaConstant), U8(1), //
673 B(Star), R(0), // 649 B(Star), R(0), //
674 B(LdaConstant), U8(1), // 650 B(LdaConstant), U8(2), //
675 B(Star), R(1), // 651 B(StoreICStrict), A(1, 2), R(0), U8(vector->GetIndex(slot1)), //
676 B(LdaConstant), U8(2), // 652 B(LdaUndefined), //
677 B(StoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // 653 B(Return), //
678 B(LdaUndefined), //
679 B(Return) //
680 }, 654 },
681 3, 655 3,
682 {"use strict", "name", "val"}}, 656 {"use strict", "name", "val"}},
683 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n" 657 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n"
684 "f({arg : \"test\"}, \"arg\")", 658 "f({arg : \"test\"}, \"arg\")",
685 2 * kPointerSize, 659 0,
686 3, 660 3,
687 18, 661 10,
688 { 662 {
689 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict" 663 // TODO(rmcilroy) Avoid unnecessary LdaConstant for "use strict"
690 // expression, or any other unused literal expression. 664 // expression, or any other unused literal expression.
691 B(LdaConstant), U8(0), // 665 B(LdaConstant), U8(0), //
692 B(Ldar), R(helper.kLastParamIndex - 1), // 666 B(LdaConstant), U8(1), //
693 B(Star), R(0), // 667 B(KeyedStoreICStrict), A(1, 3), A(2, 3), //
694 B(Ldar), R(helper.kLastParamIndex), // 668 U8(vector->GetIndex(slot1)), //
695 B(Star), R(1), // 669 B(LdaUndefined), //
696 B(LdaConstant), U8(1), // 670 B(Return), //
697 B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), //
698 B(LdaUndefined), //
699 B(Return) //
700 }, 671 },
701 2, 672 2,
702 {"use strict", "val"}}}; 673 {"use strict", "val"}}};
703 for (size_t i = 0; i < arraysize(snippets); i++) { 674 for (size_t i = 0; i < arraysize(snippets); i++) {
704 Handle<BytecodeArray> bytecode_array = 675 Handle<BytecodeArray> bytecode_array =
705 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 676 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
706 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 677 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
707 } 678 }
708 } 679 }
709 680
(...skipping 13 matching lines...) Expand all
723 694
724 Handle<i::TypeFeedbackVector> vector = 695 Handle<i::TypeFeedbackVector> vector =
725 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); 696 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
726 697
727 ExpectedSnippet<const char*> snippets[] = { 698 ExpectedSnippet<const char*> snippets[] = {
728 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", 699 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")",
729 2 * kPointerSize, 700 2 * kPointerSize,
730 2, 701 2,
731 16, 702 16,
732 { 703 {
733 B(Ldar), R(helper.kLastParamIndex), // 704 B(Ldar), A(1, 2), //
734 B(Star), R(1), // 705 B(Star), R(1), //
735 B(LdaConstant), U8(0), // 706 B(LdaConstant), U8(0), //
736 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 707 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
737 B(Star), R(0), // 708 B(Star), R(0), //
738 B(Call), R(0), R(1), U8(0), // 709 B(Call), R(0), R(1), U8(0), //
739 B(Return) // 710 B(Return), //
740 }, 711 },
741 1, 712 1,
742 {"func"}}, 713 {"func"}},
743 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", 714 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)",
744 4 * kPointerSize, 715 4 * kPointerSize,
745 4, 716 4,
746 24, 717 24,
747 { 718 {
748 B(Ldar), R(helper.kLastParamIndex - 2), // 719 B(Ldar), A(1, 4), //
749 B(Star), R(1), // 720 B(Star), R(1), //
750 B(LdaConstant), U8(0), // 721 B(LdaConstant), U8(0), //
751 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 722 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
752 B(Star), R(0), // 723 B(Star), R(0), //
753 B(Ldar), R(helper.kLastParamIndex - 1), // 724 B(Ldar), A(2, 4), //
754 B(Star), R(2), // 725 B(Star), R(2), //
755 B(Ldar), R(helper.kLastParamIndex), // 726 B(Ldar), A(3, 4), //
756 B(Star), R(3), // 727 B(Star), R(3), //
757 B(Call), R(0), R(1), U8(2), // 728 B(Call), R(0), R(1), U8(2), //
758 B(Return) // 729 B(Return) //
759 }, 730 },
760 1, 731 1,
761 {"func"}}, 732 {"func"}},
762 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", 733 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)",
763 4 * kPointerSize, 734 4 * kPointerSize,
764 3, 735 3,
765 30, 736 26,
766 { 737 {
767 B(Ldar), R(helper.kLastParamIndex - 1), // 738 B(Ldar), A(1, 3), //
768 B(Star), R(1), // 739 B(Star), R(1), //
769 B(LdaConstant), U8(0), // 740 B(LdaConstant), U8(0), //
770 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // 741 B(LoadICSloppy), R(1), U8(vector->GetIndex(slot2)), //
771 B(Star), R(0), // 742 B(Star), R(0), //
772 B(Ldar), R(helper.kLastParamIndex), // 743 B(Ldar), A(2, 3), //
744 B(Add), A(2, 3), //
773 B(Star), R(2), // 745 B(Star), R(2), //
774 B(Ldar), R(helper.kLastParamIndex), // 746 B(Ldar), A(2, 3), //
775 B(Add), R(2), //
776 B(Star), R(2), //
777 B(Ldar), R(helper.kLastParamIndex), //
778 B(Star), R(3), // 747 B(Star), R(3), //
779 B(Call), R(0), R(1), U8(2), // 748 B(Call), R(0), R(1), U8(2), //
780 B(Return) // 749 B(Return), //
781 }, 750 },
782 1, 751 1,
783 {"func"}}}; 752 {"func"}}};
784 for (size_t i = 0; i < arraysize(snippets); i++) { 753 for (size_t i = 0; i < arraysize(snippets); i++) {
785 Handle<BytecodeArray> bytecode_array = 754 Handle<BytecodeArray> bytecode_array =
786 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 755 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
787 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 756 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
788 } 757 }
789 } 758 }
790 759
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 B(LdaUndefined), // 1001 B(LdaUndefined), //
1033 B(Return) // 1002 B(Return) //
1034 }, 1003 },
1035 }, 1004 },
1036 { 1005 {
1037 "function f(a) { return %IsArray(a) }\nf(undefined)", 1006 "function f(a) { return %IsArray(a) }\nf(undefined)",
1038 1 * kPointerSize, 1007 1 * kPointerSize,
1039 2, 1008 2,
1040 10, 1009 10,
1041 { 1010 {
1042 B(Ldar), R(helper.kLastParamIndex), // 1011 B(Ldar), A(1, 2), //
1043 B(Star), R(0), // 1012 B(Star), R(0), //
1044 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), // 1013 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), //
1045 B(Return) // 1014 B(Return) //
1046 }, 1015 },
1047 }, 1016 },
1048 { 1017 {
1049 "function f() { return %Add(1, 2) }\nf()", 1018 "function f() { return %Add(1, 2) }\nf()",
1050 2 * kPointerSize, 1019 2 * kPointerSize,
1051 1, 1020 1,
1052 14, 1021 14,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 B(Return), // 1088 B(Return), //
1120 B(Jump), U8(5), // 1089 B(Jump), U8(5), //
1121 B(LdaSmi8), U8(-1), // 1090 B(LdaSmi8), U8(-1), //
1122 B(Return), // 1091 B(Return), //
1123 B(LdaUndefined), // 1092 B(LdaUndefined), //
1124 B(Return)}, // 1093 B(Return)}, //
1125 0, 1094 0,
1126 {unused, unused, unused, unused}}, 1095 {unused, unused, unused, unused}},
1127 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" 1096 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }"
1128 "f(99);", 1097 "f(99);",
1129 kPointerSize, 1098 0,
1130 2, 1099 2,
1131 19, 1100 15,
1132 {B(Ldar), R(helper.kLastParamIndex), // 1101 {B(LdaZero), //
1133 B(Star), R(0), // 1102 B(TestLessThanOrEqual), A(1, 2), //
1134 B(LdaZero), // 1103 B(JumpIfFalse), U8(7), //
1135 B(TestLessThanOrEqual), R(0), // 1104 B(LdaConstant), U8(0), //
1136 B(JumpIfFalse), U8(7), // 1105 B(Return), //
1137 B(LdaConstant), U8(0), // 1106 B(Jump), U8(5), //
1138 B(Return), // 1107 B(LdaConstant), U8(1), //
1139 B(Jump), U8(5), // 1108 B(Return), //
1140 B(LdaConstant), U8(1), // 1109 B(LdaUndefined), //
1141 B(Return), // 1110 B(Return)}, //
1142 B(LdaUndefined), //
1143 B(Return)}, //
1144 2, 1111 2,
1145 {helper.factory()->NewNumberFromInt(200), 1112 {helper.factory()->NewNumberFromInt(200),
1146 helper.factory()->NewNumberFromInt(-200), unused, unused}}, 1113 helper.factory()->NewNumberFromInt(-200), unused, unused}},
1147 {"function f(a, b) { if (a in b) { return 200; } }" 1114 {"function f(a, b) { if (a in b) { return 200; } }"
1148 "f('prop', { prop: 'yes'});", 1115 "f('prop', { prop: 'yes'});",
1149 kPointerSize, 1116 0,
1150 3, 1117 3,
1151 15, 1118 11,
1152 {B(Ldar), R(helper.kLastParamIndex - 1), // 1119 {B(Ldar), A(2, 3), //
1153 B(Star), R(0), // 1120 B(TestIn), A(1, 3), //
1154 B(Ldar), R(helper.kLastParamIndex), // 1121 B(JumpIfFalse), U8(5), //
1155 B(TestIn), R(0), // 1122 B(LdaConstant), U8(0), //
1156 B(JumpIfFalse), U8(5), // 1123 B(Return), //
1157 B(LdaConstant), U8(0), // 1124 B(LdaUndefined), //
1158 B(Return), // 1125 B(Return)}, //
1159 B(LdaUndefined), //
1160 B(Return)}, //
1161 1, 1126 1,
1162 {helper.factory()->NewNumberFromInt(200), unused, unused, unused}}, 1127 {helper.factory()->NewNumberFromInt(200), unused, unused, unused}},
1163 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " 1128 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
1164 #define X "b = a; a = b; " 1129 #define X "b = a; a = b; "
1165 X X X X X X X X X X X X X X X X X X X X X X X X 1130 X X X X X X X X X X X X X X X X X X X X X X X X
1166 #undef X 1131 #undef X
1167 " return 200; } else { return -200; } } f(0.001)", 1132 " return 200; } else { return -200; } } f(0.001)",
1168 3 * kPointerSize, 1133 2 * kPointerSize,
1169 2, 1134 2,
1170 218, 1135 214,
1171 {B(LdaZero), // 1136 {
1172 B(Star), R(0), // 1137 #define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0)
1173 B(LdaZero), // 1138 B(LdaZero), //
1174 B(Star), R(1), // 1139 B(Star), R(0), //
1175 B(Ldar), R(0), // 1140 B(LdaZero), //
1176 B(Star), R(2), // 1141 B(Star), R(1), //
1177 B(LdaConstant), U8(0), // 1142 B(LdaConstant), U8(0), //
1178 B(TestEqualStrict), R(2), // 1143 B(TestEqualStrict), R(0), //
1179 B(JumpIfFalseConstant), U8(2), // 1144 B(JumpIfFalseConstant), U8(2), //
1180 #define X B(Ldar), R(0), B(Star), R(1), B(Ldar), R(1), B(Star), R(0), 1145 X, X, X, X, X, X, X, X, X, X, //
1181 X X X X X X X X X X X X X X X X X X X X X X X X 1146 X, X, X, X, X, X, X, X, X, X, //
1147 X, X, X, X, //
1148 B(LdaConstant), U8(1), //
1149 B(Return), //
1150 B(Jump), U8(5), //
1151 B(LdaConstant), U8(3), //
1152 B(Return), //
1153 B(LdaUndefined), //
1154 B(Return)}, //
1182 #undef X 1155 #undef X
1183 B(LdaConstant), U8(1), //
1184 B(Return), //
1185 B(Jump), U8(5), //
1186 B(LdaConstant), U8(3), //
1187 B(Return), //
1188 B(LdaUndefined), //
1189 B(Return)}, //
1190 4, 1156 4,
1191 {helper.factory()->NewHeapNumber(0.01), 1157 {helper.factory()->NewHeapNumber(0.01),
1192 helper.factory()->NewNumberFromInt(200), 1158 helper.factory()->NewNumberFromInt(200),
1193 helper.factory()->NewNumberFromInt(199), 1159 helper.factory()->NewNumberFromInt(199),
1194 helper.factory()->NewNumberFromInt(-200)}}, 1160 helper.factory()->NewNumberFromInt(-200)}},
1195 {"function f(a, b) {\n" 1161 {"function f(a, b) {\n"
1196 " if (a == b) { return 1; }\n" 1162 " if (a == b) { return 1; }\n"
1197 " if (a === b) { return 1; }\n" 1163 " if (a === b) { return 1; }\n"
1198 " if (a < b) { return 1; }\n" 1164 " if (a < b) { return 1; }\n"
1199 " if (a > b) { return 1; }\n" 1165 " if (a > b) { return 1; }\n"
1200 " if (a <= b) { return 1; }\n" 1166 " if (a <= b) { return 1; }\n"
1201 " if (a >= b) { return 1; }\n" 1167 " if (a >= b) { return 1; }\n"
1202 " if (a in b) { return 1; }\n" 1168 " if (a in b) { return 1; }\n"
1203 " if (a instanceof b) { return 1; }\n" 1169 " if (a instanceof b) { return 1; }\n"
1204 " /* if (a != b) { return 1; } */" // TODO(oth) Ast visitor yields
1205 " /* if (a !== b) { return 1; } */" // UNARY NOT, rather than !=/!==.
1206 " return 0;\n" 1170 " return 0;\n"
1207 "} f(1, 1);", 1171 "} f(1, 1);",
1208 kPointerSize, 1172 0,
1209 3, 1173 3,
1210 106, 1174 74,
1211 { 1175 {
1212 #define IF_CONDITION_RETURN(condition) \ 1176 #define IF_CONDITION_RETURN(condition) \
1213 B(Ldar), R(helper.kLastParamIndex - 1), \ 1177 B(Ldar), A(2, 3), \
1214 B(Star), R(0), \ 1178 B(condition), A(1, 3), \
1215 B(Ldar), R(helper.kLastParamIndex), \ 1179 B(JumpIfFalse), U8(5), \
1216 B(condition), R(0), \ 1180 B(LdaSmi8), U8(1), \
1217 B(JumpIfFalse), U8(5), \ 1181 B(Return),
1218 B(LdaSmi8), U8(1), \
1219 B(Return),
1220 IF_CONDITION_RETURN(TestEqual) // 1182 IF_CONDITION_RETURN(TestEqual) //
1221 IF_CONDITION_RETURN(TestEqualStrict) // 1183 IF_CONDITION_RETURN(TestEqualStrict) //
1222 IF_CONDITION_RETURN(TestLessThan) // 1184 IF_CONDITION_RETURN(TestLessThan) //
1223 IF_CONDITION_RETURN(TestGreaterThan) // 1185 IF_CONDITION_RETURN(TestGreaterThan) //
1224 IF_CONDITION_RETURN(TestLessThanOrEqual) // 1186 IF_CONDITION_RETURN(TestLessThanOrEqual) //
1225 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // 1187 IF_CONDITION_RETURN(TestGreaterThanOrEqual) //
1226 IF_CONDITION_RETURN(TestIn) // 1188 IF_CONDITION_RETURN(TestIn) //
1227 IF_CONDITION_RETURN(TestInstanceOf) // 1189 IF_CONDITION_RETURN(TestInstanceOf) //
1190 B(LdaZero), //
1191 B(Return)}, //
1228 #undef IF_CONDITION_RETURN 1192 #undef IF_CONDITION_RETURN
1229 B(LdaZero), //
1230 B(Return)}, //
1231 0, 1193 0,
1232 {unused, unused, unused, unused}}, 1194 {unused, unused, unused, unused}},
1233 }; 1195 };
1234 1196
1235 for (size_t i = 0; i < arraysize(snippets); i++) { 1197 for (size_t i = 0; i < arraysize(snippets); i++) {
1236 Handle<BytecodeArray> bytecode_array = 1198 Handle<BytecodeArray> bytecode_array =
1237 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); 1199 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName);
1238 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1200 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1239 } 1201 }
1240 } 1202 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 1254
1293 1255
1294 TEST(BasicLoops) { 1256 TEST(BasicLoops) {
1295 InitializedHandleScope handle_scope; 1257 InitializedHandleScope handle_scope;
1296 BytecodeGeneratorHelper helper; 1258 BytecodeGeneratorHelper helper;
1297 1259
1298 ExpectedSnippet<int> snippets[] = { 1260 ExpectedSnippet<int> snippets[] = {
1299 {"var x = 0;" 1261 {"var x = 0;"
1300 "var y = 1;" 1262 "var y = 1;"
1301 "while (x < 10) {" 1263 "while (x < 10) {"
1302 " y = y * 10;" 1264 " y = y * 12;"
1303 " x = x + 1;" 1265 " x = x + 1;"
1304 "}" 1266 "}"
1305 "return y;", 1267 "return y;",
1306 3 * kPointerSize, 1268 2 * kPointerSize,
1307 1, 1269 1,
1308 42, 1270 30,
1309 { 1271 {
1310 B(LdaZero), // 1272 B(LdaZero), //
1311 B(Star), R(0), // 1273 B(Star), R(0), //
1312 B(LdaSmi8), U8(1), // 1274 B(LdaSmi8), U8(1), //
1313 B(Star), R(1), // 1275 B(Star), R(1), //
1314 B(Jump), U8(22), // 1276 B(Jump), U8(14), //
1315 B(Ldar), R(1), // 1277 B(LdaSmi8), U8(12), //
1316 B(Star), R(2), // 1278 B(Mul), R(1), //
1279 B(Star), R(1), //
1280 B(LdaSmi8), U8(1), //
1281 B(Add), R(0), //
1282 B(Star), R(0), //
1317 B(LdaSmi8), U8(10), // 1283 B(LdaSmi8), U8(10), //
1318 B(Mul), R(2), // 1284 B(TestLessThan), R(0), //
1319 B(Star), R(1), // 1285 B(JumpIfTrue), U8(-16), //
1320 B(Ldar), R(0), //
1321 B(Star), R(2), //
1322 B(LdaSmi8), U8(1), //
1323 B(Add), R(2), //
1324 B(Star), R(0), //
1325 B(Ldar), R(0), //
1326 B(Star), R(2), //
1327 B(LdaSmi8), U8(10), //
1328 B(TestLessThan), R(2), //
1329 B(JumpIfTrue), U8(-28), //
1330 B(Ldar), R(1), // 1286 B(Ldar), R(1), //
1331 B(Return), // 1287 B(Return), //
1332 }, 1288 },
1333 0}, 1289 0},
1334 {"var i = 0;" 1290 {"var i = 0;"
1335 "while(true) {" 1291 "while(true) {"
1336 " if (i < 0) continue;" 1292 " if (i < 0) continue;"
1337 " if (i == 3) break;" 1293 " if (i == 3) break;"
1338 " if (i == 4) break;" 1294 " if (i == 4) break;"
1339 " if (i == 10) continue;" 1295 " if (i == 10) continue;"
1340 " if (i == 5) break;" 1296 " if (i == 5) break;"
1341 " i = i + 1;" 1297 " i = i + 1;"
1342 "}" 1298 "}"
1343 "return i;", 1299 "return i;",
1344 2 * kPointerSize, 1300 1 * kPointerSize,
1345 1, 1301 1,
1346 80, 1302 56,
1347 { 1303 {
1348 B(LdaZero), // 1304 B(LdaZero), //
1349 B(Star), R(0), // 1305 B(Star), R(0), //
1350 B(Jump), U8(71), // 1306 B(Jump), U8(47), //
1351 B(Ldar), R(0), //
1352 B(Star), R(1), //
1353 B(LdaZero), // 1307 B(LdaZero), //
1354 B(TestLessThan), R(1), // 1308 B(TestLessThan), R(0), //
1355 B(JumpIfFalse), U8(4), // 1309 B(JumpIfFalse), U8(4), //
1356 B(Jump), U8(60), // 1310 B(Jump), U8(40), //
1357 B(Ldar), R(0), //
1358 B(Star), R(1), //
1359 B(LdaSmi8), U8(3), // 1311 B(LdaSmi8), U8(3), //
1360 B(TestEqual), R(1), // 1312 B(TestEqual), R(0), //
1361 B(JumpIfFalse), U8(4), // 1313 B(JumpIfFalse), U8(4), //
1362 B(Jump), U8(51), // 1314 B(Jump), U8(35), //
1363 B(Ldar), R(0), //
1364 B(Star), R(1), //
1365 B(LdaSmi8), U8(4), // 1315 B(LdaSmi8), U8(4), //
1366 B(TestEqual), R(1), // 1316 B(TestEqual), R(0), //
1367 B(JumpIfFalse), U8(4), // 1317 B(JumpIfFalse), U8(4), //
1368 B(Jump), U8(39), // 1318 B(Jump), U8(27), //
1369 B(Ldar), R(0), //
1370 B(Star), R(1), //
1371 B(LdaSmi8), U8(10), // 1319 B(LdaSmi8), U8(10), //
1372 B(TestEqual), R(1), // 1320 B(TestEqual), R(0), //
1373 B(JumpIfFalse), U8(4), // 1321 B(JumpIfFalse), U8(4), //
1374 B(Jump), U8(24), // 1322 B(Jump), U8(16), //
1375 B(Ldar), R(0), //
1376 B(Star), R(1), //
1377 B(LdaSmi8), U8(5), // 1323 B(LdaSmi8), U8(5), //
1378 B(TestEqual), R(1), // 1324 B(TestEqual), R(0), //
1379 B(JumpIfFalse), U8(4), // 1325 B(JumpIfFalse), U8(4), //
1380 B(Jump), U8(15), // 1326 B(Jump), U8(11), //
1381 B(Ldar), R(0), //
1382 B(Star), R(1), //
1383 B(LdaSmi8), U8(1), // 1327 B(LdaSmi8), U8(1), //
1384 B(Add), R(1), // 1328 B(Add), R(0), //
1385 B(Star), R(0), // 1329 B(Star), R(0), //
1386 B(LdaTrue), // 1330 B(LdaTrue), //
1387 B(JumpIfTrue), U8(-70), // 1331 B(JumpIfTrue), U8(-46), //
1388 B(Ldar), R(0), // 1332 B(Ldar), R(0), //
1389 B(Return) // 1333 B(Return), //
1390 }, 1334 },
1391 0}, 1335 0},
1392 {"var x = 0; var y = 1;" 1336 {"var x = 0; var y = 1;"
1393 "do {" 1337 "do {"
1394 " y = y * 10;" 1338 " y = y * 10;"
1395 " if (x == 5) break;" 1339 " if (x == 5) break;"
1396 " if (x == 6) continue;" 1340 " if (x == 6) continue;"
1397 " x = x + 1;" 1341 " x = x + 1;"
1398 "} while (x < 10);" 1342 "} while (x < 10);"
1399 "return y;", 1343 "return y;",
1400 3 * kPointerSize, 1344 2 * kPointerSize,
1401 1, 1345 1,
1402 64, 1346 44,
1403 { 1347 {
1404 B(LdaZero), // 1348 B(LdaZero), //
1405 B(Star), R(0), // 1349 B(Star), R(0), //
1406 B(LdaSmi8), U8(1), // 1350 B(LdaSmi8), U8(1), //
1407 B(Star), R(1), // 1351 B(Star), R(1), //
1352 B(LdaSmi8), U8(10), //
1353 B(Mul), R(1), //
1354 B(Star), R(1), //
1355 B(LdaSmi8), U8(5), //
1356 B(TestEqual), R(0), //
1357 B(JumpIfFalse), U8(4), //
1358 B(Jump), U8(22), //
1359 B(LdaSmi8), U8(6), //
1360 B(TestEqual), R(0), //
1361 B(JumpIfFalse), U8(4), //
1362 B(Jump), U8(8), //
1363 B(LdaSmi8), U8(1), //
1364 B(Add), R(0), //
1365 B(Star), R(0), //
1366 B(LdaSmi8), U8(10), //
1367 B(TestLessThan), R(0), //
1368 B(JumpIfTrue), U8(-32), //
1408 B(Ldar), R(1), // 1369 B(Ldar), R(1), //
1409 B(Star), R(2), // 1370 B(Return), //
1410 B(LdaSmi8), U8(10), //
1411 B(Mul), R(2), //
1412 B(Star), R(1), //
1413 B(Ldar), R(0), //
1414 B(Star), R(2), //
1415 B(LdaSmi8), U8(5), //
1416 B(TestEqual), R(2), //
1417 B(JumpIfFalse), U8(4), //
1418 B(Jump), U8(34), //
1419 B(Ldar), R(0), //
1420 B(Star), R(2), //
1421 B(LdaSmi8), U8(6), //
1422 B(TestEqual), R(2), //
1423 B(JumpIfFalse), U8(4), //
1424 B(Jump), U8(12), //
1425 B(Ldar), R(0), //
1426 B(Star), R(2), //
1427 B(LdaSmi8), U8(1), //
1428 B(Add), R(2), //
1429 B(Star), R(0), //
1430 B(Ldar), R(0), //
1431 B(Star), R(2), //
1432 B(LdaSmi8), U8(10), //
1433 B(TestLessThan), R(2), //
1434 B(JumpIfTrue), U8(-52), //
1435 B(Ldar), R(1), //
1436 B(Return) //
1437 }, 1371 },
1438 0}, 1372 0},
1439 {"var x = 0; " 1373 {"var x = 0; "
1440 "for(;;) {" 1374 "for(;;) {"
1441 " if (x == 1) break;" 1375 " if (x == 1) break;"
1442 " x = x + 1;" 1376 " x = x + 1;"
1443 "}", 1377 "}",
1444 2 * kPointerSize, 1378 1 * kPointerSize,
1445 1, 1379 1,
1446 29, 1380 21,
1447 { 1381 {
1448 B(LdaZero), // 1382 B(LdaZero), //
1449 B(Star), R(0), // 1383 B(Star), R(0), //
1450 B(Ldar), R(0), // 1384 B(LdaSmi8), U8(1), //
1451 B(Star), R(1), // 1385 B(TestEqual), R(0), //
1452 B(LdaSmi8), //
1453 U8(1), //
1454 B(TestEqual), R(1), //
1455 B(JumpIfFalse), U8(4), // 1386 B(JumpIfFalse), U8(4), //
1456 B(Jump), U8(14), // 1387 B(Jump), U8(10), //
1457 B(Ldar), R(0), //
1458 B(Star), R(1), //
1459 B(LdaSmi8), U8(1), // 1388 B(LdaSmi8), U8(1), //
1460 B(Add), R(1), // 1389 B(Add), R(0), //
1461 B(Star), R(0), // 1390 B(Star), R(0), //
1462 B(Jump), U8(-22), // 1391 B(Jump), U8(-14), //
1463 B(LdaUndefined), // 1392 B(LdaUndefined), //
1464 B(Return), // 1393 B(Return), //
1465 }, 1394 },
1466 0}, 1395 0},
1467 {"var u = 0;" 1396 {"var u = 0;"
1468 "for(var i = 0; i < 100; i = i + 1) {" 1397 "for(var i = 0; i < 100; i = i + 1) {"
1469 " u = u + 1;" 1398 " u = u + 1;"
1470 " continue;" 1399 " continue;"
1471 "}", 1400 "}",
1472 3 * kPointerSize, 1401 2 * kPointerSize,
1473 1, 1402 1,
1474 42, 1403 30,
1475 { 1404 {
1476 B(LdaZero), // 1405 B(LdaZero), //
1477 B(Star), R(0), // 1406 B(Star), R(0), //
1478 B(LdaZero), // 1407 B(LdaZero), //
1479 B(Star), R(1), // 1408 B(Star), R(1), //
1480 B(Jump), U8(24), // 1409 B(Jump), U8(16), //
1481 B(Ldar), R(0), //
1482 B(Star), R(2), //
1483 B(LdaSmi8), U8(1), // 1410 B(LdaSmi8), U8(1), //
1484 B(Add), R(2), // 1411 B(Add), R(0), //
1485 B(Star), R(0), // 1412 B(Star), R(0), //
1486 B(Jump), U8(2), // 1413 B(Jump), U8(2), //
1487 B(Ldar), R(1), //
1488 B(Star), R(2), //
1489 B(LdaSmi8), U8(1), // 1414 B(LdaSmi8), U8(1), //
1490 B(Add), R(2), // 1415 B(Add), R(1), //
1491 B(Star), R(1), // 1416 B(Star), R(1), //
1492 B(Ldar), R(1), //
1493 B(Star), R(2), //
1494 B(LdaSmi8), U8(100), // 1417 B(LdaSmi8), U8(100), //
1495 B(TestLessThan), R(2), // 1418 B(TestLessThan), R(1), //
1496 B(JumpIfTrue), U8(-30), // 1419 B(JumpIfTrue), U8(-18), //
1497 B(LdaUndefined), // 1420 B(LdaUndefined), //
1498 B(Return), // 1421 B(Return), //
1499 }, 1422 },
1500 0}, 1423 0},
1501 {"var i = 0;" 1424 {"var i = 0;"
1502 "while(true) {" 1425 "while(true) {"
1503 " while (i < 3) {" 1426 " while (i < 3) {"
1504 " if (i == 2) break;" 1427 " if (i == 2) break;"
1505 " i = i + 1;" 1428 " i = i + 1;"
1506 " }" 1429 " }"
1507 " i = i + 1;" 1430 " i = i + 1;"
1508 " break;" 1431 " break;"
1509 "}" 1432 "}"
1510 "return i;", 1433 "return i;",
1511 2 * kPointerSize, 1434 1 * kPointerSize,
1512 1, 1435 1,
1513 57, 1436 41,
1514 { 1437 {
1515 B(LdaZero), // 1438 B(LdaZero), //
1516 B(Star), R(0), // 1439 B(Star), R(0), //
1517 B(Jump), U8(48), // 1440 B(Jump), U8(32), //
1518 B(Jump), U8(24), // 1441 B(Jump), U8(16), //
1519 B(Ldar), R(0), //
1520 B(Star), R(1), //
1521 B(LdaSmi8), U8(2), // 1442 B(LdaSmi8), U8(2), //
1522 B(TestEqual), R(1), // 1443 B(TestEqual), R(0), //
1523 B(JumpIfFalse), U8(4), // 1444 B(JumpIfFalse), U8(4), //
1524 B(Jump), U8(22), // 1445 B(Jump), U8(14), //
1525 B(Ldar), R(0), //
1526 B(Star), R(1), //
1527 B(LdaSmi8), U8(1), // 1446 B(LdaSmi8), U8(1), //
1528 B(Add), R(1), // 1447 B(Add), R(0), //
1529 B(Star), R(0), // 1448 B(Star), R(0), //
1530 B(Ldar), R(0), //
1531 B(Star), R(1), //
1532 B(LdaSmi8), U8(3), // 1449 B(LdaSmi8), U8(3), //
1533 B(TestLessThan), R(1), // 1450 B(TestLessThan), R(0), //
1534 B(JumpIfTrue), U8(-30), // 1451 B(JumpIfTrue), U8(-18), //
1535 B(Ldar), R(0), //
1536 B(Star), R(1), //
1537 B(LdaSmi8), U8(1), // 1452 B(LdaSmi8), U8(1), //
1538 B(Add), R(1), // 1453 B(Add), R(0), //
1539 B(Star), R(0), // 1454 B(Star), R(0), //
1540 B(Jump), U8(5), // 1455 B(Jump), U8(5), //
1541 B(LdaTrue), // 1456 B(LdaTrue), //
1542 B(JumpIfTrue), U8(-47), // 1457 B(JumpIfTrue), U8(-31), //
1543 B(Ldar), R(0), // 1458 B(Ldar), R(0), //
1544 B(Return), // 1459 B(Return), //
1545 }, 1460 },
1546 0}, 1461 0},
1547 }; 1462 };
1548 1463
1549 for (size_t i = 0; i < arraysize(snippets); i++) { 1464 for (size_t i = 0; i < arraysize(snippets); i++) {
1550 Handle<BytecodeArray> bytecode_array = 1465 Handle<BytecodeArray> bytecode_array =
1551 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1466 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1552 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1467 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1553 } 1468 }
1554 } 1469 }
1555 1470
1556 1471
1557 TEST(UnaryOperators) { 1472 TEST(UnaryOperators) {
1558 InitializedHandleScope handle_scope; 1473 InitializedHandleScope handle_scope;
1559 BytecodeGeneratorHelper helper; 1474 BytecodeGeneratorHelper helper;
1560 1475
1561 ExpectedSnippet<int> snippets[] = { 1476 ExpectedSnippet<int> snippets[] = {
1562 {"var x = 0;" 1477 {"var x = 0;"
1563 "while (x != 10) {" 1478 "while (x != 10) {"
1564 " x = x + 10;" 1479 " x = x + 10;"
1565 "}" 1480 "}"
1566 "return x;", 1481 "return x;",
1567 2 * kPointerSize, 1482 kPointerSize,
1568 1, 1483 1,
1569 29, 1484 21,
1570 { 1485 {
1571 B(LdaZero), // 1486 B(LdaZero), //
1572 B(Star), R(0), // 1487 B(Star), R(0), //
1573 B(Jump), U8(12), // 1488 B(Jump), U8(8), //
1574 B(Ldar), R(0), // 1489 B(LdaSmi8), U8(10), //
1575 B(Star), R(1), // 1490 B(Add), R(0), //
1576 B(LdaSmi8), U8(10), // 1491 B(Star), R(0), //
1577 B(Add), R(1), // 1492 B(LdaSmi8), U8(10), //
1578 B(Star), R(0), // 1493 B(TestEqual), R(0), //
1579 B(Ldar), R(0), // 1494 B(LogicalNot), //
1580 B(Star), R(1), // 1495 B(JumpIfTrue), U8(-11), //
1581 B(LdaSmi8), U8(10), // 1496 B(Ldar), R(0), //
1582 B(TestEqual), R(1), // 1497 B(Return), //
1583 B(LogicalNot), //
1584 B(JumpIfTrue), U8(-19), //
1585 B(Ldar), R(0), //
1586 B(Return), //
1587 }, 1498 },
1588 0}, 1499 0},
1589 {"var x = false;" 1500 {"var x = false;"
1590 "do {" 1501 "do {"
1591 " x = !x;" 1502 " x = !x;"
1592 "} while(x == false);" 1503 "} while(x == false);"
1593 "return x;", 1504 "return x;",
1594 2 * kPointerSize, 1505 kPointerSize,
1595 1, 1506 1,
1596 20, 1507 16,
1597 { 1508 {
1598 B(LdaFalse), // 1509 B(LdaFalse), //
1599 B(Star), R(0), // 1510 B(Star), R(0), //
1600 B(Ldar), R(0), // 1511 B(Ldar), R(0), //
1601 B(LogicalNot), // 1512 B(LogicalNot), //
1602 B(Star), R(0), // 1513 B(Star), R(0), //
1603 B(Ldar), R(0), // 1514 B(LdaFalse), //
1604 B(Star), R(1), // 1515 B(TestEqual), R(0), //
1605 B(LdaFalse), // 1516 B(JumpIfTrue), U8(-8), //
1606 B(TestEqual), R(1), // 1517 B(Ldar), R(0), //
1607 B(JumpIfTrue), U8(-12), // 1518 B(Return), //
1608 B(Ldar), R(0), //
1609 B(Return), //
1610 }, 1519 },
1611 0}, 1520 0},
1612 {"var x = 101;" 1521 {"var x = 101;"
1613 "return void(x * 3);", 1522 "return void(x * 3);",
1614 2 * kPointerSize, 1523 kPointerSize,
1615 1, 1524 1,
1616 14, 1525 10,
1617 { 1526 {
1618 B(LdaSmi8), U8(101), // 1527 B(LdaSmi8), U8(101), //
1619 B(Star), R(0), // 1528 B(Star), R(0), //
1620 B(Ldar), R(0), //
1621 B(Star), R(1), //
1622 B(LdaSmi8), U8(3), // 1529 B(LdaSmi8), U8(3), //
1623 B(Mul), R(1), // 1530 B(Mul), R(0), //
1624 B(LdaUndefined), // 1531 B(LdaUndefined), //
1625 B(Return), // 1532 B(Return), //
1626 }, 1533 },
1627 0}, 1534 0},
1628 {"var x = 1234;" 1535 {"var x = 1234;"
1629 "var y = void (x * x - 1);" 1536 "var y = void (x * x - 1);"
1630 "return y;", 1537 "return y;",
1631 4 * kPointerSize, 1538 3 * kPointerSize,
1632 1, 1539 1,
1633 24, 1540 20,
1634 { 1541 {
1635 B(LdaConstant), U8(0), // 1542 B(LdaConstant), U8(0), //
1636 B(Star), R(0), // 1543 B(Star), R(0), //
1637 B(Ldar), R(0), // 1544 B(Ldar), R(0), //
1638 B(Star), R(3), // 1545 B(Mul), R(0), //
1639 B(Ldar), R(0), //
1640 B(Mul), R(3), //
1641 B(Star), R(2), // 1546 B(Star), R(2), //
1642 B(LdaSmi8), U8(1), // 1547 B(LdaSmi8), U8(1), //
1643 B(Sub), R(2), // 1548 B(Sub), R(2), //
1644 B(LdaUndefined), // 1549 B(LdaUndefined), //
1645 B(Star), R(1), // 1550 B(Star), R(1), //
1646 B(Ldar), R(1), // 1551 B(Ldar), R(1), //
1647 B(Return), // 1552 B(Return), //
1648 }, 1553 },
1649 1, 1554 1,
1650 {1234}}, 1555 {1234}},
1651 {"var x = 13;" 1556 {"var x = 13;"
1652 "return typeof(x);", 1557 "return typeof(x);",
1653 1 * kPointerSize, 1558 kPointerSize,
1654 1, 1559 1,
1655 8, 1560 8,
1656 { 1561 {
1657 B(LdaSmi8), U8(13), // 1562 B(LdaSmi8), U8(13), //
1658 B(Star), R(0), // 1563 B(Star), R(0), //
1659 B(Ldar), R(0), // 1564 B(Ldar), R(0), // TODO(oth): Ldar R(X) following Star R(X)
1660 B(TypeOf), // 1565 B(TypeOf), // could be culled in bytecode array builder.
1661 B(Return), // 1566 B(Return), //
1662 }, 1567 },
1663 0}, 1568 0},
1664 }; 1569 };
1665 1570
1666 for (size_t i = 0; i < arraysize(snippets); i++) { 1571 for (size_t i = 0; i < arraysize(snippets); i++) {
1667 Handle<BytecodeArray> bytecode_array = 1572 Handle<BytecodeArray> bytecode_array =
1668 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1573 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1669 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1574 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1670 } 1575 }
1671 } 1576 }
1672 1577
1673 1578
1674 } // namespace interpreter 1579 } // namespace interpreter
1675 } // namespace internal 1580 } // namespace internal
1676 } // namespace v8 1581 } // namespace v8
OLDNEW
« src/interpreter/bytecode-generator.cc ('K') | « src/interpreter/bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698