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

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

Issue 1399773002: [Interpreter] Adds logical and, logical or and comma operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a new bytecode to jump by casting the value to boolean. This reduces code size for logical op… 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 13, 388 13,
389 { 389 {
390 B(LdaSmi8), U8(10), // 390 B(LdaSmi8), U8(10), //
391 B(Star), R(0), // 391 B(Star), R(0), //
392 B(Ldar), R(0), // Easy to spot r1 not really needed here. 392 B(Ldar), R(0), // Easy to spot r1 not really needed here.
393 B(Star), R(1), // Dead store. 393 B(Star), R(1), // Dead store.
394 B(LdaSmi8), U8(3), // 394 B(LdaSmi8), U8(3), //
395 B(ShiftRightLogical), R(1), // 395 B(ShiftRightLogical), R(1), //
396 B(Return) // 396 B(Return) //
397 }, 397 },
398 0},
399 {"var x = 0; return (x, 3);",
400 1 * kPointerSize,
401 1,
402 8,
403 {
404 B(LdaZero), //
405 B(Star), R(0), //
406 B(Ldar), R(0), //
407 B(LdaSmi8), U8(3), //
408 B(Return) //
409 },
398 0}}; 410 0}};
399 411
400 for (size_t i = 0; i < arraysize(snippets); i++) { 412 for (size_t i = 0; i < arraysize(snippets); i++) {
401 Handle<BytecodeArray> bytecode_array = 413 Handle<BytecodeArray> bytecode_array =
402 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 414 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
403 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 415 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
404 } 416 }
405 } 417 }
406 418
407 419
420 TEST(LogicalExpressions) {
421 InitializedHandleScope handle_scope;
422 BytecodeGeneratorHelper helper;
423
424 Handle<Object> unused = helper.factory()->undefined_value();
425
426 ExpectedSnippet<Handle<Object>> snippets[] = {
427 {"var x = 0; return x || 3;",
428 1 * kPointerSize,
429 1,
430 10,
431 {
432 B(LdaZero), //
433 B(Star), R(0), //
434 B(Ldar), R(0), //
435 B(JumpIfToBooleanTrue), U8(4), //
436 B(LdaSmi8), U8(3), //
437 B(Return) //
438 },
439 0,
440 {unused, unused, unused, unused}},
441 {"var x = 1; var a = 2, b = 3; return x || ("
rmcilroy 2015/10/13 15:43:24 Could you make a similar test for && as well pleas
mythria 2015/10/14 13:33:42 Done.
442 #define X "a, b, a, b, "
443 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
444 #undef X
445 "3);",
446 3 * kPointerSize,
447 1,
448 283,
449 {
450 B(LdaSmi8), U8(1), //
451 B(Star), R(0), //
452 B(LdaSmi8), U8(2), //
453 B(Star), R(1), //
454 B(LdaSmi8), U8(3), //
455 B(Star), R(2), //
456 B(Ldar), R(0), //
457 B(JumpIfToBooleanTrueConstant), U8(0), //
458 #define X B(Ldar), R(1), B(Ldar), R(2), B(Ldar), R(1), B(Ldar), R(2),
459 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
460 #undef X
461 B(LdaSmi8),
rmcilroy 2015/10/13 15:43:24 nit - indentation, and add '//' after
mythria 2015/10/14 13:33:42 Done.
462 U8(3), //
463 B(Return) //
464 },
465 1,
466 {helper.factory()->NewNumberFromInt(268), unused, unused, unused}},
467 {"var x = 0; return x && 3;",
468 1 * kPointerSize,
469 1,
470 10,
471 {
472 B(LdaZero), //
473 B(Star), R(0), //
474 B(Ldar), R(0), //
475 B(JumpIfToBooleanFalse), U8(4), //
476 B(LdaSmi8), U8(3), //
477 B(Return) //
478 },
479 0,
480 {unused, unused, unused, unused}},
rmcilroy 2015/10/13 15:43:24 nit - would be nice to have one test that is neste
mythria 2015/10/14 13:33:42 Done.
481 {"return 0 && 3;",
482 0 * kPointerSize,
483 1,
484 2,
485 {B(LdaZero), B(Return)},
rmcilroy 2015/10/13 15:43:24 nit - new bytecode on new line (use '//' to avoid
mythria 2015/10/14 13:33:42 Done.
486 0,
487 {unused, unused, unused, unused}},
488 {" return 1 || 3;",
rmcilroy 2015/10/13 15:43:24 nit - remove extra space at start
mythria 2015/10/14 13:33:42 Done.
489 0 * kPointerSize,
490 1,
491 3,
492 {B(LdaSmi8), U8(1), B(Return)},
rmcilroy 2015/10/13 15:43:24 ditto
mythria 2015/10/14 13:33:42 Done.
493 0,
494 {unused, unused, unused, unused}}};
495
496 for (size_t i = 0; i < arraysize(snippets); i++) {
497 Handle<BytecodeArray> bytecode_array =
498 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
499 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
500 }
501 }
502
503
408 TEST(Parameters) { 504 TEST(Parameters) {
409 InitializedHandleScope handle_scope; 505 InitializedHandleScope handle_scope;
410 BytecodeGeneratorHelper helper; 506 BytecodeGeneratorHelper helper;
411 507
412 ExpectedSnippet<int> snippets[] = { 508 ExpectedSnippet<int> snippets[] = {
413 {"function f() { return this; }", 509 {"function f() { return this; }",
414 0, 1, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 510 0, 1, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0},
415 {"function f(arg1) { return arg1; }", 511 {"function f(arg1) { return arg1; }",
416 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0}, 512 0, 2, 3, {B(Ldar), R(helper.kLastParamIndex), B(Return)}, 0},
417 {"function f(arg1) { return this; }", 513 {"function f(arg1) { return this; }",
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 for (size_t i = 0; i < arraysize(snippets); i++) { 2036 for (size_t i = 0; i < arraysize(snippets); i++) {
1941 Handle<BytecodeArray> bytecode_array = 2037 Handle<BytecodeArray> bytecode_array =
1942 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2038 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1943 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2039 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1944 } 2040 }
1945 } 2041 }
1946 2042
1947 } // namespace interpreter 2043 } // namespace interpreter
1948 } // namespace internal 2044 } // namespace internal
1949 } // namespace v8 2045 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698