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

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

Issue 17611: Combine smi and overflow checks for count operations. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 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
« no previous file with comments | « src/assembler-ia32.cc ('k') | src/disasm-ia32.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 3973 matching lines...) Expand 10 before | Expand all | Expand 10 after
3984 // Postfix: Store the old value as the result. 3984 // Postfix: Store the old value as the result.
3985 if (is_postfix) { 3985 if (is_postfix) {
3986 Result old_value = value; 3986 Result old_value = value;
3987 frame_->SetElementAt(target.size(), &old_value); 3987 frame_->SetElementAt(target.size(), &old_value);
3988 } 3988 }
3989 3989
3990 // Perform optimistic increment/decrement. Ensure the value is 3990 // Perform optimistic increment/decrement. Ensure the value is
3991 // writable. 3991 // writable.
3992 frame_->Spill(value.reg()); 3992 frame_->Spill(value.reg());
3993 ASSERT(allocator_->count(value.reg()) == 1); 3993 ASSERT(allocator_->count(value.reg()) == 1);
3994
3995 // In order to combine the overflow and the smi check, we need to
3996 // be able to allocate a byte register. We attempt to do so
3997 // without spilling. If we fail, we will generate separate
3998 // overflow and smi checks.
3999 //
4000 // We need to allocate and clear the temporary byte register
4001 // before performing the count operation since clearing the
4002 // register using xor will clear the overflow flag.
4003 Result tmp = allocator_->AllocateByteRegisterWithoutSpilling();
4004 if (tmp.is_valid()) {
4005 __ Set(tmp.reg(), Immediate(0));
4006 }
4007
3994 if (is_increment) { 4008 if (is_increment) {
3995 __ add(Operand(value.reg()), Immediate(Smi::FromInt(1))); 4009 __ add(Operand(value.reg()), Immediate(Smi::FromInt(1)));
3996 } else { 4010 } else {
3997 __ sub(Operand(value.reg()), Immediate(Smi::FromInt(1))); 4011 __ sub(Operand(value.reg()), Immediate(Smi::FromInt(1)));
3998 } 4012 }
3999 4013
4000 // If the count operation didn't overflow and the result is a 4014 // If the count operation didn't overflow and the result is a
4001 // valid smi, we're done. Otherwise, we jump to the deferred 4015 // valid smi, we're done. Otherwise, we jump to the deferred
4002 // slow-case code. 4016 // slow-case code.
4003 deferred->enter()->Branch(overflow, &value, not_taken); 4017 //
4004 __ test(value.reg(), Immediate(kSmiTagMask)); 4018 // We combine the overflow and the smi check if we could
4005 deferred->enter()->Branch(not_zero, &value, not_taken); 4019 // successfully allocate a temporary byte register.
4020 if (tmp.is_valid()) {
4021 __ setcc(overflow, tmp.reg());
4022 __ or_(Operand(value.reg()), tmp.reg());
4023 tmp.Unuse();
4024 __ test(value.reg(), Immediate(kSmiTagMask));
4025 deferred->enter()->Branch(not_zero, &value, not_taken);
4026 } else {
4027 deferred->enter()->Branch(overflow, &value, not_taken);
4028 __ test(value.reg(), Immediate(kSmiTagMask));
4029 deferred->enter()->Branch(not_zero, &value, not_taken);
4030 }
4006 4031
4007 // Store the new value in the target if not const. 4032 // Store the new value in the target if not const.
4008 deferred->exit()->Bind(&value); 4033 deferred->exit()->Bind(&value);
4009 frame_->Push(&value); 4034 frame_->Push(&value);
4010 if (!is_const) { 4035 if (!is_const) {
4011 target.SetValue(NOT_CONST_INIT); 4036 target.SetValue(NOT_CONST_INIT);
4012 } 4037 }
4013 } 4038 }
4014 4039
4015 // Postfix: Discard the new value and use the old. 4040 // Postfix: Discard the new value and use the old.
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 6045
6021 // Slow-case: Go through the JavaScript implementation. 6046 // Slow-case: Go through the JavaScript implementation.
6022 __ bind(&slow); 6047 __ bind(&slow);
6023 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); 6048 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
6024 } 6049 }
6025 6050
6026 6051
6027 #undef __ 6052 #undef __
6028 6053
6029 } } // namespace v8::internal 6054 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/assembler-ia32.cc ('k') | src/disasm-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698