| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // |
| 3 // Copyright IBM Corp. 2012, 2013. All rights reserved. |
| 4 // |
| 2 // Use of this source code is governed by a BSD-style license that can be | 5 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 6 // found in the LICENSE file. |
| 4 | 7 |
| 5 #include "src/v8.h" | 8 #include "src/v8.h" |
| 6 | 9 |
| 7 #include "src/arm/lithium-codegen-arm.h" | |
| 8 #include "src/arm/lithium-gap-resolver-arm.h" | |
| 9 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| 10 #include "src/hydrogen-osr.h" | 11 #include "src/hydrogen-osr.h" |
| 11 #include "src/stub-cache.h" | 12 #include "src/stub-cache.h" |
| 12 | 13 |
| 14 #include "src/ppc/lithium-codegen-ppc.h" |
| 15 #include "src/ppc/lithium-gap-resolver-ppc.h" |
| 16 |
| 13 namespace v8 { | 17 namespace v8 { |
| 14 namespace internal { | 18 namespace internal { |
| 15 | 19 |
| 16 | 20 |
| 17 class SafepointGenerator V8_FINAL : public CallWrapper { | 21 class SafepointGenerator V8_FINAL : public CallWrapper { |
| 18 public: | 22 public: |
| 19 SafepointGenerator(LCodeGen* codegen, | 23 SafepointGenerator(LCodeGen* codegen, |
| 20 LPointerMap* pointers, | 24 LPointerMap* pointers, |
| 21 Safepoint::DeoptMode mode) | 25 Safepoint::DeoptMode mode) |
| 22 : codegen_(codegen), | 26 : codegen_(codegen), |
| 23 pointers_(pointers), | 27 pointers_(pointers), |
| 24 deopt_mode_(mode) { } | 28 deopt_mode_(mode) { } |
| 25 virtual ~SafepointGenerator() {} | 29 virtual ~SafepointGenerator() { } |
| 26 | 30 |
| 27 virtual void BeforeCall(int call_size) const V8_OVERRIDE {} | 31 virtual void BeforeCall(int call_size) const V8_OVERRIDE {} |
| 28 | 32 |
| 29 virtual void AfterCall() const V8_OVERRIDE { | 33 virtual void AfterCall() const V8_OVERRIDE { |
| 30 codegen_->RecordSafepoint(pointers_, deopt_mode_); | 34 codegen_->RecordSafepoint(pointers_, deopt_mode_); |
| 31 } | 35 } |
| 32 | 36 |
| 33 private: | 37 private: |
| 34 LCodeGen* codegen_; | 38 LCodeGen* codegen_; |
| 35 LPointerMap* pointers_; | 39 LPointerMap* pointers_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 71 |
| 68 | 72 |
| 69 void LCodeGen::SaveCallerDoubles() { | 73 void LCodeGen::SaveCallerDoubles() { |
| 70 ASSERT(info()->saves_caller_doubles()); | 74 ASSERT(info()->saves_caller_doubles()); |
| 71 ASSERT(NeedsEagerFrame()); | 75 ASSERT(NeedsEagerFrame()); |
| 72 Comment(";;; Save clobbered callee double registers"); | 76 Comment(";;; Save clobbered callee double registers"); |
| 73 int count = 0; | 77 int count = 0; |
| 74 BitVector* doubles = chunk()->allocated_double_registers(); | 78 BitVector* doubles = chunk()->allocated_double_registers(); |
| 75 BitVector::Iterator save_iterator(doubles); | 79 BitVector::Iterator save_iterator(doubles); |
| 76 while (!save_iterator.Done()) { | 80 while (!save_iterator.Done()) { |
| 77 __ vstr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), | 81 __ stfd(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
| 78 MemOperand(sp, count * kDoubleSize)); | 82 MemOperand(sp, count * kDoubleSize)); |
| 79 save_iterator.Advance(); | 83 save_iterator.Advance(); |
| 80 count++; | 84 count++; |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 | 87 |
| 84 | 88 |
| 85 void LCodeGen::RestoreCallerDoubles() { | 89 void LCodeGen::RestoreCallerDoubles() { |
| 86 ASSERT(info()->saves_caller_doubles()); | 90 ASSERT(info()->saves_caller_doubles()); |
| 87 ASSERT(NeedsEagerFrame()); | 91 ASSERT(NeedsEagerFrame()); |
| 88 Comment(";;; Restore clobbered callee double registers"); | 92 Comment(";;; Restore clobbered callee double registers"); |
| 89 BitVector* doubles = chunk()->allocated_double_registers(); | 93 BitVector* doubles = chunk()->allocated_double_registers(); |
| 90 BitVector::Iterator save_iterator(doubles); | 94 BitVector::Iterator save_iterator(doubles); |
| 91 int count = 0; | 95 int count = 0; |
| 92 while (!save_iterator.Done()) { | 96 while (!save_iterator.Done()) { |
| 93 __ vldr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), | 97 __ lfd(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
| 94 MemOperand(sp, count * kDoubleSize)); | 98 MemOperand(sp, count * kDoubleSize)); |
| 95 save_iterator.Advance(); | 99 save_iterator.Advance(); |
| 96 count++; | 100 count++; |
| 97 } | 101 } |
| 98 } | 102 } |
| 99 | 103 |
| 100 | 104 |
| 101 bool LCodeGen::GeneratePrologue() { | 105 bool LCodeGen::GeneratePrologue() { |
| 102 ASSERT(is_generating()); | 106 ASSERT(is_generating()); |
| 103 | 107 |
| 104 if (info()->IsOptimizing()) { | 108 if (info()->IsOptimizing()) { |
| 105 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | 109 ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 106 | 110 |
| 107 #ifdef DEBUG | 111 #ifdef DEBUG |
| 108 if (strlen(FLAG_stop_at) > 0 && | 112 if (strlen(FLAG_stop_at) > 0 && |
| 109 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | 113 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
| 110 __ stop("stop_at"); | 114 __ stop("stop_at"); |
| 111 } | 115 } |
| 112 #endif | 116 #endif |
| 113 | 117 |
| 114 // r1: Callee's JS function. | 118 // r4: Callee's JS function. |
| 115 // cp: Callee's context. | 119 // cp: Callee's context. |
| 116 // pp: Callee's constant pool pointer (if FLAG_enable_ool_constant_pool) | |
| 117 // fp: Caller's frame pointer. | 120 // fp: Caller's frame pointer. |
| 118 // lr: Caller's pc. | 121 // lr: Caller's pc. |
| 119 | 122 |
| 120 // Sloppy mode functions and builtins need to replace the receiver with the | 123 // Sloppy mode functions and builtins need to replace the receiver with the |
| 121 // global proxy when called as functions (without an explicit receiver | 124 // global proxy when called as functions (without an explicit receiver |
| 122 // object). | 125 // object). |
| 123 if (info_->this_has_uses() && | 126 if (info_->this_has_uses() && |
| 124 info_->strict_mode() == SLOPPY && | 127 info_->strict_mode() == SLOPPY && |
| 125 !info_->is_native()) { | 128 !info_->is_native()) { |
| 126 Label ok; | 129 Label ok; |
| 127 int receiver_offset = info_->scope()->num_parameters() * kPointerSize; | 130 int receiver_offset = info_->scope()->num_parameters() * kPointerSize; |
| 128 __ ldr(r2, MemOperand(sp, receiver_offset)); | 131 __ LoadP(r5, MemOperand(sp, receiver_offset)); |
| 129 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex); | 132 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex); |
| 130 __ b(ne, &ok); | 133 __ bne(&ok); |
| 131 | 134 |
| 132 __ ldr(r2, GlobalObjectOperand()); | 135 __ LoadP(r5, GlobalObjectOperand()); |
| 133 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset)); | 136 __ LoadP(r5, FieldMemOperand(r5, GlobalObject::kGlobalProxyOffset)); |
| 134 | 137 |
| 135 __ str(r2, MemOperand(sp, receiver_offset)); | 138 __ StoreP(r5, MemOperand(sp, receiver_offset)); |
| 136 | 139 |
| 137 __ bind(&ok); | 140 __ bind(&ok); |
| 138 } | 141 } |
| 139 } | 142 } |
| 140 | 143 |
| 141 info()->set_prologue_offset(masm_->pc_offset()); | 144 info()->set_prologue_offset(masm_->pc_offset()); |
| 142 if (NeedsEagerFrame()) { | 145 if (NeedsEagerFrame()) { |
| 143 if (info()->IsStub()) { | 146 if (info()->IsStub()) { |
| 144 __ StubPrologue(); | 147 __ StubPrologue(); |
| 145 } else { | 148 } else { |
| 146 __ Prologue(info()->IsCodePreAgingActive()); | 149 __ Prologue(info()->IsCodePreAgingActive()); |
| 147 } | 150 } |
| 148 frame_is_built_ = true; | 151 frame_is_built_ = true; |
| 149 info_->AddNoFrameRange(0, masm_->pc_offset()); | 152 info_->AddNoFrameRange(0, masm_->pc_offset()); |
| 150 } | 153 } |
| 151 | 154 |
| 152 // Reserve space for the stack slots needed by the code. | 155 // Reserve space for the stack slots needed by the code. |
| 153 int slots = GetStackSlotCount(); | 156 int slots = GetStackSlotCount(); |
| 154 if (slots > 0) { | 157 if (slots > 0) { |
| 158 __ subi(sp, sp, Operand(slots * kPointerSize)); |
| 155 if (FLAG_debug_code) { | 159 if (FLAG_debug_code) { |
| 156 __ sub(sp, sp, Operand(slots * kPointerSize)); | 160 __ Push(r3, r4); |
| 157 __ push(r0); | 161 __ li(r0, Operand(slots)); |
| 158 __ push(r1); | 162 __ mtctr(r0); |
| 159 __ add(r0, sp, Operand(slots * kPointerSize)); | 163 __ addi(r3, sp, Operand((slots + 2) * kPointerSize)); |
| 160 __ mov(r1, Operand(kSlotsZapValue)); | 164 __ mov(r4, Operand(kSlotsZapValue)); |
| 161 Label loop; | 165 Label loop; |
| 162 __ bind(&loop); | 166 __ bind(&loop); |
| 163 __ sub(r0, r0, Operand(kPointerSize)); | 167 __ StorePU(r4, MemOperand(r3, -kPointerSize)); |
| 164 __ str(r1, MemOperand(r0, 2 * kPointerSize)); | 168 __ bdnz(&loop); |
| 165 __ cmp(r0, sp); | 169 __ Pop(r3, r4); |
| 166 __ b(ne, &loop); | |
| 167 __ pop(r1); | |
| 168 __ pop(r0); | |
| 169 } else { | |
| 170 __ sub(sp, sp, Operand(slots * kPointerSize)); | |
| 171 } | 170 } |
| 172 } | 171 } |
| 173 | 172 |
| 174 if (info()->saves_caller_doubles()) { | 173 if (info()->saves_caller_doubles()) { |
| 175 SaveCallerDoubles(); | 174 SaveCallerDoubles(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 // Possibly allocate a local context. | 177 // Possibly allocate a local context. |
| 179 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 178 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 180 if (heap_slots > 0) { | 179 if (heap_slots > 0) { |
| 181 Comment(";;; Allocate local context"); | 180 Comment(";;; Allocate local context"); |
| 182 bool need_write_barrier = true; | 181 bool need_write_barrier = true; |
| 183 // Argument to NewContext is the function, which is in r1. | 182 // Argument to NewContext is the function, which is in r4. |
| 184 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | 183 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 185 FastNewContextStub stub(isolate(), heap_slots); | 184 FastNewContextStub stub(isolate(), heap_slots); |
| 186 __ CallStub(&stub); | 185 __ CallStub(&stub); |
| 187 // Result of FastNewContextStub is always in new space. | 186 // Result of FastNewContextStub is always in new space. |
| 188 need_write_barrier = false; | 187 need_write_barrier = false; |
| 189 } else { | 188 } else { |
| 190 __ push(r1); | 189 __ push(r4); |
| 191 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 190 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 192 } | 191 } |
| 193 RecordSafepoint(Safepoint::kNoLazyDeopt); | 192 RecordSafepoint(Safepoint::kNoLazyDeopt); |
| 194 // Context is returned in both r0 and cp. It replaces the context | 193 // Context is returned in both r3 and cp. It replaces the context |
| 195 // passed to us. It's saved in the stack and kept live in cp. | 194 // passed to us. It's saved in the stack and kept live in cp. |
| 196 __ mov(cp, r0); | 195 __ mr(cp, r3); |
| 197 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 196 __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 198 // Copy any necessary parameters into the context. | 197 // Copy any necessary parameters into the context. |
| 199 int num_parameters = scope()->num_parameters(); | 198 int num_parameters = scope()->num_parameters(); |
| 200 for (int i = 0; i < num_parameters; i++) { | 199 for (int i = 0; i < num_parameters; i++) { |
| 201 Variable* var = scope()->parameter(i); | 200 Variable* var = scope()->parameter(i); |
| 202 if (var->IsContextSlot()) { | 201 if (var->IsContextSlot()) { |
| 203 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | 202 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 204 (num_parameters - 1 - i) * kPointerSize; | 203 (num_parameters - 1 - i) * kPointerSize; |
| 205 // Load parameter from stack. | 204 // Load parameter from stack. |
| 206 __ ldr(r0, MemOperand(fp, parameter_offset)); | 205 __ LoadP(r3, MemOperand(fp, parameter_offset)); |
| 207 // Store it in the context. | 206 // Store it in the context. |
| 208 MemOperand target = ContextOperand(cp, var->index()); | 207 MemOperand target = ContextOperand(cp, var->index()); |
| 209 __ str(r0, target); | 208 __ StoreP(r3, target, r0); |
| 210 // Update the write barrier. This clobbers r3 and r0. | 209 // Update the write barrier. This clobbers r6 and r3. |
| 211 if (need_write_barrier) { | 210 if (need_write_barrier) { |
| 212 __ RecordWriteContextSlot( | 211 __ RecordWriteContextSlot( |
| 213 cp, | 212 cp, |
| 214 target.offset(), | 213 target.offset(), |
| 215 r0, | |
| 216 r3, | 214 r3, |
| 215 r6, |
| 217 GetLinkRegisterState(), | 216 GetLinkRegisterState(), |
| 218 kSaveFPRegs); | 217 kSaveFPRegs); |
| 219 } else if (FLAG_debug_code) { | 218 } else if (FLAG_debug_code) { |
| 220 Label done; | 219 Label done; |
| 221 __ JumpIfInNewSpace(cp, r0, &done); | 220 __ JumpIfInNewSpace(cp, r3, &done); |
| 222 __ Abort(kExpectedNewSpaceObject); | 221 __ Abort(kExpectedNewSpaceObject); |
| 223 __ bind(&done); | 222 __ bind(&done); |
| 224 } | 223 } |
| 225 } | 224 } |
| 226 } | 225 } |
| 227 Comment(";;; End allocate local context"); | 226 Comment(";;; End allocate local context"); |
| 228 } | 227 } |
| 229 | 228 |
| 230 // Trace the call. | 229 // Trace the call. |
| 231 if (FLAG_trace && info()->IsOptimizing()) { | 230 if (FLAG_trace && info()->IsOptimizing()) { |
| 232 // We have not executed any compiled code yet, so cp still holds the | 231 // We have not executed any compiled code yet, so cp still holds the |
| 233 // incoming context. | 232 // incoming context. |
| 234 __ CallRuntime(Runtime::kTraceEnter, 0); | 233 __ CallRuntime(Runtime::kTraceEnter, 0); |
| 235 } | 234 } |
| 236 return !is_aborted(); | 235 return !is_aborted(); |
| 237 } | 236 } |
| 238 | 237 |
| 239 | 238 |
| 240 void LCodeGen::GenerateOsrPrologue() { | 239 void LCodeGen::GenerateOsrPrologue() { |
| 241 // Generate the OSR entry prologue at the first unknown OSR value, or if there | 240 // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 242 // are none, at the OSR entrypoint instruction. | 241 // are none, at the OSR entrypoint instruction. |
| 243 if (osr_pc_offset_ >= 0) return; | 242 if (osr_pc_offset_ >= 0) return; |
| 244 | 243 |
| 245 osr_pc_offset_ = masm()->pc_offset(); | 244 osr_pc_offset_ = masm()->pc_offset(); |
| 246 | 245 |
| 247 // Adjust the frame size, subsuming the unoptimized frame into the | 246 // Adjust the frame size, subsuming the unoptimized frame into the |
| 248 // optimized frame. | 247 // optimized frame. |
| 249 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); | 248 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 250 ASSERT(slots >= 0); | 249 ASSERT(slots >= 0); |
| 251 __ sub(sp, sp, Operand(slots * kPointerSize)); | 250 __ subi(sp, sp, Operand(slots * kPointerSize)); |
| 252 } | 251 } |
| 253 | 252 |
| 254 | 253 |
| 255 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { | 254 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
| 256 if (instr->IsCall()) { | 255 if (instr->IsCall()) { |
| 257 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | 256 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 258 } | 257 } |
| 259 if (!instr->IsLazyBailout() && !instr->IsGap()) { | 258 if (!instr->IsLazyBailout() && !instr->IsGap()) { |
| 260 safepoints_.BumpLastLazySafepointIndex(); | 259 safepoints_.BumpLastLazySafepointIndex(); |
| 261 } | 260 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 278 code->instruction_index(), | 277 code->instruction_index(), |
| 279 code->instr()->hydrogen_value()->id(), | 278 code->instr()->hydrogen_value()->id(), |
| 280 code->instr()->Mnemonic()); | 279 code->instr()->Mnemonic()); |
| 281 __ bind(code->entry()); | 280 __ bind(code->entry()); |
| 282 if (NeedsDeferredFrame()) { | 281 if (NeedsDeferredFrame()) { |
| 283 Comment(";;; Build frame"); | 282 Comment(";;; Build frame"); |
| 284 ASSERT(!frame_is_built_); | 283 ASSERT(!frame_is_built_); |
| 285 ASSERT(info()->IsStub()); | 284 ASSERT(info()->IsStub()); |
| 286 frame_is_built_ = true; | 285 frame_is_built_ = true; |
| 287 __ PushFixedFrame(); | 286 __ PushFixedFrame(); |
| 288 __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); | 287 __ LoadSmiLiteral(scratch0(), Smi::FromInt(StackFrame::STUB)); |
| 289 __ push(scratch0()); | 288 __ push(scratch0()); |
| 290 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | 289 __ addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 291 Comment(";;; Deferred code"); | 290 Comment(";;; Deferred code"); |
| 292 } | 291 } |
| 293 code->Generate(); | 292 code->Generate(); |
| 294 if (NeedsDeferredFrame()) { | 293 if (NeedsDeferredFrame()) { |
| 295 Comment(";;; Destroy frame"); | 294 Comment(";;; Destroy frame"); |
| 296 ASSERT(frame_is_built_); | 295 ASSERT(frame_is_built_); |
| 297 __ pop(ip); | 296 __ pop(ip); |
| 298 __ PopFixedFrame(); | 297 __ PopFixedFrame(); |
| 299 frame_is_built_ = false; | 298 frame_is_built_ = false; |
| 300 } | 299 } |
| 301 __ jmp(code->exit()); | 300 __ b(code->exit()); |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 | 303 |
| 305 // Force constant pool emission at the end of the deferred code to make | |
| 306 // sure that no constant pools are emitted after. | |
| 307 masm()->CheckConstPool(true, false); | |
| 308 | |
| 309 return !is_aborted(); | 304 return !is_aborted(); |
| 310 } | 305 } |
| 311 | 306 |
| 312 | 307 |
| 313 bool LCodeGen::GenerateDeoptJumpTable() { | 308 bool LCodeGen::GenerateDeoptJumpTable() { |
| 314 // Check that the jump table is accessible from everywhere in the function | |
| 315 // code, i.e. that offsets to the table can be encoded in the 24bit signed | |
| 316 // immediate of a branch instruction. | |
| 317 // To simplify we consider the code size from the first instruction to the | |
| 318 // end of the jump table. We also don't consider the pc load delta. | |
| 319 // Each entry in the jump table generates one instruction and inlines one | |
| 320 // 32bit data after it. | |
| 321 if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) + | |
| 322 deopt_jump_table_.length() * 7)) { | |
| 323 Abort(kGeneratedCodeIsTooLarge); | |
| 324 } | |
| 325 | |
| 326 if (deopt_jump_table_.length() > 0) { | 309 if (deopt_jump_table_.length() > 0) { |
| 327 Label needs_frame, call_deopt_entry; | 310 Label needs_frame, call_deopt_entry; |
| 328 | 311 |
| 329 Comment(";;; -------------------- Jump table --------------------"); | 312 Comment(";;; -------------------- Jump table --------------------"); |
| 330 Address base = deopt_jump_table_[0].address; | 313 Address base = deopt_jump_table_[0].address; |
| 331 | 314 |
| 332 Register entry_offset = scratch0(); | 315 Register entry_offset = scratch0(); |
| 333 | 316 |
| 334 int length = deopt_jump_table_.length(); | 317 int length = deopt_jump_table_.length(); |
| 335 for (int i = 0; i < length; i++) { | 318 for (int i = 0; i < length; i++) { |
| 319 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 336 __ bind(&deopt_jump_table_[i].label); | 320 __ bind(&deopt_jump_table_[i].label); |
| 337 | 321 |
| 338 Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; | 322 Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; |
| 339 ASSERT(type == deopt_jump_table_[0].bailout_type); | 323 ASSERT(type == deopt_jump_table_[0].bailout_type); |
| 340 Address entry = deopt_jump_table_[i].address; | 324 Address entry = deopt_jump_table_[i].address; |
| 341 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); | 325 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
| 342 ASSERT(id != Deoptimizer::kNotDeoptimizationEntry); | 326 ASSERT(id != Deoptimizer::kNotDeoptimizationEntry); |
| 343 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); | 327 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 344 | 328 |
| 345 // Second-level deopt table entries are contiguous and small, so instead | 329 // Second-level deopt table entries are contiguous and small, so instead |
| 346 // of loading the full, absolute address of each one, load an immediate | 330 // of loading the full, absolute address of each one, load an immediate |
| 347 // offset which will be added to the base address later. | 331 // offset which will be added to the base address later. |
| 348 __ mov(entry_offset, Operand(entry - base)); | 332 __ mov(entry_offset, Operand(entry - base)); |
| 349 | 333 |
| 350 if (deopt_jump_table_[i].needs_frame) { | 334 if (deopt_jump_table_[i].needs_frame) { |
| 351 ASSERT(!info()->saves_caller_doubles()); | 335 ASSERT(!info()->saves_caller_doubles()); |
| 352 if (needs_frame.is_bound()) { | 336 if (needs_frame.is_bound()) { |
| 353 __ b(&needs_frame); | 337 __ b(&needs_frame); |
| 354 } else { | 338 } else { |
| 355 __ bind(&needs_frame); | 339 __ bind(&needs_frame); |
| 356 Comment(";;; call deopt with frame"); | 340 Comment(";;; call deopt with frame"); |
| 357 __ PushFixedFrame(); | 341 __ PushFixedFrame(); |
| 358 // This variant of deopt can only be used with stubs. Since we don't | 342 // This variant of deopt can only be used with stubs. Since we don't |
| 359 // have a function pointer to install in the stack frame that we're | 343 // have a function pointer to install in the stack frame that we're |
| 360 // building, install a special marker there instead. | 344 // building, install a special marker there instead. |
| 361 ASSERT(info()->IsStub()); | 345 ASSERT(info()->IsStub()); |
| 362 __ mov(ip, Operand(Smi::FromInt(StackFrame::STUB))); | 346 __ LoadSmiLiteral(r0, Smi::FromInt(StackFrame::STUB)); |
| 363 __ push(ip); | 347 __ push(r0); |
| 364 __ add(fp, sp, | 348 __ addi(fp, sp, |
| 365 Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | 349 Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 366 __ bind(&call_deopt_entry); | 350 __ bind(&call_deopt_entry); |
| 367 // Add the base address to the offset previously loaded in | 351 // Add the base address to the offset previously loaded in |
| 368 // entry_offset. | 352 // entry_offset. |
| 369 __ add(entry_offset, entry_offset, | 353 __ mov(ip, Operand(ExternalReference::ForDeoptEntry(base))); |
| 370 Operand(ExternalReference::ForDeoptEntry(base))); | 354 __ add(ip, entry_offset, ip); |
| 371 __ blx(entry_offset); | 355 __ Call(ip); |
| 372 } | 356 } |
| 373 | |
| 374 masm()->CheckConstPool(false, false); | |
| 375 } else { | 357 } else { |
| 376 // The last entry can fall through into `call_deopt_entry`, avoiding a | 358 // The last entry can fall through into `call_deopt_entry`, avoiding a |
| 377 // branch. | 359 // branch. |
| 378 bool need_branch = ((i + 1) != length) || call_deopt_entry.is_bound(); | 360 bool need_branch = ((i + 1) != length) || call_deopt_entry.is_bound(); |
| 379 | 361 |
| 380 if (need_branch) __ b(&call_deopt_entry); | 362 if (need_branch) __ b(&call_deopt_entry); |
| 381 | |
| 382 masm()->CheckConstPool(false, !need_branch); | |
| 383 } | 363 } |
| 384 } | 364 } |
| 385 | 365 |
| 386 if (!call_deopt_entry.is_bound()) { | 366 if (!call_deopt_entry.is_bound()) { |
| 387 Comment(";;; call deopt"); | 367 Comment(";;; call deopt"); |
| 388 __ bind(&call_deopt_entry); | 368 __ bind(&call_deopt_entry); |
| 389 | 369 |
| 390 if (info()->saves_caller_doubles()) { | 370 if (info()->saves_caller_doubles()) { |
| 391 ASSERT(info()->IsStub()); | 371 ASSERT(info()->IsStub()); |
| 392 RestoreCallerDoubles(); | 372 RestoreCallerDoubles(); |
| 393 } | 373 } |
| 394 | 374 |
| 395 // Add the base address to the offset previously loaded in entry_offset. | 375 // Add the base address to the offset previously loaded in entry_offset. |
| 396 __ add(entry_offset, entry_offset, | 376 __ mov(ip, Operand(ExternalReference::ForDeoptEntry(base))); |
| 397 Operand(ExternalReference::ForDeoptEntry(base))); | 377 __ add(ip, entry_offset, ip); |
| 398 __ blx(entry_offset); | 378 __ Call(ip); |
| 399 } | 379 } |
| 400 } | 380 } |
| 401 | 381 |
| 402 // Force constant pool emission at the end of the deopt jump table to make | |
| 403 // sure that no constant pools are emitted after. | |
| 404 masm()->CheckConstPool(true, false); | |
| 405 | |
| 406 // The deoptimization jump table is the last part of the instruction | 382 // The deoptimization jump table is the last part of the instruction |
| 407 // sequence. Mark the generated code as done unless we bailed out. | 383 // sequence. Mark the generated code as done unless we bailed out. |
| 408 if (!is_aborted()) status_ = DONE; | 384 if (!is_aborted()) status_ = DONE; |
| 409 return !is_aborted(); | 385 return !is_aborted(); |
| 410 } | 386 } |
| 411 | 387 |
| 412 | 388 |
| 413 bool LCodeGen::GenerateSafepointTable() { | 389 bool LCodeGen::GenerateSafepointTable() { |
| 414 ASSERT(is_done()); | 390 ASSERT(is_done()); |
| 415 safepoints_.Emit(masm(), GetStackSlotCount()); | 391 safepoints_.Emit(masm(), GetStackSlotCount()); |
| 416 return !is_aborted(); | 392 return !is_aborted(); |
| 417 } | 393 } |
| 418 | 394 |
| 419 | 395 |
| 420 Register LCodeGen::ToRegister(int index) const { | 396 Register LCodeGen::ToRegister(int index) const { |
| 421 return Register::FromAllocationIndex(index); | 397 return Register::FromAllocationIndex(index); |
| 422 } | 398 } |
| 423 | 399 |
| 424 | 400 |
| 425 DwVfpRegister LCodeGen::ToDoubleRegister(int index) const { | 401 DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
| 426 return DwVfpRegister::FromAllocationIndex(index); | 402 return DoubleRegister::FromAllocationIndex(index); |
| 427 } | 403 } |
| 428 | 404 |
| 429 | 405 |
| 430 Register LCodeGen::ToRegister(LOperand* op) const { | 406 Register LCodeGen::ToRegister(LOperand* op) const { |
| 431 ASSERT(op->IsRegister()); | 407 ASSERT(op->IsRegister()); |
| 432 return ToRegister(op->index()); | 408 return ToRegister(op->index()); |
| 433 } | 409 } |
| 434 | 410 |
| 435 | 411 |
| 436 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { | 412 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 437 if (op->IsRegister()) { | 413 if (op->IsRegister()) { |
| 438 return ToRegister(op->index()); | 414 return ToRegister(op->index()); |
| 439 } else if (op->IsConstantOperand()) { | 415 } else if (op->IsConstantOperand()) { |
| 440 LConstantOperand* const_op = LConstantOperand::cast(op); | 416 LConstantOperand* const_op = LConstantOperand::cast(op); |
| 441 HConstant* constant = chunk_->LookupConstant(const_op); | 417 HConstant* constant = chunk_->LookupConstant(const_op); |
| 442 Handle<Object> literal = constant->handle(isolate()); | 418 Handle<Object> literal = constant->handle(isolate()); |
| 443 Representation r = chunk_->LookupLiteralRepresentation(const_op); | 419 Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 444 if (r.IsInteger32()) { | 420 if (r.IsInteger32()) { |
| 445 ASSERT(literal->IsNumber()); | 421 ASSERT(literal->IsNumber()); |
| 446 __ mov(scratch, Operand(static_cast<int32_t>(literal->Number()))); | 422 __ LoadIntLiteral(scratch, static_cast<int32_t>(literal->Number())); |
| 447 } else if (r.IsDouble()) { | 423 } else if (r.IsDouble()) { |
| 448 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); | 424 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); |
| 449 } else { | 425 } else { |
| 450 ASSERT(r.IsSmiOrTagged()); | 426 ASSERT(r.IsSmiOrTagged()); |
| 451 __ Move(scratch, literal); | 427 __ Move(scratch, literal); |
| 452 } | 428 } |
| 453 return scratch; | 429 return scratch; |
| 454 } else if (op->IsStackSlot()) { | 430 } else if (op->IsStackSlot()) { |
| 455 __ ldr(scratch, ToMemOperand(op)); | 431 __ LoadP(scratch, ToMemOperand(op)); |
| 456 return scratch; | 432 return scratch; |
| 457 } | 433 } |
| 458 UNREACHABLE(); | 434 UNREACHABLE(); |
| 459 return scratch; | 435 return scratch; |
| 460 } | 436 } |
| 461 | 437 |
| 462 | 438 |
| 463 DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const { | 439 void LCodeGen::EmitLoadIntegerConstant(LConstantOperand* const_op, |
| 440 Register dst) { |
| 441 ASSERT(IsInteger32(const_op)); |
| 442 HConstant* constant = chunk_->LookupConstant(const_op); |
| 443 int32_t value = constant->Integer32Value(); |
| 444 if (IsSmi(const_op)) { |
| 445 __ LoadSmiLiteral(dst, Smi::FromInt(value)); |
| 446 } else { |
| 447 __ LoadIntLiteral(dst, value); |
| 448 } |
| 449 } |
| 450 |
| 451 |
| 452 DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 464 ASSERT(op->IsDoubleRegister()); | 453 ASSERT(op->IsDoubleRegister()); |
| 465 return ToDoubleRegister(op->index()); | 454 return ToDoubleRegister(op->index()); |
| 466 } | 455 } |
| 467 | 456 |
| 468 | 457 |
| 469 DwVfpRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, | |
| 470 SwVfpRegister flt_scratch, | |
| 471 DwVfpRegister dbl_scratch) { | |
| 472 if (op->IsDoubleRegister()) { | |
| 473 return ToDoubleRegister(op->index()); | |
| 474 } else if (op->IsConstantOperand()) { | |
| 475 LConstantOperand* const_op = LConstantOperand::cast(op); | |
| 476 HConstant* constant = chunk_->LookupConstant(const_op); | |
| 477 Handle<Object> literal = constant->handle(isolate()); | |
| 478 Representation r = chunk_->LookupLiteralRepresentation(const_op); | |
| 479 if (r.IsInteger32()) { | |
| 480 ASSERT(literal->IsNumber()); | |
| 481 __ mov(ip, Operand(static_cast<int32_t>(literal->Number()))); | |
| 482 __ vmov(flt_scratch, ip); | |
| 483 __ vcvt_f64_s32(dbl_scratch, flt_scratch); | |
| 484 return dbl_scratch; | |
| 485 } else if (r.IsDouble()) { | |
| 486 Abort(kUnsupportedDoubleImmediate); | |
| 487 } else if (r.IsTagged()) { | |
| 488 Abort(kUnsupportedTaggedImmediate); | |
| 489 } | |
| 490 } else if (op->IsStackSlot()) { | |
| 491 // TODO(regis): Why is vldr not taking a MemOperand? | |
| 492 // __ vldr(dbl_scratch, ToMemOperand(op)); | |
| 493 MemOperand mem_op = ToMemOperand(op); | |
| 494 __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset()); | |
| 495 return dbl_scratch; | |
| 496 } | |
| 497 UNREACHABLE(); | |
| 498 return dbl_scratch; | |
| 499 } | |
| 500 | |
| 501 | |
| 502 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { | 458 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
| 503 HConstant* constant = chunk_->LookupConstant(op); | 459 HConstant* constant = chunk_->LookupConstant(op); |
| 504 ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); | 460 ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
| 505 return constant->handle(isolate()); | 461 return constant->handle(isolate()); |
| 506 } | 462 } |
| 507 | 463 |
| 508 | 464 |
| 509 bool LCodeGen::IsInteger32(LConstantOperand* op) const { | 465 bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
| 510 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); | 466 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
| 511 } | 467 } |
| 512 | 468 |
| 513 | 469 |
| 514 bool LCodeGen::IsSmi(LConstantOperand* op) const { | 470 bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 515 return chunk_->LookupLiteralRepresentation(op).IsSmi(); | 471 return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 516 } | 472 } |
| 517 | 473 |
| 518 | 474 |
| 519 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { | 475 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 520 return ToRepresentation(op, Representation::Integer32()); | 476 return ToRepresentation(op, Representation::Integer32()); |
| 521 } | 477 } |
| 522 | 478 |
| 523 | 479 |
| 524 int32_t LCodeGen::ToRepresentation(LConstantOperand* op, | 480 intptr_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 525 const Representation& r) const { | 481 const Representation& r) const { |
| 526 HConstant* constant = chunk_->LookupConstant(op); | 482 HConstant* constant = chunk_->LookupConstant(op); |
| 527 int32_t value = constant->Integer32Value(); | 483 int32_t value = constant->Integer32Value(); |
| 528 if (r.IsInteger32()) return value; | 484 if (r.IsInteger32()) return value; |
| 529 ASSERT(r.IsSmiOrTagged()); | 485 ASSERT(r.IsSmiOrTagged()); |
| 530 return reinterpret_cast<int32_t>(Smi::FromInt(value)); | 486 return reinterpret_cast<intptr_t>(Smi::FromInt(value)); |
| 531 } | 487 } |
| 532 | 488 |
| 533 | 489 |
| 534 Smi* LCodeGen::ToSmi(LConstantOperand* op) const { | 490 Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
| 535 HConstant* constant = chunk_->LookupConstant(op); | 491 HConstant* constant = chunk_->LookupConstant(op); |
| 536 return Smi::FromInt(constant->Integer32Value()); | 492 return Smi::FromInt(constant->Integer32Value()); |
| 537 } | 493 } |
| 538 | 494 |
| 539 | 495 |
| 540 double LCodeGen::ToDouble(LConstantOperand* op) const { | 496 double LCodeGen::ToDouble(LConstantOperand* op) const { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 } else if (op->IsConstantOperand()) { | 678 } else if (op->IsConstantOperand()) { |
| 723 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); | 679 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
| 724 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); | 680 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
| 725 translation->StoreLiteral(src_index); | 681 translation->StoreLiteral(src_index); |
| 726 } else { | 682 } else { |
| 727 UNREACHABLE(); | 683 UNREACHABLE(); |
| 728 } | 684 } |
| 729 } | 685 } |
| 730 | 686 |
| 731 | 687 |
| 732 int LCodeGen::CallCodeSize(Handle<Code> code, RelocInfo::Mode mode) { | |
| 733 int size = masm()->CallSize(code, mode); | |
| 734 if (code->kind() == Code::BINARY_OP_IC || | |
| 735 code->kind() == Code::COMPARE_IC) { | |
| 736 size += Assembler::kInstrSize; // extra nop() added in CallCodeGeneric. | |
| 737 } | |
| 738 return size; | |
| 739 } | |
| 740 | |
| 741 | |
| 742 void LCodeGen::CallCode(Handle<Code> code, | 688 void LCodeGen::CallCode(Handle<Code> code, |
| 743 RelocInfo::Mode mode, | 689 RelocInfo::Mode mode, |
| 744 LInstruction* instr, | 690 LInstruction* instr) { |
| 745 TargetAddressStorageMode storage_mode) { | 691 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
| 746 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode); | |
| 747 } | 692 } |
| 748 | 693 |
| 749 | 694 |
| 750 void LCodeGen::CallCodeGeneric(Handle<Code> code, | 695 void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 751 RelocInfo::Mode mode, | 696 RelocInfo::Mode mode, |
| 752 LInstruction* instr, | 697 LInstruction* instr, |
| 753 SafepointMode safepoint_mode, | 698 SafepointMode safepoint_mode) { |
| 754 TargetAddressStorageMode storage_mode) { | |
| 755 ASSERT(instr != NULL); | 699 ASSERT(instr != NULL); |
| 756 // Block literal pool emission to ensure nop indicating no inlined smi code | 700 __ Call(code, mode); |
| 757 // is in the correct position. | |
| 758 Assembler::BlockConstPoolScope block_const_pool(masm()); | |
| 759 __ Call(code, mode, TypeFeedbackId::None(), al, storage_mode); | |
| 760 RecordSafepointWithLazyDeopt(instr, safepoint_mode); | 701 RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
| 761 | 702 |
| 762 // Signal that we don't inline smi code before these stubs in the | 703 // Signal that we don't inline smi code before these stubs in the |
| 763 // optimizing code generator. | 704 // optimizing code generator. |
| 764 if (code->kind() == Code::BINARY_OP_IC || | 705 if (code->kind() == Code::BINARY_OP_IC || |
| 765 code->kind() == Code::COMPARE_IC) { | 706 code->kind() == Code::COMPARE_IC) { |
| 766 __ nop(); | 707 __ nop(); |
| 767 } | 708 } |
| 768 } | 709 } |
| 769 | 710 |
| 770 | 711 |
| 771 void LCodeGen::CallRuntime(const Runtime::Function* function, | 712 void LCodeGen::CallRuntime(const Runtime::Function* function, |
| 772 int num_arguments, | 713 int num_arguments, |
| 773 LInstruction* instr, | 714 LInstruction* instr, |
| 774 SaveFPRegsMode save_doubles) { | 715 SaveFPRegsMode save_doubles) { |
| 775 ASSERT(instr != NULL); | 716 ASSERT(instr != NULL); |
| 776 | 717 |
| 777 __ CallRuntime(function, num_arguments, save_doubles); | 718 __ CallRuntime(function, num_arguments, save_doubles); |
| 778 | 719 |
| 779 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 720 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 780 } | 721 } |
| 781 | 722 |
| 782 | 723 |
| 783 void LCodeGen::LoadContextFromDeferred(LOperand* context) { | 724 void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
| 784 if (context->IsRegister()) { | 725 if (context->IsRegister()) { |
| 785 __ Move(cp, ToRegister(context)); | 726 __ Move(cp, ToRegister(context)); |
| 786 } else if (context->IsStackSlot()) { | 727 } else if (context->IsStackSlot()) { |
| 787 __ ldr(cp, ToMemOperand(context)); | 728 __ LoadP(cp, ToMemOperand(context)); |
| 788 } else if (context->IsConstantOperand()) { | 729 } else if (context->IsConstantOperand()) { |
| 789 HConstant* constant = | 730 HConstant* constant = |
| 790 chunk_->LookupConstant(LConstantOperand::cast(context)); | 731 chunk_->LookupConstant(LConstantOperand::cast(context)); |
| 791 __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); | 732 __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); |
| 792 } else { | 733 } else { |
| 793 UNREACHABLE(); | 734 UNREACHABLE(); |
| 794 } | 735 } |
| 795 } | 736 } |
| 796 | 737 |
| 797 | 738 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 int deoptimization_index = deoptimizations_.length(); | 777 int deoptimization_index = deoptimizations_.length(); |
| 837 int pc_offset = masm()->pc_offset(); | 778 int pc_offset = masm()->pc_offset(); |
| 838 environment->Register(deoptimization_index, | 779 environment->Register(deoptimization_index, |
| 839 translation.index(), | 780 translation.index(), |
| 840 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); | 781 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
| 841 deoptimizations_.Add(environment, zone()); | 782 deoptimizations_.Add(environment, zone()); |
| 842 } | 783 } |
| 843 } | 784 } |
| 844 | 785 |
| 845 | 786 |
| 846 void LCodeGen::DeoptimizeIf(Condition condition, | 787 void LCodeGen::DeoptimizeIf(Condition cond, |
| 847 LEnvironment* environment, | 788 LEnvironment* environment, |
| 848 Deoptimizer::BailoutType bailout_type) { | 789 Deoptimizer::BailoutType bailout_type, |
| 790 CRegister cr) { |
| 849 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 791 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 850 ASSERT(environment->HasBeenRegistered()); | 792 ASSERT(environment->HasBeenRegistered()); |
| 851 int id = environment->deoptimization_index(); | 793 int id = environment->deoptimization_index(); |
| 852 ASSERT(info()->IsOptimizing() || info()->IsStub()); | 794 ASSERT(info()->IsOptimizing() || info()->IsStub()); |
| 853 Address entry = | 795 Address entry = |
| 854 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); | 796 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
| 855 if (entry == NULL) { | 797 if (entry == NULL) { |
| 856 Abort(kBailoutWasNotPrepared); | 798 Abort(kBailoutWasNotPrepared); |
| 857 return; | 799 return; |
| 858 } | 800 } |
| 859 | 801 |
| 860 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { | 802 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { |
| 803 CRegister alt_cr = cr6; |
| 861 Register scratch = scratch0(); | 804 Register scratch = scratch0(); |
| 862 ExternalReference count = ExternalReference::stress_deopt_count(isolate()); | 805 ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 806 Label no_deopt; |
| 807 ASSERT(!alt_cr.is(cr)); |
| 808 __ Push(r4, scratch); |
| 809 __ mov(scratch, Operand(count)); |
| 810 __ lwz(r4, MemOperand(scratch)); |
| 811 __ subi(r4, r4, Operand(1)); |
| 812 __ cmpi(r4, Operand::Zero(), alt_cr); |
| 813 __ bne(&no_deopt, alt_cr); |
| 814 __ li(r4, Operand(FLAG_deopt_every_n_times)); |
| 815 __ stw(r4, MemOperand(scratch)); |
| 816 __ Pop(r4, scratch); |
| 863 | 817 |
| 864 // Store the condition on the stack if necessary | 818 __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
| 865 if (condition != al) { | 819 __ bind(&no_deopt); |
| 866 __ mov(scratch, Operand::Zero(), LeaveCC, NegateCondition(condition)); | 820 __ stw(r4, MemOperand(scratch)); |
| 867 __ mov(scratch, Operand(1), LeaveCC, condition); | 821 __ Pop(r4, scratch); |
| 868 __ push(scratch); | |
| 869 } | |
| 870 | |
| 871 __ push(r1); | |
| 872 __ mov(scratch, Operand(count)); | |
| 873 __ ldr(r1, MemOperand(scratch)); | |
| 874 __ sub(r1, r1, Operand(1), SetCC); | |
| 875 __ mov(r1, Operand(FLAG_deopt_every_n_times), LeaveCC, eq); | |
| 876 __ str(r1, MemOperand(scratch)); | |
| 877 __ pop(r1); | |
| 878 | |
| 879 if (condition != al) { | |
| 880 // Clean up the stack before the deoptimizer call | |
| 881 __ pop(scratch); | |
| 882 } | |
| 883 | |
| 884 __ Call(entry, RelocInfo::RUNTIME_ENTRY, eq); | |
| 885 | |
| 886 // 'Restore' the condition in a slightly hacky way. (It would be better | |
| 887 // to use 'msr' and 'mrs' instructions here, but they are not supported by | |
| 888 // our ARM simulator). | |
| 889 if (condition != al) { | |
| 890 condition = ne; | |
| 891 __ cmp(scratch, Operand::Zero()); | |
| 892 } | |
| 893 } | 822 } |
| 894 | 823 |
| 895 if (info()->ShouldTrapOnDeopt()) { | 824 if (info()->ShouldTrapOnDeopt()) { |
| 896 __ stop("trap_on_deopt", condition); | 825 __ stop("trap_on_deopt", cond, kDefaultStopCode, cr); |
| 897 } | 826 } |
| 898 | 827 |
| 899 ASSERT(info()->IsStub() || frame_is_built_); | 828 ASSERT(info()->IsStub() || frame_is_built_); |
| 900 // Go through jump table if we need to handle condition, build frame, or | 829 // Go through jump table if we need to handle condition, build frame, or |
| 901 // restore caller doubles. | 830 // restore caller doubles. |
| 902 if (condition == al && frame_is_built_ && | 831 if (cond == al && frame_is_built_ && |
| 903 !info()->saves_caller_doubles()) { | 832 !info()->saves_caller_doubles()) { |
| 904 __ Call(entry, RelocInfo::RUNTIME_ENTRY); | 833 __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
| 905 } else { | 834 } else { |
| 906 // We often have several deopts to the same entry, reuse the last | 835 // We often have several deopts to the same entry, reuse the last |
| 907 // jump entry if this is the case. | 836 // jump entry if this is the case. |
| 908 if (deopt_jump_table_.is_empty() || | 837 if (deopt_jump_table_.is_empty() || |
| 909 (deopt_jump_table_.last().address != entry) || | 838 (deopt_jump_table_.last().address != entry) || |
| 910 (deopt_jump_table_.last().bailout_type != bailout_type) || | 839 (deopt_jump_table_.last().bailout_type != bailout_type) || |
| 911 (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { | 840 (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
| 912 Deoptimizer::JumpTableEntry table_entry(entry, | 841 Deoptimizer::JumpTableEntry table_entry(entry, |
| 913 bailout_type, | 842 bailout_type, |
| 914 !frame_is_built_); | 843 !frame_is_built_); |
| 915 deopt_jump_table_.Add(table_entry, zone()); | 844 deopt_jump_table_.Add(table_entry, zone()); |
| 916 } | 845 } |
| 917 __ b(condition, &deopt_jump_table_.last().label); | 846 __ b(cond, &deopt_jump_table_.last().label, cr); |
| 918 } | 847 } |
| 919 } | 848 } |
| 920 | 849 |
| 921 | 850 |
| 922 void LCodeGen::DeoptimizeIf(Condition condition, | 851 void LCodeGen::DeoptimizeIf(Condition cond, |
| 923 LEnvironment* environment) { | 852 LEnvironment* environment, |
| 853 CRegister cr) { |
| 924 Deoptimizer::BailoutType bailout_type = info()->IsStub() | 854 Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 925 ? Deoptimizer::LAZY | 855 ? Deoptimizer::LAZY |
| 926 : Deoptimizer::EAGER; | 856 : Deoptimizer::EAGER; |
| 927 DeoptimizeIf(condition, environment, bailout_type); | 857 DeoptimizeIf(cond, environment, bailout_type, cr); |
| 928 } | 858 } |
| 929 | 859 |
| 930 | 860 |
| 931 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { | 861 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 932 int length = deoptimizations_.length(); | 862 int length = deoptimizations_.length(); |
| 933 if (length == 0) return; | 863 if (length == 0) return; |
| 934 Handle<DeoptimizationInputData> data = | 864 Handle<DeoptimizationInputData> data = |
| 935 DeoptimizationInputData::New(isolate(), length, TENURED); | 865 DeoptimizationInputData::New(isolate(), length, TENURED); |
| 936 | 866 |
| 937 Handle<ByteArray> translations = | 867 Handle<ByteArray> translations = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 Safepoint safepoint = safepoints_.DefineSafepoint(masm(), | 951 Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
| 1022 kind, arguments, deopt_mode); | 952 kind, arguments, deopt_mode); |
| 1023 for (int i = 0; i < operands->length(); i++) { | 953 for (int i = 0; i < operands->length(); i++) { |
| 1024 LOperand* pointer = operands->at(i); | 954 LOperand* pointer = operands->at(i); |
| 1025 if (pointer->IsStackSlot()) { | 955 if (pointer->IsStackSlot()) { |
| 1026 safepoint.DefinePointerSlot(pointer->index(), zone()); | 956 safepoint.DefinePointerSlot(pointer->index(), zone()); |
| 1027 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { | 957 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
| 1028 safepoint.DefinePointerRegister(ToRegister(pointer), zone()); | 958 safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
| 1029 } | 959 } |
| 1030 } | 960 } |
| 1031 if (FLAG_enable_ool_constant_pool && (kind & Safepoint::kWithRegisters)) { | 961 #if V8_OOL_CONSTANT_POOL |
| 1032 // Register pp always contains a pointer to the constant pool. | 962 if (kind & Safepoint::kWithRegisters) { |
| 1033 safepoint.DefinePointerRegister(pp, zone()); | 963 // Register always contains a pointer to the constant pool. |
| 964 safepoint.DefinePointerRegister(kConstantPoolRegister, zone()); |
| 1034 } | 965 } |
| 966 #endif |
| 1035 } | 967 } |
| 1036 | 968 |
| 1037 | 969 |
| 1038 void LCodeGen::RecordSafepoint(LPointerMap* pointers, | 970 void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
| 1039 Safepoint::DeoptMode deopt_mode) { | 971 Safepoint::DeoptMode deopt_mode) { |
| 1040 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); | 972 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
| 1041 } | 973 } |
| 1042 | 974 |
| 1043 | 975 |
| 1044 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { | 976 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 } | 1034 } |
| 1103 | 1035 |
| 1104 | 1036 |
| 1105 void LCodeGen::DoParameter(LParameter* instr) { | 1037 void LCodeGen::DoParameter(LParameter* instr) { |
| 1106 // Nothing to do. | 1038 // Nothing to do. |
| 1107 } | 1039 } |
| 1108 | 1040 |
| 1109 | 1041 |
| 1110 void LCodeGen::DoCallStub(LCallStub* instr) { | 1042 void LCodeGen::DoCallStub(LCallStub* instr) { |
| 1111 ASSERT(ToRegister(instr->context()).is(cp)); | 1043 ASSERT(ToRegister(instr->context()).is(cp)); |
| 1112 ASSERT(ToRegister(instr->result()).is(r0)); | 1044 ASSERT(ToRegister(instr->result()).is(r3)); |
| 1113 switch (instr->hydrogen()->major_key()) { | 1045 switch (instr->hydrogen()->major_key()) { |
| 1114 case CodeStub::RegExpExec: { | 1046 case CodeStub::RegExpExec: { |
| 1115 RegExpExecStub stub(isolate()); | 1047 RegExpExecStub stub(isolate()); |
| 1116 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 1048 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 1117 break; | 1049 break; |
| 1118 } | 1050 } |
| 1119 case CodeStub::SubString: { | 1051 case CodeStub::SubString: { |
| 1120 SubStringStub stub(isolate()); | 1052 SubStringStub stub(isolate()); |
| 1121 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 1053 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 1122 break; | 1054 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1142 int32_t divisor = instr->divisor(); | 1074 int32_t divisor = instr->divisor(); |
| 1143 ASSERT(dividend.is(ToRegister(instr->result()))); | 1075 ASSERT(dividend.is(ToRegister(instr->result()))); |
| 1144 | 1076 |
| 1145 // Theoretically, a variation of the branch-free code for integer division by | 1077 // Theoretically, a variation of the branch-free code for integer division by |
| 1146 // a power of 2 (calculating the remainder via an additional multiplication | 1078 // a power of 2 (calculating the remainder via an additional multiplication |
| 1147 // (which gets simplified to an 'and') and subtraction) should be faster, and | 1079 // (which gets simplified to an 'and') and subtraction) should be faster, and |
| 1148 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to | 1080 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
| 1149 // indicate that positive dividends are heavily favored, so the branching | 1081 // indicate that positive dividends are heavily favored, so the branching |
| 1150 // version performs better. | 1082 // version performs better. |
| 1151 HMod* hmod = instr->hydrogen(); | 1083 HMod* hmod = instr->hydrogen(); |
| 1152 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1084 int32_t shift = WhichPowerOf2Abs(divisor); |
| 1153 Label dividend_is_not_negative, done; | 1085 Label dividend_is_not_negative, done; |
| 1154 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { | 1086 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
| 1155 __ cmp(dividend, Operand::Zero()); | 1087 __ cmpwi(dividend, Operand::Zero()); |
| 1156 __ b(pl, ÷nd_is_not_negative); | 1088 __ bge(÷nd_is_not_negative); |
| 1157 // Note that this is correct even for kMinInt operands. | 1089 if (shift) { |
| 1158 __ rsb(dividend, dividend, Operand::Zero()); | 1090 // Note that this is correct even for kMinInt operands. |
| 1159 __ and_(dividend, dividend, Operand(mask)); | 1091 __ neg(dividend, dividend); |
| 1160 __ rsb(dividend, dividend, Operand::Zero(), SetCC); | 1092 __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
| 1161 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1093 __ neg(dividend, dividend, LeaveOE, SetRC); |
| 1162 DeoptimizeIf(eq, instr->environment()); | 1094 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1095 DeoptimizeIf(eq, instr->environment(), cr0); |
| 1096 } |
| 1097 } else if (!hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1098 __ li(dividend, Operand::Zero()); |
| 1099 } else { |
| 1100 DeoptimizeIf(al, instr->environment()); |
| 1163 } | 1101 } |
| 1164 __ b(&done); | 1102 __ b(&done); |
| 1165 } | 1103 } |
| 1166 | 1104 |
| 1167 __ bind(÷nd_is_not_negative); | 1105 __ bind(÷nd_is_not_negative); |
| 1168 __ and_(dividend, dividend, Operand(mask)); | 1106 if (shift) { |
| 1107 __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
| 1108 } else { |
| 1109 __ li(dividend, Operand::Zero()); |
| 1110 } |
| 1169 __ bind(&done); | 1111 __ bind(&done); |
| 1170 } | 1112 } |
| 1171 | 1113 |
| 1172 | 1114 |
| 1173 void LCodeGen::DoModByConstI(LModByConstI* instr) { | 1115 void LCodeGen::DoModByConstI(LModByConstI* instr) { |
| 1174 Register dividend = ToRegister(instr->dividend()); | 1116 Register dividend = ToRegister(instr->dividend()); |
| 1175 int32_t divisor = instr->divisor(); | 1117 int32_t divisor = instr->divisor(); |
| 1176 Register result = ToRegister(instr->result()); | 1118 Register result = ToRegister(instr->result()); |
| 1177 ASSERT(!dividend.is(result)); | 1119 ASSERT(!dividend.is(result)); |
| 1178 | 1120 |
| 1179 if (divisor == 0) { | 1121 if (divisor == 0) { |
| 1180 DeoptimizeIf(al, instr->environment()); | 1122 DeoptimizeIf(al, instr->environment()); |
| 1181 return; | 1123 return; |
| 1182 } | 1124 } |
| 1183 | 1125 |
| 1184 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1126 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1185 __ mov(ip, Operand(Abs(divisor))); | 1127 __ mov(ip, Operand(Abs(divisor))); |
| 1186 __ smull(result, ip, result, ip); | 1128 __ mullw(result, result, ip); |
| 1187 __ sub(result, dividend, result, SetCC); | 1129 __ sub(result, dividend, result, LeaveOE, SetRC); |
| 1188 | 1130 |
| 1189 // Check for negative zero. | 1131 // Check for negative zero. |
| 1190 HMod* hmod = instr->hydrogen(); | 1132 HMod* hmod = instr->hydrogen(); |
| 1191 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1133 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1192 Label remainder_not_zero; | 1134 Label remainder_not_zero; |
| 1193 __ b(ne, &remainder_not_zero); | 1135 __ bne(&remainder_not_zero, cr0); |
| 1194 __ cmp(dividend, Operand::Zero()); | 1136 __ cmpwi(dividend, Operand::Zero()); |
| 1195 DeoptimizeIf(lt, instr->environment()); | 1137 DeoptimizeIf(lt, instr->environment()); |
| 1196 __ bind(&remainder_not_zero); | 1138 __ bind(&remainder_not_zero); |
| 1197 } | 1139 } |
| 1198 } | 1140 } |
| 1199 | 1141 |
| 1200 | 1142 |
| 1201 void LCodeGen::DoModI(LModI* instr) { | 1143 void LCodeGen::DoModI(LModI* instr) { |
| 1202 HMod* hmod = instr->hydrogen(); | 1144 HMod* hmod = instr->hydrogen(); |
| 1203 if (CpuFeatures::IsSupported(SUDIV)) { | 1145 Register left_reg = ToRegister(instr->left()); |
| 1204 CpuFeatureScope scope(masm(), SUDIV); | 1146 Register right_reg = ToRegister(instr->right()); |
| 1147 Register result_reg = ToRegister(instr->result()); |
| 1148 Register scratch = scratch0(); |
| 1149 Label done; |
| 1205 | 1150 |
| 1206 Register left_reg = ToRegister(instr->left()); | 1151 if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 1207 Register right_reg = ToRegister(instr->right()); | 1152 __ li(r0, Operand::Zero()); // clear xer |
| 1208 Register result_reg = ToRegister(instr->result()); | 1153 __ mtxer(r0); |
| 1154 } |
| 1209 | 1155 |
| 1210 Label done; | 1156 __ divw(scratch, left_reg, right_reg, SetOE, SetRC); |
| 1211 // Check for x % 0, sdiv might signal an exception. We have to deopt in this | 1157 |
| 1212 // case because we can't return a NaN. | 1158 // Check for x % 0. |
| 1213 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { | 1159 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1214 __ cmp(right_reg, Operand::Zero()); | 1160 __ cmpwi(right_reg, Operand::Zero()); |
| 1215 DeoptimizeIf(eq, instr->environment()); | 1161 DeoptimizeIf(eq, instr->environment()); |
| 1162 } |
| 1163 |
| 1164 // Check for kMinInt % -1, divw will return undefined, which is not what we |
| 1165 // want. We have to deopt if we care about -0, because we can't return that. |
| 1166 if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 1167 Label no_overflow_possible; |
| 1168 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1169 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1170 } else { |
| 1171 __ bnooverflow(&no_overflow_possible, cr0); |
| 1172 __ li(result_reg, Operand::Zero()); |
| 1173 __ b(&done); |
| 1216 } | 1174 } |
| 1175 __ bind(&no_overflow_possible); |
| 1176 } |
| 1217 | 1177 |
| 1218 // Check for kMinInt % -1, sdiv will return kMinInt, which is not what we | 1178 __ mullw(scratch, right_reg, scratch); |
| 1219 // want. We have to deopt if we care about -0, because we can't return that. | 1179 __ sub(result_reg, left_reg, scratch, LeaveOE, SetRC); |
| 1220 if (hmod->CheckFlag(HValue::kCanOverflow)) { | |
| 1221 Label no_overflow_possible; | |
| 1222 __ cmp(left_reg, Operand(kMinInt)); | |
| 1223 __ b(ne, &no_overflow_possible); | |
| 1224 __ cmp(right_reg, Operand(-1)); | |
| 1225 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1226 DeoptimizeIf(eq, instr->environment()); | |
| 1227 } else { | |
| 1228 __ b(ne, &no_overflow_possible); | |
| 1229 __ mov(result_reg, Operand::Zero()); | |
| 1230 __ jmp(&done); | |
| 1231 } | |
| 1232 __ bind(&no_overflow_possible); | |
| 1233 } | |
| 1234 | 1180 |
| 1235 // For 'r3 = r1 % r2' we can have the following ARM code: | 1181 // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1236 // sdiv r3, r1, r2 | 1182 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1237 // mls r3, r3, r2, r1 | 1183 __ bne(&done, cr0); |
| 1184 __ cmpwi(left_reg, Operand::Zero()); |
| 1185 DeoptimizeIf(lt, instr->environment()); |
| 1186 } |
| 1238 | 1187 |
| 1239 __ sdiv(result_reg, left_reg, right_reg); | 1188 __ bind(&done); |
| 1240 __ Mls(result_reg, result_reg, right_reg, left_reg); | |
| 1241 | |
| 1242 // If we care about -0, test if the dividend is <0 and the result is 0. | |
| 1243 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1244 __ cmp(result_reg, Operand::Zero()); | |
| 1245 __ b(ne, &done); | |
| 1246 __ cmp(left_reg, Operand::Zero()); | |
| 1247 DeoptimizeIf(lt, instr->environment()); | |
| 1248 } | |
| 1249 __ bind(&done); | |
| 1250 | |
| 1251 } else { | |
| 1252 // General case, without any SDIV support. | |
| 1253 Register left_reg = ToRegister(instr->left()); | |
| 1254 Register right_reg = ToRegister(instr->right()); | |
| 1255 Register result_reg = ToRegister(instr->result()); | |
| 1256 Register scratch = scratch0(); | |
| 1257 ASSERT(!scratch.is(left_reg)); | |
| 1258 ASSERT(!scratch.is(right_reg)); | |
| 1259 ASSERT(!scratch.is(result_reg)); | |
| 1260 DwVfpRegister dividend = ToDoubleRegister(instr->temp()); | |
| 1261 DwVfpRegister divisor = ToDoubleRegister(instr->temp2()); | |
| 1262 ASSERT(!divisor.is(dividend)); | |
| 1263 LowDwVfpRegister quotient = double_scratch0(); | |
| 1264 ASSERT(!quotient.is(dividend)); | |
| 1265 ASSERT(!quotient.is(divisor)); | |
| 1266 | |
| 1267 Label done; | |
| 1268 // Check for x % 0, we have to deopt in this case because we can't return a | |
| 1269 // NaN. | |
| 1270 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { | |
| 1271 __ cmp(right_reg, Operand::Zero()); | |
| 1272 DeoptimizeIf(eq, instr->environment()); | |
| 1273 } | |
| 1274 | |
| 1275 __ Move(result_reg, left_reg); | |
| 1276 // Load the arguments in VFP registers. The divisor value is preloaded | |
| 1277 // before. Be careful that 'right_reg' is only live on entry. | |
| 1278 // TODO(svenpanne) The last comments seems to be wrong nowadays. | |
| 1279 __ vmov(double_scratch0().low(), left_reg); | |
| 1280 __ vcvt_f64_s32(dividend, double_scratch0().low()); | |
| 1281 __ vmov(double_scratch0().low(), right_reg); | |
| 1282 __ vcvt_f64_s32(divisor, double_scratch0().low()); | |
| 1283 | |
| 1284 // We do not care about the sign of the divisor. Note that we still handle | |
| 1285 // the kMinInt % -1 case correctly, though. | |
| 1286 __ vabs(divisor, divisor); | |
| 1287 // Compute the quotient and round it to a 32bit integer. | |
| 1288 __ vdiv(quotient, dividend, divisor); | |
| 1289 __ vcvt_s32_f64(quotient.low(), quotient); | |
| 1290 __ vcvt_f64_s32(quotient, quotient.low()); | |
| 1291 | |
| 1292 // Compute the remainder in result. | |
| 1293 __ vmul(double_scratch0(), divisor, quotient); | |
| 1294 __ vcvt_s32_f64(double_scratch0().low(), double_scratch0()); | |
| 1295 __ vmov(scratch, double_scratch0().low()); | |
| 1296 __ sub(result_reg, left_reg, scratch, SetCC); | |
| 1297 | |
| 1298 // If we care about -0, test if the dividend is <0 and the result is 0. | |
| 1299 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
| 1300 __ b(ne, &done); | |
| 1301 __ cmp(left_reg, Operand::Zero()); | |
| 1302 DeoptimizeIf(mi, instr->environment()); | |
| 1303 } | |
| 1304 __ bind(&done); | |
| 1305 } | |
| 1306 } | 1189 } |
| 1307 | 1190 |
| 1308 | 1191 |
| 1309 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { | 1192 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
| 1310 Register dividend = ToRegister(instr->dividend()); | 1193 Register dividend = ToRegister(instr->dividend()); |
| 1311 int32_t divisor = instr->divisor(); | 1194 int32_t divisor = instr->divisor(); |
| 1312 Register result = ToRegister(instr->result()); | 1195 Register result = ToRegister(instr->result()); |
| 1313 ASSERT(divisor == kMinInt || IsPowerOf2(Abs(divisor))); | 1196 ASSERT(divisor == kMinInt || IsPowerOf2(Abs(divisor))); |
| 1314 ASSERT(!result.is(dividend)); | 1197 ASSERT(!result.is(dividend)); |
| 1315 | 1198 |
| 1316 // Check for (0 / -x) that will produce negative zero. | 1199 // Check for (0 / -x) that will produce negative zero. |
| 1317 HDiv* hdiv = instr->hydrogen(); | 1200 HDiv* hdiv = instr->hydrogen(); |
| 1318 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1201 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1319 __ cmp(dividend, Operand::Zero()); | 1202 __ cmpwi(dividend, Operand::Zero()); |
| 1320 DeoptimizeIf(eq, instr->environment()); | 1203 DeoptimizeIf(eq, instr->environment()); |
| 1321 } | 1204 } |
| 1322 // Check for (kMinInt / -1). | 1205 // Check for (kMinInt / -1). |
| 1323 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { | 1206 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
| 1324 __ cmp(dividend, Operand(kMinInt)); | 1207 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 1208 __ cmpw(dividend, r0); |
| 1325 DeoptimizeIf(eq, instr->environment()); | 1209 DeoptimizeIf(eq, instr->environment()); |
| 1326 } | 1210 } |
| 1211 |
| 1212 int32_t shift = WhichPowerOf2Abs(divisor); |
| 1213 |
| 1327 // Deoptimize if remainder will not be 0. | 1214 // Deoptimize if remainder will not be 0. |
| 1328 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | 1215 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && shift) { |
| 1329 divisor != 1 && divisor != -1) { | 1216 __ TestBitRange(dividend, shift - 1, 0, r0); |
| 1330 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1217 DeoptimizeIf(ne, instr->environment(), cr0); |
| 1331 __ tst(dividend, Operand(mask)); | |
| 1332 DeoptimizeIf(ne, instr->environment()); | |
| 1333 } | 1218 } |
| 1334 | 1219 |
| 1335 if (divisor == -1) { // Nice shortcut, not needed for correctness. | 1220 if (divisor == -1) { // Nice shortcut, not needed for correctness. |
| 1336 __ rsb(result, dividend, Operand(0)); | 1221 __ neg(result, dividend); |
| 1337 return; | 1222 return; |
| 1338 } | 1223 } |
| 1339 int32_t shift = WhichPowerOf2Abs(divisor); | |
| 1340 if (shift == 0) { | 1224 if (shift == 0) { |
| 1341 __ mov(result, dividend); | 1225 __ mr(result, dividend); |
| 1342 } else if (shift == 1) { | 1226 } else { |
| 1343 __ add(result, dividend, Operand(dividend, LSR, 31)); | 1227 if (shift == 1) { |
| 1344 } else { | 1228 __ srwi(result, dividend, Operand(31)); |
| 1345 __ mov(result, Operand(dividend, ASR, 31)); | 1229 } else { |
| 1346 __ add(result, dividend, Operand(result, LSR, 32 - shift)); | 1230 __ srawi(result, dividend, 31); |
| 1231 __ srwi(result, result, Operand(32 - shift)); |
| 1232 } |
| 1233 __ add(result, dividend, result); |
| 1234 __ srawi(result, result, shift); |
| 1347 } | 1235 } |
| 1348 if (shift > 0) __ mov(result, Operand(result, ASR, shift)); | 1236 if (divisor < 0) __ neg(result, result); |
| 1349 if (divisor < 0) __ rsb(result, result, Operand(0)); | |
| 1350 } | 1237 } |
| 1351 | 1238 |
| 1352 | 1239 |
| 1353 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { | 1240 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
| 1354 Register dividend = ToRegister(instr->dividend()); | 1241 Register dividend = ToRegister(instr->dividend()); |
| 1355 int32_t divisor = instr->divisor(); | 1242 int32_t divisor = instr->divisor(); |
| 1356 Register result = ToRegister(instr->result()); | 1243 Register result = ToRegister(instr->result()); |
| 1357 ASSERT(!dividend.is(result)); | 1244 ASSERT(!dividend.is(result)); |
| 1358 | 1245 |
| 1359 if (divisor == 0) { | 1246 if (divisor == 0) { |
| 1360 DeoptimizeIf(al, instr->environment()); | 1247 DeoptimizeIf(al, instr->environment()); |
| 1361 return; | 1248 return; |
| 1362 } | 1249 } |
| 1363 | 1250 |
| 1364 // Check for (0 / -x) that will produce negative zero. | 1251 // Check for (0 / -x) that will produce negative zero. |
| 1365 HDiv* hdiv = instr->hydrogen(); | 1252 HDiv* hdiv = instr->hydrogen(); |
| 1366 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1253 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1367 __ cmp(dividend, Operand::Zero()); | 1254 __ cmpwi(dividend, Operand::Zero()); |
| 1368 DeoptimizeIf(eq, instr->environment()); | 1255 DeoptimizeIf(eq, instr->environment()); |
| 1369 } | 1256 } |
| 1370 | 1257 |
| 1371 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1258 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1372 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1259 if (divisor < 0) __ neg(result, result); |
| 1373 | 1260 |
| 1374 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1261 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1262 Register scratch = scratch0(); |
| 1375 __ mov(ip, Operand(divisor)); | 1263 __ mov(ip, Operand(divisor)); |
| 1376 __ smull(scratch0(), ip, result, ip); | 1264 __ mullw(scratch, result, ip); |
| 1377 __ sub(scratch0(), scratch0(), dividend, SetCC); | 1265 __ cmpw(scratch, dividend); |
| 1378 DeoptimizeIf(ne, instr->environment()); | 1266 DeoptimizeIf(ne, instr->environment()); |
| 1379 } | 1267 } |
| 1380 } | 1268 } |
| 1381 | 1269 |
| 1382 | 1270 |
| 1383 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. | 1271 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
| 1384 void LCodeGen::DoDivI(LDivI* instr) { | 1272 void LCodeGen::DoDivI(LDivI* instr) { |
| 1385 HBinaryOperation* hdiv = instr->hydrogen(); | 1273 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1386 Register dividend = ToRegister(instr->dividend()); | 1274 const Register dividend = ToRegister(instr->dividend()); |
| 1387 Register divisor = ToRegister(instr->divisor()); | 1275 const Register divisor = ToRegister(instr->divisor()); |
| 1388 Register result = ToRegister(instr->result()); | 1276 Register result = ToRegister(instr->result()); |
| 1389 | 1277 |
| 1278 ASSERT(!dividend.is(result)); |
| 1279 ASSERT(!divisor.is(result)); |
| 1280 |
| 1281 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1282 __ li(r0, Operand::Zero()); // clear xer |
| 1283 __ mtxer(r0); |
| 1284 } |
| 1285 |
| 1286 __ divw(result, dividend, divisor, SetOE, SetRC); |
| 1287 |
| 1390 // Check for x / 0. | 1288 // Check for x / 0. |
| 1391 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1289 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1392 __ cmp(divisor, Operand::Zero()); | 1290 __ cmpwi(divisor, Operand::Zero()); |
| 1393 DeoptimizeIf(eq, instr->environment()); | 1291 DeoptimizeIf(eq, instr->environment()); |
| 1394 } | 1292 } |
| 1395 | 1293 |
| 1396 // Check for (0 / -x) that will produce negative zero. | 1294 // Check for (0 / -x) that will produce negative zero. |
| 1397 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1295 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1398 Label positive; | 1296 Label dividend_not_zero; |
| 1399 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { | 1297 __ cmpwi(dividend, Operand::Zero()); |
| 1400 // Do the test only if it hadn't be done above. | 1298 __ bne(÷nd_not_zero); |
| 1401 __ cmp(divisor, Operand::Zero()); | 1299 __ cmpwi(divisor, Operand::Zero()); |
| 1402 } | 1300 DeoptimizeIf(lt, instr->environment()); |
| 1403 __ b(pl, &positive); | 1301 __ bind(÷nd_not_zero); |
| 1404 __ cmp(dividend, Operand::Zero()); | |
| 1405 DeoptimizeIf(eq, instr->environment()); | |
| 1406 __ bind(&positive); | |
| 1407 } | 1302 } |
| 1408 | 1303 |
| 1409 // Check for (kMinInt / -1). | 1304 // Check for (kMinInt / -1). |
| 1410 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1305 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1411 (!CpuFeatures::IsSupported(SUDIV) || | 1306 Label no_overflow_possible; |
| 1412 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { | 1307 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1413 // We don't need to check for overflow when truncating with sdiv | 1308 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1414 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. | 1309 } else { |
| 1415 __ cmp(dividend, Operand(kMinInt)); | 1310 // When truncating, we want kMinInt / -1 = kMinInt. |
| 1416 __ cmp(divisor, Operand(-1), eq); | 1311 __ bnooverflow(&no_overflow_possible, cr0); |
| 1417 DeoptimizeIf(eq, instr->environment()); | 1312 __ mr(result, dividend); |
| 1313 } |
| 1314 __ bind(&no_overflow_possible); |
| 1418 } | 1315 } |
| 1419 | 1316 |
| 1420 if (CpuFeatures::IsSupported(SUDIV)) { | 1317 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1421 CpuFeatureScope scope(masm(), SUDIV); | 1318 // Deoptimize if remainder is not 0. |
| 1422 __ sdiv(result, dividend, divisor); | 1319 Register scratch = scratch0(); |
| 1423 } else { | 1320 __ mullw(scratch, divisor, result); |
| 1424 DoubleRegister vleft = ToDoubleRegister(instr->temp()); | 1321 __ cmpw(dividend, scratch); |
| 1425 DoubleRegister vright = double_scratch0(); | |
| 1426 __ vmov(double_scratch0().low(), dividend); | |
| 1427 __ vcvt_f64_s32(vleft, double_scratch0().low()); | |
| 1428 __ vmov(double_scratch0().low(), divisor); | |
| 1429 __ vcvt_f64_s32(vright, double_scratch0().low()); | |
| 1430 __ vdiv(vleft, vleft, vright); // vleft now contains the result. | |
| 1431 __ vcvt_s32_f64(double_scratch0().low(), vleft); | |
| 1432 __ vmov(result, double_scratch0().low()); | |
| 1433 } | |
| 1434 | |
| 1435 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { | |
| 1436 // Compute remainder and deopt if it's not zero. | |
| 1437 Register remainder = scratch0(); | |
| 1438 __ Mls(remainder, result, divisor, dividend); | |
| 1439 __ cmp(remainder, Operand::Zero()); | |
| 1440 DeoptimizeIf(ne, instr->environment()); | 1322 DeoptimizeIf(ne, instr->environment()); |
| 1441 } | 1323 } |
| 1442 } | 1324 } |
| 1443 | 1325 |
| 1444 | 1326 |
| 1445 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { | |
| 1446 DwVfpRegister addend = ToDoubleRegister(instr->addend()); | |
| 1447 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); | |
| 1448 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); | |
| 1449 | |
| 1450 // This is computed in-place. | |
| 1451 ASSERT(addend.is(ToDoubleRegister(instr->result()))); | |
| 1452 | |
| 1453 __ vmla(addend, multiplier, multiplicand); | |
| 1454 } | |
| 1455 | |
| 1456 | |
| 1457 void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { | |
| 1458 DwVfpRegister minuend = ToDoubleRegister(instr->minuend()); | |
| 1459 DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); | |
| 1460 DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); | |
| 1461 | |
| 1462 // This is computed in-place. | |
| 1463 ASSERT(minuend.is(ToDoubleRegister(instr->result()))); | |
| 1464 | |
| 1465 __ vmls(minuend, multiplier, multiplicand); | |
| 1466 } | |
| 1467 | |
| 1468 | |
| 1469 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { | 1327 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1328 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1470 Register dividend = ToRegister(instr->dividend()); | 1329 Register dividend = ToRegister(instr->dividend()); |
| 1471 Register result = ToRegister(instr->result()); | 1330 Register result = ToRegister(instr->result()); |
| 1472 int32_t divisor = instr->divisor(); | 1331 int32_t divisor = instr->divisor(); |
| 1473 | 1332 |
| 1474 // If the divisor is 1, return the dividend. | |
| 1475 if (divisor == 1) { | |
| 1476 __ Move(result, dividend); | |
| 1477 return; | |
| 1478 } | |
| 1479 | |
| 1480 // If the divisor is positive, things are easy: There can be no deopts and we | 1333 // If the divisor is positive, things are easy: There can be no deopts and we |
| 1481 // can simply do an arithmetic right shift. | 1334 // can simply do an arithmetic right shift. |
| 1482 int32_t shift = WhichPowerOf2Abs(divisor); | 1335 int32_t shift = WhichPowerOf2Abs(divisor); |
| 1483 if (divisor > 1) { | 1336 if (divisor > 0) { |
| 1484 __ mov(result, Operand(dividend, ASR, shift)); | 1337 if (shift || !result.is(dividend)) { |
| 1338 __ srawi(result, dividend, shift); |
| 1339 } |
| 1485 return; | 1340 return; |
| 1486 } | 1341 } |
| 1487 | 1342 |
| 1488 // If the divisor is negative, we have to negate and handle edge cases. | 1343 // If the divisor is negative, we have to negate and handle edge cases. |
| 1489 __ rsb(result, dividend, Operand::Zero(), SetCC); | 1344 OEBit oe = LeaveOE; |
| 1490 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1345 #if V8_TARGET_ARCH_PPC64 |
| 1346 if (divisor == -1 && hdiv->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1347 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 1348 __ cmpw(dividend, r0); |
| 1491 DeoptimizeIf(eq, instr->environment()); | 1349 DeoptimizeIf(eq, instr->environment()); |
| 1492 } | 1350 } |
| 1351 #else |
| 1352 if (hdiv->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1353 __ li(r0, Operand::Zero()); // clear xer |
| 1354 __ mtxer(r0); |
| 1355 oe = SetOE; |
| 1356 } |
| 1357 #endif |
| 1358 |
| 1359 __ neg(result, dividend, oe, SetRC); |
| 1360 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1361 DeoptimizeIf(eq, instr->environment(), cr0); |
| 1362 } |
| 1363 |
| 1364 // If the negation could not overflow, simply shifting is OK. |
| 1365 #if !V8_TARGET_ARCH_PPC64 |
| 1366 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1367 #endif |
| 1368 if (shift) { |
| 1369 __ ShiftRightArithImm(result, result, shift); |
| 1370 } |
| 1371 return; |
| 1372 #if !V8_TARGET_ARCH_PPC64 |
| 1373 } |
| 1493 | 1374 |
| 1494 // Dividing by -1 is basically negation, unless we overflow. | 1375 // Dividing by -1 is basically negation, unless we overflow. |
| 1495 if (divisor == -1) { | 1376 if (divisor == -1) { |
| 1496 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | 1377 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1497 DeoptimizeIf(vs, instr->environment()); | |
| 1498 } | |
| 1499 return; | 1378 return; |
| 1500 } | 1379 } |
| 1501 | 1380 |
| 1502 // If the negation could not overflow, simply shifting is OK. | 1381 Label overflow, done; |
| 1503 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | 1382 __ boverflow(&overflow, cr0); |
| 1504 __ mov(result, Operand(result, ASR, shift)); | 1383 __ srawi(result, result, shift); |
| 1505 return; | 1384 __ b(&done); |
| 1506 } | 1385 __ bind(&overflow); |
| 1507 | 1386 __ mov(result, Operand(kMinInt / divisor)); |
| 1508 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs); | 1387 __ bind(&done); |
| 1509 __ mov(result, Operand(result, ASR, shift), LeaveCC, vc); | 1388 #endif |
| 1510 } | 1389 } |
| 1511 | 1390 |
| 1512 | 1391 |
| 1513 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | 1392 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
| 1514 Register dividend = ToRegister(instr->dividend()); | 1393 Register dividend = ToRegister(instr->dividend()); |
| 1515 int32_t divisor = instr->divisor(); | 1394 int32_t divisor = instr->divisor(); |
| 1516 Register result = ToRegister(instr->result()); | 1395 Register result = ToRegister(instr->result()); |
| 1517 ASSERT(!dividend.is(result)); | 1396 ASSERT(!dividend.is(result)); |
| 1518 | 1397 |
| 1519 if (divisor == 0) { | 1398 if (divisor == 0) { |
| 1520 DeoptimizeIf(al, instr->environment()); | 1399 DeoptimizeIf(al, instr->environment()); |
| 1521 return; | 1400 return; |
| 1522 } | 1401 } |
| 1523 | 1402 |
| 1524 // Check for (0 / -x) that will produce negative zero. | 1403 // Check for (0 / -x) that will produce negative zero. |
| 1525 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1404 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
| 1526 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1405 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1527 __ cmp(dividend, Operand::Zero()); | 1406 __ cmpwi(dividend, Operand::Zero()); |
| 1528 DeoptimizeIf(eq, instr->environment()); | 1407 DeoptimizeIf(eq, instr->environment()); |
| 1529 } | 1408 } |
| 1530 | 1409 |
| 1531 // Easy case: We need no dynamic check for the dividend and the flooring | 1410 // Easy case: We need no dynamic check for the dividend and the flooring |
| 1532 // division is the same as the truncating division. | 1411 // division is the same as the truncating division. |
| 1533 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || | 1412 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1534 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { | 1413 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1535 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1414 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1536 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1415 if (divisor < 0) __ neg(result, result); |
| 1537 return; | 1416 return; |
| 1538 } | 1417 } |
| 1539 | 1418 |
| 1540 // In the general case we may need to adjust before and after the truncating | 1419 // In the general case we may need to adjust before and after the truncating |
| 1541 // division to get a flooring division. | 1420 // division to get a flooring division. |
| 1542 Register temp = ToRegister(instr->temp()); | 1421 Register temp = ToRegister(instr->temp()); |
| 1543 ASSERT(!temp.is(dividend) && !temp.is(result)); | 1422 ASSERT(!temp.is(dividend) && !temp.is(result)); |
| 1544 Label needs_adjustment, done; | 1423 Label needs_adjustment, done; |
| 1545 __ cmp(dividend, Operand::Zero()); | 1424 __ cmpwi(dividend, Operand::Zero()); |
| 1546 __ b(divisor > 0 ? lt : gt, &needs_adjustment); | 1425 __ b(divisor > 0 ? lt : gt, &needs_adjustment); |
| 1547 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1426 __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1548 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1427 if (divisor < 0) __ neg(result, result); |
| 1549 __ jmp(&done); | 1428 __ b(&done); |
| 1550 __ bind(&needs_adjustment); | 1429 __ bind(&needs_adjustment); |
| 1551 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); | 1430 __ addi(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 1552 __ TruncatingDiv(result, temp, Abs(divisor)); | 1431 __ TruncatingDiv(result, temp, Abs(divisor)); |
| 1553 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1432 if (divisor < 0) __ neg(result, result); |
| 1554 __ sub(result, result, Operand(1)); | 1433 __ subi(result, result, Operand(1)); |
| 1555 __ bind(&done); | 1434 __ bind(&done); |
| 1556 } | 1435 } |
| 1557 | 1436 |
| 1558 | 1437 |
| 1559 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. | 1438 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1560 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { | 1439 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1561 HBinaryOperation* hdiv = instr->hydrogen(); | 1440 HBinaryOperation* hdiv = instr->hydrogen(); |
| 1562 Register left = ToRegister(instr->dividend()); | 1441 const Register dividend = ToRegister(instr->dividend()); |
| 1563 Register right = ToRegister(instr->divisor()); | 1442 const Register divisor = ToRegister(instr->divisor()); |
| 1564 Register result = ToRegister(instr->result()); | 1443 Register result = ToRegister(instr->result()); |
| 1565 | 1444 |
| 1445 ASSERT(!dividend.is(result)); |
| 1446 ASSERT(!divisor.is(result)); |
| 1447 |
| 1448 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1449 __ li(r0, Operand::Zero()); // clear xer |
| 1450 __ mtxer(r0); |
| 1451 } |
| 1452 |
| 1453 __ divw(result, dividend, divisor, SetOE, SetRC); |
| 1454 |
| 1566 // Check for x / 0. | 1455 // Check for x / 0. |
| 1567 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1456 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1568 __ cmp(right, Operand::Zero()); | 1457 __ cmpwi(divisor, Operand::Zero()); |
| 1569 DeoptimizeIf(eq, instr->environment()); | 1458 DeoptimizeIf(eq, instr->environment()); |
| 1570 } | 1459 } |
| 1571 | 1460 |
| 1572 // Check for (0 / -x) that will produce negative zero. | 1461 // Check for (0 / -x) that will produce negative zero. |
| 1573 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1462 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1574 Label positive; | 1463 Label dividend_not_zero; |
| 1575 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { | 1464 __ cmpwi(dividend, Operand::Zero()); |
| 1576 // Do the test only if it hadn't be done above. | 1465 __ bne(÷nd_not_zero); |
| 1577 __ cmp(right, Operand::Zero()); | 1466 __ cmpwi(divisor, Operand::Zero()); |
| 1578 } | 1467 DeoptimizeIf(lt, instr->environment()); |
| 1579 __ b(pl, &positive); | 1468 __ bind(÷nd_not_zero); |
| 1580 __ cmp(left, Operand::Zero()); | |
| 1581 DeoptimizeIf(eq, instr->environment()); | |
| 1582 __ bind(&positive); | |
| 1583 } | 1469 } |
| 1584 | 1470 |
| 1585 // Check for (kMinInt / -1). | 1471 // Check for (kMinInt / -1). |
| 1586 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1472 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1587 (!CpuFeatures::IsSupported(SUDIV) || | 1473 Label no_overflow_possible; |
| 1588 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { | 1474 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1589 // We don't need to check for overflow when truncating with sdiv | 1475 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1590 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. | 1476 } else { |
| 1591 __ cmp(left, Operand(kMinInt)); | 1477 // When truncating, we want kMinInt / -1 = kMinInt. |
| 1592 __ cmp(right, Operand(-1), eq); | 1478 __ bnooverflow(&no_overflow_possible, cr0); |
| 1593 DeoptimizeIf(eq, instr->environment()); | 1479 __ mr(result, dividend); |
| 1594 } | 1480 } |
| 1595 | 1481 __ bind(&no_overflow_possible); |
| 1596 if (CpuFeatures::IsSupported(SUDIV)) { | |
| 1597 CpuFeatureScope scope(masm(), SUDIV); | |
| 1598 __ sdiv(result, left, right); | |
| 1599 } else { | |
| 1600 DoubleRegister vleft = ToDoubleRegister(instr->temp()); | |
| 1601 DoubleRegister vright = double_scratch0(); | |
| 1602 __ vmov(double_scratch0().low(), left); | |
| 1603 __ vcvt_f64_s32(vleft, double_scratch0().low()); | |
| 1604 __ vmov(double_scratch0().low(), right); | |
| 1605 __ vcvt_f64_s32(vright, double_scratch0().low()); | |
| 1606 __ vdiv(vleft, vleft, vright); // vleft now contains the result. | |
| 1607 __ vcvt_s32_f64(double_scratch0().low(), vleft); | |
| 1608 __ vmov(result, double_scratch0().low()); | |
| 1609 } | 1482 } |
| 1610 | 1483 |
| 1611 Label done; | 1484 Label done; |
| 1612 Register remainder = scratch0(); | 1485 Register scratch = scratch0(); |
| 1613 __ Mls(remainder, result, right, left); | 1486 // If both operands have the same sign then we are done. |
| 1614 __ cmp(remainder, Operand::Zero()); | 1487 #if V8_TARGET_ARCH_PPC64 |
| 1615 __ b(eq, &done); | 1488 __ xor_(scratch, dividend, divisor); |
| 1616 __ eor(remainder, remainder, Operand(right)); | 1489 __ cmpwi(scratch, Operand::Zero()); |
| 1617 __ add(result, result, Operand(remainder, ASR, 31)); | 1490 __ bge(&done); |
| 1491 #else |
| 1492 __ xor_(scratch, dividend, divisor, SetRC); |
| 1493 __ bge(&done, cr0); |
| 1494 #endif |
| 1495 |
| 1496 // If there is no remainder then we are done. |
| 1497 __ mullw(scratch, divisor, result); |
| 1498 __ cmpw(dividend, scratch); |
| 1499 __ beq(&done); |
| 1500 |
| 1501 // We performed a truncating division. Correct the result. |
| 1502 __ subi(result, result, Operand(1)); |
| 1618 __ bind(&done); | 1503 __ bind(&done); |
| 1619 } | 1504 } |
| 1620 | 1505 |
| 1621 | 1506 |
| 1507 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1508 DoubleRegister addend = ToDoubleRegister(instr->addend()); |
| 1509 DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1510 DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1511 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1512 |
| 1513 __ fmadd(result, multiplier, multiplicand, addend); |
| 1514 } |
| 1515 |
| 1516 |
| 1517 void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { |
| 1518 DoubleRegister minuend = ToDoubleRegister(instr->minuend()); |
| 1519 DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1520 DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1521 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1522 |
| 1523 __ fmsub(result, multiplier, multiplicand, minuend); |
| 1524 } |
| 1525 |
| 1526 |
| 1622 void LCodeGen::DoMulI(LMulI* instr) { | 1527 void LCodeGen::DoMulI(LMulI* instr) { |
| 1528 Register scratch = scratch0(); |
| 1623 Register result = ToRegister(instr->result()); | 1529 Register result = ToRegister(instr->result()); |
| 1624 // Note that result may alias left. | 1530 // Note that result may alias left. |
| 1625 Register left = ToRegister(instr->left()); | 1531 Register left = ToRegister(instr->left()); |
| 1626 LOperand* right_op = instr->right(); | 1532 LOperand* right_op = instr->right(); |
| 1627 | 1533 |
| 1628 bool bailout_on_minus_zero = | 1534 bool bailout_on_minus_zero = |
| 1629 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | 1535 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
| 1630 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1536 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1631 | 1537 |
| 1632 if (right_op->IsConstantOperand()) { | 1538 if (right_op->IsConstantOperand()) { |
| 1633 int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); | 1539 int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
| 1634 | 1540 |
| 1635 if (bailout_on_minus_zero && (constant < 0)) { | 1541 if (bailout_on_minus_zero && (constant < 0)) { |
| 1636 // The case of a null constant will be handled separately. | 1542 // The case of a null constant will be handled separately. |
| 1637 // If constant is negative and left is null, the result should be -0. | 1543 // If constant is negative and left is null, the result should be -0. |
| 1638 __ cmp(left, Operand::Zero()); | 1544 __ cmpi(left, Operand::Zero()); |
| 1639 DeoptimizeIf(eq, instr->environment()); | 1545 DeoptimizeIf(eq, instr->environment()); |
| 1640 } | 1546 } |
| 1641 | 1547 |
| 1642 switch (constant) { | 1548 switch (constant) { |
| 1643 case -1: | 1549 case -1: |
| 1644 if (overflow) { | 1550 if (can_overflow) { |
| 1645 __ rsb(result, left, Operand::Zero(), SetCC); | 1551 #if V8_TARGET_ARCH_PPC64 |
| 1646 DeoptimizeIf(vs, instr->environment()); | 1552 if (instr->hydrogen()->representation().IsSmi()) { |
| 1553 #endif |
| 1554 __ li(r0, Operand::Zero()); // clear xer |
| 1555 __ mtxer(r0); |
| 1556 __ neg(result, left, SetOE, SetRC); |
| 1557 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1558 #if V8_TARGET_ARCH_PPC64 |
| 1559 } else { |
| 1560 __ neg(result, left); |
| 1561 __ TestIfInt32(result, scratch, r0); |
| 1562 DeoptimizeIf(ne, instr->environment()); |
| 1563 } |
| 1564 #endif |
| 1647 } else { | 1565 } else { |
| 1648 __ rsb(result, left, Operand::Zero()); | 1566 __ neg(result, left); |
| 1649 } | 1567 } |
| 1650 break; | 1568 break; |
| 1651 case 0: | 1569 case 0: |
| 1652 if (bailout_on_minus_zero) { | 1570 if (bailout_on_minus_zero) { |
| 1653 // If left is strictly negative and the constant is null, the | 1571 // If left is strictly negative and the constant is null, the |
| 1654 // result is -0. Deoptimize if required, otherwise return 0. | 1572 // result is -0. Deoptimize if required, otherwise return 0. |
| 1655 __ cmp(left, Operand::Zero()); | 1573 #if V8_TARGET_ARCH_PPC64 |
| 1656 DeoptimizeIf(mi, instr->environment()); | 1574 if (instr->hydrogen()->representation().IsSmi()) { |
| 1575 #endif |
| 1576 __ cmpi(left, Operand::Zero()); |
| 1577 #if V8_TARGET_ARCH_PPC64 |
| 1578 } else { |
| 1579 __ cmpwi(left, Operand::Zero()); |
| 1580 } |
| 1581 #endif |
| 1582 DeoptimizeIf(lt, instr->environment()); |
| 1657 } | 1583 } |
| 1658 __ mov(result, Operand::Zero()); | 1584 __ li(result, Operand::Zero()); |
| 1659 break; | 1585 break; |
| 1660 case 1: | 1586 case 1: |
| 1661 __ Move(result, left); | 1587 __ Move(result, left); |
| 1662 break; | 1588 break; |
| 1663 default: | 1589 default: |
| 1664 // Multiplying by powers of two and powers of two plus or minus | 1590 // Multiplying by powers of two and powers of two plus or minus |
| 1665 // one can be done faster with shifted operands. | 1591 // one can be done faster with shifted operands. |
| 1666 // For other constants we emit standard code. | 1592 // For other constants we emit standard code. |
| 1667 int32_t mask = constant >> 31; | 1593 int32_t mask = constant >> 31; |
| 1668 uint32_t constant_abs = (constant + mask) ^ mask; | 1594 uint32_t constant_abs = (constant + mask) ^ mask; |
| 1669 | 1595 |
| 1670 if (IsPowerOf2(constant_abs)) { | 1596 if (IsPowerOf2(constant_abs)) { |
| 1671 int32_t shift = WhichPowerOf2(constant_abs); | 1597 int32_t shift = WhichPowerOf2(constant_abs); |
| 1672 __ mov(result, Operand(left, LSL, shift)); | 1598 __ ShiftLeftImm(result, left, Operand(shift)); |
| 1673 // Correct the sign of the result is the constant is negative. | 1599 // Correct the sign of the result if the constant is negative. |
| 1674 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1600 if (constant < 0) __ neg(result, result); |
| 1675 } else if (IsPowerOf2(constant_abs - 1)) { | 1601 } else if (IsPowerOf2(constant_abs - 1)) { |
| 1676 int32_t shift = WhichPowerOf2(constant_abs - 1); | 1602 int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1677 __ add(result, left, Operand(left, LSL, shift)); | 1603 __ ShiftLeftImm(scratch, left, Operand(shift)); |
| 1678 // Correct the sign of the result is the constant is negative. | 1604 __ add(result, scratch, left); |
| 1679 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1605 // Correct the sign of the result if the constant is negative. |
| 1606 if (constant < 0) __ neg(result, result); |
| 1680 } else if (IsPowerOf2(constant_abs + 1)) { | 1607 } else if (IsPowerOf2(constant_abs + 1)) { |
| 1681 int32_t shift = WhichPowerOf2(constant_abs + 1); | 1608 int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1682 __ rsb(result, left, Operand(left, LSL, shift)); | 1609 __ ShiftLeftImm(scratch, left, Operand(shift)); |
| 1683 // Correct the sign of the result is the constant is negative. | 1610 __ sub(result, scratch, left); |
| 1684 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1611 // Correct the sign of the result if the constant is negative. |
| 1612 if (constant < 0) __ neg(result, result); |
| 1685 } else { | 1613 } else { |
| 1686 // Generate standard code. | 1614 // Generate standard code. |
| 1687 __ mov(ip, Operand(constant)); | 1615 __ mov(ip, Operand(constant)); |
| 1688 __ mul(result, left, ip); | 1616 __ Mul(result, left, ip); |
| 1689 } | 1617 } |
| 1690 } | 1618 } |
| 1691 | 1619 |
| 1692 } else { | 1620 } else { |
| 1693 ASSERT(right_op->IsRegister()); | 1621 ASSERT(right_op->IsRegister()); |
| 1694 Register right = ToRegister(right_op); | 1622 Register right = ToRegister(right_op); |
| 1695 | 1623 |
| 1696 if (overflow) { | 1624 if (can_overflow) { |
| 1697 Register scratch = scratch0(); | 1625 #if V8_TARGET_ARCH_PPC64 |
| 1626 // result = left * right. |
| 1627 if (instr->hydrogen()->representation().IsSmi()) { |
| 1628 __ SmiUntag(result, left); |
| 1629 __ SmiUntag(scratch, right); |
| 1630 __ Mul(result, result, scratch); |
| 1631 } else { |
| 1632 __ Mul(result, left, right); |
| 1633 } |
| 1634 __ TestIfInt32(result, scratch, r0); |
| 1635 DeoptimizeIf(ne, instr->environment()); |
| 1636 if (instr->hydrogen()->representation().IsSmi()) { |
| 1637 __ SmiTag(result); |
| 1638 } |
| 1639 #else |
| 1698 // scratch:result = left * right. | 1640 // scratch:result = left * right. |
| 1699 if (instr->hydrogen()->representation().IsSmi()) { | 1641 if (instr->hydrogen()->representation().IsSmi()) { |
| 1700 __ SmiUntag(result, left); | 1642 __ SmiUntag(result, left); |
| 1701 __ smull(result, scratch, result, right); | 1643 __ mulhw(scratch, result, right); |
| 1644 __ mullw(result, result, right); |
| 1702 } else { | 1645 } else { |
| 1703 __ smull(result, scratch, left, right); | 1646 __ mulhw(scratch, left, right); |
| 1647 __ mullw(result, left, right); |
| 1704 } | 1648 } |
| 1705 __ cmp(scratch, Operand(result, ASR, 31)); | 1649 __ TestIfInt32(scratch, result, r0); |
| 1706 DeoptimizeIf(ne, instr->environment()); | 1650 DeoptimizeIf(ne, instr->environment()); |
| 1651 #endif |
| 1707 } else { | 1652 } else { |
| 1708 if (instr->hydrogen()->representation().IsSmi()) { | 1653 if (instr->hydrogen()->representation().IsSmi()) { |
| 1709 __ SmiUntag(result, left); | 1654 __ SmiUntag(result, left); |
| 1710 __ mul(result, result, right); | 1655 __ Mul(result, result, right); |
| 1711 } else { | 1656 } else { |
| 1712 __ mul(result, left, right); | 1657 __ Mul(result, left, right); |
| 1713 } | 1658 } |
| 1714 } | 1659 } |
| 1715 | 1660 |
| 1716 if (bailout_on_minus_zero) { | 1661 if (bailout_on_minus_zero) { |
| 1717 Label done; | 1662 Label done; |
| 1718 __ teq(left, Operand(right)); | 1663 #if V8_TARGET_ARCH_PPC64 |
| 1719 __ b(pl, &done); | 1664 if (instr->hydrogen()->representation().IsSmi()) { |
| 1665 #endif |
| 1666 __ xor_(r0, left, right, SetRC); |
| 1667 __ bge(&done, cr0); |
| 1668 #if V8_TARGET_ARCH_PPC64 |
| 1669 } else { |
| 1670 __ xor_(r0, left, right); |
| 1671 __ cmpwi(r0, Operand::Zero()); |
| 1672 __ bge(&done); |
| 1673 } |
| 1674 #endif |
| 1720 // Bail out if the result is minus zero. | 1675 // Bail out if the result is minus zero. |
| 1721 __ cmp(result, Operand::Zero()); | 1676 __ cmpi(result, Operand::Zero()); |
| 1722 DeoptimizeIf(eq, instr->environment()); | 1677 DeoptimizeIf(eq, instr->environment()); |
| 1723 __ bind(&done); | 1678 __ bind(&done); |
| 1724 } | 1679 } |
| 1725 } | 1680 } |
| 1726 } | 1681 } |
| 1727 | 1682 |
| 1728 | 1683 |
| 1729 void LCodeGen::DoBitI(LBitI* instr) { | 1684 void LCodeGen::DoBitI(LBitI* instr) { |
| 1730 LOperand* left_op = instr->left(); | 1685 LOperand* left_op = instr->left(); |
| 1731 LOperand* right_op = instr->right(); | 1686 LOperand* right_op = instr->right(); |
| 1732 ASSERT(left_op->IsRegister()); | 1687 ASSERT(left_op->IsRegister()); |
| 1733 Register left = ToRegister(left_op); | 1688 Register left = ToRegister(left_op); |
| 1734 Register result = ToRegister(instr->result()); | 1689 Register result = ToRegister(instr->result()); |
| 1735 Operand right(no_reg); | 1690 Operand right(no_reg); |
| 1736 | 1691 |
| 1737 if (right_op->IsStackSlot()) { | 1692 if (right_op->IsStackSlot()) { |
| 1738 right = Operand(EmitLoadRegister(right_op, ip)); | 1693 right = Operand(EmitLoadRegister(right_op, ip)); |
| 1739 } else { | 1694 } else { |
| 1740 ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); | 1695 ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1741 right = ToOperand(right_op); | 1696 right = ToOperand(right_op); |
| 1697 |
| 1698 if (right_op->IsConstantOperand() && is_uint16(right.immediate())) { |
| 1699 switch (instr->op()) { |
| 1700 case Token::BIT_AND: |
| 1701 __ andi(result, left, right); |
| 1702 break; |
| 1703 case Token::BIT_OR: |
| 1704 __ ori(result, left, right); |
| 1705 break; |
| 1706 case Token::BIT_XOR: |
| 1707 __ xori(result, left, right); |
| 1708 break; |
| 1709 default: |
| 1710 UNREACHABLE(); |
| 1711 break; |
| 1712 } |
| 1713 return; |
| 1714 } |
| 1742 } | 1715 } |
| 1743 | 1716 |
| 1744 switch (instr->op()) { | 1717 switch (instr->op()) { |
| 1745 case Token::BIT_AND: | 1718 case Token::BIT_AND: |
| 1746 __ and_(result, left, right); | 1719 __ And(result, left, right); |
| 1747 break; | 1720 break; |
| 1748 case Token::BIT_OR: | 1721 case Token::BIT_OR: |
| 1749 __ orr(result, left, right); | 1722 __ Or(result, left, right); |
| 1750 break; | 1723 break; |
| 1751 case Token::BIT_XOR: | 1724 case Token::BIT_XOR: |
| 1752 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { | 1725 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { |
| 1753 __ mvn(result, Operand(left)); | 1726 __ notx(result, left); |
| 1754 } else { | 1727 } else { |
| 1755 __ eor(result, left, right); | 1728 __ Xor(result, left, right); |
| 1756 } | 1729 } |
| 1757 break; | 1730 break; |
| 1758 default: | 1731 default: |
| 1759 UNREACHABLE(); | 1732 UNREACHABLE(); |
| 1760 break; | 1733 break; |
| 1761 } | 1734 } |
| 1762 } | 1735 } |
| 1763 | 1736 |
| 1764 | 1737 |
| 1765 void LCodeGen::DoShiftI(LShiftI* instr) { | 1738 void LCodeGen::DoShiftI(LShiftI* instr) { |
| 1766 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so | 1739 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1767 // result may alias either of them. | 1740 // result may alias either of them. |
| 1768 LOperand* right_op = instr->right(); | 1741 LOperand* right_op = instr->right(); |
| 1769 Register left = ToRegister(instr->left()); | 1742 Register left = ToRegister(instr->left()); |
| 1770 Register result = ToRegister(instr->result()); | 1743 Register result = ToRegister(instr->result()); |
| 1771 Register scratch = scratch0(); | 1744 Register scratch = scratch0(); |
| 1772 if (right_op->IsRegister()) { | 1745 if (right_op->IsRegister()) { |
| 1773 // Mask the right_op operand. | 1746 // Mask the right_op operand. |
| 1774 __ and_(scratch, ToRegister(right_op), Operand(0x1F)); | 1747 __ andi(scratch, ToRegister(right_op), Operand(0x1F)); |
| 1775 switch (instr->op()) { | 1748 switch (instr->op()) { |
| 1776 case Token::ROR: | 1749 case Token::ROR: |
| 1777 __ mov(result, Operand(left, ROR, scratch)); | 1750 // rotate_right(a, b) == rotate_left(a, 32 - b) |
| 1751 __ subfic(scratch, scratch, Operand(32)); |
| 1752 __ rotlw(result, left, scratch); |
| 1778 break; | 1753 break; |
| 1779 case Token::SAR: | 1754 case Token::SAR: |
| 1780 __ mov(result, Operand(left, ASR, scratch)); | 1755 __ sraw(result, left, scratch); |
| 1781 break; | 1756 break; |
| 1782 case Token::SHR: | 1757 case Token::SHR: |
| 1783 if (instr->can_deopt()) { | 1758 if (instr->can_deopt()) { |
| 1784 __ mov(result, Operand(left, LSR, scratch), SetCC); | 1759 __ srw(result, left, scratch, SetRC); |
| 1785 DeoptimizeIf(mi, instr->environment()); | 1760 #if V8_TARGET_ARCH_PPC64 |
| 1761 __ extsw(result, result, SetRC); |
| 1762 #endif |
| 1763 DeoptimizeIf(lt, instr->environment(), cr0); |
| 1786 } else { | 1764 } else { |
| 1787 __ mov(result, Operand(left, LSR, scratch)); | 1765 __ srw(result, left, scratch); |
| 1788 } | 1766 } |
| 1789 break; | 1767 break; |
| 1790 case Token::SHL: | 1768 case Token::SHL: |
| 1791 __ mov(result, Operand(left, LSL, scratch)); | 1769 __ slw(result, left, scratch); |
| 1770 #if V8_TARGET_ARCH_PPC64 |
| 1771 __ extsw(result, result); |
| 1772 #endif |
| 1792 break; | 1773 break; |
| 1793 default: | 1774 default: |
| 1794 UNREACHABLE(); | 1775 UNREACHABLE(); |
| 1795 break; | 1776 break; |
| 1796 } | 1777 } |
| 1797 } else { | 1778 } else { |
| 1798 // Mask the right_op operand. | 1779 // Mask the right_op operand. |
| 1799 int value = ToInteger32(LConstantOperand::cast(right_op)); | 1780 int value = ToInteger32(LConstantOperand::cast(right_op)); |
| 1800 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); | 1781 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1801 switch (instr->op()) { | 1782 switch (instr->op()) { |
| 1802 case Token::ROR: | 1783 case Token::ROR: |
| 1803 if (shift_count != 0) { | 1784 if (shift_count != 0) { |
| 1804 __ mov(result, Operand(left, ROR, shift_count)); | 1785 __ rotrwi(result, left, shift_count); |
| 1805 } else { | 1786 } else { |
| 1806 __ Move(result, left); | 1787 __ Move(result, left); |
| 1807 } | 1788 } |
| 1808 break; | 1789 break; |
| 1809 case Token::SAR: | 1790 case Token::SAR: |
| 1810 if (shift_count != 0) { | 1791 if (shift_count != 0) { |
| 1811 __ mov(result, Operand(left, ASR, shift_count)); | 1792 __ srawi(result, left, shift_count); |
| 1812 } else { | 1793 } else { |
| 1813 __ Move(result, left); | 1794 __ Move(result, left); |
| 1814 } | 1795 } |
| 1815 break; | 1796 break; |
| 1816 case Token::SHR: | 1797 case Token::SHR: |
| 1817 if (shift_count != 0) { | 1798 if (shift_count != 0) { |
| 1818 __ mov(result, Operand(left, LSR, shift_count)); | 1799 __ srwi(result, left, Operand(shift_count)); |
| 1819 } else { | 1800 } else { |
| 1820 if (instr->can_deopt()) { | 1801 if (instr->can_deopt()) { |
| 1821 __ tst(left, Operand(0x80000000)); | 1802 __ cmpwi(left, Operand::Zero()); |
| 1822 DeoptimizeIf(ne, instr->environment()); | 1803 DeoptimizeIf(lt, instr->environment()); |
| 1823 } | 1804 } |
| 1824 __ Move(result, left); | 1805 __ Move(result, left); |
| 1825 } | 1806 } |
| 1826 break; | 1807 break; |
| 1827 case Token::SHL: | 1808 case Token::SHL: |
| 1828 if (shift_count != 0) { | 1809 if (shift_count != 0) { |
| 1810 #if V8_TARGET_ARCH_PPC64 |
| 1811 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 1812 __ sldi(result, left, Operand(shift_count)); |
| 1813 #else |
| 1829 if (instr->hydrogen_value()->representation().IsSmi() && | 1814 if (instr->hydrogen_value()->representation().IsSmi() && |
| 1830 instr->can_deopt()) { | 1815 instr->can_deopt()) { |
| 1831 if (shift_count != 1) { | 1816 if (shift_count != 1) { |
| 1832 __ mov(result, Operand(left, LSL, shift_count - 1)); | 1817 __ slwi(result, left, Operand(shift_count - 1)); |
| 1833 __ SmiTag(result, result, SetCC); | 1818 __ SmiTagCheckOverflow(result, result, scratch); |
| 1834 } else { | 1819 } else { |
| 1835 __ SmiTag(result, left, SetCC); | 1820 __ SmiTagCheckOverflow(result, left, scratch); |
| 1836 } | 1821 } |
| 1837 DeoptimizeIf(vs, instr->environment()); | 1822 DeoptimizeIf(lt, instr->environment(), cr0); |
| 1823 #endif |
| 1838 } else { | 1824 } else { |
| 1839 __ mov(result, Operand(left, LSL, shift_count)); | 1825 __ slwi(result, left, Operand(shift_count)); |
| 1826 #if V8_TARGET_ARCH_PPC64 |
| 1827 __ extsw(result, result); |
| 1828 #endif |
| 1840 } | 1829 } |
| 1841 } else { | 1830 } else { |
| 1842 __ Move(result, left); | 1831 __ Move(result, left); |
| 1843 } | 1832 } |
| 1844 break; | 1833 break; |
| 1845 default: | 1834 default: |
| 1846 UNREACHABLE(); | 1835 UNREACHABLE(); |
| 1847 break; | 1836 break; |
| 1848 } | 1837 } |
| 1849 } | 1838 } |
| 1850 } | 1839 } |
| 1851 | 1840 |
| 1852 | 1841 |
| 1853 void LCodeGen::DoSubI(LSubI* instr) { | 1842 void LCodeGen::DoSubI(LSubI* instr) { |
| 1854 LOperand* left = instr->left(); | |
| 1855 LOperand* right = instr->right(); | 1843 LOperand* right = instr->right(); |
| 1856 LOperand* result = instr->result(); | 1844 Register left = ToRegister(instr->left()); |
| 1845 Register result = ToRegister(instr->result()); |
| 1857 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1846 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1858 SBit set_cond = can_overflow ? SetCC : LeaveCC; | 1847 if (!can_overflow && right->IsConstantOperand()) { |
| 1848 Operand right_operand = ToOperand(right); |
| 1849 __ Add(result, left, -right_operand.immediate(), r0); |
| 1850 } else { |
| 1851 Register right_reg = EmitLoadRegister(right, ip); |
| 1859 | 1852 |
| 1860 if (right->IsStackSlot()) { | 1853 if (!can_overflow) { |
| 1861 Register right_reg = EmitLoadRegister(right, ip); | 1854 __ sub(result, left, right_reg); |
| 1862 __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 1855 } else { |
| 1863 } else { | 1856 __ SubAndCheckForOverflow(result, |
| 1864 ASSERT(right->IsRegister() || right->IsConstantOperand()); | 1857 left, |
| 1865 __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 1858 right_reg, |
| 1859 scratch0(), r0); |
| 1860 // Doptimize on overflow |
| 1861 #if V8_TARGET_ARCH_PPC64 |
| 1862 if (!instr->hydrogen()->representation().IsSmi()) { |
| 1863 __ extsw(scratch0(), scratch0(), SetRC); |
| 1864 } |
| 1865 #endif |
| 1866 DeoptimizeIf(lt, instr->environment(), cr0); |
| 1867 } |
| 1866 } | 1868 } |
| 1867 | 1869 |
| 1868 if (can_overflow) { | 1870 #if V8_TARGET_ARCH_PPC64 |
| 1869 DeoptimizeIf(vs, instr->environment()); | 1871 if (!instr->hydrogen()->representation().IsSmi()) { |
| 1872 __ extsw(result, result); |
| 1870 } | 1873 } |
| 1874 #endif |
| 1871 } | 1875 } |
| 1872 | 1876 |
| 1873 | 1877 |
| 1874 void LCodeGen::DoRSubI(LRSubI* instr) { | 1878 void LCodeGen::DoRSubI(LRSubI* instr) { |
| 1875 LOperand* left = instr->left(); | 1879 LOperand* left = instr->left(); |
| 1876 LOperand* right = instr->right(); | 1880 LOperand* right = instr->right(); |
| 1877 LOperand* result = instr->result(); | 1881 LOperand* result = instr->result(); |
| 1878 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
| 1879 SBit set_cond = can_overflow ? SetCC : LeaveCC; | |
| 1880 | 1882 |
| 1881 if (right->IsStackSlot()) { | 1883 ASSERT(!instr->hydrogen()->CheckFlag(HValue::kCanOverflow) && |
| 1882 Register right_reg = EmitLoadRegister(right, ip); | 1884 right->IsConstantOperand()); |
| 1883 __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 1885 |
| 1886 Operand right_operand = ToOperand(right); |
| 1887 if (is_int16(right_operand.immediate())) { |
| 1888 __ subfic(ToRegister(result), ToRegister(left), right_operand); |
| 1884 } else { | 1889 } else { |
| 1885 ASSERT(right->IsRegister() || right->IsConstantOperand()); | 1890 __ mov(r0, right_operand); |
| 1886 __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 1891 __ sub(ToRegister(result), r0, ToRegister(left)); |
| 1887 } | |
| 1888 | |
| 1889 if (can_overflow) { | |
| 1890 DeoptimizeIf(vs, instr->environment()); | |
| 1891 } | 1892 } |
| 1892 } | 1893 } |
| 1893 | 1894 |
| 1894 | 1895 |
| 1895 void LCodeGen::DoConstantI(LConstantI* instr) { | 1896 void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1896 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1897 __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1897 } | 1898 } |
| 1898 | 1899 |
| 1899 | 1900 |
| 1900 void LCodeGen::DoConstantS(LConstantS* instr) { | 1901 void LCodeGen::DoConstantS(LConstantS* instr) { |
| 1901 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1902 __ LoadSmiLiteral(ToRegister(instr->result()), instr->value()); |
| 1902 } | 1903 } |
| 1903 | 1904 |
| 1904 | 1905 |
| 1906 // TODO(penguin): put const to constant pool instead |
| 1907 // of storing double to stack |
| 1905 void LCodeGen::DoConstantD(LConstantD* instr) { | 1908 void LCodeGen::DoConstantD(LConstantD* instr) { |
| 1906 ASSERT(instr->result()->IsDoubleRegister()); | 1909 ASSERT(instr->result()->IsDoubleRegister()); |
| 1907 DwVfpRegister result = ToDoubleRegister(instr->result()); | 1910 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1908 double v = instr->value(); | 1911 double v = instr->value(); |
| 1909 __ Vmov(result, v, scratch0()); | 1912 __ LoadDoubleLiteral(result, v, scratch0()); |
| 1910 } | 1913 } |
| 1911 | 1914 |
| 1912 | 1915 |
| 1913 void LCodeGen::DoConstantE(LConstantE* instr) { | 1916 void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1914 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1917 __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1915 } | 1918 } |
| 1916 | 1919 |
| 1917 | 1920 |
| 1918 void LCodeGen::DoConstantT(LConstantT* instr) { | 1921 void LCodeGen::DoConstantT(LConstantT* instr) { |
| 1919 Handle<Object> object = instr->value(isolate()); | 1922 Handle<Object> object = instr->value(isolate()); |
| 1920 AllowDeferredHandleDereference smi_check; | 1923 AllowDeferredHandleDereference smi_check; |
| 1921 __ Move(ToRegister(instr->result()), object); | 1924 __ Move(ToRegister(instr->result()), object); |
| 1922 } | 1925 } |
| 1923 | 1926 |
| 1924 | 1927 |
| 1925 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { | 1928 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1926 Register result = ToRegister(instr->result()); | 1929 Register result = ToRegister(instr->result()); |
| 1927 Register map = ToRegister(instr->value()); | 1930 Register map = ToRegister(instr->value()); |
| 1928 __ EnumLength(result, map); | 1931 __ EnumLength(result, map); |
| 1929 } | 1932 } |
| 1930 | 1933 |
| 1931 | 1934 |
| 1932 void LCodeGen::DoDateField(LDateField* instr) { | 1935 void LCodeGen::DoDateField(LDateField* instr) { |
| 1933 Register object = ToRegister(instr->date()); | 1936 Register object = ToRegister(instr->date()); |
| 1934 Register result = ToRegister(instr->result()); | 1937 Register result = ToRegister(instr->result()); |
| 1935 Register scratch = ToRegister(instr->temp()); | 1938 Register scratch = ToRegister(instr->temp()); |
| 1936 Smi* index = instr->index(); | 1939 Smi* index = instr->index(); |
| 1937 Label runtime, done; | 1940 Label runtime, done; |
| 1938 ASSERT(object.is(result)); | 1941 ASSERT(object.is(result)); |
| 1939 ASSERT(object.is(r0)); | 1942 ASSERT(object.is(r3)); |
| 1940 ASSERT(!scratch.is(scratch0())); | 1943 ASSERT(!scratch.is(scratch0())); |
| 1941 ASSERT(!scratch.is(object)); | 1944 ASSERT(!scratch.is(object)); |
| 1942 | 1945 |
| 1943 __ SmiTst(object); | 1946 __ TestIfSmi(object, r0); |
| 1944 DeoptimizeIf(eq, instr->environment()); | 1947 DeoptimizeIf(eq, instr->environment(), cr0); |
| 1945 __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); | 1948 __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); |
| 1946 DeoptimizeIf(ne, instr->environment()); | 1949 DeoptimizeIf(ne, instr->environment()); |
| 1947 | 1950 |
| 1948 if (index->value() == 0) { | 1951 if (index->value() == 0) { |
| 1949 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); | 1952 __ LoadP(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 1950 } else { | 1953 } else { |
| 1951 if (index->value() < JSDate::kFirstUncachedField) { | 1954 if (index->value() < JSDate::kFirstUncachedField) { |
| 1952 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); | 1955 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 1953 __ mov(scratch, Operand(stamp)); | 1956 __ mov(scratch, Operand(stamp)); |
| 1954 __ ldr(scratch, MemOperand(scratch)); | 1957 __ LoadP(scratch, MemOperand(scratch)); |
| 1955 __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); | 1958 __ LoadP(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 1956 __ cmp(scratch, scratch0()); | 1959 __ cmp(scratch, scratch0()); |
| 1957 __ b(ne, &runtime); | 1960 __ bne(&runtime); |
| 1958 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset + | 1961 __ LoadP(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 1959 kPointerSize * index->value())); | 1962 kPointerSize * index->value())); |
| 1960 __ jmp(&done); | 1963 __ b(&done); |
| 1961 } | 1964 } |
| 1962 __ bind(&runtime); | 1965 __ bind(&runtime); |
| 1963 __ PrepareCallCFunction(2, scratch); | 1966 __ PrepareCallCFunction(2, scratch); |
| 1964 __ mov(r1, Operand(index)); | 1967 __ LoadSmiLiteral(r4, index); |
| 1965 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); | 1968 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1966 __ bind(&done); | 1969 __ bind(&done); |
| 1967 } | 1970 } |
| 1968 } | 1971 } |
| 1969 | 1972 |
| 1970 | 1973 |
| 1971 MemOperand LCodeGen::BuildSeqStringOperand(Register string, | 1974 MemOperand LCodeGen::BuildSeqStringOperand(Register string, |
| 1972 LOperand* index, | 1975 LOperand* index, |
| 1973 String::Encoding encoding) { | 1976 String::Encoding encoding) { |
| 1974 if (index->IsConstantOperand()) { | 1977 if (index->IsConstantOperand()) { |
| 1975 int offset = ToInteger32(LConstantOperand::cast(index)); | 1978 int offset = ToInteger32(LConstantOperand::cast(index)); |
| 1976 if (encoding == String::TWO_BYTE_ENCODING) { | 1979 if (encoding == String::TWO_BYTE_ENCODING) { |
| 1977 offset *= kUC16Size; | 1980 offset *= kUC16Size; |
| 1978 } | 1981 } |
| 1979 STATIC_ASSERT(kCharSize == 1); | 1982 STATIC_ASSERT(kCharSize == 1); |
| 1980 return FieldMemOperand(string, SeqString::kHeaderSize + offset); | 1983 return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
| 1981 } | 1984 } |
| 1982 Register scratch = scratch0(); | 1985 Register scratch = scratch0(); |
| 1983 ASSERT(!scratch.is(string)); | 1986 ASSERT(!scratch.is(string)); |
| 1984 ASSERT(!scratch.is(ToRegister(index))); | 1987 ASSERT(!scratch.is(ToRegister(index))); |
| 1985 if (encoding == String::ONE_BYTE_ENCODING) { | 1988 if (encoding == String::ONE_BYTE_ENCODING) { |
| 1986 __ add(scratch, string, Operand(ToRegister(index))); | 1989 __ add(scratch, string, ToRegister(index)); |
| 1987 } else { | 1990 } else { |
| 1988 STATIC_ASSERT(kUC16Size == 2); | 1991 STATIC_ASSERT(kUC16Size == 2); |
| 1989 __ add(scratch, string, Operand(ToRegister(index), LSL, 1)); | 1992 __ ShiftLeftImm(scratch, ToRegister(index), Operand(1)); |
| 1993 __ add(scratch, string, scratch); |
| 1990 } | 1994 } |
| 1991 return FieldMemOperand(scratch, SeqString::kHeaderSize); | 1995 return FieldMemOperand(scratch, SeqString::kHeaderSize); |
| 1992 } | 1996 } |
| 1993 | 1997 |
| 1994 | 1998 |
| 1995 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { | 1999 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 1996 String::Encoding encoding = instr->hydrogen()->encoding(); | 2000 String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1997 Register string = ToRegister(instr->string()); | 2001 Register string = ToRegister(instr->string()); |
| 1998 Register result = ToRegister(instr->result()); | 2002 Register result = ToRegister(instr->result()); |
| 1999 | 2003 |
| 2000 if (FLAG_debug_code) { | 2004 if (FLAG_debug_code) { |
| 2001 Register scratch = scratch0(); | 2005 Register scratch = scratch0(); |
| 2002 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); | 2006 __ LoadP(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 2003 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); | 2007 __ lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 2004 | 2008 |
| 2005 __ and_(scratch, scratch, | 2009 __ andi(scratch, scratch, |
| 2006 Operand(kStringRepresentationMask | kStringEncodingMask)); | 2010 Operand(kStringRepresentationMask | kStringEncodingMask)); |
| 2007 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | 2011 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2008 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | 2012 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 2009 __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING | 2013 __ cmpi(scratch, Operand(encoding == String::ONE_BYTE_ENCODING |
| 2010 ? one_byte_seq_type : two_byte_seq_type)); | 2014 ? one_byte_seq_type : two_byte_seq_type)); |
| 2011 __ Check(eq, kUnexpectedStringType); | 2015 __ Check(eq, kUnexpectedStringType); |
| 2012 } | 2016 } |
| 2013 | 2017 |
| 2014 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); | 2018 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 2015 if (encoding == String::ONE_BYTE_ENCODING) { | 2019 if (encoding == String::ONE_BYTE_ENCODING) { |
| 2016 __ ldrb(result, operand); | 2020 __ lbz(result, operand); |
| 2017 } else { | 2021 } else { |
| 2018 __ ldrh(result, operand); | 2022 __ lhz(result, operand); |
| 2019 } | 2023 } |
| 2020 } | 2024 } |
| 2021 | 2025 |
| 2022 | 2026 |
| 2023 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { | 2027 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 2024 String::Encoding encoding = instr->hydrogen()->encoding(); | 2028 String::Encoding encoding = instr->hydrogen()->encoding(); |
| 2025 Register string = ToRegister(instr->string()); | 2029 Register string = ToRegister(instr->string()); |
| 2026 Register value = ToRegister(instr->value()); | 2030 Register value = ToRegister(instr->value()); |
| 2027 | 2031 |
| 2028 if (FLAG_debug_code) { | 2032 if (FLAG_debug_code) { |
| 2029 Register index = ToRegister(instr->index()); | 2033 Register index = ToRegister(instr->index()); |
| 2030 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | 2034 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 2031 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | 2035 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 2032 int encoding_mask = | 2036 int encoding_mask = |
| 2033 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING | 2037 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 2034 ? one_byte_seq_type : two_byte_seq_type; | 2038 ? one_byte_seq_type : two_byte_seq_type; |
| 2035 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); | 2039 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
| 2036 } | 2040 } |
| 2037 | 2041 |
| 2038 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); | 2042 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 2039 if (encoding == String::ONE_BYTE_ENCODING) { | 2043 if (encoding == String::ONE_BYTE_ENCODING) { |
| 2040 __ strb(value, operand); | 2044 __ stb(value, operand); |
| 2041 } else { | 2045 } else { |
| 2042 __ strh(value, operand); | 2046 __ sth(value, operand); |
| 2043 } | 2047 } |
| 2044 } | 2048 } |
| 2045 | 2049 |
| 2046 | 2050 |
| 2047 void LCodeGen::DoAddI(LAddI* instr) { | 2051 void LCodeGen::DoAddI(LAddI* instr) { |
| 2048 LOperand* left = instr->left(); | |
| 2049 LOperand* right = instr->right(); | 2052 LOperand* right = instr->right(); |
| 2050 LOperand* result = instr->result(); | 2053 Register left = ToRegister(instr->left()); |
| 2054 Register result = ToRegister(instr->result()); |
| 2051 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 2055 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 2052 SBit set_cond = can_overflow ? SetCC : LeaveCC; | 2056 #if V8_TARGET_ARCH_PPC64 |
| 2057 bool isInteger = !(instr->hydrogen()->representation().IsSmi() || |
| 2058 instr->hydrogen()->representation().IsExternal()); |
| 2059 #endif |
| 2053 | 2060 |
| 2054 if (right->IsStackSlot()) { | 2061 if (!can_overflow && right->IsConstantOperand()) { |
| 2062 Operand right_operand = ToOperand(right); |
| 2063 __ Add(result, left, right_operand.immediate(), r0); |
| 2064 } else { |
| 2055 Register right_reg = EmitLoadRegister(right, ip); | 2065 Register right_reg = EmitLoadRegister(right, ip); |
| 2056 __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 2066 |
| 2057 } else { | 2067 if (!can_overflow) { |
| 2058 ASSERT(right->IsRegister() || right->IsConstantOperand()); | 2068 __ add(result, left, right_reg); |
| 2059 __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 2069 } else { // can_overflow. |
| 2070 __ AddAndCheckForOverflow(result, |
| 2071 left, |
| 2072 right_reg, |
| 2073 scratch0(), r0); |
| 2074 #if V8_TARGET_ARCH_PPC64 |
| 2075 if (isInteger) { |
| 2076 __ extsw(scratch0(), scratch0(), SetRC); |
| 2077 } |
| 2078 #endif |
| 2079 // Doptimize on overflow |
| 2080 DeoptimizeIf(lt, instr->environment(), cr0); |
| 2081 } |
| 2060 } | 2082 } |
| 2061 | 2083 |
| 2062 if (can_overflow) { | 2084 #if V8_TARGET_ARCH_PPC64 |
| 2063 DeoptimizeIf(vs, instr->environment()); | 2085 if (isInteger) { |
| 2086 __ extsw(result, result); |
| 2064 } | 2087 } |
| 2088 #endif |
| 2065 } | 2089 } |
| 2066 | 2090 |
| 2067 | 2091 |
| 2068 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { | 2092 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
| 2069 LOperand* left = instr->left(); | 2093 LOperand* left = instr->left(); |
| 2070 LOperand* right = instr->right(); | 2094 LOperand* right = instr->right(); |
| 2071 HMathMinMax::Operation operation = instr->hydrogen()->operation(); | 2095 HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| 2096 Condition cond = (operation == HMathMinMax::kMathMin) ? le : ge; |
| 2072 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { | 2097 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
| 2073 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; | |
| 2074 Register left_reg = ToRegister(left); | 2098 Register left_reg = ToRegister(left); |
| 2075 Operand right_op = (right->IsRegister() || right->IsConstantOperand()) | 2099 Register right_reg = EmitLoadRegister(right, ip); |
| 2076 ? ToOperand(right) | |
| 2077 : Operand(EmitLoadRegister(right, ip)); | |
| 2078 Register result_reg = ToRegister(instr->result()); | 2100 Register result_reg = ToRegister(instr->result()); |
| 2079 __ cmp(left_reg, right_op); | 2101 Label return_left, done; |
| 2080 __ Move(result_reg, left_reg, condition); | 2102 #if V8_TARGET_ARCH_PPC64 |
| 2081 __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition)); | 2103 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2104 #endif |
| 2105 __ cmp(left_reg, right_reg); |
| 2106 #if V8_TARGET_ARCH_PPC64 |
| 2107 } else { |
| 2108 __ cmpw(left_reg, right_reg); |
| 2109 } |
| 2110 #endif |
| 2111 __ b(cond, &return_left); |
| 2112 __ Move(result_reg, right_reg); |
| 2113 __ b(&done); |
| 2114 __ bind(&return_left); |
| 2115 __ Move(result_reg, left_reg); |
| 2116 __ bind(&done); |
| 2082 } else { | 2117 } else { |
| 2083 ASSERT(instr->hydrogen()->representation().IsDouble()); | 2118 ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 2084 DwVfpRegister left_reg = ToDoubleRegister(left); | 2119 DoubleRegister left_reg = ToDoubleRegister(left); |
| 2085 DwVfpRegister right_reg = ToDoubleRegister(right); | 2120 DoubleRegister right_reg = ToDoubleRegister(right); |
| 2086 DwVfpRegister result_reg = ToDoubleRegister(instr->result()); | 2121 DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 2087 Label result_is_nan, return_left, return_right, check_zero, done; | 2122 Label check_nan_left, check_zero, return_left, return_right, done; |
| 2088 __ VFPCompareAndSetFlags(left_reg, right_reg); | 2123 __ fcmpu(left_reg, right_reg); |
| 2124 __ bunordered(&check_nan_left); |
| 2125 __ beq(&check_zero); |
| 2126 __ b(cond, &return_left); |
| 2127 __ b(&return_right); |
| 2128 |
| 2129 __ bind(&check_zero); |
| 2130 __ fcmpu(left_reg, kDoubleRegZero); |
| 2131 __ bne(&return_left); // left == right != 0. |
| 2132 |
| 2133 // At this point, both left and right are either 0 or -0. |
| 2134 // N.B. The following works because +0 + -0 == +0 |
| 2089 if (operation == HMathMinMax::kMathMin) { | 2135 if (operation == HMathMinMax::kMathMin) { |
| 2090 __ b(mi, &return_left); | 2136 // For min we want logical-or of sign bit: -(-L + -R) |
| 2091 __ b(gt, &return_right); | 2137 __ fneg(left_reg, left_reg); |
| 2138 __ fsub(result_reg, left_reg, right_reg); |
| 2139 __ fneg(result_reg, result_reg); |
| 2092 } else { | 2140 } else { |
| 2093 __ b(mi, &return_right); | 2141 // For max we want logical-and of sign bit: (L + R) |
| 2094 __ b(gt, &return_left); | 2142 __ fadd(result_reg, left_reg, right_reg); |
| 2095 } | |
| 2096 __ b(vs, &result_is_nan); | |
| 2097 // Left equals right => check for -0. | |
| 2098 __ VFPCompareAndSetFlags(left_reg, 0.0); | |
| 2099 if (left_reg.is(result_reg) || right_reg.is(result_reg)) { | |
| 2100 __ b(ne, &done); // left == right != 0. | |
| 2101 } else { | |
| 2102 __ b(ne, &return_left); // left == right != 0. | |
| 2103 } | |
| 2104 // At this point, both left and right are either 0 or -0. | |
| 2105 if (operation == HMathMinMax::kMathMin) { | |
| 2106 // We could use a single 'vorr' instruction here if we had NEON support. | |
| 2107 __ vneg(left_reg, left_reg); | |
| 2108 __ vsub(result_reg, left_reg, right_reg); | |
| 2109 __ vneg(result_reg, result_reg); | |
| 2110 } else { | |
| 2111 // Since we operate on +0 and/or -0, vadd and vand have the same effect; | |
| 2112 // the decision for vadd is easy because vand is a NEON instruction. | |
| 2113 __ vadd(result_reg, left_reg, right_reg); | |
| 2114 } | 2143 } |
| 2115 __ b(&done); | 2144 __ b(&done); |
| 2116 | 2145 |
| 2117 __ bind(&result_is_nan); | 2146 __ bind(&check_nan_left); |
| 2118 __ vadd(result_reg, left_reg, right_reg); | 2147 __ fcmpu(left_reg, left_reg); |
| 2148 __ bunordered(&return_left); // left == NaN. |
| 2149 |
| 2150 __ bind(&return_right); |
| 2151 if (!right_reg.is(result_reg)) { |
| 2152 __ fmr(result_reg, right_reg); |
| 2153 } |
| 2119 __ b(&done); | 2154 __ b(&done); |
| 2120 | 2155 |
| 2121 __ bind(&return_right); | 2156 __ bind(&return_left); |
| 2122 __ Move(result_reg, right_reg); | |
| 2123 if (!left_reg.is(result_reg)) { | 2157 if (!left_reg.is(result_reg)) { |
| 2124 __ b(&done); | 2158 __ fmr(result_reg, left_reg); |
| 2125 } | 2159 } |
| 2126 | |
| 2127 __ bind(&return_left); | |
| 2128 __ Move(result_reg, left_reg); | |
| 2129 | |
| 2130 __ bind(&done); | 2160 __ bind(&done); |
| 2131 } | 2161 } |
| 2132 } | 2162 } |
| 2133 | 2163 |
| 2134 | 2164 |
| 2135 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { | 2165 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
| 2136 DwVfpRegister left = ToDoubleRegister(instr->left()); | 2166 DoubleRegister left = ToDoubleRegister(instr->left()); |
| 2137 DwVfpRegister right = ToDoubleRegister(instr->right()); | 2167 DoubleRegister right = ToDoubleRegister(instr->right()); |
| 2138 DwVfpRegister result = ToDoubleRegister(instr->result()); | 2168 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2139 switch (instr->op()) { | 2169 switch (instr->op()) { |
| 2140 case Token::ADD: | 2170 case Token::ADD: |
| 2141 __ vadd(result, left, right); | 2171 __ fadd(result, left, right); |
| 2142 break; | 2172 break; |
| 2143 case Token::SUB: | 2173 case Token::SUB: |
| 2144 __ vsub(result, left, right); | 2174 __ fsub(result, left, right); |
| 2145 break; | 2175 break; |
| 2146 case Token::MUL: | 2176 case Token::MUL: |
| 2147 __ vmul(result, left, right); | 2177 __ fmul(result, left, right); |
| 2148 break; | 2178 break; |
| 2149 case Token::DIV: | 2179 case Token::DIV: |
| 2150 __ vdiv(result, left, right); | 2180 __ fdiv(result, left, right); |
| 2151 break; | 2181 break; |
| 2152 case Token::MOD: { | 2182 case Token::MOD: { |
| 2153 __ PrepareCallCFunction(0, 2, scratch0()); | 2183 __ PrepareCallCFunction(0, 2, scratch0()); |
| 2154 __ MovToFloatParameters(left, right); | 2184 __ MovToFloatParameters(left, right); |
| 2155 __ CallCFunction( | 2185 __ CallCFunction( |
| 2156 ExternalReference::mod_two_doubles_operation(isolate()), | 2186 ExternalReference::mod_two_doubles_operation(isolate()), |
| 2157 0, 2); | 2187 0, 2); |
| 2158 // Move the result in the double result register. | 2188 // Move the result in the double result register. |
| 2159 __ MovFromFloatResult(result); | 2189 __ MovFromFloatResult(result); |
| 2160 break; | 2190 break; |
| 2161 } | 2191 } |
| 2162 default: | 2192 default: |
| 2163 UNREACHABLE(); | 2193 UNREACHABLE(); |
| 2164 break; | 2194 break; |
| 2165 } | 2195 } |
| 2166 } | 2196 } |
| 2167 | 2197 |
| 2168 | 2198 |
| 2169 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { | 2199 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
| 2170 ASSERT(ToRegister(instr->context()).is(cp)); | 2200 ASSERT(ToRegister(instr->context()).is(cp)); |
| 2171 ASSERT(ToRegister(instr->left()).is(r1)); | 2201 ASSERT(ToRegister(instr->left()).is(r4)); |
| 2172 ASSERT(ToRegister(instr->right()).is(r0)); | 2202 ASSERT(ToRegister(instr->right()).is(r3)); |
| 2173 ASSERT(ToRegister(instr->result()).is(r0)); | 2203 ASSERT(ToRegister(instr->result()).is(r3)); |
| 2174 | 2204 |
| 2175 BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); | 2205 BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); |
| 2176 // Block literal pool emission to ensure nop indicating no inlined smi code | |
| 2177 // is in the correct position. | |
| 2178 Assembler::BlockConstPoolScope block_const_pool(masm()); | |
| 2179 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 2206 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2180 } | 2207 } |
| 2181 | 2208 |
| 2182 | 2209 |
| 2183 template<class InstrType> | 2210 template<class InstrType> |
| 2184 void LCodeGen::EmitBranch(InstrType instr, Condition condition) { | 2211 void LCodeGen::EmitBranch(InstrType instr, Condition cond, |
| 2212 CRegister cr) { |
| 2185 int left_block = instr->TrueDestination(chunk_); | 2213 int left_block = instr->TrueDestination(chunk_); |
| 2186 int right_block = instr->FalseDestination(chunk_); | 2214 int right_block = instr->FalseDestination(chunk_); |
| 2187 | 2215 |
| 2188 int next_block = GetNextEmittedBlock(); | 2216 int next_block = GetNextEmittedBlock(); |
| 2189 | 2217 |
| 2190 if (right_block == left_block || condition == al) { | 2218 if (right_block == left_block || cond == al) { |
| 2191 EmitGoto(left_block); | 2219 EmitGoto(left_block); |
| 2192 } else if (left_block == next_block) { | 2220 } else if (left_block == next_block) { |
| 2193 __ b(NegateCondition(condition), chunk_->GetAssemblyLabel(right_block)); | 2221 __ b(NegateCondition(cond), chunk_->GetAssemblyLabel(right_block), cr); |
| 2194 } else if (right_block == next_block) { | 2222 } else if (right_block == next_block) { |
| 2195 __ b(condition, chunk_->GetAssemblyLabel(left_block)); | 2223 __ b(cond, chunk_->GetAssemblyLabel(left_block), cr); |
| 2196 } else { | 2224 } else { |
| 2197 __ b(condition, chunk_->GetAssemblyLabel(left_block)); | 2225 __ b(cond, chunk_->GetAssemblyLabel(left_block), cr); |
| 2198 __ b(chunk_->GetAssemblyLabel(right_block)); | 2226 __ b(chunk_->GetAssemblyLabel(right_block)); |
| 2199 } | 2227 } |
| 2200 } | 2228 } |
| 2201 | 2229 |
| 2202 | 2230 |
| 2203 template<class InstrType> | 2231 template<class InstrType> |
| 2204 void LCodeGen::EmitFalseBranch(InstrType instr, Condition condition) { | 2232 void LCodeGen::EmitFalseBranch(InstrType instr, Condition cond, |
| 2233 CRegister cr) { |
| 2205 int false_block = instr->FalseDestination(chunk_); | 2234 int false_block = instr->FalseDestination(chunk_); |
| 2206 __ b(condition, chunk_->GetAssemblyLabel(false_block)); | 2235 __ b(cond, chunk_->GetAssemblyLabel(false_block), cr); |
| 2207 } | 2236 } |
| 2208 | 2237 |
| 2209 | 2238 |
| 2210 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { | 2239 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 2211 __ stop("LBreak"); | 2240 __ stop("LBreak"); |
| 2212 } | 2241 } |
| 2213 | 2242 |
| 2214 | 2243 |
| 2215 void LCodeGen::DoBranch(LBranch* instr) { | 2244 void LCodeGen::DoBranch(LBranch* instr) { |
| 2216 Representation r = instr->hydrogen()->value()->representation(); | 2245 Representation r = instr->hydrogen()->value()->representation(); |
| 2217 if (r.IsInteger32() || r.IsSmi()) { | 2246 DoubleRegister dbl_scratch = double_scratch0(); |
| 2247 const uint crZOrNaNBits = (1 << (31 - Assembler::encode_crbit(cr7, CR_EQ)) | |
| 2248 1 << (31 - Assembler::encode_crbit(cr7, CR_FU))); |
| 2249 |
| 2250 if (r.IsInteger32()) { |
| 2218 ASSERT(!info()->IsStub()); | 2251 ASSERT(!info()->IsStub()); |
| 2219 Register reg = ToRegister(instr->value()); | 2252 Register reg = ToRegister(instr->value()); |
| 2220 __ cmp(reg, Operand::Zero()); | 2253 __ cmpwi(reg, Operand::Zero()); |
| 2254 EmitBranch(instr, ne); |
| 2255 } else if (r.IsSmi()) { |
| 2256 ASSERT(!info()->IsStub()); |
| 2257 Register reg = ToRegister(instr->value()); |
| 2258 __ cmpi(reg, Operand::Zero()); |
| 2221 EmitBranch(instr, ne); | 2259 EmitBranch(instr, ne); |
| 2222 } else if (r.IsDouble()) { | 2260 } else if (r.IsDouble()) { |
| 2223 ASSERT(!info()->IsStub()); | 2261 ASSERT(!info()->IsStub()); |
| 2224 DwVfpRegister reg = ToDoubleRegister(instr->value()); | 2262 DoubleRegister reg = ToDoubleRegister(instr->value()); |
| 2225 // Test the double value. Zero and NaN are false. | 2263 // Test the double value. Zero and NaN are false. |
| 2226 __ VFPCompareAndSetFlags(reg, 0.0); | 2264 __ fcmpu(reg, kDoubleRegZero, cr7); |
| 2227 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN -> false) | 2265 __ mfcr(r0); |
| 2228 EmitBranch(instr, ne); | 2266 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2267 EmitBranch(instr, eq, cr0); |
| 2229 } else { | 2268 } else { |
| 2230 ASSERT(r.IsTagged()); | 2269 ASSERT(r.IsTagged()); |
| 2231 Register reg = ToRegister(instr->value()); | 2270 Register reg = ToRegister(instr->value()); |
| 2232 HType type = instr->hydrogen()->value()->type(); | 2271 HType type = instr->hydrogen()->value()->type(); |
| 2233 if (type.IsBoolean()) { | 2272 if (type.IsBoolean()) { |
| 2234 ASSERT(!info()->IsStub()); | 2273 ASSERT(!info()->IsStub()); |
| 2235 __ CompareRoot(reg, Heap::kTrueValueRootIndex); | 2274 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 2236 EmitBranch(instr, eq); | 2275 EmitBranch(instr, eq); |
| 2237 } else if (type.IsSmi()) { | 2276 } else if (type.IsSmi()) { |
| 2238 ASSERT(!info()->IsStub()); | 2277 ASSERT(!info()->IsStub()); |
| 2239 __ cmp(reg, Operand::Zero()); | 2278 __ cmpi(reg, Operand::Zero()); |
| 2240 EmitBranch(instr, ne); | 2279 EmitBranch(instr, ne); |
| 2241 } else if (type.IsJSArray()) { | 2280 } else if (type.IsJSArray()) { |
| 2242 ASSERT(!info()->IsStub()); | 2281 ASSERT(!info()->IsStub()); |
| 2243 EmitBranch(instr, al); | 2282 EmitBranch(instr, al); |
| 2244 } else if (type.IsHeapNumber()) { | 2283 } else if (type.IsHeapNumber()) { |
| 2245 ASSERT(!info()->IsStub()); | 2284 ASSERT(!info()->IsStub()); |
| 2246 DwVfpRegister dbl_scratch = double_scratch0(); | 2285 __ lfd(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2247 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); | |
| 2248 // Test the double value. Zero and NaN are false. | 2286 // Test the double value. Zero and NaN are false. |
| 2249 __ VFPCompareAndSetFlags(dbl_scratch, 0.0); | 2287 __ fcmpu(dbl_scratch, kDoubleRegZero, cr7); |
| 2250 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN) | 2288 __ mfcr(r0); |
| 2251 EmitBranch(instr, ne); | 2289 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2290 EmitBranch(instr, eq, cr0); |
| 2252 } else if (type.IsString()) { | 2291 } else if (type.IsString()) { |
| 2253 ASSERT(!info()->IsStub()); | 2292 ASSERT(!info()->IsStub()); |
| 2254 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); | 2293 __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 2255 __ cmp(ip, Operand::Zero()); | 2294 __ cmpi(ip, Operand::Zero()); |
| 2256 EmitBranch(instr, ne); | 2295 EmitBranch(instr, ne); |
| 2257 } else { | 2296 } else { |
| 2258 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); | 2297 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 2259 // Avoid deopts in the case where we've never executed this path before. | 2298 // Avoid deopts in the case where we've never executed this path before. |
| 2260 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); | 2299 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
| 2261 | 2300 |
| 2262 if (expected.Contains(ToBooleanStub::UNDEFINED)) { | 2301 if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2263 // undefined -> false. | 2302 // undefined -> false. |
| 2264 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); | 2303 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
| 2265 __ b(eq, instr->FalseLabel(chunk_)); | 2304 __ beq(instr->FalseLabel(chunk_)); |
| 2266 } | 2305 } |
| 2267 if (expected.Contains(ToBooleanStub::BOOLEAN)) { | 2306 if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2268 // Boolean -> its value. | 2307 // Boolean -> its value. |
| 2269 __ CompareRoot(reg, Heap::kTrueValueRootIndex); | 2308 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 2270 __ b(eq, instr->TrueLabel(chunk_)); | 2309 __ beq(instr->TrueLabel(chunk_)); |
| 2271 __ CompareRoot(reg, Heap::kFalseValueRootIndex); | 2310 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 2272 __ b(eq, instr->FalseLabel(chunk_)); | 2311 __ beq(instr->FalseLabel(chunk_)); |
| 2273 } | 2312 } |
| 2274 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { | 2313 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2275 // 'null' -> false. | 2314 // 'null' -> false. |
| 2276 __ CompareRoot(reg, Heap::kNullValueRootIndex); | 2315 __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 2277 __ b(eq, instr->FalseLabel(chunk_)); | 2316 __ beq(instr->FalseLabel(chunk_)); |
| 2278 } | 2317 } |
| 2279 | 2318 |
| 2280 if (expected.Contains(ToBooleanStub::SMI)) { | 2319 if (expected.Contains(ToBooleanStub::SMI)) { |
| 2281 // Smis: 0 -> false, all other -> true. | 2320 // Smis: 0 -> false, all other -> true. |
| 2282 __ cmp(reg, Operand::Zero()); | 2321 __ cmpi(reg, Operand::Zero()); |
| 2283 __ b(eq, instr->FalseLabel(chunk_)); | 2322 __ beq(instr->FalseLabel(chunk_)); |
| 2284 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); | 2323 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
| 2285 } else if (expected.NeedsMap()) { | 2324 } else if (expected.NeedsMap()) { |
| 2286 // If we need a map later and have a Smi -> deopt. | 2325 // If we need a map later and have a Smi -> deopt. |
| 2287 __ SmiTst(reg); | 2326 __ TestIfSmi(reg, r0); |
| 2288 DeoptimizeIf(eq, instr->environment()); | 2327 DeoptimizeIf(eq, instr->environment(), cr0); |
| 2289 } | 2328 } |
| 2290 | 2329 |
| 2291 const Register map = scratch0(); | 2330 const Register map = scratch0(); |
| 2292 if (expected.NeedsMap()) { | 2331 if (expected.NeedsMap()) { |
| 2293 __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); | 2332 __ LoadP(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2294 | 2333 |
| 2295 if (expected.CanBeUndetectable()) { | 2334 if (expected.CanBeUndetectable()) { |
| 2296 // Undetectable -> false. | 2335 // Undetectable -> false. |
| 2297 __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); | 2336 __ lbz(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 2298 __ tst(ip, Operand(1 << Map::kIsUndetectable)); | 2337 __ TestBit(ip, Map::kIsUndetectable, r0); |
| 2299 __ b(ne, instr->FalseLabel(chunk_)); | 2338 __ bne(instr->FalseLabel(chunk_), cr0); |
| 2300 } | 2339 } |
| 2301 } | 2340 } |
| 2302 | 2341 |
| 2303 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { | 2342 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2304 // spec object -> true. | 2343 // spec object -> true. |
| 2305 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); | 2344 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 2306 __ b(ge, instr->TrueLabel(chunk_)); | 2345 __ bge(instr->TrueLabel(chunk_)); |
| 2307 } | 2346 } |
| 2308 | 2347 |
| 2309 if (expected.Contains(ToBooleanStub::STRING)) { | 2348 if (expected.Contains(ToBooleanStub::STRING)) { |
| 2310 // String value -> false iff empty. | 2349 // String value -> false iff empty. |
| 2311 Label not_string; | 2350 Label not_string; |
| 2312 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); | 2351 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 2313 __ b(ge, ¬_string); | 2352 __ bge(¬_string); |
| 2314 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); | 2353 __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 2315 __ cmp(ip, Operand::Zero()); | 2354 __ cmpi(ip, Operand::Zero()); |
| 2316 __ b(ne, instr->TrueLabel(chunk_)); | 2355 __ bne(instr->TrueLabel(chunk_)); |
| 2317 __ b(instr->FalseLabel(chunk_)); | 2356 __ b(instr->FalseLabel(chunk_)); |
| 2318 __ bind(¬_string); | 2357 __ bind(¬_string); |
| 2319 } | 2358 } |
| 2320 | 2359 |
| 2321 if (expected.Contains(ToBooleanStub::SYMBOL)) { | 2360 if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2322 // Symbol value -> true. | 2361 // Symbol value -> true. |
| 2323 __ CompareInstanceType(map, ip, SYMBOL_TYPE); | 2362 __ CompareInstanceType(map, ip, SYMBOL_TYPE); |
| 2324 __ b(eq, instr->TrueLabel(chunk_)); | 2363 __ beq(instr->TrueLabel(chunk_)); |
| 2325 } | 2364 } |
| 2326 | 2365 |
| 2327 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { | 2366 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2328 // heap number -> false iff +0, -0, or NaN. | 2367 // heap number -> false iff +0, -0, or NaN. |
| 2329 DwVfpRegister dbl_scratch = double_scratch0(); | |
| 2330 Label not_heap_number; | 2368 Label not_heap_number; |
| 2331 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); | 2369 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 2332 __ b(ne, ¬_heap_number); | 2370 __ bne(¬_heap_number); |
| 2333 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); | 2371 __ lfd(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2334 __ VFPCompareAndSetFlags(dbl_scratch, 0.0); | 2372 // Test the double value. Zero and NaN are false. |
| 2335 __ cmp(r0, r0, vs); // NaN -> false. | 2373 __ fcmpu(dbl_scratch, kDoubleRegZero, cr7); |
| 2336 __ b(eq, instr->FalseLabel(chunk_)); // +0, -0 -> false. | 2374 __ mfcr(r0); |
| 2375 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2376 __ bne(instr->FalseLabel(chunk_), cr0); |
| 2337 __ b(instr->TrueLabel(chunk_)); | 2377 __ b(instr->TrueLabel(chunk_)); |
| 2338 __ bind(¬_heap_number); | 2378 __ bind(¬_heap_number); |
| 2339 } | 2379 } |
| 2340 | 2380 |
| 2341 if (!expected.IsGeneric()) { | 2381 if (!expected.IsGeneric()) { |
| 2342 // We've seen something for the first time -> deopt. | 2382 // We've seen something for the first time -> deopt. |
| 2343 // This can only happen if we are not generic already. | 2383 // This can only happen if we are not generic already. |
| 2344 DeoptimizeIf(al, instr->environment()); | 2384 DeoptimizeIf(al, instr->environment()); |
| 2345 } | 2385 } |
| 2346 } | 2386 } |
| 2347 } | 2387 } |
| 2348 } | 2388 } |
| 2349 | 2389 |
| 2350 | 2390 |
| 2351 void LCodeGen::EmitGoto(int block) { | 2391 void LCodeGen::EmitGoto(int block) { |
| 2352 if (!IsNextEmittedBlock(block)) { | 2392 if (!IsNextEmittedBlock(block)) { |
| 2353 __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); | 2393 __ b(chunk_->GetAssemblyLabel(LookupDestination(block))); |
| 2354 } | 2394 } |
| 2355 } | 2395 } |
| 2356 | 2396 |
| 2357 | 2397 |
| 2358 void LCodeGen::DoGoto(LGoto* instr) { | 2398 void LCodeGen::DoGoto(LGoto* instr) { |
| 2359 EmitGoto(instr->block_id()); | 2399 EmitGoto(instr->block_id()); |
| 2360 } | 2400 } |
| 2361 | 2401 |
| 2362 | 2402 |
| 2363 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { | 2403 Condition LCodeGen::TokenToCondition(Token::Value op) { |
| 2364 Condition cond = kNoCondition; | 2404 Condition cond = kNoCondition; |
| 2365 switch (op) { | 2405 switch (op) { |
| 2366 case Token::EQ: | 2406 case Token::EQ: |
| 2367 case Token::EQ_STRICT: | 2407 case Token::EQ_STRICT: |
| 2368 cond = eq; | 2408 cond = eq; |
| 2369 break; | 2409 break; |
| 2370 case Token::NE: | 2410 case Token::NE: |
| 2371 case Token::NE_STRICT: | 2411 case Token::NE_STRICT: |
| 2372 cond = ne; | 2412 cond = ne; |
| 2373 break; | 2413 break; |
| 2374 case Token::LT: | 2414 case Token::LT: |
| 2375 cond = is_unsigned ? lo : lt; | 2415 cond = lt; |
| 2376 break; | 2416 break; |
| 2377 case Token::GT: | 2417 case Token::GT: |
| 2378 cond = is_unsigned ? hi : gt; | 2418 cond = gt; |
| 2379 break; | 2419 break; |
| 2380 case Token::LTE: | 2420 case Token::LTE: |
| 2381 cond = is_unsigned ? ls : le; | 2421 cond = le; |
| 2382 break; | 2422 break; |
| 2383 case Token::GTE: | 2423 case Token::GTE: |
| 2384 cond = is_unsigned ? hs : ge; | 2424 cond = ge; |
| 2385 break; | 2425 break; |
| 2386 case Token::IN: | 2426 case Token::IN: |
| 2387 case Token::INSTANCEOF: | 2427 case Token::INSTANCEOF: |
| 2388 default: | 2428 default: |
| 2389 UNREACHABLE(); | 2429 UNREACHABLE(); |
| 2390 } | 2430 } |
| 2391 return cond; | 2431 return cond; |
| 2392 } | 2432 } |
| 2393 | 2433 |
| 2394 | 2434 |
| 2395 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { | 2435 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
| 2396 LOperand* left = instr->left(); | 2436 LOperand* left = instr->left(); |
| 2397 LOperand* right = instr->right(); | 2437 LOperand* right = instr->right(); |
| 2398 bool is_unsigned = | 2438 bool is_unsigned = |
| 2399 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || | 2439 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || |
| 2400 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); | 2440 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); |
| 2401 Condition cond = TokenToCondition(instr->op(), is_unsigned); | 2441 Condition cond = TokenToCondition(instr->op()); |
| 2402 | 2442 |
| 2403 if (left->IsConstantOperand() && right->IsConstantOperand()) { | 2443 if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2404 // We can statically evaluate the comparison. | 2444 // We can statically evaluate the comparison. |
| 2405 double left_val = ToDouble(LConstantOperand::cast(left)); | 2445 double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2406 double right_val = ToDouble(LConstantOperand::cast(right)); | 2446 double right_val = ToDouble(LConstantOperand::cast(right)); |
| 2407 int next_block = EvalComparison(instr->op(), left_val, right_val) ? | 2447 int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2408 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); | 2448 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
| 2409 EmitGoto(next_block); | 2449 EmitGoto(next_block); |
| 2410 } else { | 2450 } else { |
| 2411 if (instr->is_double()) { | 2451 if (instr->is_double()) { |
| 2412 // Compare left and right operands as doubles and load the | 2452 // Compare left and right operands as doubles and load the |
| 2413 // resulting flags into the normal status register. | 2453 // resulting flags into the normal status register. |
| 2414 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); | 2454 __ fcmpu(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2415 // If a NaN is involved, i.e. the result is unordered (V set), | 2455 // If a NaN is involved, i.e. the result is unordered, |
| 2416 // jump to false block label. | 2456 // jump to false block label. |
| 2417 __ b(vs, instr->FalseLabel(chunk_)); | 2457 __ bunordered(instr->FalseLabel(chunk_)); |
| 2418 } else { | 2458 } else { |
| 2419 if (right->IsConstantOperand()) { | 2459 if (right->IsConstantOperand()) { |
| 2420 int32_t value = ToInteger32(LConstantOperand::cast(right)); | 2460 int32_t value = ToInteger32(LConstantOperand::cast(right)); |
| 2421 if (instr->hydrogen_value()->representation().IsSmi()) { | 2461 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2422 __ cmp(ToRegister(left), Operand(Smi::FromInt(value))); | 2462 if (is_unsigned) { |
| 2463 __ CmplSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2464 } else { |
| 2465 __ CmpSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2466 } |
| 2423 } else { | 2467 } else { |
| 2424 __ cmp(ToRegister(left), Operand(value)); | 2468 if (is_unsigned) { |
| 2469 __ Cmplwi(ToRegister(left), Operand(value), r0); |
| 2470 } else { |
| 2471 __ Cmpwi(ToRegister(left), Operand(value), r0); |
| 2472 } |
| 2425 } | 2473 } |
| 2426 } else if (left->IsConstantOperand()) { | 2474 } else if (left->IsConstantOperand()) { |
| 2427 int32_t value = ToInteger32(LConstantOperand::cast(left)); | 2475 int32_t value = ToInteger32(LConstantOperand::cast(left)); |
| 2428 if (instr->hydrogen_value()->representation().IsSmi()) { | 2476 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2429 __ cmp(ToRegister(right), Operand(Smi::FromInt(value))); | 2477 if (is_unsigned) { |
| 2478 __ CmplSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2479 } else { |
| 2480 __ CmpSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2481 } |
| 2430 } else { | 2482 } else { |
| 2431 __ cmp(ToRegister(right), Operand(value)); | 2483 if (is_unsigned) { |
| 2484 __ Cmplwi(ToRegister(right), Operand(value), r0); |
| 2485 } else { |
| 2486 __ Cmpwi(ToRegister(right), Operand(value), r0); |
| 2487 } |
| 2432 } | 2488 } |
| 2433 // We commuted the operands, so commute the condition. | 2489 // We commuted the operands, so commute the condition. |
| 2434 cond = CommuteCondition(cond); | 2490 cond = CommuteCondition(cond); |
| 2491 } else if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2492 if (is_unsigned) { |
| 2493 __ cmpl(ToRegister(left), ToRegister(right)); |
| 2494 } else { |
| 2495 __ cmp(ToRegister(left), ToRegister(right)); |
| 2496 } |
| 2435 } else { | 2497 } else { |
| 2436 __ cmp(ToRegister(left), ToRegister(right)); | 2498 if (is_unsigned) { |
| 2499 __ cmplw(ToRegister(left), ToRegister(right)); |
| 2500 } else { |
| 2501 __ cmpw(ToRegister(left), ToRegister(right)); |
| 2502 } |
| 2437 } | 2503 } |
| 2438 } | 2504 } |
| 2439 EmitBranch(instr, cond); | 2505 EmitBranch(instr, cond); |
| 2440 } | 2506 } |
| 2441 } | 2507 } |
| 2442 | 2508 |
| 2443 | 2509 |
| 2444 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { | 2510 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
| 2445 Register left = ToRegister(instr->left()); | 2511 Register left = ToRegister(instr->left()); |
| 2446 Register right = ToRegister(instr->right()); | 2512 Register right = ToRegister(instr->right()); |
| 2447 | 2513 |
| 2448 __ cmp(left, Operand(right)); | 2514 __ cmp(left, right); |
| 2449 EmitBranch(instr, eq); | 2515 EmitBranch(instr, eq); |
| 2450 } | 2516 } |
| 2451 | 2517 |
| 2452 | 2518 |
| 2453 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { | 2519 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2454 if (instr->hydrogen()->representation().IsTagged()) { | 2520 if (instr->hydrogen()->representation().IsTagged()) { |
| 2455 Register input_reg = ToRegister(instr->object()); | 2521 Register input_reg = ToRegister(instr->object()); |
| 2456 __ mov(ip, Operand(factory()->the_hole_value())); | 2522 __ mov(ip, Operand(factory()->the_hole_value())); |
| 2457 __ cmp(input_reg, ip); | 2523 __ cmp(input_reg, ip); |
| 2458 EmitBranch(instr, eq); | 2524 EmitBranch(instr, eq); |
| 2459 return; | 2525 return; |
| 2460 } | 2526 } |
| 2461 | 2527 |
| 2462 DwVfpRegister input_reg = ToDoubleRegister(instr->object()); | 2528 DoubleRegister input_reg = ToDoubleRegister(instr->object()); |
| 2463 __ VFPCompareAndSetFlags(input_reg, input_reg); | 2529 __ fcmpu(input_reg, input_reg); |
| 2464 EmitFalseBranch(instr, vc); | 2530 EmitFalseBranch(instr, ordered); |
| 2465 | 2531 |
| 2466 Register scratch = scratch0(); | 2532 Register scratch = scratch0(); |
| 2467 __ VmovHigh(scratch, input_reg); | 2533 __ stfdu(input_reg, MemOperand(sp, -kDoubleSize)); |
| 2468 __ cmp(scratch, Operand(kHoleNanUpper32)); | 2534 __ nop(); // LHS/RAW optimization |
| 2535 __ lwz(scratch, MemOperand(sp, Register::kExponentOffset)); |
| 2536 __ addi(sp, sp, Operand(kDoubleSize)); |
| 2537 __ Cmpi(scratch, Operand(kHoleNanUpper32), r0); |
| 2469 EmitBranch(instr, eq); | 2538 EmitBranch(instr, eq); |
| 2470 } | 2539 } |
| 2471 | 2540 |
| 2472 | 2541 |
| 2473 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { | 2542 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2474 Representation rep = instr->hydrogen()->value()->representation(); | 2543 Representation rep = instr->hydrogen()->value()->representation(); |
| 2475 ASSERT(!rep.IsInteger32()); | 2544 ASSERT(!rep.IsInteger32()); |
| 2476 Register scratch = ToRegister(instr->temp()); | 2545 Register scratch = ToRegister(instr->temp()); |
| 2477 | 2546 |
| 2478 if (rep.IsDouble()) { | 2547 if (rep.IsDouble()) { |
| 2479 DwVfpRegister value = ToDoubleRegister(instr->value()); | 2548 DoubleRegister value = ToDoubleRegister(instr->value()); |
| 2480 __ VFPCompareAndSetFlags(value, 0.0); | 2549 __ fcmpu(value, kDoubleRegZero); |
| 2481 EmitFalseBranch(instr, ne); | 2550 EmitFalseBranch(instr, ne); |
| 2482 __ VmovHigh(scratch, value); | 2551 __ stfdu(value, MemOperand(sp, -kDoubleSize)); |
| 2483 __ cmp(scratch, Operand(0x80000000)); | 2552 __ nop(); // LHS/RAW optimization |
| 2553 __ lwz(scratch, MemOperand(sp, Register::kExponentOffset)); |
| 2554 __ addi(sp, sp, Operand(kDoubleSize)); |
| 2555 __ cmpwi(scratch, Operand::Zero()); |
| 2556 EmitBranch(instr, lt); |
| 2484 } else { | 2557 } else { |
| 2485 Register value = ToRegister(instr->value()); | 2558 Register value = ToRegister(instr->value()); |
| 2486 __ CheckMap(value, | 2559 __ CheckMap(value, |
| 2487 scratch, | 2560 scratch, |
| 2488 Heap::kHeapNumberMapRootIndex, | 2561 Heap::kHeapNumberMapRootIndex, |
| 2489 instr->FalseLabel(chunk()), | 2562 instr->FalseLabel(chunk()), |
| 2490 DO_SMI_CHECK); | 2563 DO_SMI_CHECK); |
| 2491 __ ldr(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); | 2564 #if V8_TARGET_ARCH_PPC64 |
| 2492 __ ldr(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset)); | 2565 __ LoadP(scratch, FieldMemOperand(value, HeapNumber::kValueOffset)); |
| 2493 __ cmp(scratch, Operand(0x80000000)); | 2566 __ li(ip, Operand(1)); |
| 2494 __ cmp(ip, Operand(0x00000000), eq); | 2567 __ rotrdi(ip, ip, 1); // ip = 0x80000000_00000000 |
| 2568 __ cmp(scratch, ip); |
| 2569 #else |
| 2570 __ lwz(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); |
| 2571 __ lwz(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset)); |
| 2572 Label skip; |
| 2573 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 2574 __ cmp(scratch, r0); |
| 2575 __ bne(&skip); |
| 2576 __ cmpi(ip, Operand::Zero()); |
| 2577 __ bind(&skip); |
| 2578 #endif |
| 2579 EmitBranch(instr, eq); |
| 2495 } | 2580 } |
| 2496 EmitBranch(instr, eq); | |
| 2497 } | 2581 } |
| 2498 | 2582 |
| 2499 | 2583 |
| 2500 Condition LCodeGen::EmitIsObject(Register input, | 2584 Condition LCodeGen::EmitIsObject(Register input, |
| 2501 Register temp1, | 2585 Register temp1, |
| 2502 Label* is_not_object, | 2586 Label* is_not_object, |
| 2503 Label* is_object) { | 2587 Label* is_object) { |
| 2504 Register temp2 = scratch0(); | 2588 Register temp2 = scratch0(); |
| 2505 __ JumpIfSmi(input, is_not_object); | 2589 __ JumpIfSmi(input, is_not_object); |
| 2506 | 2590 |
| 2507 __ LoadRoot(temp2, Heap::kNullValueRootIndex); | 2591 __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 2508 __ cmp(input, temp2); | 2592 __ cmp(input, temp2); |
| 2509 __ b(eq, is_object); | 2593 __ beq(is_object); |
| 2510 | 2594 |
| 2511 // Load map. | 2595 // Load map. |
| 2512 __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); | 2596 __ LoadP(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2513 // Undetectable objects behave like undefined. | 2597 // Undetectable objects behave like undefined. |
| 2514 __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); | 2598 __ lbz(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 2515 __ tst(temp2, Operand(1 << Map::kIsUndetectable)); | 2599 __ TestBit(temp2, Map::kIsUndetectable, r0); |
| 2516 __ b(ne, is_not_object); | 2600 __ bne(is_not_object, cr0); |
| 2517 | 2601 |
| 2518 // Load instance type and check that it is in object type range. | 2602 // Load instance type and check that it is in object type range. |
| 2519 __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); | 2603 __ lbz(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
| 2520 __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2604 __ cmpi(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2521 __ b(lt, is_not_object); | 2605 __ blt(is_not_object); |
| 2522 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2606 __ cmpi(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2523 return le; | 2607 return le; |
| 2524 } | 2608 } |
| 2525 | 2609 |
| 2526 | 2610 |
| 2527 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { | 2611 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
| 2528 Register reg = ToRegister(instr->value()); | 2612 Register reg = ToRegister(instr->value()); |
| 2529 Register temp1 = ToRegister(instr->temp()); | 2613 Register temp1 = ToRegister(instr->temp()); |
| 2530 | 2614 |
| 2531 Condition true_cond = | 2615 Condition true_cond = |
| 2532 EmitIsObject(reg, temp1, | 2616 EmitIsObject(reg, temp1, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2558 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 2642 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 2559 Condition true_cond = | 2643 Condition true_cond = |
| 2560 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); | 2644 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); |
| 2561 | 2645 |
| 2562 EmitBranch(instr, true_cond); | 2646 EmitBranch(instr, true_cond); |
| 2563 } | 2647 } |
| 2564 | 2648 |
| 2565 | 2649 |
| 2566 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { | 2650 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 2567 Register input_reg = EmitLoadRegister(instr->value(), ip); | 2651 Register input_reg = EmitLoadRegister(instr->value(), ip); |
| 2568 __ SmiTst(input_reg); | 2652 __ TestIfSmi(input_reg, r0); |
| 2569 EmitBranch(instr, eq); | 2653 EmitBranch(instr, eq, cr0); |
| 2570 } | 2654 } |
| 2571 | 2655 |
| 2572 | 2656 |
| 2573 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { | 2657 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
| 2574 Register input = ToRegister(instr->value()); | 2658 Register input = ToRegister(instr->value()); |
| 2575 Register temp = ToRegister(instr->temp()); | 2659 Register temp = ToRegister(instr->temp()); |
| 2576 | 2660 |
| 2577 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 2661 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 2578 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | 2662 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2579 } | 2663 } |
| 2580 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); | 2664 __ LoadP(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2581 __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); | 2665 __ lbz(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 2582 __ tst(temp, Operand(1 << Map::kIsUndetectable)); | 2666 __ TestBit(temp, Map::kIsUndetectable, r0); |
| 2583 EmitBranch(instr, ne); | 2667 EmitBranch(instr, ne, cr0); |
| 2584 } | 2668 } |
| 2585 | 2669 |
| 2586 | 2670 |
| 2587 static Condition ComputeCompareCondition(Token::Value op) { | 2671 static Condition ComputeCompareCondition(Token::Value op) { |
| 2588 switch (op) { | 2672 switch (op) { |
| 2589 case Token::EQ_STRICT: | 2673 case Token::EQ_STRICT: |
| 2590 case Token::EQ: | 2674 case Token::EQ: |
| 2591 return eq; | 2675 return eq; |
| 2592 case Token::LT: | 2676 case Token::LT: |
| 2593 return lt; | 2677 return lt; |
| 2594 case Token::GT: | 2678 case Token::GT: |
| 2595 return gt; | 2679 return gt; |
| 2596 case Token::LTE: | 2680 case Token::LTE: |
| 2597 return le; | 2681 return le; |
| 2598 case Token::GTE: | 2682 case Token::GTE: |
| 2599 return ge; | 2683 return ge; |
| 2600 default: | 2684 default: |
| 2601 UNREACHABLE(); | 2685 UNREACHABLE(); |
| 2602 return kNoCondition; | 2686 return kNoCondition; |
| 2603 } | 2687 } |
| 2604 } | 2688 } |
| 2605 | 2689 |
| 2606 | 2690 |
| 2607 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { | 2691 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2608 ASSERT(ToRegister(instr->context()).is(cp)); | 2692 ASSERT(ToRegister(instr->context()).is(cp)); |
| 2609 Token::Value op = instr->op(); | 2693 Token::Value op = instr->op(); |
| 2610 | 2694 |
| 2611 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); | 2695 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
| 2612 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 2696 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2613 // This instruction also signals no smi code inlined. | 2697 // This instruction also signals no smi code inlined |
| 2614 __ cmp(r0, Operand::Zero()); | 2698 __ cmpi(r3, Operand::Zero()); |
| 2615 | 2699 |
| 2616 Condition condition = ComputeCompareCondition(op); | 2700 Condition condition = ComputeCompareCondition(op); |
| 2617 | 2701 |
| 2618 EmitBranch(instr, condition); | 2702 EmitBranch(instr, condition); |
| 2619 } | 2703 } |
| 2620 | 2704 |
| 2621 | 2705 |
| 2622 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { | 2706 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
| 2623 InstanceType from = instr->from(); | 2707 InstanceType from = instr->from(); |
| 2624 InstanceType to = instr->to(); | 2708 InstanceType to = instr->to(); |
| 2625 if (from == FIRST_TYPE) return to; | 2709 if (from == FIRST_TYPE) return to; |
| 2626 ASSERT(from == to || to == LAST_TYPE); | 2710 ASSERT(from == to || to == LAST_TYPE); |
| 2627 return from; | 2711 return from; |
| 2628 } | 2712 } |
| 2629 | 2713 |
| 2630 | 2714 |
| 2631 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { | 2715 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
| 2632 InstanceType from = instr->from(); | 2716 InstanceType from = instr->from(); |
| 2633 InstanceType to = instr->to(); | 2717 InstanceType to = instr->to(); |
| 2634 if (from == to) return eq; | 2718 if (from == to) return eq; |
| 2635 if (to == LAST_TYPE) return hs; | 2719 if (to == LAST_TYPE) return ge; |
| 2636 if (from == FIRST_TYPE) return ls; | 2720 if (from == FIRST_TYPE) return le; |
| 2637 UNREACHABLE(); | 2721 UNREACHABLE(); |
| 2638 return eq; | 2722 return eq; |
| 2639 } | 2723 } |
| 2640 | 2724 |
| 2641 | 2725 |
| 2642 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { | 2726 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
| 2643 Register scratch = scratch0(); | 2727 Register scratch = scratch0(); |
| 2644 Register input = ToRegister(instr->value()); | 2728 Register input = ToRegister(instr->value()); |
| 2645 | 2729 |
| 2646 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 2730 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 2647 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | 2731 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2648 } | 2732 } |
| 2649 | 2733 |
| 2650 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); | 2734 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
| 2651 EmitBranch(instr, BranchCondition(instr->hydrogen())); | 2735 EmitBranch(instr, BranchCondition(instr->hydrogen())); |
| 2652 } | 2736 } |
| 2653 | 2737 |
| 2654 | 2738 |
| 2655 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { | 2739 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
| 2656 Register input = ToRegister(instr->value()); | 2740 Register input = ToRegister(instr->value()); |
| 2657 Register result = ToRegister(instr->result()); | 2741 Register result = ToRegister(instr->result()); |
| 2658 | 2742 |
| 2659 __ AssertString(input); | 2743 __ AssertString(input); |
| 2660 | 2744 |
| 2661 __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); | 2745 __ lwz(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2662 __ IndexFromHash(result, result); | 2746 __ IndexFromHash(result, result); |
| 2663 } | 2747 } |
| 2664 | 2748 |
| 2665 | 2749 |
| 2666 void LCodeGen::DoHasCachedArrayIndexAndBranch( | 2750 void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2667 LHasCachedArrayIndexAndBranch* instr) { | 2751 LHasCachedArrayIndexAndBranch* instr) { |
| 2668 Register input = ToRegister(instr->value()); | 2752 Register input = ToRegister(instr->value()); |
| 2669 Register scratch = scratch0(); | 2753 Register scratch = scratch0(); |
| 2670 | 2754 |
| 2671 __ ldr(scratch, | 2755 __ lwz(scratch, |
| 2672 FieldMemOperand(input, String::kHashFieldOffset)); | 2756 FieldMemOperand(input, String::kHashFieldOffset)); |
| 2673 __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask)); | 2757 __ mov(r0, Operand(String::kContainsCachedArrayIndexMask)); |
| 2674 EmitBranch(instr, eq); | 2758 __ and_(r0, scratch, r0, SetRC); |
| 2759 EmitBranch(instr, eq, cr0); |
| 2675 } | 2760 } |
| 2676 | 2761 |
| 2677 | 2762 |
| 2678 // Branches to a label or falls through with the answer in flags. Trashes | 2763 // Branches to a label or falls through with the answer in flags. Trashes |
| 2679 // the temp registers, but not the input. | 2764 // the temp registers, but not the input. |
| 2680 void LCodeGen::EmitClassOfTest(Label* is_true, | 2765 void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2681 Label* is_false, | 2766 Label* is_false, |
| 2682 Handle<String>class_name, | 2767 Handle<String>class_name, |
| 2683 Register input, | 2768 Register input, |
| 2684 Register temp, | 2769 Register temp, |
| 2685 Register temp2) { | 2770 Register temp2) { |
| 2686 ASSERT(!input.is(temp)); | 2771 ASSERT(!input.is(temp)); |
| 2687 ASSERT(!input.is(temp2)); | 2772 ASSERT(!input.is(temp2)); |
| 2688 ASSERT(!temp.is(temp2)); | 2773 ASSERT(!temp.is(temp2)); |
| 2689 | 2774 |
| 2690 __ JumpIfSmi(input, is_false); | 2775 __ JumpIfSmi(input, is_false); |
| 2691 | 2776 |
| 2692 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { | 2777 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
| 2693 // Assuming the following assertions, we can use the same compares to test | 2778 // Assuming the following assertions, we can use the same compares to test |
| 2694 // for both being a function type and being in the object type range. | 2779 // for both being a function type and being in the object type range. |
| 2695 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | 2780 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2696 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == | 2781 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2697 FIRST_SPEC_OBJECT_TYPE + 1); | 2782 FIRST_SPEC_OBJECT_TYPE + 1); |
| 2698 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | 2783 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2699 LAST_SPEC_OBJECT_TYPE - 1); | 2784 LAST_SPEC_OBJECT_TYPE - 1); |
| 2700 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | 2785 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2701 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); | 2786 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); |
| 2702 __ b(lt, is_false); | 2787 __ blt(is_false); |
| 2703 __ b(eq, is_true); | 2788 __ beq(is_true); |
| 2704 __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); | 2789 __ cmpi(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2705 __ b(eq, is_true); | 2790 __ beq(is_true); |
| 2706 } else { | 2791 } else { |
| 2707 // Faster code path to avoid two compares: subtract lower bound from the | 2792 // Faster code path to avoid two compares: subtract lower bound from the |
| 2708 // actual type and do a signed compare with the width of the type range. | 2793 // actual type and do a signed compare with the width of the type range. |
| 2709 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); | 2794 __ LoadP(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2710 __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); | 2795 __ lbz(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
| 2711 __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2796 __ subi(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2712 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - | 2797 __ cmpi(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2713 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2798 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2714 __ b(gt, is_false); | 2799 __ bgt(is_false); |
| 2715 } | 2800 } |
| 2716 | 2801 |
| 2717 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. | 2802 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
| 2718 // Check if the constructor in the map is a function. | 2803 // Check if the constructor in the map is a function. |
| 2719 __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); | 2804 __ LoadP(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2720 | 2805 |
| 2721 // Objects with a non-function constructor have class 'Object'. | 2806 // Objects with a non-function constructor have class 'Object'. |
| 2722 __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); | 2807 __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
| 2723 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { | 2808 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
| 2724 __ b(ne, is_true); | 2809 __ bne(is_true); |
| 2725 } else { | 2810 } else { |
| 2726 __ b(ne, is_false); | 2811 __ bne(is_false); |
| 2727 } | 2812 } |
| 2728 | 2813 |
| 2729 // temp now contains the constructor function. Grab the | 2814 // temp now contains the constructor function. Grab the |
| 2730 // instance class name from there. | 2815 // instance class name from there. |
| 2731 __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); | 2816 __ LoadP(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2732 __ ldr(temp, FieldMemOperand(temp, | 2817 __ LoadP(temp, FieldMemOperand(temp, |
| 2733 SharedFunctionInfo::kInstanceClassNameOffset)); | 2818 SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2734 // The class name we are testing against is internalized since it's a literal. | 2819 // The class name we are testing against is internalized since it's a literal. |
| 2735 // The name in the constructor is internalized because of the way the context | 2820 // The name in the constructor is internalized because of the way the context |
| 2736 // is booted. This routine isn't expected to work for random API-created | 2821 // is booted. This routine isn't expected to work for random API-created |
| 2737 // classes and it doesn't have to because you can't access it with natives | 2822 // classes and it doesn't have to because you can't access it with natives |
| 2738 // syntax. Since both sides are internalized it is sufficient to use an | 2823 // syntax. Since both sides are internalized it is sufficient to use an |
| 2739 // identity comparison. | 2824 // identity comparison. |
| 2740 __ cmp(temp, Operand(class_name)); | 2825 __ Cmpi(temp, Operand(class_name), r0); |
| 2741 // End with the answer in flags. | 2826 // End with the answer in flags. |
| 2742 } | 2827 } |
| 2743 | 2828 |
| 2744 | 2829 |
| 2745 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { | 2830 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
| 2746 Register input = ToRegister(instr->value()); | 2831 Register input = ToRegister(instr->value()); |
| 2747 Register temp = scratch0(); | 2832 Register temp = scratch0(); |
| 2748 Register temp2 = ToRegister(instr->temp()); | 2833 Register temp2 = ToRegister(instr->temp()); |
| 2749 Handle<String> class_name = instr->hydrogen()->class_name(); | 2834 Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2750 | 2835 |
| 2751 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), | 2836 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2752 class_name, input, temp, temp2); | 2837 class_name, input, temp, temp2); |
| 2753 | 2838 |
| 2754 EmitBranch(instr, eq); | 2839 EmitBranch(instr, eq); |
| 2755 } | 2840 } |
| 2756 | 2841 |
| 2757 | 2842 |
| 2758 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { | 2843 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
| 2759 Register reg = ToRegister(instr->value()); | 2844 Register reg = ToRegister(instr->value()); |
| 2760 Register temp = ToRegister(instr->temp()); | 2845 Register temp = ToRegister(instr->temp()); |
| 2761 | 2846 |
| 2762 __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); | 2847 __ LoadP(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2763 __ cmp(temp, Operand(instr->map())); | 2848 __ Cmpi(temp, Operand(instr->map()), r0); |
| 2764 EmitBranch(instr, eq); | 2849 EmitBranch(instr, eq); |
| 2765 } | 2850 } |
| 2766 | 2851 |
| 2767 | 2852 |
| 2768 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { | 2853 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
| 2769 ASSERT(ToRegister(instr->context()).is(cp)); | 2854 ASSERT(ToRegister(instr->context()).is(cp)); |
| 2770 ASSERT(ToRegister(instr->left()).is(r0)); // Object is in r0. | 2855 ASSERT(ToRegister(instr->left()).is(r3)); // Object is in r3. |
| 2771 ASSERT(ToRegister(instr->right()).is(r1)); // Function is in r1. | 2856 ASSERT(ToRegister(instr->right()).is(r4)); // Function is in r4. |
| 2772 | 2857 |
| 2773 InstanceofStub stub(isolate(), InstanceofStub::kArgsInRegisters); | 2858 InstanceofStub stub(isolate(), InstanceofStub::kArgsInRegisters); |
| 2774 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 2859 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2775 | 2860 |
| 2776 __ cmp(r0, Operand::Zero()); | 2861 Label equal, done; |
| 2777 __ mov(r0, Operand(factory()->false_value()), LeaveCC, ne); | 2862 __ cmpi(r3, Operand::Zero()); |
| 2778 __ mov(r0, Operand(factory()->true_value()), LeaveCC, eq); | 2863 __ beq(&equal); |
| 2864 __ mov(r3, Operand(factory()->false_value())); |
| 2865 __ b(&done); |
| 2866 |
| 2867 __ bind(&equal); |
| 2868 __ mov(r3, Operand(factory()->true_value())); |
| 2869 __ bind(&done); |
| 2779 } | 2870 } |
| 2780 | 2871 |
| 2781 | 2872 |
| 2782 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { | 2873 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
| 2783 class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { | 2874 class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
| 2784 public: | 2875 public: |
| 2785 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, | 2876 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2786 LInstanceOfKnownGlobal* instr) | 2877 LInstanceOfKnownGlobal* instr) |
| 2787 : LDeferredCode(codegen), instr_(instr) { } | 2878 : LDeferredCode(codegen), instr_(instr) { } |
| 2788 virtual void Generate() V8_OVERRIDE { | 2879 virtual void Generate() V8_OVERRIDE { |
| 2789 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_, | 2880 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
| 2790 &load_bool_); | |
| 2791 } | 2881 } |
| 2792 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 2882 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 2793 Label* map_check() { return &map_check_; } | 2883 Label* map_check() { return &map_check_; } |
| 2794 Label* load_bool() { return &load_bool_; } | |
| 2795 | |
| 2796 private: | 2884 private: |
| 2797 LInstanceOfKnownGlobal* instr_; | 2885 LInstanceOfKnownGlobal* instr_; |
| 2798 Label map_check_; | 2886 Label map_check_; |
| 2799 Label load_bool_; | |
| 2800 }; | 2887 }; |
| 2801 | 2888 |
| 2802 DeferredInstanceOfKnownGlobal* deferred; | 2889 DeferredInstanceOfKnownGlobal* deferred; |
| 2803 deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); | 2890 deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
| 2804 | 2891 |
| 2805 Label done, false_result; | 2892 Label done, false_result; |
| 2806 Register object = ToRegister(instr->value()); | 2893 Register object = ToRegister(instr->value()); |
| 2807 Register temp = ToRegister(instr->temp()); | 2894 Register temp = ToRegister(instr->temp()); |
| 2808 Register result = ToRegister(instr->result()); | 2895 Register result = ToRegister(instr->result()); |
| 2809 | 2896 |
| 2810 // A Smi is not instance of anything. | 2897 // A Smi is not instance of anything. |
| 2811 __ JumpIfSmi(object, &false_result); | 2898 __ JumpIfSmi(object, &false_result); |
| 2812 | 2899 |
| 2813 // This is the inlined call site instanceof cache. The two occurences of the | 2900 // This is the inlined call site instanceof cache. The two occurences of the |
| 2814 // hole value will be patched to the last map/result pair generated by the | 2901 // hole value will be patched to the last map/result pair generated by the |
| 2815 // instanceof stub. | 2902 // instanceof stub. |
| 2816 Label cache_miss; | 2903 Label cache_miss; |
| 2817 Register map = temp; | 2904 Register map = temp; |
| 2818 __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); | 2905 __ LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2819 { | 2906 { |
| 2820 // Block constant pool emission to ensure the positions of instructions are | 2907 // Block constant pool emission to ensure the positions of instructions are |
| 2821 // as expected by the patcher. See InstanceofStub::Generate(). | 2908 // as expected by the patcher. See InstanceofStub::Generate(). |
| 2822 Assembler::BlockConstPoolScope block_const_pool(masm()); | 2909 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 2823 __ bind(deferred->map_check()); // Label for calculating code patching. | 2910 __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2824 // We use Factory::the_hole_value() on purpose instead of loading from the | 2911 // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2825 // root array to force relocation to be able to later patch with | 2912 // root array to force relocation to be able to later patch with |
| 2826 // the cached map. | 2913 // the cached map. |
| 2827 Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); | 2914 Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); |
| 2828 __ mov(ip, Operand(Handle<Object>(cell))); | 2915 __ mov(ip, Operand(Handle<Object>(cell))); |
| 2829 __ ldr(ip, FieldMemOperand(ip, PropertyCell::kValueOffset)); | 2916 __ LoadP(ip, FieldMemOperand(ip, PropertyCell::kValueOffset)); |
| 2830 __ cmp(map, Operand(ip)); | 2917 __ cmp(map, ip); |
| 2831 __ b(ne, &cache_miss); | 2918 __ bne(&cache_miss); |
| 2832 __ bind(deferred->load_bool()); // Label for calculating code patching. | |
| 2833 // We use Factory::the_hole_value() on purpose instead of loading from the | 2919 // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2834 // root array to force relocation to be able to later patch | 2920 // root array to force relocation to be able to later patch |
| 2835 // with true or false. | 2921 // with true or false. |
| 2836 __ mov(result, Operand(factory()->the_hole_value())); | 2922 __ mov(result, Operand(factory()->the_hole_value())); |
| 2837 } | 2923 } |
| 2838 __ b(&done); | 2924 __ b(&done); |
| 2839 | 2925 |
| 2840 // The inlined call site cache did not match. Check null and string before | 2926 // The inlined call site cache did not match. Check null and string before |
| 2841 // calling the deferred code. | 2927 // calling the deferred code. |
| 2842 __ bind(&cache_miss); | 2928 __ bind(&cache_miss); |
| 2843 // Null is not instance of anything. | 2929 // Null is not instance of anything. |
| 2844 __ LoadRoot(ip, Heap::kNullValueRootIndex); | 2930 __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2845 __ cmp(object, Operand(ip)); | 2931 __ cmp(object, ip); |
| 2846 __ b(eq, &false_result); | 2932 __ beq(&false_result); |
| 2847 | 2933 |
| 2848 // String values is not instance of anything. | 2934 // String values is not instance of anything. |
| 2849 Condition is_string = masm_->IsObjectStringType(object, temp); | 2935 Condition is_string = masm_->IsObjectStringType(object, temp); |
| 2850 __ b(is_string, &false_result); | 2936 __ b(is_string, &false_result, cr0); |
| 2851 | 2937 |
| 2852 // Go to the deferred code. | 2938 // Go to the deferred code. |
| 2853 __ b(deferred->entry()); | 2939 __ b(deferred->entry()); |
| 2854 | 2940 |
| 2855 __ bind(&false_result); | 2941 __ bind(&false_result); |
| 2856 __ LoadRoot(result, Heap::kFalseValueRootIndex); | 2942 __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2857 | 2943 |
| 2858 // Here result has either true or false. Deferred code also produces true or | 2944 // Here result has either true or false. Deferred code also produces true or |
| 2859 // false object. | 2945 // false object. |
| 2860 __ bind(deferred->exit()); | 2946 __ bind(deferred->exit()); |
| 2861 __ bind(&done); | 2947 __ bind(&done); |
| 2862 } | 2948 } |
| 2863 | 2949 |
| 2864 | 2950 |
| 2865 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, | 2951 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2866 Label* map_check, | 2952 Label* map_check) { |
| 2867 Label* bool_load) { | |
| 2868 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; | 2953 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2869 flags = static_cast<InstanceofStub::Flags>( | 2954 flags = static_cast<InstanceofStub::Flags>( |
| 2870 flags | InstanceofStub::kArgsInRegisters); | 2955 flags | InstanceofStub::kArgsInRegisters); |
| 2871 flags = static_cast<InstanceofStub::Flags>( | 2956 flags = static_cast<InstanceofStub::Flags>( |
| 2872 flags | InstanceofStub::kCallSiteInlineCheck); | 2957 flags | InstanceofStub::kCallSiteInlineCheck); |
| 2873 flags = static_cast<InstanceofStub::Flags>( | 2958 flags = static_cast<InstanceofStub::Flags>( |
| 2874 flags | InstanceofStub::kReturnTrueFalseObject); | 2959 flags | InstanceofStub::kReturnTrueFalseObject); |
| 2875 InstanceofStub stub(isolate(), flags); | 2960 InstanceofStub stub(isolate(), flags); |
| 2876 | 2961 |
| 2877 PushSafepointRegistersScope scope(this); | 2962 PushSafepointRegistersScope scope(this); |
| 2878 LoadContextFromDeferred(instr->context()); | 2963 LoadContextFromDeferred(instr->context()); |
| 2879 | 2964 |
| 2880 __ Move(InstanceofStub::right(), instr->function()); | 2965 __ Move(InstanceofStub::right(), instr->function()); |
| 2881 | 2966 // Include instructions below in delta: mov + call = mov + (mov + 2) |
| 2882 int call_size = CallCodeSize(stub.GetCode(), RelocInfo::CODE_TARGET); | 2967 static const int kAdditionalDelta = (2 * Assembler::kMovInstructions) + 2; |
| 2883 int additional_delta = (call_size / Assembler::kInstrSize) + 4; | 2968 int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2884 // Make sure that code size is predicable, since we use specific constants | |
| 2885 // offsets in the code to find embedded values.. | |
| 2886 PredictableCodeSizeScope predictable( | |
| 2887 masm_, (additional_delta + 1) * Assembler::kInstrSize); | |
| 2888 // Make sure we don't emit any additional entries in the constant pool before | |
| 2889 // the call to ensure that the CallCodeSize() calculated the correct number of | |
| 2890 // instructions for the constant pool load. | |
| 2891 { | 2969 { |
| 2892 ConstantPoolUnavailableScope constant_pool_unavailable(masm_); | 2970 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 2893 int map_check_delta = | 2971 // r8 is used to communicate the offset to the location of the map check. |
| 2894 masm_->InstructionsGeneratedSince(map_check) + additional_delta; | 2972 __ mov(r8, Operand(delta * Instruction::kInstrSize)); |
| 2895 int bool_load_delta = | |
| 2896 masm_->InstructionsGeneratedSince(bool_load) + additional_delta; | |
| 2897 Label before_push_delta; | |
| 2898 __ bind(&before_push_delta); | |
| 2899 __ BlockConstPoolFor(additional_delta); | |
| 2900 // r5 is used to communicate the offset to the location of the map check. | |
| 2901 __ mov(r5, Operand(map_check_delta * kPointerSize)); | |
| 2902 // r6 is used to communicate the offset to the location of the bool load. | |
| 2903 __ mov(r6, Operand(bool_load_delta * kPointerSize)); | |
| 2904 // The mov above can generate one or two instructions. The delta was | |
| 2905 // computed for two instructions, so we need to pad here in case of one | |
| 2906 // instruction. | |
| 2907 while (masm_->InstructionsGeneratedSince(&before_push_delta) != 4) { | |
| 2908 __ nop(); | |
| 2909 } | |
| 2910 } | 2973 } |
| 2911 CallCodeGeneric(stub.GetCode(), | 2974 CallCodeGeneric(stub.GetCode(), |
| 2912 RelocInfo::CODE_TARGET, | 2975 RelocInfo::CODE_TARGET, |
| 2913 instr, | 2976 instr, |
| 2914 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | 2977 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 2978 ASSERT(delta == masm_->InstructionsGeneratedSince(map_check)); |
| 2915 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); | 2979 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
| 2916 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); | 2980 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 2917 // Put the result value (r0) into the result register slot and | 2981 // Put the result value (r3) into the result register slot and |
| 2918 // restore all registers. | 2982 // restore all registers. |
| 2919 __ StoreToSafepointRegisterSlot(r0, ToRegister(instr->result())); | 2983 __ StoreToSafepointRegisterSlot(r3, ToRegister(instr->result())); |
| 2920 } | 2984 } |
| 2921 | 2985 |
| 2922 | 2986 |
| 2923 void LCodeGen::DoCmpT(LCmpT* instr) { | 2987 void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2924 ASSERT(ToRegister(instr->context()).is(cp)); | 2988 ASSERT(ToRegister(instr->context()).is(cp)); |
| 2925 Token::Value op = instr->op(); | 2989 Token::Value op = instr->op(); |
| 2926 | 2990 |
| 2927 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); | 2991 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
| 2928 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 2992 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2929 // This instruction also signals no smi code inlined. | 2993 // This instruction also signals no smi code inlined |
| 2930 __ cmp(r0, Operand::Zero()); | 2994 __ cmpi(r3, Operand::Zero()); |
| 2931 | 2995 |
| 2932 Condition condition = ComputeCompareCondition(op); | 2996 Condition condition = ComputeCompareCondition(op); |
| 2933 __ LoadRoot(ToRegister(instr->result()), | 2997 Label true_value, done; |
| 2934 Heap::kTrueValueRootIndex, | 2998 |
| 2935 condition); | 2999 __ b(condition, &true_value); |
| 2936 __ LoadRoot(ToRegister(instr->result()), | 3000 |
| 2937 Heap::kFalseValueRootIndex, | 3001 __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
| 2938 NegateCondition(condition)); | 3002 __ b(&done); |
| 3003 |
| 3004 __ bind(&true_value); |
| 3005 __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
| 3006 |
| 3007 __ bind(&done); |
| 2939 } | 3008 } |
| 2940 | 3009 |
| 2941 | 3010 |
| 2942 void LCodeGen::DoReturn(LReturn* instr) { | 3011 void LCodeGen::DoReturn(LReturn* instr) { |
| 2943 if (FLAG_trace && info()->IsOptimizing()) { | 3012 if (FLAG_trace && info()->IsOptimizing()) { |
| 2944 // Push the return value on the stack as the parameter. | 3013 // Push the return value on the stack as the parameter. |
| 2945 // Runtime::TraceExit returns its parameter in r0. We're leaving the code | 3014 // Runtime::TraceExit returns its parameter in r3. We're leaving the code |
| 2946 // managed by the register allocator and tearing down the frame, it's | 3015 // managed by the register allocator and tearing down the frame, it's |
| 2947 // safe to write to the context register. | 3016 // safe to write to the context register. |
| 2948 __ push(r0); | 3017 __ push(r3); |
| 2949 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 3018 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2950 __ CallRuntime(Runtime::kTraceExit, 1); | 3019 __ CallRuntime(Runtime::kTraceExit, 1); |
| 2951 } | 3020 } |
| 2952 if (info()->saves_caller_doubles()) { | 3021 if (info()->saves_caller_doubles()) { |
| 2953 RestoreCallerDoubles(); | 3022 RestoreCallerDoubles(); |
| 2954 } | 3023 } |
| 2955 int no_frame_start = -1; | 3024 int no_frame_start = -1; |
| 2956 if (NeedsEagerFrame()) { | 3025 if (NeedsEagerFrame()) { |
| 2957 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); | 3026 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); |
| 2958 } | 3027 } |
| 2959 if (instr->has_constant_parameter_count()) { | 3028 if (instr->has_constant_parameter_count()) { |
| 2960 int parameter_count = ToInteger32(instr->constant_parameter_count()); | 3029 int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2961 int32_t sp_delta = (parameter_count + 1) * kPointerSize; | 3030 int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2962 if (sp_delta != 0) { | 3031 if (sp_delta != 0) { |
| 2963 __ add(sp, sp, Operand(sp_delta)); | 3032 __ addi(sp, sp, Operand(sp_delta)); |
| 2964 } | 3033 } |
| 2965 } else { | 3034 } else { |
| 2966 Register reg = ToRegister(instr->parameter_count()); | 3035 Register reg = ToRegister(instr->parameter_count()); |
| 2967 // The argument count parameter is a smi | 3036 // The argument count parameter is a smi |
| 2968 __ SmiUntag(reg); | 3037 __ SmiToPtrArrayOffset(r0, reg); |
| 2969 __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2)); | 3038 __ add(sp, sp, r0); |
| 2970 } | 3039 } |
| 2971 | 3040 |
| 2972 __ Jump(lr); | 3041 __ blr(); |
| 2973 | 3042 |
| 2974 if (no_frame_start != -1) { | 3043 if (no_frame_start != -1) { |
| 2975 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); | 3044 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 2976 } | 3045 } |
| 2977 } | 3046 } |
| 2978 | 3047 |
| 2979 | 3048 |
| 2980 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { | 3049 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
| 2981 Register result = ToRegister(instr->result()); | 3050 Register result = ToRegister(instr->result()); |
| 2982 __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); | 3051 __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); |
| 2983 __ ldr(result, FieldMemOperand(ip, Cell::kValueOffset)); | 3052 __ LoadP(result, FieldMemOperand(ip, Cell::kValueOffset)); |
| 2984 if (instr->hydrogen()->RequiresHoleCheck()) { | 3053 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2985 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3054 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2986 __ cmp(result, ip); | 3055 __ cmp(result, ip); |
| 2987 DeoptimizeIf(eq, instr->environment()); | 3056 DeoptimizeIf(eq, instr->environment()); |
| 2988 } | 3057 } |
| 2989 } | 3058 } |
| 2990 | 3059 |
| 2991 | 3060 |
| 2992 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { | 3061 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 2993 ASSERT(ToRegister(instr->context()).is(cp)); | 3062 ASSERT(ToRegister(instr->context()).is(cp)); |
| 2994 ASSERT(ToRegister(instr->global_object()).is(LoadIC::ReceiverRegister())); | 3063 ASSERT(ToRegister(instr->global_object()).is(LoadIC::ReceiverRegister())); |
| 2995 ASSERT(ToRegister(instr->result()).is(r0)); | 3064 ASSERT(ToRegister(instr->result()).is(r3)); |
| 2996 | 3065 |
| 2997 __ mov(LoadIC::NameRegister(), Operand(instr->name())); | 3066 __ mov(LoadIC::NameRegister(), Operand(instr->name())); |
| 2998 if (FLAG_vector_ics) { | 3067 if (FLAG_vector_ics) { |
| 2999 Register vector = ToRegister(instr->temp_vector()); | 3068 Register vector = ToRegister(instr->temp_vector()); |
| 3000 ASSERT(vector.is(LoadIC::VectorRegister())); | 3069 ASSERT(vector.is(LoadIC::VectorRegister())); |
| 3001 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3070 __ Move(vector, instr->hydrogen()->feedback_vector()); |
| 3002 // No need to allocate this register. | 3071 // No need to allocate this register. |
| 3003 ASSERT(LoadIC::SlotRegister().is(r0)); | 3072 ASSERT(LoadIC::SlotRegister().is(r0)); |
| 3004 __ mov(LoadIC::SlotRegister(), | 3073 __ mov(LoadIC::SlotRegister(), |
| 3005 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3074 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3017 // Load the cell. | 3086 // Load the cell. |
| 3018 __ mov(cell, Operand(instr->hydrogen()->cell().handle())); | 3087 __ mov(cell, Operand(instr->hydrogen()->cell().handle())); |
| 3019 | 3088 |
| 3020 // If the cell we are storing to contains the hole it could have | 3089 // If the cell we are storing to contains the hole it could have |
| 3021 // been deleted from the property dictionary. In that case, we need | 3090 // been deleted from the property dictionary. In that case, we need |
| 3022 // to update the property details in the property dictionary to mark | 3091 // to update the property details in the property dictionary to mark |
| 3023 // it as no longer deleted. | 3092 // it as no longer deleted. |
| 3024 if (instr->hydrogen()->RequiresHoleCheck()) { | 3093 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3025 // We use a temp to check the payload (CompareRoot might clobber ip). | 3094 // We use a temp to check the payload (CompareRoot might clobber ip). |
| 3026 Register payload = ToRegister(instr->temp()); | 3095 Register payload = ToRegister(instr->temp()); |
| 3027 __ ldr(payload, FieldMemOperand(cell, Cell::kValueOffset)); | 3096 __ LoadP(payload, FieldMemOperand(cell, Cell::kValueOffset)); |
| 3028 __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); | 3097 __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); |
| 3029 DeoptimizeIf(eq, instr->environment()); | 3098 DeoptimizeIf(eq, instr->environment()); |
| 3030 } | 3099 } |
| 3031 | 3100 |
| 3032 // Store the value. | 3101 // Store the value. |
| 3033 __ str(value, FieldMemOperand(cell, Cell::kValueOffset)); | 3102 __ StoreP(value, FieldMemOperand(cell, Cell::kValueOffset), r0); |
| 3034 // Cells are always rescanned, so no write barrier here. | 3103 // Cells are always rescanned, so no write barrier here. |
| 3035 } | 3104 } |
| 3036 | 3105 |
| 3037 | 3106 |
| 3038 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { | 3107 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
| 3039 Register context = ToRegister(instr->context()); | 3108 Register context = ToRegister(instr->context()); |
| 3040 Register result = ToRegister(instr->result()); | 3109 Register result = ToRegister(instr->result()); |
| 3041 __ ldr(result, ContextOperand(context, instr->slot_index())); | 3110 __ LoadP(result, ContextOperand(context, instr->slot_index())); |
| 3042 if (instr->hydrogen()->RequiresHoleCheck()) { | 3111 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3043 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3112 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3044 __ cmp(result, ip); | 3113 __ cmp(result, ip); |
| 3045 if (instr->hydrogen()->DeoptimizesOnHole()) { | 3114 if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3046 DeoptimizeIf(eq, instr->environment()); | 3115 DeoptimizeIf(eq, instr->environment()); |
| 3047 } else { | 3116 } else { |
| 3048 __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq); | 3117 Label skip; |
| 3118 __ bne(&skip); |
| 3119 __ mov(result, Operand(factory()->undefined_value())); |
| 3120 __ bind(&skip); |
| 3049 } | 3121 } |
| 3050 } | 3122 } |
| 3051 } | 3123 } |
| 3052 | 3124 |
| 3053 | 3125 |
| 3054 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { | 3126 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 3055 Register context = ToRegister(instr->context()); | 3127 Register context = ToRegister(instr->context()); |
| 3056 Register value = ToRegister(instr->value()); | 3128 Register value = ToRegister(instr->value()); |
| 3057 Register scratch = scratch0(); | 3129 Register scratch = scratch0(); |
| 3058 MemOperand target = ContextOperand(context, instr->slot_index()); | 3130 MemOperand target = ContextOperand(context, instr->slot_index()); |
| 3059 | 3131 |
| 3060 Label skip_assignment; | 3132 Label skip_assignment; |
| 3061 | 3133 |
| 3062 if (instr->hydrogen()->RequiresHoleCheck()) { | 3134 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3063 __ ldr(scratch, target); | 3135 __ LoadP(scratch, target); |
| 3064 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3136 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3065 __ cmp(scratch, ip); | 3137 __ cmp(scratch, ip); |
| 3066 if (instr->hydrogen()->DeoptimizesOnHole()) { | 3138 if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3067 DeoptimizeIf(eq, instr->environment()); | 3139 DeoptimizeIf(eq, instr->environment()); |
| 3068 } else { | 3140 } else { |
| 3069 __ b(ne, &skip_assignment); | 3141 __ bne(&skip_assignment); |
| 3070 } | 3142 } |
| 3071 } | 3143 } |
| 3072 | 3144 |
| 3073 __ str(value, target); | 3145 __ StoreP(value, target, r0); |
| 3074 if (instr->hydrogen()->NeedsWriteBarrier()) { | 3146 if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 3075 SmiCheck check_needed = | 3147 SmiCheck check_needed = |
| 3076 instr->hydrogen()->value()->type().IsHeapObject() | 3148 instr->hydrogen()->value()->type().IsHeapObject() |
| 3077 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 3149 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 3078 __ RecordWriteContextSlot(context, | 3150 __ RecordWriteContextSlot(context, |
| 3079 target.offset(), | 3151 target.offset(), |
| 3080 value, | 3152 value, |
| 3081 scratch, | 3153 scratch, |
| 3082 GetLinkRegisterState(), | 3154 GetLinkRegisterState(), |
| 3083 kSaveFPRegs, | 3155 kSaveFPRegs, |
| 3084 EMIT_REMEMBERED_SET, | 3156 EMIT_REMEMBERED_SET, |
| 3085 check_needed); | 3157 check_needed); |
| 3086 } | 3158 } |
| 3087 | 3159 |
| 3088 __ bind(&skip_assignment); | 3160 __ bind(&skip_assignment); |
| 3089 } | 3161 } |
| 3090 | 3162 |
| 3091 | 3163 |
| 3092 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { | 3164 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
| 3093 HObjectAccess access = instr->hydrogen()->access(); | 3165 HObjectAccess access = instr->hydrogen()->access(); |
| 3094 int offset = access.offset(); | 3166 int offset = access.offset(); |
| 3095 Register object = ToRegister(instr->object()); | 3167 Register object = ToRegister(instr->object()); |
| 3096 | 3168 |
| 3097 if (access.IsExternalMemory()) { | 3169 if (access.IsExternalMemory()) { |
| 3098 Register result = ToRegister(instr->result()); | 3170 Register result = ToRegister(instr->result()); |
| 3099 MemOperand operand = MemOperand(object, offset); | 3171 MemOperand operand = MemOperand(object, offset); |
| 3100 __ Load(result, operand, access.representation()); | 3172 __ LoadRepresentation(result, operand, access.representation(), r0); |
| 3101 return; | 3173 return; |
| 3102 } | 3174 } |
| 3103 | 3175 |
| 3104 if (instr->hydrogen()->representation().IsDouble()) { | 3176 if (instr->hydrogen()->representation().IsDouble()) { |
| 3105 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3177 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3106 __ vldr(result, FieldMemOperand(object, offset)); | 3178 __ lfd(result, FieldMemOperand(object, offset)); |
| 3107 return; | 3179 return; |
| 3108 } | 3180 } |
| 3109 | 3181 |
| 3110 Register result = ToRegister(instr->result()); | 3182 Register result = ToRegister(instr->result()); |
| 3111 if (!access.IsInobject()) { | 3183 if (!access.IsInobject()) { |
| 3112 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 3184 __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3113 object = result; | 3185 object = result; |
| 3114 } | 3186 } |
| 3115 MemOperand operand = FieldMemOperand(object, offset); | 3187 |
| 3116 __ Load(result, operand, access.representation()); | 3188 Representation representation = access.representation(); |
| 3189 |
| 3190 #if V8_TARGET_ARCH_PPC64 |
| 3191 // 64-bit Smi optimization |
| 3192 if (representation.IsSmi() && |
| 3193 instr->hydrogen()->representation().IsInteger32()) { |
| 3194 // Read int value directly from upper half of the smi. |
| 3195 STATIC_ASSERT(kSmiTag == 0); |
| 3196 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 3197 #if V8_TARGET_LITTLE_ENDIAN |
| 3198 offset += kPointerSize / 2; |
| 3199 #endif |
| 3200 representation = Representation::Integer32(); |
| 3201 } |
| 3202 #endif |
| 3203 |
| 3204 __ LoadRepresentation(result, FieldMemOperand(object, offset), |
| 3205 representation, r0); |
| 3117 } | 3206 } |
| 3118 | 3207 |
| 3119 | 3208 |
| 3120 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { | 3209 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 3121 ASSERT(ToRegister(instr->context()).is(cp)); | 3210 ASSERT(ToRegister(instr->context()).is(cp)); |
| 3122 ASSERT(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); | 3211 ASSERT(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); |
| 3123 ASSERT(ToRegister(instr->result()).is(r0)); | 3212 ASSERT(ToRegister(instr->result()).is(r3)); |
| 3124 | 3213 |
| 3125 // Name is always in r2. | |
| 3126 __ mov(LoadIC::NameRegister(), Operand(instr->name())); | 3214 __ mov(LoadIC::NameRegister(), Operand(instr->name())); |
| 3127 if (FLAG_vector_ics) { | 3215 if (FLAG_vector_ics) { |
| 3128 Register vector = ToRegister(instr->temp_vector()); | 3216 Register vector = ToRegister(instr->temp_vector()); |
| 3129 ASSERT(vector.is(LoadIC::VectorRegister())); | 3217 ASSERT(vector.is(LoadIC::VectorRegister())); |
| 3130 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3218 __ Move(vector, instr->hydrogen()->feedback_vector()); |
| 3131 // No need to allocate this register. | 3219 // No need to allocate this register. |
| 3132 ASSERT(LoadIC::SlotRegister().is(r0)); | 3220 ASSERT(LoadIC::SlotRegister().is(r0)); |
| 3133 __ mov(LoadIC::SlotRegister(), | 3221 __ mov(LoadIC::SlotRegister(), |
| 3134 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3222 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
| 3135 } | 3223 } |
| 3136 Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); | 3224 Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); |
| 3137 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 3225 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3138 } | 3226 } |
| 3139 | 3227 |
| 3140 | 3228 |
| 3141 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { | 3229 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 3142 Register scratch = scratch0(); | 3230 Register scratch = scratch0(); |
| 3143 Register function = ToRegister(instr->function()); | 3231 Register function = ToRegister(instr->function()); |
| 3144 Register result = ToRegister(instr->result()); | 3232 Register result = ToRegister(instr->result()); |
| 3145 | 3233 |
| 3146 // Get the prototype or initial map from the function. | 3234 // Get the prototype or initial map from the function. |
| 3147 __ ldr(result, | 3235 __ LoadP(result, |
| 3148 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); | 3236 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3149 | 3237 |
| 3150 // Check that the function has a prototype or an initial map. | 3238 // Check that the function has a prototype or an initial map. |
| 3151 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3239 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3152 __ cmp(result, ip); | 3240 __ cmp(result, ip); |
| 3153 DeoptimizeIf(eq, instr->environment()); | 3241 DeoptimizeIf(eq, instr->environment()); |
| 3154 | 3242 |
| 3155 // If the function does not have an initial map, we're done. | 3243 // If the function does not have an initial map, we're done. |
| 3156 Label done; | 3244 Label done; |
| 3157 __ CompareObjectType(result, scratch, scratch, MAP_TYPE); | 3245 __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 3158 __ b(ne, &done); | 3246 __ bne(&done); |
| 3159 | 3247 |
| 3160 // Get the prototype from the initial map. | 3248 // Get the prototype from the initial map. |
| 3161 __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); | 3249 __ LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 3162 | 3250 |
| 3163 // All done. | 3251 // All done. |
| 3164 __ bind(&done); | 3252 __ bind(&done); |
| 3165 } | 3253 } |
| 3166 | 3254 |
| 3167 | 3255 |
| 3168 void LCodeGen::DoLoadRoot(LLoadRoot* instr) { | 3256 void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3169 Register result = ToRegister(instr->result()); | 3257 Register result = ToRegister(instr->result()); |
| 3170 __ LoadRoot(result, instr->index()); | 3258 __ LoadRoot(result, instr->index()); |
| 3171 } | 3259 } |
| 3172 | 3260 |
| 3173 | 3261 |
| 3174 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { | 3262 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 3175 Register arguments = ToRegister(instr->arguments()); | 3263 Register arguments = ToRegister(instr->arguments()); |
| 3176 Register result = ToRegister(instr->result()); | 3264 Register result = ToRegister(instr->result()); |
| 3177 // There are two words between the frame pointer and the last argument. | 3265 // There are two words between the frame pointer and the last argument. |
| 3178 // Subtracting from length accounts for one of them add one more. | 3266 // Subtracting from length accounts for one of them add one more. |
| 3179 if (instr->length()->IsConstantOperand()) { | 3267 if (instr->length()->IsConstantOperand()) { |
| 3180 int const_length = ToInteger32(LConstantOperand::cast(instr->length())); | 3268 int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 3181 if (instr->index()->IsConstantOperand()) { | 3269 if (instr->index()->IsConstantOperand()) { |
| 3182 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3270 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3183 int index = (const_length - const_index) + 1; | 3271 int index = (const_length - const_index) + 1; |
| 3184 __ ldr(result, MemOperand(arguments, index * kPointerSize)); | 3272 __ LoadP(result, MemOperand(arguments, index * kPointerSize), r0); |
| 3185 } else { | 3273 } else { |
| 3186 Register index = ToRegister(instr->index()); | 3274 Register index = ToRegister(instr->index()); |
| 3187 __ rsb(result, index, Operand(const_length + 1)); | 3275 __ subfic(result, index, Operand(const_length + 1)); |
| 3188 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3276 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
| 3277 __ LoadPX(result, MemOperand(arguments, result)); |
| 3189 } | 3278 } |
| 3190 } else if (instr->index()->IsConstantOperand()) { | 3279 } else if (instr->index()->IsConstantOperand()) { |
| 3191 Register length = ToRegister(instr->length()); | 3280 Register length = ToRegister(instr->length()); |
| 3192 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3281 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3193 int loc = const_index - 1; | 3282 int loc = const_index - 1; |
| 3194 if (loc != 0) { | 3283 if (loc != 0) { |
| 3195 __ sub(result, length, Operand(loc)); | 3284 __ subi(result, length, Operand(loc)); |
| 3196 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3285 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
| 3197 } else { | 3286 __ LoadPX(result, MemOperand(arguments, result)); |
| 3198 __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); | |
| 3199 } | |
| 3200 } else { | 3287 } else { |
| 3288 __ ShiftLeftImm(result, length, Operand(kPointerSizeLog2)); |
| 3289 __ LoadPX(result, MemOperand(arguments, result)); |
| 3290 } |
| 3291 } else { |
| 3201 Register length = ToRegister(instr->length()); | 3292 Register length = ToRegister(instr->length()); |
| 3202 Register index = ToRegister(instr->index()); | 3293 Register index = ToRegister(instr->index()); |
| 3203 __ sub(result, length, index); | 3294 __ sub(result, length, index); |
| 3204 __ add(result, result, Operand(1)); | 3295 __ addi(result, result, Operand(1)); |
| 3205 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3296 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
| 3297 __ LoadPX(result, MemOperand(arguments, result)); |
| 3206 } | 3298 } |
| 3207 } | 3299 } |
| 3208 | 3300 |
| 3209 | 3301 |
| 3210 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { | 3302 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 3211 Register external_pointer = ToRegister(instr->elements()); | 3303 Register external_pointer = ToRegister(instr->elements()); |
| 3212 Register key = no_reg; | 3304 Register key = no_reg; |
| 3213 ElementsKind elements_kind = instr->elements_kind(); | 3305 ElementsKind elements_kind = instr->elements_kind(); |
| 3214 bool key_is_constant = instr->key()->IsConstantOperand(); | 3306 bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3215 int constant_key = 0; | 3307 int constant_key = 0; |
| 3216 if (key_is_constant) { | 3308 if (key_is_constant) { |
| 3217 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 3309 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3218 if (constant_key & 0xF0000000) { | 3310 if (constant_key & 0xF0000000) { |
| 3219 Abort(kArrayIndexConstantValueTooBig); | 3311 Abort(kArrayIndexConstantValueTooBig); |
| 3220 } | 3312 } |
| 3221 } else { | 3313 } else { |
| 3222 key = ToRegister(instr->key()); | 3314 key = ToRegister(instr->key()); |
| 3223 } | 3315 } |
| 3224 int element_size_shift = ElementsKindToShiftSize(elements_kind); | 3316 int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 3225 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 3317 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 3226 ? (element_size_shift - kSmiTagSize) : element_size_shift; | |
| 3227 int base_offset = instr->base_offset(); | 3318 int base_offset = instr->base_offset(); |
| 3228 | 3319 |
| 3229 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 3320 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
| 3230 elements_kind == FLOAT32_ELEMENTS || | 3321 elements_kind == FLOAT32_ELEMENTS || |
| 3231 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || | 3322 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
| 3232 elements_kind == FLOAT64_ELEMENTS) { | 3323 elements_kind == FLOAT64_ELEMENTS) { |
| 3233 int base_offset = instr->base_offset(); | 3324 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3234 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3325 if (key_is_constant) { |
| 3235 Operand operand = key_is_constant | 3326 __ Add(scratch0(), external_pointer, |
| 3236 ? Operand(constant_key << element_size_shift) | 3327 constant_key << element_size_shift, |
| 3237 : Operand(key, LSL, shift_size); | 3328 r0); |
| 3238 __ add(scratch0(), external_pointer, operand); | 3329 } else { |
| 3330 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 3331 __ add(scratch0(), external_pointer, r0); |
| 3332 } |
| 3239 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 3333 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
| 3240 elements_kind == FLOAT32_ELEMENTS) { | 3334 elements_kind == FLOAT32_ELEMENTS) { |
| 3241 __ vldr(double_scratch0().low(), scratch0(), base_offset); | 3335 __ lfs(result, MemOperand(scratch0(), base_offset)); |
| 3242 __ vcvt_f64_f32(result, double_scratch0().low()); | |
| 3243 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS | 3336 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
| 3244 __ vldr(result, scratch0(), base_offset); | 3337 __ lfd(result, MemOperand(scratch0(), base_offset)); |
| 3245 } | 3338 } |
| 3246 } else { | 3339 } else { |
| 3247 Register result = ToRegister(instr->result()); | 3340 Register result = ToRegister(instr->result()); |
| 3248 MemOperand mem_operand = PrepareKeyedOperand( | 3341 MemOperand mem_operand = PrepareKeyedOperand( |
| 3249 key, external_pointer, key_is_constant, constant_key, | 3342 key, external_pointer, key_is_constant, key_is_smi, constant_key, |
| 3250 element_size_shift, shift_size, base_offset); | 3343 element_size_shift, base_offset); |
| 3251 switch (elements_kind) { | 3344 switch (elements_kind) { |
| 3252 case EXTERNAL_INT8_ELEMENTS: | 3345 case EXTERNAL_INT8_ELEMENTS: |
| 3253 case INT8_ELEMENTS: | 3346 case INT8_ELEMENTS: |
| 3254 __ ldrsb(result, mem_operand); | 3347 if (key_is_constant) { |
| 3348 __ LoadByte(result, mem_operand, r0); |
| 3349 } else { |
| 3350 __ lbzx(result, mem_operand); |
| 3351 } |
| 3352 __ extsb(result, result); |
| 3255 break; | 3353 break; |
| 3256 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: | 3354 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
| 3257 case EXTERNAL_UINT8_ELEMENTS: | 3355 case EXTERNAL_UINT8_ELEMENTS: |
| 3258 case UINT8_ELEMENTS: | 3356 case UINT8_ELEMENTS: |
| 3259 case UINT8_CLAMPED_ELEMENTS: | 3357 case UINT8_CLAMPED_ELEMENTS: |
| 3260 __ ldrb(result, mem_operand); | 3358 if (key_is_constant) { |
| 3359 __ LoadByte(result, mem_operand, r0); |
| 3360 } else { |
| 3361 __ lbzx(result, mem_operand); |
| 3362 } |
| 3261 break; | 3363 break; |
| 3262 case EXTERNAL_INT16_ELEMENTS: | 3364 case EXTERNAL_INT16_ELEMENTS: |
| 3263 case INT16_ELEMENTS: | 3365 case INT16_ELEMENTS: |
| 3264 __ ldrsh(result, mem_operand); | 3366 if (key_is_constant) { |
| 3367 __ LoadHalfWord(result, mem_operand, r0); |
| 3368 } else { |
| 3369 __ lhzx(result, mem_operand); |
| 3370 } |
| 3371 __ extsh(result, result); |
| 3265 break; | 3372 break; |
| 3266 case EXTERNAL_UINT16_ELEMENTS: | 3373 case EXTERNAL_UINT16_ELEMENTS: |
| 3267 case UINT16_ELEMENTS: | 3374 case UINT16_ELEMENTS: |
| 3268 __ ldrh(result, mem_operand); | 3375 if (key_is_constant) { |
| 3376 __ LoadHalfWord(result, mem_operand, r0); |
| 3377 } else { |
| 3378 __ lhzx(result, mem_operand); |
| 3379 } |
| 3269 break; | 3380 break; |
| 3270 case EXTERNAL_INT32_ELEMENTS: | 3381 case EXTERNAL_INT32_ELEMENTS: |
| 3271 case INT32_ELEMENTS: | 3382 case INT32_ELEMENTS: |
| 3272 __ ldr(result, mem_operand); | 3383 if (key_is_constant) { |
| 3384 __ LoadWord(result, mem_operand, r0); |
| 3385 } else { |
| 3386 __ lwzx(result, mem_operand); |
| 3387 } |
| 3388 #if V8_TARGET_ARCH_PPC64 |
| 3389 __ extsw(result, result); |
| 3390 #endif |
| 3273 break; | 3391 break; |
| 3274 case EXTERNAL_UINT32_ELEMENTS: | 3392 case EXTERNAL_UINT32_ELEMENTS: |
| 3275 case UINT32_ELEMENTS: | 3393 case UINT32_ELEMENTS: |
| 3276 __ ldr(result, mem_operand); | 3394 if (key_is_constant) { |
| 3395 __ LoadWord(result, mem_operand, r0); |
| 3396 } else { |
| 3397 __ lwzx(result, mem_operand); |
| 3398 } |
| 3277 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { | 3399 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3278 __ cmp(result, Operand(0x80000000)); | 3400 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 3279 DeoptimizeIf(cs, instr->environment()); | 3401 __ cmplw(result, r0); |
| 3402 DeoptimizeIf(ge, instr->environment()); |
| 3280 } | 3403 } |
| 3281 break; | 3404 break; |
| 3282 case FLOAT32_ELEMENTS: | 3405 case FLOAT32_ELEMENTS: |
| 3283 case FLOAT64_ELEMENTS: | 3406 case FLOAT64_ELEMENTS: |
| 3284 case EXTERNAL_FLOAT32_ELEMENTS: | 3407 case EXTERNAL_FLOAT32_ELEMENTS: |
| 3285 case EXTERNAL_FLOAT64_ELEMENTS: | 3408 case EXTERNAL_FLOAT64_ELEMENTS: |
| 3286 case FAST_HOLEY_DOUBLE_ELEMENTS: | 3409 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 3287 case FAST_HOLEY_ELEMENTS: | 3410 case FAST_HOLEY_ELEMENTS: |
| 3288 case FAST_HOLEY_SMI_ELEMENTS: | 3411 case FAST_HOLEY_SMI_ELEMENTS: |
| 3289 case FAST_DOUBLE_ELEMENTS: | 3412 case FAST_DOUBLE_ELEMENTS: |
| 3290 case FAST_ELEMENTS: | 3413 case FAST_ELEMENTS: |
| 3291 case FAST_SMI_ELEMENTS: | 3414 case FAST_SMI_ELEMENTS: |
| 3292 case DICTIONARY_ELEMENTS: | 3415 case DICTIONARY_ELEMENTS: |
| 3293 case SLOPPY_ARGUMENTS_ELEMENTS: | 3416 case SLOPPY_ARGUMENTS_ELEMENTS: |
| 3294 UNREACHABLE(); | 3417 UNREACHABLE(); |
| 3295 break; | 3418 break; |
| 3296 } | 3419 } |
| 3297 } | 3420 } |
| 3298 } | 3421 } |
| 3299 | 3422 |
| 3300 | 3423 |
| 3301 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { | 3424 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 3302 Register elements = ToRegister(instr->elements()); | 3425 Register elements = ToRegister(instr->elements()); |
| 3303 bool key_is_constant = instr->key()->IsConstantOperand(); | 3426 bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3304 Register key = no_reg; | 3427 Register key = no_reg; |
| 3305 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3428 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3306 Register scratch = scratch0(); | 3429 Register scratch = scratch0(); |
| 3307 | 3430 |
| 3308 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); | 3431 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 3309 | 3432 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 3310 int base_offset = instr->base_offset(); | 3433 int constant_key = 0; |
| 3311 if (key_is_constant) { | 3434 if (key_is_constant) { |
| 3312 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 3435 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3313 if (constant_key & 0xF0000000) { | 3436 if (constant_key & 0xF0000000) { |
| 3314 Abort(kArrayIndexConstantValueTooBig); | 3437 Abort(kArrayIndexConstantValueTooBig); |
| 3315 } | 3438 } |
| 3316 base_offset += constant_key * kDoubleSize; | 3439 } else { |
| 3317 } | |
| 3318 __ add(scratch, elements, Operand(base_offset)); | |
| 3319 | |
| 3320 if (!key_is_constant) { | |
| 3321 key = ToRegister(instr->key()); | 3440 key = ToRegister(instr->key()); |
| 3322 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | |
| 3323 ? (element_size_shift - kSmiTagSize) : element_size_shift; | |
| 3324 __ add(scratch, scratch, Operand(key, LSL, shift_size)); | |
| 3325 } | 3441 } |
| 3326 | 3442 |
| 3327 __ vldr(result, scratch, 0); | 3443 int base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 3444 if (!key_is_constant) { |
| 3445 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 3446 __ add(scratch, elements, r0); |
| 3447 elements = scratch; |
| 3448 } |
| 3449 if (!is_int16(base_offset)) { |
| 3450 __ Add(scratch, elements, base_offset, r0); |
| 3451 base_offset = 0; |
| 3452 elements = scratch; |
| 3453 } |
| 3454 __ lfd(result, MemOperand(elements, base_offset)); |
| 3328 | 3455 |
| 3329 if (instr->hydrogen()->RequiresHoleCheck()) { | 3456 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3330 __ ldr(scratch, MemOperand(scratch, sizeof(kHoleNanLower32))); | 3457 if (is_int16(base_offset + Register::kExponentOffset)) { |
| 3331 __ cmp(scratch, Operand(kHoleNanUpper32)); | 3458 __ lwz(scratch, MemOperand(elements, |
| 3459 base_offset + Register::kExponentOffset)); |
| 3460 } else { |
| 3461 __ addi(scratch, elements, Operand(base_offset)); |
| 3462 __ lwz(scratch, MemOperand(scratch, Register::kExponentOffset)); |
| 3463 } |
| 3464 __ Cmpi(scratch, Operand(kHoleNanUpper32), r0); |
| 3332 DeoptimizeIf(eq, instr->environment()); | 3465 DeoptimizeIf(eq, instr->environment()); |
| 3333 } | 3466 } |
| 3334 } | 3467 } |
| 3335 | 3468 |
| 3336 | 3469 |
| 3337 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { | 3470 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3471 HLoadKeyed* hinstr = instr->hydrogen(); |
| 3338 Register elements = ToRegister(instr->elements()); | 3472 Register elements = ToRegister(instr->elements()); |
| 3339 Register result = ToRegister(instr->result()); | 3473 Register result = ToRegister(instr->result()); |
| 3340 Register scratch = scratch0(); | 3474 Register scratch = scratch0(); |
| 3341 Register store_base = scratch; | 3475 Register store_base = scratch; |
| 3342 int offset = instr->base_offset(); | 3476 int offset = instr->base_offset(); |
| 3343 | 3477 |
| 3344 if (instr->key()->IsConstantOperand()) { | 3478 if (instr->key()->IsConstantOperand()) { |
| 3345 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | 3479 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3346 offset += ToInteger32(const_operand) * kPointerSize; | 3480 offset += ToInteger32(const_operand) * kPointerSize; |
| 3347 store_base = elements; | 3481 store_base = elements; |
| 3348 } else { | 3482 } else { |
| 3349 Register key = ToRegister(instr->key()); | 3483 Register key = ToRegister(instr->key()); |
| 3350 // Even though the HLoadKeyed instruction forces the input | 3484 // Even though the HLoadKeyed instruction forces the input |
| 3351 // representation for the key to be an integer, the input gets replaced | 3485 // representation for the key to be an integer, the input gets replaced |
| 3352 // during bound check elimination with the index argument to the bounds | 3486 // during bound check elimination with the index argument to the bounds |
| 3353 // check, which can be tagged, so that case must be handled here, too. | 3487 // check, which can be tagged, so that case must be handled here, too. |
| 3354 if (instr->hydrogen()->key()->representation().IsSmi()) { | 3488 if (hinstr->key()->representation().IsSmi()) { |
| 3355 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); | 3489 __ SmiToPtrArrayOffset(r0, key); |
| 3356 } else { | 3490 } else { |
| 3357 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); | 3491 __ ShiftLeftImm(r0, key, Operand(kPointerSizeLog2)); |
| 3358 } | 3492 } |
| 3493 __ add(scratch, elements, r0); |
| 3359 } | 3494 } |
| 3360 __ ldr(result, MemOperand(store_base, offset)); | 3495 |
| 3496 bool requires_hole_check = hinstr->RequiresHoleCheck(); |
| 3497 Representation representation = hinstr->representation(); |
| 3498 |
| 3499 #if V8_TARGET_ARCH_PPC64 |
| 3500 // 64-bit Smi optimization |
| 3501 if (representation.IsInteger32() && |
| 3502 hinstr->elements_kind() == FAST_SMI_ELEMENTS) { |
| 3503 ASSERT(!requires_hole_check); |
| 3504 // Read int value directly from upper half of the smi. |
| 3505 STATIC_ASSERT(kSmiTag == 0); |
| 3506 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 3507 #if V8_TARGET_LITTLE_ENDIAN |
| 3508 offset += kPointerSize / 2; |
| 3509 #endif |
| 3510 } |
| 3511 #endif |
| 3512 |
| 3513 __ LoadRepresentation(result, MemOperand(store_base, offset), |
| 3514 representation, r0); |
| 3361 | 3515 |
| 3362 // Check for the hole value. | 3516 // Check for the hole value. |
| 3363 if (instr->hydrogen()->RequiresHoleCheck()) { | 3517 if (requires_hole_check) { |
| 3364 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { | 3518 if (IsFastSmiElementsKind(hinstr->elements_kind())) { |
| 3365 __ SmiTst(result); | 3519 __ TestIfSmi(result, r0); |
| 3366 DeoptimizeIf(ne, instr->environment()); | 3520 DeoptimizeIf(ne, instr->environment(), cr0); |
| 3367 } else { | 3521 } else { |
| 3368 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); | 3522 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3369 __ cmp(result, scratch); | 3523 __ cmp(result, scratch); |
| 3370 DeoptimizeIf(eq, instr->environment()); | 3524 DeoptimizeIf(eq, instr->environment()); |
| 3371 } | 3525 } |
| 3372 } | 3526 } |
| 3373 } | 3527 } |
| 3374 | 3528 |
| 3375 | 3529 |
| 3376 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { | 3530 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3377 if (instr->is_typed_elements()) { | 3531 if (instr->is_typed_elements()) { |
| 3378 DoLoadKeyedExternalArray(instr); | 3532 DoLoadKeyedExternalArray(instr); |
| 3379 } else if (instr->hydrogen()->representation().IsDouble()) { | 3533 } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3380 DoLoadKeyedFixedDoubleArray(instr); | 3534 DoLoadKeyedFixedDoubleArray(instr); |
| 3381 } else { | 3535 } else { |
| 3382 DoLoadKeyedFixedArray(instr); | 3536 DoLoadKeyedFixedArray(instr); |
| 3383 } | 3537 } |
| 3384 } | 3538 } |
| 3385 | 3539 |
| 3386 | 3540 |
| 3387 MemOperand LCodeGen::PrepareKeyedOperand(Register key, | 3541 MemOperand LCodeGen::PrepareKeyedOperand(Register key, |
| 3388 Register base, | 3542 Register base, |
| 3389 bool key_is_constant, | 3543 bool key_is_constant, |
| 3544 bool key_is_smi, |
| 3390 int constant_key, | 3545 int constant_key, |
| 3391 int element_size, | 3546 int element_size_shift, |
| 3392 int shift_size, | |
| 3393 int base_offset) { | 3547 int base_offset) { |
| 3548 Register scratch = scratch0(); |
| 3549 |
| 3394 if (key_is_constant) { | 3550 if (key_is_constant) { |
| 3395 return MemOperand(base, (constant_key << element_size) + base_offset); | 3551 return MemOperand(base, (constant_key << element_size_shift) + base_offset); |
| 3396 } | 3552 } |
| 3397 | 3553 |
| 3398 if (base_offset == 0) { | 3554 bool needs_shift = (element_size_shift != (key_is_smi ? |
| 3399 if (shift_size >= 0) { | 3555 kSmiTagSize + kSmiShiftSize : 0)); |
| 3400 return MemOperand(base, key, LSL, shift_size); | 3556 |
| 3401 } else { | 3557 if (!(base_offset || needs_shift)) { |
| 3402 ASSERT_EQ(-1, shift_size); | 3558 return MemOperand(base, key); |
| 3403 return MemOperand(base, key, LSR, 1); | |
| 3404 } | |
| 3405 } | 3559 } |
| 3406 | 3560 |
| 3407 if (shift_size >= 0) { | 3561 if (needs_shift) { |
| 3408 __ add(scratch0(), base, Operand(key, LSL, shift_size)); | 3562 __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 3409 return MemOperand(scratch0(), base_offset); | 3563 key = scratch; |
| 3410 } else { | |
| 3411 ASSERT_EQ(-1, shift_size); | |
| 3412 __ add(scratch0(), base, Operand(key, ASR, 1)); | |
| 3413 return MemOperand(scratch0(), base_offset); | |
| 3414 } | 3564 } |
| 3565 |
| 3566 if (base_offset) { |
| 3567 __ Add(scratch, key, base_offset, r0); |
| 3568 } |
| 3569 |
| 3570 return MemOperand(base, scratch); |
| 3415 } | 3571 } |
| 3416 | 3572 |
| 3417 | 3573 |
| 3418 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { | 3574 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 3419 ASSERT(ToRegister(instr->context()).is(cp)); | 3575 ASSERT(ToRegister(instr->context()).is(cp)); |
| 3420 ASSERT(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); | 3576 ASSERT(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); |
| 3421 ASSERT(ToRegister(instr->key()).is(LoadIC::NameRegister())); | 3577 ASSERT(ToRegister(instr->key()).is(LoadIC::NameRegister())); |
| 3422 | 3578 |
| 3423 if (FLAG_vector_ics) { | 3579 if (FLAG_vector_ics) { |
| 3424 Register vector = ToRegister(instr->temp_vector()); | 3580 Register vector = ToRegister(instr->temp_vector()); |
| 3425 ASSERT(vector.is(LoadIC::VectorRegister())); | 3581 ASSERT(vector.is(LoadIC::VectorRegister())); |
| 3426 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3582 __ Move(vector, instr->hydrogen()->feedback_vector()); |
| 3427 // No need to allocate this register. | 3583 // No need to allocate this register. |
| 3428 ASSERT(LoadIC::SlotRegister().is(r0)); | 3584 ASSERT(LoadIC::SlotRegister().is(r0)); |
| 3429 __ mov(LoadIC::SlotRegister(), | 3585 __ mov(LoadIC::SlotRegister(), |
| 3430 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3586 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
| 3431 } | 3587 } |
| 3432 | 3588 |
| 3433 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); | 3589 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
| 3434 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 3590 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3435 } | 3591 } |
| 3436 | 3592 |
| 3437 | 3593 |
| 3438 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { | 3594 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3439 Register scratch = scratch0(); | 3595 Register scratch = scratch0(); |
| 3440 Register result = ToRegister(instr->result()); | 3596 Register result = ToRegister(instr->result()); |
| 3441 | 3597 |
| 3442 if (instr->hydrogen()->from_inlined()) { | 3598 if (instr->hydrogen()->from_inlined()) { |
| 3443 __ sub(result, sp, Operand(2 * kPointerSize)); | 3599 __ subi(result, sp, Operand(2 * kPointerSize)); |
| 3444 } else { | 3600 } else { |
| 3445 // Check if the calling frame is an arguments adaptor frame. | 3601 // Check if the calling frame is an arguments adaptor frame. |
| 3446 Label done, adapted; | 3602 Label done, adapted; |
| 3447 __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 3603 __ LoadP(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3448 __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); | 3604 __ LoadP(result, |
| 3449 __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | 3605 MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3606 __ CmpSmiLiteral(result, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
| 3450 | 3607 |
| 3451 // Result is the frame pointer for the frame if not adapted and for the real | 3608 // Result is the frame pointer for the frame if not adapted and for the real |
| 3452 // frame below the adaptor frame if adapted. | 3609 // frame below the adaptor frame if adapted. |
| 3453 __ mov(result, fp, LeaveCC, ne); | 3610 __ beq(&adapted); |
| 3454 __ mov(result, scratch, LeaveCC, eq); | 3611 __ mr(result, fp); |
| 3612 __ b(&done); |
| 3613 |
| 3614 __ bind(&adapted); |
| 3615 __ mr(result, scratch); |
| 3616 __ bind(&done); |
| 3455 } | 3617 } |
| 3456 } | 3618 } |
| 3457 | 3619 |
| 3458 | 3620 |
| 3459 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { | 3621 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
| 3460 Register elem = ToRegister(instr->elements()); | 3622 Register elem = ToRegister(instr->elements()); |
| 3461 Register result = ToRegister(instr->result()); | 3623 Register result = ToRegister(instr->result()); |
| 3462 | 3624 |
| 3463 Label done; | 3625 Label done; |
| 3464 | 3626 |
| 3465 // If no arguments adaptor frame the number of arguments is fixed. | 3627 // If no arguments adaptor frame the number of arguments is fixed. |
| 3466 __ cmp(fp, elem); | 3628 __ cmp(fp, elem); |
| 3467 __ mov(result, Operand(scope()->num_parameters())); | 3629 __ mov(result, Operand(scope()->num_parameters())); |
| 3468 __ b(eq, &done); | 3630 __ beq(&done); |
| 3469 | 3631 |
| 3470 // Arguments adaptor frame present. Get argument length from there. | 3632 // Arguments adaptor frame present. Get argument length from there. |
| 3471 __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 3633 __ LoadP(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3472 __ ldr(result, | 3634 __ LoadP(result, |
| 3473 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 3635 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3474 __ SmiUntag(result); | 3636 __ SmiUntag(result); |
| 3475 | 3637 |
| 3476 // Argument length is in result register. | 3638 // Argument length is in result register. |
| 3477 __ bind(&done); | 3639 __ bind(&done); |
| 3478 } | 3640 } |
| 3479 | 3641 |
| 3480 | 3642 |
| 3481 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { | 3643 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
| 3482 Register receiver = ToRegister(instr->receiver()); | 3644 Register receiver = ToRegister(instr->receiver()); |
| 3483 Register function = ToRegister(instr->function()); | 3645 Register function = ToRegister(instr->function()); |
| 3484 Register result = ToRegister(instr->result()); | 3646 Register result = ToRegister(instr->result()); |
| 3485 Register scratch = scratch0(); | 3647 Register scratch = scratch0(); |
| 3486 | 3648 |
| 3487 // If the receiver is null or undefined, we have to pass the global | 3649 // If the receiver is null or undefined, we have to pass the global |
| 3488 // object as a receiver to normal functions. Values have to be | 3650 // object as a receiver to normal functions. Values have to be |
| 3489 // passed unchanged to builtins and strict-mode functions. | 3651 // passed unchanged to builtins and strict-mode functions. |
| 3490 Label global_object, result_in_receiver; | 3652 Label global_object, result_in_receiver; |
| 3491 | 3653 |
| 3492 if (!instr->hydrogen()->known_function()) { | 3654 if (!instr->hydrogen()->known_function()) { |
| 3493 // Do not transform the receiver to object for strict mode | 3655 // Do not transform the receiver to object for strict mode |
| 3494 // functions. | 3656 // functions. |
| 3495 __ ldr(scratch, | 3657 __ LoadP(scratch, |
| 3496 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); | 3658 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3497 __ ldr(scratch, | 3659 __ lwz(scratch, |
| 3498 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); | 3660 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3499 int mask = 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize); | 3661 __ TestBit(scratch, |
| 3500 __ tst(scratch, Operand(mask)); | 3662 #if V8_TARGET_ARCH_PPC64 |
| 3501 __ b(ne, &result_in_receiver); | 3663 SharedFunctionInfo::kStrictModeFunction, |
| 3664 #else |
| 3665 SharedFunctionInfo::kStrictModeFunction + kSmiTagSize, |
| 3666 #endif |
| 3667 r0); |
| 3668 __ bne(&result_in_receiver, cr0); |
| 3502 | 3669 |
| 3503 // Do not transform the receiver to object for builtins. | 3670 // Do not transform the receiver to object for builtins. |
| 3504 __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); | 3671 __ TestBit(scratch, |
| 3505 __ b(ne, &result_in_receiver); | 3672 #if V8_TARGET_ARCH_PPC64 |
| 3673 SharedFunctionInfo::kNative, |
| 3674 #else |
| 3675 SharedFunctionInfo::kNative + kSmiTagSize, |
| 3676 #endif |
| 3677 r0); |
| 3678 __ bne(&result_in_receiver, cr0); |
| 3506 } | 3679 } |
| 3507 | 3680 |
| 3508 // Normal function. Replace undefined or null with global receiver. | 3681 // Normal function. Replace undefined or null with global receiver. |
| 3509 __ LoadRoot(scratch, Heap::kNullValueRootIndex); | 3682 __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 3510 __ cmp(receiver, scratch); | 3683 __ cmp(receiver, scratch); |
| 3511 __ b(eq, &global_object); | 3684 __ beq(&global_object); |
| 3512 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | 3685 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 3513 __ cmp(receiver, scratch); | 3686 __ cmp(receiver, scratch); |
| 3514 __ b(eq, &global_object); | 3687 __ beq(&global_object); |
| 3515 | 3688 |
| 3516 // Deoptimize if the receiver is not a JS object. | 3689 // Deoptimize if the receiver is not a JS object. |
| 3517 __ SmiTst(receiver); | 3690 __ TestIfSmi(receiver, r0); |
| 3518 DeoptimizeIf(eq, instr->environment()); | 3691 DeoptimizeIf(eq, instr->environment(), cr0); |
| 3519 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); | 3692 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); |
| 3520 DeoptimizeIf(lt, instr->environment()); | 3693 DeoptimizeIf(lt, instr->environment()); |
| 3521 | 3694 |
| 3522 __ b(&result_in_receiver); | 3695 __ b(&result_in_receiver); |
| 3523 __ bind(&global_object); | 3696 __ bind(&global_object); |
| 3524 __ ldr(result, FieldMemOperand(function, JSFunction::kContextOffset)); | 3697 __ LoadP(result, FieldMemOperand(function, JSFunction::kContextOffset)); |
| 3525 __ ldr(result, | 3698 __ LoadP(result, |
| 3526 ContextOperand(result, Context::GLOBAL_OBJECT_INDEX)); | 3699 ContextOperand(result, Context::GLOBAL_OBJECT_INDEX)); |
| 3527 __ ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset)); | 3700 __ LoadP(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset)); |
| 3528 | |
| 3529 if (result.is(receiver)) { | 3701 if (result.is(receiver)) { |
| 3530 __ bind(&result_in_receiver); | 3702 __ bind(&result_in_receiver); |
| 3531 } else { | 3703 } else { |
| 3532 Label result_ok; | 3704 Label result_ok; |
| 3533 __ b(&result_ok); | 3705 __ b(&result_ok); |
| 3534 __ bind(&result_in_receiver); | 3706 __ bind(&result_in_receiver); |
| 3535 __ mov(result, receiver); | 3707 __ mr(result, receiver); |
| 3536 __ bind(&result_ok); | 3708 __ bind(&result_ok); |
| 3537 } | 3709 } |
| 3538 } | 3710 } |
| 3539 | 3711 |
| 3540 | 3712 |
| 3541 void LCodeGen::DoApplyArguments(LApplyArguments* instr) { | 3713 void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3542 Register receiver = ToRegister(instr->receiver()); | 3714 Register receiver = ToRegister(instr->receiver()); |
| 3543 Register function = ToRegister(instr->function()); | 3715 Register function = ToRegister(instr->function()); |
| 3544 Register length = ToRegister(instr->length()); | 3716 Register length = ToRegister(instr->length()); |
| 3545 Register elements = ToRegister(instr->elements()); | 3717 Register elements = ToRegister(instr->elements()); |
| 3546 Register scratch = scratch0(); | 3718 Register scratch = scratch0(); |
| 3547 ASSERT(receiver.is(r0)); // Used for parameter count. | 3719 ASSERT(receiver.is(r3)); // Used for parameter count. |
| 3548 ASSERT(function.is(r1)); // Required by InvokeFunction. | 3720 ASSERT(function.is(r4)); // Required by InvokeFunction. |
| 3549 ASSERT(ToRegister(instr->result()).is(r0)); | 3721 ASSERT(ToRegister(instr->result()).is(r3)); |
| 3550 | 3722 |
| 3551 // Copy the arguments to this function possibly from the | 3723 // Copy the arguments to this function possibly from the |
| 3552 // adaptor frame below it. | 3724 // adaptor frame below it. |
| 3553 const uint32_t kArgumentsLimit = 1 * KB; | 3725 const uint32_t kArgumentsLimit = 1 * KB; |
| 3554 __ cmp(length, Operand(kArgumentsLimit)); | 3726 __ cmpli(length, Operand(kArgumentsLimit)); |
| 3555 DeoptimizeIf(hi, instr->environment()); | 3727 DeoptimizeIf(gt, instr->environment()); |
| 3556 | 3728 |
| 3557 // Push the receiver and use the register to keep the original | 3729 // Push the receiver and use the register to keep the original |
| 3558 // number of arguments. | 3730 // number of arguments. |
| 3559 __ push(receiver); | 3731 __ push(receiver); |
| 3560 __ mov(receiver, length); | 3732 __ mr(receiver, length); |
| 3561 // The arguments are at a one pointer size offset from elements. | 3733 // The arguments are at a one pointer size offset from elements. |
| 3562 __ add(elements, elements, Operand(1 * kPointerSize)); | 3734 __ addi(elements, elements, Operand(1 * kPointerSize)); |
| 3563 | 3735 |
| 3564 // Loop through the arguments pushing them onto the execution | 3736 // Loop through the arguments pushing them onto the execution |
| 3565 // stack. | 3737 // stack. |
| 3566 Label invoke, loop; | 3738 Label invoke, loop; |
| 3567 // length is a small non-negative integer, due to the test above. | 3739 // length is a small non-negative integer, due to the test above. |
| 3568 __ cmp(length, Operand::Zero()); | 3740 __ cmpi(length, Operand::Zero()); |
| 3569 __ b(eq, &invoke); | 3741 __ beq(&invoke); |
| 3742 __ mtctr(length); |
| 3570 __ bind(&loop); | 3743 __ bind(&loop); |
| 3571 __ ldr(scratch, MemOperand(elements, length, LSL, 2)); | 3744 __ ShiftLeftImm(r0, length, Operand(kPointerSizeLog2)); |
| 3745 __ LoadPX(scratch, MemOperand(elements, r0)); |
| 3572 __ push(scratch); | 3746 __ push(scratch); |
| 3573 __ sub(length, length, Operand(1), SetCC); | 3747 __ addi(length, length, Operand(-1)); |
| 3574 __ b(ne, &loop); | 3748 __ bdnz(&loop); |
| 3575 | 3749 |
| 3576 __ bind(&invoke); | 3750 __ bind(&invoke); |
| 3577 ASSERT(instr->HasPointerMap()); | 3751 ASSERT(instr->HasPointerMap()); |
| 3578 LPointerMap* pointers = instr->pointer_map(); | 3752 LPointerMap* pointers = instr->pointer_map(); |
| 3579 SafepointGenerator safepoint_generator( | 3753 SafepointGenerator safepoint_generator( |
| 3580 this, pointers, Safepoint::kLazyDeopt); | 3754 this, pointers, Safepoint::kLazyDeopt); |
| 3581 // The number of arguments is stored in receiver which is r0, as expected | 3755 // The number of arguments is stored in receiver which is r3, as expected |
| 3582 // by InvokeFunction. | 3756 // by InvokeFunction. |
| 3583 ParameterCount actual(receiver); | 3757 ParameterCount actual(receiver); |
| 3584 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); | 3758 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); |
| 3585 } | 3759 } |
| 3586 | 3760 |
| 3587 | 3761 |
| 3588 void LCodeGen::DoPushArgument(LPushArgument* instr) { | 3762 void LCodeGen::DoPushArgument(LPushArgument* instr) { |
| 3589 LOperand* argument = instr->value(); | 3763 LOperand* argument = instr->value(); |
| 3590 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { | 3764 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 3591 Abort(kDoPushArgumentNotImplementedForDoubleType); | 3765 Abort(kDoPushArgumentNotImplementedForDoubleType); |
| 3592 } else { | 3766 } else { |
| 3593 Register argument_reg = EmitLoadRegister(argument, ip); | 3767 Register argument_reg = EmitLoadRegister(argument, ip); |
| 3594 __ push(argument_reg); | 3768 __ push(argument_reg); |
| 3595 } | 3769 } |
| 3596 } | 3770 } |
| 3597 | 3771 |
| 3598 | 3772 |
| 3599 void LCodeGen::DoDrop(LDrop* instr) { | 3773 void LCodeGen::DoDrop(LDrop* instr) { |
| 3600 __ Drop(instr->count()); | 3774 __ Drop(instr->count()); |
| 3601 } | 3775 } |
| 3602 | 3776 |
| 3603 | 3777 |
| 3604 void LCodeGen::DoThisFunction(LThisFunction* instr) { | 3778 void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3605 Register result = ToRegister(instr->result()); | 3779 Register result = ToRegister(instr->result()); |
| 3606 __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 3780 __ LoadP(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3607 } | 3781 } |
| 3608 | 3782 |
| 3609 | 3783 |
| 3610 void LCodeGen::DoContext(LContext* instr) { | 3784 void LCodeGen::DoContext(LContext* instr) { |
| 3611 // If there is a non-return use, the context must be moved to a register. | 3785 // If there is a non-return use, the context must be moved to a register. |
| 3612 Register result = ToRegister(instr->result()); | 3786 Register result = ToRegister(instr->result()); |
| 3613 if (info()->IsOptimizing()) { | 3787 if (info()->IsOptimizing()) { |
| 3614 __ ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 3788 __ LoadP(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3615 } else { | 3789 } else { |
| 3616 // If there is no frame, the context must be in cp. | 3790 // If there is no frame, the context must be in cp. |
| 3617 ASSERT(result.is(cp)); | 3791 ASSERT(result.is(cp)); |
| 3618 } | 3792 } |
| 3619 } | 3793 } |
| 3620 | 3794 |
| 3621 | 3795 |
| 3622 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { | 3796 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
| 3623 ASSERT(ToRegister(instr->context()).is(cp)); | 3797 ASSERT(ToRegister(instr->context()).is(cp)); |
| 3624 __ push(cp); // The context is the first argument. | 3798 __ push(cp); // The context is the first argument. |
| 3625 __ Move(scratch0(), instr->hydrogen()->pairs()); | 3799 __ Move(scratch0(), instr->hydrogen()->pairs()); |
| 3626 __ push(scratch0()); | 3800 __ push(scratch0()); |
| 3627 __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); | 3801 __ LoadSmiLiteral(scratch0(), Smi::FromInt(instr->hydrogen()->flags())); |
| 3628 __ push(scratch0()); | 3802 __ push(scratch0()); |
| 3629 CallRuntime(Runtime::kDeclareGlobals, 3, instr); | 3803 CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3630 } | 3804 } |
| 3631 | 3805 |
| 3632 | 3806 |
| 3633 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, | 3807 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
| 3634 int formal_parameter_count, | 3808 int formal_parameter_count, |
| 3635 int arity, | 3809 int arity, |
| 3636 LInstruction* instr, | 3810 LInstruction* instr, |
| 3637 R1State r1_state) { | 3811 R4State r4_state) { |
| 3638 bool dont_adapt_arguments = | 3812 bool dont_adapt_arguments = |
| 3639 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; | 3813 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3640 bool can_invoke_directly = | 3814 bool can_invoke_directly = |
| 3641 dont_adapt_arguments || formal_parameter_count == arity; | 3815 dont_adapt_arguments || formal_parameter_count == arity; |
| 3642 | 3816 |
| 3643 LPointerMap* pointers = instr->pointer_map(); | 3817 LPointerMap* pointers = instr->pointer_map(); |
| 3644 | 3818 |
| 3645 if (can_invoke_directly) { | 3819 if (can_invoke_directly) { |
| 3646 if (r1_state == R1_UNINITIALIZED) { | 3820 if (r4_state == R4_UNINITIALIZED) { |
| 3647 __ Move(r1, function); | 3821 __ Move(r4, function); |
| 3648 } | 3822 } |
| 3649 | 3823 |
| 3650 // Change context. | 3824 // Change context. |
| 3651 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 3825 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
| 3652 | 3826 |
| 3653 // Set r0 to arguments count if adaption is not needed. Assumes that r0 | 3827 // Set r3 to arguments count if adaption is not needed. Assumes that r3 |
| 3654 // is available to write to at this point. | 3828 // is available to write to at this point. |
| 3655 if (dont_adapt_arguments) { | 3829 if (dont_adapt_arguments) { |
| 3656 __ mov(r0, Operand(arity)); | 3830 __ mov(r3, Operand(arity)); |
| 3657 } | 3831 } |
| 3658 | 3832 |
| 3659 // Invoke function. | 3833 // Invoke function. |
| 3660 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); | 3834 if (function.is_identical_to(info()->closure())) { |
| 3661 __ Call(ip); | 3835 __ CallSelf(); |
| 3836 } else { |
| 3837 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 3838 __ Call(ip); |
| 3839 } |
| 3662 | 3840 |
| 3663 // Set up deoptimization. | 3841 // Set up deoptimization. |
| 3664 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 3842 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3665 } else { | 3843 } else { |
| 3666 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 3844 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3667 ParameterCount count(arity); | 3845 ParameterCount count(arity); |
| 3668 ParameterCount expected(formal_parameter_count); | 3846 ParameterCount expected(formal_parameter_count); |
| 3669 __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); | 3847 __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); |
| 3670 } | 3848 } |
| 3671 } | 3849 } |
| 3672 | 3850 |
| 3673 | 3851 |
| 3674 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { | 3852 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
| 3675 ASSERT(instr->context() != NULL); | 3853 ASSERT(instr->context() != NULL); |
| 3676 ASSERT(ToRegister(instr->context()).is(cp)); | 3854 ASSERT(ToRegister(instr->context()).is(cp)); |
| 3677 Register input = ToRegister(instr->value()); | 3855 Register input = ToRegister(instr->value()); |
| 3678 Register result = ToRegister(instr->result()); | 3856 Register result = ToRegister(instr->result()); |
| 3679 Register scratch = scratch0(); | 3857 Register scratch = scratch0(); |
| 3680 | 3858 |
| 3681 // Deoptimize if not a heap number. | 3859 // Deoptimize if not a heap number. |
| 3682 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 3860 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3683 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 3861 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3684 __ cmp(scratch, Operand(ip)); | 3862 __ cmp(scratch, ip); |
| 3685 DeoptimizeIf(ne, instr->environment()); | 3863 DeoptimizeIf(ne, instr->environment()); |
| 3686 | 3864 |
| 3687 Label done; | 3865 Label done; |
| 3688 Register exponent = scratch0(); | 3866 Register exponent = scratch0(); |
| 3689 scratch = no_reg; | 3867 scratch = no_reg; |
| 3690 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); | 3868 __ lwz(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3691 // Check the sign of the argument. If the argument is positive, just | 3869 // Check the sign of the argument. If the argument is positive, just |
| 3692 // return it. | 3870 // return it. |
| 3693 __ tst(exponent, Operand(HeapNumber::kSignMask)); | 3871 __ cmpwi(exponent, Operand::Zero()); |
| 3694 // Move the input to the result if necessary. | 3872 // Move the input to the result if necessary. |
| 3695 __ Move(result, input); | 3873 __ Move(result, input); |
| 3696 __ b(eq, &done); | 3874 __ bge(&done); |
| 3697 | 3875 |
| 3698 // Input is negative. Reverse its sign. | 3876 // Input is negative. Reverse its sign. |
| 3699 // Preserve the value of all registers. | 3877 // Preserve the value of all registers. |
| 3700 { | 3878 { |
| 3701 PushSafepointRegistersScope scope(this); | 3879 PushSafepointRegistersScope scope(this); |
| 3702 | 3880 |
| 3703 // Registers were saved at the safepoint, so we can use | 3881 // Registers were saved at the safepoint, so we can use |
| 3704 // many scratch registers. | 3882 // many scratch registers. |
| 3705 Register tmp1 = input.is(r1) ? r0 : r1; | 3883 Register tmp1 = input.is(r4) ? r3 : r4; |
| 3706 Register tmp2 = input.is(r2) ? r0 : r2; | 3884 Register tmp2 = input.is(r5) ? r3 : r5; |
| 3707 Register tmp3 = input.is(r3) ? r0 : r3; | 3885 Register tmp3 = input.is(r6) ? r3 : r6; |
| 3708 Register tmp4 = input.is(r4) ? r0 : r4; | 3886 Register tmp4 = input.is(r7) ? r3 : r7; |
| 3709 | 3887 |
| 3710 // exponent: floating point exponent value. | 3888 // exponent: floating point exponent value. |
| 3711 | 3889 |
| 3712 Label allocated, slow; | 3890 Label allocated, slow; |
| 3713 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); | 3891 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3714 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); | 3892 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3715 __ b(&allocated); | 3893 __ b(&allocated); |
| 3716 | 3894 |
| 3717 // Slow case: Call the runtime system to do the number allocation. | 3895 // Slow case: Call the runtime system to do the number allocation. |
| 3718 __ bind(&slow); | 3896 __ bind(&slow); |
| 3719 | 3897 |
| 3720 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, | 3898 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, |
| 3721 instr->context()); | 3899 instr->context()); |
| 3722 // Set the pointer to the new heap number in tmp. | 3900 // Set the pointer to the new heap number in tmp. |
| 3723 if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); | 3901 if (!tmp1.is(r3)) __ mr(tmp1, r3); |
| 3724 // Restore input_reg after call to runtime. | 3902 // Restore input_reg after call to runtime. |
| 3725 __ LoadFromSafepointRegisterSlot(input, input); | 3903 __ LoadFromSafepointRegisterSlot(input, input); |
| 3726 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); | 3904 __ lwz(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3727 | 3905 |
| 3728 __ bind(&allocated); | 3906 __ bind(&allocated); |
| 3729 // exponent: floating point exponent value. | 3907 // exponent: floating point exponent value. |
| 3730 // tmp1: allocated heap number. | 3908 // tmp1: allocated heap number. |
| 3731 __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); | 3909 STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 3732 __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); | 3910 __ clrlwi(exponent, exponent, Operand(1)); // clear sign bit |
| 3733 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); | 3911 __ stw(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3734 __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); | 3912 __ lwz(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3913 __ stw(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
| 3735 | 3914 |
| 3736 __ StoreToSafepointRegisterSlot(tmp1, result); | 3915 __ StoreToSafepointRegisterSlot(tmp1, result); |
| 3737 } | 3916 } |
| 3738 | 3917 |
| 3739 __ bind(&done); | 3918 __ bind(&done); |
| 3740 } | 3919 } |
| 3741 | 3920 |
| 3742 | 3921 |
| 3743 void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { | 3922 void LCodeGen::EmitMathAbs(LMathAbs* instr) { |
| 3744 Register input = ToRegister(instr->value()); | 3923 Register input = ToRegister(instr->value()); |
| 3745 Register result = ToRegister(instr->result()); | 3924 Register result = ToRegister(instr->result()); |
| 3746 __ cmp(input, Operand::Zero()); | 3925 Label done; |
| 3747 __ Move(result, input, pl); | 3926 __ cmpi(input, Operand::Zero()); |
| 3748 // We can make rsb conditional because the previous cmp instruction | 3927 __ Move(result, input); |
| 3749 // will clear the V (overflow) flag and rsb won't set this flag | 3928 __ bge(&done); |
| 3750 // if input is positive. | 3929 __ li(r0, Operand::Zero()); // clear xer |
| 3751 __ rsb(result, input, Operand::Zero(), SetCC, mi); | 3930 __ mtxer(r0); |
| 3931 __ neg(result, result, SetOE, SetRC); |
| 3752 // Deoptimize on overflow. | 3932 // Deoptimize on overflow. |
| 3753 DeoptimizeIf(vs, instr->environment()); | 3933 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 3934 __ bind(&done); |
| 3754 } | 3935 } |
| 3755 | 3936 |
| 3756 | 3937 |
| 3938 #if V8_TARGET_ARCH_PPC64 |
| 3939 void LCodeGen::EmitInteger32MathAbs(LMathAbs* instr) { |
| 3940 Register input = ToRegister(instr->value()); |
| 3941 Register result = ToRegister(instr->result()); |
| 3942 Label done; |
| 3943 __ cmpwi(input, Operand::Zero()); |
| 3944 __ Move(result, input); |
| 3945 __ bge(&done); |
| 3946 |
| 3947 // Deoptimize on overflow. |
| 3948 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 3949 __ cmpw(input, r0); |
| 3950 DeoptimizeIf(eq, instr->environment()); |
| 3951 |
| 3952 __ neg(result, result); |
| 3953 __ bind(&done); |
| 3954 } |
| 3955 #endif |
| 3956 |
| 3957 |
| 3757 void LCodeGen::DoMathAbs(LMathAbs* instr) { | 3958 void LCodeGen::DoMathAbs(LMathAbs* instr) { |
| 3758 // Class for deferred case. | 3959 // Class for deferred case. |
| 3759 class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { | 3960 class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
| 3760 public: | 3961 public: |
| 3761 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) | 3962 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
| 3762 : LDeferredCode(codegen), instr_(instr) { } | 3963 : LDeferredCode(codegen), instr_(instr) { } |
| 3763 virtual void Generate() V8_OVERRIDE { | 3964 virtual void Generate() V8_OVERRIDE { |
| 3764 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); | 3965 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3765 } | 3966 } |
| 3766 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 3967 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 3767 private: | 3968 private: |
| 3768 LMathAbs* instr_; | 3969 LMathAbs* instr_; |
| 3769 }; | 3970 }; |
| 3770 | 3971 |
| 3771 Representation r = instr->hydrogen()->value()->representation(); | 3972 Representation r = instr->hydrogen()->value()->representation(); |
| 3772 if (r.IsDouble()) { | 3973 if (r.IsDouble()) { |
| 3773 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3974 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3774 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3975 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3775 __ vabs(result, input); | 3976 __ fabs(result, input); |
| 3977 #if V8_TARGET_ARCH_PPC64 |
| 3978 } else if (r.IsInteger32()) { |
| 3979 EmitInteger32MathAbs(instr); |
| 3980 } else if (r.IsSmi()) { |
| 3981 #else |
| 3776 } else if (r.IsSmiOrInteger32()) { | 3982 } else if (r.IsSmiOrInteger32()) { |
| 3777 EmitIntegerMathAbs(instr); | 3983 #endif |
| 3984 EmitMathAbs(instr); |
| 3778 } else { | 3985 } else { |
| 3779 // Representation is tagged. | 3986 // Representation is tagged. |
| 3780 DeferredMathAbsTaggedHeapNumber* deferred = | 3987 DeferredMathAbsTaggedHeapNumber* deferred = |
| 3781 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); | 3988 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
| 3782 Register input = ToRegister(instr->value()); | 3989 Register input = ToRegister(instr->value()); |
| 3783 // Smi check. | 3990 // Smi check. |
| 3784 __ JumpIfNotSmi(input, deferred->entry()); | 3991 __ JumpIfNotSmi(input, deferred->entry()); |
| 3785 // If smi, handle it directly. | 3992 // If smi, handle it directly. |
| 3786 EmitIntegerMathAbs(instr); | 3993 EmitMathAbs(instr); |
| 3787 __ bind(deferred->exit()); | 3994 __ bind(deferred->exit()); |
| 3788 } | 3995 } |
| 3789 } | 3996 } |
| 3790 | 3997 |
| 3791 | 3998 |
| 3792 void LCodeGen::DoMathFloor(LMathFloor* instr) { | 3999 void LCodeGen::DoMathFloor(LMathFloor* instr) { |
| 3793 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4000 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3794 Register result = ToRegister(instr->result()); | 4001 Register result = ToRegister(instr->result()); |
| 3795 Register input_high = scratch0(); | 4002 Register input_high = scratch0(); |
| 4003 Register scratch = ip; |
| 3796 Label done, exact; | 4004 Label done, exact; |
| 3797 | 4005 |
| 3798 __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact); | 4006 __ TryInt32Floor(result, input, input_high, scratch, double_scratch0(), |
| 4007 &done, &exact); |
| 3799 DeoptimizeIf(al, instr->environment()); | 4008 DeoptimizeIf(al, instr->environment()); |
| 3800 | 4009 |
| 3801 __ bind(&exact); | 4010 __ bind(&exact); |
| 3802 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 4011 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3803 // Test for -0. | 4012 // Test for -0. |
| 3804 __ cmp(result, Operand::Zero()); | 4013 __ cmpi(result, Operand::Zero()); |
| 3805 __ b(ne, &done); | 4014 __ bne(&done); |
| 3806 __ cmp(input_high, Operand::Zero()); | 4015 __ cmpwi(input_high, Operand::Zero()); |
| 3807 DeoptimizeIf(mi, instr->environment()); | 4016 DeoptimizeIf(lt, instr->environment()); |
| 3808 } | 4017 } |
| 3809 __ bind(&done); | 4018 __ bind(&done); |
| 3810 } | 4019 } |
| 3811 | 4020 |
| 3812 | 4021 |
| 3813 void LCodeGen::DoMathRound(LMathRound* instr) { | 4022 void LCodeGen::DoMathRound(LMathRound* instr) { |
| 3814 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4023 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3815 Register result = ToRegister(instr->result()); | 4024 Register result = ToRegister(instr->result()); |
| 3816 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp()); | 4025 DoubleRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
| 3817 DwVfpRegister input_plus_dot_five = double_scratch1; | 4026 DoubleRegister input_plus_dot_five = double_scratch1; |
| 3818 Register input_high = scratch0(); | 4027 Register input_high = scratch0(); |
| 3819 DwVfpRegister dot_five = double_scratch0(); | 4028 Register scratch = ip; |
| 4029 DoubleRegister dot_five = double_scratch0(); |
| 3820 Label convert, done; | 4030 Label convert, done; |
| 3821 | 4031 |
| 3822 __ Vmov(dot_five, 0.5, scratch0()); | 4032 __ LoadDoubleLiteral(dot_five, 0.5, r0); |
| 3823 __ vabs(double_scratch1, input); | 4033 __ fabs(double_scratch1, input); |
| 3824 __ VFPCompareAndSetFlags(double_scratch1, dot_five); | 4034 __ fcmpu(double_scratch1, dot_five); |
| 4035 DeoptimizeIf(unordered, instr->environment()); |
| 3825 // If input is in [-0.5, -0], the result is -0. | 4036 // If input is in [-0.5, -0], the result is -0. |
| 3826 // If input is in [+0, +0.5[, the result is +0. | 4037 // If input is in [+0, +0.5[, the result is +0. |
| 3827 // If the input is +0.5, the result is 1. | 4038 // If the input is +0.5, the result is 1. |
| 3828 __ b(hi, &convert); // Out of [-0.5, +0.5]. | 4039 __ bgt(&convert); // Out of [-0.5, +0.5]. |
| 3829 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 4040 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3830 __ VmovHigh(input_high, input); | 4041 __ stfdu(input, MemOperand(sp, -kDoubleSize)); |
| 3831 __ cmp(input_high, Operand::Zero()); | 4042 __ nop(); // LHS/RAW optimization |
| 3832 DeoptimizeIf(mi, instr->environment()); // [-0.5, -0]. | 4043 __ lwz(input_high, MemOperand(sp, Register::kExponentOffset)); |
| 4044 __ addi(sp, sp, Operand(kDoubleSize)); |
| 4045 __ cmpwi(input_high, Operand::Zero()); |
| 4046 DeoptimizeIf(lt, instr->environment()); // [-0.5, -0]. |
| 3833 } | 4047 } |
| 3834 __ VFPCompareAndSetFlags(input, dot_five); | 4048 Label return_zero; |
| 3835 __ mov(result, Operand(1), LeaveCC, eq); // +0.5. | 4049 __ fcmpu(input, dot_five); |
| 4050 __ bne(&return_zero); |
| 4051 __ li(result, Operand(1)); // +0.5. |
| 4052 __ b(&done); |
| 3836 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on | 4053 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
| 3837 // flag kBailoutOnMinusZero. | 4054 // flag kBailoutOnMinusZero. |
| 3838 __ mov(result, Operand::Zero(), LeaveCC, ne); | 4055 __ bind(&return_zero); |
| 4056 __ li(result, Operand::Zero()); |
| 3839 __ b(&done); | 4057 __ b(&done); |
| 3840 | 4058 |
| 3841 __ bind(&convert); | 4059 __ bind(&convert); |
| 3842 __ vadd(input_plus_dot_five, input, dot_five); | 4060 __ fadd(input_plus_dot_five, input, dot_five); |
| 3843 // Reuse dot_five (double_scratch0) as we no longer need this value. | 4061 // Reuse dot_five (double_scratch0) as we no longer need this value. |
| 3844 __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(), | 4062 __ TryInt32Floor(result, input_plus_dot_five, input_high, |
| 4063 scratch, double_scratch0(), |
| 3845 &done, &done); | 4064 &done, &done); |
| 3846 DeoptimizeIf(al, instr->environment()); | 4065 DeoptimizeIf(al, instr->environment()); |
| 3847 __ bind(&done); | 4066 __ bind(&done); |
| 3848 } | 4067 } |
| 3849 | 4068 |
| 3850 | 4069 |
| 3851 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { | 4070 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
| 3852 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4071 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3853 DwVfpRegister result = ToDoubleRegister(instr->result()); | 4072 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3854 __ vsqrt(result, input); | 4073 __ fsqrt(result, input); |
| 3855 } | 4074 } |
| 3856 | 4075 |
| 3857 | 4076 |
| 3858 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { | 4077 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
| 3859 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4078 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3860 DwVfpRegister result = ToDoubleRegister(instr->result()); | 4079 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3861 DwVfpRegister temp = double_scratch0(); | 4080 DoubleRegister temp = double_scratch0(); |
| 3862 | 4081 |
| 3863 // Note that according to ECMA-262 15.8.2.13: | 4082 // Note that according to ECMA-262 15.8.2.13: |
| 3864 // Math.pow(-Infinity, 0.5) == Infinity | 4083 // Math.pow(-Infinity, 0.5) == Infinity |
| 3865 // Math.sqrt(-Infinity) == NaN | 4084 // Math.sqrt(-Infinity) == NaN |
| 3866 Label done; | 4085 Label skip, done; |
| 3867 __ vmov(temp, -V8_INFINITY, scratch0()); | 4086 |
| 3868 __ VFPCompareAndSetFlags(input, temp); | 4087 __ LoadDoubleLiteral(temp, -V8_INFINITY, scratch0()); |
| 3869 __ vneg(result, temp, eq); | 4088 __ fcmpu(input, temp); |
| 3870 __ b(&done, eq); | 4089 __ bne(&skip); |
| 4090 __ fneg(result, temp); |
| 4091 __ b(&done); |
| 3871 | 4092 |
| 3872 // Add +0 to convert -0 to +0. | 4093 // Add +0 to convert -0 to +0. |
| 3873 __ vadd(result, input, kDoubleRegZero); | 4094 __ bind(&skip); |
| 3874 __ vsqrt(result, result); | 4095 __ fadd(result, input, kDoubleRegZero); |
| 4096 __ fsqrt(result, result); |
| 3875 __ bind(&done); | 4097 __ bind(&done); |
| 3876 } | 4098 } |
| 3877 | 4099 |
| 3878 | 4100 |
| 3879 void LCodeGen::DoPower(LPower* instr) { | 4101 void LCodeGen::DoPower(LPower* instr) { |
| 3880 Representation exponent_type = instr->hydrogen()->right()->representation(); | 4102 Representation exponent_type = instr->hydrogen()->right()->representation(); |
| 3881 // Having marked this as a call, we can use any registers. | 4103 // Having marked this as a call, we can use any registers. |
| 3882 // Just make sure that the input/output registers are the expected ones. | 4104 // Just make sure that the input/output registers are the expected ones. |
| 3883 ASSERT(!instr->right()->IsDoubleRegister() || | 4105 ASSERT(!instr->right()->IsDoubleRegister() || |
| 3884 ToDoubleRegister(instr->right()).is(d1)); | 4106 ToDoubleRegister(instr->right()).is(d2)); |
| 3885 ASSERT(!instr->right()->IsRegister() || | 4107 ASSERT(!instr->right()->IsRegister() || |
| 3886 ToRegister(instr->right()).is(r2)); | 4108 ToRegister(instr->right()).is(r5)); |
| 3887 ASSERT(ToDoubleRegister(instr->left()).is(d0)); | 4109 ASSERT(ToDoubleRegister(instr->left()).is(d1)); |
| 3888 ASSERT(ToDoubleRegister(instr->result()).is(d2)); | 4110 ASSERT(ToDoubleRegister(instr->result()).is(d3)); |
| 3889 | 4111 |
| 3890 if (exponent_type.IsSmi()) { | 4112 if (exponent_type.IsSmi()) { |
| 3891 MathPowStub stub(isolate(), MathPowStub::TAGGED); | 4113 MathPowStub stub(isolate(), MathPowStub::TAGGED); |
| 3892 __ CallStub(&stub); | 4114 __ CallStub(&stub); |
| 3893 } else if (exponent_type.IsTagged()) { | 4115 } else if (exponent_type.IsTagged()) { |
| 3894 Label no_deopt; | 4116 Label no_deopt; |
| 3895 __ JumpIfSmi(r2, &no_deopt); | 4117 __ JumpIfSmi(r5, &no_deopt); |
| 3896 __ ldr(r6, FieldMemOperand(r2, HeapObject::kMapOffset)); | 4118 __ LoadP(r10, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 3897 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 4119 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3898 __ cmp(r6, Operand(ip)); | 4120 __ cmp(r10, ip); |
| 3899 DeoptimizeIf(ne, instr->environment()); | 4121 DeoptimizeIf(ne, instr->environment()); |
| 3900 __ bind(&no_deopt); | 4122 __ bind(&no_deopt); |
| 3901 MathPowStub stub(isolate(), MathPowStub::TAGGED); | 4123 MathPowStub stub(isolate(), MathPowStub::TAGGED); |
| 3902 __ CallStub(&stub); | 4124 __ CallStub(&stub); |
| 3903 } else if (exponent_type.IsInteger32()) { | 4125 } else if (exponent_type.IsInteger32()) { |
| 3904 MathPowStub stub(isolate(), MathPowStub::INTEGER); | 4126 MathPowStub stub(isolate(), MathPowStub::INTEGER); |
| 3905 __ CallStub(&stub); | 4127 __ CallStub(&stub); |
| 3906 } else { | 4128 } else { |
| 3907 ASSERT(exponent_type.IsDouble()); | 4129 ASSERT(exponent_type.IsDouble()); |
| 3908 MathPowStub stub(isolate(), MathPowStub::DOUBLE); | 4130 MathPowStub stub(isolate(), MathPowStub::DOUBLE); |
| 3909 __ CallStub(&stub); | 4131 __ CallStub(&stub); |
| 3910 } | 4132 } |
| 3911 } | 4133 } |
| 3912 | 4134 |
| 3913 | 4135 |
| 3914 void LCodeGen::DoMathExp(LMathExp* instr) { | 4136 void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3915 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4137 DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3916 DwVfpRegister result = ToDoubleRegister(instr->result()); | 4138 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3917 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); | 4139 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3918 DwVfpRegister double_scratch2 = double_scratch0(); | 4140 DoubleRegister double_scratch2 = double_scratch0(); |
| 3919 Register temp1 = ToRegister(instr->temp1()); | 4141 Register temp1 = ToRegister(instr->temp1()); |
| 3920 Register temp2 = ToRegister(instr->temp2()); | 4142 Register temp2 = ToRegister(instr->temp2()); |
| 3921 | 4143 |
| 3922 MathExpGenerator::EmitMathExp( | 4144 MathExpGenerator::EmitMathExp( |
| 3923 masm(), input, result, double_scratch1, double_scratch2, | 4145 masm(), input, result, double_scratch1, double_scratch2, |
| 3924 temp1, temp2, scratch0()); | 4146 temp1, temp2, scratch0()); |
| 3925 } | 4147 } |
| 3926 | 4148 |
| 3927 | 4149 |
| 3928 void LCodeGen::DoMathLog(LMathLog* instr) { | 4150 void LCodeGen::DoMathLog(LMathLog* instr) { |
| 3929 __ PrepareCallCFunction(0, 1, scratch0()); | 4151 __ PrepareCallCFunction(0, 1, scratch0()); |
| 3930 __ MovToFloatParameter(ToDoubleRegister(instr->value())); | 4152 __ MovToFloatParameter(ToDoubleRegister(instr->value())); |
| 3931 __ CallCFunction(ExternalReference::math_log_double_function(isolate()), | 4153 __ CallCFunction(ExternalReference::math_log_double_function(isolate()), |
| 3932 0, 1); | 4154 0, 1); |
| 3933 __ MovFromFloatResult(ToDoubleRegister(instr->result())); | 4155 __ MovFromFloatResult(ToDoubleRegister(instr->result())); |
| 3934 } | 4156 } |
| 3935 | 4157 |
| 3936 | 4158 |
| 3937 void LCodeGen::DoMathClz32(LMathClz32* instr) { | 4159 void LCodeGen::DoMathClz32(LMathClz32* instr) { |
| 3938 Register input = ToRegister(instr->value()); | 4160 Register input = ToRegister(instr->value()); |
| 3939 Register result = ToRegister(instr->result()); | 4161 Register result = ToRegister(instr->result()); |
| 3940 __ clz(result, input); | 4162 __ cntlzw_(result, input); |
| 3941 } | 4163 } |
| 3942 | 4164 |
| 3943 | 4165 |
| 3944 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { | 4166 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 3945 ASSERT(ToRegister(instr->context()).is(cp)); | 4167 ASSERT(ToRegister(instr->context()).is(cp)); |
| 3946 ASSERT(ToRegister(instr->function()).is(r1)); | 4168 ASSERT(ToRegister(instr->function()).is(r4)); |
| 3947 ASSERT(instr->HasPointerMap()); | 4169 ASSERT(instr->HasPointerMap()); |
| 3948 | 4170 |
| 3949 Handle<JSFunction> known_function = instr->hydrogen()->known_function(); | 4171 Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 3950 if (known_function.is_null()) { | 4172 if (known_function.is_null()) { |
| 3951 LPointerMap* pointers = instr->pointer_map(); | 4173 LPointerMap* pointers = instr->pointer_map(); |
| 3952 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 4174 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3953 ParameterCount count(instr->arity()); | 4175 ParameterCount count(instr->arity()); |
| 3954 __ InvokeFunction(r1, count, CALL_FUNCTION, generator); | 4176 __ InvokeFunction(r4, count, CALL_FUNCTION, generator); |
| 3955 } else { | 4177 } else { |
| 3956 CallKnownFunction(known_function, | 4178 CallKnownFunction(known_function, |
| 3957 instr->hydrogen()->formal_parameter_count(), | 4179 instr->hydrogen()->formal_parameter_count(), |
| 3958 instr->arity(), | 4180 instr->arity(), |
| 3959 instr, | 4181 instr, |
| 3960 R1_CONTAINS_TARGET); | 4182 R4_CONTAINS_TARGET); |
| 3961 } | 4183 } |
| 3962 } | 4184 } |
| 3963 | 4185 |
| 3964 | 4186 |
| 3965 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { | 4187 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { |
| 3966 ASSERT(ToRegister(instr->result()).is(r0)); | 4188 ASSERT(ToRegister(instr->result()).is(r3)); |
| 3967 | 4189 |
| 3968 LPointerMap* pointers = instr->pointer_map(); | 4190 LPointerMap* pointers = instr->pointer_map(); |
| 3969 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 4191 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3970 | 4192 |
| 3971 if (instr->target()->IsConstantOperand()) { | 4193 if (instr->target()->IsConstantOperand()) { |
| 3972 LConstantOperand* target = LConstantOperand::cast(instr->target()); | 4194 LConstantOperand* target = LConstantOperand::cast(instr->target()); |
| 3973 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); | 4195 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
| 3974 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); | 4196 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); |
| 3975 PlatformInterfaceDescriptor* call_descriptor = | 4197 __ Call(code, RelocInfo::CODE_TARGET); |
| 3976 instr->descriptor()->platform_specific_descriptor(); | |
| 3977 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al, | |
| 3978 call_descriptor->storage_mode()); | |
| 3979 } else { | 4198 } else { |
| 3980 ASSERT(instr->target()->IsRegister()); | 4199 ASSERT(instr->target()->IsRegister()); |
| 3981 Register target = ToRegister(instr->target()); | 4200 Register target = ToRegister(instr->target()); |
| 3982 generator.BeforeCall(__ CallSize(target)); | 4201 generator.BeforeCall(__ CallSize(target)); |
| 3983 // Make sure we don't emit any additional entries in the constant pool | 4202 __ addi(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3984 // before the call to ensure that the CallCodeSize() calculated the correct | |
| 3985 // number of instructions for the constant pool load. | |
| 3986 { | |
| 3987 ConstantPoolUnavailableScope constant_pool_unavailable(masm_); | |
| 3988 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); | |
| 3989 } | |
| 3990 __ Call(target); | 4203 __ Call(target); |
| 3991 } | 4204 } |
| 3992 generator.AfterCall(); | 4205 generator.AfterCall(); |
| 3993 } | 4206 } |
| 3994 | 4207 |
| 3995 | 4208 |
| 3996 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { | 4209 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { |
| 3997 ASSERT(ToRegister(instr->function()).is(r1)); | 4210 ASSERT(ToRegister(instr->function()).is(r4)); |
| 3998 ASSERT(ToRegister(instr->result()).is(r0)); | 4211 ASSERT(ToRegister(instr->result()).is(r3)); |
| 3999 | 4212 |
| 4000 if (instr->hydrogen()->pass_argument_count()) { | 4213 if (instr->hydrogen()->pass_argument_count()) { |
| 4001 __ mov(r0, Operand(instr->arity())); | 4214 __ mov(r3, Operand(instr->arity())); |
| 4002 } | 4215 } |
| 4003 | 4216 |
| 4004 // Change context. | 4217 // Change context. |
| 4005 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 4218 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
| 4006 | 4219 |
| 4007 // Load the code entry address | 4220 // Load the code entry address |
| 4008 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); | 4221 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 4009 __ Call(ip); | 4222 __ Call(ip); |
| 4010 | 4223 |
| 4011 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 4224 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 4012 } | 4225 } |
| 4013 | 4226 |
| 4014 | 4227 |
| 4015 void LCodeGen::DoCallFunction(LCallFunction* instr) { | 4228 void LCodeGen::DoCallFunction(LCallFunction* instr) { |
| 4016 ASSERT(ToRegister(instr->context()).is(cp)); | 4229 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4017 ASSERT(ToRegister(instr->function()).is(r1)); | 4230 ASSERT(ToRegister(instr->function()).is(r4)); |
| 4018 ASSERT(ToRegister(instr->result()).is(r0)); | 4231 ASSERT(ToRegister(instr->result()).is(r3)); |
| 4019 | 4232 |
| 4020 int arity = instr->arity(); | 4233 int arity = instr->arity(); |
| 4021 CallFunctionStub stub(isolate(), arity, instr->hydrogen()->function_flags()); | 4234 CallFunctionStub stub(isolate(), arity, instr->hydrogen()->function_flags()); |
| 4022 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4235 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4023 } | 4236 } |
| 4024 | 4237 |
| 4025 | 4238 |
| 4026 void LCodeGen::DoCallNew(LCallNew* instr) { | 4239 void LCodeGen::DoCallNew(LCallNew* instr) { |
| 4027 ASSERT(ToRegister(instr->context()).is(cp)); | 4240 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4028 ASSERT(ToRegister(instr->constructor()).is(r1)); | 4241 ASSERT(ToRegister(instr->constructor()).is(r4)); |
| 4029 ASSERT(ToRegister(instr->result()).is(r0)); | 4242 ASSERT(ToRegister(instr->result()).is(r3)); |
| 4030 | 4243 |
| 4031 __ mov(r0, Operand(instr->arity())); | 4244 __ mov(r3, Operand(instr->arity())); |
| 4032 // No cell in r2 for construct type feedback in optimized code | 4245 // No cell in r5 for construct type feedback in optimized code |
| 4033 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); | 4246 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
| 4034 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); | 4247 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); |
| 4035 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4248 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
| 4036 } | 4249 } |
| 4037 | 4250 |
| 4038 | 4251 |
| 4039 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { | 4252 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 4040 ASSERT(ToRegister(instr->context()).is(cp)); | 4253 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4041 ASSERT(ToRegister(instr->constructor()).is(r1)); | 4254 ASSERT(ToRegister(instr->constructor()).is(r4)); |
| 4042 ASSERT(ToRegister(instr->result()).is(r0)); | 4255 ASSERT(ToRegister(instr->result()).is(r3)); |
| 4043 | 4256 |
| 4044 __ mov(r0, Operand(instr->arity())); | 4257 __ mov(r3, Operand(instr->arity())); |
| 4045 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); | 4258 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
| 4046 ElementsKind kind = instr->hydrogen()->elements_kind(); | 4259 ElementsKind kind = instr->hydrogen()->elements_kind(); |
| 4047 AllocationSiteOverrideMode override_mode = | 4260 AllocationSiteOverrideMode override_mode = |
| 4048 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) | 4261 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
| 4049 ? DISABLE_ALLOCATION_SITES | 4262 ? DISABLE_ALLOCATION_SITES |
| 4050 : DONT_OVERRIDE; | 4263 : DONT_OVERRIDE; |
| 4051 | 4264 |
| 4052 if (instr->arity() == 0) { | 4265 if (instr->arity() == 0) { |
| 4053 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); | 4266 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); |
| 4054 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4267 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
| 4055 } else if (instr->arity() == 1) { | 4268 } else if (instr->arity() == 1) { |
| 4056 Label done; | 4269 Label done; |
| 4057 if (IsFastPackedElementsKind(kind)) { | 4270 if (IsFastPackedElementsKind(kind)) { |
| 4058 Label packed_case; | 4271 Label packed_case; |
| 4059 // We might need a change here | 4272 // We might need a change here |
| 4060 // look at the first argument | 4273 // look at the first argument |
| 4061 __ ldr(r5, MemOperand(sp, 0)); | 4274 __ LoadP(r8, MemOperand(sp, 0)); |
| 4062 __ cmp(r5, Operand::Zero()); | 4275 __ cmpi(r8, Operand::Zero()); |
| 4063 __ b(eq, &packed_case); | 4276 __ beq(&packed_case); |
| 4064 | 4277 |
| 4065 ElementsKind holey_kind = GetHoleyElementsKind(kind); | 4278 ElementsKind holey_kind = GetHoleyElementsKind(kind); |
| 4066 ArraySingleArgumentConstructorStub stub(isolate(), | 4279 ArraySingleArgumentConstructorStub stub(isolate(), |
| 4067 holey_kind, | 4280 holey_kind, |
| 4068 override_mode); | 4281 override_mode); |
| 4069 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4282 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
| 4070 __ jmp(&done); | 4283 __ b(&done); |
| 4071 __ bind(&packed_case); | 4284 __ bind(&packed_case); |
| 4072 } | 4285 } |
| 4073 | 4286 |
| 4074 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); | 4287 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); |
| 4075 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4288 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
| 4076 __ bind(&done); | 4289 __ bind(&done); |
| 4077 } else { | 4290 } else { |
| 4078 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); | 4291 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); |
| 4079 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4292 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
| 4080 } | 4293 } |
| 4081 } | 4294 } |
| 4082 | 4295 |
| 4083 | 4296 |
| 4084 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { | 4297 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 4085 CallRuntime(instr->function(), instr->arity(), instr); | 4298 CallRuntime(instr->function(), instr->arity(), instr); |
| 4086 } | 4299 } |
| 4087 | 4300 |
| 4088 | 4301 |
| 4089 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { | 4302 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 4090 Register function = ToRegister(instr->function()); | 4303 Register function = ToRegister(instr->function()); |
| 4091 Register code_object = ToRegister(instr->code_object()); | 4304 Register code_object = ToRegister(instr->code_object()); |
| 4092 __ add(code_object, code_object, Operand(Code::kHeaderSize - kHeapObjectTag)); | 4305 __ addi(code_object, code_object, |
| 4093 __ str(code_object, | 4306 Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4094 FieldMemOperand(function, JSFunction::kCodeEntryOffset)); | 4307 __ StoreP(code_object, |
| 4308 FieldMemOperand(function, JSFunction::kCodeEntryOffset), r0); |
| 4095 } | 4309 } |
| 4096 | 4310 |
| 4097 | 4311 |
| 4098 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { | 4312 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4099 Register result = ToRegister(instr->result()); | 4313 Register result = ToRegister(instr->result()); |
| 4100 Register base = ToRegister(instr->base_object()); | 4314 Register base = ToRegister(instr->base_object()); |
| 4101 if (instr->offset()->IsConstantOperand()) { | 4315 if (instr->offset()->IsConstantOperand()) { |
| 4102 LConstantOperand* offset = LConstantOperand::cast(instr->offset()); | 4316 LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
| 4103 __ add(result, base, Operand(ToInteger32(offset))); | 4317 __ Add(result, base, ToInteger32(offset), r0); |
| 4104 } else { | 4318 } else { |
| 4105 Register offset = ToRegister(instr->offset()); | 4319 Register offset = ToRegister(instr->offset()); |
| 4106 __ add(result, base, offset); | 4320 __ add(result, base, offset); |
| 4107 } | 4321 } |
| 4108 } | 4322 } |
| 4109 | 4323 |
| 4110 | 4324 |
| 4111 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { | 4325 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
| 4326 HStoreNamedField* hinstr = instr->hydrogen(); |
| 4112 Representation representation = instr->representation(); | 4327 Representation representation = instr->representation(); |
| 4113 | 4328 |
| 4114 Register object = ToRegister(instr->object()); | 4329 Register object = ToRegister(instr->object()); |
| 4115 Register scratch = scratch0(); | 4330 Register scratch = scratch0(); |
| 4116 HObjectAccess access = instr->hydrogen()->access(); | 4331 HObjectAccess access = hinstr->access(); |
| 4117 int offset = access.offset(); | 4332 int offset = access.offset(); |
| 4118 | 4333 |
| 4119 if (access.IsExternalMemory()) { | 4334 if (access.IsExternalMemory()) { |
| 4120 Register value = ToRegister(instr->value()); | 4335 Register value = ToRegister(instr->value()); |
| 4121 MemOperand operand = MemOperand(object, offset); | 4336 MemOperand operand = MemOperand(object, offset); |
| 4122 __ Store(value, operand, representation); | 4337 __ StoreRepresentation(value, operand, representation, r0); |
| 4123 return; | 4338 return; |
| 4124 } | 4339 } |
| 4125 | 4340 |
| 4126 __ AssertNotSmi(object); | 4341 __ AssertNotSmi(object); |
| 4127 | 4342 |
| 4343 #if V8_TARGET_ARCH_PPC64 |
| 4344 ASSERT(!representation.IsSmi() || |
| 4345 !instr->value()->IsConstantOperand() || |
| 4346 IsInteger32(LConstantOperand::cast(instr->value()))); |
| 4347 #else |
| 4128 ASSERT(!representation.IsSmi() || | 4348 ASSERT(!representation.IsSmi() || |
| 4129 !instr->value()->IsConstantOperand() || | 4349 !instr->value()->IsConstantOperand() || |
| 4130 IsSmi(LConstantOperand::cast(instr->value()))); | 4350 IsSmi(LConstantOperand::cast(instr->value()))); |
| 4351 #endif |
| 4131 if (representation.IsDouble()) { | 4352 if (representation.IsDouble()) { |
| 4132 ASSERT(access.IsInobject()); | 4353 ASSERT(access.IsInobject()); |
| 4133 ASSERT(!instr->hydrogen()->has_transition()); | 4354 ASSERT(!hinstr->has_transition()); |
| 4134 ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); | 4355 ASSERT(!hinstr->NeedsWriteBarrier()); |
| 4135 DwVfpRegister value = ToDoubleRegister(instr->value()); | 4356 DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4136 __ vstr(value, FieldMemOperand(object, offset)); | 4357 __ stfd(value, FieldMemOperand(object, offset)); |
| 4137 return; | 4358 return; |
| 4138 } | 4359 } |
| 4139 | 4360 |
| 4140 if (instr->hydrogen()->has_transition()) { | 4361 if (hinstr->has_transition()) { |
| 4141 Handle<Map> transition = instr->hydrogen()->transition_map(); | 4362 Handle<Map> transition = hinstr->transition_map(); |
| 4142 AddDeprecationDependency(transition); | 4363 AddDeprecationDependency(transition); |
| 4143 __ mov(scratch, Operand(transition)); | 4364 __ mov(scratch, Operand(transition)); |
| 4144 __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); | 4365 __ StoreP(scratch, FieldMemOperand(object, HeapObject::kMapOffset), r0); |
| 4145 if (instr->hydrogen()->NeedsWriteBarrierForMap()) { | 4366 if (hinstr->NeedsWriteBarrierForMap()) { |
| 4146 Register temp = ToRegister(instr->temp()); | 4367 Register temp = ToRegister(instr->temp()); |
| 4147 // Update the write barrier for the map field. | 4368 // Update the write barrier for the map field. |
| 4148 __ RecordWriteForMap(object, | 4369 __ RecordWriteForMap(object, |
| 4149 scratch, | 4370 scratch, |
| 4150 temp, | 4371 temp, |
| 4151 GetLinkRegisterState(), | 4372 GetLinkRegisterState(), |
| 4152 kSaveFPRegs); | 4373 kSaveFPRegs); |
| 4153 } | 4374 } |
| 4154 } | 4375 } |
| 4155 | 4376 |
| 4156 // Do the store. | 4377 // Do the store. |
| 4157 Register value = ToRegister(instr->value()); | 4378 Register value = ToRegister(instr->value()); |
| 4379 |
| 4380 #if V8_TARGET_ARCH_PPC64 |
| 4381 // 64-bit Smi optimization |
| 4382 if (representation.IsSmi() && |
| 4383 hinstr->value()->representation().IsInteger32()) { |
| 4384 ASSERT(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4385 // Store int value directly to upper half of the smi. |
| 4386 STATIC_ASSERT(kSmiTag == 0); |
| 4387 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 4388 #if V8_TARGET_LITTLE_ENDIAN |
| 4389 offset += kPointerSize / 2; |
| 4390 #endif |
| 4391 representation = Representation::Integer32(); |
| 4392 } |
| 4393 #endif |
| 4394 |
| 4158 if (access.IsInobject()) { | 4395 if (access.IsInobject()) { |
| 4159 MemOperand operand = FieldMemOperand(object, offset); | 4396 MemOperand operand = FieldMemOperand(object, offset); |
| 4160 __ Store(value, operand, representation); | 4397 __ StoreRepresentation(value, operand, representation, r0); |
| 4161 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4398 if (hinstr->NeedsWriteBarrier()) { |
| 4162 // Update the write barrier for the object for in-object properties. | 4399 // Update the write barrier for the object for in-object properties. |
| 4163 __ RecordWriteField(object, | 4400 __ RecordWriteField(object, |
| 4164 offset, | 4401 offset, |
| 4165 value, | 4402 value, |
| 4166 scratch, | 4403 scratch, |
| 4167 GetLinkRegisterState(), | 4404 GetLinkRegisterState(), |
| 4168 kSaveFPRegs, | 4405 kSaveFPRegs, |
| 4169 EMIT_REMEMBERED_SET, | 4406 EMIT_REMEMBERED_SET, |
| 4170 instr->hydrogen()->SmiCheckForWriteBarrier(), | 4407 hinstr->SmiCheckForWriteBarrier(), |
| 4171 instr->hydrogen()->PointersToHereCheckForValue()); | 4408 hinstr->PointersToHereCheckForValue()); |
| 4172 } | 4409 } |
| 4173 } else { | 4410 } else { |
| 4174 __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 4411 __ LoadP(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 4175 MemOperand operand = FieldMemOperand(scratch, offset); | 4412 MemOperand operand = FieldMemOperand(scratch, offset); |
| 4176 __ Store(value, operand, representation); | 4413 __ StoreRepresentation(value, operand, representation, r0); |
| 4177 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4414 if (hinstr->NeedsWriteBarrier()) { |
| 4178 // Update the write barrier for the properties array. | 4415 // Update the write barrier for the properties array. |
| 4179 // object is used as a scratch register. | 4416 // object is used as a scratch register. |
| 4180 __ RecordWriteField(scratch, | 4417 __ RecordWriteField(scratch, |
| 4181 offset, | 4418 offset, |
| 4182 value, | 4419 value, |
| 4183 object, | 4420 object, |
| 4184 GetLinkRegisterState(), | 4421 GetLinkRegisterState(), |
| 4185 kSaveFPRegs, | 4422 kSaveFPRegs, |
| 4186 EMIT_REMEMBERED_SET, | 4423 EMIT_REMEMBERED_SET, |
| 4187 instr->hydrogen()->SmiCheckForWriteBarrier(), | 4424 hinstr->SmiCheckForWriteBarrier(), |
| 4188 instr->hydrogen()->PointersToHereCheckForValue()); | 4425 hinstr->PointersToHereCheckForValue()); |
| 4189 } | 4426 } |
| 4190 } | 4427 } |
| 4191 } | 4428 } |
| 4192 | 4429 |
| 4193 | 4430 |
| 4194 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { | 4431 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 4195 ASSERT(ToRegister(instr->context()).is(cp)); | 4432 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4196 ASSERT(ToRegister(instr->object()).is(StoreIC::ReceiverRegister())); | 4433 ASSERT(ToRegister(instr->object()).is(StoreIC::ReceiverRegister())); |
| 4197 ASSERT(ToRegister(instr->value()).is(StoreIC::ValueRegister())); | 4434 ASSERT(ToRegister(instr->value()).is(StoreIC::ValueRegister())); |
| 4198 | 4435 |
| 4199 __ mov(StoreIC::NameRegister(), Operand(instr->name())); | 4436 __ mov(StoreIC::NameRegister(), Operand(instr->name())); |
| 4200 Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); | 4437 Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); |
| 4201 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 4438 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4202 } | 4439 } |
| 4203 | 4440 |
| 4204 | 4441 |
| 4205 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { | 4442 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
| 4206 Condition cc = instr->hydrogen()->allow_equality() ? hi : hs; | 4443 Representation representation = instr->hydrogen()->length()->representation(); |
| 4207 if (instr->index()->IsConstantOperand()) { | 4444 ASSERT(representation.Equals(instr->hydrogen()->index()->representation())); |
| 4208 Operand index = ToOperand(instr->index()); | 4445 ASSERT(representation.IsSmiOrInteger32()); |
| 4446 |
| 4447 Condition cc = instr->hydrogen()->allow_equality() ? lt : le; |
| 4448 if (instr->length()->IsConstantOperand()) { |
| 4449 int32_t length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 4450 Register index = ToRegister(instr->index()); |
| 4451 if (representation.IsSmi()) { |
| 4452 __ Cmpli(index, Operand(Smi::FromInt(length)), r0); |
| 4453 } else { |
| 4454 __ Cmplwi(index, Operand(length), r0); |
| 4455 } |
| 4456 cc = CommuteCondition(cc); |
| 4457 } else if (instr->index()->IsConstantOperand()) { |
| 4458 int32_t index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4209 Register length = ToRegister(instr->length()); | 4459 Register length = ToRegister(instr->length()); |
| 4210 __ cmp(length, index); | 4460 if (representation.IsSmi()) { |
| 4211 cc = CommuteCondition(cc); | 4461 __ Cmpli(length, Operand(Smi::FromInt(index)), r0); |
| 4462 } else { |
| 4463 __ Cmplwi(length, Operand(index), r0); |
| 4464 } |
| 4212 } else { | 4465 } else { |
| 4213 Register index = ToRegister(instr->index()); | 4466 Register index = ToRegister(instr->index()); |
| 4214 Operand length = ToOperand(instr->length()); | 4467 Register length = ToRegister(instr->length()); |
| 4215 __ cmp(index, length); | 4468 if (representation.IsSmi()) { |
| 4469 __ cmpl(length, index); |
| 4470 } else { |
| 4471 __ cmplw(length, index); |
| 4472 } |
| 4216 } | 4473 } |
| 4217 if (FLAG_debug_code && instr->hydrogen()->skip_check()) { | 4474 if (FLAG_debug_code && instr->hydrogen()->skip_check()) { |
| 4218 Label done; | 4475 Label done; |
| 4219 __ b(NegateCondition(cc), &done); | 4476 __ b(NegateCondition(cc), &done); |
| 4220 __ stop("eliminated bounds check failed"); | 4477 __ stop("eliminated bounds check failed"); |
| 4221 __ bind(&done); | 4478 __ bind(&done); |
| 4222 } else { | 4479 } else { |
| 4223 DeoptimizeIf(cc, instr->environment()); | 4480 DeoptimizeIf(cc, instr->environment()); |
| 4224 } | 4481 } |
| 4225 } | 4482 } |
| 4226 | 4483 |
| 4227 | 4484 |
| 4228 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { | 4485 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4229 Register external_pointer = ToRegister(instr->elements()); | 4486 Register external_pointer = ToRegister(instr->elements()); |
| 4230 Register key = no_reg; | 4487 Register key = no_reg; |
| 4231 ElementsKind elements_kind = instr->elements_kind(); | 4488 ElementsKind elements_kind = instr->elements_kind(); |
| 4232 bool key_is_constant = instr->key()->IsConstantOperand(); | 4489 bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4233 int constant_key = 0; | 4490 int constant_key = 0; |
| 4234 if (key_is_constant) { | 4491 if (key_is_constant) { |
| 4235 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 4492 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4236 if (constant_key & 0xF0000000) { | 4493 if (constant_key & 0xF0000000) { |
| 4237 Abort(kArrayIndexConstantValueTooBig); | 4494 Abort(kArrayIndexConstantValueTooBig); |
| 4238 } | 4495 } |
| 4239 } else { | 4496 } else { |
| 4240 key = ToRegister(instr->key()); | 4497 key = ToRegister(instr->key()); |
| 4241 } | 4498 } |
| 4242 int element_size_shift = ElementsKindToShiftSize(elements_kind); | 4499 int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 4243 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 4500 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 4244 ? (element_size_shift - kSmiTagSize) : element_size_shift; | |
| 4245 int base_offset = instr->base_offset(); | 4501 int base_offset = instr->base_offset(); |
| 4246 | 4502 |
| 4247 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 4503 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
| 4248 elements_kind == FLOAT32_ELEMENTS || | 4504 elements_kind == FLOAT32_ELEMENTS || |
| 4249 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || | 4505 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
| 4250 elements_kind == FLOAT64_ELEMENTS) { | 4506 elements_kind == FLOAT64_ELEMENTS) { |
| 4251 Register address = scratch0(); | 4507 Register address = scratch0(); |
| 4252 DwVfpRegister value(ToDoubleRegister(instr->value())); | 4508 DoubleRegister value(ToDoubleRegister(instr->value())); |
| 4253 if (key_is_constant) { | 4509 if (key_is_constant) { |
| 4254 if (constant_key != 0) { | 4510 if (constant_key != 0) { |
| 4255 __ add(address, external_pointer, | 4511 __ Add(address, external_pointer, |
| 4256 Operand(constant_key << element_size_shift)); | 4512 constant_key << element_size_shift, |
| 4513 r0); |
| 4257 } else { | 4514 } else { |
| 4258 address = external_pointer; | 4515 address = external_pointer; |
| 4259 } | 4516 } |
| 4260 } else { | 4517 } else { |
| 4261 __ add(address, external_pointer, Operand(key, LSL, shift_size)); | 4518 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 4519 __ add(address, external_pointer, r0); |
| 4262 } | 4520 } |
| 4263 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 4521 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
| 4264 elements_kind == FLOAT32_ELEMENTS) { | 4522 elements_kind == FLOAT32_ELEMENTS) { |
| 4265 __ vcvt_f32_f64(double_scratch0().low(), value); | 4523 __ frsp(double_scratch0(), value); |
| 4266 __ vstr(double_scratch0().low(), address, base_offset); | 4524 __ stfs(double_scratch0(), MemOperand(address, base_offset)); |
| 4267 } else { // Storing doubles, not floats. | 4525 } else { // Storing doubles, not floats. |
| 4268 __ vstr(value, address, base_offset); | 4526 __ stfd(value, MemOperand(address, base_offset)); |
| 4269 } | 4527 } |
| 4270 } else { | 4528 } else { |
| 4271 Register value(ToRegister(instr->value())); | 4529 Register value(ToRegister(instr->value())); |
| 4272 MemOperand mem_operand = PrepareKeyedOperand( | 4530 MemOperand mem_operand = PrepareKeyedOperand( |
| 4273 key, external_pointer, key_is_constant, constant_key, | 4531 key, external_pointer, key_is_constant, key_is_smi, constant_key, |
| 4274 element_size_shift, shift_size, | 4532 element_size_shift, base_offset); |
| 4275 base_offset); | |
| 4276 switch (elements_kind) { | 4533 switch (elements_kind) { |
| 4277 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: | 4534 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
| 4278 case EXTERNAL_INT8_ELEMENTS: | 4535 case EXTERNAL_INT8_ELEMENTS: |
| 4279 case EXTERNAL_UINT8_ELEMENTS: | 4536 case EXTERNAL_UINT8_ELEMENTS: |
| 4280 case UINT8_ELEMENTS: | 4537 case UINT8_ELEMENTS: |
| 4281 case UINT8_CLAMPED_ELEMENTS: | 4538 case UINT8_CLAMPED_ELEMENTS: |
| 4282 case INT8_ELEMENTS: | 4539 case INT8_ELEMENTS: |
| 4283 __ strb(value, mem_operand); | 4540 if (key_is_constant) { |
| 4541 __ StoreByte(value, mem_operand, r0); |
| 4542 } else { |
| 4543 __ stbx(value, mem_operand); |
| 4544 } |
| 4284 break; | 4545 break; |
| 4285 case EXTERNAL_INT16_ELEMENTS: | 4546 case EXTERNAL_INT16_ELEMENTS: |
| 4286 case EXTERNAL_UINT16_ELEMENTS: | 4547 case EXTERNAL_UINT16_ELEMENTS: |
| 4287 case INT16_ELEMENTS: | 4548 case INT16_ELEMENTS: |
| 4288 case UINT16_ELEMENTS: | 4549 case UINT16_ELEMENTS: |
| 4289 __ strh(value, mem_operand); | 4550 if (key_is_constant) { |
| 4551 __ StoreHalfWord(value, mem_operand, r0); |
| 4552 } else { |
| 4553 __ sthx(value, mem_operand); |
| 4554 } |
| 4290 break; | 4555 break; |
| 4291 case EXTERNAL_INT32_ELEMENTS: | 4556 case EXTERNAL_INT32_ELEMENTS: |
| 4292 case EXTERNAL_UINT32_ELEMENTS: | 4557 case EXTERNAL_UINT32_ELEMENTS: |
| 4293 case INT32_ELEMENTS: | 4558 case INT32_ELEMENTS: |
| 4294 case UINT32_ELEMENTS: | 4559 case UINT32_ELEMENTS: |
| 4295 __ str(value, mem_operand); | 4560 if (key_is_constant) { |
| 4561 __ StoreWord(value, mem_operand, r0); |
| 4562 } else { |
| 4563 __ stwx(value, mem_operand); |
| 4564 } |
| 4296 break; | 4565 break; |
| 4297 case FLOAT32_ELEMENTS: | 4566 case FLOAT32_ELEMENTS: |
| 4298 case FLOAT64_ELEMENTS: | 4567 case FLOAT64_ELEMENTS: |
| 4299 case EXTERNAL_FLOAT32_ELEMENTS: | 4568 case EXTERNAL_FLOAT32_ELEMENTS: |
| 4300 case EXTERNAL_FLOAT64_ELEMENTS: | 4569 case EXTERNAL_FLOAT64_ELEMENTS: |
| 4301 case FAST_DOUBLE_ELEMENTS: | 4570 case FAST_DOUBLE_ELEMENTS: |
| 4302 case FAST_ELEMENTS: | 4571 case FAST_ELEMENTS: |
| 4303 case FAST_SMI_ELEMENTS: | 4572 case FAST_SMI_ELEMENTS: |
| 4304 case FAST_HOLEY_DOUBLE_ELEMENTS: | 4573 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4305 case FAST_HOLEY_ELEMENTS: | 4574 case FAST_HOLEY_ELEMENTS: |
| 4306 case FAST_HOLEY_SMI_ELEMENTS: | 4575 case FAST_HOLEY_SMI_ELEMENTS: |
| 4307 case DICTIONARY_ELEMENTS: | 4576 case DICTIONARY_ELEMENTS: |
| 4308 case SLOPPY_ARGUMENTS_ELEMENTS: | 4577 case SLOPPY_ARGUMENTS_ELEMENTS: |
| 4309 UNREACHABLE(); | 4578 UNREACHABLE(); |
| 4310 break; | 4579 break; |
| 4311 } | 4580 } |
| 4312 } | 4581 } |
| 4313 } | 4582 } |
| 4314 | 4583 |
| 4315 | 4584 |
| 4316 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { | 4585 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4317 DwVfpRegister value = ToDoubleRegister(instr->value()); | 4586 DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4318 Register elements = ToRegister(instr->elements()); | 4587 Register elements = ToRegister(instr->elements()); |
| 4588 Register key = no_reg; |
| 4319 Register scratch = scratch0(); | 4589 Register scratch = scratch0(); |
| 4320 DwVfpRegister double_scratch = double_scratch0(); | 4590 DoubleRegister double_scratch = double_scratch0(); |
| 4321 bool key_is_constant = instr->key()->IsConstantOperand(); | 4591 bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4322 int base_offset = instr->base_offset(); | 4592 int constant_key = 0; |
| 4323 | 4593 |
| 4324 // Calculate the effective address of the slot in the array to store the | 4594 // Calculate the effective address of the slot in the array to store the |
| 4325 // double value. | 4595 // double value. |
| 4326 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); | |
| 4327 if (key_is_constant) { | 4596 if (key_is_constant) { |
| 4328 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 4597 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4329 if (constant_key & 0xF0000000) { | 4598 if (constant_key & 0xF0000000) { |
| 4330 Abort(kArrayIndexConstantValueTooBig); | 4599 Abort(kArrayIndexConstantValueTooBig); |
| 4331 } | 4600 } |
| 4332 __ add(scratch, elements, | |
| 4333 Operand((constant_key << element_size_shift) + base_offset)); | |
| 4334 } else { | 4601 } else { |
| 4335 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 4602 key = ToRegister(instr->key()); |
| 4336 ? (element_size_shift - kSmiTagSize) : element_size_shift; | 4603 } |
| 4337 __ add(scratch, elements, Operand(base_offset)); | 4604 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 4338 __ add(scratch, scratch, | 4605 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 4339 Operand(ToRegister(instr->key()), LSL, shift_size)); | 4606 int base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 4607 if (!key_is_constant) { |
| 4608 __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 4609 __ add(scratch, elements, scratch); |
| 4610 elements = scratch; |
| 4611 } |
| 4612 if (!is_int16(base_offset)) { |
| 4613 __ Add(scratch, elements, base_offset, r0); |
| 4614 base_offset = 0; |
| 4615 elements = scratch; |
| 4340 } | 4616 } |
| 4341 | 4617 |
| 4342 if (instr->NeedsCanonicalization()) { | 4618 if (instr->NeedsCanonicalization()) { |
| 4343 // Force a canonical NaN. | 4619 // Force a canonical NaN. |
| 4344 if (masm()->emit_debug_code()) { | 4620 __ CanonicalizeNaN(double_scratch, value); |
| 4345 __ vmrs(ip); | 4621 __ stfd(double_scratch, MemOperand(elements, base_offset)); |
| 4346 __ tst(ip, Operand(kVFPDefaultNaNModeControlBit)); | |
| 4347 __ Assert(ne, kDefaultNaNModeNotSet); | |
| 4348 } | |
| 4349 __ VFPCanonicalizeNaN(double_scratch, value); | |
| 4350 __ vstr(double_scratch, scratch, 0); | |
| 4351 } else { | 4622 } else { |
| 4352 __ vstr(value, scratch, 0); | 4623 __ stfd(value, MemOperand(elements, base_offset)); |
| 4353 } | 4624 } |
| 4354 } | 4625 } |
| 4355 | 4626 |
| 4356 | 4627 |
| 4357 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { | 4628 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4629 HStoreKeyed* hinstr = instr->hydrogen(); |
| 4358 Register value = ToRegister(instr->value()); | 4630 Register value = ToRegister(instr->value()); |
| 4359 Register elements = ToRegister(instr->elements()); | 4631 Register elements = ToRegister(instr->elements()); |
| 4360 Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) | 4632 Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 4361 : no_reg; | |
| 4362 Register scratch = scratch0(); | 4633 Register scratch = scratch0(); |
| 4363 Register store_base = scratch; | 4634 Register store_base = scratch; |
| 4364 int offset = instr->base_offset(); | 4635 int offset = instr->base_offset(); |
| 4365 | 4636 |
| 4366 // Do the store. | 4637 // Do the store. |
| 4367 if (instr->key()->IsConstantOperand()) { | 4638 if (instr->key()->IsConstantOperand()) { |
| 4368 ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); | 4639 ASSERT(!hinstr->NeedsWriteBarrier()); |
| 4369 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | 4640 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4370 offset += ToInteger32(const_operand) * kPointerSize; | 4641 offset += ToInteger32(const_operand) * kPointerSize; |
| 4371 store_base = elements; | 4642 store_base = elements; |
| 4372 } else { | 4643 } else { |
| 4373 // Even though the HLoadKeyed instruction forces the input | 4644 // Even though the HLoadKeyed instruction forces the input |
| 4374 // representation for the key to be an integer, the input gets replaced | 4645 // representation for the key to be an integer, the input gets replaced |
| 4375 // during bound check elimination with the index argument to the bounds | 4646 // during bound check elimination with the index argument to the bounds |
| 4376 // check, which can be tagged, so that case must be handled here, too. | 4647 // check, which can be tagged, so that case must be handled here, too. |
| 4377 if (instr->hydrogen()->key()->representation().IsSmi()) { | 4648 if (hinstr->key()->representation().IsSmi()) { |
| 4378 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); | 4649 __ SmiToPtrArrayOffset(scratch, key); |
| 4379 } else { | 4650 } else { |
| 4380 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); | 4651 __ ShiftLeftImm(scratch, key, Operand(kPointerSizeLog2)); |
| 4381 } | 4652 } |
| 4653 __ add(scratch, elements, scratch); |
| 4382 } | 4654 } |
| 4383 __ str(value, MemOperand(store_base, offset)); | |
| 4384 | 4655 |
| 4385 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4656 Representation representation = hinstr->value()->representation(); |
| 4386 SmiCheck check_needed = | 4657 |
| 4387 instr->hydrogen()->value()->type().IsHeapObject() | 4658 #if V8_TARGET_ARCH_PPC64 |
| 4388 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 4659 // 64-bit Smi optimization |
| 4660 if (representation.IsInteger32()) { |
| 4661 ASSERT(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4662 ASSERT(hinstr->elements_kind() == FAST_SMI_ELEMENTS); |
| 4663 // Store int value directly to upper half of the smi. |
| 4664 STATIC_ASSERT(kSmiTag == 0); |
| 4665 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 4666 #if V8_TARGET_LITTLE_ENDIAN |
| 4667 offset += kPointerSize / 2; |
| 4668 #endif |
| 4669 } |
| 4670 #endif |
| 4671 |
| 4672 __ StoreRepresentation(value, MemOperand(store_base, offset), |
| 4673 representation, r0); |
| 4674 |
| 4675 if (hinstr->NeedsWriteBarrier()) { |
| 4676 SmiCheck check_needed = hinstr->value()->type().IsHeapObject() |
| 4677 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 4389 // Compute address of modified element and store it into key register. | 4678 // Compute address of modified element and store it into key register. |
| 4390 __ add(key, store_base, Operand(offset)); | 4679 __ Add(key, store_base, offset, r0); |
| 4391 __ RecordWrite(elements, | 4680 __ RecordWrite(elements, |
| 4392 key, | 4681 key, |
| 4393 value, | 4682 value, |
| 4394 GetLinkRegisterState(), | 4683 GetLinkRegisterState(), |
| 4395 kSaveFPRegs, | 4684 kSaveFPRegs, |
| 4396 EMIT_REMEMBERED_SET, | 4685 EMIT_REMEMBERED_SET, |
| 4397 check_needed, | 4686 check_needed, |
| 4398 instr->hydrogen()->PointersToHereCheckForValue()); | 4687 hinstr->PointersToHereCheckForValue()); |
| 4399 } | 4688 } |
| 4400 } | 4689 } |
| 4401 | 4690 |
| 4402 | 4691 |
| 4403 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { | 4692 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4404 // By cases: external, fast double | 4693 // By cases: external, fast double |
| 4405 if (instr->is_typed_elements()) { | 4694 if (instr->is_typed_elements()) { |
| 4406 DoStoreKeyedExternalArray(instr); | 4695 DoStoreKeyedExternalArray(instr); |
| 4407 } else if (instr->hydrogen()->value()->representation().IsDouble()) { | 4696 } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4408 DoStoreKeyedFixedDoubleArray(instr); | 4697 DoStoreKeyedFixedDoubleArray(instr); |
| 4409 } else { | 4698 } else { |
| 4410 DoStoreKeyedFixedArray(instr); | 4699 DoStoreKeyedFixedArray(instr); |
| 4411 } | 4700 } |
| 4412 } | 4701 } |
| 4413 | 4702 |
| 4414 | 4703 |
| 4415 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { | 4704 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 4416 ASSERT(ToRegister(instr->context()).is(cp)); | 4705 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4417 ASSERT(ToRegister(instr->object()).is(KeyedStoreIC::ReceiverRegister())); | 4706 ASSERT(ToRegister(instr->object()).is(KeyedStoreIC::ReceiverRegister())); |
| 4418 ASSERT(ToRegister(instr->key()).is(KeyedStoreIC::NameRegister())); | 4707 ASSERT(ToRegister(instr->key()).is(KeyedStoreIC::NameRegister())); |
| 4419 ASSERT(ToRegister(instr->value()).is(KeyedStoreIC::ValueRegister())); | 4708 ASSERT(ToRegister(instr->value()).is(KeyedStoreIC::ValueRegister())); |
| 4420 | 4709 |
| 4421 Handle<Code> ic = instr->strict_mode() == STRICT | 4710 Handle<Code> ic = (instr->strict_mode() == STRICT) |
| 4422 ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() | 4711 ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4423 : isolate()->builtins()->KeyedStoreIC_Initialize(); | 4712 : isolate()->builtins()->KeyedStoreIC_Initialize(); |
| 4424 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 4713 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4425 } | 4714 } |
| 4426 | 4715 |
| 4427 | 4716 |
| 4428 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { | 4717 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4429 Register object_reg = ToRegister(instr->object()); | 4718 Register object_reg = ToRegister(instr->object()); |
| 4430 Register scratch = scratch0(); | 4719 Register scratch = scratch0(); |
| 4431 | 4720 |
| 4432 Handle<Map> from_map = instr->original_map(); | 4721 Handle<Map> from_map = instr->original_map(); |
| 4433 Handle<Map> to_map = instr->transitioned_map(); | 4722 Handle<Map> to_map = instr->transitioned_map(); |
| 4434 ElementsKind from_kind = instr->from_kind(); | 4723 ElementsKind from_kind = instr->from_kind(); |
| 4435 ElementsKind to_kind = instr->to_kind(); | 4724 ElementsKind to_kind = instr->to_kind(); |
| 4436 | 4725 |
| 4437 Label not_applicable; | 4726 Label not_applicable; |
| 4438 __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); | 4727 __ LoadP(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4439 __ cmp(scratch, Operand(from_map)); | 4728 __ Cmpi(scratch, Operand(from_map), r0); |
| 4440 __ b(ne, ¬_applicable); | 4729 __ bne(¬_applicable); |
| 4441 | 4730 |
| 4442 if (IsSimpleMapChangeTransition(from_kind, to_kind)) { | 4731 if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
| 4443 Register new_map_reg = ToRegister(instr->new_map_temp()); | 4732 Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4444 __ mov(new_map_reg, Operand(to_map)); | 4733 __ mov(new_map_reg, Operand(to_map)); |
| 4445 __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); | 4734 __ StoreP(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset), |
| 4735 r0); |
| 4446 // Write barrier. | 4736 // Write barrier. |
| 4447 __ RecordWriteForMap(object_reg, | 4737 __ RecordWriteForMap(object_reg, |
| 4448 new_map_reg, | 4738 new_map_reg, |
| 4449 scratch, | 4739 scratch, |
| 4450 GetLinkRegisterState(), | 4740 GetLinkRegisterState(), |
| 4451 kDontSaveFPRegs); | 4741 kDontSaveFPRegs); |
| 4452 } else { | 4742 } else { |
| 4453 ASSERT(ToRegister(instr->context()).is(cp)); | 4743 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4454 ASSERT(object_reg.is(r0)); | 4744 ASSERT(object_reg.is(r3)); |
| 4455 PushSafepointRegistersScope scope(this); | 4745 PushSafepointRegistersScope scope(this); |
| 4456 __ Move(r1, to_map); | 4746 __ Move(r4, to_map); |
| 4457 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; | 4747 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; |
| 4458 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); | 4748 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); |
| 4459 __ CallStub(&stub); | 4749 __ CallStub(&stub); |
| 4460 RecordSafepointWithRegisters( | 4750 RecordSafepointWithRegisters( |
| 4461 instr->pointer_map(), 0, Safepoint::kLazyDeopt); | 4751 instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 4462 } | 4752 } |
| 4463 __ bind(¬_applicable); | 4753 __ bind(¬_applicable); |
| 4464 } | 4754 } |
| 4465 | 4755 |
| 4466 | 4756 |
| 4467 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { | 4757 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4468 Register object = ToRegister(instr->object()); | 4758 Register object = ToRegister(instr->object()); |
| 4469 Register temp = ToRegister(instr->temp()); | 4759 Register temp = ToRegister(instr->temp()); |
| 4470 Label no_memento_found; | 4760 Label no_memento_found; |
| 4471 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); | 4761 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
| 4472 DeoptimizeIf(eq, instr->environment()); | 4762 DeoptimizeIf(eq, instr->environment()); |
| 4473 __ bind(&no_memento_found); | 4763 __ bind(&no_memento_found); |
| 4474 } | 4764 } |
| 4475 | 4765 |
| 4476 | 4766 |
| 4477 void LCodeGen::DoStringAdd(LStringAdd* instr) { | 4767 void LCodeGen::DoStringAdd(LStringAdd* instr) { |
| 4478 ASSERT(ToRegister(instr->context()).is(cp)); | 4768 ASSERT(ToRegister(instr->context()).is(cp)); |
| 4479 ASSERT(ToRegister(instr->left()).is(r1)); | 4769 ASSERT(ToRegister(instr->left()).is(r4)); |
| 4480 ASSERT(ToRegister(instr->right()).is(r0)); | 4770 ASSERT(ToRegister(instr->right()).is(r3)); |
| 4481 StringAddStub stub(isolate(), | 4771 StringAddStub stub(isolate(), |
| 4482 instr->hydrogen()->flags(), | 4772 instr->hydrogen()->flags(), |
| 4483 instr->hydrogen()->pretenure_flag()); | 4773 instr->hydrogen()->pretenure_flag()); |
| 4484 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4774 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4485 } | 4775 } |
| 4486 | 4776 |
| 4487 | 4777 |
| 4488 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { | 4778 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4489 class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { | 4779 class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
| 4490 public: | 4780 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4511 | 4801 |
| 4512 | 4802 |
| 4513 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | 4803 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4514 Register string = ToRegister(instr->string()); | 4804 Register string = ToRegister(instr->string()); |
| 4515 Register result = ToRegister(instr->result()); | 4805 Register result = ToRegister(instr->result()); |
| 4516 Register scratch = scratch0(); | 4806 Register scratch = scratch0(); |
| 4517 | 4807 |
| 4518 // TODO(3095996): Get rid of this. For now, we need to make the | 4808 // TODO(3095996): Get rid of this. For now, we need to make the |
| 4519 // result register contain a valid pointer because it is already | 4809 // result register contain a valid pointer because it is already |
| 4520 // contained in the register pointer map. | 4810 // contained in the register pointer map. |
| 4521 __ mov(result, Operand::Zero()); | 4811 __ li(result, Operand::Zero()); |
| 4522 | 4812 |
| 4523 PushSafepointRegistersScope scope(this); | 4813 PushSafepointRegistersScope scope(this); |
| 4524 __ push(string); | 4814 __ push(string); |
| 4525 // Push the index as a smi. This is safe because of the checks in | 4815 // Push the index as a smi. This is safe because of the checks in |
| 4526 // DoStringCharCodeAt above. | 4816 // DoStringCharCodeAt above. |
| 4527 if (instr->index()->IsConstantOperand()) { | 4817 if (instr->index()->IsConstantOperand()) { |
| 4528 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 4818 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4529 __ mov(scratch, Operand(Smi::FromInt(const_index))); | 4819 __ LoadSmiLiteral(scratch, Smi::FromInt(const_index)); |
| 4530 __ push(scratch); | 4820 __ push(scratch); |
| 4531 } else { | 4821 } else { |
| 4532 Register index = ToRegister(instr->index()); | 4822 Register index = ToRegister(instr->index()); |
| 4533 __ SmiTag(index); | 4823 __ SmiTag(index); |
| 4534 __ push(index); | 4824 __ push(index); |
| 4535 } | 4825 } |
| 4536 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, | 4826 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, |
| 4537 instr->context()); | 4827 instr->context()); |
| 4538 __ AssertSmi(r0); | 4828 __ AssertSmi(r3); |
| 4539 __ SmiUntag(r0); | 4829 __ SmiUntag(r3); |
| 4540 __ StoreToSafepointRegisterSlot(r0, result); | 4830 __ StoreToSafepointRegisterSlot(r3, result); |
| 4541 } | 4831 } |
| 4542 | 4832 |
| 4543 | 4833 |
| 4544 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { | 4834 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 4545 class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { | 4835 class DeferredStringCharFromCode: public LDeferredCode { |
| 4546 public: | 4836 public: |
| 4547 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) | 4837 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4548 : LDeferredCode(codegen), instr_(instr) { } | 4838 : LDeferredCode(codegen), instr_(instr) { } |
| 4549 virtual void Generate() V8_OVERRIDE { | 4839 virtual void Generate() V8_OVERRIDE { |
| 4550 codegen()->DoDeferredStringCharFromCode(instr_); | 4840 codegen()->DoDeferredStringCharFromCode(instr_); |
| 4551 } | 4841 } |
| 4552 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4842 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4553 private: | 4843 private: |
| 4554 LStringCharFromCode* instr_; | 4844 LStringCharFromCode* instr_; |
| 4555 }; | 4845 }; |
| 4556 | 4846 |
| 4557 DeferredStringCharFromCode* deferred = | 4847 DeferredStringCharFromCode* deferred = |
| 4558 new(zone()) DeferredStringCharFromCode(this, instr); | 4848 new(zone()) DeferredStringCharFromCode(this, instr); |
| 4559 | 4849 |
| 4560 ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); | 4850 ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4561 Register char_code = ToRegister(instr->char_code()); | 4851 Register char_code = ToRegister(instr->char_code()); |
| 4562 Register result = ToRegister(instr->result()); | 4852 Register result = ToRegister(instr->result()); |
| 4563 ASSERT(!char_code.is(result)); | 4853 ASSERT(!char_code.is(result)); |
| 4564 | 4854 |
| 4565 __ cmp(char_code, Operand(String::kMaxOneByteCharCode)); | 4855 __ cmpli(char_code, Operand(String::kMaxOneByteCharCode)); |
| 4566 __ b(hi, deferred->entry()); | 4856 __ bgt(deferred->entry()); |
| 4567 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); | 4857 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4568 __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); | 4858 __ ShiftLeftImm(r0, char_code, Operand(kPointerSizeLog2)); |
| 4569 __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); | 4859 __ add(result, result, r0); |
| 4860 __ LoadP(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4570 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 4861 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4571 __ cmp(result, ip); | 4862 __ cmp(result, ip); |
| 4572 __ b(eq, deferred->entry()); | 4863 __ beq(deferred->entry()); |
| 4573 __ bind(deferred->exit()); | 4864 __ bind(deferred->exit()); |
| 4574 } | 4865 } |
| 4575 | 4866 |
| 4576 | 4867 |
| 4577 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { | 4868 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4578 Register char_code = ToRegister(instr->char_code()); | 4869 Register char_code = ToRegister(instr->char_code()); |
| 4579 Register result = ToRegister(instr->result()); | 4870 Register result = ToRegister(instr->result()); |
| 4580 | 4871 |
| 4581 // TODO(3095996): Get rid of this. For now, we need to make the | 4872 // TODO(3095996): Get rid of this. For now, we need to make the |
| 4582 // result register contain a valid pointer because it is already | 4873 // result register contain a valid pointer because it is already |
| 4583 // contained in the register pointer map. | 4874 // contained in the register pointer map. |
| 4584 __ mov(result, Operand::Zero()); | 4875 __ li(result, Operand::Zero()); |
| 4585 | 4876 |
| 4586 PushSafepointRegistersScope scope(this); | 4877 PushSafepointRegistersScope scope(this); |
| 4587 __ SmiTag(char_code); | 4878 __ SmiTag(char_code); |
| 4588 __ push(char_code); | 4879 __ push(char_code); |
| 4589 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); | 4880 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
| 4590 __ StoreToSafepointRegisterSlot(r0, result); | 4881 __ StoreToSafepointRegisterSlot(r3, result); |
| 4591 } | 4882 } |
| 4592 | 4883 |
| 4593 | 4884 |
| 4594 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | 4885 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
| 4595 LOperand* input = instr->value(); | 4886 LOperand* input = instr->value(); |
| 4596 ASSERT(input->IsRegister() || input->IsStackSlot()); | 4887 ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4597 LOperand* output = instr->result(); | 4888 LOperand* output = instr->result(); |
| 4598 ASSERT(output->IsDoubleRegister()); | 4889 ASSERT(output->IsDoubleRegister()); |
| 4599 SwVfpRegister single_scratch = double_scratch0().low(); | |
| 4600 if (input->IsStackSlot()) { | 4890 if (input->IsStackSlot()) { |
| 4601 Register scratch = scratch0(); | 4891 Register scratch = scratch0(); |
| 4602 __ ldr(scratch, ToMemOperand(input)); | 4892 __ LoadP(scratch, ToMemOperand(input)); |
| 4603 __ vmov(single_scratch, scratch); | 4893 __ ConvertIntToDouble(scratch, ToDoubleRegister(output)); |
| 4604 } else { | 4894 } else { |
| 4605 __ vmov(single_scratch, ToRegister(input)); | 4895 __ ConvertIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
| 4606 } | 4896 } |
| 4607 __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); | |
| 4608 } | 4897 } |
| 4609 | 4898 |
| 4610 | 4899 |
| 4611 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { | 4900 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
| 4612 LOperand* input = instr->value(); | 4901 LOperand* input = instr->value(); |
| 4613 LOperand* output = instr->result(); | 4902 LOperand* output = instr->result(); |
| 4614 | 4903 __ ConvertUnsignedIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
| 4615 SwVfpRegister flt_scratch = double_scratch0().low(); | |
| 4616 __ vmov(flt_scratch, ToRegister(input)); | |
| 4617 __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch); | |
| 4618 } | 4904 } |
| 4619 | 4905 |
| 4620 | 4906 |
| 4621 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { | 4907 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 4622 class DeferredNumberTagI V8_FINAL : public LDeferredCode { | 4908 class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
| 4623 public: | 4909 public: |
| 4624 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) | 4910 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4625 : LDeferredCode(codegen), instr_(instr) { } | 4911 : LDeferredCode(codegen), instr_(instr) { } |
| 4626 virtual void Generate() V8_OVERRIDE { | 4912 virtual void Generate() V8_OVERRIDE { |
| 4627 codegen()->DoDeferredNumberTagIU(instr_, | 4913 codegen()->DoDeferredNumberTagIU(instr_, |
| 4628 instr_->value(), | 4914 instr_->value(), |
| 4629 instr_->temp1(), | 4915 instr_->temp1(), |
| 4630 instr_->temp2(), | 4916 instr_->temp2(), |
| 4631 SIGNED_INT32); | 4917 SIGNED_INT32); |
| 4632 } | 4918 } |
| 4633 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4919 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4634 private: | 4920 private: |
| 4635 LNumberTagI* instr_; | 4921 LNumberTagI* instr_; |
| 4636 }; | 4922 }; |
| 4637 | 4923 |
| 4638 Register src = ToRegister(instr->value()); | 4924 Register src = ToRegister(instr->value()); |
| 4639 Register dst = ToRegister(instr->result()); | 4925 Register dst = ToRegister(instr->result()); |
| 4640 | 4926 |
| 4641 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); | 4927 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
| 4642 __ SmiTag(dst, src, SetCC); | 4928 #if V8_TARGET_ARCH_PPC64 |
| 4643 __ b(vs, deferred->entry()); | 4929 __ SmiTag(dst, src); |
| 4930 #else |
| 4931 __ SmiTagCheckOverflow(dst, src, r0); |
| 4932 __ BranchOnOverflow(deferred->entry()); |
| 4933 #endif |
| 4644 __ bind(deferred->exit()); | 4934 __ bind(deferred->exit()); |
| 4645 } | 4935 } |
| 4646 | 4936 |
| 4647 | 4937 |
| 4648 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { | 4938 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
| 4649 class DeferredNumberTagU V8_FINAL : public LDeferredCode { | 4939 class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
| 4650 public: | 4940 public: |
| 4651 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) | 4941 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4652 : LDeferredCode(codegen), instr_(instr) { } | 4942 : LDeferredCode(codegen), instr_(instr) { } |
| 4653 virtual void Generate() V8_OVERRIDE { | 4943 virtual void Generate() V8_OVERRIDE { |
| 4654 codegen()->DoDeferredNumberTagIU(instr_, | 4944 codegen()->DoDeferredNumberTagIU(instr_, |
| 4655 instr_->value(), | 4945 instr_->value(), |
| 4656 instr_->temp1(), | 4946 instr_->temp1(), |
| 4657 instr_->temp2(), | 4947 instr_->temp2(), |
| 4658 UNSIGNED_INT32); | 4948 UNSIGNED_INT32); |
| 4659 } | 4949 } |
| 4660 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4950 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4661 private: | 4951 private: |
| 4662 LNumberTagU* instr_; | 4952 LNumberTagU* instr_; |
| 4663 }; | 4953 }; |
| 4664 | 4954 |
| 4665 Register input = ToRegister(instr->value()); | 4955 Register input = ToRegister(instr->value()); |
| 4666 Register result = ToRegister(instr->result()); | 4956 Register result = ToRegister(instr->result()); |
| 4667 | 4957 |
| 4668 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); | 4958 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
| 4669 __ cmp(input, Operand(Smi::kMaxValue)); | 4959 __ Cmpli(input, Operand(Smi::kMaxValue), r0); |
| 4670 __ b(hi, deferred->entry()); | 4960 __ bgt(deferred->entry()); |
| 4671 __ SmiTag(result, input); | 4961 __ SmiTag(result, input); |
| 4672 __ bind(deferred->exit()); | 4962 __ bind(deferred->exit()); |
| 4673 } | 4963 } |
| 4674 | 4964 |
| 4675 | 4965 |
| 4676 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, | 4966 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, |
| 4677 LOperand* value, | 4967 LOperand* value, |
| 4678 LOperand* temp1, | 4968 LOperand* temp1, |
| 4679 LOperand* temp2, | 4969 LOperand* temp2, |
| 4680 IntegerSignedness signedness) { | 4970 IntegerSignedness signedness) { |
| 4681 Label done, slow; | 4971 Label done, slow; |
| 4682 Register src = ToRegister(value); | 4972 Register src = ToRegister(value); |
| 4683 Register dst = ToRegister(instr->result()); | 4973 Register dst = ToRegister(instr->result()); |
| 4684 Register tmp1 = scratch0(); | 4974 Register tmp1 = scratch0(); |
| 4685 Register tmp2 = ToRegister(temp1); | 4975 Register tmp2 = ToRegister(temp1); |
| 4686 Register tmp3 = ToRegister(temp2); | 4976 Register tmp3 = ToRegister(temp2); |
| 4687 LowDwVfpRegister dbl_scratch = double_scratch0(); | 4977 DoubleRegister dbl_scratch = double_scratch0(); |
| 4688 | 4978 |
| 4689 if (signedness == SIGNED_INT32) { | 4979 if (signedness == SIGNED_INT32) { |
| 4690 // There was overflow, so bits 30 and 31 of the original integer | 4980 // There was overflow, so bits 30 and 31 of the original integer |
| 4691 // disagree. Try to allocate a heap number in new space and store | 4981 // disagree. Try to allocate a heap number in new space and store |
| 4692 // the value in there. If that fails, call the runtime system. | 4982 // the value in there. If that fails, call the runtime system. |
| 4693 if (dst.is(src)) { | 4983 if (dst.is(src)) { |
| 4694 __ SmiUntag(src, dst); | 4984 __ SmiUntag(src, dst); |
| 4695 __ eor(src, src, Operand(0x80000000)); | 4985 __ xoris(src, src, Operand(HeapNumber::kSignMask >> 16)); |
| 4696 } | 4986 } |
| 4697 __ vmov(dbl_scratch.low(), src); | 4987 __ ConvertIntToDouble(src, dbl_scratch); |
| 4698 __ vcvt_f64_s32(dbl_scratch, dbl_scratch.low()); | |
| 4699 } else { | 4988 } else { |
| 4700 __ vmov(dbl_scratch.low(), src); | 4989 __ ConvertUnsignedIntToDouble(src, dbl_scratch); |
| 4701 __ vcvt_f64_u32(dbl_scratch, dbl_scratch.low()); | |
| 4702 } | 4990 } |
| 4703 | 4991 |
| 4704 if (FLAG_inline_new) { | 4992 if (FLAG_inline_new) { |
| 4705 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); | 4993 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); |
| 4706 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow, DONT_TAG_RESULT); | 4994 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow); |
| 4707 __ b(&done); | 4995 __ b(&done); |
| 4708 } | 4996 } |
| 4709 | 4997 |
| 4710 // Slow case: Call the runtime system to do the number allocation. | 4998 // Slow case: Call the runtime system to do the number allocation. |
| 4711 __ bind(&slow); | 4999 __ bind(&slow); |
| 4712 { | 5000 { |
| 4713 // TODO(3095996): Put a valid pointer value in the stack slot where the | 5001 // TODO(3095996): Put a valid pointer value in the stack slot where the |
| 4714 // result register is stored, as this register is in the pointer map, but | 5002 // result register is stored, as this register is in the pointer map, but |
| 4715 // contains an integer value. | 5003 // contains an integer value. |
| 4716 __ mov(dst, Operand::Zero()); | 5004 __ li(dst, Operand::Zero()); |
| 4717 | 5005 |
| 4718 // Preserve the value of all registers. | 5006 // Preserve the value of all registers. |
| 4719 PushSafepointRegistersScope scope(this); | 5007 PushSafepointRegistersScope scope(this); |
| 4720 | 5008 |
| 4721 // NumberTagI and NumberTagD use the context from the frame, rather than | 5009 // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4722 // the environment's HContext or HInlinedContext value. | 5010 // the environment's HContext or HInlinedContext value. |
| 4723 // They only call Runtime::kAllocateHeapNumber. | 5011 // They only call Runtime::kAllocateHeapNumber. |
| 4724 // The corresponding HChange instructions are added in a phase that does | 5012 // The corresponding HChange instructions are added in a phase that does |
| 4725 // not have easy access to the local context. | 5013 // not have easy access to the local context. |
| 4726 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 5014 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4727 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 5015 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4728 RecordSafepointWithRegisters( | 5016 RecordSafepointWithRegisters( |
| 4729 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | 5017 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
| 4730 __ sub(r0, r0, Operand(kHeapObjectTag)); | 5018 __ StoreToSafepointRegisterSlot(r3, dst); |
| 4731 __ StoreToSafepointRegisterSlot(r0, dst); | |
| 4732 } | 5019 } |
| 4733 | 5020 |
| 4734 // Done. Put the value in dbl_scratch into the value of the allocated heap | 5021 // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4735 // number. | 5022 // number. |
| 4736 __ bind(&done); | 5023 __ bind(&done); |
| 4737 __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset); | 5024 __ stfd(dbl_scratch, FieldMemOperand(dst, HeapNumber::kValueOffset)); |
| 4738 __ add(dst, dst, Operand(kHeapObjectTag)); | |
| 4739 } | 5025 } |
| 4740 | 5026 |
| 4741 | 5027 |
| 4742 void LCodeGen::DoNumberTagD(LNumberTagD* instr) { | 5028 void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 4743 class DeferredNumberTagD V8_FINAL : public LDeferredCode { | 5029 class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
| 4744 public: | 5030 public: |
| 4745 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) | 5031 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4746 : LDeferredCode(codegen), instr_(instr) { } | 5032 : LDeferredCode(codegen), instr_(instr) { } |
| 4747 virtual void Generate() V8_OVERRIDE { | 5033 virtual void Generate() V8_OVERRIDE { |
| 4748 codegen()->DoDeferredNumberTagD(instr_); | 5034 codegen()->DoDeferredNumberTagD(instr_); |
| 4749 } | 5035 } |
| 4750 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 5036 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4751 private: | 5037 private: |
| 4752 LNumberTagD* instr_; | 5038 LNumberTagD* instr_; |
| 4753 }; | 5039 }; |
| 4754 | 5040 |
| 4755 DwVfpRegister input_reg = ToDoubleRegister(instr->value()); | 5041 DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
| 4756 Register scratch = scratch0(); | 5042 Register scratch = scratch0(); |
| 4757 Register reg = ToRegister(instr->result()); | 5043 Register reg = ToRegister(instr->result()); |
| 4758 Register temp1 = ToRegister(instr->temp()); | 5044 Register temp1 = ToRegister(instr->temp()); |
| 4759 Register temp2 = ToRegister(instr->temp2()); | 5045 Register temp2 = ToRegister(instr->temp2()); |
| 4760 | 5046 |
| 4761 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); | 5047 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
| 4762 if (FLAG_inline_new) { | 5048 if (FLAG_inline_new) { |
| 4763 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); | 5049 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 4764 // We want the untagged address first for performance | 5050 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry()); |
| 4765 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), | |
| 4766 DONT_TAG_RESULT); | |
| 4767 } else { | 5051 } else { |
| 4768 __ jmp(deferred->entry()); | 5052 __ b(deferred->entry()); |
| 4769 } | 5053 } |
| 4770 __ bind(deferred->exit()); | 5054 __ bind(deferred->exit()); |
| 4771 __ vstr(input_reg, reg, HeapNumber::kValueOffset); | 5055 __ stfd(input_reg, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 4772 // Now that we have finished with the object's real address tag it | |
| 4773 __ add(reg, reg, Operand(kHeapObjectTag)); | |
| 4774 } | 5056 } |
| 4775 | 5057 |
| 4776 | 5058 |
| 4777 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { | 5059 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4778 // TODO(3095996): Get rid of this. For now, we need to make the | 5060 // TODO(3095996): Get rid of this. For now, we need to make the |
| 4779 // result register contain a valid pointer because it is already | 5061 // result register contain a valid pointer because it is already |
| 4780 // contained in the register pointer map. | 5062 // contained in the register pointer map. |
| 4781 Register reg = ToRegister(instr->result()); | 5063 Register reg = ToRegister(instr->result()); |
| 4782 __ mov(reg, Operand::Zero()); | 5064 __ li(reg, Operand::Zero()); |
| 4783 | 5065 |
| 4784 PushSafepointRegistersScope scope(this); | 5066 PushSafepointRegistersScope scope(this); |
| 4785 // NumberTagI and NumberTagD use the context from the frame, rather than | 5067 // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4786 // the environment's HContext or HInlinedContext value. | 5068 // the environment's HContext or HInlinedContext value. |
| 4787 // They only call Runtime::kAllocateHeapNumber. | 5069 // They only call Runtime::kAllocateHeapNumber. |
| 4788 // The corresponding HChange instructions are added in a phase that does | 5070 // The corresponding HChange instructions are added in a phase that does |
| 4789 // not have easy access to the local context. | 5071 // not have easy access to the local context. |
| 4790 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 5072 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4791 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 5073 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4792 RecordSafepointWithRegisters( | 5074 RecordSafepointWithRegisters( |
| 4793 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | 5075 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
| 4794 __ sub(r0, r0, Operand(kHeapObjectTag)); | 5076 __ StoreToSafepointRegisterSlot(r3, reg); |
| 4795 __ StoreToSafepointRegisterSlot(r0, reg); | |
| 4796 } | 5077 } |
| 4797 | 5078 |
| 4798 | 5079 |
| 4799 void LCodeGen::DoSmiTag(LSmiTag* instr) { | 5080 void LCodeGen::DoSmiTag(LSmiTag* instr) { |
| 4800 HChange* hchange = instr->hydrogen(); | 5081 HChange* hchange = instr->hydrogen(); |
| 4801 Register input = ToRegister(instr->value()); | 5082 Register input = ToRegister(instr->value()); |
| 4802 Register output = ToRegister(instr->result()); | 5083 Register output = ToRegister(instr->result()); |
| 4803 if (hchange->CheckFlag(HValue::kCanOverflow) && | 5084 if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4804 hchange->value()->CheckFlag(HValue::kUint32)) { | 5085 hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4805 __ tst(input, Operand(0xc0000000)); | 5086 __ TestUnsignedSmiCandidate(input, r0); |
| 4806 DeoptimizeIf(ne, instr->environment()); | 5087 DeoptimizeIf(ne, instr->environment(), cr0); |
| 4807 } | 5088 } |
| 5089 #if !V8_TARGET_ARCH_PPC64 |
| 4808 if (hchange->CheckFlag(HValue::kCanOverflow) && | 5090 if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4809 !hchange->value()->CheckFlag(HValue::kUint32)) { | 5091 !hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4810 __ SmiTag(output, input, SetCC); | 5092 __ SmiTagCheckOverflow(output, input, r0); |
| 4811 DeoptimizeIf(vs, instr->environment()); | 5093 DeoptimizeIf(lt, instr->environment(), cr0); |
| 4812 } else { | 5094 } else { |
| 5095 #endif |
| 4813 __ SmiTag(output, input); | 5096 __ SmiTag(output, input); |
| 5097 #if !V8_TARGET_ARCH_PPC64 |
| 4814 } | 5098 } |
| 5099 #endif |
| 4815 } | 5100 } |
| 4816 | 5101 |
| 4817 | 5102 |
| 4818 void LCodeGen::DoSmiUntag(LSmiUntag* instr) { | 5103 void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
| 5104 Register scratch = scratch0(); |
| 4819 Register input = ToRegister(instr->value()); | 5105 Register input = ToRegister(instr->value()); |
| 4820 Register result = ToRegister(instr->result()); | 5106 Register result = ToRegister(instr->result()); |
| 4821 if (instr->needs_check()) { | 5107 if (instr->needs_check()) { |
| 4822 STATIC_ASSERT(kHeapObjectTag == 1); | 5108 STATIC_ASSERT(kHeapObjectTag == 1); |
| 4823 // If the input is a HeapObject, SmiUntag will set the carry flag. | 5109 // If the input is a HeapObject, value of scratch won't be zero. |
| 4824 __ SmiUntag(result, input, SetCC); | 5110 __ andi(scratch, input, Operand(kHeapObjectTag)); |
| 4825 DeoptimizeIf(cs, instr->environment()); | 5111 __ SmiUntag(result, input); |
| 5112 DeoptimizeIf(ne, instr->environment(), cr0); |
| 4826 } else { | 5113 } else { |
| 4827 __ SmiUntag(result, input); | 5114 __ SmiUntag(result, input); |
| 4828 } | 5115 } |
| 4829 } | 5116 } |
| 4830 | 5117 |
| 4831 | 5118 |
| 4832 void LCodeGen::EmitNumberUntagD(Register input_reg, | 5119 void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 4833 DwVfpRegister result_reg, | 5120 DoubleRegister result_reg, |
| 4834 bool can_convert_undefined_to_nan, | 5121 bool can_convert_undefined_to_nan, |
| 4835 bool deoptimize_on_minus_zero, | 5122 bool deoptimize_on_minus_zero, |
| 4836 LEnvironment* env, | 5123 LEnvironment* env, |
| 4837 NumberUntagDMode mode) { | 5124 NumberUntagDMode mode) { |
| 4838 Register scratch = scratch0(); | 5125 Register scratch = scratch0(); |
| 4839 SwVfpRegister flt_scratch = double_scratch0().low(); | |
| 4840 ASSERT(!result_reg.is(double_scratch0())); | 5126 ASSERT(!result_reg.is(double_scratch0())); |
| 5127 |
| 4841 Label convert, load_smi, done; | 5128 Label convert, load_smi, done; |
| 5129 |
| 4842 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { | 5130 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
| 4843 // Smi check. | 5131 // Smi check. |
| 4844 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); | 5132 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
| 5133 |
| 4845 // Heap number map check. | 5134 // Heap number map check. |
| 4846 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); | 5135 __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4847 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 5136 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 4848 __ cmp(scratch, Operand(ip)); | 5137 __ cmp(scratch, ip); |
| 4849 if (can_convert_undefined_to_nan) { | 5138 if (can_convert_undefined_to_nan) { |
| 4850 __ b(ne, &convert); | 5139 __ bne(&convert); |
| 4851 } else { | 5140 } else { |
| 4852 DeoptimizeIf(ne, env); | 5141 DeoptimizeIf(ne, env); |
| 4853 } | 5142 } |
| 4854 // load heap number | 5143 // load heap number |
| 4855 __ vldr(result_reg, input_reg, HeapNumber::kValueOffset - kHeapObjectTag); | 5144 __ lfd(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4856 if (deoptimize_on_minus_zero) { | 5145 if (deoptimize_on_minus_zero) { |
| 4857 __ VmovLow(scratch, result_reg); | 5146 __ stfdu(result_reg, MemOperand(sp, -kDoubleSize)); |
| 4858 __ cmp(scratch, Operand::Zero()); | 5147 __ nop(); // LHS/RAW optimization |
| 4859 __ b(ne, &done); | 5148 __ lwz(scratch, MemOperand(sp, Register::kExponentOffset)); |
| 4860 __ VmovHigh(scratch, result_reg); | 5149 __ lwz(ip, MemOperand(sp, Register::kMantissaOffset)); |
| 4861 __ cmp(scratch, Operand(HeapNumber::kSignMask)); | 5150 __ addi(sp, sp, Operand(kDoubleSize)); |
| 5151 |
| 5152 __ cmpi(ip, Operand::Zero()); |
| 5153 __ bne(&done); |
| 5154 __ Cmpi(scratch, Operand(HeapNumber::kSignMask), r0); |
| 4862 DeoptimizeIf(eq, env); | 5155 DeoptimizeIf(eq, env); |
| 4863 } | 5156 } |
| 4864 __ jmp(&done); | 5157 __ b(&done); |
| 4865 if (can_convert_undefined_to_nan) { | 5158 if (can_convert_undefined_to_nan) { |
| 4866 __ bind(&convert); | 5159 __ bind(&convert); |
| 4867 // Convert undefined (and hole) to NaN. | 5160 // Convert undefined (and hole) to NaN. |
| 4868 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5161 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4869 __ cmp(input_reg, Operand(ip)); | 5162 __ cmp(input_reg, ip); |
| 4870 DeoptimizeIf(ne, env); | 5163 DeoptimizeIf(ne, env); |
| 4871 __ LoadRoot(scratch, Heap::kNanValueRootIndex); | 5164 __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
| 4872 __ vldr(result_reg, scratch, HeapNumber::kValueOffset - kHeapObjectTag); | 5165 __ lfd(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset)); |
| 4873 __ jmp(&done); | 5166 __ b(&done); |
| 4874 } | 5167 } |
| 4875 } else { | 5168 } else { |
| 4876 __ SmiUntag(scratch, input_reg); | 5169 __ SmiUntag(scratch, input_reg); |
| 4877 ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); | 5170 ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
| 4878 } | 5171 } |
| 4879 // Smi to double register conversion | 5172 // Smi to double register conversion |
| 4880 __ bind(&load_smi); | 5173 __ bind(&load_smi); |
| 4881 // scratch: untagged value of input_reg | 5174 // scratch: untagged value of input_reg |
| 4882 __ vmov(flt_scratch, scratch); | 5175 __ ConvertIntToDouble(scratch, result_reg); |
| 4883 __ vcvt_f64_s32(result_reg, flt_scratch); | |
| 4884 __ bind(&done); | 5176 __ bind(&done); |
| 4885 } | 5177 } |
| 4886 | 5178 |
| 4887 | 5179 |
| 4888 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { | 5180 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
| 4889 Register input_reg = ToRegister(instr->value()); | 5181 Register input_reg = ToRegister(instr->value()); |
| 4890 Register scratch1 = scratch0(); | 5182 Register scratch1 = scratch0(); |
| 4891 Register scratch2 = ToRegister(instr->temp()); | 5183 Register scratch2 = ToRegister(instr->temp()); |
| 4892 LowDwVfpRegister double_scratch = double_scratch0(); | 5184 DoubleRegister double_scratch = double_scratch0(); |
| 4893 DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp2()); | 5185 DoubleRegister double_scratch2 = ToDoubleRegister(instr->temp2()); |
| 4894 | 5186 |
| 4895 ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); | 5187 ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4896 ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); | 5188 ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4897 | 5189 |
| 4898 Label done; | 5190 Label done; |
| 4899 | 5191 |
| 4900 // The input was optimistically untagged; revert it. | |
| 4901 // The carry flag is set when we reach this deferred code as we just executed | |
| 4902 // SmiUntag(heap_object, SetCC) | |
| 4903 STATIC_ASSERT(kHeapObjectTag == 1); | |
| 4904 __ adc(scratch2, input_reg, Operand(input_reg)); | |
| 4905 | |
| 4906 // Heap number map check. | 5192 // Heap number map check. |
| 4907 __ ldr(scratch1, FieldMemOperand(scratch2, HeapObject::kMapOffset)); | 5193 __ LoadP(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4908 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 5194 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 4909 __ cmp(scratch1, Operand(ip)); | 5195 __ cmp(scratch1, ip); |
| 4910 | 5196 |
| 4911 if (instr->truncating()) { | 5197 if (instr->truncating()) { |
| 4912 // Performs a truncating conversion of a floating point number as used by | 5198 // Performs a truncating conversion of a floating point number as used by |
| 4913 // the JS bitwise operations. | 5199 // the JS bitwise operations. |
| 4914 Label no_heap_number, check_bools, check_false; | 5200 Label no_heap_number, check_bools, check_false; |
| 4915 __ b(ne, &no_heap_number); | 5201 __ bne(&no_heap_number); |
| 5202 __ mr(scratch2, input_reg); |
| 4916 __ TruncateHeapNumberToI(input_reg, scratch2); | 5203 __ TruncateHeapNumberToI(input_reg, scratch2); |
| 4917 __ b(&done); | 5204 __ b(&done); |
| 4918 | 5205 |
| 4919 // Check for Oddballs. Undefined/False is converted to zero and True to one | 5206 // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 4920 // for truncating conversions. | 5207 // for truncating conversions. |
| 4921 __ bind(&no_heap_number); | 5208 __ bind(&no_heap_number); |
| 4922 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5209 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4923 __ cmp(scratch2, Operand(ip)); | 5210 __ cmp(input_reg, ip); |
| 4924 __ b(ne, &check_bools); | 5211 __ bne(&check_bools); |
| 4925 __ mov(input_reg, Operand::Zero()); | 5212 __ li(input_reg, Operand::Zero()); |
| 4926 __ b(&done); | 5213 __ b(&done); |
| 4927 | 5214 |
| 4928 __ bind(&check_bools); | 5215 __ bind(&check_bools); |
| 4929 __ LoadRoot(ip, Heap::kTrueValueRootIndex); | 5216 __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 4930 __ cmp(scratch2, Operand(ip)); | 5217 __ cmp(input_reg, ip); |
| 4931 __ b(ne, &check_false); | 5218 __ bne(&check_false); |
| 4932 __ mov(input_reg, Operand(1)); | 5219 __ li(input_reg, Operand(1)); |
| 4933 __ b(&done); | 5220 __ b(&done); |
| 4934 | 5221 |
| 4935 __ bind(&check_false); | 5222 __ bind(&check_false); |
| 4936 __ LoadRoot(ip, Heap::kFalseValueRootIndex); | 5223 __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 4937 __ cmp(scratch2, Operand(ip)); | 5224 __ cmp(input_reg, ip); |
| 4938 DeoptimizeIf(ne, instr->environment()); | 5225 DeoptimizeIf(ne, instr->environment()); |
| 4939 __ mov(input_reg, Operand::Zero()); | 5226 __ li(input_reg, Operand::Zero()); |
| 4940 __ b(&done); | |
| 4941 } else { | 5227 } else { |
| 4942 // Deoptimize if we don't have a heap number. | 5228 // Deoptimize if we don't have a heap number. |
| 4943 DeoptimizeIf(ne, instr->environment()); | 5229 DeoptimizeIf(ne, instr->environment()); |
| 4944 | 5230 |
| 4945 __ sub(ip, scratch2, Operand(kHeapObjectTag)); | 5231 __ lfd(double_scratch2, |
| 4946 __ vldr(double_scratch2, ip, HeapNumber::kValueOffset); | 5232 FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4947 __ TryDoubleToInt32Exact(input_reg, double_scratch2, double_scratch); | 5233 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5234 // preserve heap number pointer in scratch2 for minus zero check below |
| 5235 __ mr(scratch2, input_reg); |
| 5236 } |
| 5237 __ TryDoubleToInt32Exact(input_reg, double_scratch2, |
| 5238 scratch1, double_scratch); |
| 4948 DeoptimizeIf(ne, instr->environment()); | 5239 DeoptimizeIf(ne, instr->environment()); |
| 4949 | 5240 |
| 4950 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5241 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4951 __ cmp(input_reg, Operand::Zero()); | 5242 __ cmpi(input_reg, Operand::Zero()); |
| 4952 __ b(ne, &done); | 5243 __ bne(&done); |
| 4953 __ VmovHigh(scratch1, double_scratch2); | 5244 __ lwz(scratch1, FieldMemOperand(scratch2, HeapNumber::kValueOffset + |
| 4954 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5245 Register::kExponentOffset)); |
| 4955 DeoptimizeIf(ne, instr->environment()); | 5246 __ cmpwi(scratch1, Operand::Zero()); |
| 5247 DeoptimizeIf(lt, instr->environment()); |
| 4956 } | 5248 } |
| 4957 } | 5249 } |
| 4958 __ bind(&done); | 5250 __ bind(&done); |
| 4959 } | 5251 } |
| 4960 | 5252 |
| 4961 | 5253 |
| 4962 void LCodeGen::DoTaggedToI(LTaggedToI* instr) { | 5254 void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
| 4963 class DeferredTaggedToI V8_FINAL : public LDeferredCode { | 5255 class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
| 4964 public: | 5256 public: |
| 4965 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) | 5257 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4976 ASSERT(input->IsRegister()); | 5268 ASSERT(input->IsRegister()); |
| 4977 ASSERT(input->Equals(instr->result())); | 5269 ASSERT(input->Equals(instr->result())); |
| 4978 | 5270 |
| 4979 Register input_reg = ToRegister(input); | 5271 Register input_reg = ToRegister(input); |
| 4980 | 5272 |
| 4981 if (instr->hydrogen()->value()->representation().IsSmi()) { | 5273 if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 4982 __ SmiUntag(input_reg); | 5274 __ SmiUntag(input_reg); |
| 4983 } else { | 5275 } else { |
| 4984 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); | 5276 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
| 4985 | 5277 |
| 4986 // Optimistically untag the input. | 5278 // Branch to deferred code if the input is a HeapObject. |
| 4987 // If the input is a HeapObject, SmiUntag will set the carry flag. | 5279 __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 4988 __ SmiUntag(input_reg, SetCC); | 5280 |
| 4989 // Branch to deferred code if the input was tagged. | 5281 __ SmiUntag(input_reg); |
| 4990 // The deferred code will take care of restoring the tag. | |
| 4991 __ b(cs, deferred->entry()); | |
| 4992 __ bind(deferred->exit()); | 5282 __ bind(deferred->exit()); |
| 4993 } | 5283 } |
| 4994 } | 5284 } |
| 4995 | 5285 |
| 4996 | 5286 |
| 4997 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { | 5287 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
| 4998 LOperand* input = instr->value(); | 5288 LOperand* input = instr->value(); |
| 4999 ASSERT(input->IsRegister()); | 5289 ASSERT(input->IsRegister()); |
| 5000 LOperand* result = instr->result(); | 5290 LOperand* result = instr->result(); |
| 5001 ASSERT(result->IsDoubleRegister()); | 5291 ASSERT(result->IsDoubleRegister()); |
| 5002 | 5292 |
| 5003 Register input_reg = ToRegister(input); | 5293 Register input_reg = ToRegister(input); |
| 5004 DwVfpRegister result_reg = ToDoubleRegister(result); | 5294 DoubleRegister result_reg = ToDoubleRegister(result); |
| 5005 | 5295 |
| 5006 HValue* value = instr->hydrogen()->value(); | 5296 HValue* value = instr->hydrogen()->value(); |
| 5007 NumberUntagDMode mode = value->representation().IsSmi() | 5297 NumberUntagDMode mode = value->representation().IsSmi() |
| 5008 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; | 5298 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
| 5009 | 5299 |
| 5010 EmitNumberUntagD(input_reg, result_reg, | 5300 EmitNumberUntagD(input_reg, result_reg, |
| 5011 instr->hydrogen()->can_convert_undefined_to_nan(), | 5301 instr->hydrogen()->can_convert_undefined_to_nan(), |
| 5012 instr->hydrogen()->deoptimize_on_minus_zero(), | 5302 instr->hydrogen()->deoptimize_on_minus_zero(), |
| 5013 instr->environment(), | 5303 instr->environment(), |
| 5014 mode); | 5304 mode); |
| 5015 } | 5305 } |
| 5016 | 5306 |
| 5017 | 5307 |
| 5018 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { | 5308 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
| 5019 Register result_reg = ToRegister(instr->result()); | 5309 Register result_reg = ToRegister(instr->result()); |
| 5020 Register scratch1 = scratch0(); | 5310 Register scratch1 = scratch0(); |
| 5021 DwVfpRegister double_input = ToDoubleRegister(instr->value()); | 5311 DoubleRegister double_input = ToDoubleRegister(instr->value()); |
| 5022 LowDwVfpRegister double_scratch = double_scratch0(); | 5312 DoubleRegister double_scratch = double_scratch0(); |
| 5023 | 5313 |
| 5024 if (instr->truncating()) { | 5314 if (instr->truncating()) { |
| 5025 __ TruncateDoubleToI(result_reg, double_input); | 5315 __ TruncateDoubleToI(result_reg, double_input); |
| 5026 } else { | 5316 } else { |
| 5027 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); | 5317 __ TryDoubleToInt32Exact(result_reg, double_input, |
| 5318 scratch1, double_scratch); |
| 5028 // Deoptimize if the input wasn't a int32 (inside a double). | 5319 // Deoptimize if the input wasn't a int32 (inside a double). |
| 5029 DeoptimizeIf(ne, instr->environment()); | 5320 DeoptimizeIf(ne, instr->environment()); |
| 5030 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5321 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5031 Label done; | 5322 Label done; |
| 5032 __ cmp(result_reg, Operand::Zero()); | 5323 __ cmpi(result_reg, Operand::Zero()); |
| 5033 __ b(ne, &done); | 5324 __ bne(&done); |
| 5034 __ VmovHigh(scratch1, double_input); | 5325 __ stfdu(double_input, MemOperand(sp, -kDoubleSize)); |
| 5035 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5326 __ nop(); // LHS/RAW optimization |
| 5036 DeoptimizeIf(ne, instr->environment()); | 5327 __ lwz(scratch1, MemOperand(sp, Register::kExponentOffset)); |
| 5328 __ addi(sp, sp, Operand(kDoubleSize)); |
| 5329 __ cmpwi(scratch1, Operand::Zero()); |
| 5330 DeoptimizeIf(lt, instr->environment()); |
| 5037 __ bind(&done); | 5331 __ bind(&done); |
| 5038 } | 5332 } |
| 5039 } | 5333 } |
| 5040 } | 5334 } |
| 5041 | 5335 |
| 5042 | 5336 |
| 5043 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { | 5337 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 5044 Register result_reg = ToRegister(instr->result()); | 5338 Register result_reg = ToRegister(instr->result()); |
| 5045 Register scratch1 = scratch0(); | 5339 Register scratch1 = scratch0(); |
| 5046 DwVfpRegister double_input = ToDoubleRegister(instr->value()); | 5340 DoubleRegister double_input = ToDoubleRegister(instr->value()); |
| 5047 LowDwVfpRegister double_scratch = double_scratch0(); | 5341 DoubleRegister double_scratch = double_scratch0(); |
| 5048 | 5342 |
| 5049 if (instr->truncating()) { | 5343 if (instr->truncating()) { |
| 5050 __ TruncateDoubleToI(result_reg, double_input); | 5344 __ TruncateDoubleToI(result_reg, double_input); |
| 5051 } else { | 5345 } else { |
| 5052 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); | 5346 __ TryDoubleToInt32Exact(result_reg, double_input, |
| 5347 scratch1, double_scratch); |
| 5053 // Deoptimize if the input wasn't a int32 (inside a double). | 5348 // Deoptimize if the input wasn't a int32 (inside a double). |
| 5054 DeoptimizeIf(ne, instr->environment()); | 5349 DeoptimizeIf(ne, instr->environment()); |
| 5055 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5350 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5056 Label done; | 5351 Label done; |
| 5057 __ cmp(result_reg, Operand::Zero()); | 5352 __ cmpi(result_reg, Operand::Zero()); |
| 5058 __ b(ne, &done); | 5353 __ bne(&done); |
| 5059 __ VmovHigh(scratch1, double_input); | 5354 __ stfdu(double_input, MemOperand(sp, -kDoubleSize)); |
| 5060 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5355 __ nop(); // LHS/RAW optimization |
| 5061 DeoptimizeIf(ne, instr->environment()); | 5356 __ lwz(scratch1, MemOperand(sp, Register::kExponentOffset)); |
| 5357 __ addi(sp, sp, Operand(kDoubleSize)); |
| 5358 __ cmpwi(scratch1, Operand::Zero()); |
| 5359 DeoptimizeIf(lt, instr->environment()); |
| 5062 __ bind(&done); | 5360 __ bind(&done); |
| 5063 } | 5361 } |
| 5064 } | 5362 } |
| 5065 __ SmiTag(result_reg, SetCC); | 5363 #if V8_TARGET_ARCH_PPC64 |
| 5066 DeoptimizeIf(vs, instr->environment()); | 5364 __ SmiTag(result_reg); |
| 5365 #else |
| 5366 __ SmiTagCheckOverflow(result_reg, r0); |
| 5367 DeoptimizeIf(lt, instr->environment(), cr0); |
| 5368 #endif |
| 5067 } | 5369 } |
| 5068 | 5370 |
| 5069 | 5371 |
| 5070 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { | 5372 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
| 5071 LOperand* input = instr->value(); | 5373 LOperand* input = instr->value(); |
| 5072 __ SmiTst(ToRegister(input)); | 5374 __ TestIfSmi(ToRegister(input), r0); |
| 5073 DeoptimizeIf(ne, instr->environment()); | 5375 DeoptimizeIf(ne, instr->environment(), cr0); |
| 5074 } | 5376 } |
| 5075 | 5377 |
| 5076 | 5378 |
| 5077 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { | 5379 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
| 5078 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 5380 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 5079 LOperand* input = instr->value(); | 5381 LOperand* input = instr->value(); |
| 5080 __ SmiTst(ToRegister(input)); | 5382 __ TestIfSmi(ToRegister(input), r0); |
| 5081 DeoptimizeIf(eq, instr->environment()); | 5383 DeoptimizeIf(eq, instr->environment(), cr0); |
| 5082 } | 5384 } |
| 5083 } | 5385 } |
| 5084 | 5386 |
| 5085 | 5387 |
| 5086 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { | 5388 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
| 5087 Register input = ToRegister(instr->value()); | 5389 Register input = ToRegister(instr->value()); |
| 5088 Register scratch = scratch0(); | 5390 Register scratch = scratch0(); |
| 5089 | 5391 |
| 5090 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5392 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5091 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); | 5393 __ lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 5092 | 5394 |
| 5093 if (instr->hydrogen()->is_interval_check()) { | 5395 if (instr->hydrogen()->is_interval_check()) { |
| 5094 InstanceType first; | 5396 InstanceType first; |
| 5095 InstanceType last; | 5397 InstanceType last; |
| 5096 instr->hydrogen()->GetCheckInterval(&first, &last); | 5398 instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5097 | 5399 |
| 5098 __ cmp(scratch, Operand(first)); | 5400 __ cmpli(scratch, Operand(first)); |
| 5099 | 5401 |
| 5100 // If there is only one type in the interval check for equality. | 5402 // If there is only one type in the interval check for equality. |
| 5101 if (first == last) { | 5403 if (first == last) { |
| 5102 DeoptimizeIf(ne, instr->environment()); | 5404 DeoptimizeIf(ne, instr->environment()); |
| 5103 } else { | 5405 } else { |
| 5104 DeoptimizeIf(lo, instr->environment()); | 5406 DeoptimizeIf(lt, instr->environment()); |
| 5105 // Omit check for the last type. | 5407 // Omit check for the last type. |
| 5106 if (last != LAST_TYPE) { | 5408 if (last != LAST_TYPE) { |
| 5107 __ cmp(scratch, Operand(last)); | 5409 __ cmpli(scratch, Operand(last)); |
| 5108 DeoptimizeIf(hi, instr->environment()); | 5410 DeoptimizeIf(gt, instr->environment()); |
| 5109 } | 5411 } |
| 5110 } | 5412 } |
| 5111 } else { | 5413 } else { |
| 5112 uint8_t mask; | 5414 uint8_t mask; |
| 5113 uint8_t tag; | 5415 uint8_t tag; |
| 5114 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); | 5416 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5115 | 5417 |
| 5116 if (IsPowerOf2(mask)) { | 5418 if (IsPowerOf2(mask)) { |
| 5117 ASSERT(tag == 0 || IsPowerOf2(tag)); | 5419 ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5118 __ tst(scratch, Operand(mask)); | 5420 __ andi(r0, scratch, Operand(mask)); |
| 5119 DeoptimizeIf(tag == 0 ? ne : eq, instr->environment()); | 5421 DeoptimizeIf(tag == 0 ? ne : eq, instr->environment(), cr0); |
| 5120 } else { | 5422 } else { |
| 5121 __ and_(scratch, scratch, Operand(mask)); | 5423 __ andi(scratch, scratch, Operand(mask)); |
| 5122 __ cmp(scratch, Operand(tag)); | 5424 __ cmpi(scratch, Operand(tag)); |
| 5123 DeoptimizeIf(ne, instr->environment()); | 5425 DeoptimizeIf(ne, instr->environment()); |
| 5124 } | 5426 } |
| 5125 } | 5427 } |
| 5126 } | 5428 } |
| 5127 | 5429 |
| 5128 | 5430 |
| 5129 void LCodeGen::DoCheckValue(LCheckValue* instr) { | 5431 void LCodeGen::DoCheckValue(LCheckValue* instr) { |
| 5130 Register reg = ToRegister(instr->value()); | 5432 Register reg = ToRegister(instr->value()); |
| 5131 Handle<HeapObject> object = instr->hydrogen()->object().handle(); | 5433 Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
| 5132 AllowDeferredHandleDereference smi_check; | 5434 AllowDeferredHandleDereference smi_check; |
| 5133 if (isolate()->heap()->InNewSpace(*object)) { | 5435 if (isolate()->heap()->InNewSpace(*object)) { |
| 5134 Register reg = ToRegister(instr->value()); | 5436 Register reg = ToRegister(instr->value()); |
| 5135 Handle<Cell> cell = isolate()->factory()->NewCell(object); | 5437 Handle<Cell> cell = isolate()->factory()->NewCell(object); |
| 5136 __ mov(ip, Operand(Handle<Object>(cell))); | 5438 __ mov(ip, Operand(Handle<Object>(cell))); |
| 5137 __ ldr(ip, FieldMemOperand(ip, Cell::kValueOffset)); | 5439 __ LoadP(ip, FieldMemOperand(ip, Cell::kValueOffset)); |
| 5138 __ cmp(reg, ip); | 5440 __ cmp(reg, ip); |
| 5139 } else { | 5441 } else { |
| 5140 __ cmp(reg, Operand(object)); | 5442 __ Cmpi(reg, Operand(object), r0); |
| 5141 } | 5443 } |
| 5142 DeoptimizeIf(ne, instr->environment()); | 5444 DeoptimizeIf(ne, instr->environment()); |
| 5143 } | 5445 } |
| 5144 | 5446 |
| 5145 | 5447 |
| 5146 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { | 5448 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5147 { | 5449 { |
| 5148 PushSafepointRegistersScope scope(this); | 5450 PushSafepointRegistersScope scope(this); |
| 5149 __ push(object); | 5451 __ push(object); |
| 5150 __ mov(cp, Operand::Zero()); | 5452 __ li(cp, Operand::Zero()); |
| 5151 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); | 5453 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); |
| 5152 RecordSafepointWithRegisters( | 5454 RecordSafepointWithRegisters( |
| 5153 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); | 5455 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
| 5154 __ StoreToSafepointRegisterSlot(r0, scratch0()); | 5456 __ StoreToSafepointRegisterSlot(r3, scratch0()); |
| 5155 } | 5457 } |
| 5156 __ tst(scratch0(), Operand(kSmiTagMask)); | 5458 __ TestIfSmi(scratch0(), r0); |
| 5157 DeoptimizeIf(eq, instr->environment()); | 5459 DeoptimizeIf(eq, instr->environment(), cr0); |
| 5158 } | 5460 } |
| 5159 | 5461 |
| 5160 | 5462 |
| 5161 void LCodeGen::DoCheckMaps(LCheckMaps* instr) { | 5463 void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
| 5162 class DeferredCheckMaps V8_FINAL : public LDeferredCode { | 5464 class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
| 5163 public: | 5465 public: |
| 5164 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) | 5466 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
| 5165 : LDeferredCode(codegen), instr_(instr), object_(object) { | 5467 : LDeferredCode(codegen), instr_(instr), object_(object) { |
| 5166 SetExit(check_maps()); | 5468 SetExit(check_maps()); |
| 5167 } | 5469 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5183 } | 5485 } |
| 5184 return; | 5486 return; |
| 5185 } | 5487 } |
| 5186 | 5488 |
| 5187 Register map_reg = scratch0(); | 5489 Register map_reg = scratch0(); |
| 5188 | 5490 |
| 5189 LOperand* input = instr->value(); | 5491 LOperand* input = instr->value(); |
| 5190 ASSERT(input->IsRegister()); | 5492 ASSERT(input->IsRegister()); |
| 5191 Register reg = ToRegister(input); | 5493 Register reg = ToRegister(input); |
| 5192 | 5494 |
| 5193 __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); | 5495 __ LoadP(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 5194 | 5496 |
| 5195 DeferredCheckMaps* deferred = NULL; | 5497 DeferredCheckMaps* deferred = NULL; |
| 5196 if (instr->hydrogen()->HasMigrationTarget()) { | 5498 if (instr->hydrogen()->HasMigrationTarget()) { |
| 5197 deferred = new(zone()) DeferredCheckMaps(this, instr, reg); | 5499 deferred = new(zone()) DeferredCheckMaps(this, instr, reg); |
| 5198 __ bind(deferred->check_maps()); | 5500 __ bind(deferred->check_maps()); |
| 5199 } | 5501 } |
| 5200 | 5502 |
| 5201 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); | 5503 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); |
| 5202 Label success; | 5504 Label success; |
| 5203 for (int i = 0; i < maps->size() - 1; i++) { | 5505 for (int i = 0; i < maps->size() - 1; i++) { |
| 5204 Handle<Map> map = maps->at(i).handle(); | 5506 Handle<Map> map = maps->at(i).handle(); |
| 5205 __ CompareMap(map_reg, map, &success); | 5507 __ CompareMap(map_reg, map, &success); |
| 5206 __ b(eq, &success); | 5508 __ beq(&success); |
| 5207 } | 5509 } |
| 5208 | 5510 |
| 5209 Handle<Map> map = maps->at(maps->size() - 1).handle(); | 5511 Handle<Map> map = maps->at(maps->size() - 1).handle(); |
| 5210 __ CompareMap(map_reg, map, &success); | 5512 __ CompareMap(map_reg, map, &success); |
| 5211 if (instr->hydrogen()->HasMigrationTarget()) { | 5513 if (instr->hydrogen()->HasMigrationTarget()) { |
| 5212 __ b(ne, deferred->entry()); | 5514 __ bne(deferred->entry()); |
| 5213 } else { | 5515 } else { |
| 5214 DeoptimizeIf(ne, instr->environment()); | 5516 DeoptimizeIf(ne, instr->environment()); |
| 5215 } | 5517 } |
| 5216 | 5518 |
| 5217 __ bind(&success); | 5519 __ bind(&success); |
| 5218 } | 5520 } |
| 5219 | 5521 |
| 5220 | 5522 |
| 5221 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { | 5523 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 5222 DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped()); | 5524 DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
| 5223 Register result_reg = ToRegister(instr->result()); | 5525 Register result_reg = ToRegister(instr->result()); |
| 5224 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); | 5526 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); |
| 5225 } | 5527 } |
| 5226 | 5528 |
| 5227 | 5529 |
| 5228 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { | 5530 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5229 Register unclamped_reg = ToRegister(instr->unclamped()); | 5531 Register unclamped_reg = ToRegister(instr->unclamped()); |
| 5230 Register result_reg = ToRegister(instr->result()); | 5532 Register result_reg = ToRegister(instr->result()); |
| 5231 __ ClampUint8(result_reg, unclamped_reg); | 5533 __ ClampUint8(result_reg, unclamped_reg); |
| 5232 } | 5534 } |
| 5233 | 5535 |
| 5234 | 5536 |
| 5235 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { | 5537 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5236 Register scratch = scratch0(); | 5538 Register scratch = scratch0(); |
| 5237 Register input_reg = ToRegister(instr->unclamped()); | 5539 Register input_reg = ToRegister(instr->unclamped()); |
| 5238 Register result_reg = ToRegister(instr->result()); | 5540 Register result_reg = ToRegister(instr->result()); |
| 5239 DwVfpRegister temp_reg = ToDoubleRegister(instr->temp()); | 5541 DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
| 5240 Label is_smi, done, heap_number; | 5542 Label is_smi, done, heap_number; |
| 5241 | 5543 |
| 5242 // Both smi and heap number cases are handled. | 5544 // Both smi and heap number cases are handled. |
| 5243 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); | 5545 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
| 5244 | 5546 |
| 5245 // Check for heap number | 5547 // Check for heap number |
| 5246 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); | 5548 __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 5247 __ cmp(scratch, Operand(factory()->heap_number_map())); | 5549 __ Cmpi(scratch, Operand(factory()->heap_number_map()), r0); |
| 5248 __ b(eq, &heap_number); | 5550 __ beq(&heap_number); |
| 5249 | 5551 |
| 5250 // Check for undefined. Undefined is converted to zero for clamping | 5552 // Check for undefined. Undefined is converted to zero for clamping |
| 5251 // conversions. | 5553 // conversions. |
| 5252 __ cmp(input_reg, Operand(factory()->undefined_value())); | 5554 __ Cmpi(input_reg, Operand(factory()->undefined_value()), r0); |
| 5253 DeoptimizeIf(ne, instr->environment()); | 5555 DeoptimizeIf(ne, instr->environment()); |
| 5254 __ mov(result_reg, Operand::Zero()); | 5556 __ li(result_reg, Operand::Zero()); |
| 5255 __ jmp(&done); | 5557 __ b(&done); |
| 5256 | 5558 |
| 5257 // Heap number | 5559 // Heap number |
| 5258 __ bind(&heap_number); | 5560 __ bind(&heap_number); |
| 5259 __ vldr(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); | 5561 __ lfd(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 5260 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); | 5562 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); |
| 5261 __ jmp(&done); | 5563 __ b(&done); |
| 5262 | 5564 |
| 5263 // smi | 5565 // smi |
| 5264 __ bind(&is_smi); | 5566 __ bind(&is_smi); |
| 5265 __ ClampUint8(result_reg, result_reg); | 5567 __ ClampUint8(result_reg, result_reg); |
| 5266 | 5568 |
| 5267 __ bind(&done); | 5569 __ bind(&done); |
| 5268 } | 5570 } |
| 5269 | 5571 |
| 5270 | 5572 |
| 5271 void LCodeGen::DoDoubleBits(LDoubleBits* instr) { | 5573 void LCodeGen::DoDoubleBits(LDoubleBits* instr) { |
| 5272 DwVfpRegister value_reg = ToDoubleRegister(instr->value()); | 5574 DoubleRegister value_reg = ToDoubleRegister(instr->value()); |
| 5273 Register result_reg = ToRegister(instr->result()); | 5575 Register result_reg = ToRegister(instr->result()); |
| 5576 __ stfdu(value_reg, MemOperand(sp, -kDoubleSize)); |
| 5577 __ nop(); // LHS/RAW optimization |
| 5274 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { | 5578 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { |
| 5275 __ VmovHigh(result_reg, value_reg); | 5579 __ lwz(result_reg, MemOperand(sp, Register::kExponentOffset)); |
| 5276 } else { | 5580 } else { |
| 5277 __ VmovLow(result_reg, value_reg); | 5581 __ lwz(result_reg, MemOperand(sp, Register::kMantissaOffset)); |
| 5278 } | 5582 } |
| 5583 __ addi(sp, sp, Operand(kDoubleSize)); |
| 5279 } | 5584 } |
| 5280 | 5585 |
| 5281 | 5586 |
| 5282 void LCodeGen::DoConstructDouble(LConstructDouble* instr) { | 5587 void LCodeGen::DoConstructDouble(LConstructDouble* instr) { |
| 5283 Register hi_reg = ToRegister(instr->hi()); | 5588 Register hi_reg = ToRegister(instr->hi()); |
| 5284 Register lo_reg = ToRegister(instr->lo()); | 5589 Register lo_reg = ToRegister(instr->lo()); |
| 5285 DwVfpRegister result_reg = ToDoubleRegister(instr->result()); | 5590 DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 5286 __ VmovHigh(result_reg, hi_reg); | 5591 #if V8_TARGET_LITTLE_ENDIAN |
| 5287 __ VmovLow(result_reg, lo_reg); | 5592 __ stwu(hi_reg, MemOperand(sp, -kDoubleSize / 2)); |
| 5593 __ stwu(lo_reg, MemOperand(sp, -kDoubleSize / 2)); |
| 5594 #else |
| 5595 __ stwu(lo_reg, MemOperand(sp, -kDoubleSize / 2)); |
| 5596 __ stwu(hi_reg, MemOperand(sp, -kDoubleSize / 2)); |
| 5597 #endif |
| 5598 __ nop(); // LHS/RAW optimization |
| 5599 __ lfd(result_reg, MemOperand(sp)); |
| 5600 __ addi(sp, sp, Operand(kDoubleSize)); |
| 5288 } | 5601 } |
| 5289 | 5602 |
| 5290 | 5603 |
| 5291 void LCodeGen::DoAllocate(LAllocate* instr) { | 5604 void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5292 class DeferredAllocate V8_FINAL : public LDeferredCode { | 5605 class DeferredAllocate V8_FINAL : public LDeferredCode { |
| 5293 public: | 5606 public: |
| 5294 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5607 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5295 : LDeferredCode(codegen), instr_(instr) { } | 5608 : LDeferredCode(codegen), instr_(instr) { } |
| 5296 virtual void Generate() V8_OVERRIDE { | 5609 virtual void Generate() V8_OVERRIDE { |
| 5297 codegen()->DoDeferredAllocate(instr_); | 5610 codegen()->DoDeferredAllocate(instr_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5320 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { | 5633 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5321 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); | 5634 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
| 5322 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); | 5635 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
| 5323 } | 5636 } |
| 5324 | 5637 |
| 5325 if (instr->size()->IsConstantOperand()) { | 5638 if (instr->size()->IsConstantOperand()) { |
| 5326 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5639 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5327 if (size <= Page::kMaxRegularHeapObjectSize) { | 5640 if (size <= Page::kMaxRegularHeapObjectSize) { |
| 5328 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); | 5641 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
| 5329 } else { | 5642 } else { |
| 5330 __ jmp(deferred->entry()); | 5643 __ b(deferred->entry()); |
| 5331 } | 5644 } |
| 5332 } else { | 5645 } else { |
| 5333 Register size = ToRegister(instr->size()); | 5646 Register size = ToRegister(instr->size()); |
| 5334 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); | 5647 __ Allocate(size, |
| 5648 result, |
| 5649 scratch, |
| 5650 scratch2, |
| 5651 deferred->entry(), |
| 5652 flags); |
| 5335 } | 5653 } |
| 5336 | 5654 |
| 5337 __ bind(deferred->exit()); | 5655 __ bind(deferred->exit()); |
| 5338 | 5656 |
| 5339 if (instr->hydrogen()->MustPrefillWithFiller()) { | 5657 if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5340 STATIC_ASSERT(kHeapObjectTag == 1); | 5658 STATIC_ASSERT(kHeapObjectTag == 1); |
| 5341 if (instr->size()->IsConstantOperand()) { | 5659 if (instr->size()->IsConstantOperand()) { |
| 5342 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5660 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5343 __ mov(scratch, Operand(size - kHeapObjectTag)); | 5661 __ LoadIntLiteral(scratch, size - kHeapObjectTag); |
| 5344 } else { | 5662 } else { |
| 5345 __ sub(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag)); | 5663 __ subi(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag)); |
| 5346 } | 5664 } |
| 5347 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); | 5665 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 5348 Label loop; | 5666 Label loop; |
| 5349 __ bind(&loop); | 5667 __ bind(&loop); |
| 5350 __ sub(scratch, scratch, Operand(kPointerSize), SetCC); | 5668 __ subi(scratch, scratch, Operand(kPointerSize)); |
| 5351 __ str(scratch2, MemOperand(result, scratch)); | 5669 __ StorePX(scratch2, MemOperand(result, scratch)); |
| 5352 __ b(ge, &loop); | 5670 __ cmpi(scratch, Operand::Zero()); |
| 5671 __ bge(&loop); |
| 5353 } | 5672 } |
| 5354 } | 5673 } |
| 5355 | 5674 |
| 5356 | 5675 |
| 5357 void LCodeGen::DoDeferredAllocate(LAllocate* instr) { | 5676 void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
| 5358 Register result = ToRegister(instr->result()); | 5677 Register result = ToRegister(instr->result()); |
| 5359 | 5678 |
| 5360 // TODO(3095996): Get rid of this. For now, we need to make the | 5679 // TODO(3095996): Get rid of this. For now, we need to make the |
| 5361 // result register contain a valid pointer because it is already | 5680 // result register contain a valid pointer because it is already |
| 5362 // contained in the register pointer map. | 5681 // contained in the register pointer map. |
| 5363 __ mov(result, Operand(Smi::FromInt(0))); | 5682 __ LoadSmiLiteral(result, Smi::FromInt(0)); |
| 5364 | 5683 |
| 5365 PushSafepointRegistersScope scope(this); | 5684 PushSafepointRegistersScope scope(this); |
| 5366 if (instr->size()->IsRegister()) { | 5685 if (instr->size()->IsRegister()) { |
| 5367 Register size = ToRegister(instr->size()); | 5686 Register size = ToRegister(instr->size()); |
| 5368 ASSERT(!size.is(result)); | 5687 ASSERT(!size.is(result)); |
| 5369 __ SmiTag(size); | 5688 __ SmiTag(size); |
| 5370 __ push(size); | 5689 __ push(size); |
| 5371 } else { | 5690 } else { |
| 5372 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5691 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5692 #if !V8_TARGET_ARCH_PPC64 |
| 5373 if (size >= 0 && size <= Smi::kMaxValue) { | 5693 if (size >= 0 && size <= Smi::kMaxValue) { |
| 5694 #endif |
| 5374 __ Push(Smi::FromInt(size)); | 5695 __ Push(Smi::FromInt(size)); |
| 5696 #if !V8_TARGET_ARCH_PPC64 |
| 5375 } else { | 5697 } else { |
| 5376 // We should never get here at runtime => abort | 5698 // We should never get here at runtime => abort |
| 5377 __ stop("invalid allocation size"); | 5699 __ stop("invalid allocation size"); |
| 5378 return; | 5700 return; |
| 5379 } | 5701 } |
| 5702 #endif |
| 5380 } | 5703 } |
| 5381 | 5704 |
| 5382 int flags = AllocateDoubleAlignFlag::encode( | 5705 int flags = AllocateDoubleAlignFlag::encode( |
| 5383 instr->hydrogen()->MustAllocateDoubleAligned()); | 5706 instr->hydrogen()->MustAllocateDoubleAligned()); |
| 5384 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { | 5707 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5385 ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); | 5708 ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5386 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); | 5709 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
| 5387 flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); | 5710 flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
| 5388 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { | 5711 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5389 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); | 5712 ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
| 5390 flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); | 5713 flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
| 5391 } else { | 5714 } else { |
| 5392 flags = AllocateTargetSpace::update(flags, NEW_SPACE); | 5715 flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
| 5393 } | 5716 } |
| 5394 __ Push(Smi::FromInt(flags)); | 5717 __ Push(Smi::FromInt(flags)); |
| 5395 | 5718 |
| 5396 CallRuntimeFromDeferred( | 5719 CallRuntimeFromDeferred( |
| 5397 Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); | 5720 Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); |
| 5398 __ StoreToSafepointRegisterSlot(r0, result); | 5721 __ StoreToSafepointRegisterSlot(r3, result); |
| 5399 } | 5722 } |
| 5400 | 5723 |
| 5401 | 5724 |
| 5402 void LCodeGen::DoToFastProperties(LToFastProperties* instr) { | 5725 void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
| 5403 ASSERT(ToRegister(instr->value()).is(r0)); | 5726 ASSERT(ToRegister(instr->value()).is(r3)); |
| 5404 __ push(r0); | 5727 __ push(r3); |
| 5405 CallRuntime(Runtime::kToFastProperties, 1, instr); | 5728 CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5406 } | 5729 } |
| 5407 | 5730 |
| 5408 | 5731 |
| 5409 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { | 5732 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
| 5410 ASSERT(ToRegister(instr->context()).is(cp)); | 5733 ASSERT(ToRegister(instr->context()).is(cp)); |
| 5411 Label materialized; | 5734 Label materialized; |
| 5412 // Registers will be used as follows: | 5735 // Registers will be used as follows: |
| 5413 // r6 = literals array. | 5736 // r10 = literals array. |
| 5414 // r1 = regexp literal. | 5737 // r4 = regexp literal. |
| 5415 // r0 = regexp literal clone. | 5738 // r3 = regexp literal clone. |
| 5416 // r2-5 are used as temporaries. | 5739 // r5 and r7-r9 are used as temporaries. |
| 5417 int literal_offset = | 5740 int literal_offset = |
| 5418 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); | 5741 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
| 5419 __ Move(r6, instr->hydrogen()->literals()); | 5742 __ Move(r10, instr->hydrogen()->literals()); |
| 5420 __ ldr(r1, FieldMemOperand(r6, literal_offset)); | 5743 __ LoadP(r4, FieldMemOperand(r10, literal_offset)); |
| 5421 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5744 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5422 __ cmp(r1, ip); | 5745 __ cmp(r4, ip); |
| 5423 __ b(ne, &materialized); | 5746 __ bne(&materialized); |
| 5424 | 5747 |
| 5425 // Create regexp literal using runtime function | 5748 // Create regexp literal using runtime function |
| 5426 // Result will be in r0. | 5749 // Result will be in r3. |
| 5427 __ mov(r5, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); | 5750 __ LoadSmiLiteral(r9, Smi::FromInt(instr->hydrogen()->literal_index())); |
| 5428 __ mov(r4, Operand(instr->hydrogen()->pattern())); | 5751 __ mov(r8, Operand(instr->hydrogen()->pattern())); |
| 5429 __ mov(r3, Operand(instr->hydrogen()->flags())); | 5752 __ mov(r7, Operand(instr->hydrogen()->flags())); |
| 5430 __ Push(r6, r5, r4, r3); | 5753 __ Push(r10, r9, r8, r7); |
| 5431 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); | 5754 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 5432 __ mov(r1, r0); | 5755 __ mr(r4, r3); |
| 5433 | 5756 |
| 5434 __ bind(&materialized); | 5757 __ bind(&materialized); |
| 5435 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; | 5758 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5436 Label allocated, runtime_allocate; | 5759 Label allocated, runtime_allocate; |
| 5437 | 5760 |
| 5438 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); | 5761 __ Allocate(size, r3, r5, r6, &runtime_allocate, TAG_OBJECT); |
| 5439 __ jmp(&allocated); | 5762 __ b(&allocated); |
| 5440 | 5763 |
| 5441 __ bind(&runtime_allocate); | 5764 __ bind(&runtime_allocate); |
| 5442 __ mov(r0, Operand(Smi::FromInt(size))); | 5765 __ LoadSmiLiteral(r3, Smi::FromInt(size)); |
| 5443 __ Push(r1, r0); | 5766 __ Push(r4, r3); |
| 5444 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 5767 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 5445 __ pop(r1); | 5768 __ pop(r4); |
| 5446 | 5769 |
| 5447 __ bind(&allocated); | 5770 __ bind(&allocated); |
| 5448 // Copy the content into the newly allocated memory. | 5771 // Copy the content into the newly allocated memory. |
| 5449 __ CopyFields(r0, r1, double_scratch0(), size / kPointerSize); | 5772 __ CopyFields(r3, r4, r5.bit(), size / kPointerSize); |
| 5450 } | 5773 } |
| 5451 | 5774 |
| 5452 | 5775 |
| 5453 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { | 5776 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
| 5454 ASSERT(ToRegister(instr->context()).is(cp)); | 5777 ASSERT(ToRegister(instr->context()).is(cp)); |
| 5455 // Use the fast case closure allocation code that allocates in new | 5778 // Use the fast case closure allocation code that allocates in new |
| 5456 // space for nested functions that don't need literals cloning. | 5779 // space for nested functions that don't need literals cloning. |
| 5457 bool pretenure = instr->hydrogen()->pretenure(); | 5780 bool pretenure = instr->hydrogen()->pretenure(); |
| 5458 if (!pretenure && instr->hydrogen()->has_no_literals()) { | 5781 if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 5459 FastNewClosureStub stub(isolate(), | 5782 FastNewClosureStub stub(isolate(), |
| 5460 instr->hydrogen()->strict_mode(), | 5783 instr->hydrogen()->strict_mode(), |
| 5461 instr->hydrogen()->is_generator()); | 5784 instr->hydrogen()->is_generator()); |
| 5462 __ mov(r2, Operand(instr->hydrogen()->shared_info())); | 5785 __ mov(r5, Operand(instr->hydrogen()->shared_info())); |
| 5463 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 5786 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 5464 } else { | 5787 } else { |
| 5465 __ mov(r2, Operand(instr->hydrogen()->shared_info())); | 5788 __ mov(r5, Operand(instr->hydrogen()->shared_info())); |
| 5466 __ mov(r1, Operand(pretenure ? factory()->true_value() | 5789 __ mov(r4, Operand(pretenure ? factory()->true_value() |
| 5467 : factory()->false_value())); | 5790 : factory()->false_value())); |
| 5468 __ Push(cp, r2, r1); | 5791 __ Push(cp, r5, r4); |
| 5469 CallRuntime(Runtime::kNewClosure, 3, instr); | 5792 CallRuntime(Runtime::kNewClosure, 3, instr); |
| 5470 } | 5793 } |
| 5471 } | 5794 } |
| 5472 | 5795 |
| 5473 | 5796 |
| 5474 void LCodeGen::DoTypeof(LTypeof* instr) { | 5797 void LCodeGen::DoTypeof(LTypeof* instr) { |
| 5475 Register input = ToRegister(instr->value()); | 5798 Register input = ToRegister(instr->value()); |
| 5476 __ push(input); | 5799 __ push(input); |
| 5477 CallRuntime(Runtime::kTypeof, 1, instr); | 5800 CallRuntime(Runtime::kTypeof, 1, instr); |
| 5478 } | 5801 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5493 | 5816 |
| 5494 Condition LCodeGen::EmitTypeofIs(Label* true_label, | 5817 Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 5495 Label* false_label, | 5818 Label* false_label, |
| 5496 Register input, | 5819 Register input, |
| 5497 Handle<String> type_name) { | 5820 Handle<String> type_name) { |
| 5498 Condition final_branch_condition = kNoCondition; | 5821 Condition final_branch_condition = kNoCondition; |
| 5499 Register scratch = scratch0(); | 5822 Register scratch = scratch0(); |
| 5500 Factory* factory = isolate()->factory(); | 5823 Factory* factory = isolate()->factory(); |
| 5501 if (String::Equals(type_name, factory->number_string())) { | 5824 if (String::Equals(type_name, factory->number_string())) { |
| 5502 __ JumpIfSmi(input, true_label); | 5825 __ JumpIfSmi(input, true_label); |
| 5503 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5826 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5504 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); | 5827 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 5505 final_branch_condition = eq; | 5828 final_branch_condition = eq; |
| 5506 | 5829 |
| 5507 } else if (String::Equals(type_name, factory->string_string())) { | 5830 } else if (String::Equals(type_name, factory->string_string())) { |
| 5508 __ JumpIfSmi(input, false_label); | 5831 __ JumpIfSmi(input, false_label); |
| 5509 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); | 5832 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); |
| 5510 __ b(ge, false_label); | 5833 __ bge(false_label); |
| 5511 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | 5834 __ lbz(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5512 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5835 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5836 __ cmpi(r0, Operand::Zero()); |
| 5513 final_branch_condition = eq; | 5837 final_branch_condition = eq; |
| 5514 | 5838 |
| 5515 } else if (String::Equals(type_name, factory->symbol_string())) { | 5839 } else if (String::Equals(type_name, factory->symbol_string())) { |
| 5516 __ JumpIfSmi(input, false_label); | 5840 __ JumpIfSmi(input, false_label); |
| 5517 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); | 5841 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); |
| 5518 final_branch_condition = eq; | 5842 final_branch_condition = eq; |
| 5519 | 5843 |
| 5520 } else if (String::Equals(type_name, factory->boolean_string())) { | 5844 } else if (String::Equals(type_name, factory->boolean_string())) { |
| 5521 __ CompareRoot(input, Heap::kTrueValueRootIndex); | 5845 __ CompareRoot(input, Heap::kTrueValueRootIndex); |
| 5522 __ b(eq, true_label); | 5846 __ beq(true_label); |
| 5523 __ CompareRoot(input, Heap::kFalseValueRootIndex); | 5847 __ CompareRoot(input, Heap::kFalseValueRootIndex); |
| 5524 final_branch_condition = eq; | 5848 final_branch_condition = eq; |
| 5525 | 5849 |
| 5526 } else if (String::Equals(type_name, factory->undefined_string())) { | 5850 } else if (String::Equals(type_name, factory->undefined_string())) { |
| 5527 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); | 5851 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
| 5528 __ b(eq, true_label); | 5852 __ beq(true_label); |
| 5529 __ JumpIfSmi(input, false_label); | 5853 __ JumpIfSmi(input, false_label); |
| 5530 // Check for undetectable objects => true. | 5854 // Check for undetectable objects => true. |
| 5531 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5855 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5532 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | 5856 __ lbz(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5533 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5857 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5858 __ cmpi(r0, Operand::Zero()); |
| 5534 final_branch_condition = ne; | 5859 final_branch_condition = ne; |
| 5535 | 5860 |
| 5536 } else if (String::Equals(type_name, factory->function_string())) { | 5861 } else if (String::Equals(type_name, factory->function_string())) { |
| 5537 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | 5862 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 5538 Register type_reg = scratch; | 5863 Register type_reg = scratch; |
| 5539 __ JumpIfSmi(input, false_label); | 5864 __ JumpIfSmi(input, false_label); |
| 5540 __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE); | 5865 __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE); |
| 5541 __ b(eq, true_label); | 5866 __ beq(true_label); |
| 5542 __ cmp(type_reg, Operand(JS_FUNCTION_PROXY_TYPE)); | 5867 __ cmpi(type_reg, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5543 final_branch_condition = eq; | 5868 final_branch_condition = eq; |
| 5544 | 5869 |
| 5545 } else if (String::Equals(type_name, factory->object_string())) { | 5870 } else if (String::Equals(type_name, factory->object_string())) { |
| 5546 Register map = scratch; | 5871 Register map = scratch; |
| 5547 __ JumpIfSmi(input, false_label); | 5872 __ JumpIfSmi(input, false_label); |
| 5548 __ CompareRoot(input, Heap::kNullValueRootIndex); | 5873 __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5549 __ b(eq, true_label); | 5874 __ beq(true_label); |
| 5550 __ CheckObjectTypeRange(input, | 5875 __ CheckObjectTypeRange(input, |
| 5551 map, | 5876 map, |
| 5552 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, | 5877 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 5553 LAST_NONCALLABLE_SPEC_OBJECT_TYPE, | 5878 LAST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 5554 false_label); | 5879 false_label); |
| 5555 // Check for undetectable objects => false. | 5880 // Check for undetectable objects => false. |
| 5556 __ ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); | 5881 __ lbz(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 5557 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5882 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5883 __ cmpi(r0, Operand::Zero()); |
| 5558 final_branch_condition = eq; | 5884 final_branch_condition = eq; |
| 5559 | 5885 |
| 5560 } else { | 5886 } else { |
| 5561 __ b(false_label); | 5887 __ b(false_label); |
| 5562 } | 5888 } |
| 5563 | 5889 |
| 5564 return final_branch_condition; | 5890 return final_branch_condition; |
| 5565 } | 5891 } |
| 5566 | 5892 |
| 5567 | 5893 |
| 5568 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { | 5894 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
| 5569 Register temp1 = ToRegister(instr->temp()); | 5895 Register temp1 = ToRegister(instr->temp()); |
| 5570 | 5896 |
| 5571 EmitIsConstructCall(temp1, scratch0()); | 5897 EmitIsConstructCall(temp1, scratch0()); |
| 5572 EmitBranch(instr, eq); | 5898 EmitBranch(instr, eq); |
| 5573 } | 5899 } |
| 5574 | 5900 |
| 5575 | 5901 |
| 5576 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { | 5902 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 5577 ASSERT(!temp1.is(temp2)); | 5903 ASSERT(!temp1.is(temp2)); |
| 5578 // Get the frame pointer for the calling frame. | 5904 // Get the frame pointer for the calling frame. |
| 5579 __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 5905 __ LoadP(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5580 | 5906 |
| 5581 // Skip the arguments adaptor frame if it exists. | 5907 // Skip the arguments adaptor frame if it exists. |
| 5582 __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); | 5908 Label check_frame_marker; |
| 5583 __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | 5909 __ LoadP(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 5584 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset), eq); | 5910 __ CmpSmiLiteral(temp2, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
| 5911 __ bne(&check_frame_marker); |
| 5912 __ LoadP(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
| 5585 | 5913 |
| 5586 // Check the marker in the calling frame. | 5914 // Check the marker in the calling frame. |
| 5587 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); | 5915 __ bind(&check_frame_marker); |
| 5588 __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); | 5916 __ LoadP(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5917 __ CmpSmiLiteral(temp1, Smi::FromInt(StackFrame::CONSTRUCT), r0); |
| 5589 } | 5918 } |
| 5590 | 5919 |
| 5591 | 5920 |
| 5592 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { | 5921 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
| 5593 if (!info()->IsStub()) { | 5922 if (!info()->IsStub()) { |
| 5594 // Ensure that we have enough space after the previous lazy-bailout | 5923 // Ensure that we have enough space after the previous lazy-bailout |
| 5595 // instruction for patching the code here. | 5924 // instruction for patching the code here. |
| 5596 int current_pc = masm()->pc_offset(); | 5925 int current_pc = masm()->pc_offset(); |
| 5597 if (current_pc < last_lazy_deopt_pc_ + space_needed) { | 5926 if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 5598 // Block literal pool emission for duration of padding. | |
| 5599 Assembler::BlockConstPoolScope block_const_pool(masm()); | |
| 5600 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 5927 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 5601 ASSERT_EQ(0, padding_size % Assembler::kInstrSize); | 5928 ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 5602 while (padding_size > 0) { | 5929 while (padding_size > 0) { |
| 5603 __ nop(); | 5930 __ nop(); |
| 5604 padding_size -= Assembler::kInstrSize; | 5931 padding_size -= Assembler::kInstrSize; |
| 5605 } | 5932 } |
| 5606 } | 5933 } |
| 5607 } | 5934 } |
| 5608 last_lazy_deopt_pc_ = masm()->pc_offset(); | 5935 last_lazy_deopt_pc_ = masm()->pc_offset(); |
| 5609 } | 5936 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5669 }; | 5996 }; |
| 5670 | 5997 |
| 5671 ASSERT(instr->HasEnvironment()); | 5998 ASSERT(instr->HasEnvironment()); |
| 5672 LEnvironment* env = instr->environment(); | 5999 LEnvironment* env = instr->environment(); |
| 5673 // There is no LLazyBailout instruction for stack-checks. We have to | 6000 // There is no LLazyBailout instruction for stack-checks. We have to |
| 5674 // prepare for lazy deoptimization explicitly here. | 6001 // prepare for lazy deoptimization explicitly here. |
| 5675 if (instr->hydrogen()->is_function_entry()) { | 6002 if (instr->hydrogen()->is_function_entry()) { |
| 5676 // Perform stack overflow check. | 6003 // Perform stack overflow check. |
| 5677 Label done; | 6004 Label done; |
| 5678 __ LoadRoot(ip, Heap::kStackLimitRootIndex); | 6005 __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5679 __ cmp(sp, Operand(ip)); | 6006 __ cmpl(sp, ip); |
| 5680 __ b(hs, &done); | 6007 __ bge(&done); |
| 5681 Handle<Code> stack_check = isolate()->builtins()->StackCheck(); | |
| 5682 PredictableCodeSizeScope predictable(masm(), | |
| 5683 CallCodeSize(stack_check, RelocInfo::CODE_TARGET)); | |
| 5684 ASSERT(instr->context()->IsRegister()); | 6008 ASSERT(instr->context()->IsRegister()); |
| 5685 ASSERT(ToRegister(instr->context()).is(cp)); | 6009 ASSERT(ToRegister(instr->context()).is(cp)); |
| 5686 CallCode(stack_check, RelocInfo::CODE_TARGET, instr); | 6010 CallCode(isolate()->builtins()->StackCheck(), |
| 6011 RelocInfo::CODE_TARGET, |
| 6012 instr); |
| 5687 __ bind(&done); | 6013 __ bind(&done); |
| 5688 } else { | 6014 } else { |
| 5689 ASSERT(instr->hydrogen()->is_backwards_branch()); | 6015 ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5690 // Perform stack overflow check if this goto needs it before jumping. | 6016 // Perform stack overflow check if this goto needs it before jumping. |
| 5691 DeferredStackCheck* deferred_stack_check = | 6017 DeferredStackCheck* deferred_stack_check = |
| 5692 new(zone()) DeferredStackCheck(this, instr); | 6018 new(zone()) DeferredStackCheck(this, instr); |
| 5693 __ LoadRoot(ip, Heap::kStackLimitRootIndex); | 6019 __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5694 __ cmp(sp, Operand(ip)); | 6020 __ cmpl(sp, ip); |
| 5695 __ b(lo, deferred_stack_check->entry()); | 6021 __ blt(deferred_stack_check->entry()); |
| 5696 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | 6022 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 5697 __ bind(instr->done_label()); | 6023 __ bind(instr->done_label()); |
| 5698 deferred_stack_check->SetExit(instr->done_label()); | 6024 deferred_stack_check->SetExit(instr->done_label()); |
| 5699 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); | 6025 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5700 // Don't record a deoptimization index for the safepoint here. | 6026 // Don't record a deoptimization index for the safepoint here. |
| 5701 // This will be done explicitly when emitting call and the safepoint in | 6027 // This will be done explicitly when emitting call and the safepoint in |
| 5702 // the deferred code. | 6028 // the deferred code. |
| 5703 } | 6029 } |
| 5704 } | 6030 } |
| 5705 | 6031 |
| 5706 | 6032 |
| 5707 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 6033 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 5708 // This is a pseudo-instruction that ensures that the environment here is | 6034 // This is a pseudo-instruction that ensures that the environment here is |
| 5709 // properly registered for deoptimization and records the assembler's PC | 6035 // properly registered for deoptimization and records the assembler's PC |
| 5710 // offset. | 6036 // offset. |
| 5711 LEnvironment* environment = instr->environment(); | 6037 LEnvironment* environment = instr->environment(); |
| 5712 | 6038 |
| 5713 // If the environment were already registered, we would have no way of | 6039 // If the environment were already registered, we would have no way of |
| 5714 // backpatching it with the spill slot operands. | 6040 // backpatching it with the spill slot operands. |
| 5715 ASSERT(!environment->HasBeenRegistered()); | 6041 ASSERT(!environment->HasBeenRegistered()); |
| 5716 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 6042 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 5717 | 6043 |
| 5718 GenerateOsrPrologue(); | 6044 GenerateOsrPrologue(); |
| 5719 } | 6045 } |
| 5720 | 6046 |
| 5721 | 6047 |
| 5722 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { | 6048 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5723 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 6049 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5724 __ cmp(r0, ip); | 6050 __ cmp(r3, ip); |
| 5725 DeoptimizeIf(eq, instr->environment()); | 6051 DeoptimizeIf(eq, instr->environment()); |
| 5726 | 6052 |
| 5727 Register null_value = r5; | 6053 Register null_value = r8; |
| 5728 __ LoadRoot(null_value, Heap::kNullValueRootIndex); | 6054 __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 5729 __ cmp(r0, null_value); | 6055 __ cmp(r3, null_value); |
| 5730 DeoptimizeIf(eq, instr->environment()); | 6056 DeoptimizeIf(eq, instr->environment()); |
| 5731 | 6057 |
| 5732 __ SmiTst(r0); | 6058 __ TestIfSmi(r3, r0); |
| 5733 DeoptimizeIf(eq, instr->environment()); | 6059 DeoptimizeIf(eq, instr->environment(), cr0); |
| 5734 | 6060 |
| 5735 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | 6061 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5736 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); | 6062 __ CompareObjectType(r3, r4, r4, LAST_JS_PROXY_TYPE); |
| 5737 DeoptimizeIf(le, instr->environment()); | 6063 DeoptimizeIf(le, instr->environment()); |
| 5738 | 6064 |
| 5739 Label use_cache, call_runtime; | 6065 Label use_cache, call_runtime; |
| 5740 __ CheckEnumCache(null_value, &call_runtime); | 6066 __ CheckEnumCache(null_value, &call_runtime); |
| 5741 | 6067 |
| 5742 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); | 6068 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5743 __ b(&use_cache); | 6069 __ b(&use_cache); |
| 5744 | 6070 |
| 5745 // Get the set of properties to enumerate. | 6071 // Get the set of properties to enumerate. |
| 5746 __ bind(&call_runtime); | 6072 __ bind(&call_runtime); |
| 5747 __ push(r0); | 6073 __ push(r3); |
| 5748 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); | 6074 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5749 | 6075 |
| 5750 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); | 6076 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5751 __ LoadRoot(ip, Heap::kMetaMapRootIndex); | 6077 __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 5752 __ cmp(r1, ip); | 6078 __ cmp(r4, ip); |
| 5753 DeoptimizeIf(ne, instr->environment()); | 6079 DeoptimizeIf(ne, instr->environment()); |
| 5754 __ bind(&use_cache); | 6080 __ bind(&use_cache); |
| 5755 } | 6081 } |
| 5756 | 6082 |
| 5757 | 6083 |
| 5758 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { | 6084 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5759 Register map = ToRegister(instr->map()); | 6085 Register map = ToRegister(instr->map()); |
| 5760 Register result = ToRegister(instr->result()); | 6086 Register result = ToRegister(instr->result()); |
| 5761 Label load_cache, done; | 6087 Label load_cache, done; |
| 5762 __ EnumLength(result, map); | 6088 __ EnumLength(result, map); |
| 5763 __ cmp(result, Operand(Smi::FromInt(0))); | 6089 __ CmpSmiLiteral(result, Smi::FromInt(0), r0); |
| 5764 __ b(ne, &load_cache); | 6090 __ bne(&load_cache); |
| 5765 __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); | 6091 __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5766 __ jmp(&done); | 6092 __ b(&done); |
| 5767 | 6093 |
| 5768 __ bind(&load_cache); | 6094 __ bind(&load_cache); |
| 5769 __ LoadInstanceDescriptors(map, result); | 6095 __ LoadInstanceDescriptors(map, result); |
| 5770 __ ldr(result, | 6096 __ LoadP(result, |
| 5771 FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); | 6097 FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
| 5772 __ ldr(result, | 6098 __ LoadP(result, |
| 5773 FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); | 6099 FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
| 5774 __ cmp(result, Operand::Zero()); | 6100 __ cmpi(result, Operand::Zero()); |
| 5775 DeoptimizeIf(eq, instr->environment()); | 6101 DeoptimizeIf(eq, instr->environment()); |
| 5776 | 6102 |
| 5777 __ bind(&done); | 6103 __ bind(&done); |
| 5778 } | 6104 } |
| 5779 | 6105 |
| 5780 | 6106 |
| 5781 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { | 6107 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5782 Register object = ToRegister(instr->value()); | 6108 Register object = ToRegister(instr->value()); |
| 5783 Register map = ToRegister(instr->map()); | 6109 Register map = ToRegister(instr->map()); |
| 5784 __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); | 6110 __ LoadP(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5785 __ cmp(map, scratch0()); | 6111 __ cmp(map, scratch0()); |
| 5786 DeoptimizeIf(ne, instr->environment()); | 6112 DeoptimizeIf(ne, instr->environment()); |
| 5787 } | 6113 } |
| 5788 | 6114 |
| 5789 | 6115 |
| 5790 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, | 6116 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
| 5791 Register result, | 6117 Register result, |
| 5792 Register object, | 6118 Register object, |
| 5793 Register index) { | 6119 Register index) { |
| 5794 PushSafepointRegistersScope scope(this); | 6120 PushSafepointRegistersScope scope(this); |
| 5795 __ Push(object); | 6121 __ Push(object, index); |
| 5796 __ Push(index); | 6122 __ li(cp, Operand::Zero()); |
| 5797 __ mov(cp, Operand::Zero()); | |
| 5798 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); | 6123 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); |
| 5799 RecordSafepointWithRegisters( | 6124 RecordSafepointWithRegisters( |
| 5800 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); | 6125 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); |
| 5801 __ StoreToSafepointRegisterSlot(r0, result); | 6126 __ StoreToSafepointRegisterSlot(r3, result); |
| 5802 } | 6127 } |
| 5803 | 6128 |
| 5804 | 6129 |
| 5805 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { | 6130 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5806 class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { | 6131 class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { |
| 5807 public: | 6132 public: |
| 5808 DeferredLoadMutableDouble(LCodeGen* codegen, | 6133 DeferredLoadMutableDouble(LCodeGen* codegen, |
| 5809 LLoadFieldByIndex* instr, | 6134 LLoadFieldByIndex* instr, |
| 5810 Register result, | 6135 Register result, |
| 5811 Register object, | 6136 Register object, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5831 Register index = ToRegister(instr->index()); | 6156 Register index = ToRegister(instr->index()); |
| 5832 Register result = ToRegister(instr->result()); | 6157 Register result = ToRegister(instr->result()); |
| 5833 Register scratch = scratch0(); | 6158 Register scratch = scratch0(); |
| 5834 | 6159 |
| 5835 DeferredLoadMutableDouble* deferred; | 6160 DeferredLoadMutableDouble* deferred; |
| 5836 deferred = new(zone()) DeferredLoadMutableDouble( | 6161 deferred = new(zone()) DeferredLoadMutableDouble( |
| 5837 this, instr, result, object, index); | 6162 this, instr, result, object, index); |
| 5838 | 6163 |
| 5839 Label out_of_object, done; | 6164 Label out_of_object, done; |
| 5840 | 6165 |
| 5841 __ tst(index, Operand(Smi::FromInt(1))); | 6166 __ TestBitMask(index, reinterpret_cast<uintptr_t>(Smi::FromInt(1)), r0); |
| 5842 __ b(ne, deferred->entry()); | 6167 __ bne(deferred->entry(), cr0); |
| 5843 __ mov(index, Operand(index, ASR, 1)); | 6168 __ ShiftRightArithImm(index, index, 1); |
| 5844 | 6169 |
| 5845 __ cmp(index, Operand::Zero()); | 6170 __ cmpi(index, Operand::Zero()); |
| 5846 __ b(lt, &out_of_object); | 6171 __ blt(&out_of_object); |
| 5847 | 6172 |
| 5848 __ add(scratch, object, Operand::PointerOffsetFromSmiKey(index)); | 6173 __ SmiToPtrArrayOffset(r0, index); |
| 5849 __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); | 6174 __ add(scratch, object, r0); |
| 6175 __ LoadP(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5850 | 6176 |
| 5851 __ b(&done); | 6177 __ b(&done); |
| 5852 | 6178 |
| 5853 __ bind(&out_of_object); | 6179 __ bind(&out_of_object); |
| 5854 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 6180 __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5855 // Index is equal to negated out of object property index plus 1. | 6181 // Index is equal to negated out of object property index plus 1. |
| 5856 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); | 6182 __ SmiToPtrArrayOffset(r0, index); |
| 5857 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 6183 __ sub(scratch, result, r0); |
| 5858 __ ldr(result, FieldMemOperand(scratch, | 6184 __ LoadP(result, FieldMemOperand(scratch, |
| 5859 FixedArray::kHeaderSize - kPointerSize)); | 6185 FixedArray::kHeaderSize - kPointerSize)); |
| 5860 __ bind(deferred->exit()); | 6186 __ bind(deferred->exit()); |
| 5861 __ bind(&done); | 6187 __ bind(&done); |
| 5862 } | 6188 } |
| 5863 | 6189 |
| 5864 | 6190 |
| 5865 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) { | 6191 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) { |
| 5866 Register context = ToRegister(instr->context()); | 6192 Register context = ToRegister(instr->context()); |
| 5867 __ str(context, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 6193 __ StoreP(context, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 5868 } | 6194 } |
| 5869 | 6195 |
| 5870 | 6196 |
| 5871 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) { | 6197 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) { |
| 5872 Handle<ScopeInfo> scope_info = instr->scope_info(); | 6198 Handle<ScopeInfo> scope_info = instr->scope_info(); |
| 5873 __ Push(scope_info); | 6199 __ Push(scope_info); |
| 5874 __ push(ToRegister(instr->function())); | 6200 __ push(ToRegister(instr->function())); |
| 5875 CallRuntime(Runtime::kPushBlockContext, 2, instr); | 6201 CallRuntime(Runtime::kPushBlockContext, 2, instr); |
| 5876 RecordSafepoint(Safepoint::kNoLazyDeopt); | 6202 RecordSafepoint(Safepoint::kNoLazyDeopt); |
| 5877 } | 6203 } |
| 5878 | 6204 |
| 5879 | 6205 |
| 5880 #undef __ | 6206 #undef __ |
| 5881 | 6207 |
| 5882 } } // namespace v8::internal | 6208 } } // namespace v8::internal |
| OLD | NEW |