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, LPointerMap* pointers, |
20 LPointerMap* pointers, | |
21 Safepoint::DeoptMode mode) | 24 Safepoint::DeoptMode mode) |
22 : codegen_(codegen), | 25 : codegen_(codegen), pointers_(pointers), deopt_mode_(mode) {} |
23 pointers_(pointers), | |
24 deopt_mode_(mode) { } | |
25 virtual ~SafepointGenerator() {} | 26 virtual ~SafepointGenerator() {} |
26 | 27 |
27 virtual void BeforeCall(int call_size) const V8_OVERRIDE {} | 28 virtual void BeforeCall(int call_size) const V8_OVERRIDE {} |
28 | 29 |
29 virtual void AfterCall() const V8_OVERRIDE { | 30 virtual void AfterCall() const V8_OVERRIDE { |
30 codegen_->RecordSafepoint(pointers_, deopt_mode_); | 31 codegen_->RecordSafepoint(pointers_, deopt_mode_); |
31 } | 32 } |
32 | 33 |
33 private: | 34 private: |
34 LCodeGen* codegen_; | 35 LCodeGen* codegen_; |
35 LPointerMap* pointers_; | 36 LPointerMap* pointers_; |
36 Safepoint::DeoptMode deopt_mode_; | 37 Safepoint::DeoptMode deopt_mode_; |
37 }; | 38 }; |
38 | 39 |
39 | 40 |
40 #define __ masm()-> | 41 #define __ masm()-> |
41 | 42 |
42 bool LCodeGen::GenerateCode() { | 43 bool LCodeGen::GenerateCode() { |
43 LPhase phase("Z_Code generation", chunk()); | 44 LPhase phase("Z_Code generation", chunk()); |
44 DCHECK(is_unused()); | 45 DCHECK(is_unused()); |
45 status_ = GENERATING; | 46 status_ = GENERATING; |
46 | 47 |
47 // Open a frame scope to indicate that there is a frame on the stack. The | 48 // Open a frame scope to indicate that there is a frame on the stack. The |
48 // NONE indicates that the scope shouldn't actually generate code to set up | 49 // NONE indicates that the scope shouldn't actually generate code to set up |
49 // the frame (that is done in GeneratePrologue). | 50 // the frame (that is done in GeneratePrologue). |
50 FrameScope frame_scope(masm_, StackFrame::NONE); | 51 FrameScope frame_scope(masm_, StackFrame::NONE); |
51 | 52 |
52 return GeneratePrologue() && | 53 return GeneratePrologue() && GenerateBody() && GenerateDeferredCode() && |
53 GenerateBody() && | 54 GenerateDeoptJumpTable() && GenerateSafepointTable(); |
54 GenerateDeferredCode() && | |
55 GenerateDeoptJumpTable() && | |
56 GenerateSafepointTable(); | |
57 } | 55 } |
58 | 56 |
59 | 57 |
60 void LCodeGen::FinishCode(Handle<Code> code) { | 58 void LCodeGen::FinishCode(Handle<Code> code) { |
61 DCHECK(is_done()); | 59 DCHECK(is_done()); |
62 code->set_stack_slots(GetStackSlotCount()); | 60 code->set_stack_slots(GetStackSlotCount()); |
63 code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); | 61 code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
64 if (code->is_optimized_code()) RegisterWeakObjectsInOptimizedCode(code); | 62 if (code->is_optimized_code()) RegisterWeakObjectsInOptimizedCode(code); |
65 PopulateDeoptimizationData(code); | 63 PopulateDeoptimizationData(code); |
66 } | 64 } |
67 | 65 |
68 | 66 |
69 void LCodeGen::SaveCallerDoubles() { | 67 void LCodeGen::SaveCallerDoubles() { |
70 DCHECK(info()->saves_caller_doubles()); | 68 DCHECK(info()->saves_caller_doubles()); |
71 DCHECK(NeedsEagerFrame()); | 69 DCHECK(NeedsEagerFrame()); |
72 Comment(";;; Save clobbered callee double registers"); | 70 Comment(";;; Save clobbered callee double registers"); |
73 int count = 0; | 71 int count = 0; |
74 BitVector* doubles = chunk()->allocated_double_registers(); | 72 BitVector* doubles = chunk()->allocated_double_registers(); |
75 BitVector::Iterator save_iterator(doubles); | 73 BitVector::Iterator save_iterator(doubles); |
76 while (!save_iterator.Done()) { | 74 while (!save_iterator.Done()) { |
77 __ vstr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), | 75 __ stfd(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
78 MemOperand(sp, count * kDoubleSize)); | 76 MemOperand(sp, count * kDoubleSize)); |
79 save_iterator.Advance(); | 77 save_iterator.Advance(); |
80 count++; | 78 count++; |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 | 82 |
85 void LCodeGen::RestoreCallerDoubles() { | 83 void LCodeGen::RestoreCallerDoubles() { |
86 DCHECK(info()->saves_caller_doubles()); | 84 DCHECK(info()->saves_caller_doubles()); |
87 DCHECK(NeedsEagerFrame()); | 85 DCHECK(NeedsEagerFrame()); |
88 Comment(";;; Restore clobbered callee double registers"); | 86 Comment(";;; Restore clobbered callee double registers"); |
89 BitVector* doubles = chunk()->allocated_double_registers(); | 87 BitVector* doubles = chunk()->allocated_double_registers(); |
90 BitVector::Iterator save_iterator(doubles); | 88 BitVector::Iterator save_iterator(doubles); |
91 int count = 0; | 89 int count = 0; |
92 while (!save_iterator.Done()) { | 90 while (!save_iterator.Done()) { |
93 __ vldr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), | 91 __ lfd(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
94 MemOperand(sp, count * kDoubleSize)); | 92 MemOperand(sp, count * kDoubleSize)); |
95 save_iterator.Advance(); | 93 save_iterator.Advance(); |
96 count++; | 94 count++; |
97 } | 95 } |
98 } | 96 } |
99 | 97 |
100 | 98 |
101 bool LCodeGen::GeneratePrologue() { | 99 bool LCodeGen::GeneratePrologue() { |
102 DCHECK(is_generating()); | 100 DCHECK(is_generating()); |
103 | 101 |
104 if (info()->IsOptimizing()) { | 102 if (info()->IsOptimizing()) { |
105 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | 103 ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
106 | 104 |
107 #ifdef DEBUG | 105 #ifdef DEBUG |
108 if (strlen(FLAG_stop_at) > 0 && | 106 if (strlen(FLAG_stop_at) > 0 && |
109 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | 107 info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
110 __ stop("stop_at"); | 108 __ stop("stop_at"); |
111 } | 109 } |
112 #endif | 110 #endif |
113 | 111 |
114 // r1: Callee's JS function. | 112 // r4: Callee's JS function. |
115 // cp: Callee's context. | 113 // cp: Callee's context. |
116 // pp: Callee's constant pool pointer (if FLAG_enable_ool_constant_pool) | |
117 // fp: Caller's frame pointer. | 114 // fp: Caller's frame pointer. |
118 // lr: Caller's pc. | 115 // lr: Caller's pc. |
119 | 116 |
120 // Sloppy mode functions and builtins need to replace the receiver with the | 117 // Sloppy mode functions and builtins need to replace the receiver with the |
121 // global proxy when called as functions (without an explicit receiver | 118 // global proxy when called as functions (without an explicit receiver |
122 // object). | 119 // object). |
123 if (info_->this_has_uses() && | 120 if (info_->this_has_uses() && info_->strict_mode() == SLOPPY && |
124 info_->strict_mode() == SLOPPY && | |
125 !info_->is_native()) { | 121 !info_->is_native()) { |
126 Label ok; | 122 Label ok; |
127 int receiver_offset = info_->scope()->num_parameters() * kPointerSize; | 123 int receiver_offset = info_->scope()->num_parameters() * kPointerSize; |
128 __ ldr(r2, MemOperand(sp, receiver_offset)); | 124 __ LoadP(r5, MemOperand(sp, receiver_offset)); |
129 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex); | 125 __ CompareRoot(r5, Heap::kUndefinedValueRootIndex); |
130 __ b(ne, &ok); | 126 __ bne(&ok); |
131 | 127 |
132 __ ldr(r2, GlobalObjectOperand()); | 128 __ LoadP(r5, GlobalObjectOperand()); |
133 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalProxyOffset)); | 129 __ LoadP(r5, FieldMemOperand(r5, GlobalObject::kGlobalProxyOffset)); |
134 | 130 |
135 __ str(r2, MemOperand(sp, receiver_offset)); | 131 __ StoreP(r5, MemOperand(sp, receiver_offset)); |
136 | 132 |
137 __ bind(&ok); | 133 __ bind(&ok); |
138 } | 134 } |
139 } | 135 } |
140 | 136 |
141 info()->set_prologue_offset(masm_->pc_offset()); | 137 info()->set_prologue_offset(masm_->pc_offset()); |
142 if (NeedsEagerFrame()) { | 138 if (NeedsEagerFrame()) { |
143 if (info()->IsStub()) { | 139 if (info()->IsStub()) { |
144 __ StubPrologue(); | 140 __ StubPrologue(); |
145 } else { | 141 } else { |
146 __ Prologue(info()->IsCodePreAgingActive()); | 142 __ Prologue(info()->IsCodePreAgingActive()); |
147 } | 143 } |
148 frame_is_built_ = true; | 144 frame_is_built_ = true; |
149 info_->AddNoFrameRange(0, masm_->pc_offset()); | 145 info_->AddNoFrameRange(0, masm_->pc_offset()); |
150 } | 146 } |
151 | 147 |
152 // Reserve space for the stack slots needed by the code. | 148 // Reserve space for the stack slots needed by the code. |
153 int slots = GetStackSlotCount(); | 149 int slots = GetStackSlotCount(); |
154 if (slots > 0) { | 150 if (slots > 0) { |
| 151 __ subi(sp, sp, Operand(slots * kPointerSize)); |
155 if (FLAG_debug_code) { | 152 if (FLAG_debug_code) { |
156 __ sub(sp, sp, Operand(slots * kPointerSize)); | 153 __ Push(r3, r4); |
157 __ push(r0); | 154 __ li(r0, Operand(slots)); |
158 __ push(r1); | 155 __ mtctr(r0); |
159 __ add(r0, sp, Operand(slots * kPointerSize)); | 156 __ addi(r3, sp, Operand((slots + 2) * kPointerSize)); |
160 __ mov(r1, Operand(kSlotsZapValue)); | 157 __ mov(r4, Operand(kSlotsZapValue)); |
161 Label loop; | 158 Label loop; |
162 __ bind(&loop); | 159 __ bind(&loop); |
163 __ sub(r0, r0, Operand(kPointerSize)); | 160 __ StorePU(r4, MemOperand(r3, -kPointerSize)); |
164 __ str(r1, MemOperand(r0, 2 * kPointerSize)); | 161 __ bdnz(&loop); |
165 __ cmp(r0, sp); | 162 __ Pop(r3, r4); |
166 __ b(ne, &loop); | |
167 __ pop(r1); | |
168 __ pop(r0); | |
169 } else { | |
170 __ sub(sp, sp, Operand(slots * kPointerSize)); | |
171 } | 163 } |
172 } | 164 } |
173 | 165 |
174 if (info()->saves_caller_doubles()) { | 166 if (info()->saves_caller_doubles()) { |
175 SaveCallerDoubles(); | 167 SaveCallerDoubles(); |
176 } | 168 } |
177 | 169 |
178 // Possibly allocate a local context. | 170 // Possibly allocate a local context. |
179 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 171 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
180 if (heap_slots > 0) { | 172 if (heap_slots > 0) { |
181 Comment(";;; Allocate local context"); | 173 Comment(";;; Allocate local context"); |
182 bool need_write_barrier = true; | 174 bool need_write_barrier = true; |
183 // Argument to NewContext is the function, which is in r1. | 175 // Argument to NewContext is the function, which is in r4. |
184 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | 176 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
185 FastNewContextStub stub(isolate(), heap_slots); | 177 FastNewContextStub stub(isolate(), heap_slots); |
186 __ CallStub(&stub); | 178 __ CallStub(&stub); |
187 // Result of FastNewContextStub is always in new space. | 179 // Result of FastNewContextStub is always in new space. |
188 need_write_barrier = false; | 180 need_write_barrier = false; |
189 } else { | 181 } else { |
190 __ push(r1); | 182 __ push(r4); |
191 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 183 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
192 } | 184 } |
193 RecordSafepoint(Safepoint::kNoLazyDeopt); | 185 RecordSafepoint(Safepoint::kNoLazyDeopt); |
194 // Context is returned in both r0 and cp. It replaces the context | 186 // 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. | 187 // passed to us. It's saved in the stack and kept live in cp. |
196 __ mov(cp, r0); | 188 __ mr(cp, r3); |
197 __ str(r0, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 189 __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
198 // Copy any necessary parameters into the context. | 190 // Copy any necessary parameters into the context. |
199 int num_parameters = scope()->num_parameters(); | 191 int num_parameters = scope()->num_parameters(); |
200 for (int i = 0; i < num_parameters; i++) { | 192 for (int i = 0; i < num_parameters; i++) { |
201 Variable* var = scope()->parameter(i); | 193 Variable* var = scope()->parameter(i); |
202 if (var->IsContextSlot()) { | 194 if (var->IsContextSlot()) { |
203 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | 195 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
204 (num_parameters - 1 - i) * kPointerSize; | 196 (num_parameters - 1 - i) * kPointerSize; |
205 // Load parameter from stack. | 197 // Load parameter from stack. |
206 __ ldr(r0, MemOperand(fp, parameter_offset)); | 198 __ LoadP(r3, MemOperand(fp, parameter_offset)); |
207 // Store it in the context. | 199 // Store it in the context. |
208 MemOperand target = ContextOperand(cp, var->index()); | 200 MemOperand target = ContextOperand(cp, var->index()); |
209 __ str(r0, target); | 201 __ StoreP(r3, target, r0); |
210 // Update the write barrier. This clobbers r3 and r0. | 202 // Update the write barrier. This clobbers r6 and r3. |
211 if (need_write_barrier) { | 203 if (need_write_barrier) { |
212 __ RecordWriteContextSlot( | 204 __ RecordWriteContextSlot(cp, target.offset(), r3, r6, |
213 cp, | 205 GetLinkRegisterState(), kSaveFPRegs); |
214 target.offset(), | |
215 r0, | |
216 r3, | |
217 GetLinkRegisterState(), | |
218 kSaveFPRegs); | |
219 } else if (FLAG_debug_code) { | 206 } else if (FLAG_debug_code) { |
220 Label done; | 207 Label done; |
221 __ JumpIfInNewSpace(cp, r0, &done); | 208 __ JumpIfInNewSpace(cp, r3, &done); |
222 __ Abort(kExpectedNewSpaceObject); | 209 __ Abort(kExpectedNewSpaceObject); |
223 __ bind(&done); | 210 __ bind(&done); |
224 } | 211 } |
225 } | 212 } |
226 } | 213 } |
227 Comment(";;; End allocate local context"); | 214 Comment(";;; End allocate local context"); |
228 } | 215 } |
229 | 216 |
230 // Trace the call. | 217 // Trace the call. |
231 if (FLAG_trace && info()->IsOptimizing()) { | 218 if (FLAG_trace && info()->IsOptimizing()) { |
232 // We have not executed any compiled code yet, so cp still holds the | 219 // We have not executed any compiled code yet, so cp still holds the |
233 // incoming context. | 220 // incoming context. |
234 __ CallRuntime(Runtime::kTraceEnter, 0); | 221 __ CallRuntime(Runtime::kTraceEnter, 0); |
235 } | 222 } |
236 return !is_aborted(); | 223 return !is_aborted(); |
237 } | 224 } |
238 | 225 |
239 | 226 |
240 void LCodeGen::GenerateOsrPrologue() { | 227 void LCodeGen::GenerateOsrPrologue() { |
241 // Generate the OSR entry prologue at the first unknown OSR value, or if there | 228 // Generate the OSR entry prologue at the first unknown OSR value, or if there |
242 // are none, at the OSR entrypoint instruction. | 229 // are none, at the OSR entrypoint instruction. |
243 if (osr_pc_offset_ >= 0) return; | 230 if (osr_pc_offset_ >= 0) return; |
244 | 231 |
245 osr_pc_offset_ = masm()->pc_offset(); | 232 osr_pc_offset_ = masm()->pc_offset(); |
246 | 233 |
247 // Adjust the frame size, subsuming the unoptimized frame into the | 234 // Adjust the frame size, subsuming the unoptimized frame into the |
248 // optimized frame. | 235 // optimized frame. |
249 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); | 236 int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
250 DCHECK(slots >= 0); | 237 DCHECK(slots >= 0); |
251 __ sub(sp, sp, Operand(slots * kPointerSize)); | 238 __ subi(sp, sp, Operand(slots * kPointerSize)); |
252 } | 239 } |
253 | 240 |
254 | 241 |
255 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { | 242 void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
256 if (instr->IsCall()) { | 243 if (instr->IsCall()) { |
257 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | 244 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
258 } | 245 } |
259 if (!instr->IsLazyBailout() && !instr->IsGap()) { | 246 if (!instr->IsLazyBailout() && !instr->IsGap()) { |
260 safepoints_.BumpLastLazySafepointIndex(); | 247 safepoints_.BumpLastLazySafepointIndex(); |
261 } | 248 } |
262 } | 249 } |
263 | 250 |
264 | 251 |
265 bool LCodeGen::GenerateDeferredCode() { | 252 bool LCodeGen::GenerateDeferredCode() { |
266 DCHECK(is_generating()); | 253 DCHECK(is_generating()); |
267 if (deferred_.length() > 0) { | 254 if (deferred_.length() > 0) { |
268 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { | 255 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
269 LDeferredCode* code = deferred_[i]; | 256 LDeferredCode* code = deferred_[i]; |
270 | 257 |
271 HValue* value = | 258 HValue* value = |
272 instructions_->at(code->instruction_index())->hydrogen_value(); | 259 instructions_->at(code->instruction_index())->hydrogen_value(); |
273 RecordAndWritePosition( | 260 RecordAndWritePosition( |
274 chunk()->graph()->SourcePositionToScriptPosition(value->position())); | 261 chunk()->graph()->SourcePositionToScriptPosition(value->position())); |
275 | 262 |
276 Comment(";;; <@%d,#%d> " | 263 Comment( |
277 "-------------------- Deferred %s --------------------", | 264 ";;; <@%d,#%d> " |
278 code->instruction_index(), | 265 "-------------------- Deferred %s --------------------", |
279 code->instr()->hydrogen_value()->id(), | 266 code->instruction_index(), code->instr()->hydrogen_value()->id(), |
280 code->instr()->Mnemonic()); | 267 code->instr()->Mnemonic()); |
281 __ bind(code->entry()); | 268 __ bind(code->entry()); |
282 if (NeedsDeferredFrame()) { | 269 if (NeedsDeferredFrame()) { |
283 Comment(";;; Build frame"); | 270 Comment(";;; Build frame"); |
284 DCHECK(!frame_is_built_); | 271 DCHECK(!frame_is_built_); |
285 DCHECK(info()->IsStub()); | 272 DCHECK(info()->IsStub()); |
286 frame_is_built_ = true; | 273 frame_is_built_ = true; |
287 __ PushFixedFrame(); | 274 __ PushFixedFrame(); |
288 __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); | 275 __ LoadSmiLiteral(scratch0(), Smi::FromInt(StackFrame::STUB)); |
289 __ push(scratch0()); | 276 __ push(scratch0()); |
290 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | 277 __ addi(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
291 Comment(";;; Deferred code"); | 278 Comment(";;; Deferred code"); |
292 } | 279 } |
293 code->Generate(); | 280 code->Generate(); |
294 if (NeedsDeferredFrame()) { | 281 if (NeedsDeferredFrame()) { |
295 Comment(";;; Destroy frame"); | 282 Comment(";;; Destroy frame"); |
296 DCHECK(frame_is_built_); | 283 DCHECK(frame_is_built_); |
297 __ pop(ip); | 284 __ pop(ip); |
298 __ PopFixedFrame(); | 285 __ PopFixedFrame(); |
299 frame_is_built_ = false; | 286 frame_is_built_ = false; |
300 } | 287 } |
301 __ jmp(code->exit()); | 288 __ b(code->exit()); |
302 } | 289 } |
303 } | 290 } |
304 | 291 |
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(); | 292 return !is_aborted(); |
310 } | 293 } |
311 | 294 |
312 | 295 |
313 bool LCodeGen::GenerateDeoptJumpTable() { | 296 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) { | 297 if (deopt_jump_table_.length() > 0) { |
327 Label needs_frame, call_deopt_entry; | 298 Label needs_frame, call_deopt_entry; |
328 | 299 |
329 Comment(";;; -------------------- Jump table --------------------"); | 300 Comment(";;; -------------------- Jump table --------------------"); |
330 Address base = deopt_jump_table_[0].address; | 301 Address base = deopt_jump_table_[0].address; |
331 | 302 |
332 Register entry_offset = scratch0(); | 303 Register entry_offset = scratch0(); |
333 | 304 |
334 int length = deopt_jump_table_.length(); | 305 int length = deopt_jump_table_.length(); |
335 for (int i = 0; i < length; i++) { | 306 for (int i = 0; i < length; i++) { |
| 307 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
336 __ bind(&deopt_jump_table_[i].label); | 308 __ bind(&deopt_jump_table_[i].label); |
337 | 309 |
338 Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; | 310 Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; |
339 DCHECK(type == deopt_jump_table_[0].bailout_type); | 311 DCHECK(type == deopt_jump_table_[0].bailout_type); |
340 Address entry = deopt_jump_table_[i].address; | 312 Address entry = deopt_jump_table_[i].address; |
341 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); | 313 int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
342 DCHECK(id != Deoptimizer::kNotDeoptimizationEntry); | 314 DCHECK(id != Deoptimizer::kNotDeoptimizationEntry); |
343 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); | 315 Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
344 | 316 |
345 // Second-level deopt table entries are contiguous and small, so instead | 317 // Second-level deopt table entries are contiguous and small, so instead |
346 // of loading the full, absolute address of each one, load an immediate | 318 // of loading the full, absolute address of each one, load an immediate |
347 // offset which will be added to the base address later. | 319 // offset which will be added to the base address later. |
348 __ mov(entry_offset, Operand(entry - base)); | 320 __ mov(entry_offset, Operand(entry - base)); |
349 | 321 |
350 if (deopt_jump_table_[i].needs_frame) { | 322 if (deopt_jump_table_[i].needs_frame) { |
351 DCHECK(!info()->saves_caller_doubles()); | 323 DCHECK(!info()->saves_caller_doubles()); |
352 if (needs_frame.is_bound()) { | 324 if (needs_frame.is_bound()) { |
353 __ b(&needs_frame); | 325 __ b(&needs_frame); |
354 } else { | 326 } else { |
355 __ bind(&needs_frame); | 327 __ bind(&needs_frame); |
356 Comment(";;; call deopt with frame"); | 328 Comment(";;; call deopt with frame"); |
357 __ PushFixedFrame(); | 329 __ PushFixedFrame(); |
358 // This variant of deopt can only be used with stubs. Since we don't | 330 // 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 | 331 // have a function pointer to install in the stack frame that we're |
360 // building, install a special marker there instead. | 332 // building, install a special marker there instead. |
361 DCHECK(info()->IsStub()); | 333 DCHECK(info()->IsStub()); |
362 __ mov(ip, Operand(Smi::FromInt(StackFrame::STUB))); | 334 __ LoadSmiLiteral(r0, Smi::FromInt(StackFrame::STUB)); |
363 __ push(ip); | 335 __ push(r0); |
364 __ add(fp, sp, | 336 __ addi(fp, sp, |
365 Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | 337 Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
366 __ bind(&call_deopt_entry); | 338 __ bind(&call_deopt_entry); |
367 // Add the base address to the offset previously loaded in | 339 // Add the base address to the offset previously loaded in |
368 // entry_offset. | 340 // entry_offset. |
369 __ add(entry_offset, entry_offset, | 341 __ mov(ip, Operand(ExternalReference::ForDeoptEntry(base))); |
370 Operand(ExternalReference::ForDeoptEntry(base))); | 342 __ add(ip, entry_offset, ip); |
371 __ blx(entry_offset); | 343 __ Call(ip); |
372 } | 344 } |
373 | |
374 masm()->CheckConstPool(false, false); | |
375 } else { | 345 } else { |
376 // The last entry can fall through into `call_deopt_entry`, avoiding a | 346 // The last entry can fall through into `call_deopt_entry`, avoiding a |
377 // branch. | 347 // branch. |
378 bool need_branch = ((i + 1) != length) || call_deopt_entry.is_bound(); | 348 bool need_branch = ((i + 1) != length) || call_deopt_entry.is_bound(); |
379 | 349 |
380 if (need_branch) __ b(&call_deopt_entry); | 350 if (need_branch) __ b(&call_deopt_entry); |
381 | |
382 masm()->CheckConstPool(false, !need_branch); | |
383 } | 351 } |
384 } | 352 } |
385 | 353 |
386 if (!call_deopt_entry.is_bound()) { | 354 if (!call_deopt_entry.is_bound()) { |
387 Comment(";;; call deopt"); | 355 Comment(";;; call deopt"); |
388 __ bind(&call_deopt_entry); | 356 __ bind(&call_deopt_entry); |
389 | 357 |
390 if (info()->saves_caller_doubles()) { | 358 if (info()->saves_caller_doubles()) { |
391 DCHECK(info()->IsStub()); | 359 DCHECK(info()->IsStub()); |
392 RestoreCallerDoubles(); | 360 RestoreCallerDoubles(); |
393 } | 361 } |
394 | 362 |
395 // Add the base address to the offset previously loaded in entry_offset. | 363 // Add the base address to the offset previously loaded in entry_offset. |
396 __ add(entry_offset, entry_offset, | 364 __ mov(ip, Operand(ExternalReference::ForDeoptEntry(base))); |
397 Operand(ExternalReference::ForDeoptEntry(base))); | 365 __ add(ip, entry_offset, ip); |
398 __ blx(entry_offset); | 366 __ Call(ip); |
399 } | 367 } |
400 } | 368 } |
401 | 369 |
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 | 370 // The deoptimization jump table is the last part of the instruction |
407 // sequence. Mark the generated code as done unless we bailed out. | 371 // sequence. Mark the generated code as done unless we bailed out. |
408 if (!is_aborted()) status_ = DONE; | 372 if (!is_aborted()) status_ = DONE; |
409 return !is_aborted(); | 373 return !is_aborted(); |
410 } | 374 } |
411 | 375 |
412 | 376 |
413 bool LCodeGen::GenerateSafepointTable() { | 377 bool LCodeGen::GenerateSafepointTable() { |
414 DCHECK(is_done()); | 378 DCHECK(is_done()); |
415 safepoints_.Emit(masm(), GetStackSlotCount()); | 379 safepoints_.Emit(masm(), GetStackSlotCount()); |
416 return !is_aborted(); | 380 return !is_aborted(); |
417 } | 381 } |
418 | 382 |
419 | 383 |
420 Register LCodeGen::ToRegister(int index) const { | 384 Register LCodeGen::ToRegister(int index) const { |
421 return Register::FromAllocationIndex(index); | 385 return Register::FromAllocationIndex(index); |
422 } | 386 } |
423 | 387 |
424 | 388 |
425 DwVfpRegister LCodeGen::ToDoubleRegister(int index) const { | 389 DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
426 return DwVfpRegister::FromAllocationIndex(index); | 390 return DoubleRegister::FromAllocationIndex(index); |
427 } | 391 } |
428 | 392 |
429 | 393 |
430 Register LCodeGen::ToRegister(LOperand* op) const { | 394 Register LCodeGen::ToRegister(LOperand* op) const { |
431 DCHECK(op->IsRegister()); | 395 DCHECK(op->IsRegister()); |
432 return ToRegister(op->index()); | 396 return ToRegister(op->index()); |
433 } | 397 } |
434 | 398 |
435 | 399 |
436 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { | 400 Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
437 if (op->IsRegister()) { | 401 if (op->IsRegister()) { |
438 return ToRegister(op->index()); | 402 return ToRegister(op->index()); |
439 } else if (op->IsConstantOperand()) { | 403 } else if (op->IsConstantOperand()) { |
440 LConstantOperand* const_op = LConstantOperand::cast(op); | 404 LConstantOperand* const_op = LConstantOperand::cast(op); |
441 HConstant* constant = chunk_->LookupConstant(const_op); | 405 HConstant* constant = chunk_->LookupConstant(const_op); |
442 Handle<Object> literal = constant->handle(isolate()); | 406 Handle<Object> literal = constant->handle(isolate()); |
443 Representation r = chunk_->LookupLiteralRepresentation(const_op); | 407 Representation r = chunk_->LookupLiteralRepresentation(const_op); |
444 if (r.IsInteger32()) { | 408 if (r.IsInteger32()) { |
445 DCHECK(literal->IsNumber()); | 409 DCHECK(literal->IsNumber()); |
446 __ mov(scratch, Operand(static_cast<int32_t>(literal->Number()))); | 410 __ LoadIntLiteral(scratch, static_cast<int32_t>(literal->Number())); |
447 } else if (r.IsDouble()) { | 411 } else if (r.IsDouble()) { |
448 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); | 412 Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); |
449 } else { | 413 } else { |
450 DCHECK(r.IsSmiOrTagged()); | 414 DCHECK(r.IsSmiOrTagged()); |
451 __ Move(scratch, literal); | 415 __ Move(scratch, literal); |
452 } | 416 } |
453 return scratch; | 417 return scratch; |
454 } else if (op->IsStackSlot()) { | 418 } else if (op->IsStackSlot()) { |
455 __ ldr(scratch, ToMemOperand(op)); | 419 __ LoadP(scratch, ToMemOperand(op)); |
456 return scratch; | 420 return scratch; |
457 } | 421 } |
458 UNREACHABLE(); | 422 UNREACHABLE(); |
459 return scratch; | 423 return scratch; |
460 } | 424 } |
461 | 425 |
462 | 426 |
463 DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const { | 427 void LCodeGen::EmitLoadIntegerConstant(LConstantOperand* const_op, |
| 428 Register dst) { |
| 429 DCHECK(IsInteger32(const_op)); |
| 430 HConstant* constant = chunk_->LookupConstant(const_op); |
| 431 int32_t value = constant->Integer32Value(); |
| 432 if (IsSmi(const_op)) { |
| 433 __ LoadSmiLiteral(dst, Smi::FromInt(value)); |
| 434 } else { |
| 435 __ LoadIntLiteral(dst, value); |
| 436 } |
| 437 } |
| 438 |
| 439 |
| 440 DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
464 DCHECK(op->IsDoubleRegister()); | 441 DCHECK(op->IsDoubleRegister()); |
465 return ToDoubleRegister(op->index()); | 442 return ToDoubleRegister(op->index()); |
466 } | 443 } |
467 | 444 |
468 | 445 |
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 DCHECK(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 { | 446 Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
503 HConstant* constant = chunk_->LookupConstant(op); | 447 HConstant* constant = chunk_->LookupConstant(op); |
504 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); | 448 DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
505 return constant->handle(isolate()); | 449 return constant->handle(isolate()); |
506 } | 450 } |
507 | 451 |
508 | 452 |
509 bool LCodeGen::IsInteger32(LConstantOperand* op) const { | 453 bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
510 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); | 454 return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
511 } | 455 } |
512 | 456 |
513 | 457 |
514 bool LCodeGen::IsSmi(LConstantOperand* op) const { | 458 bool LCodeGen::IsSmi(LConstantOperand* op) const { |
515 return chunk_->LookupLiteralRepresentation(op).IsSmi(); | 459 return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
516 } | 460 } |
517 | 461 |
518 | 462 |
519 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { | 463 int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
520 return ToRepresentation(op, Representation::Integer32()); | 464 return ToRepresentation(op, Representation::Integer32()); |
521 } | 465 } |
522 | 466 |
523 | 467 |
524 int32_t LCodeGen::ToRepresentation(LConstantOperand* op, | 468 intptr_t LCodeGen::ToRepresentation(LConstantOperand* op, |
525 const Representation& r) const { | 469 const Representation& r) const { |
526 HConstant* constant = chunk_->LookupConstant(op); | 470 HConstant* constant = chunk_->LookupConstant(op); |
527 int32_t value = constant->Integer32Value(); | 471 int32_t value = constant->Integer32Value(); |
528 if (r.IsInteger32()) return value; | 472 if (r.IsInteger32()) return value; |
529 DCHECK(r.IsSmiOrTagged()); | 473 DCHECK(r.IsSmiOrTagged()); |
530 return reinterpret_cast<int32_t>(Smi::FromInt(value)); | 474 return reinterpret_cast<intptr_t>(Smi::FromInt(value)); |
531 } | 475 } |
532 | 476 |
533 | 477 |
534 Smi* LCodeGen::ToSmi(LConstantOperand* op) const { | 478 Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
535 HConstant* constant = chunk_->LookupConstant(op); | 479 HConstant* constant = chunk_->LookupConstant(op); |
536 return Smi::FromInt(constant->Integer32Value()); | 480 return Smi::FromInt(constant->Integer32Value()); |
537 } | 481 } |
538 | 482 |
539 | 483 |
540 double LCodeGen::ToDouble(LConstantOperand* op) const { | 484 double LCodeGen::ToDouble(LConstantOperand* op) const { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 536 } |
593 | 537 |
594 | 538 |
595 MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { | 539 MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
596 DCHECK(op->IsDoubleStackSlot()); | 540 DCHECK(op->IsDoubleStackSlot()); |
597 if (NeedsEagerFrame()) { | 541 if (NeedsEagerFrame()) { |
598 return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); | 542 return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); |
599 } else { | 543 } else { |
600 // Retrieve parameter without eager stack-frame relative to the | 544 // Retrieve parameter without eager stack-frame relative to the |
601 // stack-pointer. | 545 // stack-pointer. |
602 return MemOperand( | 546 return MemOperand(sp, |
603 sp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); | 547 ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
604 } | 548 } |
605 } | 549 } |
606 | 550 |
607 | 551 |
608 void LCodeGen::WriteTranslation(LEnvironment* environment, | 552 void LCodeGen::WriteTranslation(LEnvironment* environment, |
609 Translation* translation) { | 553 Translation* translation) { |
610 if (environment == NULL) return; | 554 if (environment == NULL) return; |
611 | 555 |
612 // The translation includes one command per value in the environment. | 556 // The translation includes one command per value in the environment. |
613 int translation_size = environment->translation_size(); | 557 int translation_size = environment->translation_size(); |
614 // The output frame height does not include the parameters. | 558 // The output frame height does not include the parameters. |
615 int height = translation_size - environment->parameter_count(); | 559 int height = translation_size - environment->parameter_count(); |
616 | 560 |
617 WriteTranslation(environment->outer(), translation); | 561 WriteTranslation(environment->outer(), translation); |
618 bool has_closure_id = !info()->closure().is_null() && | 562 bool has_closure_id = |
| 563 !info()->closure().is_null() && |
619 !info()->closure().is_identical_to(environment->closure()); | 564 !info()->closure().is_identical_to(environment->closure()); |
620 int closure_id = has_closure_id | 565 int closure_id = has_closure_id |
621 ? DefineDeoptimizationLiteral(environment->closure()) | 566 ? DefineDeoptimizationLiteral(environment->closure()) |
622 : Translation::kSelfLiteralId; | 567 : Translation::kSelfLiteralId; |
623 | 568 |
624 switch (environment->frame_type()) { | 569 switch (environment->frame_type()) { |
625 case JS_FUNCTION: | 570 case JS_FUNCTION: |
626 translation->BeginJSFrame(environment->ast_id(), closure_id, height); | 571 translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
627 break; | 572 break; |
628 case JS_CONSTRUCT: | 573 case JS_CONSTRUCT: |
629 translation->BeginConstructStubFrame(closure_id, translation_size); | 574 translation->BeginConstructStubFrame(closure_id, translation_size); |
630 break; | 575 break; |
631 case JS_GETTER: | 576 case JS_GETTER: |
632 DCHECK(translation_size == 1); | 577 DCHECK(translation_size == 1); |
(...skipping 10 matching lines...) Expand all Loading... |
643 break; | 588 break; |
644 case ARGUMENTS_ADAPTOR: | 589 case ARGUMENTS_ADAPTOR: |
645 translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); | 590 translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
646 break; | 591 break; |
647 } | 592 } |
648 | 593 |
649 int object_index = 0; | 594 int object_index = 0; |
650 int dematerialized_index = 0; | 595 int dematerialized_index = 0; |
651 for (int i = 0; i < translation_size; ++i) { | 596 for (int i = 0; i < translation_size; ++i) { |
652 LOperand* value = environment->values()->at(i); | 597 LOperand* value = environment->values()->at(i); |
653 AddToTranslation(environment, | 598 AddToTranslation( |
654 translation, | 599 environment, translation, value, environment->HasTaggedValueAt(i), |
655 value, | 600 environment->HasUint32ValueAt(i), &object_index, &dematerialized_index); |
656 environment->HasTaggedValueAt(i), | |
657 environment->HasUint32ValueAt(i), | |
658 &object_index, | |
659 &dematerialized_index); | |
660 } | 601 } |
661 } | 602 } |
662 | 603 |
663 | 604 |
664 void LCodeGen::AddToTranslation(LEnvironment* environment, | 605 void LCodeGen::AddToTranslation(LEnvironment* environment, |
665 Translation* translation, | 606 Translation* translation, LOperand* op, |
666 LOperand* op, | 607 bool is_tagged, bool is_uint32, |
667 bool is_tagged, | |
668 bool is_uint32, | |
669 int* object_index_pointer, | 608 int* object_index_pointer, |
670 int* dematerialized_index_pointer) { | 609 int* dematerialized_index_pointer) { |
671 if (op == LEnvironment::materialization_marker()) { | 610 if (op == LEnvironment::materialization_marker()) { |
672 int object_index = (*object_index_pointer)++; | 611 int object_index = (*object_index_pointer)++; |
673 if (environment->ObjectIsDuplicateAt(object_index)) { | 612 if (environment->ObjectIsDuplicateAt(object_index)) { |
674 int dupe_of = environment->ObjectDuplicateOfAt(object_index); | 613 int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
675 translation->DuplicateObject(dupe_of); | 614 translation->DuplicateObject(dupe_of); |
676 return; | 615 return; |
677 } | 616 } |
678 int object_length = environment->ObjectLengthAt(object_index); | 617 int object_length = environment->ObjectLengthAt(object_index); |
679 if (environment->ObjectIsArgumentsAt(object_index)) { | 618 if (environment->ObjectIsArgumentsAt(object_index)) { |
680 translation->BeginArgumentsObject(object_length); | 619 translation->BeginArgumentsObject(object_length); |
681 } else { | 620 } else { |
682 translation->BeginCapturedObject(object_length); | 621 translation->BeginCapturedObject(object_length); |
683 } | 622 } |
684 int dematerialized_index = *dematerialized_index_pointer; | 623 int dematerialized_index = *dematerialized_index_pointer; |
685 int env_offset = environment->translation_size() + dematerialized_index; | 624 int env_offset = environment->translation_size() + dematerialized_index; |
686 *dematerialized_index_pointer += object_length; | 625 *dematerialized_index_pointer += object_length; |
687 for (int i = 0; i < object_length; ++i) { | 626 for (int i = 0; i < object_length; ++i) { |
688 LOperand* value = environment->values()->at(env_offset + i); | 627 LOperand* value = environment->values()->at(env_offset + i); |
689 AddToTranslation(environment, | 628 AddToTranslation(environment, translation, value, |
690 translation, | |
691 value, | |
692 environment->HasTaggedValueAt(env_offset + i), | 629 environment->HasTaggedValueAt(env_offset + i), |
693 environment->HasUint32ValueAt(env_offset + i), | 630 environment->HasUint32ValueAt(env_offset + i), |
694 object_index_pointer, | 631 object_index_pointer, dematerialized_index_pointer); |
695 dematerialized_index_pointer); | |
696 } | 632 } |
697 return; | 633 return; |
698 } | 634 } |
699 | 635 |
700 if (op->IsStackSlot()) { | 636 if (op->IsStackSlot()) { |
701 if (is_tagged) { | 637 if (is_tagged) { |
702 translation->StoreStackSlot(op->index()); | 638 translation->StoreStackSlot(op->index()); |
703 } else if (is_uint32) { | 639 } else if (is_uint32) { |
704 translation->StoreUint32StackSlot(op->index()); | 640 translation->StoreUint32StackSlot(op->index()); |
705 } else { | 641 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
722 } else if (op->IsConstantOperand()) { | 658 } else if (op->IsConstantOperand()) { |
723 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); | 659 HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
724 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); | 660 int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
725 translation->StoreLiteral(src_index); | 661 translation->StoreLiteral(src_index); |
726 } else { | 662 } else { |
727 UNREACHABLE(); | 663 UNREACHABLE(); |
728 } | 664 } |
729 } | 665 } |
730 | 666 |
731 | 667 |
732 int LCodeGen::CallCodeSize(Handle<Code> code, RelocInfo::Mode mode) { | 668 void LCodeGen::CallCode(Handle<Code> code, RelocInfo::Mode mode, |
733 int size = masm()->CallSize(code, mode); | 669 LInstruction* instr) { |
734 if (code->kind() == Code::BINARY_OP_IC || | 670 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
735 code->kind() == Code::COMPARE_IC) { | |
736 size += Assembler::kInstrSize; // extra nop() added in CallCodeGeneric. | |
737 } | |
738 return size; | |
739 } | 671 } |
740 | 672 |
741 | 673 |
742 void LCodeGen::CallCode(Handle<Code> code, | 674 void LCodeGen::CallCodeGeneric(Handle<Code> code, RelocInfo::Mode mode, |
743 RelocInfo::Mode mode, | |
744 LInstruction* instr, | |
745 TargetAddressStorageMode storage_mode) { | |
746 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode); | |
747 } | |
748 | |
749 | |
750 void LCodeGen::CallCodeGeneric(Handle<Code> code, | |
751 RelocInfo::Mode mode, | |
752 LInstruction* instr, | 675 LInstruction* instr, |
753 SafepointMode safepoint_mode, | 676 SafepointMode safepoint_mode) { |
754 TargetAddressStorageMode storage_mode) { | |
755 DCHECK(instr != NULL); | 677 DCHECK(instr != NULL); |
756 // Block literal pool emission to ensure nop indicating no inlined smi code | 678 __ 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); | 679 RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
761 | 680 |
762 // Signal that we don't inline smi code before these stubs in the | 681 // Signal that we don't inline smi code before these stubs in the |
763 // optimizing code generator. | 682 // optimizing code generator. |
764 if (code->kind() == Code::BINARY_OP_IC || | 683 if (code->kind() == Code::BINARY_OP_IC || code->kind() == Code::COMPARE_IC) { |
765 code->kind() == Code::COMPARE_IC) { | |
766 __ nop(); | 684 __ nop(); |
767 } | 685 } |
768 } | 686 } |
769 | 687 |
770 | 688 |
771 void LCodeGen::CallRuntime(const Runtime::Function* function, | 689 void LCodeGen::CallRuntime(const Runtime::Function* function, int num_arguments, |
772 int num_arguments, | 690 LInstruction* instr, SaveFPRegsMode save_doubles) { |
773 LInstruction* instr, | |
774 SaveFPRegsMode save_doubles) { | |
775 DCHECK(instr != NULL); | 691 DCHECK(instr != NULL); |
776 | 692 |
777 __ CallRuntime(function, num_arguments, save_doubles); | 693 __ CallRuntime(function, num_arguments, save_doubles); |
778 | 694 |
779 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 695 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
780 } | 696 } |
781 | 697 |
782 | 698 |
783 void LCodeGen::LoadContextFromDeferred(LOperand* context) { | 699 void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
784 if (context->IsRegister()) { | 700 if (context->IsRegister()) { |
785 __ Move(cp, ToRegister(context)); | 701 __ Move(cp, ToRegister(context)); |
786 } else if (context->IsStackSlot()) { | 702 } else if (context->IsStackSlot()) { |
787 __ ldr(cp, ToMemOperand(context)); | 703 __ LoadP(cp, ToMemOperand(context)); |
788 } else if (context->IsConstantOperand()) { | 704 } else if (context->IsConstantOperand()) { |
789 HConstant* constant = | 705 HConstant* constant = |
790 chunk_->LookupConstant(LConstantOperand::cast(context)); | 706 chunk_->LookupConstant(LConstantOperand::cast(context)); |
791 __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); | 707 __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); |
792 } else { | 708 } else { |
793 UNREACHABLE(); | 709 UNREACHABLE(); |
794 } | 710 } |
795 } | 711 } |
796 | 712 |
797 | 713 |
798 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, | 714 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, int argc, |
799 int argc, | 715 LInstruction* instr, LOperand* context) { |
800 LInstruction* instr, | |
801 LOperand* context) { | |
802 LoadContextFromDeferred(context); | 716 LoadContextFromDeferred(context); |
803 __ CallRuntimeSaveDoubles(id); | 717 __ CallRuntimeSaveDoubles(id); |
804 RecordSafepointWithRegisters( | 718 RecordSafepointWithRegisters(instr->pointer_map(), argc, |
805 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); | 719 Safepoint::kNoLazyDeopt); |
806 } | 720 } |
807 | 721 |
808 | 722 |
809 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, | 723 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
810 Safepoint::DeoptMode mode) { | 724 Safepoint::DeoptMode mode) { |
811 environment->set_has_been_used(); | 725 environment->set_has_been_used(); |
812 if (!environment->HasBeenRegistered()) { | 726 if (!environment->HasBeenRegistered()) { |
813 // Physical stack frame layout: | 727 // Physical stack frame layout: |
814 // -x ............. -4 0 ..................................... y | 728 // -x ............. -4 0 ..................................... y |
815 // [incoming arguments] [spill slots] [pushed outgoing arguments] | 729 // [incoming arguments] [spill slots] [pushed outgoing arguments] |
(...skipping 12 matching lines...) Expand all Loading... |
828 for (LEnvironment* e = environment; e != NULL; e = e->outer()) { | 742 for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
829 ++frame_count; | 743 ++frame_count; |
830 if (e->frame_type() == JS_FUNCTION) { | 744 if (e->frame_type() == JS_FUNCTION) { |
831 ++jsframe_count; | 745 ++jsframe_count; |
832 } | 746 } |
833 } | 747 } |
834 Translation translation(&translations_, frame_count, jsframe_count, zone()); | 748 Translation translation(&translations_, frame_count, jsframe_count, zone()); |
835 WriteTranslation(environment, &translation); | 749 WriteTranslation(environment, &translation); |
836 int deoptimization_index = deoptimizations_.length(); | 750 int deoptimization_index = deoptimizations_.length(); |
837 int pc_offset = masm()->pc_offset(); | 751 int pc_offset = masm()->pc_offset(); |
838 environment->Register(deoptimization_index, | 752 environment->Register(deoptimization_index, translation.index(), |
839 translation.index(), | |
840 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); | 753 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
841 deoptimizations_.Add(environment, zone()); | 754 deoptimizations_.Add(environment, zone()); |
842 } | 755 } |
843 } | 756 } |
844 | 757 |
845 | 758 |
846 void LCodeGen::DeoptimizeIf(Condition condition, | 759 void LCodeGen::DeoptimizeIf(Condition cond, LEnvironment* environment, |
847 LEnvironment* environment, | 760 Deoptimizer::BailoutType bailout_type, |
848 Deoptimizer::BailoutType bailout_type) { | 761 CRegister cr) { |
849 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 762 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
850 DCHECK(environment->HasBeenRegistered()); | 763 DCHECK(environment->HasBeenRegistered()); |
851 int id = environment->deoptimization_index(); | 764 int id = environment->deoptimization_index(); |
852 DCHECK(info()->IsOptimizing() || info()->IsStub()); | 765 DCHECK(info()->IsOptimizing() || info()->IsStub()); |
853 Address entry = | 766 Address entry = |
854 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); | 767 Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
855 if (entry == NULL) { | 768 if (entry == NULL) { |
856 Abort(kBailoutWasNotPrepared); | 769 Abort(kBailoutWasNotPrepared); |
857 return; | 770 return; |
858 } | 771 } |
859 | 772 |
860 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { | 773 if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { |
| 774 CRegister alt_cr = cr6; |
861 Register scratch = scratch0(); | 775 Register scratch = scratch0(); |
862 ExternalReference count = ExternalReference::stress_deopt_count(isolate()); | 776 ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 777 Label no_deopt; |
| 778 DCHECK(!alt_cr.is(cr)); |
| 779 __ Push(r4, scratch); |
| 780 __ mov(scratch, Operand(count)); |
| 781 __ lwz(r4, MemOperand(scratch)); |
| 782 __ subi(r4, r4, Operand(1)); |
| 783 __ cmpi(r4, Operand::Zero(), alt_cr); |
| 784 __ bne(&no_deopt, alt_cr); |
| 785 __ li(r4, Operand(FLAG_deopt_every_n_times)); |
| 786 __ stw(r4, MemOperand(scratch)); |
| 787 __ Pop(r4, scratch); |
863 | 788 |
864 // Store the condition on the stack if necessary | 789 __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
865 if (condition != al) { | 790 __ bind(&no_deopt); |
866 __ mov(scratch, Operand::Zero(), LeaveCC, NegateCondition(condition)); | 791 __ stw(r4, MemOperand(scratch)); |
867 __ mov(scratch, Operand(1), LeaveCC, condition); | 792 __ 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 } | 793 } |
894 | 794 |
895 if (info()->ShouldTrapOnDeopt()) { | 795 if (info()->ShouldTrapOnDeopt()) { |
896 __ stop("trap_on_deopt", condition); | 796 __ stop("trap_on_deopt", cond, kDefaultStopCode, cr); |
897 } | 797 } |
898 | 798 |
899 DCHECK(info()->IsStub() || frame_is_built_); | 799 DCHECK(info()->IsStub() || frame_is_built_); |
900 // Go through jump table if we need to handle condition, build frame, or | 800 // Go through jump table if we need to handle condition, build frame, or |
901 // restore caller doubles. | 801 // restore caller doubles. |
902 if (condition == al && frame_is_built_ && | 802 if (cond == al && frame_is_built_ && !info()->saves_caller_doubles()) { |
903 !info()->saves_caller_doubles()) { | |
904 __ Call(entry, RelocInfo::RUNTIME_ENTRY); | 803 __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
905 } else { | 804 } else { |
906 // We often have several deopts to the same entry, reuse the last | 805 // We often have several deopts to the same entry, reuse the last |
907 // jump entry if this is the case. | 806 // jump entry if this is the case. |
908 if (deopt_jump_table_.is_empty() || | 807 if (deopt_jump_table_.is_empty() || |
909 (deopt_jump_table_.last().address != entry) || | 808 (deopt_jump_table_.last().address != entry) || |
910 (deopt_jump_table_.last().bailout_type != bailout_type) || | 809 (deopt_jump_table_.last().bailout_type != bailout_type) || |
911 (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { | 810 (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
912 Deoptimizer::JumpTableEntry table_entry(entry, | 811 Deoptimizer::JumpTableEntry table_entry(entry, bailout_type, |
913 bailout_type, | |
914 !frame_is_built_); | 812 !frame_is_built_); |
915 deopt_jump_table_.Add(table_entry, zone()); | 813 deopt_jump_table_.Add(table_entry, zone()); |
916 } | 814 } |
917 __ b(condition, &deopt_jump_table_.last().label); | 815 __ b(cond, &deopt_jump_table_.last().label, cr); |
918 } | 816 } |
919 } | 817 } |
920 | 818 |
921 | 819 |
922 void LCodeGen::DeoptimizeIf(Condition condition, | 820 void LCodeGen::DeoptimizeIf(Condition cond, LEnvironment* environment, |
923 LEnvironment* environment) { | 821 CRegister cr) { |
924 Deoptimizer::BailoutType bailout_type = info()->IsStub() | 822 Deoptimizer::BailoutType bailout_type = |
925 ? Deoptimizer::LAZY | 823 info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
926 : Deoptimizer::EAGER; | 824 DeoptimizeIf(cond, environment, bailout_type, cr); |
927 DeoptimizeIf(condition, environment, bailout_type); | |
928 } | 825 } |
929 | 826 |
930 | 827 |
931 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { | 828 void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
932 int length = deoptimizations_.length(); | 829 int length = deoptimizations_.length(); |
933 if (length == 0) return; | 830 if (length == 0) return; |
934 Handle<DeoptimizationInputData> data = | 831 Handle<DeoptimizationInputData> data = |
935 DeoptimizationInputData::New(isolate(), length, 0, TENURED); | 832 DeoptimizationInputData::New(isolate(), length, 0, TENURED); |
936 | 833 |
937 Handle<ByteArray> translations = | 834 Handle<ByteArray> translations = |
938 translations_.CreateByteArray(isolate()->factory()); | 835 translations_.CreateByteArray(isolate()->factory()); |
939 data->SetTranslationByteArray(*translations); | 836 data->SetTranslationByteArray(*translations); |
940 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); | 837 data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
941 data->SetOptimizationId(Smi::FromInt(info_->optimization_id())); | 838 data->SetOptimizationId(Smi::FromInt(info_->optimization_id())); |
942 if (info_->IsOptimizing()) { | 839 if (info_->IsOptimizing()) { |
943 // Reference to shared function info does not change between phases. | 840 // Reference to shared function info does not change between phases. |
944 AllowDeferredHandleDereference allow_handle_dereference; | 841 AllowDeferredHandleDereference allow_handle_dereference; |
945 data->SetSharedFunctionInfo(*info_->shared_info()); | 842 data->SetSharedFunctionInfo(*info_->shared_info()); |
946 } else { | 843 } else { |
947 data->SetSharedFunctionInfo(Smi::FromInt(0)); | 844 data->SetSharedFunctionInfo(Smi::FromInt(0)); |
948 } | 845 } |
949 | 846 |
950 Handle<FixedArray> literals = | 847 Handle<FixedArray> literals = |
951 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); | 848 factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
952 { AllowDeferredHandleDereference copy_handles; | 849 { |
| 850 AllowDeferredHandleDereference copy_handles; |
953 for (int i = 0; i < deoptimization_literals_.length(); i++) { | 851 for (int i = 0; i < deoptimization_literals_.length(); i++) { |
954 literals->set(i, *deoptimization_literals_[i]); | 852 literals->set(i, *deoptimization_literals_[i]); |
955 } | 853 } |
956 data->SetLiteralArray(*literals); | 854 data->SetLiteralArray(*literals); |
957 } | 855 } |
958 | 856 |
959 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); | 857 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
960 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); | 858 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
961 | 859 |
962 // Populate the deoptimization entries. | 860 // Populate the deoptimization entries. |
(...skipping 18 matching lines...) Expand all Loading... |
981 return result; | 879 return result; |
982 } | 880 } |
983 | 881 |
984 | 882 |
985 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { | 883 void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
986 DCHECK(deoptimization_literals_.length() == 0); | 884 DCHECK(deoptimization_literals_.length() == 0); |
987 | 885 |
988 const ZoneList<Handle<JSFunction> >* inlined_closures = | 886 const ZoneList<Handle<JSFunction> >* inlined_closures = |
989 chunk()->inlined_closures(); | 887 chunk()->inlined_closures(); |
990 | 888 |
991 for (int i = 0, length = inlined_closures->length(); | 889 for (int i = 0, length = inlined_closures->length(); i < length; i++) { |
992 i < length; | |
993 i++) { | |
994 DefineDeoptimizationLiteral(inlined_closures->at(i)); | 890 DefineDeoptimizationLiteral(inlined_closures->at(i)); |
995 } | 891 } |
996 | 892 |
997 inlined_function_count_ = deoptimization_literals_.length(); | 893 inlined_function_count_ = deoptimization_literals_.length(); |
998 } | 894 } |
999 | 895 |
1000 | 896 |
1001 void LCodeGen::RecordSafepointWithLazyDeopt( | 897 void LCodeGen::RecordSafepointWithLazyDeopt(LInstruction* instr, |
1002 LInstruction* instr, SafepointMode safepoint_mode) { | 898 SafepointMode safepoint_mode) { |
1003 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { | 899 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
1004 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); | 900 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
1005 } else { | 901 } else { |
1006 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | 902 DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
1007 RecordSafepointWithRegisters( | 903 RecordSafepointWithRegisters(instr->pointer_map(), 0, |
1008 instr->pointer_map(), 0, Safepoint::kLazyDeopt); | 904 Safepoint::kLazyDeopt); |
1009 } | 905 } |
1010 } | 906 } |
1011 | 907 |
1012 | 908 |
1013 void LCodeGen::RecordSafepoint( | 909 void LCodeGen::RecordSafepoint(LPointerMap* pointers, Safepoint::Kind kind, |
1014 LPointerMap* pointers, | 910 int arguments, Safepoint::DeoptMode deopt_mode) { |
1015 Safepoint::Kind kind, | |
1016 int arguments, | |
1017 Safepoint::DeoptMode deopt_mode) { | |
1018 DCHECK(expected_safepoint_kind_ == kind); | 911 DCHECK(expected_safepoint_kind_ == kind); |
1019 | 912 |
1020 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); | 913 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
1021 Safepoint safepoint = safepoints_.DefineSafepoint(masm(), | 914 Safepoint safepoint = |
1022 kind, arguments, deopt_mode); | 915 safepoints_.DefineSafepoint(masm(), kind, arguments, deopt_mode); |
1023 for (int i = 0; i < operands->length(); i++) { | 916 for (int i = 0; i < operands->length(); i++) { |
1024 LOperand* pointer = operands->at(i); | 917 LOperand* pointer = operands->at(i); |
1025 if (pointer->IsStackSlot()) { | 918 if (pointer->IsStackSlot()) { |
1026 safepoint.DefinePointerSlot(pointer->index(), zone()); | 919 safepoint.DefinePointerSlot(pointer->index(), zone()); |
1027 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { | 920 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
1028 safepoint.DefinePointerRegister(ToRegister(pointer), zone()); | 921 safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
1029 } | 922 } |
1030 } | 923 } |
1031 if (FLAG_enable_ool_constant_pool && (kind & Safepoint::kWithRegisters)) { | 924 #if V8_OOL_CONSTANT_POOL |
1032 // Register pp always contains a pointer to the constant pool. | 925 if (kind & Safepoint::kWithRegisters) { |
1033 safepoint.DefinePointerRegister(pp, zone()); | 926 // Register always contains a pointer to the constant pool. |
| 927 safepoint.DefinePointerRegister(kConstantPoolRegister, zone()); |
1034 } | 928 } |
| 929 #endif |
1035 } | 930 } |
1036 | 931 |
1037 | 932 |
1038 void LCodeGen::RecordSafepoint(LPointerMap* pointers, | 933 void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
1039 Safepoint::DeoptMode deopt_mode) { | 934 Safepoint::DeoptMode deopt_mode) { |
1040 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); | 935 RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
1041 } | 936 } |
1042 | 937 |
1043 | 938 |
1044 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { | 939 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
1045 LPointerMap empty_pointers(zone()); | 940 LPointerMap empty_pointers(zone()); |
1046 RecordSafepoint(&empty_pointers, deopt_mode); | 941 RecordSafepoint(&empty_pointers, deopt_mode); |
1047 } | 942 } |
1048 | 943 |
1049 | 944 |
1050 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, | 945 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
1051 int arguments, | 946 int arguments, |
1052 Safepoint::DeoptMode deopt_mode) { | 947 Safepoint::DeoptMode deopt_mode) { |
1053 RecordSafepoint( | 948 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
1054 pointers, Safepoint::kWithRegisters, arguments, deopt_mode); | |
1055 } | 949 } |
1056 | 950 |
1057 | 951 |
1058 void LCodeGen::RecordAndWritePosition(int position) { | 952 void LCodeGen::RecordAndWritePosition(int position) { |
1059 if (position == RelocInfo::kNoPosition) return; | 953 if (position == RelocInfo::kNoPosition) return; |
1060 masm()->positions_recorder()->RecordPosition(position); | 954 masm()->positions_recorder()->RecordPosition(position); |
1061 masm()->positions_recorder()->WriteRecordedPositions(); | 955 masm()->positions_recorder()->WriteRecordedPositions(); |
1062 } | 956 } |
1063 | 957 |
1064 | 958 |
1065 static const char* LabelType(LLabel* label) { | 959 static const char* LabelType(LLabel* label) { |
1066 if (label->is_loop_header()) return " (loop header)"; | 960 if (label->is_loop_header()) return " (loop header)"; |
1067 if (label->is_osr_entry()) return " (OSR entry)"; | 961 if (label->is_osr_entry()) return " (OSR entry)"; |
1068 return ""; | 962 return ""; |
1069 } | 963 } |
1070 | 964 |
1071 | 965 |
1072 void LCodeGen::DoLabel(LLabel* label) { | 966 void LCodeGen::DoLabel(LLabel* label) { |
1073 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", | 967 Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
1074 current_instruction_, | 968 current_instruction_, label->hydrogen_value()->id(), |
1075 label->hydrogen_value()->id(), | 969 label->block_id(), LabelType(label)); |
1076 label->block_id(), | |
1077 LabelType(label)); | |
1078 __ bind(label->label()); | 970 __ bind(label->label()); |
1079 current_block_ = label->block_id(); | 971 current_block_ = label->block_id(); |
1080 DoGap(label); | 972 DoGap(label); |
1081 } | 973 } |
1082 | 974 |
1083 | 975 |
1084 void LCodeGen::DoParallelMove(LParallelMove* move) { | 976 void LCodeGen::DoParallelMove(LParallelMove* move) { resolver_.Resolve(move); } |
1085 resolver_.Resolve(move); | |
1086 } | |
1087 | 977 |
1088 | 978 |
1089 void LCodeGen::DoGap(LGap* gap) { | 979 void LCodeGen::DoGap(LGap* gap) { |
1090 for (int i = LGap::FIRST_INNER_POSITION; | 980 for (int i = LGap::FIRST_INNER_POSITION; i <= LGap::LAST_INNER_POSITION; |
1091 i <= LGap::LAST_INNER_POSITION; | |
1092 i++) { | 981 i++) { |
1093 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); | 982 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
1094 LParallelMove* move = gap->GetParallelMove(inner_pos); | 983 LParallelMove* move = gap->GetParallelMove(inner_pos); |
1095 if (move != NULL) DoParallelMove(move); | 984 if (move != NULL) DoParallelMove(move); |
1096 } | 985 } |
1097 } | 986 } |
1098 | 987 |
1099 | 988 |
1100 void LCodeGen::DoInstructionGap(LInstructionGap* instr) { | 989 void LCodeGen::DoInstructionGap(LInstructionGap* instr) { DoGap(instr); } |
1101 DoGap(instr); | |
1102 } | |
1103 | 990 |
1104 | 991 |
1105 void LCodeGen::DoParameter(LParameter* instr) { | 992 void LCodeGen::DoParameter(LParameter* instr) { |
1106 // Nothing to do. | 993 // Nothing to do. |
1107 } | 994 } |
1108 | 995 |
1109 | 996 |
1110 void LCodeGen::DoCallStub(LCallStub* instr) { | 997 void LCodeGen::DoCallStub(LCallStub* instr) { |
1111 DCHECK(ToRegister(instr->context()).is(cp)); | 998 DCHECK(ToRegister(instr->context()).is(cp)); |
1112 DCHECK(ToRegister(instr->result()).is(r0)); | 999 DCHECK(ToRegister(instr->result()).is(r3)); |
1113 switch (instr->hydrogen()->major_key()) { | 1000 switch (instr->hydrogen()->major_key()) { |
1114 case CodeStub::RegExpExec: { | 1001 case CodeStub::RegExpExec: { |
1115 RegExpExecStub stub(isolate()); | 1002 RegExpExecStub stub(isolate()); |
1116 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 1003 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
1117 break; | 1004 break; |
1118 } | 1005 } |
1119 case CodeStub::SubString: { | 1006 case CodeStub::SubString: { |
1120 SubStringStub stub(isolate()); | 1007 SubStringStub stub(isolate()); |
1121 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 1008 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
1122 break; | 1009 break; |
(...skipping 19 matching lines...) Expand all Loading... |
1142 int32_t divisor = instr->divisor(); | 1029 int32_t divisor = instr->divisor(); |
1143 DCHECK(dividend.is(ToRegister(instr->result()))); | 1030 DCHECK(dividend.is(ToRegister(instr->result()))); |
1144 | 1031 |
1145 // Theoretically, a variation of the branch-free code for integer division by | 1032 // Theoretically, a variation of the branch-free code for integer division by |
1146 // a power of 2 (calculating the remainder via an additional multiplication | 1033 // a power of 2 (calculating the remainder via an additional multiplication |
1147 // (which gets simplified to an 'and') and subtraction) should be faster, and | 1034 // (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 | 1035 // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
1149 // indicate that positive dividends are heavily favored, so the branching | 1036 // indicate that positive dividends are heavily favored, so the branching |
1150 // version performs better. | 1037 // version performs better. |
1151 HMod* hmod = instr->hydrogen(); | 1038 HMod* hmod = instr->hydrogen(); |
1152 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1039 int32_t shift = WhichPowerOf2Abs(divisor); |
1153 Label dividend_is_not_negative, done; | 1040 Label dividend_is_not_negative, done; |
1154 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { | 1041 if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
1155 __ cmp(dividend, Operand::Zero()); | 1042 __ cmpwi(dividend, Operand::Zero()); |
1156 __ b(pl, ÷nd_is_not_negative); | 1043 __ bge(÷nd_is_not_negative); |
1157 // Note that this is correct even for kMinInt operands. | 1044 if (shift) { |
1158 __ rsb(dividend, dividend, Operand::Zero()); | 1045 // Note that this is correct even for kMinInt operands. |
1159 __ and_(dividend, dividend, Operand(mask)); | 1046 __ neg(dividend, dividend); |
1160 __ rsb(dividend, dividend, Operand::Zero(), SetCC); | 1047 __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
1161 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1048 __ neg(dividend, dividend, LeaveOE, SetRC); |
1162 DeoptimizeIf(eq, instr->environment()); | 1049 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1050 DeoptimizeIf(eq, instr->environment(), cr0); |
| 1051 } |
| 1052 } else if (!hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1053 __ li(dividend, Operand::Zero()); |
| 1054 } else { |
| 1055 DeoptimizeIf(al, instr->environment()); |
1163 } | 1056 } |
1164 __ b(&done); | 1057 __ b(&done); |
1165 } | 1058 } |
1166 | 1059 |
1167 __ bind(÷nd_is_not_negative); | 1060 __ bind(÷nd_is_not_negative); |
1168 __ and_(dividend, dividend, Operand(mask)); | 1061 if (shift) { |
| 1062 __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
| 1063 } else { |
| 1064 __ li(dividend, Operand::Zero()); |
| 1065 } |
1169 __ bind(&done); | 1066 __ bind(&done); |
1170 } | 1067 } |
1171 | 1068 |
1172 | 1069 |
1173 void LCodeGen::DoModByConstI(LModByConstI* instr) { | 1070 void LCodeGen::DoModByConstI(LModByConstI* instr) { |
1174 Register dividend = ToRegister(instr->dividend()); | 1071 Register dividend = ToRegister(instr->dividend()); |
1175 int32_t divisor = instr->divisor(); | 1072 int32_t divisor = instr->divisor(); |
1176 Register result = ToRegister(instr->result()); | 1073 Register result = ToRegister(instr->result()); |
1177 DCHECK(!dividend.is(result)); | 1074 DCHECK(!dividend.is(result)); |
1178 | 1075 |
1179 if (divisor == 0) { | 1076 if (divisor == 0) { |
1180 DeoptimizeIf(al, instr->environment()); | 1077 DeoptimizeIf(al, instr->environment()); |
1181 return; | 1078 return; |
1182 } | 1079 } |
1183 | 1080 |
1184 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1081 __ TruncatingDiv(result, dividend, Abs(divisor)); |
1185 __ mov(ip, Operand(Abs(divisor))); | 1082 __ mov(ip, Operand(Abs(divisor))); |
1186 __ smull(result, ip, result, ip); | 1083 __ mullw(result, result, ip); |
1187 __ sub(result, dividend, result, SetCC); | 1084 __ sub(result, dividend, result, LeaveOE, SetRC); |
1188 | 1085 |
1189 // Check for negative zero. | 1086 // Check for negative zero. |
1190 HMod* hmod = instr->hydrogen(); | 1087 HMod* hmod = instr->hydrogen(); |
1191 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1088 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1192 Label remainder_not_zero; | 1089 Label remainder_not_zero; |
1193 __ b(ne, &remainder_not_zero); | 1090 __ bne(&remainder_not_zero, cr0); |
1194 __ cmp(dividend, Operand::Zero()); | 1091 __ cmpwi(dividend, Operand::Zero()); |
1195 DeoptimizeIf(lt, instr->environment()); | 1092 DeoptimizeIf(lt, instr->environment()); |
1196 __ bind(&remainder_not_zero); | 1093 __ bind(&remainder_not_zero); |
1197 } | 1094 } |
1198 } | 1095 } |
1199 | 1096 |
1200 | 1097 |
1201 void LCodeGen::DoModI(LModI* instr) { | 1098 void LCodeGen::DoModI(LModI* instr) { |
1202 HMod* hmod = instr->hydrogen(); | 1099 HMod* hmod = instr->hydrogen(); |
1203 if (CpuFeatures::IsSupported(SUDIV)) { | 1100 Register left_reg = ToRegister(instr->left()); |
1204 CpuFeatureScope scope(masm(), SUDIV); | 1101 Register right_reg = ToRegister(instr->right()); |
| 1102 Register result_reg = ToRegister(instr->result()); |
| 1103 Register scratch = scratch0(); |
| 1104 Label done; |
1205 | 1105 |
1206 Register left_reg = ToRegister(instr->left()); | 1106 if (hmod->CheckFlag(HValue::kCanOverflow)) { |
1207 Register right_reg = ToRegister(instr->right()); | 1107 __ li(r0, Operand::Zero()); // clear xer |
1208 Register result_reg = ToRegister(instr->result()); | 1108 __ mtxer(r0); |
| 1109 } |
1209 | 1110 |
1210 Label done; | 1111 __ divw(scratch, left_reg, right_reg, SetOE, SetRC); |
1211 // Check for x % 0, sdiv might signal an exception. We have to deopt in this | 1112 |
1212 // case because we can't return a NaN. | 1113 // Check for x % 0. |
1213 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { | 1114 if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
1214 __ cmp(right_reg, Operand::Zero()); | 1115 __ cmpwi(right_reg, Operand::Zero()); |
1215 DeoptimizeIf(eq, instr->environment()); | 1116 DeoptimizeIf(eq, instr->environment()); |
| 1117 } |
| 1118 |
| 1119 // Check for kMinInt % -1, divw will return undefined, which is not what we |
| 1120 // want. We have to deopt if we care about -0, because we can't return that. |
| 1121 if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 1122 Label no_overflow_possible; |
| 1123 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1124 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1125 } else { |
| 1126 __ bnooverflow(&no_overflow_possible, cr0); |
| 1127 __ li(result_reg, Operand::Zero()); |
| 1128 __ b(&done); |
1216 } | 1129 } |
| 1130 __ bind(&no_overflow_possible); |
| 1131 } |
1217 | 1132 |
1218 // Check for kMinInt % -1, sdiv will return kMinInt, which is not what we | 1133 __ mullw(scratch, right_reg, scratch); |
1219 // want. We have to deopt if we care about -0, because we can't return that. | 1134 __ 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 | 1135 |
1235 // For 'r3 = r1 % r2' we can have the following ARM code: | 1136 // If we care about -0, test if the dividend is <0 and the result is 0. |
1236 // sdiv r3, r1, r2 | 1137 if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1237 // mls r3, r3, r2, r1 | 1138 __ bne(&done, cr0); |
| 1139 __ cmpwi(left_reg, Operand::Zero()); |
| 1140 DeoptimizeIf(lt, instr->environment()); |
| 1141 } |
1238 | 1142 |
1239 __ sdiv(result_reg, left_reg, right_reg); | 1143 __ 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 DCHECK(!scratch.is(left_reg)); | |
1258 DCHECK(!scratch.is(right_reg)); | |
1259 DCHECK(!scratch.is(result_reg)); | |
1260 DwVfpRegister dividend = ToDoubleRegister(instr->temp()); | |
1261 DwVfpRegister divisor = ToDoubleRegister(instr->temp2()); | |
1262 DCHECK(!divisor.is(dividend)); | |
1263 LowDwVfpRegister quotient = double_scratch0(); | |
1264 DCHECK(!quotient.is(dividend)); | |
1265 DCHECK(!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 } | 1144 } |
1307 | 1145 |
1308 | 1146 |
1309 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { | 1147 void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
1310 Register dividend = ToRegister(instr->dividend()); | 1148 Register dividend = ToRegister(instr->dividend()); |
1311 int32_t divisor = instr->divisor(); | 1149 int32_t divisor = instr->divisor(); |
1312 Register result = ToRegister(instr->result()); | 1150 Register result = ToRegister(instr->result()); |
1313 DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor))); | 1151 DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor))); |
1314 DCHECK(!result.is(dividend)); | 1152 DCHECK(!result.is(dividend)); |
1315 | 1153 |
1316 // Check for (0 / -x) that will produce negative zero. | 1154 // Check for (0 / -x) that will produce negative zero. |
1317 HDiv* hdiv = instr->hydrogen(); | 1155 HDiv* hdiv = instr->hydrogen(); |
1318 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1156 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1319 __ cmp(dividend, Operand::Zero()); | 1157 __ cmpwi(dividend, Operand::Zero()); |
1320 DeoptimizeIf(eq, instr->environment()); | 1158 DeoptimizeIf(eq, instr->environment()); |
1321 } | 1159 } |
1322 // Check for (kMinInt / -1). | 1160 // Check for (kMinInt / -1). |
1323 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { | 1161 if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
1324 __ cmp(dividend, Operand(kMinInt)); | 1162 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 1163 __ cmpw(dividend, r0); |
1325 DeoptimizeIf(eq, instr->environment()); | 1164 DeoptimizeIf(eq, instr->environment()); |
1326 } | 1165 } |
| 1166 |
| 1167 int32_t shift = WhichPowerOf2Abs(divisor); |
| 1168 |
1327 // Deoptimize if remainder will not be 0. | 1169 // Deoptimize if remainder will not be 0. |
1328 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && | 1170 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && shift) { |
1329 divisor != 1 && divisor != -1) { | 1171 __ TestBitRange(dividend, shift - 1, 0, r0); |
1330 int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); | 1172 DeoptimizeIf(ne, instr->environment(), cr0); |
1331 __ tst(dividend, Operand(mask)); | |
1332 DeoptimizeIf(ne, instr->environment()); | |
1333 } | 1173 } |
1334 | 1174 |
1335 if (divisor == -1) { // Nice shortcut, not needed for correctness. | 1175 if (divisor == -1) { // Nice shortcut, not needed for correctness. |
1336 __ rsb(result, dividend, Operand(0)); | 1176 __ neg(result, dividend); |
1337 return; | 1177 return; |
1338 } | 1178 } |
1339 int32_t shift = WhichPowerOf2Abs(divisor); | |
1340 if (shift == 0) { | 1179 if (shift == 0) { |
1341 __ mov(result, dividend); | 1180 __ mr(result, dividend); |
1342 } else if (shift == 1) { | |
1343 __ add(result, dividend, Operand(dividend, LSR, 31)); | |
1344 } else { | 1181 } else { |
1345 __ mov(result, Operand(dividend, ASR, 31)); | 1182 if (shift == 1) { |
1346 __ add(result, dividend, Operand(result, LSR, 32 - shift)); | 1183 __ srwi(result, dividend, Operand(31)); |
| 1184 } else { |
| 1185 __ srawi(result, dividend, 31); |
| 1186 __ srwi(result, result, Operand(32 - shift)); |
| 1187 } |
| 1188 __ add(result, dividend, result); |
| 1189 __ srawi(result, result, shift); |
1347 } | 1190 } |
1348 if (shift > 0) __ mov(result, Operand(result, ASR, shift)); | 1191 if (divisor < 0) __ neg(result, result); |
1349 if (divisor < 0) __ rsb(result, result, Operand(0)); | |
1350 } | 1192 } |
1351 | 1193 |
1352 | 1194 |
1353 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { | 1195 void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
1354 Register dividend = ToRegister(instr->dividend()); | 1196 Register dividend = ToRegister(instr->dividend()); |
1355 int32_t divisor = instr->divisor(); | 1197 int32_t divisor = instr->divisor(); |
1356 Register result = ToRegister(instr->result()); | 1198 Register result = ToRegister(instr->result()); |
1357 DCHECK(!dividend.is(result)); | 1199 DCHECK(!dividend.is(result)); |
1358 | 1200 |
1359 if (divisor == 0) { | 1201 if (divisor == 0) { |
1360 DeoptimizeIf(al, instr->environment()); | 1202 DeoptimizeIf(al, instr->environment()); |
1361 return; | 1203 return; |
1362 } | 1204 } |
1363 | 1205 |
1364 // Check for (0 / -x) that will produce negative zero. | 1206 // Check for (0 / -x) that will produce negative zero. |
1365 HDiv* hdiv = instr->hydrogen(); | 1207 HDiv* hdiv = instr->hydrogen(); |
1366 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1208 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1367 __ cmp(dividend, Operand::Zero()); | 1209 __ cmpwi(dividend, Operand::Zero()); |
1368 DeoptimizeIf(eq, instr->environment()); | 1210 DeoptimizeIf(eq, instr->environment()); |
1369 } | 1211 } |
1370 | 1212 |
1371 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1213 __ TruncatingDiv(result, dividend, Abs(divisor)); |
1372 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1214 if (divisor < 0) __ neg(result, result); |
1373 | 1215 |
1374 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { | 1216 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1217 Register scratch = scratch0(); |
1375 __ mov(ip, Operand(divisor)); | 1218 __ mov(ip, Operand(divisor)); |
1376 __ smull(scratch0(), ip, result, ip); | 1219 __ mullw(scratch, result, ip); |
1377 __ sub(scratch0(), scratch0(), dividend, SetCC); | 1220 __ cmpw(scratch, dividend); |
1378 DeoptimizeIf(ne, instr->environment()); | 1221 DeoptimizeIf(ne, instr->environment()); |
1379 } | 1222 } |
1380 } | 1223 } |
1381 | 1224 |
1382 | 1225 |
1383 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. | 1226 // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
1384 void LCodeGen::DoDivI(LDivI* instr) { | 1227 void LCodeGen::DoDivI(LDivI* instr) { |
1385 HBinaryOperation* hdiv = instr->hydrogen(); | 1228 HBinaryOperation* hdiv = instr->hydrogen(); |
1386 Register dividend = ToRegister(instr->dividend()); | 1229 const Register dividend = ToRegister(instr->dividend()); |
1387 Register divisor = ToRegister(instr->divisor()); | 1230 const Register divisor = ToRegister(instr->divisor()); |
1388 Register result = ToRegister(instr->result()); | 1231 Register result = ToRegister(instr->result()); |
1389 | 1232 |
| 1233 DCHECK(!dividend.is(result)); |
| 1234 DCHECK(!divisor.is(result)); |
| 1235 |
| 1236 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1237 __ li(r0, Operand::Zero()); // clear xer |
| 1238 __ mtxer(r0); |
| 1239 } |
| 1240 |
| 1241 __ divw(result, dividend, divisor, SetOE, SetRC); |
| 1242 |
1390 // Check for x / 0. | 1243 // Check for x / 0. |
1391 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1244 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
1392 __ cmp(divisor, Operand::Zero()); | 1245 __ cmpwi(divisor, Operand::Zero()); |
1393 DeoptimizeIf(eq, instr->environment()); | 1246 DeoptimizeIf(eq, instr->environment()); |
1394 } | 1247 } |
1395 | 1248 |
1396 // Check for (0 / -x) that will produce negative zero. | 1249 // Check for (0 / -x) that will produce negative zero. |
1397 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1250 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1398 Label positive; | 1251 Label dividend_not_zero; |
1399 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { | 1252 __ cmpwi(dividend, Operand::Zero()); |
1400 // Do the test only if it hadn't be done above. | 1253 __ bne(÷nd_not_zero); |
1401 __ cmp(divisor, Operand::Zero()); | 1254 __ cmpwi(divisor, Operand::Zero()); |
1402 } | 1255 DeoptimizeIf(lt, instr->environment()); |
1403 __ b(pl, &positive); | 1256 __ bind(÷nd_not_zero); |
1404 __ cmp(dividend, Operand::Zero()); | |
1405 DeoptimizeIf(eq, instr->environment()); | |
1406 __ bind(&positive); | |
1407 } | 1257 } |
1408 | 1258 |
1409 // Check for (kMinInt / -1). | 1259 // Check for (kMinInt / -1). |
1410 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1260 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
1411 (!CpuFeatures::IsSupported(SUDIV) || | 1261 Label no_overflow_possible; |
1412 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { | 1262 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1413 // We don't need to check for overflow when truncating with sdiv | 1263 DeoptimizeIf(overflow, instr->environment(), cr0); |
1414 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. | 1264 } else { |
1415 __ cmp(dividend, Operand(kMinInt)); | 1265 // When truncating, we want kMinInt / -1 = kMinInt. |
1416 __ cmp(divisor, Operand(-1), eq); | 1266 __ bnooverflow(&no_overflow_possible, cr0); |
1417 DeoptimizeIf(eq, instr->environment()); | 1267 __ mr(result, dividend); |
| 1268 } |
| 1269 __ bind(&no_overflow_possible); |
1418 } | 1270 } |
1419 | 1271 |
1420 if (CpuFeatures::IsSupported(SUDIV)) { | 1272 if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
1421 CpuFeatureScope scope(masm(), SUDIV); | 1273 // Deoptimize if remainder is not 0. |
1422 __ sdiv(result, dividend, divisor); | 1274 Register scratch = scratch0(); |
1423 } else { | 1275 __ mullw(scratch, divisor, result); |
1424 DoubleRegister vleft = ToDoubleRegister(instr->temp()); | 1276 __ 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()); | 1277 DeoptimizeIf(ne, instr->environment()); |
1441 } | 1278 } |
1442 } | 1279 } |
1443 | 1280 |
1444 | 1281 |
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 DCHECK(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 DCHECK(minuend.is(ToDoubleRegister(instr->result()))); | |
1464 | |
1465 __ vmls(minuend, multiplier, multiplicand); | |
1466 } | |
1467 | |
1468 | |
1469 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { | 1282 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1283 HBinaryOperation* hdiv = instr->hydrogen(); |
1470 Register dividend = ToRegister(instr->dividend()); | 1284 Register dividend = ToRegister(instr->dividend()); |
1471 Register result = ToRegister(instr->result()); | 1285 Register result = ToRegister(instr->result()); |
1472 int32_t divisor = instr->divisor(); | 1286 int32_t divisor = instr->divisor(); |
1473 | 1287 |
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 | 1288 // If the divisor is positive, things are easy: There can be no deopts and we |
1481 // can simply do an arithmetic right shift. | 1289 // can simply do an arithmetic right shift. |
1482 int32_t shift = WhichPowerOf2Abs(divisor); | 1290 int32_t shift = WhichPowerOf2Abs(divisor); |
1483 if (divisor > 1) { | 1291 if (divisor > 0) { |
1484 __ mov(result, Operand(dividend, ASR, shift)); | 1292 if (shift || !result.is(dividend)) { |
| 1293 __ srawi(result, dividend, shift); |
| 1294 } |
1485 return; | 1295 return; |
1486 } | 1296 } |
1487 | 1297 |
1488 // If the divisor is negative, we have to negate and handle edge cases. | 1298 // If the divisor is negative, we have to negate and handle edge cases. |
1489 __ rsb(result, dividend, Operand::Zero(), SetCC); | 1299 OEBit oe = LeaveOE; |
1490 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1300 #if V8_TARGET_ARCH_PPC64 |
| 1301 if (divisor == -1 && hdiv->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1302 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 1303 __ cmpw(dividend, r0); |
1491 DeoptimizeIf(eq, instr->environment()); | 1304 DeoptimizeIf(eq, instr->environment()); |
1492 } | 1305 } |
| 1306 #else |
| 1307 if (hdiv->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1308 __ li(r0, Operand::Zero()); // clear xer |
| 1309 __ mtxer(r0); |
| 1310 oe = SetOE; |
| 1311 } |
| 1312 #endif |
| 1313 |
| 1314 __ neg(result, dividend, oe, SetRC); |
| 1315 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1316 DeoptimizeIf(eq, instr->environment(), cr0); |
| 1317 } |
| 1318 |
| 1319 // If the negation could not overflow, simply shifting is OK. |
| 1320 #if !V8_TARGET_ARCH_PPC64 |
| 1321 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1322 #endif |
| 1323 if (shift) { |
| 1324 __ ShiftRightArithImm(result, result, shift); |
| 1325 } |
| 1326 return; |
| 1327 #if !V8_TARGET_ARCH_PPC64 |
| 1328 } |
1493 | 1329 |
1494 // Dividing by -1 is basically negation, unless we overflow. | 1330 // Dividing by -1 is basically negation, unless we overflow. |
1495 if (divisor == -1) { | 1331 if (divisor == -1) { |
1496 if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | 1332 DeoptimizeIf(overflow, instr->environment(), cr0); |
1497 DeoptimizeIf(vs, instr->environment()); | |
1498 } | |
1499 return; | 1333 return; |
1500 } | 1334 } |
1501 | 1335 |
1502 // If the negation could not overflow, simply shifting is OK. | 1336 Label overflow, done; |
1503 if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { | 1337 __ boverflow(&overflow, cr0); |
1504 __ mov(result, Operand(result, ASR, shift)); | 1338 __ srawi(result, result, shift); |
1505 return; | 1339 __ b(&done); |
1506 } | 1340 __ bind(&overflow); |
1507 | 1341 __ mov(result, Operand(kMinInt / divisor)); |
1508 __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs); | 1342 __ bind(&done); |
1509 __ mov(result, Operand(result, ASR, shift), LeaveCC, vc); | 1343 #endif |
1510 } | 1344 } |
1511 | 1345 |
1512 | 1346 |
1513 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { | 1347 void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
1514 Register dividend = ToRegister(instr->dividend()); | 1348 Register dividend = ToRegister(instr->dividend()); |
1515 int32_t divisor = instr->divisor(); | 1349 int32_t divisor = instr->divisor(); |
1516 Register result = ToRegister(instr->result()); | 1350 Register result = ToRegister(instr->result()); |
1517 DCHECK(!dividend.is(result)); | 1351 DCHECK(!dividend.is(result)); |
1518 | 1352 |
1519 if (divisor == 0) { | 1353 if (divisor == 0) { |
1520 DeoptimizeIf(al, instr->environment()); | 1354 DeoptimizeIf(al, instr->environment()); |
1521 return; | 1355 return; |
1522 } | 1356 } |
1523 | 1357 |
1524 // Check for (0 / -x) that will produce negative zero. | 1358 // Check for (0 / -x) that will produce negative zero. |
1525 HMathFloorOfDiv* hdiv = instr->hydrogen(); | 1359 HMathFloorOfDiv* hdiv = instr->hydrogen(); |
1526 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { | 1360 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
1527 __ cmp(dividend, Operand::Zero()); | 1361 __ cmpwi(dividend, Operand::Zero()); |
1528 DeoptimizeIf(eq, instr->environment()); | 1362 DeoptimizeIf(eq, instr->environment()); |
1529 } | 1363 } |
1530 | 1364 |
1531 // Easy case: We need no dynamic check for the dividend and the flooring | 1365 // Easy case: We need no dynamic check for the dividend and the flooring |
1532 // division is the same as the truncating division. | 1366 // division is the same as the truncating division. |
1533 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || | 1367 if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
1534 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { | 1368 (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
1535 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1369 __ TruncatingDiv(result, dividend, Abs(divisor)); |
1536 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1370 if (divisor < 0) __ neg(result, result); |
1537 return; | 1371 return; |
1538 } | 1372 } |
1539 | 1373 |
1540 // In the general case we may need to adjust before and after the truncating | 1374 // In the general case we may need to adjust before and after the truncating |
1541 // division to get a flooring division. | 1375 // division to get a flooring division. |
1542 Register temp = ToRegister(instr->temp()); | 1376 Register temp = ToRegister(instr->temp()); |
1543 DCHECK(!temp.is(dividend) && !temp.is(result)); | 1377 DCHECK(!temp.is(dividend) && !temp.is(result)); |
1544 Label needs_adjustment, done; | 1378 Label needs_adjustment, done; |
1545 __ cmp(dividend, Operand::Zero()); | 1379 __ cmpwi(dividend, Operand::Zero()); |
1546 __ b(divisor > 0 ? lt : gt, &needs_adjustment); | 1380 __ b(divisor > 0 ? lt : gt, &needs_adjustment); |
1547 __ TruncatingDiv(result, dividend, Abs(divisor)); | 1381 __ TruncatingDiv(result, dividend, Abs(divisor)); |
1548 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1382 if (divisor < 0) __ neg(result, result); |
1549 __ jmp(&done); | 1383 __ b(&done); |
1550 __ bind(&needs_adjustment); | 1384 __ bind(&needs_adjustment); |
1551 __ add(temp, dividend, Operand(divisor > 0 ? 1 : -1)); | 1385 __ addi(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
1552 __ TruncatingDiv(result, temp, Abs(divisor)); | 1386 __ TruncatingDiv(result, temp, Abs(divisor)); |
1553 if (divisor < 0) __ rsb(result, result, Operand::Zero()); | 1387 if (divisor < 0) __ neg(result, result); |
1554 __ sub(result, result, Operand(1)); | 1388 __ subi(result, result, Operand(1)); |
1555 __ bind(&done); | 1389 __ bind(&done); |
1556 } | 1390 } |
1557 | 1391 |
1558 | 1392 |
1559 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. | 1393 // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
1560 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { | 1394 void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
1561 HBinaryOperation* hdiv = instr->hydrogen(); | 1395 HBinaryOperation* hdiv = instr->hydrogen(); |
1562 Register left = ToRegister(instr->dividend()); | 1396 const Register dividend = ToRegister(instr->dividend()); |
1563 Register right = ToRegister(instr->divisor()); | 1397 const Register divisor = ToRegister(instr->divisor()); |
1564 Register result = ToRegister(instr->result()); | 1398 Register result = ToRegister(instr->result()); |
1565 | 1399 |
| 1400 DCHECK(!dividend.is(result)); |
| 1401 DCHECK(!divisor.is(result)); |
| 1402 |
| 1403 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1404 __ li(r0, Operand::Zero()); // clear xer |
| 1405 __ mtxer(r0); |
| 1406 } |
| 1407 |
| 1408 __ divw(result, dividend, divisor, SetOE, SetRC); |
| 1409 |
1566 // Check for x / 0. | 1410 // Check for x / 0. |
1567 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { | 1411 if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
1568 __ cmp(right, Operand::Zero()); | 1412 __ cmpwi(divisor, Operand::Zero()); |
1569 DeoptimizeIf(eq, instr->environment()); | 1413 DeoptimizeIf(eq, instr->environment()); |
1570 } | 1414 } |
1571 | 1415 |
1572 // Check for (0 / -x) that will produce negative zero. | 1416 // Check for (0 / -x) that will produce negative zero. |
1573 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1417 if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1574 Label positive; | 1418 Label dividend_not_zero; |
1575 if (!instr->hydrogen_value()->CheckFlag(HValue::kCanBeDivByZero)) { | 1419 __ cmpwi(dividend, Operand::Zero()); |
1576 // Do the test only if it hadn't be done above. | 1420 __ bne(÷nd_not_zero); |
1577 __ cmp(right, Operand::Zero()); | 1421 __ cmpwi(divisor, Operand::Zero()); |
1578 } | 1422 DeoptimizeIf(lt, instr->environment()); |
1579 __ b(pl, &positive); | 1423 __ bind(÷nd_not_zero); |
1580 __ cmp(left, Operand::Zero()); | |
1581 DeoptimizeIf(eq, instr->environment()); | |
1582 __ bind(&positive); | |
1583 } | 1424 } |
1584 | 1425 |
1585 // Check for (kMinInt / -1). | 1426 // Check for (kMinInt / -1). |
1586 if (hdiv->CheckFlag(HValue::kCanOverflow) && | 1427 if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
1587 (!CpuFeatures::IsSupported(SUDIV) || | 1428 Label no_overflow_possible; |
1588 !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { | 1429 if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
1589 // We don't need to check for overflow when truncating with sdiv | 1430 DeoptimizeIf(overflow, instr->environment(), cr0); |
1590 // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. | 1431 } else { |
1591 __ cmp(left, Operand(kMinInt)); | 1432 // When truncating, we want kMinInt / -1 = kMinInt. |
1592 __ cmp(right, Operand(-1), eq); | 1433 __ bnooverflow(&no_overflow_possible, cr0); |
1593 DeoptimizeIf(eq, instr->environment()); | 1434 __ mr(result, dividend); |
1594 } | 1435 } |
1595 | 1436 __ 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 } | 1437 } |
1610 | 1438 |
1611 Label done; | 1439 Label done; |
1612 Register remainder = scratch0(); | 1440 Register scratch = scratch0(); |
1613 __ Mls(remainder, result, right, left); | 1441 // If both operands have the same sign then we are done. |
1614 __ cmp(remainder, Operand::Zero()); | 1442 #if V8_TARGET_ARCH_PPC64 |
1615 __ b(eq, &done); | 1443 __ xor_(scratch, dividend, divisor); |
1616 __ eor(remainder, remainder, Operand(right)); | 1444 __ cmpwi(scratch, Operand::Zero()); |
1617 __ add(result, result, Operand(remainder, ASR, 31)); | 1445 __ bge(&done); |
| 1446 #else |
| 1447 __ xor_(scratch, dividend, divisor, SetRC); |
| 1448 __ bge(&done, cr0); |
| 1449 #endif |
| 1450 |
| 1451 // If there is no remainder then we are done. |
| 1452 __ mullw(scratch, divisor, result); |
| 1453 __ cmpw(dividend, scratch); |
| 1454 __ beq(&done); |
| 1455 |
| 1456 // We performed a truncating division. Correct the result. |
| 1457 __ subi(result, result, Operand(1)); |
1618 __ bind(&done); | 1458 __ bind(&done); |
1619 } | 1459 } |
1620 | 1460 |
1621 | 1461 |
| 1462 void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1463 DoubleRegister addend = ToDoubleRegister(instr->addend()); |
| 1464 DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1465 DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1466 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1467 |
| 1468 __ fmadd(result, multiplier, multiplicand, addend); |
| 1469 } |
| 1470 |
| 1471 |
| 1472 void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { |
| 1473 DoubleRegister minuend = ToDoubleRegister(instr->minuend()); |
| 1474 DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1475 DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1476 DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1477 |
| 1478 __ fmsub(result, multiplier, multiplicand, minuend); |
| 1479 } |
| 1480 |
| 1481 |
1622 void LCodeGen::DoMulI(LMulI* instr) { | 1482 void LCodeGen::DoMulI(LMulI* instr) { |
| 1483 Register scratch = scratch0(); |
1623 Register result = ToRegister(instr->result()); | 1484 Register result = ToRegister(instr->result()); |
1624 // Note that result may alias left. | 1485 // Note that result may alias left. |
1625 Register left = ToRegister(instr->left()); | 1486 Register left = ToRegister(instr->left()); |
1626 LOperand* right_op = instr->right(); | 1487 LOperand* right_op = instr->right(); |
1627 | 1488 |
1628 bool bailout_on_minus_zero = | 1489 bool bailout_on_minus_zero = |
1629 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); | 1490 instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
1630 bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1491 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
1631 | 1492 |
1632 if (right_op->IsConstantOperand()) { | 1493 if (right_op->IsConstantOperand()) { |
1633 int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); | 1494 int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
1634 | 1495 |
1635 if (bailout_on_minus_zero && (constant < 0)) { | 1496 if (bailout_on_minus_zero && (constant < 0)) { |
1636 // The case of a null constant will be handled separately. | 1497 // The case of a null constant will be handled separately. |
1637 // If constant is negative and left is null, the result should be -0. | 1498 // If constant is negative and left is null, the result should be -0. |
1638 __ cmp(left, Operand::Zero()); | 1499 __ cmpi(left, Operand::Zero()); |
1639 DeoptimizeIf(eq, instr->environment()); | 1500 DeoptimizeIf(eq, instr->environment()); |
1640 } | 1501 } |
1641 | 1502 |
1642 switch (constant) { | 1503 switch (constant) { |
1643 case -1: | 1504 case -1: |
1644 if (overflow) { | 1505 if (can_overflow) { |
1645 __ rsb(result, left, Operand::Zero(), SetCC); | 1506 #if V8_TARGET_ARCH_PPC64 |
1646 DeoptimizeIf(vs, instr->environment()); | 1507 if (instr->hydrogen()->representation().IsSmi()) { |
| 1508 #endif |
| 1509 __ li(r0, Operand::Zero()); // clear xer |
| 1510 __ mtxer(r0); |
| 1511 __ neg(result, left, SetOE, SetRC); |
| 1512 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 1513 #if V8_TARGET_ARCH_PPC64 |
| 1514 } else { |
| 1515 __ neg(result, left); |
| 1516 __ TestIfInt32(result, scratch, r0); |
| 1517 DeoptimizeIf(ne, instr->environment()); |
| 1518 } |
| 1519 #endif |
1647 } else { | 1520 } else { |
1648 __ rsb(result, left, Operand::Zero()); | 1521 __ neg(result, left); |
1649 } | 1522 } |
1650 break; | 1523 break; |
1651 case 0: | 1524 case 0: |
1652 if (bailout_on_minus_zero) { | 1525 if (bailout_on_minus_zero) { |
1653 // If left is strictly negative and the constant is null, the | 1526 // If left is strictly negative and the constant is null, the |
1654 // result is -0. Deoptimize if required, otherwise return 0. | 1527 // result is -0. Deoptimize if required, otherwise return 0. |
1655 __ cmp(left, Operand::Zero()); | 1528 #if V8_TARGET_ARCH_PPC64 |
1656 DeoptimizeIf(mi, instr->environment()); | 1529 if (instr->hydrogen()->representation().IsSmi()) { |
| 1530 #endif |
| 1531 __ cmpi(left, Operand::Zero()); |
| 1532 #if V8_TARGET_ARCH_PPC64 |
| 1533 } else { |
| 1534 __ cmpwi(left, Operand::Zero()); |
| 1535 } |
| 1536 #endif |
| 1537 DeoptimizeIf(lt, instr->environment()); |
1657 } | 1538 } |
1658 __ mov(result, Operand::Zero()); | 1539 __ li(result, Operand::Zero()); |
1659 break; | 1540 break; |
1660 case 1: | 1541 case 1: |
1661 __ Move(result, left); | 1542 __ Move(result, left); |
1662 break; | 1543 break; |
1663 default: | 1544 default: |
1664 // Multiplying by powers of two and powers of two plus or minus | 1545 // Multiplying by powers of two and powers of two plus or minus |
1665 // one can be done faster with shifted operands. | 1546 // one can be done faster with shifted operands. |
1666 // For other constants we emit standard code. | 1547 // For other constants we emit standard code. |
1667 int32_t mask = constant >> 31; | 1548 int32_t mask = constant >> 31; |
1668 uint32_t constant_abs = (constant + mask) ^ mask; | 1549 uint32_t constant_abs = (constant + mask) ^ mask; |
1669 | 1550 |
1670 if (IsPowerOf2(constant_abs)) { | 1551 if (IsPowerOf2(constant_abs)) { |
1671 int32_t shift = WhichPowerOf2(constant_abs); | 1552 int32_t shift = WhichPowerOf2(constant_abs); |
1672 __ mov(result, Operand(left, LSL, shift)); | 1553 __ ShiftLeftImm(result, left, Operand(shift)); |
1673 // Correct the sign of the result is the constant is negative. | 1554 // Correct the sign of the result if the constant is negative. |
1674 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1555 if (constant < 0) __ neg(result, result); |
1675 } else if (IsPowerOf2(constant_abs - 1)) { | 1556 } else if (IsPowerOf2(constant_abs - 1)) { |
1676 int32_t shift = WhichPowerOf2(constant_abs - 1); | 1557 int32_t shift = WhichPowerOf2(constant_abs - 1); |
1677 __ add(result, left, Operand(left, LSL, shift)); | 1558 __ ShiftLeftImm(scratch, left, Operand(shift)); |
1678 // Correct the sign of the result is the constant is negative. | 1559 __ add(result, scratch, left); |
1679 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1560 // Correct the sign of the result if the constant is negative. |
| 1561 if (constant < 0) __ neg(result, result); |
1680 } else if (IsPowerOf2(constant_abs + 1)) { | 1562 } else if (IsPowerOf2(constant_abs + 1)) { |
1681 int32_t shift = WhichPowerOf2(constant_abs + 1); | 1563 int32_t shift = WhichPowerOf2(constant_abs + 1); |
1682 __ rsb(result, left, Operand(left, LSL, shift)); | 1564 __ ShiftLeftImm(scratch, left, Operand(shift)); |
1683 // Correct the sign of the result is the constant is negative. | 1565 __ sub(result, scratch, left); |
1684 if (constant < 0) __ rsb(result, result, Operand::Zero()); | 1566 // Correct the sign of the result if the constant is negative. |
| 1567 if (constant < 0) __ neg(result, result); |
1685 } else { | 1568 } else { |
1686 // Generate standard code. | 1569 // Generate standard code. |
1687 __ mov(ip, Operand(constant)); | 1570 __ mov(ip, Operand(constant)); |
1688 __ mul(result, left, ip); | 1571 __ Mul(result, left, ip); |
1689 } | 1572 } |
1690 } | 1573 } |
1691 | 1574 |
1692 } else { | 1575 } else { |
1693 DCHECK(right_op->IsRegister()); | 1576 DCHECK(right_op->IsRegister()); |
1694 Register right = ToRegister(right_op); | 1577 Register right = ToRegister(right_op); |
1695 | 1578 |
1696 if (overflow) { | 1579 if (can_overflow) { |
1697 Register scratch = scratch0(); | 1580 #if V8_TARGET_ARCH_PPC64 |
| 1581 // result = left * right. |
| 1582 if (instr->hydrogen()->representation().IsSmi()) { |
| 1583 __ SmiUntag(result, left); |
| 1584 __ SmiUntag(scratch, right); |
| 1585 __ Mul(result, result, scratch); |
| 1586 } else { |
| 1587 __ Mul(result, left, right); |
| 1588 } |
| 1589 __ TestIfInt32(result, scratch, r0); |
| 1590 DeoptimizeIf(ne, instr->environment()); |
| 1591 if (instr->hydrogen()->representation().IsSmi()) { |
| 1592 __ SmiTag(result); |
| 1593 } |
| 1594 #else |
1698 // scratch:result = left * right. | 1595 // scratch:result = left * right. |
1699 if (instr->hydrogen()->representation().IsSmi()) { | 1596 if (instr->hydrogen()->representation().IsSmi()) { |
1700 __ SmiUntag(result, left); | 1597 __ SmiUntag(result, left); |
1701 __ smull(result, scratch, result, right); | 1598 __ mulhw(scratch, result, right); |
| 1599 __ mullw(result, result, right); |
1702 } else { | 1600 } else { |
1703 __ smull(result, scratch, left, right); | 1601 __ mulhw(scratch, left, right); |
| 1602 __ mullw(result, left, right); |
1704 } | 1603 } |
1705 __ cmp(scratch, Operand(result, ASR, 31)); | 1604 __ TestIfInt32(scratch, result, r0); |
1706 DeoptimizeIf(ne, instr->environment()); | 1605 DeoptimizeIf(ne, instr->environment()); |
| 1606 #endif |
1707 } else { | 1607 } else { |
1708 if (instr->hydrogen()->representation().IsSmi()) { | 1608 if (instr->hydrogen()->representation().IsSmi()) { |
1709 __ SmiUntag(result, left); | 1609 __ SmiUntag(result, left); |
1710 __ mul(result, result, right); | 1610 __ Mul(result, result, right); |
1711 } else { | 1611 } else { |
1712 __ mul(result, left, right); | 1612 __ Mul(result, left, right); |
1713 } | 1613 } |
1714 } | 1614 } |
1715 | 1615 |
1716 if (bailout_on_minus_zero) { | 1616 if (bailout_on_minus_zero) { |
1717 Label done; | 1617 Label done; |
1718 __ teq(left, Operand(right)); | 1618 #if V8_TARGET_ARCH_PPC64 |
1719 __ b(pl, &done); | 1619 if (instr->hydrogen()->representation().IsSmi()) { |
| 1620 #endif |
| 1621 __ xor_(r0, left, right, SetRC); |
| 1622 __ bge(&done, cr0); |
| 1623 #if V8_TARGET_ARCH_PPC64 |
| 1624 } else { |
| 1625 __ xor_(r0, left, right); |
| 1626 __ cmpwi(r0, Operand::Zero()); |
| 1627 __ bge(&done); |
| 1628 } |
| 1629 #endif |
1720 // Bail out if the result is minus zero. | 1630 // Bail out if the result is minus zero. |
1721 __ cmp(result, Operand::Zero()); | 1631 __ cmpi(result, Operand::Zero()); |
1722 DeoptimizeIf(eq, instr->environment()); | 1632 DeoptimizeIf(eq, instr->environment()); |
1723 __ bind(&done); | 1633 __ bind(&done); |
1724 } | 1634 } |
1725 } | 1635 } |
1726 } | 1636 } |
1727 | 1637 |
1728 | 1638 |
1729 void LCodeGen::DoBitI(LBitI* instr) { | 1639 void LCodeGen::DoBitI(LBitI* instr) { |
1730 LOperand* left_op = instr->left(); | 1640 LOperand* left_op = instr->left(); |
1731 LOperand* right_op = instr->right(); | 1641 LOperand* right_op = instr->right(); |
1732 DCHECK(left_op->IsRegister()); | 1642 DCHECK(left_op->IsRegister()); |
1733 Register left = ToRegister(left_op); | 1643 Register left = ToRegister(left_op); |
1734 Register result = ToRegister(instr->result()); | 1644 Register result = ToRegister(instr->result()); |
1735 Operand right(no_reg); | 1645 Operand right(no_reg); |
1736 | 1646 |
1737 if (right_op->IsStackSlot()) { | 1647 if (right_op->IsStackSlot()) { |
1738 right = Operand(EmitLoadRegister(right_op, ip)); | 1648 right = Operand(EmitLoadRegister(right_op, ip)); |
1739 } else { | 1649 } else { |
1740 DCHECK(right_op->IsRegister() || right_op->IsConstantOperand()); | 1650 DCHECK(right_op->IsRegister() || right_op->IsConstantOperand()); |
1741 right = ToOperand(right_op); | 1651 right = ToOperand(right_op); |
| 1652 |
| 1653 if (right_op->IsConstantOperand() && is_uint16(right.immediate())) { |
| 1654 switch (instr->op()) { |
| 1655 case Token::BIT_AND: |
| 1656 __ andi(result, left, right); |
| 1657 break; |
| 1658 case Token::BIT_OR: |
| 1659 __ ori(result, left, right); |
| 1660 break; |
| 1661 case Token::BIT_XOR: |
| 1662 __ xori(result, left, right); |
| 1663 break; |
| 1664 default: |
| 1665 UNREACHABLE(); |
| 1666 break; |
| 1667 } |
| 1668 return; |
| 1669 } |
1742 } | 1670 } |
1743 | 1671 |
1744 switch (instr->op()) { | 1672 switch (instr->op()) { |
1745 case Token::BIT_AND: | 1673 case Token::BIT_AND: |
1746 __ and_(result, left, right); | 1674 __ And(result, left, right); |
1747 break; | 1675 break; |
1748 case Token::BIT_OR: | 1676 case Token::BIT_OR: |
1749 __ orr(result, left, right); | 1677 __ Or(result, left, right); |
1750 break; | 1678 break; |
1751 case Token::BIT_XOR: | 1679 case Token::BIT_XOR: |
1752 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { | 1680 if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { |
1753 __ mvn(result, Operand(left)); | 1681 __ notx(result, left); |
1754 } else { | 1682 } else { |
1755 __ eor(result, left, right); | 1683 __ Xor(result, left, right); |
1756 } | 1684 } |
1757 break; | 1685 break; |
1758 default: | 1686 default: |
1759 UNREACHABLE(); | 1687 UNREACHABLE(); |
1760 break; | 1688 break; |
1761 } | 1689 } |
1762 } | 1690 } |
1763 | 1691 |
1764 | 1692 |
1765 void LCodeGen::DoShiftI(LShiftI* instr) { | 1693 void LCodeGen::DoShiftI(LShiftI* instr) { |
1766 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so | 1694 // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
1767 // result may alias either of them. | 1695 // result may alias either of them. |
1768 LOperand* right_op = instr->right(); | 1696 LOperand* right_op = instr->right(); |
1769 Register left = ToRegister(instr->left()); | 1697 Register left = ToRegister(instr->left()); |
1770 Register result = ToRegister(instr->result()); | 1698 Register result = ToRegister(instr->result()); |
1771 Register scratch = scratch0(); | 1699 Register scratch = scratch0(); |
1772 if (right_op->IsRegister()) { | 1700 if (right_op->IsRegister()) { |
1773 // Mask the right_op operand. | 1701 // Mask the right_op operand. |
1774 __ and_(scratch, ToRegister(right_op), Operand(0x1F)); | 1702 __ andi(scratch, ToRegister(right_op), Operand(0x1F)); |
1775 switch (instr->op()) { | 1703 switch (instr->op()) { |
1776 case Token::ROR: | 1704 case Token::ROR: |
1777 __ mov(result, Operand(left, ROR, scratch)); | 1705 // rotate_right(a, b) == rotate_left(a, 32 - b) |
| 1706 __ subfic(scratch, scratch, Operand(32)); |
| 1707 __ rotlw(result, left, scratch); |
1778 break; | 1708 break; |
1779 case Token::SAR: | 1709 case Token::SAR: |
1780 __ mov(result, Operand(left, ASR, scratch)); | 1710 __ sraw(result, left, scratch); |
1781 break; | 1711 break; |
1782 case Token::SHR: | 1712 case Token::SHR: |
1783 if (instr->can_deopt()) { | 1713 if (instr->can_deopt()) { |
1784 __ mov(result, Operand(left, LSR, scratch), SetCC); | 1714 __ srw(result, left, scratch, SetRC); |
1785 DeoptimizeIf(mi, instr->environment()); | 1715 #if V8_TARGET_ARCH_PPC64 |
| 1716 __ extsw(result, result, SetRC); |
| 1717 #endif |
| 1718 DeoptimizeIf(lt, instr->environment(), cr0); |
1786 } else { | 1719 } else { |
1787 __ mov(result, Operand(left, LSR, scratch)); | 1720 __ srw(result, left, scratch); |
1788 } | 1721 } |
1789 break; | 1722 break; |
1790 case Token::SHL: | 1723 case Token::SHL: |
1791 __ mov(result, Operand(left, LSL, scratch)); | 1724 __ slw(result, left, scratch); |
| 1725 #if V8_TARGET_ARCH_PPC64 |
| 1726 __ extsw(result, result); |
| 1727 #endif |
1792 break; | 1728 break; |
1793 default: | 1729 default: |
1794 UNREACHABLE(); | 1730 UNREACHABLE(); |
1795 break; | 1731 break; |
1796 } | 1732 } |
1797 } else { | 1733 } else { |
1798 // Mask the right_op operand. | 1734 // Mask the right_op operand. |
1799 int value = ToInteger32(LConstantOperand::cast(right_op)); | 1735 int value = ToInteger32(LConstantOperand::cast(right_op)); |
1800 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); | 1736 uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
1801 switch (instr->op()) { | 1737 switch (instr->op()) { |
1802 case Token::ROR: | 1738 case Token::ROR: |
1803 if (shift_count != 0) { | 1739 if (shift_count != 0) { |
1804 __ mov(result, Operand(left, ROR, shift_count)); | 1740 __ rotrwi(result, left, shift_count); |
1805 } else { | 1741 } else { |
1806 __ Move(result, left); | 1742 __ Move(result, left); |
1807 } | 1743 } |
1808 break; | 1744 break; |
1809 case Token::SAR: | 1745 case Token::SAR: |
1810 if (shift_count != 0) { | 1746 if (shift_count != 0) { |
1811 __ mov(result, Operand(left, ASR, shift_count)); | 1747 __ srawi(result, left, shift_count); |
1812 } else { | 1748 } else { |
1813 __ Move(result, left); | 1749 __ Move(result, left); |
1814 } | 1750 } |
1815 break; | 1751 break; |
1816 case Token::SHR: | 1752 case Token::SHR: |
1817 if (shift_count != 0) { | 1753 if (shift_count != 0) { |
1818 __ mov(result, Operand(left, LSR, shift_count)); | 1754 __ srwi(result, left, Operand(shift_count)); |
1819 } else { | 1755 } else { |
1820 if (instr->can_deopt()) { | 1756 if (instr->can_deopt()) { |
1821 __ tst(left, Operand(0x80000000)); | 1757 __ cmpwi(left, Operand::Zero()); |
1822 DeoptimizeIf(ne, instr->environment()); | 1758 DeoptimizeIf(lt, instr->environment()); |
1823 } | 1759 } |
1824 __ Move(result, left); | 1760 __ Move(result, left); |
1825 } | 1761 } |
1826 break; | 1762 break; |
1827 case Token::SHL: | 1763 case Token::SHL: |
1828 if (shift_count != 0) { | 1764 if (shift_count != 0) { |
| 1765 #if V8_TARGET_ARCH_PPC64 |
| 1766 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 1767 __ sldi(result, left, Operand(shift_count)); |
| 1768 #else |
1829 if (instr->hydrogen_value()->representation().IsSmi() && | 1769 if (instr->hydrogen_value()->representation().IsSmi() && |
1830 instr->can_deopt()) { | 1770 instr->can_deopt()) { |
1831 if (shift_count != 1) { | 1771 if (shift_count != 1) { |
1832 __ mov(result, Operand(left, LSL, shift_count - 1)); | 1772 __ slwi(result, left, Operand(shift_count - 1)); |
1833 __ SmiTag(result, result, SetCC); | 1773 __ SmiTagCheckOverflow(result, result, scratch); |
1834 } else { | 1774 } else { |
1835 __ SmiTag(result, left, SetCC); | 1775 __ SmiTagCheckOverflow(result, left, scratch); |
1836 } | 1776 } |
1837 DeoptimizeIf(vs, instr->environment()); | 1777 DeoptimizeIf(lt, instr->environment(), cr0); |
| 1778 #endif |
1838 } else { | 1779 } else { |
1839 __ mov(result, Operand(left, LSL, shift_count)); | 1780 __ slwi(result, left, Operand(shift_count)); |
| 1781 #if V8_TARGET_ARCH_PPC64 |
| 1782 __ extsw(result, result); |
| 1783 #endif |
1840 } | 1784 } |
1841 } else { | 1785 } else { |
1842 __ Move(result, left); | 1786 __ Move(result, left); |
1843 } | 1787 } |
1844 break; | 1788 break; |
1845 default: | 1789 default: |
1846 UNREACHABLE(); | 1790 UNREACHABLE(); |
1847 break; | 1791 break; |
1848 } | 1792 } |
1849 } | 1793 } |
1850 } | 1794 } |
1851 | 1795 |
1852 | 1796 |
1853 void LCodeGen::DoSubI(LSubI* instr) { | 1797 void LCodeGen::DoSubI(LSubI* instr) { |
1854 LOperand* left = instr->left(); | |
1855 LOperand* right = instr->right(); | 1798 LOperand* right = instr->right(); |
1856 LOperand* result = instr->result(); | 1799 Register left = ToRegister(instr->left()); |
| 1800 Register result = ToRegister(instr->result()); |
1857 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 1801 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
1858 SBit set_cond = can_overflow ? SetCC : LeaveCC; | 1802 if (!can_overflow && right->IsConstantOperand()) { |
| 1803 Operand right_operand = ToOperand(right); |
| 1804 __ Add(result, left, -right_operand.immediate(), r0); |
| 1805 } else { |
| 1806 Register right_reg = EmitLoadRegister(right, ip); |
1859 | 1807 |
1860 if (right->IsStackSlot()) { | 1808 if (!can_overflow) { |
1861 Register right_reg = EmitLoadRegister(right, ip); | 1809 __ sub(result, left, right_reg); |
1862 __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 1810 } else { |
1863 } else { | 1811 __ SubAndCheckForOverflow(result, left, right_reg, scratch0(), r0); |
1864 DCHECK(right->IsRegister() || right->IsConstantOperand()); | 1812 // Doptimize on overflow |
1865 __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 1813 #if V8_TARGET_ARCH_PPC64 |
| 1814 if (!instr->hydrogen()->representation().IsSmi()) { |
| 1815 __ extsw(scratch0(), scratch0(), SetRC); |
| 1816 } |
| 1817 #endif |
| 1818 DeoptimizeIf(lt, instr->environment(), cr0); |
| 1819 } |
1866 } | 1820 } |
1867 | 1821 |
1868 if (can_overflow) { | 1822 #if V8_TARGET_ARCH_PPC64 |
1869 DeoptimizeIf(vs, instr->environment()); | 1823 if (!instr->hydrogen()->representation().IsSmi()) { |
| 1824 __ extsw(result, result); |
1870 } | 1825 } |
| 1826 #endif |
1871 } | 1827 } |
1872 | 1828 |
1873 | 1829 |
1874 void LCodeGen::DoRSubI(LRSubI* instr) { | 1830 void LCodeGen::DoRSubI(LRSubI* instr) { |
1875 LOperand* left = instr->left(); | 1831 LOperand* left = instr->left(); |
1876 LOperand* right = instr->right(); | 1832 LOperand* right = instr->right(); |
1877 LOperand* result = instr->result(); | 1833 LOperand* result = instr->result(); |
1878 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | |
1879 SBit set_cond = can_overflow ? SetCC : LeaveCC; | |
1880 | 1834 |
1881 if (right->IsStackSlot()) { | 1835 DCHECK(!instr->hydrogen()->CheckFlag(HValue::kCanOverflow) && |
1882 Register right_reg = EmitLoadRegister(right, ip); | 1836 right->IsConstantOperand()); |
1883 __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 1837 |
| 1838 Operand right_operand = ToOperand(right); |
| 1839 if (is_int16(right_operand.immediate())) { |
| 1840 __ subfic(ToRegister(result), ToRegister(left), right_operand); |
1884 } else { | 1841 } else { |
1885 DCHECK(right->IsRegister() || right->IsConstantOperand()); | 1842 __ mov(r0, right_operand); |
1886 __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 1843 __ sub(ToRegister(result), r0, ToRegister(left)); |
1887 } | |
1888 | |
1889 if (can_overflow) { | |
1890 DeoptimizeIf(vs, instr->environment()); | |
1891 } | 1844 } |
1892 } | 1845 } |
1893 | 1846 |
1894 | 1847 |
1895 void LCodeGen::DoConstantI(LConstantI* instr) { | 1848 void LCodeGen::DoConstantI(LConstantI* instr) { |
1896 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1849 __ mov(ToRegister(instr->result()), Operand(instr->value())); |
1897 } | 1850 } |
1898 | 1851 |
1899 | 1852 |
1900 void LCodeGen::DoConstantS(LConstantS* instr) { | 1853 void LCodeGen::DoConstantS(LConstantS* instr) { |
1901 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1854 __ LoadSmiLiteral(ToRegister(instr->result()), instr->value()); |
1902 } | 1855 } |
1903 | 1856 |
1904 | 1857 |
| 1858 // TODO(penguin): put const to constant pool instead |
| 1859 // of storing double to stack |
1905 void LCodeGen::DoConstantD(LConstantD* instr) { | 1860 void LCodeGen::DoConstantD(LConstantD* instr) { |
1906 DCHECK(instr->result()->IsDoubleRegister()); | 1861 DCHECK(instr->result()->IsDoubleRegister()); |
1907 DwVfpRegister result = ToDoubleRegister(instr->result()); | 1862 DoubleRegister result = ToDoubleRegister(instr->result()); |
1908 double v = instr->value(); | 1863 double v = instr->value(); |
1909 __ Vmov(result, v, scratch0()); | 1864 __ LoadDoubleLiteral(result, v, scratch0()); |
1910 } | 1865 } |
1911 | 1866 |
1912 | 1867 |
1913 void LCodeGen::DoConstantE(LConstantE* instr) { | 1868 void LCodeGen::DoConstantE(LConstantE* instr) { |
1914 __ mov(ToRegister(instr->result()), Operand(instr->value())); | 1869 __ mov(ToRegister(instr->result()), Operand(instr->value())); |
1915 } | 1870 } |
1916 | 1871 |
1917 | 1872 |
1918 void LCodeGen::DoConstantT(LConstantT* instr) { | 1873 void LCodeGen::DoConstantT(LConstantT* instr) { |
1919 Handle<Object> object = instr->value(isolate()); | 1874 Handle<Object> object = instr->value(isolate()); |
1920 AllowDeferredHandleDereference smi_check; | 1875 AllowDeferredHandleDereference smi_check; |
1921 __ Move(ToRegister(instr->result()), object); | 1876 __ Move(ToRegister(instr->result()), object); |
1922 } | 1877 } |
1923 | 1878 |
1924 | 1879 |
1925 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { | 1880 void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
1926 Register result = ToRegister(instr->result()); | 1881 Register result = ToRegister(instr->result()); |
1927 Register map = ToRegister(instr->value()); | 1882 Register map = ToRegister(instr->value()); |
1928 __ EnumLength(result, map); | 1883 __ EnumLength(result, map); |
1929 } | 1884 } |
1930 | 1885 |
1931 | 1886 |
1932 void LCodeGen::DoDateField(LDateField* instr) { | 1887 void LCodeGen::DoDateField(LDateField* instr) { |
1933 Register object = ToRegister(instr->date()); | 1888 Register object = ToRegister(instr->date()); |
1934 Register result = ToRegister(instr->result()); | 1889 Register result = ToRegister(instr->result()); |
1935 Register scratch = ToRegister(instr->temp()); | 1890 Register scratch = ToRegister(instr->temp()); |
1936 Smi* index = instr->index(); | 1891 Smi* index = instr->index(); |
1937 Label runtime, done; | 1892 Label runtime, done; |
1938 DCHECK(object.is(result)); | 1893 DCHECK(object.is(result)); |
1939 DCHECK(object.is(r0)); | 1894 DCHECK(object.is(r3)); |
1940 DCHECK(!scratch.is(scratch0())); | 1895 DCHECK(!scratch.is(scratch0())); |
1941 DCHECK(!scratch.is(object)); | 1896 DCHECK(!scratch.is(object)); |
1942 | 1897 |
1943 __ SmiTst(object); | 1898 __ TestIfSmi(object, r0); |
1944 DeoptimizeIf(eq, instr->environment()); | 1899 DeoptimizeIf(eq, instr->environment(), cr0); |
1945 __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); | 1900 __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); |
1946 DeoptimizeIf(ne, instr->environment()); | 1901 DeoptimizeIf(ne, instr->environment()); |
1947 | 1902 |
1948 if (index->value() == 0) { | 1903 if (index->value() == 0) { |
1949 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); | 1904 __ LoadP(result, FieldMemOperand(object, JSDate::kValueOffset)); |
1950 } else { | 1905 } else { |
1951 if (index->value() < JSDate::kFirstUncachedField) { | 1906 if (index->value() < JSDate::kFirstUncachedField) { |
1952 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); | 1907 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
1953 __ mov(scratch, Operand(stamp)); | 1908 __ mov(scratch, Operand(stamp)); |
1954 __ ldr(scratch, MemOperand(scratch)); | 1909 __ LoadP(scratch, MemOperand(scratch)); |
1955 __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); | 1910 __ LoadP(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
1956 __ cmp(scratch, scratch0()); | 1911 __ cmp(scratch, scratch0()); |
1957 __ b(ne, &runtime); | 1912 __ bne(&runtime); |
1958 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset + | 1913 __ LoadP(result, |
1959 kPointerSize * index->value())); | 1914 FieldMemOperand(object, JSDate::kValueOffset + |
1960 __ jmp(&done); | 1915 kPointerSize * index->value())); |
| 1916 __ b(&done); |
1961 } | 1917 } |
1962 __ bind(&runtime); | 1918 __ bind(&runtime); |
1963 __ PrepareCallCFunction(2, scratch); | 1919 __ PrepareCallCFunction(2, scratch); |
1964 __ mov(r1, Operand(index)); | 1920 __ LoadSmiLiteral(r4, index); |
1965 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); | 1921 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
1966 __ bind(&done); | 1922 __ bind(&done); |
1967 } | 1923 } |
1968 } | 1924 } |
1969 | 1925 |
1970 | 1926 |
1971 MemOperand LCodeGen::BuildSeqStringOperand(Register string, | 1927 MemOperand LCodeGen::BuildSeqStringOperand(Register string, LOperand* index, |
1972 LOperand* index, | |
1973 String::Encoding encoding) { | 1928 String::Encoding encoding) { |
1974 if (index->IsConstantOperand()) { | 1929 if (index->IsConstantOperand()) { |
1975 int offset = ToInteger32(LConstantOperand::cast(index)); | 1930 int offset = ToInteger32(LConstantOperand::cast(index)); |
1976 if (encoding == String::TWO_BYTE_ENCODING) { | 1931 if (encoding == String::TWO_BYTE_ENCODING) { |
1977 offset *= kUC16Size; | 1932 offset *= kUC16Size; |
1978 } | 1933 } |
1979 STATIC_ASSERT(kCharSize == 1); | 1934 STATIC_ASSERT(kCharSize == 1); |
1980 return FieldMemOperand(string, SeqString::kHeaderSize + offset); | 1935 return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
1981 } | 1936 } |
1982 Register scratch = scratch0(); | 1937 Register scratch = scratch0(); |
1983 DCHECK(!scratch.is(string)); | 1938 DCHECK(!scratch.is(string)); |
1984 DCHECK(!scratch.is(ToRegister(index))); | 1939 DCHECK(!scratch.is(ToRegister(index))); |
1985 if (encoding == String::ONE_BYTE_ENCODING) { | 1940 if (encoding == String::ONE_BYTE_ENCODING) { |
1986 __ add(scratch, string, Operand(ToRegister(index))); | 1941 __ add(scratch, string, ToRegister(index)); |
1987 } else { | 1942 } else { |
1988 STATIC_ASSERT(kUC16Size == 2); | 1943 STATIC_ASSERT(kUC16Size == 2); |
1989 __ add(scratch, string, Operand(ToRegister(index), LSL, 1)); | 1944 __ ShiftLeftImm(scratch, ToRegister(index), Operand(1)); |
| 1945 __ add(scratch, string, scratch); |
1990 } | 1946 } |
1991 return FieldMemOperand(scratch, SeqString::kHeaderSize); | 1947 return FieldMemOperand(scratch, SeqString::kHeaderSize); |
1992 } | 1948 } |
1993 | 1949 |
1994 | 1950 |
1995 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { | 1951 void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
1996 String::Encoding encoding = instr->hydrogen()->encoding(); | 1952 String::Encoding encoding = instr->hydrogen()->encoding(); |
1997 Register string = ToRegister(instr->string()); | 1953 Register string = ToRegister(instr->string()); |
1998 Register result = ToRegister(instr->result()); | 1954 Register result = ToRegister(instr->result()); |
1999 | 1955 |
2000 if (FLAG_debug_code) { | 1956 if (FLAG_debug_code) { |
2001 Register scratch = scratch0(); | 1957 Register scratch = scratch0(); |
2002 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); | 1958 __ LoadP(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
2003 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); | 1959 __ lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
2004 | 1960 |
2005 __ and_(scratch, scratch, | 1961 __ andi(scratch, scratch, |
2006 Operand(kStringRepresentationMask | kStringEncodingMask)); | 1962 Operand(kStringRepresentationMask | kStringEncodingMask)); |
2007 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | 1963 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
2008 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | 1964 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
2009 __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING | 1965 __ cmpi(scratch, |
2010 ? one_byte_seq_type : two_byte_seq_type)); | 1966 Operand(encoding == String::ONE_BYTE_ENCODING ? one_byte_seq_type |
| 1967 : two_byte_seq_type)); |
2011 __ Check(eq, kUnexpectedStringType); | 1968 __ Check(eq, kUnexpectedStringType); |
2012 } | 1969 } |
2013 | 1970 |
2014 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); | 1971 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
2015 if (encoding == String::ONE_BYTE_ENCODING) { | 1972 if (encoding == String::ONE_BYTE_ENCODING) { |
2016 __ ldrb(result, operand); | 1973 __ lbz(result, operand); |
2017 } else { | 1974 } else { |
2018 __ ldrh(result, operand); | 1975 __ lhz(result, operand); |
2019 } | 1976 } |
2020 } | 1977 } |
2021 | 1978 |
2022 | 1979 |
2023 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { | 1980 void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
2024 String::Encoding encoding = instr->hydrogen()->encoding(); | 1981 String::Encoding encoding = instr->hydrogen()->encoding(); |
2025 Register string = ToRegister(instr->string()); | 1982 Register string = ToRegister(instr->string()); |
2026 Register value = ToRegister(instr->value()); | 1983 Register value = ToRegister(instr->value()); |
2027 | 1984 |
2028 if (FLAG_debug_code) { | 1985 if (FLAG_debug_code) { |
2029 Register index = ToRegister(instr->index()); | 1986 Register index = ToRegister(instr->index()); |
2030 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | 1987 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
2031 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | 1988 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
2032 int encoding_mask = | 1989 int encoding_mask = |
2033 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING | 1990 instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
2034 ? one_byte_seq_type : two_byte_seq_type; | 1991 ? one_byte_seq_type |
| 1992 : two_byte_seq_type; |
2035 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); | 1993 __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
2036 } | 1994 } |
2037 | 1995 |
2038 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); | 1996 MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
2039 if (encoding == String::ONE_BYTE_ENCODING) { | 1997 if (encoding == String::ONE_BYTE_ENCODING) { |
2040 __ strb(value, operand); | 1998 __ stb(value, operand); |
2041 } else { | 1999 } else { |
2042 __ strh(value, operand); | 2000 __ sth(value, operand); |
2043 } | 2001 } |
2044 } | 2002 } |
2045 | 2003 |
2046 | 2004 |
2047 void LCodeGen::DoAddI(LAddI* instr) { | 2005 void LCodeGen::DoAddI(LAddI* instr) { |
2048 LOperand* left = instr->left(); | |
2049 LOperand* right = instr->right(); | 2006 LOperand* right = instr->right(); |
2050 LOperand* result = instr->result(); | 2007 Register left = ToRegister(instr->left()); |
| 2008 Register result = ToRegister(instr->result()); |
2051 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); | 2009 bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
2052 SBit set_cond = can_overflow ? SetCC : LeaveCC; | 2010 #if V8_TARGET_ARCH_PPC64 |
| 2011 bool isInteger = !(instr->hydrogen()->representation().IsSmi() || |
| 2012 instr->hydrogen()->representation().IsExternal()); |
| 2013 #endif |
2053 | 2014 |
2054 if (right->IsStackSlot()) { | 2015 if (!can_overflow && right->IsConstantOperand()) { |
| 2016 Operand right_operand = ToOperand(right); |
| 2017 __ Add(result, left, right_operand.immediate(), r0); |
| 2018 } else { |
2055 Register right_reg = EmitLoadRegister(right, ip); | 2019 Register right_reg = EmitLoadRegister(right, ip); |
2056 __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); | 2020 |
2057 } else { | 2021 if (!can_overflow) { |
2058 DCHECK(right->IsRegister() || right->IsConstantOperand()); | 2022 __ add(result, left, right_reg); |
2059 __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); | 2023 } else { // can_overflow. |
| 2024 __ AddAndCheckForOverflow(result, left, right_reg, scratch0(), r0); |
| 2025 #if V8_TARGET_ARCH_PPC64 |
| 2026 if (isInteger) { |
| 2027 __ extsw(scratch0(), scratch0(), SetRC); |
| 2028 } |
| 2029 #endif |
| 2030 // Doptimize on overflow |
| 2031 DeoptimizeIf(lt, instr->environment(), cr0); |
| 2032 } |
2060 } | 2033 } |
2061 | 2034 |
2062 if (can_overflow) { | 2035 #if V8_TARGET_ARCH_PPC64 |
2063 DeoptimizeIf(vs, instr->environment()); | 2036 if (isInteger) { |
| 2037 __ extsw(result, result); |
2064 } | 2038 } |
| 2039 #endif |
2065 } | 2040 } |
2066 | 2041 |
2067 | 2042 |
2068 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { | 2043 void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
2069 LOperand* left = instr->left(); | 2044 LOperand* left = instr->left(); |
2070 LOperand* right = instr->right(); | 2045 LOperand* right = instr->right(); |
2071 HMathMinMax::Operation operation = instr->hydrogen()->operation(); | 2046 HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| 2047 Condition cond = (operation == HMathMinMax::kMathMin) ? le : ge; |
2072 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { | 2048 if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
2073 Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; | |
2074 Register left_reg = ToRegister(left); | 2049 Register left_reg = ToRegister(left); |
2075 Operand right_op = (right->IsRegister() || right->IsConstantOperand()) | 2050 Register right_reg = EmitLoadRegister(right, ip); |
2076 ? ToOperand(right) | |
2077 : Operand(EmitLoadRegister(right, ip)); | |
2078 Register result_reg = ToRegister(instr->result()); | 2051 Register result_reg = ToRegister(instr->result()); |
2079 __ cmp(left_reg, right_op); | 2052 Label return_left, done; |
2080 __ Move(result_reg, left_reg, condition); | 2053 #if V8_TARGET_ARCH_PPC64 |
2081 __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition)); | 2054 if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2055 #endif |
| 2056 __ cmp(left_reg, right_reg); |
| 2057 #if V8_TARGET_ARCH_PPC64 |
| 2058 } else { |
| 2059 __ cmpw(left_reg, right_reg); |
| 2060 } |
| 2061 #endif |
| 2062 __ b(cond, &return_left); |
| 2063 __ Move(result_reg, right_reg); |
| 2064 __ b(&done); |
| 2065 __ bind(&return_left); |
| 2066 __ Move(result_reg, left_reg); |
| 2067 __ bind(&done); |
2082 } else { | 2068 } else { |
2083 DCHECK(instr->hydrogen()->representation().IsDouble()); | 2069 DCHECK(instr->hydrogen()->representation().IsDouble()); |
2084 DwVfpRegister left_reg = ToDoubleRegister(left); | 2070 DoubleRegister left_reg = ToDoubleRegister(left); |
2085 DwVfpRegister right_reg = ToDoubleRegister(right); | 2071 DoubleRegister right_reg = ToDoubleRegister(right); |
2086 DwVfpRegister result_reg = ToDoubleRegister(instr->result()); | 2072 DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
2087 Label result_is_nan, return_left, return_right, check_zero, done; | 2073 Label check_nan_left, check_zero, return_left, return_right, done; |
2088 __ VFPCompareAndSetFlags(left_reg, right_reg); | 2074 __ fcmpu(left_reg, right_reg); |
| 2075 __ bunordered(&check_nan_left); |
| 2076 __ beq(&check_zero); |
| 2077 __ b(cond, &return_left); |
| 2078 __ b(&return_right); |
| 2079 |
| 2080 __ bind(&check_zero); |
| 2081 __ fcmpu(left_reg, kDoubleRegZero); |
| 2082 __ bne(&return_left); // left == right != 0. |
| 2083 |
| 2084 // At this point, both left and right are either 0 or -0. |
| 2085 // N.B. The following works because +0 + -0 == +0 |
2089 if (operation == HMathMinMax::kMathMin) { | 2086 if (operation == HMathMinMax::kMathMin) { |
2090 __ b(mi, &return_left); | 2087 // For min we want logical-or of sign bit: -(-L + -R) |
2091 __ b(gt, &return_right); | 2088 __ fneg(left_reg, left_reg); |
| 2089 __ fsub(result_reg, left_reg, right_reg); |
| 2090 __ fneg(result_reg, result_reg); |
2092 } else { | 2091 } else { |
2093 __ b(mi, &return_right); | 2092 // For max we want logical-and of sign bit: (L + R) |
2094 __ b(gt, &return_left); | 2093 __ 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 } | 2094 } |
2115 __ b(&done); | 2095 __ b(&done); |
2116 | 2096 |
2117 __ bind(&result_is_nan); | 2097 __ bind(&check_nan_left); |
2118 __ vadd(result_reg, left_reg, right_reg); | 2098 __ fcmpu(left_reg, left_reg); |
| 2099 __ bunordered(&return_left); // left == NaN. |
| 2100 |
| 2101 __ bind(&return_right); |
| 2102 if (!right_reg.is(result_reg)) { |
| 2103 __ fmr(result_reg, right_reg); |
| 2104 } |
2119 __ b(&done); | 2105 __ b(&done); |
2120 | 2106 |
2121 __ bind(&return_right); | 2107 __ bind(&return_left); |
2122 __ Move(result_reg, right_reg); | |
2123 if (!left_reg.is(result_reg)) { | 2108 if (!left_reg.is(result_reg)) { |
2124 __ b(&done); | 2109 __ fmr(result_reg, left_reg); |
2125 } | 2110 } |
2126 | |
2127 __ bind(&return_left); | |
2128 __ Move(result_reg, left_reg); | |
2129 | |
2130 __ bind(&done); | 2111 __ bind(&done); |
2131 } | 2112 } |
2132 } | 2113 } |
2133 | 2114 |
2134 | 2115 |
2135 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { | 2116 void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
2136 DwVfpRegister left = ToDoubleRegister(instr->left()); | 2117 DoubleRegister left = ToDoubleRegister(instr->left()); |
2137 DwVfpRegister right = ToDoubleRegister(instr->right()); | 2118 DoubleRegister right = ToDoubleRegister(instr->right()); |
2138 DwVfpRegister result = ToDoubleRegister(instr->result()); | 2119 DoubleRegister result = ToDoubleRegister(instr->result()); |
2139 switch (instr->op()) { | 2120 switch (instr->op()) { |
2140 case Token::ADD: | 2121 case Token::ADD: |
2141 __ vadd(result, left, right); | 2122 __ fadd(result, left, right); |
2142 break; | 2123 break; |
2143 case Token::SUB: | 2124 case Token::SUB: |
2144 __ vsub(result, left, right); | 2125 __ fsub(result, left, right); |
2145 break; | 2126 break; |
2146 case Token::MUL: | 2127 case Token::MUL: |
2147 __ vmul(result, left, right); | 2128 __ fmul(result, left, right); |
2148 break; | 2129 break; |
2149 case Token::DIV: | 2130 case Token::DIV: |
2150 __ vdiv(result, left, right); | 2131 __ fdiv(result, left, right); |
2151 break; | 2132 break; |
2152 case Token::MOD: { | 2133 case Token::MOD: { |
2153 __ PrepareCallCFunction(0, 2, scratch0()); | 2134 __ PrepareCallCFunction(0, 2, scratch0()); |
2154 __ MovToFloatParameters(left, right); | 2135 __ MovToFloatParameters(left, right); |
2155 __ CallCFunction( | 2136 __ CallCFunction(ExternalReference::mod_two_doubles_operation(isolate()), |
2156 ExternalReference::mod_two_doubles_operation(isolate()), | 2137 0, 2); |
2157 0, 2); | |
2158 // Move the result in the double result register. | 2138 // Move the result in the double result register. |
2159 __ MovFromFloatResult(result); | 2139 __ MovFromFloatResult(result); |
2160 break; | 2140 break; |
2161 } | 2141 } |
2162 default: | 2142 default: |
2163 UNREACHABLE(); | 2143 UNREACHABLE(); |
2164 break; | 2144 break; |
2165 } | 2145 } |
2166 } | 2146 } |
2167 | 2147 |
2168 | 2148 |
2169 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { | 2149 void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
2170 DCHECK(ToRegister(instr->context()).is(cp)); | 2150 DCHECK(ToRegister(instr->context()).is(cp)); |
2171 DCHECK(ToRegister(instr->left()).is(r1)); | 2151 DCHECK(ToRegister(instr->left()).is(r4)); |
2172 DCHECK(ToRegister(instr->right()).is(r0)); | 2152 DCHECK(ToRegister(instr->right()).is(r3)); |
2173 DCHECK(ToRegister(instr->result()).is(r0)); | 2153 DCHECK(ToRegister(instr->result()).is(r3)); |
2174 | 2154 |
2175 BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); | 2155 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); | 2156 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
2180 } | 2157 } |
2181 | 2158 |
2182 | 2159 |
2183 template<class InstrType> | 2160 template <class InstrType> |
2184 void LCodeGen::EmitBranch(InstrType instr, Condition condition) { | 2161 void LCodeGen::EmitBranch(InstrType instr, Condition cond, CRegister cr) { |
2185 int left_block = instr->TrueDestination(chunk_); | 2162 int left_block = instr->TrueDestination(chunk_); |
2186 int right_block = instr->FalseDestination(chunk_); | 2163 int right_block = instr->FalseDestination(chunk_); |
2187 | 2164 |
2188 int next_block = GetNextEmittedBlock(); | 2165 int next_block = GetNextEmittedBlock(); |
2189 | 2166 |
2190 if (right_block == left_block || condition == al) { | 2167 if (right_block == left_block || cond == al) { |
2191 EmitGoto(left_block); | 2168 EmitGoto(left_block); |
2192 } else if (left_block == next_block) { | 2169 } else if (left_block == next_block) { |
2193 __ b(NegateCondition(condition), chunk_->GetAssemblyLabel(right_block)); | 2170 __ b(NegateCondition(cond), chunk_->GetAssemblyLabel(right_block), cr); |
2194 } else if (right_block == next_block) { | 2171 } else if (right_block == next_block) { |
2195 __ b(condition, chunk_->GetAssemblyLabel(left_block)); | 2172 __ b(cond, chunk_->GetAssemblyLabel(left_block), cr); |
2196 } else { | 2173 } else { |
2197 __ b(condition, chunk_->GetAssemblyLabel(left_block)); | 2174 __ b(cond, chunk_->GetAssemblyLabel(left_block), cr); |
2198 __ b(chunk_->GetAssemblyLabel(right_block)); | 2175 __ b(chunk_->GetAssemblyLabel(right_block)); |
2199 } | 2176 } |
2200 } | 2177 } |
2201 | 2178 |
2202 | 2179 |
2203 template<class InstrType> | 2180 template <class InstrType> |
2204 void LCodeGen::EmitFalseBranch(InstrType instr, Condition condition) { | 2181 void LCodeGen::EmitFalseBranch(InstrType instr, Condition cond, CRegister cr) { |
2205 int false_block = instr->FalseDestination(chunk_); | 2182 int false_block = instr->FalseDestination(chunk_); |
2206 __ b(condition, chunk_->GetAssemblyLabel(false_block)); | 2183 __ b(cond, chunk_->GetAssemblyLabel(false_block), cr); |
2207 } | 2184 } |
2208 | 2185 |
2209 | 2186 |
2210 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { | 2187 void LCodeGen::DoDebugBreak(LDebugBreak* instr) { __ stop("LBreak"); } |
2211 __ stop("LBreak"); | |
2212 } | |
2213 | 2188 |
2214 | 2189 |
2215 void LCodeGen::DoBranch(LBranch* instr) { | 2190 void LCodeGen::DoBranch(LBranch* instr) { |
2216 Representation r = instr->hydrogen()->value()->representation(); | 2191 Representation r = instr->hydrogen()->value()->representation(); |
2217 if (r.IsInteger32() || r.IsSmi()) { | 2192 DoubleRegister dbl_scratch = double_scratch0(); |
| 2193 const uint crZOrNaNBits = (1 << (31 - Assembler::encode_crbit(cr7, CR_EQ)) | |
| 2194 1 << (31 - Assembler::encode_crbit(cr7, CR_FU))); |
| 2195 |
| 2196 if (r.IsInteger32()) { |
2218 DCHECK(!info()->IsStub()); | 2197 DCHECK(!info()->IsStub()); |
2219 Register reg = ToRegister(instr->value()); | 2198 Register reg = ToRegister(instr->value()); |
2220 __ cmp(reg, Operand::Zero()); | 2199 __ cmpwi(reg, Operand::Zero()); |
| 2200 EmitBranch(instr, ne); |
| 2201 } else if (r.IsSmi()) { |
| 2202 DCHECK(!info()->IsStub()); |
| 2203 Register reg = ToRegister(instr->value()); |
| 2204 __ cmpi(reg, Operand::Zero()); |
2221 EmitBranch(instr, ne); | 2205 EmitBranch(instr, ne); |
2222 } else if (r.IsDouble()) { | 2206 } else if (r.IsDouble()) { |
2223 DCHECK(!info()->IsStub()); | 2207 DCHECK(!info()->IsStub()); |
2224 DwVfpRegister reg = ToDoubleRegister(instr->value()); | 2208 DoubleRegister reg = ToDoubleRegister(instr->value()); |
2225 // Test the double value. Zero and NaN are false. | 2209 // Test the double value. Zero and NaN are false. |
2226 __ VFPCompareAndSetFlags(reg, 0.0); | 2210 __ fcmpu(reg, kDoubleRegZero, cr7); |
2227 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN -> false) | 2211 __ mfcr(r0); |
2228 EmitBranch(instr, ne); | 2212 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2213 EmitBranch(instr, eq, cr0); |
2229 } else { | 2214 } else { |
2230 DCHECK(r.IsTagged()); | 2215 DCHECK(r.IsTagged()); |
2231 Register reg = ToRegister(instr->value()); | 2216 Register reg = ToRegister(instr->value()); |
2232 HType type = instr->hydrogen()->value()->type(); | 2217 HType type = instr->hydrogen()->value()->type(); |
2233 if (type.IsBoolean()) { | 2218 if (type.IsBoolean()) { |
2234 DCHECK(!info()->IsStub()); | 2219 DCHECK(!info()->IsStub()); |
2235 __ CompareRoot(reg, Heap::kTrueValueRootIndex); | 2220 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
2236 EmitBranch(instr, eq); | 2221 EmitBranch(instr, eq); |
2237 } else if (type.IsSmi()) { | 2222 } else if (type.IsSmi()) { |
2238 DCHECK(!info()->IsStub()); | 2223 DCHECK(!info()->IsStub()); |
2239 __ cmp(reg, Operand::Zero()); | 2224 __ cmpi(reg, Operand::Zero()); |
2240 EmitBranch(instr, ne); | 2225 EmitBranch(instr, ne); |
2241 } else if (type.IsJSArray()) { | 2226 } else if (type.IsJSArray()) { |
2242 DCHECK(!info()->IsStub()); | 2227 DCHECK(!info()->IsStub()); |
2243 EmitBranch(instr, al); | 2228 EmitBranch(instr, al); |
2244 } else if (type.IsHeapNumber()) { | 2229 } else if (type.IsHeapNumber()) { |
2245 DCHECK(!info()->IsStub()); | 2230 DCHECK(!info()->IsStub()); |
2246 DwVfpRegister dbl_scratch = double_scratch0(); | 2231 __ 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. | 2232 // Test the double value. Zero and NaN are false. |
2249 __ VFPCompareAndSetFlags(dbl_scratch, 0.0); | 2233 __ fcmpu(dbl_scratch, kDoubleRegZero, cr7); |
2250 __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN) | 2234 __ mfcr(r0); |
2251 EmitBranch(instr, ne); | 2235 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2236 EmitBranch(instr, eq, cr0); |
2252 } else if (type.IsString()) { | 2237 } else if (type.IsString()) { |
2253 DCHECK(!info()->IsStub()); | 2238 DCHECK(!info()->IsStub()); |
2254 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); | 2239 __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
2255 __ cmp(ip, Operand::Zero()); | 2240 __ cmpi(ip, Operand::Zero()); |
2256 EmitBranch(instr, ne); | 2241 EmitBranch(instr, ne); |
2257 } else { | 2242 } else { |
2258 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); | 2243 ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
2259 // Avoid deopts in the case where we've never executed this path before. | 2244 // Avoid deopts in the case where we've never executed this path before. |
2260 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); | 2245 if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
2261 | 2246 |
2262 if (expected.Contains(ToBooleanStub::UNDEFINED)) { | 2247 if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
2263 // undefined -> false. | 2248 // undefined -> false. |
2264 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); | 2249 __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
2265 __ b(eq, instr->FalseLabel(chunk_)); | 2250 __ beq(instr->FalseLabel(chunk_)); |
2266 } | 2251 } |
2267 if (expected.Contains(ToBooleanStub::BOOLEAN)) { | 2252 if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
2268 // Boolean -> its value. | 2253 // Boolean -> its value. |
2269 __ CompareRoot(reg, Heap::kTrueValueRootIndex); | 2254 __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
2270 __ b(eq, instr->TrueLabel(chunk_)); | 2255 __ beq(instr->TrueLabel(chunk_)); |
2271 __ CompareRoot(reg, Heap::kFalseValueRootIndex); | 2256 __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
2272 __ b(eq, instr->FalseLabel(chunk_)); | 2257 __ beq(instr->FalseLabel(chunk_)); |
2273 } | 2258 } |
2274 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { | 2259 if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
2275 // 'null' -> false. | 2260 // 'null' -> false. |
2276 __ CompareRoot(reg, Heap::kNullValueRootIndex); | 2261 __ CompareRoot(reg, Heap::kNullValueRootIndex); |
2277 __ b(eq, instr->FalseLabel(chunk_)); | 2262 __ beq(instr->FalseLabel(chunk_)); |
2278 } | 2263 } |
2279 | 2264 |
2280 if (expected.Contains(ToBooleanStub::SMI)) { | 2265 if (expected.Contains(ToBooleanStub::SMI)) { |
2281 // Smis: 0 -> false, all other -> true. | 2266 // Smis: 0 -> false, all other -> true. |
2282 __ cmp(reg, Operand::Zero()); | 2267 __ cmpi(reg, Operand::Zero()); |
2283 __ b(eq, instr->FalseLabel(chunk_)); | 2268 __ beq(instr->FalseLabel(chunk_)); |
2284 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); | 2269 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
2285 } else if (expected.NeedsMap()) { | 2270 } else if (expected.NeedsMap()) { |
2286 // If we need a map later and have a Smi -> deopt. | 2271 // If we need a map later and have a Smi -> deopt. |
2287 __ SmiTst(reg); | 2272 __ TestIfSmi(reg, r0); |
2288 DeoptimizeIf(eq, instr->environment()); | 2273 DeoptimizeIf(eq, instr->environment(), cr0); |
2289 } | 2274 } |
2290 | 2275 |
2291 const Register map = scratch0(); | 2276 const Register map = scratch0(); |
2292 if (expected.NeedsMap()) { | 2277 if (expected.NeedsMap()) { |
2293 __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); | 2278 __ LoadP(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
2294 | 2279 |
2295 if (expected.CanBeUndetectable()) { | 2280 if (expected.CanBeUndetectable()) { |
2296 // Undetectable -> false. | 2281 // Undetectable -> false. |
2297 __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); | 2282 __ lbz(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
2298 __ tst(ip, Operand(1 << Map::kIsUndetectable)); | 2283 __ TestBit(ip, Map::kIsUndetectable, r0); |
2299 __ b(ne, instr->FalseLabel(chunk_)); | 2284 __ bne(instr->FalseLabel(chunk_), cr0); |
2300 } | 2285 } |
2301 } | 2286 } |
2302 | 2287 |
2303 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { | 2288 if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
2304 // spec object -> true. | 2289 // spec object -> true. |
2305 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); | 2290 __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
2306 __ b(ge, instr->TrueLabel(chunk_)); | 2291 __ bge(instr->TrueLabel(chunk_)); |
2307 } | 2292 } |
2308 | 2293 |
2309 if (expected.Contains(ToBooleanStub::STRING)) { | 2294 if (expected.Contains(ToBooleanStub::STRING)) { |
2310 // String value -> false iff empty. | 2295 // String value -> false iff empty. |
2311 Label not_string; | 2296 Label not_string; |
2312 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); | 2297 __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
2313 __ b(ge, ¬_string); | 2298 __ bge(¬_string); |
2314 __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); | 2299 __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
2315 __ cmp(ip, Operand::Zero()); | 2300 __ cmpi(ip, Operand::Zero()); |
2316 __ b(ne, instr->TrueLabel(chunk_)); | 2301 __ bne(instr->TrueLabel(chunk_)); |
2317 __ b(instr->FalseLabel(chunk_)); | 2302 __ b(instr->FalseLabel(chunk_)); |
2318 __ bind(¬_string); | 2303 __ bind(¬_string); |
2319 } | 2304 } |
2320 | 2305 |
2321 if (expected.Contains(ToBooleanStub::SYMBOL)) { | 2306 if (expected.Contains(ToBooleanStub::SYMBOL)) { |
2322 // Symbol value -> true. | 2307 // Symbol value -> true. |
2323 __ CompareInstanceType(map, ip, SYMBOL_TYPE); | 2308 __ CompareInstanceType(map, ip, SYMBOL_TYPE); |
2324 __ b(eq, instr->TrueLabel(chunk_)); | 2309 __ beq(instr->TrueLabel(chunk_)); |
2325 } | 2310 } |
2326 | 2311 |
2327 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { | 2312 if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
2328 // heap number -> false iff +0, -0, or NaN. | 2313 // heap number -> false iff +0, -0, or NaN. |
2329 DwVfpRegister dbl_scratch = double_scratch0(); | |
2330 Label not_heap_number; | 2314 Label not_heap_number; |
2331 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); | 2315 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
2332 __ b(ne, ¬_heap_number); | 2316 __ bne(¬_heap_number); |
2333 __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); | 2317 __ lfd(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
2334 __ VFPCompareAndSetFlags(dbl_scratch, 0.0); | 2318 // Test the double value. Zero and NaN are false. |
2335 __ cmp(r0, r0, vs); // NaN -> false. | 2319 __ fcmpu(dbl_scratch, kDoubleRegZero, cr7); |
2336 __ b(eq, instr->FalseLabel(chunk_)); // +0, -0 -> false. | 2320 __ mfcr(r0); |
| 2321 __ andi(r0, r0, Operand(crZOrNaNBits)); |
| 2322 __ bne(instr->FalseLabel(chunk_), cr0); |
2337 __ b(instr->TrueLabel(chunk_)); | 2323 __ b(instr->TrueLabel(chunk_)); |
2338 __ bind(¬_heap_number); | 2324 __ bind(¬_heap_number); |
2339 } | 2325 } |
2340 | 2326 |
2341 if (!expected.IsGeneric()) { | 2327 if (!expected.IsGeneric()) { |
2342 // We've seen something for the first time -> deopt. | 2328 // We've seen something for the first time -> deopt. |
2343 // This can only happen if we are not generic already. | 2329 // This can only happen if we are not generic already. |
2344 DeoptimizeIf(al, instr->environment()); | 2330 DeoptimizeIf(al, instr->environment()); |
2345 } | 2331 } |
2346 } | 2332 } |
2347 } | 2333 } |
2348 } | 2334 } |
2349 | 2335 |
2350 | 2336 |
2351 void LCodeGen::EmitGoto(int block) { | 2337 void LCodeGen::EmitGoto(int block) { |
2352 if (!IsNextEmittedBlock(block)) { | 2338 if (!IsNextEmittedBlock(block)) { |
2353 __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); | 2339 __ b(chunk_->GetAssemblyLabel(LookupDestination(block))); |
2354 } | 2340 } |
2355 } | 2341 } |
2356 | 2342 |
2357 | 2343 |
2358 void LCodeGen::DoGoto(LGoto* instr) { | 2344 void LCodeGen::DoGoto(LGoto* instr) { EmitGoto(instr->block_id()); } |
2359 EmitGoto(instr->block_id()); | |
2360 } | |
2361 | 2345 |
2362 | 2346 |
2363 Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { | 2347 Condition LCodeGen::TokenToCondition(Token::Value op) { |
2364 Condition cond = kNoCondition; | 2348 Condition cond = kNoCondition; |
2365 switch (op) { | 2349 switch (op) { |
2366 case Token::EQ: | 2350 case Token::EQ: |
2367 case Token::EQ_STRICT: | 2351 case Token::EQ_STRICT: |
2368 cond = eq; | 2352 cond = eq; |
2369 break; | 2353 break; |
2370 case Token::NE: | 2354 case Token::NE: |
2371 case Token::NE_STRICT: | 2355 case Token::NE_STRICT: |
2372 cond = ne; | 2356 cond = ne; |
2373 break; | 2357 break; |
2374 case Token::LT: | 2358 case Token::LT: |
2375 cond = is_unsigned ? lo : lt; | 2359 cond = lt; |
2376 break; | 2360 break; |
2377 case Token::GT: | 2361 case Token::GT: |
2378 cond = is_unsigned ? hi : gt; | 2362 cond = gt; |
2379 break; | 2363 break; |
2380 case Token::LTE: | 2364 case Token::LTE: |
2381 cond = is_unsigned ? ls : le; | 2365 cond = le; |
2382 break; | 2366 break; |
2383 case Token::GTE: | 2367 case Token::GTE: |
2384 cond = is_unsigned ? hs : ge; | 2368 cond = ge; |
2385 break; | 2369 break; |
2386 case Token::IN: | 2370 case Token::IN: |
2387 case Token::INSTANCEOF: | 2371 case Token::INSTANCEOF: |
2388 default: | 2372 default: |
2389 UNREACHABLE(); | 2373 UNREACHABLE(); |
2390 } | 2374 } |
2391 return cond; | 2375 return cond; |
2392 } | 2376 } |
2393 | 2377 |
2394 | 2378 |
2395 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { | 2379 void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
2396 LOperand* left = instr->left(); | 2380 LOperand* left = instr->left(); |
2397 LOperand* right = instr->right(); | 2381 LOperand* right = instr->right(); |
2398 bool is_unsigned = | 2382 bool is_unsigned = |
2399 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || | 2383 instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || |
2400 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); | 2384 instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); |
2401 Condition cond = TokenToCondition(instr->op(), is_unsigned); | 2385 Condition cond = TokenToCondition(instr->op()); |
2402 | 2386 |
2403 if (left->IsConstantOperand() && right->IsConstantOperand()) { | 2387 if (left->IsConstantOperand() && right->IsConstantOperand()) { |
2404 // We can statically evaluate the comparison. | 2388 // We can statically evaluate the comparison. |
2405 double left_val = ToDouble(LConstantOperand::cast(left)); | 2389 double left_val = ToDouble(LConstantOperand::cast(left)); |
2406 double right_val = ToDouble(LConstantOperand::cast(right)); | 2390 double right_val = ToDouble(LConstantOperand::cast(right)); |
2407 int next_block = EvalComparison(instr->op(), left_val, right_val) ? | 2391 int next_block = EvalComparison(instr->op(), left_val, right_val) |
2408 instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); | 2392 ? instr->TrueDestination(chunk_) |
| 2393 : instr->FalseDestination(chunk_); |
2409 EmitGoto(next_block); | 2394 EmitGoto(next_block); |
2410 } else { | 2395 } else { |
2411 if (instr->is_double()) { | 2396 if (instr->is_double()) { |
2412 // Compare left and right operands as doubles and load the | 2397 // Compare left and right operands as doubles and load the |
2413 // resulting flags into the normal status register. | 2398 // resulting flags into the normal status register. |
2414 __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); | 2399 __ fcmpu(ToDoubleRegister(left), ToDoubleRegister(right)); |
2415 // If a NaN is involved, i.e. the result is unordered (V set), | 2400 // If a NaN is involved, i.e. the result is unordered, |
2416 // jump to false block label. | 2401 // jump to false block label. |
2417 __ b(vs, instr->FalseLabel(chunk_)); | 2402 __ bunordered(instr->FalseLabel(chunk_)); |
2418 } else { | 2403 } else { |
2419 if (right->IsConstantOperand()) { | 2404 if (right->IsConstantOperand()) { |
2420 int32_t value = ToInteger32(LConstantOperand::cast(right)); | 2405 int32_t value = ToInteger32(LConstantOperand::cast(right)); |
2421 if (instr->hydrogen_value()->representation().IsSmi()) { | 2406 if (instr->hydrogen_value()->representation().IsSmi()) { |
2422 __ cmp(ToRegister(left), Operand(Smi::FromInt(value))); | 2407 if (is_unsigned) { |
| 2408 __ CmplSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2409 } else { |
| 2410 __ CmpSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2411 } |
2423 } else { | 2412 } else { |
2424 __ cmp(ToRegister(left), Operand(value)); | 2413 if (is_unsigned) { |
| 2414 __ Cmplwi(ToRegister(left), Operand(value), r0); |
| 2415 } else { |
| 2416 __ Cmpwi(ToRegister(left), Operand(value), r0); |
| 2417 } |
2425 } | 2418 } |
2426 } else if (left->IsConstantOperand()) { | 2419 } else if (left->IsConstantOperand()) { |
2427 int32_t value = ToInteger32(LConstantOperand::cast(left)); | 2420 int32_t value = ToInteger32(LConstantOperand::cast(left)); |
2428 if (instr->hydrogen_value()->representation().IsSmi()) { | 2421 if (instr->hydrogen_value()->representation().IsSmi()) { |
2429 __ cmp(ToRegister(right), Operand(Smi::FromInt(value))); | 2422 if (is_unsigned) { |
| 2423 __ CmplSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2424 } else { |
| 2425 __ CmpSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2426 } |
2430 } else { | 2427 } else { |
2431 __ cmp(ToRegister(right), Operand(value)); | 2428 if (is_unsigned) { |
| 2429 __ Cmplwi(ToRegister(right), Operand(value), r0); |
| 2430 } else { |
| 2431 __ Cmpwi(ToRegister(right), Operand(value), r0); |
| 2432 } |
2432 } | 2433 } |
2433 // We commuted the operands, so commute the condition. | 2434 // We commuted the operands, so commute the condition. |
2434 cond = CommuteCondition(cond); | 2435 cond = CommuteCondition(cond); |
| 2436 } else if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2437 if (is_unsigned) { |
| 2438 __ cmpl(ToRegister(left), ToRegister(right)); |
| 2439 } else { |
| 2440 __ cmp(ToRegister(left), ToRegister(right)); |
| 2441 } |
2435 } else { | 2442 } else { |
2436 __ cmp(ToRegister(left), ToRegister(right)); | 2443 if (is_unsigned) { |
| 2444 __ cmplw(ToRegister(left), ToRegister(right)); |
| 2445 } else { |
| 2446 __ cmpw(ToRegister(left), ToRegister(right)); |
| 2447 } |
2437 } | 2448 } |
2438 } | 2449 } |
2439 EmitBranch(instr, cond); | 2450 EmitBranch(instr, cond); |
2440 } | 2451 } |
2441 } | 2452 } |
2442 | 2453 |
2443 | 2454 |
2444 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { | 2455 void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
2445 Register left = ToRegister(instr->left()); | 2456 Register left = ToRegister(instr->left()); |
2446 Register right = ToRegister(instr->right()); | 2457 Register right = ToRegister(instr->right()); |
2447 | 2458 |
2448 __ cmp(left, Operand(right)); | 2459 __ cmp(left, right); |
2449 EmitBranch(instr, eq); | 2460 EmitBranch(instr, eq); |
2450 } | 2461 } |
2451 | 2462 |
2452 | 2463 |
2453 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { | 2464 void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
2454 if (instr->hydrogen()->representation().IsTagged()) { | 2465 if (instr->hydrogen()->representation().IsTagged()) { |
2455 Register input_reg = ToRegister(instr->object()); | 2466 Register input_reg = ToRegister(instr->object()); |
2456 __ mov(ip, Operand(factory()->the_hole_value())); | 2467 __ mov(ip, Operand(factory()->the_hole_value())); |
2457 __ cmp(input_reg, ip); | 2468 __ cmp(input_reg, ip); |
2458 EmitBranch(instr, eq); | 2469 EmitBranch(instr, eq); |
2459 return; | 2470 return; |
2460 } | 2471 } |
2461 | 2472 |
2462 DwVfpRegister input_reg = ToDoubleRegister(instr->object()); | 2473 DoubleRegister input_reg = ToDoubleRegister(instr->object()); |
2463 __ VFPCompareAndSetFlags(input_reg, input_reg); | 2474 __ fcmpu(input_reg, input_reg); |
2464 EmitFalseBranch(instr, vc); | 2475 EmitFalseBranch(instr, ordered); |
2465 | 2476 |
2466 Register scratch = scratch0(); | 2477 Register scratch = scratch0(); |
2467 __ VmovHigh(scratch, input_reg); | 2478 __ MovDoubleHighToInt(scratch, input_reg); |
2468 __ cmp(scratch, Operand(kHoleNanUpper32)); | 2479 __ Cmpi(scratch, Operand(kHoleNanUpper32), r0); |
2469 EmitBranch(instr, eq); | 2480 EmitBranch(instr, eq); |
2470 } | 2481 } |
2471 | 2482 |
2472 | 2483 |
2473 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { | 2484 void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
2474 Representation rep = instr->hydrogen()->value()->representation(); | 2485 Representation rep = instr->hydrogen()->value()->representation(); |
2475 DCHECK(!rep.IsInteger32()); | 2486 DCHECK(!rep.IsInteger32()); |
2476 Register scratch = ToRegister(instr->temp()); | 2487 Register scratch = ToRegister(instr->temp()); |
2477 | 2488 |
2478 if (rep.IsDouble()) { | 2489 if (rep.IsDouble()) { |
2479 DwVfpRegister value = ToDoubleRegister(instr->value()); | 2490 DoubleRegister value = ToDoubleRegister(instr->value()); |
2480 __ VFPCompareAndSetFlags(value, 0.0); | 2491 __ fcmpu(value, kDoubleRegZero); |
2481 EmitFalseBranch(instr, ne); | 2492 EmitFalseBranch(instr, ne); |
2482 __ VmovHigh(scratch, value); | 2493 #if V8_TARGET_ARCH_PPC64 |
2483 __ cmp(scratch, Operand(0x80000000)); | 2494 __ MovDoubleToInt64(scratch, value); |
| 2495 #else |
| 2496 __ MovDoubleHighToInt(scratch, value); |
| 2497 #endif |
| 2498 __ cmpi(scratch, Operand::Zero()); |
| 2499 EmitBranch(instr, lt); |
2484 } else { | 2500 } else { |
2485 Register value = ToRegister(instr->value()); | 2501 Register value = ToRegister(instr->value()); |
2486 __ CheckMap(value, | 2502 __ CheckMap(value, scratch, Heap::kHeapNumberMapRootIndex, |
2487 scratch, | 2503 instr->FalseLabel(chunk()), DO_SMI_CHECK); |
2488 Heap::kHeapNumberMapRootIndex, | 2504 #if V8_TARGET_ARCH_PPC64 |
2489 instr->FalseLabel(chunk()), | 2505 __ LoadP(scratch, FieldMemOperand(value, HeapNumber::kValueOffset)); |
2490 DO_SMI_CHECK); | 2506 __ li(ip, Operand(1)); |
2491 __ ldr(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); | 2507 __ rotrdi(ip, ip, 1); // ip = 0x80000000_00000000 |
2492 __ ldr(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset)); | 2508 __ cmp(scratch, ip); |
2493 __ cmp(scratch, Operand(0x80000000)); | 2509 #else |
2494 __ cmp(ip, Operand(0x00000000), eq); | 2510 __ lwz(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); |
| 2511 __ lwz(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset)); |
| 2512 Label skip; |
| 2513 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 2514 __ cmp(scratch, r0); |
| 2515 __ bne(&skip); |
| 2516 __ cmpi(ip, Operand::Zero()); |
| 2517 __ bind(&skip); |
| 2518 #endif |
| 2519 EmitBranch(instr, eq); |
2495 } | 2520 } |
2496 EmitBranch(instr, eq); | |
2497 } | 2521 } |
2498 | 2522 |
2499 | 2523 |
2500 Condition LCodeGen::EmitIsObject(Register input, | 2524 Condition LCodeGen::EmitIsObject(Register input, Register temp1, |
2501 Register temp1, | 2525 Label* is_not_object, Label* is_object) { |
2502 Label* is_not_object, | |
2503 Label* is_object) { | |
2504 Register temp2 = scratch0(); | 2526 Register temp2 = scratch0(); |
2505 __ JumpIfSmi(input, is_not_object); | 2527 __ JumpIfSmi(input, is_not_object); |
2506 | 2528 |
2507 __ LoadRoot(temp2, Heap::kNullValueRootIndex); | 2529 __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
2508 __ cmp(input, temp2); | 2530 __ cmp(input, temp2); |
2509 __ b(eq, is_object); | 2531 __ beq(is_object); |
2510 | 2532 |
2511 // Load map. | 2533 // Load map. |
2512 __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); | 2534 __ LoadP(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
2513 // Undetectable objects behave like undefined. | 2535 // Undetectable objects behave like undefined. |
2514 __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); | 2536 __ lbz(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
2515 __ tst(temp2, Operand(1 << Map::kIsUndetectable)); | 2537 __ TestBit(temp2, Map::kIsUndetectable, r0); |
2516 __ b(ne, is_not_object); | 2538 __ bne(is_not_object, cr0); |
2517 | 2539 |
2518 // Load instance type and check that it is in object type range. | 2540 // Load instance type and check that it is in object type range. |
2519 __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); | 2541 __ lbz(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
2520 __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2542 __ cmpi(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
2521 __ b(lt, is_not_object); | 2543 __ blt(is_not_object); |
2522 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2544 __ cmpi(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
2523 return le; | 2545 return le; |
2524 } | 2546 } |
2525 | 2547 |
2526 | 2548 |
2527 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { | 2549 void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
2528 Register reg = ToRegister(instr->value()); | 2550 Register reg = ToRegister(instr->value()); |
2529 Register temp1 = ToRegister(instr->temp()); | 2551 Register temp1 = ToRegister(instr->temp()); |
2530 | 2552 |
2531 Condition true_cond = | 2553 Condition true_cond = EmitIsObject(reg, temp1, instr->FalseLabel(chunk_), |
2532 EmitIsObject(reg, temp1, | 2554 instr->TrueLabel(chunk_)); |
2533 instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); | |
2534 | 2555 |
2535 EmitBranch(instr, true_cond); | 2556 EmitBranch(instr, true_cond); |
2536 } | 2557 } |
2537 | 2558 |
2538 | 2559 |
2539 Condition LCodeGen::EmitIsString(Register input, | 2560 Condition LCodeGen::EmitIsString(Register input, Register temp1, |
2540 Register temp1, | |
2541 Label* is_not_string, | 2561 Label* is_not_string, |
2542 SmiCheck check_needed = INLINE_SMI_CHECK) { | 2562 SmiCheck check_needed = INLINE_SMI_CHECK) { |
2543 if (check_needed == INLINE_SMI_CHECK) { | 2563 if (check_needed == INLINE_SMI_CHECK) { |
2544 __ JumpIfSmi(input, is_not_string); | 2564 __ JumpIfSmi(input, is_not_string); |
2545 } | 2565 } |
2546 __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); | 2566 __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); |
2547 | 2567 |
2548 return lt; | 2568 return lt; |
2549 } | 2569 } |
2550 | 2570 |
2551 | 2571 |
2552 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { | 2572 void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
2553 Register reg = ToRegister(instr->value()); | 2573 Register reg = ToRegister(instr->value()); |
2554 Register temp1 = ToRegister(instr->temp()); | 2574 Register temp1 = ToRegister(instr->temp()); |
2555 | 2575 |
2556 SmiCheck check_needed = | 2576 SmiCheck check_needed = instr->hydrogen()->value()->type().IsHeapObject() |
2557 instr->hydrogen()->value()->type().IsHeapObject() | 2577 ? OMIT_SMI_CHECK |
2558 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 2578 : INLINE_SMI_CHECK; |
2559 Condition true_cond = | 2579 Condition true_cond = |
2560 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); | 2580 EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); |
2561 | 2581 |
2562 EmitBranch(instr, true_cond); | 2582 EmitBranch(instr, true_cond); |
2563 } | 2583 } |
2564 | 2584 |
2565 | 2585 |
2566 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { | 2586 void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
2567 Register input_reg = EmitLoadRegister(instr->value(), ip); | 2587 Register input_reg = EmitLoadRegister(instr->value(), ip); |
2568 __ SmiTst(input_reg); | 2588 __ TestIfSmi(input_reg, r0); |
2569 EmitBranch(instr, eq); | 2589 EmitBranch(instr, eq, cr0); |
2570 } | 2590 } |
2571 | 2591 |
2572 | 2592 |
2573 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { | 2593 void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
2574 Register input = ToRegister(instr->value()); | 2594 Register input = ToRegister(instr->value()); |
2575 Register temp = ToRegister(instr->temp()); | 2595 Register temp = ToRegister(instr->temp()); |
2576 | 2596 |
2577 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 2597 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
2578 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | 2598 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
2579 } | 2599 } |
2580 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); | 2600 __ LoadP(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
2581 __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); | 2601 __ lbz(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
2582 __ tst(temp, Operand(1 << Map::kIsUndetectable)); | 2602 __ TestBit(temp, Map::kIsUndetectable, r0); |
2583 EmitBranch(instr, ne); | 2603 EmitBranch(instr, ne, cr0); |
2584 } | 2604 } |
2585 | 2605 |
2586 | 2606 |
2587 static Condition ComputeCompareCondition(Token::Value op) { | 2607 static Condition ComputeCompareCondition(Token::Value op) { |
2588 switch (op) { | 2608 switch (op) { |
2589 case Token::EQ_STRICT: | 2609 case Token::EQ_STRICT: |
2590 case Token::EQ: | 2610 case Token::EQ: |
2591 return eq; | 2611 return eq; |
2592 case Token::LT: | 2612 case Token::LT: |
2593 return lt; | 2613 return lt; |
2594 case Token::GT: | 2614 case Token::GT: |
2595 return gt; | 2615 return gt; |
2596 case Token::LTE: | 2616 case Token::LTE: |
2597 return le; | 2617 return le; |
2598 case Token::GTE: | 2618 case Token::GTE: |
2599 return ge; | 2619 return ge; |
2600 default: | 2620 default: |
2601 UNREACHABLE(); | 2621 UNREACHABLE(); |
2602 return kNoCondition; | 2622 return kNoCondition; |
2603 } | 2623 } |
2604 } | 2624 } |
2605 | 2625 |
2606 | 2626 |
2607 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { | 2627 void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
2608 DCHECK(ToRegister(instr->context()).is(cp)); | 2628 DCHECK(ToRegister(instr->context()).is(cp)); |
2609 Token::Value op = instr->op(); | 2629 Token::Value op = instr->op(); |
2610 | 2630 |
2611 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); | 2631 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
2612 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 2632 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
2613 // This instruction also signals no smi code inlined. | 2633 // This instruction also signals no smi code inlined |
2614 __ cmp(r0, Operand::Zero()); | 2634 __ cmpi(r3, Operand::Zero()); |
2615 | 2635 |
2616 Condition condition = ComputeCompareCondition(op); | 2636 Condition condition = ComputeCompareCondition(op); |
2617 | 2637 |
2618 EmitBranch(instr, condition); | 2638 EmitBranch(instr, condition); |
2619 } | 2639 } |
2620 | 2640 |
2621 | 2641 |
2622 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { | 2642 static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
2623 InstanceType from = instr->from(); | 2643 InstanceType from = instr->from(); |
2624 InstanceType to = instr->to(); | 2644 InstanceType to = instr->to(); |
2625 if (from == FIRST_TYPE) return to; | 2645 if (from == FIRST_TYPE) return to; |
2626 DCHECK(from == to || to == LAST_TYPE); | 2646 DCHECK(from == to || to == LAST_TYPE); |
2627 return from; | 2647 return from; |
2628 } | 2648 } |
2629 | 2649 |
2630 | 2650 |
2631 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { | 2651 static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
2632 InstanceType from = instr->from(); | 2652 InstanceType from = instr->from(); |
2633 InstanceType to = instr->to(); | 2653 InstanceType to = instr->to(); |
2634 if (from == to) return eq; | 2654 if (from == to) return eq; |
2635 if (to == LAST_TYPE) return hs; | 2655 if (to == LAST_TYPE) return ge; |
2636 if (from == FIRST_TYPE) return ls; | 2656 if (from == FIRST_TYPE) return le; |
2637 UNREACHABLE(); | 2657 UNREACHABLE(); |
2638 return eq; | 2658 return eq; |
2639 } | 2659 } |
2640 | 2660 |
2641 | 2661 |
2642 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { | 2662 void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
2643 Register scratch = scratch0(); | 2663 Register scratch = scratch0(); |
2644 Register input = ToRegister(instr->value()); | 2664 Register input = ToRegister(instr->value()); |
2645 | 2665 |
2646 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 2666 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
2647 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); | 2667 __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
2648 } | 2668 } |
2649 | 2669 |
2650 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); | 2670 __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
2651 EmitBranch(instr, BranchCondition(instr->hydrogen())); | 2671 EmitBranch(instr, BranchCondition(instr->hydrogen())); |
2652 } | 2672 } |
2653 | 2673 |
2654 | 2674 |
2655 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { | 2675 void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
2656 Register input = ToRegister(instr->value()); | 2676 Register input = ToRegister(instr->value()); |
2657 Register result = ToRegister(instr->result()); | 2677 Register result = ToRegister(instr->result()); |
2658 | 2678 |
2659 __ AssertString(input); | 2679 __ AssertString(input); |
2660 | 2680 |
2661 __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); | 2681 __ lwz(result, FieldMemOperand(input, String::kHashFieldOffset)); |
2662 __ IndexFromHash(result, result); | 2682 __ IndexFromHash(result, result); |
2663 } | 2683 } |
2664 | 2684 |
2665 | 2685 |
2666 void LCodeGen::DoHasCachedArrayIndexAndBranch( | 2686 void LCodeGen::DoHasCachedArrayIndexAndBranch( |
2667 LHasCachedArrayIndexAndBranch* instr) { | 2687 LHasCachedArrayIndexAndBranch* instr) { |
2668 Register input = ToRegister(instr->value()); | 2688 Register input = ToRegister(instr->value()); |
2669 Register scratch = scratch0(); | 2689 Register scratch = scratch0(); |
2670 | 2690 |
2671 __ ldr(scratch, | 2691 __ lwz(scratch, FieldMemOperand(input, String::kHashFieldOffset)); |
2672 FieldMemOperand(input, String::kHashFieldOffset)); | 2692 __ mov(r0, Operand(String::kContainsCachedArrayIndexMask)); |
2673 __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask)); | 2693 __ and_(r0, scratch, r0, SetRC); |
2674 EmitBranch(instr, eq); | 2694 EmitBranch(instr, eq, cr0); |
2675 } | 2695 } |
2676 | 2696 |
2677 | 2697 |
2678 // Branches to a label or falls through with the answer in flags. Trashes | 2698 // Branches to a label or falls through with the answer in flags. Trashes |
2679 // the temp registers, but not the input. | 2699 // the temp registers, but not the input. |
2680 void LCodeGen::EmitClassOfTest(Label* is_true, | 2700 void LCodeGen::EmitClassOfTest(Label* is_true, Label* is_false, |
2681 Label* is_false, | 2701 Handle<String> class_name, Register input, |
2682 Handle<String>class_name, | 2702 Register temp, Register temp2) { |
2683 Register input, | |
2684 Register temp, | |
2685 Register temp2) { | |
2686 DCHECK(!input.is(temp)); | 2703 DCHECK(!input.is(temp)); |
2687 DCHECK(!input.is(temp2)); | 2704 DCHECK(!input.is(temp2)); |
2688 DCHECK(!temp.is(temp2)); | 2705 DCHECK(!temp.is(temp2)); |
2689 | 2706 |
2690 __ JumpIfSmi(input, is_false); | 2707 __ JumpIfSmi(input, is_false); |
2691 | 2708 |
2692 if (String::Equals(isolate()->factory()->Function_string(), class_name)) { | 2709 if (String::Equals(isolate()->factory()->Function_string(), class_name)) { |
2693 // Assuming the following assertions, we can use the same compares to test | 2710 // 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. | 2711 // for both being a function type and being in the object type range. |
2695 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | 2712 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
2696 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == | 2713 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
2697 FIRST_SPEC_OBJECT_TYPE + 1); | 2714 FIRST_SPEC_OBJECT_TYPE + 1); |
2698 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | 2715 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
2699 LAST_SPEC_OBJECT_TYPE - 1); | 2716 LAST_SPEC_OBJECT_TYPE - 1); |
2700 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); | 2717 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
2701 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); | 2718 __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); |
2702 __ b(lt, is_false); | 2719 __ blt(is_false); |
2703 __ b(eq, is_true); | 2720 __ beq(is_true); |
2704 __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); | 2721 __ cmpi(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
2705 __ b(eq, is_true); | 2722 __ beq(is_true); |
2706 } else { | 2723 } else { |
2707 // Faster code path to avoid two compares: subtract lower bound from the | 2724 // 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. | 2725 // actual type and do a signed compare with the width of the type range. |
2709 __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); | 2726 __ LoadP(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
2710 __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); | 2727 __ lbz(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
2711 __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2728 __ subi(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
2712 __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - | 2729 __ cmpi(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
2713 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); | 2730 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
2714 __ b(gt, is_false); | 2731 __ bgt(is_false); |
2715 } | 2732 } |
2716 | 2733 |
2717 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. | 2734 // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
2718 // Check if the constructor in the map is a function. | 2735 // Check if the constructor in the map is a function. |
2719 __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); | 2736 __ LoadP(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
2720 | 2737 |
2721 // Objects with a non-function constructor have class 'Object'. | 2738 // Objects with a non-function constructor have class 'Object'. |
2722 __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); | 2739 __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
2723 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { | 2740 if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
2724 __ b(ne, is_true); | 2741 __ bne(is_true); |
2725 } else { | 2742 } else { |
2726 __ b(ne, is_false); | 2743 __ bne(is_false); |
2727 } | 2744 } |
2728 | 2745 |
2729 // temp now contains the constructor function. Grab the | 2746 // temp now contains the constructor function. Grab the |
2730 // instance class name from there. | 2747 // instance class name from there. |
2731 __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); | 2748 __ LoadP(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
2732 __ ldr(temp, FieldMemOperand(temp, | 2749 __ LoadP(temp, |
2733 SharedFunctionInfo::kInstanceClassNameOffset)); | 2750 FieldMemOperand(temp, SharedFunctionInfo::kInstanceClassNameOffset)); |
2734 // The class name we are testing against is internalized since it's a literal. | 2751 // 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 | 2752 // 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 | 2753 // 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 | 2754 // 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 | 2755 // syntax. Since both sides are internalized it is sufficient to use an |
2739 // identity comparison. | 2756 // identity comparison. |
2740 __ cmp(temp, Operand(class_name)); | 2757 __ Cmpi(temp, Operand(class_name), r0); |
2741 // End with the answer in flags. | 2758 // End with the answer in flags. |
2742 } | 2759 } |
2743 | 2760 |
2744 | 2761 |
2745 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { | 2762 void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
2746 Register input = ToRegister(instr->value()); | 2763 Register input = ToRegister(instr->value()); |
2747 Register temp = scratch0(); | 2764 Register temp = scratch0(); |
2748 Register temp2 = ToRegister(instr->temp()); | 2765 Register temp2 = ToRegister(instr->temp()); |
2749 Handle<String> class_name = instr->hydrogen()->class_name(); | 2766 Handle<String> class_name = instr->hydrogen()->class_name(); |
2750 | 2767 |
2751 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), | 2768 EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
2752 class_name, input, temp, temp2); | 2769 class_name, input, temp, temp2); |
2753 | 2770 |
2754 EmitBranch(instr, eq); | 2771 EmitBranch(instr, eq); |
2755 } | 2772 } |
2756 | 2773 |
2757 | 2774 |
2758 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { | 2775 void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
2759 Register reg = ToRegister(instr->value()); | 2776 Register reg = ToRegister(instr->value()); |
2760 Register temp = ToRegister(instr->temp()); | 2777 Register temp = ToRegister(instr->temp()); |
2761 | 2778 |
2762 __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); | 2779 __ LoadP(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
2763 __ cmp(temp, Operand(instr->map())); | 2780 __ Cmpi(temp, Operand(instr->map()), r0); |
2764 EmitBranch(instr, eq); | 2781 EmitBranch(instr, eq); |
2765 } | 2782 } |
2766 | 2783 |
2767 | 2784 |
2768 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { | 2785 void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
2769 DCHECK(ToRegister(instr->context()).is(cp)); | 2786 DCHECK(ToRegister(instr->context()).is(cp)); |
2770 DCHECK(ToRegister(instr->left()).is(r0)); // Object is in r0. | 2787 DCHECK(ToRegister(instr->left()).is(r3)); // Object is in r3. |
2771 DCHECK(ToRegister(instr->right()).is(r1)); // Function is in r1. | 2788 DCHECK(ToRegister(instr->right()).is(r4)); // Function is in r4. |
2772 | 2789 |
2773 InstanceofStub stub(isolate(), InstanceofStub::kArgsInRegisters); | 2790 InstanceofStub stub(isolate(), InstanceofStub::kArgsInRegisters); |
2774 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 2791 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
2775 | 2792 |
2776 __ cmp(r0, Operand::Zero()); | 2793 Label equal, done; |
2777 __ mov(r0, Operand(factory()->false_value()), LeaveCC, ne); | 2794 __ cmpi(r3, Operand::Zero()); |
2778 __ mov(r0, Operand(factory()->true_value()), LeaveCC, eq); | 2795 __ beq(&equal); |
| 2796 __ mov(r3, Operand(factory()->false_value())); |
| 2797 __ b(&done); |
| 2798 |
| 2799 __ bind(&equal); |
| 2800 __ mov(r3, Operand(factory()->true_value())); |
| 2801 __ bind(&done); |
2779 } | 2802 } |
2780 | 2803 |
2781 | 2804 |
2782 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { | 2805 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
2783 class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { | 2806 class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
2784 public: | 2807 public: |
2785 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, | 2808 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
2786 LInstanceOfKnownGlobal* instr) | 2809 LInstanceOfKnownGlobal* instr) |
2787 : LDeferredCode(codegen), instr_(instr) { } | 2810 : LDeferredCode(codegen), instr_(instr) {} |
2788 virtual void Generate() V8_OVERRIDE { | 2811 virtual void Generate() V8_OVERRIDE { |
2789 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_, | 2812 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
2790 &load_bool_); | |
2791 } | 2813 } |
2792 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 2814 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
2793 Label* map_check() { return &map_check_; } | 2815 Label* map_check() { return &map_check_; } |
2794 Label* load_bool() { return &load_bool_; } | |
2795 | 2816 |
2796 private: | 2817 private: |
2797 LInstanceOfKnownGlobal* instr_; | 2818 LInstanceOfKnownGlobal* instr_; |
2798 Label map_check_; | 2819 Label map_check_; |
2799 Label load_bool_; | |
2800 }; | 2820 }; |
2801 | 2821 |
2802 DeferredInstanceOfKnownGlobal* deferred; | 2822 DeferredInstanceOfKnownGlobal* deferred; |
2803 deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); | 2823 deferred = new (zone()) DeferredInstanceOfKnownGlobal(this, instr); |
2804 | 2824 |
2805 Label done, false_result; | 2825 Label done, false_result; |
2806 Register object = ToRegister(instr->value()); | 2826 Register object = ToRegister(instr->value()); |
2807 Register temp = ToRegister(instr->temp()); | 2827 Register temp = ToRegister(instr->temp()); |
2808 Register result = ToRegister(instr->result()); | 2828 Register result = ToRegister(instr->result()); |
2809 | 2829 |
2810 // A Smi is not instance of anything. | 2830 // A Smi is not instance of anything. |
2811 __ JumpIfSmi(object, &false_result); | 2831 __ JumpIfSmi(object, &false_result); |
2812 | 2832 |
2813 // This is the inlined call site instanceof cache. The two occurences of the | 2833 // 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 | 2834 // hole value will be patched to the last map/result pair generated by the |
2815 // instanceof stub. | 2835 // instanceof stub. |
2816 Label cache_miss; | 2836 Label cache_miss; |
2817 Register map = temp; | 2837 Register map = temp; |
2818 __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); | 2838 __ LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
2819 { | 2839 { |
2820 // Block constant pool emission to ensure the positions of instructions are | 2840 // Block constant pool emission to ensure the positions of instructions are |
2821 // as expected by the patcher. See InstanceofStub::Generate(). | 2841 // as expected by the patcher. See InstanceofStub::Generate(). |
2822 Assembler::BlockConstPoolScope block_const_pool(masm()); | 2842 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
2823 __ bind(deferred->map_check()); // Label for calculating code patching. | 2843 __ bind(deferred->map_check()); // Label for calculating code patching. |
2824 // We use Factory::the_hole_value() on purpose instead of loading from the | 2844 // 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 | 2845 // root array to force relocation to be able to later patch with |
2826 // the cached map. | 2846 // the cached map. |
2827 Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); | 2847 Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); |
2828 __ mov(ip, Operand(Handle<Object>(cell))); | 2848 __ mov(ip, Operand(Handle<Object>(cell))); |
2829 __ ldr(ip, FieldMemOperand(ip, PropertyCell::kValueOffset)); | 2849 __ LoadP(ip, FieldMemOperand(ip, PropertyCell::kValueOffset)); |
2830 __ cmp(map, Operand(ip)); | 2850 __ cmp(map, ip); |
2831 __ b(ne, &cache_miss); | 2851 __ 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 | 2852 // 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 | 2853 // root array to force relocation to be able to later patch |
2835 // with true or false. | 2854 // with true or false. |
2836 __ mov(result, Operand(factory()->the_hole_value())); | 2855 __ mov(result, Operand(factory()->the_hole_value())); |
2837 } | 2856 } |
2838 __ b(&done); | 2857 __ b(&done); |
2839 | 2858 |
2840 // The inlined call site cache did not match. Check null and string before | 2859 // The inlined call site cache did not match. Check null and string before |
2841 // calling the deferred code. | 2860 // calling the deferred code. |
2842 __ bind(&cache_miss); | 2861 __ bind(&cache_miss); |
2843 // Null is not instance of anything. | 2862 // Null is not instance of anything. |
2844 __ LoadRoot(ip, Heap::kNullValueRootIndex); | 2863 __ LoadRoot(ip, Heap::kNullValueRootIndex); |
2845 __ cmp(object, Operand(ip)); | 2864 __ cmp(object, ip); |
2846 __ b(eq, &false_result); | 2865 __ beq(&false_result); |
2847 | 2866 |
2848 // String values is not instance of anything. | 2867 // String values is not instance of anything. |
2849 Condition is_string = masm_->IsObjectStringType(object, temp); | 2868 Condition is_string = masm_->IsObjectStringType(object, temp); |
2850 __ b(is_string, &false_result); | 2869 __ b(is_string, &false_result, cr0); |
2851 | 2870 |
2852 // Go to the deferred code. | 2871 // Go to the deferred code. |
2853 __ b(deferred->entry()); | 2872 __ b(deferred->entry()); |
2854 | 2873 |
2855 __ bind(&false_result); | 2874 __ bind(&false_result); |
2856 __ LoadRoot(result, Heap::kFalseValueRootIndex); | 2875 __ LoadRoot(result, Heap::kFalseValueRootIndex); |
2857 | 2876 |
2858 // Here result has either true or false. Deferred code also produces true or | 2877 // Here result has either true or false. Deferred code also produces true or |
2859 // false object. | 2878 // false object. |
2860 __ bind(deferred->exit()); | 2879 __ bind(deferred->exit()); |
2861 __ bind(&done); | 2880 __ bind(&done); |
2862 } | 2881 } |
2863 | 2882 |
2864 | 2883 |
2865 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, | 2884 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
2866 Label* map_check, | 2885 Label* map_check) { |
2867 Label* bool_load) { | |
2868 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; | 2886 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
2869 flags = static_cast<InstanceofStub::Flags>( | 2887 flags = static_cast<InstanceofStub::Flags>(flags | |
2870 flags | InstanceofStub::kArgsInRegisters); | 2888 InstanceofStub::kArgsInRegisters); |
2871 flags = static_cast<InstanceofStub::Flags>( | 2889 flags = static_cast<InstanceofStub::Flags>( |
2872 flags | InstanceofStub::kCallSiteInlineCheck); | 2890 flags | InstanceofStub::kCallSiteInlineCheck); |
2873 flags = static_cast<InstanceofStub::Flags>( | 2891 flags = static_cast<InstanceofStub::Flags>( |
2874 flags | InstanceofStub::kReturnTrueFalseObject); | 2892 flags | InstanceofStub::kReturnTrueFalseObject); |
2875 InstanceofStub stub(isolate(), flags); | 2893 InstanceofStub stub(isolate(), flags); |
2876 | 2894 |
2877 PushSafepointRegistersScope scope(this); | 2895 PushSafepointRegistersScope scope(this); |
2878 LoadContextFromDeferred(instr->context()); | 2896 LoadContextFromDeferred(instr->context()); |
2879 | 2897 |
2880 __ Move(InstanceofStub::right(), instr->function()); | 2898 __ Move(InstanceofStub::right(), instr->function()); |
2881 | 2899 // Include instructions below in delta: mov + call = mov + (mov + 2) |
2882 int call_size = CallCodeSize(stub.GetCode(), RelocInfo::CODE_TARGET); | 2900 static const int kAdditionalDelta = (2 * Assembler::kMovInstructions) + 2; |
2883 int additional_delta = (call_size / Assembler::kInstrSize) + 4; | 2901 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 { | 2902 { |
2892 ConstantPoolUnavailableScope constant_pool_unavailable(masm_); | 2903 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
2893 int map_check_delta = | 2904 // r8 is used to communicate the offset to the location of the map check. |
2894 masm_->InstructionsGeneratedSince(map_check) + additional_delta; | 2905 __ 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 } | 2906 } |
2911 CallCodeGeneric(stub.GetCode(), | 2907 CallCodeGeneric(stub.GetCode(), RelocInfo::CODE_TARGET, instr, |
2912 RelocInfo::CODE_TARGET, | |
2913 instr, | |
2914 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | 2908 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 2909 DCHECK(delta == masm_->InstructionsGeneratedSince(map_check)); |
2915 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); | 2910 LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
2916 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); | 2911 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
2917 // Put the result value (r0) into the result register slot and | 2912 // Put the result value (r3) into the result register slot and |
2918 // restore all registers. | 2913 // restore all registers. |
2919 __ StoreToSafepointRegisterSlot(r0, ToRegister(instr->result())); | 2914 __ StoreToSafepointRegisterSlot(r3, ToRegister(instr->result())); |
2920 } | 2915 } |
2921 | 2916 |
2922 | 2917 |
2923 void LCodeGen::DoCmpT(LCmpT* instr) { | 2918 void LCodeGen::DoCmpT(LCmpT* instr) { |
2924 DCHECK(ToRegister(instr->context()).is(cp)); | 2919 DCHECK(ToRegister(instr->context()).is(cp)); |
2925 Token::Value op = instr->op(); | 2920 Token::Value op = instr->op(); |
2926 | 2921 |
2927 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); | 2922 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
2928 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 2923 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
2929 // This instruction also signals no smi code inlined. | 2924 // This instruction also signals no smi code inlined |
2930 __ cmp(r0, Operand::Zero()); | 2925 __ cmpi(r3, Operand::Zero()); |
2931 | 2926 |
2932 Condition condition = ComputeCompareCondition(op); | 2927 Condition condition = ComputeCompareCondition(op); |
2933 __ LoadRoot(ToRegister(instr->result()), | 2928 Label true_value, done; |
2934 Heap::kTrueValueRootIndex, | 2929 |
2935 condition); | 2930 __ b(condition, &true_value); |
2936 __ LoadRoot(ToRegister(instr->result()), | 2931 |
2937 Heap::kFalseValueRootIndex, | 2932 __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
2938 NegateCondition(condition)); | 2933 __ b(&done); |
| 2934 |
| 2935 __ bind(&true_value); |
| 2936 __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
| 2937 |
| 2938 __ bind(&done); |
2939 } | 2939 } |
2940 | 2940 |
2941 | 2941 |
2942 void LCodeGen::DoReturn(LReturn* instr) { | 2942 void LCodeGen::DoReturn(LReturn* instr) { |
2943 if (FLAG_trace && info()->IsOptimizing()) { | 2943 if (FLAG_trace && info()->IsOptimizing()) { |
2944 // Push the return value on the stack as the parameter. | 2944 // Push the return value on the stack as the parameter. |
2945 // Runtime::TraceExit returns its parameter in r0. We're leaving the code | 2945 // 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 | 2946 // managed by the register allocator and tearing down the frame, it's |
2947 // safe to write to the context register. | 2947 // safe to write to the context register. |
2948 __ push(r0); | 2948 __ push(r3); |
2949 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 2949 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
2950 __ CallRuntime(Runtime::kTraceExit, 1); | 2950 __ CallRuntime(Runtime::kTraceExit, 1); |
2951 } | 2951 } |
2952 if (info()->saves_caller_doubles()) { | 2952 if (info()->saves_caller_doubles()) { |
2953 RestoreCallerDoubles(); | 2953 RestoreCallerDoubles(); |
2954 } | 2954 } |
2955 int no_frame_start = -1; | 2955 int no_frame_start = -1; |
2956 if (NeedsEagerFrame()) { | 2956 if (NeedsEagerFrame()) { |
2957 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); | 2957 no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); |
2958 } | 2958 } |
2959 if (instr->has_constant_parameter_count()) { | 2959 if (instr->has_constant_parameter_count()) { |
2960 int parameter_count = ToInteger32(instr->constant_parameter_count()); | 2960 int parameter_count = ToInteger32(instr->constant_parameter_count()); |
2961 int32_t sp_delta = (parameter_count + 1) * kPointerSize; | 2961 int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
2962 if (sp_delta != 0) { | 2962 if (sp_delta != 0) { |
2963 __ add(sp, sp, Operand(sp_delta)); | 2963 __ addi(sp, sp, Operand(sp_delta)); |
2964 } | 2964 } |
2965 } else { | 2965 } else { |
2966 Register reg = ToRegister(instr->parameter_count()); | 2966 Register reg = ToRegister(instr->parameter_count()); |
2967 // The argument count parameter is a smi | 2967 // The argument count parameter is a smi |
2968 __ SmiUntag(reg); | 2968 __ SmiToPtrArrayOffset(r0, reg); |
2969 __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2)); | 2969 __ add(sp, sp, r0); |
2970 } | 2970 } |
2971 | 2971 |
2972 __ Jump(lr); | 2972 __ blr(); |
2973 | 2973 |
2974 if (no_frame_start != -1) { | 2974 if (no_frame_start != -1) { |
2975 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); | 2975 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
2976 } | 2976 } |
2977 } | 2977 } |
2978 | 2978 |
2979 | 2979 |
2980 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { | 2980 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
2981 Register result = ToRegister(instr->result()); | 2981 Register result = ToRegister(instr->result()); |
2982 __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); | 2982 __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); |
2983 __ ldr(result, FieldMemOperand(ip, Cell::kValueOffset)); | 2983 __ LoadP(result, FieldMemOperand(ip, Cell::kValueOffset)); |
2984 if (instr->hydrogen()->RequiresHoleCheck()) { | 2984 if (instr->hydrogen()->RequiresHoleCheck()) { |
2985 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 2985 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
2986 __ cmp(result, ip); | 2986 __ cmp(result, ip); |
2987 DeoptimizeIf(eq, instr->environment()); | 2987 DeoptimizeIf(eq, instr->environment()); |
2988 } | 2988 } |
2989 } | 2989 } |
2990 | 2990 |
2991 | 2991 |
2992 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { | 2992 void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
2993 DCHECK(ToRegister(instr->context()).is(cp)); | 2993 DCHECK(ToRegister(instr->context()).is(cp)); |
2994 DCHECK(ToRegister(instr->global_object()).is(LoadIC::ReceiverRegister())); | 2994 DCHECK(ToRegister(instr->global_object()).is(LoadIC::ReceiverRegister())); |
2995 DCHECK(ToRegister(instr->result()).is(r0)); | 2995 DCHECK(ToRegister(instr->result()).is(r3)); |
2996 | 2996 |
2997 __ mov(LoadIC::NameRegister(), Operand(instr->name())); | 2997 __ mov(LoadIC::NameRegister(), Operand(instr->name())); |
2998 if (FLAG_vector_ics) { | 2998 if (FLAG_vector_ics) { |
2999 Register vector = ToRegister(instr->temp_vector()); | 2999 Register vector = ToRegister(instr->temp_vector()); |
3000 DCHECK(vector.is(LoadIC::VectorRegister())); | 3000 DCHECK(vector.is(LoadIC::VectorRegister())); |
3001 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3001 __ Move(vector, instr->hydrogen()->feedback_vector()); |
3002 // No need to allocate this register. | 3002 // No need to allocate this register. |
3003 DCHECK(LoadIC::SlotRegister().is(r0)); | 3003 DCHECK(LoadIC::SlotRegister().is(r0)); |
3004 __ mov(LoadIC::SlotRegister(), | 3004 __ mov(LoadIC::SlotRegister(), |
3005 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3005 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
(...skipping 11 matching lines...) Expand all Loading... |
3017 // Load the cell. | 3017 // Load the cell. |
3018 __ mov(cell, Operand(instr->hydrogen()->cell().handle())); | 3018 __ mov(cell, Operand(instr->hydrogen()->cell().handle())); |
3019 | 3019 |
3020 // If the cell we are storing to contains the hole it could have | 3020 // 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 | 3021 // been deleted from the property dictionary. In that case, we need |
3022 // to update the property details in the property dictionary to mark | 3022 // to update the property details in the property dictionary to mark |
3023 // it as no longer deleted. | 3023 // it as no longer deleted. |
3024 if (instr->hydrogen()->RequiresHoleCheck()) { | 3024 if (instr->hydrogen()->RequiresHoleCheck()) { |
3025 // We use a temp to check the payload (CompareRoot might clobber ip). | 3025 // We use a temp to check the payload (CompareRoot might clobber ip). |
3026 Register payload = ToRegister(instr->temp()); | 3026 Register payload = ToRegister(instr->temp()); |
3027 __ ldr(payload, FieldMemOperand(cell, Cell::kValueOffset)); | 3027 __ LoadP(payload, FieldMemOperand(cell, Cell::kValueOffset)); |
3028 __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); | 3028 __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); |
3029 DeoptimizeIf(eq, instr->environment()); | 3029 DeoptimizeIf(eq, instr->environment()); |
3030 } | 3030 } |
3031 | 3031 |
3032 // Store the value. | 3032 // Store the value. |
3033 __ str(value, FieldMemOperand(cell, Cell::kValueOffset)); | 3033 __ StoreP(value, FieldMemOperand(cell, Cell::kValueOffset), r0); |
3034 // Cells are always rescanned, so no write barrier here. | 3034 // Cells are always rescanned, so no write barrier here. |
3035 } | 3035 } |
3036 | 3036 |
3037 | 3037 |
3038 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { | 3038 void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
3039 Register context = ToRegister(instr->context()); | 3039 Register context = ToRegister(instr->context()); |
3040 Register result = ToRegister(instr->result()); | 3040 Register result = ToRegister(instr->result()); |
3041 __ ldr(result, ContextOperand(context, instr->slot_index())); | 3041 __ LoadP(result, ContextOperand(context, instr->slot_index())); |
3042 if (instr->hydrogen()->RequiresHoleCheck()) { | 3042 if (instr->hydrogen()->RequiresHoleCheck()) { |
3043 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3043 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
3044 __ cmp(result, ip); | 3044 __ cmp(result, ip); |
3045 if (instr->hydrogen()->DeoptimizesOnHole()) { | 3045 if (instr->hydrogen()->DeoptimizesOnHole()) { |
3046 DeoptimizeIf(eq, instr->environment()); | 3046 DeoptimizeIf(eq, instr->environment()); |
3047 } else { | 3047 } else { |
3048 __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq); | 3048 Label skip; |
| 3049 __ bne(&skip); |
| 3050 __ mov(result, Operand(factory()->undefined_value())); |
| 3051 __ bind(&skip); |
3049 } | 3052 } |
3050 } | 3053 } |
3051 } | 3054 } |
3052 | 3055 |
3053 | 3056 |
3054 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { | 3057 void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
3055 Register context = ToRegister(instr->context()); | 3058 Register context = ToRegister(instr->context()); |
3056 Register value = ToRegister(instr->value()); | 3059 Register value = ToRegister(instr->value()); |
3057 Register scratch = scratch0(); | 3060 Register scratch = scratch0(); |
3058 MemOperand target = ContextOperand(context, instr->slot_index()); | 3061 MemOperand target = ContextOperand(context, instr->slot_index()); |
3059 | 3062 |
3060 Label skip_assignment; | 3063 Label skip_assignment; |
3061 | 3064 |
3062 if (instr->hydrogen()->RequiresHoleCheck()) { | 3065 if (instr->hydrogen()->RequiresHoleCheck()) { |
3063 __ ldr(scratch, target); | 3066 __ LoadP(scratch, target); |
3064 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3067 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
3065 __ cmp(scratch, ip); | 3068 __ cmp(scratch, ip); |
3066 if (instr->hydrogen()->DeoptimizesOnHole()) { | 3069 if (instr->hydrogen()->DeoptimizesOnHole()) { |
3067 DeoptimizeIf(eq, instr->environment()); | 3070 DeoptimizeIf(eq, instr->environment()); |
3068 } else { | 3071 } else { |
3069 __ b(ne, &skip_assignment); | 3072 __ bne(&skip_assignment); |
3070 } | 3073 } |
3071 } | 3074 } |
3072 | 3075 |
3073 __ str(value, target); | 3076 __ StoreP(value, target, r0); |
3074 if (instr->hydrogen()->NeedsWriteBarrier()) { | 3077 if (instr->hydrogen()->NeedsWriteBarrier()) { |
3075 SmiCheck check_needed = | 3078 SmiCheck check_needed = instr->hydrogen()->value()->type().IsHeapObject() |
3076 instr->hydrogen()->value()->type().IsHeapObject() | 3079 ? OMIT_SMI_CHECK |
3077 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 3080 : INLINE_SMI_CHECK; |
3078 __ RecordWriteContextSlot(context, | 3081 __ RecordWriteContextSlot(context, target.offset(), value, scratch, |
3079 target.offset(), | 3082 GetLinkRegisterState(), kSaveFPRegs, |
3080 value, | 3083 EMIT_REMEMBERED_SET, check_needed); |
3081 scratch, | |
3082 GetLinkRegisterState(), | |
3083 kSaveFPRegs, | |
3084 EMIT_REMEMBERED_SET, | |
3085 check_needed); | |
3086 } | 3084 } |
3087 | 3085 |
3088 __ bind(&skip_assignment); | 3086 __ bind(&skip_assignment); |
3089 } | 3087 } |
3090 | 3088 |
3091 | 3089 |
3092 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { | 3090 void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
3093 HObjectAccess access = instr->hydrogen()->access(); | 3091 HObjectAccess access = instr->hydrogen()->access(); |
3094 int offset = access.offset(); | 3092 int offset = access.offset(); |
3095 Register object = ToRegister(instr->object()); | 3093 Register object = ToRegister(instr->object()); |
3096 | 3094 |
3097 if (access.IsExternalMemory()) { | 3095 if (access.IsExternalMemory()) { |
3098 Register result = ToRegister(instr->result()); | 3096 Register result = ToRegister(instr->result()); |
3099 MemOperand operand = MemOperand(object, offset); | 3097 MemOperand operand = MemOperand(object, offset); |
3100 __ Load(result, operand, access.representation()); | 3098 __ LoadRepresentation(result, operand, access.representation(), r0); |
3101 return; | 3099 return; |
3102 } | 3100 } |
3103 | 3101 |
3104 if (instr->hydrogen()->representation().IsDouble()) { | 3102 if (instr->hydrogen()->representation().IsDouble()) { |
3105 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3103 DoubleRegister result = ToDoubleRegister(instr->result()); |
3106 __ vldr(result, FieldMemOperand(object, offset)); | 3104 __ lfd(result, FieldMemOperand(object, offset)); |
3107 return; | 3105 return; |
3108 } | 3106 } |
3109 | 3107 |
3110 Register result = ToRegister(instr->result()); | 3108 Register result = ToRegister(instr->result()); |
3111 if (!access.IsInobject()) { | 3109 if (!access.IsInobject()) { |
3112 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 3110 __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
3113 object = result; | 3111 object = result; |
3114 } | 3112 } |
3115 MemOperand operand = FieldMemOperand(object, offset); | 3113 |
3116 __ Load(result, operand, access.representation()); | 3114 Representation representation = access.representation(); |
| 3115 |
| 3116 #if V8_TARGET_ARCH_PPC64 |
| 3117 // 64-bit Smi optimization |
| 3118 if (representation.IsSmi() && |
| 3119 instr->hydrogen()->representation().IsInteger32()) { |
| 3120 // Read int value directly from upper half of the smi. |
| 3121 STATIC_ASSERT(kSmiTag == 0); |
| 3122 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 3123 #if V8_TARGET_LITTLE_ENDIAN |
| 3124 offset += kPointerSize / 2; |
| 3125 #endif |
| 3126 representation = Representation::Integer32(); |
| 3127 } |
| 3128 #endif |
| 3129 |
| 3130 __ LoadRepresentation(result, FieldMemOperand(object, offset), representation, |
| 3131 r0); |
3117 } | 3132 } |
3118 | 3133 |
3119 | 3134 |
3120 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { | 3135 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
3121 DCHECK(ToRegister(instr->context()).is(cp)); | 3136 DCHECK(ToRegister(instr->context()).is(cp)); |
3122 DCHECK(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); | 3137 DCHECK(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); |
3123 DCHECK(ToRegister(instr->result()).is(r0)); | 3138 DCHECK(ToRegister(instr->result()).is(r3)); |
3124 | 3139 |
3125 // Name is always in r2. | |
3126 __ mov(LoadIC::NameRegister(), Operand(instr->name())); | 3140 __ mov(LoadIC::NameRegister(), Operand(instr->name())); |
3127 if (FLAG_vector_ics) { | 3141 if (FLAG_vector_ics) { |
3128 Register vector = ToRegister(instr->temp_vector()); | 3142 Register vector = ToRegister(instr->temp_vector()); |
3129 DCHECK(vector.is(LoadIC::VectorRegister())); | 3143 DCHECK(vector.is(LoadIC::VectorRegister())); |
3130 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3144 __ Move(vector, instr->hydrogen()->feedback_vector()); |
3131 // No need to allocate this register. | 3145 // No need to allocate this register. |
3132 DCHECK(LoadIC::SlotRegister().is(r0)); | 3146 DCHECK(LoadIC::SlotRegister().is(r0)); |
3133 __ mov(LoadIC::SlotRegister(), | 3147 __ mov(LoadIC::SlotRegister(), |
3134 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3148 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
3135 } | 3149 } |
3136 Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); | 3150 Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); |
3137 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 3151 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
3138 } | 3152 } |
3139 | 3153 |
3140 | 3154 |
3141 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { | 3155 void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
3142 Register scratch = scratch0(); | 3156 Register scratch = scratch0(); |
3143 Register function = ToRegister(instr->function()); | 3157 Register function = ToRegister(instr->function()); |
3144 Register result = ToRegister(instr->result()); | 3158 Register result = ToRegister(instr->result()); |
3145 | 3159 |
3146 // Get the prototype or initial map from the function. | 3160 // Get the prototype or initial map from the function. |
3147 __ ldr(result, | 3161 __ LoadP(result, |
3148 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); | 3162 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
3149 | 3163 |
3150 // Check that the function has a prototype or an initial map. | 3164 // Check that the function has a prototype or an initial map. |
3151 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 3165 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
3152 __ cmp(result, ip); | 3166 __ cmp(result, ip); |
3153 DeoptimizeIf(eq, instr->environment()); | 3167 DeoptimizeIf(eq, instr->environment()); |
3154 | 3168 |
3155 // If the function does not have an initial map, we're done. | 3169 // If the function does not have an initial map, we're done. |
3156 Label done; | 3170 Label done; |
3157 __ CompareObjectType(result, scratch, scratch, MAP_TYPE); | 3171 __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
3158 __ b(ne, &done); | 3172 __ bne(&done); |
3159 | 3173 |
3160 // Get the prototype from the initial map. | 3174 // Get the prototype from the initial map. |
3161 __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); | 3175 __ LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
3162 | 3176 |
3163 // All done. | 3177 // All done. |
3164 __ bind(&done); | 3178 __ bind(&done); |
3165 } | 3179 } |
3166 | 3180 |
3167 | 3181 |
3168 void LCodeGen::DoLoadRoot(LLoadRoot* instr) { | 3182 void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
3169 Register result = ToRegister(instr->result()); | 3183 Register result = ToRegister(instr->result()); |
3170 __ LoadRoot(result, instr->index()); | 3184 __ LoadRoot(result, instr->index()); |
3171 } | 3185 } |
3172 | 3186 |
3173 | 3187 |
3174 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { | 3188 void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
3175 Register arguments = ToRegister(instr->arguments()); | 3189 Register arguments = ToRegister(instr->arguments()); |
3176 Register result = ToRegister(instr->result()); | 3190 Register result = ToRegister(instr->result()); |
3177 // There are two words between the frame pointer and the last argument. | 3191 // There are two words between the frame pointer and the last argument. |
3178 // Subtracting from length accounts for one of them add one more. | 3192 // Subtracting from length accounts for one of them add one more. |
3179 if (instr->length()->IsConstantOperand()) { | 3193 if (instr->length()->IsConstantOperand()) { |
3180 int const_length = ToInteger32(LConstantOperand::cast(instr->length())); | 3194 int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
3181 if (instr->index()->IsConstantOperand()) { | 3195 if (instr->index()->IsConstantOperand()) { |
3182 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3196 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
3183 int index = (const_length - const_index) + 1; | 3197 int index = (const_length - const_index) + 1; |
3184 __ ldr(result, MemOperand(arguments, index * kPointerSize)); | 3198 __ LoadP(result, MemOperand(arguments, index * kPointerSize), r0); |
3185 } else { | 3199 } else { |
3186 Register index = ToRegister(instr->index()); | 3200 Register index = ToRegister(instr->index()); |
3187 __ rsb(result, index, Operand(const_length + 1)); | 3201 __ subfic(result, index, Operand(const_length + 1)); |
3188 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3202 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
| 3203 __ LoadPX(result, MemOperand(arguments, result)); |
3189 } | 3204 } |
3190 } else if (instr->index()->IsConstantOperand()) { | 3205 } else if (instr->index()->IsConstantOperand()) { |
3191 Register length = ToRegister(instr->length()); | 3206 Register length = ToRegister(instr->length()); |
3192 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3207 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
3193 int loc = const_index - 1; | 3208 int loc = const_index - 1; |
3194 if (loc != 0) { | 3209 if (loc != 0) { |
3195 __ sub(result, length, Operand(loc)); | 3210 __ subi(result, length, Operand(loc)); |
3196 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3211 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
3197 } else { | 3212 __ LoadPX(result, MemOperand(arguments, result)); |
3198 __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); | |
3199 } | |
3200 } else { | 3213 } else { |
| 3214 __ ShiftLeftImm(result, length, Operand(kPointerSizeLog2)); |
| 3215 __ LoadPX(result, MemOperand(arguments, result)); |
| 3216 } |
| 3217 } else { |
3201 Register length = ToRegister(instr->length()); | 3218 Register length = ToRegister(instr->length()); |
3202 Register index = ToRegister(instr->index()); | 3219 Register index = ToRegister(instr->index()); |
3203 __ sub(result, length, index); | 3220 __ sub(result, length, index); |
3204 __ add(result, result, Operand(1)); | 3221 __ addi(result, result, Operand(1)); |
3205 __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); | 3222 __ ShiftLeftImm(result, result, Operand(kPointerSizeLog2)); |
| 3223 __ LoadPX(result, MemOperand(arguments, result)); |
3206 } | 3224 } |
3207 } | 3225 } |
3208 | 3226 |
3209 | 3227 |
3210 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { | 3228 void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
3211 Register external_pointer = ToRegister(instr->elements()); | 3229 Register external_pointer = ToRegister(instr->elements()); |
3212 Register key = no_reg; | 3230 Register key = no_reg; |
3213 ElementsKind elements_kind = instr->elements_kind(); | 3231 ElementsKind elements_kind = instr->elements_kind(); |
3214 bool key_is_constant = instr->key()->IsConstantOperand(); | 3232 bool key_is_constant = instr->key()->IsConstantOperand(); |
3215 int constant_key = 0; | 3233 int constant_key = 0; |
3216 if (key_is_constant) { | 3234 if (key_is_constant) { |
3217 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 3235 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
3218 if (constant_key & 0xF0000000) { | 3236 if (constant_key & 0xF0000000) { |
3219 Abort(kArrayIndexConstantValueTooBig); | 3237 Abort(kArrayIndexConstantValueTooBig); |
3220 } | 3238 } |
3221 } else { | 3239 } else { |
3222 key = ToRegister(instr->key()); | 3240 key = ToRegister(instr->key()); |
3223 } | 3241 } |
3224 int element_size_shift = ElementsKindToShiftSize(elements_kind); | 3242 int element_size_shift = ElementsKindToShiftSize(elements_kind); |
3225 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 3243 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
3226 ? (element_size_shift - kSmiTagSize) : element_size_shift; | |
3227 int base_offset = instr->base_offset(); | 3244 int base_offset = instr->base_offset(); |
3228 | 3245 |
3229 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 3246 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
3230 elements_kind == FLOAT32_ELEMENTS || | 3247 elements_kind == FLOAT32_ELEMENTS || |
3231 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || | 3248 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
3232 elements_kind == FLOAT64_ELEMENTS) { | 3249 elements_kind == FLOAT64_ELEMENTS) { |
3233 int base_offset = instr->base_offset(); | 3250 DoubleRegister result = ToDoubleRegister(instr->result()); |
3234 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3251 if (key_is_constant) { |
3235 Operand operand = key_is_constant | 3252 __ Add(scratch0(), external_pointer, constant_key << element_size_shift, |
3236 ? Operand(constant_key << element_size_shift) | 3253 r0); |
3237 : Operand(key, LSL, shift_size); | 3254 } else { |
3238 __ add(scratch0(), external_pointer, operand); | 3255 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 3256 __ add(scratch0(), external_pointer, r0); |
| 3257 } |
3239 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 3258 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
3240 elements_kind == FLOAT32_ELEMENTS) { | 3259 elements_kind == FLOAT32_ELEMENTS) { |
3241 __ vldr(double_scratch0().low(), scratch0(), base_offset); | 3260 __ lfs(result, MemOperand(scratch0(), base_offset)); |
3242 __ vcvt_f64_f32(result, double_scratch0().low()); | 3261 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
3243 } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS | 3262 __ lfd(result, MemOperand(scratch0(), base_offset)); |
3244 __ vldr(result, scratch0(), base_offset); | |
3245 } | 3263 } |
3246 } else { | 3264 } else { |
3247 Register result = ToRegister(instr->result()); | 3265 Register result = ToRegister(instr->result()); |
3248 MemOperand mem_operand = PrepareKeyedOperand( | 3266 MemOperand mem_operand = |
3249 key, external_pointer, key_is_constant, constant_key, | 3267 PrepareKeyedOperand(key, external_pointer, key_is_constant, key_is_smi, |
3250 element_size_shift, shift_size, base_offset); | 3268 constant_key, element_size_shift, base_offset); |
3251 switch (elements_kind) { | 3269 switch (elements_kind) { |
3252 case EXTERNAL_INT8_ELEMENTS: | 3270 case EXTERNAL_INT8_ELEMENTS: |
3253 case INT8_ELEMENTS: | 3271 case INT8_ELEMENTS: |
3254 __ ldrsb(result, mem_operand); | 3272 if (key_is_constant) { |
| 3273 __ LoadByte(result, mem_operand, r0); |
| 3274 } else { |
| 3275 __ lbzx(result, mem_operand); |
| 3276 } |
| 3277 __ extsb(result, result); |
3255 break; | 3278 break; |
3256 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: | 3279 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
3257 case EXTERNAL_UINT8_ELEMENTS: | 3280 case EXTERNAL_UINT8_ELEMENTS: |
3258 case UINT8_ELEMENTS: | 3281 case UINT8_ELEMENTS: |
3259 case UINT8_CLAMPED_ELEMENTS: | 3282 case UINT8_CLAMPED_ELEMENTS: |
3260 __ ldrb(result, mem_operand); | 3283 if (key_is_constant) { |
| 3284 __ LoadByte(result, mem_operand, r0); |
| 3285 } else { |
| 3286 __ lbzx(result, mem_operand); |
| 3287 } |
3261 break; | 3288 break; |
3262 case EXTERNAL_INT16_ELEMENTS: | 3289 case EXTERNAL_INT16_ELEMENTS: |
3263 case INT16_ELEMENTS: | 3290 case INT16_ELEMENTS: |
3264 __ ldrsh(result, mem_operand); | 3291 if (key_is_constant) { |
| 3292 __ LoadHalfWord(result, mem_operand, r0); |
| 3293 } else { |
| 3294 __ lhzx(result, mem_operand); |
| 3295 } |
| 3296 __ extsh(result, result); |
3265 break; | 3297 break; |
3266 case EXTERNAL_UINT16_ELEMENTS: | 3298 case EXTERNAL_UINT16_ELEMENTS: |
3267 case UINT16_ELEMENTS: | 3299 case UINT16_ELEMENTS: |
3268 __ ldrh(result, mem_operand); | 3300 if (key_is_constant) { |
| 3301 __ LoadHalfWord(result, mem_operand, r0); |
| 3302 } else { |
| 3303 __ lhzx(result, mem_operand); |
| 3304 } |
3269 break; | 3305 break; |
3270 case EXTERNAL_INT32_ELEMENTS: | 3306 case EXTERNAL_INT32_ELEMENTS: |
3271 case INT32_ELEMENTS: | 3307 case INT32_ELEMENTS: |
3272 __ ldr(result, mem_operand); | 3308 if (key_is_constant) { |
| 3309 __ LoadWord(result, mem_operand, r0); |
| 3310 } else { |
| 3311 __ lwzx(result, mem_operand); |
| 3312 } |
| 3313 #if V8_TARGET_ARCH_PPC64 |
| 3314 __ extsw(result, result); |
| 3315 #endif |
3273 break; | 3316 break; |
3274 case EXTERNAL_UINT32_ELEMENTS: | 3317 case EXTERNAL_UINT32_ELEMENTS: |
3275 case UINT32_ELEMENTS: | 3318 case UINT32_ELEMENTS: |
3276 __ ldr(result, mem_operand); | 3319 if (key_is_constant) { |
| 3320 __ LoadWord(result, mem_operand, r0); |
| 3321 } else { |
| 3322 __ lwzx(result, mem_operand); |
| 3323 } |
3277 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { | 3324 if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
3278 __ cmp(result, Operand(0x80000000)); | 3325 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
3279 DeoptimizeIf(cs, instr->environment()); | 3326 __ cmplw(result, r0); |
| 3327 DeoptimizeIf(ge, instr->environment()); |
3280 } | 3328 } |
3281 break; | 3329 break; |
3282 case FLOAT32_ELEMENTS: | 3330 case FLOAT32_ELEMENTS: |
3283 case FLOAT64_ELEMENTS: | 3331 case FLOAT64_ELEMENTS: |
3284 case EXTERNAL_FLOAT32_ELEMENTS: | 3332 case EXTERNAL_FLOAT32_ELEMENTS: |
3285 case EXTERNAL_FLOAT64_ELEMENTS: | 3333 case EXTERNAL_FLOAT64_ELEMENTS: |
3286 case FAST_HOLEY_DOUBLE_ELEMENTS: | 3334 case FAST_HOLEY_DOUBLE_ELEMENTS: |
3287 case FAST_HOLEY_ELEMENTS: | 3335 case FAST_HOLEY_ELEMENTS: |
3288 case FAST_HOLEY_SMI_ELEMENTS: | 3336 case FAST_HOLEY_SMI_ELEMENTS: |
3289 case FAST_DOUBLE_ELEMENTS: | 3337 case FAST_DOUBLE_ELEMENTS: |
3290 case FAST_ELEMENTS: | 3338 case FAST_ELEMENTS: |
3291 case FAST_SMI_ELEMENTS: | 3339 case FAST_SMI_ELEMENTS: |
3292 case DICTIONARY_ELEMENTS: | 3340 case DICTIONARY_ELEMENTS: |
3293 case SLOPPY_ARGUMENTS_ELEMENTS: | 3341 case SLOPPY_ARGUMENTS_ELEMENTS: |
3294 UNREACHABLE(); | 3342 UNREACHABLE(); |
3295 break; | 3343 break; |
3296 } | 3344 } |
3297 } | 3345 } |
3298 } | 3346 } |
3299 | 3347 |
3300 | 3348 |
3301 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { | 3349 void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
3302 Register elements = ToRegister(instr->elements()); | 3350 Register elements = ToRegister(instr->elements()); |
3303 bool key_is_constant = instr->key()->IsConstantOperand(); | 3351 bool key_is_constant = instr->key()->IsConstantOperand(); |
3304 Register key = no_reg; | 3352 Register key = no_reg; |
3305 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3353 DoubleRegister result = ToDoubleRegister(instr->result()); |
3306 Register scratch = scratch0(); | 3354 Register scratch = scratch0(); |
3307 | 3355 |
3308 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); | 3356 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
3309 | 3357 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
3310 int base_offset = instr->base_offset(); | 3358 int constant_key = 0; |
3311 if (key_is_constant) { | 3359 if (key_is_constant) { |
3312 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 3360 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
3313 if (constant_key & 0xF0000000) { | 3361 if (constant_key & 0xF0000000) { |
3314 Abort(kArrayIndexConstantValueTooBig); | 3362 Abort(kArrayIndexConstantValueTooBig); |
3315 } | 3363 } |
3316 base_offset += constant_key * kDoubleSize; | 3364 } else { |
3317 } | |
3318 __ add(scratch, elements, Operand(base_offset)); | |
3319 | |
3320 if (!key_is_constant) { | |
3321 key = ToRegister(instr->key()); | 3365 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 } | 3366 } |
3326 | 3367 |
3327 __ vldr(result, scratch, 0); | 3368 int base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 3369 if (!key_is_constant) { |
| 3370 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 3371 __ add(scratch, elements, r0); |
| 3372 elements = scratch; |
| 3373 } |
| 3374 if (!is_int16(base_offset)) { |
| 3375 __ Add(scratch, elements, base_offset, r0); |
| 3376 base_offset = 0; |
| 3377 elements = scratch; |
| 3378 } |
| 3379 __ lfd(result, MemOperand(elements, base_offset)); |
3328 | 3380 |
3329 if (instr->hydrogen()->RequiresHoleCheck()) { | 3381 if (instr->hydrogen()->RequiresHoleCheck()) { |
3330 __ ldr(scratch, MemOperand(scratch, sizeof(kHoleNanLower32))); | 3382 if (is_int16(base_offset + Register::kExponentOffset)) { |
3331 __ cmp(scratch, Operand(kHoleNanUpper32)); | 3383 __ lwz(scratch, |
| 3384 MemOperand(elements, base_offset + Register::kExponentOffset)); |
| 3385 } else { |
| 3386 __ addi(scratch, elements, Operand(base_offset)); |
| 3387 __ lwz(scratch, MemOperand(scratch, Register::kExponentOffset)); |
| 3388 } |
| 3389 __ Cmpi(scratch, Operand(kHoleNanUpper32), r0); |
3332 DeoptimizeIf(eq, instr->environment()); | 3390 DeoptimizeIf(eq, instr->environment()); |
3333 } | 3391 } |
3334 } | 3392 } |
3335 | 3393 |
3336 | 3394 |
3337 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { | 3395 void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3396 HLoadKeyed* hinstr = instr->hydrogen(); |
3338 Register elements = ToRegister(instr->elements()); | 3397 Register elements = ToRegister(instr->elements()); |
3339 Register result = ToRegister(instr->result()); | 3398 Register result = ToRegister(instr->result()); |
3340 Register scratch = scratch0(); | 3399 Register scratch = scratch0(); |
3341 Register store_base = scratch; | 3400 Register store_base = scratch; |
3342 int offset = instr->base_offset(); | 3401 int offset = instr->base_offset(); |
3343 | 3402 |
3344 if (instr->key()->IsConstantOperand()) { | 3403 if (instr->key()->IsConstantOperand()) { |
3345 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | 3404 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
3346 offset += ToInteger32(const_operand) * kPointerSize; | 3405 offset += ToInteger32(const_operand) * kPointerSize; |
3347 store_base = elements; | 3406 store_base = elements; |
3348 } else { | 3407 } else { |
3349 Register key = ToRegister(instr->key()); | 3408 Register key = ToRegister(instr->key()); |
3350 // Even though the HLoadKeyed instruction forces the input | 3409 // Even though the HLoadKeyed instruction forces the input |
3351 // representation for the key to be an integer, the input gets replaced | 3410 // representation for the key to be an integer, the input gets replaced |
3352 // during bound check elimination with the index argument to the bounds | 3411 // 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. | 3412 // check, which can be tagged, so that case must be handled here, too. |
3354 if (instr->hydrogen()->key()->representation().IsSmi()) { | 3413 if (hinstr->key()->representation().IsSmi()) { |
3355 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); | 3414 __ SmiToPtrArrayOffset(r0, key); |
3356 } else { | 3415 } else { |
3357 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); | 3416 __ ShiftLeftImm(r0, key, Operand(kPointerSizeLog2)); |
3358 } | 3417 } |
| 3418 __ add(scratch, elements, r0); |
3359 } | 3419 } |
3360 __ ldr(result, MemOperand(store_base, offset)); | 3420 |
| 3421 bool requires_hole_check = hinstr->RequiresHoleCheck(); |
| 3422 Representation representation = hinstr->representation(); |
| 3423 |
| 3424 #if V8_TARGET_ARCH_PPC64 |
| 3425 // 64-bit Smi optimization |
| 3426 if (representation.IsInteger32() && |
| 3427 hinstr->elements_kind() == FAST_SMI_ELEMENTS) { |
| 3428 DCHECK(!requires_hole_check); |
| 3429 // Read int value directly from upper half of the smi. |
| 3430 STATIC_ASSERT(kSmiTag == 0); |
| 3431 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 3432 #if V8_TARGET_LITTLE_ENDIAN |
| 3433 offset += kPointerSize / 2; |
| 3434 #endif |
| 3435 } |
| 3436 #endif |
| 3437 |
| 3438 __ LoadRepresentation(result, MemOperand(store_base, offset), representation, |
| 3439 r0); |
3361 | 3440 |
3362 // Check for the hole value. | 3441 // Check for the hole value. |
3363 if (instr->hydrogen()->RequiresHoleCheck()) { | 3442 if (requires_hole_check) { |
3364 if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { | 3443 if (IsFastSmiElementsKind(hinstr->elements_kind())) { |
3365 __ SmiTst(result); | 3444 __ TestIfSmi(result, r0); |
3366 DeoptimizeIf(ne, instr->environment()); | 3445 DeoptimizeIf(ne, instr->environment(), cr0); |
3367 } else { | 3446 } else { |
3368 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); | 3447 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
3369 __ cmp(result, scratch); | 3448 __ cmp(result, scratch); |
3370 DeoptimizeIf(eq, instr->environment()); | 3449 DeoptimizeIf(eq, instr->environment()); |
3371 } | 3450 } |
3372 } | 3451 } |
3373 } | 3452 } |
3374 | 3453 |
3375 | 3454 |
3376 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { | 3455 void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
3377 if (instr->is_typed_elements()) { | 3456 if (instr->is_typed_elements()) { |
3378 DoLoadKeyedExternalArray(instr); | 3457 DoLoadKeyedExternalArray(instr); |
3379 } else if (instr->hydrogen()->representation().IsDouble()) { | 3458 } else if (instr->hydrogen()->representation().IsDouble()) { |
3380 DoLoadKeyedFixedDoubleArray(instr); | 3459 DoLoadKeyedFixedDoubleArray(instr); |
3381 } else { | 3460 } else { |
3382 DoLoadKeyedFixedArray(instr); | 3461 DoLoadKeyedFixedArray(instr); |
3383 } | 3462 } |
3384 } | 3463 } |
3385 | 3464 |
3386 | 3465 |
3387 MemOperand LCodeGen::PrepareKeyedOperand(Register key, | 3466 MemOperand LCodeGen::PrepareKeyedOperand(Register key, Register base, |
3388 Register base, | 3467 bool key_is_constant, bool key_is_smi, |
3389 bool key_is_constant, | |
3390 int constant_key, | 3468 int constant_key, |
3391 int element_size, | 3469 int element_size_shift, |
3392 int shift_size, | |
3393 int base_offset) { | 3470 int base_offset) { |
| 3471 Register scratch = scratch0(); |
| 3472 |
3394 if (key_is_constant) { | 3473 if (key_is_constant) { |
3395 return MemOperand(base, (constant_key << element_size) + base_offset); | 3474 return MemOperand(base, (constant_key << element_size_shift) + base_offset); |
3396 } | 3475 } |
3397 | 3476 |
3398 if (base_offset == 0) { | 3477 bool needs_shift = |
3399 if (shift_size >= 0) { | 3478 (element_size_shift != (key_is_smi ? kSmiTagSize + kSmiShiftSize : 0)); |
3400 return MemOperand(base, key, LSL, shift_size); | 3479 |
3401 } else { | 3480 if (!(base_offset || needs_shift)) { |
3402 DCHECK_EQ(-1, shift_size); | 3481 return MemOperand(base, key); |
3403 return MemOperand(base, key, LSR, 1); | |
3404 } | |
3405 } | 3482 } |
3406 | 3483 |
3407 if (shift_size >= 0) { | 3484 if (needs_shift) { |
3408 __ add(scratch0(), base, Operand(key, LSL, shift_size)); | 3485 __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
3409 return MemOperand(scratch0(), base_offset); | 3486 key = scratch; |
3410 } else { | |
3411 DCHECK_EQ(-1, shift_size); | |
3412 __ add(scratch0(), base, Operand(key, ASR, 1)); | |
3413 return MemOperand(scratch0(), base_offset); | |
3414 } | 3487 } |
| 3488 |
| 3489 if (base_offset) { |
| 3490 __ Add(scratch, key, base_offset, r0); |
| 3491 } |
| 3492 |
| 3493 return MemOperand(base, scratch); |
3415 } | 3494 } |
3416 | 3495 |
3417 | 3496 |
3418 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { | 3497 void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
3419 DCHECK(ToRegister(instr->context()).is(cp)); | 3498 DCHECK(ToRegister(instr->context()).is(cp)); |
3420 DCHECK(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); | 3499 DCHECK(ToRegister(instr->object()).is(LoadIC::ReceiverRegister())); |
3421 DCHECK(ToRegister(instr->key()).is(LoadIC::NameRegister())); | 3500 DCHECK(ToRegister(instr->key()).is(LoadIC::NameRegister())); |
3422 | 3501 |
3423 if (FLAG_vector_ics) { | 3502 if (FLAG_vector_ics) { |
3424 Register vector = ToRegister(instr->temp_vector()); | 3503 Register vector = ToRegister(instr->temp_vector()); |
3425 DCHECK(vector.is(LoadIC::VectorRegister())); | 3504 DCHECK(vector.is(LoadIC::VectorRegister())); |
3426 __ Move(vector, instr->hydrogen()->feedback_vector()); | 3505 __ Move(vector, instr->hydrogen()->feedback_vector()); |
3427 // No need to allocate this register. | 3506 // No need to allocate this register. |
3428 DCHECK(LoadIC::SlotRegister().is(r0)); | 3507 DCHECK(LoadIC::SlotRegister().is(r0)); |
3429 __ mov(LoadIC::SlotRegister(), | 3508 __ mov(LoadIC::SlotRegister(), |
3430 Operand(Smi::FromInt(instr->hydrogen()->slot()))); | 3509 Operand(Smi::FromInt(instr->hydrogen()->slot()))); |
3431 } | 3510 } |
3432 | 3511 |
3433 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); | 3512 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
3434 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 3513 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
3435 } | 3514 } |
3436 | 3515 |
3437 | 3516 |
3438 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { | 3517 void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
3439 Register scratch = scratch0(); | 3518 Register scratch = scratch0(); |
3440 Register result = ToRegister(instr->result()); | 3519 Register result = ToRegister(instr->result()); |
3441 | 3520 |
3442 if (instr->hydrogen()->from_inlined()) { | 3521 if (instr->hydrogen()->from_inlined()) { |
3443 __ sub(result, sp, Operand(2 * kPointerSize)); | 3522 __ subi(result, sp, Operand(2 * kPointerSize)); |
3444 } else { | 3523 } else { |
3445 // Check if the calling frame is an arguments adaptor frame. | 3524 // Check if the calling frame is an arguments adaptor frame. |
3446 Label done, adapted; | 3525 Label done, adapted; |
3447 __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 3526 __ LoadP(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
3448 __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); | 3527 __ LoadP(result, |
3449 __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | 3528 MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3529 __ CmpSmiLiteral(result, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
3450 | 3530 |
3451 // Result is the frame pointer for the frame if not adapted and for the real | 3531 // Result is the frame pointer for the frame if not adapted and for the real |
3452 // frame below the adaptor frame if adapted. | 3532 // frame below the adaptor frame if adapted. |
3453 __ mov(result, fp, LeaveCC, ne); | 3533 __ beq(&adapted); |
3454 __ mov(result, scratch, LeaveCC, eq); | 3534 __ mr(result, fp); |
| 3535 __ b(&done); |
| 3536 |
| 3537 __ bind(&adapted); |
| 3538 __ mr(result, scratch); |
| 3539 __ bind(&done); |
3455 } | 3540 } |
3456 } | 3541 } |
3457 | 3542 |
3458 | 3543 |
3459 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { | 3544 void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
3460 Register elem = ToRegister(instr->elements()); | 3545 Register elem = ToRegister(instr->elements()); |
3461 Register result = ToRegister(instr->result()); | 3546 Register result = ToRegister(instr->result()); |
3462 | 3547 |
3463 Label done; | 3548 Label done; |
3464 | 3549 |
3465 // If no arguments adaptor frame the number of arguments is fixed. | 3550 // If no arguments adaptor frame the number of arguments is fixed. |
3466 __ cmp(fp, elem); | 3551 __ cmp(fp, elem); |
3467 __ mov(result, Operand(scope()->num_parameters())); | 3552 __ mov(result, Operand(scope()->num_parameters())); |
3468 __ b(eq, &done); | 3553 __ beq(&done); |
3469 | 3554 |
3470 // Arguments adaptor frame present. Get argument length from there. | 3555 // Arguments adaptor frame present. Get argument length from there. |
3471 __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 3556 __ LoadP(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
3472 __ ldr(result, | 3557 __ LoadP(result, |
3473 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 3558 MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
3474 __ SmiUntag(result); | 3559 __ SmiUntag(result); |
3475 | 3560 |
3476 // Argument length is in result register. | 3561 // Argument length is in result register. |
3477 __ bind(&done); | 3562 __ bind(&done); |
3478 } | 3563 } |
3479 | 3564 |
3480 | 3565 |
3481 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { | 3566 void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
3482 Register receiver = ToRegister(instr->receiver()); | 3567 Register receiver = ToRegister(instr->receiver()); |
3483 Register function = ToRegister(instr->function()); | 3568 Register function = ToRegister(instr->function()); |
3484 Register result = ToRegister(instr->result()); | 3569 Register result = ToRegister(instr->result()); |
3485 Register scratch = scratch0(); | 3570 Register scratch = scratch0(); |
3486 | 3571 |
3487 // If the receiver is null or undefined, we have to pass the global | 3572 // 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 | 3573 // object as a receiver to normal functions. Values have to be |
3489 // passed unchanged to builtins and strict-mode functions. | 3574 // passed unchanged to builtins and strict-mode functions. |
3490 Label global_object, result_in_receiver; | 3575 Label global_object, result_in_receiver; |
3491 | 3576 |
3492 if (!instr->hydrogen()->known_function()) { | 3577 if (!instr->hydrogen()->known_function()) { |
3493 // Do not transform the receiver to object for strict mode | 3578 // Do not transform the receiver to object for strict mode |
3494 // functions. | 3579 // functions. |
3495 __ ldr(scratch, | 3580 __ LoadP(scratch, |
3496 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); | 3581 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
3497 __ ldr(scratch, | 3582 __ lwz(scratch, |
3498 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); | 3583 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
3499 int mask = 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize); | 3584 __ TestBit(scratch, |
3500 __ tst(scratch, Operand(mask)); | 3585 #if V8_TARGET_ARCH_PPC64 |
3501 __ b(ne, &result_in_receiver); | 3586 SharedFunctionInfo::kStrictModeFunction, |
| 3587 #else |
| 3588 SharedFunctionInfo::kStrictModeFunction + kSmiTagSize, |
| 3589 #endif |
| 3590 r0); |
| 3591 __ bne(&result_in_receiver, cr0); |
3502 | 3592 |
3503 // Do not transform the receiver to object for builtins. | 3593 // Do not transform the receiver to object for builtins. |
3504 __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); | 3594 __ TestBit(scratch, |
3505 __ b(ne, &result_in_receiver); | 3595 #if V8_TARGET_ARCH_PPC64 |
| 3596 SharedFunctionInfo::kNative, |
| 3597 #else |
| 3598 SharedFunctionInfo::kNative + kSmiTagSize, |
| 3599 #endif |
| 3600 r0); |
| 3601 __ bne(&result_in_receiver, cr0); |
3506 } | 3602 } |
3507 | 3603 |
3508 // Normal function. Replace undefined or null with global receiver. | 3604 // Normal function. Replace undefined or null with global receiver. |
3509 __ LoadRoot(scratch, Heap::kNullValueRootIndex); | 3605 __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
3510 __ cmp(receiver, scratch); | 3606 __ cmp(receiver, scratch); |
3511 __ b(eq, &global_object); | 3607 __ beq(&global_object); |
3512 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | 3608 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
3513 __ cmp(receiver, scratch); | 3609 __ cmp(receiver, scratch); |
3514 __ b(eq, &global_object); | 3610 __ beq(&global_object); |
3515 | 3611 |
3516 // Deoptimize if the receiver is not a JS object. | 3612 // Deoptimize if the receiver is not a JS object. |
3517 __ SmiTst(receiver); | 3613 __ TestIfSmi(receiver, r0); |
3518 DeoptimizeIf(eq, instr->environment()); | 3614 DeoptimizeIf(eq, instr->environment(), cr0); |
3519 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); | 3615 __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); |
3520 DeoptimizeIf(lt, instr->environment()); | 3616 DeoptimizeIf(lt, instr->environment()); |
3521 | 3617 |
3522 __ b(&result_in_receiver); | 3618 __ b(&result_in_receiver); |
3523 __ bind(&global_object); | 3619 __ bind(&global_object); |
3524 __ ldr(result, FieldMemOperand(function, JSFunction::kContextOffset)); | 3620 __ LoadP(result, FieldMemOperand(function, JSFunction::kContextOffset)); |
3525 __ ldr(result, | 3621 __ LoadP(result, ContextOperand(result, Context::GLOBAL_OBJECT_INDEX)); |
3526 ContextOperand(result, Context::GLOBAL_OBJECT_INDEX)); | 3622 __ LoadP(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset)); |
3527 __ ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset)); | |
3528 | |
3529 if (result.is(receiver)) { | 3623 if (result.is(receiver)) { |
3530 __ bind(&result_in_receiver); | 3624 __ bind(&result_in_receiver); |
3531 } else { | 3625 } else { |
3532 Label result_ok; | 3626 Label result_ok; |
3533 __ b(&result_ok); | 3627 __ b(&result_ok); |
3534 __ bind(&result_in_receiver); | 3628 __ bind(&result_in_receiver); |
3535 __ mov(result, receiver); | 3629 __ mr(result, receiver); |
3536 __ bind(&result_ok); | 3630 __ bind(&result_ok); |
3537 } | 3631 } |
3538 } | 3632 } |
3539 | 3633 |
3540 | 3634 |
3541 void LCodeGen::DoApplyArguments(LApplyArguments* instr) { | 3635 void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
3542 Register receiver = ToRegister(instr->receiver()); | 3636 Register receiver = ToRegister(instr->receiver()); |
3543 Register function = ToRegister(instr->function()); | 3637 Register function = ToRegister(instr->function()); |
3544 Register length = ToRegister(instr->length()); | 3638 Register length = ToRegister(instr->length()); |
3545 Register elements = ToRegister(instr->elements()); | 3639 Register elements = ToRegister(instr->elements()); |
3546 Register scratch = scratch0(); | 3640 Register scratch = scratch0(); |
3547 DCHECK(receiver.is(r0)); // Used for parameter count. | 3641 DCHECK(receiver.is(r3)); // Used for parameter count. |
3548 DCHECK(function.is(r1)); // Required by InvokeFunction. | 3642 DCHECK(function.is(r4)); // Required by InvokeFunction. |
3549 DCHECK(ToRegister(instr->result()).is(r0)); | 3643 DCHECK(ToRegister(instr->result()).is(r3)); |
3550 | 3644 |
3551 // Copy the arguments to this function possibly from the | 3645 // Copy the arguments to this function possibly from the |
3552 // adaptor frame below it. | 3646 // adaptor frame below it. |
3553 const uint32_t kArgumentsLimit = 1 * KB; | 3647 const uint32_t kArgumentsLimit = 1 * KB; |
3554 __ cmp(length, Operand(kArgumentsLimit)); | 3648 __ cmpli(length, Operand(kArgumentsLimit)); |
3555 DeoptimizeIf(hi, instr->environment()); | 3649 DeoptimizeIf(gt, instr->environment()); |
3556 | 3650 |
3557 // Push the receiver and use the register to keep the original | 3651 // Push the receiver and use the register to keep the original |
3558 // number of arguments. | 3652 // number of arguments. |
3559 __ push(receiver); | 3653 __ push(receiver); |
3560 __ mov(receiver, length); | 3654 __ mr(receiver, length); |
3561 // The arguments are at a one pointer size offset from elements. | 3655 // The arguments are at a one pointer size offset from elements. |
3562 __ add(elements, elements, Operand(1 * kPointerSize)); | 3656 __ addi(elements, elements, Operand(1 * kPointerSize)); |
3563 | 3657 |
3564 // Loop through the arguments pushing them onto the execution | 3658 // Loop through the arguments pushing them onto the execution |
3565 // stack. | 3659 // stack. |
3566 Label invoke, loop; | 3660 Label invoke, loop; |
3567 // length is a small non-negative integer, due to the test above. | 3661 // length is a small non-negative integer, due to the test above. |
3568 __ cmp(length, Operand::Zero()); | 3662 __ cmpi(length, Operand::Zero()); |
3569 __ b(eq, &invoke); | 3663 __ beq(&invoke); |
| 3664 __ mtctr(length); |
3570 __ bind(&loop); | 3665 __ bind(&loop); |
3571 __ ldr(scratch, MemOperand(elements, length, LSL, 2)); | 3666 __ ShiftLeftImm(r0, length, Operand(kPointerSizeLog2)); |
| 3667 __ LoadPX(scratch, MemOperand(elements, r0)); |
3572 __ push(scratch); | 3668 __ push(scratch); |
3573 __ sub(length, length, Operand(1), SetCC); | 3669 __ addi(length, length, Operand(-1)); |
3574 __ b(ne, &loop); | 3670 __ bdnz(&loop); |
3575 | 3671 |
3576 __ bind(&invoke); | 3672 __ bind(&invoke); |
3577 DCHECK(instr->HasPointerMap()); | 3673 DCHECK(instr->HasPointerMap()); |
3578 LPointerMap* pointers = instr->pointer_map(); | 3674 LPointerMap* pointers = instr->pointer_map(); |
3579 SafepointGenerator safepoint_generator( | 3675 SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); |
3580 this, pointers, Safepoint::kLazyDeopt); | 3676 // The number of arguments is stored in receiver which is r3, as expected |
3581 // The number of arguments is stored in receiver which is r0, as expected | |
3582 // by InvokeFunction. | 3677 // by InvokeFunction. |
3583 ParameterCount actual(receiver); | 3678 ParameterCount actual(receiver); |
3584 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); | 3679 __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); |
3585 } | 3680 } |
3586 | 3681 |
3587 | 3682 |
3588 void LCodeGen::DoPushArgument(LPushArgument* instr) { | 3683 void LCodeGen::DoPushArgument(LPushArgument* instr) { |
3589 LOperand* argument = instr->value(); | 3684 LOperand* argument = instr->value(); |
3590 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { | 3685 if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
3591 Abort(kDoPushArgumentNotImplementedForDoubleType); | 3686 Abort(kDoPushArgumentNotImplementedForDoubleType); |
3592 } else { | 3687 } else { |
3593 Register argument_reg = EmitLoadRegister(argument, ip); | 3688 Register argument_reg = EmitLoadRegister(argument, ip); |
3594 __ push(argument_reg); | 3689 __ push(argument_reg); |
3595 } | 3690 } |
3596 } | 3691 } |
3597 | 3692 |
3598 | 3693 |
3599 void LCodeGen::DoDrop(LDrop* instr) { | 3694 void LCodeGen::DoDrop(LDrop* instr) { __ Drop(instr->count()); } |
3600 __ Drop(instr->count()); | |
3601 } | |
3602 | 3695 |
3603 | 3696 |
3604 void LCodeGen::DoThisFunction(LThisFunction* instr) { | 3697 void LCodeGen::DoThisFunction(LThisFunction* instr) { |
3605 Register result = ToRegister(instr->result()); | 3698 Register result = ToRegister(instr->result()); |
3606 __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 3699 __ LoadP(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
3607 } | 3700 } |
3608 | 3701 |
3609 | 3702 |
3610 void LCodeGen::DoContext(LContext* instr) { | 3703 void LCodeGen::DoContext(LContext* instr) { |
3611 // If there is a non-return use, the context must be moved to a register. | 3704 // If there is a non-return use, the context must be moved to a register. |
3612 Register result = ToRegister(instr->result()); | 3705 Register result = ToRegister(instr->result()); |
3613 if (info()->IsOptimizing()) { | 3706 if (info()->IsOptimizing()) { |
3614 __ ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 3707 __ LoadP(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
3615 } else { | 3708 } else { |
3616 // If there is no frame, the context must be in cp. | 3709 // If there is no frame, the context must be in cp. |
3617 DCHECK(result.is(cp)); | 3710 DCHECK(result.is(cp)); |
3618 } | 3711 } |
3619 } | 3712 } |
3620 | 3713 |
3621 | 3714 |
3622 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { | 3715 void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
3623 DCHECK(ToRegister(instr->context()).is(cp)); | 3716 DCHECK(ToRegister(instr->context()).is(cp)); |
3624 __ push(cp); // The context is the first argument. | 3717 __ push(cp); // The context is the first argument. |
3625 __ Move(scratch0(), instr->hydrogen()->pairs()); | 3718 __ Move(scratch0(), instr->hydrogen()->pairs()); |
3626 __ push(scratch0()); | 3719 __ push(scratch0()); |
3627 __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); | 3720 __ LoadSmiLiteral(scratch0(), Smi::FromInt(instr->hydrogen()->flags())); |
3628 __ push(scratch0()); | 3721 __ push(scratch0()); |
3629 CallRuntime(Runtime::kDeclareGlobals, 3, instr); | 3722 CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
3630 } | 3723 } |
3631 | 3724 |
3632 | 3725 |
3633 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, | 3726 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
3634 int formal_parameter_count, | 3727 int formal_parameter_count, int arity, |
3635 int arity, | 3728 LInstruction* instr, R4State r4_state) { |
3636 LInstruction* instr, | |
3637 R1State r1_state) { | |
3638 bool dont_adapt_arguments = | 3729 bool dont_adapt_arguments = |
3639 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; | 3730 formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
3640 bool can_invoke_directly = | 3731 bool can_invoke_directly = |
3641 dont_adapt_arguments || formal_parameter_count == arity; | 3732 dont_adapt_arguments || formal_parameter_count == arity; |
3642 | 3733 |
3643 LPointerMap* pointers = instr->pointer_map(); | 3734 LPointerMap* pointers = instr->pointer_map(); |
3644 | 3735 |
3645 if (can_invoke_directly) { | 3736 if (can_invoke_directly) { |
3646 if (r1_state == R1_UNINITIALIZED) { | 3737 if (r4_state == R4_UNINITIALIZED) { |
3647 __ Move(r1, function); | 3738 __ Move(r4, function); |
3648 } | 3739 } |
3649 | 3740 |
3650 // Change context. | 3741 // Change context. |
3651 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 3742 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
3652 | 3743 |
3653 // Set r0 to arguments count if adaption is not needed. Assumes that r0 | 3744 // Set r3 to arguments count if adaption is not needed. Assumes that r3 |
3654 // is available to write to at this point. | 3745 // is available to write to at this point. |
3655 if (dont_adapt_arguments) { | 3746 if (dont_adapt_arguments) { |
3656 __ mov(r0, Operand(arity)); | 3747 __ mov(r3, Operand(arity)); |
3657 } | 3748 } |
3658 | 3749 |
3659 // Invoke function. | 3750 // Invoke function. |
3660 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); | 3751 if (function.is_identical_to(info()->closure())) { |
3661 __ Call(ip); | 3752 __ CallSelf(); |
| 3753 } else { |
| 3754 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
| 3755 __ Call(ip); |
| 3756 } |
3662 | 3757 |
3663 // Set up deoptimization. | 3758 // Set up deoptimization. |
3664 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 3759 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
3665 } else { | 3760 } else { |
3666 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 3761 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
3667 ParameterCount count(arity); | 3762 ParameterCount count(arity); |
3668 ParameterCount expected(formal_parameter_count); | 3763 ParameterCount expected(formal_parameter_count); |
3669 __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); | 3764 __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); |
3670 } | 3765 } |
3671 } | 3766 } |
3672 | 3767 |
3673 | 3768 |
3674 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { | 3769 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
3675 DCHECK(instr->context() != NULL); | 3770 DCHECK(instr->context() != NULL); |
3676 DCHECK(ToRegister(instr->context()).is(cp)); | 3771 DCHECK(ToRegister(instr->context()).is(cp)); |
3677 Register input = ToRegister(instr->value()); | 3772 Register input = ToRegister(instr->value()); |
3678 Register result = ToRegister(instr->result()); | 3773 Register result = ToRegister(instr->result()); |
3679 Register scratch = scratch0(); | 3774 Register scratch = scratch0(); |
3680 | 3775 |
3681 // Deoptimize if not a heap number. | 3776 // Deoptimize if not a heap number. |
3682 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 3777 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
3683 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 3778 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
3684 __ cmp(scratch, Operand(ip)); | 3779 __ cmp(scratch, ip); |
3685 DeoptimizeIf(ne, instr->environment()); | 3780 DeoptimizeIf(ne, instr->environment()); |
3686 | 3781 |
3687 Label done; | 3782 Label done; |
3688 Register exponent = scratch0(); | 3783 Register exponent = scratch0(); |
3689 scratch = no_reg; | 3784 scratch = no_reg; |
3690 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); | 3785 __ lwz(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
3691 // Check the sign of the argument. If the argument is positive, just | 3786 // Check the sign of the argument. If the argument is positive, just |
3692 // return it. | 3787 // return it. |
3693 __ tst(exponent, Operand(HeapNumber::kSignMask)); | 3788 __ cmpwi(exponent, Operand::Zero()); |
3694 // Move the input to the result if necessary. | 3789 // Move the input to the result if necessary. |
3695 __ Move(result, input); | 3790 __ Move(result, input); |
3696 __ b(eq, &done); | 3791 __ bge(&done); |
3697 | 3792 |
3698 // Input is negative. Reverse its sign. | 3793 // Input is negative. Reverse its sign. |
3699 // Preserve the value of all registers. | 3794 // Preserve the value of all registers. |
3700 { | 3795 { |
3701 PushSafepointRegistersScope scope(this); | 3796 PushSafepointRegistersScope scope(this); |
3702 | 3797 |
3703 // Registers were saved at the safepoint, so we can use | 3798 // Registers were saved at the safepoint, so we can use |
3704 // many scratch registers. | 3799 // many scratch registers. |
3705 Register tmp1 = input.is(r1) ? r0 : r1; | 3800 Register tmp1 = input.is(r4) ? r3 : r4; |
3706 Register tmp2 = input.is(r2) ? r0 : r2; | 3801 Register tmp2 = input.is(r5) ? r3 : r5; |
3707 Register tmp3 = input.is(r3) ? r0 : r3; | 3802 Register tmp3 = input.is(r6) ? r3 : r6; |
3708 Register tmp4 = input.is(r4) ? r0 : r4; | 3803 Register tmp4 = input.is(r7) ? r3 : r7; |
3709 | 3804 |
3710 // exponent: floating point exponent value. | 3805 // exponent: floating point exponent value. |
3711 | 3806 |
3712 Label allocated, slow; | 3807 Label allocated, slow; |
3713 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); | 3808 __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
3714 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); | 3809 __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
3715 __ b(&allocated); | 3810 __ b(&allocated); |
3716 | 3811 |
3717 // Slow case: Call the runtime system to do the number allocation. | 3812 // Slow case: Call the runtime system to do the number allocation. |
3718 __ bind(&slow); | 3813 __ bind(&slow); |
3719 | 3814 |
3720 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, | 3815 CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, |
3721 instr->context()); | 3816 instr->context()); |
3722 // Set the pointer to the new heap number in tmp. | 3817 // Set the pointer to the new heap number in tmp. |
3723 if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); | 3818 if (!tmp1.is(r3)) __ mr(tmp1, r3); |
3724 // Restore input_reg after call to runtime. | 3819 // Restore input_reg after call to runtime. |
3725 __ LoadFromSafepointRegisterSlot(input, input); | 3820 __ LoadFromSafepointRegisterSlot(input, input); |
3726 __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); | 3821 __ lwz(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
3727 | 3822 |
3728 __ bind(&allocated); | 3823 __ bind(&allocated); |
3729 // exponent: floating point exponent value. | 3824 // exponent: floating point exponent value. |
3730 // tmp1: allocated heap number. | 3825 // tmp1: allocated heap number. |
3731 __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); | 3826 STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
3732 __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); | 3827 __ clrlwi(exponent, exponent, Operand(1)); // clear sign bit |
3733 __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); | 3828 __ stw(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
3734 __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); | 3829 __ lwz(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3830 __ stw(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
3735 | 3831 |
3736 __ StoreToSafepointRegisterSlot(tmp1, result); | 3832 __ StoreToSafepointRegisterSlot(tmp1, result); |
3737 } | 3833 } |
3738 | 3834 |
3739 __ bind(&done); | 3835 __ bind(&done); |
3740 } | 3836 } |
3741 | 3837 |
3742 | 3838 |
3743 void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { | 3839 void LCodeGen::EmitMathAbs(LMathAbs* instr) { |
3744 Register input = ToRegister(instr->value()); | 3840 Register input = ToRegister(instr->value()); |
3745 Register result = ToRegister(instr->result()); | 3841 Register result = ToRegister(instr->result()); |
3746 __ cmp(input, Operand::Zero()); | 3842 Label done; |
3747 __ Move(result, input, pl); | 3843 __ cmpi(input, Operand::Zero()); |
3748 // We can make rsb conditional because the previous cmp instruction | 3844 __ Move(result, input); |
3749 // will clear the V (overflow) flag and rsb won't set this flag | 3845 __ bge(&done); |
3750 // if input is positive. | 3846 __ li(r0, Operand::Zero()); // clear xer |
3751 __ rsb(result, input, Operand::Zero(), SetCC, mi); | 3847 __ mtxer(r0); |
| 3848 __ neg(result, result, SetOE, SetRC); |
3752 // Deoptimize on overflow. | 3849 // Deoptimize on overflow. |
3753 DeoptimizeIf(vs, instr->environment()); | 3850 DeoptimizeIf(overflow, instr->environment(), cr0); |
| 3851 __ bind(&done); |
3754 } | 3852 } |
3755 | 3853 |
3756 | 3854 |
| 3855 #if V8_TARGET_ARCH_PPC64 |
| 3856 void LCodeGen::EmitInteger32MathAbs(LMathAbs* instr) { |
| 3857 Register input = ToRegister(instr->value()); |
| 3858 Register result = ToRegister(instr->result()); |
| 3859 Label done; |
| 3860 __ cmpwi(input, Operand::Zero()); |
| 3861 __ Move(result, input); |
| 3862 __ bge(&done); |
| 3863 |
| 3864 // Deoptimize on overflow. |
| 3865 __ lis(r0, Operand(SIGN_EXT_IMM16(0x8000))); |
| 3866 __ cmpw(input, r0); |
| 3867 DeoptimizeIf(eq, instr->environment()); |
| 3868 |
| 3869 __ neg(result, result); |
| 3870 __ bind(&done); |
| 3871 } |
| 3872 #endif |
| 3873 |
| 3874 |
3757 void LCodeGen::DoMathAbs(LMathAbs* instr) { | 3875 void LCodeGen::DoMathAbs(LMathAbs* instr) { |
3758 // Class for deferred case. | 3876 // Class for deferred case. |
3759 class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { | 3877 class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
3760 public: | 3878 public: |
3761 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) | 3879 DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
3762 : LDeferredCode(codegen), instr_(instr) { } | 3880 : LDeferredCode(codegen), instr_(instr) {} |
3763 virtual void Generate() V8_OVERRIDE { | 3881 virtual void Generate() V8_OVERRIDE { |
3764 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); | 3882 codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
3765 } | 3883 } |
3766 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 3884 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 3885 |
3767 private: | 3886 private: |
3768 LMathAbs* instr_; | 3887 LMathAbs* instr_; |
3769 }; | 3888 }; |
3770 | 3889 |
3771 Representation r = instr->hydrogen()->value()->representation(); | 3890 Representation r = instr->hydrogen()->value()->representation(); |
3772 if (r.IsDouble()) { | 3891 if (r.IsDouble()) { |
3773 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3892 DoubleRegister input = ToDoubleRegister(instr->value()); |
3774 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3893 DoubleRegister result = ToDoubleRegister(instr->result()); |
3775 __ vabs(result, input); | 3894 __ fabs(result, input); |
| 3895 #if V8_TARGET_ARCH_PPC64 |
| 3896 } else if (r.IsInteger32()) { |
| 3897 EmitInteger32MathAbs(instr); |
| 3898 } else if (r.IsSmi()) { |
| 3899 #else |
3776 } else if (r.IsSmiOrInteger32()) { | 3900 } else if (r.IsSmiOrInteger32()) { |
3777 EmitIntegerMathAbs(instr); | 3901 #endif |
| 3902 EmitMathAbs(instr); |
3778 } else { | 3903 } else { |
3779 // Representation is tagged. | 3904 // Representation is tagged. |
3780 DeferredMathAbsTaggedHeapNumber* deferred = | 3905 DeferredMathAbsTaggedHeapNumber* deferred = |
3781 new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); | 3906 new (zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
3782 Register input = ToRegister(instr->value()); | 3907 Register input = ToRegister(instr->value()); |
3783 // Smi check. | 3908 // Smi check. |
3784 __ JumpIfNotSmi(input, deferred->entry()); | 3909 __ JumpIfNotSmi(input, deferred->entry()); |
3785 // If smi, handle it directly. | 3910 // If smi, handle it directly. |
3786 EmitIntegerMathAbs(instr); | 3911 EmitMathAbs(instr); |
3787 __ bind(deferred->exit()); | 3912 __ bind(deferred->exit()); |
3788 } | 3913 } |
3789 } | 3914 } |
3790 | 3915 |
3791 | 3916 |
3792 void LCodeGen::DoMathFloor(LMathFloor* instr) { | 3917 void LCodeGen::DoMathFloor(LMathFloor* instr) { |
3793 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3918 DoubleRegister input = ToDoubleRegister(instr->value()); |
3794 Register result = ToRegister(instr->result()); | 3919 Register result = ToRegister(instr->result()); |
3795 Register input_high = scratch0(); | 3920 Register input_high = scratch0(); |
| 3921 Register scratch = ip; |
3796 Label done, exact; | 3922 Label done, exact; |
3797 | 3923 |
3798 __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact); | 3924 __ TryInt32Floor(result, input, input_high, scratch, double_scratch0(), &done, |
| 3925 &exact); |
3799 DeoptimizeIf(al, instr->environment()); | 3926 DeoptimizeIf(al, instr->environment()); |
3800 | 3927 |
3801 __ bind(&exact); | 3928 __ bind(&exact); |
3802 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 3929 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
3803 // Test for -0. | 3930 // Test for -0. |
3804 __ cmp(result, Operand::Zero()); | 3931 __ cmpi(result, Operand::Zero()); |
3805 __ b(ne, &done); | 3932 __ bne(&done); |
3806 __ cmp(input_high, Operand::Zero()); | 3933 __ cmpwi(input_high, Operand::Zero()); |
3807 DeoptimizeIf(mi, instr->environment()); | 3934 DeoptimizeIf(lt, instr->environment()); |
3808 } | 3935 } |
3809 __ bind(&done); | 3936 __ bind(&done); |
3810 } | 3937 } |
3811 | 3938 |
3812 | 3939 |
3813 void LCodeGen::DoMathRound(LMathRound* instr) { | 3940 void LCodeGen::DoMathRound(LMathRound* instr) { |
3814 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3941 DoubleRegister input = ToDoubleRegister(instr->value()); |
3815 Register result = ToRegister(instr->result()); | 3942 Register result = ToRegister(instr->result()); |
3816 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp()); | 3943 DoubleRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
3817 DwVfpRegister input_plus_dot_five = double_scratch1; | 3944 DoubleRegister input_plus_dot_five = double_scratch1; |
3818 Register input_high = scratch0(); | 3945 Register scratch1 = scratch0(); |
3819 DwVfpRegister dot_five = double_scratch0(); | 3946 Register scratch2 = ip; |
| 3947 DoubleRegister dot_five = double_scratch0(); |
3820 Label convert, done; | 3948 Label convert, done; |
3821 | 3949 |
3822 __ Vmov(dot_five, 0.5, scratch0()); | 3950 __ LoadDoubleLiteral(dot_five, 0.5, r0); |
3823 __ vabs(double_scratch1, input); | 3951 __ fabs(double_scratch1, input); |
3824 __ VFPCompareAndSetFlags(double_scratch1, dot_five); | 3952 __ fcmpu(double_scratch1, dot_five); |
| 3953 DeoptimizeIf(unordered, instr->environment()); |
3825 // If input is in [-0.5, -0], the result is -0. | 3954 // If input is in [-0.5, -0], the result is -0. |
3826 // If input is in [+0, +0.5[, the result is +0. | 3955 // If input is in [+0, +0.5[, the result is +0. |
3827 // If the input is +0.5, the result is 1. | 3956 // If the input is +0.5, the result is 1. |
3828 __ b(hi, &convert); // Out of [-0.5, +0.5]. | 3957 __ bgt(&convert); // Out of [-0.5, +0.5]. |
3829 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 3958 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
3830 __ VmovHigh(input_high, input); | 3959 #if V8_TARGET_ARCH_PPC64 |
3831 __ cmp(input_high, Operand::Zero()); | 3960 __ MovDoubleToInt64(scratch1, input); |
3832 DeoptimizeIf(mi, instr->environment()); // [-0.5, -0]. | 3961 #else |
| 3962 __ MovDoubleHighToInt(scratch1, input); |
| 3963 #endif |
| 3964 __ cmpi(scratch1, Operand::Zero()); |
| 3965 DeoptimizeIf(lt, instr->environment()); // [-0.5, -0]. |
3833 } | 3966 } |
3834 __ VFPCompareAndSetFlags(input, dot_five); | 3967 Label return_zero; |
3835 __ mov(result, Operand(1), LeaveCC, eq); // +0.5. | 3968 __ fcmpu(input, dot_five); |
| 3969 __ bne(&return_zero); |
| 3970 __ li(result, Operand(1)); // +0.5. |
| 3971 __ b(&done); |
3836 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on | 3972 // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
3837 // flag kBailoutOnMinusZero. | 3973 // flag kBailoutOnMinusZero. |
3838 __ mov(result, Operand::Zero(), LeaveCC, ne); | 3974 __ bind(&return_zero); |
| 3975 __ li(result, Operand::Zero()); |
3839 __ b(&done); | 3976 __ b(&done); |
3840 | 3977 |
3841 __ bind(&convert); | 3978 __ bind(&convert); |
3842 __ vadd(input_plus_dot_five, input, dot_five); | 3979 __ fadd(input_plus_dot_five, input, dot_five); |
3843 // Reuse dot_five (double_scratch0) as we no longer need this value. | 3980 // Reuse dot_five (double_scratch0) as we no longer need this value. |
3844 __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(), | 3981 __ TryInt32Floor(result, input_plus_dot_five, scratch1, scratch2, |
3845 &done, &done); | 3982 double_scratch0(), &done, &done); |
3846 DeoptimizeIf(al, instr->environment()); | 3983 DeoptimizeIf(al, instr->environment()); |
3847 __ bind(&done); | 3984 __ bind(&done); |
3848 } | 3985 } |
3849 | 3986 |
3850 | 3987 |
3851 void LCodeGen::DoMathFround(LMathFround* instr) { | 3988 void LCodeGen::DoMathFround(LMathFround* instr) { |
3852 DwVfpRegister input_reg = ToDoubleRegister(instr->value()); | 3989 DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
3853 DwVfpRegister output_reg = ToDoubleRegister(instr->result()); | 3990 DoubleRegister output_reg = ToDoubleRegister(instr->result()); |
3854 LowDwVfpRegister scratch = double_scratch0(); | 3991 __ frsp(output_reg, input_reg); |
3855 __ vcvt_f32_f64(scratch.low(), input_reg); | |
3856 __ vcvt_f64_f32(output_reg, scratch.low()); | |
3857 } | 3992 } |
3858 | 3993 |
3859 | 3994 |
3860 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { | 3995 void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
3861 DwVfpRegister input = ToDoubleRegister(instr->value()); | 3996 DoubleRegister input = ToDoubleRegister(instr->value()); |
3862 DwVfpRegister result = ToDoubleRegister(instr->result()); | 3997 DoubleRegister result = ToDoubleRegister(instr->result()); |
3863 __ vsqrt(result, input); | 3998 __ fsqrt(result, input); |
3864 } | 3999 } |
3865 | 4000 |
3866 | 4001 |
3867 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { | 4002 void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
3868 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4003 DoubleRegister input = ToDoubleRegister(instr->value()); |
3869 DwVfpRegister result = ToDoubleRegister(instr->result()); | 4004 DoubleRegister result = ToDoubleRegister(instr->result()); |
3870 DwVfpRegister temp = double_scratch0(); | 4005 DoubleRegister temp = double_scratch0(); |
3871 | 4006 |
3872 // Note that according to ECMA-262 15.8.2.13: | 4007 // Note that according to ECMA-262 15.8.2.13: |
3873 // Math.pow(-Infinity, 0.5) == Infinity | 4008 // Math.pow(-Infinity, 0.5) == Infinity |
3874 // Math.sqrt(-Infinity) == NaN | 4009 // Math.sqrt(-Infinity) == NaN |
3875 Label done; | 4010 Label skip, done; |
3876 __ vmov(temp, -V8_INFINITY, scratch0()); | 4011 |
3877 __ VFPCompareAndSetFlags(input, temp); | 4012 __ LoadDoubleLiteral(temp, -V8_INFINITY, scratch0()); |
3878 __ vneg(result, temp, eq); | 4013 __ fcmpu(input, temp); |
3879 __ b(&done, eq); | 4014 __ bne(&skip); |
| 4015 __ fneg(result, temp); |
| 4016 __ b(&done); |
3880 | 4017 |
3881 // Add +0 to convert -0 to +0. | 4018 // Add +0 to convert -0 to +0. |
3882 __ vadd(result, input, kDoubleRegZero); | 4019 __ bind(&skip); |
3883 __ vsqrt(result, result); | 4020 __ fadd(result, input, kDoubleRegZero); |
| 4021 __ fsqrt(result, result); |
3884 __ bind(&done); | 4022 __ bind(&done); |
3885 } | 4023 } |
3886 | 4024 |
3887 | 4025 |
3888 void LCodeGen::DoPower(LPower* instr) { | 4026 void LCodeGen::DoPower(LPower* instr) { |
3889 Representation exponent_type = instr->hydrogen()->right()->representation(); | 4027 Representation exponent_type = instr->hydrogen()->right()->representation(); |
3890 // Having marked this as a call, we can use any registers. | 4028 // Having marked this as a call, we can use any registers. |
3891 // Just make sure that the input/output registers are the expected ones. | 4029 // Just make sure that the input/output registers are the expected ones. |
3892 DCHECK(!instr->right()->IsDoubleRegister() || | 4030 DCHECK(!instr->right()->IsDoubleRegister() || |
3893 ToDoubleRegister(instr->right()).is(d1)); | 4031 ToDoubleRegister(instr->right()).is(d2)); |
3894 DCHECK(!instr->right()->IsRegister() || | 4032 DCHECK(!instr->right()->IsRegister() || ToRegister(instr->right()).is(r5)); |
3895 ToRegister(instr->right()).is(r2)); | 4033 DCHECK(ToDoubleRegister(instr->left()).is(d1)); |
3896 DCHECK(ToDoubleRegister(instr->left()).is(d0)); | 4034 DCHECK(ToDoubleRegister(instr->result()).is(d3)); |
3897 DCHECK(ToDoubleRegister(instr->result()).is(d2)); | |
3898 | 4035 |
3899 if (exponent_type.IsSmi()) { | 4036 if (exponent_type.IsSmi()) { |
3900 MathPowStub stub(isolate(), MathPowStub::TAGGED); | 4037 MathPowStub stub(isolate(), MathPowStub::TAGGED); |
3901 __ CallStub(&stub); | 4038 __ CallStub(&stub); |
3902 } else if (exponent_type.IsTagged()) { | 4039 } else if (exponent_type.IsTagged()) { |
3903 Label no_deopt; | 4040 Label no_deopt; |
3904 __ JumpIfSmi(r2, &no_deopt); | 4041 __ JumpIfSmi(r5, &no_deopt); |
3905 __ ldr(r6, FieldMemOperand(r2, HeapObject::kMapOffset)); | 4042 __ LoadP(r10, FieldMemOperand(r5, HeapObject::kMapOffset)); |
3906 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 4043 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
3907 __ cmp(r6, Operand(ip)); | 4044 __ cmp(r10, ip); |
3908 DeoptimizeIf(ne, instr->environment()); | 4045 DeoptimizeIf(ne, instr->environment()); |
3909 __ bind(&no_deopt); | 4046 __ bind(&no_deopt); |
3910 MathPowStub stub(isolate(), MathPowStub::TAGGED); | 4047 MathPowStub stub(isolate(), MathPowStub::TAGGED); |
3911 __ CallStub(&stub); | 4048 __ CallStub(&stub); |
3912 } else if (exponent_type.IsInteger32()) { | 4049 } else if (exponent_type.IsInteger32()) { |
3913 MathPowStub stub(isolate(), MathPowStub::INTEGER); | 4050 MathPowStub stub(isolate(), MathPowStub::INTEGER); |
3914 __ CallStub(&stub); | 4051 __ CallStub(&stub); |
3915 } else { | 4052 } else { |
3916 DCHECK(exponent_type.IsDouble()); | 4053 DCHECK(exponent_type.IsDouble()); |
3917 MathPowStub stub(isolate(), MathPowStub::DOUBLE); | 4054 MathPowStub stub(isolate(), MathPowStub::DOUBLE); |
3918 __ CallStub(&stub); | 4055 __ CallStub(&stub); |
3919 } | 4056 } |
3920 } | 4057 } |
3921 | 4058 |
3922 | 4059 |
3923 void LCodeGen::DoMathExp(LMathExp* instr) { | 4060 void LCodeGen::DoMathExp(LMathExp* instr) { |
3924 DwVfpRegister input = ToDoubleRegister(instr->value()); | 4061 DoubleRegister input = ToDoubleRegister(instr->value()); |
3925 DwVfpRegister result = ToDoubleRegister(instr->result()); | 4062 DoubleRegister result = ToDoubleRegister(instr->result()); |
3926 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); | 4063 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
3927 DwVfpRegister double_scratch2 = double_scratch0(); | 4064 DoubleRegister double_scratch2 = double_scratch0(); |
3928 Register temp1 = ToRegister(instr->temp1()); | 4065 Register temp1 = ToRegister(instr->temp1()); |
3929 Register temp2 = ToRegister(instr->temp2()); | 4066 Register temp2 = ToRegister(instr->temp2()); |
3930 | 4067 |
3931 MathExpGenerator::EmitMathExp( | 4068 MathExpGenerator::EmitMathExp(masm(), input, result, double_scratch1, |
3932 masm(), input, result, double_scratch1, double_scratch2, | 4069 double_scratch2, temp1, temp2, scratch0()); |
3933 temp1, temp2, scratch0()); | |
3934 } | 4070 } |
3935 | 4071 |
3936 | 4072 |
3937 void LCodeGen::DoMathLog(LMathLog* instr) { | 4073 void LCodeGen::DoMathLog(LMathLog* instr) { |
3938 __ PrepareCallCFunction(0, 1, scratch0()); | 4074 __ PrepareCallCFunction(0, 1, scratch0()); |
3939 __ MovToFloatParameter(ToDoubleRegister(instr->value())); | 4075 __ MovToFloatParameter(ToDoubleRegister(instr->value())); |
3940 __ CallCFunction(ExternalReference::math_log_double_function(isolate()), | 4076 __ CallCFunction(ExternalReference::math_log_double_function(isolate()), 0, |
3941 0, 1); | 4077 1); |
3942 __ MovFromFloatResult(ToDoubleRegister(instr->result())); | 4078 __ MovFromFloatResult(ToDoubleRegister(instr->result())); |
3943 } | 4079 } |
3944 | 4080 |
3945 | 4081 |
3946 void LCodeGen::DoMathClz32(LMathClz32* instr) { | 4082 void LCodeGen::DoMathClz32(LMathClz32* instr) { |
3947 Register input = ToRegister(instr->value()); | 4083 Register input = ToRegister(instr->value()); |
3948 Register result = ToRegister(instr->result()); | 4084 Register result = ToRegister(instr->result()); |
3949 __ clz(result, input); | 4085 __ cntlzw_(result, input); |
3950 } | 4086 } |
3951 | 4087 |
3952 | 4088 |
3953 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { | 4089 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
3954 DCHECK(ToRegister(instr->context()).is(cp)); | 4090 DCHECK(ToRegister(instr->context()).is(cp)); |
3955 DCHECK(ToRegister(instr->function()).is(r1)); | 4091 DCHECK(ToRegister(instr->function()).is(r4)); |
3956 DCHECK(instr->HasPointerMap()); | 4092 DCHECK(instr->HasPointerMap()); |
3957 | 4093 |
3958 Handle<JSFunction> known_function = instr->hydrogen()->known_function(); | 4094 Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
3959 if (known_function.is_null()) { | 4095 if (known_function.is_null()) { |
3960 LPointerMap* pointers = instr->pointer_map(); | 4096 LPointerMap* pointers = instr->pointer_map(); |
3961 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 4097 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
3962 ParameterCount count(instr->arity()); | 4098 ParameterCount count(instr->arity()); |
3963 __ InvokeFunction(r1, count, CALL_FUNCTION, generator); | 4099 __ InvokeFunction(r4, count, CALL_FUNCTION, generator); |
3964 } else { | 4100 } else { |
3965 CallKnownFunction(known_function, | 4101 CallKnownFunction(known_function, |
3966 instr->hydrogen()->formal_parameter_count(), | 4102 instr->hydrogen()->formal_parameter_count(), |
3967 instr->arity(), | 4103 instr->arity(), instr, R4_CONTAINS_TARGET); |
3968 instr, | |
3969 R1_CONTAINS_TARGET); | |
3970 } | 4104 } |
3971 } | 4105 } |
3972 | 4106 |
3973 | 4107 |
3974 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { | 4108 void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { |
3975 DCHECK(ToRegister(instr->result()).is(r0)); | 4109 DCHECK(ToRegister(instr->result()).is(r3)); |
3976 | 4110 |
3977 LPointerMap* pointers = instr->pointer_map(); | 4111 LPointerMap* pointers = instr->pointer_map(); |
3978 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); | 4112 SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
3979 | 4113 |
3980 if (instr->target()->IsConstantOperand()) { | 4114 if (instr->target()->IsConstantOperand()) { |
3981 LConstantOperand* target = LConstantOperand::cast(instr->target()); | 4115 LConstantOperand* target = LConstantOperand::cast(instr->target()); |
3982 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); | 4116 Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
3983 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); | 4117 generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); |
3984 PlatformInterfaceDescriptor* call_descriptor = | 4118 __ Call(code, RelocInfo::CODE_TARGET); |
3985 instr->descriptor()->platform_specific_descriptor(); | |
3986 __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None(), al, | |
3987 call_descriptor->storage_mode()); | |
3988 } else { | 4119 } else { |
3989 DCHECK(instr->target()->IsRegister()); | 4120 DCHECK(instr->target()->IsRegister()); |
3990 Register target = ToRegister(instr->target()); | 4121 Register target = ToRegister(instr->target()); |
3991 generator.BeforeCall(__ CallSize(target)); | 4122 generator.BeforeCall(__ CallSize(target)); |
3992 // Make sure we don't emit any additional entries in the constant pool | 4123 __ addi(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
3993 // before the call to ensure that the CallCodeSize() calculated the correct | |
3994 // number of instructions for the constant pool load. | |
3995 { | |
3996 ConstantPoolUnavailableScope constant_pool_unavailable(masm_); | |
3997 __ add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); | |
3998 } | |
3999 __ Call(target); | 4124 __ Call(target); |
4000 } | 4125 } |
4001 generator.AfterCall(); | 4126 generator.AfterCall(); |
4002 } | 4127 } |
4003 | 4128 |
4004 | 4129 |
4005 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { | 4130 void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { |
4006 DCHECK(ToRegister(instr->function()).is(r1)); | 4131 DCHECK(ToRegister(instr->function()).is(r4)); |
4007 DCHECK(ToRegister(instr->result()).is(r0)); | 4132 DCHECK(ToRegister(instr->result()).is(r3)); |
4008 | 4133 |
4009 if (instr->hydrogen()->pass_argument_count()) { | 4134 if (instr->hydrogen()->pass_argument_count()) { |
4010 __ mov(r0, Operand(instr->arity())); | 4135 __ mov(r3, Operand(instr->arity())); |
4011 } | 4136 } |
4012 | 4137 |
4013 // Change context. | 4138 // Change context. |
4014 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 4139 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset)); |
4015 | 4140 |
4016 // Load the code entry address | 4141 // Load the code entry address |
4017 __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); | 4142 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); |
4018 __ Call(ip); | 4143 __ Call(ip); |
4019 | 4144 |
4020 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); | 4145 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
4021 } | 4146 } |
4022 | 4147 |
4023 | 4148 |
4024 void LCodeGen::DoCallFunction(LCallFunction* instr) { | 4149 void LCodeGen::DoCallFunction(LCallFunction* instr) { |
4025 DCHECK(ToRegister(instr->context()).is(cp)); | 4150 DCHECK(ToRegister(instr->context()).is(cp)); |
4026 DCHECK(ToRegister(instr->function()).is(r1)); | 4151 DCHECK(ToRegister(instr->function()).is(r4)); |
4027 DCHECK(ToRegister(instr->result()).is(r0)); | 4152 DCHECK(ToRegister(instr->result()).is(r3)); |
4028 | 4153 |
4029 int arity = instr->arity(); | 4154 int arity = instr->arity(); |
4030 CallFunctionStub stub(isolate(), arity, instr->hydrogen()->function_flags()); | 4155 CallFunctionStub stub(isolate(), arity, instr->hydrogen()->function_flags()); |
4031 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4156 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
4032 } | 4157 } |
4033 | 4158 |
4034 | 4159 |
4035 void LCodeGen::DoCallNew(LCallNew* instr) { | 4160 void LCodeGen::DoCallNew(LCallNew* instr) { |
4036 DCHECK(ToRegister(instr->context()).is(cp)); | 4161 DCHECK(ToRegister(instr->context()).is(cp)); |
4037 DCHECK(ToRegister(instr->constructor()).is(r1)); | 4162 DCHECK(ToRegister(instr->constructor()).is(r4)); |
4038 DCHECK(ToRegister(instr->result()).is(r0)); | 4163 DCHECK(ToRegister(instr->result()).is(r3)); |
4039 | 4164 |
4040 __ mov(r0, Operand(instr->arity())); | 4165 __ mov(r3, Operand(instr->arity())); |
4041 // No cell in r2 for construct type feedback in optimized code | 4166 // No cell in r5 for construct type feedback in optimized code |
4042 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); | 4167 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
4043 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); | 4168 CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); |
4044 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4169 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
4045 } | 4170 } |
4046 | 4171 |
4047 | 4172 |
4048 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { | 4173 void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
4049 DCHECK(ToRegister(instr->context()).is(cp)); | 4174 DCHECK(ToRegister(instr->context()).is(cp)); |
4050 DCHECK(ToRegister(instr->constructor()).is(r1)); | 4175 DCHECK(ToRegister(instr->constructor()).is(r4)); |
4051 DCHECK(ToRegister(instr->result()).is(r0)); | 4176 DCHECK(ToRegister(instr->result()).is(r3)); |
4052 | 4177 |
4053 __ mov(r0, Operand(instr->arity())); | 4178 __ mov(r3, Operand(instr->arity())); |
4054 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); | 4179 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
4055 ElementsKind kind = instr->hydrogen()->elements_kind(); | 4180 ElementsKind kind = instr->hydrogen()->elements_kind(); |
4056 AllocationSiteOverrideMode override_mode = | 4181 AllocationSiteOverrideMode override_mode = |
4057 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) | 4182 (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
4058 ? DISABLE_ALLOCATION_SITES | 4183 ? DISABLE_ALLOCATION_SITES |
4059 : DONT_OVERRIDE; | 4184 : DONT_OVERRIDE; |
4060 | 4185 |
4061 if (instr->arity() == 0) { | 4186 if (instr->arity() == 0) { |
4062 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); | 4187 ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); |
4063 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4188 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
4064 } else if (instr->arity() == 1) { | 4189 } else if (instr->arity() == 1) { |
4065 Label done; | 4190 Label done; |
4066 if (IsFastPackedElementsKind(kind)) { | 4191 if (IsFastPackedElementsKind(kind)) { |
4067 Label packed_case; | 4192 Label packed_case; |
4068 // We might need a change here | 4193 // We might need a change here |
4069 // look at the first argument | 4194 // look at the first argument |
4070 __ ldr(r5, MemOperand(sp, 0)); | 4195 __ LoadP(r8, MemOperand(sp, 0)); |
4071 __ cmp(r5, Operand::Zero()); | 4196 __ cmpi(r8, Operand::Zero()); |
4072 __ b(eq, &packed_case); | 4197 __ beq(&packed_case); |
4073 | 4198 |
4074 ElementsKind holey_kind = GetHoleyElementsKind(kind); | 4199 ElementsKind holey_kind = GetHoleyElementsKind(kind); |
4075 ArraySingleArgumentConstructorStub stub(isolate(), | 4200 ArraySingleArgumentConstructorStub stub(isolate(), holey_kind, |
4076 holey_kind, | |
4077 override_mode); | 4201 override_mode); |
4078 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4202 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
4079 __ jmp(&done); | 4203 __ b(&done); |
4080 __ bind(&packed_case); | 4204 __ bind(&packed_case); |
4081 } | 4205 } |
4082 | 4206 |
4083 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); | 4207 ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); |
4084 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4208 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
4085 __ bind(&done); | 4209 __ bind(&done); |
4086 } else { | 4210 } else { |
4087 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); | 4211 ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); |
4088 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); | 4212 CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr); |
4089 } | 4213 } |
4090 } | 4214 } |
4091 | 4215 |
4092 | 4216 |
4093 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { | 4217 void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
4094 CallRuntime(instr->function(), instr->arity(), instr); | 4218 CallRuntime(instr->function(), instr->arity(), instr); |
4095 } | 4219 } |
4096 | 4220 |
4097 | 4221 |
4098 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { | 4222 void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
4099 Register function = ToRegister(instr->function()); | 4223 Register function = ToRegister(instr->function()); |
4100 Register code_object = ToRegister(instr->code_object()); | 4224 Register code_object = ToRegister(instr->code_object()); |
4101 __ add(code_object, code_object, Operand(Code::kHeaderSize - kHeapObjectTag)); | 4225 __ addi(code_object, code_object, |
4102 __ str(code_object, | 4226 Operand(Code::kHeaderSize - kHeapObjectTag)); |
4103 FieldMemOperand(function, JSFunction::kCodeEntryOffset)); | 4227 __ StoreP(code_object, |
| 4228 FieldMemOperand(function, JSFunction::kCodeEntryOffset), r0); |
4104 } | 4229 } |
4105 | 4230 |
4106 | 4231 |
4107 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { | 4232 void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
4108 Register result = ToRegister(instr->result()); | 4233 Register result = ToRegister(instr->result()); |
4109 Register base = ToRegister(instr->base_object()); | 4234 Register base = ToRegister(instr->base_object()); |
4110 if (instr->offset()->IsConstantOperand()) { | 4235 if (instr->offset()->IsConstantOperand()) { |
4111 LConstantOperand* offset = LConstantOperand::cast(instr->offset()); | 4236 LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
4112 __ add(result, base, Operand(ToInteger32(offset))); | 4237 __ Add(result, base, ToInteger32(offset), r0); |
4113 } else { | 4238 } else { |
4114 Register offset = ToRegister(instr->offset()); | 4239 Register offset = ToRegister(instr->offset()); |
4115 __ add(result, base, offset); | 4240 __ add(result, base, offset); |
4116 } | 4241 } |
4117 } | 4242 } |
4118 | 4243 |
4119 | 4244 |
4120 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { | 4245 void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
| 4246 HStoreNamedField* hinstr = instr->hydrogen(); |
4121 Representation representation = instr->representation(); | 4247 Representation representation = instr->representation(); |
4122 | 4248 |
4123 Register object = ToRegister(instr->object()); | 4249 Register object = ToRegister(instr->object()); |
4124 Register scratch = scratch0(); | 4250 Register scratch = scratch0(); |
4125 HObjectAccess access = instr->hydrogen()->access(); | 4251 HObjectAccess access = hinstr->access(); |
4126 int offset = access.offset(); | 4252 int offset = access.offset(); |
4127 | 4253 |
4128 if (access.IsExternalMemory()) { | 4254 if (access.IsExternalMemory()) { |
4129 Register value = ToRegister(instr->value()); | 4255 Register value = ToRegister(instr->value()); |
4130 MemOperand operand = MemOperand(object, offset); | 4256 MemOperand operand = MemOperand(object, offset); |
4131 __ Store(value, operand, representation); | 4257 __ StoreRepresentation(value, operand, representation, r0); |
4132 return; | 4258 return; |
4133 } | 4259 } |
4134 | 4260 |
4135 __ AssertNotSmi(object); | 4261 __ AssertNotSmi(object); |
4136 | 4262 |
4137 DCHECK(!representation.IsSmi() || | 4263 #if V8_TARGET_ARCH_PPC64 |
4138 !instr->value()->IsConstantOperand() || | 4264 DCHECK(!representation.IsSmi() || !instr->value()->IsConstantOperand() || |
| 4265 IsInteger32(LConstantOperand::cast(instr->value()))); |
| 4266 #else |
| 4267 DCHECK(!representation.IsSmi() || !instr->value()->IsConstantOperand() || |
4139 IsSmi(LConstantOperand::cast(instr->value()))); | 4268 IsSmi(LConstantOperand::cast(instr->value()))); |
| 4269 #endif |
4140 if (representation.IsDouble()) { | 4270 if (representation.IsDouble()) { |
4141 DCHECK(access.IsInobject()); | 4271 DCHECK(access.IsInobject()); |
4142 DCHECK(!instr->hydrogen()->has_transition()); | 4272 DCHECK(!hinstr->has_transition()); |
4143 DCHECK(!instr->hydrogen()->NeedsWriteBarrier()); | 4273 DCHECK(!hinstr->NeedsWriteBarrier()); |
4144 DwVfpRegister value = ToDoubleRegister(instr->value()); | 4274 DoubleRegister value = ToDoubleRegister(instr->value()); |
4145 __ vstr(value, FieldMemOperand(object, offset)); | 4275 __ stfd(value, FieldMemOperand(object, offset)); |
4146 return; | 4276 return; |
4147 } | 4277 } |
4148 | 4278 |
4149 if (instr->hydrogen()->has_transition()) { | 4279 if (hinstr->has_transition()) { |
4150 Handle<Map> transition = instr->hydrogen()->transition_map(); | 4280 Handle<Map> transition = hinstr->transition_map(); |
4151 AddDeprecationDependency(transition); | 4281 AddDeprecationDependency(transition); |
4152 __ mov(scratch, Operand(transition)); | 4282 __ mov(scratch, Operand(transition)); |
4153 __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); | 4283 __ StoreP(scratch, FieldMemOperand(object, HeapObject::kMapOffset), r0); |
4154 if (instr->hydrogen()->NeedsWriteBarrierForMap()) { | 4284 if (hinstr->NeedsWriteBarrierForMap()) { |
4155 Register temp = ToRegister(instr->temp()); | 4285 Register temp = ToRegister(instr->temp()); |
4156 // Update the write barrier for the map field. | 4286 // Update the write barrier for the map field. |
4157 __ RecordWriteForMap(object, | 4287 __ RecordWriteForMap(object, scratch, temp, GetLinkRegisterState(), |
4158 scratch, | |
4159 temp, | |
4160 GetLinkRegisterState(), | |
4161 kSaveFPRegs); | 4288 kSaveFPRegs); |
4162 } | 4289 } |
4163 } | 4290 } |
4164 | 4291 |
4165 // Do the store. | 4292 // Do the store. |
4166 Register value = ToRegister(instr->value()); | 4293 Register value = ToRegister(instr->value()); |
| 4294 |
| 4295 #if V8_TARGET_ARCH_PPC64 |
| 4296 // 64-bit Smi optimization |
| 4297 if (representation.IsSmi() && |
| 4298 hinstr->value()->representation().IsInteger32()) { |
| 4299 DCHECK(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4300 // Store int value directly to upper half of the smi. |
| 4301 STATIC_ASSERT(kSmiTag == 0); |
| 4302 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 4303 #if V8_TARGET_LITTLE_ENDIAN |
| 4304 offset += kPointerSize / 2; |
| 4305 #endif |
| 4306 representation = Representation::Integer32(); |
| 4307 } |
| 4308 #endif |
| 4309 |
4167 if (access.IsInobject()) { | 4310 if (access.IsInobject()) { |
4168 MemOperand operand = FieldMemOperand(object, offset); | 4311 MemOperand operand = FieldMemOperand(object, offset); |
4169 __ Store(value, operand, representation); | 4312 __ StoreRepresentation(value, operand, representation, r0); |
4170 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4313 if (hinstr->NeedsWriteBarrier()) { |
4171 // Update the write barrier for the object for in-object properties. | 4314 // Update the write barrier for the object for in-object properties. |
4172 __ RecordWriteField(object, | 4315 __ RecordWriteField( |
4173 offset, | 4316 object, offset, value, scratch, GetLinkRegisterState(), kSaveFPRegs, |
4174 value, | 4317 EMIT_REMEMBERED_SET, hinstr->SmiCheckForWriteBarrier(), |
4175 scratch, | 4318 hinstr->PointersToHereCheckForValue()); |
4176 GetLinkRegisterState(), | |
4177 kSaveFPRegs, | |
4178 EMIT_REMEMBERED_SET, | |
4179 instr->hydrogen()->SmiCheckForWriteBarrier(), | |
4180 instr->hydrogen()->PointersToHereCheckForValue()); | |
4181 } | 4319 } |
4182 } else { | 4320 } else { |
4183 __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 4321 __ LoadP(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
4184 MemOperand operand = FieldMemOperand(scratch, offset); | 4322 MemOperand operand = FieldMemOperand(scratch, offset); |
4185 __ Store(value, operand, representation); | 4323 __ StoreRepresentation(value, operand, representation, r0); |
4186 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4324 if (hinstr->NeedsWriteBarrier()) { |
4187 // Update the write barrier for the properties array. | 4325 // Update the write barrier for the properties array. |
4188 // object is used as a scratch register. | 4326 // object is used as a scratch register. |
4189 __ RecordWriteField(scratch, | 4327 __ RecordWriteField( |
4190 offset, | 4328 scratch, offset, value, object, GetLinkRegisterState(), kSaveFPRegs, |
4191 value, | 4329 EMIT_REMEMBERED_SET, hinstr->SmiCheckForWriteBarrier(), |
4192 object, | 4330 hinstr->PointersToHereCheckForValue()); |
4193 GetLinkRegisterState(), | |
4194 kSaveFPRegs, | |
4195 EMIT_REMEMBERED_SET, | |
4196 instr->hydrogen()->SmiCheckForWriteBarrier(), | |
4197 instr->hydrogen()->PointersToHereCheckForValue()); | |
4198 } | 4331 } |
4199 } | 4332 } |
4200 } | 4333 } |
4201 | 4334 |
4202 | 4335 |
4203 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { | 4336 void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
4204 DCHECK(ToRegister(instr->context()).is(cp)); | 4337 DCHECK(ToRegister(instr->context()).is(cp)); |
4205 DCHECK(ToRegister(instr->object()).is(StoreIC::ReceiverRegister())); | 4338 DCHECK(ToRegister(instr->object()).is(StoreIC::ReceiverRegister())); |
4206 DCHECK(ToRegister(instr->value()).is(StoreIC::ValueRegister())); | 4339 DCHECK(ToRegister(instr->value()).is(StoreIC::ValueRegister())); |
4207 | 4340 |
4208 __ mov(StoreIC::NameRegister(), Operand(instr->name())); | 4341 __ mov(StoreIC::NameRegister(), Operand(instr->name())); |
4209 Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); | 4342 Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); |
4210 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 4343 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
4211 } | 4344 } |
4212 | 4345 |
4213 | 4346 |
4214 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { | 4347 void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
4215 Condition cc = instr->hydrogen()->allow_equality() ? hi : hs; | 4348 Representation representation = instr->hydrogen()->length()->representation(); |
4216 if (instr->index()->IsConstantOperand()) { | 4349 DCHECK(representation.Equals(instr->hydrogen()->index()->representation())); |
4217 Operand index = ToOperand(instr->index()); | 4350 DCHECK(representation.IsSmiOrInteger32()); |
| 4351 |
| 4352 Condition cc = instr->hydrogen()->allow_equality() ? lt : le; |
| 4353 if (instr->length()->IsConstantOperand()) { |
| 4354 int32_t length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 4355 Register index = ToRegister(instr->index()); |
| 4356 if (representation.IsSmi()) { |
| 4357 __ Cmpli(index, Operand(Smi::FromInt(length)), r0); |
| 4358 } else { |
| 4359 __ Cmplwi(index, Operand(length), r0); |
| 4360 } |
| 4361 cc = CommuteCondition(cc); |
| 4362 } else if (instr->index()->IsConstantOperand()) { |
| 4363 int32_t index = ToInteger32(LConstantOperand::cast(instr->index())); |
4218 Register length = ToRegister(instr->length()); | 4364 Register length = ToRegister(instr->length()); |
4219 __ cmp(length, index); | 4365 if (representation.IsSmi()) { |
4220 cc = CommuteCondition(cc); | 4366 __ Cmpli(length, Operand(Smi::FromInt(index)), r0); |
| 4367 } else { |
| 4368 __ Cmplwi(length, Operand(index), r0); |
| 4369 } |
4221 } else { | 4370 } else { |
4222 Register index = ToRegister(instr->index()); | 4371 Register index = ToRegister(instr->index()); |
4223 Operand length = ToOperand(instr->length()); | 4372 Register length = ToRegister(instr->length()); |
4224 __ cmp(index, length); | 4373 if (representation.IsSmi()) { |
| 4374 __ cmpl(length, index); |
| 4375 } else { |
| 4376 __ cmplw(length, index); |
| 4377 } |
4225 } | 4378 } |
4226 if (FLAG_debug_code && instr->hydrogen()->skip_check()) { | 4379 if (FLAG_debug_code && instr->hydrogen()->skip_check()) { |
4227 Label done; | 4380 Label done; |
4228 __ b(NegateCondition(cc), &done); | 4381 __ b(NegateCondition(cc), &done); |
4229 __ stop("eliminated bounds check failed"); | 4382 __ stop("eliminated bounds check failed"); |
4230 __ bind(&done); | 4383 __ bind(&done); |
4231 } else { | 4384 } else { |
4232 DeoptimizeIf(cc, instr->environment()); | 4385 DeoptimizeIf(cc, instr->environment()); |
4233 } | 4386 } |
4234 } | 4387 } |
4235 | 4388 |
4236 | 4389 |
4237 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { | 4390 void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
4238 Register external_pointer = ToRegister(instr->elements()); | 4391 Register external_pointer = ToRegister(instr->elements()); |
4239 Register key = no_reg; | 4392 Register key = no_reg; |
4240 ElementsKind elements_kind = instr->elements_kind(); | 4393 ElementsKind elements_kind = instr->elements_kind(); |
4241 bool key_is_constant = instr->key()->IsConstantOperand(); | 4394 bool key_is_constant = instr->key()->IsConstantOperand(); |
4242 int constant_key = 0; | 4395 int constant_key = 0; |
4243 if (key_is_constant) { | 4396 if (key_is_constant) { |
4244 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 4397 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
4245 if (constant_key & 0xF0000000) { | 4398 if (constant_key & 0xF0000000) { |
4246 Abort(kArrayIndexConstantValueTooBig); | 4399 Abort(kArrayIndexConstantValueTooBig); |
4247 } | 4400 } |
4248 } else { | 4401 } else { |
4249 key = ToRegister(instr->key()); | 4402 key = ToRegister(instr->key()); |
4250 } | 4403 } |
4251 int element_size_shift = ElementsKindToShiftSize(elements_kind); | 4404 int element_size_shift = ElementsKindToShiftSize(elements_kind); |
4252 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 4405 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
4253 ? (element_size_shift - kSmiTagSize) : element_size_shift; | |
4254 int base_offset = instr->base_offset(); | 4406 int base_offset = instr->base_offset(); |
4255 | 4407 |
4256 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 4408 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
4257 elements_kind == FLOAT32_ELEMENTS || | 4409 elements_kind == FLOAT32_ELEMENTS || |
4258 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || | 4410 elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
4259 elements_kind == FLOAT64_ELEMENTS) { | 4411 elements_kind == FLOAT64_ELEMENTS) { |
4260 Register address = scratch0(); | 4412 Register address = scratch0(); |
4261 DwVfpRegister value(ToDoubleRegister(instr->value())); | 4413 DoubleRegister value(ToDoubleRegister(instr->value())); |
4262 if (key_is_constant) { | 4414 if (key_is_constant) { |
4263 if (constant_key != 0) { | 4415 if (constant_key != 0) { |
4264 __ add(address, external_pointer, | 4416 __ Add(address, external_pointer, constant_key << element_size_shift, |
4265 Operand(constant_key << element_size_shift)); | 4417 r0); |
4266 } else { | 4418 } else { |
4267 address = external_pointer; | 4419 address = external_pointer; |
4268 } | 4420 } |
4269 } else { | 4421 } else { |
4270 __ add(address, external_pointer, Operand(key, LSL, shift_size)); | 4422 __ IndexToArrayOffset(r0, key, element_size_shift, key_is_smi); |
| 4423 __ add(address, external_pointer, r0); |
4271 } | 4424 } |
4272 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || | 4425 if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
4273 elements_kind == FLOAT32_ELEMENTS) { | 4426 elements_kind == FLOAT32_ELEMENTS) { |
4274 __ vcvt_f32_f64(double_scratch0().low(), value); | 4427 __ frsp(double_scratch0(), value); |
4275 __ vstr(double_scratch0().low(), address, base_offset); | 4428 __ stfs(double_scratch0(), MemOperand(address, base_offset)); |
4276 } else { // Storing doubles, not floats. | 4429 } else { // Storing doubles, not floats. |
4277 __ vstr(value, address, base_offset); | 4430 __ stfd(value, MemOperand(address, base_offset)); |
4278 } | 4431 } |
4279 } else { | 4432 } else { |
4280 Register value(ToRegister(instr->value())); | 4433 Register value(ToRegister(instr->value())); |
4281 MemOperand mem_operand = PrepareKeyedOperand( | 4434 MemOperand mem_operand = |
4282 key, external_pointer, key_is_constant, constant_key, | 4435 PrepareKeyedOperand(key, external_pointer, key_is_constant, key_is_smi, |
4283 element_size_shift, shift_size, | 4436 constant_key, element_size_shift, base_offset); |
4284 base_offset); | |
4285 switch (elements_kind) { | 4437 switch (elements_kind) { |
4286 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: | 4438 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
4287 case EXTERNAL_INT8_ELEMENTS: | 4439 case EXTERNAL_INT8_ELEMENTS: |
4288 case EXTERNAL_UINT8_ELEMENTS: | 4440 case EXTERNAL_UINT8_ELEMENTS: |
4289 case UINT8_ELEMENTS: | 4441 case UINT8_ELEMENTS: |
4290 case UINT8_CLAMPED_ELEMENTS: | 4442 case UINT8_CLAMPED_ELEMENTS: |
4291 case INT8_ELEMENTS: | 4443 case INT8_ELEMENTS: |
4292 __ strb(value, mem_operand); | 4444 if (key_is_constant) { |
| 4445 __ StoreByte(value, mem_operand, r0); |
| 4446 } else { |
| 4447 __ stbx(value, mem_operand); |
| 4448 } |
4293 break; | 4449 break; |
4294 case EXTERNAL_INT16_ELEMENTS: | 4450 case EXTERNAL_INT16_ELEMENTS: |
4295 case EXTERNAL_UINT16_ELEMENTS: | 4451 case EXTERNAL_UINT16_ELEMENTS: |
4296 case INT16_ELEMENTS: | 4452 case INT16_ELEMENTS: |
4297 case UINT16_ELEMENTS: | 4453 case UINT16_ELEMENTS: |
4298 __ strh(value, mem_operand); | 4454 if (key_is_constant) { |
| 4455 __ StoreHalfWord(value, mem_operand, r0); |
| 4456 } else { |
| 4457 __ sthx(value, mem_operand); |
| 4458 } |
4299 break; | 4459 break; |
4300 case EXTERNAL_INT32_ELEMENTS: | 4460 case EXTERNAL_INT32_ELEMENTS: |
4301 case EXTERNAL_UINT32_ELEMENTS: | 4461 case EXTERNAL_UINT32_ELEMENTS: |
4302 case INT32_ELEMENTS: | 4462 case INT32_ELEMENTS: |
4303 case UINT32_ELEMENTS: | 4463 case UINT32_ELEMENTS: |
4304 __ str(value, mem_operand); | 4464 if (key_is_constant) { |
| 4465 __ StoreWord(value, mem_operand, r0); |
| 4466 } else { |
| 4467 __ stwx(value, mem_operand); |
| 4468 } |
4305 break; | 4469 break; |
4306 case FLOAT32_ELEMENTS: | 4470 case FLOAT32_ELEMENTS: |
4307 case FLOAT64_ELEMENTS: | 4471 case FLOAT64_ELEMENTS: |
4308 case EXTERNAL_FLOAT32_ELEMENTS: | 4472 case EXTERNAL_FLOAT32_ELEMENTS: |
4309 case EXTERNAL_FLOAT64_ELEMENTS: | 4473 case EXTERNAL_FLOAT64_ELEMENTS: |
4310 case FAST_DOUBLE_ELEMENTS: | 4474 case FAST_DOUBLE_ELEMENTS: |
4311 case FAST_ELEMENTS: | 4475 case FAST_ELEMENTS: |
4312 case FAST_SMI_ELEMENTS: | 4476 case FAST_SMI_ELEMENTS: |
4313 case FAST_HOLEY_DOUBLE_ELEMENTS: | 4477 case FAST_HOLEY_DOUBLE_ELEMENTS: |
4314 case FAST_HOLEY_ELEMENTS: | 4478 case FAST_HOLEY_ELEMENTS: |
4315 case FAST_HOLEY_SMI_ELEMENTS: | 4479 case FAST_HOLEY_SMI_ELEMENTS: |
4316 case DICTIONARY_ELEMENTS: | 4480 case DICTIONARY_ELEMENTS: |
4317 case SLOPPY_ARGUMENTS_ELEMENTS: | 4481 case SLOPPY_ARGUMENTS_ELEMENTS: |
4318 UNREACHABLE(); | 4482 UNREACHABLE(); |
4319 break; | 4483 break; |
4320 } | 4484 } |
4321 } | 4485 } |
4322 } | 4486 } |
4323 | 4487 |
4324 | 4488 |
4325 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { | 4489 void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
4326 DwVfpRegister value = ToDoubleRegister(instr->value()); | 4490 DoubleRegister value = ToDoubleRegister(instr->value()); |
4327 Register elements = ToRegister(instr->elements()); | 4491 Register elements = ToRegister(instr->elements()); |
| 4492 Register key = no_reg; |
4328 Register scratch = scratch0(); | 4493 Register scratch = scratch0(); |
4329 DwVfpRegister double_scratch = double_scratch0(); | 4494 DoubleRegister double_scratch = double_scratch0(); |
4330 bool key_is_constant = instr->key()->IsConstantOperand(); | 4495 bool key_is_constant = instr->key()->IsConstantOperand(); |
4331 int base_offset = instr->base_offset(); | 4496 int constant_key = 0; |
4332 | 4497 |
4333 // Calculate the effective address of the slot in the array to store the | 4498 // Calculate the effective address of the slot in the array to store the |
4334 // double value. | 4499 // double value. |
4335 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); | |
4336 if (key_is_constant) { | 4500 if (key_is_constant) { |
4337 int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); | 4501 constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
4338 if (constant_key & 0xF0000000) { | 4502 if (constant_key & 0xF0000000) { |
4339 Abort(kArrayIndexConstantValueTooBig); | 4503 Abort(kArrayIndexConstantValueTooBig); |
4340 } | 4504 } |
4341 __ add(scratch, elements, | |
4342 Operand((constant_key << element_size_shift) + base_offset)); | |
4343 } else { | 4505 } else { |
4344 int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) | 4506 key = ToRegister(instr->key()); |
4345 ? (element_size_shift - kSmiTagSize) : element_size_shift; | 4507 } |
4346 __ add(scratch, elements, Operand(base_offset)); | 4508 int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
4347 __ add(scratch, scratch, | 4509 bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
4348 Operand(ToRegister(instr->key()), LSL, shift_size)); | 4510 int base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 4511 if (!key_is_constant) { |
| 4512 __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 4513 __ add(scratch, elements, scratch); |
| 4514 elements = scratch; |
| 4515 } |
| 4516 if (!is_int16(base_offset)) { |
| 4517 __ Add(scratch, elements, base_offset, r0); |
| 4518 base_offset = 0; |
| 4519 elements = scratch; |
4349 } | 4520 } |
4350 | 4521 |
4351 if (instr->NeedsCanonicalization()) { | 4522 if (instr->NeedsCanonicalization()) { |
4352 // Force a canonical NaN. | 4523 // Force a canonical NaN. |
4353 if (masm()->emit_debug_code()) { | 4524 __ CanonicalizeNaN(double_scratch, value); |
4354 __ vmrs(ip); | 4525 __ stfd(double_scratch, MemOperand(elements, base_offset)); |
4355 __ tst(ip, Operand(kVFPDefaultNaNModeControlBit)); | |
4356 __ Assert(ne, kDefaultNaNModeNotSet); | |
4357 } | |
4358 __ VFPCanonicalizeNaN(double_scratch, value); | |
4359 __ vstr(double_scratch, scratch, 0); | |
4360 } else { | 4526 } else { |
4361 __ vstr(value, scratch, 0); | 4527 __ stfd(value, MemOperand(elements, base_offset)); |
4362 } | 4528 } |
4363 } | 4529 } |
4364 | 4530 |
4365 | 4531 |
4366 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { | 4532 void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4533 HStoreKeyed* hinstr = instr->hydrogen(); |
4367 Register value = ToRegister(instr->value()); | 4534 Register value = ToRegister(instr->value()); |
4368 Register elements = ToRegister(instr->elements()); | 4535 Register elements = ToRegister(instr->elements()); |
4369 Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) | 4536 Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
4370 : no_reg; | |
4371 Register scratch = scratch0(); | 4537 Register scratch = scratch0(); |
4372 Register store_base = scratch; | 4538 Register store_base = scratch; |
4373 int offset = instr->base_offset(); | 4539 int offset = instr->base_offset(); |
4374 | 4540 |
4375 // Do the store. | 4541 // Do the store. |
4376 if (instr->key()->IsConstantOperand()) { | 4542 if (instr->key()->IsConstantOperand()) { |
4377 DCHECK(!instr->hydrogen()->NeedsWriteBarrier()); | 4543 DCHECK(!hinstr->NeedsWriteBarrier()); |
4378 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); | 4544 LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
4379 offset += ToInteger32(const_operand) * kPointerSize; | 4545 offset += ToInteger32(const_operand) * kPointerSize; |
4380 store_base = elements; | 4546 store_base = elements; |
4381 } else { | 4547 } else { |
4382 // Even though the HLoadKeyed instruction forces the input | 4548 // Even though the HLoadKeyed instruction forces the input |
4383 // representation for the key to be an integer, the input gets replaced | 4549 // representation for the key to be an integer, the input gets replaced |
4384 // during bound check elimination with the index argument to the bounds | 4550 // during bound check elimination with the index argument to the bounds |
4385 // check, which can be tagged, so that case must be handled here, too. | 4551 // check, which can be tagged, so that case must be handled here, too. |
4386 if (instr->hydrogen()->key()->representation().IsSmi()) { | 4552 if (hinstr->key()->representation().IsSmi()) { |
4387 __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); | 4553 __ SmiToPtrArrayOffset(scratch, key); |
4388 } else { | 4554 } else { |
4389 __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); | 4555 __ ShiftLeftImm(scratch, key, Operand(kPointerSizeLog2)); |
4390 } | 4556 } |
| 4557 __ add(scratch, elements, scratch); |
4391 } | 4558 } |
4392 __ str(value, MemOperand(store_base, offset)); | |
4393 | 4559 |
4394 if (instr->hydrogen()->NeedsWriteBarrier()) { | 4560 Representation representation = hinstr->value()->representation(); |
4395 SmiCheck check_needed = | 4561 |
4396 instr->hydrogen()->value()->type().IsHeapObject() | 4562 #if V8_TARGET_ARCH_PPC64 |
4397 ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; | 4563 // 64-bit Smi optimization |
| 4564 if (representation.IsInteger32()) { |
| 4565 DCHECK(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4566 DCHECK(hinstr->elements_kind() == FAST_SMI_ELEMENTS); |
| 4567 // Store int value directly to upper half of the smi. |
| 4568 STATIC_ASSERT(kSmiTag == 0); |
| 4569 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32); |
| 4570 #if V8_TARGET_LITTLE_ENDIAN |
| 4571 offset += kPointerSize / 2; |
| 4572 #endif |
| 4573 } |
| 4574 #endif |
| 4575 |
| 4576 __ StoreRepresentation(value, MemOperand(store_base, offset), representation, |
| 4577 r0); |
| 4578 |
| 4579 if (hinstr->NeedsWriteBarrier()) { |
| 4580 SmiCheck check_needed = hinstr->value()->type().IsHeapObject() |
| 4581 ? OMIT_SMI_CHECK |
| 4582 : INLINE_SMI_CHECK; |
4398 // Compute address of modified element and store it into key register. | 4583 // Compute address of modified element and store it into key register. |
4399 __ add(key, store_base, Operand(offset)); | 4584 __ Add(key, store_base, offset, r0); |
4400 __ RecordWrite(elements, | 4585 __ RecordWrite(elements, key, value, GetLinkRegisterState(), kSaveFPRegs, |
4401 key, | 4586 EMIT_REMEMBERED_SET, check_needed, |
4402 value, | 4587 hinstr->PointersToHereCheckForValue()); |
4403 GetLinkRegisterState(), | |
4404 kSaveFPRegs, | |
4405 EMIT_REMEMBERED_SET, | |
4406 check_needed, | |
4407 instr->hydrogen()->PointersToHereCheckForValue()); | |
4408 } | 4588 } |
4409 } | 4589 } |
4410 | 4590 |
4411 | 4591 |
4412 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { | 4592 void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
4413 // By cases: external, fast double | 4593 // By cases: external, fast double |
4414 if (instr->is_typed_elements()) { | 4594 if (instr->is_typed_elements()) { |
4415 DoStoreKeyedExternalArray(instr); | 4595 DoStoreKeyedExternalArray(instr); |
4416 } else if (instr->hydrogen()->value()->representation().IsDouble()) { | 4596 } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
4417 DoStoreKeyedFixedDoubleArray(instr); | 4597 DoStoreKeyedFixedDoubleArray(instr); |
4418 } else { | 4598 } else { |
4419 DoStoreKeyedFixedArray(instr); | 4599 DoStoreKeyedFixedArray(instr); |
4420 } | 4600 } |
4421 } | 4601 } |
4422 | 4602 |
4423 | 4603 |
4424 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { | 4604 void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
4425 DCHECK(ToRegister(instr->context()).is(cp)); | 4605 DCHECK(ToRegister(instr->context()).is(cp)); |
4426 DCHECK(ToRegister(instr->object()).is(KeyedStoreIC::ReceiverRegister())); | 4606 DCHECK(ToRegister(instr->object()).is(KeyedStoreIC::ReceiverRegister())); |
4427 DCHECK(ToRegister(instr->key()).is(KeyedStoreIC::NameRegister())); | 4607 DCHECK(ToRegister(instr->key()).is(KeyedStoreIC::NameRegister())); |
4428 DCHECK(ToRegister(instr->value()).is(KeyedStoreIC::ValueRegister())); | 4608 DCHECK(ToRegister(instr->value()).is(KeyedStoreIC::ValueRegister())); |
4429 | 4609 |
4430 Handle<Code> ic = instr->strict_mode() == STRICT | 4610 Handle<Code> ic = |
4431 ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() | 4611 (instr->strict_mode() == STRICT) |
4432 : isolate()->builtins()->KeyedStoreIC_Initialize(); | 4612 ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
4433 CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); | 4613 : isolate()->builtins()->KeyedStoreIC_Initialize(); |
| 4614 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
4434 } | 4615 } |
4435 | 4616 |
4436 | 4617 |
4437 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { | 4618 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
4438 Register object_reg = ToRegister(instr->object()); | 4619 Register object_reg = ToRegister(instr->object()); |
4439 Register scratch = scratch0(); | 4620 Register scratch = scratch0(); |
4440 | 4621 |
4441 Handle<Map> from_map = instr->original_map(); | 4622 Handle<Map> from_map = instr->original_map(); |
4442 Handle<Map> to_map = instr->transitioned_map(); | 4623 Handle<Map> to_map = instr->transitioned_map(); |
4443 ElementsKind from_kind = instr->from_kind(); | 4624 ElementsKind from_kind = instr->from_kind(); |
4444 ElementsKind to_kind = instr->to_kind(); | 4625 ElementsKind to_kind = instr->to_kind(); |
4445 | 4626 |
4446 Label not_applicable; | 4627 Label not_applicable; |
4447 __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); | 4628 __ LoadP(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
4448 __ cmp(scratch, Operand(from_map)); | 4629 __ Cmpi(scratch, Operand(from_map), r0); |
4449 __ b(ne, ¬_applicable); | 4630 __ bne(¬_applicable); |
4450 | 4631 |
4451 if (IsSimpleMapChangeTransition(from_kind, to_kind)) { | 4632 if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
4452 Register new_map_reg = ToRegister(instr->new_map_temp()); | 4633 Register new_map_reg = ToRegister(instr->new_map_temp()); |
4453 __ mov(new_map_reg, Operand(to_map)); | 4634 __ mov(new_map_reg, Operand(to_map)); |
4454 __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); | 4635 __ StoreP(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset), |
| 4636 r0); |
4455 // Write barrier. | 4637 // Write barrier. |
4456 __ RecordWriteForMap(object_reg, | 4638 __ RecordWriteForMap(object_reg, new_map_reg, scratch, |
4457 new_map_reg, | 4639 GetLinkRegisterState(), kDontSaveFPRegs); |
4458 scratch, | |
4459 GetLinkRegisterState(), | |
4460 kDontSaveFPRegs); | |
4461 } else { | 4640 } else { |
4462 DCHECK(ToRegister(instr->context()).is(cp)); | 4641 DCHECK(ToRegister(instr->context()).is(cp)); |
4463 DCHECK(object_reg.is(r0)); | 4642 DCHECK(object_reg.is(r3)); |
4464 PushSafepointRegistersScope scope(this); | 4643 PushSafepointRegistersScope scope(this); |
4465 __ Move(r1, to_map); | 4644 __ Move(r4, to_map); |
4466 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; | 4645 bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; |
4467 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); | 4646 TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); |
4468 __ CallStub(&stub); | 4647 __ CallStub(&stub); |
4469 RecordSafepointWithRegisters( | 4648 RecordSafepointWithRegisters(instr->pointer_map(), 0, |
4470 instr->pointer_map(), 0, Safepoint::kLazyDeopt); | 4649 Safepoint::kLazyDeopt); |
4471 } | 4650 } |
4472 __ bind(¬_applicable); | 4651 __ bind(¬_applicable); |
4473 } | 4652 } |
4474 | 4653 |
4475 | 4654 |
4476 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { | 4655 void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
4477 Register object = ToRegister(instr->object()); | 4656 Register object = ToRegister(instr->object()); |
4478 Register temp = ToRegister(instr->temp()); | 4657 Register temp = ToRegister(instr->temp()); |
4479 Label no_memento_found; | 4658 Label no_memento_found; |
4480 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); | 4659 __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
4481 DeoptimizeIf(eq, instr->environment()); | 4660 DeoptimizeIf(eq, instr->environment()); |
4482 __ bind(&no_memento_found); | 4661 __ bind(&no_memento_found); |
4483 } | 4662 } |
4484 | 4663 |
4485 | 4664 |
4486 void LCodeGen::DoStringAdd(LStringAdd* instr) { | 4665 void LCodeGen::DoStringAdd(LStringAdd* instr) { |
4487 DCHECK(ToRegister(instr->context()).is(cp)); | 4666 DCHECK(ToRegister(instr->context()).is(cp)); |
4488 DCHECK(ToRegister(instr->left()).is(r1)); | 4667 DCHECK(ToRegister(instr->left()).is(r4)); |
4489 DCHECK(ToRegister(instr->right()).is(r0)); | 4668 DCHECK(ToRegister(instr->right()).is(r3)); |
4490 StringAddStub stub(isolate(), | 4669 StringAddStub stub(isolate(), instr->hydrogen()->flags(), |
4491 instr->hydrogen()->flags(), | |
4492 instr->hydrogen()->pretenure_flag()); | 4670 instr->hydrogen()->pretenure_flag()); |
4493 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4671 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
4494 } | 4672 } |
4495 | 4673 |
4496 | 4674 |
4497 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { | 4675 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
4498 class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { | 4676 class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
4499 public: | 4677 public: |
4500 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 4678 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
4501 : LDeferredCode(codegen), instr_(instr) { } | 4679 : LDeferredCode(codegen), instr_(instr) {} |
4502 virtual void Generate() V8_OVERRIDE { | 4680 virtual void Generate() V8_OVERRIDE { |
4503 codegen()->DoDeferredStringCharCodeAt(instr_); | 4681 codegen()->DoDeferredStringCharCodeAt(instr_); |
4504 } | 4682 } |
4505 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4683 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4684 |
4506 private: | 4685 private: |
4507 LStringCharCodeAt* instr_; | 4686 LStringCharCodeAt* instr_; |
4508 }; | 4687 }; |
4509 | 4688 |
4510 DeferredStringCharCodeAt* deferred = | 4689 DeferredStringCharCodeAt* deferred = |
4511 new(zone()) DeferredStringCharCodeAt(this, instr); | 4690 new (zone()) DeferredStringCharCodeAt(this, instr); |
4512 | 4691 |
4513 StringCharLoadGenerator::Generate(masm(), | 4692 StringCharLoadGenerator::Generate( |
4514 ToRegister(instr->string()), | 4693 masm(), ToRegister(instr->string()), ToRegister(instr->index()), |
4515 ToRegister(instr->index()), | 4694 ToRegister(instr->result()), deferred->entry()); |
4516 ToRegister(instr->result()), | |
4517 deferred->entry()); | |
4518 __ bind(deferred->exit()); | 4695 __ bind(deferred->exit()); |
4519 } | 4696 } |
4520 | 4697 |
4521 | 4698 |
4522 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | 4699 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
4523 Register string = ToRegister(instr->string()); | 4700 Register string = ToRegister(instr->string()); |
4524 Register result = ToRegister(instr->result()); | 4701 Register result = ToRegister(instr->result()); |
4525 Register scratch = scratch0(); | 4702 Register scratch = scratch0(); |
4526 | 4703 |
4527 // TODO(3095996): Get rid of this. For now, we need to make the | 4704 // TODO(3095996): Get rid of this. For now, we need to make the |
4528 // result register contain a valid pointer because it is already | 4705 // result register contain a valid pointer because it is already |
4529 // contained in the register pointer map. | 4706 // contained in the register pointer map. |
4530 __ mov(result, Operand::Zero()); | 4707 __ li(result, Operand::Zero()); |
4531 | 4708 |
4532 PushSafepointRegistersScope scope(this); | 4709 PushSafepointRegistersScope scope(this); |
4533 __ push(string); | 4710 __ push(string); |
4534 // Push the index as a smi. This is safe because of the checks in | 4711 // Push the index as a smi. This is safe because of the checks in |
4535 // DoStringCharCodeAt above. | 4712 // DoStringCharCodeAt above. |
4536 if (instr->index()->IsConstantOperand()) { | 4713 if (instr->index()->IsConstantOperand()) { |
4537 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 4714 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
4538 __ mov(scratch, Operand(Smi::FromInt(const_index))); | 4715 __ LoadSmiLiteral(scratch, Smi::FromInt(const_index)); |
4539 __ push(scratch); | 4716 __ push(scratch); |
4540 } else { | 4717 } else { |
4541 Register index = ToRegister(instr->index()); | 4718 Register index = ToRegister(instr->index()); |
4542 __ SmiTag(index); | 4719 __ SmiTag(index); |
4543 __ push(index); | 4720 __ push(index); |
4544 } | 4721 } |
4545 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, | 4722 CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, |
4546 instr->context()); | 4723 instr->context()); |
4547 __ AssertSmi(r0); | 4724 __ AssertSmi(r3); |
4548 __ SmiUntag(r0); | 4725 __ SmiUntag(r3); |
4549 __ StoreToSafepointRegisterSlot(r0, result); | 4726 __ StoreToSafepointRegisterSlot(r3, result); |
4550 } | 4727 } |
4551 | 4728 |
4552 | 4729 |
4553 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { | 4730 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
4554 class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { | 4731 class DeferredStringCharFromCode : public LDeferredCode { |
4555 public: | 4732 public: |
4556 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) | 4733 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
4557 : LDeferredCode(codegen), instr_(instr) { } | 4734 : LDeferredCode(codegen), instr_(instr) {} |
4558 virtual void Generate() V8_OVERRIDE { | 4735 virtual void Generate() V8_OVERRIDE { |
4559 codegen()->DoDeferredStringCharFromCode(instr_); | 4736 codegen()->DoDeferredStringCharFromCode(instr_); |
4560 } | 4737 } |
4561 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4738 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4739 |
4562 private: | 4740 private: |
4563 LStringCharFromCode* instr_; | 4741 LStringCharFromCode* instr_; |
4564 }; | 4742 }; |
4565 | 4743 |
4566 DeferredStringCharFromCode* deferred = | 4744 DeferredStringCharFromCode* deferred = |
4567 new(zone()) DeferredStringCharFromCode(this, instr); | 4745 new (zone()) DeferredStringCharFromCode(this, instr); |
4568 | 4746 |
4569 DCHECK(instr->hydrogen()->value()->representation().IsInteger32()); | 4747 DCHECK(instr->hydrogen()->value()->representation().IsInteger32()); |
4570 Register char_code = ToRegister(instr->char_code()); | 4748 Register char_code = ToRegister(instr->char_code()); |
4571 Register result = ToRegister(instr->result()); | 4749 Register result = ToRegister(instr->result()); |
4572 DCHECK(!char_code.is(result)); | 4750 DCHECK(!char_code.is(result)); |
4573 | 4751 |
4574 __ cmp(char_code, Operand(String::kMaxOneByteCharCode)); | 4752 __ cmpli(char_code, Operand(String::kMaxOneByteCharCode)); |
4575 __ b(hi, deferred->entry()); | 4753 __ bgt(deferred->entry()); |
4576 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); | 4754 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
4577 __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); | 4755 __ ShiftLeftImm(r0, char_code, Operand(kPointerSizeLog2)); |
4578 __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); | 4756 __ add(result, result, r0); |
| 4757 __ LoadP(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
4579 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 4758 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
4580 __ cmp(result, ip); | 4759 __ cmp(result, ip); |
4581 __ b(eq, deferred->entry()); | 4760 __ beq(deferred->entry()); |
4582 __ bind(deferred->exit()); | 4761 __ bind(deferred->exit()); |
4583 } | 4762 } |
4584 | 4763 |
4585 | 4764 |
4586 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { | 4765 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
4587 Register char_code = ToRegister(instr->char_code()); | 4766 Register char_code = ToRegister(instr->char_code()); |
4588 Register result = ToRegister(instr->result()); | 4767 Register result = ToRegister(instr->result()); |
4589 | 4768 |
4590 // TODO(3095996): Get rid of this. For now, we need to make the | 4769 // TODO(3095996): Get rid of this. For now, we need to make the |
4591 // result register contain a valid pointer because it is already | 4770 // result register contain a valid pointer because it is already |
4592 // contained in the register pointer map. | 4771 // contained in the register pointer map. |
4593 __ mov(result, Operand::Zero()); | 4772 __ li(result, Operand::Zero()); |
4594 | 4773 |
4595 PushSafepointRegistersScope scope(this); | 4774 PushSafepointRegistersScope scope(this); |
4596 __ SmiTag(char_code); | 4775 __ SmiTag(char_code); |
4597 __ push(char_code); | 4776 __ push(char_code); |
4598 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); | 4777 CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
4599 __ StoreToSafepointRegisterSlot(r0, result); | 4778 __ StoreToSafepointRegisterSlot(r3, result); |
4600 } | 4779 } |
4601 | 4780 |
4602 | 4781 |
4603 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | 4782 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
4604 LOperand* input = instr->value(); | 4783 LOperand* input = instr->value(); |
4605 DCHECK(input->IsRegister() || input->IsStackSlot()); | 4784 DCHECK(input->IsRegister() || input->IsStackSlot()); |
4606 LOperand* output = instr->result(); | 4785 LOperand* output = instr->result(); |
4607 DCHECK(output->IsDoubleRegister()); | 4786 DCHECK(output->IsDoubleRegister()); |
4608 SwVfpRegister single_scratch = double_scratch0().low(); | |
4609 if (input->IsStackSlot()) { | 4787 if (input->IsStackSlot()) { |
4610 Register scratch = scratch0(); | 4788 Register scratch = scratch0(); |
4611 __ ldr(scratch, ToMemOperand(input)); | 4789 __ LoadP(scratch, ToMemOperand(input)); |
4612 __ vmov(single_scratch, scratch); | 4790 __ ConvertIntToDouble(scratch, ToDoubleRegister(output)); |
4613 } else { | 4791 } else { |
4614 __ vmov(single_scratch, ToRegister(input)); | 4792 __ ConvertIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
4615 } | 4793 } |
4616 __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); | |
4617 } | 4794 } |
4618 | 4795 |
4619 | 4796 |
4620 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { | 4797 void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
4621 LOperand* input = instr->value(); | 4798 LOperand* input = instr->value(); |
4622 LOperand* output = instr->result(); | 4799 LOperand* output = instr->result(); |
4623 | 4800 __ ConvertUnsignedIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
4624 SwVfpRegister flt_scratch = double_scratch0().low(); | |
4625 __ vmov(flt_scratch, ToRegister(input)); | |
4626 __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch); | |
4627 } | 4801 } |
4628 | 4802 |
4629 | 4803 |
4630 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { | 4804 void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
4631 class DeferredNumberTagI V8_FINAL : public LDeferredCode { | 4805 class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
4632 public: | 4806 public: |
4633 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) | 4807 DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
4634 : LDeferredCode(codegen), instr_(instr) { } | 4808 : LDeferredCode(codegen), instr_(instr) {} |
4635 virtual void Generate() V8_OVERRIDE { | 4809 virtual void Generate() V8_OVERRIDE { |
4636 codegen()->DoDeferredNumberTagIU(instr_, | 4810 codegen()->DoDeferredNumberTagIU(instr_, instr_->value(), instr_->temp1(), |
4637 instr_->value(), | 4811 instr_->temp2(), SIGNED_INT32); |
4638 instr_->temp1(), | |
4639 instr_->temp2(), | |
4640 SIGNED_INT32); | |
4641 } | 4812 } |
4642 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4813 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4814 |
4643 private: | 4815 private: |
4644 LNumberTagI* instr_; | 4816 LNumberTagI* instr_; |
4645 }; | 4817 }; |
4646 | 4818 |
4647 Register src = ToRegister(instr->value()); | 4819 Register src = ToRegister(instr->value()); |
4648 Register dst = ToRegister(instr->result()); | 4820 Register dst = ToRegister(instr->result()); |
4649 | 4821 |
4650 DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); | 4822 DeferredNumberTagI* deferred = new (zone()) DeferredNumberTagI(this, instr); |
4651 __ SmiTag(dst, src, SetCC); | 4823 #if V8_TARGET_ARCH_PPC64 |
4652 __ b(vs, deferred->entry()); | 4824 __ SmiTag(dst, src); |
| 4825 #else |
| 4826 __ SmiTagCheckOverflow(dst, src, r0); |
| 4827 __ BranchOnOverflow(deferred->entry()); |
| 4828 #endif |
4653 __ bind(deferred->exit()); | 4829 __ bind(deferred->exit()); |
4654 } | 4830 } |
4655 | 4831 |
4656 | 4832 |
4657 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { | 4833 void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
4658 class DeferredNumberTagU V8_FINAL : public LDeferredCode { | 4834 class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
4659 public: | 4835 public: |
4660 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) | 4836 DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
4661 : LDeferredCode(codegen), instr_(instr) { } | 4837 : LDeferredCode(codegen), instr_(instr) {} |
4662 virtual void Generate() V8_OVERRIDE { | 4838 virtual void Generate() V8_OVERRIDE { |
4663 codegen()->DoDeferredNumberTagIU(instr_, | 4839 codegen()->DoDeferredNumberTagIU(instr_, instr_->value(), instr_->temp1(), |
4664 instr_->value(), | 4840 instr_->temp2(), UNSIGNED_INT32); |
4665 instr_->temp1(), | |
4666 instr_->temp2(), | |
4667 UNSIGNED_INT32); | |
4668 } | 4841 } |
4669 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4842 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4843 |
4670 private: | 4844 private: |
4671 LNumberTagU* instr_; | 4845 LNumberTagU* instr_; |
4672 }; | 4846 }; |
4673 | 4847 |
4674 Register input = ToRegister(instr->value()); | 4848 Register input = ToRegister(instr->value()); |
4675 Register result = ToRegister(instr->result()); | 4849 Register result = ToRegister(instr->result()); |
4676 | 4850 |
4677 DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); | 4851 DeferredNumberTagU* deferred = new (zone()) DeferredNumberTagU(this, instr); |
4678 __ cmp(input, Operand(Smi::kMaxValue)); | 4852 __ Cmpli(input, Operand(Smi::kMaxValue), r0); |
4679 __ b(hi, deferred->entry()); | 4853 __ bgt(deferred->entry()); |
4680 __ SmiTag(result, input); | 4854 __ SmiTag(result, input); |
4681 __ bind(deferred->exit()); | 4855 __ bind(deferred->exit()); |
4682 } | 4856 } |
4683 | 4857 |
4684 | 4858 |
4685 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, | 4859 void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, LOperand* value, |
4686 LOperand* value, | 4860 LOperand* temp1, LOperand* temp2, |
4687 LOperand* temp1, | |
4688 LOperand* temp2, | |
4689 IntegerSignedness signedness) { | 4861 IntegerSignedness signedness) { |
4690 Label done, slow; | 4862 Label done, slow; |
4691 Register src = ToRegister(value); | 4863 Register src = ToRegister(value); |
4692 Register dst = ToRegister(instr->result()); | 4864 Register dst = ToRegister(instr->result()); |
4693 Register tmp1 = scratch0(); | 4865 Register tmp1 = scratch0(); |
4694 Register tmp2 = ToRegister(temp1); | 4866 Register tmp2 = ToRegister(temp1); |
4695 Register tmp3 = ToRegister(temp2); | 4867 Register tmp3 = ToRegister(temp2); |
4696 LowDwVfpRegister dbl_scratch = double_scratch0(); | 4868 DoubleRegister dbl_scratch = double_scratch0(); |
4697 | 4869 |
4698 if (signedness == SIGNED_INT32) { | 4870 if (signedness == SIGNED_INT32) { |
4699 // There was overflow, so bits 30 and 31 of the original integer | 4871 // There was overflow, so bits 30 and 31 of the original integer |
4700 // disagree. Try to allocate a heap number in new space and store | 4872 // disagree. Try to allocate a heap number in new space and store |
4701 // the value in there. If that fails, call the runtime system. | 4873 // the value in there. If that fails, call the runtime system. |
4702 if (dst.is(src)) { | 4874 if (dst.is(src)) { |
4703 __ SmiUntag(src, dst); | 4875 __ SmiUntag(src, dst); |
4704 __ eor(src, src, Operand(0x80000000)); | 4876 __ xoris(src, src, Operand(HeapNumber::kSignMask >> 16)); |
4705 } | 4877 } |
4706 __ vmov(dbl_scratch.low(), src); | 4878 __ ConvertIntToDouble(src, dbl_scratch); |
4707 __ vcvt_f64_s32(dbl_scratch, dbl_scratch.low()); | |
4708 } else { | 4879 } else { |
4709 __ vmov(dbl_scratch.low(), src); | 4880 __ ConvertUnsignedIntToDouble(src, dbl_scratch); |
4710 __ vcvt_f64_u32(dbl_scratch, dbl_scratch.low()); | |
4711 } | 4881 } |
4712 | 4882 |
4713 if (FLAG_inline_new) { | 4883 if (FLAG_inline_new) { |
4714 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); | 4884 __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); |
4715 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow, DONT_TAG_RESULT); | 4885 __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow); |
4716 __ b(&done); | 4886 __ b(&done); |
4717 } | 4887 } |
4718 | 4888 |
4719 // Slow case: Call the runtime system to do the number allocation. | 4889 // Slow case: Call the runtime system to do the number allocation. |
4720 __ bind(&slow); | 4890 __ bind(&slow); |
4721 { | 4891 { |
4722 // TODO(3095996): Put a valid pointer value in the stack slot where the | 4892 // TODO(3095996): Put a valid pointer value in the stack slot where the |
4723 // result register is stored, as this register is in the pointer map, but | 4893 // result register is stored, as this register is in the pointer map, but |
4724 // contains an integer value. | 4894 // contains an integer value. |
4725 __ mov(dst, Operand::Zero()); | 4895 __ li(dst, Operand::Zero()); |
4726 | 4896 |
4727 // Preserve the value of all registers. | 4897 // Preserve the value of all registers. |
4728 PushSafepointRegistersScope scope(this); | 4898 PushSafepointRegistersScope scope(this); |
4729 | 4899 |
4730 // NumberTagI and NumberTagD use the context from the frame, rather than | 4900 // NumberTagI and NumberTagD use the context from the frame, rather than |
4731 // the environment's HContext or HInlinedContext value. | 4901 // the environment's HContext or HInlinedContext value. |
4732 // They only call Runtime::kAllocateHeapNumber. | 4902 // They only call Runtime::kAllocateHeapNumber. |
4733 // The corresponding HChange instructions are added in a phase that does | 4903 // The corresponding HChange instructions are added in a phase that does |
4734 // not have easy access to the local context. | 4904 // not have easy access to the local context. |
4735 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 4905 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
4736 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 4906 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
4737 RecordSafepointWithRegisters( | 4907 RecordSafepointWithRegisters(instr->pointer_map(), 0, |
4738 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | 4908 Safepoint::kNoLazyDeopt); |
4739 __ sub(r0, r0, Operand(kHeapObjectTag)); | 4909 __ StoreToSafepointRegisterSlot(r3, dst); |
4740 __ StoreToSafepointRegisterSlot(r0, dst); | |
4741 } | 4910 } |
4742 | 4911 |
4743 // Done. Put the value in dbl_scratch into the value of the allocated heap | 4912 // Done. Put the value in dbl_scratch into the value of the allocated heap |
4744 // number. | 4913 // number. |
4745 __ bind(&done); | 4914 __ bind(&done); |
4746 __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset); | 4915 __ stfd(dbl_scratch, FieldMemOperand(dst, HeapNumber::kValueOffset)); |
4747 __ add(dst, dst, Operand(kHeapObjectTag)); | |
4748 } | 4916 } |
4749 | 4917 |
4750 | 4918 |
4751 void LCodeGen::DoNumberTagD(LNumberTagD* instr) { | 4919 void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
4752 class DeferredNumberTagD V8_FINAL : public LDeferredCode { | 4920 class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
4753 public: | 4921 public: |
4754 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) | 4922 DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
4755 : LDeferredCode(codegen), instr_(instr) { } | 4923 : LDeferredCode(codegen), instr_(instr) {} |
4756 virtual void Generate() V8_OVERRIDE { | 4924 virtual void Generate() V8_OVERRIDE { |
4757 codegen()->DoDeferredNumberTagD(instr_); | 4925 codegen()->DoDeferredNumberTagD(instr_); |
4758 } | 4926 } |
4759 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 4927 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 4928 |
4760 private: | 4929 private: |
4761 LNumberTagD* instr_; | 4930 LNumberTagD* instr_; |
4762 }; | 4931 }; |
4763 | 4932 |
4764 DwVfpRegister input_reg = ToDoubleRegister(instr->value()); | 4933 DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
4765 Register scratch = scratch0(); | 4934 Register scratch = scratch0(); |
4766 Register reg = ToRegister(instr->result()); | 4935 Register reg = ToRegister(instr->result()); |
4767 Register temp1 = ToRegister(instr->temp()); | 4936 Register temp1 = ToRegister(instr->temp()); |
4768 Register temp2 = ToRegister(instr->temp2()); | 4937 Register temp2 = ToRegister(instr->temp2()); |
4769 | 4938 |
4770 DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); | 4939 DeferredNumberTagD* deferred = new (zone()) DeferredNumberTagD(this, instr); |
4771 if (FLAG_inline_new) { | 4940 if (FLAG_inline_new) { |
4772 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); | 4941 __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
4773 // We want the untagged address first for performance | 4942 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry()); |
4774 __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), | |
4775 DONT_TAG_RESULT); | |
4776 } else { | 4943 } else { |
4777 __ jmp(deferred->entry()); | 4944 __ b(deferred->entry()); |
4778 } | 4945 } |
4779 __ bind(deferred->exit()); | 4946 __ bind(deferred->exit()); |
4780 __ vstr(input_reg, reg, HeapNumber::kValueOffset); | 4947 __ stfd(input_reg, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
4781 // Now that we have finished with the object's real address tag it | |
4782 __ add(reg, reg, Operand(kHeapObjectTag)); | |
4783 } | 4948 } |
4784 | 4949 |
4785 | 4950 |
4786 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { | 4951 void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
4787 // TODO(3095996): Get rid of this. For now, we need to make the | 4952 // TODO(3095996): Get rid of this. For now, we need to make the |
4788 // result register contain a valid pointer because it is already | 4953 // result register contain a valid pointer because it is already |
4789 // contained in the register pointer map. | 4954 // contained in the register pointer map. |
4790 Register reg = ToRegister(instr->result()); | 4955 Register reg = ToRegister(instr->result()); |
4791 __ mov(reg, Operand::Zero()); | 4956 __ li(reg, Operand::Zero()); |
4792 | 4957 |
4793 PushSafepointRegistersScope scope(this); | 4958 PushSafepointRegistersScope scope(this); |
4794 // NumberTagI and NumberTagD use the context from the frame, rather than | 4959 // NumberTagI and NumberTagD use the context from the frame, rather than |
4795 // the environment's HContext or HInlinedContext value. | 4960 // the environment's HContext or HInlinedContext value. |
4796 // They only call Runtime::kAllocateHeapNumber. | 4961 // They only call Runtime::kAllocateHeapNumber. |
4797 // The corresponding HChange instructions are added in a phase that does | 4962 // The corresponding HChange instructions are added in a phase that does |
4798 // not have easy access to the local context. | 4963 // not have easy access to the local context. |
4799 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 4964 __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
4800 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 4965 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
4801 RecordSafepointWithRegisters( | 4966 RecordSafepointWithRegisters(instr->pointer_map(), 0, |
4802 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); | 4967 Safepoint::kNoLazyDeopt); |
4803 __ sub(r0, r0, Operand(kHeapObjectTag)); | 4968 __ StoreToSafepointRegisterSlot(r3, reg); |
4804 __ StoreToSafepointRegisterSlot(r0, reg); | |
4805 } | 4969 } |
4806 | 4970 |
4807 | 4971 |
4808 void LCodeGen::DoSmiTag(LSmiTag* instr) { | 4972 void LCodeGen::DoSmiTag(LSmiTag* instr) { |
4809 HChange* hchange = instr->hydrogen(); | 4973 HChange* hchange = instr->hydrogen(); |
4810 Register input = ToRegister(instr->value()); | 4974 Register input = ToRegister(instr->value()); |
4811 Register output = ToRegister(instr->result()); | 4975 Register output = ToRegister(instr->result()); |
4812 if (hchange->CheckFlag(HValue::kCanOverflow) && | 4976 if (hchange->CheckFlag(HValue::kCanOverflow) && |
4813 hchange->value()->CheckFlag(HValue::kUint32)) { | 4977 hchange->value()->CheckFlag(HValue::kUint32)) { |
4814 __ tst(input, Operand(0xc0000000)); | 4978 __ TestUnsignedSmiCandidate(input, r0); |
4815 DeoptimizeIf(ne, instr->environment()); | 4979 DeoptimizeIf(ne, instr->environment(), cr0); |
4816 } | 4980 } |
| 4981 #if !V8_TARGET_ARCH_PPC64 |
4817 if (hchange->CheckFlag(HValue::kCanOverflow) && | 4982 if (hchange->CheckFlag(HValue::kCanOverflow) && |
4818 !hchange->value()->CheckFlag(HValue::kUint32)) { | 4983 !hchange->value()->CheckFlag(HValue::kUint32)) { |
4819 __ SmiTag(output, input, SetCC); | 4984 __ SmiTagCheckOverflow(output, input, r0); |
4820 DeoptimizeIf(vs, instr->environment()); | 4985 DeoptimizeIf(lt, instr->environment(), cr0); |
4821 } else { | 4986 } else { |
| 4987 #endif |
4822 __ SmiTag(output, input); | 4988 __ SmiTag(output, input); |
| 4989 #if !V8_TARGET_ARCH_PPC64 |
4823 } | 4990 } |
| 4991 #endif |
4824 } | 4992 } |
4825 | 4993 |
4826 | 4994 |
4827 void LCodeGen::DoSmiUntag(LSmiUntag* instr) { | 4995 void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
| 4996 Register scratch = scratch0(); |
4828 Register input = ToRegister(instr->value()); | 4997 Register input = ToRegister(instr->value()); |
4829 Register result = ToRegister(instr->result()); | 4998 Register result = ToRegister(instr->result()); |
4830 if (instr->needs_check()) { | 4999 if (instr->needs_check()) { |
4831 STATIC_ASSERT(kHeapObjectTag == 1); | 5000 STATIC_ASSERT(kHeapObjectTag == 1); |
4832 // If the input is a HeapObject, SmiUntag will set the carry flag. | 5001 // If the input is a HeapObject, value of scratch won't be zero. |
4833 __ SmiUntag(result, input, SetCC); | 5002 __ andi(scratch, input, Operand(kHeapObjectTag)); |
4834 DeoptimizeIf(cs, instr->environment()); | 5003 __ SmiUntag(result, input); |
| 5004 DeoptimizeIf(ne, instr->environment(), cr0); |
4835 } else { | 5005 } else { |
4836 __ SmiUntag(result, input); | 5006 __ SmiUntag(result, input); |
4837 } | 5007 } |
4838 } | 5008 } |
4839 | 5009 |
4840 | 5010 |
4841 void LCodeGen::EmitNumberUntagD(Register input_reg, | 5011 void LCodeGen::EmitNumberUntagD(Register input_reg, DoubleRegister result_reg, |
4842 DwVfpRegister result_reg, | |
4843 bool can_convert_undefined_to_nan, | 5012 bool can_convert_undefined_to_nan, |
4844 bool deoptimize_on_minus_zero, | 5013 bool deoptimize_on_minus_zero, |
4845 LEnvironment* env, | 5014 LEnvironment* env, NumberUntagDMode mode) { |
4846 NumberUntagDMode mode) { | |
4847 Register scratch = scratch0(); | 5015 Register scratch = scratch0(); |
4848 SwVfpRegister flt_scratch = double_scratch0().low(); | |
4849 DCHECK(!result_reg.is(double_scratch0())); | 5016 DCHECK(!result_reg.is(double_scratch0())); |
| 5017 |
4850 Label convert, load_smi, done; | 5018 Label convert, load_smi, done; |
| 5019 |
4851 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { | 5020 if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
4852 // Smi check. | 5021 // Smi check. |
4853 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); | 5022 __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
| 5023 |
4854 // Heap number map check. | 5024 // Heap number map check. |
4855 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); | 5025 __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
4856 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 5026 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
4857 __ cmp(scratch, Operand(ip)); | 5027 __ cmp(scratch, ip); |
4858 if (can_convert_undefined_to_nan) { | 5028 if (can_convert_undefined_to_nan) { |
4859 __ b(ne, &convert); | 5029 __ bne(&convert); |
4860 } else { | 5030 } else { |
4861 DeoptimizeIf(ne, env); | 5031 DeoptimizeIf(ne, env); |
4862 } | 5032 } |
4863 // load heap number | 5033 // load heap number |
4864 __ vldr(result_reg, input_reg, HeapNumber::kValueOffset - kHeapObjectTag); | 5034 __ lfd(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
4865 if (deoptimize_on_minus_zero) { | 5035 if (deoptimize_on_minus_zero) { |
4866 __ VmovLow(scratch, result_reg); | 5036 #if V8_TARGET_ARCH_PPC64 |
4867 __ cmp(scratch, Operand::Zero()); | 5037 __ MovDoubleToInt64(scratch, result_reg); |
4868 __ b(ne, &done); | 5038 // rotate left by one for simple compare. |
4869 __ VmovHigh(scratch, result_reg); | 5039 __ rldicl(scratch, scratch, 1, 0); |
4870 __ cmp(scratch, Operand(HeapNumber::kSignMask)); | 5040 __ cmpi(scratch, Operand(1)); |
| 5041 #else |
| 5042 __ MovDoubleToInt64(scratch, ip, result_reg); |
| 5043 __ cmpi(ip, Operand::Zero()); |
| 5044 __ bne(&done); |
| 5045 __ Cmpi(scratch, Operand(HeapNumber::kSignMask), r0); |
| 5046 #endif |
4871 DeoptimizeIf(eq, env); | 5047 DeoptimizeIf(eq, env); |
4872 } | 5048 } |
4873 __ jmp(&done); | 5049 __ b(&done); |
4874 if (can_convert_undefined_to_nan) { | 5050 if (can_convert_undefined_to_nan) { |
4875 __ bind(&convert); | 5051 __ bind(&convert); |
4876 // Convert undefined (and hole) to NaN. | 5052 // Convert undefined (and hole) to NaN. |
4877 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5053 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
4878 __ cmp(input_reg, Operand(ip)); | 5054 __ cmp(input_reg, ip); |
4879 DeoptimizeIf(ne, env); | 5055 DeoptimizeIf(ne, env); |
4880 __ LoadRoot(scratch, Heap::kNanValueRootIndex); | 5056 __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
4881 __ vldr(result_reg, scratch, HeapNumber::kValueOffset - kHeapObjectTag); | 5057 __ lfd(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset)); |
4882 __ jmp(&done); | 5058 __ b(&done); |
4883 } | 5059 } |
4884 } else { | 5060 } else { |
4885 __ SmiUntag(scratch, input_reg); | 5061 __ SmiUntag(scratch, input_reg); |
4886 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI); | 5062 DCHECK(mode == NUMBER_CANDIDATE_IS_SMI); |
4887 } | 5063 } |
4888 // Smi to double register conversion | 5064 // Smi to double register conversion |
4889 __ bind(&load_smi); | 5065 __ bind(&load_smi); |
4890 // scratch: untagged value of input_reg | 5066 // scratch: untagged value of input_reg |
4891 __ vmov(flt_scratch, scratch); | 5067 __ ConvertIntToDouble(scratch, result_reg); |
4892 __ vcvt_f64_s32(result_reg, flt_scratch); | |
4893 __ bind(&done); | 5068 __ bind(&done); |
4894 } | 5069 } |
4895 | 5070 |
4896 | 5071 |
4897 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { | 5072 void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
4898 Register input_reg = ToRegister(instr->value()); | 5073 Register input_reg = ToRegister(instr->value()); |
4899 Register scratch1 = scratch0(); | 5074 Register scratch1 = scratch0(); |
4900 Register scratch2 = ToRegister(instr->temp()); | 5075 Register scratch2 = ToRegister(instr->temp()); |
4901 LowDwVfpRegister double_scratch = double_scratch0(); | 5076 DoubleRegister double_scratch = double_scratch0(); |
4902 DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp2()); | 5077 DoubleRegister double_scratch2 = ToDoubleRegister(instr->temp2()); |
4903 | 5078 |
4904 DCHECK(!scratch1.is(input_reg) && !scratch1.is(scratch2)); | 5079 DCHECK(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
4905 DCHECK(!scratch2.is(input_reg) && !scratch2.is(scratch1)); | 5080 DCHECK(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
4906 | 5081 |
4907 Label done; | 5082 Label done; |
4908 | 5083 |
4909 // The input was optimistically untagged; revert it. | |
4910 // The carry flag is set when we reach this deferred code as we just executed | |
4911 // SmiUntag(heap_object, SetCC) | |
4912 STATIC_ASSERT(kHeapObjectTag == 1); | |
4913 __ adc(scratch2, input_reg, Operand(input_reg)); | |
4914 | |
4915 // Heap number map check. | 5084 // Heap number map check. |
4916 __ ldr(scratch1, FieldMemOperand(scratch2, HeapObject::kMapOffset)); | 5085 __ LoadP(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
4917 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); | 5086 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
4918 __ cmp(scratch1, Operand(ip)); | 5087 __ cmp(scratch1, ip); |
4919 | 5088 |
4920 if (instr->truncating()) { | 5089 if (instr->truncating()) { |
4921 // Performs a truncating conversion of a floating point number as used by | 5090 // Performs a truncating conversion of a floating point number as used by |
4922 // the JS bitwise operations. | 5091 // the JS bitwise operations. |
4923 Label no_heap_number, check_bools, check_false; | 5092 Label no_heap_number, check_bools, check_false; |
4924 __ b(ne, &no_heap_number); | 5093 __ bne(&no_heap_number); |
| 5094 __ mr(scratch2, input_reg); |
4925 __ TruncateHeapNumberToI(input_reg, scratch2); | 5095 __ TruncateHeapNumberToI(input_reg, scratch2); |
4926 __ b(&done); | 5096 __ b(&done); |
4927 | 5097 |
4928 // Check for Oddballs. Undefined/False is converted to zero and True to one | 5098 // Check for Oddballs. Undefined/False is converted to zero and True to one |
4929 // for truncating conversions. | 5099 // for truncating conversions. |
4930 __ bind(&no_heap_number); | 5100 __ bind(&no_heap_number); |
4931 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5101 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
4932 __ cmp(scratch2, Operand(ip)); | 5102 __ cmp(input_reg, ip); |
4933 __ b(ne, &check_bools); | 5103 __ bne(&check_bools); |
4934 __ mov(input_reg, Operand::Zero()); | 5104 __ li(input_reg, Operand::Zero()); |
4935 __ b(&done); | 5105 __ b(&done); |
4936 | 5106 |
4937 __ bind(&check_bools); | 5107 __ bind(&check_bools); |
4938 __ LoadRoot(ip, Heap::kTrueValueRootIndex); | 5108 __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
4939 __ cmp(scratch2, Operand(ip)); | 5109 __ cmp(input_reg, ip); |
4940 __ b(ne, &check_false); | 5110 __ bne(&check_false); |
4941 __ mov(input_reg, Operand(1)); | 5111 __ li(input_reg, Operand(1)); |
4942 __ b(&done); | 5112 __ b(&done); |
4943 | 5113 |
4944 __ bind(&check_false); | 5114 __ bind(&check_false); |
4945 __ LoadRoot(ip, Heap::kFalseValueRootIndex); | 5115 __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
4946 __ cmp(scratch2, Operand(ip)); | 5116 __ cmp(input_reg, ip); |
4947 DeoptimizeIf(ne, instr->environment()); | 5117 DeoptimizeIf(ne, instr->environment()); |
4948 __ mov(input_reg, Operand::Zero()); | 5118 __ li(input_reg, Operand::Zero()); |
4949 __ b(&done); | |
4950 } else { | 5119 } else { |
4951 // Deoptimize if we don't have a heap number. | 5120 // Deoptimize if we don't have a heap number. |
4952 DeoptimizeIf(ne, instr->environment()); | 5121 DeoptimizeIf(ne, instr->environment()); |
4953 | 5122 |
4954 __ sub(ip, scratch2, Operand(kHeapObjectTag)); | 5123 __ lfd(double_scratch2, |
4955 __ vldr(double_scratch2, ip, HeapNumber::kValueOffset); | 5124 FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
4956 __ TryDoubleToInt32Exact(input_reg, double_scratch2, double_scratch); | 5125 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5126 // preserve heap number pointer in scratch2 for minus zero check below |
| 5127 __ mr(scratch2, input_reg); |
| 5128 } |
| 5129 __ TryDoubleToInt32Exact(input_reg, double_scratch2, scratch1, |
| 5130 double_scratch); |
4957 DeoptimizeIf(ne, instr->environment()); | 5131 DeoptimizeIf(ne, instr->environment()); |
4958 | 5132 |
4959 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5133 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
4960 __ cmp(input_reg, Operand::Zero()); | 5134 __ cmpi(input_reg, Operand::Zero()); |
4961 __ b(ne, &done); | 5135 __ bne(&done); |
4962 __ VmovHigh(scratch1, double_scratch2); | 5136 __ lwz(scratch1, |
4963 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5137 FieldMemOperand(scratch2, HeapNumber::kValueOffset + |
4964 DeoptimizeIf(ne, instr->environment()); | 5138 Register::kExponentOffset)); |
| 5139 __ cmpwi(scratch1, Operand::Zero()); |
| 5140 DeoptimizeIf(lt, instr->environment()); |
4965 } | 5141 } |
4966 } | 5142 } |
4967 __ bind(&done); | 5143 __ bind(&done); |
4968 } | 5144 } |
4969 | 5145 |
4970 | 5146 |
4971 void LCodeGen::DoTaggedToI(LTaggedToI* instr) { | 5147 void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
4972 class DeferredTaggedToI V8_FINAL : public LDeferredCode { | 5148 class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
4973 public: | 5149 public: |
4974 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) | 5150 DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
4975 : LDeferredCode(codegen), instr_(instr) { } | 5151 : LDeferredCode(codegen), instr_(instr) {} |
4976 virtual void Generate() V8_OVERRIDE { | 5152 virtual void Generate() V8_OVERRIDE { |
4977 codegen()->DoDeferredTaggedToI(instr_); | 5153 codegen()->DoDeferredTaggedToI(instr_); |
4978 } | 5154 } |
4979 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 5155 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5156 |
4980 private: | 5157 private: |
4981 LTaggedToI* instr_; | 5158 LTaggedToI* instr_; |
4982 }; | 5159 }; |
4983 | 5160 |
4984 LOperand* input = instr->value(); | 5161 LOperand* input = instr->value(); |
4985 DCHECK(input->IsRegister()); | 5162 DCHECK(input->IsRegister()); |
4986 DCHECK(input->Equals(instr->result())); | 5163 DCHECK(input->Equals(instr->result())); |
4987 | 5164 |
4988 Register input_reg = ToRegister(input); | 5165 Register input_reg = ToRegister(input); |
4989 | 5166 |
4990 if (instr->hydrogen()->value()->representation().IsSmi()) { | 5167 if (instr->hydrogen()->value()->representation().IsSmi()) { |
4991 __ SmiUntag(input_reg); | 5168 __ SmiUntag(input_reg); |
4992 } else { | 5169 } else { |
4993 DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); | 5170 DeferredTaggedToI* deferred = new (zone()) DeferredTaggedToI(this, instr); |
4994 | 5171 |
4995 // Optimistically untag the input. | 5172 // Branch to deferred code if the input is a HeapObject. |
4996 // If the input is a HeapObject, SmiUntag will set the carry flag. | 5173 __ JumpIfNotSmi(input_reg, deferred->entry()); |
4997 __ SmiUntag(input_reg, SetCC); | 5174 |
4998 // Branch to deferred code if the input was tagged. | 5175 __ SmiUntag(input_reg); |
4999 // The deferred code will take care of restoring the tag. | |
5000 __ b(cs, deferred->entry()); | |
5001 __ bind(deferred->exit()); | 5176 __ bind(deferred->exit()); |
5002 } | 5177 } |
5003 } | 5178 } |
5004 | 5179 |
5005 | 5180 |
5006 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { | 5181 void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
5007 LOperand* input = instr->value(); | 5182 LOperand* input = instr->value(); |
5008 DCHECK(input->IsRegister()); | 5183 DCHECK(input->IsRegister()); |
5009 LOperand* result = instr->result(); | 5184 LOperand* result = instr->result(); |
5010 DCHECK(result->IsDoubleRegister()); | 5185 DCHECK(result->IsDoubleRegister()); |
5011 | 5186 |
5012 Register input_reg = ToRegister(input); | 5187 Register input_reg = ToRegister(input); |
5013 DwVfpRegister result_reg = ToDoubleRegister(result); | 5188 DoubleRegister result_reg = ToDoubleRegister(result); |
5014 | 5189 |
5015 HValue* value = instr->hydrogen()->value(); | 5190 HValue* value = instr->hydrogen()->value(); |
5016 NumberUntagDMode mode = value->representation().IsSmi() | 5191 NumberUntagDMode mode = value->representation().IsSmi() |
5017 ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; | 5192 ? NUMBER_CANDIDATE_IS_SMI |
| 5193 : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
5018 | 5194 |
5019 EmitNumberUntagD(input_reg, result_reg, | 5195 EmitNumberUntagD(input_reg, result_reg, |
5020 instr->hydrogen()->can_convert_undefined_to_nan(), | 5196 instr->hydrogen()->can_convert_undefined_to_nan(), |
5021 instr->hydrogen()->deoptimize_on_minus_zero(), | 5197 instr->hydrogen()->deoptimize_on_minus_zero(), |
5022 instr->environment(), | 5198 instr->environment(), mode); |
5023 mode); | |
5024 } | 5199 } |
5025 | 5200 |
5026 | 5201 |
5027 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { | 5202 void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
5028 Register result_reg = ToRegister(instr->result()); | 5203 Register result_reg = ToRegister(instr->result()); |
5029 Register scratch1 = scratch0(); | 5204 Register scratch1 = scratch0(); |
5030 DwVfpRegister double_input = ToDoubleRegister(instr->value()); | 5205 DoubleRegister double_input = ToDoubleRegister(instr->value()); |
5031 LowDwVfpRegister double_scratch = double_scratch0(); | 5206 DoubleRegister double_scratch = double_scratch0(); |
5032 | 5207 |
5033 if (instr->truncating()) { | 5208 if (instr->truncating()) { |
5034 __ TruncateDoubleToI(result_reg, double_input); | 5209 __ TruncateDoubleToI(result_reg, double_input); |
5035 } else { | 5210 } else { |
5036 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); | 5211 __ TryDoubleToInt32Exact(result_reg, double_input, scratch1, |
| 5212 double_scratch); |
5037 // Deoptimize if the input wasn't a int32 (inside a double). | 5213 // Deoptimize if the input wasn't a int32 (inside a double). |
5038 DeoptimizeIf(ne, instr->environment()); | 5214 DeoptimizeIf(ne, instr->environment()); |
5039 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5215 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
5040 Label done; | 5216 Label done; |
5041 __ cmp(result_reg, Operand::Zero()); | 5217 __ cmpi(result_reg, Operand::Zero()); |
5042 __ b(ne, &done); | 5218 __ bne(&done); |
5043 __ VmovHigh(scratch1, double_input); | 5219 #if V8_TARGET_ARCH_PPC64 |
5044 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5220 __ MovDoubleToInt64(scratch1, double_input); |
5045 DeoptimizeIf(ne, instr->environment()); | 5221 #else |
| 5222 __ MovDoubleHighToInt(scratch1, double_input); |
| 5223 #endif |
| 5224 __ cmpi(scratch1, Operand::Zero()); |
| 5225 DeoptimizeIf(lt, instr->environment()); |
5046 __ bind(&done); | 5226 __ bind(&done); |
5047 } | 5227 } |
5048 } | 5228 } |
5049 } | 5229 } |
5050 | 5230 |
5051 | 5231 |
5052 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { | 5232 void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
5053 Register result_reg = ToRegister(instr->result()); | 5233 Register result_reg = ToRegister(instr->result()); |
5054 Register scratch1 = scratch0(); | 5234 Register scratch1 = scratch0(); |
5055 DwVfpRegister double_input = ToDoubleRegister(instr->value()); | 5235 DoubleRegister double_input = ToDoubleRegister(instr->value()); |
5056 LowDwVfpRegister double_scratch = double_scratch0(); | 5236 DoubleRegister double_scratch = double_scratch0(); |
5057 | 5237 |
5058 if (instr->truncating()) { | 5238 if (instr->truncating()) { |
5059 __ TruncateDoubleToI(result_reg, double_input); | 5239 __ TruncateDoubleToI(result_reg, double_input); |
5060 } else { | 5240 } else { |
5061 __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); | 5241 __ TryDoubleToInt32Exact(result_reg, double_input, scratch1, |
| 5242 double_scratch); |
5062 // Deoptimize if the input wasn't a int32 (inside a double). | 5243 // Deoptimize if the input wasn't a int32 (inside a double). |
5063 DeoptimizeIf(ne, instr->environment()); | 5244 DeoptimizeIf(ne, instr->environment()); |
5064 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { | 5245 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
5065 Label done; | 5246 Label done; |
5066 __ cmp(result_reg, Operand::Zero()); | 5247 __ cmpi(result_reg, Operand::Zero()); |
5067 __ b(ne, &done); | 5248 __ bne(&done); |
5068 __ VmovHigh(scratch1, double_input); | 5249 #if V8_TARGET_ARCH_PPC64 |
5069 __ tst(scratch1, Operand(HeapNumber::kSignMask)); | 5250 __ MovDoubleToInt64(scratch1, double_input); |
5070 DeoptimizeIf(ne, instr->environment()); | 5251 #else |
| 5252 __ MovDoubleHighToInt(scratch1, double_input); |
| 5253 #endif |
| 5254 __ cmpi(scratch1, Operand::Zero()); |
| 5255 DeoptimizeIf(lt, instr->environment()); |
5071 __ bind(&done); | 5256 __ bind(&done); |
5072 } | 5257 } |
5073 } | 5258 } |
5074 __ SmiTag(result_reg, SetCC); | 5259 #if V8_TARGET_ARCH_PPC64 |
5075 DeoptimizeIf(vs, instr->environment()); | 5260 __ SmiTag(result_reg); |
| 5261 #else |
| 5262 __ SmiTagCheckOverflow(result_reg, r0); |
| 5263 DeoptimizeIf(lt, instr->environment(), cr0); |
| 5264 #endif |
5076 } | 5265 } |
5077 | 5266 |
5078 | 5267 |
5079 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { | 5268 void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
5080 LOperand* input = instr->value(); | 5269 LOperand* input = instr->value(); |
5081 __ SmiTst(ToRegister(input)); | 5270 __ TestIfSmi(ToRegister(input), r0); |
5082 DeoptimizeIf(ne, instr->environment()); | 5271 DeoptimizeIf(ne, instr->environment(), cr0); |
5083 } | 5272 } |
5084 | 5273 |
5085 | 5274 |
5086 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { | 5275 void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
5087 if (!instr->hydrogen()->value()->type().IsHeapObject()) { | 5276 if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
5088 LOperand* input = instr->value(); | 5277 LOperand* input = instr->value(); |
5089 __ SmiTst(ToRegister(input)); | 5278 __ TestIfSmi(ToRegister(input), r0); |
5090 DeoptimizeIf(eq, instr->environment()); | 5279 DeoptimizeIf(eq, instr->environment(), cr0); |
5091 } | 5280 } |
5092 } | 5281 } |
5093 | 5282 |
5094 | 5283 |
5095 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { | 5284 void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
5096 Register input = ToRegister(instr->value()); | 5285 Register input = ToRegister(instr->value()); |
5097 Register scratch = scratch0(); | 5286 Register scratch = scratch0(); |
5098 | 5287 |
5099 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5288 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
5100 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); | 5289 __ lbz(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
5101 | 5290 |
5102 if (instr->hydrogen()->is_interval_check()) { | 5291 if (instr->hydrogen()->is_interval_check()) { |
5103 InstanceType first; | 5292 InstanceType first; |
5104 InstanceType last; | 5293 InstanceType last; |
5105 instr->hydrogen()->GetCheckInterval(&first, &last); | 5294 instr->hydrogen()->GetCheckInterval(&first, &last); |
5106 | 5295 |
5107 __ cmp(scratch, Operand(first)); | 5296 __ cmpli(scratch, Operand(first)); |
5108 | 5297 |
5109 // If there is only one type in the interval check for equality. | 5298 // If there is only one type in the interval check for equality. |
5110 if (first == last) { | 5299 if (first == last) { |
5111 DeoptimizeIf(ne, instr->environment()); | 5300 DeoptimizeIf(ne, instr->environment()); |
5112 } else { | 5301 } else { |
5113 DeoptimizeIf(lo, instr->environment()); | 5302 DeoptimizeIf(lt, instr->environment()); |
5114 // Omit check for the last type. | 5303 // Omit check for the last type. |
5115 if (last != LAST_TYPE) { | 5304 if (last != LAST_TYPE) { |
5116 __ cmp(scratch, Operand(last)); | 5305 __ cmpli(scratch, Operand(last)); |
5117 DeoptimizeIf(hi, instr->environment()); | 5306 DeoptimizeIf(gt, instr->environment()); |
5118 } | 5307 } |
5119 } | 5308 } |
5120 } else { | 5309 } else { |
5121 uint8_t mask; | 5310 uint8_t mask; |
5122 uint8_t tag; | 5311 uint8_t tag; |
5123 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); | 5312 instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
5124 | 5313 |
5125 if (IsPowerOf2(mask)) { | 5314 if (IsPowerOf2(mask)) { |
5126 DCHECK(tag == 0 || IsPowerOf2(tag)); | 5315 DCHECK(tag == 0 || IsPowerOf2(tag)); |
5127 __ tst(scratch, Operand(mask)); | 5316 __ andi(r0, scratch, Operand(mask)); |
5128 DeoptimizeIf(tag == 0 ? ne : eq, instr->environment()); | 5317 DeoptimizeIf(tag == 0 ? ne : eq, instr->environment(), cr0); |
5129 } else { | 5318 } else { |
5130 __ and_(scratch, scratch, Operand(mask)); | 5319 __ andi(scratch, scratch, Operand(mask)); |
5131 __ cmp(scratch, Operand(tag)); | 5320 __ cmpi(scratch, Operand(tag)); |
5132 DeoptimizeIf(ne, instr->environment()); | 5321 DeoptimizeIf(ne, instr->environment()); |
5133 } | 5322 } |
5134 } | 5323 } |
5135 } | 5324 } |
5136 | 5325 |
5137 | 5326 |
5138 void LCodeGen::DoCheckValue(LCheckValue* instr) { | 5327 void LCodeGen::DoCheckValue(LCheckValue* instr) { |
5139 Register reg = ToRegister(instr->value()); | 5328 Register reg = ToRegister(instr->value()); |
5140 Handle<HeapObject> object = instr->hydrogen()->object().handle(); | 5329 Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
5141 AllowDeferredHandleDereference smi_check; | 5330 AllowDeferredHandleDereference smi_check; |
5142 if (isolate()->heap()->InNewSpace(*object)) { | 5331 if (isolate()->heap()->InNewSpace(*object)) { |
5143 Register reg = ToRegister(instr->value()); | 5332 Register reg = ToRegister(instr->value()); |
5144 Handle<Cell> cell = isolate()->factory()->NewCell(object); | 5333 Handle<Cell> cell = isolate()->factory()->NewCell(object); |
5145 __ mov(ip, Operand(Handle<Object>(cell))); | 5334 __ mov(ip, Operand(Handle<Object>(cell))); |
5146 __ ldr(ip, FieldMemOperand(ip, Cell::kValueOffset)); | 5335 __ LoadP(ip, FieldMemOperand(ip, Cell::kValueOffset)); |
5147 __ cmp(reg, ip); | 5336 __ cmp(reg, ip); |
5148 } else { | 5337 } else { |
5149 __ cmp(reg, Operand(object)); | 5338 __ Cmpi(reg, Operand(object), r0); |
5150 } | 5339 } |
5151 DeoptimizeIf(ne, instr->environment()); | 5340 DeoptimizeIf(ne, instr->environment()); |
5152 } | 5341 } |
5153 | 5342 |
5154 | 5343 |
5155 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { | 5344 void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
5156 { | 5345 { |
5157 PushSafepointRegistersScope scope(this); | 5346 PushSafepointRegistersScope scope(this); |
5158 __ push(object); | 5347 __ push(object); |
5159 __ mov(cp, Operand::Zero()); | 5348 __ li(cp, Operand::Zero()); |
5160 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); | 5349 __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); |
5161 RecordSafepointWithRegisters( | 5350 RecordSafepointWithRegisters(instr->pointer_map(), 1, |
5162 instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); | 5351 Safepoint::kNoLazyDeopt); |
5163 __ StoreToSafepointRegisterSlot(r0, scratch0()); | 5352 __ StoreToSafepointRegisterSlot(r3, scratch0()); |
5164 } | 5353 } |
5165 __ tst(scratch0(), Operand(kSmiTagMask)); | 5354 __ TestIfSmi(scratch0(), r0); |
5166 DeoptimizeIf(eq, instr->environment()); | 5355 DeoptimizeIf(eq, instr->environment(), cr0); |
5167 } | 5356 } |
5168 | 5357 |
5169 | 5358 |
5170 void LCodeGen::DoCheckMaps(LCheckMaps* instr) { | 5359 void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
5171 class DeferredCheckMaps V8_FINAL : public LDeferredCode { | 5360 class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
5172 public: | 5361 public: |
5173 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) | 5362 DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
5174 : LDeferredCode(codegen), instr_(instr), object_(object) { | 5363 : LDeferredCode(codegen), instr_(instr), object_(object) { |
5175 SetExit(check_maps()); | 5364 SetExit(check_maps()); |
5176 } | 5365 } |
5177 virtual void Generate() V8_OVERRIDE { | 5366 virtual void Generate() V8_OVERRIDE { |
5178 codegen()->DoDeferredInstanceMigration(instr_, object_); | 5367 codegen()->DoDeferredInstanceMigration(instr_, object_); |
5179 } | 5368 } |
5180 Label* check_maps() { return &check_maps_; } | 5369 Label* check_maps() { return &check_maps_; } |
5181 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 5370 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5371 |
5182 private: | 5372 private: |
5183 LCheckMaps* instr_; | 5373 LCheckMaps* instr_; |
5184 Label check_maps_; | 5374 Label check_maps_; |
5185 Register object_; | 5375 Register object_; |
5186 }; | 5376 }; |
5187 | 5377 |
5188 if (instr->hydrogen()->IsStabilityCheck()) { | 5378 if (instr->hydrogen()->IsStabilityCheck()) { |
5189 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); | 5379 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); |
5190 for (int i = 0; i < maps->size(); ++i) { | 5380 for (int i = 0; i < maps->size(); ++i) { |
5191 AddStabilityDependency(maps->at(i).handle()); | 5381 AddStabilityDependency(maps->at(i).handle()); |
5192 } | 5382 } |
5193 return; | 5383 return; |
5194 } | 5384 } |
5195 | 5385 |
5196 Register map_reg = scratch0(); | 5386 Register map_reg = scratch0(); |
5197 | 5387 |
5198 LOperand* input = instr->value(); | 5388 LOperand* input = instr->value(); |
5199 DCHECK(input->IsRegister()); | 5389 DCHECK(input->IsRegister()); |
5200 Register reg = ToRegister(input); | 5390 Register reg = ToRegister(input); |
5201 | 5391 |
5202 __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); | 5392 __ LoadP(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
5203 | 5393 |
5204 DeferredCheckMaps* deferred = NULL; | 5394 DeferredCheckMaps* deferred = NULL; |
5205 if (instr->hydrogen()->HasMigrationTarget()) { | 5395 if (instr->hydrogen()->HasMigrationTarget()) { |
5206 deferred = new(zone()) DeferredCheckMaps(this, instr, reg); | 5396 deferred = new (zone()) DeferredCheckMaps(this, instr, reg); |
5207 __ bind(deferred->check_maps()); | 5397 __ bind(deferred->check_maps()); |
5208 } | 5398 } |
5209 | 5399 |
5210 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); | 5400 const UniqueSet<Map>* maps = instr->hydrogen()->maps(); |
5211 Label success; | 5401 Label success; |
5212 for (int i = 0; i < maps->size() - 1; i++) { | 5402 for (int i = 0; i < maps->size() - 1; i++) { |
5213 Handle<Map> map = maps->at(i).handle(); | 5403 Handle<Map> map = maps->at(i).handle(); |
5214 __ CompareMap(map_reg, map, &success); | 5404 __ CompareMap(map_reg, map, &success); |
5215 __ b(eq, &success); | 5405 __ beq(&success); |
5216 } | 5406 } |
5217 | 5407 |
5218 Handle<Map> map = maps->at(maps->size() - 1).handle(); | 5408 Handle<Map> map = maps->at(maps->size() - 1).handle(); |
5219 __ CompareMap(map_reg, map, &success); | 5409 __ CompareMap(map_reg, map, &success); |
5220 if (instr->hydrogen()->HasMigrationTarget()) { | 5410 if (instr->hydrogen()->HasMigrationTarget()) { |
5221 __ b(ne, deferred->entry()); | 5411 __ bne(deferred->entry()); |
5222 } else { | 5412 } else { |
5223 DeoptimizeIf(ne, instr->environment()); | 5413 DeoptimizeIf(ne, instr->environment()); |
5224 } | 5414 } |
5225 | 5415 |
5226 __ bind(&success); | 5416 __ bind(&success); |
5227 } | 5417 } |
5228 | 5418 |
5229 | 5419 |
5230 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { | 5420 void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
5231 DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped()); | 5421 DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
5232 Register result_reg = ToRegister(instr->result()); | 5422 Register result_reg = ToRegister(instr->result()); |
5233 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); | 5423 __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); |
5234 } | 5424 } |
5235 | 5425 |
5236 | 5426 |
5237 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { | 5427 void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
5238 Register unclamped_reg = ToRegister(instr->unclamped()); | 5428 Register unclamped_reg = ToRegister(instr->unclamped()); |
5239 Register result_reg = ToRegister(instr->result()); | 5429 Register result_reg = ToRegister(instr->result()); |
5240 __ ClampUint8(result_reg, unclamped_reg); | 5430 __ ClampUint8(result_reg, unclamped_reg); |
5241 } | 5431 } |
5242 | 5432 |
5243 | 5433 |
5244 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { | 5434 void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
5245 Register scratch = scratch0(); | 5435 Register scratch = scratch0(); |
5246 Register input_reg = ToRegister(instr->unclamped()); | 5436 Register input_reg = ToRegister(instr->unclamped()); |
5247 Register result_reg = ToRegister(instr->result()); | 5437 Register result_reg = ToRegister(instr->result()); |
5248 DwVfpRegister temp_reg = ToDoubleRegister(instr->temp()); | 5438 DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
5249 Label is_smi, done, heap_number; | 5439 Label is_smi, done, heap_number; |
5250 | 5440 |
5251 // Both smi and heap number cases are handled. | 5441 // Both smi and heap number cases are handled. |
5252 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); | 5442 __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
5253 | 5443 |
5254 // Check for heap number | 5444 // Check for heap number |
5255 __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); | 5445 __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
5256 __ cmp(scratch, Operand(factory()->heap_number_map())); | 5446 __ Cmpi(scratch, Operand(factory()->heap_number_map()), r0); |
5257 __ b(eq, &heap_number); | 5447 __ beq(&heap_number); |
5258 | 5448 |
5259 // Check for undefined. Undefined is converted to zero for clamping | 5449 // Check for undefined. Undefined is converted to zero for clamping |
5260 // conversions. | 5450 // conversions. |
5261 __ cmp(input_reg, Operand(factory()->undefined_value())); | 5451 __ Cmpi(input_reg, Operand(factory()->undefined_value()), r0); |
5262 DeoptimizeIf(ne, instr->environment()); | 5452 DeoptimizeIf(ne, instr->environment()); |
5263 __ mov(result_reg, Operand::Zero()); | 5453 __ li(result_reg, Operand::Zero()); |
5264 __ jmp(&done); | 5454 __ b(&done); |
5265 | 5455 |
5266 // Heap number | 5456 // Heap number |
5267 __ bind(&heap_number); | 5457 __ bind(&heap_number); |
5268 __ vldr(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); | 5458 __ lfd(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
5269 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); | 5459 __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); |
5270 __ jmp(&done); | 5460 __ b(&done); |
5271 | 5461 |
5272 // smi | 5462 // smi |
5273 __ bind(&is_smi); | 5463 __ bind(&is_smi); |
5274 __ ClampUint8(result_reg, result_reg); | 5464 __ ClampUint8(result_reg, result_reg); |
5275 | 5465 |
5276 __ bind(&done); | 5466 __ bind(&done); |
5277 } | 5467 } |
5278 | 5468 |
5279 | 5469 |
5280 void LCodeGen::DoDoubleBits(LDoubleBits* instr) { | 5470 void LCodeGen::DoDoubleBits(LDoubleBits* instr) { |
5281 DwVfpRegister value_reg = ToDoubleRegister(instr->value()); | 5471 DoubleRegister value_reg = ToDoubleRegister(instr->value()); |
5282 Register result_reg = ToRegister(instr->result()); | 5472 Register result_reg = ToRegister(instr->result()); |
| 5473 |
5283 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { | 5474 if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { |
5284 __ VmovHigh(result_reg, value_reg); | 5475 __ MovDoubleHighToInt(result_reg, value_reg); |
5285 } else { | 5476 } else { |
5286 __ VmovLow(result_reg, value_reg); | 5477 __ MovDoubleLowToInt(result_reg, value_reg); |
5287 } | 5478 } |
5288 } | 5479 } |
5289 | 5480 |
5290 | 5481 |
5291 void LCodeGen::DoConstructDouble(LConstructDouble* instr) { | 5482 void LCodeGen::DoConstructDouble(LConstructDouble* instr) { |
5292 Register hi_reg = ToRegister(instr->hi()); | 5483 Register hi_reg = ToRegister(instr->hi()); |
5293 Register lo_reg = ToRegister(instr->lo()); | 5484 Register lo_reg = ToRegister(instr->lo()); |
5294 DwVfpRegister result_reg = ToDoubleRegister(instr->result()); | 5485 DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
5295 __ VmovHigh(result_reg, hi_reg); | 5486 #if V8_TARGET_ARCH_PPC64 |
5296 __ VmovLow(result_reg, lo_reg); | 5487 __ MovInt64ComponentsToDouble(result_reg, hi_reg, lo_reg, r0); |
| 5488 #else |
| 5489 __ MovInt64ToDouble(result_reg, hi_reg, lo_reg); |
| 5490 #endif |
5297 } | 5491 } |
5298 | 5492 |
5299 | 5493 |
5300 void LCodeGen::DoAllocate(LAllocate* instr) { | 5494 void LCodeGen::DoAllocate(LAllocate* instr) { |
5301 class DeferredAllocate V8_FINAL : public LDeferredCode { | 5495 class DeferredAllocate V8_FINAL : public LDeferredCode { |
5302 public: | 5496 public: |
5303 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5497 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
5304 : LDeferredCode(codegen), instr_(instr) { } | 5498 : LDeferredCode(codegen), instr_(instr) {} |
5305 virtual void Generate() V8_OVERRIDE { | 5499 virtual void Generate() V8_OVERRIDE { |
5306 codegen()->DoDeferredAllocate(instr_); | 5500 codegen()->DoDeferredAllocate(instr_); |
5307 } | 5501 } |
5308 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 5502 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5503 |
5309 private: | 5504 private: |
5310 LAllocate* instr_; | 5505 LAllocate* instr_; |
5311 }; | 5506 }; |
5312 | 5507 |
5313 DeferredAllocate* deferred = | 5508 DeferredAllocate* deferred = new (zone()) DeferredAllocate(this, instr); |
5314 new(zone()) DeferredAllocate(this, instr); | |
5315 | 5509 |
5316 Register result = ToRegister(instr->result()); | 5510 Register result = ToRegister(instr->result()); |
5317 Register scratch = ToRegister(instr->temp1()); | 5511 Register scratch = ToRegister(instr->temp1()); |
5318 Register scratch2 = ToRegister(instr->temp2()); | 5512 Register scratch2 = ToRegister(instr->temp2()); |
5319 | 5513 |
5320 // Allocate memory for the object. | 5514 // Allocate memory for the object. |
5321 AllocationFlags flags = TAG_OBJECT; | 5515 AllocationFlags flags = TAG_OBJECT; |
5322 if (instr->hydrogen()->MustAllocateDoubleAligned()) { | 5516 if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
5323 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); | 5517 flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
5324 } | 5518 } |
5325 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { | 5519 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
5326 DCHECK(!instr->hydrogen()->IsOldDataSpaceAllocation()); | 5520 DCHECK(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
5327 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | 5521 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
5328 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); | 5522 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
5329 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { | 5523 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
5330 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | 5524 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
5331 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); | 5525 flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
5332 } | 5526 } |
5333 | 5527 |
5334 if (instr->size()->IsConstantOperand()) { | 5528 if (instr->size()->IsConstantOperand()) { |
5335 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5529 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
5336 if (size <= Page::kMaxRegularHeapObjectSize) { | 5530 if (size <= Page::kMaxRegularHeapObjectSize) { |
5337 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); | 5531 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
5338 } else { | 5532 } else { |
5339 __ jmp(deferred->entry()); | 5533 __ b(deferred->entry()); |
5340 } | 5534 } |
5341 } else { | 5535 } else { |
5342 Register size = ToRegister(instr->size()); | 5536 Register size = ToRegister(instr->size()); |
5343 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); | 5537 __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
5344 } | 5538 } |
5345 | 5539 |
5346 __ bind(deferred->exit()); | 5540 __ bind(deferred->exit()); |
5347 | 5541 |
5348 if (instr->hydrogen()->MustPrefillWithFiller()) { | 5542 if (instr->hydrogen()->MustPrefillWithFiller()) { |
5349 STATIC_ASSERT(kHeapObjectTag == 1); | 5543 STATIC_ASSERT(kHeapObjectTag == 1); |
5350 if (instr->size()->IsConstantOperand()) { | 5544 if (instr->size()->IsConstantOperand()) { |
5351 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5545 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
5352 __ mov(scratch, Operand(size - kHeapObjectTag)); | 5546 __ LoadIntLiteral(scratch, size - kHeapObjectTag); |
5353 } else { | 5547 } else { |
5354 __ sub(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag)); | 5548 __ subi(scratch, ToRegister(instr->size()), Operand(kHeapObjectTag)); |
5355 } | 5549 } |
5356 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); | 5550 __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
5357 Label loop; | 5551 Label loop; |
5358 __ bind(&loop); | 5552 __ bind(&loop); |
5359 __ sub(scratch, scratch, Operand(kPointerSize), SetCC); | 5553 __ subi(scratch, scratch, Operand(kPointerSize)); |
5360 __ str(scratch2, MemOperand(result, scratch)); | 5554 __ StorePX(scratch2, MemOperand(result, scratch)); |
5361 __ b(ge, &loop); | 5555 __ cmpi(scratch, Operand::Zero()); |
| 5556 __ bge(&loop); |
5362 } | 5557 } |
5363 } | 5558 } |
5364 | 5559 |
5365 | 5560 |
5366 void LCodeGen::DoDeferredAllocate(LAllocate* instr) { | 5561 void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
5367 Register result = ToRegister(instr->result()); | 5562 Register result = ToRegister(instr->result()); |
5368 | 5563 |
5369 // TODO(3095996): Get rid of this. For now, we need to make the | 5564 // TODO(3095996): Get rid of this. For now, we need to make the |
5370 // result register contain a valid pointer because it is already | 5565 // result register contain a valid pointer because it is already |
5371 // contained in the register pointer map. | 5566 // contained in the register pointer map. |
5372 __ mov(result, Operand(Smi::FromInt(0))); | 5567 __ LoadSmiLiteral(result, Smi::FromInt(0)); |
5373 | 5568 |
5374 PushSafepointRegistersScope scope(this); | 5569 PushSafepointRegistersScope scope(this); |
5375 if (instr->size()->IsRegister()) { | 5570 if (instr->size()->IsRegister()) { |
5376 Register size = ToRegister(instr->size()); | 5571 Register size = ToRegister(instr->size()); |
5377 DCHECK(!size.is(result)); | 5572 DCHECK(!size.is(result)); |
5378 __ SmiTag(size); | 5573 __ SmiTag(size); |
5379 __ push(size); | 5574 __ push(size); |
5380 } else { | 5575 } else { |
5381 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); | 5576 int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5577 #if !V8_TARGET_ARCH_PPC64 |
5382 if (size >= 0 && size <= Smi::kMaxValue) { | 5578 if (size >= 0 && size <= Smi::kMaxValue) { |
| 5579 #endif |
5383 __ Push(Smi::FromInt(size)); | 5580 __ Push(Smi::FromInt(size)); |
| 5581 #if !V8_TARGET_ARCH_PPC64 |
5384 } else { | 5582 } else { |
5385 // We should never get here at runtime => abort | 5583 // We should never get here at runtime => abort |
5386 __ stop("invalid allocation size"); | 5584 __ stop("invalid allocation size"); |
5387 return; | 5585 return; |
5388 } | 5586 } |
| 5587 #endif |
5389 } | 5588 } |
5390 | 5589 |
5391 int flags = AllocateDoubleAlignFlag::encode( | 5590 int flags = AllocateDoubleAlignFlag::encode( |
5392 instr->hydrogen()->MustAllocateDoubleAligned()); | 5591 instr->hydrogen()->MustAllocateDoubleAligned()); |
5393 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { | 5592 if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
5394 DCHECK(!instr->hydrogen()->IsOldDataSpaceAllocation()); | 5593 DCHECK(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
5395 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | 5594 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
5396 flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); | 5595 flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
5397 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { | 5596 } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
5398 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); | 5597 DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
5399 flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); | 5598 flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
5400 } else { | 5599 } else { |
5401 flags = AllocateTargetSpace::update(flags, NEW_SPACE); | 5600 flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
5402 } | 5601 } |
5403 __ Push(Smi::FromInt(flags)); | 5602 __ Push(Smi::FromInt(flags)); |
5404 | 5603 |
5405 CallRuntimeFromDeferred( | 5604 CallRuntimeFromDeferred(Runtime::kAllocateInTargetSpace, 2, instr, |
5406 Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); | 5605 instr->context()); |
5407 __ StoreToSafepointRegisterSlot(r0, result); | 5606 __ StoreToSafepointRegisterSlot(r3, result); |
5408 } | 5607 } |
5409 | 5608 |
5410 | 5609 |
5411 void LCodeGen::DoToFastProperties(LToFastProperties* instr) { | 5610 void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
5412 DCHECK(ToRegister(instr->value()).is(r0)); | 5611 DCHECK(ToRegister(instr->value()).is(r3)); |
5413 __ push(r0); | 5612 __ push(r3); |
5414 CallRuntime(Runtime::kToFastProperties, 1, instr); | 5613 CallRuntime(Runtime::kToFastProperties, 1, instr); |
5415 } | 5614 } |
5416 | 5615 |
5417 | 5616 |
5418 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { | 5617 void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
5419 DCHECK(ToRegister(instr->context()).is(cp)); | 5618 DCHECK(ToRegister(instr->context()).is(cp)); |
5420 Label materialized; | 5619 Label materialized; |
5421 // Registers will be used as follows: | 5620 // Registers will be used as follows: |
5422 // r6 = literals array. | 5621 // r10 = literals array. |
5423 // r1 = regexp literal. | 5622 // r4 = regexp literal. |
5424 // r0 = regexp literal clone. | 5623 // r3 = regexp literal clone. |
5425 // r2-5 are used as temporaries. | 5624 // r5 and r7-r9 are used as temporaries. |
5426 int literal_offset = | 5625 int literal_offset = |
5427 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); | 5626 FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
5428 __ Move(r6, instr->hydrogen()->literals()); | 5627 __ Move(r10, instr->hydrogen()->literals()); |
5429 __ ldr(r1, FieldMemOperand(r6, literal_offset)); | 5628 __ LoadP(r4, FieldMemOperand(r10, literal_offset)); |
5430 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5629 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
5431 __ cmp(r1, ip); | 5630 __ cmp(r4, ip); |
5432 __ b(ne, &materialized); | 5631 __ bne(&materialized); |
5433 | 5632 |
5434 // Create regexp literal using runtime function | 5633 // Create regexp literal using runtime function |
5435 // Result will be in r0. | 5634 // Result will be in r3. |
5436 __ mov(r5, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); | 5635 __ LoadSmiLiteral(r9, Smi::FromInt(instr->hydrogen()->literal_index())); |
5437 __ mov(r4, Operand(instr->hydrogen()->pattern())); | 5636 __ mov(r8, Operand(instr->hydrogen()->pattern())); |
5438 __ mov(r3, Operand(instr->hydrogen()->flags())); | 5637 __ mov(r7, Operand(instr->hydrogen()->flags())); |
5439 __ Push(r6, r5, r4, r3); | 5638 __ Push(r10, r9, r8, r7); |
5440 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); | 5639 CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
5441 __ mov(r1, r0); | 5640 __ mr(r4, r3); |
5442 | 5641 |
5443 __ bind(&materialized); | 5642 __ bind(&materialized); |
5444 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; | 5643 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
5445 Label allocated, runtime_allocate; | 5644 Label allocated, runtime_allocate; |
5446 | 5645 |
5447 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); | 5646 __ Allocate(size, r3, r5, r6, &runtime_allocate, TAG_OBJECT); |
5448 __ jmp(&allocated); | 5647 __ b(&allocated); |
5449 | 5648 |
5450 __ bind(&runtime_allocate); | 5649 __ bind(&runtime_allocate); |
5451 __ mov(r0, Operand(Smi::FromInt(size))); | 5650 __ LoadSmiLiteral(r3, Smi::FromInt(size)); |
5452 __ Push(r1, r0); | 5651 __ Push(r4, r3); |
5453 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 5652 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
5454 __ pop(r1); | 5653 __ pop(r4); |
5455 | 5654 |
5456 __ bind(&allocated); | 5655 __ bind(&allocated); |
5457 // Copy the content into the newly allocated memory. | 5656 // Copy the content into the newly allocated memory. |
5458 __ CopyFields(r0, r1, double_scratch0(), size / kPointerSize); | 5657 __ CopyFields(r3, r4, r5.bit(), size / kPointerSize); |
5459 } | 5658 } |
5460 | 5659 |
5461 | 5660 |
5462 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { | 5661 void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
5463 DCHECK(ToRegister(instr->context()).is(cp)); | 5662 DCHECK(ToRegister(instr->context()).is(cp)); |
5464 // Use the fast case closure allocation code that allocates in new | 5663 // Use the fast case closure allocation code that allocates in new |
5465 // space for nested functions that don't need literals cloning. | 5664 // space for nested functions that don't need literals cloning. |
5466 bool pretenure = instr->hydrogen()->pretenure(); | 5665 bool pretenure = instr->hydrogen()->pretenure(); |
5467 if (!pretenure && instr->hydrogen()->has_no_literals()) { | 5666 if (!pretenure && instr->hydrogen()->has_no_literals()) { |
5468 FastNewClosureStub stub(isolate(), | 5667 FastNewClosureStub stub(isolate(), instr->hydrogen()->strict_mode(), |
5469 instr->hydrogen()->strict_mode(), | |
5470 instr->hydrogen()->is_generator()); | 5668 instr->hydrogen()->is_generator()); |
5471 __ mov(r2, Operand(instr->hydrogen()->shared_info())); | 5669 __ mov(r5, Operand(instr->hydrogen()->shared_info())); |
5472 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 5670 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
5473 } else { | 5671 } else { |
5474 __ mov(r2, Operand(instr->hydrogen()->shared_info())); | 5672 __ mov(r5, Operand(instr->hydrogen()->shared_info())); |
5475 __ mov(r1, Operand(pretenure ? factory()->true_value() | 5673 __ mov(r4, Operand(pretenure ? factory()->true_value() |
5476 : factory()->false_value())); | 5674 : factory()->false_value())); |
5477 __ Push(cp, r2, r1); | 5675 __ Push(cp, r5, r4); |
5478 CallRuntime(Runtime::kNewClosure, 3, instr); | 5676 CallRuntime(Runtime::kNewClosure, 3, instr); |
5479 } | 5677 } |
5480 } | 5678 } |
5481 | 5679 |
5482 | 5680 |
5483 void LCodeGen::DoTypeof(LTypeof* instr) { | 5681 void LCodeGen::DoTypeof(LTypeof* instr) { |
5484 Register input = ToRegister(instr->value()); | 5682 Register input = ToRegister(instr->value()); |
5485 __ push(input); | 5683 __ push(input); |
5486 CallRuntime(Runtime::kTypeof, 1, instr); | 5684 CallRuntime(Runtime::kTypeof, 1, instr); |
5487 } | 5685 } |
5488 | 5686 |
5489 | 5687 |
5490 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { | 5688 void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
5491 Register input = ToRegister(instr->value()); | 5689 Register input = ToRegister(instr->value()); |
5492 | 5690 |
5493 Condition final_branch_condition = EmitTypeofIs(instr->TrueLabel(chunk_), | 5691 Condition final_branch_condition = |
5494 instr->FalseLabel(chunk_), | 5692 EmitTypeofIs(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), input, |
5495 input, | 5693 instr->type_literal()); |
5496 instr->type_literal()); | |
5497 if (final_branch_condition != kNoCondition) { | 5694 if (final_branch_condition != kNoCondition) { |
5498 EmitBranch(instr, final_branch_condition); | 5695 EmitBranch(instr, final_branch_condition); |
5499 } | 5696 } |
5500 } | 5697 } |
5501 | 5698 |
5502 | 5699 |
5503 Condition LCodeGen::EmitTypeofIs(Label* true_label, | 5700 Condition LCodeGen::EmitTypeofIs(Label* true_label, Label* false_label, |
5504 Label* false_label, | 5701 Register input, Handle<String> type_name) { |
5505 Register input, | |
5506 Handle<String> type_name) { | |
5507 Condition final_branch_condition = kNoCondition; | 5702 Condition final_branch_condition = kNoCondition; |
5508 Register scratch = scratch0(); | 5703 Register scratch = scratch0(); |
5509 Factory* factory = isolate()->factory(); | 5704 Factory* factory = isolate()->factory(); |
5510 if (String::Equals(type_name, factory->number_string())) { | 5705 if (String::Equals(type_name, factory->number_string())) { |
5511 __ JumpIfSmi(input, true_label); | 5706 __ JumpIfSmi(input, true_label); |
5512 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5707 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
5513 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); | 5708 __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
5514 final_branch_condition = eq; | 5709 final_branch_condition = eq; |
5515 | 5710 |
5516 } else if (String::Equals(type_name, factory->string_string())) { | 5711 } else if (String::Equals(type_name, factory->string_string())) { |
5517 __ JumpIfSmi(input, false_label); | 5712 __ JumpIfSmi(input, false_label); |
5518 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); | 5713 __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); |
5519 __ b(ge, false_label); | 5714 __ bge(false_label); |
5520 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | 5715 __ lbz(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
5521 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5716 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5717 __ cmpi(r0, Operand::Zero()); |
5522 final_branch_condition = eq; | 5718 final_branch_condition = eq; |
5523 | 5719 |
5524 } else if (String::Equals(type_name, factory->symbol_string())) { | 5720 } else if (String::Equals(type_name, factory->symbol_string())) { |
5525 __ JumpIfSmi(input, false_label); | 5721 __ JumpIfSmi(input, false_label); |
5526 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); | 5722 __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); |
5527 final_branch_condition = eq; | 5723 final_branch_condition = eq; |
5528 | 5724 |
5529 } else if (String::Equals(type_name, factory->boolean_string())) { | 5725 } else if (String::Equals(type_name, factory->boolean_string())) { |
5530 __ CompareRoot(input, Heap::kTrueValueRootIndex); | 5726 __ CompareRoot(input, Heap::kTrueValueRootIndex); |
5531 __ b(eq, true_label); | 5727 __ beq(true_label); |
5532 __ CompareRoot(input, Heap::kFalseValueRootIndex); | 5728 __ CompareRoot(input, Heap::kFalseValueRootIndex); |
5533 final_branch_condition = eq; | 5729 final_branch_condition = eq; |
5534 | 5730 |
5535 } else if (String::Equals(type_name, factory->undefined_string())) { | 5731 } else if (String::Equals(type_name, factory->undefined_string())) { |
5536 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); | 5732 __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
5537 __ b(eq, true_label); | 5733 __ beq(true_label); |
5538 __ JumpIfSmi(input, false_label); | 5734 __ JumpIfSmi(input, false_label); |
5539 // Check for undetectable objects => true. | 5735 // Check for undetectable objects => true. |
5540 __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); | 5736 __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
5541 __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); | 5737 __ lbz(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
5542 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5738 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5739 __ cmpi(r0, Operand::Zero()); |
5543 final_branch_condition = ne; | 5740 final_branch_condition = ne; |
5544 | 5741 |
5545 } else if (String::Equals(type_name, factory->function_string())) { | 5742 } else if (String::Equals(type_name, factory->function_string())) { |
5546 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | 5743 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
5547 Register type_reg = scratch; | 5744 Register type_reg = scratch; |
5548 __ JumpIfSmi(input, false_label); | 5745 __ JumpIfSmi(input, false_label); |
5549 __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE); | 5746 __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE); |
5550 __ b(eq, true_label); | 5747 __ beq(true_label); |
5551 __ cmp(type_reg, Operand(JS_FUNCTION_PROXY_TYPE)); | 5748 __ cmpi(type_reg, Operand(JS_FUNCTION_PROXY_TYPE)); |
5552 final_branch_condition = eq; | 5749 final_branch_condition = eq; |
5553 | 5750 |
5554 } else if (String::Equals(type_name, factory->object_string())) { | 5751 } else if (String::Equals(type_name, factory->object_string())) { |
5555 Register map = scratch; | 5752 Register map = scratch; |
5556 __ JumpIfSmi(input, false_label); | 5753 __ JumpIfSmi(input, false_label); |
5557 __ CompareRoot(input, Heap::kNullValueRootIndex); | 5754 __ CompareRoot(input, Heap::kNullValueRootIndex); |
5558 __ b(eq, true_label); | 5755 __ beq(true_label); |
5559 __ CheckObjectTypeRange(input, | 5756 __ CheckObjectTypeRange(input, map, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
5560 map, | 5757 LAST_NONCALLABLE_SPEC_OBJECT_TYPE, false_label); |
5561 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, | |
5562 LAST_NONCALLABLE_SPEC_OBJECT_TYPE, | |
5563 false_label); | |
5564 // Check for undetectable objects => false. | 5758 // Check for undetectable objects => false. |
5565 __ ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); | 5759 __ lbz(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); |
5566 __ tst(scratch, Operand(1 << Map::kIsUndetectable)); | 5760 __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5761 __ cmpi(r0, Operand::Zero()); |
5567 final_branch_condition = eq; | 5762 final_branch_condition = eq; |
5568 | 5763 |
5569 } else { | 5764 } else { |
5570 __ b(false_label); | 5765 __ b(false_label); |
5571 } | 5766 } |
5572 | 5767 |
5573 return final_branch_condition; | 5768 return final_branch_condition; |
5574 } | 5769 } |
5575 | 5770 |
5576 | 5771 |
5577 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { | 5772 void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
5578 Register temp1 = ToRegister(instr->temp()); | 5773 Register temp1 = ToRegister(instr->temp()); |
5579 | 5774 |
5580 EmitIsConstructCall(temp1, scratch0()); | 5775 EmitIsConstructCall(temp1, scratch0()); |
5581 EmitBranch(instr, eq); | 5776 EmitBranch(instr, eq); |
5582 } | 5777 } |
5583 | 5778 |
5584 | 5779 |
5585 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { | 5780 void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
5586 DCHECK(!temp1.is(temp2)); | 5781 DCHECK(!temp1.is(temp2)); |
5587 // Get the frame pointer for the calling frame. | 5782 // Get the frame pointer for the calling frame. |
5588 __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 5783 __ LoadP(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
5589 | 5784 |
5590 // Skip the arguments adaptor frame if it exists. | 5785 // Skip the arguments adaptor frame if it exists. |
5591 __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); | 5786 Label check_frame_marker; |
5592 __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | 5787 __ LoadP(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
5593 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset), eq); | 5788 __ CmpSmiLiteral(temp2, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
| 5789 __ bne(&check_frame_marker); |
| 5790 __ LoadP(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
5594 | 5791 |
5595 // Check the marker in the calling frame. | 5792 // Check the marker in the calling frame. |
5596 __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); | 5793 __ bind(&check_frame_marker); |
5597 __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); | 5794 __ LoadP(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5795 __ CmpSmiLiteral(temp1, Smi::FromInt(StackFrame::CONSTRUCT), r0); |
5598 } | 5796 } |
5599 | 5797 |
5600 | 5798 |
5601 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { | 5799 void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
5602 if (!info()->IsStub()) { | 5800 if (!info()->IsStub()) { |
5603 // Ensure that we have enough space after the previous lazy-bailout | 5801 // Ensure that we have enough space after the previous lazy-bailout |
5604 // instruction for patching the code here. | 5802 // instruction for patching the code here. |
5605 int current_pc = masm()->pc_offset(); | 5803 int current_pc = masm()->pc_offset(); |
5606 if (current_pc < last_lazy_deopt_pc_ + space_needed) { | 5804 if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
5607 // Block literal pool emission for duration of padding. | |
5608 Assembler::BlockConstPoolScope block_const_pool(masm()); | |
5609 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 5805 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
5610 DCHECK_EQ(0, padding_size % Assembler::kInstrSize); | 5806 DCHECK_EQ(0, padding_size % Assembler::kInstrSize); |
5611 while (padding_size > 0) { | 5807 while (padding_size > 0) { |
5612 __ nop(); | 5808 __ nop(); |
5613 padding_size -= Assembler::kInstrSize; | 5809 padding_size -= Assembler::kInstrSize; |
5614 } | 5810 } |
5615 } | 5811 } |
5616 } | 5812 } |
5617 last_lazy_deopt_pc_ = masm()->pc_offset(); | 5813 last_lazy_deopt_pc_ = masm()->pc_offset(); |
5618 } | 5814 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5661 DCHECK(instr->HasEnvironment()); | 5857 DCHECK(instr->HasEnvironment()); |
5662 LEnvironment* env = instr->environment(); | 5858 LEnvironment* env = instr->environment(); |
5663 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); | 5859 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
5664 } | 5860 } |
5665 | 5861 |
5666 | 5862 |
5667 void LCodeGen::DoStackCheck(LStackCheck* instr) { | 5863 void LCodeGen::DoStackCheck(LStackCheck* instr) { |
5668 class DeferredStackCheck V8_FINAL : public LDeferredCode { | 5864 class DeferredStackCheck V8_FINAL : public LDeferredCode { |
5669 public: | 5865 public: |
5670 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) | 5866 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
5671 : LDeferredCode(codegen), instr_(instr) { } | 5867 : LDeferredCode(codegen), instr_(instr) {} |
5672 virtual void Generate() V8_OVERRIDE { | 5868 virtual void Generate() V8_OVERRIDE { |
5673 codegen()->DoDeferredStackCheck(instr_); | 5869 codegen()->DoDeferredStackCheck(instr_); |
5674 } | 5870 } |
5675 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 5871 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5872 |
5676 private: | 5873 private: |
5677 LStackCheck* instr_; | 5874 LStackCheck* instr_; |
5678 }; | 5875 }; |
5679 | 5876 |
5680 DCHECK(instr->HasEnvironment()); | 5877 DCHECK(instr->HasEnvironment()); |
5681 LEnvironment* env = instr->environment(); | 5878 LEnvironment* env = instr->environment(); |
5682 // There is no LLazyBailout instruction for stack-checks. We have to | 5879 // There is no LLazyBailout instruction for stack-checks. We have to |
5683 // prepare for lazy deoptimization explicitly here. | 5880 // prepare for lazy deoptimization explicitly here. |
5684 if (instr->hydrogen()->is_function_entry()) { | 5881 if (instr->hydrogen()->is_function_entry()) { |
5685 // Perform stack overflow check. | 5882 // Perform stack overflow check. |
5686 Label done; | 5883 Label done; |
5687 __ LoadRoot(ip, Heap::kStackLimitRootIndex); | 5884 __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
5688 __ cmp(sp, Operand(ip)); | 5885 __ cmpl(sp, ip); |
5689 __ b(hs, &done); | 5886 __ bge(&done); |
5690 Handle<Code> stack_check = isolate()->builtins()->StackCheck(); | |
5691 PredictableCodeSizeScope predictable(masm(), | |
5692 CallCodeSize(stack_check, RelocInfo::CODE_TARGET)); | |
5693 DCHECK(instr->context()->IsRegister()); | 5887 DCHECK(instr->context()->IsRegister()); |
5694 DCHECK(ToRegister(instr->context()).is(cp)); | 5888 DCHECK(ToRegister(instr->context()).is(cp)); |
5695 CallCode(stack_check, RelocInfo::CODE_TARGET, instr); | 5889 CallCode(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET, |
| 5890 instr); |
5696 __ bind(&done); | 5891 __ bind(&done); |
5697 } else { | 5892 } else { |
5698 DCHECK(instr->hydrogen()->is_backwards_branch()); | 5893 DCHECK(instr->hydrogen()->is_backwards_branch()); |
5699 // Perform stack overflow check if this goto needs it before jumping. | 5894 // Perform stack overflow check if this goto needs it before jumping. |
5700 DeferredStackCheck* deferred_stack_check = | 5895 DeferredStackCheck* deferred_stack_check = |
5701 new(zone()) DeferredStackCheck(this, instr); | 5896 new (zone()) DeferredStackCheck(this, instr); |
5702 __ LoadRoot(ip, Heap::kStackLimitRootIndex); | 5897 __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
5703 __ cmp(sp, Operand(ip)); | 5898 __ cmpl(sp, ip); |
5704 __ b(lo, deferred_stack_check->entry()); | 5899 __ blt(deferred_stack_check->entry()); |
5705 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); | 5900 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
5706 __ bind(instr->done_label()); | 5901 __ bind(instr->done_label()); |
5707 deferred_stack_check->SetExit(instr->done_label()); | 5902 deferred_stack_check->SetExit(instr->done_label()); |
5708 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); | 5903 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
5709 // Don't record a deoptimization index for the safepoint here. | 5904 // Don't record a deoptimization index for the safepoint here. |
5710 // This will be done explicitly when emitting call and the safepoint in | 5905 // This will be done explicitly when emitting call and the safepoint in |
5711 // the deferred code. | 5906 // the deferred code. |
5712 } | 5907 } |
5713 } | 5908 } |
5714 | 5909 |
5715 | 5910 |
5716 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 5911 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
5717 // This is a pseudo-instruction that ensures that the environment here is | 5912 // This is a pseudo-instruction that ensures that the environment here is |
5718 // properly registered for deoptimization and records the assembler's PC | 5913 // properly registered for deoptimization and records the assembler's PC |
5719 // offset. | 5914 // offset. |
5720 LEnvironment* environment = instr->environment(); | 5915 LEnvironment* environment = instr->environment(); |
5721 | 5916 |
5722 // If the environment were already registered, we would have no way of | 5917 // If the environment were already registered, we would have no way of |
5723 // backpatching it with the spill slot operands. | 5918 // backpatching it with the spill slot operands. |
5724 DCHECK(!environment->HasBeenRegistered()); | 5919 DCHECK(!environment->HasBeenRegistered()); |
5725 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 5920 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
5726 | 5921 |
5727 GenerateOsrPrologue(); | 5922 GenerateOsrPrologue(); |
5728 } | 5923 } |
5729 | 5924 |
5730 | 5925 |
5731 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { | 5926 void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
5732 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 5927 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
5733 __ cmp(r0, ip); | 5928 __ cmp(r3, ip); |
5734 DeoptimizeIf(eq, instr->environment()); | 5929 DeoptimizeIf(eq, instr->environment()); |
5735 | 5930 |
5736 Register null_value = r5; | 5931 Register null_value = r8; |
5737 __ LoadRoot(null_value, Heap::kNullValueRootIndex); | 5932 __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
5738 __ cmp(r0, null_value); | 5933 __ cmp(r3, null_value); |
5739 DeoptimizeIf(eq, instr->environment()); | 5934 DeoptimizeIf(eq, instr->environment()); |
5740 | 5935 |
5741 __ SmiTst(r0); | 5936 __ TestIfSmi(r3, r0); |
5742 DeoptimizeIf(eq, instr->environment()); | 5937 DeoptimizeIf(eq, instr->environment(), cr0); |
5743 | 5938 |
5744 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | 5939 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
5745 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); | 5940 __ CompareObjectType(r3, r4, r4, LAST_JS_PROXY_TYPE); |
5746 DeoptimizeIf(le, instr->environment()); | 5941 DeoptimizeIf(le, instr->environment()); |
5747 | 5942 |
5748 Label use_cache, call_runtime; | 5943 Label use_cache, call_runtime; |
5749 __ CheckEnumCache(null_value, &call_runtime); | 5944 __ CheckEnumCache(null_value, &call_runtime); |
5750 | 5945 |
5751 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); | 5946 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); |
5752 __ b(&use_cache); | 5947 __ b(&use_cache); |
5753 | 5948 |
5754 // Get the set of properties to enumerate. | 5949 // Get the set of properties to enumerate. |
5755 __ bind(&call_runtime); | 5950 __ bind(&call_runtime); |
5756 __ push(r0); | 5951 __ push(r3); |
5757 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); | 5952 CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
5758 | 5953 |
5759 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); | 5954 __ LoadP(r4, FieldMemOperand(r3, HeapObject::kMapOffset)); |
5760 __ LoadRoot(ip, Heap::kMetaMapRootIndex); | 5955 __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
5761 __ cmp(r1, ip); | 5956 __ cmp(r4, ip); |
5762 DeoptimizeIf(ne, instr->environment()); | 5957 DeoptimizeIf(ne, instr->environment()); |
5763 __ bind(&use_cache); | 5958 __ bind(&use_cache); |
5764 } | 5959 } |
5765 | 5960 |
5766 | 5961 |
5767 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { | 5962 void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
5768 Register map = ToRegister(instr->map()); | 5963 Register map = ToRegister(instr->map()); |
5769 Register result = ToRegister(instr->result()); | 5964 Register result = ToRegister(instr->result()); |
5770 Label load_cache, done; | 5965 Label load_cache, done; |
5771 __ EnumLength(result, map); | 5966 __ EnumLength(result, map); |
5772 __ cmp(result, Operand(Smi::FromInt(0))); | 5967 __ CmpSmiLiteral(result, Smi::FromInt(0), r0); |
5773 __ b(ne, &load_cache); | 5968 __ bne(&load_cache); |
5774 __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); | 5969 __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); |
5775 __ jmp(&done); | 5970 __ b(&done); |
5776 | 5971 |
5777 __ bind(&load_cache); | 5972 __ bind(&load_cache); |
5778 __ LoadInstanceDescriptors(map, result); | 5973 __ LoadInstanceDescriptors(map, result); |
5779 __ ldr(result, | 5974 __ LoadP(result, FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
5780 FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); | 5975 __ LoadP(result, FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
5781 __ ldr(result, | 5976 __ cmpi(result, Operand::Zero()); |
5782 FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); | |
5783 __ cmp(result, Operand::Zero()); | |
5784 DeoptimizeIf(eq, instr->environment()); | 5977 DeoptimizeIf(eq, instr->environment()); |
5785 | 5978 |
5786 __ bind(&done); | 5979 __ bind(&done); |
5787 } | 5980 } |
5788 | 5981 |
5789 | 5982 |
5790 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { | 5983 void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
5791 Register object = ToRegister(instr->value()); | 5984 Register object = ToRegister(instr->value()); |
5792 Register map = ToRegister(instr->map()); | 5985 Register map = ToRegister(instr->map()); |
5793 __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); | 5986 __ LoadP(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
5794 __ cmp(map, scratch0()); | 5987 __ cmp(map, scratch0()); |
5795 DeoptimizeIf(ne, instr->environment()); | 5988 DeoptimizeIf(ne, instr->environment()); |
5796 } | 5989 } |
5797 | 5990 |
5798 | 5991 |
5799 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, | 5992 void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
5800 Register result, | 5993 Register result, Register object, |
5801 Register object, | |
5802 Register index) { | 5994 Register index) { |
5803 PushSafepointRegistersScope scope(this); | 5995 PushSafepointRegistersScope scope(this); |
5804 __ Push(object); | 5996 __ Push(object, index); |
5805 __ Push(index); | 5997 __ li(cp, Operand::Zero()); |
5806 __ mov(cp, Operand::Zero()); | |
5807 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); | 5998 __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); |
5808 RecordSafepointWithRegisters( | 5999 RecordSafepointWithRegisters(instr->pointer_map(), 2, |
5809 instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); | 6000 Safepoint::kNoLazyDeopt); |
5810 __ StoreToSafepointRegisterSlot(r0, result); | 6001 __ StoreToSafepointRegisterSlot(r3, result); |
5811 } | 6002 } |
5812 | 6003 |
5813 | 6004 |
5814 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { | 6005 void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
5815 class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { | 6006 class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { |
5816 public: | 6007 public: |
5817 DeferredLoadMutableDouble(LCodeGen* codegen, | 6008 DeferredLoadMutableDouble(LCodeGen* codegen, LLoadFieldByIndex* instr, |
5818 LLoadFieldByIndex* instr, | 6009 Register result, Register object, Register index) |
5819 Register result, | |
5820 Register object, | |
5821 Register index) | |
5822 : LDeferredCode(codegen), | 6010 : LDeferredCode(codegen), |
5823 instr_(instr), | 6011 instr_(instr), |
5824 result_(result), | 6012 result_(result), |
5825 object_(object), | 6013 object_(object), |
5826 index_(index) { | 6014 index_(index) {} |
5827 } | |
5828 virtual void Generate() V8_OVERRIDE { | 6015 virtual void Generate() V8_OVERRIDE { |
5829 codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_); | 6016 codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_); |
5830 } | 6017 } |
5831 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } | 6018 virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 6019 |
5832 private: | 6020 private: |
5833 LLoadFieldByIndex* instr_; | 6021 LLoadFieldByIndex* instr_; |
5834 Register result_; | 6022 Register result_; |
5835 Register object_; | 6023 Register object_; |
5836 Register index_; | 6024 Register index_; |
5837 }; | 6025 }; |
5838 | 6026 |
5839 Register object = ToRegister(instr->object()); | 6027 Register object = ToRegister(instr->object()); |
5840 Register index = ToRegister(instr->index()); | 6028 Register index = ToRegister(instr->index()); |
5841 Register result = ToRegister(instr->result()); | 6029 Register result = ToRegister(instr->result()); |
5842 Register scratch = scratch0(); | 6030 Register scratch = scratch0(); |
5843 | 6031 |
5844 DeferredLoadMutableDouble* deferred; | 6032 DeferredLoadMutableDouble* deferred; |
5845 deferred = new(zone()) DeferredLoadMutableDouble( | 6033 deferred = new (zone()) |
5846 this, instr, result, object, index); | 6034 DeferredLoadMutableDouble(this, instr, result, object, index); |
5847 | 6035 |
5848 Label out_of_object, done; | 6036 Label out_of_object, done; |
5849 | 6037 |
5850 __ tst(index, Operand(Smi::FromInt(1))); | 6038 __ TestBitMask(index, reinterpret_cast<uintptr_t>(Smi::FromInt(1)), r0); |
5851 __ b(ne, deferred->entry()); | 6039 __ bne(deferred->entry(), cr0); |
5852 __ mov(index, Operand(index, ASR, 1)); | 6040 __ ShiftRightArithImm(index, index, 1); |
5853 | 6041 |
5854 __ cmp(index, Operand::Zero()); | 6042 __ cmpi(index, Operand::Zero()); |
5855 __ b(lt, &out_of_object); | 6043 __ blt(&out_of_object); |
5856 | 6044 |
5857 __ add(scratch, object, Operand::PointerOffsetFromSmiKey(index)); | 6045 __ SmiToPtrArrayOffset(r0, index); |
5858 __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); | 6046 __ add(scratch, object, r0); |
| 6047 __ LoadP(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
5859 | 6048 |
5860 __ b(&done); | 6049 __ b(&done); |
5861 | 6050 |
5862 __ bind(&out_of_object); | 6051 __ bind(&out_of_object); |
5863 __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 6052 __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
5864 // Index is equal to negated out of object property index plus 1. | 6053 // Index is equal to negated out of object property index plus 1. |
5865 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); | 6054 __ SmiToPtrArrayOffset(r0, index); |
5866 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 6055 __ sub(scratch, result, r0); |
5867 __ ldr(result, FieldMemOperand(scratch, | 6056 __ LoadP(result, |
5868 FixedArray::kHeaderSize - kPointerSize)); | 6057 FieldMemOperand(scratch, FixedArray::kHeaderSize - kPointerSize)); |
5869 __ bind(deferred->exit()); | 6058 __ bind(deferred->exit()); |
5870 __ bind(&done); | 6059 __ bind(&done); |
5871 } | 6060 } |
5872 | 6061 |
5873 | 6062 |
5874 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) { | 6063 void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) { |
5875 Register context = ToRegister(instr->context()); | 6064 Register context = ToRegister(instr->context()); |
5876 __ str(context, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 6065 __ StoreP(context, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
5877 } | 6066 } |
5878 | 6067 |
5879 | 6068 |
5880 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) { | 6069 void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) { |
5881 Handle<ScopeInfo> scope_info = instr->scope_info(); | 6070 Handle<ScopeInfo> scope_info = instr->scope_info(); |
5882 __ Push(scope_info); | 6071 __ Push(scope_info); |
5883 __ push(ToRegister(instr->function())); | 6072 __ push(ToRegister(instr->function())); |
5884 CallRuntime(Runtime::kPushBlockContext, 2, instr); | 6073 CallRuntime(Runtime::kPushBlockContext, 2, instr); |
5885 RecordSafepoint(Safepoint::kNoLazyDeopt); | 6074 RecordSafepoint(Safepoint::kNoLazyDeopt); |
5886 } | 6075 } |
5887 | 6076 |
5888 | 6077 |
5889 #undef __ | 6078 #undef __ |
5890 | 6079 } |
5891 } } // namespace v8::internal | 6080 } // namespace v8::internal |
OLD | NEW |