Simplify ToBoolean if we know we have a Smi.
Review URL: http://codereview.chromium.org/2808039 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5007 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
a835641dee
commit
f9eb21f950
@ -748,37 +748,43 @@ void CodeGenerator::ToBoolean(JumpTarget* true_target,
|
||||
JumpTarget* false_target) {
|
||||
// Note: The generated code snippet does not change stack variables.
|
||||
// Only the condition code should be set.
|
||||
bool known_smi = frame_->KnownSmiAt(0);
|
||||
Register tos = frame_->PopToRegister();
|
||||
|
||||
// Fast case checks
|
||||
|
||||
// Check if the value is 'false'.
|
||||
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
false_target->Branch(eq);
|
||||
if (!known_smi) {
|
||||
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
false_target->Branch(eq);
|
||||
|
||||
// Check if the value is 'true'.
|
||||
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
true_target->Branch(eq);
|
||||
// Check if the value is 'true'.
|
||||
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
true_target->Branch(eq);
|
||||
|
||||
// Check if the value is 'undefined'.
|
||||
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
false_target->Branch(eq);
|
||||
// Check if the value is 'undefined'.
|
||||
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
||||
__ cmp(tos, ip);
|
||||
false_target->Branch(eq);
|
||||
}
|
||||
|
||||
// Check if the value is a smi.
|
||||
__ cmp(tos, Operand(Smi::FromInt(0)));
|
||||
false_target->Branch(eq);
|
||||
__ tst(tos, Operand(kSmiTagMask));
|
||||
true_target->Branch(eq);
|
||||
|
||||
// Slow case: call the runtime.
|
||||
frame_->EmitPush(tos);
|
||||
frame_->CallRuntime(Runtime::kToBool, 1);
|
||||
// Convert the result (r0) to a condition code.
|
||||
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
||||
__ cmp(r0, ip);
|
||||
if (!known_smi) {
|
||||
false_target->Branch(eq);
|
||||
__ tst(tos, Operand(kSmiTagMask));
|
||||
true_target->Branch(eq);
|
||||
|
||||
// Slow case: call the runtime.
|
||||
frame_->EmitPush(tos);
|
||||
frame_->CallRuntime(Runtime::kToBool, 1);
|
||||
// Convert the result (r0) to a condition code.
|
||||
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
||||
__ cmp(r0, ip);
|
||||
}
|
||||
|
||||
cc_reg_ = ne;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user