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

Side by Side Diff: src/ia32/fast-codegen-ia32.cc

Issue 334006: Simple toplevel code generator support for short-circuited boolean OR... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 453
454 __ CallRuntime(function, arg_count); 454 __ CallRuntime(function, arg_count);
455 if (expr->location().is_temporary()) { 455 if (expr->location().is_temporary()) {
456 __ push(eax); 456 __ push(eax);
457 } else { 457 } else {
458 ASSERT(expr->location().is_nowhere()); 458 ASSERT(expr->location().is_nowhere());
459 } 459 }
460 } 460 }
461 461
462 462
463 void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
464 // Compile a short-circuited boolean or operation in a non-test
465 // context.
466 ASSERT(expr->op() == Token::OR);
467 // Compile (e0 || e1) as if it were
468 // (let (temp = e0) temp ? temp : e1).
469
470 Label eval_right, done;
471 Location destination = expr->location();
472 ASSERT(!destination.is_constant());
473
474 Expression* left = expr->left();
475 Location left_source = left->location();
476 ASSERT(!left_source.is_nowhere());
477
478 Expression* right = expr->right();
479 Location right_source = right->location();
480 ASSERT(!right_source.is_nowhere());
481
482 Visit(left);
483 // Use the shared ToBoolean stub to find the boolean value of the
484 // left-hand subexpression. Load the value into eax to perform some
485 // inlined checks assumed by the stub.
486 if (left_source.is_temporary()) {
487 if (destination.is_temporary()) {
488 // Copy the left-hand value into eax because we may need it as the
489 // final result.
490 __ mov(eax, Operand(esp, 0));
491 } else {
492 // Pop the left-hand value into eax because we will not need it as the
493 // final result.
494 __ pop(eax);
495 }
496 } else {
497 // Load the left-hand value into eax. Put it on the stack if we may
498 // need it.
499 ASSERT(left->AsLiteral() != NULL);
500 __ mov(eax, left->AsLiteral()->handle());
501 if (destination.is_temporary()) __ push(eax);
502 }
503 // The left-hand value is in eax. It is also on the stack iff the
504 // destination location is temporary.
505
506 // Perform fast checks assumed by the stub.
507 __ cmp(eax, Factory::undefined_value()); // The undefined value is false.
508 __ j(equal, &eval_right);
509 __ cmp(eax, Factory::true_value()); // True is true.
510 __ j(equal, &done);
511 __ cmp(eax, Factory::false_value()); // False is false.
512 __ j(equal, &eval_right);
513 ASSERT(kSmiTag == 0);
514 __ test(eax, Operand(eax)); // The smi zero is false.
515 __ j(zero, &eval_right);
516 __ test(eax, Immediate(kSmiTagMask)); // All other smis are true.
517 __ j(zero, &done);
518
fschneider 2009/10/23 08:41:37 Idea: I don't know how relevant these expressions
519 // Call the stub for all other cases.
520 __ push(eax);
521 ToBooleanStub stub;
522 __ CallStub(&stub);
523 __ test(eax, Operand(eax)); // The stub returns nonzero for true.
524 __ j(not_zero, &done);
525
526 __ bind(&eval_right);
527 // Discard the left-hand value if present on the stack.
528 if (destination.is_temporary()) {
529 __ add(Operand(esp), Immediate(kPointerSize));
530 }
531 Visit(right);
532
533 // Save or discard the right-hand value as needed.
534 if (destination.is_temporary() && right_source.is_constant()) {
535 ASSERT(right->AsLiteral() != NULL);
536 __ push(Immediate(right->AsLiteral()->handle()));
537 } else if (destination.is_nowhere() && right_source.is_temporary()) {
538 __ add(Operand(esp), Immediate(kPointerSize));
539 }
540
541 __ bind(&done);
542 }
543
544
463 } } // namespace v8::internal 545 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/x64/codegen-x64.h » ('j') | src/x64/fast-codegen-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698