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