erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 30 | #include "arm/lithium-codegen-arm.h" |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 31 | #include "arm/lithium-gap-resolver-arm.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
| 33 | #include "stub-cache.h" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 39 | class SafepointGenerator : public CallWrapper { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | public: |
| 41 | SafepointGenerator(LCodeGen* codegen, |
| 42 | LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 43 | Safepoint::DeoptMode mode) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 44 | : codegen_(codegen), |
| 45 | pointers_(pointers), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 46 | deopt_mode_(mode) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | virtual ~SafepointGenerator() { } |
| 48 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 49 | virtual void BeforeCall(int call_size) const { } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 50 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 51 | virtual void AfterCall() const { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 52 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | private: |
| 56 | LCodeGen* codegen_; |
| 57 | LPointerMap* pointers_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 58 | Safepoint::DeoptMode deopt_mode_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | |
| 62 | #define __ masm()-> |
| 63 | |
| 64 | bool LCodeGen::GenerateCode() { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 65 | HPhase phase("Z_Code generation", chunk()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 66 | ASSERT(is_unused()); |
| 67 | status_ = GENERATING; |
| 68 | CpuFeatures::Scope scope1(VFP3); |
| 69 | CpuFeatures::Scope scope2(ARMv7); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 70 | |
| 71 | CodeStub::GenerateFPStubs(); |
| 72 | |
| 73 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 74 | // NONE indicates that the scope shouldn't actually generate code to set up |
| 75 | // the frame (that is done in GeneratePrologue). |
| 76 | FrameScope frame_scope(masm_, StackFrame::NONE); |
| 77 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 78 | return GeneratePrologue() && |
| 79 | GenerateBody() && |
| 80 | GenerateDeferredCode() && |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 81 | GenerateDeoptJumpTable() && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 82 | GenerateSafepointTable(); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 87 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 88 | code->set_stack_slots(GetStackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 89 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 90 | PopulateDeoptimizationData(code); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void LCodeGen::Abort(const char* format, ...) { |
| 95 | if (FLAG_trace_bailout) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 96 | SmartArrayPointer<char> name( |
| 97 | info()->shared_info()->DebugName()->ToCString()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 98 | PrintF("Aborting LCodeGen in @\"%s\": ", *name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 99 | va_list arguments; |
| 100 | va_start(arguments, format); |
| 101 | OS::VPrint(format, arguments); |
| 102 | va_end(arguments); |
| 103 | PrintF("\n"); |
| 104 | } |
| 105 | status_ = ABORTED; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void LCodeGen::Comment(const char* format, ...) { |
| 110 | if (!FLAG_code_comments) return; |
| 111 | char buffer[4 * KB]; |
| 112 | StringBuilder builder(buffer, ARRAY_SIZE(buffer)); |
| 113 | va_list arguments; |
| 114 | va_start(arguments, format); |
| 115 | builder.AddFormattedList(format, arguments); |
| 116 | va_end(arguments); |
| 117 | |
| 118 | // Copy the string before recording it in the assembler to avoid |
| 119 | // issues when the stack allocated buffer goes out of scope. |
| 120 | size_t length = builder.position(); |
| 121 | Vector<char> copy = Vector<char>::New(length + 1); |
| 122 | memcpy(copy.start(), builder.Finalize(), copy.length()); |
| 123 | masm()->RecordComment(copy.start()); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | bool LCodeGen::GeneratePrologue() { |
| 128 | ASSERT(is_generating()); |
| 129 | |
| 130 | #ifdef DEBUG |
| 131 | if (strlen(FLAG_stop_at) > 0 && |
| 132 | info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 133 | __ stop("stop_at"); |
| 134 | } |
| 135 | #endif |
| 136 | |
| 137 | // r1: Callee's JS function. |
| 138 | // cp: Callee's context. |
| 139 | // fp: Caller's frame pointer. |
| 140 | // lr: Caller's pc. |
| 141 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 142 | // Strict mode functions and builtins need to replace the receiver |
| 143 | // with undefined when called as functions (without an explicit |
| 144 | // receiver object). r5 is zero for method calls and non-zero for |
| 145 | // function calls. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 146 | if (!info_->is_classic_mode() || info_->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 147 | Label ok; |
| 148 | __ cmp(r5, Operand(0)); |
| 149 | __ b(eq, &ok); |
| 150 | int receiver_offset = scope()->num_parameters() * kPointerSize; |
| 151 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 152 | __ str(r2, MemOperand(sp, receiver_offset)); |
| 153 | __ bind(&ok); |
| 154 | } |
| 155 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 156 | __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 157 | __ add(fp, sp, Operand(2 * kPointerSize)); // Adjust FP to point to saved FP. |
| 158 | |
| 159 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 160 | int slots = GetStackSlotCount(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 161 | if (slots > 0) { |
| 162 | if (FLAG_debug_code) { |
| 163 | __ mov(r0, Operand(slots)); |
| 164 | __ mov(r2, Operand(kSlotsZapValue)); |
| 165 | Label loop; |
| 166 | __ bind(&loop); |
| 167 | __ push(r2); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 168 | __ sub(r0, r0, Operand(1), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 169 | __ b(ne, &loop); |
| 170 | } else { |
| 171 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 172 | } |
| 173 | } |
| 174 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 175 | // Possibly allocate a local context. |
| 176 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 177 | if (heap_slots > 0) { |
| 178 | Comment(";;; Allocate local context"); |
| 179 | // Argument to NewContext is the function, which is in r1. |
| 180 | __ push(r1); |
| 181 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 182 | FastNewContextStub stub(heap_slots); |
| 183 | __ CallStub(&stub); |
| 184 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 185 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 186 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 187 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 188 | // Context is returned in both r0 and cp. It replaces the context |
| 189 | // passed to us. It's saved in the stack and kept live in cp. |
| 190 | __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 191 | // Copy any necessary parameters into the context. |
| 192 | int num_parameters = scope()->num_parameters(); |
| 193 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 194 | Variable* var = scope()->parameter(i); |
| 195 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 196 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 197 | (num_parameters - 1 - i) * kPointerSize; |
| 198 | // Load parameter from stack. |
| 199 | __ ldr(r0, MemOperand(fp, parameter_offset)); |
| 200 | // Store it in the context. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 201 | MemOperand target = ContextOperand(cp, var->index()); |
| 202 | __ str(r0, target); |
| 203 | // Update the write barrier. This clobbers r3 and r0. |
| 204 | __ RecordWriteContextSlot( |
| 205 | cp, target.offset(), r0, r3, kLRHasBeenSaved, kSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | Comment(";;; End allocate local context"); |
| 209 | } |
| 210 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 211 | // Trace the call. |
| 212 | if (FLAG_trace) { |
| 213 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 214 | } |
| 215 | return !is_aborted(); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | bool LCodeGen::GenerateBody() { |
| 220 | ASSERT(is_generating()); |
| 221 | bool emit_instructions = true; |
| 222 | for (current_instruction_ = 0; |
| 223 | !is_aborted() && current_instruction_ < instructions_->length(); |
| 224 | current_instruction_++) { |
| 225 | LInstruction* instr = instructions_->at(current_instruction_); |
| 226 | if (instr->IsLabel()) { |
| 227 | LLabel* label = LLabel::cast(instr); |
| 228 | emit_instructions = !label->HasReplacement(); |
| 229 | } |
| 230 | |
| 231 | if (emit_instructions) { |
| 232 | Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); |
| 233 | instr->CompileToNative(this); |
| 234 | } |
| 235 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 236 | EnsureSpaceForLazyDeopt(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 237 | return !is_aborted(); |
| 238 | } |
| 239 | |
| 240 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 241 | bool LCodeGen::GenerateDeferredCode() { |
| 242 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 243 | if (deferred_.length() > 0) { |
| 244 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 245 | LDeferredCode* code = deferred_[i]; |
| 246 | __ bind(code->entry()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 247 | Comment(";;; Deferred code @%d: %s.", |
| 248 | code->instruction_index(), |
| 249 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 250 | code->Generate(); |
| 251 | __ jmp(code->exit()); |
| 252 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 253 | } |
| 254 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 255 | // Force constant pool emission at the end of the deferred code to make |
| 256 | // sure that no constant pools are emitted after. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 257 | masm()->CheckConstPool(true, false); |
| 258 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 259 | return !is_aborted(); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | bool LCodeGen::GenerateDeoptJumpTable() { |
| 264 | // Check that the jump table is accessible from everywhere in the function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 265 | // code, i.e. that offsets to the table can be encoded in the 24bit signed |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 266 | // immediate of a branch instruction. |
| 267 | // To simplify we consider the code size from the first instruction to the |
| 268 | // end of the jump table. We also don't consider the pc load delta. |
| 269 | // Each entry in the jump table generates one instruction and inlines one |
| 270 | // 32bit data after it. |
| 271 | if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) + |
| 272 | deopt_jump_table_.length() * 2)) { |
| 273 | Abort("Generated code is too large"); |
| 274 | } |
| 275 | |
| 276 | // Block the constant pool emission during the jump table emission. |
| 277 | __ BlockConstPoolFor(deopt_jump_table_.length()); |
| 278 | __ RecordComment("[ Deoptimisation jump table"); |
| 279 | Label table_start; |
| 280 | __ bind(&table_start); |
| 281 | for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 282 | __ bind(&deopt_jump_table_[i].label); |
| 283 | __ ldr(pc, MemOperand(pc, Assembler::kInstrSize - Assembler::kPcLoadDelta)); |
| 284 | __ dd(reinterpret_cast<uint32_t>(deopt_jump_table_[i].address)); |
| 285 | } |
| 286 | ASSERT(masm()->InstructionsGeneratedSince(&table_start) == |
| 287 | deopt_jump_table_.length() * 2); |
| 288 | __ RecordComment("]"); |
| 289 | |
| 290 | // The deoptimization jump table is the last part of the instruction |
| 291 | // sequence. Mark the generated code as done unless we bailed out. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 292 | if (!is_aborted()) status_ = DONE; |
| 293 | return !is_aborted(); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | bool LCodeGen::GenerateSafepointTable() { |
| 298 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 299 | safepoints_.Emit(masm(), GetStackSlotCount()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 300 | return !is_aborted(); |
| 301 | } |
| 302 | |
| 303 | |
| 304 | Register LCodeGen::ToRegister(int index) const { |
| 305 | return Register::FromAllocationIndex(index); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
| 310 | return DoubleRegister::FromAllocationIndex(index); |
| 311 | } |
| 312 | |
| 313 | |
| 314 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 315 | ASSERT(op->IsRegister()); |
| 316 | return ToRegister(op->index()); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 321 | if (op->IsRegister()) { |
| 322 | return ToRegister(op->index()); |
| 323 | } else if (op->IsConstantOperand()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 324 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 325 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 326 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 327 | if (r.IsInteger32()) { |
| 328 | ASSERT(literal->IsNumber()); |
| 329 | __ mov(scratch, Operand(static_cast<int32_t>(literal->Number()))); |
| 330 | } else if (r.IsDouble()) { |
| 331 | Abort("EmitLoadRegister: Unsupported double immediate."); |
| 332 | } else { |
| 333 | ASSERT(r.IsTagged()); |
| 334 | if (literal->IsSmi()) { |
| 335 | __ mov(scratch, Operand(literal)); |
| 336 | } else { |
| 337 | __ LoadHeapObject(scratch, Handle<HeapObject>::cast(literal)); |
| 338 | } |
| 339 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 340 | return scratch; |
| 341 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 342 | __ ldr(scratch, ToMemOperand(op)); |
| 343 | return scratch; |
| 344 | } |
| 345 | UNREACHABLE(); |
| 346 | return scratch; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 351 | ASSERT(op->IsDoubleRegister()); |
| 352 | return ToDoubleRegister(op->index()); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 357 | SwVfpRegister flt_scratch, |
| 358 | DoubleRegister dbl_scratch) { |
| 359 | if (op->IsDoubleRegister()) { |
| 360 | return ToDoubleRegister(op->index()); |
| 361 | } else if (op->IsConstantOperand()) { |
| 362 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 363 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 364 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 365 | if (r.IsInteger32()) { |
| 366 | ASSERT(literal->IsNumber()); |
| 367 | __ mov(ip, Operand(static_cast<int32_t>(literal->Number()))); |
| 368 | __ vmov(flt_scratch, ip); |
| 369 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 370 | return dbl_scratch; |
| 371 | } else if (r.IsDouble()) { |
| 372 | Abort("unsupported double immediate"); |
| 373 | } else if (r.IsTagged()) { |
| 374 | Abort("unsupported tagged immediate"); |
| 375 | } |
| 376 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 377 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 378 | // __ vldr(dbl_scratch, ToMemOperand(op)); |
| 379 | MemOperand mem_op = ToMemOperand(op); |
| 380 | __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset()); |
| 381 | return dbl_scratch; |
| 382 | } |
| 383 | UNREACHABLE(); |
| 384 | return dbl_scratch; |
| 385 | } |
| 386 | |
| 387 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 388 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
| 389 | Handle<Object> literal = chunk_->LookupLiteral(op); |
| 390 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); |
| 391 | return literal; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
| 396 | return chunk_->LookupLiteralRepresentation(op).IsInteger32(); |
| 397 | } |
| 398 | |
| 399 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 400 | int LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 401 | Handle<Object> value = chunk_->LookupLiteral(op); |
| 402 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); |
| 403 | ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == |
| 404 | value->Number()); |
| 405 | return static_cast<int32_t>(value->Number()); |
| 406 | } |
| 407 | |
| 408 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 409 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
| 410 | Handle<Object> value = chunk_->LookupLiteral(op); |
| 411 | return value->Number(); |
| 412 | } |
| 413 | |
| 414 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 416 | if (op->IsConstantOperand()) { |
| 417 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 418 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 419 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 420 | if (r.IsInteger32()) { |
| 421 | ASSERT(literal->IsNumber()); |
| 422 | return Operand(static_cast<int32_t>(literal->Number())); |
| 423 | } else if (r.IsDouble()) { |
| 424 | Abort("ToOperand Unsupported double immediate."); |
| 425 | } |
| 426 | ASSERT(r.IsTagged()); |
| 427 | return Operand(literal); |
| 428 | } else if (op->IsRegister()) { |
| 429 | return Operand(ToRegister(op)); |
| 430 | } else if (op->IsDoubleRegister()) { |
| 431 | Abort("ToOperand IsDoubleRegister unimplemented"); |
| 432 | return Operand(0); |
| 433 | } |
| 434 | // Stack slots not implemented, use ToMemOperand instead. |
| 435 | UNREACHABLE(); |
| 436 | return Operand(0); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 441 | ASSERT(!op->IsRegister()); |
| 442 | ASSERT(!op->IsDoubleRegister()); |
| 443 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
| 444 | int index = op->index(); |
| 445 | if (index >= 0) { |
| 446 | // Local or spill slot. Skip the frame pointer, function, and |
| 447 | // context in the fixed part of the frame. |
| 448 | return MemOperand(fp, -(index + 3) * kPointerSize); |
| 449 | } else { |
| 450 | // Incoming parameter. Skip the return address. |
| 451 | return MemOperand(fp, -(index - 1) * kPointerSize); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 456 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 457 | ASSERT(op->IsDoubleStackSlot()); |
| 458 | int index = op->index(); |
| 459 | if (index >= 0) { |
| 460 | // Local or spill slot. Skip the frame pointer, function, context, |
| 461 | // and the first word of the double in the fixed part of the frame. |
| 462 | return MemOperand(fp, -(index + 3) * kPointerSize + kPointerSize); |
| 463 | } else { |
| 464 | // Incoming parameter. Skip the return address and the first word of |
| 465 | // the double. |
| 466 | return MemOperand(fp, -(index - 1) * kPointerSize + kPointerSize); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 471 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
| 472 | Translation* translation) { |
| 473 | if (environment == NULL) return; |
| 474 | |
| 475 | // The translation includes one command per value in the environment. |
| 476 | int translation_size = environment->values()->length(); |
| 477 | // The output frame height does not include the parameters. |
| 478 | int height = translation_size - environment->parameter_count(); |
| 479 | |
| 480 | WriteTranslation(environment->outer(), translation); |
| 481 | int closure_id = DefineDeoptimizationLiteral(environment->closure()); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 482 | switch (environment->frame_type()) { |
| 483 | case JS_FUNCTION: |
| 484 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 485 | break; |
| 486 | case JS_CONSTRUCT: |
| 487 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 488 | break; |
| 489 | case ARGUMENTS_ADAPTOR: |
| 490 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 491 | break; |
| 492 | default: |
| 493 | UNREACHABLE(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 494 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 495 | for (int i = 0; i < translation_size; ++i) { |
| 496 | LOperand* value = environment->values()->at(i); |
| 497 | // spilled_registers_ and spilled_double_registers_ are either |
| 498 | // both NULL or both set. |
| 499 | if (environment->spilled_registers() != NULL && value != NULL) { |
| 500 | if (value->IsRegister() && |
| 501 | environment->spilled_registers()[value->index()] != NULL) { |
| 502 | translation->MarkDuplicate(); |
| 503 | AddToTranslation(translation, |
| 504 | environment->spilled_registers()[value->index()], |
| 505 | environment->HasTaggedValueAt(i)); |
| 506 | } else if ( |
| 507 | value->IsDoubleRegister() && |
| 508 | environment->spilled_double_registers()[value->index()] != NULL) { |
| 509 | translation->MarkDuplicate(); |
| 510 | AddToTranslation( |
| 511 | translation, |
| 512 | environment->spilled_double_registers()[value->index()], |
| 513 | false); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | AddToTranslation(translation, value, environment->HasTaggedValueAt(i)); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 522 | void LCodeGen::AddToTranslation(Translation* translation, |
| 523 | LOperand* op, |
| 524 | bool is_tagged) { |
| 525 | if (op == NULL) { |
| 526 | // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 527 | // is not present and must be reconstructed from the deoptimizer. Currently |
| 528 | // this is only used for the arguments object. |
| 529 | translation->StoreArgumentsObject(); |
| 530 | } else if (op->IsStackSlot()) { |
| 531 | if (is_tagged) { |
| 532 | translation->StoreStackSlot(op->index()); |
| 533 | } else { |
| 534 | translation->StoreInt32StackSlot(op->index()); |
| 535 | } |
| 536 | } else if (op->IsDoubleStackSlot()) { |
| 537 | translation->StoreDoubleStackSlot(op->index()); |
| 538 | } else if (op->IsArgument()) { |
| 539 | ASSERT(is_tagged); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 540 | int src_index = GetStackSlotCount() + op->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 541 | translation->StoreStackSlot(src_index); |
| 542 | } else if (op->IsRegister()) { |
| 543 | Register reg = ToRegister(op); |
| 544 | if (is_tagged) { |
| 545 | translation->StoreRegister(reg); |
| 546 | } else { |
| 547 | translation->StoreInt32Register(reg); |
| 548 | } |
| 549 | } else if (op->IsDoubleRegister()) { |
| 550 | DoubleRegister reg = ToDoubleRegister(op); |
| 551 | translation->StoreDoubleRegister(reg); |
| 552 | } else if (op->IsConstantOperand()) { |
| 553 | Handle<Object> literal = chunk()->LookupLiteral(LConstantOperand::cast(op)); |
| 554 | int src_index = DefineDeoptimizationLiteral(literal); |
| 555 | translation->StoreLiteral(src_index); |
| 556 | } else { |
| 557 | UNREACHABLE(); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void LCodeGen::CallCode(Handle<Code> code, |
| 563 | RelocInfo::Mode mode, |
| 564 | LInstruction* instr) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 565 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 570 | RelocInfo::Mode mode, |
| 571 | LInstruction* instr, |
| 572 | SafepointMode safepoint_mode) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 573 | ASSERT(instr != NULL); |
| 574 | LPointerMap* pointers = instr->pointer_map(); |
| 575 | RecordPosition(pointers->position()); |
| 576 | __ Call(code, mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 577 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 578 | |
| 579 | // Signal that we don't inline smi code before these stubs in the |
| 580 | // optimizing code generator. |
| 581 | if (code->kind() == Code::BINARY_OP_IC || |
| 582 | code->kind() == Code::COMPARE_IC) { |
| 583 | __ nop(); |
| 584 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 588 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 589 | int num_arguments, |
| 590 | LInstruction* instr) { |
| 591 | ASSERT(instr != NULL); |
| 592 | LPointerMap* pointers = instr->pointer_map(); |
| 593 | ASSERT(pointers != NULL); |
| 594 | RecordPosition(pointers->position()); |
| 595 | |
| 596 | __ CallRuntime(function, num_arguments); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 597 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 601 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 602 | int argc, |
| 603 | LInstruction* instr) { |
| 604 | __ CallRuntimeSaveDoubles(id); |
| 605 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 606 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 610 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 611 | Safepoint::DeoptMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 612 | if (!environment->HasBeenRegistered()) { |
| 613 | // Physical stack frame layout: |
| 614 | // -x ............. -4 0 ..................................... y |
| 615 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 616 | |
| 617 | // Layout of the environment: |
| 618 | // 0 ..................................................... size-1 |
| 619 | // [parameters] [locals] [expression stack including arguments] |
| 620 | |
| 621 | // Layout of the translation: |
| 622 | // 0 ........................................................ size - 1 + 4 |
| 623 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 624 | // |>------------ translation_size ------------<| |
| 625 | |
| 626 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 627 | int jsframe_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 628 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 629 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 630 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 631 | ++jsframe_count; |
| 632 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 633 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 634 | Translation translation(&translations_, frame_count, jsframe_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 635 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 636 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 637 | int pc_offset = masm()->pc_offset(); |
| 638 | environment->Register(deoptimization_index, |
| 639 | translation.index(), |
| 640 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 641 | deoptimizations_.Add(environment); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 647 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 648 | ASSERT(environment->HasBeenRegistered()); |
| 649 | int id = environment->deoptimization_index(); |
| 650 | Address entry = Deoptimizer::GetDeoptimizationEntry(id, Deoptimizer::EAGER); |
| 651 | ASSERT(entry != NULL); |
| 652 | if (entry == NULL) { |
| 653 | Abort("bailout was not prepared"); |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | ASSERT(FLAG_deopt_every_n_times < 2); // Other values not supported on ARM. |
| 658 | |
| 659 | if (FLAG_deopt_every_n_times == 1 && |
| 660 | info_->shared_info()->opt_count() == id) { |
| 661 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 662 | return; |
| 663 | } |
| 664 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 665 | if (FLAG_trap_on_deopt) __ stop("trap_on_deopt", cc); |
| 666 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 667 | if (cc == al) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 668 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 669 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 670 | // We often have several deopts to the same entry, reuse the last |
| 671 | // jump entry if this is the case. |
| 672 | if (deopt_jump_table_.is_empty() || |
| 673 | (deopt_jump_table_.last().address != entry)) { |
| 674 | deopt_jump_table_.Add(JumpTableEntry(entry)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 675 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 676 | __ b(cc, &deopt_jump_table_.last().label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | |
| 681 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 682 | int length = deoptimizations_.length(); |
| 683 | if (length == 0) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 684 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 685 | factory()->NewDeoptimizationInputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 686 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 687 | Handle<ByteArray> translations = translations_.CreateByteArray(); |
| 688 | data->SetTranslationByteArray(*translations); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 689 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 690 | |
| 691 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 692 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 693 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 694 | literals->set(i, *deoptimization_literals_[i]); |
| 695 | } |
| 696 | data->SetLiteralArray(*literals); |
| 697 | |
| 698 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id())); |
| 699 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 700 | |
| 701 | // Populate the deoptimization entries. |
| 702 | for (int i = 0; i < length; i++) { |
| 703 | LEnvironment* env = deoptimizations_[i]; |
| 704 | data->SetAstId(i, Smi::FromInt(env->ast_id())); |
| 705 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 706 | data->SetArgumentsStackHeight(i, |
| 707 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 708 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 709 | } |
| 710 | code->set_deoptimization_data(*data); |
| 711 | } |
| 712 | |
| 713 | |
| 714 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 715 | int result = deoptimization_literals_.length(); |
| 716 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 717 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 718 | } |
| 719 | deoptimization_literals_.Add(literal); |
| 720 | return result; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 725 | ASSERT(deoptimization_literals_.length() == 0); |
| 726 | |
| 727 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 728 | chunk()->inlined_closures(); |
| 729 | |
| 730 | for (int i = 0, length = inlined_closures->length(); |
| 731 | i < length; |
| 732 | i++) { |
| 733 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 734 | } |
| 735 | |
| 736 | inlined_function_count_ = deoptimization_literals_.length(); |
| 737 | } |
| 738 | |
| 739 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 740 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 741 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 742 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 743 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 744 | } else { |
| 745 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 746 | RecordSafepointWithRegisters( |
| 747 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 752 | void LCodeGen::RecordSafepoint( |
| 753 | LPointerMap* pointers, |
| 754 | Safepoint::Kind kind, |
| 755 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 756 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 757 | ASSERT(expected_safepoint_kind_ == kind); |
| 758 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 759 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 760 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 761 | kind, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 762 | for (int i = 0; i < operands->length(); i++) { |
| 763 | LOperand* pointer = operands->at(i); |
| 764 | if (pointer->IsStackSlot()) { |
| 765 | safepoint.DefinePointerSlot(pointer->index()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 766 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
| 767 | safepoint.DefinePointerRegister(ToRegister(pointer)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 768 | } |
| 769 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 770 | if (kind & Safepoint::kWithRegisters) { |
| 771 | // Register cp always contains a pointer to the context. |
| 772 | safepoint.DefinePointerRegister(cp); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | |
| 777 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 778 | Safepoint::DeoptMode deopt_mode) { |
| 779 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 783 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 784 | LPointerMap empty_pointers(RelocInfo::kNoPosition); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 785 | RecordSafepoint(&empty_pointers, deopt_mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 789 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 790 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 791 | Safepoint::DeoptMode deopt_mode) { |
| 792 | RecordSafepoint( |
| 793 | pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 797 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 798 | LPointerMap* pointers, |
| 799 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 800 | Safepoint::DeoptMode deopt_mode) { |
| 801 | RecordSafepoint( |
| 802 | pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 806 | void LCodeGen::RecordPosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 807 | if (position == RelocInfo::kNoPosition) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 808 | masm()->positions_recorder()->RecordPosition(position); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | void LCodeGen::DoLabel(LLabel* label) { |
| 813 | if (label->is_loop_header()) { |
| 814 | Comment(";;; B%d - LOOP entry", label->block_id()); |
| 815 | } else { |
| 816 | Comment(";;; B%d", label->block_id()); |
| 817 | } |
| 818 | __ bind(label->label()); |
| 819 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 820 | DoGap(label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
| 824 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 825 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | |
| 829 | void LCodeGen::DoGap(LGap* gap) { |
| 830 | for (int i = LGap::FIRST_INNER_POSITION; |
| 831 | i <= LGap::LAST_INNER_POSITION; |
| 832 | i++) { |
| 833 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 834 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 835 | if (move != NULL) DoParallelMove(move); |
| 836 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 841 | DoGap(instr); |
| 842 | } |
| 843 | |
| 844 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 845 | void LCodeGen::DoParameter(LParameter* instr) { |
| 846 | // Nothing to do. |
| 847 | } |
| 848 | |
| 849 | |
| 850 | void LCodeGen::DoCallStub(LCallStub* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 851 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 852 | switch (instr->hydrogen()->major_key()) { |
| 853 | case CodeStub::RegExpConstructResult: { |
| 854 | RegExpConstructResultStub stub; |
| 855 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 856 | break; |
| 857 | } |
| 858 | case CodeStub::RegExpExec: { |
| 859 | RegExpExecStub stub; |
| 860 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 861 | break; |
| 862 | } |
| 863 | case CodeStub::SubString: { |
| 864 | SubStringStub stub; |
| 865 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 866 | break; |
| 867 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 868 | case CodeStub::NumberToString: { |
| 869 | NumberToStringStub stub; |
| 870 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 871 | break; |
| 872 | } |
| 873 | case CodeStub::StringAdd: { |
| 874 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 875 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 876 | break; |
| 877 | } |
| 878 | case CodeStub::StringCompare: { |
| 879 | StringCompareStub stub; |
| 880 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 881 | break; |
| 882 | } |
| 883 | case CodeStub::TranscendentalCache: { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 884 | __ ldr(r0, MemOperand(sp, 0)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 885 | TranscendentalCacheStub stub(instr->transcendental_type(), |
| 886 | TranscendentalCacheStub::TAGGED); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 887 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 888 | break; |
| 889 | } |
| 890 | default: |
| 891 | UNREACHABLE(); |
| 892 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
| 896 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 897 | // Nothing to do. |
| 898 | } |
| 899 | |
| 900 | |
| 901 | void LCodeGen::DoModI(LModI* instr) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 902 | if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 903 | Register dividend = ToRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 904 | Register result = ToRegister(instr->result()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 905 | |
| 906 | int32_t divisor = |
| 907 | HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 908 | |
| 909 | if (divisor < 0) divisor = -divisor; |
| 910 | |
| 911 | Label positive_dividend, done; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 912 | __ cmp(dividend, Operand(0)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 913 | __ b(pl, &positive_dividend); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 914 | __ rsb(result, dividend, Operand(0)); |
| 915 | __ and_(result, result, Operand(divisor - 1), SetCC); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 916 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 917 | DeoptimizeIf(eq, instr->environment()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 918 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 919 | __ rsb(result, result, Operand(0)); |
| 920 | __ b(&done); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 921 | __ bind(&positive_dividend); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 922 | __ and_(result, dividend, Operand(divisor - 1)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 923 | __ bind(&done); |
| 924 | return; |
| 925 | } |
| 926 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 927 | // These registers hold untagged 32 bit values. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 928 | Register left = ToRegister(instr->InputAt(0)); |
| 929 | Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 930 | Register result = ToRegister(instr->result()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 931 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 932 | Register scratch = scratch0(); |
| 933 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 934 | DwVfpRegister dividend = ToDoubleRegister(instr->TempAt(1)); |
| 935 | DwVfpRegister divisor = ToDoubleRegister(instr->TempAt(2)); |
| 936 | DwVfpRegister quotient = double_scratch0(); |
| 937 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 938 | ASSERT(!dividend.is(divisor)); |
| 939 | ASSERT(!dividend.is(quotient)); |
| 940 | ASSERT(!divisor.is(quotient)); |
| 941 | ASSERT(!scratch.is(left)); |
| 942 | ASSERT(!scratch.is(right)); |
| 943 | ASSERT(!scratch.is(result)); |
| 944 | |
| 945 | Label done, vfp_modulo, both_positive, right_negative; |
| 946 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 947 | // Check for x % 0. |
| 948 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 949 | __ cmp(right, Operand(0)); |
| 950 | DeoptimizeIf(eq, instr->environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 951 | } |
| 952 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 953 | __ Move(result, left); |
| 954 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 955 | // (0 % x) must yield 0 (if x is finite, which is the case here). |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 956 | __ cmp(left, Operand(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 957 | __ b(eq, &done); |
| 958 | // Preload right in a vfp register. |
| 959 | __ vmov(divisor.low(), right); |
| 960 | __ b(lt, &vfp_modulo); |
| 961 | |
| 962 | __ cmp(left, Operand(right)); |
| 963 | __ b(lt, &done); |
| 964 | |
| 965 | // Check for (positive) power of two on the right hand side. |
| 966 | __ JumpIfNotPowerOfTwoOrZeroAndNeg(right, |
| 967 | scratch, |
| 968 | &right_negative, |
| 969 | &both_positive); |
| 970 | // Perform modulo operation (scratch contains right - 1). |
| 971 | __ and_(result, scratch, Operand(left)); |
| 972 | __ b(&done); |
| 973 | |
| 974 | __ bind(&right_negative); |
| 975 | // Negate right. The sign of the divisor does not matter. |
| 976 | __ rsb(right, right, Operand(0)); |
| 977 | |
| 978 | __ bind(&both_positive); |
| 979 | const int kUnfolds = 3; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 980 | // If the right hand side is smaller than the (nonnegative) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | // left hand side, the left hand side is the result. |
| 982 | // Else try a few subtractions of the left hand side. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 983 | __ mov(scratch, left); |
| 984 | for (int i = 0; i < kUnfolds; i++) { |
| 985 | // Check if the left hand side is less or equal than the |
| 986 | // the right hand side. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 987 | __ cmp(scratch, Operand(right)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 988 | __ mov(result, scratch, LeaveCC, lt); |
| 989 | __ b(lt, &done); |
| 990 | // If not, reduce the left hand side by the right hand |
| 991 | // side and check again. |
| 992 | if (i < kUnfolds - 1) __ sub(scratch, scratch, right); |
| 993 | } |
| 994 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 995 | __ bind(&vfp_modulo); |
| 996 | // Load the arguments in VFP registers. |
| 997 | // The divisor value is preloaded before. Be careful that 'right' is only live |
| 998 | // on entry. |
| 999 | __ vmov(dividend.low(), left); |
| 1000 | // From here on don't use right as it may have been reallocated (for example |
| 1001 | // to scratch2). |
| 1002 | right = no_reg; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1003 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1004 | __ vcvt_f64_s32(dividend, dividend.low()); |
| 1005 | __ vcvt_f64_s32(divisor, divisor.low()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1006 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1007 | // We do not care about the sign of the divisor. |
| 1008 | __ vabs(divisor, divisor); |
| 1009 | // Compute the quotient and round it to a 32bit integer. |
| 1010 | __ vdiv(quotient, dividend, divisor); |
| 1011 | __ vcvt_s32_f64(quotient.low(), quotient); |
| 1012 | __ vcvt_f64_s32(quotient, quotient.low()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1013 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1014 | // Compute the remainder in result. |
| 1015 | DwVfpRegister double_scratch = dividend; |
| 1016 | __ vmul(double_scratch, divisor, quotient); |
| 1017 | __ vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 1018 | __ vmov(scratch, double_scratch.low()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1019 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1020 | if (!instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1021 | __ sub(result, left, scratch); |
| 1022 | } else { |
| 1023 | Label ok; |
| 1024 | // Check for -0. |
| 1025 | __ sub(scratch2, left, scratch, SetCC); |
| 1026 | __ b(ne, &ok); |
| 1027 | __ cmp(left, Operand(0)); |
| 1028 | DeoptimizeIf(mi, instr->environment()); |
| 1029 | __ bind(&ok); |
| 1030 | // Load the result and we are done. |
| 1031 | __ mov(result, scratch2); |
| 1032 | } |
| 1033 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1034 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | void LCodeGen::DoDivI(LDivI* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1039 | class DeferredDivI: public LDeferredCode { |
| 1040 | public: |
| 1041 | DeferredDivI(LCodeGen* codegen, LDivI* instr) |
| 1042 | : LDeferredCode(codegen), instr_(instr) { } |
| 1043 | virtual void Generate() { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1044 | codegen()->DoDeferredBinaryOpStub(instr_, Token::DIV); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1045 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1046 | virtual LInstruction* instr() { return instr_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1047 | private: |
| 1048 | LDivI* instr_; |
| 1049 | }; |
| 1050 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1051 | const Register left = ToRegister(instr->InputAt(0)); |
| 1052 | const Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1053 | const Register scratch = scratch0(); |
| 1054 | const Register result = ToRegister(instr->result()); |
| 1055 | |
| 1056 | // Check for x / 0. |
| 1057 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1058 | __ cmp(right, Operand(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1059 | DeoptimizeIf(eq, instr->environment()); |
| 1060 | } |
| 1061 | |
| 1062 | // Check for (0 / -x) that will produce negative zero. |
| 1063 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1064 | Label left_not_zero; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1065 | __ cmp(left, Operand(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1066 | __ b(ne, &left_not_zero); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1067 | __ cmp(right, Operand(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1068 | DeoptimizeIf(mi, instr->environment()); |
| 1069 | __ bind(&left_not_zero); |
| 1070 | } |
| 1071 | |
| 1072 | // Check for (-kMinInt / -1). |
| 1073 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1074 | Label left_not_min_int; |
| 1075 | __ cmp(left, Operand(kMinInt)); |
| 1076 | __ b(ne, &left_not_min_int); |
| 1077 | __ cmp(right, Operand(-1)); |
| 1078 | DeoptimizeIf(eq, instr->environment()); |
| 1079 | __ bind(&left_not_min_int); |
| 1080 | } |
| 1081 | |
| 1082 | Label done, deoptimize; |
| 1083 | // Test for a few common cases first. |
| 1084 | __ cmp(right, Operand(1)); |
| 1085 | __ mov(result, left, LeaveCC, eq); |
| 1086 | __ b(eq, &done); |
| 1087 | |
| 1088 | __ cmp(right, Operand(2)); |
| 1089 | __ tst(left, Operand(1), eq); |
| 1090 | __ mov(result, Operand(left, ASR, 1), LeaveCC, eq); |
| 1091 | __ b(eq, &done); |
| 1092 | |
| 1093 | __ cmp(right, Operand(4)); |
| 1094 | __ tst(left, Operand(3), eq); |
| 1095 | __ mov(result, Operand(left, ASR, 2), LeaveCC, eq); |
| 1096 | __ b(eq, &done); |
| 1097 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1098 | // Call the stub. The numbers in r0 and r1 have |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1099 | // to be tagged to Smis. If that is not possible, deoptimize. |
| 1100 | DeferredDivI* deferred = new DeferredDivI(this, instr); |
| 1101 | |
| 1102 | __ TrySmiTag(left, &deoptimize, scratch); |
| 1103 | __ TrySmiTag(right, &deoptimize, scratch); |
| 1104 | |
| 1105 | __ b(al, deferred->entry()); |
| 1106 | __ bind(deferred->exit()); |
| 1107 | |
| 1108 | // If the result in r0 is a Smi, untag it, else deoptimize. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1109 | __ JumpIfNotSmi(result, &deoptimize); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1110 | __ SmiUntag(result); |
| 1111 | __ b(&done); |
| 1112 | |
| 1113 | __ bind(&deoptimize); |
| 1114 | DeoptimizeIf(al, instr->environment()); |
| 1115 | __ bind(&done); |
| 1116 | } |
| 1117 | |
| 1118 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1119 | template<int T> |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1120 | void LCodeGen::DoDeferredBinaryOpStub(LTemplateInstruction<1, 2, T>* instr, |
| 1121 | Token::Value op) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1122 | Register left = ToRegister(instr->InputAt(0)); |
| 1123 | Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1124 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1125 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegistersAndDoubles); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1126 | // Move left to r1 and right to r0 for the stub call. |
| 1127 | if (left.is(r1)) { |
| 1128 | __ Move(r0, right); |
| 1129 | } else if (left.is(r0) && right.is(r1)) { |
| 1130 | __ Swap(r0, r1, r2); |
| 1131 | } else if (left.is(r0)) { |
| 1132 | ASSERT(!right.is(r1)); |
| 1133 | __ mov(r1, r0); |
| 1134 | __ mov(r0, right); |
| 1135 | } else { |
| 1136 | ASSERT(!left.is(r0) && !right.is(r0)); |
| 1137 | __ mov(r0, right); |
| 1138 | __ mov(r1, left); |
| 1139 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1140 | BinaryOpStub stub(op, OVERWRITE_LEFT); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1141 | __ CallStub(&stub); |
| 1142 | RecordSafepointWithRegistersAndDoubles(instr->pointer_map(), |
| 1143 | 0, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1144 | Safepoint::kNoLazyDeopt); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1145 | // Overwrite the stored value of r0 with the result of the stub. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1146 | __ StoreToSafepointRegistersAndDoublesSlot(r0, r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | void LCodeGen::DoMulI(LMulI* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1151 | Register scratch = scratch0(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1152 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1153 | // Note that result may alias left. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1154 | Register left = ToRegister(instr->InputAt(0)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1155 | LOperand* right_op = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1156 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1157 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1158 | bool bailout_on_minus_zero = |
| 1159 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1160 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1161 | if (right_op->IsConstantOperand() && !can_overflow) { |
| 1162 | // Use optimized code for specific constants. |
| 1163 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
| 1164 | |
| 1165 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1166 | // The case of a null constant will be handled separately. |
| 1167 | // If constant is negative and left is null, the result should be -0. |
| 1168 | __ cmp(left, Operand(0)); |
| 1169 | DeoptimizeIf(eq, instr->environment()); |
| 1170 | } |
| 1171 | |
| 1172 | switch (constant) { |
| 1173 | case -1: |
| 1174 | __ rsb(result, left, Operand(0)); |
| 1175 | break; |
| 1176 | case 0: |
| 1177 | if (bailout_on_minus_zero) { |
| 1178 | // If left is strictly negative and the constant is null, the |
| 1179 | // result is -0. Deoptimize if required, otherwise return 0. |
| 1180 | __ cmp(left, Operand(0)); |
| 1181 | DeoptimizeIf(mi, instr->environment()); |
| 1182 | } |
| 1183 | __ mov(result, Operand(0)); |
| 1184 | break; |
| 1185 | case 1: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1186 | __ Move(result, left); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1187 | break; |
| 1188 | default: |
| 1189 | // Multiplying by powers of two and powers of two plus or minus |
| 1190 | // one can be done faster with shifted operands. |
| 1191 | // For other constants we emit standard code. |
| 1192 | int32_t mask = constant >> 31; |
| 1193 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1194 | |
| 1195 | if (IsPowerOf2(constant_abs) || |
| 1196 | IsPowerOf2(constant_abs - 1) || |
| 1197 | IsPowerOf2(constant_abs + 1)) { |
| 1198 | if (IsPowerOf2(constant_abs)) { |
| 1199 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1200 | __ mov(result, Operand(left, LSL, shift)); |
| 1201 | } else if (IsPowerOf2(constant_abs - 1)) { |
| 1202 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1203 | __ add(result, left, Operand(left, LSL, shift)); |
| 1204 | } else if (IsPowerOf2(constant_abs + 1)) { |
| 1205 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1206 | __ rsb(result, left, Operand(left, LSL, shift)); |
| 1207 | } |
| 1208 | |
| 1209 | // Correct the sign of the result is the constant is negative. |
| 1210 | if (constant < 0) __ rsb(result, result, Operand(0)); |
| 1211 | |
| 1212 | } else { |
| 1213 | // Generate standard code. |
| 1214 | __ mov(ip, Operand(constant)); |
| 1215 | __ mul(result, left, ip); |
| 1216 | } |
| 1217 | } |
| 1218 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1219 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1220 | Register right = EmitLoadRegister(right_op, scratch); |
| 1221 | if (bailout_on_minus_zero) { |
| 1222 | __ orr(ToRegister(instr->TempAt(0)), left, right); |
| 1223 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1224 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1225 | if (can_overflow) { |
| 1226 | // scratch:result = left * right. |
| 1227 | __ smull(result, scratch, left, right); |
| 1228 | __ cmp(scratch, Operand(result, ASR, 31)); |
| 1229 | DeoptimizeIf(ne, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1230 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1231 | __ mul(result, left, right); |
| 1232 | } |
| 1233 | |
| 1234 | if (bailout_on_minus_zero) { |
| 1235 | // Bail out if the result is supposed to be negative zero. |
| 1236 | Label done; |
| 1237 | __ cmp(result, Operand(0)); |
| 1238 | __ b(ne, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1239 | __ cmp(ToRegister(instr->TempAt(0)), Operand(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1240 | DeoptimizeIf(mi, instr->environment()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1241 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1242 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | void LCodeGen::DoBitI(LBitI* instr) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1248 | LOperand* left_op = instr->InputAt(0); |
| 1249 | LOperand* right_op = instr->InputAt(1); |
| 1250 | ASSERT(left_op->IsRegister()); |
| 1251 | Register left = ToRegister(left_op); |
| 1252 | Register result = ToRegister(instr->result()); |
| 1253 | Operand right(no_reg); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1254 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1255 | if (right_op->IsStackSlot() || right_op->IsArgument()) { |
| 1256 | right = Operand(EmitLoadRegister(right_op, ip)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1257 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1258 | ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1259 | right = ToOperand(right_op); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | switch (instr->op()) { |
| 1263 | case Token::BIT_AND: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1264 | __ and_(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1265 | break; |
| 1266 | case Token::BIT_OR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1267 | __ orr(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | break; |
| 1269 | case Token::BIT_XOR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1270 | __ eor(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1271 | break; |
| 1272 | default: |
| 1273 | UNREACHABLE(); |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | |
| 1279 | void LCodeGen::DoShiftI(LShiftI* instr) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1280 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1281 | // result may alias either of them. |
| 1282 | LOperand* right_op = instr->InputAt(1); |
| 1283 | Register left = ToRegister(instr->InputAt(0)); |
| 1284 | Register result = ToRegister(instr->result()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1285 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1286 | if (right_op->IsRegister()) { |
| 1287 | // Mask the right_op operand. |
| 1288 | __ and_(scratch, ToRegister(right_op), Operand(0x1F)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1289 | switch (instr->op()) { |
| 1290 | case Token::SAR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1291 | __ mov(result, Operand(left, ASR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1292 | break; |
| 1293 | case Token::SHR: |
| 1294 | if (instr->can_deopt()) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1295 | __ mov(result, Operand(left, LSR, scratch), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1296 | DeoptimizeIf(mi, instr->environment()); |
| 1297 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1298 | __ mov(result, Operand(left, LSR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1299 | } |
| 1300 | break; |
| 1301 | case Token::SHL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1302 | __ mov(result, Operand(left, LSL, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1303 | break; |
| 1304 | default: |
| 1305 | UNREACHABLE(); |
| 1306 | break; |
| 1307 | } |
| 1308 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1309 | // Mask the right_op operand. |
| 1310 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1311 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1312 | switch (instr->op()) { |
| 1313 | case Token::SAR: |
| 1314 | if (shift_count != 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1315 | __ mov(result, Operand(left, ASR, shift_count)); |
| 1316 | } else { |
| 1317 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1318 | } |
| 1319 | break; |
| 1320 | case Token::SHR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1321 | if (shift_count != 0) { |
| 1322 | __ mov(result, Operand(left, LSR, shift_count)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1323 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1324 | if (instr->can_deopt()) { |
| 1325 | __ tst(left, Operand(0x80000000)); |
| 1326 | DeoptimizeIf(ne, instr->environment()); |
| 1327 | } |
| 1328 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1329 | } |
| 1330 | break; |
| 1331 | case Token::SHL: |
| 1332 | if (shift_count != 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1333 | __ mov(result, Operand(left, LSL, shift_count)); |
| 1334 | } else { |
| 1335 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1336 | } |
| 1337 | break; |
| 1338 | default: |
| 1339 | UNREACHABLE(); |
| 1340 | break; |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | void LCodeGen::DoSubI(LSubI* instr) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1347 | LOperand* left = instr->InputAt(0); |
| 1348 | LOperand* right = instr->InputAt(1); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1349 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1350 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1351 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
| 1352 | |
| 1353 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1354 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1355 | __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1356 | } else { |
| 1357 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1358 | __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1362 | DeoptimizeIf(vs, instr->environment()); |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1368 | ASSERT(instr->result()->IsRegister()); |
| 1369 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | void LCodeGen::DoConstantD(LConstantD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1374 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1375 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 1376 | double v = instr->value(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1377 | __ Vmov(result, v); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
| 1381 | void LCodeGen::DoConstantT(LConstantT* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1382 | Handle<Object> value = instr->value(); |
| 1383 | if (value->IsSmi()) { |
| 1384 | __ mov(ToRegister(instr->result()), Operand(value)); |
| 1385 | } else { |
| 1386 | __ LoadHeapObject(ToRegister(instr->result()), |
| 1387 | Handle<HeapObject>::cast(value)); |
| 1388 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1392 | void LCodeGen::DoJSArrayLength(LJSArrayLength* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1393 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1394 | Register array = ToRegister(instr->InputAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1395 | __ ldr(result, FieldMemOperand(array, JSArray::kLengthOffset)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1396 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1397 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1398 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1399 | void LCodeGen::DoFixedArrayBaseLength(LFixedArrayBaseLength* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1400 | Register result = ToRegister(instr->result()); |
| 1401 | Register array = ToRegister(instr->InputAt(0)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1402 | __ ldr(result, FieldMemOperand(array, FixedArrayBase::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1406 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 1407 | Register result = ToRegister(instr->result()); |
| 1408 | Register input = ToRegister(instr->InputAt(0)); |
| 1409 | |
| 1410 | // Load map into |result|. |
| 1411 | __ ldr(result, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1412 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 1413 | // but the following bit field extraction takes care of that anyway. |
| 1414 | __ ldr(result, FieldMemOperand(result, Map::kBitField2Offset)); |
| 1415 | // Retrieve elements_kind from bit field 2. |
| 1416 | __ ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 1417 | } |
| 1418 | |
| 1419 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1420 | void LCodeGen::DoValueOf(LValueOf* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1421 | Register input = ToRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1422 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1423 | Register map = ToRegister(instr->TempAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1424 | Label done; |
| 1425 | |
| 1426 | // If the object is a smi return the object. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1427 | __ tst(input, Operand(kSmiTagMask)); |
| 1428 | __ Move(result, input, eq); |
| 1429 | __ b(eq, &done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1430 | |
| 1431 | // If the object is not a value type, return the object. |
| 1432 | __ CompareObjectType(input, map, map, JS_VALUE_TYPE); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1433 | __ Move(result, input, ne); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1434 | __ b(ne, &done); |
| 1435 | __ ldr(result, FieldMemOperand(input, JSValue::kValueOffset)); |
| 1436 | |
| 1437 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | |
| 1441 | void LCodeGen::DoBitNotI(LBitNotI* instr) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1442 | Register input = ToRegister(instr->InputAt(0)); |
| 1443 | Register result = ToRegister(instr->result()); |
| 1444 | __ mvn(result, Operand(input)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | void LCodeGen::DoThrow(LThrow* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1449 | Register input_reg = EmitLoadRegister(instr->InputAt(0), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1450 | __ push(input_reg); |
| 1451 | CallRuntime(Runtime::kThrow, 1, instr); |
| 1452 | |
| 1453 | if (FLAG_debug_code) { |
| 1454 | __ stop("Unreachable code."); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | void LCodeGen::DoAddI(LAddI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1460 | LOperand* left = instr->InputAt(0); |
| 1461 | LOperand* right = instr->InputAt(1); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1462 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1463 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1464 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1465 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1466 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1467 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1468 | __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1469 | } else { |
| 1470 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1471 | __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1472 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1473 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1474 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | DeoptimizeIf(vs, instr->environment()); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | |
| 1480 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1481 | DoubleRegister left = ToDoubleRegister(instr->InputAt(0)); |
| 1482 | DoubleRegister right = ToDoubleRegister(instr->InputAt(1)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1483 | DoubleRegister result = ToDoubleRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1484 | switch (instr->op()) { |
| 1485 | case Token::ADD: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1486 | __ vadd(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1487 | break; |
| 1488 | case Token::SUB: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1489 | __ vsub(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1490 | break; |
| 1491 | case Token::MUL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1492 | __ vmul(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | case Token::DIV: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1495 | __ vdiv(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | case Token::MOD: { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1498 | // Save r0-r3 on the stack. |
| 1499 | __ stm(db_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit()); |
| 1500 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1501 | __ PrepareCallCFunction(0, 2, scratch0()); |
| 1502 | __ SetCallCDoubleArguments(left, right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1503 | __ CallCFunction( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1504 | ExternalReference::double_fp_operation(Token::MOD, isolate()), |
| 1505 | 0, 2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1506 | // Move the result in the double result register. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1507 | __ GetCFunctionDoubleResult(result); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1508 | |
| 1509 | // Restore r0-r3. |
| 1510 | __ ldm(ia_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | default: |
| 1514 | UNREACHABLE(); |
| 1515 | break; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | |
| 1520 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1521 | ASSERT(ToRegister(instr->InputAt(0)).is(r1)); |
| 1522 | ASSERT(ToRegister(instr->InputAt(1)).is(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1523 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 1524 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1525 | BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1527 | __ nop(); // Signals no inlined code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | int LCodeGen::GetNextEmittedBlock(int block) { |
| 1532 | for (int i = block + 1; i < graph()->blocks()->length(); ++i) { |
| 1533 | LLabel* label = chunk_->GetLabel(i); |
| 1534 | if (!label->HasReplacement()) return i; |
| 1535 | } |
| 1536 | return -1; |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { |
| 1541 | int next_block = GetNextEmittedBlock(current_block_); |
| 1542 | right_block = chunk_->LookupDestination(right_block); |
| 1543 | left_block = chunk_->LookupDestination(left_block); |
| 1544 | |
| 1545 | if (right_block == left_block) { |
| 1546 | EmitGoto(left_block); |
| 1547 | } else if (left_block == next_block) { |
| 1548 | __ b(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 1549 | } else if (right_block == next_block) { |
| 1550 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1551 | } else { |
| 1552 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1553 | __ b(chunk_->GetAssemblyLabel(right_block)); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | |
| 1558 | void LCodeGen::DoBranch(LBranch* instr) { |
| 1559 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1560 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1561 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1562 | Representation r = instr->hydrogen()->value()->representation(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1563 | if (r.IsInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1564 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1565 | __ cmp(reg, Operand(0)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1566 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1567 | } else if (r.IsDouble()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1568 | DoubleRegister reg = ToDoubleRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1569 | Register scratch = scratch0(); |
| 1570 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1571 | // Test the double value. Zero and NaN are false. |
| 1572 | __ VFPCompareAndLoadFlags(reg, 0.0, scratch); |
| 1573 | __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 1574 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1575 | } else { |
| 1576 | ASSERT(r.IsTagged()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1577 | Register reg = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1578 | HType type = instr->hydrogen()->value()->type(); |
| 1579 | if (type.IsBoolean()) { |
| 1580 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1581 | EmitBranch(true_block, false_block, eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1582 | } else if (type.IsSmi()) { |
| 1583 | __ cmp(reg, Operand(0)); |
| 1584 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1585 | } else { |
| 1586 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1587 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1588 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1589 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 1590 | // Avoid deopts in the case where we've never executed this path before. |
| 1591 | if (expected.IsEmpty()) expected = ToBooleanStub::all_types(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1592 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1593 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 1594 | // undefined -> false. |
| 1595 | __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
| 1596 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1597 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1598 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 1599 | // Boolean -> its value. |
| 1600 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 1601 | __ b(eq, true_label); |
| 1602 | __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 1603 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1604 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1605 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 1606 | // 'null' -> false. |
| 1607 | __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 1608 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 1612 | // Smis: 0 -> false, all other -> true. |
| 1613 | __ cmp(reg, Operand(0)); |
| 1614 | __ b(eq, false_label); |
| 1615 | __ JumpIfSmi(reg, true_label); |
| 1616 | } else if (expected.NeedsMap()) { |
| 1617 | // If we need a map later and have a Smi -> deopt. |
| 1618 | __ tst(reg, Operand(kSmiTagMask)); |
| 1619 | DeoptimizeIf(eq, instr->environment()); |
| 1620 | } |
| 1621 | |
| 1622 | const Register map = scratch0(); |
| 1623 | if (expected.NeedsMap()) { |
| 1624 | __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1625 | |
| 1626 | if (expected.CanBeUndetectable()) { |
| 1627 | // Undetectable -> false. |
| 1628 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1629 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 1630 | __ b(ne, false_label); |
| 1631 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 1635 | // spec object -> true. |
| 1636 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1637 | __ b(ge, true_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 1641 | // String value -> false iff empty. |
| 1642 | Label not_string; |
| 1643 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 1644 | __ b(ge, ¬_string); |
| 1645 | __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 1646 | __ cmp(ip, Operand(0)); |
| 1647 | __ b(ne, true_label); |
| 1648 | __ b(false_label); |
| 1649 | __ bind(¬_string); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 1653 | // heap number -> false iff +0, -0, or NaN. |
| 1654 | DoubleRegister dbl_scratch = double_scratch0(); |
| 1655 | Label not_heap_number; |
| 1656 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1657 | __ b(ne, ¬_heap_number); |
| 1658 | __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 1659 | __ VFPCompareAndSetFlags(dbl_scratch, 0.0); |
| 1660 | __ b(vs, false_label); // NaN -> false. |
| 1661 | __ b(eq, false_label); // +0, -0 -> false. |
| 1662 | __ b(true_label); |
| 1663 | __ bind(¬_heap_number); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1666 | // We've seen something for the first time -> deopt. |
| 1667 | DeoptimizeIf(al, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1673 | void LCodeGen::EmitGoto(int block) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | block = chunk_->LookupDestination(block); |
| 1675 | int next_block = GetNextEmittedBlock(current_block_); |
| 1676 | if (block != next_block) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1677 | __ jmp(chunk_->GetAssemblyLabel(block)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1682 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1683 | EmitGoto(instr->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | |
| 1687 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1688 | Condition cond = kNoCondition; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1689 | switch (op) { |
| 1690 | case Token::EQ: |
| 1691 | case Token::EQ_STRICT: |
| 1692 | cond = eq; |
| 1693 | break; |
| 1694 | case Token::LT: |
| 1695 | cond = is_unsigned ? lo : lt; |
| 1696 | break; |
| 1697 | case Token::GT: |
| 1698 | cond = is_unsigned ? hi : gt; |
| 1699 | break; |
| 1700 | case Token::LTE: |
| 1701 | cond = is_unsigned ? ls : le; |
| 1702 | break; |
| 1703 | case Token::GTE: |
| 1704 | cond = is_unsigned ? hs : ge; |
| 1705 | break; |
| 1706 | case Token::IN: |
| 1707 | case Token::INSTANCEOF: |
| 1708 | default: |
| 1709 | UNREACHABLE(); |
| 1710 | } |
| 1711 | return cond; |
| 1712 | } |
| 1713 | |
| 1714 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1715 | void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1716 | LOperand* left = instr->InputAt(0); |
| 1717 | LOperand* right = instr->InputAt(1); |
| 1718 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1719 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1720 | Condition cond = TokenToCondition(instr->op(), false); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1721 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1722 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 1723 | // We can statically evaluate the comparison. |
| 1724 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 1725 | double right_val = ToDouble(LConstantOperand::cast(right)); |
| 1726 | int next_block = |
| 1727 | EvalComparison(instr->op(), left_val, right_val) ? true_block |
| 1728 | : false_block; |
| 1729 | EmitGoto(next_block); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1730 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1731 | if (instr->is_double()) { |
| 1732 | // Compare left and right operands as doubles and load the |
| 1733 | // resulting flags into the normal status register. |
| 1734 | __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1735 | // If a NaN is involved, i.e. the result is unordered (V set), |
| 1736 | // jump to false block label. |
| 1737 | __ b(vs, chunk_->GetAssemblyLabel(false_block)); |
| 1738 | } else { |
| 1739 | if (right->IsConstantOperand()) { |
| 1740 | __ cmp(ToRegister(left), |
| 1741 | Operand(ToInteger32(LConstantOperand::cast(right)))); |
| 1742 | } else if (left->IsConstantOperand()) { |
| 1743 | __ cmp(ToRegister(right), |
| 1744 | Operand(ToInteger32(LConstantOperand::cast(left)))); |
| 1745 | // We transposed the operands. Reverse the condition. |
| 1746 | cond = ReverseCondition(cond); |
| 1747 | } else { |
| 1748 | __ cmp(ToRegister(left), ToRegister(right)); |
| 1749 | } |
| 1750 | } |
| 1751 | EmitBranch(true_block, false_block, cond); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1752 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1756 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1757 | Register left = ToRegister(instr->InputAt(0)); |
| 1758 | Register right = ToRegister(instr->InputAt(1)); |
| 1759 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1760 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1761 | |
| 1762 | __ cmp(left, Operand(right)); |
| 1763 | EmitBranch(true_block, false_block, eq); |
| 1764 | } |
| 1765 | |
| 1766 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1767 | void LCodeGen::DoCmpConstantEqAndBranch(LCmpConstantEqAndBranch* instr) { |
| 1768 | Register left = ToRegister(instr->InputAt(0)); |
| 1769 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1770 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1771 | |
| 1772 | __ cmp(left, Operand(instr->hydrogen()->right())); |
| 1773 | EmitBranch(true_block, false_block, eq); |
| 1774 | } |
| 1775 | |
| 1776 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1777 | void LCodeGen::DoIsNilAndBranch(LIsNilAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1778 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1779 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1780 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1781 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1782 | // If the expression is known to be untagged or a smi, then it's definitely |
| 1783 | // not null, and it can't be a an undetectable object. |
| 1784 | if (instr->hydrogen()->representation().IsSpecialization() || |
| 1785 | instr->hydrogen()->type().IsSmi()) { |
| 1786 | EmitGoto(false_block); |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1791 | Heap::RootListIndex nil_value = instr->nil() == kNullValue ? |
| 1792 | Heap::kNullValueRootIndex : |
| 1793 | Heap::kUndefinedValueRootIndex; |
| 1794 | __ LoadRoot(ip, nil_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1795 | __ cmp(reg, ip); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1796 | if (instr->kind() == kStrictEquality) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1797 | EmitBranch(true_block, false_block, eq); |
| 1798 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1799 | Heap::RootListIndex other_nil_value = instr->nil() == kNullValue ? |
| 1800 | Heap::kUndefinedValueRootIndex : |
| 1801 | Heap::kNullValueRootIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1802 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1803 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1804 | __ b(eq, true_label); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1805 | __ LoadRoot(ip, other_nil_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1806 | __ cmp(reg, ip); |
| 1807 | __ b(eq, true_label); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1808 | __ JumpIfSmi(reg, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | // Check for undetectable objects by looking in the bit field in |
| 1810 | // the map. The object has already been smi checked. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1811 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1812 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 1813 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
| 1814 | EmitBranch(true_block, false_block, ne); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1819 | Condition LCodeGen::EmitIsObject(Register input, |
| 1820 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1821 | Label* is_not_object, |
| 1822 | Label* is_object) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1823 | Register temp2 = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1824 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1825 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1826 | __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 1827 | __ cmp(input, temp2); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1828 | __ b(eq, is_object); |
| 1829 | |
| 1830 | // Load map. |
| 1831 | __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1832 | // Undetectable objects behave like undefined. |
| 1833 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 1834 | __ tst(temp2, Operand(1 << Map::kIsUndetectable)); |
| 1835 | __ b(ne, is_not_object); |
| 1836 | |
| 1837 | // Load instance type and check that it is in object type range. |
| 1838 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1839 | __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1840 | __ b(lt, is_not_object); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1841 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1842 | return le; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1846 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1847 | Register reg = ToRegister(instr->InputAt(0)); |
| 1848 | Register temp1 = ToRegister(instr->TempAt(0)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1849 | |
| 1850 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1851 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1852 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1853 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1854 | |
| 1855 | Condition true_cond = |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1856 | EmitIsObject(reg, temp1, false_label, true_label); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1857 | |
| 1858 | EmitBranch(true_block, false_block, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1862 | Condition LCodeGen::EmitIsString(Register input, |
| 1863 | Register temp1, |
| 1864 | Label* is_not_string) { |
| 1865 | __ JumpIfSmi(input, is_not_string); |
| 1866 | __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); |
| 1867 | |
| 1868 | return lt; |
| 1869 | } |
| 1870 | |
| 1871 | |
| 1872 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
| 1873 | Register reg = ToRegister(instr->InputAt(0)); |
| 1874 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 1875 | |
| 1876 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1877 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1878 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1879 | |
| 1880 | Condition true_cond = |
| 1881 | EmitIsString(reg, temp1, false_label); |
| 1882 | |
| 1883 | EmitBranch(true_block, false_block, true_cond); |
| 1884 | } |
| 1885 | |
| 1886 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1887 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 1888 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1889 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1890 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1891 | Register input_reg = EmitLoadRegister(instr->InputAt(0), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1892 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 1893 | EmitBranch(true_block, false_block, eq); |
| 1894 | } |
| 1895 | |
| 1896 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1897 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
| 1898 | Register input = ToRegister(instr->InputAt(0)); |
| 1899 | Register temp = ToRegister(instr->TempAt(0)); |
| 1900 | |
| 1901 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1902 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1903 | |
| 1904 | __ JumpIfSmi(input, chunk_->GetAssemblyLabel(false_block)); |
| 1905 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1906 | __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 1907 | __ tst(temp, Operand(1 << Map::kIsUndetectable)); |
| 1908 | EmitBranch(true_block, false_block, ne); |
| 1909 | } |
| 1910 | |
| 1911 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1912 | static Condition ComputeCompareCondition(Token::Value op) { |
| 1913 | switch (op) { |
| 1914 | case Token::EQ_STRICT: |
| 1915 | case Token::EQ: |
| 1916 | return eq; |
| 1917 | case Token::LT: |
| 1918 | return lt; |
| 1919 | case Token::GT: |
| 1920 | return gt; |
| 1921 | case Token::LTE: |
| 1922 | return le; |
| 1923 | case Token::GTE: |
| 1924 | return ge; |
| 1925 | default: |
| 1926 | UNREACHABLE(); |
| 1927 | return kNoCondition; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | |
| 1932 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 1933 | Token::Value op = instr->op(); |
| 1934 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1935 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1936 | |
| 1937 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
| 1938 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 1939 | __ cmp(r0, Operand(0)); // This instruction also signals no smi code inlined. |
| 1940 | |
| 1941 | Condition condition = ComputeCompareCondition(op); |
| 1942 | |
| 1943 | EmitBranch(true_block, false_block, condition); |
| 1944 | } |
| 1945 | |
| 1946 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1947 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1948 | InstanceType from = instr->from(); |
| 1949 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1950 | if (from == FIRST_TYPE) return to; |
| 1951 | ASSERT(from == to || to == LAST_TYPE); |
| 1952 | return from; |
| 1953 | } |
| 1954 | |
| 1955 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1956 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1957 | InstanceType from = instr->from(); |
| 1958 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1959 | if (from == to) return eq; |
| 1960 | if (to == LAST_TYPE) return hs; |
| 1961 | if (from == FIRST_TYPE) return ls; |
| 1962 | UNREACHABLE(); |
| 1963 | return eq; |
| 1964 | } |
| 1965 | |
| 1966 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1967 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1968 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1969 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1970 | |
| 1971 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1972 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1973 | |
| 1974 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1975 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1976 | __ JumpIfSmi(input, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1977 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1978 | __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
| 1979 | EmitBranch(true_block, false_block, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1983 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
| 1984 | Register input = ToRegister(instr->InputAt(0)); |
| 1985 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1986 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1987 | if (FLAG_debug_code) { |
| 1988 | __ AbortIfNotString(input); |
| 1989 | } |
| 1990 | |
| 1991 | __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 1992 | __ IndexFromHash(result, result); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1996 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 1997 | LHasCachedArrayIndexAndBranch* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1998 | Register input = ToRegister(instr->InputAt(0)); |
| 1999 | Register scratch = scratch0(); |
| 2000 | |
| 2001 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2002 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2003 | |
| 2004 | __ ldr(scratch, |
| 2005 | FieldMemOperand(input, String::kHashFieldOffset)); |
| 2006 | __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask)); |
| 2007 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2011 | // Branches to a label or falls through with the answer in flags. Trashes |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2012 | // the temp registers, but not the input. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2013 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2014 | Label* is_false, |
| 2015 | Handle<String>class_name, |
| 2016 | Register input, |
| 2017 | Register temp, |
| 2018 | Register temp2) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2019 | ASSERT(!input.is(temp)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2020 | ASSERT(!input.is(temp2)); |
| 2021 | ASSERT(!temp.is(temp2)); |
| 2022 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2023 | __ JumpIfSmi(input, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2024 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2025 | if (class_name->IsEqualTo(CStrVector("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2026 | // Assuming the following assertions, we can use the same compares to test |
| 2027 | // for both being a function type and being in the object type range. |
| 2028 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2029 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2030 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2031 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2032 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2033 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2034 | __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); |
| 2035 | __ b(lt, is_false); |
| 2036 | __ b(eq, is_true); |
| 2037 | __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2038 | __ b(eq, is_true); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2039 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2040 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2041 | // actual type and do a signed compare with the width of the type range. |
| 2042 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2043 | __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
| 2044 | __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2045 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2046 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2047 | __ b(gt, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2050 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2051 | // Check if the constructor in the map is a function. |
| 2052 | __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2053 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2054 | // Objects with a non-function constructor have class 'Object'. |
| 2055 | __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
| 2056 | if (class_name->IsEqualTo(CStrVector("Object"))) { |
| 2057 | __ b(ne, is_true); |
| 2058 | } else { |
| 2059 | __ b(ne, is_false); |
| 2060 | } |
| 2061 | |
| 2062 | // temp now contains the constructor function. Grab the |
| 2063 | // instance class name from there. |
| 2064 | __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2065 | __ ldr(temp, FieldMemOperand(temp, |
| 2066 | SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2067 | // The class name we are testing against is a symbol because it's a literal. |
| 2068 | // The name in the constructor is a symbol because of the way the context is |
| 2069 | // booted. This routine isn't expected to work for random API-created |
| 2070 | // classes and it doesn't have to because you can't access it with natives |
| 2071 | // syntax. Since both sides are symbols it is sufficient to use an identity |
| 2072 | // comparison. |
| 2073 | __ cmp(temp, Operand(class_name)); |
| 2074 | // End with the answer in flags. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2078 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2079 | Register input = ToRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2080 | Register temp = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2081 | Register temp2 = ToRegister(instr->TempAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2082 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2083 | |
| 2084 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2085 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2086 | |
| 2087 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2088 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2089 | |
| 2090 | EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
| 2091 | |
| 2092 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | |
| 2096 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2097 | Register reg = ToRegister(instr->InputAt(0)); |
| 2098 | Register temp = ToRegister(instr->TempAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2099 | int true_block = instr->true_block_id(); |
| 2100 | int false_block = instr->false_block_id(); |
| 2101 | |
| 2102 | __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2103 | __ cmp(temp, Operand(instr->map())); |
| 2104 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | |
| 2108 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2109 | ASSERT(ToRegister(instr->InputAt(0)).is(r0)); // Object is in r0. |
| 2110 | ASSERT(ToRegister(instr->InputAt(1)).is(r1)); // Function is in r1. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2111 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2112 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
| 2113 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2114 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2115 | __ cmp(r0, Operand(0)); |
| 2116 | __ mov(r0, Operand(factory()->false_value()), LeaveCC, ne); |
| 2117 | __ mov(r0, Operand(factory()->true_value()), LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2121 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2122 | class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
| 2123 | public: |
| 2124 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2125 | LInstanceOfKnownGlobal* instr) |
| 2126 | : LDeferredCode(codegen), instr_(instr) { } |
| 2127 | virtual void Generate() { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2128 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2129 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2130 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2131 | Label* map_check() { return &map_check_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2132 | private: |
| 2133 | LInstanceOfKnownGlobal* instr_; |
| 2134 | Label map_check_; |
| 2135 | }; |
| 2136 | |
| 2137 | DeferredInstanceOfKnownGlobal* deferred; |
| 2138 | deferred = new DeferredInstanceOfKnownGlobal(this, instr); |
| 2139 | |
| 2140 | Label done, false_result; |
| 2141 | Register object = ToRegister(instr->InputAt(0)); |
| 2142 | Register temp = ToRegister(instr->TempAt(0)); |
| 2143 | Register result = ToRegister(instr->result()); |
| 2144 | |
| 2145 | ASSERT(object.is(r0)); |
| 2146 | ASSERT(result.is(r0)); |
| 2147 | |
| 2148 | // A Smi is not instance of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2149 | __ JumpIfSmi(object, &false_result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2150 | |
| 2151 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2152 | // hole value will be patched to the last map/result pair generated by the |
| 2153 | // instanceof stub. |
| 2154 | Label cache_miss; |
| 2155 | Register map = temp; |
| 2156 | __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2157 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2158 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2159 | // root array to force relocation to be able to later patch with |
| 2160 | // the cached map. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2161 | Handle<JSGlobalPropertyCell> cell = |
| 2162 | factory()->NewJSGlobalPropertyCell(factory()->the_hole_value()); |
| 2163 | __ mov(ip, Operand(Handle<Object>(cell))); |
| 2164 | __ ldr(ip, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2165 | __ cmp(map, Operand(ip)); |
| 2166 | __ b(ne, &cache_miss); |
| 2167 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2168 | // root array to force relocation to be able to later patch |
| 2169 | // with true or false. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2170 | __ mov(result, Operand(factory()->the_hole_value())); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2171 | __ b(&done); |
| 2172 | |
| 2173 | // The inlined call site cache did not match. Check null and string before |
| 2174 | // calling the deferred code. |
| 2175 | __ bind(&cache_miss); |
| 2176 | // Null is not instance of anything. |
| 2177 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2178 | __ cmp(object, Operand(ip)); |
| 2179 | __ b(eq, &false_result); |
| 2180 | |
| 2181 | // String values is not instance of anything. |
| 2182 | Condition is_string = masm_->IsObjectStringType(object, temp); |
| 2183 | __ b(is_string, &false_result); |
| 2184 | |
| 2185 | // Go to the deferred code. |
| 2186 | __ b(deferred->entry()); |
| 2187 | |
| 2188 | __ bind(&false_result); |
| 2189 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2190 | |
| 2191 | // Here result has either true or false. Deferred code also produces true or |
| 2192 | // false object. |
| 2193 | __ bind(deferred->exit()); |
| 2194 | __ bind(&done); |
| 2195 | } |
| 2196 | |
| 2197 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2198 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2199 | Label* map_check) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2200 | Register result = ToRegister(instr->result()); |
| 2201 | ASSERT(result.is(r0)); |
| 2202 | |
| 2203 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2204 | flags = static_cast<InstanceofStub::Flags>( |
| 2205 | flags | InstanceofStub::kArgsInRegisters); |
| 2206 | flags = static_cast<InstanceofStub::Flags>( |
| 2207 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2208 | flags = static_cast<InstanceofStub::Flags>( |
| 2209 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2210 | InstanceofStub stub(flags); |
| 2211 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2212 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2213 | |
| 2214 | // Get the temp register reserved by the instruction. This needs to be r4 as |
| 2215 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2216 | // offset to the location of the map check. |
| 2217 | Register temp = ToRegister(instr->TempAt(0)); |
| 2218 | ASSERT(temp.is(r4)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2219 | __ LoadHeapObject(InstanceofStub::right(), instr->function()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2220 | static const int kAdditionalDelta = 4; |
| 2221 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2222 | Label before_push_delta; |
| 2223 | __ bind(&before_push_delta); |
| 2224 | __ BlockConstPoolFor(kAdditionalDelta); |
| 2225 | __ mov(temp, Operand(delta * kPointerSize)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2226 | __ StoreToSafepointRegisterSlot(temp, temp); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2227 | CallCodeGeneric(stub.GetCode(), |
| 2228 | RelocInfo::CODE_TARGET, |
| 2229 | instr, |
| 2230 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2231 | ASSERT(instr->HasDeoptimizationEnvironment()); |
| 2232 | LEnvironment* env = instr->deoptimization_environment(); |
| 2233 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2234 | // Put the result value into the result register slot and |
| 2235 | // restore all registers. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2236 | __ StoreToSafepointRegisterSlot(result, result); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2239 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2240 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2241 | Token::Value op = instr->op(); |
| 2242 | |
| 2243 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
| 2244 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2245 | __ cmp(r0, Operand(0)); // This instruction also signals no smi code inlined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2246 | |
| 2247 | Condition condition = ComputeCompareCondition(op); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2248 | __ LoadRoot(ToRegister(instr->result()), |
| 2249 | Heap::kTrueValueRootIndex, |
| 2250 | condition); |
| 2251 | __ LoadRoot(ToRegister(instr->result()), |
| 2252 | Heap::kFalseValueRootIndex, |
| 2253 | NegateCondition(condition)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2257 | void LCodeGen::DoReturn(LReturn* instr) { |
| 2258 | if (FLAG_trace) { |
| 2259 | // Push the return value on the stack as the parameter. |
| 2260 | // Runtime::TraceExit returns its parameter in r0. |
| 2261 | __ push(r0); |
| 2262 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2263 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2264 | int32_t sp_delta = (GetParameterCount() + 1) * kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2265 | __ mov(sp, fp); |
| 2266 | __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 2267 | __ add(sp, sp, Operand(sp_delta)); |
| 2268 | __ Jump(lr); |
| 2269 | } |
| 2270 | |
| 2271 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2272 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2273 | Register result = ToRegister(instr->result()); |
| 2274 | __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell()))); |
| 2275 | __ ldr(result, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2276 | if (instr->hydrogen()->RequiresHoleCheck()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2277 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2278 | __ cmp(result, ip); |
| 2279 | DeoptimizeIf(eq, instr->environment()); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2284 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 2285 | ASSERT(ToRegister(instr->global_object()).is(r0)); |
| 2286 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2287 | |
| 2288 | __ mov(r2, Operand(instr->name())); |
| 2289 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET |
| 2290 | : RelocInfo::CODE_TARGET_CONTEXT; |
| 2291 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2292 | CallCode(ic, mode, instr); |
| 2293 | } |
| 2294 | |
| 2295 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2296 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2297 | Register value = ToRegister(instr->value()); |
| 2298 | Register cell = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2299 | |
| 2300 | // Load the cell. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2301 | __ mov(cell, Operand(instr->hydrogen()->cell())); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2302 | |
| 2303 | // If the cell we are storing to contains the hole it could have |
| 2304 | // been deleted from the property dictionary. In that case, we need |
| 2305 | // to update the property details in the property dictionary to mark |
| 2306 | // it as no longer deleted. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2307 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2308 | // We use a temp to check the payload (CompareRoot might clobber ip). |
| 2309 | Register payload = ToRegister(instr->TempAt(0)); |
| 2310 | __ ldr(payload, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
| 2311 | __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2312 | DeoptimizeIf(eq, instr->environment()); |
| 2313 | } |
| 2314 | |
| 2315 | // Store the value. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2316 | __ str(value, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2317 | // Cells are always rescanned, so no write barrier here. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2321 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
| 2322 | ASSERT(ToRegister(instr->global_object()).is(r1)); |
| 2323 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 2324 | |
| 2325 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2326 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2327 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 2328 | : isolate()->builtins()->StoreIC_Initialize(); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2329 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
| 2330 | } |
| 2331 | |
| 2332 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2333 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2334 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2335 | Register result = ToRegister(instr->result()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2336 | __ ldr(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2337 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2338 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2339 | __ cmp(result, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2340 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2341 | DeoptimizeIf(eq, instr->environment()); |
| 2342 | } else { |
| 2343 | __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq); |
| 2344 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2345 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2349 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2350 | Register context = ToRegister(instr->context()); |
| 2351 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2352 | Register scratch = scratch0(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2353 | MemOperand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2354 | |
| 2355 | Label skip_assignment; |
| 2356 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2357 | if (instr->hydrogen()->RequiresHoleCheck()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2358 | __ ldr(scratch, target); |
| 2359 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2360 | __ cmp(scratch, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2361 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2362 | DeoptimizeIf(eq, instr->environment()); |
| 2363 | } else { |
| 2364 | __ b(ne, &skip_assignment); |
| 2365 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2366 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2367 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2368 | __ str(value, target); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2369 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 2370 | HType type = instr->hydrogen()->value()->type(); |
| 2371 | SmiCheck check_needed = |
| 2372 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2373 | __ RecordWriteContextSlot(context, |
| 2374 | target.offset(), |
| 2375 | value, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2376 | scratch, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2377 | kLRHasBeenSaved, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2378 | kSaveFPRegs, |
| 2379 | EMIT_REMEMBERED_SET, |
| 2380 | check_needed); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2381 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2382 | |
| 2383 | __ bind(&skip_assignment); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2387 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2388 | Register object = ToRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2389 | Register result = ToRegister(instr->result()); |
| 2390 | if (instr->hydrogen()->is_in_object()) { |
| 2391 | __ ldr(result, FieldMemOperand(object, instr->hydrogen()->offset())); |
| 2392 | } else { |
| 2393 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2394 | __ ldr(result, FieldMemOperand(result, instr->hydrogen()->offset())); |
| 2395 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2399 | void LCodeGen::EmitLoadFieldOrConstantFunction(Register result, |
| 2400 | Register object, |
| 2401 | Handle<Map> type, |
| 2402 | Handle<String> name) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2403 | LookupResult lookup(isolate()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2404 | type->LookupInDescriptors(NULL, *name, &lookup); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2405 | ASSERT(lookup.IsFound() && |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2406 | (lookup.type() == FIELD || lookup.type() == CONSTANT_FUNCTION)); |
| 2407 | if (lookup.type() == FIELD) { |
| 2408 | int index = lookup.GetLocalFieldIndexFromMap(*type); |
| 2409 | int offset = index * kPointerSize; |
| 2410 | if (index < 0) { |
| 2411 | // Negative property indices are in-object properties, indexed |
| 2412 | // from the end of the fixed part of the object. |
| 2413 | __ ldr(result, FieldMemOperand(object, offset + type->instance_size())); |
| 2414 | } else { |
| 2415 | // Non-negative property indices are in the properties array. |
| 2416 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2417 | __ ldr(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize)); |
| 2418 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2419 | } else { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2420 | Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2421 | __ LoadHeapObject(result, function); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { |
| 2427 | Register object = ToRegister(instr->object()); |
| 2428 | Register result = ToRegister(instr->result()); |
| 2429 | Register scratch = scratch0(); |
| 2430 | int map_count = instr->hydrogen()->types()->length(); |
| 2431 | Handle<String> name = instr->hydrogen()->name(); |
| 2432 | if (map_count == 0) { |
| 2433 | ASSERT(instr->hydrogen()->need_generic()); |
| 2434 | __ mov(r2, Operand(name)); |
| 2435 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2436 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2437 | } else { |
| 2438 | Label done; |
| 2439 | __ ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2440 | for (int i = 0; i < map_count - 1; ++i) { |
| 2441 | Handle<Map> map = instr->hydrogen()->types()->at(i); |
| 2442 | Label next; |
| 2443 | __ cmp(scratch, Operand(map)); |
| 2444 | __ b(ne, &next); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2445 | EmitLoadFieldOrConstantFunction(result, object, map, name); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2446 | __ b(&done); |
| 2447 | __ bind(&next); |
| 2448 | } |
| 2449 | Handle<Map> map = instr->hydrogen()->types()->last(); |
| 2450 | __ cmp(scratch, Operand(map)); |
| 2451 | if (instr->hydrogen()->need_generic()) { |
| 2452 | Label generic; |
| 2453 | __ b(ne, &generic); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2454 | EmitLoadFieldOrConstantFunction(result, object, map, name); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2455 | __ b(&done); |
| 2456 | __ bind(&generic); |
| 2457 | __ mov(r2, Operand(name)); |
| 2458 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2459 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2460 | } else { |
| 2461 | DeoptimizeIf(ne, instr->environment()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2462 | EmitLoadFieldOrConstantFunction(result, object, map, name); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2463 | } |
| 2464 | __ bind(&done); |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2469 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 2470 | ASSERT(ToRegister(instr->object()).is(r0)); |
| 2471 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2472 | |
| 2473 | // Name is always in r2. |
| 2474 | __ mov(r2, Operand(instr->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2475 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2476 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2477 | } |
| 2478 | |
| 2479 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2480 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2481 | Register scratch = scratch0(); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2482 | Register function = ToRegister(instr->function()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2483 | Register result = ToRegister(instr->result()); |
| 2484 | |
| 2485 | // Check that the function really is a function. Load map into the |
| 2486 | // result register. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2487 | __ CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2488 | DeoptimizeIf(ne, instr->environment()); |
| 2489 | |
| 2490 | // Make sure that the function has an instance prototype. |
| 2491 | Label non_instance; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2492 | __ ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 2493 | __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2494 | __ b(ne, &non_instance); |
| 2495 | |
| 2496 | // Get the prototype or initial map from the function. |
| 2497 | __ ldr(result, |
| 2498 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2499 | |
| 2500 | // Check that the function has a prototype or an initial map. |
| 2501 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2502 | __ cmp(result, ip); |
| 2503 | DeoptimizeIf(eq, instr->environment()); |
| 2504 | |
| 2505 | // If the function does not have an initial map, we're done. |
| 2506 | Label done; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2507 | __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2508 | __ b(ne, &done); |
| 2509 | |
| 2510 | // Get the prototype from the initial map. |
| 2511 | __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2512 | __ jmp(&done); |
| 2513 | |
| 2514 | // Non-instance prototype: Fetch prototype from constructor field |
| 2515 | // in initial map. |
| 2516 | __ bind(&non_instance); |
| 2517 | __ ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 2518 | |
| 2519 | // All done. |
| 2520 | __ bind(&done); |
| 2521 | } |
| 2522 | |
| 2523 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2524 | void LCodeGen::DoLoadElements(LLoadElements* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2525 | Register result = ToRegister(instr->result()); |
| 2526 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2527 | Register scratch = scratch0(); |
| 2528 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2529 | __ ldr(result, FieldMemOperand(input, JSObject::kElementsOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2530 | if (FLAG_debug_code) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2531 | Label done, fail; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2532 | __ ldr(scratch, FieldMemOperand(result, HeapObject::kMapOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2533 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2534 | __ cmp(scratch, ip); |
| 2535 | __ b(eq, &done); |
| 2536 | __ LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2537 | __ cmp(scratch, ip); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2538 | __ b(eq, &done); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2539 | // |scratch| still contains |input|'s map. |
| 2540 | __ ldr(scratch, FieldMemOperand(scratch, Map::kBitField2Offset)); |
| 2541 | __ ubfx(scratch, scratch, Map::kElementsKindShift, |
| 2542 | Map::kElementsKindBitCount); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2543 | __ cmp(scratch, Operand(FAST_ELEMENTS)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2544 | __ b(eq, &done); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2545 | __ cmp(scratch, Operand(FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2546 | __ b(lt, &fail); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2547 | __ cmp(scratch, Operand(LAST_EXTERNAL_ARRAY_ELEMENTS_KIND)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2548 | __ b(le, &done); |
| 2549 | __ bind(&fail); |
| 2550 | __ Abort("Check for fast or external elements failed."); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2551 | __ bind(&done); |
| 2552 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2556 | void LCodeGen::DoLoadExternalArrayPointer( |
| 2557 | LLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2558 | Register to_reg = ToRegister(instr->result()); |
| 2559 | Register from_reg = ToRegister(instr->InputAt(0)); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2560 | __ ldr(to_reg, FieldMemOperand(from_reg, |
| 2561 | ExternalArray::kExternalPointerOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2565 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2566 | Register arguments = ToRegister(instr->arguments()); |
| 2567 | Register length = ToRegister(instr->length()); |
| 2568 | Register index = ToRegister(instr->index()); |
| 2569 | Register result = ToRegister(instr->result()); |
| 2570 | |
| 2571 | // Bailout index is not a valid argument index. Use unsigned check to get |
| 2572 | // negative check for free. |
| 2573 | __ sub(length, length, index, SetCC); |
| 2574 | DeoptimizeIf(ls, instr->environment()); |
| 2575 | |
| 2576 | // There are two words between the frame pointer and the last argument. |
| 2577 | // Subtracting from length accounts for one of them add one more. |
| 2578 | __ add(length, length, Operand(1)); |
| 2579 | __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | |
| 2583 | void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2584 | Register elements = ToRegister(instr->elements()); |
| 2585 | Register key = EmitLoadRegister(instr->key(), scratch0()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2586 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2587 | Register scratch = scratch0(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2588 | |
| 2589 | // Load the result. |
| 2590 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 2591 | __ ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 2592 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2593 | // Check for the hole value. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2594 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2595 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 2596 | __ cmp(result, scratch); |
| 2597 | DeoptimizeIf(eq, instr->environment()); |
| 2598 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2602 | void LCodeGen::DoLoadKeyedFastDoubleElement( |
| 2603 | LLoadKeyedFastDoubleElement* instr) { |
| 2604 | Register elements = ToRegister(instr->elements()); |
| 2605 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2606 | Register key = no_reg; |
| 2607 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 2608 | Register scratch = scratch0(); |
| 2609 | |
| 2610 | int shift_size = |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2611 | ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2612 | int constant_key = 0; |
| 2613 | if (key_is_constant) { |
| 2614 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2615 | if (constant_key & 0xF0000000) { |
| 2616 | Abort("array index constant value too big."); |
| 2617 | } |
| 2618 | } else { |
| 2619 | key = ToRegister(instr->key()); |
| 2620 | } |
| 2621 | |
| 2622 | Operand operand = key_is_constant |
| 2623 | ? Operand(constant_key * (1 << shift_size) + |
| 2624 | FixedDoubleArray::kHeaderSize - kHeapObjectTag) |
| 2625 | : Operand(key, LSL, shift_size); |
| 2626 | __ add(elements, elements, operand); |
| 2627 | if (!key_is_constant) { |
| 2628 | __ add(elements, elements, |
| 2629 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
| 2630 | } |
| 2631 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2632 | __ ldr(scratch, MemOperand(elements, sizeof(kHoleNanLower32))); |
| 2633 | __ cmp(scratch, Operand(kHoleNanUpper32)); |
| 2634 | DeoptimizeIf(eq, instr->environment()); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2635 | |
| 2636 | __ vldr(result, elements, 0); |
| 2637 | } |
| 2638 | |
| 2639 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2640 | void LCodeGen::DoLoadKeyedSpecializedArrayElement( |
| 2641 | LLoadKeyedSpecializedArrayElement* instr) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2642 | Register external_pointer = ToRegister(instr->external_pointer()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2643 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2644 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2645 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2646 | int constant_key = 0; |
| 2647 | if (key_is_constant) { |
| 2648 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2649 | if (constant_key & 0xF0000000) { |
| 2650 | Abort("array index constant value too big."); |
| 2651 | } |
| 2652 | } else { |
| 2653 | key = ToRegister(instr->key()); |
| 2654 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2655 | int shift_size = ElementsKindToShiftSize(elements_kind); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2656 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2657 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 2658 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2659 | CpuFeatures::Scope scope(VFP3); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2660 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 2661 | Operand operand = key_is_constant |
| 2662 | ? Operand(constant_key * (1 << shift_size)) |
| 2663 | : Operand(key, LSL, shift_size); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2664 | __ add(scratch0(), external_pointer, operand); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2665 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2666 | __ vldr(result.low(), scratch0(), 0); |
| 2667 | __ vcvt_f64_f32(result, result.low()); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2668 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2669 | __ vldr(result, scratch0(), 0); |
| 2670 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2671 | } else { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2672 | Register result = ToRegister(instr->result()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2673 | MemOperand mem_operand(key_is_constant |
| 2674 | ? MemOperand(external_pointer, constant_key * (1 << shift_size)) |
| 2675 | : MemOperand(external_pointer, key, LSL, shift_size)); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2676 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2677 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2678 | __ ldrsb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2679 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2680 | case EXTERNAL_PIXEL_ELEMENTS: |
| 2681 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2682 | __ ldrb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2683 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2684 | case EXTERNAL_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2685 | __ ldrsh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2686 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2687 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2688 | __ ldrh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2689 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2690 | case EXTERNAL_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2691 | __ ldr(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2692 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2693 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2694 | __ ldr(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2695 | __ cmp(result, Operand(0x80000000)); |
| 2696 | // TODO(danno): we could be more clever here, perhaps having a special |
| 2697 | // version of the stub that detects if the overflow case actually |
| 2698 | // happens, and generate code that returns a double rather than int. |
| 2699 | DeoptimizeIf(cs, instr->environment()); |
| 2700 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2701 | case EXTERNAL_FLOAT_ELEMENTS: |
| 2702 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 2703 | case FAST_DOUBLE_ELEMENTS: |
| 2704 | case FAST_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2705 | case FAST_SMI_ONLY_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2706 | case DICTIONARY_ELEMENTS: |
| 2707 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2708 | UNREACHABLE(); |
| 2709 | break; |
| 2710 | } |
| 2711 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2715 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 2716 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 2717 | ASSERT(ToRegister(instr->key()).is(r0)); |
| 2718 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2719 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2720 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2721 | } |
| 2722 | |
| 2723 | |
| 2724 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2725 | Register scratch = scratch0(); |
| 2726 | Register result = ToRegister(instr->result()); |
| 2727 | |
| 2728 | // Check if the calling frame is an arguments adaptor frame. |
| 2729 | Label done, adapted; |
| 2730 | __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2731 | __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 2732 | __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2733 | |
| 2734 | // Result is the frame pointer for the frame if not adapted and for the real |
| 2735 | // frame below the adaptor frame if adapted. |
| 2736 | __ mov(result, fp, LeaveCC, ne); |
| 2737 | __ mov(result, scratch, LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | |
| 2741 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2742 | Register elem = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2743 | Register result = ToRegister(instr->result()); |
| 2744 | |
| 2745 | Label done; |
| 2746 | |
| 2747 | // If no arguments adaptor frame the number of arguments is fixed. |
| 2748 | __ cmp(fp, elem); |
| 2749 | __ mov(result, Operand(scope()->num_parameters())); |
| 2750 | __ b(eq, &done); |
| 2751 | |
| 2752 | // Arguments adaptor frame present. Get argument length from there. |
| 2753 | __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2754 | __ ldr(result, |
| 2755 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2756 | __ SmiUntag(result); |
| 2757 | |
| 2758 | // Argument length is in result register. |
| 2759 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | |
| 2763 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2764 | Register receiver = ToRegister(instr->receiver()); |
| 2765 | Register function = ToRegister(instr->function()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2766 | Register length = ToRegister(instr->length()); |
| 2767 | Register elements = ToRegister(instr->elements()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2768 | Register scratch = scratch0(); |
| 2769 | ASSERT(receiver.is(r0)); // Used for parameter count. |
| 2770 | ASSERT(function.is(r1)); // Required by InvokeFunction. |
| 2771 | ASSERT(ToRegister(instr->result()).is(r0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2772 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2773 | // If the receiver is null or undefined, we have to pass the global |
| 2774 | // object as a receiver to normal functions. Values have to be |
| 2775 | // passed unchanged to builtins and strict-mode functions. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2776 | Label global_object, receiver_ok; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2777 | |
| 2778 | // Do not transform the receiver to object for strict mode |
| 2779 | // functions. |
| 2780 | __ ldr(scratch, |
| 2781 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 2782 | __ ldr(scratch, |
| 2783 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 2784 | __ tst(scratch, |
| 2785 | Operand(1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize))); |
| 2786 | __ b(ne, &receiver_ok); |
| 2787 | |
| 2788 | // Do not transform the receiver to object for builtins. |
| 2789 | __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); |
| 2790 | __ b(ne, &receiver_ok); |
| 2791 | |
| 2792 | // Normal function. Replace undefined or null with global receiver. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2793 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 2794 | __ cmp(receiver, scratch); |
| 2795 | __ b(eq, &global_object); |
| 2796 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 2797 | __ cmp(receiver, scratch); |
| 2798 | __ b(eq, &global_object); |
| 2799 | |
| 2800 | // Deoptimize if the receiver is not a JS object. |
| 2801 | __ tst(receiver, Operand(kSmiTagMask)); |
| 2802 | DeoptimizeIf(eq, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2803 | __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); |
| 2804 | DeoptimizeIf(lt, instr->environment()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2805 | __ jmp(&receiver_ok); |
| 2806 | |
| 2807 | __ bind(&global_object); |
| 2808 | __ ldr(receiver, GlobalObjectOperand()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2809 | __ ldr(receiver, |
| 2810 | FieldMemOperand(receiver, JSGlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2811 | __ bind(&receiver_ok); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2812 | |
| 2813 | // Copy the arguments to this function possibly from the |
| 2814 | // adaptor frame below it. |
| 2815 | const uint32_t kArgumentsLimit = 1 * KB; |
| 2816 | __ cmp(length, Operand(kArgumentsLimit)); |
| 2817 | DeoptimizeIf(hi, instr->environment()); |
| 2818 | |
| 2819 | // Push the receiver and use the register to keep the original |
| 2820 | // number of arguments. |
| 2821 | __ push(receiver); |
| 2822 | __ mov(receiver, length); |
| 2823 | // The arguments are at a one pointer size offset from elements. |
| 2824 | __ add(elements, elements, Operand(1 * kPointerSize)); |
| 2825 | |
| 2826 | // Loop through the arguments pushing them onto the execution |
| 2827 | // stack. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2828 | Label invoke, loop; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2829 | // length is a small non-negative integer, due to the test above. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2830 | __ cmp(length, Operand(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2831 | __ b(eq, &invoke); |
| 2832 | __ bind(&loop); |
| 2833 | __ ldr(scratch, MemOperand(elements, length, LSL, 2)); |
| 2834 | __ push(scratch); |
| 2835 | __ sub(length, length, Operand(1), SetCC); |
| 2836 | __ b(ne, &loop); |
| 2837 | |
| 2838 | __ bind(&invoke); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2839 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 2840 | LPointerMap* pointers = instr->pointer_map(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2841 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2842 | SafepointGenerator safepoint_generator( |
| 2843 | this, pointers, Safepoint::kLazyDeopt); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2844 | // The number of arguments is stored in receiver which is r0, as expected |
| 2845 | // by InvokeFunction. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2846 | ParameterCount actual(receiver); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2847 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 2848 | safepoint_generator, CALL_AS_METHOD); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2849 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | |
| 2853 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2854 | LOperand* argument = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2855 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 2856 | Abort("DoPushArgument not implemented for double type."); |
| 2857 | } else { |
| 2858 | Register argument_reg = EmitLoadRegister(argument, ip); |
| 2859 | __ push(argument_reg); |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2864 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 2865 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2866 | __ LoadHeapObject(result, instr->hydrogen()->closure()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2870 | void LCodeGen::DoContext(LContext* instr) { |
| 2871 | Register result = ToRegister(instr->result()); |
| 2872 | __ mov(result, cp); |
| 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 2877 | Register context = ToRegister(instr->context()); |
| 2878 | Register result = ToRegister(instr->result()); |
| 2879 | __ ldr(result, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2880 | MemOperand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 2884 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
| 2885 | __ push(cp); // The context is the first argument. |
| 2886 | __ LoadHeapObject(scratch0(), instr->hydrogen()->pairs()); |
| 2887 | __ push(scratch0()); |
| 2888 | __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); |
| 2889 | __ push(scratch0()); |
| 2890 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 2891 | } |
| 2892 | |
| 2893 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2894 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
| 2895 | Register result = ToRegister(instr->result()); |
| 2896 | __ ldr(result, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 2897 | } |
| 2898 | |
| 2899 | |
| 2900 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2901 | Register global = ToRegister(instr->global()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2902 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2903 | __ ldr(result, FieldMemOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
| 2908 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2909 | LInstruction* instr, |
| 2910 | CallKind call_kind) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2911 | bool can_invoke_directly = !function->NeedsArgumentsAdaption() || |
| 2912 | function->shared()->formal_parameter_count() == arity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2913 | |
| 2914 | LPointerMap* pointers = instr->pointer_map(); |
| 2915 | RecordPosition(pointers->position()); |
| 2916 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2917 | if (can_invoke_directly) { |
| 2918 | __ LoadHeapObject(r1, function); |
| 2919 | // Change context if needed. |
| 2920 | bool change_context = |
| 2921 | (info()->closure()->context() != function->context()) || |
| 2922 | scope()->contains_with() || |
| 2923 | (scope()->num_heap_slots() > 0); |
| 2924 | if (change_context) { |
| 2925 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 2926 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2927 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2928 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 2929 | // is available to write to at this point. |
| 2930 | if (!function->NeedsArgumentsAdaption()) { |
| 2931 | __ mov(r0, Operand(arity)); |
| 2932 | } |
| 2933 | |
| 2934 | // Invoke function. |
| 2935 | __ SetCallKind(r5, call_kind); |
| 2936 | __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 2937 | __ Call(ip); |
| 2938 | |
| 2939 | // Set up deoptimization. |
| 2940 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 2941 | } else { |
| 2942 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 2943 | ParameterCount count(arity); |
| 2944 | __ InvokeFunction(function, count, CALL_FUNCTION, generator, call_kind); |
| 2945 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2946 | |
| 2947 | // Restore context. |
| 2948 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2953 | ASSERT(ToRegister(instr->result()).is(r0)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2954 | CallKnownFunction(instr->function(), |
| 2955 | instr->arity(), |
| 2956 | instr, |
| 2957 | CALL_AS_METHOD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | |
| 2961 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2962 | Register input = ToRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2963 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2964 | Register scratch = scratch0(); |
| 2965 | |
| 2966 | // Deoptimize if not a heap number. |
| 2967 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2968 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 2969 | __ cmp(scratch, Operand(ip)); |
| 2970 | DeoptimizeIf(ne, instr->environment()); |
| 2971 | |
| 2972 | Label done; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2973 | Register exponent = scratch0(); |
| 2974 | scratch = no_reg; |
| 2975 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2976 | // Check the sign of the argument. If the argument is positive, just |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2977 | // return it. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2978 | __ tst(exponent, Operand(HeapNumber::kSignMask)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2979 | // Move the input to the result if necessary. |
| 2980 | __ Move(result, input); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2981 | __ b(eq, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2982 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2983 | // Input is negative. Reverse its sign. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2984 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2985 | { |
| 2986 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2987 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2988 | // Registers were saved at the safepoint, so we can use |
| 2989 | // many scratch registers. |
| 2990 | Register tmp1 = input.is(r1) ? r0 : r1; |
| 2991 | Register tmp2 = input.is(r2) ? r0 : r2; |
| 2992 | Register tmp3 = input.is(r3) ? r0 : r3; |
| 2993 | Register tmp4 = input.is(r4) ? r0 : r4; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2994 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2995 | // exponent: floating point exponent value. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2996 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2997 | Label allocated, slow; |
| 2998 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 2999 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3000 | __ b(&allocated); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3001 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3002 | // Slow case: Call the runtime system to do the number allocation. |
| 3003 | __ bind(&slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3004 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3005 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
| 3006 | // Set the pointer to the new heap number in tmp. |
| 3007 | if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); |
| 3008 | // Restore input_reg after call to runtime. |
| 3009 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3010 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3011 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3012 | __ bind(&allocated); |
| 3013 | // exponent: floating point exponent value. |
| 3014 | // tmp1: allocated heap number. |
| 3015 | __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); |
| 3016 | __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3017 | __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3018 | __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3019 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3020 | __ StoreToSafepointRegisterSlot(tmp1, result); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3021 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3022 | |
| 3023 | __ bind(&done); |
| 3024 | } |
| 3025 | |
| 3026 | |
| 3027 | void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3028 | Register input = ToRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3029 | Register result = ToRegister(instr->result()); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3030 | __ cmp(input, Operand(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3031 | __ Move(result, input, pl); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3032 | // We can make rsb conditional because the previous cmp instruction |
| 3033 | // will clear the V (overflow) flag and rsb won't set this flag |
| 3034 | // if input is positive. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3035 | __ rsb(result, input, Operand(0), SetCC, mi); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3036 | // Deoptimize on overflow. |
| 3037 | DeoptimizeIf(vs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | |
| 3041 | void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3042 | // Class for deferred case. |
| 3043 | class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 3044 | public: |
| 3045 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 3046 | LUnaryMathOperation* instr) |
| 3047 | : LDeferredCode(codegen), instr_(instr) { } |
| 3048 | virtual void Generate() { |
| 3049 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3050 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3051 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3052 | private: |
| 3053 | LUnaryMathOperation* instr_; |
| 3054 | }; |
| 3055 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3056 | Representation r = instr->hydrogen()->value()->representation(); |
| 3057 | if (r.IsDouble()) { |
| 3058 | DwVfpRegister input = ToDoubleRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3059 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3060 | __ vabs(result, input); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3061 | } else if (r.IsInteger32()) { |
| 3062 | EmitIntegerMathAbs(instr); |
| 3063 | } else { |
| 3064 | // Representation is tagged. |
| 3065 | DeferredMathAbsTaggedHeapNumber* deferred = |
| 3066 | new DeferredMathAbsTaggedHeapNumber(this, instr); |
| 3067 | Register input = ToRegister(instr->InputAt(0)); |
| 3068 | // Smi check. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3069 | __ JumpIfNotSmi(input, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3070 | // If smi, handle it directly. |
| 3071 | EmitIntegerMathAbs(instr); |
| 3072 | __ bind(deferred->exit()); |
| 3073 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3077 | void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
| 3078 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
| 3079 | Register result = ToRegister(instr->result()); |
| 3080 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 3081 | Register scratch1 = scratch0(); |
| 3082 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 3083 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3084 | __ EmitVFPTruncate(kRoundToMinusInf, |
| 3085 | single_scratch, |
| 3086 | input, |
| 3087 | scratch1, |
| 3088 | scratch2); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3089 | DeoptimizeIf(ne, instr->environment()); |
| 3090 | |
| 3091 | // Move the result back to general purpose register r0. |
| 3092 | __ vmov(result, single_scratch); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3093 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3094 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3095 | // Test for -0. |
| 3096 | Label done; |
| 3097 | __ cmp(result, Operand(0)); |
| 3098 | __ b(ne, &done); |
| 3099 | __ vmov(scratch1, input.high()); |
| 3100 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
| 3101 | DeoptimizeIf(ne, instr->environment()); |
| 3102 | __ bind(&done); |
| 3103 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3107 | void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { |
| 3108 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
| 3109 | Register result = ToRegister(instr->result()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3110 | Register scratch = scratch0(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3111 | Label done, check_sign_on_zero; |
| 3112 | |
| 3113 | // Extract exponent bits. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3114 | __ vmov(result, input.high()); |
| 3115 | __ ubfx(scratch, |
| 3116 | result, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3117 | HeapNumber::kExponentShift, |
| 3118 | HeapNumber::kExponentBits); |
| 3119 | |
| 3120 | // If the number is in ]-0.5, +0.5[, the result is +/- 0. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3121 | __ cmp(scratch, Operand(HeapNumber::kExponentBias - 2)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3122 | __ mov(result, Operand(0), LeaveCC, le); |
| 3123 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3124 | __ b(le, &check_sign_on_zero); |
| 3125 | } else { |
| 3126 | __ b(le, &done); |
| 3127 | } |
| 3128 | |
| 3129 | // The following conversion will not work with numbers |
| 3130 | // outside of ]-2^32, 2^32[. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3131 | __ cmp(scratch, Operand(HeapNumber::kExponentBias + 32)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3132 | DeoptimizeIf(ge, instr->environment()); |
| 3133 | |
| 3134 | // Save the original sign for later comparison. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3135 | __ and_(scratch, result, Operand(HeapNumber::kSignMask)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3136 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3137 | __ Vmov(double_scratch0(), 0.5); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3138 | __ vadd(double_scratch0(), input, double_scratch0()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3139 | |
| 3140 | // Check sign of the result: if the sign changed, the input |
| 3141 | // value was in ]0.5, 0[ and the result should be -0. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3142 | __ vmov(result, double_scratch0().high()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3143 | __ eor(result, result, Operand(scratch), SetCC); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3144 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3145 | DeoptimizeIf(mi, instr->environment()); |
| 3146 | } else { |
| 3147 | __ mov(result, Operand(0), LeaveCC, mi); |
| 3148 | __ b(mi, &done); |
| 3149 | } |
| 3150 | |
| 3151 | __ EmitVFPTruncate(kRoundToMinusInf, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3152 | double_scratch0().low(), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3153 | double_scratch0(), |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3154 | result, |
| 3155 | scratch); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3156 | DeoptimizeIf(ne, instr->environment()); |
| 3157 | __ vmov(result, double_scratch0().low()); |
| 3158 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3159 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3160 | // Test for -0. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3161 | __ cmp(result, Operand(0)); |
| 3162 | __ b(ne, &done); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3163 | __ bind(&check_sign_on_zero); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3164 | __ vmov(scratch, input.high()); |
| 3165 | __ tst(scratch, Operand(HeapNumber::kSignMask)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3166 | DeoptimizeIf(ne, instr->environment()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3167 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3168 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3172 | void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3173 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3174 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3175 | __ vsqrt(result, input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3179 | void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) { |
| 3180 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3181 | DoubleRegister result = ToDoubleRegister(instr->result()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3182 | DoubleRegister temp = ToDoubleRegister(instr->TempAt(0)); |
| 3183 | |
| 3184 | // Note that according to ECMA-262 15.8.2.13: |
| 3185 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3186 | // Math.sqrt(-Infinity) == NaN |
| 3187 | Label done; |
| 3188 | __ vmov(temp, -V8_INFINITY); |
| 3189 | __ VFPCompareAndSetFlags(input, temp); |
| 3190 | __ vneg(result, temp, eq); |
| 3191 | __ b(&done, eq); |
| 3192 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3193 | // Add +0 to convert -0 to +0. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3194 | __ vadd(result, input, kDoubleRegZero); |
| 3195 | __ vsqrt(result, result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3196 | __ bind(&done); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3200 | void LCodeGen::DoPower(LPower* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3201 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3202 | // Having marked this as a call, we can use any registers. |
| 3203 | // Just make sure that the input/output registers are the expected ones. |
| 3204 | ASSERT(!instr->InputAt(1)->IsDoubleRegister() || |
| 3205 | ToDoubleRegister(instr->InputAt(1)).is(d2)); |
| 3206 | ASSERT(!instr->InputAt(1)->IsRegister() || |
| 3207 | ToRegister(instr->InputAt(1)).is(r2)); |
| 3208 | ASSERT(ToDoubleRegister(instr->InputAt(0)).is(d1)); |
| 3209 | ASSERT(ToDoubleRegister(instr->result()).is(d3)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3210 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3211 | if (exponent_type.IsTagged()) { |
| 3212 | Label no_deopt; |
| 3213 | __ JumpIfSmi(r2, &no_deopt); |
| 3214 | __ ldr(r7, FieldMemOperand(r2, HeapObject::kMapOffset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3215 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3216 | __ cmp(r7, Operand(ip)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3217 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3218 | __ bind(&no_deopt); |
| 3219 | MathPowStub stub(MathPowStub::TAGGED); |
| 3220 | __ CallStub(&stub); |
| 3221 | } else if (exponent_type.IsInteger32()) { |
| 3222 | MathPowStub stub(MathPowStub::INTEGER); |
| 3223 | __ CallStub(&stub); |
| 3224 | } else { |
| 3225 | ASSERT(exponent_type.IsDouble()); |
| 3226 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3227 | __ CallStub(&stub); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3228 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3232 | void LCodeGen::DoRandom(LRandom* instr) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 3233 | class DeferredDoRandom: public LDeferredCode { |
| 3234 | public: |
| 3235 | DeferredDoRandom(LCodeGen* codegen, LRandom* instr) |
| 3236 | : LDeferredCode(codegen), instr_(instr) { } |
| 3237 | virtual void Generate() { codegen()->DoDeferredRandom(instr_); } |
| 3238 | virtual LInstruction* instr() { return instr_; } |
| 3239 | private: |
| 3240 | LRandom* instr_; |
| 3241 | }; |
| 3242 | |
| 3243 | DeferredDoRandom* deferred = new DeferredDoRandom(this, instr); |
| 3244 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3245 | // Having marked this instruction as a call we can use any |
| 3246 | // registers. |
| 3247 | ASSERT(ToDoubleRegister(instr->result()).is(d7)); |
| 3248 | ASSERT(ToRegister(instr->InputAt(0)).is(r0)); |
| 3249 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 3250 | static const int kSeedSize = sizeof(uint32_t); |
| 3251 | STATIC_ASSERT(kPointerSize == kSeedSize); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3252 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 3253 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kGlobalContextOffset)); |
| 3254 | static const int kRandomSeedOffset = |
| 3255 | FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3256 | __ ldr(r2, FieldMemOperand(r0, kRandomSeedOffset)); |
| 3257 | // r2: FixedArray of the global context's random seeds |
| 3258 | |
| 3259 | // Load state[0]. |
| 3260 | __ ldr(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); |
| 3261 | __ cmp(r1, Operand(0)); |
| 3262 | __ b(eq, deferred->entry()); |
| 3263 | // Load state[1]. |
| 3264 | __ ldr(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); |
| 3265 | // r1: state[0]. |
| 3266 | // r0: state[1]. |
| 3267 | |
| 3268 | // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3269 | __ and_(r3, r1, Operand(0xFFFF)); |
| 3270 | __ mov(r4, Operand(18273)); |
| 3271 | __ mul(r3, r3, r4); |
| 3272 | __ add(r1, r3, Operand(r1, LSR, 16)); |
| 3273 | // Save state[0]. |
| 3274 | __ str(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); |
| 3275 | |
| 3276 | // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3277 | __ and_(r3, r0, Operand(0xFFFF)); |
| 3278 | __ mov(r4, Operand(36969)); |
| 3279 | __ mul(r3, r3, r4); |
| 3280 | __ add(r0, r3, Operand(r0, LSR, 16)); |
| 3281 | // Save state[1]. |
| 3282 | __ str(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); |
| 3283 | |
| 3284 | // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3285 | __ and_(r0, r0, Operand(0x3FFFF)); |
| 3286 | __ add(r0, r0, Operand(r1, LSL, 14)); |
| 3287 | |
| 3288 | __ bind(deferred->exit()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3289 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 3290 | // Create this constant using mov/orr to avoid PC relative load. |
| 3291 | __ mov(r1, Operand(0x41000000)); |
| 3292 | __ orr(r1, r1, Operand(0x300000)); |
| 3293 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 3294 | __ vmov(d7, r0, r1); |
| 3295 | // Move 0x4130000000000000 to VFP. |
| 3296 | __ mov(r0, Operand(0, RelocInfo::NONE)); |
| 3297 | __ vmov(d8, r0, r1); |
| 3298 | // Subtract and store the result in the heap number. |
| 3299 | __ vsub(d7, d7, d8); |
| 3300 | } |
| 3301 | |
| 3302 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 3303 | void LCodeGen::DoDeferredRandom(LRandom* instr) { |
| 3304 | __ PrepareCallCFunction(1, scratch0()); |
| 3305 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
| 3306 | // Return value is in r0. |
| 3307 | } |
| 3308 | |
| 3309 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3310 | void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { |
| 3311 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 3312 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 3313 | TranscendentalCacheStub::UNTAGGED); |
| 3314 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3315 | } |
| 3316 | |
| 3317 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3318 | void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { |
| 3319 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 3320 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 3321 | TranscendentalCacheStub::UNTAGGED); |
| 3322 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3323 | } |
| 3324 | |
| 3325 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3326 | void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { |
| 3327 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 3328 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 3329 | TranscendentalCacheStub::UNTAGGED); |
| 3330 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3331 | } |
| 3332 | |
| 3333 | |
| 3334 | void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { |
| 3335 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 3336 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 3337 | TranscendentalCacheStub::UNTAGGED); |
| 3338 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3339 | } |
| 3340 | |
| 3341 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3342 | void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3343 | switch (instr->op()) { |
| 3344 | case kMathAbs: |
| 3345 | DoMathAbs(instr); |
| 3346 | break; |
| 3347 | case kMathFloor: |
| 3348 | DoMathFloor(instr); |
| 3349 | break; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3350 | case kMathRound: |
| 3351 | DoMathRound(instr); |
| 3352 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3353 | case kMathSqrt: |
| 3354 | DoMathSqrt(instr); |
| 3355 | break; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3356 | case kMathPowHalf: |
| 3357 | DoMathPowHalf(instr); |
| 3358 | break; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3359 | case kMathCos: |
| 3360 | DoMathCos(instr); |
| 3361 | break; |
| 3362 | case kMathSin: |
| 3363 | DoMathSin(instr); |
| 3364 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3365 | case kMathTan: |
| 3366 | DoMathTan(instr); |
| 3367 | break; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3368 | case kMathLog: |
| 3369 | DoMathLog(instr); |
| 3370 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3371 | default: |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3372 | Abort("Unimplemented type of LUnaryMathOperation."); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3373 | UNREACHABLE(); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3378 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 3379 | ASSERT(ToRegister(instr->function()).is(r1)); |
| 3380 | ASSERT(instr->HasPointerMap()); |
| 3381 | ASSERT(instr->HasDeoptimizationEnvironment()); |
| 3382 | LPointerMap* pointers = instr->pointer_map(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3383 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3384 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3385 | ParameterCount count(instr->arity()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3386 | __ InvokeFunction(r1, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3387 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3388 | } |
| 3389 | |
| 3390 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3391 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3392 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3393 | |
| 3394 | int arity = instr->arity(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3395 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3396 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3397 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3398 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | |
| 3402 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
| 3403 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3404 | |
| 3405 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3406 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 3407 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3408 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3409 | __ mov(r2, Operand(instr->name())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3410 | CallCode(ic, mode, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3411 | // Restore context register. |
| 3412 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3417 | ASSERT(ToRegister(instr->function()).is(r1)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3418 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3419 | |
| 3420 | int arity = instr->arity(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3421 | CallFunctionStub stub(arity, NO_CALL_FUNCTION_FLAGS); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3422 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3423 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | |
| 3427 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3428 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3429 | |
| 3430 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3431 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3432 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3433 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3434 | __ mov(r2, Operand(instr->name())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3435 | CallCode(ic, mode, instr); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3436 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | |
| 3440 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 3441 | ASSERT(ToRegister(instr->result()).is(r0)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3442 | CallKnownFunction(instr->target(), instr->arity(), instr, CALL_AS_FUNCTION); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | |
| 3446 | void LCodeGen::DoCallNew(LCallNew* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3447 | ASSERT(ToRegister(instr->InputAt(0)).is(r1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3448 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3449 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3450 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3451 | __ mov(r0, Operand(instr->arity())); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3452 | CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | |
| 3456 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 3457 | CallRuntime(instr->function(), instr->arity(), instr); |
| 3458 | } |
| 3459 | |
| 3460 | |
| 3461 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3462 | Register object = ToRegister(instr->object()); |
| 3463 | Register value = ToRegister(instr->value()); |
| 3464 | Register scratch = scratch0(); |
| 3465 | int offset = instr->offset(); |
| 3466 | |
| 3467 | ASSERT(!object.is(value)); |
| 3468 | |
| 3469 | if (!instr->transition().is_null()) { |
| 3470 | __ mov(scratch, Operand(instr->transition())); |
| 3471 | __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3472 | } |
| 3473 | |
| 3474 | // Do the store. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3475 | HType type = instr->hydrogen()->value()->type(); |
| 3476 | SmiCheck check_needed = |
| 3477 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3478 | if (instr->is_in_object()) { |
| 3479 | __ str(value, FieldMemOperand(object, offset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3480 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3481 | // Update the write barrier for the object for in-object properties. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3482 | __ RecordWriteField(object, |
| 3483 | offset, |
| 3484 | value, |
| 3485 | scratch, |
| 3486 | kLRHasBeenSaved, |
| 3487 | kSaveFPRegs, |
| 3488 | EMIT_REMEMBERED_SET, |
| 3489 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3490 | } |
| 3491 | } else { |
| 3492 | __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3493 | __ str(value, FieldMemOperand(scratch, offset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3494 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3495 | // Update the write barrier for the properties array. |
| 3496 | // object is used as a scratch register. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3497 | __ RecordWriteField(scratch, |
| 3498 | offset, |
| 3499 | value, |
| 3500 | object, |
| 3501 | kLRHasBeenSaved, |
| 3502 | kSaveFPRegs, |
| 3503 | EMIT_REMEMBERED_SET, |
| 3504 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3505 | } |
| 3506 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
| 3510 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 3511 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 3512 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 3513 | |
| 3514 | // Name is always in r2. |
| 3515 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3516 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3517 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3518 | : isolate()->builtins()->StoreIC_Initialize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3519 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3520 | } |
| 3521 | |
| 3522 | |
| 3523 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3524 | __ cmp(ToRegister(instr->index()), ToRegister(instr->length())); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3525 | DeoptimizeIf(hs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | |
| 3529 | void LCodeGen::DoStoreKeyedFastElement(LStoreKeyedFastElement* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3530 | Register value = ToRegister(instr->value()); |
| 3531 | Register elements = ToRegister(instr->object()); |
| 3532 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 3533 | Register scratch = scratch0(); |
| 3534 | |
| 3535 | // Do the store. |
| 3536 | if (instr->key()->IsConstantOperand()) { |
| 3537 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 3538 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3539 | int offset = |
| 3540 | ToInteger32(const_operand) * kPointerSize + FixedArray::kHeaderSize; |
| 3541 | __ str(value, FieldMemOperand(elements, offset)); |
| 3542 | } else { |
| 3543 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 3544 | __ str(value, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 3545 | } |
| 3546 | |
| 3547 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3548 | HType type = instr->hydrogen()->value()->type(); |
| 3549 | SmiCheck check_needed = |
| 3550 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3551 | // Compute address of modified element and store it into key register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3552 | __ add(key, scratch, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3553 | __ RecordWrite(elements, |
| 3554 | key, |
| 3555 | value, |
| 3556 | kLRHasBeenSaved, |
| 3557 | kSaveFPRegs, |
| 3558 | EMIT_REMEMBERED_SET, |
| 3559 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3560 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3564 | void LCodeGen::DoStoreKeyedFastDoubleElement( |
| 3565 | LStoreKeyedFastDoubleElement* instr) { |
| 3566 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 3567 | Register elements = ToRegister(instr->elements()); |
| 3568 | Register key = no_reg; |
| 3569 | Register scratch = scratch0(); |
| 3570 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3571 | int constant_key = 0; |
| 3572 | Label not_nan; |
| 3573 | |
| 3574 | // Calculate the effective address of the slot in the array to store the |
| 3575 | // double value. |
| 3576 | if (key_is_constant) { |
| 3577 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3578 | if (constant_key & 0xF0000000) { |
| 3579 | Abort("array index constant value too big."); |
| 3580 | } |
| 3581 | } else { |
| 3582 | key = ToRegister(instr->key()); |
| 3583 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3584 | int shift_size = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3585 | Operand operand = key_is_constant |
| 3586 | ? Operand(constant_key * (1 << shift_size) + |
| 3587 | FixedDoubleArray::kHeaderSize - kHeapObjectTag) |
| 3588 | : Operand(key, LSL, shift_size); |
| 3589 | __ add(scratch, elements, operand); |
| 3590 | if (!key_is_constant) { |
| 3591 | __ add(scratch, scratch, |
| 3592 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
| 3593 | } |
| 3594 | |
| 3595 | // Check for NaN. All NaNs must be canonicalized. |
| 3596 | __ VFPCompareAndSetFlags(value, value); |
| 3597 | |
| 3598 | // Only load canonical NaN if the comparison above set the overflow. |
| 3599 | __ Vmov(value, FixedDoubleArray::canonical_not_the_hole_nan_as_double(), vs); |
| 3600 | |
| 3601 | __ bind(¬_nan); |
| 3602 | __ vstr(value, scratch, 0); |
| 3603 | } |
| 3604 | |
| 3605 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3606 | void LCodeGen::DoStoreKeyedSpecializedArrayElement( |
| 3607 | LStoreKeyedSpecializedArrayElement* instr) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3608 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3609 | Register external_pointer = ToRegister(instr->external_pointer()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3610 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3611 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3612 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3613 | int constant_key = 0; |
| 3614 | if (key_is_constant) { |
| 3615 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3616 | if (constant_key & 0xF0000000) { |
| 3617 | Abort("array index constant value too big."); |
| 3618 | } |
| 3619 | } else { |
| 3620 | key = ToRegister(instr->key()); |
| 3621 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3622 | int shift_size = ElementsKindToShiftSize(elements_kind); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3623 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3624 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 3625 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 3626 | CpuFeatures::Scope scope(VFP3); |
| 3627 | DwVfpRegister value(ToDoubleRegister(instr->value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3628 | Operand operand(key_is_constant ? Operand(constant_key * (1 << shift_size)) |
| 3629 | : Operand(key, LSL, shift_size)); |
| 3630 | __ add(scratch0(), external_pointer, operand); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3631 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3632 | __ vcvt_f32_f64(double_scratch0().low(), value); |
| 3633 | __ vstr(double_scratch0().low(), scratch0(), 0); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3634 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3635 | __ vstr(value, scratch0(), 0); |
| 3636 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3637 | } else { |
| 3638 | Register value(ToRegister(instr->value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3639 | MemOperand mem_operand(key_is_constant |
| 3640 | ? MemOperand(external_pointer, constant_key * (1 << shift_size)) |
| 3641 | : MemOperand(external_pointer, key, LSL, shift_size)); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3642 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3643 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3644 | case EXTERNAL_BYTE_ELEMENTS: |
| 3645 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3646 | __ strb(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3647 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3648 | case EXTERNAL_SHORT_ELEMENTS: |
| 3649 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3650 | __ strh(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3651 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3652 | case EXTERNAL_INT_ELEMENTS: |
| 3653 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3654 | __ str(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3655 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3656 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3657 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 3658 | case FAST_DOUBLE_ELEMENTS: |
| 3659 | case FAST_ELEMENTS: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3660 | case FAST_SMI_ONLY_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3661 | case DICTIONARY_ELEMENTS: |
| 3662 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3663 | UNREACHABLE(); |
| 3664 | break; |
| 3665 | } |
| 3666 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3670 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 3671 | ASSERT(ToRegister(instr->object()).is(r2)); |
| 3672 | ASSERT(ToRegister(instr->key()).is(r1)); |
| 3673 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 3674 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3675 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3676 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 3677 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3678 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3679 | } |
| 3680 | |
| 3681 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3682 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 3683 | Register object_reg = ToRegister(instr->object()); |
| 3684 | Register new_map_reg = ToRegister(instr->new_map_reg()); |
| 3685 | Register scratch = scratch0(); |
| 3686 | |
| 3687 | Handle<Map> from_map = instr->original_map(); |
| 3688 | Handle<Map> to_map = instr->transitioned_map(); |
| 3689 | ElementsKind from_kind = from_map->elements_kind(); |
| 3690 | ElementsKind to_kind = to_map->elements_kind(); |
| 3691 | |
| 3692 | Label not_applicable; |
| 3693 | __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 3694 | __ cmp(scratch, Operand(from_map)); |
| 3695 | __ b(ne, ¬_applicable); |
| 3696 | __ mov(new_map_reg, Operand(to_map)); |
| 3697 | if (from_kind == FAST_SMI_ONLY_ELEMENTS && to_kind == FAST_ELEMENTS) { |
| 3698 | __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 3699 | // Write barrier. |
| 3700 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
| 3701 | scratch, kLRHasBeenSaved, kDontSaveFPRegs); |
| 3702 | } else if (from_kind == FAST_SMI_ONLY_ELEMENTS && |
| 3703 | to_kind == FAST_DOUBLE_ELEMENTS) { |
| 3704 | Register fixed_object_reg = ToRegister(instr->temp_reg()); |
| 3705 | ASSERT(fixed_object_reg.is(r2)); |
| 3706 | ASSERT(new_map_reg.is(r3)); |
| 3707 | __ mov(fixed_object_reg, object_reg); |
| 3708 | CallCode(isolate()->builtins()->TransitionElementsSmiToDouble(), |
| 3709 | RelocInfo::CODE_TARGET, instr); |
| 3710 | } else if (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS) { |
| 3711 | Register fixed_object_reg = ToRegister(instr->temp_reg()); |
| 3712 | ASSERT(fixed_object_reg.is(r2)); |
| 3713 | ASSERT(new_map_reg.is(r3)); |
| 3714 | __ mov(fixed_object_reg, object_reg); |
| 3715 | CallCode(isolate()->builtins()->TransitionElementsDoubleToObject(), |
| 3716 | RelocInfo::CODE_TARGET, instr); |
| 3717 | } else { |
| 3718 | UNREACHABLE(); |
| 3719 | } |
| 3720 | __ bind(¬_applicable); |
| 3721 | } |
| 3722 | |
| 3723 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3724 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
| 3725 | __ push(ToRegister(instr->left())); |
| 3726 | __ push(ToRegister(instr->right())); |
| 3727 | StringAddStub stub(NO_STRING_CHECK_IN_STUB); |
| 3728 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3729 | } |
| 3730 | |
| 3731 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3732 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3733 | class DeferredStringCharCodeAt: public LDeferredCode { |
| 3734 | public: |
| 3735 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 3736 | : LDeferredCode(codegen), instr_(instr) { } |
| 3737 | virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3738 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3739 | private: |
| 3740 | LStringCharCodeAt* instr_; |
| 3741 | }; |
| 3742 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3743 | DeferredStringCharCodeAt* deferred = |
| 3744 | new DeferredStringCharCodeAt(this, instr); |
| 3745 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3746 | StringCharLoadGenerator::Generate(masm(), |
| 3747 | ToRegister(instr->string()), |
| 3748 | ToRegister(instr->index()), |
| 3749 | ToRegister(instr->result()), |
| 3750 | deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3751 | __ bind(deferred->exit()); |
| 3752 | } |
| 3753 | |
| 3754 | |
| 3755 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3756 | Register string = ToRegister(instr->string()); |
| 3757 | Register result = ToRegister(instr->result()); |
| 3758 | Register scratch = scratch0(); |
| 3759 | |
| 3760 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3761 | // result register contain a valid pointer because it is already |
| 3762 | // contained in the register pointer map. |
| 3763 | __ mov(result, Operand(0)); |
| 3764 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3765 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3766 | __ push(string); |
| 3767 | // Push the index as a smi. This is safe because of the checks in |
| 3768 | // DoStringCharCodeAt above. |
| 3769 | if (instr->index()->IsConstantOperand()) { |
| 3770 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3771 | __ mov(scratch, Operand(Smi::FromInt(const_index))); |
| 3772 | __ push(scratch); |
| 3773 | } else { |
| 3774 | Register index = ToRegister(instr->index()); |
| 3775 | __ SmiTag(index); |
| 3776 | __ push(index); |
| 3777 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3778 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3779 | if (FLAG_debug_code) { |
| 3780 | __ AbortIfNotSmi(r0); |
| 3781 | } |
| 3782 | __ SmiUntag(r0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3783 | __ StoreToSafepointRegisterSlot(r0, result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3787 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 3788 | class DeferredStringCharFromCode: public LDeferredCode { |
| 3789 | public: |
| 3790 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 3791 | : LDeferredCode(codegen), instr_(instr) { } |
| 3792 | virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3793 | virtual LInstruction* instr() { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3794 | private: |
| 3795 | LStringCharFromCode* instr_; |
| 3796 | }; |
| 3797 | |
| 3798 | DeferredStringCharFromCode* deferred = |
| 3799 | new DeferredStringCharFromCode(this, instr); |
| 3800 | |
| 3801 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 3802 | Register char_code = ToRegister(instr->char_code()); |
| 3803 | Register result = ToRegister(instr->result()); |
| 3804 | ASSERT(!char_code.is(result)); |
| 3805 | |
| 3806 | __ cmp(char_code, Operand(String::kMaxAsciiCharCode)); |
| 3807 | __ b(hi, deferred->entry()); |
| 3808 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 3809 | __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); |
| 3810 | __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 3811 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3812 | __ cmp(result, ip); |
| 3813 | __ b(eq, deferred->entry()); |
| 3814 | __ bind(deferred->exit()); |
| 3815 | } |
| 3816 | |
| 3817 | |
| 3818 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 3819 | Register char_code = ToRegister(instr->char_code()); |
| 3820 | Register result = ToRegister(instr->result()); |
| 3821 | |
| 3822 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3823 | // result register contain a valid pointer because it is already |
| 3824 | // contained in the register pointer map. |
| 3825 | __ mov(result, Operand(0)); |
| 3826 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3827 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3828 | __ SmiTag(char_code); |
| 3829 | __ push(char_code); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3830 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3831 | __ StoreToSafepointRegisterSlot(r0, result); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3835 | void LCodeGen::DoStringLength(LStringLength* instr) { |
| 3836 | Register string = ToRegister(instr->InputAt(0)); |
| 3837 | Register result = ToRegister(instr->result()); |
| 3838 | __ ldr(result, FieldMemOperand(string, String::kLengthOffset)); |
| 3839 | } |
| 3840 | |
| 3841 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3842 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3843 | LOperand* input = instr->InputAt(0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3844 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 3845 | LOperand* output = instr->result(); |
| 3846 | ASSERT(output->IsDoubleRegister()); |
| 3847 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 3848 | if (input->IsStackSlot()) { |
| 3849 | Register scratch = scratch0(); |
| 3850 | __ ldr(scratch, ToMemOperand(input)); |
| 3851 | __ vmov(single_scratch, scratch); |
| 3852 | } else { |
| 3853 | __ vmov(single_scratch, ToRegister(input)); |
| 3854 | } |
| 3855 | __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | |
| 3859 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 3860 | class DeferredNumberTagI: public LDeferredCode { |
| 3861 | public: |
| 3862 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 3863 | : LDeferredCode(codegen), instr_(instr) { } |
| 3864 | virtual void Generate() { codegen()->DoDeferredNumberTagI(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3865 | virtual LInstruction* instr() { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3866 | private: |
| 3867 | LNumberTagI* instr_; |
| 3868 | }; |
| 3869 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3870 | Register src = ToRegister(instr->InputAt(0)); |
| 3871 | Register dst = ToRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3872 | |
| 3873 | DeferredNumberTagI* deferred = new DeferredNumberTagI(this, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3874 | __ SmiTag(dst, src, SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3875 | __ b(vs, deferred->entry()); |
| 3876 | __ bind(deferred->exit()); |
| 3877 | } |
| 3878 | |
| 3879 | |
| 3880 | void LCodeGen::DoDeferredNumberTagI(LNumberTagI* instr) { |
| 3881 | Label slow; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3882 | Register src = ToRegister(instr->InputAt(0)); |
| 3883 | Register dst = ToRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3884 | DoubleRegister dbl_scratch = double_scratch0(); |
| 3885 | SwVfpRegister flt_scratch = dbl_scratch.low(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3886 | |
| 3887 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3888 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3889 | |
| 3890 | // There was overflow, so bits 30 and 31 of the original integer |
| 3891 | // disagree. Try to allocate a heap number in new space and store |
| 3892 | // the value in there. If that fails, call the runtime system. |
| 3893 | Label done; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3894 | if (dst.is(src)) { |
| 3895 | __ SmiUntag(src, dst); |
| 3896 | __ eor(src, src, Operand(0x80000000)); |
| 3897 | } |
| 3898 | __ vmov(flt_scratch, src); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3899 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 3900 | if (FLAG_inline_new) { |
| 3901 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 3902 | __ AllocateHeapNumber(r5, r3, r4, r6, &slow); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3903 | __ Move(dst, r5); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3904 | __ b(&done); |
| 3905 | } |
| 3906 | |
| 3907 | // Slow case: Call the runtime system to do the number allocation. |
| 3908 | __ bind(&slow); |
| 3909 | |
| 3910 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 3911 | // register is stored, as this register is in the pointer map, but contains an |
| 3912 | // integer value. |
| 3913 | __ mov(ip, Operand(0)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3914 | __ StoreToSafepointRegisterSlot(ip, dst); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3915 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3916 | __ Move(dst, r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3917 | |
| 3918 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 3919 | // number. |
| 3920 | __ bind(&done); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3921 | __ sub(ip, dst, Operand(kHeapObjectTag)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3922 | __ vstr(dbl_scratch, ip, HeapNumber::kValueOffset); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3923 | __ StoreToSafepointRegisterSlot(dst, dst); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | |
| 3927 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 3928 | class DeferredNumberTagD: public LDeferredCode { |
| 3929 | public: |
| 3930 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 3931 | : LDeferredCode(codegen), instr_(instr) { } |
| 3932 | virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3933 | virtual LInstruction* instr() { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3934 | private: |
| 3935 | LNumberTagD* instr_; |
| 3936 | }; |
| 3937 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3938 | DoubleRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3939 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3940 | Register reg = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3941 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 3942 | Register temp2 = ToRegister(instr->TempAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3943 | |
| 3944 | DeferredNumberTagD* deferred = new DeferredNumberTagD(this, instr); |
| 3945 | if (FLAG_inline_new) { |
| 3946 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3947 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3948 | } else { |
| 3949 | __ jmp(deferred->entry()); |
| 3950 | } |
| 3951 | __ bind(deferred->exit()); |
| 3952 | __ sub(ip, reg, Operand(kHeapObjectTag)); |
| 3953 | __ vstr(input_reg, ip, HeapNumber::kValueOffset); |
| 3954 | } |
| 3955 | |
| 3956 | |
| 3957 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 3958 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3959 | // result register contain a valid pointer because it is already |
| 3960 | // contained in the register pointer map. |
| 3961 | Register reg = ToRegister(instr->result()); |
| 3962 | __ mov(reg, Operand(0)); |
| 3963 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3964 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 3965 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3966 | __ StoreToSafepointRegisterSlot(r0, reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | |
| 3970 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3971 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3972 | __ SmiTag(ToRegister(instr->result()), ToRegister(instr->InputAt(0))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | |
| 3976 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3977 | Register input = ToRegister(instr->InputAt(0)); |
| 3978 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3979 | if (instr->needs_check()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3980 | STATIC_ASSERT(kHeapObjectTag == 1); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 3981 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3982 | __ SmiUntag(result, input, SetCC); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 3983 | DeoptimizeIf(cs, instr->environment()); |
| 3984 | } else { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3985 | __ SmiUntag(result, input); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3986 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | |
| 3990 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 3991 | DoubleRegister result_reg, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3992 | bool deoptimize_on_undefined, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3993 | bool deoptimize_on_minus_zero, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3994 | LEnvironment* env) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3995 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3996 | SwVfpRegister flt_scratch = double_scratch0().low(); |
| 3997 | ASSERT(!result_reg.is(double_scratch0())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3998 | |
| 3999 | Label load_smi, heap_number, done; |
| 4000 | |
| 4001 | // Smi check. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4002 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4003 | |
| 4004 | // Heap number map check. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4005 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4006 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4007 | __ cmp(scratch, Operand(ip)); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4008 | if (deoptimize_on_undefined) { |
| 4009 | DeoptimizeIf(ne, env); |
| 4010 | } else { |
| 4011 | Label heap_number; |
| 4012 | __ b(eq, &heap_number); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4013 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4014 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4015 | __ cmp(input_reg, Operand(ip)); |
| 4016 | DeoptimizeIf(ne, env); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4017 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4018 | // Convert undefined to NaN. |
| 4019 | __ LoadRoot(ip, Heap::kNanValueRootIndex); |
| 4020 | __ sub(ip, ip, Operand(kHeapObjectTag)); |
| 4021 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
| 4022 | __ jmp(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4023 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4024 | __ bind(&heap_number); |
| 4025 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4026 | // Heap number to double register conversion. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4027 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
| 4028 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4029 | if (deoptimize_on_minus_zero) { |
| 4030 | __ vmov(ip, result_reg.low()); |
| 4031 | __ cmp(ip, Operand(0)); |
| 4032 | __ b(ne, &done); |
| 4033 | __ vmov(ip, result_reg.high()); |
| 4034 | __ cmp(ip, Operand(HeapNumber::kSignMask)); |
| 4035 | DeoptimizeIf(eq, env); |
| 4036 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4037 | __ jmp(&done); |
| 4038 | |
| 4039 | // Smi to double register conversion |
| 4040 | __ bind(&load_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4041 | // scratch: untagged value of input_reg |
| 4042 | __ vmov(flt_scratch, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4043 | __ vcvt_f64_s32(result_reg, flt_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4044 | __ bind(&done); |
| 4045 | } |
| 4046 | |
| 4047 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4048 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4049 | Register input_reg = ToRegister(instr->InputAt(0)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4050 | Register scratch1 = scratch0(); |
| 4051 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 4052 | DwVfpRegister double_scratch = double_scratch0(); |
| 4053 | SwVfpRegister single_scratch = double_scratch.low(); |
| 4054 | |
| 4055 | ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4056 | ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4057 | |
| 4058 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4059 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4060 | // The input was optimistically untagged; revert it. |
| 4061 | // The carry flag is set when we reach this deferred code as we just executed |
| 4062 | // SmiUntag(heap_object, SetCC) |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4063 | STATIC_ASSERT(kHeapObjectTag == 1); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4064 | __ adc(input_reg, input_reg, Operand(input_reg)); |
| 4065 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4066 | // Heap number map check. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4067 | __ ldr(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4068 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4069 | __ cmp(scratch1, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4070 | |
| 4071 | if (instr->truncating()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4072 | Register scratch3 = ToRegister(instr->TempAt(1)); |
| 4073 | DwVfpRegister double_scratch2 = ToDoubleRegister(instr->TempAt(2)); |
| 4074 | ASSERT(!scratch3.is(input_reg) && |
| 4075 | !scratch3.is(scratch1) && |
| 4076 | !scratch3.is(scratch2)); |
| 4077 | // Performs a truncating conversion of a floating point number as used by |
| 4078 | // the JS bitwise operations. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4079 | Label heap_number; |
| 4080 | __ b(eq, &heap_number); |
| 4081 | // Check for undefined. Undefined is converted to zero for truncating |
| 4082 | // conversions. |
| 4083 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4084 | __ cmp(input_reg, Operand(ip)); |
| 4085 | DeoptimizeIf(ne, instr->environment()); |
| 4086 | __ mov(input_reg, Operand(0)); |
| 4087 | __ b(&done); |
| 4088 | |
| 4089 | __ bind(&heap_number); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4090 | __ sub(scratch1, input_reg, Operand(kHeapObjectTag)); |
| 4091 | __ vldr(double_scratch2, scratch1, HeapNumber::kValueOffset); |
| 4092 | |
| 4093 | __ EmitECMATruncate(input_reg, |
| 4094 | double_scratch2, |
| 4095 | single_scratch, |
| 4096 | scratch1, |
| 4097 | scratch2, |
| 4098 | scratch3); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4099 | |
| 4100 | } else { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4101 | CpuFeatures::Scope scope(VFP3); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4102 | // Deoptimize if we don't have a heap number. |
| 4103 | DeoptimizeIf(ne, instr->environment()); |
| 4104 | |
| 4105 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4106 | __ vldr(double_scratch, ip, HeapNumber::kValueOffset); |
| 4107 | __ EmitVFPTruncate(kRoundToZero, |
| 4108 | single_scratch, |
| 4109 | double_scratch, |
| 4110 | scratch1, |
| 4111 | scratch2, |
| 4112 | kCheckForInexactConversion); |
| 4113 | DeoptimizeIf(ne, instr->environment()); |
| 4114 | // Load the result. |
| 4115 | __ vmov(input_reg, single_scratch); |
| 4116 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4117 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4118 | __ cmp(input_reg, Operand(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4119 | __ b(ne, &done); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4120 | __ vmov(scratch1, double_scratch.high()); |
| 4121 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4122 | DeoptimizeIf(ne, instr->environment()); |
| 4123 | } |
| 4124 | } |
| 4125 | __ bind(&done); |
| 4126 | } |
| 4127 | |
| 4128 | |
| 4129 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4130 | class DeferredTaggedToI: public LDeferredCode { |
| 4131 | public: |
| 4132 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4133 | : LDeferredCode(codegen), instr_(instr) { } |
| 4134 | virtual void Generate() { codegen()->DoDeferredTaggedToI(instr_); } |
| 4135 | virtual LInstruction* instr() { return instr_; } |
| 4136 | private: |
| 4137 | LTaggedToI* instr_; |
| 4138 | }; |
| 4139 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4140 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4141 | ASSERT(input->IsRegister()); |
| 4142 | ASSERT(input->Equals(instr->result())); |
| 4143 | |
| 4144 | Register input_reg = ToRegister(input); |
| 4145 | |
| 4146 | DeferredTaggedToI* deferred = new DeferredTaggedToI(this, instr); |
| 4147 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4148 | // Optimistically untag the input. |
| 4149 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
| 4150 | __ SmiUntag(input_reg, SetCC); |
| 4151 | // Branch to deferred code if the input was tagged. |
| 4152 | // The deferred code will take care of restoring the tag. |
| 4153 | __ b(cs, deferred->entry()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4154 | __ bind(deferred->exit()); |
| 4155 | } |
| 4156 | |
| 4157 | |
| 4158 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4159 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4160 | ASSERT(input->IsRegister()); |
| 4161 | LOperand* result = instr->result(); |
| 4162 | ASSERT(result->IsDoubleRegister()); |
| 4163 | |
| 4164 | Register input_reg = ToRegister(input); |
| 4165 | DoubleRegister result_reg = ToDoubleRegister(result); |
| 4166 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4167 | EmitNumberUntagD(input_reg, result_reg, |
| 4168 | instr->hydrogen()->deoptimize_on_undefined(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4169 | instr->hydrogen()->deoptimize_on_minus_zero(), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4170 | instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | |
| 4174 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4175 | Register result_reg = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4176 | Register scratch1 = scratch0(); |
| 4177 | Register scratch2 = ToRegister(instr->TempAt(0)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4178 | DwVfpRegister double_input = ToDoubleRegister(instr->InputAt(0)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4179 | SwVfpRegister single_scratch = double_scratch0().low(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4180 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4181 | Label done; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 4182 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4183 | if (instr->truncating()) { |
| 4184 | Register scratch3 = ToRegister(instr->TempAt(1)); |
| 4185 | __ EmitECMATruncate(result_reg, |
| 4186 | double_input, |
| 4187 | single_scratch, |
| 4188 | scratch1, |
| 4189 | scratch2, |
| 4190 | scratch3); |
| 4191 | } else { |
| 4192 | VFPRoundingMode rounding_mode = kRoundToMinusInf; |
| 4193 | __ EmitVFPTruncate(rounding_mode, |
| 4194 | single_scratch, |
| 4195 | double_input, |
| 4196 | scratch1, |
| 4197 | scratch2, |
| 4198 | kCheckForInexactConversion); |
| 4199 | // Deoptimize if we had a vfp invalid exception, |
| 4200 | // including inexact operation. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4201 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4202 | // Retrieve the result. |
| 4203 | __ vmov(result_reg, single_scratch); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4204 | } |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4205 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | |
| 4209 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4210 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4211 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4212 | DeoptimizeIf(ne, instr->environment()); |
| 4213 | } |
| 4214 | |
| 4215 | |
| 4216 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
| 4217 | LOperand* input = instr->InputAt(0); |
| 4218 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
| 4219 | DeoptimizeIf(eq, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | |
| 4223 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4224 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4225 | Register scratch = scratch0(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4226 | |
| 4227 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 4228 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4229 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4230 | if (instr->hydrogen()->is_interval_check()) { |
| 4231 | InstanceType first; |
| 4232 | InstanceType last; |
| 4233 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 4234 | |
| 4235 | __ cmp(scratch, Operand(first)); |
| 4236 | |
| 4237 | // If there is only one type in the interval check for equality. |
| 4238 | if (first == last) { |
| 4239 | DeoptimizeIf(ne, instr->environment()); |
| 4240 | } else { |
| 4241 | DeoptimizeIf(lo, instr->environment()); |
| 4242 | // Omit check for the last type. |
| 4243 | if (last != LAST_TYPE) { |
| 4244 | __ cmp(scratch, Operand(last)); |
| 4245 | DeoptimizeIf(hi, instr->environment()); |
| 4246 | } |
| 4247 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4248 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4249 | uint8_t mask; |
| 4250 | uint8_t tag; |
| 4251 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 4252 | |
| 4253 | if (IsPowerOf2(mask)) { |
| 4254 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 4255 | __ tst(scratch, Operand(mask)); |
| 4256 | DeoptimizeIf(tag == 0 ? ne : eq, instr->environment()); |
| 4257 | } else { |
| 4258 | __ and_(scratch, scratch, Operand(mask)); |
| 4259 | __ cmp(scratch, Operand(tag)); |
| 4260 | DeoptimizeIf(ne, instr->environment()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4261 | } |
| 4262 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | |
| 4266 | void LCodeGen::DoCheckFunction(LCheckFunction* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4267 | Register reg = ToRegister(instr->value()); |
| 4268 | Handle<JSFunction> target = instr->hydrogen()->target(); |
| 4269 | if (isolate()->heap()->InNewSpace(*target)) { |
| 4270 | Register reg = ToRegister(instr->value()); |
| 4271 | Handle<JSGlobalPropertyCell> cell = |
| 4272 | isolate()->factory()->NewJSGlobalPropertyCell(target); |
| 4273 | __ mov(ip, Operand(Handle<Object>(cell))); |
| 4274 | __ ldr(ip, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
| 4275 | __ cmp(reg, ip); |
| 4276 | } else { |
| 4277 | __ cmp(reg, Operand(target)); |
| 4278 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4279 | DeoptimizeIf(ne, instr->environment()); |
| 4280 | } |
| 4281 | |
| 4282 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4283 | void LCodeGen::DoCheckMapCommon(Register reg, |
| 4284 | Register scratch, |
| 4285 | Handle<Map> map, |
| 4286 | CompareMapMode mode, |
| 4287 | LEnvironment* env) { |
| 4288 | Label success; |
| 4289 | __ CompareMap(reg, scratch, map, &success, mode); |
| 4290 | DeoptimizeIf(ne, env); |
| 4291 | __ bind(&success); |
| 4292 | } |
| 4293 | |
| 4294 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4295 | void LCodeGen::DoCheckMap(LCheckMap* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4296 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4297 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4298 | ASSERT(input->IsRegister()); |
| 4299 | Register reg = ToRegister(input); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4300 | Handle<Map> map = instr->hydrogen()->map(); |
| 4301 | DoCheckMapCommon(reg, scratch, map, instr->hydrogen()->mode(), |
| 4302 | instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4306 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 4307 | DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
| 4308 | Register result_reg = ToRegister(instr->result()); |
| 4309 | DoubleRegister temp_reg = ToDoubleRegister(instr->TempAt(0)); |
| 4310 | __ ClampDoubleToUint8(result_reg, value_reg, temp_reg); |
| 4311 | } |
| 4312 | |
| 4313 | |
| 4314 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 4315 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 4316 | Register result_reg = ToRegister(instr->result()); |
| 4317 | __ ClampUint8(result_reg, unclamped_reg); |
| 4318 | } |
| 4319 | |
| 4320 | |
| 4321 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 4322 | Register scratch = scratch0(); |
| 4323 | Register input_reg = ToRegister(instr->unclamped()); |
| 4324 | Register result_reg = ToRegister(instr->result()); |
| 4325 | DoubleRegister temp_reg = ToDoubleRegister(instr->TempAt(0)); |
| 4326 | Label is_smi, done, heap_number; |
| 4327 | |
| 4328 | // Both smi and heap number cases are handled. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4329 | __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4330 | |
| 4331 | // Check for heap number |
| 4332 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4333 | __ cmp(scratch, Operand(factory()->heap_number_map())); |
| 4334 | __ b(eq, &heap_number); |
| 4335 | |
| 4336 | // Check for undefined. Undefined is converted to zero for clamping |
| 4337 | // conversions. |
| 4338 | __ cmp(input_reg, Operand(factory()->undefined_value())); |
| 4339 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4340 | __ mov(result_reg, Operand(0)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4341 | __ jmp(&done); |
| 4342 | |
| 4343 | // Heap number |
| 4344 | __ bind(&heap_number); |
| 4345 | __ vldr(double_scratch0(), FieldMemOperand(input_reg, |
| 4346 | HeapNumber::kValueOffset)); |
| 4347 | __ ClampDoubleToUint8(result_reg, double_scratch0(), temp_reg); |
| 4348 | __ jmp(&done); |
| 4349 | |
| 4350 | // smi |
| 4351 | __ bind(&is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4352 | __ ClampUint8(result_reg, result_reg); |
| 4353 | |
| 4354 | __ bind(&done); |
| 4355 | } |
| 4356 | |
| 4357 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4358 | void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4359 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 4360 | Register temp2 = ToRegister(instr->TempAt(1)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4361 | |
| 4362 | Handle<JSObject> holder = instr->holder(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4363 | Handle<JSObject> current_prototype = instr->prototype(); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4364 | |
| 4365 | // Load prototype object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4366 | __ LoadHeapObject(temp1, current_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4367 | |
| 4368 | // Check prototype maps up to the holder. |
| 4369 | while (!current_prototype.is_identical_to(holder)) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4370 | DoCheckMapCommon(temp1, temp2, |
| 4371 | Handle<Map>(current_prototype->map()), |
| 4372 | ALLOW_ELEMENT_TRANSITION_MAPS, instr->environment()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4373 | current_prototype = |
| 4374 | Handle<JSObject>(JSObject::cast(current_prototype->GetPrototype())); |
| 4375 | // Load next prototype object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4376 | __ LoadHeapObject(temp1, current_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | // Check the holder map. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4380 | DoCheckMapCommon(temp1, temp2, |
| 4381 | Handle<Map>(current_prototype->map()), |
| 4382 | ALLOW_ELEMENT_TRANSITION_MAPS, instr->environment()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4383 | DeoptimizeIf(ne, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4387 | void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
| 4388 | class DeferredAllocateObject: public LDeferredCode { |
| 4389 | public: |
| 4390 | DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 4391 | : LDeferredCode(codegen), instr_(instr) { } |
| 4392 | virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 4393 | virtual LInstruction* instr() { return instr_; } |
| 4394 | private: |
| 4395 | LAllocateObject* instr_; |
| 4396 | }; |
| 4397 | |
| 4398 | DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); |
| 4399 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 4400 | Register result = ToRegister(instr->result()); |
| 4401 | Register scratch = ToRegister(instr->TempAt(0)); |
| 4402 | Register scratch2 = ToRegister(instr->TempAt(1)); |
| 4403 | Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 4404 | Handle<Map> initial_map(constructor->initial_map()); |
| 4405 | int instance_size = initial_map->instance_size(); |
| 4406 | ASSERT(initial_map->pre_allocated_property_fields() + |
| 4407 | initial_map->unused_property_fields() - |
| 4408 | initial_map->inobject_properties() == 0); |
| 4409 | |
| 4410 | // Allocate memory for the object. The initial map might change when |
| 4411 | // the constructor's prototype changes, but instance size and property |
| 4412 | // counts remain unchanged (if slack tracking finished). |
| 4413 | ASSERT(!constructor->shared()->IsInobjectSlackTrackingInProgress()); |
| 4414 | __ AllocateInNewSpace(instance_size, |
| 4415 | result, |
| 4416 | scratch, |
| 4417 | scratch2, |
| 4418 | deferred->entry(), |
| 4419 | TAG_OBJECT); |
| 4420 | |
| 4421 | // Load the initial map. |
| 4422 | Register map = scratch; |
| 4423 | __ LoadHeapObject(map, constructor); |
| 4424 | __ ldr(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4425 | |
| 4426 | // Initialize map and fields of the newly allocated object. |
| 4427 | ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 4428 | __ str(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 4429 | __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 4430 | __ str(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 4431 | __ str(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 4432 | if (initial_map->inobject_properties() != 0) { |
| 4433 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 4434 | for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 4435 | int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 4436 | __ str(scratch, FieldMemOperand(result, property_offset)); |
| 4437 | } |
| 4438 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4439 | |
| 4440 | __ bind(deferred->exit()); |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 4445 | Register result = ToRegister(instr->result()); |
| 4446 | Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 4447 | |
| 4448 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4449 | // result register contain a valid pointer because it is already |
| 4450 | // contained in the register pointer map. |
| 4451 | __ mov(result, Operand(0)); |
| 4452 | |
| 4453 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4454 | __ LoadHeapObject(r0, constructor); |
| 4455 | __ push(r0); |
| 4456 | CallRuntimeFromDeferred(Runtime::kNewObject, 1, instr); |
| 4457 | __ StoreToSafepointRegisterSlot(r0, result); |
| 4458 | } |
| 4459 | |
| 4460 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4461 | void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4462 | Heap* heap = isolate()->heap(); |
| 4463 | ElementsKind boilerplate_elements_kind = |
| 4464 | instr->hydrogen()->boilerplate_elements_kind(); |
| 4465 | |
| 4466 | // Deopt if the array literal boilerplate ElementsKind is of a type different |
| 4467 | // than the expected one. The check isn't necessary if the boilerplate has |
| 4468 | // already been converted to FAST_ELEMENTS. |
| 4469 | if (boilerplate_elements_kind != FAST_ELEMENTS) { |
| 4470 | __ LoadHeapObject(r1, instr->hydrogen()->boilerplate_object()); |
| 4471 | // Load map into r2. |
| 4472 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 4473 | // Load the map's "bit field 2". |
| 4474 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitField2Offset)); |
| 4475 | // Retrieve elements_kind from bit field 2. |
| 4476 | __ ubfx(r2, r2, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 4477 | __ cmp(r2, Operand(boilerplate_elements_kind)); |
| 4478 | DeoptimizeIf(ne, instr->environment()); |
| 4479 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4480 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4481 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4482 | __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 4483 | __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4484 | // Boilerplate already exists, constant elements are never accessed. |
| 4485 | // Pass an empty fixed array. |
| 4486 | __ mov(r1, Operand(Handle<FixedArray>(heap->empty_fixed_array()))); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4487 | __ Push(r3, r2, r1); |
| 4488 | |
| 4489 | // Pick the right runtime function or stub to call. |
| 4490 | int length = instr->hydrogen()->length(); |
| 4491 | if (instr->hydrogen()->IsCopyOnWrite()) { |
| 4492 | ASSERT(instr->hydrogen()->depth() == 1); |
| 4493 | FastCloneShallowArrayStub::Mode mode = |
| 4494 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
| 4495 | FastCloneShallowArrayStub stub(mode, length); |
| 4496 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4497 | } else if (instr->hydrogen()->depth() > 1) { |
| 4498 | CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
| 4499 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 4500 | CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
| 4501 | } else { |
| 4502 | FastCloneShallowArrayStub::Mode mode = |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4503 | boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
| 4504 | ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 4505 | : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4506 | FastCloneShallowArrayStub stub(mode, length); |
| 4507 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4508 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4512 | void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
| 4513 | Register result, |
| 4514 | Register source, |
| 4515 | int* offset) { |
| 4516 | ASSERT(!source.is(r2)); |
| 4517 | ASSERT(!result.is(r2)); |
| 4518 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4519 | // Only elements backing stores for non-COW arrays need to be copied. |
| 4520 | Handle<FixedArrayBase> elements(object->elements()); |
| 4521 | bool has_elements = elements->length() > 0 && |
| 4522 | elements->map() != isolate()->heap()->fixed_cow_array_map(); |
| 4523 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4524 | // Increase the offset so that subsequent objects end up right after |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4525 | // this object and its backing store. |
| 4526 | int object_offset = *offset; |
| 4527 | int object_size = object->map()->instance_size(); |
| 4528 | int elements_offset = *offset + object_size; |
| 4529 | int elements_size = has_elements ? elements->Size() : 0; |
| 4530 | *offset += object_size + elements_size; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4531 | |
| 4532 | // Copy object header. |
| 4533 | ASSERT(object->properties()->length() == 0); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4534 | int inobject_properties = object->map()->inobject_properties(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4535 | int header_size = object_size - inobject_properties * kPointerSize; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4536 | for (int i = 0; i < header_size; i += kPointerSize) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4537 | if (has_elements && i == JSObject::kElementsOffset) { |
| 4538 | __ add(r2, result, Operand(elements_offset)); |
| 4539 | } else { |
| 4540 | __ ldr(r2, FieldMemOperand(source, i)); |
| 4541 | } |
| 4542 | __ str(r2, FieldMemOperand(result, object_offset + i)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | // Copy in-object properties. |
| 4546 | for (int i = 0; i < inobject_properties; i++) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4547 | int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4548 | Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
| 4549 | if (value->IsJSObject()) { |
| 4550 | Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
| 4551 | __ add(r2, result, Operand(*offset)); |
| 4552 | __ str(r2, FieldMemOperand(result, total_offset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4553 | __ LoadHeapObject(source, value_object); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4554 | EmitDeepCopy(value_object, result, source, offset); |
| 4555 | } else if (value->IsHeapObject()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4556 | __ LoadHeapObject(r2, Handle<HeapObject>::cast(value)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4557 | __ str(r2, FieldMemOperand(result, total_offset)); |
| 4558 | } else { |
| 4559 | __ mov(r2, Operand(value)); |
| 4560 | __ str(r2, FieldMemOperand(result, total_offset)); |
| 4561 | } |
| 4562 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4563 | |
| 4564 | // Copy elements backing store header. |
| 4565 | ASSERT(!has_elements || elements->IsFixedArray()); |
| 4566 | if (has_elements) { |
| 4567 | __ LoadHeapObject(source, elements); |
| 4568 | for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { |
| 4569 | __ ldr(r2, FieldMemOperand(source, i)); |
| 4570 | __ str(r2, FieldMemOperand(result, elements_offset + i)); |
| 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | // Copy elements backing store content. |
| 4575 | ASSERT(!has_elements || elements->IsFixedArray()); |
| 4576 | int elements_length = has_elements ? elements->length() : 0; |
| 4577 | for (int i = 0; i < elements_length; i++) { |
| 4578 | int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); |
| 4579 | Handle<Object> value = JSObject::GetElement(object, i); |
| 4580 | if (value->IsJSObject()) { |
| 4581 | Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
| 4582 | __ add(r2, result, Operand(*offset)); |
| 4583 | __ str(r2, FieldMemOperand(result, total_offset)); |
| 4584 | __ LoadHeapObject(source, value_object); |
| 4585 | EmitDeepCopy(value_object, result, source, offset); |
| 4586 | } else if (value->IsHeapObject()) { |
| 4587 | __ LoadHeapObject(r2, Handle<HeapObject>::cast(value)); |
| 4588 | __ str(r2, FieldMemOperand(result, total_offset)); |
| 4589 | } else { |
| 4590 | __ mov(r2, Operand(value)); |
| 4591 | __ str(r2, FieldMemOperand(result, total_offset)); |
| 4592 | } |
| 4593 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4597 | void LCodeGen::DoFastLiteral(LFastLiteral* instr) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4598 | int size = instr->hydrogen()->total_size(); |
| 4599 | |
| 4600 | // Allocate all objects that are part of the literal in one big |
| 4601 | // allocation. This avoids multiple limit checks. |
| 4602 | Label allocated, runtime_allocate; |
| 4603 | __ AllocateInNewSpace(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
| 4604 | __ jmp(&allocated); |
| 4605 | |
| 4606 | __ bind(&runtime_allocate); |
| 4607 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 4608 | __ push(r0); |
| 4609 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 4610 | |
| 4611 | __ bind(&allocated); |
| 4612 | int offset = 0; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4613 | __ LoadHeapObject(r1, instr->hydrogen()->boilerplate()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4614 | EmitDeepCopy(instr->hydrogen()->boilerplate(), r0, r1, &offset); |
| 4615 | ASSERT_EQ(size, offset); |
| 4616 | } |
| 4617 | |
| 4618 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4619 | void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4620 | Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4621 | Handle<FixedArray> constant_properties = |
| 4622 | instr->hydrogen()->constant_properties(); |
| 4623 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4624 | // Set up the parameters to the stub/runtime call. |
| 4625 | __ LoadHeapObject(r4, literals); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4626 | __ mov(r3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4627 | __ mov(r2, Operand(constant_properties)); |
| 4628 | int flags = instr->hydrogen()->fast_elements() |
| 4629 | ? ObjectLiteral::kFastElements |
| 4630 | : ObjectLiteral::kNoFlags; |
| 4631 | __ mov(r1, Operand(Smi::FromInt(flags))); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4632 | __ Push(r4, r3, r2, r1); |
| 4633 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4634 | // Pick the right runtime function or stub to call. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4635 | int properties_count = constant_properties->length() / 2; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4636 | if (instr->hydrogen()->depth() > 1) { |
| 4637 | CallRuntime(Runtime::kCreateObjectLiteral, 4, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4638 | } else if (flags != ObjectLiteral::kFastElements || |
| 4639 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4640 | CallRuntime(Runtime::kCreateObjectLiteralShallow, 4, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4641 | } else { |
| 4642 | FastCloneShallowObjectStub stub(properties_count); |
| 4643 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4644 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4648 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
| 4649 | ASSERT(ToRegister(instr->InputAt(0)).is(r0)); |
| 4650 | __ push(r0); |
| 4651 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 4652 | } |
| 4653 | |
| 4654 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4655 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4656 | Label materialized; |
| 4657 | // Registers will be used as follows: |
| 4658 | // r3 = JS function. |
| 4659 | // r7 = literals array. |
| 4660 | // r1 = regexp literal. |
| 4661 | // r0 = regexp literal clone. |
| 4662 | // r2 and r4-r6 are used as temporaries. |
| 4663 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4664 | __ ldr(r7, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 4665 | int literal_offset = FixedArray::kHeaderSize + |
| 4666 | instr->hydrogen()->literal_index() * kPointerSize; |
| 4667 | __ ldr(r1, FieldMemOperand(r7, literal_offset)); |
| 4668 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4669 | __ cmp(r1, ip); |
| 4670 | __ b(ne, &materialized); |
| 4671 | |
| 4672 | // Create regexp literal using runtime function |
| 4673 | // Result will be in r0. |
| 4674 | __ mov(r6, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 4675 | __ mov(r5, Operand(instr->hydrogen()->pattern())); |
| 4676 | __ mov(r4, Operand(instr->hydrogen()->flags())); |
| 4677 | __ Push(r7, r6, r5, r4); |
| 4678 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 4679 | __ mov(r1, r0); |
| 4680 | |
| 4681 | __ bind(&materialized); |
| 4682 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 4683 | Label allocated, runtime_allocate; |
| 4684 | |
| 4685 | __ AllocateInNewSpace(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
| 4686 | __ jmp(&allocated); |
| 4687 | |
| 4688 | __ bind(&runtime_allocate); |
| 4689 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 4690 | __ Push(r1, r0); |
| 4691 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 4692 | __ pop(r1); |
| 4693 | |
| 4694 | __ bind(&allocated); |
| 4695 | // Copy the content into the newly allocated memory. |
| 4696 | // (Unroll copy loop once for better throughput). |
| 4697 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 4698 | __ ldr(r3, FieldMemOperand(r1, i)); |
| 4699 | __ ldr(r2, FieldMemOperand(r1, i + kPointerSize)); |
| 4700 | __ str(r3, FieldMemOperand(r0, i)); |
| 4701 | __ str(r2, FieldMemOperand(r0, i + kPointerSize)); |
| 4702 | } |
| 4703 | if ((size % (2 * kPointerSize)) != 0) { |
| 4704 | __ ldr(r3, FieldMemOperand(r1, size - kPointerSize)); |
| 4705 | __ str(r3, FieldMemOperand(r0, size - kPointerSize)); |
| 4706 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | |
| 4710 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4711 | // Use the fast case closure allocation code that allocates in new |
| 4712 | // space for nested functions that don't need literals cloning. |
| 4713 | Handle<SharedFunctionInfo> shared_info = instr->shared_info(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4714 | bool pretenure = instr->hydrogen()->pretenure(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4715 | if (!pretenure && shared_info->num_literals() == 0) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4716 | FastNewClosureStub stub(shared_info->language_mode()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4717 | __ mov(r1, Operand(shared_info)); |
| 4718 | __ push(r1); |
| 4719 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4720 | } else { |
| 4721 | __ mov(r2, Operand(shared_info)); |
| 4722 | __ mov(r1, Operand(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4723 | ? factory()->true_value() |
| 4724 | : factory()->false_value())); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4725 | __ Push(cp, r2, r1); |
| 4726 | CallRuntime(Runtime::kNewClosure, 3, instr); |
| 4727 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | |
| 4731 | void LCodeGen::DoTypeof(LTypeof* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4732 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4733 | __ push(input); |
| 4734 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4738 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4739 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4740 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 4741 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 4742 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 4743 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 4744 | |
| 4745 | Condition final_branch_condition = EmitTypeofIs(true_label, |
| 4746 | false_label, |
| 4747 | input, |
| 4748 | instr->type_literal()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4749 | if (final_branch_condition != kNoCondition) { |
| 4750 | EmitBranch(true_block, false_block, final_branch_condition); |
| 4751 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | |
| 4755 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 4756 | Label* false_label, |
| 4757 | Register input, |
| 4758 | Handle<String> type_name) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4759 | Condition final_branch_condition = kNoCondition; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4760 | Register scratch = scratch0(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4761 | if (type_name->Equals(heap()->number_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4762 | __ JumpIfSmi(input, true_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4763 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 4764 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 4765 | __ cmp(input, Operand(ip)); |
| 4766 | final_branch_condition = eq; |
| 4767 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4768 | } else if (type_name->Equals(heap()->string_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4769 | __ JumpIfSmi(input, false_label); |
| 4770 | __ CompareObjectType(input, input, scratch, FIRST_NONSTRING_TYPE); |
| 4771 | __ b(ge, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4772 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 4773 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4774 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4775 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4776 | } else if (type_name->Equals(heap()->boolean_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4777 | __ CompareRoot(input, Heap::kTrueValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4778 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4779 | __ CompareRoot(input, Heap::kFalseValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4780 | final_branch_condition = eq; |
| 4781 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4782 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_symbol())) { |
| 4783 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 4784 | final_branch_condition = eq; |
| 4785 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4786 | } else if (type_name->Equals(heap()->undefined_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4787 | __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4788 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4789 | __ JumpIfSmi(input, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4790 | // Check for undetectable objects => true. |
| 4791 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 4792 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 4793 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 4794 | final_branch_condition = ne; |
| 4795 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4796 | } else if (type_name->Equals(heap()->function_symbol())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4797 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4798 | __ JumpIfSmi(input, false_label); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4799 | __ CompareObjectType(input, scratch, input, JS_FUNCTION_TYPE); |
| 4800 | __ b(eq, true_label); |
| 4801 | __ cmp(input, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 4802 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4803 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4804 | } else if (type_name->Equals(heap()->object_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4805 | __ JumpIfSmi(input, false_label); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4806 | if (!FLAG_harmony_typeof) { |
| 4807 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 4808 | __ b(eq, true_label); |
| 4809 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4810 | __ CompareObjectType(input, input, scratch, |
| 4811 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4812 | __ b(lt, false_label); |
| 4813 | __ CompareInstanceType(input, scratch, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4814 | __ b(gt, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4815 | // Check for undetectable objects => false. |
| 4816 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 4817 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4818 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4819 | |
| 4820 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4821 | __ b(false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | return final_branch_condition; |
| 4825 | } |
| 4826 | |
| 4827 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4828 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
| 4829 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 4830 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 4831 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 4832 | |
| 4833 | EmitIsConstructCall(temp1, scratch0()); |
| 4834 | EmitBranch(true_block, false_block, eq); |
| 4835 | } |
| 4836 | |
| 4837 | |
| 4838 | void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 4839 | ASSERT(!temp1.is(temp2)); |
| 4840 | // Get the frame pointer for the calling frame. |
| 4841 | __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4842 | |
| 4843 | // Skip the arguments adaptor frame if it exists. |
| 4844 | Label check_frame_marker; |
| 4845 | __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 4846 | __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4847 | __ b(ne, &check_frame_marker); |
| 4848 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
| 4849 | |
| 4850 | // Check the marker in the calling frame. |
| 4851 | __ bind(&check_frame_marker); |
| 4852 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 4853 | __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 4854 | } |
| 4855 | |
| 4856 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4857 | void LCodeGen::EnsureSpaceForLazyDeopt() { |
| 4858 | // Ensure that we have enough space after the previous lazy-bailout |
| 4859 | // instruction for patching the code here. |
| 4860 | int current_pc = masm()->pc_offset(); |
| 4861 | int patch_size = Deoptimizer::patch_size(); |
| 4862 | if (current_pc < last_lazy_deopt_pc_ + patch_size) { |
| 4863 | int padding_size = last_lazy_deopt_pc_ + patch_size - current_pc; |
| 4864 | ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 4865 | while (padding_size > 0) { |
| 4866 | __ nop(); |
| 4867 | padding_size -= Assembler::kInstrSize; |
| 4868 | } |
| 4869 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4870 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4874 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4875 | EnsureSpaceForLazyDeopt(); |
| 4876 | ASSERT(instr->HasEnvironment()); |
| 4877 | LEnvironment* env = instr->environment(); |
| 4878 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4879 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | |
| 4883 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4884 | DeoptimizeIf(al, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | |
| 4888 | void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4889 | Register object = ToRegister(instr->object()); |
| 4890 | Register key = ToRegister(instr->key()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4891 | Register strict = scratch0(); |
| 4892 | __ mov(strict, Operand(Smi::FromInt(strict_mode_flag()))); |
| 4893 | __ Push(object, key, strict); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 4894 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 4895 | LPointerMap* pointers = instr->pointer_map(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 4896 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4897 | SafepointGenerator safepoint_generator( |
| 4898 | this, pointers, Safepoint::kLazyDeopt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4899 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4903 | void LCodeGen::DoIn(LIn* instr) { |
| 4904 | Register obj = ToRegister(instr->object()); |
| 4905 | Register key = ToRegister(instr->key()); |
| 4906 | __ Push(key, obj); |
| 4907 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 4908 | LPointerMap* pointers = instr->pointer_map(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4909 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4910 | SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4911 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4915 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4916 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4917 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 4918 | RecordSafepointWithLazyDeopt( |
| 4919 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 4920 | ASSERT(instr->HasEnvironment()); |
| 4921 | LEnvironment* env = instr->environment(); |
| 4922 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4926 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4927 | class DeferredStackCheck: public LDeferredCode { |
| 4928 | public: |
| 4929 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 4930 | : LDeferredCode(codegen), instr_(instr) { } |
| 4931 | virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4932 | virtual LInstruction* instr() { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4933 | private: |
| 4934 | LStackCheck* instr_; |
| 4935 | }; |
| 4936 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4937 | ASSERT(instr->HasEnvironment()); |
| 4938 | LEnvironment* env = instr->environment(); |
| 4939 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 4940 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4941 | if (instr->hydrogen()->is_function_entry()) { |
| 4942 | // Perform stack overflow check. |
| 4943 | Label done; |
| 4944 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 4945 | __ cmp(sp, Operand(ip)); |
| 4946 | __ b(hs, &done); |
| 4947 | StackCheckStub stub; |
| 4948 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4949 | EnsureSpaceForLazyDeopt(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4950 | __ bind(&done); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4951 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4952 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4953 | } else { |
| 4954 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 4955 | // Perform stack overflow check if this goto needs it before jumping. |
| 4956 | DeferredStackCheck* deferred_stack_check = |
| 4957 | new DeferredStackCheck(this, instr); |
| 4958 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 4959 | __ cmp(sp, Operand(ip)); |
| 4960 | __ b(lo, deferred_stack_check->entry()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4961 | EnsureSpaceForLazyDeopt(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4962 | __ bind(instr->done_label()); |
| 4963 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4964 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4965 | // Don't record a deoptimization index for the safepoint here. |
| 4966 | // This will be done explicitly when emitting call and the safepoint in |
| 4967 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4968 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | |
| 4972 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4973 | // This is a pseudo-instruction that ensures that the environment here is |
| 4974 | // properly registered for deoptimization and records the assembler's PC |
| 4975 | // offset. |
| 4976 | LEnvironment* environment = instr->environment(); |
| 4977 | environment->SetSpilledRegisters(instr->SpilledRegisterArray(), |
| 4978 | instr->SpilledDoubleRegisterArray()); |
| 4979 | |
| 4980 | // If the environment were already registered, we would have no way of |
| 4981 | // backpatching it with the spill slot operands. |
| 4982 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4983 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4984 | ASSERT(osr_pc_offset_ == -1); |
| 4985 | osr_pc_offset_ = masm()->pc_offset(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 4989 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 4990 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4991 | __ cmp(r0, ip); |
| 4992 | DeoptimizeIf(eq, instr->environment()); |
| 4993 | |
| 4994 | Register null_value = r5; |
| 4995 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 4996 | __ cmp(r0, null_value); |
| 4997 | DeoptimizeIf(eq, instr->environment()); |
| 4998 | |
| 4999 | __ tst(r0, Operand(kSmiTagMask)); |
| 5000 | DeoptimizeIf(eq, instr->environment()); |
| 5001 | |
| 5002 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5003 | __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); |
| 5004 | DeoptimizeIf(le, instr->environment()); |
| 5005 | |
| 5006 | Label use_cache, call_runtime; |
| 5007 | __ CheckEnumCache(null_value, &call_runtime); |
| 5008 | |
| 5009 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5010 | __ b(&use_cache); |
| 5011 | |
| 5012 | // Get the set of properties to enumerate. |
| 5013 | __ bind(&call_runtime); |
| 5014 | __ push(r0); |
| 5015 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5016 | |
| 5017 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5018 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 5019 | __ cmp(r1, ip); |
| 5020 | DeoptimizeIf(ne, instr->environment()); |
| 5021 | __ bind(&use_cache); |
| 5022 | } |
| 5023 | |
| 5024 | |
| 5025 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5026 | Register map = ToRegister(instr->map()); |
| 5027 | Register result = ToRegister(instr->result()); |
| 5028 | __ LoadInstanceDescriptors(map, result); |
| 5029 | __ ldr(result, |
| 5030 | FieldMemOperand(result, DescriptorArray::kEnumerationIndexOffset)); |
| 5031 | __ ldr(result, |
| 5032 | FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
| 5033 | __ cmp(result, Operand(0)); |
| 5034 | DeoptimizeIf(eq, instr->environment()); |
| 5035 | } |
| 5036 | |
| 5037 | |
| 5038 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5039 | Register object = ToRegister(instr->value()); |
| 5040 | Register map = ToRegister(instr->map()); |
| 5041 | __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5042 | __ cmp(map, scratch0()); |
| 5043 | DeoptimizeIf(ne, instr->environment()); |
| 5044 | } |
| 5045 | |
| 5046 | |
| 5047 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5048 | Register object = ToRegister(instr->object()); |
| 5049 | Register index = ToRegister(instr->index()); |
| 5050 | Register result = ToRegister(instr->result()); |
| 5051 | Register scratch = scratch0(); |
| 5052 | |
| 5053 | Label out_of_object, done; |
| 5054 | __ cmp(index, Operand(0)); |
| 5055 | __ b(lt, &out_of_object); |
| 5056 | |
| 5057 | STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize); |
| 5058 | __ add(scratch, object, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5059 | __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5060 | |
| 5061 | __ b(&done); |
| 5062 | |
| 5063 | __ bind(&out_of_object); |
| 5064 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5065 | // Index is equal to negated out of object property index plus 1. |
| 5066 | __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5067 | __ ldr(result, FieldMemOperand(scratch, |
| 5068 | FixedArray::kHeaderSize - kPointerSize)); |
| 5069 | __ bind(&done); |
| 5070 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5071 | |
| 5072 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5073 | #undef __ |
| 5074 | |
| 5075 | } } // namespace v8::internal |