sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_ARM) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
| 33 | #include "codegen-inl.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 34 | #include "compiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "debug.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 36 | #include "ic-inl.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 37 | #include "jsregexp.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 38 | #include "jump-target-light-inl.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 39 | #include "parser.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 40 | #include "regexp-macro-assembler.h" |
| 41 | #include "regexp-stack.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 42 | #include "register-allocator-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | #include "runtime.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 44 | #include "scopes.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 45 | #include "virtual-frame-inl.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 46 | #include "virtual-frame-arm-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 48 | namespace v8 { |
| 49 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 51 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 52 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 53 | Label* slow, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 54 | Condition cc, |
| 55 | bool never_nan_nan); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 56 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 57 | Register lhs, |
| 58 | Register rhs, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 59 | Label* lhs_not_nan, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 60 | Label* slow, |
| 61 | bool strict); |
| 62 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cc); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 63 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 64 | Register lhs, |
| 65 | Register rhs); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 66 | static void MultiplyByKnownInt(MacroAssembler* masm, |
| 67 | Register source, |
| 68 | Register destination, |
| 69 | int known_int); |
| 70 | static bool IsEasyToMultiplyBy(int x); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 71 | |
| 72 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 73 | #define __ ACCESS_MASM(masm_) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 74 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 75 | // ------------------------------------------------------------------------- |
| 76 | // Platform-specific DeferredCode functions. |
| 77 | |
| 78 | void DeferredCode::SaveRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 79 | // On ARM you either have a completely spilled frame or you |
| 80 | // handle it yourself, but at the moment there's no automation |
| 81 | // of registers and deferred code. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | void DeferredCode::RestoreRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
| 89 | // ------------------------------------------------------------------------- |
| 90 | // Platform-specific RuntimeCallHelper functions. |
| 91 | |
| 92 | void VirtualFrameRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 93 | frame_state_->frame()->AssertIsSpilled(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void VirtualFrameRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void ICRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 102 | masm->EnterInternalFrame(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void ICRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 107 | masm->LeaveInternalFrame(); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 108 | } |
| 109 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 110 | |
| 111 | // ------------------------------------------------------------------------- |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 112 | // CodeGenState implementation. |
| 113 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 114 | CodeGenState::CodeGenState(CodeGenerator* owner) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 115 | : owner_(owner), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 116 | previous_(owner->state()) { |
| 117 | owner->set_state(this); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 121 | ConditionCodeGenState::ConditionCodeGenState(CodeGenerator* owner, |
| 122 | JumpTarget* true_target, |
| 123 | JumpTarget* false_target) |
| 124 | : CodeGenState(owner), |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 125 | true_target_(true_target), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 126 | false_target_(false_target) { |
| 127 | owner->set_state(this); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | TypeInfoCodeGenState::TypeInfoCodeGenState(CodeGenerator* owner, |
| 132 | Slot* slot, |
| 133 | TypeInfo type_info) |
| 134 | : CodeGenState(owner), |
| 135 | slot_(slot) { |
| 136 | owner->set_state(this); |
| 137 | old_type_info_ = owner->set_type_info(slot, type_info); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 141 | CodeGenState::~CodeGenState() { |
| 142 | ASSERT(owner_->state() == this); |
| 143 | owner_->set_state(previous_); |
| 144 | } |
| 145 | |
| 146 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 147 | TypeInfoCodeGenState::~TypeInfoCodeGenState() { |
| 148 | owner()->set_type_info(slot_, old_type_info_); |
| 149 | } |
| 150 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 151 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 152 | // CodeGenerator implementation |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 154 | int CodeGenerator::inlined_write_barrier_size_ = -1; |
| 155 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 156 | CodeGenerator::CodeGenerator(MacroAssembler* masm) |
| 157 | : deferred_(8), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 158 | masm_(masm), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 159 | info_(NULL), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 160 | frame_(NULL), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 161 | allocator_(NULL), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | cc_reg_(al), |
| 163 | state_(NULL), |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 164 | loop_nesting_(0), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 165 | type_info_(NULL), |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 166 | function_return_(JumpTarget::BIDIRECTIONAL), |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 167 | function_return_is_shadowed_(false) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | // Calling conventions: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 172 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 174 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | // cp: callee's context |
| 176 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 177 | void CodeGenerator::Generate(CompilationInfo* info) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 178 | // Record the position for debugging purposes. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 179 | CodeForFunctionPosition(info->function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 180 | Comment cmnt(masm_, "[ function compiled by virtual frame code generator"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 181 | |
| 182 | // Initialize state. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 183 | info_ = info; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 184 | |
| 185 | int slots = scope()->num_parameters() + scope()->num_stack_slots(); |
| 186 | ScopedVector<TypeInfo> type_info_array(slots); |
| 187 | type_info_ = &type_info_array; |
| 188 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 189 | ASSERT(allocator_ == NULL); |
| 190 | RegisterAllocator register_allocator(this); |
| 191 | allocator_ = ®ister_allocator; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 192 | ASSERT(frame_ == NULL); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 193 | frame_ = new VirtualFrame(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 194 | cc_reg_ = al; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 195 | |
| 196 | // Adjust for function-level loop nesting. |
| 197 | ASSERT_EQ(0, loop_nesting_); |
| 198 | loop_nesting_ = info->loop_nesting(); |
| 199 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 200 | { |
| 201 | CodeGenState state(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 203 | // Entry: |
| 204 | // Stack: receiver, arguments |
| 205 | // lr: return address |
| 206 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 208 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | // cp: callee's context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 210 | allocator_->Initialize(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 211 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | #ifdef DEBUG |
| 213 | if (strlen(FLAG_stop_at) > 0 && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 214 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 215 | frame_->SpillAll(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 216 | __ stop("stop-at"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | } |
| 218 | #endif |
| 219 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 220 | if (info->mode() == CompilationInfo::PRIMARY) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 221 | frame_->Enter(); |
| 222 | // tos: code slot |
| 223 | |
| 224 | // Allocate space for locals and initialize them. This also checks |
| 225 | // for stack overflow. |
| 226 | frame_->AllocateStackSlots(); |
| 227 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 228 | frame_->AssertIsSpilled(); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 229 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 230 | if (heap_slots > 0) { |
| 231 | // Allocate local context. |
| 232 | // Get outer context and create a new context based on it. |
| 233 | __ ldr(r0, frame_->Function()); |
| 234 | frame_->EmitPush(r0); |
| 235 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 236 | FastNewContextStub stub(heap_slots); |
| 237 | frame_->CallStub(&stub, 1); |
| 238 | } else { |
| 239 | frame_->CallRuntime(Runtime::kNewContext, 1); |
| 240 | } |
| 241 | |
| 242 | #ifdef DEBUG |
| 243 | JumpTarget verified_true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 244 | __ cmp(r0, cp); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 245 | verified_true.Branch(eq); |
| 246 | __ stop("NewContext: r0 is expected to be the same as cp"); |
| 247 | verified_true.Bind(); |
| 248 | #endif |
| 249 | // Update context local. |
| 250 | __ str(cp, frame_->Context()); |
| 251 | } |
| 252 | |
| 253 | // TODO(1241774): Improve this code: |
| 254 | // 1) only needed if we have a context |
| 255 | // 2) no need to recompute context ptr every single time |
| 256 | // 3) don't copy parameter operand code from SlotOperand! |
| 257 | { |
| 258 | Comment cmnt2(masm_, "[ copy context parameters into .context"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 259 | // Note that iteration order is relevant here! If we have the same |
| 260 | // parameter twice (e.g., function (x, y, x)), and that parameter |
| 261 | // needs to be copied into the context, it must be the last argument |
| 262 | // passed to the parameter that needs to be copied. This is a rare |
| 263 | // case so we don't check for it, instead we rely on the copying |
| 264 | // order: such a parameter is copied repeatedly into the same |
| 265 | // context location and thus the last value is what is seen inside |
| 266 | // the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 267 | frame_->AssertIsSpilled(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 268 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 269 | Variable* par = scope()->parameter(i); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 270 | Slot* slot = par->slot(); |
| 271 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 272 | ASSERT(!scope()->is_global_scope()); // No params in global scope. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 273 | __ ldr(r1, frame_->ParameterAt(i)); |
| 274 | // Loads r2 with context; used below in RecordWrite. |
| 275 | __ str(r1, SlotOperand(slot, r2)); |
| 276 | // Load the offset into r3. |
| 277 | int slot_offset = |
| 278 | FixedArray::kHeaderSize + slot->index() * kPointerSize; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 279 | __ RecordWrite(r2, Operand(slot_offset), r3, r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // Store the arguments object. This must happen after context |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 285 | // initialization because the arguments object may be stored in |
| 286 | // the context. |
| 287 | if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) { |
| 288 | StoreArgumentsObject(true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // Initialize ThisFunction reference if present. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 292 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 293 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 294 | StoreToSlot(scope()->function()->slot(), NOT_CONST_INIT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 295 | } |
| 296 | } else { |
| 297 | // When used as the secondary compiler for splitting, r1, cp, |
| 298 | // fp, and lr have been pushed on the stack. Adjust the virtual |
| 299 | // frame to match this state. |
| 300 | frame_->Adjust(4); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 301 | |
| 302 | // Bind all the bailout labels to the beginning of the function. |
| 303 | List<CompilationInfo::Bailout*>* bailouts = info->bailouts(); |
| 304 | for (int i = 0; i < bailouts->length(); i++) { |
| 305 | __ bind(bailouts->at(i)->label()); |
| 306 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 307 | } |
| 308 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 309 | // Initialize the function return target after the locals are set |
| 310 | // up, because it needs the expected frame height from the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 311 | function_return_.SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 312 | function_return_is_shadowed_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 314 | // Generate code to 'execute' declarations and initialize functions |
| 315 | // (source elements). In case of an illegal redeclaration we need to |
| 316 | // handle that instead of processing the declarations. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 317 | if (scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 318 | Comment cmnt(masm_, "[ illegal redeclarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 319 | scope()->VisitIllegalRedeclaration(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 320 | } else { |
| 321 | Comment cmnt(masm_, "[ declarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 322 | ProcessDeclarations(scope()->declarations()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 323 | // Bail out if a stack-overflow exception occurred when processing |
| 324 | // declarations. |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 325 | if (HasStackOverflow()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | } |
| 327 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 328 | if (FLAG_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 329 | frame_->CallRuntime(Runtime::kTraceEnter, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 330 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 331 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | |
| 333 | // Compile the body of the function in a vanilla state. Don't |
| 334 | // bother compiling all the code if the scope has an illegal |
| 335 | // redeclaration. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 336 | if (!scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | Comment cmnt(masm_, "[ function body"); |
| 338 | #ifdef DEBUG |
| 339 | bool is_builtin = Bootstrapper::IsActive(); |
| 340 | bool should_trace = |
| 341 | is_builtin ? FLAG_trace_builtin_calls : FLAG_trace_calls; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 342 | if (should_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 343 | frame_->CallRuntime(Runtime::kDebugTrace, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 344 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 345 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | #endif |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 347 | VisitStatements(info->function()->body()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | } |
| 350 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 351 | // Handle the return from the function. |
| 352 | if (has_valid_frame()) { |
| 353 | // If there is a valid frame, control flow can fall off the end of |
| 354 | // the body. In that case there is an implicit return statement. |
| 355 | ASSERT(!function_return_is_shadowed_); |
| 356 | frame_->PrepareForReturn(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 357 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 358 | if (function_return_.is_bound()) { |
| 359 | function_return_.Jump(); |
| 360 | } else { |
| 361 | function_return_.Bind(); |
| 362 | GenerateReturnSequence(); |
| 363 | } |
| 364 | } else if (function_return_.is_linked()) { |
| 365 | // If the return target has dangling jumps to it, then we have not |
| 366 | // yet generated the return sequence. This can happen when (a) |
| 367 | // control does not flow off the end of the body so we did not |
| 368 | // compile an artificial return statement just above, and (b) there |
| 369 | // are return statements in the body but (c) they are all shadowed. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 370 | function_return_.Bind(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 371 | GenerateReturnSequence(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 372 | } |
| 373 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 374 | // Adjust for function-level loop nesting. |
| 375 | ASSERT(loop_nesting_ == info->loop_nesting()); |
| 376 | loop_nesting_ = 0; |
| 377 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | // Code generation state must be reset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | ASSERT(!has_cc()); |
| 380 | ASSERT(state_ == NULL); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 381 | ASSERT(loop_nesting() == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 382 | ASSERT(!function_return_is_shadowed_); |
| 383 | function_return_.Unuse(); |
| 384 | DeleteFrame(); |
| 385 | |
| 386 | // Process any deferred code using the register allocator. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 387 | if (!HasStackOverflow()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 388 | ProcessDeferred(); |
| 389 | } |
| 390 | |
| 391 | allocator_ = NULL; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 392 | type_info_ = NULL; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | int CodeGenerator::NumberOfSlot(Slot* slot) { |
| 397 | if (slot == NULL) return kInvalidSlotNumber; |
| 398 | switch (slot->type()) { |
| 399 | case Slot::PARAMETER: |
| 400 | return slot->index(); |
| 401 | case Slot::LOCAL: |
| 402 | return slot->index() + scope()->num_parameters(); |
| 403 | default: |
| 404 | break; |
| 405 | } |
| 406 | return kInvalidSlotNumber; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 410 | MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) { |
| 411 | // Currently, this assertion will fail if we try to assign to |
| 412 | // a constant variable that is constant because it is read-only |
| 413 | // (such as the variable referring to a named function expression). |
| 414 | // We need to implement assignments to read-only variables. |
| 415 | // Ideally, we should do this during AST generation (by converting |
| 416 | // such assignments into expression statements); however, in general |
| 417 | // we may not be able to make the decision until past AST generation, |
| 418 | // that is when the entire program is known. |
| 419 | ASSERT(slot != NULL); |
| 420 | int index = slot->index(); |
| 421 | switch (slot->type()) { |
| 422 | case Slot::PARAMETER: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 423 | return frame_->ParameterAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 424 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 425 | case Slot::LOCAL: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 426 | return frame_->LocalAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 427 | |
| 428 | case Slot::CONTEXT: { |
| 429 | // Follow the context chain if necessary. |
| 430 | ASSERT(!tmp.is(cp)); // do not overwrite context register |
| 431 | Register context = cp; |
| 432 | int chain_length = scope()->ContextChainLength(slot->var()->scope()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 433 | for (int i = 0; i < chain_length; i++) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 434 | // Load the closure. |
| 435 | // (All contexts, even 'with' contexts, have a closure, |
| 436 | // and it is the same for all contexts inside a function. |
| 437 | // There is no need to go to the function context first.) |
| 438 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 439 | // Load the function context (which is the incoming, outer context). |
| 440 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 441 | context = tmp; |
| 442 | } |
| 443 | // We may have a 'with' context now. Get the function context. |
| 444 | // (In fact this mov may never be the needed, since the scope analysis |
| 445 | // may not permit a direct context access in this case and thus we are |
| 446 | // always at a function context. However it is safe to dereference be- |
| 447 | // cause the function context of a function context is itself. Before |
| 448 | // deleting this mov we should try to create a counter-example first, |
| 449 | // though...) |
| 450 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
| 451 | return ContextOperand(tmp, index); |
| 452 | } |
| 453 | |
| 454 | default: |
| 455 | UNREACHABLE(); |
| 456 | return MemOperand(r0, 0); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 461 | MemOperand CodeGenerator::ContextSlotOperandCheckExtensions( |
| 462 | Slot* slot, |
| 463 | Register tmp, |
| 464 | Register tmp2, |
| 465 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 466 | ASSERT(slot->type() == Slot::CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 467 | Register context = cp; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 468 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 469 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 470 | if (s->num_heap_slots() > 0) { |
| 471 | if (s->calls_eval()) { |
| 472 | // Check that extension is NULL. |
| 473 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 474 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 475 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 476 | } |
| 477 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 478 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 479 | context = tmp; |
| 480 | } |
| 481 | } |
| 482 | // Check that last extension is NULL. |
| 483 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 484 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 485 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 486 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 487 | return ContextOperand(tmp, slot->index()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 491 | // Loads a value on TOS. If it is a boolean value, the result may have been |
| 492 | // (partially) translated into branches, or it may have set the condition |
| 493 | // code register. If force_cc is set, the value is forced to set the |
| 494 | // condition code register and no value is pushed. If the condition code |
| 495 | // register was set, has_cc() is true and cc_reg_ contains the condition to |
| 496 | // test for 'true'. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 497 | void CodeGenerator::LoadCondition(Expression* x, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 498 | JumpTarget* true_target, |
| 499 | JumpTarget* false_target, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 500 | bool force_cc) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 501 | ASSERT(!has_cc()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 502 | int original_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 504 | { ConditionCodeGenState new_state(this, true_target, false_target); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 505 | Visit(x); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 506 | |
| 507 | // If we hit a stack overflow, we may not have actually visited |
| 508 | // the expression. In that case, we ensure that we have a |
| 509 | // valid-looking frame state because we will continue to generate |
| 510 | // code as we unwind the C++ stack. |
| 511 | // |
| 512 | // It's possible to have both a stack overflow and a valid frame |
| 513 | // state (eg, a subexpression overflowed, visiting it returned |
| 514 | // with a dummied frame state, and visiting this expression |
| 515 | // returned with a normal-looking state). |
| 516 | if (HasStackOverflow() && |
| 517 | has_valid_frame() && |
| 518 | !has_cc() && |
| 519 | frame_->height() == original_height) { |
| 520 | true_target->Jump(); |
| 521 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 522 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 523 | if (force_cc && frame_ != NULL && !has_cc()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 524 | // Convert the TOS value to a boolean in the condition code register. |
| 525 | ToBoolean(true_target, false_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 527 | ASSERT(!force_cc || !has_valid_frame() || has_cc()); |
| 528 | ASSERT(!has_valid_frame() || |
| 529 | (has_cc() && frame_->height() == original_height) || |
| 530 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 534 | void CodeGenerator::Load(Expression* expr) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 535 | #ifdef DEBUG |
| 536 | int original_height = frame_->height(); |
| 537 | #endif |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 538 | JumpTarget true_target; |
| 539 | JumpTarget false_target; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 540 | LoadCondition(expr, &true_target, &false_target, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | |
| 542 | if (has_cc()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 543 | // Convert cc_reg_ into a boolean value. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 544 | JumpTarget loaded; |
| 545 | JumpTarget materialize_true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 546 | materialize_true.Branch(cc_reg_); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 547 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 548 | loaded.Jump(); |
| 549 | materialize_true.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 550 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 551 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 552 | cc_reg_ = al; |
| 553 | } |
| 554 | |
| 555 | if (true_target.is_linked() || false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 556 | // We have at least one condition value that has been "translated" |
| 557 | // into a branch, thus it needs to be loaded explicitly. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 558 | JumpTarget loaded; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 559 | if (frame_ != NULL) { |
| 560 | loaded.Jump(); // Don't lose the current TOS. |
| 561 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | bool both = true_target.is_linked() && false_target.is_linked(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 563 | // Load "true" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 564 | if (true_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 565 | true_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 566 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 568 | // If both "true" and "false" need to be loaded jump across the code for |
| 569 | // "false". |
| 570 | if (both) { |
| 571 | loaded.Jump(); |
| 572 | } |
| 573 | // Load "false" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | if (false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 575 | false_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 576 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 578 | // A value is loaded on all paths reaching this point. |
| 579 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 581 | ASSERT(has_valid_frame()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | ASSERT(!has_cc()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 583 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 587 | void CodeGenerator::LoadGlobal() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 588 | Register reg = frame_->GetTOSRegister(); |
| 589 | __ ldr(reg, GlobalObject()); |
| 590 | frame_->EmitPush(reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 594 | void CodeGenerator::LoadGlobalReceiver(Register scratch) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 595 | Register reg = frame_->GetTOSRegister(); |
| 596 | __ ldr(reg, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 597 | __ ldr(reg, |
| 598 | FieldMemOperand(reg, GlobalObject::kGlobalReceiverOffset)); |
| 599 | frame_->EmitPush(reg); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 603 | ArgumentsAllocationMode CodeGenerator::ArgumentsMode() { |
| 604 | if (scope()->arguments() == NULL) return NO_ARGUMENTS_ALLOCATION; |
| 605 | ASSERT(scope()->arguments_shadow() != NULL); |
| 606 | // We don't want to do lazy arguments allocation for functions that |
| 607 | // have heap-allocated contexts, because it interfers with the |
| 608 | // uninitialized const tracking in the context objects. |
| 609 | return (scope()->num_heap_slots() > 0) |
| 610 | ? EAGER_ARGUMENTS_ALLOCATION |
| 611 | : LAZY_ARGUMENTS_ALLOCATION; |
| 612 | } |
| 613 | |
| 614 | |
| 615 | void CodeGenerator::StoreArgumentsObject(bool initial) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 616 | ArgumentsAllocationMode mode = ArgumentsMode(); |
| 617 | ASSERT(mode != NO_ARGUMENTS_ALLOCATION); |
| 618 | |
| 619 | Comment cmnt(masm_, "[ store arguments object"); |
| 620 | if (mode == LAZY_ARGUMENTS_ALLOCATION && initial) { |
| 621 | // When using lazy arguments allocation, we store the hole value |
| 622 | // as a sentinel indicating that the arguments object hasn't been |
| 623 | // allocated yet. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 624 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 625 | } else { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 626 | frame_->SpillAll(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 627 | ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 628 | __ ldr(r2, frame_->Function()); |
| 629 | // The receiver is below the arguments, the return address, and the |
| 630 | // frame pointer on the stack. |
| 631 | const int kReceiverDisplacement = 2 + scope()->num_parameters(); |
| 632 | __ add(r1, fp, Operand(kReceiverDisplacement * kPointerSize)); |
| 633 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 634 | frame_->Adjust(3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 635 | __ Push(r2, r1, r0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 636 | frame_->CallStub(&stub, 3); |
| 637 | frame_->EmitPush(r0); |
| 638 | } |
| 639 | |
| 640 | Variable* arguments = scope()->arguments()->var(); |
| 641 | Variable* shadow = scope()->arguments_shadow()->var(); |
| 642 | ASSERT(arguments != NULL && arguments->slot() != NULL); |
| 643 | ASSERT(shadow != NULL && shadow->slot() != NULL); |
| 644 | JumpTarget done; |
| 645 | if (mode == LAZY_ARGUMENTS_ALLOCATION && !initial) { |
| 646 | // We have to skip storing into the arguments slot if it has |
| 647 | // already been written to. This can happen if the a function |
| 648 | // has a local variable named 'arguments'. |
| 649 | LoadFromSlot(scope()->arguments()->var()->slot(), NOT_INSIDE_TYPEOF); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 650 | Register arguments = frame_->PopToRegister(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 651 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 652 | __ cmp(arguments, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 653 | done.Branch(ne); |
| 654 | } |
| 655 | StoreToSlot(arguments->slot(), NOT_CONST_INIT); |
| 656 | if (mode == LAZY_ARGUMENTS_ALLOCATION) done.Bind(); |
| 657 | StoreToSlot(shadow->slot(), NOT_CONST_INIT); |
| 658 | } |
| 659 | |
| 660 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 661 | void CodeGenerator::LoadTypeofExpression(Expression* expr) { |
| 662 | // Special handling of identifiers as subexpressions of typeof. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 663 | Variable* variable = expr->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | if (variable != NULL && !variable->is_this() && variable->is_global()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 665 | // For a global variable we build the property reference |
| 666 | // <global>.<variable> and perform a (regular non-contextual) property |
| 667 | // load to make sure we do not get reference errors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | Slot global(variable, Slot::CONTEXT, Context::GLOBAL_INDEX); |
| 669 | Literal key(variable->name()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 670 | Property property(&global, &key, RelocInfo::kNoPosition); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 671 | Reference ref(this, &property); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 672 | ref.GetValue(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 673 | } else if (variable != NULL && variable->slot() != NULL) { |
| 674 | // For a variable that rewrites to a slot, we signal it is the immediate |
| 675 | // subexpression of a typeof. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 676 | LoadFromSlotCheckForArguments(variable->slot(), INSIDE_TYPEOF); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | } else { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 678 | // Anything else can be handled normally. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 679 | Load(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
| 683 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 684 | Reference::Reference(CodeGenerator* cgen, |
| 685 | Expression* expression, |
| 686 | bool persist_after_get) |
| 687 | : cgen_(cgen), |
| 688 | expression_(expression), |
| 689 | type_(ILLEGAL), |
| 690 | persist_after_get_(persist_after_get) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 691 | cgen->LoadReference(this); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | Reference::~Reference() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | ASSERT(is_unloaded() || is_illegal()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 700 | void CodeGenerator::LoadReference(Reference* ref) { |
| 701 | Comment cmnt(masm_, "[ LoadReference"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | Expression* e = ref->expression(); |
| 703 | Property* property = e->AsProperty(); |
| 704 | Variable* var = e->AsVariableProxy()->AsVariable(); |
| 705 | |
| 706 | if (property != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 707 | // The expression is either a property or a variable proxy that rewrites |
| 708 | // to a property. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 709 | Load(property->obj()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 710 | if (property->key()->IsPropertyName()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | ref->set_type(Reference::NAMED); |
| 712 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 713 | Load(property->key()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 714 | ref->set_type(Reference::KEYED); |
| 715 | } |
| 716 | } else if (var != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 717 | // The expression is a variable proxy that does not rewrite to a |
| 718 | // property. Global variables are treated as named property references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | if (var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 720 | LoadGlobal(); |
| 721 | ref->set_type(Reference::NAMED); |
| 722 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 723 | ASSERT(var->slot() != NULL); |
| 724 | ref->set_type(Reference::SLOT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | } |
| 726 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 727 | // Anything else is a runtime error. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 728 | Load(e); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 729 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 734 | void CodeGenerator::UnloadReference(Reference* ref) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | int size = ref->size(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 736 | ref->set_unloaded(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 737 | if (size == 0) return; |
| 738 | |
| 739 | // Pop a reference from the stack while preserving TOS. |
| 740 | VirtualFrame::RegisterAllocationScope scope(this); |
| 741 | Comment cmnt(masm_, "[ UnloadReference"); |
| 742 | if (size > 0) { |
| 743 | Register tos = frame_->PopToRegister(); |
| 744 | frame_->Drop(size); |
| 745 | frame_->EmitPush(tos); |
| 746 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 750 | // ECMA-262, section 9.2, page 30: ToBoolean(). Convert the given |
| 751 | // register to a boolean in the condition code register. The code |
| 752 | // may jump to 'false_target' in case the register converts to 'false'. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 753 | void CodeGenerator::ToBoolean(JumpTarget* true_target, |
| 754 | JumpTarget* false_target) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 755 | // Note: The generated code snippet does not change stack variables. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 756 | // Only the condition code should be set. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 757 | bool known_smi = frame_->KnownSmiAt(0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 758 | Register tos = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | |
| 760 | // Fast case checks |
| 761 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 762 | // Check if the value is 'false'. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 763 | if (!known_smi) { |
| 764 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 765 | __ cmp(tos, ip); |
| 766 | false_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 767 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 768 | // Check if the value is 'true'. |
| 769 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 770 | __ cmp(tos, ip); |
| 771 | true_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 772 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 773 | // Check if the value is 'undefined'. |
| 774 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 775 | __ cmp(tos, ip); |
| 776 | false_target->Branch(eq); |
| 777 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 779 | // Check if the value is a smi. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 780 | __ cmp(tos, Operand(Smi::FromInt(0))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 782 | if (!known_smi) { |
| 783 | false_target->Branch(eq); |
| 784 | __ tst(tos, Operand(kSmiTagMask)); |
| 785 | true_target->Branch(eq); |
| 786 | |
| 787 | // Slow case: call the runtime. |
| 788 | frame_->EmitPush(tos); |
| 789 | frame_->CallRuntime(Runtime::kToBool, 1); |
| 790 | // Convert the result (r0) to a condition code. |
| 791 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 792 | __ cmp(r0, ip); |
| 793 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 794 | |
| 795 | cc_reg_ = ne; |
| 796 | } |
| 797 | |
| 798 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 799 | void CodeGenerator::GenericBinaryOperation(Token::Value op, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 800 | OverwriteMode overwrite_mode, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 801 | GenerateInlineSmi inline_smi, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 802 | int constant_rhs) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 803 | // top of virtual frame: y |
| 804 | // 2nd elt. on virtual frame : x |
| 805 | // result : top of virtual frame |
| 806 | |
| 807 | // Stub is entered with a call: 'return address' is in lr. |
| 808 | switch (op) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 809 | case Token::ADD: |
| 810 | case Token::SUB: |
| 811 | if (inline_smi) { |
| 812 | JumpTarget done; |
| 813 | Register rhs = frame_->PopToRegister(); |
| 814 | Register lhs = frame_->PopToRegister(rhs); |
| 815 | Register scratch = VirtualFrame::scratch0(); |
| 816 | __ orr(scratch, rhs, Operand(lhs)); |
| 817 | // Check they are both small and positive. |
| 818 | __ tst(scratch, Operand(kSmiTagMask | 0xc0000000)); |
| 819 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 820 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 821 | if (op == Token::ADD) { |
| 822 | __ add(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 823 | } else { |
| 824 | __ sub(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 825 | } |
| 826 | done.Branch(eq); |
| 827 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 828 | frame_->SpillAll(); |
| 829 | frame_->CallStub(&stub, 0); |
| 830 | done.Bind(); |
| 831 | frame_->EmitPush(r0); |
| 832 | break; |
| 833 | } else { |
| 834 | // Fall through! |
| 835 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 836 | case Token::BIT_OR: |
| 837 | case Token::BIT_AND: |
| 838 | case Token::BIT_XOR: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 839 | if (inline_smi) { |
| 840 | bool rhs_is_smi = frame_->KnownSmiAt(0); |
| 841 | bool lhs_is_smi = frame_->KnownSmiAt(1); |
| 842 | Register rhs = frame_->PopToRegister(); |
| 843 | Register lhs = frame_->PopToRegister(rhs); |
| 844 | Register smi_test_reg; |
| 845 | Condition cond; |
| 846 | if (!rhs_is_smi || !lhs_is_smi) { |
| 847 | if (rhs_is_smi) { |
| 848 | smi_test_reg = lhs; |
| 849 | } else if (lhs_is_smi) { |
| 850 | smi_test_reg = rhs; |
| 851 | } else { |
| 852 | smi_test_reg = VirtualFrame::scratch0(); |
| 853 | __ orr(smi_test_reg, rhs, Operand(lhs)); |
| 854 | } |
| 855 | // Check they are both Smis. |
| 856 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 857 | cond = eq; |
| 858 | } else { |
| 859 | cond = al; |
| 860 | } |
| 861 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
| 862 | if (op == Token::BIT_OR) { |
| 863 | __ orr(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 864 | } else if (op == Token::BIT_AND) { |
| 865 | __ and_(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 866 | } else { |
| 867 | ASSERT(op == Token::BIT_XOR); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 868 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 869 | __ eor(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 870 | } |
| 871 | if (cond != al) { |
| 872 | JumpTarget done; |
| 873 | done.Branch(cond); |
| 874 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 875 | frame_->SpillAll(); |
| 876 | frame_->CallStub(&stub, 0); |
| 877 | done.Bind(); |
| 878 | } |
| 879 | frame_->EmitPush(r0); |
| 880 | break; |
| 881 | } else { |
| 882 | // Fall through! |
| 883 | } |
| 884 | case Token::MUL: |
| 885 | case Token::DIV: |
| 886 | case Token::MOD: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 887 | case Token::SHL: |
| 888 | case Token::SHR: |
| 889 | case Token::SAR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 890 | Register rhs = frame_->PopToRegister(); |
| 891 | Register lhs = frame_->PopToRegister(rhs); // Don't pop to rhs register. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 892 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 893 | frame_->SpillAll(); |
| 894 | frame_->CallStub(&stub, 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 895 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 899 | case Token::COMMA: { |
| 900 | Register scratch = frame_->PopToRegister(); |
| 901 | // Simply discard left value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 902 | frame_->Drop(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 903 | frame_->EmitPush(scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | break; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 905 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 906 | |
| 907 | default: |
| 908 | // Other cases should have been handled before this point. |
| 909 | UNREACHABLE(); |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 915 | class DeferredInlineSmiOperation: public DeferredCode { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 916 | public: |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 917 | DeferredInlineSmiOperation(Token::Value op, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 918 | int value, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 919 | bool reversed, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 920 | OverwriteMode overwrite_mode, |
| 921 | Register tos) |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 922 | : op_(op), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 923 | value_(value), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 924 | reversed_(reversed), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 925 | overwrite_mode_(overwrite_mode), |
| 926 | tos_register_(tos) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 927 | set_comment("[ DeferredInlinedSmiOperation"); |
| 928 | } |
| 929 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 930 | virtual void Generate(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 931 | |
| 932 | private: |
| 933 | Token::Value op_; |
| 934 | int value_; |
| 935 | bool reversed_; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 936 | OverwriteMode overwrite_mode_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 937 | Register tos_register_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 938 | }; |
| 939 | |
| 940 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 941 | |
| 942 | // On entry the non-constant side of the binary operation is in tos_register_ |
| 943 | // and the constant smi side is nowhere. The tos_register_ is not used by the |
| 944 | // virtual frame. On exit the answer is in the tos_register_ and the virtual |
| 945 | // frame is unchanged. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 946 | void DeferredInlineSmiOperation::Generate() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 947 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 948 | copied_frame.SpillAll(); |
| 949 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 950 | Register lhs = r1; |
| 951 | Register rhs = r0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 952 | switch (op_) { |
| 953 | case Token::ADD: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 954 | // Revert optimistic add. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 955 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 956 | __ sub(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 957 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 958 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 959 | __ sub(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 960 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 961 | } |
| 962 | break; |
| 963 | } |
| 964 | |
| 965 | case Token::SUB: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 966 | // Revert optimistic sub. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 967 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 968 | __ rsb(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 969 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 970 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 971 | __ add(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 972 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 977 | // For these operations there is no optimistic operation that needs to be |
| 978 | // reverted. |
| 979 | case Token::MUL: |
| 980 | case Token::MOD: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 981 | case Token::BIT_OR: |
| 982 | case Token::BIT_XOR: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 983 | case Token::BIT_AND: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 984 | case Token::SHL: |
| 985 | case Token::SHR: |
| 986 | case Token::SAR: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 987 | if (tos_register_.is(r1)) { |
| 988 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 989 | } else { |
| 990 | ASSERT(tos_register_.is(r0)); |
| 991 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 992 | } |
| 993 | if (reversed_ == tos_register_.is(r1)) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 994 | lhs = r0; |
| 995 | rhs = r1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 996 | } |
| 997 | break; |
| 998 | } |
| 999 | |
| 1000 | default: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1001 | // Other cases should have been handled before this point. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1002 | UNREACHABLE(); |
| 1003 | break; |
| 1004 | } |
| 1005 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1006 | GenericBinaryOpStub stub(op_, overwrite_mode_, lhs, rhs, value_); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1007 | __ CallStub(&stub); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1008 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1009 | // The generic stub returns its value in r0, but that's not |
| 1010 | // necessarily what we want. We want whatever the inlined code |
| 1011 | // expected, which is that the answer is in the same register as |
| 1012 | // the operand was. |
| 1013 | __ Move(tos_register_, r0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1014 | |
| 1015 | // The tos register was not in use for the virtual frame that we |
| 1016 | // came into this function with, so we can merge back to that frame |
| 1017 | // without trashing it. |
| 1018 | copied_frame.MergeTo(frame_state()->frame()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1022 | static bool PopCountLessThanEqual2(unsigned int x) { |
| 1023 | x &= x - 1; |
| 1024 | return (x & (x - 1)) == 0; |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | // Returns the index of the lowest bit set. |
| 1029 | static int BitPosition(unsigned x) { |
| 1030 | int bit_posn = 0; |
| 1031 | while ((x & 0xf) == 0) { |
| 1032 | bit_posn += 4; |
| 1033 | x >>= 4; |
| 1034 | } |
| 1035 | while ((x & 1) == 0) { |
| 1036 | bit_posn++; |
| 1037 | x >>= 1; |
| 1038 | } |
| 1039 | return bit_posn; |
| 1040 | } |
| 1041 | |
| 1042 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1043 | void CodeGenerator::SmiOperation(Token::Value op, |
| 1044 | Handle<Object> value, |
| 1045 | bool reversed, |
| 1046 | OverwriteMode mode) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1047 | int int_value = Smi::cast(*value)->value(); |
| 1048 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1049 | bool both_sides_are_smi = frame_->KnownSmiAt(0); |
| 1050 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1051 | bool something_to_inline; |
| 1052 | switch (op) { |
| 1053 | case Token::ADD: |
| 1054 | case Token::SUB: |
| 1055 | case Token::BIT_AND: |
| 1056 | case Token::BIT_OR: |
| 1057 | case Token::BIT_XOR: { |
| 1058 | something_to_inline = true; |
| 1059 | break; |
| 1060 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1061 | case Token::SHL: { |
| 1062 | something_to_inline = (both_sides_are_smi || !reversed); |
| 1063 | break; |
| 1064 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1065 | case Token::SHR: |
| 1066 | case Token::SAR: { |
| 1067 | if (reversed) { |
| 1068 | something_to_inline = false; |
| 1069 | } else { |
| 1070 | something_to_inline = true; |
| 1071 | } |
| 1072 | break; |
| 1073 | } |
| 1074 | case Token::MOD: { |
| 1075 | if (reversed || int_value < 2 || !IsPowerOf2(int_value)) { |
| 1076 | something_to_inline = false; |
| 1077 | } else { |
| 1078 | something_to_inline = true; |
| 1079 | } |
| 1080 | break; |
| 1081 | } |
| 1082 | case Token::MUL: { |
| 1083 | if (!IsEasyToMultiplyBy(int_value)) { |
| 1084 | something_to_inline = false; |
| 1085 | } else { |
| 1086 | something_to_inline = true; |
| 1087 | } |
| 1088 | break; |
| 1089 | } |
| 1090 | default: { |
| 1091 | something_to_inline = false; |
| 1092 | break; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | if (!something_to_inline) { |
| 1097 | if (!reversed) { |
| 1098 | // Push the rhs onto the virtual frame by putting it in a TOS register. |
| 1099 | Register rhs = frame_->GetTOSRegister(); |
| 1100 | __ mov(rhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1101 | frame_->EmitPush(rhs, TypeInfo::Smi()); |
| 1102 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1103 | } else { |
| 1104 | // Pop the rhs, then push lhs and rhs in the right order. Only performs |
| 1105 | // at most one pop, the rest takes place in TOS registers. |
| 1106 | Register lhs = frame_->GetTOSRegister(); // Get reg for pushing. |
| 1107 | Register rhs = frame_->PopToRegister(lhs); // Don't use lhs for this. |
| 1108 | __ mov(lhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1109 | frame_->EmitPush(lhs, TypeInfo::Smi()); |
| 1110 | TypeInfo t = both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Unknown(); |
| 1111 | frame_->EmitPush(rhs, t); |
| 1112 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, kUnknownIntValue); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1113 | } |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | // We move the top of stack to a register (normally no move is invoved). |
| 1118 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1119 | switch (op) { |
| 1120 | case Token::ADD: { |
| 1121 | DeferredCode* deferred = |
| 1122 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1123 | |
| 1124 | __ add(tos, tos, Operand(value), SetCC); |
| 1125 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1126 | if (!both_sides_are_smi) { |
| 1127 | __ tst(tos, Operand(kSmiTagMask)); |
| 1128 | deferred->Branch(ne); |
| 1129 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1130 | deferred->BindExit(); |
| 1131 | frame_->EmitPush(tos); |
| 1132 | break; |
| 1133 | } |
| 1134 | |
| 1135 | case Token::SUB: { |
| 1136 | DeferredCode* deferred = |
| 1137 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1138 | |
| 1139 | if (reversed) { |
| 1140 | __ rsb(tos, tos, Operand(value), SetCC); |
| 1141 | } else { |
| 1142 | __ sub(tos, tos, Operand(value), SetCC); |
| 1143 | } |
| 1144 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1145 | if (!both_sides_are_smi) { |
| 1146 | __ tst(tos, Operand(kSmiTagMask)); |
| 1147 | deferred->Branch(ne); |
| 1148 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1149 | deferred->BindExit(); |
| 1150 | frame_->EmitPush(tos); |
| 1151 | break; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | case Token::BIT_OR: |
| 1156 | case Token::BIT_XOR: |
| 1157 | case Token::BIT_AND: { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1158 | if (both_sides_are_smi) { |
| 1159 | switch (op) { |
| 1160 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1161 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1162 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1163 | default: UNREACHABLE(); |
| 1164 | } |
| 1165 | frame_->EmitPush(tos, TypeInfo::Smi()); |
| 1166 | } else { |
| 1167 | DeferredCode* deferred = |
| 1168 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1169 | __ tst(tos, Operand(kSmiTagMask)); |
| 1170 | deferred->Branch(ne); |
| 1171 | switch (op) { |
| 1172 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1173 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1174 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1175 | default: UNREACHABLE(); |
| 1176 | } |
| 1177 | deferred->BindExit(); |
| 1178 | TypeInfo result_type = |
| 1179 | (op == Token::BIT_AND) ? TypeInfo::Smi() : TypeInfo::Integer32(); |
| 1180 | frame_->EmitPush(tos, result_type); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1181 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1182 | break; |
| 1183 | } |
| 1184 | |
| 1185 | case Token::SHL: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1186 | if (reversed) { |
| 1187 | ASSERT(both_sides_are_smi); |
| 1188 | int max_shift = 0; |
| 1189 | int max_result = int_value == 0 ? 1 : int_value; |
| 1190 | while (Smi::IsValid(max_result << 1)) { |
| 1191 | max_shift++; |
| 1192 | max_result <<= 1; |
| 1193 | } |
| 1194 | DeferredCode* deferred = |
| 1195 | new DeferredInlineSmiOperation(op, int_value, true, mode, tos); |
| 1196 | // Mask off the last 5 bits of the shift operand (rhs). This is part |
| 1197 | // of the definition of shift in JS and we know we have a Smi so we |
| 1198 | // can safely do this. The masked version gets passed to the |
| 1199 | // deferred code, but that makes no difference. |
| 1200 | __ and_(tos, tos, Operand(Smi::FromInt(0x1f))); |
| 1201 | __ cmp(tos, Operand(Smi::FromInt(max_shift))); |
| 1202 | deferred->Branch(ge); |
| 1203 | Register scratch = VirtualFrame::scratch0(); |
| 1204 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Untag. |
| 1205 | __ mov(tos, Operand(Smi::FromInt(int_value))); // Load constant. |
| 1206 | __ mov(tos, Operand(tos, LSL, scratch)); // Shift constant. |
| 1207 | deferred->BindExit(); |
| 1208 | TypeInfo result = TypeInfo::Integer32(); |
| 1209 | frame_->EmitPush(tos, result); |
| 1210 | break; |
| 1211 | } |
| 1212 | // Fall through! |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1213 | case Token::SHR: |
| 1214 | case Token::SAR: { |
| 1215 | ASSERT(!reversed); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1216 | TypeInfo result = TypeInfo::Integer32(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1217 | Register scratch = VirtualFrame::scratch0(); |
| 1218 | Register scratch2 = VirtualFrame::scratch1(); |
| 1219 | int shift_value = int_value & 0x1f; // least significant 5 bits |
| 1220 | DeferredCode* deferred = |
| 1221 | new DeferredInlineSmiOperation(op, shift_value, false, mode, tos); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1222 | uint32_t problematic_mask = kSmiTagMask; |
| 1223 | // For unsigned shift by zero all negative smis are problematic. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1224 | bool skip_smi_test = both_sides_are_smi; |
| 1225 | if (shift_value == 0 && op == Token::SHR) { |
| 1226 | problematic_mask |= 0x80000000; |
| 1227 | skip_smi_test = false; |
| 1228 | } |
| 1229 | if (!skip_smi_test) { |
| 1230 | __ tst(tos, Operand(problematic_mask)); |
| 1231 | deferred->Branch(ne); // Go slow for problematic input. |
| 1232 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1233 | switch (op) { |
| 1234 | case Token::SHL: { |
| 1235 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1236 | int adjusted_shift = shift_value - kSmiTagSize; |
| 1237 | ASSERT(adjusted_shift >= 0); |
| 1238 | if (adjusted_shift != 0) { |
| 1239 | __ mov(scratch, Operand(tos, LSL, adjusted_shift)); |
| 1240 | // Check that the *signed* result fits in a smi. |
| 1241 | __ add(scratch2, scratch, Operand(0x40000000), SetCC); |
| 1242 | deferred->Branch(mi); |
| 1243 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
| 1244 | } else { |
| 1245 | // Check that the *signed* result fits in a smi. |
| 1246 | __ add(scratch2, tos, Operand(0x40000000), SetCC); |
| 1247 | deferred->Branch(mi); |
| 1248 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
| 1249 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1250 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1251 | break; |
| 1252 | } |
| 1253 | case Token::SHR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1254 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1255 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Remove tag. |
| 1256 | // LSR by immediate 0 means shifting 32 bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1257 | __ mov(scratch, Operand(scratch, LSR, shift_value)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1258 | if (shift_value == 1) { |
| 1259 | // check that the *unsigned* result fits in a smi |
| 1260 | // neither of the two high-order bits can be set: |
| 1261 | // - 0x80000000: high bit would be lost when smi tagging |
| 1262 | // - 0x40000000: this number would convert to negative when |
| 1263 | // smi tagging these two cases can only happen with shifts |
| 1264 | // by 0 or 1 when handed a valid smi |
| 1265 | __ tst(scratch, Operand(0xc0000000)); |
| 1266 | deferred->Branch(ne); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1267 | } else { |
| 1268 | ASSERT(shift_value >= 2); |
| 1269 | result = TypeInfo::Smi(); // SHR by at least 2 gives a Smi. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1270 | } |
| 1271 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1272 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1273 | break; |
| 1274 | } |
| 1275 | case Token::SAR: { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1276 | // In the ARM instructions set, ASR by immediate 0 means shifting 32 |
| 1277 | // bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1278 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1279 | // Do the shift and the tag removal in one operation. If the shift |
| 1280 | // is 31 bits (the highest possible value) then we emit the |
| 1281 | // instruction as a shift by 0 which means shift arithmetically by |
| 1282 | // 32. |
| 1283 | __ mov(tos, Operand(tos, ASR, (kSmiTagSize + shift_value) & 0x1f)); |
| 1284 | // Put tag back. |
| 1285 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1286 | // SAR by at least 1 gives a Smi. |
| 1287 | result = TypeInfo::Smi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1288 | } |
| 1289 | break; |
| 1290 | } |
| 1291 | default: UNREACHABLE(); |
| 1292 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1293 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1294 | frame_->EmitPush(tos, result); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1295 | break; |
| 1296 | } |
| 1297 | |
| 1298 | case Token::MOD: { |
| 1299 | ASSERT(!reversed); |
| 1300 | ASSERT(int_value >= 2); |
| 1301 | ASSERT(IsPowerOf2(int_value)); |
| 1302 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1303 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1304 | unsigned mask = (0x80000000u | kSmiTagMask); |
| 1305 | __ tst(tos, Operand(mask)); |
| 1306 | deferred->Branch(ne); // Go to deferred code on non-Smis and negative. |
| 1307 | mask = (int_value << kSmiTagSize) - 1; |
| 1308 | __ and_(tos, tos, Operand(mask)); |
| 1309 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1310 | // Mod of positive power of 2 Smi gives a Smi if the lhs is an integer. |
| 1311 | frame_->EmitPush( |
| 1312 | tos, |
| 1313 | both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Number()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1314 | break; |
| 1315 | } |
| 1316 | |
| 1317 | case Token::MUL: { |
| 1318 | ASSERT(IsEasyToMultiplyBy(int_value)); |
| 1319 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1320 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1321 | unsigned max_smi_that_wont_overflow = Smi::kMaxValue / int_value; |
| 1322 | max_smi_that_wont_overflow <<= kSmiTagSize; |
| 1323 | unsigned mask = 0x80000000u; |
| 1324 | while ((mask & max_smi_that_wont_overflow) == 0) { |
| 1325 | mask |= mask >> 1; |
| 1326 | } |
| 1327 | mask |= kSmiTagMask; |
| 1328 | // This does a single mask that checks for a too high value in a |
| 1329 | // conservative way and for a non-Smi. It also filters out negative |
| 1330 | // numbers, unfortunately, but since this code is inline we prefer |
| 1331 | // brevity to comprehensiveness. |
| 1332 | __ tst(tos, Operand(mask)); |
| 1333 | deferred->Branch(ne); |
| 1334 | MultiplyByKnownInt(masm_, tos, tos, int_value); |
| 1335 | deferred->BindExit(); |
| 1336 | frame_->EmitPush(tos); |
| 1337 | break; |
| 1338 | } |
| 1339 | |
| 1340 | default: |
| 1341 | UNREACHABLE(); |
| 1342 | break; |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1347 | void CodeGenerator::Comparison(Condition cc, |
| 1348 | Expression* left, |
| 1349 | Expression* right, |
| 1350 | bool strict) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1351 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1352 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1353 | if (left != NULL) Load(left); |
| 1354 | if (right != NULL) Load(right); |
| 1355 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1356 | // sp[0] : y |
| 1357 | // sp[1] : x |
| 1358 | // result : cc register |
| 1359 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1360 | // Strict only makes sense for equality comparisons. |
| 1361 | ASSERT(!strict || cc == eq); |
| 1362 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1363 | Register lhs; |
| 1364 | Register rhs; |
| 1365 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1366 | bool lhs_is_smi; |
| 1367 | bool rhs_is_smi; |
| 1368 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1369 | // We load the top two stack positions into registers chosen by the virtual |
| 1370 | // frame. This should keep the register shuffling to a minimum. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1371 | // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| 1372 | if (cc == gt || cc == le) { |
| 1373 | cc = ReverseCondition(cc); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1374 | lhs_is_smi = frame_->KnownSmiAt(0); |
| 1375 | rhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1376 | lhs = frame_->PopToRegister(); |
| 1377 | rhs = frame_->PopToRegister(lhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1378 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1379 | rhs_is_smi = frame_->KnownSmiAt(0); |
| 1380 | lhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1381 | rhs = frame_->PopToRegister(); |
| 1382 | lhs = frame_->PopToRegister(rhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1383 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1384 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1385 | bool both_sides_are_smi = (lhs_is_smi && rhs_is_smi); |
| 1386 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1387 | ASSERT(rhs.is(r0) || rhs.is(r1)); |
| 1388 | ASSERT(lhs.is(r0) || lhs.is(r1)); |
| 1389 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1390 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1391 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1392 | if (!both_sides_are_smi) { |
| 1393 | // Now we have the two sides in r0 and r1. We flush any other registers |
| 1394 | // because the stub doesn't know about register allocation. |
| 1395 | frame_->SpillAll(); |
| 1396 | Register scratch = VirtualFrame::scratch0(); |
| 1397 | Register smi_test_reg; |
| 1398 | if (lhs_is_smi) { |
| 1399 | smi_test_reg = rhs; |
| 1400 | } else if (rhs_is_smi) { |
| 1401 | smi_test_reg = lhs; |
| 1402 | } else { |
| 1403 | __ orr(scratch, lhs, Operand(rhs)); |
| 1404 | smi_test_reg = scratch; |
| 1405 | } |
| 1406 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 1407 | JumpTarget smi; |
| 1408 | smi.Branch(eq); |
| 1409 | |
| 1410 | // Perform non-smi comparison by stub. |
| 1411 | // CompareStub takes arguments in r0 and r1, returns <0, >0 or 0 in r0. |
| 1412 | // We call with 0 args because there are 0 on the stack. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1413 | CompareStub stub(cc, strict, kBothCouldBeNaN, true, lhs, rhs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1414 | frame_->CallStub(&stub, 0); |
| 1415 | __ cmp(r0, Operand(0)); |
| 1416 | exit.Jump(); |
| 1417 | |
| 1418 | smi.Bind(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1421 | // Do smi comparisons by pointer comparison. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1422 | __ cmp(lhs, Operand(rhs)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1423 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1424 | exit.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1425 | cc_reg_ = cc; |
| 1426 | } |
| 1427 | |
| 1428 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1429 | // Call the function on the stack with the given arguments. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1430 | void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1431 | CallFunctionFlags flags, |
| 1432 | int position) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1433 | // Push the arguments ("left-to-right") on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1434 | int arg_count = args->length(); |
| 1435 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1436 | Load(args->at(i)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1437 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1438 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1439 | // Record the position for debugging purposes. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1440 | CodeForSourcePosition(position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1441 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1442 | // Use the shared code stub to call the function. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1443 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1444 | CallFunctionStub call_function(arg_count, in_loop, flags); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1445 | frame_->CallStub(&call_function, arg_count + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | |
| 1447 | // Restore context and pop function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1448 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1449 | frame_->Drop(); // discard the TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1453 | void CodeGenerator::CallApplyLazy(Expression* applicand, |
| 1454 | Expression* receiver, |
| 1455 | VariableProxy* arguments, |
| 1456 | int position) { |
| 1457 | // An optimized implementation of expressions of the form |
| 1458 | // x.apply(y, arguments). |
| 1459 | // If the arguments object of the scope has not been allocated, |
| 1460 | // and x.apply is Function.prototype.apply, this optimization |
| 1461 | // just copies y and the arguments of the current function on the |
| 1462 | // stack, as receiver and arguments, and calls x. |
| 1463 | // In the implementation comments, we call x the applicand |
| 1464 | // and y the receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1465 | |
| 1466 | ASSERT(ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION); |
| 1467 | ASSERT(arguments->IsArguments()); |
| 1468 | |
| 1469 | // Load applicand.apply onto the stack. This will usually |
| 1470 | // give us a megamorphic load site. Not super, but it works. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1471 | Load(applicand); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1472 | Handle<String> name = Factory::LookupAsciiSymbol("apply"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1473 | frame_->Dup(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1474 | frame_->CallLoadIC(name, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1475 | frame_->EmitPush(r0); |
| 1476 | |
| 1477 | // Load the receiver and the existing arguments object onto the |
| 1478 | // expression stack. Avoid allocating the arguments object here. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1479 | Load(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1480 | LoadFromSlot(scope()->arguments()->var()->slot(), NOT_INSIDE_TYPEOF); |
| 1481 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1482 | // At this point the top two stack elements are probably in registers |
| 1483 | // since they were just loaded. Ensure they are in regs and get the |
| 1484 | // regs. |
| 1485 | Register receiver_reg = frame_->Peek2(); |
| 1486 | Register arguments_reg = frame_->Peek(); |
| 1487 | |
| 1488 | // From now on the frame is spilled. |
| 1489 | frame_->SpillAll(); |
| 1490 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1491 | // Emit the source position information after having loaded the |
| 1492 | // receiver and the arguments. |
| 1493 | CodeForSourcePosition(position); |
| 1494 | // Contents of the stack at this point: |
| 1495 | // sp[0]: arguments object of the current function or the hole. |
| 1496 | // sp[1]: receiver |
| 1497 | // sp[2]: applicand.apply |
| 1498 | // sp[3]: applicand. |
| 1499 | |
| 1500 | // Check if the arguments object has been lazily allocated |
| 1501 | // already. If so, just use that instead of copying the arguments |
| 1502 | // from the stack. This also deals with cases where a local variable |
| 1503 | // named 'arguments' has been introduced. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1504 | JumpTarget slow; |
| 1505 | Label done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1506 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1507 | __ cmp(ip, arguments_reg); |
| 1508 | slow.Branch(ne); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1509 | |
| 1510 | Label build_args; |
| 1511 | // Get rid of the arguments object probe. |
| 1512 | frame_->Drop(); |
| 1513 | // Stack now has 3 elements on it. |
| 1514 | // Contents of stack at this point: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1515 | // sp[0]: receiver - in the receiver_reg register. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1516 | // sp[1]: applicand.apply |
| 1517 | // sp[2]: applicand. |
| 1518 | |
| 1519 | // Check that the receiver really is a JavaScript object. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1520 | __ BranchOnSmi(receiver_reg, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1521 | // We allow all JSObjects including JSFunctions. As long as |
| 1522 | // JS_FUNCTION_TYPE is the last instance type and it is right |
| 1523 | // after LAST_JS_OBJECT_TYPE, we do not have to check the upper |
| 1524 | // bound. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1525 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1526 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1527 | __ CompareObjectType(receiver_reg, r2, r3, FIRST_JS_OBJECT_TYPE); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1528 | __ b(lt, &build_args); |
| 1529 | |
| 1530 | // Check that applicand.apply is Function.prototype.apply. |
| 1531 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1532 | __ BranchOnSmi(r0, &build_args); |
| 1533 | __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE); |
| 1534 | __ b(ne, &build_args); |
| 1535 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 1536 | Handle<Code> apply_code(Builtins::builtin(Builtins::FunctionApply)); |
| 1537 | __ ldr(r1, FieldMemOperand(r0, SharedFunctionInfo::kCodeOffset)); |
| 1538 | __ cmp(r1, Operand(apply_code)); |
| 1539 | __ b(ne, &build_args); |
| 1540 | |
| 1541 | // Check that applicand is a function. |
| 1542 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 1543 | __ BranchOnSmi(r1, &build_args); |
| 1544 | __ CompareObjectType(r1, r2, r3, JS_FUNCTION_TYPE); |
| 1545 | __ b(ne, &build_args); |
| 1546 | |
| 1547 | // Copy the arguments to this function possibly from the |
| 1548 | // adaptor frame below it. |
| 1549 | Label invoke, adapted; |
| 1550 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 1551 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 1552 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 1553 | __ b(eq, &adapted); |
| 1554 | |
| 1555 | // No arguments adaptor frame. Copy fixed number of arguments. |
| 1556 | __ mov(r0, Operand(scope()->num_parameters())); |
| 1557 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 1558 | __ ldr(r2, frame_->ParameterAt(i)); |
| 1559 | __ push(r2); |
| 1560 | } |
| 1561 | __ jmp(&invoke); |
| 1562 | |
| 1563 | // Arguments adaptor frame present. Copy arguments from there, but |
| 1564 | // avoid copying too many arguments to avoid stack overflows. |
| 1565 | __ bind(&adapted); |
| 1566 | static const uint32_t kArgumentsLimit = 1 * KB; |
| 1567 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1568 | __ mov(r0, Operand(r0, LSR, kSmiTagSize)); |
| 1569 | __ mov(r3, r0); |
| 1570 | __ cmp(r0, Operand(kArgumentsLimit)); |
| 1571 | __ b(gt, &build_args); |
| 1572 | |
| 1573 | // Loop through the arguments pushing them onto the execution |
| 1574 | // stack. We don't inform the virtual frame of the push, so we don't |
| 1575 | // have to worry about getting rid of the elements from the virtual |
| 1576 | // frame. |
| 1577 | Label loop; |
| 1578 | // r3 is a small non-negative integer, due to the test above. |
| 1579 | __ cmp(r3, Operand(0)); |
| 1580 | __ b(eq, &invoke); |
| 1581 | // Compute the address of the first argument. |
| 1582 | __ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2)); |
| 1583 | __ add(r2, r2, Operand(kPointerSize)); |
| 1584 | __ bind(&loop); |
| 1585 | // Post-decrement argument address by kPointerSize on each iteration. |
| 1586 | __ ldr(r4, MemOperand(r2, kPointerSize, NegPostIndex)); |
| 1587 | __ push(r4); |
| 1588 | __ sub(r3, r3, Operand(1), SetCC); |
| 1589 | __ b(gt, &loop); |
| 1590 | |
| 1591 | // Invoke the function. |
| 1592 | __ bind(&invoke); |
| 1593 | ParameterCount actual(r0); |
| 1594 | __ InvokeFunction(r1, actual, CALL_FUNCTION); |
| 1595 | // Drop applicand.apply and applicand from the stack, and push |
| 1596 | // the result of the function call, but leave the spilled frame |
| 1597 | // unchanged, with 3 elements, so it is correct when we compile the |
| 1598 | // slow-case code. |
| 1599 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 1600 | __ push(r0); |
| 1601 | // Stack now has 1 element: |
| 1602 | // sp[0]: result |
| 1603 | __ jmp(&done); |
| 1604 | |
| 1605 | // Slow-case: Allocate the arguments object since we know it isn't |
| 1606 | // there, and fall-through to the slow-case where we call |
| 1607 | // applicand.apply. |
| 1608 | __ bind(&build_args); |
| 1609 | // Stack now has 3 elements, because we have jumped from where: |
| 1610 | // sp[0]: receiver |
| 1611 | // sp[1]: applicand.apply |
| 1612 | // sp[2]: applicand. |
| 1613 | StoreArgumentsObject(false); |
| 1614 | |
| 1615 | // Stack and frame now have 4 elements. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1616 | slow.Bind(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1617 | |
| 1618 | // Generic computation of x.apply(y, args) with no special optimization. |
| 1619 | // Flip applicand.apply and applicand on the stack, so |
| 1620 | // applicand looks like the receiver of the applicand.apply call. |
| 1621 | // Then process it as a normal function call. |
| 1622 | __ ldr(r0, MemOperand(sp, 3 * kPointerSize)); |
| 1623 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1624 | __ Strd(r0, r1, MemOperand(sp, 2 * kPointerSize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1625 | |
| 1626 | CallFunctionStub call_function(2, NOT_IN_LOOP, NO_CALL_FUNCTION_FLAGS); |
| 1627 | frame_->CallStub(&call_function, 3); |
| 1628 | // The function and its two arguments have been dropped. |
| 1629 | frame_->Drop(); // Drop the receiver as well. |
| 1630 | frame_->EmitPush(r0); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame^] | 1631 | frame_->SpillAll(); // A spilled frame is also jumping to label done. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1632 | // Stack now has 1 element: |
| 1633 | // sp[0]: result |
| 1634 | __ bind(&done); |
| 1635 | |
| 1636 | // Restore the context register after a call. |
| 1637 | __ ldr(cp, frame_->Context()); |
| 1638 | } |
| 1639 | |
| 1640 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1641 | void CodeGenerator::Branch(bool if_true, JumpTarget* target) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1642 | ASSERT(has_cc()); |
| 1643 | Condition cc = if_true ? cc_reg_ : NegateCondition(cc_reg_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1644 | target->Branch(cc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | cc_reg_ = al; |
| 1646 | } |
| 1647 | |
| 1648 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1649 | void CodeGenerator::CheckStack() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1650 | frame_->SpillAll(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1651 | Comment cmnt(masm_, "[ check stack"); |
| 1652 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 1653 | // Put the lr setup instruction in the delay slot. kInstrSize is added to |
| 1654 | // the implicit 8 byte offset that always applies to operations with pc and |
| 1655 | // gives a return address 12 bytes down. |
| 1656 | masm_->add(lr, pc, Operand(Assembler::kInstrSize)); |
| 1657 | masm_->cmp(sp, Operand(ip)); |
| 1658 | StackCheckStub stub; |
| 1659 | // Call the stub if lower. |
| 1660 | masm_->mov(pc, |
| 1661 | Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
| 1662 | RelocInfo::CODE_TARGET), |
| 1663 | LeaveCC, |
| 1664 | lo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1668 | void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { |
| 1669 | #ifdef DEBUG |
| 1670 | int original_height = frame_->height(); |
| 1671 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1672 | for (int i = 0; frame_ != NULL && i < statements->length(); i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1673 | Visit(statements->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1674 | } |
| 1675 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 1676 | } |
| 1677 | |
| 1678 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1679 | void CodeGenerator::VisitBlock(Block* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1680 | #ifdef DEBUG |
| 1681 | int original_height = frame_->height(); |
| 1682 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | Comment cmnt(masm_, "[ Block"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1684 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1685 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1686 | VisitStatements(node->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1687 | if (node->break_target()->is_linked()) { |
| 1688 | node->break_target()->Bind(); |
| 1689 | } |
| 1690 | node->break_target()->Unuse(); |
| 1691 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1695 | void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1696 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1697 | frame_->EmitPush(Operand(pairs)); |
| 1698 | frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1699 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1700 | frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1701 | // The result is discarded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1705 | void CodeGenerator::VisitDeclaration(Declaration* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1706 | #ifdef DEBUG |
| 1707 | int original_height = frame_->height(); |
| 1708 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1709 | Comment cmnt(masm_, "[ Declaration"); |
| 1710 | Variable* var = node->proxy()->var(); |
| 1711 | ASSERT(var != NULL); // must have been resolved |
| 1712 | Slot* slot = var->slot(); |
| 1713 | |
| 1714 | // If it was not possible to allocate the variable at compile time, |
| 1715 | // we need to "declare" it at runtime to make sure it actually |
| 1716 | // exists in the local context. |
| 1717 | if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1718 | // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1719 | // during variable resolution and must have mode DYNAMIC. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1720 | ASSERT(var->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | // For now, just do a runtime call. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1722 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1723 | frame_->EmitPush(Operand(var->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1724 | // Declaration nodes are always declared in only two modes. |
| 1725 | ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1726 | PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1727 | frame_->EmitPush(Operand(Smi::FromInt(attr))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1728 | // Push initial value, if any. |
| 1729 | // Note: For variables we must not push an initial value (such as |
| 1730 | // 'undefined') because we may have a (legal) redeclaration and we |
| 1731 | // must not destroy the current value. |
| 1732 | if (node->mode() == Variable::CONST) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1733 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | } else if (node->fun() != NULL) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1735 | Load(node->fun()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1736 | } else { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1737 | frame_->EmitPush(Operand(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1738 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1739 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1740 | frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1741 | // Ignore the return value (declarations are statements). |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1742 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1743 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1744 | return; |
| 1745 | } |
| 1746 | |
| 1747 | ASSERT(!var->is_global()); |
| 1748 | |
| 1749 | // If we have a function or a constant, we need to initialize the variable. |
| 1750 | Expression* val = NULL; |
| 1751 | if (node->mode() == Variable::CONST) { |
| 1752 | val = new Literal(Factory::the_hole_value()); |
| 1753 | } else { |
| 1754 | val = node->fun(); // NULL if we don't have a function |
| 1755 | } |
| 1756 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1757 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | if (val != NULL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1759 | WriteBarrierCharacter wb_info = |
| 1760 | val->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
| 1761 | if (val->AsLiteral() != NULL) wb_info = NEVER_NEWSPACE; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1762 | // Set initial value. |
| 1763 | Reference target(this, node->proxy()); |
| 1764 | Load(val); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1765 | target.SetValue(NOT_CONST_INIT, wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1766 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1767 | // Get rid of the assigned value (declarations are statements). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1768 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1770 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1774 | void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1775 | #ifdef DEBUG |
| 1776 | int original_height = frame_->height(); |
| 1777 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1778 | Comment cmnt(masm_, "[ ExpressionStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1779 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1780 | Expression* expression = node->expression(); |
| 1781 | expression->MarkAsStatement(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1782 | Load(expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1783 | frame_->Drop(); |
| 1784 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1788 | void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1789 | #ifdef DEBUG |
| 1790 | int original_height = frame_->height(); |
| 1791 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1792 | Comment cmnt(masm_, "// EmptyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1793 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1794 | // nothing to do |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1795 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1799 | void CodeGenerator::VisitIfStatement(IfStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1800 | #ifdef DEBUG |
| 1801 | int original_height = frame_->height(); |
| 1802 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | Comment cmnt(masm_, "[ IfStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1804 | // Generate different code depending on which parts of the if statement |
| 1805 | // are present or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1806 | bool has_then_stm = node->HasThenStatement(); |
| 1807 | bool has_else_stm = node->HasElseStatement(); |
| 1808 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1809 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1810 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1811 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1812 | if (has_then_stm && has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1813 | Comment cmnt(masm_, "[ IfThenElse"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1814 | JumpTarget then; |
| 1815 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1817 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1818 | if (frame_ != NULL) { |
| 1819 | Branch(false, &else_); |
| 1820 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1821 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1822 | if (frame_ != NULL || then.is_linked()) { |
| 1823 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1824 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1825 | } |
| 1826 | if (frame_ != NULL) { |
| 1827 | exit.Jump(); |
| 1828 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1829 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1830 | if (else_.is_linked()) { |
| 1831 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1832 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1833 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1834 | |
| 1835 | } else if (has_then_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1836 | Comment cmnt(masm_, "[ IfThen"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1837 | ASSERT(!has_else_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1838 | JumpTarget then; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1839 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1840 | LoadCondition(node->condition(), &then, &exit, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1841 | if (frame_ != NULL) { |
| 1842 | Branch(false, &exit); |
| 1843 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1844 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1845 | if (frame_ != NULL || then.is_linked()) { |
| 1846 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1847 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1848 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | |
| 1850 | } else if (has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1851 | Comment cmnt(masm_, "[ IfElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | ASSERT(!has_then_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1853 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1854 | // if (!cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1855 | LoadCondition(node->condition(), &exit, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1856 | if (frame_ != NULL) { |
| 1857 | Branch(true, &exit); |
| 1858 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1860 | if (frame_ != NULL || else_.is_linked()) { |
| 1861 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1862 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1863 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1864 | |
| 1865 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1866 | Comment cmnt(masm_, "[ If"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1867 | ASSERT(!has_then_stm && !has_else_stm); |
| 1868 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1869 | LoadCondition(node->condition(), &exit, &exit, false); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1870 | if (frame_ != NULL) { |
| 1871 | if (has_cc()) { |
| 1872 | cc_reg_ = al; |
| 1873 | } else { |
| 1874 | frame_->Drop(); |
| 1875 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | // end |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1880 | if (exit.is_linked()) { |
| 1881 | exit.Bind(); |
| 1882 | } |
| 1883 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1887 | void CodeGenerator::VisitContinueStatement(ContinueStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | Comment cmnt(masm_, "[ ContinueStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1889 | CodeForStatementPosition(node); |
| 1890 | node->target()->continue_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1894 | void CodeGenerator::VisitBreakStatement(BreakStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1895 | Comment cmnt(masm_, "[ BreakStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1896 | CodeForStatementPosition(node); |
| 1897 | node->target()->break_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1901 | void CodeGenerator::VisitReturnStatement(ReturnStatement* node) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1902 | frame_->SpillAll(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1903 | Comment cmnt(masm_, "[ ReturnStatement"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1904 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1905 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1906 | Load(node->expression()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1907 | if (function_return_is_shadowed_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1908 | frame_->EmitPop(r0); |
| 1909 | function_return_.Jump(); |
| 1910 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1911 | // Pop the result from the frame and prepare the frame for |
| 1912 | // returning thus making it easier to merge. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1913 | frame_->PopToR0(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1914 | frame_->PrepareForReturn(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1915 | if (function_return_.is_bound()) { |
| 1916 | // If the function return label is already bound we reuse the |
| 1917 | // code by jumping to the return site. |
| 1918 | function_return_.Jump(); |
| 1919 | } else { |
| 1920 | function_return_.Bind(); |
| 1921 | GenerateReturnSequence(); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1925 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1926 | |
| 1927 | void CodeGenerator::GenerateReturnSequence() { |
| 1928 | if (FLAG_trace) { |
| 1929 | // Push the return value on the stack as the parameter. |
| 1930 | // Runtime::TraceExit returns the parameter as it is. |
| 1931 | frame_->EmitPush(r0); |
| 1932 | frame_->CallRuntime(Runtime::kTraceExit, 1); |
| 1933 | } |
| 1934 | |
| 1935 | #ifdef DEBUG |
| 1936 | // Add a label for checking the size of the code used for returning. |
| 1937 | Label check_exit_codesize; |
| 1938 | masm_->bind(&check_exit_codesize); |
| 1939 | #endif |
| 1940 | // Make sure that the constant pool is not emitted inside of the return |
| 1941 | // sequence. |
| 1942 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 1943 | // Tear down the frame which will restore the caller's frame pointer and |
| 1944 | // the link register. |
| 1945 | frame_->Exit(); |
| 1946 | |
| 1947 | // Here we use masm_-> instead of the __ macro to avoid the code coverage |
| 1948 | // tool from instrumenting as we rely on the code size here. |
| 1949 | int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
| 1950 | masm_->add(sp, sp, Operand(sp_delta)); |
| 1951 | masm_->Jump(lr); |
| 1952 | DeleteFrame(); |
| 1953 | |
| 1954 | #ifdef DEBUG |
| 1955 | // Check that the size of the code used for returning matches what is |
| 1956 | // expected by the debugger. If the sp_delts above cannot be encoded in |
| 1957 | // the add instruction the add will generate two instructions. |
| 1958 | int return_sequence_length = |
| 1959 | masm_->InstructionsGeneratedSince(&check_exit_codesize); |
| 1960 | CHECK(return_sequence_length == |
| 1961 | Assembler::kJSReturnSequenceInstructions || |
| 1962 | return_sequence_length == |
| 1963 | Assembler::kJSReturnSequenceInstructions + 1); |
| 1964 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1965 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1969 | void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1970 | #ifdef DEBUG |
| 1971 | int original_height = frame_->height(); |
| 1972 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1973 | Comment cmnt(masm_, "[ WithEnterStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1974 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1975 | Load(node->expression()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1976 | if (node->is_catch_block()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1977 | frame_->CallRuntime(Runtime::kPushCatchContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1978 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1979 | frame_->CallRuntime(Runtime::kPushContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1980 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1981 | #ifdef DEBUG |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1982 | JumpTarget verified_true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1983 | __ cmp(r0, cp); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1984 | verified_true.Branch(eq); |
| 1985 | __ stop("PushContext: r0 is expected to be the same as cp"); |
| 1986 | verified_true.Bind(); |
| 1987 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1989 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1990 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1994 | void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1995 | #ifdef DEBUG |
| 1996 | int original_height = frame_->height(); |
| 1997 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1998 | Comment cmnt(masm_, "[ WithExitStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1999 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2000 | // Pop context. |
| 2001 | __ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX)); |
| 2002 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2003 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2004 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2008 | void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2009 | #ifdef DEBUG |
| 2010 | int original_height = frame_->height(); |
| 2011 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2012 | Comment cmnt(masm_, "[ SwitchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2013 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2014 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2015 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2016 | Load(node->tag()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2017 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2018 | JumpTarget next_test; |
| 2019 | JumpTarget fall_through; |
| 2020 | JumpTarget default_entry; |
| 2021 | JumpTarget default_exit(JumpTarget::BIDIRECTIONAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2022 | ZoneList<CaseClause*>* cases = node->cases(); |
| 2023 | int length = cases->length(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2024 | CaseClause* default_clause = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2025 | |
| 2026 | for (int i = 0; i < length; i++) { |
| 2027 | CaseClause* clause = cases->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2028 | if (clause->is_default()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2029 | // Remember the default clause and compile it at the end. |
| 2030 | default_clause = clause; |
| 2031 | continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2034 | Comment cmnt(masm_, "[ Case clause"); |
| 2035 | // Compile the test. |
| 2036 | next_test.Bind(); |
| 2037 | next_test.Unuse(); |
| 2038 | // Duplicate TOS. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2039 | frame_->Dup(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2040 | Comparison(eq, NULL, clause->label(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2041 | Branch(false, &next_test); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2042 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2043 | // Before entering the body from the test, remove the switch value from |
| 2044 | // the stack. |
| 2045 | frame_->Drop(); |
| 2046 | |
| 2047 | // Label the body so that fall through is enabled. |
| 2048 | if (i > 0 && cases->at(i - 1)->is_default()) { |
| 2049 | default_exit.Bind(); |
| 2050 | } else { |
| 2051 | fall_through.Bind(); |
| 2052 | fall_through.Unuse(); |
| 2053 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2054 | VisitStatements(clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2055 | |
| 2056 | // If control flow can fall through from the body, jump to the next body |
| 2057 | // or the end of the statement. |
| 2058 | if (frame_ != NULL) { |
| 2059 | if (i < length - 1 && cases->at(i + 1)->is_default()) { |
| 2060 | default_entry.Jump(); |
| 2061 | } else { |
| 2062 | fall_through.Jump(); |
| 2063 | } |
| 2064 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2067 | // The final "test" removes the switch value. |
| 2068 | next_test.Bind(); |
| 2069 | frame_->Drop(); |
| 2070 | |
| 2071 | // If there is a default clause, compile it. |
| 2072 | if (default_clause != NULL) { |
| 2073 | Comment cmnt(masm_, "[ Default clause"); |
| 2074 | default_entry.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2075 | VisitStatements(default_clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2076 | // If control flow can fall out of the default and there is a case after |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2077 | // it, jump to that case's body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2078 | if (frame_ != NULL && default_exit.is_bound()) { |
| 2079 | default_exit.Jump(); |
| 2080 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2081 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2082 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2083 | if (fall_through.is_linked()) { |
| 2084 | fall_through.Bind(); |
| 2085 | } |
| 2086 | |
| 2087 | if (node->break_target()->is_linked()) { |
| 2088 | node->break_target()->Bind(); |
| 2089 | } |
| 2090 | node->break_target()->Unuse(); |
| 2091 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2095 | void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2096 | #ifdef DEBUG |
| 2097 | int original_height = frame_->height(); |
| 2098 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2099 | Comment cmnt(masm_, "[ DoWhileStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2100 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2101 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2102 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2103 | IncrementLoopNesting(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2104 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2105 | // Label the top of the loop for the backward CFG edge. If the test |
| 2106 | // is always true we can use the continue target, and if the test is |
| 2107 | // always false there is no need. |
| 2108 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2109 | switch (info) { |
| 2110 | case ALWAYS_TRUE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2111 | node->continue_target()->SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2112 | node->continue_target()->Bind(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2113 | break; |
| 2114 | case ALWAYS_FALSE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2115 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | case DONT_KNOW: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2118 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2119 | body.Bind(); |
| 2120 | break; |
| 2121 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2122 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2123 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2124 | Visit(node->body()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2125 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2126 | // Compile the test. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2127 | switch (info) { |
| 2128 | case ALWAYS_TRUE: |
| 2129 | // If control can fall off the end of the body, jump back to the |
| 2130 | // top. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2131 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2132 | node->continue_target()->Jump(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2133 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2134 | break; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2135 | case ALWAYS_FALSE: |
| 2136 | // If we have a continue in the body, we only have to bind its |
| 2137 | // jump target. |
| 2138 | if (node->continue_target()->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2139 | node->continue_target()->Bind(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2140 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | case DONT_KNOW: |
| 2143 | // We have to compile the test expression if it can be reached by |
| 2144 | // control flow falling out of the body or via continue. |
| 2145 | if (node->continue_target()->is_linked()) { |
| 2146 | node->continue_target()->Bind(); |
| 2147 | } |
| 2148 | if (has_valid_frame()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2149 | Comment cmnt(masm_, "[ DoWhileCondition"); |
| 2150 | CodeForDoWhileConditionPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2151 | LoadCondition(node->cond(), &body, node->break_target(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2152 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2153 | // A invalid frame here indicates that control did not |
| 2154 | // fall out of the test expression. |
| 2155 | Branch(true, &body); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2156 | } |
| 2157 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| 2160 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2161 | if (node->break_target()->is_linked()) { |
| 2162 | node->break_target()->Bind(); |
| 2163 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2164 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2165 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2166 | } |
| 2167 | |
| 2168 | |
| 2169 | void CodeGenerator::VisitWhileStatement(WhileStatement* node) { |
| 2170 | #ifdef DEBUG |
| 2171 | int original_height = frame_->height(); |
| 2172 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2173 | Comment cmnt(masm_, "[ WhileStatement"); |
| 2174 | CodeForStatementPosition(node); |
| 2175 | |
| 2176 | // If the test is never true and has no side effects there is no need |
| 2177 | // to compile the test or body. |
| 2178 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2179 | if (info == ALWAYS_FALSE) return; |
| 2180 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2181 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2182 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2183 | |
| 2184 | // Label the top of the loop with the continue target for the backward |
| 2185 | // CFG edge. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2186 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2187 | node->continue_target()->Bind(); |
| 2188 | |
| 2189 | if (info == DONT_KNOW) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2190 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2191 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2192 | if (has_valid_frame()) { |
| 2193 | // A NULL frame indicates that control did not fall out of the |
| 2194 | // test expression. |
| 2195 | Branch(false, node->break_target()); |
| 2196 | } |
| 2197 | if (has_valid_frame() || body.is_linked()) { |
| 2198 | body.Bind(); |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | if (has_valid_frame()) { |
| 2203 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2204 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2205 | |
| 2206 | // If control flow can fall out of the body, jump back to the top. |
| 2207 | if (has_valid_frame()) { |
| 2208 | node->continue_target()->Jump(); |
| 2209 | } |
| 2210 | } |
| 2211 | if (node->break_target()->is_linked()) { |
| 2212 | node->break_target()->Bind(); |
| 2213 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2214 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2215 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | void CodeGenerator::VisitForStatement(ForStatement* node) { |
| 2220 | #ifdef DEBUG |
| 2221 | int original_height = frame_->height(); |
| 2222 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2223 | Comment cmnt(masm_, "[ ForStatement"); |
| 2224 | CodeForStatementPosition(node); |
| 2225 | if (node->init() != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2226 | Visit(node->init()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | // If the test is never true there is no need to compile the test or |
| 2230 | // body. |
| 2231 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2232 | if (info == ALWAYS_FALSE) return; |
| 2233 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2234 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2235 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2236 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2237 | // We know that the loop index is a smi if it is not modified in the |
| 2238 | // loop body and it is checked against a constant limit in the loop |
| 2239 | // condition. In this case, we reset the static type information of the |
| 2240 | // loop index to smi before compiling the body, the update expression, and |
| 2241 | // the bottom check of the loop condition. |
| 2242 | TypeInfoCodeGenState type_info_scope(this, |
| 2243 | node->is_fast_smi_loop() ? |
| 2244 | node->loop_variable()->slot() : |
| 2245 | NULL, |
| 2246 | TypeInfo::Smi()); |
| 2247 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2248 | // If there is no update statement, label the top of the loop with the |
| 2249 | // continue target, otherwise with the loop target. |
| 2250 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2251 | if (node->next() == NULL) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2252 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2253 | node->continue_target()->Bind(); |
| 2254 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2255 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2256 | loop.Bind(); |
| 2257 | } |
| 2258 | |
| 2259 | // If the test is always true, there is no need to compile it. |
| 2260 | if (info == DONT_KNOW) { |
| 2261 | JumpTarget body; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2262 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2263 | if (has_valid_frame()) { |
| 2264 | Branch(false, node->break_target()); |
| 2265 | } |
| 2266 | if (has_valid_frame() || body.is_linked()) { |
| 2267 | body.Bind(); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | if (has_valid_frame()) { |
| 2272 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2273 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2274 | |
| 2275 | if (node->next() == NULL) { |
| 2276 | // If there is no update statement and control flow can fall out |
| 2277 | // of the loop, jump directly to the continue label. |
| 2278 | if (has_valid_frame()) { |
| 2279 | node->continue_target()->Jump(); |
| 2280 | } |
| 2281 | } else { |
| 2282 | // If there is an update statement and control flow can reach it |
| 2283 | // via falling out of the body of the loop or continuing, we |
| 2284 | // compile the update statement. |
| 2285 | if (node->continue_target()->is_linked()) { |
| 2286 | node->continue_target()->Bind(); |
| 2287 | } |
| 2288 | if (has_valid_frame()) { |
| 2289 | // Record source position of the statement as this code which is |
| 2290 | // after the code for the body actually belongs to the loop |
| 2291 | // statement and not the body. |
| 2292 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2293 | Visit(node->next()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2294 | loop.Jump(); |
| 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | if (node->break_target()->is_linked()) { |
| 2299 | node->break_target()->Bind(); |
| 2300 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2301 | DecrementLoopNesting(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2302 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2306 | void CodeGenerator::VisitForInStatement(ForInStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2307 | #ifdef DEBUG |
| 2308 | int original_height = frame_->height(); |
| 2309 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2310 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | Comment cmnt(masm_, "[ ForInStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2312 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2313 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2314 | JumpTarget primitive; |
| 2315 | JumpTarget jsobject; |
| 2316 | JumpTarget fixed_array; |
| 2317 | JumpTarget entry(JumpTarget::BIDIRECTIONAL); |
| 2318 | JumpTarget end_del_check; |
| 2319 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2320 | |
| 2321 | // Get the object to enumerate over (converted to JSObject). |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2322 | Load(node->enumerable()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2323 | |
| 2324 | // Both SpiderMonkey and kjs ignore null and undefined in contrast |
| 2325 | // to the specification. 12.6.4 mandates a call to ToObject. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2326 | frame_->EmitPop(r0); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2327 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 2328 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2329 | exit.Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2330 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2331 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2332 | exit.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Stack layout in body: |
| 2335 | // [iteration counter (Smi)] |
| 2336 | // [length of array] |
| 2337 | // [FixedArray] |
| 2338 | // [Map or 0] |
| 2339 | // [Object] |
| 2340 | |
| 2341 | // Check if enumerable is already a JSObject |
| 2342 | __ tst(r0, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2343 | primitive.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2344 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2345 | jsobject.Branch(hs); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2346 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2347 | primitive.Bind(); |
| 2348 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2349 | frame_->InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2350 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2351 | jsobject.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2352 | // Get the set of properties (as a FixedArray or Map). |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2353 | // r0: value to be iterated over |
| 2354 | frame_->EmitPush(r0); // Push the object being iterated over. |
| 2355 | |
| 2356 | // Check cache validity in generated code. This is a fast case for |
| 2357 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 2358 | // guarantee cache validity, call the runtime system to check cache |
| 2359 | // validity or get the property names in a fixed array. |
| 2360 | JumpTarget call_runtime; |
| 2361 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2362 | JumpTarget check_prototype; |
| 2363 | JumpTarget use_cache; |
| 2364 | __ mov(r1, Operand(r0)); |
| 2365 | loop.Bind(); |
| 2366 | // Check that there are no elements. |
| 2367 | __ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 2368 | __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex); |
| 2369 | __ cmp(r2, r4); |
| 2370 | call_runtime.Branch(ne); |
| 2371 | // Check that instance descriptors are not empty so that we can |
| 2372 | // check for an enum cache. Leave the map in r3 for the subsequent |
| 2373 | // prototype load. |
| 2374 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2375 | __ ldr(r2, FieldMemOperand(r3, Map::kInstanceDescriptorsOffset)); |
| 2376 | __ LoadRoot(ip, Heap::kEmptyDescriptorArrayRootIndex); |
| 2377 | __ cmp(r2, ip); |
| 2378 | call_runtime.Branch(eq); |
| 2379 | // Check that there in an enum cache in the non-empty instance |
| 2380 | // descriptors. This is the case if the next enumeration index |
| 2381 | // field does not contain a smi. |
| 2382 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumerationIndexOffset)); |
| 2383 | __ tst(r2, Operand(kSmiTagMask)); |
| 2384 | call_runtime.Branch(eq); |
| 2385 | // For all objects but the receiver, check that the cache is empty. |
| 2386 | // r4: empty fixed array root. |
| 2387 | __ cmp(r1, r0); |
| 2388 | check_prototype.Branch(eq); |
| 2389 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2390 | __ cmp(r2, r4); |
| 2391 | call_runtime.Branch(ne); |
| 2392 | check_prototype.Bind(); |
| 2393 | // Load the prototype from the map and loop if non-null. |
| 2394 | __ ldr(r1, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 2395 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2396 | __ cmp(r1, ip); |
| 2397 | loop.Branch(ne); |
| 2398 | // The enum cache is valid. Load the map of the object being |
| 2399 | // iterated over and use the cache for the iteration. |
| 2400 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2401 | use_cache.Jump(); |
| 2402 | |
| 2403 | call_runtime.Bind(); |
| 2404 | // Call the runtime to get the property names for the object. |
| 2405 | frame_->EmitPush(r0); // push the object (slot 4) for the runtime call |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2406 | frame_->CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2407 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2408 | // If we got a map from the runtime call, we can do a fast |
| 2409 | // modification check. Otherwise, we got a fixed array, and we have |
| 2410 | // to do a slow check. |
| 2411 | // r0: map or fixed array (result from call to |
| 2412 | // Runtime::kGetPropertyNamesFast) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2413 | __ mov(r2, Operand(r0)); |
| 2414 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2415 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 2416 | __ cmp(r1, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2417 | fixed_array.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2418 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2419 | use_cache.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2420 | // Get enum cache |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2421 | // r0: map (either the result from a call to |
| 2422 | // Runtime::kGetPropertyNamesFast or has been fetched directly from |
| 2423 | // the object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2424 | __ mov(r1, Operand(r0)); |
| 2425 | __ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset)); |
| 2426 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 2427 | __ ldr(r2, |
| 2428 | FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2429 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2430 | frame_->EmitPush(r0); // map |
| 2431 | frame_->EmitPush(r2); // enum cache bridge cache |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2432 | __ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2433 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2434 | __ mov(r0, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2435 | frame_->EmitPush(r0); |
| 2436 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2437 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2438 | fixed_array.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2439 | __ mov(r1, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2440 | frame_->EmitPush(r1); // insert 0 in place of Map |
| 2441 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2442 | |
| 2443 | // Push the length of the array and the initial index onto the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2444 | __ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2445 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2446 | __ mov(r0, Operand(Smi::FromInt(0))); // init index |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2447 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | |
| 2449 | // Condition. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2450 | entry.Bind(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2451 | // sp[0] : index |
| 2452 | // sp[1] : array/enum cache length |
| 2453 | // sp[2] : array or enum cache |
| 2454 | // sp[3] : 0 or map |
| 2455 | // sp[4] : enumerable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2456 | // Grab the current frame's height for the break and continue |
| 2457 | // targets only after all the state is pushed on the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2458 | node->break_target()->SetExpectedHeight(); |
| 2459 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2461 | // Load the current count to r0, load the length to r1. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2462 | __ Ldrd(r0, r1, frame_->ElementAt(0)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2463 | __ cmp(r0, r1); // compare to the array length |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2464 | node->break_target()->Branch(hs); |
| 2465 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2466 | // Get the i'th entry of the array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2467 | __ ldr(r2, frame_->ElementAt(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2469 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 2470 | |
| 2471 | // Get Map or 0. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2472 | __ ldr(r2, frame_->ElementAt(3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | // Check if this (still) matches the map of the enumerable. |
| 2474 | // If not, we have to filter the key. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2475 | __ ldr(r1, frame_->ElementAt(4)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2476 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2477 | __ cmp(r1, Operand(r2)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2478 | end_del_check.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2479 | |
| 2480 | // Convert the entry to a string (or null if it isn't a property anymore). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2481 | __ ldr(r0, frame_->ElementAt(4)); // push enumerable |
| 2482 | frame_->EmitPush(r0); |
| 2483 | frame_->EmitPush(r3); // push entry |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2484 | frame_->InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS, 2); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 2485 | __ mov(r3, Operand(r0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2486 | |
| 2487 | // If the property has been removed while iterating, we just skip it. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2488 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2489 | __ cmp(r3, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2490 | node->continue_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2491 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2492 | end_del_check.Bind(); |
| 2493 | // Store the entry in the 'each' expression and take another spin in the |
| 2494 | // loop. r3: i'th entry of the enum cache (or string there of) |
| 2495 | frame_->EmitPush(r3); // push entry |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2496 | { Reference each(this, node->each()); |
| 2497 | if (!each.is_illegal()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2498 | if (each.size() > 0) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2499 | __ ldr(r0, frame_->ElementAt(each.size())); |
| 2500 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2501 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2502 | frame_->Drop(2); |
| 2503 | } else { |
| 2504 | // If the reference was to a slot we rely on the convenient property |
| 2505 | // that it doesn't matter whether a value (eg, r3 pushed above) is |
| 2506 | // right on top of or right underneath a zero-sized reference. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2507 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2508 | frame_->Drop(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2509 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2510 | } |
| 2511 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2512 | // Body. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2513 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2514 | Visit(node->body()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2515 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2516 | // Next. Reestablish a spilled frame in case we are coming here via |
| 2517 | // a continue in the body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2518 | node->continue_target()->Bind(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2519 | frame_->SpillAll(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2520 | frame_->EmitPop(r0); |
| 2521 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 2522 | frame_->EmitPush(r0); |
| 2523 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2524 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2525 | // Cleanup. No need to spill because VirtualFrame::Drop is safe for |
| 2526 | // any frame. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2527 | node->break_target()->Bind(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2528 | frame_->Drop(5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2529 | |
| 2530 | // Exit. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2531 | exit.Bind(); |
| 2532 | node->continue_target()->Unuse(); |
| 2533 | node->break_target()->Unuse(); |
| 2534 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2538 | void CodeGenerator::VisitTryCatchStatement(TryCatchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2539 | #ifdef DEBUG |
| 2540 | int original_height = frame_->height(); |
| 2541 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2542 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2543 | Comment cmnt(masm_, "[ TryCatchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2544 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2545 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2546 | JumpTarget try_block; |
| 2547 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2548 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2549 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2550 | // --- Catch block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2551 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2552 | |
| 2553 | // Store the caught exception in the catch variable. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2554 | Variable* catch_var = node->catch_var()->var(); |
| 2555 | ASSERT(catch_var != NULL && catch_var->slot() != NULL); |
| 2556 | StoreToSlot(catch_var->slot(), NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2557 | |
| 2558 | // Remove the exception from the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2559 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2560 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2561 | VisitStatements(node->catch_block()->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2562 | if (frame_ != NULL) { |
| 2563 | exit.Jump(); |
| 2564 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2565 | |
| 2566 | |
| 2567 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2568 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2569 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2570 | frame_->PushTryHandler(TRY_CATCH_HANDLER); |
| 2571 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2572 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2573 | // Shadow the labels for all escapes from the try block, including |
| 2574 | // returns. During shadowing, the original label is hidden as the |
| 2575 | // LabelShadow and operations on the original actually affect the |
| 2576 | // shadowing label. |
| 2577 | // |
| 2578 | // We should probably try to unify the escaping labels and the return |
| 2579 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2580 | int nof_escapes = node->escaping_targets()->length(); |
| 2581 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2582 | |
| 2583 | // Add the shadow target for the function return. |
| 2584 | static const int kReturnShadowIndex = 0; |
| 2585 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2586 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2587 | function_return_is_shadowed_ = true; |
| 2588 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2589 | |
| 2590 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2591 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2592 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | // Generate code for the statements in the try block. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2596 | VisitStatements(node->try_block()->statements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | |
| 2598 | // Stop the introduced shadowing and count the number of required unlinks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2599 | // After shadowing stops, the original labels are unshadowed and the |
| 2600 | // LabelShadows represent the formerly shadowing labels. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2601 | bool has_unlinks = false; |
| 2602 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2603 | shadows[i]->StopShadowing(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2604 | has_unlinks = has_unlinks || shadows[i]->is_linked(); |
| 2605 | } |
| 2606 | function_return_is_shadowed_ = function_return_was_shadowed; |
| 2607 | |
| 2608 | // Get an external reference to the handler address. |
| 2609 | ExternalReference handler_address(Top::k_handler_address); |
| 2610 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2611 | // If we can fall off the end of the try block, unlink from try chain. |
| 2612 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2613 | // The next handler address is on top of the frame. Unlink from |
| 2614 | // the handler list and drop the rest of this handler from the |
| 2615 | // frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2616 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2617 | frame_->EmitPop(r1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2618 | __ mov(r3, Operand(handler_address)); |
| 2619 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2620 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2621 | if (has_unlinks) { |
| 2622 | exit.Jump(); |
| 2623 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2626 | // Generate unlink code for the (formerly) shadowing labels that have been |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2627 | // jumped to. Deallocate each shadow target. |
| 2628 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | if (shadows[i]->is_linked()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2630 | // Unlink from try chain; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2631 | shadows[i]->Bind(); |
| 2632 | // Because we can be jumping here (to spilled code) from unspilled |
| 2633 | // code, we need to reestablish a spilled frame at this block. |
| 2634 | frame_->SpillAll(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2636 | // Reload sp from the top handler, because some statements that we |
| 2637 | // break from (eg, for...in) may have left stuff on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2638 | __ mov(r3, Operand(handler_address)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2639 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2640 | frame_->Forget(frame_->height() - handler_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2641 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2642 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2643 | frame_->EmitPop(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2644 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2645 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2646 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2647 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
| 2648 | frame_->PrepareForReturn(); |
| 2649 | } |
| 2650 | shadows[i]->other_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2654 | exit.Bind(); |
| 2655 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2659 | void CodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2660 | #ifdef DEBUG |
| 2661 | int original_height = frame_->height(); |
| 2662 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2663 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2664 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2665 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2666 | |
| 2667 | // State: Used to keep track of reason for entering the finally |
| 2668 | // block. Should probably be extended to hold information for |
| 2669 | // break/continue from within the try block. |
| 2670 | enum { FALLING, THROWING, JUMPING }; |
| 2671 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2672 | JumpTarget try_block; |
| 2673 | JumpTarget finally_block; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2674 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2675 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2676 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2677 | frame_->EmitPush(r0); // save exception object on the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2678 | // In case of thrown exceptions, this is where we continue. |
| 2679 | __ mov(r2, Operand(Smi::FromInt(THROWING))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2680 | finally_block.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2681 | |
| 2682 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2683 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2684 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2685 | frame_->PushTryHandler(TRY_FINALLY_HANDLER); |
| 2686 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2687 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2688 | // Shadow the labels for all escapes from the try block, including |
| 2689 | // returns. Shadowing hides the original label as the LabelShadow and |
| 2690 | // operations on the original actually affect the shadowing label. |
| 2691 | // |
| 2692 | // We should probably try to unify the escaping labels and the return |
| 2693 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2694 | int nof_escapes = node->escaping_targets()->length(); |
| 2695 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2696 | |
| 2697 | // Add the shadow target for the function return. |
| 2698 | static const int kReturnShadowIndex = 0; |
| 2699 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2700 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2701 | function_return_is_shadowed_ = true; |
| 2702 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2703 | |
| 2704 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2705 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2706 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | // Generate code for the statements in the try block. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2710 | VisitStatements(node->try_block()->statements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2711 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2712 | // Stop the introduced shadowing and count the number of required unlinks. |
| 2713 | // After shadowing stops, the original labels are unshadowed and the |
| 2714 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2715 | int nof_unlinks = 0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2716 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2717 | shadows[i]->StopShadowing(); |
| 2718 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 2719 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2720 | function_return_is_shadowed_ = function_return_was_shadowed; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2721 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2722 | // Get an external reference to the handler address. |
| 2723 | ExternalReference handler_address(Top::k_handler_address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2725 | // If we can fall off the end of the try block, unlink from the try |
| 2726 | // chain and set the state on the frame to FALLING. |
| 2727 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2728 | // The next handler address is on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2729 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2730 | frame_->EmitPop(r1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2731 | __ mov(r3, Operand(handler_address)); |
| 2732 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2733 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2734 | |
| 2735 | // Fake a top of stack value (unneeded when FALLING) and set the |
| 2736 | // state in r2, then jump around the unlink blocks if any. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2737 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2738 | frame_->EmitPush(r0); |
| 2739 | __ mov(r2, Operand(Smi::FromInt(FALLING))); |
| 2740 | if (nof_unlinks > 0) { |
| 2741 | finally_block.Jump(); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | // Generate code to unlink and set the state for the (formerly) |
| 2746 | // shadowing targets that have been jumped to. |
| 2747 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2748 | if (shadows[i]->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2749 | // If we have come from the shadowed return, the return value is |
| 2750 | // in (a non-refcounted reference to) r0. We must preserve it |
| 2751 | // until it is pushed. |
| 2752 | // |
| 2753 | // Because we can be jumping here (to spilled code) from |
| 2754 | // unspilled code, we need to reestablish a spilled frame at |
| 2755 | // this block. |
| 2756 | shadows[i]->Bind(); |
| 2757 | frame_->SpillAll(); |
| 2758 | |
| 2759 | // Reload sp from the top handler, because some statements that |
| 2760 | // we break from (eg, for...in) may have left stuff on the |
| 2761 | // stack. |
| 2762 | __ mov(r3, Operand(handler_address)); |
| 2763 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2764 | frame_->Forget(frame_->height() - handler_height); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2765 | |
| 2766 | // Unlink this handler and drop it from the frame. The next |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2767 | // handler address is currently on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2768 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2769 | frame_->EmitPop(r1); |
| 2770 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2771 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2772 | |
| 2773 | if (i == kReturnShadowIndex) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2774 | // If this label shadowed the function return, materialize the |
| 2775 | // return value on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2776 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2777 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2778 | // Fake TOS for targets that shadowed breaks and continues. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2779 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2780 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2781 | } |
| 2782 | __ mov(r2, Operand(Smi::FromInt(JUMPING + i))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2783 | if (--nof_unlinks > 0) { |
| 2784 | // If this is not the last unlink block, jump around the next. |
| 2785 | finally_block.Jump(); |
| 2786 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2787 | } |
| 2788 | } |
| 2789 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2790 | // --- Finally block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2791 | finally_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2792 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2793 | // Push the state on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2794 | frame_->EmitPush(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2795 | |
| 2796 | // We keep two elements on the stack - the (possibly faked) result |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2797 | // and the state - while evaluating the finally block. |
| 2798 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2799 | // Generate code for the statements in the finally block. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2800 | VisitStatements(node->finally_block()->statements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2801 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2802 | if (has_valid_frame()) { |
| 2803 | // Restore state and return value or faked TOS. |
| 2804 | frame_->EmitPop(r2); |
| 2805 | frame_->EmitPop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2808 | // Generate code to jump to the right destination for all used |
| 2809 | // formerly shadowing targets. Deallocate each shadow target. |
| 2810 | for (int i = 0; i < shadows.length(); i++) { |
| 2811 | if (has_valid_frame() && shadows[i]->is_bound()) { |
| 2812 | JumpTarget* original = shadows[i]->other_target(); |
| 2813 | __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); |
| 2814 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2815 | JumpTarget skip; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2816 | skip.Branch(ne); |
| 2817 | frame_->PrepareForReturn(); |
| 2818 | original->Jump(); |
| 2819 | skip.Bind(); |
| 2820 | } else { |
| 2821 | original->Branch(eq); |
| 2822 | } |
| 2823 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2824 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2825 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2826 | if (has_valid_frame()) { |
| 2827 | // Check if we need to rethrow the exception. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2828 | JumpTarget exit; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2829 | __ cmp(r2, Operand(Smi::FromInt(THROWING))); |
| 2830 | exit.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2831 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2832 | // Rethrow exception. |
| 2833 | frame_->EmitPush(r0); |
| 2834 | frame_->CallRuntime(Runtime::kReThrow, 1); |
| 2835 | |
| 2836 | // Done. |
| 2837 | exit.Bind(); |
| 2838 | } |
| 2839 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2843 | void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2844 | #ifdef DEBUG |
| 2845 | int original_height = frame_->height(); |
| 2846 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | Comment cmnt(masm_, "[ DebuggerStatament"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2848 | CodeForStatementPosition(node); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2849 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2850 | frame_->DebugBreak(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2851 | #endif |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2852 | // Ignore the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2853 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2857 | void CodeGenerator::InstantiateFunction( |
| 2858 | Handle<SharedFunctionInfo> function_info) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2859 | // Use the fast case closure allocation code that allocates in new |
| 2860 | // space for nested functions that don't need literals cloning. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2861 | if (scope()->is_function_scope() && function_info->num_literals() == 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2862 | FastNewClosureStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2863 | frame_->EmitPush(Operand(function_info)); |
| 2864 | frame_->SpillAll(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2865 | frame_->CallStub(&stub, 1); |
| 2866 | frame_->EmitPush(r0); |
| 2867 | } else { |
| 2868 | // Create a new closure. |
| 2869 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2870 | frame_->EmitPush(Operand(function_info)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2871 | frame_->CallRuntime(Runtime::kNewClosure, 2); |
| 2872 | frame_->EmitPush(r0); |
| 2873 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2877 | void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2878 | #ifdef DEBUG |
| 2879 | int original_height = frame_->height(); |
| 2880 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2881 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 2882 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2883 | // Build the function info and instantiate it. |
| 2884 | Handle<SharedFunctionInfo> function_info = |
| 2885 | Compiler::BuildFunctionInfo(node, script(), this); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2886 | // Check for stack-overflow exception. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2887 | if (HasStackOverflow()) { |
| 2888 | ASSERT(frame_->height() == original_height); |
| 2889 | return; |
| 2890 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2891 | InstantiateFunction(function_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2892 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2896 | void CodeGenerator::VisitSharedFunctionInfoLiteral( |
| 2897 | SharedFunctionInfoLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2898 | #ifdef DEBUG |
| 2899 | int original_height = frame_->height(); |
| 2900 | #endif |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2901 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
| 2902 | InstantiateFunction(node->shared_function_info()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2903 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2907 | void CodeGenerator::VisitConditional(Conditional* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2908 | #ifdef DEBUG |
| 2909 | int original_height = frame_->height(); |
| 2910 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2911 | Comment cmnt(masm_, "[ Conditional"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2912 | JumpTarget then; |
| 2913 | JumpTarget else_; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2914 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2915 | if (has_valid_frame()) { |
| 2916 | Branch(false, &else_); |
| 2917 | } |
| 2918 | if (has_valid_frame() || then.is_linked()) { |
| 2919 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2920 | Load(node->then_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2921 | } |
| 2922 | if (else_.is_linked()) { |
| 2923 | JumpTarget exit; |
| 2924 | if (has_valid_frame()) exit.Jump(); |
| 2925 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2926 | Load(node->else_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2927 | if (exit.is_linked()) exit.Bind(); |
| 2928 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2929 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2933 | void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) { |
| 2934 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2935 | ASSERT(slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2936 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2937 | // JumpTargets do not yet support merging frames so the frame must be |
| 2938 | // spilled when jumping to these targets. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2939 | JumpTarget slow; |
| 2940 | JumpTarget done; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2941 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2942 | // Generate fast case for loading from slots that correspond to |
| 2943 | // local/global variables or arguments unless they are shadowed by |
| 2944 | // eval-introduced bindings. |
| 2945 | EmitDynamicLoadFromSlotFastCase(slot, |
| 2946 | typeof_state, |
| 2947 | &slow, |
| 2948 | &done); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2949 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2950 | slow.Bind(); |
| 2951 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2952 | frame_->EmitPush(Operand(slot->var()->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2953 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2954 | if (typeof_state == INSIDE_TYPEOF) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2955 | frame_->CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2956 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2957 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2958 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2959 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2960 | done.Bind(); |
| 2961 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | |
| 2963 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2964 | Register scratch = VirtualFrame::scratch0(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2965 | TypeInfo info = type_info(slot); |
| 2966 | frame_->EmitPush(SlotOperand(slot, scratch), info); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2967 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2968 | if (slot->var()->mode() == Variable::CONST) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2969 | // Const slots may contain 'the hole' value (the constant hasn't been |
| 2970 | // initialized yet) which needs to be converted into the 'undefined' |
| 2971 | // value. |
| 2972 | Comment cmnt(masm_, "[ Unhole const"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2973 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2974 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2975 | __ cmp(tos, ip); |
| 2976 | __ LoadRoot(tos, Heap::kUndefinedValueRootIndex, eq); |
| 2977 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2983 | void CodeGenerator::LoadFromSlotCheckForArguments(Slot* slot, |
| 2984 | TypeofState state) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2985 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2986 | LoadFromSlot(slot, state); |
| 2987 | |
| 2988 | // Bail out quickly if we're not using lazy arguments allocation. |
| 2989 | if (ArgumentsMode() != LAZY_ARGUMENTS_ALLOCATION) return; |
| 2990 | |
| 2991 | // ... or if the slot isn't a non-parameter arguments slot. |
| 2992 | if (slot->type() == Slot::PARAMETER || !slot->is_arguments()) return; |
| 2993 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2994 | // Load the loaded value from the stack into a register but leave it on the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2995 | // stack. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2996 | Register tos = frame_->Peek(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2997 | |
| 2998 | // If the loaded value is the sentinel that indicates that we |
| 2999 | // haven't loaded the arguments object yet, we need to do it now. |
| 3000 | JumpTarget exit; |
| 3001 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3002 | __ cmp(tos, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3003 | exit.Branch(ne); |
| 3004 | frame_->Drop(); |
| 3005 | StoreArgumentsObject(false); |
| 3006 | exit.Bind(); |
| 3007 | } |
| 3008 | |
| 3009 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3010 | void CodeGenerator::StoreToSlot(Slot* slot, InitState init_state) { |
| 3011 | ASSERT(slot != NULL); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3012 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3013 | if (slot->type() == Slot::LOOKUP) { |
| 3014 | ASSERT(slot->var()->is_dynamic()); |
| 3015 | |
| 3016 | // For now, just do a runtime call. |
| 3017 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3018 | frame_->EmitPush(Operand(slot->var()->name())); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3019 | |
| 3020 | if (init_state == CONST_INIT) { |
| 3021 | // Same as the case for a normal store, but ignores attribute |
| 3022 | // (e.g. READ_ONLY) of context slot so that we can initialize |
| 3023 | // const properties (introduced via eval("const foo = (some |
| 3024 | // expr);")). Also, uses the current function context instead of |
| 3025 | // the top context. |
| 3026 | // |
| 3027 | // Note that we must declare the foo upon entry of eval(), via a |
| 3028 | // context slot declaration, but we cannot initialize it at the |
| 3029 | // same time, because the const declaration may be at the end of |
| 3030 | // the eval code (sigh...) and the const variable may have been |
| 3031 | // used before (where its value is 'undefined'). Thus, we can only |
| 3032 | // do the initialization when we actually encounter the expression |
| 3033 | // and when the expression operands are defined and valid, and |
| 3034 | // thus we need the split into 2 operations: declaration of the |
| 3035 | // context slot followed by initialization. |
| 3036 | frame_->CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 3037 | } else { |
| 3038 | frame_->CallRuntime(Runtime::kStoreContextSlot, 3); |
| 3039 | } |
| 3040 | // Storing a variable must keep the (new) value on the expression |
| 3041 | // stack. This is necessary for compiling assignment expressions. |
| 3042 | frame_->EmitPush(r0); |
| 3043 | |
| 3044 | } else { |
| 3045 | ASSERT(!slot->var()->is_dynamic()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3046 | Register scratch = VirtualFrame::scratch0(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3047 | Register scratch2 = VirtualFrame::scratch1(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3048 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3049 | // The frame must be spilled when branching to this target. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3050 | JumpTarget exit; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3051 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3052 | if (init_state == CONST_INIT) { |
| 3053 | ASSERT(slot->var()->mode() == Variable::CONST); |
| 3054 | // Only the first const initialization must be executed (the slot |
| 3055 | // still contains 'the hole' value). When the assignment is |
| 3056 | // executed, the code is identical to a normal store (see below). |
| 3057 | Comment cmnt(masm_, "[ Init const"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3058 | __ ldr(scratch, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3059 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3060 | __ cmp(scratch, ip); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3061 | exit.Branch(ne); |
| 3062 | } |
| 3063 | |
| 3064 | // We must execute the store. Storing a variable must keep the |
| 3065 | // (new) value on the stack. This is necessary for compiling |
| 3066 | // assignment expressions. |
| 3067 | // |
| 3068 | // Note: We will reach here even with slot->var()->mode() == |
| 3069 | // Variable::CONST because of const declarations which will |
| 3070 | // initialize consts to 'the hole' value and by doing so, end up |
| 3071 | // calling this code. r2 may be loaded with context; used below in |
| 3072 | // RecordWrite. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3073 | Register tos = frame_->Peek(); |
| 3074 | __ str(tos, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3075 | if (slot->type() == Slot::CONTEXT) { |
| 3076 | // Skip write barrier if the written value is a smi. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3077 | __ tst(tos, Operand(kSmiTagMask)); |
| 3078 | // We don't use tos any more after here. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3079 | exit.Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3080 | // scratch is loaded with context when calling SlotOperand above. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3081 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3082 | // We need an extra register. Until we have a way to do that in the |
| 3083 | // virtual frame we will cheat and ask for a free TOS register. |
| 3084 | Register scratch3 = frame_->GetTOSRegister(); |
| 3085 | __ RecordWrite(scratch, Operand(offset), scratch2, scratch3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3086 | } |
| 3087 | // If we definitely did not jump over the assignment, we do not need |
| 3088 | // to bind the exit label. Doing so can defeat peephole |
| 3089 | // optimization. |
| 3090 | if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) { |
| 3091 | exit.Bind(); |
| 3092 | } |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3097 | void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 3098 | TypeofState typeof_state, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3099 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3100 | // Check that no extension objects have been created by calls to |
| 3101 | // eval from the current scope to the global scope. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3102 | Register tmp = frame_->scratch0(); |
| 3103 | Register tmp2 = frame_->scratch1(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3104 | Register context = cp; |
| 3105 | Scope* s = scope(); |
| 3106 | while (s != NULL) { |
| 3107 | if (s->num_heap_slots() > 0) { |
| 3108 | if (s->calls_eval()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3109 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3110 | // Check that extension is NULL. |
| 3111 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 3112 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3113 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3114 | } |
| 3115 | // Load next context in chain. |
| 3116 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 3117 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3118 | context = tmp; |
| 3119 | } |
| 3120 | // If no outer scope calls eval, we do not need to check more |
| 3121 | // context extensions. |
| 3122 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 3123 | s = s->outer_scope(); |
| 3124 | } |
| 3125 | |
| 3126 | if (s->is_eval_scope()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3127 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3128 | Label next, fast; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3129 | __ Move(tmp, context); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3130 | __ bind(&next); |
| 3131 | // Terminate at global context. |
| 3132 | __ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3133 | __ LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 3134 | __ cmp(tmp2, ip); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3135 | __ b(eq, &fast); |
| 3136 | // Check that extension is NULL. |
| 3137 | __ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX)); |
| 3138 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3139 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3140 | // Load next context in chain. |
| 3141 | __ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 3142 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3143 | __ b(&next); |
| 3144 | __ bind(&fast); |
| 3145 | } |
| 3146 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3147 | // Load the global object. |
| 3148 | LoadGlobal(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3149 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3150 | frame_->CallLoadIC(slot->var()->name(), |
| 3151 | typeof_state == INSIDE_TYPEOF |
| 3152 | ? RelocInfo::CODE_TARGET |
| 3153 | : RelocInfo::CODE_TARGET_CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3157 | void CodeGenerator::EmitDynamicLoadFromSlotFastCase(Slot* slot, |
| 3158 | TypeofState typeof_state, |
| 3159 | JumpTarget* slow, |
| 3160 | JumpTarget* done) { |
| 3161 | // Generate fast-case code for variables that might be shadowed by |
| 3162 | // eval-introduced variables. Eval is used a lot without |
| 3163 | // introducing variables. In those cases, we do not want to |
| 3164 | // perform a runtime call for all variables in the scope |
| 3165 | // containing the eval. |
| 3166 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3167 | LoadFromGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 3168 | frame_->SpillAll(); |
| 3169 | done->Jump(); |
| 3170 | |
| 3171 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
| 3172 | frame_->SpillAll(); |
| 3173 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); |
| 3174 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 3175 | if (potential_slot != NULL) { |
| 3176 | // Generate fast case for locals that rewrite to slots. |
| 3177 | __ ldr(r0, |
| 3178 | ContextSlotOperandCheckExtensions(potential_slot, |
| 3179 | r1, |
| 3180 | r2, |
| 3181 | slow)); |
| 3182 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 3183 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3184 | __ cmp(r0, ip); |
| 3185 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 3186 | } |
| 3187 | done->Jump(); |
| 3188 | } else if (rewrite != NULL) { |
| 3189 | // Generate fast case for argument loads. |
| 3190 | Property* property = rewrite->AsProperty(); |
| 3191 | if (property != NULL) { |
| 3192 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 3193 | Literal* key_literal = property->key()->AsLiteral(); |
| 3194 | if (obj_proxy != NULL && |
| 3195 | key_literal != NULL && |
| 3196 | obj_proxy->IsArguments() && |
| 3197 | key_literal->handle()->IsSmi()) { |
| 3198 | // Load arguments object if there are no eval-introduced |
| 3199 | // variables. Then load the argument from the arguments |
| 3200 | // object using keyed load. |
| 3201 | __ ldr(r0, |
| 3202 | ContextSlotOperandCheckExtensions(obj_proxy->var()->slot(), |
| 3203 | r1, |
| 3204 | r2, |
| 3205 | slow)); |
| 3206 | frame_->EmitPush(r0); |
| 3207 | __ mov(r1, Operand(key_literal->handle())); |
| 3208 | frame_->EmitPush(r1); |
| 3209 | EmitKeyedLoad(); |
| 3210 | done->Jump(); |
| 3211 | } |
| 3212 | } |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3218 | void CodeGenerator::VisitSlot(Slot* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3219 | #ifdef DEBUG |
| 3220 | int original_height = frame_->height(); |
| 3221 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3222 | Comment cmnt(masm_, "[ Slot"); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3223 | LoadFromSlotCheckForArguments(node, NOT_INSIDE_TYPEOF); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3224 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3225 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3226 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3227 | |
| 3228 | void CodeGenerator::VisitVariableProxy(VariableProxy* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3229 | #ifdef DEBUG |
| 3230 | int original_height = frame_->height(); |
| 3231 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3232 | Comment cmnt(masm_, "[ VariableProxy"); |
| 3233 | |
| 3234 | Variable* var = node->var(); |
| 3235 | Expression* expr = var->rewrite(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3236 | if (expr != NULL) { |
| 3237 | Visit(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3238 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3239 | ASSERT(var->is_global()); |
| 3240 | Reference ref(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3241 | ref.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3242 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3243 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3247 | void CodeGenerator::VisitLiteral(Literal* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3248 | #ifdef DEBUG |
| 3249 | int original_height = frame_->height(); |
| 3250 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3251 | Comment cmnt(masm_, "[ Literal"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3252 | Register reg = frame_->GetTOSRegister(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3253 | bool is_smi = node->handle()->IsSmi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3254 | __ mov(reg, Operand(node->handle())); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3255 | frame_->EmitPush(reg, is_smi ? TypeInfo::Smi() : TypeInfo::Unknown()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3256 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3260 | void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3261 | #ifdef DEBUG |
| 3262 | int original_height = frame_->height(); |
| 3263 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3264 | Comment cmnt(masm_, "[ RexExp Literal"); |
| 3265 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3266 | Register tmp = VirtualFrame::scratch0(); |
| 3267 | // Free up a TOS register that can be used to push the literal. |
| 3268 | Register literal = frame_->GetTOSRegister(); |
| 3269 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3270 | // Retrieve the literal array and check the allocated entry. |
| 3271 | |
| 3272 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3273 | __ ldr(tmp, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3274 | |
| 3275 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3276 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kLiteralsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3277 | |
| 3278 | // Load the literal at the ast saved index. |
| 3279 | int literal_offset = |
| 3280 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3281 | __ ldr(literal, FieldMemOperand(tmp, literal_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3282 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3283 | JumpTarget done; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3284 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3285 | __ cmp(literal, ip); |
| 3286 | // This branch locks the virtual frame at the done label to match the |
| 3287 | // one we have here, where the literal register is not on the stack and |
| 3288 | // nothing is spilled. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3289 | done.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3290 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3291 | // If the entry is undefined we call the runtime system to compute |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3292 | // the literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3293 | // literal array (0) |
| 3294 | frame_->EmitPush(tmp); |
| 3295 | // literal index (1) |
| 3296 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3297 | // RegExp pattern (2) |
| 3298 | frame_->EmitPush(Operand(node->pattern())); |
| 3299 | // RegExp flags (3) |
| 3300 | frame_->EmitPush(Operand(node->flags())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3301 | frame_->CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3302 | __ Move(literal, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3303 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3304 | // This call to bind will get us back to the virtual frame we had before |
| 3305 | // where things are not spilled and the literal register is not on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3306 | done.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3307 | // Push the literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3308 | frame_->EmitPush(literal); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3309 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3313 | void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3314 | #ifdef DEBUG |
| 3315 | int original_height = frame_->height(); |
| 3316 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3317 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 3318 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3319 | Register literal = frame_->GetTOSRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3320 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3321 | __ ldr(literal, frame_->Function()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3322 | // Literal array. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3323 | __ ldr(literal, FieldMemOperand(literal, JSFunction::kLiteralsOffset)); |
| 3324 | frame_->EmitPush(literal); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3325 | // Literal index. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3326 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3327 | // Constant properties. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3328 | frame_->EmitPush(Operand(node->constant_properties())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3329 | // Should the object literal have fast elements? |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3330 | frame_->EmitPush(Operand(Smi::FromInt(node->fast_elements() ? 1 : 0))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3331 | if (node->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3332 | frame_->CallRuntime(Runtime::kCreateObjectLiteral, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3333 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3334 | frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3335 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3336 | frame_->EmitPush(r0); // save the result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3337 | for (int i = 0; i < node->properties()->length(); i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3338 | // At the start of each iteration, the top of stack contains |
| 3339 | // the newly created object literal. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3340 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 3341 | Literal* key = property->key(); |
| 3342 | Expression* value = property->value(); |
| 3343 | switch (property->kind()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3344 | case ObjectLiteral::Property::CONSTANT: |
| 3345 | break; |
| 3346 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 3347 | if (CompileTimeValue::IsCompileTimeValue(property->value())) break; |
| 3348 | // else fall through |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3349 | case ObjectLiteral::Property::COMPUTED: |
| 3350 | if (key->handle()->IsSymbol()) { |
| 3351 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3352 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3353 | frame_->PopToR0(); |
| 3354 | // Fetch the object literal. |
| 3355 | frame_->SpillAllButCopyTOSToR1(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3356 | __ mov(r2, Operand(key->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3357 | frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); |
| 3358 | break; |
| 3359 | } |
| 3360 | // else fall through |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3361 | case ObjectLiteral::Property::PROTOTYPE: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3362 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3363 | Load(key); |
| 3364 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3365 | frame_->CallRuntime(Runtime::kSetProperty, 3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3366 | break; |
| 3367 | } |
| 3368 | case ObjectLiteral::Property::SETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3369 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3370 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3371 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3372 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3373 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3374 | break; |
| 3375 | } |
| 3376 | case ObjectLiteral::Property::GETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3377 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3378 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3379 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3380 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3381 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3382 | break; |
| 3383 | } |
| 3384 | } |
| 3385 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3386 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3390 | void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3391 | #ifdef DEBUG |
| 3392 | int original_height = frame_->height(); |
| 3393 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | Comment cmnt(masm_, "[ ArrayLiteral"); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3395 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3396 | Register tos = frame_->GetTOSRegister(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3397 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3398 | __ ldr(tos, frame_->Function()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3399 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3400 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kLiteralsOffset)); |
| 3401 | frame_->EmitPush(tos); |
| 3402 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3403 | frame_->EmitPush(Operand(node->constant_elements())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3404 | int length = node->values()->length(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3405 | if (node->depth() > 1) { |
| 3406 | frame_->CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3407 | } else if (length > FastCloneShallowArrayStub::kMaximumLength) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3408 | frame_->CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3409 | } else { |
| 3410 | FastCloneShallowArrayStub stub(length); |
| 3411 | frame_->CallStub(&stub, 3); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3412 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3413 | frame_->EmitPush(r0); // save the result |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3414 | // r0: created object literal |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3415 | |
| 3416 | // Generate code to set the elements in the array that are not |
| 3417 | // literals. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3418 | for (int i = 0; i < node->values()->length(); i++) { |
| 3419 | Expression* value = node->values()->at(i); |
| 3420 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3421 | // If value is a literal the property value is already set in the |
| 3422 | // boilerplate object. |
| 3423 | if (value->AsLiteral() != NULL) continue; |
| 3424 | // If value is a materialized literal the property value is already set |
| 3425 | // in the boilerplate object if it is simple. |
| 3426 | if (CompileTimeValue::IsCompileTimeValue(value)) continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3427 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3428 | // The property must be set by generated code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3429 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3430 | frame_->PopToR0(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3431 | // Fetch the object literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3432 | frame_->SpillAllButCopyTOSToR1(); |
| 3433 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3434 | // Get the elements array. |
| 3435 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3436 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3437 | // Write to the indexed properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3438 | int offset = i * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3439 | __ str(r0, FieldMemOperand(r1, offset)); |
| 3440 | |
| 3441 | // Update the write barrier for the array address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3442 | __ RecordWrite(r1, Operand(offset), r3, r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3443 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3444 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3448 | void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3449 | #ifdef DEBUG |
| 3450 | int original_height = frame_->height(); |
| 3451 | #endif |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3452 | // Call runtime routine to allocate the catch extension object and |
| 3453 | // assign the exception value to the catch variable. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3454 | Comment cmnt(masm_, "[ CatchExtensionObject"); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3455 | Load(node->key()); |
| 3456 | Load(node->value()); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 3457 | frame_->CallRuntime(Runtime::kCreateCatchExtensionObject, 2); |
| 3458 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3459 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3460 | } |
| 3461 | |
| 3462 | |
| 3463 | void CodeGenerator::EmitSlotAssignment(Assignment* node) { |
| 3464 | #ifdef DEBUG |
| 3465 | int original_height = frame_->height(); |
| 3466 | #endif |
| 3467 | Comment cmnt(masm(), "[ Variable Assignment"); |
| 3468 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3469 | ASSERT(var != NULL); |
| 3470 | Slot* slot = var->slot(); |
| 3471 | ASSERT(slot != NULL); |
| 3472 | |
| 3473 | // Evaluate the right-hand side. |
| 3474 | if (node->is_compound()) { |
| 3475 | // For a compound assignment the right-hand side is a binary operation |
| 3476 | // between the current property value and the actual right-hand side. |
| 3477 | LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
| 3478 | |
| 3479 | // Perform the binary operation. |
| 3480 | Literal* literal = node->value()->AsLiteral(); |
| 3481 | bool overwrite_value = |
| 3482 | (node->value()->AsBinaryOperation() != NULL && |
| 3483 | node->value()->AsBinaryOperation()->ResultOverwriteAllowed()); |
| 3484 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3485 | SmiOperation(node->binary_op(), |
| 3486 | literal->handle(), |
| 3487 | false, |
| 3488 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3489 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3490 | GenerateInlineSmi inline_smi = |
| 3491 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3492 | if (literal != NULL) { |
| 3493 | ASSERT(!literal->handle()->IsSmi()); |
| 3494 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3495 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3496 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3497 | GenericBinaryOperation(node->binary_op(), |
| 3498 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3499 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3500 | } |
| 3501 | } else { |
| 3502 | Load(node->value()); |
| 3503 | } |
| 3504 | |
| 3505 | // Perform the assignment. |
| 3506 | if (var->mode() != Variable::CONST || node->op() == Token::INIT_CONST) { |
| 3507 | CodeForSourcePosition(node->position()); |
| 3508 | StoreToSlot(slot, |
| 3509 | node->op() == Token::INIT_CONST ? CONST_INIT : NOT_CONST_INIT); |
| 3510 | } |
| 3511 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3512 | } |
| 3513 | |
| 3514 | |
| 3515 | void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) { |
| 3516 | #ifdef DEBUG |
| 3517 | int original_height = frame_->height(); |
| 3518 | #endif |
| 3519 | Comment cmnt(masm(), "[ Named Property Assignment"); |
| 3520 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3521 | Property* prop = node->target()->AsProperty(); |
| 3522 | ASSERT(var == NULL || (prop == NULL && var->is_global())); |
| 3523 | |
| 3524 | // Initialize name and evaluate the receiver sub-expression if necessary. If |
| 3525 | // the receiver is trivial it is not placed on the stack at this point, but |
| 3526 | // loaded whenever actually needed. |
| 3527 | Handle<String> name; |
| 3528 | bool is_trivial_receiver = false; |
| 3529 | if (var != NULL) { |
| 3530 | name = var->name(); |
| 3531 | } else { |
| 3532 | Literal* lit = prop->key()->AsLiteral(); |
| 3533 | ASSERT_NOT_NULL(lit); |
| 3534 | name = Handle<String>::cast(lit->handle()); |
| 3535 | // Do not materialize the receiver on the frame if it is trivial. |
| 3536 | is_trivial_receiver = prop->obj()->IsTrivial(); |
| 3537 | if (!is_trivial_receiver) Load(prop->obj()); |
| 3538 | } |
| 3539 | |
| 3540 | // Change to slow case in the beginning of an initialization block to |
| 3541 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3542 | if (node->starts_initialization_block()) { |
| 3543 | // Initialization block consists of assignments of the form expr.x = ..., so |
| 3544 | // this will never be an assignment to a variable, so there must be a |
| 3545 | // receiver object. |
| 3546 | ASSERT_EQ(NULL, var); |
| 3547 | if (is_trivial_receiver) { |
| 3548 | Load(prop->obj()); |
| 3549 | } else { |
| 3550 | frame_->Dup(); |
| 3551 | } |
| 3552 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3553 | } |
| 3554 | |
| 3555 | // Change to fast case at the end of an initialization block. To prepare for |
| 3556 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3557 | // converted back to fast case after the assignment. |
| 3558 | if (node->ends_initialization_block() && !is_trivial_receiver) { |
| 3559 | frame_->Dup(); |
| 3560 | } |
| 3561 | |
| 3562 | // Stack layout: |
| 3563 | // [tos] : receiver (only materialized if non-trivial) |
| 3564 | // [tos+1] : receiver if at the end of an initialization block |
| 3565 | |
| 3566 | // Evaluate the right-hand side. |
| 3567 | if (node->is_compound()) { |
| 3568 | // For a compound assignment the right-hand side is a binary operation |
| 3569 | // between the current property value and the actual right-hand side. |
| 3570 | if (is_trivial_receiver) { |
| 3571 | Load(prop->obj()); |
| 3572 | } else if (var != NULL) { |
| 3573 | LoadGlobal(); |
| 3574 | } else { |
| 3575 | frame_->Dup(); |
| 3576 | } |
| 3577 | EmitNamedLoad(name, var != NULL); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3578 | |
| 3579 | // Perform the binary operation. |
| 3580 | Literal* literal = node->value()->AsLiteral(); |
| 3581 | bool overwrite_value = |
| 3582 | (node->value()->AsBinaryOperation() != NULL && |
| 3583 | node->value()->AsBinaryOperation()->ResultOverwriteAllowed()); |
| 3584 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3585 | SmiOperation(node->binary_op(), |
| 3586 | literal->handle(), |
| 3587 | false, |
| 3588 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3589 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3590 | GenerateInlineSmi inline_smi = |
| 3591 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3592 | if (literal != NULL) { |
| 3593 | ASSERT(!literal->handle()->IsSmi()); |
| 3594 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3595 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3596 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3597 | GenericBinaryOperation(node->binary_op(), |
| 3598 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3599 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3600 | } |
| 3601 | } else { |
| 3602 | // For non-compound assignment just load the right-hand side. |
| 3603 | Load(node->value()); |
| 3604 | } |
| 3605 | |
| 3606 | // Stack layout: |
| 3607 | // [tos] : value |
| 3608 | // [tos+1] : receiver (only materialized if non-trivial) |
| 3609 | // [tos+2] : receiver if at the end of an initialization block |
| 3610 | |
| 3611 | // Perform the assignment. It is safe to ignore constants here. |
| 3612 | ASSERT(var == NULL || var->mode() != Variable::CONST); |
| 3613 | ASSERT_NE(Token::INIT_CONST, node->op()); |
| 3614 | if (is_trivial_receiver) { |
| 3615 | // Load the receiver and swap with the value. |
| 3616 | Load(prop->obj()); |
| 3617 | Register t0 = frame_->PopToRegister(); |
| 3618 | Register t1 = frame_->PopToRegister(t0); |
| 3619 | frame_->EmitPush(t0); |
| 3620 | frame_->EmitPush(t1); |
| 3621 | } |
| 3622 | CodeForSourcePosition(node->position()); |
| 3623 | bool is_contextual = (var != NULL); |
| 3624 | EmitNamedStore(name, is_contextual); |
| 3625 | frame_->EmitPush(r0); |
| 3626 | |
| 3627 | // Change to fast case at the end of an initialization block. |
| 3628 | if (node->ends_initialization_block()) { |
| 3629 | ASSERT_EQ(NULL, var); |
| 3630 | // The argument to the runtime call is the receiver. |
| 3631 | if (is_trivial_receiver) { |
| 3632 | Load(prop->obj()); |
| 3633 | } else { |
| 3634 | // A copy of the receiver is below the value of the assignment. Swap |
| 3635 | // the receiver and the value of the assignment expression. |
| 3636 | Register t0 = frame_->PopToRegister(); |
| 3637 | Register t1 = frame_->PopToRegister(t0); |
| 3638 | frame_->EmitPush(t0); |
| 3639 | frame_->EmitPush(t1); |
| 3640 | } |
| 3641 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3642 | } |
| 3643 | |
| 3644 | // Stack layout: |
| 3645 | // [tos] : result |
| 3646 | |
| 3647 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3648 | } |
| 3649 | |
| 3650 | |
| 3651 | void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) { |
| 3652 | #ifdef DEBUG |
| 3653 | int original_height = frame_->height(); |
| 3654 | #endif |
| 3655 | Comment cmnt(masm_, "[ Keyed Property Assignment"); |
| 3656 | Property* prop = node->target()->AsProperty(); |
| 3657 | ASSERT_NOT_NULL(prop); |
| 3658 | |
| 3659 | // Evaluate the receiver subexpression. |
| 3660 | Load(prop->obj()); |
| 3661 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3662 | WriteBarrierCharacter wb_info; |
| 3663 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3664 | // Change to slow case in the beginning of an initialization block to |
| 3665 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3666 | if (node->starts_initialization_block()) { |
| 3667 | frame_->Dup(); |
| 3668 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3669 | } |
| 3670 | |
| 3671 | // Change to fast case at the end of an initialization block. To prepare for |
| 3672 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3673 | // converted back to fast case after the assignment. |
| 3674 | if (node->ends_initialization_block()) { |
| 3675 | frame_->Dup(); |
| 3676 | } |
| 3677 | |
| 3678 | // Evaluate the key subexpression. |
| 3679 | Load(prop->key()); |
| 3680 | |
| 3681 | // Stack layout: |
| 3682 | // [tos] : key |
| 3683 | // [tos+1] : receiver |
| 3684 | // [tos+2] : receiver if at the end of an initialization block |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3685 | // |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3686 | // Evaluate the right-hand side. |
| 3687 | if (node->is_compound()) { |
| 3688 | // For a compound assignment the right-hand side is a binary operation |
| 3689 | // between the current property value and the actual right-hand side. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3690 | // Duplicate receiver and key for loading the current property value. |
| 3691 | frame_->Dup2(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3692 | EmitKeyedLoad(); |
| 3693 | frame_->EmitPush(r0); |
| 3694 | |
| 3695 | // Perform the binary operation. |
| 3696 | Literal* literal = node->value()->AsLiteral(); |
| 3697 | bool overwrite_value = |
| 3698 | (node->value()->AsBinaryOperation() != NULL && |
| 3699 | node->value()->AsBinaryOperation()->ResultOverwriteAllowed()); |
| 3700 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3701 | SmiOperation(node->binary_op(), |
| 3702 | literal->handle(), |
| 3703 | false, |
| 3704 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3705 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3706 | GenerateInlineSmi inline_smi = |
| 3707 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3708 | if (literal != NULL) { |
| 3709 | ASSERT(!literal->handle()->IsSmi()); |
| 3710 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3711 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3712 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3713 | GenericBinaryOperation(node->binary_op(), |
| 3714 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3715 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3716 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3717 | wb_info = node->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3718 | } else { |
| 3719 | // For non-compound assignment just load the right-hand side. |
| 3720 | Load(node->value()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3721 | wb_info = node->value()->AsLiteral() != NULL ? |
| 3722 | NEVER_NEWSPACE : |
| 3723 | (node->value()->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | // Stack layout: |
| 3727 | // [tos] : value |
| 3728 | // [tos+1] : key |
| 3729 | // [tos+2] : receiver |
| 3730 | // [tos+3] : receiver if at the end of an initialization block |
| 3731 | |
| 3732 | // Perform the assignment. It is safe to ignore constants here. |
| 3733 | ASSERT(node->op() != Token::INIT_CONST); |
| 3734 | CodeForSourcePosition(node->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3735 | EmitKeyedStore(prop->key()->type(), wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3736 | frame_->EmitPush(r0); |
| 3737 | |
| 3738 | // Stack layout: |
| 3739 | // [tos] : result |
| 3740 | // [tos+1] : receiver if at the end of an initialization block |
| 3741 | |
| 3742 | // Change to fast case at the end of an initialization block. |
| 3743 | if (node->ends_initialization_block()) { |
| 3744 | // The argument to the runtime call is the extra copy of the receiver, |
| 3745 | // which is below the value of the assignment. Swap the receiver and |
| 3746 | // the value of the assignment expression. |
| 3747 | Register t0 = frame_->PopToRegister(); |
| 3748 | Register t1 = frame_->PopToRegister(t0); |
| 3749 | frame_->EmitPush(t1); |
| 3750 | frame_->EmitPush(t0); |
| 3751 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3752 | } |
| 3753 | |
| 3754 | // Stack layout: |
| 3755 | // [tos] : result |
| 3756 | |
| 3757 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3761 | void CodeGenerator::VisitAssignment(Assignment* node) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3762 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3763 | #ifdef DEBUG |
| 3764 | int original_height = frame_->height(); |
| 3765 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3766 | Comment cmnt(masm_, "[ Assignment"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3767 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3768 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3769 | Property* prop = node->target()->AsProperty(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3770 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3771 | if (var != NULL && !var->is_global()) { |
| 3772 | EmitSlotAssignment(node); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3773 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3774 | } else if ((prop != NULL && prop->key()->IsPropertyName()) || |
| 3775 | (var != NULL && var->is_global())) { |
| 3776 | // Properties whose keys are property names and global variables are |
| 3777 | // treated as named property references. We do not need to consider |
| 3778 | // global 'this' because it is not a valid left-hand side. |
| 3779 | EmitNamedPropertyAssignment(node); |
| 3780 | |
| 3781 | } else if (prop != NULL) { |
| 3782 | // Other properties (including rewritten parameters for a function that |
| 3783 | // uses arguments) are keyed property assignments. |
| 3784 | EmitKeyedPropertyAssignment(node); |
| 3785 | |
| 3786 | } else { |
| 3787 | // Invalid left-hand side. |
| 3788 | Load(node->target()); |
| 3789 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
| 3790 | // The runtime call doesn't actually return but the code generator will |
| 3791 | // still generate code and expects a certain frame height. |
| 3792 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3793 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3794 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3798 | void CodeGenerator::VisitThrow(Throw* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3799 | #ifdef DEBUG |
| 3800 | int original_height = frame_->height(); |
| 3801 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3802 | Comment cmnt(masm_, "[ Throw"); |
| 3803 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3804 | Load(node->exception()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3805 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3806 | frame_->CallRuntime(Runtime::kThrow, 1); |
| 3807 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3808 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3812 | void CodeGenerator::VisitProperty(Property* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3813 | #ifdef DEBUG |
| 3814 | int original_height = frame_->height(); |
| 3815 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3816 | Comment cmnt(masm_, "[ Property"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3817 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3818 | { Reference property(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3819 | property.GetValue(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3820 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3821 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3825 | void CodeGenerator::VisitCall(Call* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3826 | #ifdef DEBUG |
| 3827 | int original_height = frame_->height(); |
| 3828 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3829 | Comment cmnt(masm_, "[ Call"); |
| 3830 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3831 | Expression* function = node->expression(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3832 | ZoneList<Expression*>* args = node->arguments(); |
| 3833 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3834 | // Standard function call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3835 | // Check if the function is a variable or a property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3836 | Variable* var = function->AsVariableProxy()->AsVariable(); |
| 3837 | Property* property = function->AsProperty(); |
| 3838 | |
| 3839 | // ------------------------------------------------------------------------ |
| 3840 | // Fast-case: Use inline caching. |
| 3841 | // --- |
| 3842 | // According to ECMA-262, section 11.2.3, page 44, the function to call |
| 3843 | // must be resolved after the arguments have been evaluated. The IC code |
| 3844 | // automatically handles this by loading the arguments before the function |
| 3845 | // is resolved in cache misses (this also holds for megamorphic calls). |
| 3846 | // ------------------------------------------------------------------------ |
| 3847 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3848 | if (var != NULL && var->is_possibly_eval()) { |
| 3849 | // ---------------------------------- |
| 3850 | // JavaScript example: 'eval(arg)' // eval is not known to be shadowed |
| 3851 | // ---------------------------------- |
| 3852 | |
| 3853 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 3854 | // resolve the function we need to call and the receiver of the |
| 3855 | // call. Then we call the resolved function using the given |
| 3856 | // arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3857 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3858 | // Prepare stack for call to resolved function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3859 | Load(function); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3860 | |
| 3861 | // Allocate a frame slot for the receiver. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3862 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3863 | |
| 3864 | // Load the arguments. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3865 | int arg_count = args->length(); |
| 3866 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3867 | Load(args->at(i)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3870 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 3871 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3872 | // If we know that eval can only be shadowed by eval-introduced |
| 3873 | // variables we attempt to load the global eval function directly |
| 3874 | // in generated code. If we succeed, there is no need to perform a |
| 3875 | // context lookup in the runtime system. |
| 3876 | JumpTarget done; |
| 3877 | if (var->slot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3878 | ASSERT(var->slot()->type() == Slot::LOOKUP); |
| 3879 | JumpTarget slow; |
| 3880 | // Prepare the stack for the call to |
| 3881 | // ResolvePossiblyDirectEvalNoLookup by pushing the loaded |
| 3882 | // function, the first argument to the eval call and the |
| 3883 | // receiver. |
| 3884 | LoadFromGlobalSlotCheckExtensions(var->slot(), |
| 3885 | NOT_INSIDE_TYPEOF, |
| 3886 | &slow); |
| 3887 | frame_->EmitPush(r0); |
| 3888 | if (arg_count > 0) { |
| 3889 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3890 | frame_->EmitPush(r1); |
| 3891 | } else { |
| 3892 | frame_->EmitPush(r2); |
| 3893 | } |
| 3894 | __ ldr(r1, frame_->Receiver()); |
| 3895 | frame_->EmitPush(r1); |
| 3896 | |
| 3897 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEvalNoLookup, 3); |
| 3898 | |
| 3899 | done.Jump(); |
| 3900 | slow.Bind(); |
| 3901 | } |
| 3902 | |
| 3903 | // Prepare the stack for the call to ResolvePossiblyDirectEval by |
| 3904 | // pushing the loaded function, the first argument to the eval |
| 3905 | // call and the receiver. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3906 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); |
| 3907 | frame_->EmitPush(r1); |
| 3908 | if (arg_count > 0) { |
| 3909 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3910 | frame_->EmitPush(r1); |
| 3911 | } else { |
| 3912 | frame_->EmitPush(r2); |
| 3913 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3914 | __ ldr(r1, frame_->Receiver()); |
| 3915 | frame_->EmitPush(r1); |
| 3916 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3917 | // Resolve the call. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3918 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3919 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3920 | // If we generated fast-case code bind the jump-target where fast |
| 3921 | // and slow case merge. |
| 3922 | if (done.is_linked()) done.Bind(); |
| 3923 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3924 | // Touch up stack with the right values for the function and the receiver. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3925 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3926 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3927 | |
| 3928 | // Call the function. |
| 3929 | CodeForSourcePosition(node->position()); |
| 3930 | |
| 3931 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3932 | CallFunctionStub call_function(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3933 | frame_->CallStub(&call_function, arg_count + 1); |
| 3934 | |
| 3935 | __ ldr(cp, frame_->Context()); |
| 3936 | // Remove the function from the stack. |
| 3937 | frame_->Drop(); |
| 3938 | frame_->EmitPush(r0); |
| 3939 | |
| 3940 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3941 | // ---------------------------------- |
| 3942 | // JavaScript example: 'foo(1, 2, 3)' // foo is global |
| 3943 | // ---------------------------------- |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3944 | // Pass the global object as the receiver and let the IC stub |
| 3945 | // patch the stack to use the global proxy as 'this' in the |
| 3946 | // invoked function. |
| 3947 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3948 | |
| 3949 | // Load the arguments. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3950 | int arg_count = args->length(); |
| 3951 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3952 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3953 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3954 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3955 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3956 | // Setup the name register and call the IC initialization code. |
| 3957 | __ mov(r2, Operand(var->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3958 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 3959 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3960 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3961 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET_CONTEXT, |
| 3962 | arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3963 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3964 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3965 | |
| 3966 | } else if (var != NULL && var->slot() != NULL && |
| 3967 | var->slot()->type() == Slot::LOOKUP) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3968 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3969 | // ---------------------------------- |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3970 | // JavaScript examples: |
| 3971 | // |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3972 | // with (obj) foo(1, 2, 3) // foo may be in obj. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3973 | // |
| 3974 | // function f() {}; |
| 3975 | // function g() { |
| 3976 | // eval(...); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3977 | // f(); // f could be in extension object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3978 | // } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3979 | // ---------------------------------- |
| 3980 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3981 | // JumpTargets do not yet support merging frames so the frame must be |
| 3982 | // spilled when jumping to these targets. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3983 | JumpTarget slow, done; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3984 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3985 | // Generate fast case for loading functions from slots that |
| 3986 | // correspond to local/global variables or arguments unless they |
| 3987 | // are shadowed by eval-introduced bindings. |
| 3988 | EmitDynamicLoadFromSlotFastCase(var->slot(), |
| 3989 | NOT_INSIDE_TYPEOF, |
| 3990 | &slow, |
| 3991 | &done); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3992 | |
| 3993 | slow.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3994 | // Load the function |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3995 | frame_->EmitPush(cp); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3996 | __ mov(r0, Operand(var->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3997 | frame_->EmitPush(r0); |
| 3998 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3999 | // r0: slot value; r1: receiver |
| 4000 | |
| 4001 | // Load the receiver. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4002 | frame_->EmitPush(r0); // function |
| 4003 | frame_->EmitPush(r1); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4004 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4005 | // If fast case code has been generated, emit code to push the |
| 4006 | // function and receiver and have the slow path jump around this |
| 4007 | // code. |
| 4008 | if (done.is_linked()) { |
| 4009 | JumpTarget call; |
| 4010 | call.Jump(); |
| 4011 | done.Bind(); |
| 4012 | frame_->EmitPush(r0); // function |
| 4013 | LoadGlobalReceiver(r1); // receiver |
| 4014 | call.Bind(); |
| 4015 | } |
| 4016 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4017 | // Call the function. At this point, everything is spilled but the |
| 4018 | // function and receiver are in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4019 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4020 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4021 | |
| 4022 | } else if (property != NULL) { |
| 4023 | // Check if the key is a literal string. |
| 4024 | Literal* literal = property->key()->AsLiteral(); |
| 4025 | |
| 4026 | if (literal != NULL && literal->handle()->IsSymbol()) { |
| 4027 | // ------------------------------------------------------------------ |
| 4028 | // JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)' |
| 4029 | // ------------------------------------------------------------------ |
| 4030 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4031 | Handle<String> name = Handle<String>::cast(literal->handle()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4032 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4033 | if (ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION && |
| 4034 | name->IsEqualTo(CStrVector("apply")) && |
| 4035 | args->length() == 2 && |
| 4036 | args->at(1)->AsVariableProxy() != NULL && |
| 4037 | args->at(1)->AsVariableProxy()->IsArguments()) { |
| 4038 | // Use the optimized Function.prototype.apply that avoids |
| 4039 | // allocating lazily allocated arguments objects. |
| 4040 | CallApplyLazy(property->obj(), |
| 4041 | args->at(0), |
| 4042 | args->at(1)->AsVariableProxy(), |
| 4043 | node->position()); |
| 4044 | |
| 4045 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4046 | Load(property->obj()); // Receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4047 | // Load the arguments. |
| 4048 | int arg_count = args->length(); |
| 4049 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4050 | Load(args->at(i)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4053 | VirtualFrame::SpilledScope spilled_scope(frame_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4054 | // Set the name register and call the IC initialization code. |
| 4055 | __ mov(r2, Operand(name)); |
| 4056 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4057 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
| 4058 | CodeForSourcePosition(node->position()); |
| 4059 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4060 | __ ldr(cp, frame_->Context()); |
| 4061 | frame_->EmitPush(r0); |
| 4062 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4063 | |
| 4064 | } else { |
| 4065 | // ------------------------------------------- |
| 4066 | // JavaScript example: 'array[index](1, 2, 3)' |
| 4067 | // ------------------------------------------- |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4068 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4069 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4070 | Load(property->obj()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4071 | if (property->is_synthetic()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4072 | Load(property->key()); |
| 4073 | EmitKeyedLoad(); |
| 4074 | // Put the function below the receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4075 | // Use the global receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4076 | frame_->EmitPush(r0); // Function. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4077 | LoadGlobalReceiver(r0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4078 | // Call the function. |
| 4079 | CallWithArguments(args, RECEIVER_MIGHT_BE_VALUE, node->position()); |
| 4080 | frame_->EmitPush(r0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4081 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4082 | // Load the arguments. |
| 4083 | int arg_count = args->length(); |
| 4084 | for (int i = 0; i < arg_count; i++) { |
| 4085 | Load(args->at(i)); |
| 4086 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4087 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4088 | // Set the name register and call the IC initialization code. |
| 4089 | Load(property->key()); |
| 4090 | frame_->EmitPop(r2); // Function name. |
| 4091 | |
| 4092 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4093 | Handle<Code> stub = ComputeKeyedCallInitialize(arg_count, in_loop); |
| 4094 | CodeForSourcePosition(node->position()); |
| 4095 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4096 | __ ldr(cp, frame_->Context()); |
| 4097 | frame_->EmitPush(r0); |
| 4098 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | } else { |
| 4102 | // ---------------------------------- |
| 4103 | // JavaScript example: 'foo(1, 2, 3)' // foo is not global |
| 4104 | // ---------------------------------- |
| 4105 | |
| 4106 | // Load the function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4107 | Load(function); |
| 4108 | |
| 4109 | VirtualFrame::SpilledScope spilled_scope(frame_); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4110 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4111 | // Pass the global proxy as the receiver. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4112 | LoadGlobalReceiver(r0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4113 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4114 | // Call the function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4115 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4116 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4117 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4118 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4122 | void CodeGenerator::VisitCallNew(CallNew* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4123 | #ifdef DEBUG |
| 4124 | int original_height = frame_->height(); |
| 4125 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4126 | Comment cmnt(masm_, "[ CallNew"); |
| 4127 | |
| 4128 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 4129 | // expression in new calls must be evaluated before the |
| 4130 | // arguments. This is different from ordinary calls, where the |
| 4131 | // actual function to call is resolved after the arguments have been |
| 4132 | // evaluated. |
| 4133 | |
| 4134 | // Compute function to call and use the global object as the |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4135 | // receiver. There is no need to use the global proxy here because |
| 4136 | // it will always be replaced with a newly allocated object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4137 | Load(node->expression()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4138 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4139 | |
| 4140 | // Push the arguments ("left-to-right") on the stack. |
| 4141 | ZoneList<Expression*>* args = node->arguments(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4142 | int arg_count = args->length(); |
| 4143 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4144 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4145 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4146 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4147 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4148 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4149 | // r0: the number of arguments. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4150 | __ mov(r0, Operand(arg_count)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4151 | // Load the function into r1 as per calling convention. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4152 | __ ldr(r1, frame_->ElementAt(arg_count + 1)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4153 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4154 | // Call the construct call builtin that handles allocation and |
| 4155 | // constructor invocation. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4156 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4157 | Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4158 | frame_->CallCodeObject(ic, RelocInfo::CONSTRUCT_CALL, arg_count + 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4159 | |
| 4160 | // Discard old TOS value and push r0 on the stack (same as Pop(), push(r0)). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4161 | __ str(r0, frame_->Top()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4162 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4166 | void CodeGenerator::GenerateClassOf(ZoneList<Expression*>* args) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4167 | VirtualFrame::SpilledScope spilled_scope(frame_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4168 | ASSERT(args->length() == 1); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4169 | JumpTarget leave, null, function, non_function_constructor; |
| 4170 | |
| 4171 | // Load the object into r0. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4172 | Load(args->at(0)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4173 | frame_->EmitPop(r0); |
| 4174 | |
| 4175 | // If the object is a smi, we return null. |
| 4176 | __ tst(r0, Operand(kSmiTagMask)); |
| 4177 | null.Branch(eq); |
| 4178 | |
| 4179 | // Check that the object is a JS object but take special care of JS |
| 4180 | // functions to make sure they have 'Function' as their class. |
| 4181 | __ CompareObjectType(r0, r0, r1, FIRST_JS_OBJECT_TYPE); |
| 4182 | null.Branch(lt); |
| 4183 | |
| 4184 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 4185 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 4186 | // LAST_JS_OBJECT_TYPE. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 4187 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 4188 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4189 | __ cmp(r1, Operand(JS_FUNCTION_TYPE)); |
| 4190 | function.Branch(eq); |
| 4191 | |
| 4192 | // Check if the constructor in the map is a function. |
| 4193 | __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset)); |
| 4194 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
| 4195 | non_function_constructor.Branch(ne); |
| 4196 | |
| 4197 | // The r0 register now contains the constructor function. Grab the |
| 4198 | // instance class name from there. |
| 4199 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 4200 | __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4201 | frame_->EmitPush(r0); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4202 | leave.Jump(); |
| 4203 | |
| 4204 | // Functions have class 'Function'. |
| 4205 | function.Bind(); |
| 4206 | __ mov(r0, Operand(Factory::function_class_symbol())); |
| 4207 | frame_->EmitPush(r0); |
| 4208 | leave.Jump(); |
| 4209 | |
| 4210 | // Objects with a non-function constructor have class 'Object'. |
| 4211 | non_function_constructor.Bind(); |
| 4212 | __ mov(r0, Operand(Factory::Object_symbol())); |
| 4213 | frame_->EmitPush(r0); |
| 4214 | leave.Jump(); |
| 4215 | |
| 4216 | // Non-JS objects have class null. |
| 4217 | null.Bind(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4218 | __ LoadRoot(r0, Heap::kNullValueRootIndex); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4219 | frame_->EmitPush(r0); |
| 4220 | |
| 4221 | // All done. |
| 4222 | leave.Bind(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4226 | void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4227 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4228 | ASSERT(args->length() == 1); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4229 | JumpTarget leave; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4230 | Load(args->at(0)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4231 | frame_->EmitPop(r0); // r0 contains object. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4232 | // if (object->IsSmi()) return the object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4233 | __ tst(r0, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4234 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4235 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
| 4236 | __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4237 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4238 | // Load the value. |
| 4239 | __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4240 | leave.Bind(); |
| 4241 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4245 | void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4246 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4247 | ASSERT(args->length() == 2); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4248 | JumpTarget leave; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4249 | Load(args->at(0)); // Load the object. |
| 4250 | Load(args->at(1)); // Load the value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4251 | frame_->EmitPop(r0); // r0 contains value |
| 4252 | frame_->EmitPop(r1); // r1 contains object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4253 | // if (object->IsSmi()) return object. |
| 4254 | __ tst(r1, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4255 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4256 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
| 4257 | __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4258 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4259 | // Store the value. |
| 4260 | __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); |
| 4261 | // Update the write barrier. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4262 | __ RecordWrite(r1, Operand(JSValue::kValueOffset - kHeapObjectTag), r2, r3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4263 | // Leave. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4264 | leave.Bind(); |
| 4265 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4269 | void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4270 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4271 | Load(args->at(0)); |
| 4272 | Register reg = frame_->PopToRegister(); |
| 4273 | __ tst(reg, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4274 | cc_reg_ = eq; |
| 4275 | } |
| 4276 | |
| 4277 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4278 | void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) { |
| 4279 | // See comment in CodeGenerator::GenerateLog in codegen-ia32.cc. |
| 4280 | ASSERT_EQ(args->length(), 3); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4281 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4282 | if (ShouldGenerateLog(args->at(0))) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4283 | Load(args->at(1)); |
| 4284 | Load(args->at(2)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4285 | frame_->CallRuntime(Runtime::kLog, 2); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4286 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4287 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4288 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4292 | void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4293 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4294 | Load(args->at(0)); |
| 4295 | Register reg = frame_->PopToRegister(); |
| 4296 | __ tst(reg, Operand(kSmiTagMask | 0x80000000u)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4297 | cc_reg_ = eq; |
| 4298 | } |
| 4299 | |
| 4300 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4301 | // Generates the Math.pow method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4302 | void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) { |
| 4303 | ASSERT(args->length() == 2); |
| 4304 | Load(args->at(0)); |
| 4305 | Load(args->at(1)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4306 | |
| 4307 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4308 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4309 | frame_->EmitPush(r0); |
| 4310 | } else { |
| 4311 | CpuFeatures::Scope scope(VFP3); |
| 4312 | JumpTarget runtime, done; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4313 | Label exponent_nonsmi, base_nonsmi, powi, not_minus_half, allocate_return; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4314 | |
| 4315 | Register scratch1 = VirtualFrame::scratch0(); |
| 4316 | Register scratch2 = VirtualFrame::scratch1(); |
| 4317 | |
| 4318 | // Get base and exponent to registers. |
| 4319 | Register exponent = frame_->PopToRegister(); |
| 4320 | Register base = frame_->PopToRegister(exponent); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4321 | Register heap_number_map = no_reg; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4322 | |
| 4323 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4324 | // jump target label so the frame needs to be established before that. |
| 4325 | ASSERT(runtime.entry_frame() == NULL); |
| 4326 | runtime.set_entry_frame(frame_); |
| 4327 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4328 | __ BranchOnNotSmi(exponent, &exponent_nonsmi); |
| 4329 | __ BranchOnNotSmi(base, &base_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4330 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4331 | heap_number_map = r6; |
| 4332 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4333 | |
| 4334 | // Exponent is a smi and base is a smi. Get the smi value into vfp register |
| 4335 | // d1. |
| 4336 | __ SmiToDoubleVFPRegister(base, d1, scratch1, s0); |
| 4337 | __ b(&powi); |
| 4338 | |
| 4339 | __ bind(&base_nonsmi); |
| 4340 | // Exponent is smi and base is non smi. Get the double value from the base |
| 4341 | // into vfp register d1. |
| 4342 | __ ObjectToDoubleVFPRegister(base, d1, |
| 4343 | scratch1, scratch2, heap_number_map, s0, |
| 4344 | runtime.entry_label()); |
| 4345 | |
| 4346 | __ bind(&powi); |
| 4347 | |
| 4348 | // Load 1.0 into d0. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4349 | __ vmov(d0, 1.0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4350 | |
| 4351 | // Get the absolute untagged value of the exponent and use that for the |
| 4352 | // calculation. |
| 4353 | __ mov(scratch1, Operand(exponent, ASR, kSmiTagSize), SetCC); |
| 4354 | __ rsb(scratch1, scratch1, Operand(0), LeaveCC, mi); // Negate if negative. |
| 4355 | __ vmov(d2, d0, mi); // 1.0 needed in d2 later if exponent is negative. |
| 4356 | |
| 4357 | // Run through all the bits in the exponent. The result is calculated in d0 |
| 4358 | // and d1 holds base^(bit^2). |
| 4359 | Label more_bits; |
| 4360 | __ bind(&more_bits); |
| 4361 | __ mov(scratch1, Operand(scratch1, LSR, 1), SetCC); |
| 4362 | __ vmul(d0, d0, d1, cs); // Multiply with base^(bit^2) if bit is set. |
| 4363 | __ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done. |
| 4364 | __ b(ne, &more_bits); |
| 4365 | |
| 4366 | // If exponent is positive we are done. |
| 4367 | __ cmp(exponent, Operand(0)); |
| 4368 | __ b(ge, &allocate_return); |
| 4369 | |
| 4370 | // If exponent is negative result is 1/result (d2 already holds 1.0 in that |
| 4371 | // case). However if d0 has reached infinity this will not provide the |
| 4372 | // correct result, so call runtime if that is the case. |
| 4373 | __ mov(scratch2, Operand(0x7FF00000)); |
| 4374 | __ mov(scratch1, Operand(0)); |
| 4375 | __ vmov(d1, scratch1, scratch2); // Load infinity into d1. |
| 4376 | __ vcmp(d0, d1); |
| 4377 | __ vmrs(pc); |
| 4378 | runtime.Branch(eq); // d0 reached infinity. |
| 4379 | __ vdiv(d0, d2, d0); |
| 4380 | __ b(&allocate_return); |
| 4381 | |
| 4382 | __ bind(&exponent_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4383 | // Special handling of raising to the power of -0.5 and 0.5. First check |
| 4384 | // that the value is a heap number and that the lower bits (which for both |
| 4385 | // values are zero). |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4386 | heap_number_map = r6; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4387 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4388 | __ ldr(scratch1, FieldMemOperand(exponent, HeapObject::kMapOffset)); |
| 4389 | __ ldr(scratch2, FieldMemOperand(exponent, HeapNumber::kMantissaOffset)); |
| 4390 | __ cmp(scratch1, heap_number_map); |
| 4391 | runtime.Branch(ne); |
| 4392 | __ tst(scratch2, scratch2); |
| 4393 | runtime.Branch(ne); |
| 4394 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4395 | // Load the higher bits (which contains the floating point exponent). |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4396 | __ ldr(scratch1, FieldMemOperand(exponent, HeapNumber::kExponentOffset)); |
| 4397 | |
| 4398 | // Compare exponent with -0.5. |
| 4399 | __ cmp(scratch1, Operand(0xbfe00000)); |
| 4400 | __ b(ne, ¬_minus_half); |
| 4401 | |
| 4402 | // Get the double value from the base into vfp register d0. |
| 4403 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4404 | scratch1, scratch2, heap_number_map, s0, |
| 4405 | runtime.entry_label(), |
| 4406 | AVOID_NANS_AND_INFINITIES); |
| 4407 | |
| 4408 | // Load 1.0 into d2. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4409 | __ vmov(d2, 1.0); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4410 | |
| 4411 | // Calculate the reciprocal of the square root. 1/sqrt(x) = sqrt(1/x). |
| 4412 | __ vdiv(d0, d2, d0); |
| 4413 | __ vsqrt(d0, d0); |
| 4414 | |
| 4415 | __ b(&allocate_return); |
| 4416 | |
| 4417 | __ bind(¬_minus_half); |
| 4418 | // Compare exponent with 0.5. |
| 4419 | __ cmp(scratch1, Operand(0x3fe00000)); |
| 4420 | runtime.Branch(ne); |
| 4421 | |
| 4422 | // Get the double value from the base into vfp register d0. |
| 4423 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4424 | scratch1, scratch2, heap_number_map, s0, |
| 4425 | runtime.entry_label(), |
| 4426 | AVOID_NANS_AND_INFINITIES); |
| 4427 | __ vsqrt(d0, d0); |
| 4428 | |
| 4429 | __ bind(&allocate_return); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4430 | Register scratch3 = r5; |
| 4431 | __ AllocateHeapNumberWithValue(scratch3, d0, scratch1, scratch2, |
| 4432 | heap_number_map, runtime.entry_label()); |
| 4433 | __ mov(base, scratch3); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4434 | done.Jump(); |
| 4435 | |
| 4436 | runtime.Bind(); |
| 4437 | |
| 4438 | // Push back the arguments again for the runtime call. |
| 4439 | frame_->EmitPush(base); |
| 4440 | frame_->EmitPush(exponent); |
| 4441 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4442 | __ Move(base, r0); |
| 4443 | |
| 4444 | done.Bind(); |
| 4445 | frame_->EmitPush(base); |
| 4446 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4450 | // Generates the Math.sqrt method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4451 | void CodeGenerator::GenerateMathSqrt(ZoneList<Expression*>* args) { |
| 4452 | ASSERT(args->length() == 1); |
| 4453 | Load(args->at(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4454 | |
| 4455 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4456 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4457 | frame_->EmitPush(r0); |
| 4458 | } else { |
| 4459 | CpuFeatures::Scope scope(VFP3); |
| 4460 | JumpTarget runtime, done; |
| 4461 | |
| 4462 | Register scratch1 = VirtualFrame::scratch0(); |
| 4463 | Register scratch2 = VirtualFrame::scratch1(); |
| 4464 | |
| 4465 | // Get the value from the frame. |
| 4466 | Register tos = frame_->PopToRegister(); |
| 4467 | |
| 4468 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4469 | // jump target label so the frame needs to be established before that. |
| 4470 | ASSERT(runtime.entry_frame() == NULL); |
| 4471 | runtime.set_entry_frame(frame_); |
| 4472 | |
| 4473 | Register heap_number_map = r6; |
| 4474 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4475 | |
| 4476 | // Get the double value from the heap number into vfp register d0. |
| 4477 | __ ObjectToDoubleVFPRegister(tos, d0, |
| 4478 | scratch1, scratch2, heap_number_map, s0, |
| 4479 | runtime.entry_label()); |
| 4480 | |
| 4481 | // Calculate the square root of d0 and place result in a heap number object. |
| 4482 | __ vsqrt(d0, d0); |
| 4483 | __ AllocateHeapNumberWithValue( |
| 4484 | tos, d0, scratch1, scratch2, heap_number_map, runtime.entry_label()); |
| 4485 | done.Jump(); |
| 4486 | |
| 4487 | runtime.Bind(); |
| 4488 | // Push back the argument again for the runtime call. |
| 4489 | frame_->EmitPush(tos); |
| 4490 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4491 | __ Move(tos, r0); |
| 4492 | |
| 4493 | done.Bind(); |
| 4494 | frame_->EmitPush(tos); |
| 4495 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4499 | class DeferredStringCharCodeAt : public DeferredCode { |
| 4500 | public: |
| 4501 | DeferredStringCharCodeAt(Register object, |
| 4502 | Register index, |
| 4503 | Register scratch, |
| 4504 | Register result) |
| 4505 | : result_(result), |
| 4506 | char_code_at_generator_(object, |
| 4507 | index, |
| 4508 | scratch, |
| 4509 | result, |
| 4510 | &need_conversion_, |
| 4511 | &need_conversion_, |
| 4512 | &index_out_of_range_, |
| 4513 | STRING_INDEX_IS_NUMBER) {} |
| 4514 | |
| 4515 | StringCharCodeAtGenerator* fast_case_generator() { |
| 4516 | return &char_code_at_generator_; |
| 4517 | } |
| 4518 | |
| 4519 | virtual void Generate() { |
| 4520 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4521 | char_code_at_generator_.GenerateSlow(masm(), call_helper); |
| 4522 | |
| 4523 | __ bind(&need_conversion_); |
| 4524 | // Move the undefined value into the result register, which will |
| 4525 | // trigger conversion. |
| 4526 | __ LoadRoot(result_, Heap::kUndefinedValueRootIndex); |
| 4527 | __ jmp(exit_label()); |
| 4528 | |
| 4529 | __ bind(&index_out_of_range_); |
| 4530 | // When the index is out of range, the spec requires us to return |
| 4531 | // NaN. |
| 4532 | __ LoadRoot(result_, Heap::kNanValueRootIndex); |
| 4533 | __ jmp(exit_label()); |
| 4534 | } |
| 4535 | |
| 4536 | private: |
| 4537 | Register result_; |
| 4538 | |
| 4539 | Label need_conversion_; |
| 4540 | Label index_out_of_range_; |
| 4541 | |
| 4542 | StringCharCodeAtGenerator char_code_at_generator_; |
| 4543 | }; |
| 4544 | |
| 4545 | |
| 4546 | // This generates code that performs a String.prototype.charCodeAt() call |
| 4547 | // or returns a smi in order to trigger conversion. |
| 4548 | void CodeGenerator::GenerateStringCharCodeAt(ZoneList<Expression*>* args) { |
| 4549 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4550 | Comment(masm_, "[ GenerateStringCharCodeAt"); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4551 | ASSERT(args->length() == 2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4552 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4553 | Load(args->at(0)); |
| 4554 | Load(args->at(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4555 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4556 | Register index = r1; |
| 4557 | Register object = r2; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4558 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4559 | frame_->EmitPop(r1); |
| 4560 | frame_->EmitPop(r2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4561 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4562 | // We need two extra registers. |
| 4563 | Register scratch = r3; |
| 4564 | Register result = r0; |
| 4565 | |
| 4566 | DeferredStringCharCodeAt* deferred = |
| 4567 | new DeferredStringCharCodeAt(object, |
| 4568 | index, |
| 4569 | scratch, |
| 4570 | result); |
| 4571 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4572 | deferred->BindExit(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4573 | frame_->EmitPush(result); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4577 | class DeferredStringCharFromCode : public DeferredCode { |
| 4578 | public: |
| 4579 | DeferredStringCharFromCode(Register code, |
| 4580 | Register result) |
| 4581 | : char_from_code_generator_(code, result) {} |
| 4582 | |
| 4583 | StringCharFromCodeGenerator* fast_case_generator() { |
| 4584 | return &char_from_code_generator_; |
| 4585 | } |
| 4586 | |
| 4587 | virtual void Generate() { |
| 4588 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4589 | char_from_code_generator_.GenerateSlow(masm(), call_helper); |
| 4590 | } |
| 4591 | |
| 4592 | private: |
| 4593 | StringCharFromCodeGenerator char_from_code_generator_; |
| 4594 | }; |
| 4595 | |
| 4596 | |
| 4597 | // Generates code for creating a one-char string from a char code. |
| 4598 | void CodeGenerator::GenerateStringCharFromCode(ZoneList<Expression*>* args) { |
| 4599 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4600 | Comment(masm_, "[ GenerateStringCharFromCode"); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4601 | ASSERT(args->length() == 1); |
| 4602 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4603 | Load(args->at(0)); |
| 4604 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4605 | Register code = r1; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4606 | Register result = r0; |
| 4607 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4608 | frame_->EmitPop(code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4609 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4610 | DeferredStringCharFromCode* deferred = new DeferredStringCharFromCode( |
| 4611 | code, result); |
| 4612 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4613 | deferred->BindExit(); |
| 4614 | frame_->EmitPush(result); |
| 4615 | } |
| 4616 | |
| 4617 | |
| 4618 | class DeferredStringCharAt : public DeferredCode { |
| 4619 | public: |
| 4620 | DeferredStringCharAt(Register object, |
| 4621 | Register index, |
| 4622 | Register scratch1, |
| 4623 | Register scratch2, |
| 4624 | Register result) |
| 4625 | : result_(result), |
| 4626 | char_at_generator_(object, |
| 4627 | index, |
| 4628 | scratch1, |
| 4629 | scratch2, |
| 4630 | result, |
| 4631 | &need_conversion_, |
| 4632 | &need_conversion_, |
| 4633 | &index_out_of_range_, |
| 4634 | STRING_INDEX_IS_NUMBER) {} |
| 4635 | |
| 4636 | StringCharAtGenerator* fast_case_generator() { |
| 4637 | return &char_at_generator_; |
| 4638 | } |
| 4639 | |
| 4640 | virtual void Generate() { |
| 4641 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4642 | char_at_generator_.GenerateSlow(masm(), call_helper); |
| 4643 | |
| 4644 | __ bind(&need_conversion_); |
| 4645 | // Move smi zero into the result register, which will trigger |
| 4646 | // conversion. |
| 4647 | __ mov(result_, Operand(Smi::FromInt(0))); |
| 4648 | __ jmp(exit_label()); |
| 4649 | |
| 4650 | __ bind(&index_out_of_range_); |
| 4651 | // When the index is out of range, the spec requires us to return |
| 4652 | // the empty string. |
| 4653 | __ LoadRoot(result_, Heap::kEmptyStringRootIndex); |
| 4654 | __ jmp(exit_label()); |
| 4655 | } |
| 4656 | |
| 4657 | private: |
| 4658 | Register result_; |
| 4659 | |
| 4660 | Label need_conversion_; |
| 4661 | Label index_out_of_range_; |
| 4662 | |
| 4663 | StringCharAtGenerator char_at_generator_; |
| 4664 | }; |
| 4665 | |
| 4666 | |
| 4667 | // This generates code that performs a String.prototype.charAt() call |
| 4668 | // or returns a smi in order to trigger conversion. |
| 4669 | void CodeGenerator::GenerateStringCharAt(ZoneList<Expression*>* args) { |
| 4670 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4671 | Comment(masm_, "[ GenerateStringCharAt"); |
| 4672 | ASSERT(args->length() == 2); |
| 4673 | |
| 4674 | Load(args->at(0)); |
| 4675 | Load(args->at(1)); |
| 4676 | |
| 4677 | Register index = r1; |
| 4678 | Register object = r2; |
| 4679 | |
| 4680 | frame_->EmitPop(r1); |
| 4681 | frame_->EmitPop(r2); |
| 4682 | |
| 4683 | // We need three extra registers. |
| 4684 | Register scratch1 = r3; |
| 4685 | Register scratch2 = r4; |
| 4686 | Register result = r0; |
| 4687 | |
| 4688 | DeferredStringCharAt* deferred = |
| 4689 | new DeferredStringCharAt(object, |
| 4690 | index, |
| 4691 | scratch1, |
| 4692 | scratch2, |
| 4693 | result); |
| 4694 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4695 | deferred->BindExit(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4696 | frame_->EmitPush(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4700 | void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4701 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4702 | Load(args->at(0)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4703 | JumpTarget answer; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4704 | // We need the CC bits to come out as not_equal in the case where the |
| 4705 | // object is a smi. This can't be done with the usual test opcode so |
| 4706 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4707 | Register possible_array = frame_->PopToRegister(); |
| 4708 | Register scratch = VirtualFrame::scratch0(); |
| 4709 | __ and_(scratch, possible_array, Operand(kSmiTagMask)); |
| 4710 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4711 | answer.Branch(ne); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4712 | // It is a heap object - get the map. Check if the object is a JS array. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4713 | __ CompareObjectType(possible_array, scratch, scratch, JS_ARRAY_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4714 | answer.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4715 | cc_reg_ = eq; |
| 4716 | } |
| 4717 | |
| 4718 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4719 | void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4720 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4721 | Load(args->at(0)); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4722 | JumpTarget answer; |
| 4723 | // We need the CC bits to come out as not_equal in the case where the |
| 4724 | // object is a smi. This can't be done with the usual test opcode so |
| 4725 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4726 | Register possible_regexp = frame_->PopToRegister(); |
| 4727 | Register scratch = VirtualFrame::scratch0(); |
| 4728 | __ and_(scratch, possible_regexp, Operand(kSmiTagMask)); |
| 4729 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4730 | answer.Branch(ne); |
| 4731 | // It is a heap object - get the map. Check if the object is a regexp. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4732 | __ CompareObjectType(possible_regexp, scratch, scratch, JS_REGEXP_TYPE); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4733 | answer.Bind(); |
| 4734 | cc_reg_ = eq; |
| 4735 | } |
| 4736 | |
| 4737 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4738 | void CodeGenerator::GenerateIsObject(ZoneList<Expression*>* args) { |
| 4739 | // This generates a fast version of: |
| 4740 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4741 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4742 | Load(args->at(0)); |
| 4743 | Register possible_object = frame_->PopToRegister(); |
| 4744 | __ tst(possible_object, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4745 | false_target()->Branch(eq); |
| 4746 | |
| 4747 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4748 | __ cmp(possible_object, ip); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4749 | true_target()->Branch(eq); |
| 4750 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4751 | Register map_reg = VirtualFrame::scratch0(); |
| 4752 | __ ldr(map_reg, FieldMemOperand(possible_object, HeapObject::kMapOffset)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4753 | // Undetectable objects behave like undefined when tested with typeof. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4754 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 4755 | __ tst(possible_object, Operand(1 << Map::kIsUndetectable)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4756 | false_target()->Branch(ne); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4757 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4758 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 4759 | __ cmp(possible_object, Operand(FIRST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4760 | false_target()->Branch(lt); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4761 | __ cmp(possible_object, Operand(LAST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4762 | cc_reg_ = le; |
| 4763 | } |
| 4764 | |
| 4765 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 4766 | void CodeGenerator::GenerateIsSpecObject(ZoneList<Expression*>* args) { |
| 4767 | // This generates a fast version of: |
| 4768 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp' || |
| 4769 | // typeof(arg) == function). |
| 4770 | // It includes undetectable objects (as opposed to IsObject). |
| 4771 | ASSERT(args->length() == 1); |
| 4772 | Load(args->at(0)); |
| 4773 | Register value = frame_->PopToRegister(); |
| 4774 | __ tst(value, Operand(kSmiTagMask)); |
| 4775 | false_target()->Branch(eq); |
| 4776 | // Check that this is an object. |
| 4777 | __ ldr(value, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 4778 | __ ldrb(value, FieldMemOperand(value, Map::kInstanceTypeOffset)); |
| 4779 | __ cmp(value, Operand(FIRST_JS_OBJECT_TYPE)); |
| 4780 | cc_reg_ = ge; |
| 4781 | } |
| 4782 | |
| 4783 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4784 | void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { |
| 4785 | // This generates a fast version of: |
| 4786 | // (%_ClassOf(arg) === 'Function') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4787 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4788 | Load(args->at(0)); |
| 4789 | Register possible_function = frame_->PopToRegister(); |
| 4790 | __ tst(possible_function, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4791 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4792 | Register map_reg = VirtualFrame::scratch0(); |
| 4793 | Register scratch = VirtualFrame::scratch1(); |
| 4794 | __ CompareObjectType(possible_function, map_reg, scratch, JS_FUNCTION_TYPE); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4795 | cc_reg_ = eq; |
| 4796 | } |
| 4797 | |
| 4798 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4799 | void CodeGenerator::GenerateIsUndetectableObject(ZoneList<Expression*>* args) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4800 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4801 | Load(args->at(0)); |
| 4802 | Register possible_undetectable = frame_->PopToRegister(); |
| 4803 | __ tst(possible_undetectable, Operand(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4804 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4805 | Register scratch = VirtualFrame::scratch0(); |
| 4806 | __ ldr(scratch, |
| 4807 | FieldMemOperand(possible_undetectable, HeapObject::kMapOffset)); |
| 4808 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 4809 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4810 | cc_reg_ = ne; |
| 4811 | } |
| 4812 | |
| 4813 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4814 | void CodeGenerator::GenerateIsConstructCall(ZoneList<Expression*>* args) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4815 | ASSERT(args->length() == 0); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4816 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4817 | Register scratch0 = VirtualFrame::scratch0(); |
| 4818 | Register scratch1 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4819 | // Get the frame pointer for the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4820 | __ ldr(scratch0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4821 | |
| 4822 | // Skip the arguments adaptor frame if it exists. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4823 | __ ldr(scratch1, |
| 4824 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 4825 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4826 | __ ldr(scratch0, |
| 4827 | MemOperand(scratch0, StandardFrameConstants::kCallerFPOffset), eq); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4828 | |
| 4829 | // Check the marker in the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4830 | __ ldr(scratch1, |
| 4831 | MemOperand(scratch0, StandardFrameConstants::kMarkerOffset)); |
| 4832 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4833 | cc_reg_ = eq; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4837 | void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4838 | ASSERT(args->length() == 0); |
| 4839 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4840 | Register tos = frame_->GetTOSRegister(); |
| 4841 | Register scratch0 = VirtualFrame::scratch0(); |
| 4842 | Register scratch1 = VirtualFrame::scratch1(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4843 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 4844 | // Check if the calling frame is an arguments adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4845 | __ ldr(scratch0, |
| 4846 | MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4847 | __ ldr(scratch1, |
| 4848 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 4849 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4850 | |
| 4851 | // Get the number of formal parameters. |
| 4852 | __ mov(tos, Operand(Smi::FromInt(scope()->num_parameters())), LeaveCC, ne); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 4853 | |
| 4854 | // Arguments adaptor case: Read the arguments length from the |
| 4855 | // adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4856 | __ ldr(tos, |
| 4857 | MemOperand(scratch0, ArgumentsAdaptorFrameConstants::kLengthOffset), |
| 4858 | eq); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 4859 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4860 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4864 | void CodeGenerator::GenerateArguments(ZoneList<Expression*>* args) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4865 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4866 | ASSERT(args->length() == 1); |
| 4867 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4868 | // Satisfy contract with ArgumentsAccessStub: |
| 4869 | // Load the key into r1 and the formal parameters count into r0. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4870 | Load(args->at(0)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4871 | frame_->EmitPop(r1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4872 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4873 | |
| 4874 | // Call the shared stub to get to arguments[key]. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4875 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4876 | frame_->CallStub(&stub, 0); |
| 4877 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4881 | void CodeGenerator::GenerateRandomHeapNumber( |
| 4882 | ZoneList<Expression*>* args) { |
| 4883 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4884 | ASSERT(args->length() == 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4885 | |
| 4886 | Label slow_allocate_heapnumber; |
| 4887 | Label heapnumber_allocated; |
| 4888 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4889 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 4890 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4891 | __ jmp(&heapnumber_allocated); |
| 4892 | |
| 4893 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4894 | // Allocate a heap number. |
| 4895 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4896 | __ mov(r4, Operand(r0)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4897 | |
| 4898 | __ bind(&heapnumber_allocated); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4899 | |
| 4900 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 4901 | // by computing: |
| 4902 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 4903 | if (CpuFeatures::IsSupported(VFP3)) { |
| 4904 | __ PrepareCallCFunction(0, r1); |
| 4905 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 4906 | |
| 4907 | CpuFeatures::Scope scope(VFP3); |
| 4908 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 4909 | // Create this constant using mov/orr to avoid PC relative load. |
| 4910 | __ mov(r1, Operand(0x41000000)); |
| 4911 | __ orr(r1, r1, Operand(0x300000)); |
| 4912 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 4913 | __ vmov(d7, r0, r1); |
| 4914 | // Move 0x4130000000000000 to VFP. |
| 4915 | __ mov(r0, Operand(0)); |
| 4916 | __ vmov(d8, r0, r1); |
| 4917 | // Subtract and store the result in the heap number. |
| 4918 | __ vsub(d7, d7, d8); |
| 4919 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 4920 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 4921 | frame_->EmitPush(r4); |
| 4922 | } else { |
| 4923 | __ mov(r0, Operand(r4)); |
| 4924 | __ PrepareCallCFunction(1, r1); |
| 4925 | __ CallCFunction( |
| 4926 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 4927 | frame_->EmitPush(r0); |
| 4928 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4932 | void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { |
| 4933 | ASSERT_EQ(2, args->length()); |
| 4934 | |
| 4935 | Load(args->at(0)); |
| 4936 | Load(args->at(1)); |
| 4937 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4938 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4939 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4940 | frame_->CallStub(&stub, 2); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4941 | frame_->EmitPush(r0); |
| 4942 | } |
| 4943 | |
| 4944 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4945 | void CodeGenerator::GenerateSubString(ZoneList<Expression*>* args) { |
| 4946 | ASSERT_EQ(3, args->length()); |
| 4947 | |
| 4948 | Load(args->at(0)); |
| 4949 | Load(args->at(1)); |
| 4950 | Load(args->at(2)); |
| 4951 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4952 | SubStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4953 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4954 | frame_->CallStub(&stub, 3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4955 | frame_->EmitPush(r0); |
| 4956 | } |
| 4957 | |
| 4958 | |
| 4959 | void CodeGenerator::GenerateStringCompare(ZoneList<Expression*>* args) { |
| 4960 | ASSERT_EQ(2, args->length()); |
| 4961 | |
| 4962 | Load(args->at(0)); |
| 4963 | Load(args->at(1)); |
| 4964 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4965 | StringCompareStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4966 | frame_->SpillAll(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4967 | frame_->CallStub(&stub, 2); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4968 | frame_->EmitPush(r0); |
| 4969 | } |
| 4970 | |
| 4971 | |
| 4972 | void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) { |
| 4973 | ASSERT_EQ(4, args->length()); |
| 4974 | |
| 4975 | Load(args->at(0)); |
| 4976 | Load(args->at(1)); |
| 4977 | Load(args->at(2)); |
| 4978 | Load(args->at(3)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4979 | RegExpExecStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4980 | frame_->SpillAll(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4981 | frame_->CallStub(&stub, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4982 | frame_->EmitPush(r0); |
| 4983 | } |
| 4984 | |
| 4985 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4986 | void CodeGenerator::GenerateRegExpConstructResult(ZoneList<Expression*>* args) { |
| 4987 | // No stub. This code only occurs a few times in regexp.js. |
| 4988 | const int kMaxInlineLength = 100; |
| 4989 | ASSERT_EQ(3, args->length()); |
| 4990 | Load(args->at(0)); // Size of array, smi. |
| 4991 | Load(args->at(1)); // "index" property value. |
| 4992 | Load(args->at(2)); // "input" property value. |
| 4993 | { |
| 4994 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4995 | Label slowcase; |
| 4996 | Label done; |
| 4997 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 4998 | STATIC_ASSERT(kSmiTag == 0); |
| 4999 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5000 | __ tst(r1, Operand(kSmiTagMask)); |
| 5001 | __ b(ne, &slowcase); |
| 5002 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5003 | __ b(hi, &slowcase); |
| 5004 | // Smi-tagging is equivalent to multiplying by 2. |
| 5005 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5006 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5007 | // Elements: [Map][Length][..elements..] |
| 5008 | // Size of JSArray with two in-object properties and the header of a |
| 5009 | // FixedArray. |
| 5010 | int objects_size = |
| 5011 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5012 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5013 | __ add(r2, r5, Operand(objects_size)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 5014 | __ AllocateInNewSpace( |
| 5015 | r2, // In: Size, in words. |
| 5016 | r0, // Out: Start of allocation (tagged). |
| 5017 | r3, // Scratch register. |
| 5018 | r4, // Scratch register. |
| 5019 | &slowcase, |
| 5020 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5021 | // r0: Start of allocated area, object-tagged. |
| 5022 | // r1: Number of elements in array, as smi. |
| 5023 | // r5: Number of elements, untagged. |
| 5024 | |
| 5025 | // Set JSArray map to global.regexp_result_map(). |
| 5026 | // Set empty properties FixedArray. |
| 5027 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5028 | // Interleave operations for better latency. |
| 5029 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5030 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
| 5031 | __ mov(r4, Operand(Factory::empty_fixed_array())); |
| 5032 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 5033 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5034 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5035 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5036 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5037 | |
| 5038 | // Set input, index and length fields from arguments. |
| 5039 | __ ldm(ia_w, sp, static_cast<RegList>(r2.bit() | r4.bit())); |
| 5040 | __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset)); |
| 5041 | __ add(sp, sp, Operand(kPointerSize)); |
| 5042 | __ str(r4, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5043 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
| 5044 | |
| 5045 | // Fill out the elements FixedArray. |
| 5046 | // r0: JSArray, tagged. |
| 5047 | // r3: FixedArray, tagged. |
| 5048 | // r5: Number of elements in array, untagged. |
| 5049 | |
| 5050 | // Set map. |
| 5051 | __ mov(r2, Operand(Factory::fixed_array_map())); |
| 5052 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5053 | // Set FixedArray length. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5054 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5055 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5056 | // Fill contents of fixed-array with the-hole. |
| 5057 | __ mov(r2, Operand(Factory::the_hole_value())); |
| 5058 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5059 | // Fill fixed array elements with hole. |
| 5060 | // r0: JSArray, tagged. |
| 5061 | // r2: the hole. |
| 5062 | // r3: Start of elements in FixedArray. |
| 5063 | // r5: Number of elements to fill. |
| 5064 | Label loop; |
| 5065 | __ tst(r5, Operand(r5)); |
| 5066 | __ bind(&loop); |
| 5067 | __ b(le, &done); // Jump if r1 is negative or zero. |
| 5068 | __ sub(r5, r5, Operand(1), SetCC); |
| 5069 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5070 | __ jmp(&loop); |
| 5071 | |
| 5072 | __ bind(&slowcase); |
| 5073 | __ CallRuntime(Runtime::kRegExpConstructResult, 3); |
| 5074 | |
| 5075 | __ bind(&done); |
| 5076 | } |
| 5077 | frame_->Forget(3); |
| 5078 | frame_->EmitPush(r0); |
| 5079 | } |
| 5080 | |
| 5081 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5082 | class DeferredSearchCache: public DeferredCode { |
| 5083 | public: |
| 5084 | DeferredSearchCache(Register dst, Register cache, Register key) |
| 5085 | : dst_(dst), cache_(cache), key_(key) { |
| 5086 | set_comment("[ DeferredSearchCache"); |
| 5087 | } |
| 5088 | |
| 5089 | virtual void Generate(); |
| 5090 | |
| 5091 | private: |
| 5092 | Register dst_, cache_, key_; |
| 5093 | }; |
| 5094 | |
| 5095 | |
| 5096 | void DeferredSearchCache::Generate() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 5097 | __ Push(cache_, key_); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5098 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 5099 | if (!dst_.is(r0)) { |
| 5100 | __ mov(dst_, r0); |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | |
| 5105 | void CodeGenerator::GenerateGetFromCache(ZoneList<Expression*>* args) { |
| 5106 | ASSERT_EQ(2, args->length()); |
| 5107 | |
| 5108 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 5109 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 5110 | |
| 5111 | Handle<FixedArray> jsfunction_result_caches( |
| 5112 | Top::global_context()->jsfunction_result_caches()); |
| 5113 | if (jsfunction_result_caches->length() <= cache_id) { |
| 5114 | __ Abort("Attempt to use undefined cache."); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5115 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5116 | return; |
| 5117 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5118 | |
| 5119 | Load(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5120 | |
| 5121 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5122 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5123 | frame_->EmitPop(r2); |
| 5124 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5125 | __ ldr(r1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5126 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalContextOffset)); |
| 5127 | __ ldr(r1, ContextOperand(r1, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
| 5128 | __ ldr(r1, FieldMemOperand(r1, FixedArray::OffsetOfElementAt(cache_id))); |
| 5129 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5130 | DeferredSearchCache* deferred = new DeferredSearchCache(r0, r1, r2); |
| 5131 | |
| 5132 | const int kFingerOffset = |
| 5133 | FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 5134 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5135 | __ ldr(r0, FieldMemOperand(r1, kFingerOffset)); |
| 5136 | // r0 now holds finger offset as a smi. |
| 5137 | __ add(r3, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5138 | // r3 now points to the start of fixed array elements. |
| 5139 | __ ldr(r0, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 5140 | // Note side effect of PreIndex: r3 now points to the key of the pair. |
| 5141 | __ cmp(r2, r0); |
| 5142 | deferred->Branch(ne); |
| 5143 | |
| 5144 | __ ldr(r0, MemOperand(r3, kPointerSize)); |
| 5145 | |
| 5146 | deferred->BindExit(); |
| 5147 | frame_->EmitPush(r0); |
| 5148 | } |
| 5149 | |
| 5150 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5151 | void CodeGenerator::GenerateNumberToString(ZoneList<Expression*>* args) { |
| 5152 | ASSERT_EQ(args->length(), 1); |
| 5153 | |
| 5154 | // Load the argument on the stack and jump to the runtime. |
| 5155 | Load(args->at(0)); |
| 5156 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5157 | NumberToStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5158 | frame_->SpillAll(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5159 | frame_->CallStub(&stub, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5160 | frame_->EmitPush(r0); |
| 5161 | } |
| 5162 | |
| 5163 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5164 | class DeferredSwapElements: public DeferredCode { |
| 5165 | public: |
| 5166 | DeferredSwapElements(Register object, Register index1, Register index2) |
| 5167 | : object_(object), index1_(index1), index2_(index2) { |
| 5168 | set_comment("[ DeferredSwapElements"); |
| 5169 | } |
| 5170 | |
| 5171 | virtual void Generate(); |
| 5172 | |
| 5173 | private: |
| 5174 | Register object_, index1_, index2_; |
| 5175 | }; |
| 5176 | |
| 5177 | |
| 5178 | void DeferredSwapElements::Generate() { |
| 5179 | __ push(object_); |
| 5180 | __ push(index1_); |
| 5181 | __ push(index2_); |
| 5182 | __ CallRuntime(Runtime::kSwapElements, 3); |
| 5183 | } |
| 5184 | |
| 5185 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5186 | void CodeGenerator::GenerateSwapElements(ZoneList<Expression*>* args) { |
| 5187 | Comment cmnt(masm_, "[ GenerateSwapElements"); |
| 5188 | |
| 5189 | ASSERT_EQ(3, args->length()); |
| 5190 | |
| 5191 | Load(args->at(0)); |
| 5192 | Load(args->at(1)); |
| 5193 | Load(args->at(2)); |
| 5194 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5195 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5196 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5197 | Register index2 = r2; |
| 5198 | Register index1 = r1; |
| 5199 | Register object = r0; |
| 5200 | Register tmp1 = r3; |
| 5201 | Register tmp2 = r4; |
| 5202 | |
| 5203 | frame_->EmitPop(index2); |
| 5204 | frame_->EmitPop(index1); |
| 5205 | frame_->EmitPop(object); |
| 5206 | |
| 5207 | DeferredSwapElements* deferred = |
| 5208 | new DeferredSwapElements(object, index1, index2); |
| 5209 | |
| 5210 | // Fetch the map and check if array is in fast case. |
| 5211 | // Check that object doesn't require security checks and |
| 5212 | // has no indexed interceptor. |
| 5213 | __ CompareObjectType(object, tmp1, tmp2, FIRST_JS_OBJECT_TYPE); |
| 5214 | deferred->Branch(lt); |
| 5215 | __ ldrb(tmp2, FieldMemOperand(tmp1, Map::kBitFieldOffset)); |
| 5216 | __ tst(tmp2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask)); |
| 5217 | deferred->Branch(nz); |
| 5218 | |
| 5219 | // Check the object's elements are in fast case. |
| 5220 | __ ldr(tmp1, FieldMemOperand(object, JSObject::kElementsOffset)); |
| 5221 | __ ldr(tmp2, FieldMemOperand(tmp1, HeapObject::kMapOffset)); |
| 5222 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 5223 | __ cmp(tmp2, ip); |
| 5224 | deferred->Branch(ne); |
| 5225 | |
| 5226 | // Smi-tagging is equivalent to multiplying by 2. |
| 5227 | STATIC_ASSERT(kSmiTag == 0); |
| 5228 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5229 | |
| 5230 | // Check that both indices are smis. |
| 5231 | __ mov(tmp2, index1); |
| 5232 | __ orr(tmp2, tmp2, index2); |
| 5233 | __ tst(tmp2, Operand(kSmiTagMask)); |
| 5234 | deferred->Branch(nz); |
| 5235 | |
| 5236 | // Bring the offsets into the fixed array in tmp1 into index1 and |
| 5237 | // index2. |
| 5238 | __ mov(tmp2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5239 | __ add(index1, tmp2, Operand(index1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5240 | __ add(index2, tmp2, Operand(index2, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5241 | |
| 5242 | // Swap elements. |
| 5243 | Register tmp3 = object; |
| 5244 | object = no_reg; |
| 5245 | __ ldr(tmp3, MemOperand(tmp1, index1)); |
| 5246 | __ ldr(tmp2, MemOperand(tmp1, index2)); |
| 5247 | __ str(tmp3, MemOperand(tmp1, index2)); |
| 5248 | __ str(tmp2, MemOperand(tmp1, index1)); |
| 5249 | |
| 5250 | Label done; |
| 5251 | __ InNewSpace(tmp1, tmp2, eq, &done); |
| 5252 | // Possible optimization: do a check that both values are Smis |
| 5253 | // (or them and test against Smi mask.) |
| 5254 | |
| 5255 | __ mov(tmp2, tmp1); |
| 5256 | RecordWriteStub recordWrite1(tmp1, index1, tmp3); |
| 5257 | __ CallStub(&recordWrite1); |
| 5258 | |
| 5259 | RecordWriteStub recordWrite2(tmp2, index2, tmp3); |
| 5260 | __ CallStub(&recordWrite2); |
| 5261 | |
| 5262 | __ bind(&done); |
| 5263 | |
| 5264 | deferred->BindExit(); |
| 5265 | __ LoadRoot(tmp1, Heap::kUndefinedValueRootIndex); |
| 5266 | frame_->EmitPush(tmp1); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5270 | void CodeGenerator::GenerateCallFunction(ZoneList<Expression*>* args) { |
| 5271 | Comment cmnt(masm_, "[ GenerateCallFunction"); |
| 5272 | |
| 5273 | ASSERT(args->length() >= 2); |
| 5274 | |
| 5275 | int n_args = args->length() - 2; // for receiver and function. |
| 5276 | Load(args->at(0)); // receiver |
| 5277 | for (int i = 0; i < n_args; i++) { |
| 5278 | Load(args->at(i + 1)); |
| 5279 | } |
| 5280 | Load(args->at(n_args + 1)); // function |
| 5281 | frame_->CallJSFunction(n_args); |
| 5282 | frame_->EmitPush(r0); |
| 5283 | } |
| 5284 | |
| 5285 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5286 | void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) { |
| 5287 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5288 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5289 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5290 | TranscendentalCacheStub stub(TranscendentalCache::SIN); |
| 5291 | frame_->SpillAllButCopyTOSToR0(); |
| 5292 | frame_->CallStub(&stub, 1); |
| 5293 | } else { |
| 5294 | frame_->CallRuntime(Runtime::kMath_sin, 1); |
| 5295 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5296 | frame_->EmitPush(r0); |
| 5297 | } |
| 5298 | |
| 5299 | |
| 5300 | void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) { |
| 5301 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5302 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5303 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5304 | TranscendentalCacheStub stub(TranscendentalCache::COS); |
| 5305 | frame_->SpillAllButCopyTOSToR0(); |
| 5306 | frame_->CallStub(&stub, 1); |
| 5307 | } else { |
| 5308 | frame_->CallRuntime(Runtime::kMath_cos, 1); |
| 5309 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5310 | frame_->EmitPush(r0); |
| 5311 | } |
| 5312 | |
| 5313 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5314 | void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5315 | ASSERT(args->length() == 2); |
| 5316 | |
| 5317 | // Load the two objects into registers and perform the comparison. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5318 | Load(args->at(0)); |
| 5319 | Load(args->at(1)); |
| 5320 | Register lhs = frame_->PopToRegister(); |
| 5321 | Register rhs = frame_->PopToRegister(lhs); |
| 5322 | __ cmp(lhs, rhs); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5323 | cc_reg_ = eq; |
| 5324 | } |
| 5325 | |
| 5326 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5327 | void CodeGenerator::VisitCallRuntime(CallRuntime* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5328 | #ifdef DEBUG |
| 5329 | int original_height = frame_->height(); |
| 5330 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5331 | if (CheckForInlineRuntimeCall(node)) { |
| 5332 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 5333 | (!has_cc() && frame_->height() == original_height + 1)); |
| 5334 | return; |
| 5335 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5336 | |
| 5337 | ZoneList<Expression*>* args = node->arguments(); |
| 5338 | Comment cmnt(masm_, "[ CallRuntime"); |
| 5339 | Runtime::Function* function = node->function(); |
| 5340 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5341 | if (function == NULL) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5342 | // Prepare stack for calling JS runtime function. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5343 | // Push the builtins object found in the current global object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5344 | Register scratch = VirtualFrame::scratch0(); |
| 5345 | __ ldr(scratch, GlobalObject()); |
| 5346 | Register builtins = frame_->GetTOSRegister(); |
| 5347 | __ ldr(builtins, FieldMemOperand(scratch, GlobalObject::kBuiltinsOffset)); |
| 5348 | frame_->EmitPush(builtins); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5349 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5350 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5351 | // Push the arguments ("left-to-right"). |
| 5352 | int arg_count = args->length(); |
| 5353 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5354 | Load(args->at(i)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5355 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5356 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5357 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5358 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5359 | if (function == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5360 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5361 | __ mov(r2, Operand(node->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5362 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 5363 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5364 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5365 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5366 | frame_->EmitPush(r0); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5367 | } else { |
| 5368 | // Call the C runtime function. |
| 5369 | frame_->CallRuntime(function, arg_count); |
| 5370 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5371 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5372 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5376 | void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5377 | #ifdef DEBUG |
| 5378 | int original_height = frame_->height(); |
| 5379 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5380 | Comment cmnt(masm_, "[ UnaryOperation"); |
| 5381 | |
| 5382 | Token::Value op = node->op(); |
| 5383 | |
| 5384 | if (op == Token::NOT) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5385 | LoadCondition(node->expression(), false_target(), true_target(), true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5386 | // LoadCondition may (and usually does) leave a test and branch to |
| 5387 | // be emitted by the caller. In that case, negate the condition. |
| 5388 | if (has_cc()) cc_reg_ = NegateCondition(cc_reg_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5389 | |
| 5390 | } else if (op == Token::DELETE) { |
| 5391 | Property* property = node->expression()->AsProperty(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5392 | Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5393 | if (property != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5394 | Load(property->obj()); |
| 5395 | Load(property->key()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5396 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5397 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5398 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5399 | } else if (variable != NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5400 | Slot* slot = variable->slot(); |
| 5401 | if (variable->is_global()) { |
| 5402 | LoadGlobal(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5403 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5404 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5405 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5406 | |
| 5407 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 5408 | // lookup the context holding the named variable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5409 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5410 | frame_->EmitPush(Operand(variable->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5411 | frame_->CallRuntime(Runtime::kLookupContext, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5412 | // r0: context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5413 | frame_->EmitPush(r0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5414 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5415 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5416 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5417 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5418 | } else { |
| 5419 | // Default: Result of deleting non-global, not dynamically |
| 5420 | // introduced variables is false. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5421 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5422 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5423 | |
| 5424 | } else { |
| 5425 | // Default: Result of deleting expressions is true. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5426 | Load(node->expression()); // may have side-effects |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5427 | frame_->Drop(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5428 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | } else if (op == Token::TYPEOF) { |
| 5432 | // Special case for loading the typeof expression; see comment on |
| 5433 | // LoadTypeofExpression(). |
| 5434 | LoadTypeofExpression(node->expression()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5435 | frame_->CallRuntime(Runtime::kTypeof, 1); |
| 5436 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5437 | |
| 5438 | } else { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5439 | bool can_overwrite = |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5440 | (node->expression()->AsBinaryOperation() != NULL && |
| 5441 | node->expression()->AsBinaryOperation()->ResultOverwriteAllowed()); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5442 | UnaryOverwriteMode overwrite = |
| 5443 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
| 5444 | |
| 5445 | bool no_negative_zero = node->expression()->no_negative_zero(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5446 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5447 | switch (op) { |
| 5448 | case Token::NOT: |
| 5449 | case Token::DELETE: |
| 5450 | case Token::TYPEOF: |
| 5451 | UNREACHABLE(); // handled above |
| 5452 | break; |
| 5453 | |
| 5454 | case Token::SUB: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5455 | frame_->PopToR0(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5456 | GenericUnaryOpStub stub( |
| 5457 | Token::SUB, |
| 5458 | overwrite, |
| 5459 | no_negative_zero ? kIgnoreNegativeZero : kStrictNegativeZero); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5460 | frame_->CallStub(&stub, 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5461 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5462 | break; |
| 5463 | } |
| 5464 | |
| 5465 | case Token::BIT_NOT: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5466 | Register tos = frame_->PopToRegister(); |
| 5467 | JumpTarget not_smi_label; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5468 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5469 | // Smi check. |
| 5470 | __ tst(tos, Operand(kSmiTagMask)); |
| 5471 | not_smi_label.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5472 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5473 | __ mvn(tos, Operand(tos)); |
| 5474 | __ bic(tos, tos, Operand(kSmiTagMask)); // Bit-clear inverted smi-tag. |
| 5475 | frame_->EmitPush(tos); |
| 5476 | // The fast case is the first to jump to the continue label, so it gets |
| 5477 | // to decide the virtual frame layout. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5478 | continue_label.Jump(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5479 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5480 | not_smi_label.Bind(); |
| 5481 | frame_->SpillAll(); |
| 5482 | __ Move(r0, tos); |
| 5483 | GenericUnaryOpStub stub(Token::BIT_NOT, overwrite); |
| 5484 | frame_->CallStub(&stub, 0); |
| 5485 | frame_->EmitPush(r0); |
| 5486 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5487 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5488 | break; |
| 5489 | } |
| 5490 | |
| 5491 | case Token::VOID: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5492 | frame_->Drop(); |
| 5493 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5494 | break; |
| 5495 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5496 | case Token::ADD: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5497 | Register tos = frame_->Peek(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5498 | // Smi check. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5499 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5500 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5501 | continue_label.Branch(eq); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5502 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5503 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5504 | frame_->EmitPush(r0); |
| 5505 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5506 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5507 | break; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5508 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5509 | default: |
| 5510 | UNREACHABLE(); |
| 5511 | } |
| 5512 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5513 | ASSERT(!has_valid_frame() || |
| 5514 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5515 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5519 | void CodeGenerator::VisitCountOperation(CountOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5520 | #ifdef DEBUG |
| 5521 | int original_height = frame_->height(); |
| 5522 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5523 | Comment cmnt(masm_, "[ CountOperation"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5524 | VirtualFrame::RegisterAllocationScope scope(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5525 | |
| 5526 | bool is_postfix = node->is_postfix(); |
| 5527 | bool is_increment = node->op() == Token::INC; |
| 5528 | |
| 5529 | Variable* var = node->expression()->AsVariableProxy()->AsVariable(); |
| 5530 | bool is_const = (var != NULL && var->mode() == Variable::CONST); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5531 | bool is_slot = (var != NULL && var->mode() == Variable::VAR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5532 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5533 | if (!is_const && is_slot && type_info(var->slot()).IsSmi()) { |
| 5534 | // The type info declares that this variable is always a Smi. That |
| 5535 | // means it is a Smi both before and after the increment/decrement. |
| 5536 | // Lets make use of that to make a very minimal count. |
| 5537 | Reference target(this, node->expression(), !is_const); |
| 5538 | ASSERT(!target.is_illegal()); |
| 5539 | target.GetValue(); // Pushes the value. |
| 5540 | Register value = frame_->PopToRegister(); |
| 5541 | if (is_postfix) frame_->EmitPush(value); |
| 5542 | if (is_increment) { |
| 5543 | __ add(value, value, Operand(Smi::FromInt(1))); |
| 5544 | } else { |
| 5545 | __ sub(value, value, Operand(Smi::FromInt(1))); |
| 5546 | } |
| 5547 | frame_->EmitPush(value); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5548 | target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5549 | if (is_postfix) frame_->Pop(); |
| 5550 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 5551 | return; |
| 5552 | } |
| 5553 | |
| 5554 | // If it's a postfix expression and its result is not ignored and the |
| 5555 | // reference is non-trivial, then push a placeholder on the stack now |
| 5556 | // to hold the result of the expression. |
| 5557 | bool placeholder_pushed = false; |
| 5558 | if (!is_slot && is_postfix) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5559 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5560 | placeholder_pushed = true; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5561 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5562 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5563 | // A constant reference is not saved to, so a constant reference is not a |
| 5564 | // compound assignment reference. |
| 5565 | { Reference target(this, node->expression(), !is_const); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5566 | if (target.is_illegal()) { |
| 5567 | // Spoof the virtual frame to have the expected height (one higher |
| 5568 | // than on entry). |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5569 | if (!placeholder_pushed) frame_->EmitPush(Operand(Smi::FromInt(0))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5570 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5571 | return; |
| 5572 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5573 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5574 | // This pushes 0, 1 or 2 words on the object to be used later when updating |
| 5575 | // the target. It also pushes the current value of the target. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5576 | target.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5577 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5578 | JumpTarget slow; |
| 5579 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5580 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5581 | Register value = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5582 | |
| 5583 | // Postfix: Store the old value as the result. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5584 | if (placeholder_pushed) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5585 | frame_->SetElementAt(value, target.size()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5586 | } else if (is_postfix) { |
| 5587 | frame_->EmitPush(value); |
| 5588 | __ mov(VirtualFrame::scratch0(), value); |
| 5589 | value = VirtualFrame::scratch0(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5590 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5591 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5592 | // Check for smi operand. |
| 5593 | __ tst(value, Operand(kSmiTagMask)); |
| 5594 | slow.Branch(ne); |
| 5595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5596 | // Perform optimistic increment/decrement. |
| 5597 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5598 | __ add(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5599 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5600 | __ sub(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | // If the increment/decrement didn't overflow, we're done. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5604 | exit.Branch(vc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5605 | |
| 5606 | // Revert optimistic increment/decrement. |
| 5607 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5608 | __ sub(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5609 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5610 | __ add(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5613 | // Slow case: Convert to number. At this point the |
| 5614 | // value to be incremented is in the value register.. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5615 | slow.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5616 | |
| 5617 | // Convert the operand to a number. |
| 5618 | frame_->EmitPush(value); |
| 5619 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5620 | { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5621 | VirtualFrame::SpilledScope spilled(frame_); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5622 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5623 | |
| 5624 | if (is_postfix) { |
| 5625 | // Postfix: store to result (on the stack). |
| 5626 | __ str(r0, frame_->ElementAt(target.size())); |
| 5627 | } |
| 5628 | |
| 5629 | // Compute the new value. |
| 5630 | frame_->EmitPush(r0); |
| 5631 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
| 5632 | if (is_increment) { |
| 5633 | frame_->CallRuntime(Runtime::kNumberAdd, 2); |
| 5634 | } else { |
| 5635 | frame_->CallRuntime(Runtime::kNumberSub, 2); |
| 5636 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5637 | } |
| 5638 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5639 | __ Move(value, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5640 | // Store the new value in the target if not const. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5641 | // At this point the answer is in the value register. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5642 | exit.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5643 | frame_->EmitPush(value); |
| 5644 | // Set the target with the result, leaving the result on |
| 5645 | // top of the stack. Removes the target from the stack if |
| 5646 | // it has a non-zero size. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5647 | if (!is_const) target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | // Postfix: Discard the new value and use the old. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5651 | if (is_postfix) frame_->Pop(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5652 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5656 | void CodeGenerator::GenerateLogicalBooleanOperation(BinaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5657 | // According to ECMA-262 section 11.11, page 58, the binary logical |
| 5658 | // operators must yield the result of one of the two expressions |
| 5659 | // before any ToBoolean() conversions. This means that the value |
| 5660 | // produced by a && or || operator is not necessarily a boolean. |
| 5661 | |
| 5662 | // NOTE: If the left hand side produces a materialized value (not in |
| 5663 | // the CC register), we force the right hand side to do the |
| 5664 | // same. This is necessary because we may have to branch to the exit |
| 5665 | // after evaluating the left hand side (due to the shortcut |
| 5666 | // semantics), but the compiler must (statically) know if the result |
| 5667 | // of compiling the binary operation is materialized or not. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5668 | if (node->op() == Token::AND) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5669 | JumpTarget is_true; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5670 | LoadCondition(node->left(), &is_true, false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5671 | if (has_valid_frame() && !has_cc()) { |
| 5672 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5673 | JumpTarget pop_and_continue; |
| 5674 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5675 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5676 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5677 | // Avoid popping the result if it converts to 'false' using the |
| 5678 | // standard ToBoolean() conversion as described in ECMA-262, |
| 5679 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5680 | ToBoolean(&pop_and_continue, &exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5681 | Branch(false, &exit); |
| 5682 | |
| 5683 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5684 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5685 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5686 | |
| 5687 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5688 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5689 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5690 | |
| 5691 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5692 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5693 | } else if (has_cc() || is_true.is_linked()) { |
| 5694 | // The left-hand side is either (a) partially compiled to |
| 5695 | // control flow with a final branch left to emit or (b) fully |
| 5696 | // compiled to control flow and possibly true. |
| 5697 | if (has_cc()) { |
| 5698 | Branch(false, false_target()); |
| 5699 | } |
| 5700 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5701 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5702 | } else { |
| 5703 | // Nothing to do. |
| 5704 | ASSERT(!has_valid_frame() && !has_cc() && !is_true.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5707 | } else { |
| 5708 | ASSERT(node->op() == Token::OR); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5709 | JumpTarget is_false; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5710 | LoadCondition(node->left(), true_target(), &is_false, false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5711 | if (has_valid_frame() && !has_cc()) { |
| 5712 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5713 | JumpTarget pop_and_continue; |
| 5714 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5715 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5716 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5717 | // Avoid popping the result if it converts to 'true' using the |
| 5718 | // standard ToBoolean() conversion as described in ECMA-262, |
| 5719 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5720 | ToBoolean(&exit, &pop_and_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5721 | Branch(true, &exit); |
| 5722 | |
| 5723 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5724 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5725 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5726 | |
| 5727 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5728 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5729 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5730 | |
| 5731 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5732 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5733 | } else if (has_cc() || is_false.is_linked()) { |
| 5734 | // The left-hand side is either (a) partially compiled to |
| 5735 | // control flow with a final branch left to emit or (b) fully |
| 5736 | // compiled to control flow and possibly false. |
| 5737 | if (has_cc()) { |
| 5738 | Branch(true, true_target()); |
| 5739 | } |
| 5740 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5741 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5742 | } else { |
| 5743 | // Nothing to do. |
| 5744 | ASSERT(!has_valid_frame() && !has_cc() && !is_false.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5745 | } |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5746 | } |
| 5747 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5748 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5749 | |
| 5750 | void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) { |
| 5751 | #ifdef DEBUG |
| 5752 | int original_height = frame_->height(); |
| 5753 | #endif |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5754 | Comment cmnt(masm_, "[ BinaryOperation"); |
| 5755 | |
| 5756 | if (node->op() == Token::AND || node->op() == Token::OR) { |
| 5757 | GenerateLogicalBooleanOperation(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5758 | } else { |
| 5759 | // Optimize for the case where (at least) one of the expressions |
| 5760 | // is a literal small integer. |
| 5761 | Literal* lliteral = node->left()->AsLiteral(); |
| 5762 | Literal* rliteral = node->right()->AsLiteral(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5763 | // NOTE: The code below assumes that the slow cases (calls to runtime) |
| 5764 | // never return a constant/immutable object. |
| 5765 | bool overwrite_left = |
| 5766 | (node->left()->AsBinaryOperation() != NULL && |
| 5767 | node->left()->AsBinaryOperation()->ResultOverwriteAllowed()); |
| 5768 | bool overwrite_right = |
| 5769 | (node->right()->AsBinaryOperation() != NULL && |
| 5770 | node->right()->AsBinaryOperation()->ResultOverwriteAllowed()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5771 | |
| 5772 | if (rliteral != NULL && rliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5773 | VirtualFrame::RegisterAllocationScope scope(this); |
| 5774 | Load(node->left()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5775 | if (frame_->KnownSmiAt(0)) overwrite_left = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5776 | SmiOperation(node->op(), |
| 5777 | rliteral->handle(), |
| 5778 | false, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5779 | overwrite_left ? OVERWRITE_LEFT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5780 | } else if (lliteral != NULL && lliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5781 | VirtualFrame::RegisterAllocationScope scope(this); |
| 5782 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5783 | if (frame_->KnownSmiAt(0)) overwrite_right = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5784 | SmiOperation(node->op(), |
| 5785 | lliteral->handle(), |
| 5786 | true, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5787 | overwrite_right ? OVERWRITE_RIGHT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5788 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5789 | GenerateInlineSmi inline_smi = |
| 5790 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 5791 | if (lliteral != NULL) { |
| 5792 | ASSERT(!lliteral->handle()->IsSmi()); |
| 5793 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 5794 | } |
| 5795 | if (rliteral != NULL) { |
| 5796 | ASSERT(!rliteral->handle()->IsSmi()); |
| 5797 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 5798 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5799 | VirtualFrame::RegisterAllocationScope scope(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5800 | OverwriteMode overwrite_mode = NO_OVERWRITE; |
| 5801 | if (overwrite_left) { |
| 5802 | overwrite_mode = OVERWRITE_LEFT; |
| 5803 | } else if (overwrite_right) { |
| 5804 | overwrite_mode = OVERWRITE_RIGHT; |
| 5805 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5806 | Load(node->left()); |
| 5807 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5808 | GenericBinaryOperation(node->op(), overwrite_mode, inline_smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5809 | } |
| 5810 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5811 | ASSERT(!has_valid_frame() || |
| 5812 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5813 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5817 | void CodeGenerator::VisitThisFunction(ThisFunction* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5818 | #ifdef DEBUG |
| 5819 | int original_height = frame_->height(); |
| 5820 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5821 | frame_->EmitPush(MemOperand(frame_->Function())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5822 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5826 | void CodeGenerator::VisitCompareOperation(CompareOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5827 | #ifdef DEBUG |
| 5828 | int original_height = frame_->height(); |
| 5829 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5830 | Comment cmnt(masm_, "[ CompareOperation"); |
| 5831 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5832 | VirtualFrame::RegisterAllocationScope nonspilled_scope(this); |
| 5833 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5834 | // Get the expressions from the node. |
| 5835 | Expression* left = node->left(); |
| 5836 | Expression* right = node->right(); |
| 5837 | Token::Value op = node->op(); |
| 5838 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5839 | // To make null checks efficient, we check if either left or right is the |
| 5840 | // literal 'null'. If so, we optimize the code by inlining a null check |
| 5841 | // instead of calling the (very) general runtime routine for checking |
| 5842 | // equality. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5843 | if (op == Token::EQ || op == Token::EQ_STRICT) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5844 | bool left_is_null = |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5845 | left->AsLiteral() != NULL && left->AsLiteral()->IsNull(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5846 | bool right_is_null = |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5847 | right->AsLiteral() != NULL && right->AsLiteral()->IsNull(); |
| 5848 | // The 'null' value can only be equal to 'null' or 'undefined'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5849 | if (left_is_null || right_is_null) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5850 | Load(left_is_null ? right : left); |
| 5851 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5852 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5853 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5854 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5855 | // The 'null' value is only equal to 'undefined' if using non-strict |
| 5856 | // comparisons. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5857 | if (op != Token::EQ_STRICT) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5858 | true_target()->Branch(eq); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5859 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5860 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5861 | __ cmp(tos, Operand(ip)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5862 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5863 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5864 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5865 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5866 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5867 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5868 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 5869 | __ ldrb(tos, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 5870 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 5871 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5874 | cc_reg_ = eq; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5875 | ASSERT(has_cc() && frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5876 | return; |
| 5877 | } |
| 5878 | } |
| 5879 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5880 | // To make typeof testing for natives implemented in JavaScript really |
| 5881 | // efficient, we generate special code for expressions of the form: |
| 5882 | // 'typeof <expression> == <string>'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5883 | UnaryOperation* operation = left->AsUnaryOperation(); |
| 5884 | if ((op == Token::EQ || op == Token::EQ_STRICT) && |
| 5885 | (operation != NULL && operation->op() == Token::TYPEOF) && |
| 5886 | (right->AsLiteral() != NULL && |
| 5887 | right->AsLiteral()->handle()->IsString())) { |
| 5888 | Handle<String> check(String::cast(*right->AsLiteral()->handle())); |
| 5889 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5890 | // Load the operand, move it to a register. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5891 | LoadTypeofExpression(operation->expression()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5892 | Register tos = frame_->PopToRegister(); |
| 5893 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5894 | Register scratch = VirtualFrame::scratch0(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5895 | |
| 5896 | if (check->Equals(Heap::number_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5897 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5898 | true_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5899 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5900 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5901 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5902 | cc_reg_ = eq; |
| 5903 | |
| 5904 | } else if (check->Equals(Heap::string_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5905 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5906 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5907 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5908 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5909 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5910 | // It can be an undetectable string object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5911 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 5912 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 5913 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5914 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5915 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5916 | __ ldrb(scratch, FieldMemOperand(tos, Map::kInstanceTypeOffset)); |
| 5917 | __ cmp(scratch, Operand(FIRST_NONSTRING_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5918 | cc_reg_ = lt; |
| 5919 | |
| 5920 | } else if (check->Equals(Heap::boolean_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5921 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5922 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5923 | true_target()->Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5924 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5925 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5926 | cc_reg_ = eq; |
| 5927 | |
| 5928 | } else if (check->Equals(Heap::undefined_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5929 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5930 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5931 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5932 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5933 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5934 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5935 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5936 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5937 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 5938 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 5939 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 5940 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5941 | |
| 5942 | cc_reg_ = eq; |
| 5943 | |
| 5944 | } else if (check->Equals(Heap::function_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5945 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5946 | false_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5947 | Register map_reg = scratch; |
| 5948 | __ CompareObjectType(tos, map_reg, tos, JS_FUNCTION_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5949 | true_target()->Branch(eq); |
| 5950 | // Regular expressions are callable so typeof == 'function'. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5951 | __ CompareInstanceType(map_reg, tos, JS_REGEXP_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5952 | cc_reg_ = eq; |
| 5953 | |
| 5954 | } else if (check->Equals(Heap::object_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5955 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5956 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5957 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 5958 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5959 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5960 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5961 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5962 | Register map_reg = scratch; |
| 5963 | __ CompareObjectType(tos, map_reg, tos, JS_REGEXP_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5964 | false_target()->Branch(eq); |
| 5965 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5966 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5967 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 5968 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 5969 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5970 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5971 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5972 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 5973 | __ cmp(tos, Operand(FIRST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5974 | false_target()->Branch(lt); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5975 | __ cmp(tos, Operand(LAST_JS_OBJECT_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5976 | cc_reg_ = le; |
| 5977 | |
| 5978 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5979 | // Uncommon case: typeof testing against a string literal that is |
| 5980 | // never returned from the typeof operator. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5981 | false_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5982 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5983 | ASSERT(!has_valid_frame() || |
| 5984 | (has_cc() && frame_->height() == original_height)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5985 | return; |
| 5986 | } |
| 5987 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5988 | switch (op) { |
| 5989 | case Token::EQ: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5990 | Comparison(eq, left, right, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5991 | break; |
| 5992 | |
| 5993 | case Token::LT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5994 | Comparison(lt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5995 | break; |
| 5996 | |
| 5997 | case Token::GT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5998 | Comparison(gt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5999 | break; |
| 6000 | |
| 6001 | case Token::LTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6002 | Comparison(le, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6003 | break; |
| 6004 | |
| 6005 | case Token::GTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6006 | Comparison(ge, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6007 | break; |
| 6008 | |
| 6009 | case Token::EQ_STRICT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6010 | Comparison(eq, left, right, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6011 | break; |
| 6012 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6013 | case Token::IN: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6014 | Load(left); |
| 6015 | Load(right); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6016 | frame_->InvokeBuiltin(Builtins::IN, CALL_JS, 2); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6017 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6018 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6019 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6020 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6021 | case Token::INSTANCEOF: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6022 | Load(left); |
| 6023 | Load(right); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6024 | InstanceofStub stub; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6025 | frame_->CallStub(&stub, 2); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6026 | // At this point if instanceof succeeded then r0 == 0. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6027 | __ tst(r0, Operand(r0)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6028 | cc_reg_ = eq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6029 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6030 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6031 | |
| 6032 | default: |
| 6033 | UNREACHABLE(); |
| 6034 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6035 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 6036 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6040 | class DeferredReferenceGetNamedValue: public DeferredCode { |
| 6041 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6042 | explicit DeferredReferenceGetNamedValue(Register receiver, |
| 6043 | Handle<String> name) |
| 6044 | : receiver_(receiver), name_(name) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6045 | set_comment("[ DeferredReferenceGetNamedValue"); |
| 6046 | } |
| 6047 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6048 | virtual void Generate(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6049 | |
| 6050 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6051 | Register receiver_; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6052 | Handle<String> name_; |
| 6053 | }; |
| 6054 | |
| 6055 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6056 | // Convention for this is that on entry the receiver is in a register that |
| 6057 | // is not used by the stack. On exit the answer is found in that same |
| 6058 | // register and the stack has the same height. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6059 | void DeferredReferenceGetNamedValue::Generate() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6060 | #ifdef DEBUG |
| 6061 | int expected_height = frame_state()->frame()->height(); |
| 6062 | #endif |
| 6063 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6064 | copied_frame.SpillAll(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6065 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6066 | Register scratch1 = VirtualFrame::scratch0(); |
| 6067 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6068 | ASSERT(!receiver_.is(scratch1) && !receiver_.is(scratch2)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6069 | __ DecrementCounter(&Counters::named_load_inline, 1, scratch1, scratch2); |
| 6070 | __ IncrementCounter(&Counters::named_load_inline_miss, 1, scratch1, scratch2); |
| 6071 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6072 | // Ensure receiver in r0 and name in r2 to match load ic calling convention. |
| 6073 | __ Move(r0, receiver_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6074 | __ mov(r2, Operand(name_)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6075 | |
| 6076 | // The rest of the instructions in the deferred code must be together. |
| 6077 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6078 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 6079 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6080 | // The call must be followed by a nop(1) instruction to indicate that the |
| 6081 | // in-object has been inlined. |
| 6082 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6083 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6084 | // At this point the answer is in r0. We move it to the expected register |
| 6085 | // if necessary. |
| 6086 | __ Move(receiver_, r0); |
| 6087 | |
| 6088 | // Now go back to the frame that we entered with. This will not overwrite |
| 6089 | // the receiver register since that register was not in use when we came |
| 6090 | // in. The instructions emitted by this merge are skipped over by the |
| 6091 | // inline load patching mechanism when looking for the branch instruction |
| 6092 | // that tells it where the code to patch is. |
| 6093 | copied_frame.MergeTo(frame_state()->frame()); |
| 6094 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6095 | // Block the constant pool for one more instruction after leaving this |
| 6096 | // constant pool block scope to include the branch instruction ending the |
| 6097 | // deferred code. |
| 6098 | __ BlockConstPoolFor(1); |
| 6099 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6100 | ASSERT_EQ(expected_height, frame_state()->frame()->height()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6104 | class DeferredReferenceGetKeyedValue: public DeferredCode { |
| 6105 | public: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6106 | DeferredReferenceGetKeyedValue(Register key, Register receiver) |
| 6107 | : key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6108 | set_comment("[ DeferredReferenceGetKeyedValue"); |
| 6109 | } |
| 6110 | |
| 6111 | virtual void Generate(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6112 | |
| 6113 | private: |
| 6114 | Register key_; |
| 6115 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6116 | }; |
| 6117 | |
| 6118 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6119 | // Takes key and register in r0 and r1 or vice versa. Returns result |
| 6120 | // in r0. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6121 | void DeferredReferenceGetKeyedValue::Generate() { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6122 | ASSERT((key_.is(r0) && receiver_.is(r1)) || |
| 6123 | (key_.is(r1) && receiver_.is(r0))); |
| 6124 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6125 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6126 | copied_frame.SpillAll(); |
| 6127 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6128 | Register scratch1 = VirtualFrame::scratch0(); |
| 6129 | Register scratch2 = VirtualFrame::scratch1(); |
| 6130 | __ DecrementCounter(&Counters::keyed_load_inline, 1, scratch1, scratch2); |
| 6131 | __ IncrementCounter(&Counters::keyed_load_inline_miss, 1, scratch1, scratch2); |
| 6132 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6133 | // Ensure key in r0 and receiver in r1 to match keyed load ic calling |
| 6134 | // convention. |
| 6135 | if (key_.is(r1)) { |
| 6136 | __ Swap(r0, r1, ip); |
| 6137 | } |
| 6138 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6139 | // The rest of the instructions in the deferred code must be together. |
| 6140 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6141 | // Call keyed load IC. It has the arguments key and receiver in r0 and r1. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6142 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 6143 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6144 | // The call must be followed by a nop instruction to indicate that the |
| 6145 | // keyed load has been inlined. |
| 6146 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6147 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6148 | // Now go back to the frame that we entered with. This will not overwrite |
| 6149 | // the receiver or key registers since they were not in use when we came |
| 6150 | // in. The instructions emitted by this merge are skipped over by the |
| 6151 | // inline load patching mechanism when looking for the branch instruction |
| 6152 | // that tells it where the code to patch is. |
| 6153 | copied_frame.MergeTo(frame_state()->frame()); |
| 6154 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6155 | // Block the constant pool for one more instruction after leaving this |
| 6156 | // constant pool block scope to include the branch instruction ending the |
| 6157 | // deferred code. |
| 6158 | __ BlockConstPoolFor(1); |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | |
| 6163 | class DeferredReferenceSetKeyedValue: public DeferredCode { |
| 6164 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6165 | DeferredReferenceSetKeyedValue(Register value, |
| 6166 | Register key, |
| 6167 | Register receiver) |
| 6168 | : value_(value), key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6169 | set_comment("[ DeferredReferenceSetKeyedValue"); |
| 6170 | } |
| 6171 | |
| 6172 | virtual void Generate(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6173 | |
| 6174 | private: |
| 6175 | Register value_; |
| 6176 | Register key_; |
| 6177 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6178 | }; |
| 6179 | |
| 6180 | |
| 6181 | void DeferredReferenceSetKeyedValue::Generate() { |
| 6182 | Register scratch1 = VirtualFrame::scratch0(); |
| 6183 | Register scratch2 = VirtualFrame::scratch1(); |
| 6184 | __ DecrementCounter(&Counters::keyed_store_inline, 1, scratch1, scratch2); |
| 6185 | __ IncrementCounter( |
| 6186 | &Counters::keyed_store_inline_miss, 1, scratch1, scratch2); |
| 6187 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6188 | // Ensure value in r0, key in r1 and receiver in r2 to match keyed store ic |
| 6189 | // calling convention. |
| 6190 | if (value_.is(r1)) { |
| 6191 | __ Swap(r0, r1, ip); |
| 6192 | } |
| 6193 | ASSERT(receiver_.is(r2)); |
| 6194 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6195 | // The rest of the instructions in the deferred code must be together. |
| 6196 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6197 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6198 | // r1 and r2. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6199 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 6200 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6201 | // The call must be followed by a nop instruction to indicate that the |
| 6202 | // keyed store has been inlined. |
| 6203 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6204 | |
| 6205 | // Block the constant pool for one more instruction after leaving this |
| 6206 | // constant pool block scope to include the branch instruction ending the |
| 6207 | // deferred code. |
| 6208 | __ BlockConstPoolFor(1); |
| 6209 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6213 | class DeferredReferenceSetNamedValue: public DeferredCode { |
| 6214 | public: |
| 6215 | DeferredReferenceSetNamedValue(Register value, |
| 6216 | Register receiver, |
| 6217 | Handle<String> name) |
| 6218 | : value_(value), receiver_(receiver), name_(name) { |
| 6219 | set_comment("[ DeferredReferenceSetNamedValue"); |
| 6220 | } |
| 6221 | |
| 6222 | virtual void Generate(); |
| 6223 | |
| 6224 | private: |
| 6225 | Register value_; |
| 6226 | Register receiver_; |
| 6227 | Handle<String> name_; |
| 6228 | }; |
| 6229 | |
| 6230 | |
| 6231 | // Takes value in r0, receiver in r1 and returns the result (the |
| 6232 | // value) in r0. |
| 6233 | void DeferredReferenceSetNamedValue::Generate() { |
| 6234 | // Record the entry frame and spill. |
| 6235 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6236 | copied_frame.SpillAll(); |
| 6237 | |
| 6238 | // Ensure value in r0, receiver in r1 to match store ic calling |
| 6239 | // convention. |
| 6240 | ASSERT(value_.is(r0) && receiver_.is(r1)); |
| 6241 | __ mov(r2, Operand(name_)); |
| 6242 | |
| 6243 | // The rest of the instructions in the deferred code must be together. |
| 6244 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6245 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6246 | // r1 and r2. |
| 6247 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 6248 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6249 | // The call must be followed by a nop instruction to indicate that the |
| 6250 | // named store has been inlined. |
| 6251 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6252 | |
| 6253 | // Go back to the frame we entered with. The instructions |
| 6254 | // generated by this merge are skipped over by the inline store |
| 6255 | // patching mechanism when looking for the branch instruction that |
| 6256 | // tells it where the code to patch is. |
| 6257 | copied_frame.MergeTo(frame_state()->frame()); |
| 6258 | |
| 6259 | // Block the constant pool for one more instruction after leaving this |
| 6260 | // constant pool block scope to include the branch instruction ending the |
| 6261 | // deferred code. |
| 6262 | __ BlockConstPoolFor(1); |
| 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6267 | // Consumes the top of stack (the receiver) and pushes the result instead. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6268 | void CodeGenerator::EmitNamedLoad(Handle<String> name, bool is_contextual) { |
| 6269 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6270 | Comment cmnt(masm(), "[ Load from named Property"); |
| 6271 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6272 | frame_->CallLoadIC(name, |
| 6273 | is_contextual |
| 6274 | ? RelocInfo::CODE_TARGET_CONTEXT |
| 6275 | : RelocInfo::CODE_TARGET); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6276 | frame_->EmitPush(r0); // Push answer. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6277 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6278 | // Inline the in-object property case. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6279 | Comment cmnt(masm(), "[ Inlined named property load"); |
| 6280 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6281 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6282 | // having it in the instruction stream below where patching will occur. |
| 6283 | __ IncrementCounter(&Counters::named_load_inline, 1, |
| 6284 | frame_->scratch0(), frame_->scratch1()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6285 | |
| 6286 | // The following instructions are the inlined load of an in-object property. |
| 6287 | // Parts of this code is patched, so the exact instructions generated needs |
| 6288 | // to be fixed. Therefore the instruction pool is blocked when generating |
| 6289 | // this code |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6290 | |
| 6291 | // Load the receiver from the stack. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6292 | Register receiver = frame_->PopToRegister(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6293 | |
| 6294 | DeferredReferenceGetNamedValue* deferred = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6295 | new DeferredReferenceGetNamedValue(receiver, name); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6296 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6297 | #ifdef DEBUG |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6298 | int kInlinedNamedLoadInstructions = 7; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6299 | Label check_inlined_codesize; |
| 6300 | masm_->bind(&check_inlined_codesize); |
| 6301 | #endif |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6302 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6303 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6304 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6305 | __ tst(receiver, Operand(kSmiTagMask)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6306 | deferred->Branch(eq); |
| 6307 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6308 | Register scratch = VirtualFrame::scratch0(); |
| 6309 | Register scratch2 = VirtualFrame::scratch1(); |
| 6310 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6311 | // Check the map. The null map used below is patched by the inline cache |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6312 | // code. Therefore we can't use a LoadRoot call. |
| 6313 | __ ldr(scratch, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6314 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6315 | __ cmp(scratch, scratch2); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6316 | deferred->Branch(ne); |
| 6317 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6318 | // Initially use an invalid index. The index will be patched by the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6319 | // inline cache code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6320 | __ ldr(receiver, MemOperand(receiver, 0)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6321 | |
| 6322 | // Make sure that the expected number of instructions are generated. |
| 6323 | ASSERT_EQ(kInlinedNamedLoadInstructions, |
| 6324 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6327 | deferred->BindExit(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6328 | // At this point the receiver register has the result, either from the |
| 6329 | // deferred code or from the inlined code. |
| 6330 | frame_->EmitPush(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6331 | } |
| 6332 | } |
| 6333 | |
| 6334 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6335 | void CodeGenerator::EmitNamedStore(Handle<String> name, bool is_contextual) { |
| 6336 | #ifdef DEBUG |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6337 | int expected_height = frame()->height() - (is_contextual ? 1 : 2); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6338 | #endif |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6339 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6340 | Result result; |
| 6341 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6342 | frame()->CallStoreIC(name, is_contextual); |
| 6343 | } else { |
| 6344 | // Inline the in-object property case. |
| 6345 | JumpTarget slow, done; |
| 6346 | |
| 6347 | // Get the value and receiver from the stack. |
| 6348 | frame()->PopToR0(); |
| 6349 | Register value = r0; |
| 6350 | frame()->PopToR1(); |
| 6351 | Register receiver = r1; |
| 6352 | |
| 6353 | DeferredReferenceSetNamedValue* deferred = |
| 6354 | new DeferredReferenceSetNamedValue(value, receiver, name); |
| 6355 | |
| 6356 | // Check that the receiver is a heap object. |
| 6357 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6358 | deferred->Branch(eq); |
| 6359 | |
| 6360 | // The following instructions are the part of the inlined |
| 6361 | // in-object property store code which can be patched. Therefore |
| 6362 | // the exact number of instructions generated must be fixed, so |
| 6363 | // the constant pool is blocked while generating this code. |
| 6364 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6365 | Register scratch0 = VirtualFrame::scratch0(); |
| 6366 | Register scratch1 = VirtualFrame::scratch1(); |
| 6367 | |
| 6368 | // Check the map. Initially use an invalid map to force a |
| 6369 | // failure. The map check will be patched in the runtime system. |
| 6370 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6371 | |
| 6372 | #ifdef DEBUG |
| 6373 | Label check_inlined_codesize; |
| 6374 | masm_->bind(&check_inlined_codesize); |
| 6375 | #endif |
| 6376 | __ mov(scratch0, Operand(Factory::null_value())); |
| 6377 | __ cmp(scratch0, scratch1); |
| 6378 | deferred->Branch(ne); |
| 6379 | |
| 6380 | int offset = 0; |
| 6381 | __ str(value, MemOperand(receiver, offset)); |
| 6382 | |
| 6383 | // Update the write barrier and record its size. We do not use |
| 6384 | // the RecordWrite macro here because we want the offset |
| 6385 | // addition instruction first to make it easy to patch. |
| 6386 | Label record_write_start, record_write_done; |
| 6387 | __ bind(&record_write_start); |
| 6388 | // Add offset into the object. |
| 6389 | __ add(scratch0, receiver, Operand(offset)); |
| 6390 | // Test that the object is not in the new space. We cannot set |
| 6391 | // region marks for new space pages. |
| 6392 | __ InNewSpace(receiver, scratch1, eq, &record_write_done); |
| 6393 | // Record the actual write. |
| 6394 | __ RecordWriteHelper(receiver, scratch0, scratch1); |
| 6395 | __ bind(&record_write_done); |
| 6396 | // Clobber all input registers when running with the debug-code flag |
| 6397 | // turned on to provoke errors. |
| 6398 | if (FLAG_debug_code) { |
| 6399 | __ mov(receiver, Operand(BitCast<int32_t>(kZapValue))); |
| 6400 | __ mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 6401 | __ mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
| 6402 | } |
| 6403 | // Check that this is the first inlined write barrier or that |
| 6404 | // this inlined write barrier has the same size as all the other |
| 6405 | // inlined write barriers. |
| 6406 | ASSERT((inlined_write_barrier_size_ == -1) || |
| 6407 | (inlined_write_barrier_size_ == |
| 6408 | masm()->InstructionsGeneratedSince(&record_write_start))); |
| 6409 | inlined_write_barrier_size_ = |
| 6410 | masm()->InstructionsGeneratedSince(&record_write_start); |
| 6411 | |
| 6412 | // Make sure that the expected number of instructions are generated. |
| 6413 | ASSERT_EQ(GetInlinedNamedStoreInstructionsAfterPatch(), |
| 6414 | masm()->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6415 | } |
| 6416 | deferred->BindExit(); |
| 6417 | } |
| 6418 | ASSERT_EQ(expected_height, frame()->height()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6422 | void CodeGenerator::EmitKeyedLoad() { |
| 6423 | if (loop_nesting() == 0) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6424 | Comment cmnt(masm_, "[ Load from keyed property"); |
| 6425 | frame_->CallKeyedLoadIC(); |
| 6426 | } else { |
| 6427 | // Inline the keyed load. |
| 6428 | Comment cmnt(masm_, "[ Inlined load from keyed property"); |
| 6429 | |
| 6430 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6431 | // having it in the instruction stream below where patching will occur. |
| 6432 | __ IncrementCounter(&Counters::keyed_load_inline, 1, |
| 6433 | frame_->scratch0(), frame_->scratch1()); |
| 6434 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6435 | // Load the key and receiver from the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6436 | bool key_is_known_smi = frame_->KnownSmiAt(0); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6437 | Register key = frame_->PopToRegister(); |
| 6438 | Register receiver = frame_->PopToRegister(key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6439 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6440 | // The deferred code expects key and receiver in registers. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6441 | DeferredReferenceGetKeyedValue* deferred = |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6442 | new DeferredReferenceGetKeyedValue(key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6443 | |
| 6444 | // Check that the receiver is a heap object. |
| 6445 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6446 | deferred->Branch(eq); |
| 6447 | |
| 6448 | // The following instructions are the part of the inlined load keyed |
| 6449 | // property code which can be patched. Therefore the exact number of |
| 6450 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6451 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6452 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6453 | Register scratch1 = VirtualFrame::scratch0(); |
| 6454 | Register scratch2 = VirtualFrame::scratch1(); |
| 6455 | // Check the map. The null map used below is patched by the inline cache |
| 6456 | // code. |
| 6457 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6458 | |
| 6459 | // Check that the key is a smi. |
| 6460 | if (!key_is_known_smi) { |
| 6461 | __ tst(key, Operand(kSmiTagMask)); |
| 6462 | deferred->Branch(ne); |
| 6463 | } |
| 6464 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6465 | #ifdef DEBUG |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6466 | Label check_inlined_codesize; |
| 6467 | masm_->bind(&check_inlined_codesize); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6468 | #endif |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6469 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6470 | __ cmp(scratch1, scratch2); |
| 6471 | deferred->Branch(ne); |
| 6472 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6473 | // Get the elements array from the receiver and check that it |
| 6474 | // is not a dictionary. |
| 6475 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6476 | if (FLAG_debug_code) { |
| 6477 | __ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset)); |
| 6478 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 6479 | __ cmp(scratch2, ip); |
| 6480 | __ Assert(eq, "JSObject with fast elements map has slow elements"); |
| 6481 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6482 | |
| 6483 | // Check that key is within bounds. Use unsigned comparison to handle |
| 6484 | // negative keys. |
| 6485 | __ ldr(scratch2, FieldMemOperand(scratch1, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6486 | __ cmp(scratch2, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6487 | deferred->Branch(ls); // Unsigned less equal. |
| 6488 | |
| 6489 | // Load and check that the result is not the hole (key is a smi). |
| 6490 | __ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex); |
| 6491 | __ add(scratch1, |
| 6492 | scratch1, |
| 6493 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6494 | __ ldr(scratch1, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6495 | MemOperand(scratch1, key, LSL, |
| 6496 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6497 | __ cmp(scratch1, scratch2); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6498 | deferred->Branch(eq); |
| 6499 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6500 | __ mov(r0, scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6501 | // Make sure that the expected number of instructions are generated. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6502 | ASSERT_EQ(GetInlinedKeyedLoadInstructionsAfterPatch(), |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6503 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6504 | } |
| 6505 | |
| 6506 | deferred->BindExit(); |
| 6507 | } |
| 6508 | } |
| 6509 | |
| 6510 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6511 | void CodeGenerator::EmitKeyedStore(StaticType* key_type, |
| 6512 | WriteBarrierCharacter wb_info) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6513 | // Generate inlined version of the keyed store if the code is in a loop |
| 6514 | // and the key is likely to be a smi. |
| 6515 | if (loop_nesting() > 0 && key_type->IsLikelySmi()) { |
| 6516 | // Inline the keyed store. |
| 6517 | Comment cmnt(masm_, "[ Inlined store to keyed property"); |
| 6518 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6519 | Register scratch1 = VirtualFrame::scratch0(); |
| 6520 | Register scratch2 = VirtualFrame::scratch1(); |
| 6521 | Register scratch3 = r3; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6524 | // having it in the instruction stream below where patching will occur. |
| 6525 | __ IncrementCounter(&Counters::keyed_store_inline, 1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6526 | scratch1, scratch2); |
| 6527 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6528 | |
| 6529 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6530 | // Load the value, key and receiver from the stack. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6531 | bool value_is_harmless = frame_->KnownSmiAt(0); |
| 6532 | if (wb_info == NEVER_NEWSPACE) value_is_harmless = true; |
| 6533 | bool key_is_smi = frame_->KnownSmiAt(1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6534 | Register value = frame_->PopToRegister(); |
| 6535 | Register key = frame_->PopToRegister(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6536 | VirtualFrame::SpilledScope spilled(frame_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6537 | Register receiver = r2; |
| 6538 | frame_->EmitPop(receiver); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6539 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6540 | #ifdef DEBUG |
| 6541 | bool we_remembered_the_write_barrier = value_is_harmless; |
| 6542 | #endif |
| 6543 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6544 | // The deferred code expects value, key and receiver in registers. |
| 6545 | DeferredReferenceSetKeyedValue* deferred = |
| 6546 | new DeferredReferenceSetKeyedValue(value, key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6547 | |
| 6548 | // Check that the value is a smi. As this inlined code does not set the |
| 6549 | // write barrier it is only possible to store smi values. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6550 | if (!value_is_harmless) { |
| 6551 | // If the value is not likely to be a Smi then let's test the fixed array |
| 6552 | // for new space instead. See below. |
| 6553 | if (wb_info == LIKELY_SMI) { |
| 6554 | __ tst(value, Operand(kSmiTagMask)); |
| 6555 | deferred->Branch(ne); |
| 6556 | #ifdef DEBUG |
| 6557 | we_remembered_the_write_barrier = true; |
| 6558 | #endif |
| 6559 | } |
| 6560 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6561 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6562 | if (!key_is_smi) { |
| 6563 | // Check that the key is a smi. |
| 6564 | __ tst(key, Operand(kSmiTagMask)); |
| 6565 | deferred->Branch(ne); |
| 6566 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6567 | |
| 6568 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6569 | __ tst(receiver, Operand(kSmiTagMask)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6570 | deferred->Branch(eq); |
| 6571 | |
| 6572 | // Check that the receiver is a JSArray. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6573 | __ CompareObjectType(receiver, scratch1, scratch1, JS_ARRAY_TYPE); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6574 | deferred->Branch(ne); |
| 6575 | |
| 6576 | // Check that the key is within bounds. Both the key and the length of |
| 6577 | // the JSArray are smis. Use unsigned comparison to handle negative keys. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6578 | __ ldr(scratch1, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 6579 | __ cmp(scratch1, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6580 | deferred->Branch(ls); // Unsigned less equal. |
| 6581 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6582 | // Get the elements array from the receiver. |
| 6583 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 6584 | if (!value_is_harmless && wb_info != LIKELY_SMI) { |
| 6585 | Label ok; |
| 6586 | __ and_(scratch2, scratch1, Operand(ExternalReference::new_space_mask())); |
| 6587 | __ cmp(scratch2, Operand(ExternalReference::new_space_start())); |
| 6588 | __ tst(value, Operand(kSmiTagMask), ne); |
| 6589 | deferred->Branch(ne); |
| 6590 | #ifdef DEBUG |
| 6591 | we_remembered_the_write_barrier = true; |
| 6592 | #endif |
| 6593 | } |
| 6594 | // Check that the elements array is not a dictionary. |
| 6595 | __ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6596 | // The following instructions are the part of the inlined store keyed |
| 6597 | // property code which can be patched. Therefore the exact number of |
| 6598 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6599 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6600 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6601 | #ifdef DEBUG |
| 6602 | Label check_inlined_codesize; |
| 6603 | masm_->bind(&check_inlined_codesize); |
| 6604 | #endif |
| 6605 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6606 | // Read the fixed array map from the constant pool (not from the root |
| 6607 | // array) so that the value can be patched. When debugging, we patch this |
| 6608 | // comparison to always fail so that we will hit the IC call in the |
| 6609 | // deferred code which will allow the debugger to break for fast case |
| 6610 | // stores. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6611 | __ mov(scratch3, Operand(Factory::fixed_array_map())); |
| 6612 | __ cmp(scratch2, scratch3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6613 | deferred->Branch(ne); |
| 6614 | |
| 6615 | // Store the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6616 | __ add(scratch1, scratch1, |
| 6617 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 6618 | __ str(value, |
| 6619 | MemOperand(scratch1, key, LSL, |
| 6620 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6621 | |
| 6622 | // Make sure that the expected number of instructions are generated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6623 | ASSERT_EQ(kInlinedKeyedStoreInstructionsAfterPatch, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6624 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6625 | } |
| 6626 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6627 | ASSERT(we_remembered_the_write_barrier); |
| 6628 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6629 | deferred->BindExit(); |
| 6630 | } else { |
| 6631 | frame()->CallKeyedStoreIC(); |
| 6632 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6636 | #ifdef DEBUG |
| 6637 | bool CodeGenerator::HasValidEntryRegisters() { return true; } |
| 6638 | #endif |
| 6639 | |
| 6640 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6641 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6642 | #define __ ACCESS_MASM(masm) |
| 6643 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6644 | Handle<String> Reference::GetName() { |
| 6645 | ASSERT(type_ == NAMED); |
| 6646 | Property* property = expression_->AsProperty(); |
| 6647 | if (property == NULL) { |
| 6648 | // Global variable reference treated as a named property reference. |
| 6649 | VariableProxy* proxy = expression_->AsVariableProxy(); |
| 6650 | ASSERT(proxy->AsVariable() != NULL); |
| 6651 | ASSERT(proxy->AsVariable()->is_global()); |
| 6652 | return proxy->name(); |
| 6653 | } else { |
| 6654 | Literal* raw_name = property->key()->AsLiteral(); |
| 6655 | ASSERT(raw_name != NULL); |
| 6656 | return Handle<String>(String::cast(*raw_name->handle())); |
| 6657 | } |
| 6658 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6659 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6660 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6661 | void Reference::DupIfPersist() { |
| 6662 | if (persist_after_get_) { |
| 6663 | switch (type_) { |
| 6664 | case KEYED: |
| 6665 | cgen_->frame()->Dup2(); |
| 6666 | break; |
| 6667 | case NAMED: |
| 6668 | cgen_->frame()->Dup(); |
| 6669 | // Fall through. |
| 6670 | case UNLOADED: |
| 6671 | case ILLEGAL: |
| 6672 | case SLOT: |
| 6673 | // Do nothing. |
| 6674 | ; |
| 6675 | } |
| 6676 | } else { |
| 6677 | set_unloaded(); |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6682 | void Reference::GetValue() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6683 | ASSERT(cgen_->HasValidEntryRegisters()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6684 | ASSERT(!is_illegal()); |
| 6685 | ASSERT(!cgen_->has_cc()); |
| 6686 | MacroAssembler* masm = cgen_->masm(); |
| 6687 | Property* property = expression_->AsProperty(); |
| 6688 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 6689 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | switch (type_) { |
| 6693 | case SLOT: { |
| 6694 | Comment cmnt(masm, "[ Load from Slot"); |
| 6695 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
| 6696 | ASSERT(slot != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6697 | DupIfPersist(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6698 | cgen_->LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6699 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6702 | case NAMED: { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6703 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6704 | bool is_global = var != NULL; |
| 6705 | ASSERT(!is_global || var->is_global()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6706 | Handle<String> name = GetName(); |
| 6707 | DupIfPersist(); |
| 6708 | cgen_->EmitNamedLoad(name, is_global); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6709 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6712 | case KEYED: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6713 | ASSERT(property != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6714 | DupIfPersist(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6715 | cgen_->EmitKeyedLoad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6716 | cgen_->frame()->EmitPush(r0); |
| 6717 | break; |
| 6718 | } |
| 6719 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6720 | default: |
| 6721 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6726 | void Reference::SetValue(InitState init_state, WriteBarrierCharacter wb_info) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6727 | ASSERT(!is_illegal()); |
| 6728 | ASSERT(!cgen_->has_cc()); |
| 6729 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6730 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6731 | Property* property = expression_->AsProperty(); |
| 6732 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 6733 | cgen_->CodeForSourcePosition(property->position()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6734 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6735 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6736 | switch (type_) { |
| 6737 | case SLOT: { |
| 6738 | Comment cmnt(masm, "[ Store to Slot"); |
| 6739 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6740 | cgen_->StoreToSlot(slot, init_state); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6741 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6742 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6743 | } |
| 6744 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6745 | case NAMED: { |
| 6746 | Comment cmnt(masm, "[ Store to named Property"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6747 | cgen_->EmitNamedStore(GetName(), false); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6748 | frame->EmitPush(r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 6749 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6750 | break; |
| 6751 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6752 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6753 | case KEYED: { |
| 6754 | Comment cmnt(masm, "[ Store to keyed Property"); |
| 6755 | Property* property = expression_->AsProperty(); |
| 6756 | ASSERT(property != NULL); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 6757 | cgen_->CodeForSourcePosition(property->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6758 | cgen_->EmitKeyedStore(property->key()->type(), wb_info); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6759 | frame->EmitPush(r0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6760 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6761 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6762 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6763 | |
| 6764 | default: |
| 6765 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6770 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6771 | // Create a new closure from the given function info in new |
| 6772 | // space. Set the context to the current context in cp. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6773 | Label gc; |
| 6774 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6775 | // Pop the function info from the stack. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6776 | __ pop(r3); |
| 6777 | |
| 6778 | // Attempt to allocate new JSFunction in new space. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6779 | __ AllocateInNewSpace(JSFunction::kSize, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6780 | r0, |
| 6781 | r1, |
| 6782 | r2, |
| 6783 | &gc, |
| 6784 | TAG_OBJECT); |
| 6785 | |
| 6786 | // Compute the function map in the current global context and set that |
| 6787 | // as the map of the allocated object. |
| 6788 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 6789 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 6790 | __ ldr(r2, MemOperand(r2, Context::SlotOffset(Context::FUNCTION_MAP_INDEX))); |
| 6791 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6792 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6793 | // Initialize the rest of the function. We don't have to update the |
| 6794 | // write barrier because the allocated object is in new space. |
| 6795 | __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex); |
| 6796 | __ LoadRoot(r2, Heap::kTheHoleValueRootIndex); |
| 6797 | __ str(r1, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 6798 | __ str(r1, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 6799 | __ str(r2, FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset)); |
| 6800 | __ str(r3, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 6801 | __ str(cp, FieldMemOperand(r0, JSFunction::kContextOffset)); |
| 6802 | __ str(r1, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6803 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6804 | // Return result. The argument function info has been popped already. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6805 | __ Ret(); |
| 6806 | |
| 6807 | // Create a new closure through the slower runtime call. |
| 6808 | __ bind(&gc); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6809 | __ Push(cp, r3); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6810 | __ TailCallRuntime(Runtime::kNewClosure, 2, 1); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | |
| 6814 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 6815 | // Try to allocate the context in new space. |
| 6816 | Label gc; |
| 6817 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 6818 | |
| 6819 | // Attempt to allocate the context in new space. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6820 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6821 | r0, |
| 6822 | r1, |
| 6823 | r2, |
| 6824 | &gc, |
| 6825 | TAG_OBJECT); |
| 6826 | |
| 6827 | // Load the function from the stack. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 6828 | __ ldr(r3, MemOperand(sp, 0)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6829 | |
| 6830 | // Setup the object header. |
| 6831 | __ LoadRoot(r2, Heap::kContextMapRootIndex); |
| 6832 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6833 | __ mov(r2, Operand(Smi::FromInt(length))); |
| 6834 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6835 | |
| 6836 | // Setup the fixed slots. |
| 6837 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 6838 | __ str(r3, MemOperand(r0, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 6839 | __ str(r0, MemOperand(r0, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 6840 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
| 6841 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::EXTENSION_INDEX))); |
| 6842 | |
| 6843 | // Copy the global object from the surrounding context. |
| 6844 | __ ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 6845 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 6846 | |
| 6847 | // Initialize the rest of the slots to undefined. |
| 6848 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 6849 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
| 6850 | __ str(r1, MemOperand(r0, Context::SlotOffset(i))); |
| 6851 | } |
| 6852 | |
| 6853 | // Remove the on-stack argument and return. |
| 6854 | __ mov(cp, r0); |
| 6855 | __ pop(); |
| 6856 | __ Ret(); |
| 6857 | |
| 6858 | // Need to collect. Call into runtime system. |
| 6859 | __ bind(&gc); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6860 | __ TailCallRuntime(Runtime::kNewContext, 1, 1); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 6864 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 6865 | // Stack layout on entry: |
| 6866 | // |
| 6867 | // [sp]: constant elements. |
| 6868 | // [sp + kPointerSize]: literal index. |
| 6869 | // [sp + (2 * kPointerSize)]: literals array. |
| 6870 | |
| 6871 | // All sizes here are multiples of kPointerSize. |
| 6872 | int elements_size = (length_ > 0) ? FixedArray::SizeFor(length_) : 0; |
| 6873 | int size = JSArray::kSize + elements_size; |
| 6874 | |
| 6875 | // Load boilerplate object into r3 and check if we need to create a |
| 6876 | // boilerplate. |
| 6877 | Label slow_case; |
| 6878 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 6879 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 6880 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 6881 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 6882 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 6883 | __ cmp(r3, ip); |
| 6884 | __ b(eq, &slow_case); |
| 6885 | |
| 6886 | // Allocate both the JS array and the elements array in one big |
| 6887 | // allocation. This avoids multiple limit checks. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6888 | __ AllocateInNewSpace(size, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 6889 | r0, |
| 6890 | r1, |
| 6891 | r2, |
| 6892 | &slow_case, |
| 6893 | TAG_OBJECT); |
| 6894 | |
| 6895 | // Copy the JS array part. |
| 6896 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
| 6897 | if ((i != JSArray::kElementsOffset) || (length_ == 0)) { |
| 6898 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 6899 | __ str(r1, FieldMemOperand(r0, i)); |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | if (length_ > 0) { |
| 6904 | // Get hold of the elements array of the boilerplate and setup the |
| 6905 | // elements pointer in the resulting object. |
| 6906 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 6907 | __ add(r2, r0, Operand(JSArray::kSize)); |
| 6908 | __ str(r2, FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 6909 | |
| 6910 | // Copy the elements array. |
| 6911 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 6912 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 6913 | __ str(r1, FieldMemOperand(r2, i)); |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | // Return and remove the on-stack parameters. |
| 6918 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 6919 | __ Ret(); |
| 6920 | |
| 6921 | __ bind(&slow_case); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6922 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
| 6925 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6926 | // Takes a Smi and converts to an IEEE 64 bit floating point value in two |
| 6927 | // registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and |
| 6928 | // 52 fraction bits (20 in the first word, 32 in the second). Zeros is a |
| 6929 | // scratch register. Destroys the source register. No GC occurs during this |
| 6930 | // stub so you don't have to set up the frame. |
| 6931 | class ConvertToDoubleStub : public CodeStub { |
| 6932 | public: |
| 6933 | ConvertToDoubleStub(Register result_reg_1, |
| 6934 | Register result_reg_2, |
| 6935 | Register source_reg, |
| 6936 | Register scratch_reg) |
| 6937 | : result1_(result_reg_1), |
| 6938 | result2_(result_reg_2), |
| 6939 | source_(source_reg), |
| 6940 | zeros_(scratch_reg) { } |
| 6941 | |
| 6942 | private: |
| 6943 | Register result1_; |
| 6944 | Register result2_; |
| 6945 | Register source_; |
| 6946 | Register zeros_; |
| 6947 | |
| 6948 | // Minor key encoding in 16 bits. |
| 6949 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 6950 | class OpBits: public BitField<Token::Value, 2, 14> {}; |
| 6951 | |
| 6952 | Major MajorKey() { return ConvertToDouble; } |
| 6953 | int MinorKey() { |
| 6954 | // Encode the parameters in a unique 16 bit value. |
| 6955 | return result1_.code() + |
| 6956 | (result2_.code() << 4) + |
| 6957 | (source_.code() << 8) + |
| 6958 | (zeros_.code() << 12); |
| 6959 | } |
| 6960 | |
| 6961 | void Generate(MacroAssembler* masm); |
| 6962 | |
| 6963 | const char* GetName() { return "ConvertToDoubleStub"; } |
| 6964 | |
| 6965 | #ifdef DEBUG |
| 6966 | void Print() { PrintF("ConvertToDoubleStub\n"); } |
| 6967 | #endif |
| 6968 | }; |
| 6969 | |
| 6970 | |
| 6971 | void ConvertToDoubleStub::Generate(MacroAssembler* masm) { |
| 6972 | #ifndef BIG_ENDIAN_FLOATING_POINT |
| 6973 | Register exponent = result1_; |
| 6974 | Register mantissa = result2_; |
| 6975 | #else |
| 6976 | Register exponent = result2_; |
| 6977 | Register mantissa = result1_; |
| 6978 | #endif |
| 6979 | Label not_special; |
| 6980 | // Convert from Smi to integer. |
| 6981 | __ mov(source_, Operand(source_, ASR, kSmiTagSize)); |
| 6982 | // Move sign bit from source to destination. This works because the sign bit |
| 6983 | // in the exponent word of the double has the same position and polarity as |
| 6984 | // the 2's complement sign bit in a Smi. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6985 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6986 | __ and_(exponent, source_, Operand(HeapNumber::kSignMask), SetCC); |
| 6987 | // Subtract from 0 if source was negative. |
| 6988 | __ rsb(source_, source_, Operand(0), LeaveCC, ne); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6989 | |
| 6990 | // We have -1, 0 or 1, which we treat specially. Register source_ contains |
| 6991 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 6992 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6993 | __ cmp(source_, Operand(1)); |
| 6994 | __ b(gt, ¬_special); |
| 6995 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6996 | // For 1 or -1 we need to or in the 0 exponent (biased to 1023). |
| 6997 | static const uint32_t exponent_word_for_1 = |
| 6998 | HeapNumber::kExponentBias << HeapNumber::kExponentShift; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6999 | __ orr(exponent, exponent, Operand(exponent_word_for_1), LeaveCC, eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7000 | // 1, 0 and -1 all have 0 for the second word. |
| 7001 | __ mov(mantissa, Operand(0)); |
| 7002 | __ Ret(); |
| 7003 | |
| 7004 | __ bind(¬_special); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 7005 | // Count leading zeros. Uses mantissa for a scratch register on pre-ARM5. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7006 | // Gets the wrong answer for 0, but we already checked for that case above. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7007 | __ CountLeadingZeros(zeros_, source_, mantissa); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7008 | // Compute exponent and or it into the exponent register. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7009 | // We use mantissa as a scratch register here. Use a fudge factor to |
| 7010 | // divide the constant 31 + HeapNumber::kExponentBias, 0x41d, into two parts |
| 7011 | // that fit in the ARM's constant field. |
| 7012 | int fudge = 0x400; |
| 7013 | __ rsb(mantissa, zeros_, Operand(31 + HeapNumber::kExponentBias - fudge)); |
| 7014 | __ add(mantissa, mantissa, Operand(fudge)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7015 | __ orr(exponent, |
| 7016 | exponent, |
| 7017 | Operand(mantissa, LSL, HeapNumber::kExponentShift)); |
| 7018 | // Shift up the source chopping the top bit off. |
| 7019 | __ add(zeros_, zeros_, Operand(1)); |
| 7020 | // This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0. |
| 7021 | __ mov(source_, Operand(source_, LSL, zeros_)); |
| 7022 | // Compute lower part of fraction (last 12 bits). |
| 7023 | __ mov(mantissa, Operand(source_, LSL, HeapNumber::kMantissaBitsInTopWord)); |
| 7024 | // And the top (top 20 bits). |
| 7025 | __ orr(exponent, |
| 7026 | exponent, |
| 7027 | Operand(source_, LSR, 32 - HeapNumber::kMantissaBitsInTopWord)); |
| 7028 | __ Ret(); |
| 7029 | } |
| 7030 | |
| 7031 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7032 | // See comment for class. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7033 | void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7034 | Label max_negative_int; |
| 7035 | // the_int_ has the answer which is a signed int32 but not a Smi. |
| 7036 | // We test for the special value that has a different exponent. This test |
| 7037 | // has the neat side effect of setting the flags according to the sign. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7038 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 7039 | __ cmp(the_int_, Operand(0x80000000u)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7040 | __ b(eq, &max_negative_int); |
| 7041 | // Set up the correct exponent in scratch_. All non-Smi int32s have the same. |
| 7042 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). |
| 7043 | uint32_t non_smi_exponent = |
| 7044 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 7045 | __ mov(scratch_, Operand(non_smi_exponent)); |
| 7046 | // Set the sign bit in scratch_ if the value was negative. |
| 7047 | __ orr(scratch_, scratch_, Operand(HeapNumber::kSignMask), LeaveCC, cs); |
| 7048 | // Subtract from 0 if the value was negative. |
| 7049 | __ rsb(the_int_, the_int_, Operand(0), LeaveCC, cs); |
| 7050 | // We should be masking the implict first digit of the mantissa away here, |
| 7051 | // but it just ends up combining harmlessly with the last digit of the |
| 7052 | // exponent that happens to be 1. The sign bit is 0 so we shift 10 to get |
| 7053 | // the most significant 1 to hit the last bit of the 12 bit sign and exponent. |
| 7054 | ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0); |
| 7055 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 7056 | __ orr(scratch_, scratch_, Operand(the_int_, LSR, shift_distance)); |
| 7057 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 7058 | HeapNumber::kExponentOffset)); |
| 7059 | __ mov(scratch_, Operand(the_int_, LSL, 32 - shift_distance)); |
| 7060 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 7061 | HeapNumber::kMantissaOffset)); |
| 7062 | __ Ret(); |
| 7063 | |
| 7064 | __ bind(&max_negative_int); |
| 7065 | // The max negative int32 is stored as a positive number in the mantissa of |
| 7066 | // a double because it uses a sign bit instead of using two's complement. |
| 7067 | // The actual mantissa bits stored are all 0 because the implicit most |
| 7068 | // significant 1 bit is not stored. |
| 7069 | non_smi_exponent += 1 << HeapNumber::kExponentShift; |
| 7070 | __ mov(ip, Operand(HeapNumber::kSignMask | non_smi_exponent)); |
| 7071 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset)); |
| 7072 | __ mov(ip, Operand(0)); |
| 7073 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset)); |
| 7074 | __ Ret(); |
| 7075 | } |
| 7076 | |
| 7077 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7078 | // Handle the case where the lhs and rhs are the same object. |
| 7079 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 7080 | // for "identity and not NaN". |
| 7081 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 7082 | Label* slow, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7083 | Condition cc, |
| 7084 | bool never_nan_nan) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7085 | Label not_identical; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7086 | Label heap_number, return_equal; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7087 | __ cmp(r0, r1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7088 | __ b(ne, ¬_identical); |
| 7089 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7090 | // The two objects are identical. If we know that one of them isn't NaN then |
| 7091 | // we now know they test equal. |
| 7092 | if (cc != eq || !never_nan_nan) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7093 | // Test for NaN. Sadly, we can't just compare to Factory::nan_value(), |
| 7094 | // so we do the second best thing - test it ourselves. |
| 7095 | // They are both equal and they are not both Smis so both of them are not |
| 7096 | // Smis. If it's not a heap number, then return equal. |
| 7097 | if (cc == lt || cc == gt) { |
| 7098 | __ CompareObjectType(r0, r4, r4, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7099 | __ b(ge, slow); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7100 | } else { |
| 7101 | __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE); |
| 7102 | __ b(eq, &heap_number); |
| 7103 | // Comparing JS objects with <=, >= is complicated. |
| 7104 | if (cc != eq) { |
| 7105 | __ cmp(r4, Operand(FIRST_JS_OBJECT_TYPE)); |
| 7106 | __ b(ge, slow); |
| 7107 | // Normally here we fall through to return_equal, but undefined is |
| 7108 | // special: (undefined == undefined) == true, but |
| 7109 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 7110 | if (cc == le || cc == ge) { |
| 7111 | __ cmp(r4, Operand(ODDBALL_TYPE)); |
| 7112 | __ b(ne, &return_equal); |
| 7113 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7114 | __ cmp(r0, r2); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7115 | __ b(ne, &return_equal); |
| 7116 | if (cc == le) { |
| 7117 | // undefined <= undefined should fail. |
| 7118 | __ mov(r0, Operand(GREATER)); |
| 7119 | } else { |
| 7120 | // undefined >= undefined should fail. |
| 7121 | __ mov(r0, Operand(LESS)); |
| 7122 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7123 | __ Ret(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7124 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7125 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7126 | } |
| 7127 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7128 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7129 | __ bind(&return_equal); |
| 7130 | if (cc == lt) { |
| 7131 | __ mov(r0, Operand(GREATER)); // Things aren't less than themselves. |
| 7132 | } else if (cc == gt) { |
| 7133 | __ mov(r0, Operand(LESS)); // Things aren't greater than themselves. |
| 7134 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7135 | __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7136 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7137 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7138 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7139 | if (cc != eq || !never_nan_nan) { |
| 7140 | // For less and greater we don't have to check for NaN since the result of |
| 7141 | // x < x is false regardless. For the others here is some code to check |
| 7142 | // for NaN. |
| 7143 | if (cc != lt && cc != gt) { |
| 7144 | __ bind(&heap_number); |
| 7145 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 7146 | // not NaN. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7147 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7148 | // The representation of NaN values has all exponent bits (52..62) set, |
| 7149 | // and not all mantissa bits (0..51) clear. |
| 7150 | // Read top bits of double representation (second word of value). |
| 7151 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 7152 | // Test that exponent bits are all set. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7153 | __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 7154 | // NaNs have all-one exponents so they sign extend to -1. |
| 7155 | __ cmp(r3, Operand(-1)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7156 | __ b(ne, &return_equal); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7157 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7158 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 7159 | __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 7160 | // Or with all low-bits of mantissa. |
| 7161 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 7162 | __ orr(r0, r3, Operand(r2), SetCC); |
| 7163 | // For equal we already have the right value in r0: Return zero (equal) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7164 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 7165 | // not (it's a NaN). For <= and >= we need to load r0 with the failing |
| 7166 | // value if it's a NaN. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7167 | if (cc != eq) { |
| 7168 | // All-zero means Infinity means equal. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7169 | __ Ret(eq); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7170 | if (cc == le) { |
| 7171 | __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail. |
| 7172 | } else { |
| 7173 | __ mov(r0, Operand(LESS)); // NaN >= NaN should fail. |
| 7174 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7175 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7176 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7177 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7178 | // No fall through here. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7179 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7180 | |
| 7181 | __ bind(¬_identical); |
| 7182 | } |
| 7183 | |
| 7184 | |
| 7185 | // See comment at call site. |
| 7186 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7187 | Register lhs, |
| 7188 | Register rhs, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7189 | Label* lhs_not_nan, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7190 | Label* slow, |
| 7191 | bool strict) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7192 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 7193 | (lhs.is(r1) && rhs.is(r0))); |
| 7194 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7195 | Label rhs_is_smi; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7196 | __ tst(rhs, Operand(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7197 | __ b(eq, &rhs_is_smi); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7198 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7199 | // Lhs is a Smi. Check whether the rhs is a heap number. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7200 | __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7201 | if (strict) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7202 | // If rhs is not a number and lhs is a Smi then strict equality cannot |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7203 | // succeed. Return non-equal |
| 7204 | // If rhs is r0 then there is already a non zero value in it. |
| 7205 | if (!rhs.is(r0)) { |
| 7206 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 7207 | } |
| 7208 | __ Ret(ne); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7209 | } else { |
| 7210 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 7211 | // the runtime. |
| 7212 | __ b(ne, slow); |
| 7213 | } |
| 7214 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7215 | // Lhs is a smi, rhs is a number. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7216 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7217 | // Convert lhs to a double in d7. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7218 | CpuFeatures::Scope scope(VFP3); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7219 | __ SmiToDoubleVFPRegister(lhs, d7, r7, s15); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7220 | // Load the double from rhs, tagged HeapNumber r0, to d6. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7221 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7222 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7223 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7224 | __ push(lr); |
| 7225 | // Convert lhs to a double in r2, r3. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7226 | __ mov(r7, Operand(lhs)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7227 | ConvertToDoubleStub stub1(r3, r2, r7, r6); |
| 7228 | __ Call(stub1.GetCode(), RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7229 | // Load rhs to a double in r0, r1. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7230 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7231 | __ pop(lr); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7234 | // We now have both loaded as doubles but we can skip the lhs nan check |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7235 | // since it's a smi. |
| 7236 | __ jmp(lhs_not_nan); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7237 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7238 | __ bind(&rhs_is_smi); |
| 7239 | // Rhs is a smi. Check whether the non-smi lhs is a heap number. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7240 | __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7241 | if (strict) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7242 | // If lhs is not a number and rhs is a smi then strict equality cannot |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7243 | // succeed. Return non-equal. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7244 | // If lhs is r0 then there is already a non zero value in it. |
| 7245 | if (!lhs.is(r0)) { |
| 7246 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 7247 | } |
| 7248 | __ Ret(ne); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7249 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7250 | // Smi compared non-strictly with a non-smi non-heap-number. Call |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7251 | // the runtime. |
| 7252 | __ b(ne, slow); |
| 7253 | } |
| 7254 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7255 | // Rhs is a smi, lhs is a heap number. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7256 | if (CpuFeatures::IsSupported(VFP3)) { |
| 7257 | CpuFeatures::Scope scope(VFP3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7258 | // Load the double from lhs, tagged HeapNumber r1, to d7. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7259 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7260 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7261 | // Convert rhs to a double in d6 . |
| 7262 | __ SmiToDoubleVFPRegister(rhs, d6, r7, s13); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7263 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7264 | __ push(lr); |
| 7265 | // Load lhs to a double in r2, r3. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7266 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7267 | // Convert rhs to a double in r0, r1. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7268 | __ mov(r7, Operand(rhs)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7269 | ConvertToDoubleStub stub2(r1, r0, r7, r6); |
| 7270 | __ Call(stub2.GetCode(), RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7271 | __ pop(lr); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7272 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7273 | // Fall through to both_loaded_as_doubles. |
| 7274 | } |
| 7275 | |
| 7276 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7277 | void EmitNanCheck(MacroAssembler* masm, Label* lhs_not_nan, Condition cc) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7278 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7279 | Register rhs_exponent = exp_first ? r0 : r1; |
| 7280 | Register lhs_exponent = exp_first ? r2 : r3; |
| 7281 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 7282 | Register lhs_mantissa = exp_first ? r3 : r2; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7283 | Label one_is_nan, neither_is_nan; |
| 7284 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7285 | __ Sbfx(r4, |
| 7286 | lhs_exponent, |
| 7287 | HeapNumber::kExponentShift, |
| 7288 | HeapNumber::kExponentBits); |
| 7289 | // NaNs have all-one exponents so they sign extend to -1. |
| 7290 | __ cmp(r4, Operand(-1)); |
| 7291 | __ b(ne, lhs_not_nan); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7292 | __ mov(r4, |
| 7293 | Operand(lhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 7294 | SetCC); |
| 7295 | __ b(ne, &one_is_nan); |
| 7296 | __ cmp(lhs_mantissa, Operand(0)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7297 | __ b(ne, &one_is_nan); |
| 7298 | |
| 7299 | __ bind(lhs_not_nan); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7300 | __ Sbfx(r4, |
| 7301 | rhs_exponent, |
| 7302 | HeapNumber::kExponentShift, |
| 7303 | HeapNumber::kExponentBits); |
| 7304 | // NaNs have all-one exponents so they sign extend to -1. |
| 7305 | __ cmp(r4, Operand(-1)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7306 | __ b(ne, &neither_is_nan); |
| 7307 | __ mov(r4, |
| 7308 | Operand(rhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 7309 | SetCC); |
| 7310 | __ b(ne, &one_is_nan); |
| 7311 | __ cmp(rhs_mantissa, Operand(0)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7312 | __ b(eq, &neither_is_nan); |
| 7313 | |
| 7314 | __ bind(&one_is_nan); |
| 7315 | // NaN comparisons always fail. |
| 7316 | // Load whatever we need in r0 to make the comparison fail. |
| 7317 | if (cc == lt || cc == le) { |
| 7318 | __ mov(r0, Operand(GREATER)); |
| 7319 | } else { |
| 7320 | __ mov(r0, Operand(LESS)); |
| 7321 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7322 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7323 | |
| 7324 | __ bind(&neither_is_nan); |
| 7325 | } |
| 7326 | |
| 7327 | |
| 7328 | // See comment at call site. |
| 7329 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cc) { |
| 7330 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7331 | Register rhs_exponent = exp_first ? r0 : r1; |
| 7332 | Register lhs_exponent = exp_first ? r2 : r3; |
| 7333 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 7334 | Register lhs_mantissa = exp_first ? r3 : r2; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7335 | |
| 7336 | // r0, r1, r2, r3 have the two doubles. Neither is a NaN. |
| 7337 | if (cc == eq) { |
| 7338 | // Doubles are not equal unless they have the same bit pattern. |
| 7339 | // Exception: 0 and -0. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7340 | __ cmp(rhs_mantissa, Operand(lhs_mantissa)); |
| 7341 | __ orr(r0, rhs_mantissa, Operand(lhs_mantissa), LeaveCC, ne); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7342 | // Return non-zero if the numbers are unequal. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7343 | __ Ret(ne); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7344 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7345 | __ sub(r0, rhs_exponent, Operand(lhs_exponent), SetCC); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7346 | // If exponents are equal then return 0. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7347 | __ Ret(eq); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7348 | |
| 7349 | // Exponents are unequal. The only way we can return that the numbers |
| 7350 | // are equal is if one is -0 and the other is 0. We already dealt |
| 7351 | // with the case where both are -0 or both are 0. |
| 7352 | // We start by seeing if the mantissas (that are equal) or the bottom |
| 7353 | // 31 bits of the rhs exponent are non-zero. If so we return not |
| 7354 | // equal. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7355 | __ orr(r4, lhs_mantissa, Operand(lhs_exponent, LSL, kSmiTagSize), SetCC); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7356 | __ mov(r0, Operand(r4), LeaveCC, ne); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7357 | __ Ret(ne); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7358 | // Now they are equal if and only if the lhs exponent is zero in its |
| 7359 | // low 31 bits. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7360 | __ mov(r0, Operand(rhs_exponent, LSL, kSmiTagSize)); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7361 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7362 | } else { |
| 7363 | // Call a native function to do a comparison between two non-NaNs. |
| 7364 | // Call C routine that may not cause GC or other trouble. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 7365 | __ push(lr); |
| 7366 | __ PrepareCallCFunction(4, r5); // Two doubles count as 4 arguments. |
| 7367 | __ CallCFunction(ExternalReference::compare_doubles(), 4); |
| 7368 | __ pop(pc); // Return. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7369 | } |
| 7370 | } |
| 7371 | |
| 7372 | |
| 7373 | // See comment at call site. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7374 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 7375 | Register lhs, |
| 7376 | Register rhs) { |
| 7377 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 7378 | (lhs.is(r1) && rhs.is(r0))); |
| 7379 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7380 | // If either operand is a JSObject or an oddball value, then they are |
| 7381 | // not equal since their pointers are different. |
| 7382 | // There is no test for undetectability in strict equality. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7383 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7384 | Label first_non_object; |
| 7385 | // Get the type of the first operand into r2 and compare it with |
| 7386 | // FIRST_JS_OBJECT_TYPE. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7387 | __ CompareObjectType(rhs, r2, r2, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7388 | __ b(lt, &first_non_object); |
| 7389 | |
| 7390 | // Return non-zero (r0 is not zero) |
| 7391 | Label return_not_equal; |
| 7392 | __ bind(&return_not_equal); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7393 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7394 | |
| 7395 | __ bind(&first_non_object); |
| 7396 | // Check for oddballs: true, false, null, undefined. |
| 7397 | __ cmp(r2, Operand(ODDBALL_TYPE)); |
| 7398 | __ b(eq, &return_not_equal); |
| 7399 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7400 | __ CompareObjectType(lhs, r3, r3, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7401 | __ b(ge, &return_not_equal); |
| 7402 | |
| 7403 | // Check for oddballs: true, false, null, undefined. |
| 7404 | __ cmp(r3, Operand(ODDBALL_TYPE)); |
| 7405 | __ b(eq, &return_not_equal); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7406 | |
| 7407 | // Now that we have the types we might as well check for symbol-symbol. |
| 7408 | // Ensure that no non-strings have the symbol bit set. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7409 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 7410 | STATIC_ASSERT(kSymbolTag != 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7411 | __ and_(r2, r2, Operand(r3)); |
| 7412 | __ tst(r2, Operand(kIsSymbolMask)); |
| 7413 | __ b(ne, &return_not_equal); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
| 7416 | |
| 7417 | // See comment at call site. |
| 7418 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7419 | Register lhs, |
| 7420 | Register rhs, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7421 | Label* both_loaded_as_doubles, |
| 7422 | Label* not_heap_numbers, |
| 7423 | Label* slow) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7424 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 7425 | (lhs.is(r1) && rhs.is(r0))); |
| 7426 | |
| 7427 | __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7428 | __ b(ne, not_heap_numbers); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7429 | __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7430 | __ cmp(r2, r3); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7431 | __ b(ne, slow); // First was a heap number, second wasn't. Go slow case. |
| 7432 | |
| 7433 | // Both are heap numbers. Load them up then jump to the code we have |
| 7434 | // for that. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7435 | if (CpuFeatures::IsSupported(VFP3)) { |
| 7436 | CpuFeatures::Scope scope(VFP3); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7437 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7438 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7439 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7440 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 7441 | } else { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7442 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 7443 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7444 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7445 | __ jmp(both_loaded_as_doubles); |
| 7446 | } |
| 7447 | |
| 7448 | |
| 7449 | // Fast negative check for symbol-to-symbol equality. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7450 | static void EmitCheckForSymbolsOrObjects(MacroAssembler* masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7451 | Register lhs, |
| 7452 | Register rhs, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7453 | Label* possible_strings, |
| 7454 | Label* not_both_strings) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7455 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 7456 | (lhs.is(r1) && rhs.is(r0))); |
| 7457 | |
| 7458 | // r2 is object type of rhs. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7459 | // Ensure that no non-strings have the symbol bit set. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7460 | Label object_test; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7461 | STATIC_ASSERT(kSymbolTag != 0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7462 | __ tst(r2, Operand(kIsNotStringMask)); |
| 7463 | __ b(ne, &object_test); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7464 | __ tst(r2, Operand(kIsSymbolMask)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7465 | __ b(eq, possible_strings); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7466 | __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7467 | __ b(ge, not_both_strings); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7468 | __ tst(r3, Operand(kIsSymbolMask)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7469 | __ b(eq, possible_strings); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7470 | |
| 7471 | // Both are symbols. We already checked they weren't the same pointer |
| 7472 | // so they are not equal. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7473 | __ mov(r0, Operand(NOT_EQUAL)); |
| 7474 | __ Ret(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7475 | |
| 7476 | __ bind(&object_test); |
| 7477 | __ cmp(r2, Operand(FIRST_JS_OBJECT_TYPE)); |
| 7478 | __ b(lt, not_both_strings); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7479 | __ CompareObjectType(lhs, r2, r3, FIRST_JS_OBJECT_TYPE); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7480 | __ b(lt, not_both_strings); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7481 | // If both objects are undetectable, they are equal. Otherwise, they |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7482 | // are not equal, since they are different objects and an object is not |
| 7483 | // equal to undefined. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7484 | __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7485 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 7486 | __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset)); |
| 7487 | __ and_(r0, r2, Operand(r3)); |
| 7488 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 7489 | __ eor(r0, r0, Operand(1 << Map::kIsUndetectable)); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7490 | __ Ret(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7494 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 7495 | Register object, |
| 7496 | Register result, |
| 7497 | Register scratch1, |
| 7498 | Register scratch2, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7499 | Register scratch3, |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7500 | bool object_is_smi, |
| 7501 | Label* not_found) { |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7502 | // Use of registers. Register result is used as a temporary. |
| 7503 | Register number_string_cache = result; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7504 | Register mask = scratch3; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7505 | |
| 7506 | // Load the number string cache. |
| 7507 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 7508 | |
| 7509 | // Make the hash mask from the length of the number string cache. It |
| 7510 | // contains two elements (number and string) for each cache entry. |
| 7511 | __ ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7512 | // Divide length by two (length is a smi). |
| 7513 | __ mov(mask, Operand(mask, ASR, kSmiTagSize + 1)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7514 | __ sub(mask, mask, Operand(1)); // Make mask. |
| 7515 | |
| 7516 | // Calculate the entry in the number string cache. The hash value in the |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7517 | // number string cache for smis is just the smi value, and the hash for |
| 7518 | // doubles is the xor of the upper and lower words. See |
| 7519 | // Heap::GetNumberStringCache. |
| 7520 | Label is_smi; |
| 7521 | Label load_result_from_cache; |
| 7522 | if (!object_is_smi) { |
| 7523 | __ BranchOnSmi(object, &is_smi); |
| 7524 | if (CpuFeatures::IsSupported(VFP3)) { |
| 7525 | CpuFeatures::Scope scope(VFP3); |
| 7526 | __ CheckMap(object, |
| 7527 | scratch1, |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 7528 | Heap::kHeapNumberMapRootIndex, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7529 | not_found, |
| 7530 | true); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7531 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7532 | STATIC_ASSERT(8 == kDoubleSize); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7533 | __ add(scratch1, |
| 7534 | object, |
| 7535 | Operand(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 7536 | __ ldm(ia, scratch1, scratch1.bit() | scratch2.bit()); |
| 7537 | __ eor(scratch1, scratch1, Operand(scratch2)); |
| 7538 | __ and_(scratch1, scratch1, Operand(mask)); |
| 7539 | |
| 7540 | // Calculate address of entry in string cache: each entry consists |
| 7541 | // of two pointer sized fields. |
| 7542 | __ add(scratch1, |
| 7543 | number_string_cache, |
| 7544 | Operand(scratch1, LSL, kPointerSizeLog2 + 1)); |
| 7545 | |
| 7546 | Register probe = mask; |
| 7547 | __ ldr(probe, |
| 7548 | FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
| 7549 | __ BranchOnSmi(probe, not_found); |
| 7550 | __ sub(scratch2, object, Operand(kHeapObjectTag)); |
| 7551 | __ vldr(d0, scratch2, HeapNumber::kValueOffset); |
| 7552 | __ sub(probe, probe, Operand(kHeapObjectTag)); |
| 7553 | __ vldr(d1, probe, HeapNumber::kValueOffset); |
| 7554 | __ vcmp(d0, d1); |
| 7555 | __ vmrs(pc); |
| 7556 | __ b(ne, not_found); // The cache did not contain this value. |
| 7557 | __ b(&load_result_from_cache); |
| 7558 | } else { |
| 7559 | __ b(not_found); |
| 7560 | } |
| 7561 | } |
| 7562 | |
| 7563 | __ bind(&is_smi); |
| 7564 | Register scratch = scratch1; |
| 7565 | __ and_(scratch, mask, Operand(object, ASR, 1)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7566 | // Calculate address of entry in string cache: each entry consists |
| 7567 | // of two pointer sized fields. |
| 7568 | __ add(scratch, |
| 7569 | number_string_cache, |
| 7570 | Operand(scratch, LSL, kPointerSizeLog2 + 1)); |
| 7571 | |
| 7572 | // Check if the entry is the smi we are looking for. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7573 | Register probe = mask; |
| 7574 | __ ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 7575 | __ cmp(object, probe); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7576 | __ b(ne, not_found); |
| 7577 | |
| 7578 | // Get the result from the cache. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7579 | __ bind(&load_result_from_cache); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7580 | __ ldr(result, |
| 7581 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7582 | __ IncrementCounter(&Counters::number_to_string_native, |
| 7583 | 1, |
| 7584 | scratch1, |
| 7585 | scratch2); |
| 7586 | } |
| 7587 | |
| 7588 | |
| 7589 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 7590 | Label runtime; |
| 7591 | |
| 7592 | __ ldr(r1, MemOperand(sp, 0)); |
| 7593 | |
| 7594 | // Generate code to lookup number in the number string cache. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7595 | GenerateLookupNumberStringCache(masm, r1, r0, r2, r3, r4, false, &runtime); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7596 | __ add(sp, sp, Operand(1 * kPointerSize)); |
| 7597 | __ Ret(); |
| 7598 | |
| 7599 | __ bind(&runtime); |
| 7600 | // Handle number to string in the runtime system if not found in the cache. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7601 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7605 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7606 | __ add(offset_, object_, Operand(offset_)); |
| 7607 | __ RecordWriteHelper(object_, offset_, scratch_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7608 | __ Ret(); |
| 7609 | } |
| 7610 | |
| 7611 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7612 | // On entry lhs_ and rhs_ are the values to be compared. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7613 | // On exit r0 is 0, positive or negative to indicate the result of |
| 7614 | // the comparison. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7615 | void CompareStub::Generate(MacroAssembler* masm) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7616 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 7617 | (lhs_.is(r1) && rhs_.is(r0))); |
| 7618 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7619 | Label slow; // Call builtin. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7620 | Label not_smis, both_loaded_as_doubles, lhs_not_nan; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7621 | |
| 7622 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 7623 | // it is certain that at least one operand isn't a smi. |
| 7624 | |
| 7625 | // Handle the case where the objects are identical. Either returns the answer |
| 7626 | // or goes to slow. Only falls through if the objects were not identical. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7627 | EmitIdenticalObjectComparison(masm, &slow, cc_, never_nan_nan_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7628 | |
| 7629 | // If either is a Smi (we know that not both are), then they can only |
| 7630 | // be strictly equal if the other is a HeapNumber. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 7631 | STATIC_ASSERT(kSmiTag == 0); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7632 | ASSERT_EQ(0, Smi::FromInt(0)); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7633 | __ and_(r2, lhs_, Operand(rhs_)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7634 | __ tst(r2, Operand(kSmiTagMask)); |
| 7635 | __ b(ne, ¬_smis); |
| 7636 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 7637 | // 1) Return the answer. |
| 7638 | // 2) Go to slow. |
| 7639 | // 3) Fall through to both_loaded_as_doubles. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7640 | // 4) Jump to lhs_not_nan. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7641 | // In cases 3 and 4 we have found out we were dealing with a number-number |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7642 | // comparison. If VFP3 is supported the double values of the numbers have |
| 7643 | // been loaded into d7 and d6. Otherwise, the double values have been loaded |
| 7644 | // into r0, r1, r2, and r3. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7645 | EmitSmiNonsmiComparison(masm, lhs_, rhs_, &lhs_not_nan, &slow, strict_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7646 | |
| 7647 | __ bind(&both_loaded_as_doubles); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7648 | // The arguments have been converted to doubles and stored in d6 and d7, if |
| 7649 | // VFP3 is supported, or in r0, r1, r2, and r3. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7650 | if (CpuFeatures::IsSupported(VFP3)) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7651 | __ bind(&lhs_not_nan); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7652 | CpuFeatures::Scope scope(VFP3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7653 | Label no_nan; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7654 | // ARMv7 VFP3 instructions to implement double precision comparison. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7655 | __ vcmp(d7, d6); |
| 7656 | __ vmrs(pc); // Move vector status bits to normal status bits. |
| 7657 | Label nan; |
| 7658 | __ b(vs, &nan); |
| 7659 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 7660 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 7661 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7662 | __ Ret(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7663 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7664 | __ bind(&nan); |
| 7665 | // If one of the sides was a NaN then the v flag is set. Load r0 with |
| 7666 | // whatever it takes to make the comparison fail, since comparisons with NaN |
| 7667 | // always fail. |
| 7668 | if (cc_ == lt || cc_ == le) { |
| 7669 | __ mov(r0, Operand(GREATER)); |
| 7670 | } else { |
| 7671 | __ mov(r0, Operand(LESS)); |
| 7672 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7673 | __ Ret(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7674 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7675 | // Checks for NaN in the doubles we have loaded. Can return the answer or |
| 7676 | // fall through if neither is a NaN. Also binds lhs_not_nan. |
| 7677 | EmitNanCheck(masm, &lhs_not_nan, cc_); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7678 | // Compares two doubles in r0, r1, r2, r3 that are not NaNs. Returns the |
| 7679 | // answer. Never falls through. |
| 7680 | EmitTwoNonNanDoubleComparison(masm, cc_); |
| 7681 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7682 | |
| 7683 | __ bind(¬_smis); |
| 7684 | // At this point we know we are dealing with two different objects, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7685 | // and neither of them is a Smi. The objects are in rhs_ and lhs_. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7686 | if (strict_) { |
| 7687 | // This returns non-equal for some object types, or falls through if it |
| 7688 | // was not lucky. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7689 | EmitStrictTwoHeapObjectCompare(masm, lhs_, rhs_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | Label check_for_symbols; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7693 | Label flat_string_check; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7694 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 7695 | // or load both doubles into r0, r1, r2, r3 and jump to the code that handles |
| 7696 | // that case. If the inputs are not doubles then jumps to check_for_symbols. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7697 | // In this case r2 will contain the type of rhs_. Never falls through. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7698 | EmitCheckForTwoHeapNumbers(masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7699 | lhs_, |
| 7700 | rhs_, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7701 | &both_loaded_as_doubles, |
| 7702 | &check_for_symbols, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7703 | &flat_string_check); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7704 | |
| 7705 | __ bind(&check_for_symbols); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7706 | // In the strict case the EmitStrictTwoHeapObjectCompare already took care of |
| 7707 | // symbols. |
| 7708 | if (cc_ == eq && !strict_) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7709 | // Returns an answer for two symbols or two detectable objects. |
| 7710 | // Otherwise jumps to string case or not both strings case. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7711 | // Assumes that r2 is the type of rhs_ on entry. |
| 7712 | EmitCheckForSymbolsOrObjects(masm, lhs_, rhs_, &flat_string_check, &slow); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7713 | } |
| 7714 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7715 | // Check for both being sequential ASCII strings, and inline if that is the |
| 7716 | // case. |
| 7717 | __ bind(&flat_string_check); |
| 7718 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7719 | __ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs_, rhs_, r2, r3, &slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7720 | |
| 7721 | __ IncrementCounter(&Counters::string_compare_native, 1, r2, r3); |
| 7722 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7723 | lhs_, |
| 7724 | rhs_, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7725 | r2, |
| 7726 | r3, |
| 7727 | r4, |
| 7728 | r5); |
| 7729 | // Never falls through to here. |
| 7730 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7731 | __ bind(&slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7732 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 7733 | __ Push(lhs_, rhs_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7734 | // Figure out which native to call and setup the arguments. |
| 7735 | Builtins::JavaScript native; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7736 | if (cc_ == eq) { |
| 7737 | native = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 7738 | } else { |
| 7739 | native = Builtins::COMPARE; |
| 7740 | int ncr; // NaN compare result |
| 7741 | if (cc_ == lt || cc_ == le) { |
| 7742 | ncr = GREATER; |
| 7743 | } else { |
| 7744 | ASSERT(cc_ == gt || cc_ == ge); // remaining cases |
| 7745 | ncr = LESS; |
| 7746 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7747 | __ mov(r0, Operand(Smi::FromInt(ncr))); |
| 7748 | __ push(r0); |
| 7749 | } |
| 7750 | |
| 7751 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 7752 | // tagged as a small integer. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7753 | __ InvokeBuiltin(native, JUMP_JS); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7754 | } |
| 7755 | |
| 7756 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 7757 | // We fall into this code if the operands were Smis, but the result was |
| 7758 | // not (eg. overflow). We branch into this code (to the not_smi label) if |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7759 | // the operands were not both Smi. The operands are in r0 and r1. In order |
| 7760 | // to call the C-implemented binary fp operation routines we need to end up |
| 7761 | // with the double precision floating point operands in r0 and r1 (for the |
| 7762 | // value in r1) and r2 and r3 (for the value in r0). |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7763 | void GenericBinaryOpStub::HandleBinaryOpSlowCases( |
| 7764 | MacroAssembler* masm, |
| 7765 | Label* not_smi, |
| 7766 | Register lhs, |
| 7767 | Register rhs, |
| 7768 | const Builtins::JavaScript& builtin) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7769 | Label slow, slow_reverse, do_the_call; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7770 | bool use_fp_registers = CpuFeatures::IsSupported(VFP3) && Token::MOD != op_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7771 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 7772 | ASSERT((lhs.is(r0) && rhs.is(r1)) || (lhs.is(r1) && rhs.is(r0))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7773 | Register heap_number_map = r6; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7774 | |
| 7775 | if (ShouldGenerateSmiCode()) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7776 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 7777 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7778 | // Smi-smi case (overflow). |
| 7779 | // Since both are Smis there is no heap number to overwrite, so allocate. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7780 | // The new heap number is in r5. r3 and r7 are scratch. |
| 7781 | __ AllocateHeapNumber( |
| 7782 | r5, r3, r7, heap_number_map, lhs.is(r0) ? &slow_reverse : &slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7783 | |
| 7784 | // If we have floating point hardware, inline ADD, SUB, MUL, and DIV, |
| 7785 | // using registers d7 and d6 for the double values. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7786 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7787 | CpuFeatures::Scope scope(VFP3); |
| 7788 | __ mov(r7, Operand(rhs, ASR, kSmiTagSize)); |
| 7789 | __ vmov(s15, r7); |
| 7790 | __ vcvt_f64_s32(d7, s15); |
| 7791 | __ mov(r7, Operand(lhs, ASR, kSmiTagSize)); |
| 7792 | __ vmov(s13, r7); |
| 7793 | __ vcvt_f64_s32(d6, s13); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7794 | if (!use_fp_registers) { |
| 7795 | __ vmov(r2, r3, d7); |
| 7796 | __ vmov(r0, r1, d6); |
| 7797 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7798 | } else { |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7799 | // Write Smi from rhs to r3 and r2 in double format. r9 is scratch. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7800 | __ mov(r7, Operand(rhs)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7801 | ConvertToDoubleStub stub1(r3, r2, r7, r9); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7802 | __ push(lr); |
| 7803 | __ Call(stub1.GetCode(), RelocInfo::CODE_TARGET); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7804 | // Write Smi from lhs to r1 and r0 in double format. r9 is scratch. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7805 | __ mov(r7, Operand(lhs)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7806 | ConvertToDoubleStub stub2(r1, r0, r7, r9); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7807 | __ Call(stub2.GetCode(), RelocInfo::CODE_TARGET); |
| 7808 | __ pop(lr); |
| 7809 | } |
| 7810 | __ jmp(&do_the_call); // Tail call. No return. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7811 | } |
| 7812 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7813 | // We branch here if at least one of r0 and r1 is not a Smi. |
| 7814 | __ bind(not_smi); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7815 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 7816 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7817 | // After this point we have the left hand side in r1 and the right hand side |
| 7818 | // in r0. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7819 | if (lhs.is(r0)) { |
| 7820 | __ Swap(r0, r1, ip); |
| 7821 | } |
| 7822 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7823 | // The type transition also calculates the answer. |
| 7824 | bool generate_code_to_calculate_answer = true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7825 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7826 | if (ShouldGenerateFPCode()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7827 | if (runtime_operands_type_ == BinaryOpIC::DEFAULT) { |
| 7828 | switch (op_) { |
| 7829 | case Token::ADD: |
| 7830 | case Token::SUB: |
| 7831 | case Token::MUL: |
| 7832 | case Token::DIV: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7833 | GenerateTypeTransition(masm); // Tail call. |
| 7834 | generate_code_to_calculate_answer = false; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7835 | break; |
| 7836 | |
| 7837 | default: |
| 7838 | break; |
| 7839 | } |
| 7840 | } |
| 7841 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7842 | if (generate_code_to_calculate_answer) { |
| 7843 | Label r0_is_smi, r1_is_smi, finished_loading_r0, finished_loading_r1; |
| 7844 | if (mode_ == NO_OVERWRITE) { |
| 7845 | // In the case where there is no chance of an overwritable float we may |
| 7846 | // as well do the allocation immediately while r0 and r1 are untouched. |
| 7847 | __ AllocateHeapNumber(r5, r3, r7, heap_number_map, &slow); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7848 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7849 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7850 | // Move r0 to a double in r2-r3. |
| 7851 | __ tst(r0, Operand(kSmiTagMask)); |
| 7852 | __ b(eq, &r0_is_smi); // It's a Smi so don't check it's a heap number. |
| 7853 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 7854 | __ AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 7855 | __ cmp(r4, heap_number_map); |
| 7856 | __ b(ne, &slow); |
| 7857 | if (mode_ == OVERWRITE_RIGHT) { |
| 7858 | __ mov(r5, Operand(r0)); // Overwrite this heap number. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 7859 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7860 | if (use_fp_registers) { |
| 7861 | CpuFeatures::Scope scope(VFP3); |
| 7862 | // Load the double from tagged HeapNumber r0 to d7. |
| 7863 | __ sub(r7, r0, Operand(kHeapObjectTag)); |
| 7864 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7865 | } else { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7866 | // Calling convention says that second double is in r2 and r3. |
| 7867 | __ Ldrd(r2, r3, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7868 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7869 | __ jmp(&finished_loading_r0); |
| 7870 | __ bind(&r0_is_smi); |
| 7871 | if (mode_ == OVERWRITE_RIGHT) { |
| 7872 | // We can't overwrite a Smi so get address of new heap number into r5. |
| 7873 | __ AllocateHeapNumber(r5, r4, r7, heap_number_map, &slow); |
| 7874 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7875 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7876 | if (CpuFeatures::IsSupported(VFP3)) { |
| 7877 | CpuFeatures::Scope scope(VFP3); |
| 7878 | // Convert smi in r0 to double in d7. |
| 7879 | __ mov(r7, Operand(r0, ASR, kSmiTagSize)); |
| 7880 | __ vmov(s15, r7); |
| 7881 | __ vcvt_f64_s32(d7, s15); |
| 7882 | if (!use_fp_registers) { |
| 7883 | __ vmov(r2, r3, d7); |
| 7884 | } |
| 7885 | } else { |
| 7886 | // Write Smi from r0 to r3 and r2 in double format. |
| 7887 | __ mov(r7, Operand(r0)); |
| 7888 | ConvertToDoubleStub stub3(r3, r2, r7, r4); |
| 7889 | __ push(lr); |
| 7890 | __ Call(stub3.GetCode(), RelocInfo::CODE_TARGET); |
| 7891 | __ pop(lr); |
| 7892 | } |
| 7893 | |
| 7894 | // HEAP_NUMBERS stub is slower than GENERIC on a pair of smis. |
| 7895 | // r0 is known to be a smi. If r1 is also a smi then switch to GENERIC. |
| 7896 | Label r1_is_not_smi; |
| 7897 | if (runtime_operands_type_ == BinaryOpIC::HEAP_NUMBERS) { |
| 7898 | __ tst(r1, Operand(kSmiTagMask)); |
| 7899 | __ b(ne, &r1_is_not_smi); |
| 7900 | GenerateTypeTransition(masm); // Tail call. |
| 7901 | } |
| 7902 | |
| 7903 | __ bind(&finished_loading_r0); |
| 7904 | |
| 7905 | // Move r1 to a double in r0-r1. |
| 7906 | __ tst(r1, Operand(kSmiTagMask)); |
| 7907 | __ b(eq, &r1_is_smi); // It's a Smi so don't check it's a heap number. |
| 7908 | __ bind(&r1_is_not_smi); |
| 7909 | __ ldr(r4, FieldMemOperand(r1, HeapNumber::kMapOffset)); |
| 7910 | __ AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 7911 | __ cmp(r4, heap_number_map); |
| 7912 | __ b(ne, &slow); |
| 7913 | if (mode_ == OVERWRITE_LEFT) { |
| 7914 | __ mov(r5, Operand(r1)); // Overwrite this heap number. |
| 7915 | } |
| 7916 | if (use_fp_registers) { |
| 7917 | CpuFeatures::Scope scope(VFP3); |
| 7918 | // Load the double from tagged HeapNumber r1 to d6. |
| 7919 | __ sub(r7, r1, Operand(kHeapObjectTag)); |
| 7920 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 7921 | } else { |
| 7922 | // Calling convention says that first double is in r0 and r1. |
| 7923 | __ Ldrd(r0, r1, FieldMemOperand(r1, HeapNumber::kValueOffset)); |
| 7924 | } |
| 7925 | __ jmp(&finished_loading_r1); |
| 7926 | __ bind(&r1_is_smi); |
| 7927 | if (mode_ == OVERWRITE_LEFT) { |
| 7928 | // We can't overwrite a Smi so get address of new heap number into r5. |
| 7929 | __ AllocateHeapNumber(r5, r4, r7, heap_number_map, &slow); |
| 7930 | } |
| 7931 | |
| 7932 | if (CpuFeatures::IsSupported(VFP3)) { |
| 7933 | CpuFeatures::Scope scope(VFP3); |
| 7934 | // Convert smi in r1 to double in d6. |
| 7935 | __ mov(r7, Operand(r1, ASR, kSmiTagSize)); |
| 7936 | __ vmov(s13, r7); |
| 7937 | __ vcvt_f64_s32(d6, s13); |
| 7938 | if (!use_fp_registers) { |
| 7939 | __ vmov(r0, r1, d6); |
| 7940 | } |
| 7941 | } else { |
| 7942 | // Write Smi from r1 to r1 and r0 in double format. |
| 7943 | __ mov(r7, Operand(r1)); |
| 7944 | ConvertToDoubleStub stub4(r1, r0, r7, r9); |
| 7945 | __ push(lr); |
| 7946 | __ Call(stub4.GetCode(), RelocInfo::CODE_TARGET); |
| 7947 | __ pop(lr); |
| 7948 | } |
| 7949 | |
| 7950 | __ bind(&finished_loading_r1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 7951 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7952 | |
| 7953 | if (generate_code_to_calculate_answer || do_the_call.is_linked()) { |
| 7954 | __ bind(&do_the_call); |
| 7955 | // If we are inlining the operation using VFP3 instructions for |
| 7956 | // add, subtract, multiply, or divide, the arguments are in d6 and d7. |
| 7957 | if (use_fp_registers) { |
| 7958 | CpuFeatures::Scope scope(VFP3); |
| 7959 | // ARMv7 VFP3 instructions to implement |
| 7960 | // double precision, add, subtract, multiply, divide. |
| 7961 | |
| 7962 | if (Token::MUL == op_) { |
| 7963 | __ vmul(d5, d6, d7); |
| 7964 | } else if (Token::DIV == op_) { |
| 7965 | __ vdiv(d5, d6, d7); |
| 7966 | } else if (Token::ADD == op_) { |
| 7967 | __ vadd(d5, d6, d7); |
| 7968 | } else if (Token::SUB == op_) { |
| 7969 | __ vsub(d5, d6, d7); |
| 7970 | } else { |
| 7971 | UNREACHABLE(); |
| 7972 | } |
| 7973 | __ sub(r0, r5, Operand(kHeapObjectTag)); |
| 7974 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 7975 | __ add(r0, r0, Operand(kHeapObjectTag)); |
| 7976 | __ mov(pc, lr); |
| 7977 | } else { |
| 7978 | // If we did not inline the operation, then the arguments are in: |
| 7979 | // r0: Left value (least significant part of mantissa). |
| 7980 | // r1: Left value (sign, exponent, top of mantissa). |
| 7981 | // r2: Right value (least significant part of mantissa). |
| 7982 | // r3: Right value (sign, exponent, top of mantissa). |
| 7983 | // r5: Address of heap number for result. |
| 7984 | |
| 7985 | __ push(lr); // For later. |
| 7986 | __ PrepareCallCFunction(4, r4); // Two doubles count as 4 arguments. |
| 7987 | // Call C routine that may not cause GC or other trouble. r5 is callee |
| 7988 | // save. |
| 7989 | __ CallCFunction(ExternalReference::double_fp_operation(op_), 4); |
| 7990 | // Store answer in the overwritable heap number. |
| 7991 | #if !defined(USE_ARM_EABI) |
| 7992 | // Double returned in fp coprocessor register 0 and 1, encoded as |
| 7993 | // register cr8. Offsets must be divisible by 4 for coprocessor so we |
| 7994 | // need to substract the tag from r5. |
| 7995 | __ sub(r4, r5, Operand(kHeapObjectTag)); |
| 7996 | __ stc(p1, cr8, MemOperand(r4, HeapNumber::kValueOffset)); |
| 7997 | #else |
| 7998 | // Double returned in registers 0 and 1. |
| 7999 | __ Strd(r0, r1, FieldMemOperand(r5, HeapNumber::kValueOffset)); |
| 8000 | #endif |
| 8001 | __ mov(r0, Operand(r5)); |
| 8002 | // And we are done. |
| 8003 | __ pop(pc); |
| 8004 | } |
| 8005 | } |
| 8006 | } |
| 8007 | |
| 8008 | if (!generate_code_to_calculate_answer && |
| 8009 | !slow_reverse.is_linked() && |
| 8010 | !slow.is_linked()) { |
| 8011 | return; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8012 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 8013 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 8014 | if (lhs.is(r0)) { |
| 8015 | __ b(&slow); |
| 8016 | __ bind(&slow_reverse); |
| 8017 | __ Swap(r0, r1, ip); |
| 8018 | } |
| 8019 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8020 | heap_number_map = no_reg; // Don't use this any more from here on. |
| 8021 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8022 | // We jump to here if something goes wrong (one param is not a number of any |
| 8023 | // sort or new-space allocation fails). |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8024 | __ bind(&slow); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8025 | |
| 8026 | // Push arguments to the stack |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 8027 | __ Push(r1, r0); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8028 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8029 | if (Token::ADD == op_) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8030 | // Test for string arguments before calling runtime. |
| 8031 | // r1 : first argument |
| 8032 | // r0 : second argument |
| 8033 | // sp[0] : second argument |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 8034 | // sp[4] : first argument |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8035 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 8036 | Label not_strings, not_string1, string1, string1_smi2; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8037 | __ tst(r1, Operand(kSmiTagMask)); |
| 8038 | __ b(eq, ¬_string1); |
| 8039 | __ CompareObjectType(r1, r2, r2, FIRST_NONSTRING_TYPE); |
| 8040 | __ b(ge, ¬_string1); |
| 8041 | |
| 8042 | // First argument is a a string, test second. |
| 8043 | __ tst(r0, Operand(kSmiTagMask)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 8044 | __ b(eq, &string1_smi2); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8045 | __ CompareObjectType(r0, r2, r2, FIRST_NONSTRING_TYPE); |
| 8046 | __ b(ge, &string1); |
| 8047 | |
| 8048 | // First and second argument are strings. |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 8049 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 8050 | __ TailCallStub(&string_add_stub); |
| 8051 | |
| 8052 | __ bind(&string1_smi2); |
| 8053 | // First argument is a string, second is a smi. Try to lookup the number |
| 8054 | // string for the smi in the number string cache. |
| 8055 | NumberToStringStub::GenerateLookupNumberStringCache( |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 8056 | masm, r0, r2, r4, r5, r6, true, &string1); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 8057 | |
| 8058 | // Replace second argument on stack and tailcall string add stub to make |
| 8059 | // the result. |
| 8060 | __ str(r2, MemOperand(sp, 0)); |
| 8061 | __ TailCallStub(&string_add_stub); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8062 | |
| 8063 | // Only first argument is a string. |
| 8064 | __ bind(&string1); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8065 | __ InvokeBuiltin(Builtins::STRING_ADD_LEFT, JUMP_JS); |
| 8066 | |
| 8067 | // First argument was not a string, test second. |
| 8068 | __ bind(¬_string1); |
| 8069 | __ tst(r0, Operand(kSmiTagMask)); |
| 8070 | __ b(eq, ¬_strings); |
| 8071 | __ CompareObjectType(r0, r2, r2, FIRST_NONSTRING_TYPE); |
| 8072 | __ b(ge, ¬_strings); |
| 8073 | |
| 8074 | // Only second argument is a string. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 8075 | __ InvokeBuiltin(Builtins::STRING_ADD_RIGHT, JUMP_JS); |
| 8076 | |
| 8077 | __ bind(¬_strings); |
| 8078 | } |
| 8079 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8080 | __ InvokeBuiltin(builtin, JUMP_JS); // Tail call. No return. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8084 | // Tries to get a signed int32 out of a double precision floating point heap |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8085 | // number. Rounds towards 0. Fastest for doubles that are in the ranges |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8086 | // -0x7fffffff to -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds |
| 8087 | // almost to the range of signed int32 values that are not Smis. Jumps to the |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8088 | // label 'slow' if the double isn't in the range -0x80000000.0 to 0x80000000.0 |
| 8089 | // (excluding the endpoints). |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8090 | static void GetInt32(MacroAssembler* masm, |
| 8091 | Register source, |
| 8092 | Register dest, |
| 8093 | Register scratch, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8094 | Register scratch2, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8095 | Label* slow) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8096 | Label right_exponent, done; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8097 | // Get exponent word. |
| 8098 | __ ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 8099 | // Get exponent alone in scratch2. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8100 | __ Ubfx(scratch2, |
| 8101 | scratch, |
| 8102 | HeapNumber::kExponentShift, |
| 8103 | HeapNumber::kExponentBits); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8104 | // Load dest with zero. We use this either for the final shift or |
| 8105 | // for the answer. |
| 8106 | __ mov(dest, Operand(0)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8107 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8108 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 8109 | // the exponent that we are fastest at and also the highest exponent we can |
| 8110 | // handle here. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8111 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 8112 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 8113 | // split it up to avoid a constant pool entry. You can't do that in general |
| 8114 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 8115 | // range 0-2047 so there is no overflow. |
| 8116 | int fudge_factor = 0x400; |
| 8117 | __ sub(scratch2, scratch2, Operand(fudge_factor)); |
| 8118 | __ cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8119 | // If we have a match of the int32-but-not-Smi exponent then skip some logic. |
| 8120 | __ b(eq, &right_exponent); |
| 8121 | // If the exponent is higher than that then go to slow case. This catches |
| 8122 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 8123 | __ b(gt, slow); |
| 8124 | |
| 8125 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 8126 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 8127 | // it rounds to zero. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8128 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 8129 | __ sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8130 | // Dest already has a Smi zero. |
| 8131 | __ b(lt, &done); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8132 | if (!CpuFeatures::IsSupported(VFP3)) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8133 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 8134 | // get how much to shift down. |
| 8135 | __ rsb(dest, scratch2, Operand(30)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8136 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8137 | __ bind(&right_exponent); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8138 | if (CpuFeatures::IsSupported(VFP3)) { |
| 8139 | CpuFeatures::Scope scope(VFP3); |
| 8140 | // ARMv7 VFP3 instructions implementing double precision to integer |
| 8141 | // conversion using round to zero. |
| 8142 | __ ldr(scratch2, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 8143 | __ vmov(d7, scratch2, scratch); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 8144 | __ vcvt_s32_f64(s15, d7); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 8145 | __ vmov(dest, s15); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8146 | } else { |
| 8147 | // Get the top bits of the mantissa. |
| 8148 | __ and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 8149 | // Put back the implicit 1. |
| 8150 | __ orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 8151 | // Shift up the mantissa bits to take up the space the exponent used to |
| 8152 | // take. We just orred in the implicit bit so that took care of one and |
| 8153 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 8154 | // distance. |
| 8155 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 8156 | __ mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 8157 | // Put sign in zero flag. |
| 8158 | __ tst(scratch, Operand(HeapNumber::kSignMask)); |
| 8159 | // Get the second half of the double. For some exponents we don't |
| 8160 | // actually need this because the bits get shifted out again, but |
| 8161 | // it's probably slower to test than just to do it. |
| 8162 | __ ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 8163 | // Shift down 22 bits to get the last 10 bits. |
| 8164 | __ orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 8165 | // Move down according to the exponent. |
| 8166 | __ mov(dest, Operand(scratch, LSR, dest)); |
| 8167 | // Fix sign if sign bit was set. |
| 8168 | __ rsb(dest, dest, Operand(0), LeaveCC, ne); |
| 8169 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8170 | __ bind(&done); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8171 | } |
| 8172 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8173 | // For bitwise ops where the inputs are not both Smis we here try to determine |
| 8174 | // whether both inputs are either Smis or at least heap numbers that can be |
| 8175 | // represented by a 32 bit signed value. We truncate towards zero as required |
| 8176 | // by the ES spec. If this is the case we do the bitwise op and see if the |
| 8177 | // result is a Smi. If so, great, otherwise we try to find a heap number to |
| 8178 | // write the answer into (either by allocating or by overwriting). |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8179 | // On entry the operands are in lhs and rhs. On exit the answer is in r0. |
| 8180 | void GenericBinaryOpStub::HandleNonSmiBitwiseOp(MacroAssembler* masm, |
| 8181 | Register lhs, |
| 8182 | Register rhs) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8183 | Label slow, result_not_a_smi; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8184 | Label rhs_is_smi, lhs_is_smi; |
| 8185 | Label done_checking_rhs, done_checking_lhs; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8186 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8187 | Register heap_number_map = r6; |
| 8188 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 8189 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8190 | __ tst(lhs, Operand(kSmiTagMask)); |
| 8191 | __ b(eq, &lhs_is_smi); // It's a Smi so don't check it's a heap number. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8192 | __ ldr(r4, FieldMemOperand(lhs, HeapNumber::kMapOffset)); |
| 8193 | __ cmp(r4, heap_number_map); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8194 | __ b(ne, &slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8195 | GetInt32(masm, lhs, r3, r5, r4, &slow); |
| 8196 | __ jmp(&done_checking_lhs); |
| 8197 | __ bind(&lhs_is_smi); |
| 8198 | __ mov(r3, Operand(lhs, ASR, 1)); |
| 8199 | __ bind(&done_checking_lhs); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8200 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8201 | __ tst(rhs, Operand(kSmiTagMask)); |
| 8202 | __ b(eq, &rhs_is_smi); // It's a Smi so don't check it's a heap number. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8203 | __ ldr(r4, FieldMemOperand(rhs, HeapNumber::kMapOffset)); |
| 8204 | __ cmp(r4, heap_number_map); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8205 | __ b(ne, &slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8206 | GetInt32(masm, rhs, r2, r5, r4, &slow); |
| 8207 | __ jmp(&done_checking_rhs); |
| 8208 | __ bind(&rhs_is_smi); |
| 8209 | __ mov(r2, Operand(rhs, ASR, 1)); |
| 8210 | __ bind(&done_checking_rhs); |
| 8211 | |
| 8212 | ASSERT(((lhs.is(r0) && rhs.is(r1)) || (lhs.is(r1) && rhs.is(r0)))); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8213 | |
| 8214 | // r0 and r1: Original operands (Smi or heap numbers). |
| 8215 | // r2 and r3: Signed int32 operands. |
| 8216 | switch (op_) { |
| 8217 | case Token::BIT_OR: __ orr(r2, r2, Operand(r3)); break; |
| 8218 | case Token::BIT_XOR: __ eor(r2, r2, Operand(r3)); break; |
| 8219 | case Token::BIT_AND: __ and_(r2, r2, Operand(r3)); break; |
| 8220 | case Token::SAR: |
| 8221 | // Use only the 5 least significant bits of the shift count. |
| 8222 | __ and_(r2, r2, Operand(0x1f)); |
| 8223 | __ mov(r2, Operand(r3, ASR, r2)); |
| 8224 | break; |
| 8225 | case Token::SHR: |
| 8226 | // Use only the 5 least significant bits of the shift count. |
| 8227 | __ and_(r2, r2, Operand(0x1f)); |
| 8228 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 8229 | // SHR is special because it is required to produce a positive answer. |
| 8230 | // The code below for writing into heap numbers isn't capable of writing |
| 8231 | // the register as an unsigned int so we go to slow case if we hit this |
| 8232 | // case. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 8233 | if (CpuFeatures::IsSupported(VFP3)) { |
| 8234 | __ b(mi, &result_not_a_smi); |
| 8235 | } else { |
| 8236 | __ b(mi, &slow); |
| 8237 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8238 | break; |
| 8239 | case Token::SHL: |
| 8240 | // Use only the 5 least significant bits of the shift count. |
| 8241 | __ and_(r2, r2, Operand(0x1f)); |
| 8242 | __ mov(r2, Operand(r3, LSL, r2)); |
| 8243 | break; |
| 8244 | default: UNREACHABLE(); |
| 8245 | } |
| 8246 | // check that the *signed* result fits in a smi |
| 8247 | __ add(r3, r2, Operand(0x40000000), SetCC); |
| 8248 | __ b(mi, &result_not_a_smi); |
| 8249 | __ mov(r0, Operand(r2, LSL, kSmiTagSize)); |
| 8250 | __ Ret(); |
| 8251 | |
| 8252 | Label have_to_allocate, got_a_heap_number; |
| 8253 | __ bind(&result_not_a_smi); |
| 8254 | switch (mode_) { |
| 8255 | case OVERWRITE_RIGHT: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8256 | __ tst(rhs, Operand(kSmiTagMask)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8257 | __ b(eq, &have_to_allocate); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8258 | __ mov(r5, Operand(rhs)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8259 | break; |
| 8260 | } |
| 8261 | case OVERWRITE_LEFT: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8262 | __ tst(lhs, Operand(kSmiTagMask)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8263 | __ b(eq, &have_to_allocate); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8264 | __ mov(r5, Operand(lhs)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8265 | break; |
| 8266 | } |
| 8267 | case NO_OVERWRITE: { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8268 | // Get a new heap number in r5. r4 and r7 are scratch. |
| 8269 | __ AllocateHeapNumber(r5, r4, r7, heap_number_map, &slow); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8270 | } |
| 8271 | default: break; |
| 8272 | } |
| 8273 | __ bind(&got_a_heap_number); |
| 8274 | // r2: Answer as signed int32. |
| 8275 | // r5: Heap number to write answer into. |
| 8276 | |
| 8277 | // Nothing can go wrong now, so move the heap number to r0, which is the |
| 8278 | // result. |
| 8279 | __ mov(r0, Operand(r5)); |
| 8280 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 8281 | if (CpuFeatures::IsSupported(VFP3)) { |
| 8282 | // Convert the int32 in r2 to the heap number in r0. r3 is corrupted. |
| 8283 | CpuFeatures::Scope scope(VFP3); |
| 8284 | __ vmov(s0, r2); |
| 8285 | if (op_ == Token::SHR) { |
| 8286 | __ vcvt_f64_u32(d0, s0); |
| 8287 | } else { |
| 8288 | __ vcvt_f64_s32(d0, s0); |
| 8289 | } |
| 8290 | __ sub(r3, r0, Operand(kHeapObjectTag)); |
| 8291 | __ vstr(d0, r3, HeapNumber::kValueOffset); |
| 8292 | __ Ret(); |
| 8293 | } else { |
| 8294 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 8295 | // r3 as scratch. r0 is preserved and returned. |
| 8296 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 8297 | __ TailCallStub(&stub); |
| 8298 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8299 | |
| 8300 | if (mode_ != NO_OVERWRITE) { |
| 8301 | __ bind(&have_to_allocate); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8302 | // Get a new heap number in r5. r4 and r7 are scratch. |
| 8303 | __ AllocateHeapNumber(r5, r4, r7, heap_number_map, &slow); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8304 | __ jmp(&got_a_heap_number); |
| 8305 | } |
| 8306 | |
| 8307 | // If all else failed then we go to the runtime system. |
| 8308 | __ bind(&slow); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 8309 | __ Push(lhs, rhs); // Restore stack. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8310 | switch (op_) { |
| 8311 | case Token::BIT_OR: |
| 8312 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_JS); |
| 8313 | break; |
| 8314 | case Token::BIT_AND: |
| 8315 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_JS); |
| 8316 | break; |
| 8317 | case Token::BIT_XOR: |
| 8318 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_JS); |
| 8319 | break; |
| 8320 | case Token::SAR: |
| 8321 | __ InvokeBuiltin(Builtins::SAR, JUMP_JS); |
| 8322 | break; |
| 8323 | case Token::SHR: |
| 8324 | __ InvokeBuiltin(Builtins::SHR, JUMP_JS); |
| 8325 | break; |
| 8326 | case Token::SHL: |
| 8327 | __ InvokeBuiltin(Builtins::SHL, JUMP_JS); |
| 8328 | break; |
| 8329 | default: |
| 8330 | UNREACHABLE(); |
| 8331 | } |
| 8332 | } |
| 8333 | |
| 8334 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8335 | // Can we multiply by x with max two shifts and an add. |
| 8336 | // This answers yes to all integers from 2 to 10. |
| 8337 | static bool IsEasyToMultiplyBy(int x) { |
| 8338 | if (x < 2) return false; // Avoid special cases. |
| 8339 | if (x > (Smi::kMaxValue + 1) >> 2) return false; // Almost always overflows. |
| 8340 | if (IsPowerOf2(x)) return true; // Simple shift. |
| 8341 | if (PopCountLessThanEqual2(x)) return true; // Shift and add and shift. |
| 8342 | if (IsPowerOf2(x + 1)) return true; // Patterns like 11111. |
| 8343 | return false; |
| 8344 | } |
| 8345 | |
| 8346 | |
| 8347 | // Can multiply by anything that IsEasyToMultiplyBy returns true for. |
| 8348 | // Source and destination may be the same register. This routine does |
| 8349 | // not set carry and overflow the way a mul instruction would. |
| 8350 | static void MultiplyByKnownInt(MacroAssembler* masm, |
| 8351 | Register source, |
| 8352 | Register destination, |
| 8353 | int known_int) { |
| 8354 | if (IsPowerOf2(known_int)) { |
| 8355 | __ mov(destination, Operand(source, LSL, BitPosition(known_int))); |
| 8356 | } else if (PopCountLessThanEqual2(known_int)) { |
| 8357 | int first_bit = BitPosition(known_int); |
| 8358 | int second_bit = BitPosition(known_int ^ (1 << first_bit)); |
| 8359 | __ add(destination, source, Operand(source, LSL, second_bit - first_bit)); |
| 8360 | if (first_bit != 0) { |
| 8361 | __ mov(destination, Operand(destination, LSL, first_bit)); |
| 8362 | } |
| 8363 | } else { |
| 8364 | ASSERT(IsPowerOf2(known_int + 1)); // Patterns like 1111. |
| 8365 | int the_bit = BitPosition(known_int + 1); |
| 8366 | __ rsb(destination, source, Operand(source, LSL, the_bit)); |
| 8367 | } |
| 8368 | } |
| 8369 | |
| 8370 | |
| 8371 | // This function (as opposed to MultiplyByKnownInt) takes the known int in a |
| 8372 | // a register for the cases where it doesn't know a good trick, and may deliver |
| 8373 | // a result that needs shifting. |
| 8374 | static void MultiplyByKnownInt2( |
| 8375 | MacroAssembler* masm, |
| 8376 | Register result, |
| 8377 | Register source, |
| 8378 | Register known_int_register, // Smi tagged. |
| 8379 | int known_int, |
| 8380 | int* required_shift) { // Including Smi tag shift |
| 8381 | switch (known_int) { |
| 8382 | case 3: |
| 8383 | __ add(result, source, Operand(source, LSL, 1)); |
| 8384 | *required_shift = 1; |
| 8385 | break; |
| 8386 | case 5: |
| 8387 | __ add(result, source, Operand(source, LSL, 2)); |
| 8388 | *required_shift = 1; |
| 8389 | break; |
| 8390 | case 6: |
| 8391 | __ add(result, source, Operand(source, LSL, 1)); |
| 8392 | *required_shift = 2; |
| 8393 | break; |
| 8394 | case 7: |
| 8395 | __ rsb(result, source, Operand(source, LSL, 3)); |
| 8396 | *required_shift = 1; |
| 8397 | break; |
| 8398 | case 9: |
| 8399 | __ add(result, source, Operand(source, LSL, 3)); |
| 8400 | *required_shift = 1; |
| 8401 | break; |
| 8402 | case 10: |
| 8403 | __ add(result, source, Operand(source, LSL, 2)); |
| 8404 | *required_shift = 2; |
| 8405 | break; |
| 8406 | default: |
| 8407 | ASSERT(!IsPowerOf2(known_int)); // That would be very inefficient. |
| 8408 | __ mul(result, source, known_int_register); |
| 8409 | *required_shift = 0; |
| 8410 | } |
| 8411 | } |
| 8412 | |
| 8413 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8414 | // This uses versions of the sum-of-digits-to-see-if-a-number-is-divisible-by-3 |
| 8415 | // trick. See http://en.wikipedia.org/wiki/Divisibility_rule |
| 8416 | // Takes the sum of the digits base (mask + 1) repeatedly until we have a |
| 8417 | // number from 0 to mask. On exit the 'eq' condition flags are set if the |
| 8418 | // answer is exactly the mask. |
| 8419 | void IntegerModStub::DigitSum(MacroAssembler* masm, |
| 8420 | Register lhs, |
| 8421 | int mask, |
| 8422 | int shift, |
| 8423 | Label* entry) { |
| 8424 | ASSERT(mask > 0); |
| 8425 | ASSERT(mask <= 0xff); // This ensures we don't need ip to use it. |
| 8426 | Label loop; |
| 8427 | __ bind(&loop); |
| 8428 | __ and_(ip, lhs, Operand(mask)); |
| 8429 | __ add(lhs, ip, Operand(lhs, LSR, shift)); |
| 8430 | __ bind(entry); |
| 8431 | __ cmp(lhs, Operand(mask)); |
| 8432 | __ b(gt, &loop); |
| 8433 | } |
| 8434 | |
| 8435 | |
| 8436 | void IntegerModStub::DigitSum(MacroAssembler* masm, |
| 8437 | Register lhs, |
| 8438 | Register scratch, |
| 8439 | int mask, |
| 8440 | int shift1, |
| 8441 | int shift2, |
| 8442 | Label* entry) { |
| 8443 | ASSERT(mask > 0); |
| 8444 | ASSERT(mask <= 0xff); // This ensures we don't need ip to use it. |
| 8445 | Label loop; |
| 8446 | __ bind(&loop); |
| 8447 | __ bic(scratch, lhs, Operand(mask)); |
| 8448 | __ and_(ip, lhs, Operand(mask)); |
| 8449 | __ add(lhs, ip, Operand(lhs, LSR, shift1)); |
| 8450 | __ add(lhs, lhs, Operand(scratch, LSR, shift2)); |
| 8451 | __ bind(entry); |
| 8452 | __ cmp(lhs, Operand(mask)); |
| 8453 | __ b(gt, &loop); |
| 8454 | } |
| 8455 | |
| 8456 | |
| 8457 | // Splits the number into two halves (bottom half has shift bits). The top |
| 8458 | // half is subtracted from the bottom half. If the result is negative then |
| 8459 | // rhs is added. |
| 8460 | void IntegerModStub::ModGetInRangeBySubtraction(MacroAssembler* masm, |
| 8461 | Register lhs, |
| 8462 | int shift, |
| 8463 | int rhs) { |
| 8464 | int mask = (1 << shift) - 1; |
| 8465 | __ and_(ip, lhs, Operand(mask)); |
| 8466 | __ sub(lhs, ip, Operand(lhs, LSR, shift), SetCC); |
| 8467 | __ add(lhs, lhs, Operand(rhs), LeaveCC, mi); |
| 8468 | } |
| 8469 | |
| 8470 | |
| 8471 | void IntegerModStub::ModReduce(MacroAssembler* masm, |
| 8472 | Register lhs, |
| 8473 | int max, |
| 8474 | int denominator) { |
| 8475 | int limit = denominator; |
| 8476 | while (limit * 2 <= max) limit *= 2; |
| 8477 | while (limit >= denominator) { |
| 8478 | __ cmp(lhs, Operand(limit)); |
| 8479 | __ sub(lhs, lhs, Operand(limit), LeaveCC, ge); |
| 8480 | limit >>= 1; |
| 8481 | } |
| 8482 | } |
| 8483 | |
| 8484 | |
| 8485 | void IntegerModStub::ModAnswer(MacroAssembler* masm, |
| 8486 | Register result, |
| 8487 | Register shift_distance, |
| 8488 | Register mask_bits, |
| 8489 | Register sum_of_digits) { |
| 8490 | __ add(result, mask_bits, Operand(sum_of_digits, LSL, shift_distance)); |
| 8491 | __ Ret(); |
| 8492 | } |
| 8493 | |
| 8494 | |
| 8495 | // See comment for class. |
| 8496 | void IntegerModStub::Generate(MacroAssembler* masm) { |
| 8497 | __ mov(lhs_, Operand(lhs_, LSR, shift_distance_)); |
| 8498 | __ bic(odd_number_, odd_number_, Operand(1)); |
| 8499 | __ mov(odd_number_, Operand(odd_number_, LSL, 1)); |
| 8500 | // We now have (odd_number_ - 1) * 2 in the register. |
| 8501 | // Build a switch out of branches instead of data because it avoids |
| 8502 | // having to teach the assembler about intra-code-object pointers |
| 8503 | // that are not in relative branch instructions. |
| 8504 | Label mod3, mod5, mod7, mod9, mod11, mod13, mod15, mod17, mod19; |
| 8505 | Label mod21, mod23, mod25; |
| 8506 | { Assembler::BlockConstPoolScope block_const_pool(masm); |
| 8507 | __ add(pc, pc, Operand(odd_number_)); |
| 8508 | // When you read pc it is always 8 ahead, but when you write it you always |
| 8509 | // write the actual value. So we put in two nops to take up the slack. |
| 8510 | __ nop(); |
| 8511 | __ nop(); |
| 8512 | __ b(&mod3); |
| 8513 | __ b(&mod5); |
| 8514 | __ b(&mod7); |
| 8515 | __ b(&mod9); |
| 8516 | __ b(&mod11); |
| 8517 | __ b(&mod13); |
| 8518 | __ b(&mod15); |
| 8519 | __ b(&mod17); |
| 8520 | __ b(&mod19); |
| 8521 | __ b(&mod21); |
| 8522 | __ b(&mod23); |
| 8523 | __ b(&mod25); |
| 8524 | } |
| 8525 | |
| 8526 | // For each denominator we find a multiple that is almost only ones |
| 8527 | // when expressed in binary. Then we do the sum-of-digits trick for |
| 8528 | // that number. If the multiple is not 1 then we have to do a little |
| 8529 | // more work afterwards to get the answer into the 0-denominator-1 |
| 8530 | // range. |
| 8531 | DigitSum(masm, lhs_, 3, 2, &mod3); // 3 = b11. |
| 8532 | __ sub(lhs_, lhs_, Operand(3), LeaveCC, eq); |
| 8533 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8534 | |
| 8535 | DigitSum(masm, lhs_, 0xf, 4, &mod5); // 5 * 3 = b1111. |
| 8536 | ModGetInRangeBySubtraction(masm, lhs_, 2, 5); |
| 8537 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8538 | |
| 8539 | DigitSum(masm, lhs_, 7, 3, &mod7); // 7 = b111. |
| 8540 | __ sub(lhs_, lhs_, Operand(7), LeaveCC, eq); |
| 8541 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8542 | |
| 8543 | DigitSum(masm, lhs_, 0x3f, 6, &mod9); // 7 * 9 = b111111. |
| 8544 | ModGetInRangeBySubtraction(masm, lhs_, 3, 9); |
| 8545 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8546 | |
| 8547 | DigitSum(masm, lhs_, r5, 0x3f, 6, 3, &mod11); // 5 * 11 = b110111. |
| 8548 | ModReduce(masm, lhs_, 0x3f, 11); |
| 8549 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8550 | |
| 8551 | DigitSum(masm, lhs_, r5, 0xff, 8, 5, &mod13); // 19 * 13 = b11110111. |
| 8552 | ModReduce(masm, lhs_, 0xff, 13); |
| 8553 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8554 | |
| 8555 | DigitSum(masm, lhs_, 0xf, 4, &mod15); // 15 = b1111. |
| 8556 | __ sub(lhs_, lhs_, Operand(15), LeaveCC, eq); |
| 8557 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8558 | |
| 8559 | DigitSum(masm, lhs_, 0xff, 8, &mod17); // 15 * 17 = b11111111. |
| 8560 | ModGetInRangeBySubtraction(masm, lhs_, 4, 17); |
| 8561 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8562 | |
| 8563 | DigitSum(masm, lhs_, r5, 0xff, 8, 5, &mod19); // 13 * 19 = b11110111. |
| 8564 | ModReduce(masm, lhs_, 0xff, 19); |
| 8565 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8566 | |
| 8567 | DigitSum(masm, lhs_, 0x3f, 6, &mod21); // 3 * 21 = b111111. |
| 8568 | ModReduce(masm, lhs_, 0x3f, 21); |
| 8569 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8570 | |
| 8571 | DigitSum(masm, lhs_, r5, 0xff, 8, 7, &mod23); // 11 * 23 = b11111101. |
| 8572 | ModReduce(masm, lhs_, 0xff, 23); |
| 8573 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8574 | |
| 8575 | DigitSum(masm, lhs_, r5, 0x7f, 7, 6, &mod25); // 5 * 25 = b1111101. |
| 8576 | ModReduce(masm, lhs_, 0x7f, 25); |
| 8577 | ModAnswer(masm, result_, shift_distance_, mask_bits_, lhs_); |
| 8578 | } |
| 8579 | |
| 8580 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 8581 | const char* GenericBinaryOpStub::GetName() { |
| 8582 | if (name_ != NULL) return name_; |
| 8583 | const int len = 100; |
| 8584 | name_ = Bootstrapper::AllocateAutoDeletedArray(len); |
| 8585 | if (name_ == NULL) return "OOM"; |
| 8586 | const char* op_name = Token::Name(op_); |
| 8587 | const char* overwrite_name; |
| 8588 | switch (mode_) { |
| 8589 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 8590 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 8591 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 8592 | default: overwrite_name = "UnknownOverwrite"; break; |
| 8593 | } |
| 8594 | |
| 8595 | OS::SNPrintF(Vector<char>(name_, len), |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8596 | "GenericBinaryOpStub_%s_%s%s_%s", |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 8597 | op_name, |
| 8598 | overwrite_name, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8599 | specialized_on_rhs_ ? "_ConstantRhs" : "", |
| 8600 | BinaryOpIC::GetName(runtime_operands_type_)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 8601 | return name_; |
| 8602 | } |
| 8603 | |
| 8604 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 8605 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8606 | void GenericBinaryOpStub::Generate(MacroAssembler* masm) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8607 | // lhs_ : x |
| 8608 | // rhs_ : y |
| 8609 | // r0 : result |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8610 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8611 | Register result = r0; |
| 8612 | Register lhs = lhs_; |
| 8613 | Register rhs = rhs_; |
| 8614 | |
| 8615 | // This code can't cope with other register allocations yet. |
| 8616 | ASSERT(result.is(r0) && |
| 8617 | ((lhs.is(r0) && rhs.is(r1)) || |
| 8618 | (lhs.is(r1) && rhs.is(r0)))); |
| 8619 | |
| 8620 | Register smi_test_reg = VirtualFrame::scratch0(); |
| 8621 | Register scratch = VirtualFrame::scratch1(); |
| 8622 | |
| 8623 | // All ops need to know whether we are dealing with two Smis. Set up |
| 8624 | // smi_test_reg to tell us that. |
| 8625 | if (ShouldGenerateSmiCode()) { |
| 8626 | __ orr(smi_test_reg, lhs, Operand(rhs)); |
| 8627 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8628 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8629 | switch (op_) { |
| 8630 | case Token::ADD: { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8631 | Label not_smi; |
| 8632 | // Fast path. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8633 | if (ShouldGenerateSmiCode()) { |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 8634 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8635 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 8636 | __ b(ne, ¬_smi); |
| 8637 | __ add(r0, r1, Operand(r0), SetCC); // Add y optimistically. |
| 8638 | // Return if no overflow. |
| 8639 | __ Ret(vc); |
| 8640 | __ sub(r0, r0, Operand(r1)); // Revert optimistic add. |
| 8641 | } |
| 8642 | HandleBinaryOpSlowCases(masm, ¬_smi, lhs, rhs, Builtins::ADD); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8643 | break; |
| 8644 | } |
| 8645 | |
| 8646 | case Token::SUB: { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8647 | Label not_smi; |
| 8648 | // Fast path. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8649 | if (ShouldGenerateSmiCode()) { |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 8650 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8651 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 8652 | __ b(ne, ¬_smi); |
| 8653 | if (lhs.is(r1)) { |
| 8654 | __ sub(r0, r1, Operand(r0), SetCC); // Subtract y optimistically. |
| 8655 | // Return if no overflow. |
| 8656 | __ Ret(vc); |
| 8657 | __ sub(r0, r1, Operand(r0)); // Revert optimistic subtract. |
| 8658 | } else { |
| 8659 | __ sub(r0, r0, Operand(r1), SetCC); // Subtract y optimistically. |
| 8660 | // Return if no overflow. |
| 8661 | __ Ret(vc); |
| 8662 | __ add(r0, r0, Operand(r1)); // Revert optimistic subtract. |
| 8663 | } |
| 8664 | } |
| 8665 | HandleBinaryOpSlowCases(masm, ¬_smi, lhs, rhs, Builtins::SUB); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8666 | break; |
| 8667 | } |
| 8668 | |
| 8669 | case Token::MUL: { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8670 | Label not_smi, slow; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8671 | if (ShouldGenerateSmiCode()) { |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 8672 | STATIC_ASSERT(kSmiTag == 0); // adjust code below |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8673 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 8674 | Register scratch2 = smi_test_reg; |
| 8675 | smi_test_reg = no_reg; |
| 8676 | __ b(ne, ¬_smi); |
| 8677 | // Remove tag from one operand (but keep sign), so that result is Smi. |
| 8678 | __ mov(ip, Operand(rhs, ASR, kSmiTagSize)); |
| 8679 | // Do multiplication |
| 8680 | // scratch = lower 32 bits of ip * lhs. |
| 8681 | __ smull(scratch, scratch2, lhs, ip); |
| 8682 | // Go slow on overflows (overflow bit is not set). |
| 8683 | __ mov(ip, Operand(scratch, ASR, 31)); |
| 8684 | // No overflow if higher 33 bits are identical. |
| 8685 | __ cmp(ip, Operand(scratch2)); |
| 8686 | __ b(ne, &slow); |
| 8687 | // Go slow on zero result to handle -0. |
| 8688 | __ tst(scratch, Operand(scratch)); |
| 8689 | __ mov(result, Operand(scratch), LeaveCC, ne); |
| 8690 | __ Ret(ne); |
| 8691 | // We need -0 if we were multiplying a negative number with 0 to get 0. |
| 8692 | // We know one of them was zero. |
| 8693 | __ add(scratch2, rhs, Operand(lhs), SetCC); |
| 8694 | __ mov(result, Operand(Smi::FromInt(0)), LeaveCC, pl); |
| 8695 | __ Ret(pl); // Return Smi 0 if the non-zero one was positive. |
| 8696 | // Slow case. We fall through here if we multiplied a negative number |
| 8697 | // with 0, because that would mean we should produce -0. |
| 8698 | __ bind(&slow); |
| 8699 | } |
| 8700 | HandleBinaryOpSlowCases(masm, ¬_smi, lhs, rhs, Builtins::MUL); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8701 | break; |
| 8702 | } |
| 8703 | |
| 8704 | case Token::DIV: |
| 8705 | case Token::MOD: { |
| 8706 | Label not_smi; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8707 | if (ShouldGenerateSmiCode() && specialized_on_rhs_) { |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8708 | Label lhs_is_unsuitable; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8709 | __ BranchOnNotSmi(lhs, ¬_smi); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8710 | if (IsPowerOf2(constant_rhs_)) { |
| 8711 | if (op_ == Token::MOD) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8712 | __ and_(rhs, |
| 8713 | lhs, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8714 | Operand(0x80000000u | ((constant_rhs_ << kSmiTagSize) - 1)), |
| 8715 | SetCC); |
| 8716 | // We now have the answer, but if the input was negative we also |
| 8717 | // have the sign bit. Our work is done if the result is |
| 8718 | // positive or zero: |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8719 | if (!rhs.is(r0)) { |
| 8720 | __ mov(r0, rhs, LeaveCC, pl); |
| 8721 | } |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8722 | __ Ret(pl); |
| 8723 | // A mod of a negative left hand side must return a negative number. |
| 8724 | // Unfortunately if the answer is 0 then we must return -0. And we |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8725 | // already optimistically trashed rhs so we may need to restore it. |
| 8726 | __ eor(rhs, rhs, Operand(0x80000000u), SetCC); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8727 | // Next two instructions are conditional on the answer being -0. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8728 | __ mov(rhs, Operand(Smi::FromInt(constant_rhs_)), LeaveCC, eq); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8729 | __ b(eq, &lhs_is_unsuitable); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8730 | // We need to subtract the dividend. Eg. -3 % 4 == -3. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8731 | __ sub(result, rhs, Operand(Smi::FromInt(constant_rhs_))); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8732 | } else { |
| 8733 | ASSERT(op_ == Token::DIV); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8734 | __ tst(lhs, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8735 | Operand(0x80000000u | ((constant_rhs_ << kSmiTagSize) - 1))); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8736 | __ b(ne, &lhs_is_unsuitable); // Go slow on negative or remainder. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8737 | int shift = 0; |
| 8738 | int d = constant_rhs_; |
| 8739 | while ((d & 1) == 0) { |
| 8740 | d >>= 1; |
| 8741 | shift++; |
| 8742 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8743 | __ mov(r0, Operand(lhs, LSR, shift)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8744 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 8745 | } |
| 8746 | } else { |
| 8747 | // Not a power of 2. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8748 | __ tst(lhs, Operand(0x80000000u)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8749 | __ b(ne, &lhs_is_unsuitable); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8750 | // Find a fixed point reciprocal of the divisor so we can divide by |
| 8751 | // multiplying. |
| 8752 | double divisor = 1.0 / constant_rhs_; |
| 8753 | int shift = 32; |
| 8754 | double scale = 4294967296.0; // 1 << 32. |
| 8755 | uint32_t mul; |
| 8756 | // Maximise the precision of the fixed point reciprocal. |
| 8757 | while (true) { |
| 8758 | mul = static_cast<uint32_t>(scale * divisor); |
| 8759 | if (mul >= 0x7fffffff) break; |
| 8760 | scale *= 2.0; |
| 8761 | shift++; |
| 8762 | } |
| 8763 | mul++; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8764 | Register scratch2 = smi_test_reg; |
| 8765 | smi_test_reg = no_reg; |
| 8766 | __ mov(scratch2, Operand(mul)); |
| 8767 | __ umull(scratch, scratch2, scratch2, lhs); |
| 8768 | __ mov(scratch2, Operand(scratch2, LSR, shift - 31)); |
| 8769 | // scratch2 is lhs / rhs. scratch2 is not Smi tagged. |
| 8770 | // rhs is still the known rhs. rhs is Smi tagged. |
| 8771 | // lhs is still the unkown lhs. lhs is Smi tagged. |
| 8772 | int required_scratch_shift = 0; // Including the Smi tag shift of 1. |
| 8773 | // scratch = scratch2 * rhs. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8774 | MultiplyByKnownInt2(masm, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8775 | scratch, |
| 8776 | scratch2, |
| 8777 | rhs, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8778 | constant_rhs_, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8779 | &required_scratch_shift); |
| 8780 | // scratch << required_scratch_shift is now the Smi tagged rhs * |
| 8781 | // (lhs / rhs) where / indicates integer division. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8782 | if (op_ == Token::DIV) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8783 | __ cmp(lhs, Operand(scratch, LSL, required_scratch_shift)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8784 | __ b(ne, &lhs_is_unsuitable); // There was a remainder. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8785 | __ mov(result, Operand(scratch2, LSL, kSmiTagSize)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8786 | } else { |
| 8787 | ASSERT(op_ == Token::MOD); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8788 | __ sub(result, lhs, Operand(scratch, LSL, required_scratch_shift)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8789 | } |
| 8790 | } |
| 8791 | __ Ret(); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8792 | __ bind(&lhs_is_unsuitable); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8793 | } else if (op_ == Token::MOD && |
| 8794 | runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS && |
| 8795 | runtime_operands_type_ != BinaryOpIC::STRINGS) { |
| 8796 | // Do generate a bit of smi code for modulus even though the default for |
| 8797 | // modulus is not to do it, but as the ARM processor has no coprocessor |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8798 | // support for modulus checking for smis makes sense. We can handle |
| 8799 | // 1 to 25 times any power of 2. This covers over half the numbers from |
| 8800 | // 1 to 100 including all of the first 25. (Actually the constants < 10 |
| 8801 | // are handled above by reciprocal multiplication. We only get here for |
| 8802 | // those cases if the right hand side is not a constant or for cases |
| 8803 | // like 192 which is 3*2^6 and ends up in the 3 case in the integer mod |
| 8804 | // stub.) |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8805 | Label slow; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8806 | Label not_power_of_2; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8807 | ASSERT(!ShouldGenerateSmiCode()); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 8808 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8809 | // Check for two positive smis. |
| 8810 | __ orr(smi_test_reg, lhs, Operand(rhs)); |
| 8811 | __ tst(smi_test_reg, Operand(0x80000000u | kSmiTagMask)); |
| 8812 | __ b(ne, &slow); |
| 8813 | // Check that rhs is a power of two and not zero. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8814 | Register mask_bits = r3; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8815 | __ sub(scratch, rhs, Operand(1), SetCC); |
| 8816 | __ b(mi, &slow); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8817 | __ and_(mask_bits, rhs, Operand(scratch), SetCC); |
| 8818 | __ b(ne, ¬_power_of_2); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8819 | // Calculate power of two modulus. |
| 8820 | __ and_(result, lhs, Operand(scratch)); |
| 8821 | __ Ret(); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 8822 | |
| 8823 | __ bind(¬_power_of_2); |
| 8824 | __ eor(scratch, scratch, Operand(mask_bits)); |
| 8825 | // At least two bits are set in the modulus. The high one(s) are in |
| 8826 | // mask_bits and the low one is scratch + 1. |
| 8827 | __ and_(mask_bits, scratch, Operand(lhs)); |
| 8828 | Register shift_distance = scratch; |
| 8829 | scratch = no_reg; |
| 8830 | |
| 8831 | // The rhs consists of a power of 2 multiplied by some odd number. |
| 8832 | // The power-of-2 part we handle by putting the corresponding bits |
| 8833 | // from the lhs in the mask_bits register, and the power in the |
| 8834 | // shift_distance register. Shift distance is never 0 due to Smi |
| 8835 | // tagging. |
| 8836 | __ CountLeadingZeros(r4, shift_distance, shift_distance); |
| 8837 | __ rsb(shift_distance, r4, Operand(32)); |
| 8838 | |
| 8839 | // Now we need to find out what the odd number is. The last bit is |
| 8840 | // always 1. |
| 8841 | Register odd_number = r4; |
| 8842 | __ mov(odd_number, Operand(rhs, LSR, shift_distance)); |
| 8843 | __ cmp(odd_number, Operand(25)); |
| 8844 | __ b(gt, &slow); |
| 8845 | |
| 8846 | IntegerModStub stub( |
| 8847 | result, shift_distance, odd_number, mask_bits, lhs, r5); |
| 8848 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); // Tail call. |
| 8849 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 8850 | __ bind(&slow); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 8851 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8852 | HandleBinaryOpSlowCases( |
| 8853 | masm, |
| 8854 | ¬_smi, |
| 8855 | lhs, |
| 8856 | rhs, |
| 8857 | op_ == Token::MOD ? Builtins::MOD : Builtins::DIV); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8858 | break; |
| 8859 | } |
| 8860 | |
| 8861 | case Token::BIT_OR: |
| 8862 | case Token::BIT_AND: |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8863 | case Token::BIT_XOR: |
| 8864 | case Token::SAR: |
| 8865 | case Token::SHR: |
| 8866 | case Token::SHL: { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8867 | Label slow; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 8868 | STATIC_ASSERT(kSmiTag == 0); // adjust code below |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8869 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8870 | __ b(ne, &slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8871 | Register scratch2 = smi_test_reg; |
| 8872 | smi_test_reg = no_reg; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8873 | switch (op_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8874 | case Token::BIT_OR: __ orr(result, rhs, Operand(lhs)); break; |
| 8875 | case Token::BIT_AND: __ and_(result, rhs, Operand(lhs)); break; |
| 8876 | case Token::BIT_XOR: __ eor(result, rhs, Operand(lhs)); break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8877 | case Token::SAR: |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8878 | // Remove tags from right operand. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8879 | __ GetLeastBitsFromSmi(scratch2, rhs, 5); |
| 8880 | __ mov(result, Operand(lhs, ASR, scratch2)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8881 | // Smi tag result. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8882 | __ bic(result, result, Operand(kSmiTagMask)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8883 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8884 | case Token::SHR: |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8885 | // Remove tags from operands. We can't do this on a 31 bit number |
| 8886 | // because then the 0s get shifted into bit 30 instead of bit 31. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8887 | __ mov(scratch, Operand(lhs, ASR, kSmiTagSize)); // x |
| 8888 | __ GetLeastBitsFromSmi(scratch2, rhs, 5); |
| 8889 | __ mov(scratch, Operand(scratch, LSR, scratch2)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8890 | // Unsigned shift is not allowed to produce a negative number, so |
| 8891 | // check the sign bit and the sign bit after Smi tagging. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8892 | __ tst(scratch, Operand(0xc0000000)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8893 | __ b(ne, &slow); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8894 | // Smi tag result. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8895 | __ mov(result, Operand(scratch, LSL, kSmiTagSize)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8896 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8897 | case Token::SHL: |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8898 | // Remove tags from operands. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8899 | __ mov(scratch, Operand(lhs, ASR, kSmiTagSize)); // x |
| 8900 | __ GetLeastBitsFromSmi(scratch2, rhs, 5); |
| 8901 | __ mov(scratch, Operand(scratch, LSL, scratch2)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8902 | // Check that the signed result fits in a Smi. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8903 | __ add(scratch2, scratch, Operand(0x40000000), SetCC); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8904 | __ b(mi, &slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8905 | __ mov(result, Operand(scratch, LSL, kSmiTagSize)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8906 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8907 | default: UNREACHABLE(); |
| 8908 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8909 | __ Ret(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8910 | __ bind(&slow); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8911 | HandleNonSmiBitwiseOp(masm, lhs, rhs); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8912 | break; |
| 8913 | } |
| 8914 | |
| 8915 | default: UNREACHABLE(); |
| 8916 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8917 | // This code should be unreachable. |
| 8918 | __ stop("Unreachable"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8919 | |
| 8920 | // Generate an unreachable reference to the DEFAULT stub so that it can be |
| 8921 | // found at the end of this stub when clearing ICs at GC. |
| 8922 | // TODO(kaznacheev): Check performance impact and get rid of this. |
| 8923 | if (runtime_operands_type_ != BinaryOpIC::DEFAULT) { |
| 8924 | GenericBinaryOpStub uninit(MinorKey(), BinaryOpIC::DEFAULT); |
| 8925 | __ CallStub(&uninit); |
| 8926 | } |
| 8927 | } |
| 8928 | |
| 8929 | |
| 8930 | void GenericBinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 8931 | Label get_result; |
| 8932 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 8933 | __ Push(r1, r0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8934 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 8935 | __ mov(r2, Operand(Smi::FromInt(MinorKey()))); |
| 8936 | __ mov(r1, Operand(Smi::FromInt(op_))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8937 | __ mov(r0, Operand(Smi::FromInt(runtime_operands_type_))); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 8938 | __ Push(r2, r1, r0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8939 | |
| 8940 | __ TailCallExternalReference( |
| 8941 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch)), |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 8942 | 5, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8943 | 1); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 8944 | } |
| 8945 | |
| 8946 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 8947 | Handle<Code> GetBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 8948 | GenericBinaryOpStub stub(key, type_info); |
| 8949 | return stub.GetCode(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 8950 | } |
| 8951 | |
| 8952 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 8953 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
| 8954 | // Argument is a number and is on stack and in r0. |
| 8955 | Label runtime_call; |
| 8956 | Label input_not_smi; |
| 8957 | Label loaded; |
| 8958 | |
| 8959 | if (CpuFeatures::IsSupported(VFP3)) { |
| 8960 | // Load argument and check if it is a smi. |
| 8961 | __ BranchOnNotSmi(r0, &input_not_smi); |
| 8962 | |
| 8963 | CpuFeatures::Scope scope(VFP3); |
| 8964 | // Input is a smi. Convert to double and load the low and high words |
| 8965 | // of the double into r2, r3. |
| 8966 | __ IntegerToDoubleConversionWithVFP3(r0, r3, r2); |
| 8967 | __ b(&loaded); |
| 8968 | |
| 8969 | __ bind(&input_not_smi); |
| 8970 | // Check if input is a HeapNumber. |
| 8971 | __ CheckMap(r0, |
| 8972 | r1, |
| 8973 | Heap::kHeapNumberMapRootIndex, |
| 8974 | &runtime_call, |
| 8975 | true); |
| 8976 | // Input is a HeapNumber. Load it to a double register and store the |
| 8977 | // low and high words into r2, r3. |
| 8978 | __ Ldrd(r2, r3, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 8979 | |
| 8980 | __ bind(&loaded); |
| 8981 | // r2 = low 32 bits of double value |
| 8982 | // r3 = high 32 bits of double value |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8983 | // Compute hash (the shifts are arithmetic): |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 8984 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 8985 | __ eor(r1, r2, Operand(r3)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8986 | __ eor(r1, r1, Operand(r1, ASR, 16)); |
| 8987 | __ eor(r1, r1, Operand(r1, ASR, 8)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 8988 | ASSERT(IsPowerOf2(TranscendentalCache::kCacheSize)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 8989 | __ And(r1, r1, Operand(TranscendentalCache::kCacheSize - 1)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 8990 | |
| 8991 | // r2 = low 32 bits of double value. |
| 8992 | // r3 = high 32 bits of double value. |
| 8993 | // r1 = TranscendentalCache::hash(double value). |
| 8994 | __ mov(r0, |
| 8995 | Operand(ExternalReference::transcendental_cache_array_address())); |
| 8996 | // r0 points to cache array. |
| 8997 | __ ldr(r0, MemOperand(r0, type_ * sizeof(TranscendentalCache::caches_[0]))); |
| 8998 | // r0 points to the cache for the type type_. |
| 8999 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
| 9000 | __ cmp(r0, Operand(0)); |
| 9001 | __ b(eq, &runtime_call); |
| 9002 | |
| 9003 | #ifdef DEBUG |
| 9004 | // Check that the layout of cache elements match expectations. |
| 9005 | { TranscendentalCache::Element test_elem[2]; |
| 9006 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 9007 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 9008 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 9009 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 9010 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 9011 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 9012 | CHECK_EQ(0, elem_in0 - elem_start); |
| 9013 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 9014 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 9015 | } |
| 9016 | #endif |
| 9017 | |
| 9018 | // Find the address of the r1'st entry in the cache, i.e., &r0[r1*12]. |
| 9019 | __ add(r1, r1, Operand(r1, LSL, 1)); |
| 9020 | __ add(r0, r0, Operand(r1, LSL, 2)); |
| 9021 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
| 9022 | __ ldm(ia, r0, r4.bit()| r5.bit() | r6.bit()); |
| 9023 | __ cmp(r2, r4); |
| 9024 | __ b(ne, &runtime_call); |
| 9025 | __ cmp(r3, r5); |
| 9026 | __ b(ne, &runtime_call); |
| 9027 | // Cache hit. Load result, pop argument and return. |
| 9028 | __ mov(r0, Operand(r6)); |
| 9029 | __ pop(); |
| 9030 | __ Ret(); |
| 9031 | } |
| 9032 | |
| 9033 | __ bind(&runtime_call); |
| 9034 | __ TailCallExternalReference(ExternalReference(RuntimeFunction()), 1, 1); |
| 9035 | } |
| 9036 | |
| 9037 | |
| 9038 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 9039 | switch (type_) { |
| 9040 | // Add more cases when necessary. |
| 9041 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 9042 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
| 9043 | default: |
| 9044 | UNIMPLEMENTED(); |
| 9045 | return Runtime::kAbort; |
| 9046 | } |
| 9047 | } |
| 9048 | |
| 9049 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9050 | void StackCheckStub::Generate(MacroAssembler* masm) { |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 9051 | // Do tail-call to runtime routine. Runtime routines expect at least one |
| 9052 | // argument, so give it a Smi. |
| 9053 | __ mov(r0, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9054 | __ push(r0); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 9055 | __ TailCallRuntime(Runtime::kStackGuard, 1, 1); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9056 | |
| 9057 | __ StubReturn(1); |
| 9058 | } |
| 9059 | |
| 9060 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 9061 | void GenericUnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9062 | Label slow, done; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 9063 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 9064 | Register heap_number_map = r6; |
| 9065 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 9066 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9067 | if (op_ == Token::SUB) { |
| 9068 | // Check whether the value is a smi. |
| 9069 | Label try_float; |
| 9070 | __ tst(r0, Operand(kSmiTagMask)); |
| 9071 | __ b(ne, &try_float); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9072 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9073 | // Go slow case if the value of the expression is zero |
| 9074 | // to make sure that we switch between 0 and -0. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 9075 | if (negative_zero_ == kStrictNegativeZero) { |
| 9076 | // If we have to check for zero, then we can check for the max negative |
| 9077 | // smi while we are at it. |
| 9078 | __ bic(ip, r0, Operand(0x80000000), SetCC); |
| 9079 | __ b(eq, &slow); |
| 9080 | __ rsb(r0, r0, Operand(0)); |
| 9081 | __ StubReturn(1); |
| 9082 | } else { |
| 9083 | // The value of the expression is a smi and 0 is OK for -0. Try |
| 9084 | // optimistic subtraction '0 - value'. |
| 9085 | __ rsb(r0, r0, Operand(0), SetCC); |
| 9086 | __ StubReturn(1, vc); |
| 9087 | // We don't have to reverse the optimistic neg since the only case |
| 9088 | // where we fall through is the minimum negative Smi, which is the case |
| 9089 | // where the neg leaves the register unchanged. |
| 9090 | __ jmp(&slow); // Go slow on max negative Smi. |
| 9091 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9092 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9093 | __ bind(&try_float); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 9094 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 9095 | __ AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 9096 | __ cmp(r1, heap_number_map); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9097 | __ b(ne, &slow); |
| 9098 | // r0 is a heap number. Get a new heap number in r1. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 9099 | if (overwrite_ == UNARY_OVERWRITE) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9100 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 9101 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 9102 | __ str(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 9103 | } else { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 9104 | __ AllocateHeapNumber(r1, r2, r3, r6, &slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9105 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 9106 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 9107 | __ str(r3, FieldMemOperand(r1, HeapNumber::kMantissaOffset)); |
| 9108 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 9109 | __ str(r2, FieldMemOperand(r1, HeapNumber::kExponentOffset)); |
| 9110 | __ mov(r0, Operand(r1)); |
| 9111 | } |
| 9112 | } else if (op_ == Token::BIT_NOT) { |
| 9113 | // Check if the operand is a heap number. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 9114 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 9115 | __ AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 9116 | __ cmp(r1, heap_number_map); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9117 | __ b(ne, &slow); |
| 9118 | |
| 9119 | // Convert the heap number is r0 to an untagged integer in r1. |
| 9120 | GetInt32(masm, r0, r1, r2, r3, &slow); |
| 9121 | |
| 9122 | // Do the bitwise operation (move negated) and check if the result |
| 9123 | // fits in a smi. |
| 9124 | Label try_float; |
| 9125 | __ mvn(r1, Operand(r1)); |
| 9126 | __ add(r2, r1, Operand(0x40000000), SetCC); |
| 9127 | __ b(mi, &try_float); |
| 9128 | __ mov(r0, Operand(r1, LSL, kSmiTagSize)); |
| 9129 | __ b(&done); |
| 9130 | |
| 9131 | __ bind(&try_float); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 9132 | if (!overwrite_ == UNARY_OVERWRITE) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9133 | // Allocate a fresh heap number, but don't overwrite r0 until |
| 9134 | // we're sure we can do it without going through the slow case |
| 9135 | // that needs the value in r0. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 9136 | __ AllocateHeapNumber(r2, r3, r4, r6, &slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9137 | __ mov(r0, Operand(r2)); |
| 9138 | } |
| 9139 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 9140 | if (CpuFeatures::IsSupported(VFP3)) { |
| 9141 | // Convert the int32 in r1 to the heap number in r0. r2 is corrupted. |
| 9142 | CpuFeatures::Scope scope(VFP3); |
| 9143 | __ vmov(s0, r1); |
| 9144 | __ vcvt_f64_s32(d0, s0); |
| 9145 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 9146 | __ vstr(d0, r2, HeapNumber::kValueOffset); |
| 9147 | } else { |
| 9148 | // WriteInt32ToHeapNumberStub does not trigger GC, so we do not |
| 9149 | // have to set up a frame. |
| 9150 | WriteInt32ToHeapNumberStub stub(r1, r0, r2); |
| 9151 | __ push(lr); |
| 9152 | __ Call(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 9153 | __ pop(lr); |
| 9154 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9155 | } else { |
| 9156 | UNIMPLEMENTED(); |
| 9157 | } |
| 9158 | |
| 9159 | __ bind(&done); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9160 | __ StubReturn(1); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9161 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9162 | // Handle the slow case by jumping to the JavaScript builtin. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9163 | __ bind(&slow); |
| 9164 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9165 | switch (op_) { |
| 9166 | case Token::SUB: |
| 9167 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_JS); |
| 9168 | break; |
| 9169 | case Token::BIT_NOT: |
| 9170 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_JS); |
| 9171 | break; |
| 9172 | default: |
| 9173 | UNREACHABLE(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9174 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 9175 | } |
| 9176 | |
| 9177 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9178 | void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9179 | // r0 holds the exception. |
| 9180 | |
| 9181 | // Adjust this code if not the case. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9182 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9183 | |
| 9184 | // Drop the sp to the top of the handler. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9185 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 9186 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9187 | |
| 9188 | // Restore the next handler and frame pointer, discard handler state. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9189 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9190 | __ pop(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9191 | __ str(r2, MemOperand(r3)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9192 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9193 | __ ldm(ia_w, sp, r3.bit() | fp.bit()); // r3: discarded state. |
| 9194 | |
| 9195 | // Before returning we restore the context from the frame pointer if |
| 9196 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 9197 | // JS entry frame. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9198 | __ cmp(fp, Operand(0)); |
| 9199 | // Set cp to NULL if fp is NULL. |
| 9200 | __ mov(cp, Operand(0), LeaveCC, eq); |
| 9201 | // Restore cp otherwise. |
| 9202 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9203 | #ifdef DEBUG |
| 9204 | if (FLAG_debug_code) { |
| 9205 | __ mov(lr, Operand(pc)); |
| 9206 | } |
| 9207 | #endif |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9208 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9209 | __ pop(pc); |
| 9210 | } |
| 9211 | |
| 9212 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9213 | void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm, |
| 9214 | UncatchableExceptionType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9215 | // Adjust this code if not the case. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9216 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9217 | |
| 9218 | // Drop sp to the top stack handler. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9219 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9220 | __ ldr(sp, MemOperand(r3)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9221 | |
| 9222 | // Unwind the handlers until the ENTRY handler is found. |
| 9223 | Label loop, done; |
| 9224 | __ bind(&loop); |
| 9225 | // Load the type of the current stack handler. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9226 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 9227 | __ ldr(r2, MemOperand(sp, kStateOffset)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9228 | __ cmp(r2, Operand(StackHandler::ENTRY)); |
| 9229 | __ b(eq, &done); |
| 9230 | // Fetch the next handler in the list. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9231 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 9232 | __ ldr(sp, MemOperand(sp, kNextOffset)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9233 | __ jmp(&loop); |
| 9234 | __ bind(&done); |
| 9235 | |
| 9236 | // Set the top handler address to next handler past the current ENTRY handler. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9237 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9238 | __ pop(r2); |
| 9239 | __ str(r2, MemOperand(r3)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9240 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9241 | if (type == OUT_OF_MEMORY) { |
| 9242 | // Set external caught exception to false. |
| 9243 | ExternalReference external_caught(Top::k_external_caught_exception_address); |
| 9244 | __ mov(r0, Operand(false)); |
| 9245 | __ mov(r2, Operand(external_caught)); |
| 9246 | __ str(r0, MemOperand(r2)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9247 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9248 | // Set pending exception and r0 to out of memory exception. |
| 9249 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 9250 | __ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 9251 | __ mov(r2, Operand(ExternalReference(Top::k_pending_exception_address))); |
| 9252 | __ str(r0, MemOperand(r2)); |
| 9253 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9254 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9255 | // Stack layout at this point. See also StackHandlerConstants. |
| 9256 | // sp -> state (ENTRY) |
| 9257 | // fp |
| 9258 | // lr |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9259 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9260 | // Discard handler state (r2 is not used) and restore frame pointer. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9261 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9262 | __ ldm(ia_w, sp, r2.bit() | fp.bit()); // r2: discarded state. |
| 9263 | // Before returning we restore the context from the frame pointer if |
| 9264 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 9265 | // JS entry frame. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9266 | __ cmp(fp, Operand(0)); |
| 9267 | // Set cp to NULL if fp is NULL. |
| 9268 | __ mov(cp, Operand(0), LeaveCC, eq); |
| 9269 | // Restore cp otherwise. |
| 9270 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9271 | #ifdef DEBUG |
| 9272 | if (FLAG_debug_code) { |
| 9273 | __ mov(lr, Operand(pc)); |
| 9274 | } |
| 9275 | #endif |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9276 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9277 | __ pop(pc); |
| 9278 | } |
| 9279 | |
| 9280 | |
| 9281 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 9282 | Label* throw_normal_exception, |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9283 | Label* throw_termination_exception, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9284 | Label* throw_out_of_memory_exception, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9285 | bool do_gc, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9286 | bool always_allocate, |
| 9287 | int frame_alignment_skew) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9288 | // r0: result parameter for PerformGC, if any |
| 9289 | // r4: number of arguments including receiver (C callee-saved) |
| 9290 | // r5: pointer to builtin function (C callee-saved) |
| 9291 | // r6: pointer to the first argument (C callee-saved) |
| 9292 | |
| 9293 | if (do_gc) { |
| 9294 | // Passing r0. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9295 | __ PrepareCallCFunction(1, r1); |
| 9296 | __ CallCFunction(ExternalReference::perform_gc_function(), 1); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9297 | } |
| 9298 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9299 | ExternalReference scope_depth = |
| 9300 | ExternalReference::heap_always_allocate_scope_depth(); |
| 9301 | if (always_allocate) { |
| 9302 | __ mov(r0, Operand(scope_depth)); |
| 9303 | __ ldr(r1, MemOperand(r0)); |
| 9304 | __ add(r1, r1, Operand(1)); |
| 9305 | __ str(r1, MemOperand(r0)); |
| 9306 | } |
| 9307 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9308 | // Call C built-in. |
| 9309 | // r0 = argc, r1 = argv |
| 9310 | __ mov(r0, Operand(r4)); |
| 9311 | __ mov(r1, Operand(r6)); |
| 9312 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9313 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 9314 | int frame_alignment_mask = frame_alignment - 1; |
| 9315 | #if defined(V8_HOST_ARCH_ARM) |
| 9316 | if (FLAG_debug_code) { |
| 9317 | if (frame_alignment > kPointerSize) { |
| 9318 | Label alignment_as_expected; |
| 9319 | ASSERT(IsPowerOf2(frame_alignment)); |
| 9320 | __ sub(r2, sp, Operand(frame_alignment_skew)); |
| 9321 | __ tst(r2, Operand(frame_alignment_mask)); |
| 9322 | __ b(eq, &alignment_as_expected); |
| 9323 | // Don't use Check here, as it will call Runtime_Abort re-entering here. |
| 9324 | __ stop("Unexpected alignment"); |
| 9325 | __ bind(&alignment_as_expected); |
| 9326 | } |
| 9327 | } |
| 9328 | #endif |
| 9329 | |
| 9330 | // Just before the call (jump) below lr is pushed, so the actual alignment is |
| 9331 | // adding one to the current skew. |
| 9332 | int alignment_before_call = |
| 9333 | (frame_alignment_skew + kPointerSize) & frame_alignment_mask; |
| 9334 | if (alignment_before_call > 0) { |
| 9335 | // Push until the alignment before the call is met. |
| 9336 | __ mov(r2, Operand(0)); |
| 9337 | for (int i = alignment_before_call; |
| 9338 | (i & frame_alignment_mask) != 0; |
| 9339 | i += kPointerSize) { |
| 9340 | __ push(r2); |
| 9341 | } |
| 9342 | } |
| 9343 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9344 | // TODO(1242173): To let the GC traverse the return address of the exit |
| 9345 | // frames, we need to know where the return address is. Right now, |
| 9346 | // we push it on the stack to be able to find it again, but we never |
| 9347 | // restore from it in case of changes, which makes it impossible to |
| 9348 | // support moving the C entry code stub. This should be fixed, but currently |
| 9349 | // this is OK because the CEntryStub gets generated so early in the V8 boot |
| 9350 | // sequence that it is not moving ever. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9351 | masm->add(lr, pc, Operand(4)); // Compute return address: (pc + 8) + 4 |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 9352 | masm->push(lr); |
| 9353 | masm->Jump(r5); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9354 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9355 | // Restore sp back to before aligning the stack. |
| 9356 | if (alignment_before_call > 0) { |
| 9357 | __ add(sp, sp, Operand(alignment_before_call)); |
| 9358 | } |
| 9359 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9360 | if (always_allocate) { |
| 9361 | // It's okay to clobber r2 and r3 here. Don't mess with r0 and r1 |
| 9362 | // though (contain the result). |
| 9363 | __ mov(r2, Operand(scope_depth)); |
| 9364 | __ ldr(r3, MemOperand(r2)); |
| 9365 | __ sub(r3, r3, Operand(1)); |
| 9366 | __ str(r3, MemOperand(r2)); |
| 9367 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9368 | |
| 9369 | // check for failure result |
| 9370 | Label failure_returned; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9371 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9372 | // Lower 2 bits of r2 are 0 iff r0 has failure tag. |
| 9373 | __ add(r2, r0, Operand(1)); |
| 9374 | __ tst(r2, Operand(kFailureTagMask)); |
| 9375 | __ b(eq, &failure_returned); |
| 9376 | |
| 9377 | // Exit C frame and return. |
| 9378 | // r0:r1: result |
| 9379 | // sp: stack pointer |
| 9380 | // fp: frame pointer |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9381 | __ LeaveExitFrame(mode_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9382 | |
| 9383 | // check if we should retry or throw exception |
| 9384 | Label retry; |
| 9385 | __ bind(&failure_returned); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9386 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9387 | __ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
| 9388 | __ b(eq, &retry); |
| 9389 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9390 | // Special handling of out of memory exceptions. |
| 9391 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 9392 | __ cmp(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 9393 | __ b(eq, throw_out_of_memory_exception); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9394 | |
| 9395 | // Retrieve the pending exception and clear the variable. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 9396 | __ mov(ip, Operand(ExternalReference::the_hole_value_location())); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9397 | __ ldr(r3, MemOperand(ip)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 9398 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9399 | __ ldr(r0, MemOperand(ip)); |
| 9400 | __ str(r3, MemOperand(ip)); |
| 9401 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9402 | // Special handling of termination exceptions which are uncatchable |
| 9403 | // by javascript code. |
| 9404 | __ cmp(r0, Operand(Factory::termination_exception())); |
| 9405 | __ b(eq, throw_termination_exception); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9406 | |
| 9407 | // Handle normal exception. |
| 9408 | __ jmp(throw_normal_exception); |
| 9409 | |
| 9410 | __ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying |
| 9411 | } |
| 9412 | |
| 9413 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9414 | void CEntryStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9415 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 9416 | // r0: number of arguments including receiver |
| 9417 | // r1: pointer to builtin function |
| 9418 | // fp: frame pointer (restored after C call) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9419 | // sp: stack pointer (restored as callee's sp after C call) |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9420 | // cp: current context (C callee-saved) |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9421 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9422 | // Result returned in r0 or r0+r1 by default. |
| 9423 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9424 | // NOTE: Invocations of builtins may return failure objects |
| 9425 | // instead of a proper result. The builtin entry handles |
| 9426 | // this by performing a garbage collection and retrying the |
| 9427 | // builtin once. |
| 9428 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9429 | // Enter the exit frame that transitions from JavaScript to C++. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 9430 | __ EnterExitFrame(mode_); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9431 | |
| 9432 | // r4: number of arguments (C callee-saved) |
| 9433 | // r5: pointer to builtin function (C callee-saved) |
| 9434 | // r6: pointer to first argument (C callee-saved) |
| 9435 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9436 | Label throw_normal_exception; |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9437 | Label throw_termination_exception; |
| 9438 | Label throw_out_of_memory_exception; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9439 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 9440 | // Call into the runtime system. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9441 | GenerateCore(masm, |
| 9442 | &throw_normal_exception, |
| 9443 | &throw_termination_exception, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9444 | &throw_out_of_memory_exception, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 9445 | false, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9446 | false, |
| 9447 | -kPointerSize); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9448 | |
| 9449 | // Do space-specific GC and retry runtime call. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9450 | GenerateCore(masm, |
| 9451 | &throw_normal_exception, |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9452 | &throw_termination_exception, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9453 | &throw_out_of_memory_exception, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9454 | true, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9455 | false, |
| 9456 | 0); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9457 | |
| 9458 | // Do full GC and retry runtime call one final time. |
| 9459 | Failure* failure = Failure::InternalError(); |
| 9460 | __ mov(r0, Operand(reinterpret_cast<int32_t>(failure))); |
| 9461 | GenerateCore(masm, |
| 9462 | &throw_normal_exception, |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9463 | &throw_termination_exception, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9464 | &throw_out_of_memory_exception, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 9465 | true, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9466 | true, |
| 9467 | kPointerSize); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9468 | |
| 9469 | __ bind(&throw_out_of_memory_exception); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 9470 | GenerateThrowUncatchable(masm, OUT_OF_MEMORY); |
| 9471 | |
| 9472 | __ bind(&throw_termination_exception); |
| 9473 | GenerateThrowUncatchable(masm, TERMINATION); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9474 | |
| 9475 | __ bind(&throw_normal_exception); |
| 9476 | GenerateThrowTOS(masm); |
| 9477 | } |
| 9478 | |
| 9479 | |
| 9480 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 9481 | // r0: code entry |
| 9482 | // r1: function |
| 9483 | // r2: receiver |
| 9484 | // r3: argc |
| 9485 | // [sp+0]: argv |
| 9486 | |
| 9487 | Label invoke, exit; |
| 9488 | |
| 9489 | // Called from C, so do not pop argc and args on exit (preserve sp) |
| 9490 | // No need to save register-passed args |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9491 | // Save callee-saved registers (incl. cp and fp), sp, and lr |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9492 | __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| 9493 | |
| 9494 | // Get address of argv, see stm above. |
| 9495 | // r0: code entry |
| 9496 | // r1: function |
| 9497 | // r2: receiver |
| 9498 | // r3: argc |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9499 | __ ldr(r4, MemOperand(sp, (kNumCalleeSaved + 1) * kPointerSize)); // argv |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9500 | |
| 9501 | // Push a frame with special values setup to mark it as an entry frame. |
| 9502 | // r0: code entry |
| 9503 | // r1: function |
| 9504 | // r2: receiver |
| 9505 | // r3: argc |
| 9506 | // r4: argv |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9507 | __ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 9508 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 9509 | __ mov(r7, Operand(Smi::FromInt(marker))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9510 | __ mov(r6, Operand(Smi::FromInt(marker))); |
| 9511 | __ mov(r5, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 9512 | __ ldr(r5, MemOperand(r5)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 9513 | __ Push(r8, r7, r6, r5); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9514 | |
| 9515 | // Setup frame pointer for the frame to be pushed. |
| 9516 | __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 9517 | |
| 9518 | // Call a faked try-block that does the invoke. |
| 9519 | __ bl(&invoke); |
| 9520 | |
| 9521 | // Caught exception: Store result (exception) in the pending |
| 9522 | // exception field in the JSEnv and return a failure sentinel. |
| 9523 | // Coming in here the fp will be invalid because the PushTryHandler below |
| 9524 | // sets it to 0 to signal the existence of the JSEntry frame. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 9525 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9526 | __ str(r0, MemOperand(ip)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 9527 | __ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9528 | __ b(&exit); |
| 9529 | |
| 9530 | // Invoke: Link this frame into the handler chain. |
| 9531 | __ bind(&invoke); |
| 9532 | // Must preserve r0-r4, r5-r7 are available. |
| 9533 | __ PushTryHandler(IN_JS_ENTRY, JS_ENTRY_HANDLER); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9534 | // If an exception not caught by another handler occurs, this handler |
| 9535 | // returns control to the code after the bl(&invoke) above, which |
| 9536 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 9537 | // saved values before returning a failure to C. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9538 | |
| 9539 | // Clear any pending exceptions. |
| 9540 | __ mov(ip, Operand(ExternalReference::the_hole_value_location())); |
| 9541 | __ ldr(r5, MemOperand(ip)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 9542 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9543 | __ str(r5, MemOperand(ip)); |
| 9544 | |
| 9545 | // Invoke the function by calling through JS entry trampoline builtin. |
| 9546 | // Notice that we cannot store a reference to the trampoline code directly in |
| 9547 | // this stub, because runtime stubs are not traversed when doing GC. |
| 9548 | |
| 9549 | // Expected registers by Builtins::JSEntryTrampoline |
| 9550 | // r0: code entry |
| 9551 | // r1: function |
| 9552 | // r2: receiver |
| 9553 | // r3: argc |
| 9554 | // r4: argv |
| 9555 | if (is_construct) { |
| 9556 | ExternalReference construct_entry(Builtins::JSConstructEntryTrampoline); |
| 9557 | __ mov(ip, Operand(construct_entry)); |
| 9558 | } else { |
| 9559 | ExternalReference entry(Builtins::JSEntryTrampoline); |
| 9560 | __ mov(ip, Operand(entry)); |
| 9561 | } |
| 9562 | __ ldr(ip, MemOperand(ip)); // deref address |
| 9563 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9564 | // Branch and link to JSEntryTrampoline. We don't use the double underscore |
| 9565 | // macro for the add instruction because we don't want the coverage tool |
| 9566 | // inserting instructions here after we read the pc. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9567 | __ mov(lr, Operand(pc)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9568 | masm->add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9569 | |
| 9570 | // Unlink this frame from the handler chain. When reading the |
| 9571 | // address of the next handler, there is no need to use the address |
| 9572 | // displacement since the current stack pointer (sp) points directly |
| 9573 | // to the stack handler. |
| 9574 | __ ldr(r3, MemOperand(sp, StackHandlerConstants::kNextOffset)); |
| 9575 | __ mov(ip, Operand(ExternalReference(Top::k_handler_address))); |
| 9576 | __ str(r3, MemOperand(ip)); |
| 9577 | // No need to restore registers |
| 9578 | __ add(sp, sp, Operand(StackHandlerConstants::kSize)); |
| 9579 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9580 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9581 | __ bind(&exit); // r0 holds result |
| 9582 | // Restore the top frame descriptors from the stack. |
| 9583 | __ pop(r3); |
| 9584 | __ mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 9585 | __ str(r3, MemOperand(ip)); |
| 9586 | |
| 9587 | // Reset the stack to the callee saved registers. |
| 9588 | __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 9589 | |
| 9590 | // Restore callee-saved registers and return. |
| 9591 | #ifdef DEBUG |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 9592 | if (FLAG_debug_code) { |
| 9593 | __ mov(lr, Operand(pc)); |
| 9594 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9595 | #endif |
| 9596 | __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 9597 | } |
| 9598 | |
| 9599 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9600 | // This stub performs an instanceof, calling the builtin function if |
| 9601 | // necessary. Uses r1 for the object, r0 for the function that it may |
| 9602 | // be an instance of (these are fetched from the stack). |
| 9603 | void InstanceofStub::Generate(MacroAssembler* masm) { |
| 9604 | // Get the object - slow case for smis (we may need to throw an exception |
| 9605 | // depending on the rhs). |
| 9606 | Label slow, loop, is_instance, is_not_instance; |
| 9607 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 9608 | __ BranchOnSmi(r0, &slow); |
| 9609 | |
| 9610 | // Check that the left hand is a JS object and put map in r3. |
| 9611 | __ CompareObjectType(r0, r3, r2, FIRST_JS_OBJECT_TYPE); |
| 9612 | __ b(lt, &slow); |
| 9613 | __ cmp(r2, Operand(LAST_JS_OBJECT_TYPE)); |
| 9614 | __ b(gt, &slow); |
| 9615 | |
| 9616 | // Get the prototype of the function (r4 is result, r2 is scratch). |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9617 | __ ldr(r1, MemOperand(sp, 0)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9618 | // r1 is function, r3 is map. |
| 9619 | |
| 9620 | // Look up the function and the map in the instanceof cache. |
| 9621 | Label miss; |
| 9622 | __ LoadRoot(ip, Heap::kInstanceofCacheFunctionRootIndex); |
| 9623 | __ cmp(r1, ip); |
| 9624 | __ b(ne, &miss); |
| 9625 | __ LoadRoot(ip, Heap::kInstanceofCacheMapRootIndex); |
| 9626 | __ cmp(r3, ip); |
| 9627 | __ b(ne, &miss); |
| 9628 | __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 9629 | __ pop(); |
| 9630 | __ pop(); |
| 9631 | __ mov(pc, Operand(lr)); |
| 9632 | |
| 9633 | __ bind(&miss); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9634 | __ TryGetFunctionPrototype(r1, r4, r2, &slow); |
| 9635 | |
| 9636 | // Check that the function prototype is a JS object. |
| 9637 | __ BranchOnSmi(r4, &slow); |
| 9638 | __ CompareObjectType(r4, r5, r5, FIRST_JS_OBJECT_TYPE); |
| 9639 | __ b(lt, &slow); |
| 9640 | __ cmp(r5, Operand(LAST_JS_OBJECT_TYPE)); |
| 9641 | __ b(gt, &slow); |
| 9642 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9643 | __ StoreRoot(r1, Heap::kInstanceofCacheFunctionRootIndex); |
| 9644 | __ StoreRoot(r3, Heap::kInstanceofCacheMapRootIndex); |
| 9645 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9646 | // Register mapping: r3 is object map and r4 is function prototype. |
| 9647 | // Get prototype of object into r2. |
| 9648 | __ ldr(r2, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 9649 | |
| 9650 | // Loop through the prototype chain looking for the function prototype. |
| 9651 | __ bind(&loop); |
| 9652 | __ cmp(r2, Operand(r4)); |
| 9653 | __ b(eq, &is_instance); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 9654 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 9655 | __ cmp(r2, ip); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9656 | __ b(eq, &is_not_instance); |
| 9657 | __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 9658 | __ ldr(r2, FieldMemOperand(r2, Map::kPrototypeOffset)); |
| 9659 | __ jmp(&loop); |
| 9660 | |
| 9661 | __ bind(&is_instance); |
| 9662 | __ mov(r0, Operand(Smi::FromInt(0))); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9663 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9664 | __ pop(); |
| 9665 | __ pop(); |
| 9666 | __ mov(pc, Operand(lr)); // Return. |
| 9667 | |
| 9668 | __ bind(&is_not_instance); |
| 9669 | __ mov(r0, Operand(Smi::FromInt(1))); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9670 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9671 | __ pop(); |
| 9672 | __ pop(); |
| 9673 | __ mov(pc, Operand(lr)); // Return. |
| 9674 | |
| 9675 | // Slow-case. Tail call builtin. |
| 9676 | __ bind(&slow); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9677 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_JS); |
| 9678 | } |
| 9679 | |
| 9680 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9681 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 9682 | // The displacement is the offset of the last parameter (if any) |
| 9683 | // relative to the frame pointer. |
| 9684 | static const int kDisplacement = |
| 9685 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9686 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9687 | // Check that the key is a smi. |
| 9688 | Label slow; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 9689 | __ BranchOnNotSmi(r1, &slow); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9690 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9691 | // Check if the calling frame is an arguments adaptor frame. |
| 9692 | Label adaptor; |
| 9693 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 9694 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 9695 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9696 | __ b(eq, &adaptor); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9697 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9698 | // Check index against formal parameters count limit passed in |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 9699 | // through register r0. Use unsigned comparison to get negative |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9700 | // check for free. |
| 9701 | __ cmp(r1, r0); |
| 9702 | __ b(cs, &slow); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9703 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9704 | // Read the argument from the stack and return it. |
| 9705 | __ sub(r3, r0, r1); |
| 9706 | __ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 9707 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 9708 | __ Jump(lr); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9709 | |
| 9710 | // Arguments adaptor case: Check index against actual arguments |
| 9711 | // limit found in the arguments adaptor frame. Use unsigned |
| 9712 | // comparison to get negative check for free. |
| 9713 | __ bind(&adaptor); |
| 9714 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 9715 | __ cmp(r1, r0); |
| 9716 | __ b(cs, &slow); |
| 9717 | |
| 9718 | // Read the argument from the adaptor frame and return it. |
| 9719 | __ sub(r3, r0, r1); |
| 9720 | __ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 9721 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 9722 | __ Jump(lr); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9723 | |
| 9724 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 9725 | // by calling the runtime system. |
| 9726 | __ bind(&slow); |
| 9727 | __ push(r1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 9728 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9729 | } |
| 9730 | |
| 9731 | |
| 9732 | void ArgumentsAccessStub::GenerateNewObject(MacroAssembler* masm) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9733 | // sp[0] : number of parameters |
| 9734 | // sp[4] : receiver displacement |
| 9735 | // sp[8] : function |
| 9736 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9737 | // Check if the calling frame is an arguments adaptor frame. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9738 | Label adaptor_frame, try_allocate, runtime; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9739 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 9740 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 9741 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9742 | __ b(eq, &adaptor_frame); |
| 9743 | |
| 9744 | // Get the length from the frame. |
| 9745 | __ ldr(r1, MemOperand(sp, 0)); |
| 9746 | __ b(&try_allocate); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9747 | |
| 9748 | // Patch the arguments.length and the parameters pointer. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9749 | __ bind(&adaptor_frame); |
| 9750 | __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 9751 | __ str(r1, MemOperand(sp, 0)); |
| 9752 | __ add(r3, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9753 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 9754 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 9755 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9756 | // Try the new space allocation. Start out with computing the size |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9757 | // of the arguments object and the elements array in words. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9758 | Label add_arguments_object; |
| 9759 | __ bind(&try_allocate); |
| 9760 | __ cmp(r1, Operand(0)); |
| 9761 | __ b(eq, &add_arguments_object); |
| 9762 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| 9763 | __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 9764 | __ bind(&add_arguments_object); |
| 9765 | __ add(r1, r1, Operand(Heap::kArgumentsObjectSize / kPointerSize)); |
| 9766 | |
| 9767 | // Do the allocation of both objects in one go. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9768 | __ AllocateInNewSpace( |
| 9769 | r1, |
| 9770 | r0, |
| 9771 | r2, |
| 9772 | r3, |
| 9773 | &runtime, |
| 9774 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9775 | |
| 9776 | // Get the arguments boilerplate from the current (global) context. |
| 9777 | int offset = Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| 9778 | __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 9779 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
| 9780 | __ ldr(r4, MemOperand(r4, offset)); |
| 9781 | |
| 9782 | // Copy the JS object part. |
| 9783 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 9784 | __ ldr(r3, FieldMemOperand(r4, i)); |
| 9785 | __ str(r3, FieldMemOperand(r0, i)); |
| 9786 | } |
| 9787 | |
| 9788 | // Setup the callee in-object property. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9789 | STATIC_ASSERT(Heap::arguments_callee_index == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9790 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 9791 | __ str(r3, FieldMemOperand(r0, JSObject::kHeaderSize)); |
| 9792 | |
| 9793 | // Get the length (smi tagged) and set that as an in-object property too. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9794 | STATIC_ASSERT(Heap::arguments_length_index == 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9795 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 9796 | __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + kPointerSize)); |
| 9797 | |
| 9798 | // If there are no actual arguments, we're done. |
| 9799 | Label done; |
| 9800 | __ cmp(r1, Operand(0)); |
| 9801 | __ b(eq, &done); |
| 9802 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 9803 | // Get the parameters pointer from the stack. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9804 | __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9805 | |
| 9806 | // Setup the elements pointer in the allocated arguments object and |
| 9807 | // initialize the header in the elements fixed array. |
| 9808 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSize)); |
| 9809 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 9810 | __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| 9811 | __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 9812 | __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 9813 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); // Untag the length for the loop. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 9814 | |
| 9815 | // Copy the fixed array slots. |
| 9816 | Label loop; |
| 9817 | // Setup r4 to point to the first array slot. |
| 9818 | __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 9819 | __ bind(&loop); |
| 9820 | // Pre-decrement r2 with kPointerSize on each iteration. |
| 9821 | // Pre-decrement in order to skip receiver. |
| 9822 | __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| 9823 | // Post-increment r4 with kPointerSize on each iteration. |
| 9824 | __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| 9825 | __ sub(r1, r1, Operand(1)); |
| 9826 | __ cmp(r1, Operand(0)); |
| 9827 | __ b(ne, &loop); |
| 9828 | |
| 9829 | // Return and remove the on-stack parameters. |
| 9830 | __ bind(&done); |
| 9831 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 9832 | __ Ret(); |
| 9833 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 9834 | // Do the runtime call to allocate the arguments object. |
| 9835 | __ bind(&runtime); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 9836 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 9837 | } |
| 9838 | |
| 9839 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9840 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 9841 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 9842 | // time or if regexp entry in generated code is turned off runtime switch or |
| 9843 | // at compilation. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 9844 | #ifdef V8_INTERPRETED_REGEXP |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9845 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 9846 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9847 | if (!FLAG_regexp_entry_native) { |
| 9848 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 9849 | return; |
| 9850 | } |
| 9851 | |
| 9852 | // Stack frame on entry. |
| 9853 | // sp[0]: last_match_info (expected JSArray) |
| 9854 | // sp[4]: previous index |
| 9855 | // sp[8]: subject string |
| 9856 | // sp[12]: JSRegExp object |
| 9857 | |
| 9858 | static const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 9859 | static const int kPreviousIndexOffset = 1 * kPointerSize; |
| 9860 | static const int kSubjectOffset = 2 * kPointerSize; |
| 9861 | static const int kJSRegExpOffset = 3 * kPointerSize; |
| 9862 | |
| 9863 | Label runtime, invoke_regexp; |
| 9864 | |
| 9865 | // Allocation of registers for this function. These are in callee save |
| 9866 | // registers and will be preserved by the call to the native RegExp code, as |
| 9867 | // this code is called using the normal C calling convention. When calling |
| 9868 | // directly from generated code the native RegExp code will not do a GC and |
| 9869 | // therefore the content of these registers are safe to use after the call. |
| 9870 | Register subject = r4; |
| 9871 | Register regexp_data = r5; |
| 9872 | Register last_match_info_elements = r6; |
| 9873 | |
| 9874 | // Ensure that a RegExp stack is allocated. |
| 9875 | ExternalReference address_of_regexp_stack_memory_address = |
| 9876 | ExternalReference::address_of_regexp_stack_memory_address(); |
| 9877 | ExternalReference address_of_regexp_stack_memory_size = |
| 9878 | ExternalReference::address_of_regexp_stack_memory_size(); |
| 9879 | __ mov(r0, Operand(address_of_regexp_stack_memory_size)); |
| 9880 | __ ldr(r0, MemOperand(r0, 0)); |
| 9881 | __ tst(r0, Operand(r0)); |
| 9882 | __ b(eq, &runtime); |
| 9883 | |
| 9884 | // Check that the first argument is a JSRegExp object. |
| 9885 | __ ldr(r0, MemOperand(sp, kJSRegExpOffset)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9886 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9887 | __ tst(r0, Operand(kSmiTagMask)); |
| 9888 | __ b(eq, &runtime); |
| 9889 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
| 9890 | __ b(ne, &runtime); |
| 9891 | |
| 9892 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 9893 | __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset)); |
| 9894 | if (FLAG_debug_code) { |
| 9895 | __ tst(regexp_data, Operand(kSmiTagMask)); |
| 9896 | __ Check(nz, "Unexpected type for RegExp data, FixedArray expected"); |
| 9897 | __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE); |
| 9898 | __ Check(eq, "Unexpected type for RegExp data, FixedArray expected"); |
| 9899 | } |
| 9900 | |
| 9901 | // regexp_data: RegExp data (FixedArray) |
| 9902 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 9903 | __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 9904 | __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 9905 | __ b(ne, &runtime); |
| 9906 | |
| 9907 | // regexp_data: RegExp data (FixedArray) |
| 9908 | // Check that the number of captures fit in the static offsets vector buffer. |
| 9909 | __ ldr(r2, |
| 9910 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 9911 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 9912 | // uses the asumption that smis are 2 * their untagged value. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9913 | STATIC_ASSERT(kSmiTag == 0); |
| 9914 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9915 | __ add(r2, r2, Operand(2)); // r2 was a smi. |
| 9916 | // Check that the static offsets vector buffer is large enough. |
| 9917 | __ cmp(r2, Operand(OffsetsVector::kStaticOffsetsVectorSize)); |
| 9918 | __ b(hi, &runtime); |
| 9919 | |
| 9920 | // r2: Number of capture registers |
| 9921 | // regexp_data: RegExp data (FixedArray) |
| 9922 | // Check that the second argument is a string. |
| 9923 | __ ldr(subject, MemOperand(sp, kSubjectOffset)); |
| 9924 | __ tst(subject, Operand(kSmiTagMask)); |
| 9925 | __ b(eq, &runtime); |
| 9926 | Condition is_string = masm->IsObjectStringType(subject, r0); |
| 9927 | __ b(NegateCondition(is_string), &runtime); |
| 9928 | // Get the length of the string to r3. |
| 9929 | __ ldr(r3, FieldMemOperand(subject, String::kLengthOffset)); |
| 9930 | |
| 9931 | // r2: Number of capture registers |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 9932 | // r3: Length of subject string as a smi |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9933 | // subject: Subject string |
| 9934 | // regexp_data: RegExp data (FixedArray) |
| 9935 | // Check that the third argument is a positive smi less than the subject |
| 9936 | // string length. A negative value will be greater (unsigned comparison). |
| 9937 | __ ldr(r0, MemOperand(sp, kPreviousIndexOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 9938 | __ tst(r0, Operand(kSmiTagMask)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9939 | __ b(ne, &runtime); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 9940 | __ cmp(r3, Operand(r0)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 9941 | __ b(ls, &runtime); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9942 | |
| 9943 | // r2: Number of capture registers |
| 9944 | // subject: Subject string |
| 9945 | // regexp_data: RegExp data (FixedArray) |
| 9946 | // Check that the fourth object is a JSArray object. |
| 9947 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
| 9948 | __ tst(r0, Operand(kSmiTagMask)); |
| 9949 | __ b(eq, &runtime); |
| 9950 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
| 9951 | __ b(ne, &runtime); |
| 9952 | // Check that the JSArray is in fast case. |
| 9953 | __ ldr(last_match_info_elements, |
| 9954 | FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 9955 | __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 9956 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 9957 | __ cmp(r0, ip); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9958 | __ b(ne, &runtime); |
| 9959 | // Check that the last match info has space for the capture registers and the |
| 9960 | // additional information. |
| 9961 | __ ldr(r0, |
| 9962 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 9963 | __ add(r2, r2, Operand(RegExpImpl::kLastMatchOverhead)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 9964 | __ cmp(r2, Operand(r0, ASR, kSmiTagSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9965 | __ b(gt, &runtime); |
| 9966 | |
| 9967 | // subject: Subject string |
| 9968 | // regexp_data: RegExp data (FixedArray) |
| 9969 | // Check the representation and encoding of the subject string. |
| 9970 | Label seq_string; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9971 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 9972 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 9973 | // First check for flat string. |
| 9974 | __ tst(r0, Operand(kIsNotStringMask | kStringRepresentationMask)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9975 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9976 | __ b(eq, &seq_string); |
| 9977 | |
| 9978 | // subject: Subject string |
| 9979 | // regexp_data: RegExp data (FixedArray) |
| 9980 | // Check for flat cons string. |
| 9981 | // A flat cons string is a cons string where the second part is the empty |
| 9982 | // string. In that case the subject string is just the first part of the cons |
| 9983 | // string. Also in this case the first part of the cons string is known to be |
| 9984 | // a sequential string or an external string. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9985 | STATIC_ASSERT(kExternalStringTag !=0); |
| 9986 | STATIC_ASSERT((kConsStringTag & kExternalStringTag) == 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 9987 | __ tst(r0, Operand(kIsNotStringMask | kExternalStringTag)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9988 | __ b(ne, &runtime); |
| 9989 | __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
| 9990 | __ LoadRoot(r1, Heap::kEmptyStringRootIndex); |
| 9991 | __ cmp(r0, r1); |
| 9992 | __ b(ne, &runtime); |
| 9993 | __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
| 9994 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 9995 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 9996 | // Is first part a flat string? |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 9997 | STATIC_ASSERT(kSeqStringTag == 0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 9998 | __ tst(r0, Operand(kStringRepresentationMask)); |
| 9999 | __ b(nz, &runtime); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10000 | |
| 10001 | __ bind(&seq_string); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10002 | // subject: Subject string |
| 10003 | // regexp_data: RegExp data (FixedArray) |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 10004 | // r0: Instance type of subject string |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10005 | STATIC_ASSERT(4 == kAsciiStringTag); |
| 10006 | STATIC_ASSERT(kTwoByteStringTag == 0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10007 | // Find the code object based on the assumptions above. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 10008 | __ and_(r0, r0, Operand(kStringEncodingMask)); |
| 10009 | __ mov(r3, Operand(r0, ASR, 2), SetCC); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10010 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset), ne); |
| 10011 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq); |
| 10012 | |
| 10013 | // Check that the irregexp code has been generated for the actual string |
| 10014 | // encoding. If it has, the field contains a code object otherwise it contains |
| 10015 | // the hole. |
| 10016 | __ CompareObjectType(r7, r0, r0, CODE_TYPE); |
| 10017 | __ b(ne, &runtime); |
| 10018 | |
| 10019 | // r3: encoding of subject string (1 if ascii, 0 if two_byte); |
| 10020 | // r7: code |
| 10021 | // subject: Subject string |
| 10022 | // regexp_data: RegExp data (FixedArray) |
| 10023 | // Load used arguments before starting to push arguments for call to native |
| 10024 | // RegExp code to avoid handling changing stack height. |
| 10025 | __ ldr(r1, MemOperand(sp, kPreviousIndexOffset)); |
| 10026 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); |
| 10027 | |
| 10028 | // r1: previous index |
| 10029 | // r3: encoding of subject string (1 if ascii, 0 if two_byte); |
| 10030 | // r7: code |
| 10031 | // subject: Subject string |
| 10032 | // regexp_data: RegExp data (FixedArray) |
| 10033 | // All checks done. Now push arguments for native regexp code. |
| 10034 | __ IncrementCounter(&Counters::regexp_entry_native, 1, r0, r2); |
| 10035 | |
| 10036 | static const int kRegExpExecuteArguments = 7; |
| 10037 | __ push(lr); |
| 10038 | __ PrepareCallCFunction(kRegExpExecuteArguments, r0); |
| 10039 | |
| 10040 | // Argument 7 (sp[8]): Indicate that this is a direct call from JavaScript. |
| 10041 | __ mov(r0, Operand(1)); |
| 10042 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
| 10043 | |
| 10044 | // Argument 6 (sp[4]): Start (high end) of backtracking stack memory area. |
| 10045 | __ mov(r0, Operand(address_of_regexp_stack_memory_address)); |
| 10046 | __ ldr(r0, MemOperand(r0, 0)); |
| 10047 | __ mov(r2, Operand(address_of_regexp_stack_memory_size)); |
| 10048 | __ ldr(r2, MemOperand(r2, 0)); |
| 10049 | __ add(r0, r0, Operand(r2)); |
| 10050 | __ str(r0, MemOperand(sp, 1 * kPointerSize)); |
| 10051 | |
| 10052 | // Argument 5 (sp[0]): static offsets vector buffer. |
| 10053 | __ mov(r0, Operand(ExternalReference::address_of_static_offsets_vector())); |
| 10054 | __ str(r0, MemOperand(sp, 0 * kPointerSize)); |
| 10055 | |
| 10056 | // For arguments 4 and 3 get string length, calculate start of string data and |
| 10057 | // calculate the shift of the index (0 for ASCII and 1 for two byte). |
| 10058 | __ ldr(r0, FieldMemOperand(subject, String::kLengthOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10059 | __ mov(r0, Operand(r0, ASR, kSmiTagSize)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10060 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10061 | __ add(r9, subject, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 10062 | __ eor(r3, r3, Operand(1)); |
| 10063 | // Argument 4 (r3): End of string data |
| 10064 | // Argument 3 (r2): Start of string data |
| 10065 | __ add(r2, r9, Operand(r1, LSL, r3)); |
| 10066 | __ add(r3, r9, Operand(r0, LSL, r3)); |
| 10067 | |
| 10068 | // Argument 2 (r1): Previous index. |
| 10069 | // Already there |
| 10070 | |
| 10071 | // Argument 1 (r0): Subject string. |
| 10072 | __ mov(r0, subject); |
| 10073 | |
| 10074 | // Locate the code entry and call it. |
| 10075 | __ add(r7, r7, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 10076 | __ CallCFunction(r7, kRegExpExecuteArguments); |
| 10077 | __ pop(lr); |
| 10078 | |
| 10079 | // r0: result |
| 10080 | // subject: subject string (callee saved) |
| 10081 | // regexp_data: RegExp data (callee saved) |
| 10082 | // last_match_info_elements: Last match info elements (callee saved) |
| 10083 | |
| 10084 | // Check the result. |
| 10085 | Label success; |
| 10086 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::SUCCESS)); |
| 10087 | __ b(eq, &success); |
| 10088 | Label failure; |
| 10089 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
| 10090 | __ b(eq, &failure); |
| 10091 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
| 10092 | // If not exception it can only be retry. Handle that in the runtime system. |
| 10093 | __ b(ne, &runtime); |
| 10094 | // Result must now be exception. If there is no pending exception already a |
| 10095 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 10096 | // haven't created the exception yet. Handle that in the runtime system. |
| 10097 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
| 10098 | __ mov(r0, Operand(ExternalReference::the_hole_value_location())); |
| 10099 | __ ldr(r0, MemOperand(r0, 0)); |
| 10100 | __ mov(r1, Operand(ExternalReference(Top::k_pending_exception_address))); |
| 10101 | __ ldr(r1, MemOperand(r1, 0)); |
| 10102 | __ cmp(r0, r1); |
| 10103 | __ b(eq, &runtime); |
| 10104 | __ bind(&failure); |
| 10105 | // For failure and exception return null. |
| 10106 | __ mov(r0, Operand(Factory::null_value())); |
| 10107 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 10108 | __ Ret(); |
| 10109 | |
| 10110 | // Process the result from the native regexp code. |
| 10111 | __ bind(&success); |
| 10112 | __ ldr(r1, |
| 10113 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 10114 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10115 | STATIC_ASSERT(kSmiTag == 0); |
| 10116 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10117 | __ add(r1, r1, Operand(2)); // r1 was a smi. |
| 10118 | |
| 10119 | // r1: number of capture registers |
| 10120 | // r4: subject string |
| 10121 | // Store the capture count. |
| 10122 | __ mov(r2, Operand(r1, LSL, kSmiTagSize + kSmiShiftSize)); // To smi. |
| 10123 | __ str(r2, FieldMemOperand(last_match_info_elements, |
| 10124 | RegExpImpl::kLastCaptureCountOffset)); |
| 10125 | // Store last subject and last input. |
| 10126 | __ mov(r3, last_match_info_elements); // Moved up to reduce latency. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10127 | __ str(subject, |
| 10128 | FieldMemOperand(last_match_info_elements, |
| 10129 | RegExpImpl::kLastSubjectOffset)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 10130 | __ RecordWrite(r3, Operand(RegExpImpl::kLastSubjectOffset), r2, r7); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10131 | __ str(subject, |
| 10132 | FieldMemOperand(last_match_info_elements, |
| 10133 | RegExpImpl::kLastInputOffset)); |
| 10134 | __ mov(r3, last_match_info_elements); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 10135 | __ RecordWrite(r3, Operand(RegExpImpl::kLastInputOffset), r2, r7); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10136 | |
| 10137 | // Get the static offsets vector filled by the native regexp code. |
| 10138 | ExternalReference address_of_static_offsets_vector = |
| 10139 | ExternalReference::address_of_static_offsets_vector(); |
| 10140 | __ mov(r2, Operand(address_of_static_offsets_vector)); |
| 10141 | |
| 10142 | // r1: number of capture registers |
| 10143 | // r2: offsets vector |
| 10144 | Label next_capture, done; |
| 10145 | // Capture register counter starts from number of capture registers and |
| 10146 | // counts down until wraping after zero. |
| 10147 | __ add(r0, |
| 10148 | last_match_info_elements, |
| 10149 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 10150 | __ bind(&next_capture); |
| 10151 | __ sub(r1, r1, Operand(1), SetCC); |
| 10152 | __ b(mi, &done); |
| 10153 | // Read the value from the static offsets vector buffer. |
| 10154 | __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex)); |
| 10155 | // Store the smi value in the last match info. |
| 10156 | __ mov(r3, Operand(r3, LSL, kSmiTagSize)); |
| 10157 | __ str(r3, MemOperand(r0, kPointerSize, PostIndex)); |
| 10158 | __ jmp(&next_capture); |
| 10159 | __ bind(&done); |
| 10160 | |
| 10161 | // Return last match info. |
| 10162 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
| 10163 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 10164 | __ Ret(); |
| 10165 | |
| 10166 | // Do the runtime call to execute the regexp. |
| 10167 | __ bind(&runtime); |
| 10168 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 10169 | #endif // V8_INTERPRETED_REGEXP |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 10170 | } |
| 10171 | |
| 10172 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10173 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
| 10174 | Label slow; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 10175 | |
| 10176 | // If the receiver might be a value (string, number or boolean) check for this |
| 10177 | // and box it if it is. |
| 10178 | if (ReceiverMightBeValue()) { |
| 10179 | // Get the receiver from the stack. |
| 10180 | // function, receiver [, arguments] |
| 10181 | Label receiver_is_value, receiver_is_js_object; |
| 10182 | __ ldr(r1, MemOperand(sp, argc_ * kPointerSize)); |
| 10183 | |
| 10184 | // Check if receiver is a smi (which is a number value). |
| 10185 | __ BranchOnSmi(r1, &receiver_is_value); |
| 10186 | |
| 10187 | // Check if the receiver is a valid JS object. |
| 10188 | __ CompareObjectType(r1, r2, r2, FIRST_JS_OBJECT_TYPE); |
| 10189 | __ b(ge, &receiver_is_js_object); |
| 10190 | |
| 10191 | // Call the runtime to box the value. |
| 10192 | __ bind(&receiver_is_value); |
| 10193 | __ EnterInternalFrame(); |
| 10194 | __ push(r1); |
| 10195 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS); |
| 10196 | __ LeaveInternalFrame(); |
| 10197 | __ str(r0, MemOperand(sp, argc_ * kPointerSize)); |
| 10198 | |
| 10199 | __ bind(&receiver_is_js_object); |
| 10200 | } |
| 10201 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10202 | // Get the function to call from the stack. |
| 10203 | // function, receiver [, arguments] |
| 10204 | __ ldr(r1, MemOperand(sp, (argc_ + 1) * kPointerSize)); |
| 10205 | |
| 10206 | // Check that the function is really a JavaScript function. |
| 10207 | // r1: pushed function (to be verified) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 10208 | __ BranchOnSmi(r1, &slow); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10209 | // Get the map of the function object. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 10210 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10211 | __ b(ne, &slow); |
| 10212 | |
| 10213 | // Fast-case: Invoke the function now. |
| 10214 | // r1: pushed function |
| 10215 | ParameterCount actual(argc_); |
| 10216 | __ InvokeFunction(r1, actual, JUMP_FUNCTION); |
| 10217 | |
| 10218 | // Slow-case: Non-function called. |
| 10219 | __ bind(&slow); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10220 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 10221 | // of the original receiver from the call site). |
| 10222 | __ str(r1, MemOperand(sp, argc_ * kPointerSize)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10223 | __ mov(r0, Operand(argc_)); // Setup the number of arguments. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 10224 | __ mov(r2, Operand(0)); |
| 10225 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
| 10226 | __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), |
| 10227 | RelocInfo::CODE_TARGET); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 10228 | } |
| 10229 | |
| 10230 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10231 | // Unfortunately you have to run without snapshots to see most of these |
| 10232 | // names in the profile since most compare stubs end up in the snapshot. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 10233 | const char* CompareStub::GetName() { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10234 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 10235 | (lhs_.is(r1) && rhs_.is(r0))); |
| 10236 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10237 | if (name_ != NULL) return name_; |
| 10238 | const int kMaxNameLength = 100; |
| 10239 | name_ = Bootstrapper::AllocateAutoDeletedArray(kMaxNameLength); |
| 10240 | if (name_ == NULL) return "OOM"; |
| 10241 | |
| 10242 | const char* cc_name; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 10243 | switch (cc_) { |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10244 | case lt: cc_name = "LT"; break; |
| 10245 | case gt: cc_name = "GT"; break; |
| 10246 | case le: cc_name = "LE"; break; |
| 10247 | case ge: cc_name = "GE"; break; |
| 10248 | case eq: cc_name = "EQ"; break; |
| 10249 | case ne: cc_name = "NE"; break; |
| 10250 | default: cc_name = "UnknownCondition"; break; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 10251 | } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10252 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10253 | const char* lhs_name = lhs_.is(r0) ? "_r0" : "_r1"; |
| 10254 | const char* rhs_name = rhs_.is(r0) ? "_r0" : "_r1"; |
| 10255 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10256 | const char* strict_name = ""; |
| 10257 | if (strict_ && (cc_ == eq || cc_ == ne)) { |
| 10258 | strict_name = "_STRICT"; |
| 10259 | } |
| 10260 | |
| 10261 | const char* never_nan_nan_name = ""; |
| 10262 | if (never_nan_nan_ && (cc_ == eq || cc_ == ne)) { |
| 10263 | never_nan_nan_name = "_NO_NAN"; |
| 10264 | } |
| 10265 | |
| 10266 | const char* include_number_compare_name = ""; |
| 10267 | if (!include_number_compare_) { |
| 10268 | include_number_compare_name = "_NO_NUMBER"; |
| 10269 | } |
| 10270 | |
| 10271 | OS::SNPrintF(Vector<char>(name_, kMaxNameLength), |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10272 | "CompareStub_%s%s%s%s%s%s", |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10273 | cc_name, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10274 | lhs_name, |
| 10275 | rhs_name, |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10276 | strict_name, |
| 10277 | never_nan_nan_name, |
| 10278 | include_number_compare_name); |
| 10279 | return name_; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 10280 | } |
| 10281 | |
| 10282 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 10283 | int CompareStub::MinorKey() { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 10284 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 10285 | // stubs the never NaN NaN condition is only taken into account if the |
| 10286 | // condition is equals. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10287 | ASSERT((static_cast<unsigned>(cc_) >> 28) < (1 << 12)); |
| 10288 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 10289 | (lhs_.is(r1) && rhs_.is(r0))); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 10290 | return ConditionField::encode(static_cast<unsigned>(cc_) >> 28) |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 10291 | | RegisterField::encode(lhs_.is(r0)) |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 10292 | | StrictField::encode(strict_) |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 10293 | | NeverNanNanField::encode(cc_ == eq ? never_nan_nan_ : false) |
| 10294 | | IncludeNumberCompareField::encode(include_number_compare_); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 10295 | } |
| 10296 | |
| 10297 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10298 | // StringCharCodeAtGenerator |
| 10299 | |
| 10300 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 10301 | Label flat_string; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10302 | Label ascii_string; |
| 10303 | Label got_char_code; |
| 10304 | |
| 10305 | // If the receiver is a smi trigger the non-string case. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10306 | __ BranchOnSmi(object_, receiver_not_string_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10307 | |
| 10308 | // Fetch the instance type of the receiver into result register. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10309 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 10310 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10311 | // If the receiver is not a string trigger the non-string case. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10312 | __ tst(result_, Operand(kIsNotStringMask)); |
| 10313 | __ b(ne, receiver_not_string_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10314 | |
| 10315 | // If the index is non-smi trigger the non-smi case. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10316 | __ BranchOnNotSmi(index_, &index_not_smi_); |
| 10317 | |
| 10318 | // Put smi-tagged index into scratch register. |
| 10319 | __ mov(scratch_, index_); |
| 10320 | __ bind(&got_smi_index_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10321 | |
| 10322 | // Check for index out of range. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10323 | __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset)); |
| 10324 | __ cmp(ip, Operand(scratch_)); |
| 10325 | __ b(ls, index_out_of_range_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10326 | |
| 10327 | // We need special handling for non-flat strings. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10328 | STATIC_ASSERT(kSeqStringTag == 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10329 | __ tst(result_, Operand(kStringRepresentationMask)); |
| 10330 | __ b(eq, &flat_string); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10331 | |
| 10332 | // Handle non-flat strings. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10333 | __ tst(result_, Operand(kIsConsStringMask)); |
| 10334 | __ b(eq, &call_runtime_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10335 | |
| 10336 | // ConsString. |
| 10337 | // Check whether the right hand side is the empty string (i.e. if |
| 10338 | // this is really a flat string in a cons string). If that is not |
| 10339 | // the case we would rather go to the runtime system now to flatten |
| 10340 | // the string. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10341 | __ ldr(result_, FieldMemOperand(object_, ConsString::kSecondOffset)); |
| 10342 | __ LoadRoot(ip, Heap::kEmptyStringRootIndex); |
| 10343 | __ cmp(result_, Operand(ip)); |
| 10344 | __ b(ne, &call_runtime_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10345 | // Get the first of the two strings and load its instance type. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10346 | __ ldr(object_, FieldMemOperand(object_, ConsString::kFirstOffset)); |
| 10347 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 10348 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 10349 | // If the first cons component is also non-flat, then go to runtime. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10350 | STATIC_ASSERT(kSeqStringTag == 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10351 | __ tst(result_, Operand(kStringRepresentationMask)); |
| 10352 | __ b(nz, &call_runtime_); |
| 10353 | |
| 10354 | // Check for 1-byte or 2-byte string. |
| 10355 | __ bind(&flat_string); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10356 | STATIC_ASSERT(kAsciiStringTag != 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10357 | __ tst(result_, Operand(kStringEncodingMask)); |
| 10358 | __ b(nz, &ascii_string); |
| 10359 | |
| 10360 | // 2-byte string. |
| 10361 | // Load the 2-byte character code into the result register. We can |
| 10362 | // add without shifting since the smi tag size is the log2 of the |
| 10363 | // number of bytes in a two-byte character. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10364 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1 && kSmiShiftSize == 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10365 | __ add(scratch_, object_, Operand(scratch_)); |
| 10366 | __ ldrh(result_, FieldMemOperand(scratch_, SeqTwoByteString::kHeaderSize)); |
| 10367 | __ jmp(&got_char_code); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10368 | |
| 10369 | // ASCII string. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10370 | // Load the byte into the result register. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10371 | __ bind(&ascii_string); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10372 | __ add(scratch_, object_, Operand(scratch_, LSR, kSmiTagSize)); |
| 10373 | __ ldrb(result_, FieldMemOperand(scratch_, SeqAsciiString::kHeaderSize)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10374 | |
| 10375 | __ bind(&got_char_code); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10376 | __ mov(result_, Operand(result_, LSL, kSmiTagSize)); |
| 10377 | __ bind(&exit_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10378 | } |
| 10379 | |
| 10380 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10381 | void StringCharCodeAtGenerator::GenerateSlow( |
| 10382 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 10383 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10384 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10385 | // Index is not a smi. |
| 10386 | __ bind(&index_not_smi_); |
| 10387 | // If index is a heap number, try converting it to an integer. |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 10388 | __ CheckMap(index_, |
| 10389 | scratch_, |
| 10390 | Heap::kHeapNumberMapRootIndex, |
| 10391 | index_not_number_, |
| 10392 | true); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10393 | call_helper.BeforeCall(masm); |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 10394 | __ Push(object_, index_); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10395 | __ push(index_); // Consumed by runtime conversion function. |
| 10396 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 10397 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 10398 | } else { |
| 10399 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 10400 | // NumberToSmi discards numbers that are not exact integers. |
| 10401 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 10402 | } |
| 10403 | if (!scratch_.is(r0)) { |
| 10404 | // Save the conversion result before the pop instructions below |
| 10405 | // have a chance to overwrite it. |
| 10406 | __ mov(scratch_, r0); |
| 10407 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10408 | __ pop(index_); |
| 10409 | __ pop(object_); |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 10410 | // Reload the instance type. |
| 10411 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 10412 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10413 | call_helper.AfterCall(masm); |
| 10414 | // If index is still not a smi, it must be out of range. |
| 10415 | __ BranchOnNotSmi(scratch_, index_out_of_range_); |
| 10416 | // Otherwise, return to the fast path. |
| 10417 | __ jmp(&got_smi_index_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10418 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10419 | // Call runtime. We get here when the receiver is a string and the |
| 10420 | // index is a number, but the code of getting the actual character |
| 10421 | // is too complex (e.g., when the string needs to be flattened). |
| 10422 | __ bind(&call_runtime_); |
| 10423 | call_helper.BeforeCall(masm); |
| 10424 | __ Push(object_, index_); |
| 10425 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 10426 | if (!result_.is(r0)) { |
| 10427 | __ mov(result_, r0); |
| 10428 | } |
| 10429 | call_helper.AfterCall(masm); |
| 10430 | __ jmp(&exit_); |
| 10431 | |
| 10432 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 10433 | } |
| 10434 | |
| 10435 | |
| 10436 | // ------------------------------------------------------------------------- |
| 10437 | // StringCharFromCodeGenerator |
| 10438 | |
| 10439 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10440 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10441 | STATIC_ASSERT(kSmiTag == 0); |
| 10442 | STATIC_ASSERT(kSmiShiftSize == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10443 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10444 | __ tst(code_, |
| 10445 | Operand(kSmiTagMask | |
| 10446 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
| 10447 | __ b(nz, &slow_case_); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10448 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10449 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
| 10450 | // At this point code register contains smi tagged ascii char code. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10451 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10452 | __ add(result_, result_, Operand(code_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 10453 | __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 10454 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 10455 | __ cmp(result_, Operand(ip)); |
| 10456 | __ b(eq, &slow_case_); |
| 10457 | __ bind(&exit_); |
| 10458 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10459 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10460 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10461 | void StringCharFromCodeGenerator::GenerateSlow( |
| 10462 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 10463 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 10464 | |
| 10465 | __ bind(&slow_case_); |
| 10466 | call_helper.BeforeCall(masm); |
| 10467 | __ push(code_); |
| 10468 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 10469 | if (!result_.is(r0)) { |
| 10470 | __ mov(result_, r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10471 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 10472 | call_helper.AfterCall(masm); |
| 10473 | __ jmp(&exit_); |
| 10474 | |
| 10475 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 10476 | } |
| 10477 | |
| 10478 | |
| 10479 | // ------------------------------------------------------------------------- |
| 10480 | // StringCharAtGenerator |
| 10481 | |
| 10482 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 10483 | char_code_at_generator_.GenerateFast(masm); |
| 10484 | char_from_code_generator_.GenerateFast(masm); |
| 10485 | } |
| 10486 | |
| 10487 | |
| 10488 | void StringCharAtGenerator::GenerateSlow( |
| 10489 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 10490 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 10491 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10492 | } |
| 10493 | |
| 10494 | |
| 10495 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 10496 | Register dest, |
| 10497 | Register src, |
| 10498 | Register count, |
| 10499 | Register scratch, |
| 10500 | bool ascii) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10501 | Label loop; |
| 10502 | Label done; |
| 10503 | // This loop just copies one character at a time, as it is only used for very |
| 10504 | // short strings. |
| 10505 | if (!ascii) { |
| 10506 | __ add(count, count, Operand(count), SetCC); |
| 10507 | } else { |
| 10508 | __ cmp(count, Operand(0)); |
| 10509 | } |
| 10510 | __ b(eq, &done); |
| 10511 | |
| 10512 | __ bind(&loop); |
| 10513 | __ ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 10514 | // Perform sub between load and dependent store to get the load time to |
| 10515 | // complete. |
| 10516 | __ sub(count, count, Operand(1), SetCC); |
| 10517 | __ strb(scratch, MemOperand(dest, 1, PostIndex)); |
| 10518 | // last iteration. |
| 10519 | __ b(gt, &loop); |
| 10520 | |
| 10521 | __ bind(&done); |
| 10522 | } |
| 10523 | |
| 10524 | |
| 10525 | enum CopyCharactersFlags { |
| 10526 | COPY_ASCII = 1, |
| 10527 | DEST_ALWAYS_ALIGNED = 2 |
| 10528 | }; |
| 10529 | |
| 10530 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10531 | void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm, |
| 10532 | Register dest, |
| 10533 | Register src, |
| 10534 | Register count, |
| 10535 | Register scratch1, |
| 10536 | Register scratch2, |
| 10537 | Register scratch3, |
| 10538 | Register scratch4, |
| 10539 | Register scratch5, |
| 10540 | int flags) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10541 | bool ascii = (flags & COPY_ASCII) != 0; |
| 10542 | bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0; |
| 10543 | |
| 10544 | if (dest_always_aligned && FLAG_debug_code) { |
| 10545 | // Check that destination is actually word aligned if the flag says |
| 10546 | // that it is. |
| 10547 | __ tst(dest, Operand(kPointerAlignmentMask)); |
| 10548 | __ Check(eq, "Destination of copy not aligned."); |
| 10549 | } |
| 10550 | |
| 10551 | const int kReadAlignment = 4; |
| 10552 | const int kReadAlignmentMask = kReadAlignment - 1; |
| 10553 | // Ensure that reading an entire aligned word containing the last character |
| 10554 | // of a string will not read outside the allocated area (because we pad up |
| 10555 | // to kObjectAlignment). |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10556 | STATIC_ASSERT(kObjectAlignment >= kReadAlignment); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10557 | // Assumes word reads and writes are little endian. |
| 10558 | // Nothing to do for zero characters. |
| 10559 | Label done; |
| 10560 | if (!ascii) { |
| 10561 | __ add(count, count, Operand(count), SetCC); |
| 10562 | } else { |
| 10563 | __ cmp(count, Operand(0)); |
| 10564 | } |
| 10565 | __ b(eq, &done); |
| 10566 | |
| 10567 | // Assume that you cannot read (or write) unaligned. |
| 10568 | Label byte_loop; |
| 10569 | // Must copy at least eight bytes, otherwise just do it one byte at a time. |
| 10570 | __ cmp(count, Operand(8)); |
| 10571 | __ add(count, dest, Operand(count)); |
| 10572 | Register limit = count; // Read until src equals this. |
| 10573 | __ b(lt, &byte_loop); |
| 10574 | |
| 10575 | if (!dest_always_aligned) { |
| 10576 | // Align dest by byte copying. Copies between zero and three bytes. |
| 10577 | __ and_(scratch4, dest, Operand(kReadAlignmentMask), SetCC); |
| 10578 | Label dest_aligned; |
| 10579 | __ b(eq, &dest_aligned); |
| 10580 | __ cmp(scratch4, Operand(2)); |
| 10581 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex)); |
| 10582 | __ ldrb(scratch2, MemOperand(src, 1, PostIndex), le); |
| 10583 | __ ldrb(scratch3, MemOperand(src, 1, PostIndex), lt); |
| 10584 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 10585 | __ strb(scratch2, MemOperand(dest, 1, PostIndex), le); |
| 10586 | __ strb(scratch3, MemOperand(dest, 1, PostIndex), lt); |
| 10587 | __ bind(&dest_aligned); |
| 10588 | } |
| 10589 | |
| 10590 | Label simple_loop; |
| 10591 | |
| 10592 | __ sub(scratch4, dest, Operand(src)); |
| 10593 | __ and_(scratch4, scratch4, Operand(0x03), SetCC); |
| 10594 | __ b(eq, &simple_loop); |
| 10595 | // Shift register is number of bits in a source word that |
| 10596 | // must be combined with bits in the next source word in order |
| 10597 | // to create a destination word. |
| 10598 | |
| 10599 | // Complex loop for src/dst that are not aligned the same way. |
| 10600 | { |
| 10601 | Label loop; |
| 10602 | __ mov(scratch4, Operand(scratch4, LSL, 3)); |
| 10603 | Register left_shift = scratch4; |
| 10604 | __ and_(src, src, Operand(~3)); // Round down to load previous word. |
| 10605 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 10606 | // Store the "shift" most significant bits of scratch in the least |
| 10607 | // signficant bits (i.e., shift down by (32-shift)). |
| 10608 | __ rsb(scratch2, left_shift, Operand(32)); |
| 10609 | Register right_shift = scratch2; |
| 10610 | __ mov(scratch1, Operand(scratch1, LSR, right_shift)); |
| 10611 | |
| 10612 | __ bind(&loop); |
| 10613 | __ ldr(scratch3, MemOperand(src, 4, PostIndex)); |
| 10614 | __ sub(scratch5, limit, Operand(dest)); |
| 10615 | __ orr(scratch1, scratch1, Operand(scratch3, LSL, left_shift)); |
| 10616 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 10617 | __ mov(scratch1, Operand(scratch3, LSR, right_shift)); |
| 10618 | // Loop if four or more bytes left to copy. |
| 10619 | // Compare to eight, because we did the subtract before increasing dst. |
| 10620 | __ sub(scratch5, scratch5, Operand(8), SetCC); |
| 10621 | __ b(ge, &loop); |
| 10622 | } |
| 10623 | // There is now between zero and three bytes left to copy (negative that |
| 10624 | // number is in scratch5), and between one and three bytes already read into |
| 10625 | // scratch1 (eight times that number in scratch4). We may have read past |
| 10626 | // the end of the string, but because objects are aligned, we have not read |
| 10627 | // past the end of the object. |
| 10628 | // Find the minimum of remaining characters to move and preloaded characters |
| 10629 | // and write those as bytes. |
| 10630 | __ add(scratch5, scratch5, Operand(4), SetCC); |
| 10631 | __ b(eq, &done); |
| 10632 | __ cmp(scratch4, Operand(scratch5, LSL, 3), ne); |
| 10633 | // Move minimum of bytes read and bytes left to copy to scratch4. |
| 10634 | __ mov(scratch5, Operand(scratch4, LSR, 3), LeaveCC, lt); |
| 10635 | // Between one and three (value in scratch5) characters already read into |
| 10636 | // scratch ready to write. |
| 10637 | __ cmp(scratch5, Operand(2)); |
| 10638 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 10639 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, ge); |
| 10640 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), ge); |
| 10641 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, gt); |
| 10642 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), gt); |
| 10643 | // Copy any remaining bytes. |
| 10644 | __ b(&byte_loop); |
| 10645 | |
| 10646 | // Simple loop. |
| 10647 | // Copy words from src to dst, until less than four bytes left. |
| 10648 | // Both src and dest are word aligned. |
| 10649 | __ bind(&simple_loop); |
| 10650 | { |
| 10651 | Label loop; |
| 10652 | __ bind(&loop); |
| 10653 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 10654 | __ sub(scratch3, limit, Operand(dest)); |
| 10655 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 10656 | // Compare to 8, not 4, because we do the substraction before increasing |
| 10657 | // dest. |
| 10658 | __ cmp(scratch3, Operand(8)); |
| 10659 | __ b(ge, &loop); |
| 10660 | } |
| 10661 | |
| 10662 | // Copy bytes from src to dst until dst hits limit. |
| 10663 | __ bind(&byte_loop); |
| 10664 | __ cmp(dest, Operand(limit)); |
| 10665 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex), lt); |
| 10666 | __ b(ge, &done); |
| 10667 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 10668 | __ b(&byte_loop); |
| 10669 | |
| 10670 | __ bind(&done); |
| 10671 | } |
| 10672 | |
| 10673 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10674 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 10675 | Register c1, |
| 10676 | Register c2, |
| 10677 | Register scratch1, |
| 10678 | Register scratch2, |
| 10679 | Register scratch3, |
| 10680 | Register scratch4, |
| 10681 | Register scratch5, |
| 10682 | Label* not_found) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10683 | // Register scratch3 is the general scratch register in this function. |
| 10684 | Register scratch = scratch3; |
| 10685 | |
| 10686 | // Make sure that both characters are not digits as such strings has a |
| 10687 | // different hash algorithm. Don't try to look for these in the symbol table. |
| 10688 | Label not_array_index; |
| 10689 | __ sub(scratch, c1, Operand(static_cast<int>('0'))); |
| 10690 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 10691 | __ b(hi, ¬_array_index); |
| 10692 | __ sub(scratch, c2, Operand(static_cast<int>('0'))); |
| 10693 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 10694 | |
| 10695 | // If check failed combine both characters into single halfword. |
| 10696 | // This is required by the contract of the method: code at the |
| 10697 | // not_found branch expects this combination in c1 register |
| 10698 | __ orr(c1, c1, Operand(c2, LSL, kBitsPerByte), LeaveCC, ls); |
| 10699 | __ b(ls, not_found); |
| 10700 | |
| 10701 | __ bind(¬_array_index); |
| 10702 | // Calculate the two character string hash. |
| 10703 | Register hash = scratch1; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10704 | StringHelper::GenerateHashInit(masm, hash, c1); |
| 10705 | StringHelper::GenerateHashAddCharacter(masm, hash, c2); |
| 10706 | StringHelper::GenerateHashGetHash(masm, hash); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10707 | |
| 10708 | // Collect the two characters in a register. |
| 10709 | Register chars = c1; |
| 10710 | __ orr(chars, chars, Operand(c2, LSL, kBitsPerByte)); |
| 10711 | |
| 10712 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 10713 | // hash: hash of two character string. |
| 10714 | |
| 10715 | // Load symbol table |
| 10716 | // Load address of first element of the symbol table. |
| 10717 | Register symbol_table = c2; |
| 10718 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 10719 | |
| 10720 | // Load undefined value |
| 10721 | Register undefined = scratch4; |
| 10722 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 10723 | |
| 10724 | // Calculate capacity mask from the symbol table capacity. |
| 10725 | Register mask = scratch2; |
| 10726 | __ ldr(mask, FieldMemOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 10727 | __ mov(mask, Operand(mask, ASR, 1)); |
| 10728 | __ sub(mask, mask, Operand(1)); |
| 10729 | |
| 10730 | // Calculate untagged address of the first element of the symbol table. |
| 10731 | Register first_symbol_table_element = symbol_table; |
| 10732 | __ add(first_symbol_table_element, symbol_table, |
| 10733 | Operand(SymbolTable::kElementsStartOffset - kHeapObjectTag)); |
| 10734 | |
| 10735 | // Registers |
| 10736 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 10737 | // hash: hash of two character string |
| 10738 | // mask: capacity mask |
| 10739 | // first_symbol_table_element: address of the first element of |
| 10740 | // the symbol table |
| 10741 | // scratch: - |
| 10742 | |
| 10743 | // Perform a number of probes in the symbol table. |
| 10744 | static const int kProbes = 4; |
| 10745 | Label found_in_symbol_table; |
| 10746 | Label next_probe[kProbes]; |
| 10747 | for (int i = 0; i < kProbes; i++) { |
| 10748 | Register candidate = scratch5; // Scratch register contains candidate. |
| 10749 | |
| 10750 | // Calculate entry in symbol table. |
| 10751 | if (i > 0) { |
| 10752 | __ add(candidate, hash, Operand(SymbolTable::GetProbeOffset(i))); |
| 10753 | } else { |
| 10754 | __ mov(candidate, hash); |
| 10755 | } |
| 10756 | |
| 10757 | __ and_(candidate, candidate, Operand(mask)); |
| 10758 | |
| 10759 | // Load the entry from the symble table. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10760 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10761 | __ ldr(candidate, |
| 10762 | MemOperand(first_symbol_table_element, |
| 10763 | candidate, |
| 10764 | LSL, |
| 10765 | kPointerSizeLog2)); |
| 10766 | |
| 10767 | // If entry is undefined no string with this hash can be found. |
| 10768 | __ cmp(candidate, undefined); |
| 10769 | __ b(eq, not_found); |
| 10770 | |
| 10771 | // If length is not 2 the string is not a candidate. |
| 10772 | __ ldr(scratch, FieldMemOperand(candidate, String::kLengthOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10773 | __ cmp(scratch, Operand(Smi::FromInt(2))); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10774 | __ b(ne, &next_probe[i]); |
| 10775 | |
| 10776 | // Check that the candidate is a non-external ascii string. |
| 10777 | __ ldr(scratch, FieldMemOperand(candidate, HeapObject::kMapOffset)); |
| 10778 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 10779 | __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, |
| 10780 | &next_probe[i]); |
| 10781 | |
| 10782 | // Check if the two characters match. |
| 10783 | // Assumes that word load is little endian. |
| 10784 | __ ldrh(scratch, FieldMemOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 10785 | __ cmp(chars, scratch); |
| 10786 | __ b(eq, &found_in_symbol_table); |
| 10787 | __ bind(&next_probe[i]); |
| 10788 | } |
| 10789 | |
| 10790 | // No matching 2 character string found by probing. |
| 10791 | __ jmp(not_found); |
| 10792 | |
| 10793 | // Scratch register contains result when we fall through to here. |
| 10794 | Register result = scratch; |
| 10795 | __ bind(&found_in_symbol_table); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 10796 | __ Move(r0, result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10797 | } |
| 10798 | |
| 10799 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10800 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 10801 | Register hash, |
| 10802 | Register character) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10803 | // hash = character + (character << 10); |
| 10804 | __ add(hash, character, Operand(character, LSL, 10)); |
| 10805 | // hash ^= hash >> 6; |
| 10806 | __ eor(hash, hash, Operand(hash, ASR, 6)); |
| 10807 | } |
| 10808 | |
| 10809 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10810 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 10811 | Register hash, |
| 10812 | Register character) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10813 | // hash += character; |
| 10814 | __ add(hash, hash, Operand(character)); |
| 10815 | // hash += hash << 10; |
| 10816 | __ add(hash, hash, Operand(hash, LSL, 10)); |
| 10817 | // hash ^= hash >> 6; |
| 10818 | __ eor(hash, hash, Operand(hash, ASR, 6)); |
| 10819 | } |
| 10820 | |
| 10821 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10822 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 10823 | Register hash) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10824 | // hash += hash << 3; |
| 10825 | __ add(hash, hash, Operand(hash, LSL, 3)); |
| 10826 | // hash ^= hash >> 11; |
| 10827 | __ eor(hash, hash, Operand(hash, ASR, 11)); |
| 10828 | // hash += hash << 15; |
| 10829 | __ add(hash, hash, Operand(hash, LSL, 15), SetCC); |
| 10830 | |
| 10831 | // if (hash == 0) hash = 27; |
| 10832 | __ mov(hash, Operand(27), LeaveCC, nz); |
| 10833 | } |
| 10834 | |
| 10835 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10836 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 10837 | Label runtime; |
| 10838 | |
| 10839 | // Stack frame on entry. |
| 10840 | // lr: return address |
| 10841 | // sp[0]: to |
| 10842 | // sp[4]: from |
| 10843 | // sp[8]: string |
| 10844 | |
| 10845 | // This stub is called from the native-call %_SubString(...), so |
| 10846 | // nothing can be assumed about the arguments. It is tested that: |
| 10847 | // "string" is a sequential string, |
| 10848 | // both "from" and "to" are smis, and |
| 10849 | // 0 <= from <= to <= string.length. |
| 10850 | // If any of these assumptions fail, we call the runtime system. |
| 10851 | |
| 10852 | static const int kToOffset = 0 * kPointerSize; |
| 10853 | static const int kFromOffset = 1 * kPointerSize; |
| 10854 | static const int kStringOffset = 2 * kPointerSize; |
| 10855 | |
| 10856 | |
| 10857 | // Check bounds and smi-ness. |
| 10858 | __ ldr(r7, MemOperand(sp, kToOffset)); |
| 10859 | __ ldr(r6, MemOperand(sp, kFromOffset)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10860 | STATIC_ASSERT(kSmiTag == 0); |
| 10861 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10862 | // I.e., arithmetic shift right by one un-smi-tags. |
| 10863 | __ mov(r2, Operand(r7, ASR, 1), SetCC); |
| 10864 | __ mov(r3, Operand(r6, ASR, 1), SetCC, cc); |
| 10865 | // If either r2 or r6 had the smi tag bit set, then carry is set now. |
| 10866 | __ b(cs, &runtime); // Either "from" or "to" is not a smi. |
| 10867 | __ b(mi, &runtime); // From is negative. |
| 10868 | |
| 10869 | __ sub(r2, r2, Operand(r3), SetCC); |
| 10870 | __ b(mi, &runtime); // Fail if from > to. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10871 | // Special handling of sub-strings of length 1 and 2. One character strings |
| 10872 | // are handled in the runtime system (looked up in the single character |
| 10873 | // cache). Two character strings are looked for in the symbol cache. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10874 | __ cmp(r2, Operand(2)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10875 | __ b(lt, &runtime); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10876 | |
| 10877 | // r2: length |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10878 | // r3: from index (untaged smi) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10879 | // r6: from (smi) |
| 10880 | // r7: to (smi) |
| 10881 | |
| 10882 | // Make sure first argument is a sequential (or flat) string. |
| 10883 | __ ldr(r5, MemOperand(sp, kStringOffset)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10884 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10885 | __ tst(r5, Operand(kSmiTagMask)); |
| 10886 | __ b(eq, &runtime); |
| 10887 | Condition is_string = masm->IsObjectStringType(r5, r1); |
| 10888 | __ b(NegateCondition(is_string), &runtime); |
| 10889 | |
| 10890 | // r1: instance type |
| 10891 | // r2: length |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10892 | // r3: from index (untaged smi) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10893 | // r5: string |
| 10894 | // r6: from (smi) |
| 10895 | // r7: to (smi) |
| 10896 | Label seq_string; |
| 10897 | __ and_(r4, r1, Operand(kStringRepresentationMask)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10898 | STATIC_ASSERT(kSeqStringTag < kConsStringTag); |
| 10899 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10900 | __ cmp(r4, Operand(kConsStringTag)); |
| 10901 | __ b(gt, &runtime); // External strings go to runtime. |
| 10902 | __ b(lt, &seq_string); // Sequential strings are handled directly. |
| 10903 | |
| 10904 | // Cons string. Try to recurse (once) on the first substring. |
| 10905 | // (This adds a little more generality than necessary to handle flattened |
| 10906 | // cons strings, but not much). |
| 10907 | __ ldr(r5, FieldMemOperand(r5, ConsString::kFirstOffset)); |
| 10908 | __ ldr(r4, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 10909 | __ ldrb(r1, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 10910 | __ tst(r1, Operand(kStringRepresentationMask)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10911 | STATIC_ASSERT(kSeqStringTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10912 | __ b(ne, &runtime); // Cons and External strings go to runtime. |
| 10913 | |
| 10914 | // Definitly a sequential string. |
| 10915 | __ bind(&seq_string); |
| 10916 | |
| 10917 | // r1: instance type. |
| 10918 | // r2: length |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10919 | // r3: from index (untaged smi) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10920 | // r5: string |
| 10921 | // r6: from (smi) |
| 10922 | // r7: to (smi) |
| 10923 | __ ldr(r4, FieldMemOperand(r5, String::kLengthOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10924 | __ cmp(r4, Operand(r7)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10925 | __ b(lt, &runtime); // Fail if to > length. |
| 10926 | |
| 10927 | // r1: instance type. |
| 10928 | // r2: result string length. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10929 | // r3: from index (untaged smi) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10930 | // r5: string. |
| 10931 | // r6: from offset (smi) |
| 10932 | // Check for flat ascii string. |
| 10933 | Label non_ascii_flat; |
| 10934 | __ tst(r1, Operand(kStringEncodingMask)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10935 | STATIC_ASSERT(kTwoByteStringTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10936 | __ b(eq, &non_ascii_flat); |
| 10937 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10938 | Label result_longer_than_two; |
| 10939 | __ cmp(r2, Operand(2)); |
| 10940 | __ b(gt, &result_longer_than_two); |
| 10941 | |
| 10942 | // Sub string of length 2 requested. |
| 10943 | // Get the two characters forming the sub string. |
| 10944 | __ add(r5, r5, Operand(r3)); |
| 10945 | __ ldrb(r3, FieldMemOperand(r5, SeqAsciiString::kHeaderSize)); |
| 10946 | __ ldrb(r4, FieldMemOperand(r5, SeqAsciiString::kHeaderSize + 1)); |
| 10947 | |
| 10948 | // Try to lookup two character string in symbol table. |
| 10949 | Label make_two_character_string; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10950 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 10951 | masm, r3, r4, r1, r5, r6, r7, r9, &make_two_character_string); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 10952 | __ IncrementCounter(&Counters::sub_string_native, 1, r3, r4); |
| 10953 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 10954 | __ Ret(); |
| 10955 | |
| 10956 | // r2: result string length. |
| 10957 | // r3: two characters combined into halfword in little endian byte order. |
| 10958 | __ bind(&make_two_character_string); |
| 10959 | __ AllocateAsciiString(r0, r2, r4, r5, r9, &runtime); |
| 10960 | __ strh(r3, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
| 10961 | __ IncrementCounter(&Counters::sub_string_native, 1, r3, r4); |
| 10962 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 10963 | __ Ret(); |
| 10964 | |
| 10965 | __ bind(&result_longer_than_two); |
| 10966 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10967 | // Allocate the result. |
| 10968 | __ AllocateAsciiString(r0, r2, r3, r4, r1, &runtime); |
| 10969 | |
| 10970 | // r0: result string. |
| 10971 | // r2: result string length. |
| 10972 | // r5: string. |
| 10973 | // r6: from offset (smi) |
| 10974 | // Locate first character of result. |
| 10975 | __ add(r1, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 10976 | // Locate 'from' character of string. |
| 10977 | __ add(r5, r5, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 10978 | __ add(r5, r5, Operand(r6, ASR, 1)); |
| 10979 | |
| 10980 | // r0: result string. |
| 10981 | // r1: first character of result string. |
| 10982 | // r2: result string length. |
| 10983 | // r5: first character of sub string to copy. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 10984 | STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 10985 | StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9, |
| 10986 | COPY_ASCII | DEST_ALWAYS_ALIGNED); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 10987 | __ IncrementCounter(&Counters::sub_string_native, 1, r3, r4); |
| 10988 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 10989 | __ Ret(); |
| 10990 | |
| 10991 | __ bind(&non_ascii_flat); |
| 10992 | // r2: result string length. |
| 10993 | // r5: string. |
| 10994 | // r6: from offset (smi) |
| 10995 | // Check for flat two byte string. |
| 10996 | |
| 10997 | // Allocate the result. |
| 10998 | __ AllocateTwoByteString(r0, r2, r1, r3, r4, &runtime); |
| 10999 | |
| 11000 | // r0: result string. |
| 11001 | // r2: result string length. |
| 11002 | // r5: string. |
| 11003 | // Locate first character of result. |
| 11004 | __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 11005 | // Locate 'from' character of string. |
| 11006 | __ add(r5, r5, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 11007 | // As "from" is a smi it is 2 times the value which matches the size of a two |
| 11008 | // byte character. |
| 11009 | __ add(r5, r5, Operand(r6)); |
| 11010 | |
| 11011 | // r0: result string. |
| 11012 | // r1: first character of result. |
| 11013 | // r2: result length. |
| 11014 | // r5: first character of string to copy. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11015 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11016 | StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9, |
| 11017 | DEST_ALWAYS_ALIGNED); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11018 | __ IncrementCounter(&Counters::sub_string_native, 1, r3, r4); |
| 11019 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 11020 | __ Ret(); |
| 11021 | |
| 11022 | // Just jump to runtime to create the sub string. |
| 11023 | __ bind(&runtime); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11024 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11025 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11026 | |
| 11027 | |
| 11028 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 11029 | Register left, |
| 11030 | Register right, |
| 11031 | Register scratch1, |
| 11032 | Register scratch2, |
| 11033 | Register scratch3, |
| 11034 | Register scratch4) { |
| 11035 | Label compare_lengths; |
| 11036 | // Find minimum length and length difference. |
| 11037 | __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 11038 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 11039 | __ sub(scratch3, scratch1, Operand(scratch2), SetCC); |
| 11040 | Register length_delta = scratch3; |
| 11041 | __ mov(scratch1, scratch2, LeaveCC, gt); |
| 11042 | Register min_length = scratch1; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11043 | STATIC_ASSERT(kSmiTag == 0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11044 | __ tst(min_length, Operand(min_length)); |
| 11045 | __ b(eq, &compare_lengths); |
| 11046 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11047 | // Untag smi. |
| 11048 | __ mov(min_length, Operand(min_length, ASR, kSmiTagSize)); |
| 11049 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11050 | // Setup registers so that we only need to increment one register |
| 11051 | // in the loop. |
| 11052 | __ add(scratch2, min_length, |
| 11053 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 11054 | __ add(left, left, Operand(scratch2)); |
| 11055 | __ add(right, right, Operand(scratch2)); |
| 11056 | // Registers left and right points to the min_length character of strings. |
| 11057 | __ rsb(min_length, min_length, Operand(-1)); |
| 11058 | Register index = min_length; |
| 11059 | // Index starts at -min_length. |
| 11060 | |
| 11061 | { |
| 11062 | // Compare loop. |
| 11063 | Label loop; |
| 11064 | __ bind(&loop); |
| 11065 | // Compare characters. |
| 11066 | __ add(index, index, Operand(1), SetCC); |
| 11067 | __ ldrb(scratch2, MemOperand(left, index), ne); |
| 11068 | __ ldrb(scratch4, MemOperand(right, index), ne); |
| 11069 | // Skip to compare lengths with eq condition true. |
| 11070 | __ b(eq, &compare_lengths); |
| 11071 | __ cmp(scratch2, scratch4); |
| 11072 | __ b(eq, &loop); |
| 11073 | // Fallthrough with eq condition false. |
| 11074 | } |
| 11075 | // Compare lengths - strings up to min-length are equal. |
| 11076 | __ bind(&compare_lengths); |
| 11077 | ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
| 11078 | // Use zero length_delta as result. |
| 11079 | __ mov(r0, Operand(length_delta), SetCC, eq); |
| 11080 | // Fall through to here if characters compare not-equal. |
| 11081 | __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt); |
| 11082 | __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt); |
| 11083 | __ Ret(); |
| 11084 | } |
| 11085 | |
| 11086 | |
| 11087 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 11088 | Label runtime; |
| 11089 | |
| 11090 | // Stack frame on entry. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11091 | // sp[0]: right string |
| 11092 | // sp[4]: left string |
| 11093 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // left |
| 11094 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // right |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11095 | |
| 11096 | Label not_same; |
| 11097 | __ cmp(r0, r1); |
| 11098 | __ b(ne, ¬_same); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11099 | STATIC_ASSERT(EQUAL == 0); |
| 11100 | STATIC_ASSERT(kSmiTag == 0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11101 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 11102 | __ IncrementCounter(&Counters::string_compare_native, 1, r1, r2); |
| 11103 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11104 | __ Ret(); |
| 11105 | |
| 11106 | __ bind(¬_same); |
| 11107 | |
| 11108 | // Check that both objects are sequential ascii strings. |
| 11109 | __ JumpIfNotBothSequentialAsciiStrings(r0, r1, r2, r3, &runtime); |
| 11110 | |
| 11111 | // Compare flat ascii strings natively. Remove arguments from stack first. |
| 11112 | __ IncrementCounter(&Counters::string_compare_native, 1, r2, r3); |
| 11113 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11114 | GenerateCompareFlatAsciiStrings(masm, r0, r1, r2, r3, r4, r5); |
| 11115 | |
| 11116 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 11117 | // tagged as a small integer. |
| 11118 | __ bind(&runtime); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11119 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 11120 | } |
| 11121 | |
| 11122 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11123 | void StringAddStub::Generate(MacroAssembler* masm) { |
| 11124 | Label string_add_runtime; |
| 11125 | // Stack on entry: |
| 11126 | // sp[0]: second argument. |
| 11127 | // sp[4]: first argument. |
| 11128 | |
| 11129 | // Load the two arguments. |
| 11130 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
| 11131 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
| 11132 | |
| 11133 | // Make sure that both arguments are strings if not known in advance. |
| 11134 | if (string_check_) { |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11135 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11136 | __ JumpIfEitherSmi(r0, r1, &string_add_runtime); |
| 11137 | // Load instance types. |
| 11138 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 11139 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 11140 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 11141 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11142 | STATIC_ASSERT(kStringTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11143 | // If either is not a string, go to runtime. |
| 11144 | __ tst(r4, Operand(kIsNotStringMask)); |
| 11145 | __ tst(r5, Operand(kIsNotStringMask), eq); |
| 11146 | __ b(ne, &string_add_runtime); |
| 11147 | } |
| 11148 | |
| 11149 | // Both arguments are strings. |
| 11150 | // r0: first string |
| 11151 | // r1: second string |
| 11152 | // r4: first string instance type (if string_check_) |
| 11153 | // r5: second string instance type (if string_check_) |
| 11154 | { |
| 11155 | Label strings_not_empty; |
| 11156 | // Check if either of the strings are empty. In that case return the other. |
| 11157 | __ ldr(r2, FieldMemOperand(r0, String::kLengthOffset)); |
| 11158 | __ ldr(r3, FieldMemOperand(r1, String::kLengthOffset)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11159 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11160 | __ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11161 | __ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11162 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11163 | // Else test if second string is empty. |
| 11164 | __ cmp(r3, Operand(Smi::FromInt(0)), ne); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11165 | __ b(ne, &strings_not_empty); // If either string was empty, return r0. |
| 11166 | |
| 11167 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11168 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11169 | __ Ret(); |
| 11170 | |
| 11171 | __ bind(&strings_not_empty); |
| 11172 | } |
| 11173 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11174 | __ mov(r2, Operand(r2, ASR, kSmiTagSize)); |
| 11175 | __ mov(r3, Operand(r3, ASR, kSmiTagSize)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11176 | // Both strings are non-empty. |
| 11177 | // r0: first string |
| 11178 | // r1: second string |
| 11179 | // r2: length of first string |
| 11180 | // r3: length of second string |
| 11181 | // r4: first string instance type (if string_check_) |
| 11182 | // r5: second string instance type (if string_check_) |
| 11183 | // Look at the length of the result of adding the two strings. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11184 | Label string_add_flat_result, longer_than_two; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11185 | // Adding two lengths can't overflow. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11186 | STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11187 | __ add(r6, r2, Operand(r3)); |
| 11188 | // Use the runtime system when adding two one character strings, as it |
| 11189 | // contains optimizations for this specific case using the symbol table. |
| 11190 | __ cmp(r6, Operand(2)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11191 | __ b(ne, &longer_than_two); |
| 11192 | |
| 11193 | // Check that both strings are non-external ascii strings. |
| 11194 | if (!string_check_) { |
| 11195 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 11196 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 11197 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 11198 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 11199 | } |
| 11200 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r7, |
| 11201 | &string_add_runtime); |
| 11202 | |
| 11203 | // Get the two characters forming the sub string. |
| 11204 | __ ldrb(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
| 11205 | __ ldrb(r3, FieldMemOperand(r1, SeqAsciiString::kHeaderSize)); |
| 11206 | |
| 11207 | // Try to lookup two character string in symbol table. If it is not found |
| 11208 | // just allocate a new one. |
| 11209 | Label make_two_character_string; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11210 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 11211 | masm, r2, r3, r6, r7, r4, r5, r9, &make_two_character_string); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11212 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11213 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11214 | __ Ret(); |
| 11215 | |
| 11216 | __ bind(&make_two_character_string); |
| 11217 | // Resulting string has length 2 and first chars of two strings |
| 11218 | // are combined into single halfword in r2 register. |
| 11219 | // So we can fill resulting string without two loops by a single |
| 11220 | // halfword store instruction (which assumes that processor is |
| 11221 | // in a little endian mode) |
| 11222 | __ mov(r6, Operand(2)); |
| 11223 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &string_add_runtime); |
| 11224 | __ strh(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
| 11225 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11226 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11227 | __ Ret(); |
| 11228 | |
| 11229 | __ bind(&longer_than_two); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11230 | // Check if resulting string will be flat. |
| 11231 | __ cmp(r6, Operand(String::kMinNonFlatLength)); |
| 11232 | __ b(lt, &string_add_flat_result); |
| 11233 | // Handle exceptionally long strings in the runtime system. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11234 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11235 | ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
| 11236 | // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
| 11237 | __ cmp(r6, Operand(String::kMaxLength + 1)); |
| 11238 | __ b(hs, &string_add_runtime); |
| 11239 | |
| 11240 | // If result is not supposed to be flat, allocate a cons string object. |
| 11241 | // If both strings are ascii the result is an ascii cons string. |
| 11242 | if (!string_check_) { |
| 11243 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 11244 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 11245 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 11246 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 11247 | } |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 11248 | Label non_ascii, allocated, ascii_data; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11249 | STATIC_ASSERT(kTwoByteStringTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11250 | __ tst(r4, Operand(kStringEncodingMask)); |
| 11251 | __ tst(r5, Operand(kStringEncodingMask), ne); |
| 11252 | __ b(eq, &non_ascii); |
| 11253 | |
| 11254 | // Allocate an ASCII cons string. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 11255 | __ bind(&ascii_data); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11256 | __ AllocateAsciiConsString(r7, r6, r4, r5, &string_add_runtime); |
| 11257 | __ bind(&allocated); |
| 11258 | // Fill the fields of the cons string. |
| 11259 | __ str(r0, FieldMemOperand(r7, ConsString::kFirstOffset)); |
| 11260 | __ str(r1, FieldMemOperand(r7, ConsString::kSecondOffset)); |
| 11261 | __ mov(r0, Operand(r7)); |
| 11262 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11263 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11264 | __ Ret(); |
| 11265 | |
| 11266 | __ bind(&non_ascii); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 11267 | // At least one of the strings is two-byte. Check whether it happens |
| 11268 | // to contain only ascii characters. |
| 11269 | // r4: first instance type. |
| 11270 | // r5: second instance type. |
| 11271 | __ tst(r4, Operand(kAsciiDataHintMask)); |
| 11272 | __ tst(r5, Operand(kAsciiDataHintMask), ne); |
| 11273 | __ b(ne, &ascii_data); |
| 11274 | __ eor(r4, r4, Operand(r5)); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11275 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 11276 | __ and_(r4, r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 11277 | __ cmp(r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 11278 | __ b(eq, &ascii_data); |
| 11279 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11280 | // Allocate a two byte cons string. |
| 11281 | __ AllocateTwoByteConsString(r7, r6, r4, r5, &string_add_runtime); |
| 11282 | __ jmp(&allocated); |
| 11283 | |
| 11284 | // Handle creating a flat result. First check that both strings are |
| 11285 | // sequential and that they have the same encoding. |
| 11286 | // r0: first string |
| 11287 | // r1: second string |
| 11288 | // r2: length of first string |
| 11289 | // r3: length of second string |
| 11290 | // r4: first string instance type (if string_check_) |
| 11291 | // r5: second string instance type (if string_check_) |
| 11292 | // r6: sum of lengths. |
| 11293 | __ bind(&string_add_flat_result); |
| 11294 | if (!string_check_) { |
| 11295 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 11296 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 11297 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 11298 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 11299 | } |
| 11300 | // Check that both strings are sequential. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 11301 | STATIC_ASSERT(kSeqStringTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11302 | __ tst(r4, Operand(kStringRepresentationMask)); |
| 11303 | __ tst(r5, Operand(kStringRepresentationMask), eq); |
| 11304 | __ b(ne, &string_add_runtime); |
| 11305 | // Now check if both strings have the same encoding (ASCII/Two-byte). |
| 11306 | // r0: first string. |
| 11307 | // r1: second string. |
| 11308 | // r2: length of first string. |
| 11309 | // r3: length of second string. |
| 11310 | // r6: sum of lengths.. |
| 11311 | Label non_ascii_string_add_flat_result; |
| 11312 | ASSERT(IsPowerOf2(kStringEncodingMask)); // Just one bit to test. |
| 11313 | __ eor(r7, r4, Operand(r5)); |
| 11314 | __ tst(r7, Operand(kStringEncodingMask)); |
| 11315 | __ b(ne, &string_add_runtime); |
| 11316 | // And see if it's ASCII or two-byte. |
| 11317 | __ tst(r4, Operand(kStringEncodingMask)); |
| 11318 | __ b(eq, &non_ascii_string_add_flat_result); |
| 11319 | |
| 11320 | // Both strings are sequential ASCII strings. We also know that they are |
| 11321 | // short (since the sum of the lengths is less than kMinNonFlatLength). |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11322 | // r6: length of resulting flat string |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11323 | __ AllocateAsciiString(r7, r6, r4, r5, r9, &string_add_runtime); |
| 11324 | // Locate first character of result. |
| 11325 | __ add(r6, r7, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 11326 | // Locate first character of first argument. |
| 11327 | __ add(r0, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 11328 | // r0: first character of first string. |
| 11329 | // r1: second string. |
| 11330 | // r2: length of first string. |
| 11331 | // r3: length of second string. |
| 11332 | // r6: first character of result. |
| 11333 | // r7: result string. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11334 | StringHelper::GenerateCopyCharacters(masm, r6, r0, r2, r4, true); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11335 | |
| 11336 | // Load second argument and locate first character. |
| 11337 | __ add(r1, r1, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 11338 | // r1: first character of second string. |
| 11339 | // r3: length of second string. |
| 11340 | // r6: next character of result. |
| 11341 | // r7: result string. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11342 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, true); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11343 | __ mov(r0, Operand(r7)); |
| 11344 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11345 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11346 | __ Ret(); |
| 11347 | |
| 11348 | __ bind(&non_ascii_string_add_flat_result); |
| 11349 | // Both strings are sequential two byte strings. |
| 11350 | // r0: first string. |
| 11351 | // r1: second string. |
| 11352 | // r2: length of first string. |
| 11353 | // r3: length of second string. |
| 11354 | // r6: sum of length of strings. |
| 11355 | __ AllocateTwoByteString(r7, r6, r4, r5, r9, &string_add_runtime); |
| 11356 | // r0: first string. |
| 11357 | // r1: second string. |
| 11358 | // r2: length of first string. |
| 11359 | // r3: length of second string. |
| 11360 | // r7: result string. |
| 11361 | |
| 11362 | // Locate first character of result. |
| 11363 | __ add(r6, r7, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 11364 | // Locate first character of first argument. |
| 11365 | __ add(r0, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 11366 | |
| 11367 | // r0: first character of first string. |
| 11368 | // r1: second string. |
| 11369 | // r2: length of first string. |
| 11370 | // r3: length of second string. |
| 11371 | // r6: first character of result. |
| 11372 | // r7: result string. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11373 | StringHelper::GenerateCopyCharacters(masm, r6, r0, r2, r4, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11374 | |
| 11375 | // Locate first character of second argument. |
| 11376 | __ add(r1, r1, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 11377 | |
| 11378 | // r1: first character of second string. |
| 11379 | // r3: length of second string. |
| 11380 | // r6: next character of result (after copy of first string). |
| 11381 | // r7: result string. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 11382 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11383 | |
| 11384 | __ mov(r0, Operand(r7)); |
| 11385 | __ IncrementCounter(&Counters::string_add_native, 1, r2, r3); |
| 11386 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 11387 | __ Ret(); |
| 11388 | |
| 11389 | // Just jump to runtime to add the two strings. |
| 11390 | __ bind(&string_add_runtime); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 11391 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 11392 | } |
| 11393 | |
| 11394 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 11395 | #undef __ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 11396 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 11397 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 11398 | |
| 11399 | #endif // V8_TARGET_ARCH_ARM |