blob: c845a3d7e90836b7f2f297b7e11c2da1969475fe [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Iain Merrick9ac36c92010-09-13 15:29:50 +01005#include <limits.h> // For LONG_MIN, LONG_MAX.
6
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/v8.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#if V8_TARGET_ARCH_ARM
Leon Clarkef7060e22010-06-03 12:02:55 +010010
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/base/bits.h"
12#include "src/base/division-by-constant.h"
13#include "src/bootstrapper.h"
14#include "src/codegen.h"
15#include "src/cpu-profiler.h"
16#include "src/debug.h"
17#include "src/isolate-inl.h"
18#include "src/runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000019
20namespace v8 {
21namespace internal {
22
Ben Murdoch8b112d22011-06-08 16:22:53 +010023MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size)
24 : Assembler(arg_isolate, buffer, size),
Steve Blocka7e24c12009-10-30 11:49:00 +000025 generating_stub_(false),
Ben Murdoch3ef787d2012-04-12 10:51:47 +010026 has_frame_(false) {
Ben Murdoch8b112d22011-06-08 16:22:53 +010027 if (isolate() != NULL) {
28 code_object_ = Handle<Object>(isolate()->heap()->undefined_value(),
29 isolate());
30 }
Steve Blocka7e24c12009-10-30 11:49:00 +000031}
32
33
Steve Blocka7e24c12009-10-30 11:49:00 +000034void MacroAssembler::Jump(Register target, Condition cond) {
Steve Blocka7e24c12009-10-30 11:49:00 +000035 bx(target, cond);
Steve Blocka7e24c12009-10-30 11:49:00 +000036}
37
38
39void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
40 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041 DCHECK(RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +000042 mov(pc, Operand(target, rmode), LeaveCC, cond);
Steve Blocka7e24c12009-10-30 11:49:00 +000043}
44
45
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000046void MacroAssembler::Jump(Address target, RelocInfo::Mode rmode,
Steve Blocka7e24c12009-10-30 11:49:00 +000047 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048 DCHECK(!RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +000049 Jump(reinterpret_cast<intptr_t>(target), rmode, cond);
50}
51
52
53void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
54 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 DCHECK(RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +000056 // 'code' is always generated ARM code, never THUMB code
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 AllowDeferredHandleDereference embedding_raw_address;
Steve Blocka7e24c12009-10-30 11:49:00 +000058 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
59}
60
61
Steve Block44f0eee2011-05-26 01:26:41 +010062int MacroAssembler::CallSize(Register target, Condition cond) {
Steve Block44f0eee2011-05-26 01:26:41 +010063 return kInstrSize;
Steve Block44f0eee2011-05-26 01:26:41 +010064}
65
66
Steve Blocka7e24c12009-10-30 11:49:00 +000067void MacroAssembler::Call(Register target, Condition cond) {
Steve Block44f0eee2011-05-26 01:26:41 +010068 // Block constant pool for the call instruction sequence.
69 BlockConstPoolScope block_const_pool(this);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000070 Label start;
71 bind(&start);
Steve Blocka7e24c12009-10-30 11:49:00 +000072 blx(target, cond);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073 DCHECK_EQ(CallSize(target, cond), SizeOfCodeGeneratedSince(&start));
Steve Blocka7e24c12009-10-30 11:49:00 +000074}
75
76
Steve Block44f0eee2011-05-26 01:26:41 +010077int MacroAssembler::CallSize(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000078 Address target, RelocInfo::Mode rmode, Condition cond) {
Steve Block44f0eee2011-05-26 01:26:41 +010079 Instr mov_instr = cond | MOV | LeaveCC;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080 Operand mov_operand = Operand(reinterpret_cast<intptr_t>(target), rmode);
81 return kInstrSize +
82 mov_operand.instructions_required(this, mov_instr) * kInstrSize;
83}
84
85
86int MacroAssembler::CallStubSize(
87 CodeStub* stub, TypeFeedbackId ast_id, Condition cond) {
88 return CallSize(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id, cond);
89}
90
91
92int MacroAssembler::CallSizeNotPredictableCodeSize(Isolate* isolate,
93 Address target,
94 RelocInfo::Mode rmode,
95 Condition cond) {
96 Instr mov_instr = cond | MOV | LeaveCC;
97 Operand mov_operand = Operand(reinterpret_cast<intptr_t>(target), rmode);
98 return kInstrSize +
99 mov_operand.instructions_required(NULL, mov_instr) * kInstrSize;
Steve Block44f0eee2011-05-26 01:26:41 +0100100}
101
102
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000103void MacroAssembler::Call(Address target,
Ben Murdoch257744e2011-11-30 15:57:28 +0000104 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 Condition cond,
106 TargetAddressStorageMode mode) {
Steve Block44f0eee2011-05-26 01:26:41 +0100107 // Block constant pool for the call instruction sequence.
108 BlockConstPoolScope block_const_pool(this);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000109 Label start;
110 bind(&start);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111
112 bool old_predictable_code_size = predictable_code_size();
113 if (mode == NEVER_INLINE_TARGET_ADDRESS) {
114 set_predictable_code_size(true);
115 }
116
117#ifdef DEBUG
118 // Check the expected size before generating code to ensure we assume the same
119 // constant pool availability (e.g., whether constant pool is full or not).
120 int expected_size = CallSize(target, rmode, cond);
121#endif
122
123 // Call sequence on V7 or later may be :
124 // movw ip, #... @ call address low 16
125 // movt ip, #... @ call address high 16
126 // blx ip
127 // @ return address
128 // Or for pre-V7 or values that may be back-patched
129 // to avoid ICache flushes:
130 // ldr ip, [pc, #...] @ call address
131 // blx ip
132 // @ return address
Steve Block6ded16b2010-05-10 14:33:55 +0100133
Steve Block44f0eee2011-05-26 01:26:41 +0100134 // Statement positions are expected to be recorded when the target
135 // address is loaded. The mov method will automatically record
136 // positions when pc is the target, since this is not the case here
137 // we have to do it explicitly.
138 positions_recorder()->WriteRecordedPositions();
Steve Block6ded16b2010-05-10 14:33:55 +0100139
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000140 mov(ip, Operand(reinterpret_cast<int32_t>(target), rmode));
Steve Block44f0eee2011-05-26 01:26:41 +0100141 blx(ip, cond);
Steve Block6ded16b2010-05-10 14:33:55 +0100142
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000143 DCHECK_EQ(expected_size, SizeOfCodeGeneratedSince(&start));
144 if (mode == NEVER_INLINE_TARGET_ADDRESS) {
145 set_predictable_code_size(old_predictable_code_size);
146 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000147}
148
149
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000150int MacroAssembler::CallSize(Handle<Code> code,
151 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000152 TypeFeedbackId ast_id,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000153 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154 AllowDeferredHandleDereference using_raw_address;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000155 return CallSize(reinterpret_cast<Address>(code.location()), rmode, cond);
Ben Murdoch257744e2011-11-30 15:57:28 +0000156}
157
158
159void MacroAssembler::Call(Handle<Code> code,
160 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161 TypeFeedbackId ast_id,
162 Condition cond,
163 TargetAddressStorageMode mode) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000164 Label start;
165 bind(&start);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166 DCHECK(RelocInfo::IsCodeTarget(rmode));
167 if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000168 SetRecordedAstId(ast_id);
169 rmode = RelocInfo::CODE_TARGET_WITH_ID;
170 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 // 'code' is always generated ARM code, never THUMB code
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172 AllowDeferredHandleDereference embedding_raw_address;
173 Call(reinterpret_cast<Address>(code.location()), rmode, cond, mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000174}
175
176
177void MacroAssembler::Ret(Condition cond) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000178 bx(lr, cond);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179}
180
181
Leon Clarkee46be812010-01-19 14:06:41 +0000182void MacroAssembler::Drop(int count, Condition cond) {
183 if (count > 0) {
184 add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond);
185 }
186}
187
188
Ben Murdochb0fe1622011-05-05 13:52:32 +0100189void MacroAssembler::Ret(int drop, Condition cond) {
190 Drop(drop, cond);
191 Ret(cond);
192}
193
194
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100195void MacroAssembler::Swap(Register reg1,
196 Register reg2,
197 Register scratch,
198 Condition cond) {
Steve Block6ded16b2010-05-10 14:33:55 +0100199 if (scratch.is(no_reg)) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100200 eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
201 eor(reg2, reg2, Operand(reg1), LeaveCC, cond);
202 eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
Steve Block6ded16b2010-05-10 14:33:55 +0100203 } else {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100204 mov(scratch, reg1, LeaveCC, cond);
205 mov(reg1, reg2, LeaveCC, cond);
206 mov(reg2, scratch, LeaveCC, cond);
Steve Block6ded16b2010-05-10 14:33:55 +0100207 }
208}
209
210
Leon Clarkee46be812010-01-19 14:06:41 +0000211void MacroAssembler::Call(Label* target) {
212 bl(target);
213}
214
215
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000216void MacroAssembler::Push(Handle<Object> handle) {
217 mov(ip, Operand(handle));
218 push(ip);
219}
220
221
Leon Clarkee46be812010-01-19 14:06:41 +0000222void MacroAssembler::Move(Register dst, Handle<Object> value) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000223 AllowDeferredHandleDereference smi_check;
224 if (value->IsSmi()) {
225 mov(dst, Operand(value));
226 } else {
227 DCHECK(value->IsHeapObject());
228 if (isolate()->heap()->InNewSpace(*value)) {
229 Handle<Cell> cell = isolate()->factory()->NewCell(value);
230 mov(dst, Operand(cell));
231 ldr(dst, FieldMemOperand(dst, Cell::kValueOffset));
232 } else {
233 mov(dst, Operand(value));
234 }
235 }
Leon Clarkee46be812010-01-19 14:06:41 +0000236}
Steve Blockd0582a62009-12-15 09:54:21 +0000237
238
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000239void MacroAssembler::Move(Register dst, Register src, Condition cond) {
Steve Block6ded16b2010-05-10 14:33:55 +0100240 if (!dst.is(src)) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000241 mov(dst, src, LeaveCC, cond);
Steve Block6ded16b2010-05-10 14:33:55 +0100242 }
243}
244
245
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246void MacroAssembler::Move(DwVfpRegister dst, DwVfpRegister src) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000247 if (!dst.is(src)) {
248 vmov(dst, src);
249 }
250}
251
252
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253void MacroAssembler::Mls(Register dst, Register src1, Register src2,
254 Register srcA, Condition cond) {
255 if (CpuFeatures::IsSupported(MLS)) {
256 CpuFeatureScope scope(this, MLS);
257 mls(dst, src1, src2, srcA, cond);
258 } else {
259 DCHECK(!srcA.is(ip));
260 mul(ip, src1, src2, LeaveCC, cond);
261 sub(dst, srcA, ip, LeaveCC, cond);
262 }
263}
264
265
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100266void MacroAssembler::And(Register dst, Register src1, const Operand& src2,
267 Condition cond) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800268 if (!src2.is_reg() &&
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000269 !src2.must_output_reloc_info(this) &&
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800270 src2.immediate() == 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000271 mov(dst, Operand::Zero(), LeaveCC, cond);
272 } else if (!(src2.instructions_required(this) == 1) &&
273 !src2.must_output_reloc_info(this) &&
Ben Murdoch8b112d22011-06-08 16:22:53 +0100274 CpuFeatures::IsSupported(ARMv7) &&
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275 base::bits::IsPowerOfTwo32(src2.immediate() + 1)) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000276 ubfx(dst, src1, 0,
277 WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800278 } else {
279 and_(dst, src1, src2, LeaveCC, cond);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100280 }
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100281}
282
283
284void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width,
285 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 DCHECK(lsb < 32);
287 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100288 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
289 and_(dst, src1, Operand(mask), LeaveCC, cond);
290 if (lsb != 0) {
291 mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond);
292 }
293 } else {
294 ubfx(dst, src1, lsb, width, cond);
295 }
296}
297
298
299void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width,
300 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 DCHECK(lsb < 32);
302 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100303 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
304 and_(dst, src1, Operand(mask), LeaveCC, cond);
305 int shift_up = 32 - lsb - width;
306 int shift_down = lsb + shift_up;
307 if (shift_up != 0) {
308 mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond);
309 }
310 if (shift_down != 0) {
311 mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond);
312 }
313 } else {
314 sbfx(dst, src1, lsb, width, cond);
315 }
316}
317
318
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100319void MacroAssembler::Bfi(Register dst,
320 Register src,
321 Register scratch,
322 int lsb,
323 int width,
324 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000325 DCHECK(0 <= lsb && lsb < 32);
326 DCHECK(0 <= width && width < 32);
327 DCHECK(lsb + width < 32);
328 DCHECK(!scratch.is(dst));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100329 if (width == 0) return;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000330 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100331 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
332 bic(dst, dst, Operand(mask));
333 and_(scratch, src, Operand((1 << width) - 1));
334 mov(scratch, Operand(scratch, LSL, lsb));
335 orr(dst, dst, scratch);
336 } else {
337 bfi(dst, src, lsb, width, cond);
338 }
339}
340
341
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000342void MacroAssembler::Bfc(Register dst, Register src, int lsb, int width,
343 Condition cond) {
344 DCHECK(lsb < 32);
345 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100346 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000347 bic(dst, src, Operand(mask));
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100348 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000349 Move(dst, src, cond);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100350 bfc(dst, lsb, width, cond);
351 }
352}
353
354
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100355void MacroAssembler::Usat(Register dst, int satpos, const Operand& src,
356 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000357 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
358 DCHECK(!dst.is(pc) && !src.rm().is(pc));
359 DCHECK((satpos >= 0) && (satpos <= 31));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100360
361 // These asserts are required to ensure compatibility with the ARMv7
362 // implementation.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363 DCHECK((src.shift_op() == ASR) || (src.shift_op() == LSL));
364 DCHECK(src.rs().is(no_reg));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100365
366 Label done;
367 int satval = (1 << satpos) - 1;
368
369 if (cond != al) {
370 b(NegateCondition(cond), &done); // Skip saturate if !condition.
371 }
372 if (!(src.is_reg() && dst.is(src.rm()))) {
373 mov(dst, src);
374 }
375 tst(dst, Operand(~satval));
376 b(eq, &done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000377 mov(dst, Operand::Zero(), LeaveCC, mi); // 0 if negative.
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100378 mov(dst, Operand(satval), LeaveCC, pl); // satval if positive.
379 bind(&done);
380 } else {
381 usat(dst, satpos, src, cond);
382 }
383}
384
385
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386void MacroAssembler::Load(Register dst,
387 const MemOperand& src,
388 Representation r) {
389 DCHECK(!r.IsDouble());
390 if (r.IsInteger8()) {
391 ldrsb(dst, src);
392 } else if (r.IsUInteger8()) {
393 ldrb(dst, src);
394 } else if (r.IsInteger16()) {
395 ldrsh(dst, src);
396 } else if (r.IsUInteger16()) {
397 ldrh(dst, src);
398 } else {
399 ldr(dst, src);
400 }
401}
402
403
404void MacroAssembler::Store(Register src,
405 const MemOperand& dst,
406 Representation r) {
407 DCHECK(!r.IsDouble());
408 if (r.IsInteger8() || r.IsUInteger8()) {
409 strb(src, dst);
410 } else if (r.IsInteger16() || r.IsUInteger16()) {
411 strh(src, dst);
412 } else {
413 if (r.IsHeapObject()) {
414 AssertNotSmi(src);
415 } else if (r.IsSmi()) {
416 AssertSmi(src);
417 }
418 str(src, dst);
419 }
420}
421
422
Steve Blocka7e24c12009-10-30 11:49:00 +0000423void MacroAssembler::LoadRoot(Register destination,
424 Heap::RootListIndex index,
425 Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000426 if (CpuFeatures::IsSupported(MOVW_MOVT_IMMEDIATE_LOADS) &&
427 isolate()->heap()->RootCanBeTreatedAsConstant(index) &&
428 !predictable_code_size()) {
429 // The CPU supports fast immediate values, and this root will never
430 // change. We will load it as a relocatable immediate value.
431 Handle<Object> root(&isolate()->heap()->roots_array_start()[index]);
432 mov(destination, Operand(root), LeaveCC, cond);
433 return;
434 }
Ben Murdochc7cc0282012-03-05 14:35:55 +0000435 ldr(destination, MemOperand(kRootRegister, index << kPointerSizeLog2), cond);
Steve Blocka7e24c12009-10-30 11:49:00 +0000436}
437
438
Kristian Monsen25f61362010-05-21 11:50:48 +0100439void MacroAssembler::StoreRoot(Register source,
440 Heap::RootListIndex index,
441 Condition cond) {
Ben Murdochc7cc0282012-03-05 14:35:55 +0000442 str(source, MemOperand(kRootRegister, index << kPointerSizeLog2), cond);
443}
444
445
Steve Block6ded16b2010-05-10 14:33:55 +0100446void MacroAssembler::InNewSpace(Register object,
447 Register scratch,
Steve Block1e0659c2011-05-24 12:43:12 +0100448 Condition cond,
Steve Block6ded16b2010-05-10 14:33:55 +0100449 Label* branch) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 DCHECK(cond == eq || cond == ne);
Steve Block44f0eee2011-05-26 01:26:41 +0100451 and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate())));
452 cmp(scratch, Operand(ExternalReference::new_space_start(isolate())));
Steve Block1e0659c2011-05-24 12:43:12 +0100453 b(cond, branch);
Steve Block6ded16b2010-05-10 14:33:55 +0100454}
455
456
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100457void MacroAssembler::RecordWriteField(
458 Register object,
459 int offset,
460 Register value,
461 Register dst,
462 LinkRegisterStatus lr_status,
463 SaveFPRegsMode save_fp,
464 RememberedSetAction remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000465 SmiCheck smi_check,
466 PointersToHereCheck pointers_to_here_check_for_value) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100467 // First, check if a write barrier is even needed. The tests below
468 // catch stores of Smis.
Steve Block6ded16b2010-05-10 14:33:55 +0100469 Label done;
470
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100471 // Skip barrier if writing a smi.
472 if (smi_check == INLINE_SMI_CHECK) {
473 JumpIfSmi(value, &done);
474 }
Steve Block6ded16b2010-05-10 14:33:55 +0100475
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100476 // Although the object register is tagged, the offset is relative to the start
477 // of the object, so so offset must be a multiple of kPointerSize.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000478 DCHECK(IsAligned(offset, kPointerSize));
Steve Block8defd9f2010-07-08 12:39:36 +0100479
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100480 add(dst, object, Operand(offset - kHeapObjectTag));
481 if (emit_debug_code()) {
482 Label ok;
483 tst(dst, Operand((1 << kPointerSizeLog2) - 1));
484 b(eq, &ok);
485 stop("Unaligned cell in write barrier");
486 bind(&ok);
487 }
488
489 RecordWrite(object,
490 dst,
491 value,
492 lr_status,
493 save_fp,
494 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000495 OMIT_SMI_CHECK,
496 pointers_to_here_check_for_value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000497
498 bind(&done);
Leon Clarke4515c472010-02-03 11:58:03 +0000499
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100500 // Clobber clobbered input registers when running with the debug-code flag
Leon Clarke4515c472010-02-03 11:58:03 +0000501 // turned on to provoke errors.
Steve Block44f0eee2011-05-26 01:26:41 +0100502 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000503 mov(value, Operand(bit_cast<int32_t>(kZapValue + 4)));
504 mov(dst, Operand(bit_cast<int32_t>(kZapValue + 8)));
505 }
506}
507
508
509// Will clobber 4 registers: object, map, dst, ip. The
510// register 'object' contains a heap object pointer.
511void MacroAssembler::RecordWriteForMap(Register object,
512 Register map,
513 Register dst,
514 LinkRegisterStatus lr_status,
515 SaveFPRegsMode fp_mode) {
516 if (emit_debug_code()) {
517 ldr(dst, FieldMemOperand(map, HeapObject::kMapOffset));
518 cmp(dst, Operand(isolate()->factory()->meta_map()));
519 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
520 }
521
522 if (!FLAG_incremental_marking) {
523 return;
524 }
525
526 if (emit_debug_code()) {
527 ldr(ip, FieldMemOperand(object, HeapObject::kMapOffset));
528 cmp(ip, map);
529 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
530 }
531
532 Label done;
533
534 // A single check of the map's pages interesting flag suffices, since it is
535 // only set during incremental collection, and then it's also guaranteed that
536 // the from object's page's interesting flag is also set. This optimization
537 // relies on the fact that maps can never be in new space.
538 CheckPageFlag(map,
539 map, // Used as scratch.
540 MemoryChunk::kPointersToHereAreInterestingMask,
541 eq,
542 &done);
543
544 add(dst, object, Operand(HeapObject::kMapOffset - kHeapObjectTag));
545 if (emit_debug_code()) {
546 Label ok;
547 tst(dst, Operand((1 << kPointerSizeLog2) - 1));
548 b(eq, &ok);
549 stop("Unaligned cell in write barrier");
550 bind(&ok);
551 }
552
553 // Record the actual write.
554 if (lr_status == kLRHasNotBeenSaved) {
555 push(lr);
556 }
557 RecordWriteStub stub(isolate(), object, map, dst, OMIT_REMEMBERED_SET,
558 fp_mode);
559 CallStub(&stub);
560 if (lr_status == kLRHasNotBeenSaved) {
561 pop(lr);
562 }
563
564 bind(&done);
565
566 // Count number of write barriers in generated code.
567 isolate()->counters()->write_barriers_static()->Increment();
568 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, ip, dst);
569
570 // Clobber clobbered registers when running with the debug-code flag
571 // turned on to provoke errors.
572 if (emit_debug_code()) {
573 mov(dst, Operand(bit_cast<int32_t>(kZapValue + 12)));
574 mov(map, Operand(bit_cast<int32_t>(kZapValue + 16)));
Leon Clarke4515c472010-02-03 11:58:03 +0000575 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000576}
577
578
Steve Block8defd9f2010-07-08 12:39:36 +0100579// Will clobber 4 registers: object, address, scratch, ip. The
580// register 'object' contains a heap object pointer. The heap object
581// tag is shifted away.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000582void MacroAssembler::RecordWrite(
583 Register object,
584 Register address,
585 Register value,
586 LinkRegisterStatus lr_status,
587 SaveFPRegsMode fp_mode,
588 RememberedSetAction remembered_set_action,
589 SmiCheck smi_check,
590 PointersToHereCheck pointers_to_here_check_for_value) {
591 DCHECK(!object.is(value));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100592 if (emit_debug_code()) {
593 ldr(ip, MemOperand(address));
594 cmp(ip, value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000595 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100596 }
Steve Block8defd9f2010-07-08 12:39:36 +0100597
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000598 if (remembered_set_action == OMIT_REMEMBERED_SET &&
599 !FLAG_incremental_marking) {
600 return;
601 }
602
603 // First, check if a write barrier is even needed. The tests below
604 // catch stores of smis and stores into the young generation.
Steve Block8defd9f2010-07-08 12:39:36 +0100605 Label done;
606
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100607 if (smi_check == INLINE_SMI_CHECK) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000608 JumpIfSmi(value, &done);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100609 }
610
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000611 if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) {
612 CheckPageFlag(value,
613 value, // Used as scratch.
614 MemoryChunk::kPointersToHereAreInterestingMask,
615 eq,
616 &done);
617 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100618 CheckPageFlag(object,
619 value, // Used as scratch.
620 MemoryChunk::kPointersFromHereAreInterestingMask,
621 eq,
622 &done);
Steve Block8defd9f2010-07-08 12:39:36 +0100623
624 // Record the actual write.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100625 if (lr_status == kLRHasNotBeenSaved) {
626 push(lr);
627 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000628 RecordWriteStub stub(isolate(), object, value, address, remembered_set_action,
629 fp_mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100630 CallStub(&stub);
631 if (lr_status == kLRHasNotBeenSaved) {
632 pop(lr);
633 }
Steve Block8defd9f2010-07-08 12:39:36 +0100634
635 bind(&done);
636
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000637 // Count number of write barriers in generated code.
638 isolate()->counters()->write_barriers_static()->Increment();
639 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, ip,
640 value);
641
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100642 // Clobber clobbered registers when running with the debug-code flag
Steve Block8defd9f2010-07-08 12:39:36 +0100643 // turned on to provoke errors.
Steve Block44f0eee2011-05-26 01:26:41 +0100644 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000645 mov(address, Operand(bit_cast<int32_t>(kZapValue + 12)));
646 mov(value, Operand(bit_cast<int32_t>(kZapValue + 16)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100647 }
648}
649
650
651void MacroAssembler::RememberedSetHelper(Register object, // For debug tests.
652 Register address,
653 Register scratch,
654 SaveFPRegsMode fp_mode,
655 RememberedSetFinalAction and_then) {
656 Label done;
657 if (emit_debug_code()) {
658 Label ok;
659 JumpIfNotInNewSpace(object, scratch, &ok);
660 stop("Remembered set pointer is in new space");
661 bind(&ok);
662 }
663 // Load store buffer top.
664 ExternalReference store_buffer =
665 ExternalReference::store_buffer_top(isolate());
666 mov(ip, Operand(store_buffer));
667 ldr(scratch, MemOperand(ip));
668 // Store pointer to buffer and increment buffer top.
669 str(address, MemOperand(scratch, kPointerSize, PostIndex));
670 // Write back new top of buffer.
671 str(scratch, MemOperand(ip));
672 // Call stub on end of buffer.
673 // Check for end of buffer.
674 tst(scratch, Operand(StoreBuffer::kStoreBufferOverflowBit));
675 if (and_then == kFallThroughAtEnd) {
676 b(eq, &done);
677 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000678 DCHECK(and_then == kReturnAtEnd);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100679 Ret(eq);
680 }
681 push(lr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000682 StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100683 CallStub(&store_buffer_overflow);
684 pop(lr);
685 bind(&done);
686 if (and_then == kReturnAtEnd) {
687 Ret();
Steve Block8defd9f2010-07-08 12:39:36 +0100688 }
689}
690
691
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000692void MacroAssembler::PushFixedFrame(Register marker_reg) {
693 DCHECK(!marker_reg.is_valid() || marker_reg.code() < cp.code());
694 stm(db_w, sp, (marker_reg.is_valid() ? marker_reg.bit() : 0) |
695 cp.bit() |
696 (FLAG_enable_ool_constant_pool ? pp.bit() : 0) |
697 fp.bit() |
698 lr.bit());
699}
700
701
702void MacroAssembler::PopFixedFrame(Register marker_reg) {
703 DCHECK(!marker_reg.is_valid() || marker_reg.code() < cp.code());
704 ldm(ia_w, sp, (marker_reg.is_valid() ? marker_reg.bit() : 0) |
705 cp.bit() |
706 (FLAG_enable_ool_constant_pool ? pp.bit() : 0) |
707 fp.bit() |
708 lr.bit());
709}
710
711
Ben Murdochb0fe1622011-05-05 13:52:32 +0100712// Push and pop all registers that can hold pointers.
713void MacroAssembler::PushSafepointRegisters() {
714 // Safepoints expect a block of contiguous register values starting with r0:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000715 DCHECK(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100716 // Safepoints expect a block of kNumSafepointRegisters values on the
717 // stack, so adjust the stack for unsaved registers.
718 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000719 DCHECK(num_unsaved >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100720 sub(sp, sp, Operand(num_unsaved * kPointerSize));
721 stm(db_w, sp, kSafepointSavedRegisters);
722}
723
724
725void MacroAssembler::PopSafepointRegisters() {
726 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
727 ldm(ia_w, sp, kSafepointSavedRegisters);
728 add(sp, sp, Operand(num_unsaved * kPointerSize));
729}
730
731
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100732void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) {
733 str(src, SafepointRegisterSlot(dst));
Steve Block1e0659c2011-05-24 12:43:12 +0100734}
735
736
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100737void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) {
738 ldr(dst, SafepointRegisterSlot(src));
Steve Block1e0659c2011-05-24 12:43:12 +0100739}
740
741
Ben Murdochb0fe1622011-05-05 13:52:32 +0100742int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
743 // The registers are pushed starting with the highest encoding,
744 // which means that lowest encodings are closest to the stack pointer.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000745 DCHECK(reg_code >= 0 && reg_code < kNumSafepointRegisters);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100746 return reg_code;
747}
748
749
Steve Block1e0659c2011-05-24 12:43:12 +0100750MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
751 return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
752}
753
754
755MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000756 // Number of d-regs not known at snapshot time.
757 DCHECK(!serializer_enabled());
Steve Block1e0659c2011-05-24 12:43:12 +0100758 // General purpose registers are pushed last on the stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759 int doubles_size = DwVfpRegister::NumAllocatableRegisters() * kDoubleSize;
Steve Block1e0659c2011-05-24 12:43:12 +0100760 int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize;
761 return MemOperand(sp, doubles_size + register_offset);
762}
763
764
Leon Clarkef7060e22010-06-03 12:02:55 +0100765void MacroAssembler::Ldrd(Register dst1, Register dst2,
766 const MemOperand& src, Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000767 DCHECK(src.rm().is(no_reg));
768 DCHECK(!dst1.is(lr)); // r14.
Leon Clarkef7060e22010-06-03 12:02:55 +0100769
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000770 // V8 does not use this addressing mode, so the fallback code
771 // below doesn't support it yet.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000772 DCHECK((src.am() != PreIndex) && (src.am() != NegPreIndex));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000773
Leon Clarkef7060e22010-06-03 12:02:55 +0100774 // Generate two ldr instructions if ldrd is not available.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000775 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() &&
776 (dst1.code() % 2 == 0) && (dst1.code() + 1 == dst2.code())) {
777 CpuFeatureScope scope(this, ARMv7);
Leon Clarkef7060e22010-06-03 12:02:55 +0100778 ldrd(dst1, dst2, src, cond);
779 } else {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000780 if ((src.am() == Offset) || (src.am() == NegOffset)) {
781 MemOperand src2(src);
782 src2.set_offset(src2.offset() + 4);
783 if (dst1.is(src.rn())) {
784 ldr(dst2, src2, cond);
785 ldr(dst1, src, cond);
786 } else {
787 ldr(dst1, src, cond);
788 ldr(dst2, src2, cond);
789 }
790 } else { // PostIndex or NegPostIndex.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791 DCHECK((src.am() == PostIndex) || (src.am() == NegPostIndex));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000792 if (dst1.is(src.rn())) {
793 ldr(dst2, MemOperand(src.rn(), 4, Offset), cond);
794 ldr(dst1, src, cond);
795 } else {
796 MemOperand src2(src);
797 src2.set_offset(src2.offset() - 4);
798 ldr(dst1, MemOperand(src.rn(), 4, PostIndex), cond);
799 ldr(dst2, src2, cond);
800 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100801 }
802 }
803}
804
805
806void MacroAssembler::Strd(Register src1, Register src2,
807 const MemOperand& dst, Condition cond) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000808 DCHECK(dst.rm().is(no_reg));
809 DCHECK(!src1.is(lr)); // r14.
Leon Clarkef7060e22010-06-03 12:02:55 +0100810
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000811 // V8 does not use this addressing mode, so the fallback code
812 // below doesn't support it yet.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000813 DCHECK((dst.am() != PreIndex) && (dst.am() != NegPreIndex));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000814
Leon Clarkef7060e22010-06-03 12:02:55 +0100815 // Generate two str instructions if strd is not available.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000816 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() &&
817 (src1.code() % 2 == 0) && (src1.code() + 1 == src2.code())) {
818 CpuFeatureScope scope(this, ARMv7);
Leon Clarkef7060e22010-06-03 12:02:55 +0100819 strd(src1, src2, dst, cond);
820 } else {
821 MemOperand dst2(dst);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000822 if ((dst.am() == Offset) || (dst.am() == NegOffset)) {
823 dst2.set_offset(dst2.offset() + 4);
824 str(src1, dst, cond);
825 str(src2, dst2, cond);
826 } else { // PostIndex or NegPostIndex.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000827 DCHECK((dst.am() == PostIndex) || (dst.am() == NegPostIndex));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000828 dst2.set_offset(dst2.offset() - 4);
829 str(src1, MemOperand(dst.rn(), 4, PostIndex), cond);
830 str(src2, dst2, cond);
831 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100832 }
833}
834
835
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000836void MacroAssembler::VFPEnsureFPSCRState(Register scratch) {
837 // If needed, restore wanted bits of FPSCR.
838 Label fpscr_done;
839 vmrs(scratch);
840 if (emit_debug_code()) {
841 Label rounding_mode_correct;
842 tst(scratch, Operand(kVFPRoundingModeMask));
843 b(eq, &rounding_mode_correct);
844 // Don't call Assert here, since Runtime_Abort could re-enter here.
845 stop("Default rounding mode not set");
846 bind(&rounding_mode_correct);
847 }
848 tst(scratch, Operand(kVFPDefaultNaNModeControlBit));
849 b(ne, &fpscr_done);
850 orr(scratch, scratch, Operand(kVFPDefaultNaNModeControlBit));
851 vmsr(scratch);
852 bind(&fpscr_done);
853}
854
855
856void MacroAssembler::VFPCanonicalizeNaN(const DwVfpRegister dst,
857 const DwVfpRegister src,
858 const Condition cond) {
859 vsub(dst, src, kDoubleRegZero, cond);
Ben Murdochb8e0da22011-05-16 14:20:40 +0100860}
861
862
863void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
864 const DwVfpRegister src2,
865 const Condition cond) {
866 // Compare and move FPSCR flags to the normal condition flags.
867 VFPCompareAndLoadFlags(src1, src2, pc, cond);
868}
869
870void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
871 const double src2,
872 const Condition cond) {
873 // Compare and move FPSCR flags to the normal condition flags.
874 VFPCompareAndLoadFlags(src1, src2, pc, cond);
875}
876
877
878void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
879 const DwVfpRegister src2,
880 const Register fpscr_flags,
881 const Condition cond) {
882 // Compare and load FPSCR.
883 vcmp(src1, src2, cond);
884 vmrs(fpscr_flags, cond);
885}
886
887void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
888 const double src2,
889 const Register fpscr_flags,
890 const Condition cond) {
891 // Compare and load FPSCR.
892 vcmp(src1, src2, cond);
893 vmrs(fpscr_flags, cond);
Ben Murdoch086aeea2011-05-13 15:57:08 +0100894}
895
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000896void MacroAssembler::Vmov(const DwVfpRegister dst,
897 const double imm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000898 const Register scratch) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000899 static const DoubleRepresentation minus_zero(-0.0);
900 static const DoubleRepresentation zero(0.0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901 DoubleRepresentation value_rep(imm);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000902 // Handle special values first.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000903 if (value_rep == zero) {
904 vmov(dst, kDoubleRegZero);
905 } else if (value_rep == minus_zero) {
906 vneg(dst, kDoubleRegZero);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000907 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000908 vmov(dst, imm, scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000909 }
910}
911
Ben Murdoch086aeea2011-05-13 15:57:08 +0100912
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000913void MacroAssembler::VmovHigh(Register dst, DwVfpRegister src) {
914 if (src.code() < 16) {
915 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
916 vmov(dst, loc.high());
917 } else {
918 vmov(dst, VmovIndexHi, src);
919 }
920}
921
922
923void MacroAssembler::VmovHigh(DwVfpRegister dst, Register src) {
924 if (dst.code() < 16) {
925 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
926 vmov(loc.high(), src);
927 } else {
928 vmov(dst, VmovIndexHi, src);
929 }
930}
931
932
933void MacroAssembler::VmovLow(Register dst, DwVfpRegister src) {
934 if (src.code() < 16) {
935 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
936 vmov(dst, loc.low());
937 } else {
938 vmov(dst, VmovIndexLo, src);
939 }
940}
941
942
943void MacroAssembler::VmovLow(DwVfpRegister dst, Register src) {
944 if (dst.code() < 16) {
945 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
946 vmov(loc.low(), src);
947 } else {
948 vmov(dst, VmovIndexLo, src);
949 }
950}
951
952
953void MacroAssembler::LoadConstantPoolPointerRegister() {
954 if (FLAG_enable_ool_constant_pool) {
955 int constant_pool_offset = Code::kConstantPoolOffset - Code::kHeaderSize -
956 pc_offset() - Instruction::kPCReadOffset;
957 DCHECK(ImmediateFitsAddrMode2Instruction(constant_pool_offset));
958 ldr(pp, MemOperand(pc, constant_pool_offset));
959 }
960}
961
962
963void MacroAssembler::StubPrologue() {
964 PushFixedFrame();
965 Push(Smi::FromInt(StackFrame::STUB));
966 // Adjust FP to point to saved FP.
967 add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
968 if (FLAG_enable_ool_constant_pool) {
969 LoadConstantPoolPointerRegister();
970 set_constant_pool_available(true);
971 }
972}
973
974
975void MacroAssembler::Prologue(bool code_pre_aging) {
976 { PredictableCodeSizeScope predictible_code_size_scope(
977 this, kNoCodeAgeSequenceLength);
978 // The following three instructions must remain together and unmodified
979 // for code aging to work properly.
980 if (code_pre_aging) {
981 // Pre-age the code.
982 Code* stub = Code::GetPreAgedCodeAgeStub(isolate());
983 add(r0, pc, Operand(-8));
984 ldr(pc, MemOperand(pc, -4));
985 emit_code_stub_address(stub);
986 } else {
987 PushFixedFrame(r1);
988 nop(ip.code());
989 // Adjust FP to point to saved FP.
990 add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
991 }
992 }
993 if (FLAG_enable_ool_constant_pool) {
994 LoadConstantPoolPointerRegister();
995 set_constant_pool_available(true);
996 }
997}
998
999
1000void MacroAssembler::EnterFrame(StackFrame::Type type,
1001 bool load_constant_pool) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001002 // r0-r3: preserved
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 PushFixedFrame();
1004 if (FLAG_enable_ool_constant_pool && load_constant_pool) {
1005 LoadConstantPoolPointerRegister();
1006 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001007 mov(ip, Operand(Smi::FromInt(type)));
1008 push(ip);
1009 mov(ip, Operand(CodeObject()));
1010 push(ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001011 // Adjust FP to point to saved FP.
1012 add(fp, sp,
1013 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
Steve Blocka7e24c12009-10-30 11:49:00 +00001014}
1015
1016
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001017int MacroAssembler::LeaveFrame(StackFrame::Type type) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001018 // r0: preserved
1019 // r1: preserved
1020 // r2: preserved
1021
1022 // Drop the execution stack down to the frame pointer and restore
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001023 // the caller frame pointer, return address and constant pool pointer
1024 // (if FLAG_enable_ool_constant_pool).
1025 int frame_ends;
1026 if (FLAG_enable_ool_constant_pool) {
1027 add(sp, fp, Operand(StandardFrameConstants::kConstantPoolOffset));
1028 frame_ends = pc_offset();
1029 ldm(ia_w, sp, pp.bit() | fp.bit() | lr.bit());
1030 } else {
1031 mov(sp, fp);
1032 frame_ends = pc_offset();
1033 ldm(ia_w, sp, fp.bit() | lr.bit());
1034 }
1035 return frame_ends;
Steve Blocka7e24c12009-10-30 11:49:00 +00001036}
1037
1038
Steve Block1e0659c2011-05-24 12:43:12 +01001039void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001040 // Set up the frame structure on the stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001041 DCHECK_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement);
1042 DCHECK_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset);
1043 DCHECK_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset);
Steve Block1e0659c2011-05-24 12:43:12 +01001044 Push(lr, fp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001045 mov(fp, Operand(sp)); // Set up new frame pointer.
Steve Block1e0659c2011-05-24 12:43:12 +01001046 // Reserve room for saved entry sp and code object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047 sub(sp, sp, Operand(ExitFrameConstants::kFrameSize));
Steve Block44f0eee2011-05-26 01:26:41 +01001048 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001049 mov(ip, Operand::Zero());
Steve Block1e0659c2011-05-24 12:43:12 +01001050 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
1051 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001052 if (FLAG_enable_ool_constant_pool) {
1053 str(pp, MemOperand(fp, ExitFrameConstants::kConstantPoolOffset));
1054 }
Andrei Popescu402d9372010-02-26 13:31:12 +00001055 mov(ip, Operand(CodeObject()));
Steve Block1e0659c2011-05-24 12:43:12 +01001056 str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001057
1058 // Save the frame pointer and the context in top.
Ben Murdoch589d6972011-11-30 16:04:58 +00001059 mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Steve Blocka7e24c12009-10-30 11:49:00 +00001060 str(fp, MemOperand(ip));
Ben Murdoch589d6972011-11-30 16:04:58 +00001061 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
Steve Blocka7e24c12009-10-30 11:49:00 +00001062 str(cp, MemOperand(ip));
1063
Ben Murdochb0fe1622011-05-05 13:52:32 +01001064 // Optionally save all double registers.
1065 if (save_doubles) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001066 SaveFPRegs(sp, ip);
Steve Block1e0659c2011-05-24 12:43:12 +01001067 // Note that d0 will be accessible at
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001068 // fp - ExitFrameConstants::kFrameSize -
1069 // DwVfpRegister::kMaxNumRegisters * kDoubleSize,
1070 // since the sp slot, code slot and constant pool slot (if
1071 // FLAG_enable_ool_constant_pool) were pushed after the fp.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001072 }
Steve Block1e0659c2011-05-24 12:43:12 +01001073
1074 // Reserve place for the return address and stack space and align the frame
1075 // preparing for calling the runtime function.
1076 const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1077 sub(sp, sp, Operand((stack_space + 1) * kPointerSize));
1078 if (frame_alignment > 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001079 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Steve Block1e0659c2011-05-24 12:43:12 +01001080 and_(sp, sp, Operand(-frame_alignment));
1081 }
1082
1083 // Set the exit frame sp value to point just before the return address
1084 // location.
1085 add(ip, sp, Operand(kPointerSize));
1086 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001087}
1088
1089
Steve Block6ded16b2010-05-10 14:33:55 +01001090void MacroAssembler::InitializeNewString(Register string,
1091 Register length,
1092 Heap::RootListIndex map_index,
1093 Register scratch1,
1094 Register scratch2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001095 SmiTag(scratch1, length);
Steve Block6ded16b2010-05-10 14:33:55 +01001096 LoadRoot(scratch2, map_index);
1097 str(scratch1, FieldMemOperand(string, String::kLengthOffset));
1098 mov(scratch1, Operand(String::kEmptyHashField));
1099 str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
1100 str(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
1101}
1102
1103
1104int MacroAssembler::ActivationFrameAlignment() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001105#if V8_HOST_ARCH_ARM
Steve Blocka7e24c12009-10-30 11:49:00 +00001106 // Running on the real platform. Use the alignment as mandated by the local
1107 // environment.
1108 // Note: This will break if we ever start generating snapshots on one ARM
1109 // platform for another ARM platform with a different alignment.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001110 return base::OS::ActivationFrameAlignment();
1111#else // V8_HOST_ARCH_ARM
Steve Blocka7e24c12009-10-30 11:49:00 +00001112 // If we are using the simulator then we should always align to the expected
1113 // alignment. As the simulator is used to generate snapshots we do not know
Steve Block6ded16b2010-05-10 14:33:55 +01001114 // if the target platform will need alignment, so this is controlled from a
1115 // flag.
1116 return FLAG_sim_stack_alignment;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001117#endif // V8_HOST_ARCH_ARM
Steve Blocka7e24c12009-10-30 11:49:00 +00001118}
1119
1120
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001121void MacroAssembler::LeaveExitFrame(bool save_doubles,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001122 Register argument_count,
1123 bool restore_context) {
1124 ConstantPoolUnavailableScope constant_pool_unavailable(this);
1125
Ben Murdochb0fe1622011-05-05 13:52:32 +01001126 // Optionally restore all double registers.
1127 if (save_doubles) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001128 // Calculate the stack location of the saved doubles and restore them.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129 const int offset = ExitFrameConstants::kFrameSize;
1130 sub(r3, fp,
1131 Operand(offset + DwVfpRegister::kMaxNumRegisters * kDoubleSize));
1132 RestoreFPRegs(r3, ip);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001133 }
1134
Steve Blocka7e24c12009-10-30 11:49:00 +00001135 // Clear top frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001136 mov(r3, Operand::Zero());
Ben Murdoch589d6972011-11-30 16:04:58 +00001137 mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
Steve Blocka7e24c12009-10-30 11:49:00 +00001138 str(r3, MemOperand(ip));
1139
1140 // Restore current context from top and clear it in debug mode.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001141 if (restore_context) {
1142 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
1143 ldr(cp, MemOperand(ip));
1144 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001145#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001146 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
Steve Blocka7e24c12009-10-30 11:49:00 +00001147 str(r3, MemOperand(ip));
1148#endif
1149
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001150 // Tear down the exit frame, pop the arguments, and return.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001151 if (FLAG_enable_ool_constant_pool) {
1152 ldr(pp, MemOperand(fp, ExitFrameConstants::kConstantPoolOffset));
1153 }
Steve Block1e0659c2011-05-24 12:43:12 +01001154 mov(sp, Operand(fp));
1155 ldm(ia_w, sp, fp.bit() | lr.bit());
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001156 if (argument_count.is_valid()) {
1157 add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2));
1158 }
1159}
1160
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001161
1162void MacroAssembler::MovFromFloatResult(const DwVfpRegister dst) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001163 if (use_eabi_hardfloat()) {
1164 Move(dst, d0);
1165 } else {
1166 vmov(dst, r0, r1);
1167 }
1168}
1169
1170
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001171// On ARM this is just a synonym to make the purpose clear.
1172void MacroAssembler::MovFromFloatParameter(DwVfpRegister dst) {
1173 MovFromFloatResult(dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001174}
1175
1176
1177void MacroAssembler::InvokePrologue(const ParameterCount& expected,
1178 const ParameterCount& actual,
1179 Handle<Code> code_constant,
1180 Register code_reg,
1181 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001182 bool* definitely_mismatches,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001183 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001184 const CallWrapper& call_wrapper) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001185 bool definitely_matches = false;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001186 *definitely_mismatches = false;
Steve Blocka7e24c12009-10-30 11:49:00 +00001187 Label regular_invoke;
1188
1189 // Check whether the expected and actual arguments count match. If not,
1190 // setup registers according to contract with ArgumentsAdaptorTrampoline:
1191 // r0: actual arguments count
1192 // r1: function (passed through to callee)
1193 // r2: expected arguments count
Steve Blocka7e24c12009-10-30 11:49:00 +00001194
1195 // The code below is made a lot easier because the calling code already sets
1196 // up actual and expected registers according to the contract if values are
1197 // passed in registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001198 DCHECK(actual.is_immediate() || actual.reg().is(r0));
1199 DCHECK(expected.is_immediate() || expected.reg().is(r2));
1200 DCHECK((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3));
Steve Blocka7e24c12009-10-30 11:49:00 +00001201
1202 if (expected.is_immediate()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001203 DCHECK(actual.is_immediate());
Steve Blocka7e24c12009-10-30 11:49:00 +00001204 if (expected.immediate() == actual.immediate()) {
1205 definitely_matches = true;
1206 } else {
1207 mov(r0, Operand(actual.immediate()));
1208 const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
1209 if (expected.immediate() == sentinel) {
1210 // Don't worry about adapting arguments for builtins that
1211 // don't want that done. Skip adaption code by making it look
1212 // like we have a match between expected and actual number of
1213 // arguments.
1214 definitely_matches = true;
1215 } else {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001216 *definitely_mismatches = true;
Steve Blocka7e24c12009-10-30 11:49:00 +00001217 mov(r2, Operand(expected.immediate()));
1218 }
1219 }
1220 } else {
1221 if (actual.is_immediate()) {
1222 cmp(expected.reg(), Operand(actual.immediate()));
1223 b(eq, &regular_invoke);
1224 mov(r0, Operand(actual.immediate()));
1225 } else {
1226 cmp(expected.reg(), Operand(actual.reg()));
1227 b(eq, &regular_invoke);
1228 }
1229 }
1230
1231 if (!definitely_matches) {
1232 if (!code_constant.is_null()) {
1233 mov(r3, Operand(code_constant));
1234 add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
1235 }
1236
1237 Handle<Code> adaptor =
Steve Block44f0eee2011-05-26 01:26:41 +01001238 isolate()->builtins()->ArgumentsAdaptorTrampoline();
Steve Blocka7e24c12009-10-30 11:49:00 +00001239 if (flag == CALL_FUNCTION) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001240 call_wrapper.BeforeCall(CallSize(adaptor));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001241 Call(adaptor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001242 call_wrapper.AfterCall();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001243 if (!*definitely_mismatches) {
1244 b(done);
1245 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001246 } else {
1247 Jump(adaptor, RelocInfo::CODE_TARGET);
1248 }
1249 bind(&regular_invoke);
1250 }
1251}
1252
1253
1254void MacroAssembler::InvokeCode(Register code,
1255 const ParameterCount& expected,
1256 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001257 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001258 const CallWrapper& call_wrapper) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001259 // You can't call a function without a valid frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001260 DCHECK(flag == JUMP_FUNCTION || has_frame());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001261
Steve Blocka7e24c12009-10-30 11:49:00 +00001262 Label done;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001263 bool definitely_mismatches = false;
1264 InvokePrologue(expected, actual, Handle<Code>::null(), code,
1265 &done, &definitely_mismatches, flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001266 call_wrapper);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001267 if (!definitely_mismatches) {
1268 if (flag == CALL_FUNCTION) {
1269 call_wrapper.BeforeCall(CallSize(code));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001270 Call(code);
1271 call_wrapper.AfterCall();
1272 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001273 DCHECK(flag == JUMP_FUNCTION);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001274 Jump(code);
1275 }
Ben Murdoch85b71792012-04-11 18:30:58 +01001276
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001277 // Continue here if InvokePrologue does handle the invocation due to
1278 // mismatched parameter counts.
1279 bind(&done);
1280 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001281}
1282
1283
Steve Blocka7e24c12009-10-30 11:49:00 +00001284void MacroAssembler::InvokeFunction(Register fun,
1285 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001286 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001287 const CallWrapper& call_wrapper) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001288 // You can't call a function without a valid frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001289 DCHECK(flag == JUMP_FUNCTION || has_frame());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001290
Steve Blocka7e24c12009-10-30 11:49:00 +00001291 // Contract with called JS functions requires that function is passed in r1.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001292 DCHECK(fun.is(r1));
Steve Blocka7e24c12009-10-30 11:49:00 +00001293
1294 Register expected_reg = r2;
1295 Register code_reg = r3;
1296
1297 ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
1298 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
1299 ldr(expected_reg,
1300 FieldMemOperand(code_reg,
1301 SharedFunctionInfo::kFormalParameterCountOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001302 SmiUntag(expected_reg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001303 ldr(code_reg,
Steve Block791712a2010-08-27 10:21:07 +01001304 FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001305
1306 ParameterCount expected(expected_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001307 InvokeCode(code_reg, expected, actual, flag, call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001308}
1309
1310
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001311void MacroAssembler::InvokeFunction(Register function,
1312 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +00001313 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +00001314 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001315 const CallWrapper& call_wrapper) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001316 // You can't call a function without a valid frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001317 DCHECK(flag == JUMP_FUNCTION || has_frame());
1318
1319 // Contract with called JS functions requires that function is passed in r1.
1320 DCHECK(function.is(r1));
Andrei Popescu402d9372010-02-26 13:31:12 +00001321
1322 // Get the function and setup the context.
Andrei Popescu402d9372010-02-26 13:31:12 +00001323 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
1324
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001325 // We call indirectly through the code field in the function to
1326 // allow recompilation to take effect without changing any of the
1327 // call sites.
1328 ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001329 InvokeCode(r3, expected, actual, flag, call_wrapper);
1330}
1331
1332
1333void MacroAssembler::InvokeFunction(Handle<JSFunction> function,
1334 const ParameterCount& expected,
1335 const ParameterCount& actual,
1336 InvokeFlag flag,
1337 const CallWrapper& call_wrapper) {
1338 Move(r1, function);
1339 InvokeFunction(r1, expected, actual, flag, call_wrapper);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001340}
1341
1342
1343void MacroAssembler::IsObjectJSObjectType(Register heap_object,
1344 Register map,
1345 Register scratch,
1346 Label* fail) {
1347 ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
1348 IsInstanceJSObjectType(map, scratch, fail);
1349}
1350
1351
1352void MacroAssembler::IsInstanceJSObjectType(Register map,
1353 Register scratch,
1354 Label* fail) {
1355 ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001356 cmp(scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001357 b(lt, fail);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001358 cmp(scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001359 b(gt, fail);
1360}
1361
1362
1363void MacroAssembler::IsObjectJSStringType(Register object,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001364 Register scratch,
1365 Label* fail) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001366 DCHECK(kNotStringTag != 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001367
1368 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
1369 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1370 tst(scratch, Operand(kIsNotStringMask));
Steve Block1e0659c2011-05-24 12:43:12 +01001371 b(ne, fail);
Andrei Popescu402d9372010-02-26 13:31:12 +00001372}
1373
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001374
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001375void MacroAssembler::IsObjectNameType(Register object,
1376 Register scratch,
1377 Label* fail) {
1378 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
1379 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1380 cmp(scratch, Operand(LAST_NAME_TYPE));
1381 b(hi, fail);
1382}
1383
1384
Andrei Popescu402d9372010-02-26 13:31:12 +00001385void MacroAssembler::DebugBreak() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001386 mov(r0, Operand::Zero());
Steve Block44f0eee2011-05-26 01:26:41 +01001387 mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001388 CEntryStub ces(isolate(), 1);
1389 DCHECK(AllowThisStubCall(&ces));
Andrei Popescu402d9372010-02-26 13:31:12 +00001390 Call(ces.GetCode(), RelocInfo::DEBUG_BREAK);
1391}
Steve Blocka7e24c12009-10-30 11:49:00 +00001392
1393
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001394void MacroAssembler::PushTryHandler(StackHandler::Kind kind,
1395 int handler_index) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001396 // Adjust this code if not the case.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001397 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
1398 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001399 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1400 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1401 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1402 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001403
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001404 // For the JSEntry handler, we must preserve r0-r4, r5-r6 are available.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001405 // We will build up the handler from the bottom by pushing on the stack.
1406 // Set up the code object (r5) and the state (r6) for pushing.
1407 unsigned state =
1408 StackHandler::IndexField::encode(handler_index) |
1409 StackHandler::KindField::encode(kind);
1410 mov(r5, Operand(CodeObject()));
1411 mov(r6, Operand(state));
1412
1413 // Push the frame pointer, context, state, and code object.
1414 if (kind == StackHandler::JS_ENTRY) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001415 mov(cp, Operand(Smi::FromInt(0))); // Indicates no context.
1416 mov(ip, Operand::Zero()); // NULL frame pointer.
1417 stm(db_w, sp, r5.bit() | r6.bit() | cp.bit() | ip.bit());
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01001418 } else {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001419 stm(db_w, sp, r5.bit() | r6.bit() | cp.bit() | fp.bit());
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001420 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001421
1422 // Link the current handler as the next handler.
1423 mov(r6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1424 ldr(r5, MemOperand(r6));
1425 push(r5);
1426 // Set this new handler as the current one.
1427 str(sp, MemOperand(r6));
Steve Blocka7e24c12009-10-30 11:49:00 +00001428}
1429
1430
Leon Clarkee46be812010-01-19 14:06:41 +00001431void MacroAssembler::PopTryHandler() {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001432 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
Leon Clarkee46be812010-01-19 14:06:41 +00001433 pop(r1);
Ben Murdoch589d6972011-11-30 16:04:58 +00001434 mov(ip, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
Leon Clarkee46be812010-01-19 14:06:41 +00001435 add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
1436 str(r1, MemOperand(ip));
1437}
1438
1439
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001440void MacroAssembler::JumpToHandlerEntry() {
1441 // Compute the handler entry address and jump to it. The handler table is
1442 // a fixed array of (smi-tagged) code offsets.
1443 // r0 = exception, r1 = code object, r2 = state.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001444
1445 ConstantPoolUnavailableScope constant_pool_unavailable(this);
1446 if (FLAG_enable_ool_constant_pool) {
1447 ldr(pp, FieldMemOperand(r1, Code::kConstantPoolOffset)); // Constant pool.
1448 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001449 ldr(r3, FieldMemOperand(r1, Code::kHandlerTableOffset)); // Handler table.
1450 add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1451 mov(r2, Operand(r2, LSR, StackHandler::kKindWidth)); // Handler index.
1452 ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2)); // Smi-tagged offset.
1453 add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001454 add(pc, r1, Operand::SmiUntag(r2)); // Jump
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001455}
1456
1457
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001458void MacroAssembler::Throw(Register value) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001459 // Adjust this code if not the case.
1460 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001461 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
1462 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1463 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1464 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1465 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
1466
1467 // The exception is expected in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001468 if (!value.is(r0)) {
1469 mov(r0, value);
1470 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001471 // Drop the stack pointer to the top of the top handler.
Ben Murdoch589d6972011-11-30 16:04:58 +00001472 mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001473 ldr(sp, MemOperand(r3));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001474 // Restore the next handler.
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001475 pop(r2);
1476 str(r2, MemOperand(r3));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001477
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001478 // Get the code object (r1) and state (r2). Restore the context and frame
1479 // pointer.
1480 ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit());
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001481
1482 // If the handler is a JS frame, restore the context to the frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001483 // (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp
1484 // or cp.
1485 tst(cp, cp);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001486 str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1487
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001488 JumpToHandlerEntry();
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001489}
1490
1491
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001492void MacroAssembler::ThrowUncatchable(Register value) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001493 // Adjust this code if not the case.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001494 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
1495 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001496 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1497 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1498 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1499 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
1500
1501 // The exception is expected in r0.
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01001502 if (!value.is(r0)) {
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001503 mov(r0, value);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001504 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001505 // Drop the stack pointer to the top of the top stack handler.
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001506 mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1507 ldr(sp, MemOperand(r3));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001508
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001509 // Unwind the handlers until the ENTRY handler is found.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001510 Label fetch_next, check_kind;
1511 jmp(&check_kind);
1512 bind(&fetch_next);
1513 ldr(sp, MemOperand(sp, StackHandlerConstants::kNextOffset));
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001514
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001515 bind(&check_kind);
1516 STATIC_ASSERT(StackHandler::JS_ENTRY == 0);
1517 ldr(r2, MemOperand(sp, StackHandlerConstants::kStateOffset));
1518 tst(r2, Operand(StackHandler::KindField::kMask));
1519 b(ne, &fetch_next);
1520
1521 // Set the top handler address to next handler past the top ENTRY handler.
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001522 pop(r2);
1523 str(r2, MemOperand(r3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001524 // Get the code object (r1) and state (r2). Clear the context and frame
1525 // pointer (0 was saved in the handler).
1526 ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit());
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001527
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001528 JumpToHandlerEntry();
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001529}
1530
1531
Steve Blocka7e24c12009-10-30 11:49:00 +00001532void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
1533 Register scratch,
1534 Label* miss) {
1535 Label same_contexts;
1536
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001537 DCHECK(!holder_reg.is(scratch));
1538 DCHECK(!holder_reg.is(ip));
1539 DCHECK(!scratch.is(ip));
Steve Blocka7e24c12009-10-30 11:49:00 +00001540
1541 // Load current lexical context from the stack frame.
1542 ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
1543 // In debug mode, make sure the lexical context is set.
1544#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001545 cmp(scratch, Operand::Zero());
1546 Check(ne, kWeShouldNotHaveAnEmptyLexicalContext);
Steve Blocka7e24c12009-10-30 11:49:00 +00001547#endif
1548
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001549 // Load the native context of the current context.
1550 int offset =
1551 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001552 ldr(scratch, FieldMemOperand(scratch, offset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001553 ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001554
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555 // Check the context is a native context.
Steve Block44f0eee2011-05-26 01:26:41 +01001556 if (emit_debug_code()) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001557 // Cannot use ip as a temporary in this verification code. Due to the fact
1558 // that ip is clobbered as part of cmp with an object Operand.
1559 push(holder_reg); // Temporarily save holder on the stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001560 // Read the first word and compare to the native_context_map.
Steve Blocka7e24c12009-10-30 11:49:00 +00001561 ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001562 LoadRoot(ip, Heap::kNativeContextMapRootIndex);
Steve Blocka7e24c12009-10-30 11:49:00 +00001563 cmp(holder_reg, ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001564 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext);
Steve Blocka7e24c12009-10-30 11:49:00 +00001565 pop(holder_reg); // Restore holder.
1566 }
1567
1568 // Check if both contexts are the same.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001569 ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001570 cmp(scratch, Operand(ip));
1571 b(eq, &same_contexts);
1572
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001573 // Check the context is a native context.
Steve Block44f0eee2011-05-26 01:26:41 +01001574 if (emit_debug_code()) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001575 // Cannot use ip as a temporary in this verification code. Due to the fact
1576 // that ip is clobbered as part of cmp with an object Operand.
1577 push(holder_reg); // Temporarily save holder on the stack.
1578 mov(holder_reg, ip); // Move ip to its holding place.
1579 LoadRoot(ip, Heap::kNullValueRootIndex);
1580 cmp(holder_reg, ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001581 Check(ne, kJSGlobalProxyContextShouldNotBeNull);
Steve Blocka7e24c12009-10-30 11:49:00 +00001582
1583 ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001584 LoadRoot(ip, Heap::kNativeContextMapRootIndex);
Steve Blocka7e24c12009-10-30 11:49:00 +00001585 cmp(holder_reg, ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001586 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext);
Steve Blocka7e24c12009-10-30 11:49:00 +00001587 // Restore ip is not needed. ip is reloaded below.
1588 pop(holder_reg); // Restore holder.
1589 // Restore ip to holder's context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001590 ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00001591 }
1592
1593 // Check that the security token in the calling global object is
1594 // compatible with the security token in the receiving global
1595 // object.
1596 int token_offset = Context::kHeaderSize +
1597 Context::SECURITY_TOKEN_INDEX * kPointerSize;
1598
1599 ldr(scratch, FieldMemOperand(scratch, token_offset));
1600 ldr(ip, FieldMemOperand(ip, token_offset));
1601 cmp(scratch, Operand(ip));
1602 b(ne, miss);
1603
1604 bind(&same_contexts);
1605}
1606
1607
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001608// Compute the hash code from the untagged key. This must be kept in sync with
1609// ComputeIntegerHash in utils.h and KeyedLoadGenericStub in
1610// code-stub-hydrogen.cc
Ben Murdochc7cc0282012-03-05 14:35:55 +00001611void MacroAssembler::GetNumberHash(Register t0, Register scratch) {
1612 // First of all we assign the hash seed to scratch.
1613 LoadRoot(scratch, Heap::kHashSeedRootIndex);
1614 SmiUntag(scratch);
1615
1616 // Xor original key with a seed.
1617 eor(t0, t0, Operand(scratch));
1618
1619 // Compute the hash code from the untagged key. This must be kept in sync
1620 // with ComputeIntegerHash in utils.h.
1621 //
1622 // hash = ~hash + (hash << 15);
1623 mvn(scratch, Operand(t0));
1624 add(t0, scratch, Operand(t0, LSL, 15));
1625 // hash = hash ^ (hash >> 12);
1626 eor(t0, t0, Operand(t0, LSR, 12));
1627 // hash = hash + (hash << 2);
1628 add(t0, t0, Operand(t0, LSL, 2));
1629 // hash = hash ^ (hash >> 4);
1630 eor(t0, t0, Operand(t0, LSR, 4));
1631 // hash = hash * 2057;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001632 mov(scratch, Operand(t0, LSL, 11));
1633 add(t0, t0, Operand(t0, LSL, 3));
1634 add(t0, t0, scratch);
Ben Murdochc7cc0282012-03-05 14:35:55 +00001635 // hash = hash ^ (hash >> 16);
1636 eor(t0, t0, Operand(t0, LSR, 16));
1637}
1638
1639
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001640void MacroAssembler::LoadFromNumberDictionary(Label* miss,
1641 Register elements,
1642 Register key,
1643 Register result,
1644 Register t0,
1645 Register t1,
1646 Register t2) {
1647 // Register use:
1648 //
1649 // elements - holds the slow-case elements of the receiver on entry.
1650 // Unchanged unless 'result' is the same register.
1651 //
1652 // key - holds the smi key on entry.
1653 // Unchanged unless 'result' is the same register.
1654 //
1655 // result - holds the result on exit if the load succeeded.
1656 // Allowed to be the same as 'key' or 'result'.
1657 // Unchanged on bailout so 'key' or 'result' can be used
1658 // in further computation.
1659 //
1660 // Scratch registers:
1661 //
1662 // t0 - holds the untagged key on entry and holds the hash once computed.
1663 //
1664 // t1 - used to hold the capacity mask of the dictionary
1665 //
1666 // t2 - used for the index into the dictionary.
1667 Label done;
1668
Ben Murdochc7cc0282012-03-05 14:35:55 +00001669 GetNumberHash(t0, t1);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001670
1671 // Compute the capacity mask.
Ben Murdochc7cc0282012-03-05 14:35:55 +00001672 ldr(t1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001673 SmiUntag(t1);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001674 sub(t1, t1, Operand(1));
1675
1676 // Generate an unrolled loop that performs a few probes before giving up.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001677 for (int i = 0; i < kNumberDictionaryProbes; i++) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001678 // Use t2 for index calculations and keep the hash intact in t0.
1679 mov(t2, t0);
1680 // Compute the masked index: (hash + i + i * i) & mask.
1681 if (i > 0) {
Ben Murdochc7cc0282012-03-05 14:35:55 +00001682 add(t2, t2, Operand(SeededNumberDictionary::GetProbeOffset(i)));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001683 }
1684 and_(t2, t2, Operand(t1));
1685
1686 // Scale the index by multiplying by the element size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001687 DCHECK(SeededNumberDictionary::kEntrySize == 3);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001688 add(t2, t2, Operand(t2, LSL, 1)); // t2 = t2 * 3
1689
1690 // Check if the key is identical to the name.
1691 add(t2, elements, Operand(t2, LSL, kPointerSizeLog2));
Ben Murdochc7cc0282012-03-05 14:35:55 +00001692 ldr(ip, FieldMemOperand(t2, SeededNumberDictionary::kElementsStartOffset));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001693 cmp(key, Operand(ip));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001694 if (i != kNumberDictionaryProbes - 1) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001695 b(eq, &done);
1696 } else {
1697 b(ne, miss);
1698 }
1699 }
1700
1701 bind(&done);
1702 // Check that the value is a normal property.
1703 // t2: elements + (index * kPointerSize)
1704 const int kDetailsOffset =
Ben Murdochc7cc0282012-03-05 14:35:55 +00001705 SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001706 ldr(t1, FieldMemOperand(t2, kDetailsOffset));
Ben Murdoch589d6972011-11-30 16:04:58 +00001707 tst(t1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask)));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001708 b(ne, miss);
1709
1710 // Get the value at the masked, scaled index and return.
1711 const int kValueOffset =
Ben Murdochc7cc0282012-03-05 14:35:55 +00001712 SeededNumberDictionary::kElementsStartOffset + kPointerSize;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001713 ldr(result, FieldMemOperand(t2, kValueOffset));
1714}
1715
1716
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001717void MacroAssembler::Allocate(int object_size,
1718 Register result,
1719 Register scratch1,
1720 Register scratch2,
1721 Label* gc_required,
1722 AllocationFlags flags) {
1723 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize);
John Reck59135872010-11-02 12:39:01 -07001724 if (!FLAG_inline_new) {
Steve Block44f0eee2011-05-26 01:26:41 +01001725 if (emit_debug_code()) {
John Reck59135872010-11-02 12:39:01 -07001726 // Trash the registers to simulate an allocation failure.
1727 mov(result, Operand(0x7091));
1728 mov(scratch1, Operand(0x7191));
1729 mov(scratch2, Operand(0x7291));
1730 }
1731 jmp(gc_required);
1732 return;
1733 }
1734
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001735 DCHECK(!result.is(scratch1));
1736 DCHECK(!result.is(scratch2));
1737 DCHECK(!scratch1.is(scratch2));
1738 DCHECK(!scratch1.is(ip));
1739 DCHECK(!scratch2.is(ip));
Steve Blocka7e24c12009-10-30 11:49:00 +00001740
Kristian Monsen25f61362010-05-21 11:50:48 +01001741 // Make object size into bytes.
1742 if ((flags & SIZE_IN_WORDS) != 0) {
1743 object_size *= kPointerSize;
1744 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001745 DCHECK_EQ(0, object_size & kObjectAlignmentMask);
Kristian Monsen25f61362010-05-21 11:50:48 +01001746
Ben Murdochb0fe1622011-05-05 13:52:32 +01001747 // Check relative positions of allocation top and limit addresses.
1748 // The values must be adjacent in memory to allow the use of LDM.
1749 // Also, assert that the registers are numbered such that the values
1750 // are loaded in the correct order.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001751 ExternalReference allocation_top =
1752 AllocationUtils::GetAllocationTopReference(isolate(), flags);
1753 ExternalReference allocation_limit =
1754 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001755
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001756 intptr_t top =
1757 reinterpret_cast<intptr_t>(allocation_top.address());
1758 intptr_t limit =
1759 reinterpret_cast<intptr_t>(allocation_limit.address());
1760 DCHECK((limit - top) == kPointerSize);
1761 DCHECK(result.code() < ip.code());
1762
1763 // Set up allocation top address register.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001764 Register topaddr = scratch1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001765 mov(topaddr, Operand(allocation_top));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001766
1767 // This code stores a temporary value in ip. This is OK, as the code below
1768 // does not need ip for implicit literal generation.
Steve Blocka7e24c12009-10-30 11:49:00 +00001769 if ((flags & RESULT_CONTAINS_TOP) == 0) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001770 // Load allocation top into result and allocation limit into ip.
1771 ldm(ia, topaddr, result.bit() | ip.bit());
1772 } else {
Steve Block44f0eee2011-05-26 01:26:41 +01001773 if (emit_debug_code()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001774 // Assert that result actually contains top on entry. ip is used
1775 // immediately below so this use of ip does not cause difference with
1776 // respect to register content between debug and release mode.
1777 ldr(ip, MemOperand(topaddr));
1778 cmp(result, ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001779 Check(eq, kUnexpectedAllocationTop);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001780 }
1781 // Load allocation limit into ip. Result already contains allocation top.
1782 ldr(ip, MemOperand(topaddr, limit - top));
Steve Blocka7e24c12009-10-30 11:49:00 +00001783 }
1784
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001785 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1786 // Align the next allocation. Storing the filler map without checking top is
1787 // safe in new-space because the limit of the heap is aligned there.
1788 DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0);
1789 STATIC_ASSERT(kPointerAlignment * 2 == kDoubleAlignment);
1790 and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC);
1791 Label aligned;
1792 b(eq, &aligned);
1793 if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) {
1794 cmp(result, Operand(ip));
1795 b(hs, gc_required);
1796 }
1797 mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
1798 str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex));
1799 bind(&aligned);
1800 }
1801
Steve Blocka7e24c12009-10-30 11:49:00 +00001802 // Calculate new top and bail out if new space is exhausted. Use result
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001803 // to calculate the new top. We must preserve the ip register at this
1804 // point, so we cannot just use add().
1805 DCHECK(object_size > 0);
1806 Register source = result;
1807 Condition cond = al;
1808 int shift = 0;
1809 while (object_size != 0) {
1810 if (((object_size >> shift) & 0x03) == 0) {
1811 shift += 2;
1812 } else {
1813 int bits = object_size & (0xff << shift);
1814 object_size -= bits;
1815 shift += 8;
1816 Operand bits_operand(bits);
1817 DCHECK(bits_operand.instructions_required(this) == 1);
1818 add(scratch2, source, bits_operand, SetCC, cond);
1819 source = scratch2;
1820 cond = cc;
1821 }
1822 }
Steve Block1e0659c2011-05-24 12:43:12 +01001823 b(cs, gc_required);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001824 cmp(scratch2, Operand(ip));
Steve Blocka7e24c12009-10-30 11:49:00 +00001825 b(hi, gc_required);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001826 str(scratch2, MemOperand(topaddr));
Steve Blocka7e24c12009-10-30 11:49:00 +00001827
Ben Murdochb0fe1622011-05-05 13:52:32 +01001828 // Tag object if requested.
Steve Blocka7e24c12009-10-30 11:49:00 +00001829 if ((flags & TAG_OBJECT) != 0) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001830 add(result, result, Operand(kHeapObjectTag));
Steve Blocka7e24c12009-10-30 11:49:00 +00001831 }
1832}
1833
1834
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001835void MacroAssembler::Allocate(Register object_size,
1836 Register result,
1837 Register scratch1,
1838 Register scratch2,
1839 Label* gc_required,
1840 AllocationFlags flags) {
John Reck59135872010-11-02 12:39:01 -07001841 if (!FLAG_inline_new) {
Steve Block44f0eee2011-05-26 01:26:41 +01001842 if (emit_debug_code()) {
John Reck59135872010-11-02 12:39:01 -07001843 // Trash the registers to simulate an allocation failure.
1844 mov(result, Operand(0x7091));
1845 mov(scratch1, Operand(0x7191));
1846 mov(scratch2, Operand(0x7291));
1847 }
1848 jmp(gc_required);
1849 return;
1850 }
1851
Ben Murdochb0fe1622011-05-05 13:52:32 +01001852 // Assert that the register arguments are different and that none of
1853 // them are ip. ip is used explicitly in the code generated below.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001854 DCHECK(!result.is(scratch1));
1855 DCHECK(!result.is(scratch2));
1856 DCHECK(!scratch1.is(scratch2));
1857 DCHECK(!object_size.is(ip));
1858 DCHECK(!result.is(ip));
1859 DCHECK(!scratch1.is(ip));
1860 DCHECK(!scratch2.is(ip));
Steve Blocka7e24c12009-10-30 11:49:00 +00001861
Ben Murdochb0fe1622011-05-05 13:52:32 +01001862 // Check relative positions of allocation top and limit addresses.
1863 // The values must be adjacent in memory to allow the use of LDM.
1864 // Also, assert that the registers are numbered such that the values
1865 // are loaded in the correct order.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001866 ExternalReference allocation_top =
1867 AllocationUtils::GetAllocationTopReference(isolate(), flags);
1868 ExternalReference allocation_limit =
1869 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001870 intptr_t top =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001871 reinterpret_cast<intptr_t>(allocation_top.address());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001872 intptr_t limit =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001873 reinterpret_cast<intptr_t>(allocation_limit.address());
1874 DCHECK((limit - top) == kPointerSize);
1875 DCHECK(result.code() < ip.code());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001876
1877 // Set up allocation top address.
1878 Register topaddr = scratch1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001879 mov(topaddr, Operand(allocation_top));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001880
1881 // This code stores a temporary value in ip. This is OK, as the code below
1882 // does not need ip for implicit literal generation.
Steve Blocka7e24c12009-10-30 11:49:00 +00001883 if ((flags & RESULT_CONTAINS_TOP) == 0) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001884 // Load allocation top into result and allocation limit into ip.
1885 ldm(ia, topaddr, result.bit() | ip.bit());
1886 } else {
Steve Block44f0eee2011-05-26 01:26:41 +01001887 if (emit_debug_code()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001888 // Assert that result actually contains top on entry. ip is used
1889 // immediately below so this use of ip does not cause difference with
1890 // respect to register content between debug and release mode.
1891 ldr(ip, MemOperand(topaddr));
1892 cmp(result, ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001893 Check(eq, kUnexpectedAllocationTop);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001894 }
1895 // Load allocation limit into ip. Result already contains allocation top.
1896 ldr(ip, MemOperand(topaddr, limit - top));
Steve Blocka7e24c12009-10-30 11:49:00 +00001897 }
1898
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001899 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1900 // Align the next allocation. Storing the filler map without checking top is
1901 // safe in new-space because the limit of the heap is aligned there.
1902 DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0);
1903 DCHECK(kPointerAlignment * 2 == kDoubleAlignment);
1904 and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC);
1905 Label aligned;
1906 b(eq, &aligned);
1907 if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) {
1908 cmp(result, Operand(ip));
1909 b(hs, gc_required);
1910 }
1911 mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
1912 str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex));
1913 bind(&aligned);
1914 }
1915
Steve Blocka7e24c12009-10-30 11:49:00 +00001916 // Calculate new top and bail out if new space is exhausted. Use result
Ben Murdochb0fe1622011-05-05 13:52:32 +01001917 // to calculate the new top. Object size may be in words so a shift is
1918 // required to get the number of bytes.
Kristian Monsen25f61362010-05-21 11:50:48 +01001919 if ((flags & SIZE_IN_WORDS) != 0) {
Steve Block1e0659c2011-05-24 12:43:12 +01001920 add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC);
Kristian Monsen25f61362010-05-21 11:50:48 +01001921 } else {
Steve Block1e0659c2011-05-24 12:43:12 +01001922 add(scratch2, result, Operand(object_size), SetCC);
Kristian Monsen25f61362010-05-21 11:50:48 +01001923 }
Steve Block1e0659c2011-05-24 12:43:12 +01001924 b(cs, gc_required);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001925 cmp(scratch2, Operand(ip));
Steve Blocka7e24c12009-10-30 11:49:00 +00001926 b(hi, gc_required);
1927
Steve Blockd0582a62009-12-15 09:54:21 +00001928 // Update allocation top. result temporarily holds the new top.
Steve Block44f0eee2011-05-26 01:26:41 +01001929 if (emit_debug_code()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001930 tst(scratch2, Operand(kObjectAlignmentMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001931 Check(eq, kUnalignedAllocationInNewSpace);
Steve Blockd0582a62009-12-15 09:54:21 +00001932 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001933 str(scratch2, MemOperand(topaddr));
Steve Blocka7e24c12009-10-30 11:49:00 +00001934
1935 // Tag object if requested.
1936 if ((flags & TAG_OBJECT) != 0) {
1937 add(result, result, Operand(kHeapObjectTag));
1938 }
1939}
1940
1941
1942void MacroAssembler::UndoAllocationInNewSpace(Register object,
1943 Register scratch) {
1944 ExternalReference new_space_allocation_top =
Steve Block44f0eee2011-05-26 01:26:41 +01001945 ExternalReference::new_space_allocation_top_address(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +00001946
1947 // Make sure the object has no tag before resetting top.
1948 and_(object, object, Operand(~kHeapObjectTagMask));
1949#ifdef DEBUG
1950 // Check that the object un-allocated is below the current top.
1951 mov(scratch, Operand(new_space_allocation_top));
1952 ldr(scratch, MemOperand(scratch));
1953 cmp(object, scratch);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001954 Check(lt, kUndoAllocationOfNonAllocatedMemory);
Steve Blocka7e24c12009-10-30 11:49:00 +00001955#endif
1956 // Write the address of the object to un-allocate as the current top.
1957 mov(scratch, Operand(new_space_allocation_top));
1958 str(object, MemOperand(scratch));
1959}
1960
1961
Andrei Popescu31002712010-02-23 13:46:05 +00001962void MacroAssembler::AllocateTwoByteString(Register result,
1963 Register length,
1964 Register scratch1,
1965 Register scratch2,
1966 Register scratch3,
1967 Label* gc_required) {
1968 // Calculate the number of bytes needed for the characters in the string while
1969 // observing object alignment.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001970 DCHECK((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
Andrei Popescu31002712010-02-23 13:46:05 +00001971 mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars.
1972 add(scratch1, scratch1,
1973 Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize));
Kristian Monsen25f61362010-05-21 11:50:48 +01001974 and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
Andrei Popescu31002712010-02-23 13:46:05 +00001975
1976 // Allocate two-byte string in new space.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001977 Allocate(scratch1,
1978 result,
1979 scratch2,
1980 scratch3,
1981 gc_required,
1982 TAG_OBJECT);
Andrei Popescu31002712010-02-23 13:46:05 +00001983
1984 // Set the map, length and hash field.
Steve Block6ded16b2010-05-10 14:33:55 +01001985 InitializeNewString(result,
1986 length,
1987 Heap::kStringMapRootIndex,
1988 scratch1,
1989 scratch2);
Andrei Popescu31002712010-02-23 13:46:05 +00001990}
1991
1992
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001993void MacroAssembler::AllocateOneByteString(Register result, Register length,
1994 Register scratch1, Register scratch2,
1995 Register scratch3,
1996 Label* gc_required) {
Andrei Popescu31002712010-02-23 13:46:05 +00001997 // Calculate the number of bytes needed for the characters in the string while
1998 // observing object alignment.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001999 DCHECK((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2000 DCHECK(kCharSize == 1);
Andrei Popescu31002712010-02-23 13:46:05 +00002001 add(scratch1, length,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002002 Operand(kObjectAlignmentMask + SeqOneByteString::kHeaderSize));
Kristian Monsen25f61362010-05-21 11:50:48 +01002003 and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
Andrei Popescu31002712010-02-23 13:46:05 +00002004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002005 // Allocate one-byte string in new space.
2006 Allocate(scratch1,
2007 result,
2008 scratch2,
2009 scratch3,
2010 gc_required,
2011 TAG_OBJECT);
Andrei Popescu31002712010-02-23 13:46:05 +00002012
2013 // Set the map, length and hash field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002014 InitializeNewString(result, length, Heap::kOneByteStringMapRootIndex,
2015 scratch1, scratch2);
Andrei Popescu31002712010-02-23 13:46:05 +00002016}
2017
2018
2019void MacroAssembler::AllocateTwoByteConsString(Register result,
2020 Register length,
2021 Register scratch1,
2022 Register scratch2,
2023 Label* gc_required) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002024 Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required,
2025 TAG_OBJECT);
Steve Block6ded16b2010-05-10 14:33:55 +01002026
2027 InitializeNewString(result,
2028 length,
2029 Heap::kConsStringMapRootIndex,
2030 scratch1,
2031 scratch2);
Andrei Popescu31002712010-02-23 13:46:05 +00002032}
2033
2034
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002035void MacroAssembler::AllocateOneByteConsString(Register result, Register length,
2036 Register scratch1,
2037 Register scratch2,
2038 Label* gc_required) {
2039 Allocate(ConsString::kSize,
2040 result,
2041 scratch1,
2042 scratch2,
2043 gc_required,
2044 TAG_OBJECT);
Steve Block6ded16b2010-05-10 14:33:55 +01002045
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002046 InitializeNewString(result, length, Heap::kConsOneByteStringMapRootIndex,
2047 scratch1, scratch2);
Andrei Popescu31002712010-02-23 13:46:05 +00002048}
2049
2050
Ben Murdoch589d6972011-11-30 16:04:58 +00002051void MacroAssembler::AllocateTwoByteSlicedString(Register result,
2052 Register length,
2053 Register scratch1,
2054 Register scratch2,
2055 Label* gc_required) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002056 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
2057 TAG_OBJECT);
Ben Murdoch589d6972011-11-30 16:04:58 +00002058
2059 InitializeNewString(result,
2060 length,
2061 Heap::kSlicedStringMapRootIndex,
2062 scratch1,
2063 scratch2);
2064}
2065
2066
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002067void MacroAssembler::AllocateOneByteSlicedString(Register result,
2068 Register length,
2069 Register scratch1,
2070 Register scratch2,
2071 Label* gc_required) {
2072 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
2073 TAG_OBJECT);
Ben Murdoch589d6972011-11-30 16:04:58 +00002074
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002075 InitializeNewString(result, length, Heap::kSlicedOneByteStringMapRootIndex,
2076 scratch1, scratch2);
Ben Murdoch589d6972011-11-30 16:04:58 +00002077}
2078
2079
Steve Block6ded16b2010-05-10 14:33:55 +01002080void MacroAssembler::CompareObjectType(Register object,
Steve Blocka7e24c12009-10-30 11:49:00 +00002081 Register map,
2082 Register type_reg,
2083 InstanceType type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002084 const Register temp = type_reg.is(no_reg) ? ip : type_reg;
2085
Steve Block6ded16b2010-05-10 14:33:55 +01002086 ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002087 CompareInstanceType(map, temp, type);
2088}
2089
2090
2091void MacroAssembler::CheckObjectTypeRange(Register object,
2092 Register map,
2093 InstanceType min_type,
2094 InstanceType max_type,
2095 Label* false_label) {
2096 STATIC_ASSERT(Map::kInstanceTypeOffset < 4096);
2097 STATIC_ASSERT(LAST_TYPE < 256);
2098 ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
2099 ldrb(ip, FieldMemOperand(map, Map::kInstanceTypeOffset));
2100 sub(ip, ip, Operand(min_type));
2101 cmp(ip, Operand(max_type - min_type));
2102 b(hi, false_label);
Steve Blocka7e24c12009-10-30 11:49:00 +00002103}
2104
2105
2106void MacroAssembler::CompareInstanceType(Register map,
2107 Register type_reg,
2108 InstanceType type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002109 // Registers map and type_reg can be ip. These two lines assert
2110 // that ip can be used with the two instructions (the constants
2111 // will never need ip).
2112 STATIC_ASSERT(Map::kInstanceTypeOffset < 4096);
2113 STATIC_ASSERT(LAST_TYPE < 256);
Steve Blocka7e24c12009-10-30 11:49:00 +00002114 ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
2115 cmp(type_reg, Operand(type));
2116}
2117
2118
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002119void MacroAssembler::CompareRoot(Register obj,
2120 Heap::RootListIndex index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002121 DCHECK(!obj.is(ip));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002122 LoadRoot(ip, index);
2123 cmp(obj, ip);
2124}
2125
2126
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002127void MacroAssembler::CheckFastElements(Register map,
2128 Register scratch,
2129 Label* fail) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002130 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2131 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
2132 STATIC_ASSERT(FAST_ELEMENTS == 2);
2133 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002134 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002135 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002136 b(hi, fail);
2137}
2138
2139
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002140void MacroAssembler::CheckFastObjectElements(Register map,
2141 Register scratch,
2142 Label* fail) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002143 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2144 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
2145 STATIC_ASSERT(FAST_ELEMENTS == 2);
2146 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002147 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002148 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002149 b(ls, fail);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002150 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002151 b(hi, fail);
2152}
2153
2154
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002155void MacroAssembler::CheckFastSmiElements(Register map,
2156 Register scratch,
2157 Label* fail) {
2158 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2159 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002160 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002161 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002162 b(hi, fail);
2163}
2164
2165
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002166void MacroAssembler::StoreNumberToDoubleElements(
2167 Register value_reg,
2168 Register key_reg,
2169 Register elements_reg,
2170 Register scratch1,
2171 LowDwVfpRegister double_scratch,
2172 Label* fail,
2173 int elements_offset) {
2174 Label smi_value, store;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002175
2176 // Handle smi values specially.
2177 JumpIfSmi(value_reg, &smi_value);
2178
2179 // Ensure that the object is a heap number
2180 CheckMap(value_reg,
2181 scratch1,
2182 isolate()->factory()->heap_number_map(),
2183 fail,
2184 DONT_DO_SMI_CHECK);
2185
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002186 vldr(double_scratch, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
2187 // Force a canonical NaN.
2188 if (emit_debug_code()) {
2189 vmrs(ip);
2190 tst(ip, Operand(kVFPDefaultNaNModeControlBit));
2191 Assert(ne, kDefaultNaNModeNotSet);
2192 }
2193 VFPCanonicalizeNaN(double_scratch);
2194 b(&store);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002195
2196 bind(&smi_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002197 SmiToDouble(double_scratch, value_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002198
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002199 bind(&store);
2200 add(scratch1, elements_reg, Operand::DoubleOffsetFromSmiKey(key_reg));
2201 vstr(double_scratch,
2202 FieldMemOperand(scratch1,
2203 FixedDoubleArray::kHeaderSize - elements_offset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002204}
2205
2206
2207void MacroAssembler::CompareMap(Register obj,
2208 Register scratch,
2209 Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002210 Label* early_success) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002211 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002212 CompareMap(scratch, map, early_success);
2213}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002214
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002215
2216void MacroAssembler::CompareMap(Register obj_map,
2217 Handle<Map> map,
2218 Label* early_success) {
2219 cmp(obj_map, Operand(map));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002220}
2221
2222
Andrei Popescu31002712010-02-23 13:46:05 +00002223void MacroAssembler::CheckMap(Register obj,
2224 Register scratch,
2225 Handle<Map> map,
2226 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002227 SmiCheckType smi_check_type) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002228 if (smi_check_type == DO_SMI_CHECK) {
Steve Block1e0659c2011-05-24 12:43:12 +01002229 JumpIfSmi(obj, fail);
Andrei Popescu31002712010-02-23 13:46:05 +00002230 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002231
2232 Label success;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002233 CompareMap(obj, scratch, map, &success);
Andrei Popescu31002712010-02-23 13:46:05 +00002234 b(ne, fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002235 bind(&success);
Andrei Popescu31002712010-02-23 13:46:05 +00002236}
2237
2238
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002239void MacroAssembler::CheckMap(Register obj,
2240 Register scratch,
2241 Heap::RootListIndex index,
2242 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +00002243 SmiCheckType smi_check_type) {
2244 if (smi_check_type == DO_SMI_CHECK) {
Steve Block1e0659c2011-05-24 12:43:12 +01002245 JumpIfSmi(obj, fail);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002246 }
2247 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2248 LoadRoot(ip, index);
2249 cmp(scratch, ip);
2250 b(ne, fail);
2251}
2252
2253
Ben Murdoch257744e2011-11-30 15:57:28 +00002254void MacroAssembler::DispatchMap(Register obj,
2255 Register scratch,
2256 Handle<Map> map,
2257 Handle<Code> success,
2258 SmiCheckType smi_check_type) {
2259 Label fail;
2260 if (smi_check_type == DO_SMI_CHECK) {
2261 JumpIfSmi(obj, &fail);
2262 }
2263 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2264 mov(ip, Operand(map));
2265 cmp(scratch, ip);
2266 Jump(success, RelocInfo::CODE_TARGET, eq);
2267 bind(&fail);
2268}
2269
2270
Steve Blocka7e24c12009-10-30 11:49:00 +00002271void MacroAssembler::TryGetFunctionPrototype(Register function,
2272 Register result,
2273 Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002274 Label* miss,
2275 bool miss_on_bound_function) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002276 Label non_instance;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002277 if (miss_on_bound_function) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002278 // Check that the receiver isn't a smi.
2279 JumpIfSmi(function, miss);
2280
2281 // Check that the function really is a function. Load map into result reg.
2282 CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE);
2283 b(ne, miss);
2284
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002285 ldr(scratch,
2286 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2287 ldr(scratch,
2288 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset));
2289 tst(scratch,
2290 Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction)));
2291 b(ne, miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002292
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002293 // Make sure that the function has an instance prototype.
2294 ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset));
2295 tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
2296 b(ne, &non_instance);
2297 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002298
2299 // Get the prototype or initial map from the function.
2300 ldr(result,
2301 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2302
2303 // If the prototype or initial map is the hole, don't return it and
2304 // simply miss the cache instead. This will allow us to allocate a
2305 // prototype object on-demand in the runtime system.
2306 LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2307 cmp(result, ip);
2308 b(eq, miss);
2309
2310 // If the function does not have an initial map, we're done.
2311 Label done;
2312 CompareObjectType(result, scratch, scratch, MAP_TYPE);
2313 b(ne, &done);
2314
2315 // Get the prototype from the initial map.
2316 ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00002317
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002318 if (miss_on_bound_function) {
2319 jmp(&done);
2320
2321 // Non-instance prototype: Fetch prototype from constructor field
2322 // in initial map.
2323 bind(&non_instance);
2324 ldr(result, FieldMemOperand(result, Map::kConstructorOffset));
2325 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002326
2327 // All done.
2328 bind(&done);
2329}
2330
2331
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002332void MacroAssembler::CallStub(CodeStub* stub,
2333 TypeFeedbackId ast_id,
2334 Condition cond) {
2335 DCHECK(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs.
2336 Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id, cond);
Steve Blocka7e24c12009-10-30 11:49:00 +00002337}
2338
2339
Andrei Popescu31002712010-02-23 13:46:05 +00002340void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) {
Andrei Popescu31002712010-02-23 13:46:05 +00002341 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond);
2342}
2343
2344
Steve Block1e0659c2011-05-24 12:43:12 +01002345static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
2346 return ref0.address() - ref1.address();
2347}
2348
2349
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002350void MacroAssembler::CallApiFunctionAndReturn(
2351 Register function_address,
2352 ExternalReference thunk_ref,
2353 int stack_space,
2354 MemOperand return_value_operand,
2355 MemOperand* context_restore_operand) {
Steve Block1e0659c2011-05-24 12:43:12 +01002356 ExternalReference next_address =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002357 ExternalReference::handle_scope_next_address(isolate());
Steve Block1e0659c2011-05-24 12:43:12 +01002358 const int kNextOffset = 0;
2359 const int kLimitOffset = AddressOffset(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002360 ExternalReference::handle_scope_limit_address(isolate()),
Steve Block1e0659c2011-05-24 12:43:12 +01002361 next_address);
2362 const int kLevelOffset = AddressOffset(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002363 ExternalReference::handle_scope_level_address(isolate()),
Steve Block1e0659c2011-05-24 12:43:12 +01002364 next_address);
2365
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002366 DCHECK(function_address.is(r1) || function_address.is(r2));
2367
2368 Label profiler_disabled;
2369 Label end_profiler_check;
2370 mov(r9, Operand(ExternalReference::is_profiling_address(isolate())));
2371 ldrb(r9, MemOperand(r9, 0));
2372 cmp(r9, Operand(0));
2373 b(eq, &profiler_disabled);
2374
2375 // Additional parameter is the address of the actual callback.
2376 mov(r3, Operand(thunk_ref));
2377 jmp(&end_profiler_check);
2378
2379 bind(&profiler_disabled);
2380 Move(r3, function_address);
2381 bind(&end_profiler_check);
2382
Steve Block1e0659c2011-05-24 12:43:12 +01002383 // Allocate HandleScope in callee-save registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002384 mov(r9, Operand(next_address));
2385 ldr(r4, MemOperand(r9, kNextOffset));
2386 ldr(r5, MemOperand(r9, kLimitOffset));
2387 ldr(r6, MemOperand(r9, kLevelOffset));
Steve Block1e0659c2011-05-24 12:43:12 +01002388 add(r6, r6, Operand(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002389 str(r6, MemOperand(r9, kLevelOffset));
2390
2391 if (FLAG_log_timer_events) {
2392 FrameScope frame(this, StackFrame::MANUAL);
2393 PushSafepointRegisters();
2394 PrepareCallCFunction(1, r0);
2395 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2396 CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1);
2397 PopSafepointRegisters();
2398 }
Steve Block1e0659c2011-05-24 12:43:12 +01002399
2400 // Native call returns to the DirectCEntry stub which redirects to the
2401 // return address pushed on stack (could have moved after GC).
2402 // DirectCEntry stub itself is generated early and never moves.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002403 DirectCEntryStub stub(isolate());
2404 stub.GenerateCall(this, r3);
2405
2406 if (FLAG_log_timer_events) {
2407 FrameScope frame(this, StackFrame::MANUAL);
2408 PushSafepointRegisters();
2409 PrepareCallCFunction(1, r0);
2410 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2411 CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1);
2412 PopSafepointRegisters();
2413 }
Steve Block1e0659c2011-05-24 12:43:12 +01002414
2415 Label promote_scheduled_exception;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002416 Label exception_handled;
Steve Block1e0659c2011-05-24 12:43:12 +01002417 Label delete_allocated_handles;
2418 Label leave_exit_frame;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002419 Label return_value_loaded;
Steve Block1e0659c2011-05-24 12:43:12 +01002420
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002421 // load value from ReturnValue
2422 ldr(r0, return_value_operand);
2423 bind(&return_value_loaded);
Steve Block1e0659c2011-05-24 12:43:12 +01002424 // No more valid handles (the result handle was the last one). Restore
2425 // previous handle scope.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002426 str(r4, MemOperand(r9, kNextOffset));
Steve Block44f0eee2011-05-26 01:26:41 +01002427 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002428 ldr(r1, MemOperand(r9, kLevelOffset));
Steve Block1e0659c2011-05-24 12:43:12 +01002429 cmp(r1, r6);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002430 Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
Steve Block1e0659c2011-05-24 12:43:12 +01002431 }
2432 sub(r6, r6, Operand(1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002433 str(r6, MemOperand(r9, kLevelOffset));
2434 ldr(ip, MemOperand(r9, kLimitOffset));
Steve Block1e0659c2011-05-24 12:43:12 +01002435 cmp(r5, ip);
2436 b(ne, &delete_allocated_handles);
2437
2438 // Check if the function scheduled an exception.
2439 bind(&leave_exit_frame);
2440 LoadRoot(r4, Heap::kTheHoleValueRootIndex);
Steve Block44f0eee2011-05-26 01:26:41 +01002441 mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate())));
Steve Block1e0659c2011-05-24 12:43:12 +01002442 ldr(r5, MemOperand(ip));
2443 cmp(r4, r5);
2444 b(ne, &promote_scheduled_exception);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002445 bind(&exception_handled);
Steve Block1e0659c2011-05-24 12:43:12 +01002446
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002447 bool restore_context = context_restore_operand != NULL;
2448 if (restore_context) {
2449 ldr(cp, *context_restore_operand);
2450 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002451 // LeaveExitFrame expects unwind space to be in a register.
Steve Block1e0659c2011-05-24 12:43:12 +01002452 mov(r4, Operand(stack_space));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002453 LeaveExitFrame(false, r4, !restore_context);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002454 mov(pc, lr);
Steve Block1e0659c2011-05-24 12:43:12 +01002455
2456 bind(&promote_scheduled_exception);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002457 {
2458 FrameScope frame(this, StackFrame::INTERNAL);
2459 CallExternalReference(
2460 ExternalReference(Runtime::kPromoteScheduledException, isolate()),
2461 0);
2462 }
2463 jmp(&exception_handled);
Steve Block1e0659c2011-05-24 12:43:12 +01002464
2465 // HandleScope limit has changed. Delete allocated extensions.
2466 bind(&delete_allocated_handles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002467 str(r5, MemOperand(r9, kLimitOffset));
Steve Block1e0659c2011-05-24 12:43:12 +01002468 mov(r4, r0);
Ben Murdoch8b112d22011-06-08 16:22:53 +01002469 PrepareCallCFunction(1, r5);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002470 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
Steve Block44f0eee2011-05-26 01:26:41 +01002471 CallCFunction(
Ben Murdoch8b112d22011-06-08 16:22:53 +01002472 ExternalReference::delete_handle_scope_extensions(isolate()), 1);
Steve Block1e0659c2011-05-24 12:43:12 +01002473 mov(r0, r4);
2474 jmp(&leave_exit_frame);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002475}
Steve Block1e0659c2011-05-24 12:43:12 +01002476
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002477
2478bool MacroAssembler::AllowThisStubCall(CodeStub* stub) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002479 return has_frame_ || !stub->SometimesSetsUpAFrame();
Steve Blocka7e24c12009-10-30 11:49:00 +00002480}
2481
2482
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002483void MacroAssembler::IndexFromHash(Register hash, Register index) {
2484 // If the hash field contains an array index pick it out. The assert checks
2485 // that the constants for the maximum number of digits for an array index
2486 // cached in the hash field and the number of bits reserved for it does not
2487 // conflict.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002488 DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) <
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002489 (1 << String::kArrayIndexValueBits));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002490 DecodeFieldToSmi<String::ArrayIndexValueBits>(index, hash);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002491}
2492
2493
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002494void MacroAssembler::SmiToDouble(LowDwVfpRegister value, Register smi) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01002495 if (CpuFeatures::IsSupported(VFP3)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002496 vmov(value.low(), smi);
2497 vcvt_f64_s32(value, 1);
Iain Merrick9ac36c92010-09-13 15:29:50 +01002498 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002499 SmiUntag(ip, smi);
2500 vmov(value.low(), ip);
2501 vcvt_f64_s32(value, value.low());
Iain Merrick9ac36c92010-09-13 15:29:50 +01002502 }
2503}
2504
2505
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002506void MacroAssembler::TestDoubleIsInt32(DwVfpRegister double_input,
2507 LowDwVfpRegister double_scratch) {
2508 DCHECK(!double_input.is(double_scratch));
2509 vcvt_s32_f64(double_scratch.low(), double_input);
2510 vcvt_f64_s32(double_scratch, double_scratch.low());
2511 VFPCompareAndSetFlags(double_input, double_scratch);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002512}
2513
2514
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002515void MacroAssembler::TryDoubleToInt32Exact(Register result,
2516 DwVfpRegister double_input,
2517 LowDwVfpRegister double_scratch) {
2518 DCHECK(!double_input.is(double_scratch));
2519 vcvt_s32_f64(double_scratch.low(), double_input);
2520 vmov(result, double_scratch.low());
2521 vcvt_f64_s32(double_scratch, double_scratch.low());
2522 VFPCompareAndSetFlags(double_input, double_scratch);
2523}
Steve Block44f0eee2011-05-26 01:26:41 +01002524
Steve Block44f0eee2011-05-26 01:26:41 +01002525
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002526void MacroAssembler::TryInt32Floor(Register result,
2527 DwVfpRegister double_input,
2528 Register input_high,
2529 LowDwVfpRegister double_scratch,
2530 Label* done,
2531 Label* exact) {
2532 DCHECK(!result.is(input_high));
2533 DCHECK(!double_input.is(double_scratch));
2534 Label negative, exception;
Steve Block44f0eee2011-05-26 01:26:41 +01002535
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002536 VmovHigh(input_high, double_input);
Steve Block44f0eee2011-05-26 01:26:41 +01002537
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002538 // Test for NaN and infinities.
2539 Sbfx(result, input_high,
2540 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
2541 cmp(result, Operand(-1));
2542 b(eq, &exception);
2543 // Test for values that can be exactly represented as a
2544 // signed 32-bit integer.
2545 TryDoubleToInt32Exact(result, double_input, double_scratch);
2546 // If exact, return (result already fetched).
2547 b(eq, exact);
2548 cmp(input_high, Operand::Zero());
2549 b(mi, &negative);
Steve Block44f0eee2011-05-26 01:26:41 +01002550
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002551 // Input is in ]+0, +inf[.
2552 // If result equals 0x7fffffff input was out of range or
2553 // in ]0x7fffffff, 0x80000000[. We ignore this last case which
2554 // could fits into an int32, that means we always think input was
2555 // out of range and always go to exception.
2556 // If result < 0x7fffffff, go to done, result fetched.
2557 cmn(result, Operand(1));
2558 b(mi, &exception);
2559 b(done);
Steve Block44f0eee2011-05-26 01:26:41 +01002560
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002561 // Input is in ]-inf, -0[.
2562 // If x is a non integer negative number,
2563 // floor(x) <=> round_to_zero(x) - 1.
2564 bind(&negative);
2565 sub(result, result, Operand(1), SetCC);
2566 // If result is still negative, go to done, result fetched.
2567 // Else, we had an overflow and we fall through exception.
2568 b(mi, done);
2569 bind(&exception);
2570}
Steve Block44f0eee2011-05-26 01:26:41 +01002571
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002572void MacroAssembler::TryInlineTruncateDoubleToI(Register result,
2573 DwVfpRegister double_input,
2574 Label* done) {
2575 LowDwVfpRegister double_scratch = kScratchDoubleReg;
2576 vcvt_s32_f64(double_scratch.low(), double_input);
2577 vmov(result, double_scratch.low());
Steve Block44f0eee2011-05-26 01:26:41 +01002578
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002579 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
2580 sub(ip, result, Operand(1));
2581 cmp(ip, Operand(0x7ffffffe));
2582 b(lt, done);
2583}
Steve Block44f0eee2011-05-26 01:26:41 +01002584
Steve Block44f0eee2011-05-26 01:26:41 +01002585
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002586void MacroAssembler::TruncateDoubleToI(Register result,
2587 DwVfpRegister double_input) {
2588 Label done;
Steve Block44f0eee2011-05-26 01:26:41 +01002589
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002590 TryInlineTruncateDoubleToI(result, double_input, &done);
2591
2592 // If we fell through then inline version didn't succeed - call stub instead.
2593 push(lr);
2594 sub(sp, sp, Operand(kDoubleSize)); // Put input on stack.
2595 vstr(double_input, MemOperand(sp, 0));
2596
2597 DoubleToIStub stub(isolate(), sp, result, 0, true, true);
2598 CallStub(&stub);
2599
2600 add(sp, sp, Operand(kDoubleSize));
2601 pop(lr);
2602
Steve Block44f0eee2011-05-26 01:26:41 +01002603 bind(&done);
2604}
2605
2606
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002607void MacroAssembler::TruncateHeapNumberToI(Register result,
2608 Register object) {
Steve Block44f0eee2011-05-26 01:26:41 +01002609 Label done;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002610 LowDwVfpRegister double_scratch = kScratchDoubleReg;
2611 DCHECK(!result.is(object));
Steve Block44f0eee2011-05-26 01:26:41 +01002612
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002613 vldr(double_scratch,
2614 MemOperand(object, HeapNumber::kValueOffset - kHeapObjectTag));
2615 TryInlineTruncateDoubleToI(result, double_scratch, &done);
Steve Block44f0eee2011-05-26 01:26:41 +01002616
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002617 // If we fell through then inline version didn't succeed - call stub instead.
2618 push(lr);
2619 DoubleToIStub stub(isolate(),
2620 object,
2621 result,
2622 HeapNumber::kValueOffset - kHeapObjectTag,
2623 true,
2624 true);
2625 CallStub(&stub);
2626 pop(lr);
2627
2628 bind(&done);
2629}
2630
2631
2632void MacroAssembler::TruncateNumberToI(Register object,
2633 Register result,
2634 Register heap_number_map,
2635 Register scratch1,
2636 Label* not_number) {
2637 Label done;
2638 DCHECK(!result.is(object));
2639
2640 UntagAndJumpIfSmi(result, object, &done);
2641 JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number);
2642 TruncateHeapNumberToI(result, object);
2643
Steve Block44f0eee2011-05-26 01:26:41 +01002644 bind(&done);
2645}
2646
2647
Andrei Popescu31002712010-02-23 13:46:05 +00002648void MacroAssembler::GetLeastBitsFromSmi(Register dst,
2649 Register src,
2650 int num_least_bits) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002651 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size()) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002652 ubfx(dst, src, kSmiTagSize, num_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +00002653 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002654 SmiUntag(dst, src);
Andrei Popescu31002712010-02-23 13:46:05 +00002655 and_(dst, dst, Operand((1 << num_least_bits) - 1));
2656 }
2657}
2658
2659
Steve Block1e0659c2011-05-24 12:43:12 +01002660void MacroAssembler::GetLeastBitsFromInt32(Register dst,
2661 Register src,
2662 int num_least_bits) {
2663 and_(dst, src, Operand((1 << num_least_bits) - 1));
2664}
2665
2666
Steve Block44f0eee2011-05-26 01:26:41 +01002667void MacroAssembler::CallRuntime(const Runtime::Function* f,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002668 int num_arguments,
2669 SaveFPRegsMode save_doubles) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002670 // All parameters are on the stack. r0 has the return value after call.
2671
2672 // If the expected number of arguments of the runtime function is
2673 // constant, we check that the actual number of arguments match the
2674 // expectation.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002675 CHECK(f->nargs < 0 || f->nargs == num_arguments);
Steve Blocka7e24c12009-10-30 11:49:00 +00002676
Leon Clarke4515c472010-02-03 11:58:03 +00002677 // TODO(1236192): Most runtime routines don't need the number of
2678 // arguments passed in because it is constant. At some point we
2679 // should remove this need and make the runtime routine entry code
2680 // smarter.
2681 mov(r0, Operand(num_arguments));
Steve Block44f0eee2011-05-26 01:26:41 +01002682 mov(r1, Operand(ExternalReference(f, isolate())));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002683 CEntryStub stub(isolate(), 1, save_doubles);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002684 CallStub(&stub);
2685}
2686
2687
Andrei Popescu402d9372010-02-26 13:31:12 +00002688void MacroAssembler::CallExternalReference(const ExternalReference& ext,
2689 int num_arguments) {
2690 mov(r0, Operand(num_arguments));
2691 mov(r1, Operand(ext));
2692
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002693 CEntryStub stub(isolate(), 1);
Andrei Popescu402d9372010-02-26 13:31:12 +00002694 CallStub(&stub);
2695}
2696
2697
Steve Block6ded16b2010-05-10 14:33:55 +01002698void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
2699 int num_arguments,
2700 int result_size) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002701 // TODO(1236192): Most runtime routines don't need the number of
2702 // arguments passed in because it is constant. At some point we
2703 // should remove this need and make the runtime routine entry code
2704 // smarter.
2705 mov(r0, Operand(num_arguments));
Steve Block6ded16b2010-05-10 14:33:55 +01002706 JumpToExternalReference(ext);
Steve Blocka7e24c12009-10-30 11:49:00 +00002707}
2708
2709
Steve Block6ded16b2010-05-10 14:33:55 +01002710void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
2711 int num_arguments,
2712 int result_size) {
Steve Block44f0eee2011-05-26 01:26:41 +01002713 TailCallExternalReference(ExternalReference(fid, isolate()),
2714 num_arguments,
2715 result_size);
Steve Block6ded16b2010-05-10 14:33:55 +01002716}
2717
2718
2719void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002720#if defined(__thumb__)
2721 // Thumb mode builtin.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002722 DCHECK((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00002723#endif
2724 mov(r1, Operand(builtin));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002725 CEntryStub stub(isolate(), 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00002726 Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
2727}
2728
2729
Steve Blocka7e24c12009-10-30 11:49:00 +00002730void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +00002731 InvokeFlag flag,
2732 const CallWrapper& call_wrapper) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002733 // You can't call a builtin without a valid frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002734 DCHECK(flag == JUMP_FUNCTION || has_frame());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002735
Andrei Popescu402d9372010-02-26 13:31:12 +00002736 GetBuiltinEntry(r2, id);
Ben Murdoch257744e2011-11-30 15:57:28 +00002737 if (flag == CALL_FUNCTION) {
2738 call_wrapper.BeforeCall(CallSize(r2));
Andrei Popescu402d9372010-02-26 13:31:12 +00002739 Call(r2);
Ben Murdoch257744e2011-11-30 15:57:28 +00002740 call_wrapper.AfterCall();
Steve Blocka7e24c12009-10-30 11:49:00 +00002741 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002742 DCHECK(flag == JUMP_FUNCTION);
Andrei Popescu402d9372010-02-26 13:31:12 +00002743 Jump(r2);
Steve Blocka7e24c12009-10-30 11:49:00 +00002744 }
2745}
2746
2747
Steve Block791712a2010-08-27 10:21:07 +01002748void MacroAssembler::GetBuiltinFunction(Register target,
2749 Builtins::JavaScript id) {
Steve Block6ded16b2010-05-10 14:33:55 +01002750 // Load the builtins object into target register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002751 ldr(target,
2752 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
Steve Block6ded16b2010-05-10 14:33:55 +01002753 ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
Andrei Popescu402d9372010-02-26 13:31:12 +00002754 // Load the JavaScript builtin function from the builtins object.
Steve Block6ded16b2010-05-10 14:33:55 +01002755 ldr(target, FieldMemOperand(target,
Steve Block791712a2010-08-27 10:21:07 +01002756 JSBuiltinsObject::OffsetOfFunctionWithId(id)));
2757}
2758
2759
2760void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002761 DCHECK(!target.is(r1));
Steve Block791712a2010-08-27 10:21:07 +01002762 GetBuiltinFunction(r1, id);
2763 // Load the code entry point from the builtins object.
2764 ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
Steve Blocka7e24c12009-10-30 11:49:00 +00002765}
2766
2767
2768void MacroAssembler::SetCounter(StatsCounter* counter, int value,
2769 Register scratch1, Register scratch2) {
2770 if (FLAG_native_code_counters && counter->Enabled()) {
2771 mov(scratch1, Operand(value));
2772 mov(scratch2, Operand(ExternalReference(counter)));
2773 str(scratch1, MemOperand(scratch2));
2774 }
2775}
2776
2777
2778void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
2779 Register scratch1, Register scratch2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002780 DCHECK(value > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00002781 if (FLAG_native_code_counters && counter->Enabled()) {
2782 mov(scratch2, Operand(ExternalReference(counter)));
2783 ldr(scratch1, MemOperand(scratch2));
2784 add(scratch1, scratch1, Operand(value));
2785 str(scratch1, MemOperand(scratch2));
2786 }
2787}
2788
2789
2790void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
2791 Register scratch1, Register scratch2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002792 DCHECK(value > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00002793 if (FLAG_native_code_counters && counter->Enabled()) {
2794 mov(scratch2, Operand(ExternalReference(counter)));
2795 ldr(scratch1, MemOperand(scratch2));
2796 sub(scratch1, scratch1, Operand(value));
2797 str(scratch1, MemOperand(scratch2));
2798 }
2799}
2800
2801
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002802void MacroAssembler::Assert(Condition cond, BailoutReason reason) {
Steve Block44f0eee2011-05-26 01:26:41 +01002803 if (emit_debug_code())
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002804 Check(cond, reason);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01002805}
2806
2807
Iain Merrick75681382010-08-19 15:07:18 +01002808void MacroAssembler::AssertFastElements(Register elements) {
Steve Block44f0eee2011-05-26 01:26:41 +01002809 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002810 DCHECK(!elements.is(ip));
Iain Merrick75681382010-08-19 15:07:18 +01002811 Label ok;
2812 push(elements);
2813 ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
2814 LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
2815 cmp(elements, ip);
2816 b(eq, &ok);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002817 LoadRoot(ip, Heap::kFixedDoubleArrayMapRootIndex);
2818 cmp(elements, ip);
2819 b(eq, &ok);
Iain Merrick75681382010-08-19 15:07:18 +01002820 LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex);
2821 cmp(elements, ip);
2822 b(eq, &ok);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002823 Abort(kJSObjectWithFastElementsMapHasSlowElements);
Iain Merrick75681382010-08-19 15:07:18 +01002824 bind(&ok);
2825 pop(elements);
2826 }
2827}
2828
2829
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002830void MacroAssembler::Check(Condition cond, BailoutReason reason) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002831 Label L;
Steve Block1e0659c2011-05-24 12:43:12 +01002832 b(cond, &L);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002833 Abort(reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00002834 // will not return here
2835 bind(&L);
2836}
2837
2838
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002839void MacroAssembler::Abort(BailoutReason reason) {
Steve Block8defd9f2010-07-08 12:39:36 +01002840 Label abort_start;
2841 bind(&abort_start);
Steve Blocka7e24c12009-10-30 11:49:00 +00002842#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002843 const char* msg = GetBailoutReason(reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00002844 if (msg != NULL) {
2845 RecordComment("Abort message: ");
2846 RecordComment(msg);
2847 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002848
2849 if (FLAG_trap_on_abort) {
2850 stop(msg);
2851 return;
2852 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002853#endif
Steve Blockd0582a62009-12-15 09:54:21 +00002854
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002855 mov(r0, Operand(Smi::FromInt(reason)));
Steve Blocka7e24c12009-10-30 11:49:00 +00002856 push(r0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002857
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002858 // Disable stub call restrictions to always allow calls to abort.
2859 if (!has_frame_) {
2860 // We don't actually want to generate a pile of code for this, so just
2861 // claim there is a stack frame, without generating one.
2862 FrameScope scope(this, StackFrame::NONE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002863 CallRuntime(Runtime::kAbort, 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002864 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002865 CallRuntime(Runtime::kAbort, 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002866 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002867 // will not return here
Steve Block8defd9f2010-07-08 12:39:36 +01002868 if (is_const_pool_blocked()) {
2869 // If the calling code cares about the exact number of
2870 // instructions generated, we insert padding here to keep the size
2871 // of the Abort macro constant.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002872 static const int kExpectedAbortInstructions = 7;
Steve Block8defd9f2010-07-08 12:39:36 +01002873 int abort_instructions = InstructionsGeneratedSince(&abort_start);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002874 DCHECK(abort_instructions <= kExpectedAbortInstructions);
Steve Block8defd9f2010-07-08 12:39:36 +01002875 while (abort_instructions++ < kExpectedAbortInstructions) {
2876 nop();
2877 }
2878 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002879}
2880
2881
Steve Blockd0582a62009-12-15 09:54:21 +00002882void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
2883 if (context_chain_length > 0) {
2884 // Move up the chain of contexts to the context containing the slot.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002885 ldr(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX)));
Steve Blockd0582a62009-12-15 09:54:21 +00002886 for (int i = 1; i < context_chain_length; i++) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002887 ldr(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX)));
Steve Blockd0582a62009-12-15 09:54:21 +00002888 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002889 } else {
2890 // Slot is in the current function context. Move it into the
2891 // destination register in case we store into it (the write barrier
2892 // cannot be allowed to destroy the context in esi).
2893 mov(dst, cp);
2894 }
Steve Blockd0582a62009-12-15 09:54:21 +00002895}
2896
2897
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002898void MacroAssembler::LoadTransitionedArrayMapConditional(
2899 ElementsKind expected_kind,
2900 ElementsKind transitioned_kind,
2901 Register map_in_out,
2902 Register scratch,
2903 Label* no_map_match) {
2904 // Load the global or builtins object from the current context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002905 ldr(scratch,
2906 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2907 ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002908
2909 // Check that the function's map is the same as the expected cached map.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002910 ldr(scratch,
2911 MemOperand(scratch,
2912 Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX)));
2913 size_t offset = expected_kind * kPointerSize +
2914 FixedArrayBase::kHeaderSize;
2915 ldr(ip, FieldMemOperand(scratch, offset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002916 cmp(map_in_out, ip);
2917 b(ne, no_map_match);
2918
2919 // Use the transitioned cached map.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002920 offset = transitioned_kind * kPointerSize +
2921 FixedArrayBase::kHeaderSize;
2922 ldr(map_in_out, FieldMemOperand(scratch, offset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002923}
2924
2925
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002926void MacroAssembler::LoadGlobalFunction(int index, Register function) {
2927 // Load the global or builtins object from the current context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002928 ldr(function,
2929 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2930 // Load the native context from the global or builtins object.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002931 ldr(function, FieldMemOperand(function,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002932 GlobalObject::kNativeContextOffset));
2933 // Load the function from the native context.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002934 ldr(function, MemOperand(function, Context::SlotOffset(index)));
2935}
2936
2937
2938void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
2939 Register map,
2940 Register scratch) {
2941 // Load the initial map. The global functions all have initial maps.
2942 ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
Steve Block44f0eee2011-05-26 01:26:41 +01002943 if (emit_debug_code()) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002944 Label ok, fail;
Ben Murdoch257744e2011-11-30 15:57:28 +00002945 CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002946 b(&ok);
2947 bind(&fail);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002948 Abort(kGlobalFunctionsMustHaveInitialMap);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08002949 bind(&ok);
2950 }
2951}
2952
2953
Steve Block1e0659c2011-05-24 12:43:12 +01002954void MacroAssembler::JumpIfNotPowerOfTwoOrZero(
2955 Register reg,
2956 Register scratch,
2957 Label* not_power_of_two_or_zero) {
2958 sub(scratch, reg, Operand(1), SetCC);
2959 b(mi, not_power_of_two_or_zero);
2960 tst(scratch, reg);
2961 b(ne, not_power_of_two_or_zero);
2962}
2963
2964
Steve Block44f0eee2011-05-26 01:26:41 +01002965void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg(
2966 Register reg,
2967 Register scratch,
2968 Label* zero_and_neg,
2969 Label* not_power_of_two) {
2970 sub(scratch, reg, Operand(1), SetCC);
2971 b(mi, zero_and_neg);
2972 tst(scratch, reg);
2973 b(ne, not_power_of_two);
2974}
2975
2976
Andrei Popescu31002712010-02-23 13:46:05 +00002977void MacroAssembler::JumpIfNotBothSmi(Register reg1,
2978 Register reg2,
2979 Label* on_not_both_smi) {
Steve Block1e0659c2011-05-24 12:43:12 +01002980 STATIC_ASSERT(kSmiTag == 0);
Andrei Popescu31002712010-02-23 13:46:05 +00002981 tst(reg1, Operand(kSmiTagMask));
2982 tst(reg2, Operand(kSmiTagMask), eq);
2983 b(ne, on_not_both_smi);
2984}
2985
2986
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002987void MacroAssembler::UntagAndJumpIfSmi(
2988 Register dst, Register src, Label* smi_case) {
2989 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002990 SmiUntag(dst, src, SetCC);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002991 b(cc, smi_case); // Shifter carry is not set for a smi.
2992}
2993
2994
2995void MacroAssembler::UntagAndJumpIfNotSmi(
2996 Register dst, Register src, Label* non_smi_case) {
2997 STATIC_ASSERT(kSmiTag == 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002998 SmiUntag(dst, src, SetCC);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002999 b(cs, non_smi_case); // Shifter carry is set for a non-smi.
3000}
3001
3002
Andrei Popescu31002712010-02-23 13:46:05 +00003003void MacroAssembler::JumpIfEitherSmi(Register reg1,
3004 Register reg2,
3005 Label* on_either_smi) {
Steve Block1e0659c2011-05-24 12:43:12 +01003006 STATIC_ASSERT(kSmiTag == 0);
Andrei Popescu31002712010-02-23 13:46:05 +00003007 tst(reg1, Operand(kSmiTagMask));
3008 tst(reg2, Operand(kSmiTagMask), ne);
3009 b(eq, on_either_smi);
3010}
3011
3012
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003013void MacroAssembler::AssertNotSmi(Register object) {
3014 if (emit_debug_code()) {
3015 STATIC_ASSERT(kSmiTag == 0);
3016 tst(object, Operand(kSmiTagMask));
3017 Check(ne, kOperandIsASmi);
3018 }
Iain Merrick75681382010-08-19 15:07:18 +01003019}
3020
3021
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003022void MacroAssembler::AssertSmi(Register object) {
3023 if (emit_debug_code()) {
3024 STATIC_ASSERT(kSmiTag == 0);
3025 tst(object, Operand(kSmiTagMask));
3026 Check(eq, kOperandIsNotSmi);
3027 }
Steve Block1e0659c2011-05-24 12:43:12 +01003028}
3029
3030
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003031void MacroAssembler::AssertString(Register object) {
3032 if (emit_debug_code()) {
3033 STATIC_ASSERT(kSmiTag == 0);
3034 tst(object, Operand(kSmiTagMask));
3035 Check(ne, kOperandIsASmiAndNotAString);
3036 push(object);
3037 ldr(object, FieldMemOperand(object, HeapObject::kMapOffset));
3038 CompareInstanceType(object, object, FIRST_NONSTRING_TYPE);
3039 pop(object);
3040 Check(lo, kOperandIsNotAString);
3041 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003042}
3043
3044
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003045void MacroAssembler::AssertName(Register object) {
3046 if (emit_debug_code()) {
3047 STATIC_ASSERT(kSmiTag == 0);
3048 tst(object, Operand(kSmiTagMask));
3049 Check(ne, kOperandIsASmiAndNotAName);
3050 push(object);
3051 ldr(object, FieldMemOperand(object, HeapObject::kMapOffset));
3052 CompareInstanceType(object, object, LAST_NAME_TYPE);
3053 pop(object);
3054 Check(le, kOperandIsNotAName);
3055 }
3056}
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003057
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003058
3059void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
3060 Register scratch) {
3061 if (emit_debug_code()) {
3062 Label done_checking;
3063 AssertNotSmi(object);
3064 CompareRoot(object, Heap::kUndefinedValueRootIndex);
3065 b(eq, &done_checking);
3066 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
3067 CompareRoot(scratch, Heap::kAllocationSiteMapRootIndex);
3068 Assert(eq, kExpectedUndefinedOrCell);
3069 bind(&done_checking);
3070 }
3071}
3072
3073
3074void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) {
3075 if (emit_debug_code()) {
3076 CompareRoot(reg, index);
3077 Check(eq, kHeapNumberMapRegisterClobbered);
3078 }
Steve Block1e0659c2011-05-24 12:43:12 +01003079}
3080
3081
3082void MacroAssembler::JumpIfNotHeapNumber(Register object,
3083 Register heap_number_map,
3084 Register scratch,
3085 Label* on_not_heap_number) {
3086 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003087 AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
Steve Block1e0659c2011-05-24 12:43:12 +01003088 cmp(scratch, heap_number_map);
3089 b(ne, on_not_heap_number);
3090}
3091
3092
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003093void MacroAssembler::LookupNumberStringCache(Register object,
3094 Register result,
3095 Register scratch1,
3096 Register scratch2,
3097 Register scratch3,
3098 Label* not_found) {
3099 // Use of registers. Register result is used as a temporary.
3100 Register number_string_cache = result;
3101 Register mask = scratch3;
3102
3103 // Load the number string cache.
3104 LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex);
3105
3106 // Make the hash mask from the length of the number string cache. It
3107 // contains two elements (number and string) for each cache entry.
3108 ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset));
3109 // Divide length by two (length is a smi).
3110 mov(mask, Operand(mask, ASR, kSmiTagSize + 1));
3111 sub(mask, mask, Operand(1)); // Make mask.
3112
3113 // Calculate the entry in the number string cache. The hash value in the
3114 // number string cache for smis is just the smi value, and the hash for
3115 // doubles is the xor of the upper and lower words. See
3116 // Heap::GetNumberStringCache.
3117 Label is_smi;
3118 Label load_result_from_cache;
3119 JumpIfSmi(object, &is_smi);
3120 CheckMap(object,
3121 scratch1,
3122 Heap::kHeapNumberMapRootIndex,
3123 not_found,
3124 DONT_DO_SMI_CHECK);
3125
3126 STATIC_ASSERT(8 == kDoubleSize);
3127 add(scratch1,
3128 object,
3129 Operand(HeapNumber::kValueOffset - kHeapObjectTag));
3130 ldm(ia, scratch1, scratch1.bit() | scratch2.bit());
3131 eor(scratch1, scratch1, Operand(scratch2));
3132 and_(scratch1, scratch1, Operand(mask));
3133
3134 // Calculate address of entry in string cache: each entry consists
3135 // of two pointer sized fields.
3136 add(scratch1,
3137 number_string_cache,
3138 Operand(scratch1, LSL, kPointerSizeLog2 + 1));
3139
3140 Register probe = mask;
3141 ldr(probe, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
3142 JumpIfSmi(probe, not_found);
3143 sub(scratch2, object, Operand(kHeapObjectTag));
3144 vldr(d0, scratch2, HeapNumber::kValueOffset);
3145 sub(probe, probe, Operand(kHeapObjectTag));
3146 vldr(d1, probe, HeapNumber::kValueOffset);
3147 VFPCompareAndSetFlags(d0, d1);
3148 b(ne, not_found); // The cache did not contain this value.
3149 b(&load_result_from_cache);
3150
3151 bind(&is_smi);
3152 Register scratch = scratch1;
3153 and_(scratch, mask, Operand(object, ASR, 1));
3154 // Calculate address of entry in string cache: each entry consists
3155 // of two pointer sized fields.
3156 add(scratch,
3157 number_string_cache,
3158 Operand(scratch, LSL, kPointerSizeLog2 + 1));
3159
3160 // Check if the entry is the smi we are looking for.
3161 ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3162 cmp(object, probe);
3163 b(ne, not_found);
3164
3165 // Get the result from the cache.
3166 bind(&load_result_from_cache);
3167 ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize));
3168 IncrementCounter(isolate()->counters()->number_to_string_native(),
3169 1,
3170 scratch1,
3171 scratch2);
3172}
3173
3174
3175void MacroAssembler::JumpIfNonSmisNotBothSequentialOneByteStrings(
3176 Register first, Register second, Register scratch1, Register scratch2,
Leon Clarked91b9f72010-01-27 17:25:45 +00003177 Label* failure) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003178 // Test that both first and second are sequential one-byte strings.
Leon Clarked91b9f72010-01-27 17:25:45 +00003179 // Assume that they are non-smis.
3180 ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
3181 ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
3182 ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3183 ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
Steve Block6ded16b2010-05-10 14:33:55 +01003184
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003185 JumpIfBothInstanceTypesAreNotSequentialOneByte(scratch1, scratch2, scratch1,
3186 scratch2, failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00003187}
3188
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003189void MacroAssembler::JumpIfNotBothSequentialOneByteStrings(Register first,
3190 Register second,
3191 Register scratch1,
3192 Register scratch2,
3193 Label* failure) {
Leon Clarked91b9f72010-01-27 17:25:45 +00003194 // Check that neither is a smi.
Leon Clarked91b9f72010-01-27 17:25:45 +00003195 and_(scratch1, first, Operand(second));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003196 JumpIfSmi(scratch1, failure);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003197 JumpIfNonSmisNotBothSequentialOneByteStrings(first, second, scratch1,
3198 scratch2, failure);
3199}
3200
3201
3202void MacroAssembler::JumpIfNotUniqueNameInstanceType(Register reg,
3203 Label* not_unique_name) {
3204 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3205 Label succeed;
3206 tst(reg, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3207 b(eq, &succeed);
3208 cmp(reg, Operand(SYMBOL_TYPE));
3209 b(ne, not_unique_name);
3210
3211 bind(&succeed);
Leon Clarked91b9f72010-01-27 17:25:45 +00003212}
3213
Steve Blockd0582a62009-12-15 09:54:21 +00003214
Steve Block6ded16b2010-05-10 14:33:55 +01003215// Allocates a heap number or jumps to the need_gc label if the young space
3216// is full and a scavenge is needed.
3217void MacroAssembler::AllocateHeapNumber(Register result,
3218 Register scratch1,
3219 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01003220 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003221 Label* gc_required,
3222 TaggingMode tagging_mode,
3223 MutableMode mode) {
Steve Block6ded16b2010-05-10 14:33:55 +01003224 // Allocate an object in the heap for the heap number and tag it as a heap
3225 // object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003226 Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required,
3227 tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS);
3228
3229 Heap::RootListIndex map_index = mode == MUTABLE
3230 ? Heap::kMutableHeapNumberMapRootIndex
3231 : Heap::kHeapNumberMapRootIndex;
3232 AssertIsRoot(heap_number_map, map_index);
Steve Block6ded16b2010-05-10 14:33:55 +01003233
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01003234 // Store heap number map in the allocated object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003235 if (tagging_mode == TAG_RESULT) {
3236 str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
3237 } else {
3238 str(heap_number_map, MemOperand(result, HeapObject::kMapOffset));
3239 }
Steve Block6ded16b2010-05-10 14:33:55 +01003240}
3241
3242
Steve Block8defd9f2010-07-08 12:39:36 +01003243void MacroAssembler::AllocateHeapNumberWithValue(Register result,
3244 DwVfpRegister value,
3245 Register scratch1,
3246 Register scratch2,
3247 Register heap_number_map,
3248 Label* gc_required) {
3249 AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required);
3250 sub(scratch1, result, Operand(kHeapObjectTag));
3251 vstr(value, scratch1, HeapNumber::kValueOffset);
3252}
3253
3254
Ben Murdochbb769b22010-08-11 14:56:33 +01003255// Copies a fixed number of fields of heap objects from src to dst.
3256void MacroAssembler::CopyFields(Register dst,
3257 Register src,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003258 LowDwVfpRegister double_scratch,
Ben Murdochbb769b22010-08-11 14:56:33 +01003259 int field_count) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003260 int double_count = field_count / (DwVfpRegister::kSizeInBytes / kPointerSize);
3261 for (int i = 0; i < double_count; i++) {
3262 vldr(double_scratch, FieldMemOperand(src, i * DwVfpRegister::kSizeInBytes));
3263 vstr(double_scratch, FieldMemOperand(dst, i * DwVfpRegister::kSizeInBytes));
Ben Murdochbb769b22010-08-11 14:56:33 +01003264 }
Ben Murdochbb769b22010-08-11 14:56:33 +01003265
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003266 STATIC_ASSERT(SwVfpRegister::kSizeInBytes == kPointerSize);
3267 STATIC_ASSERT(2 * SwVfpRegister::kSizeInBytes == DwVfpRegister::kSizeInBytes);
3268
3269 int remain = field_count % (DwVfpRegister::kSizeInBytes / kPointerSize);
3270 if (remain != 0) {
3271 vldr(double_scratch.low(),
3272 FieldMemOperand(src, (field_count - 1) * kPointerSize));
3273 vstr(double_scratch.low(),
3274 FieldMemOperand(dst, (field_count - 1) * kPointerSize));
Ben Murdochbb769b22010-08-11 14:56:33 +01003275 }
3276}
3277
3278
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003279void MacroAssembler::CopyBytes(Register src,
3280 Register dst,
3281 Register length,
3282 Register scratch) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003283 Label align_loop_1, word_loop, byte_loop, byte_loop_1, done;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003284
3285 // Align src before copying in word size chunks.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003286 cmp(length, Operand(kPointerSize));
3287 b(le, &byte_loop);
3288
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003289 bind(&align_loop_1);
3290 tst(src, Operand(kPointerSize - 1));
3291 b(eq, &word_loop);
3292 ldrb(scratch, MemOperand(src, 1, PostIndex));
3293 strb(scratch, MemOperand(dst, 1, PostIndex));
3294 sub(length, length, Operand(1), SetCC);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003295 b(&align_loop_1);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003296 // Copy bytes in word size chunks.
3297 bind(&word_loop);
Steve Block44f0eee2011-05-26 01:26:41 +01003298 if (emit_debug_code()) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003299 tst(src, Operand(kPointerSize - 1));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003300 Assert(eq, kExpectingAlignmentForCopyBytes);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003301 }
3302 cmp(length, Operand(kPointerSize));
3303 b(lt, &byte_loop);
3304 ldr(scratch, MemOperand(src, kPointerSize, PostIndex));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003305 if (CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) {
3306 str(scratch, MemOperand(dst, kPointerSize, PostIndex));
3307 } else {
3308 strb(scratch, MemOperand(dst, 1, PostIndex));
3309 mov(scratch, Operand(scratch, LSR, 8));
3310 strb(scratch, MemOperand(dst, 1, PostIndex));
3311 mov(scratch, Operand(scratch, LSR, 8));
3312 strb(scratch, MemOperand(dst, 1, PostIndex));
3313 mov(scratch, Operand(scratch, LSR, 8));
3314 strb(scratch, MemOperand(dst, 1, PostIndex));
3315 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003316 sub(length, length, Operand(kPointerSize));
3317 b(&word_loop);
3318
3319 // Copy the last bytes if any left.
3320 bind(&byte_loop);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003321 cmp(length, Operand::Zero());
Ben Murdoche0cee9b2011-05-25 10:26:03 +01003322 b(eq, &done);
3323 bind(&byte_loop_1);
3324 ldrb(scratch, MemOperand(src, 1, PostIndex));
3325 strb(scratch, MemOperand(dst, 1, PostIndex));
3326 sub(length, length, Operand(1), SetCC);
3327 b(ne, &byte_loop_1);
3328 bind(&done);
3329}
3330
3331
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003332void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
3333 Register end_offset,
3334 Register filler) {
3335 Label loop, entry;
3336 b(&entry);
3337 bind(&loop);
3338 str(filler, MemOperand(start_offset, kPointerSize, PostIndex));
3339 bind(&entry);
3340 cmp(start_offset, end_offset);
3341 b(lt, &loop);
3342}
3343
3344
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003345void MacroAssembler::CheckFor32DRegs(Register scratch) {
3346 mov(scratch, Operand(ExternalReference::cpu_features()));
3347 ldr(scratch, MemOperand(scratch));
3348 tst(scratch, Operand(1u << VFP32DREGS));
Steve Block6ded16b2010-05-10 14:33:55 +01003349}
3350
3351
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003352void MacroAssembler::SaveFPRegs(Register location, Register scratch) {
3353 CheckFor32DRegs(scratch);
3354 vstm(db_w, location, d16, d31, ne);
3355 sub(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
3356 vstm(db_w, location, d0, d15);
3357}
3358
3359
3360void MacroAssembler::RestoreFPRegs(Register location, Register scratch) {
3361 CheckFor32DRegs(scratch);
3362 vldm(ia_w, location, d0, d15);
3363 vldm(ia_w, location, d16, d31, ne);
3364 add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
3365}
3366
3367
3368void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialOneByte(
3369 Register first, Register second, Register scratch1, Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +01003370 Label* failure) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003371 const int kFlatOneByteStringMask =
Steve Block6ded16b2010-05-10 14:33:55 +01003372 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003373 const int kFlatOneByteStringTag =
3374 kStringTag | kOneByteStringTag | kSeqStringTag;
3375 and_(scratch1, first, Operand(kFlatOneByteStringMask));
3376 and_(scratch2, second, Operand(kFlatOneByteStringMask));
3377 cmp(scratch1, Operand(kFlatOneByteStringTag));
Steve Block6ded16b2010-05-10 14:33:55 +01003378 // Ignore second test if first test failed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003379 cmp(scratch2, Operand(kFlatOneByteStringTag), eq);
Steve Block6ded16b2010-05-10 14:33:55 +01003380 b(ne, failure);
3381}
3382
3383
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003384void MacroAssembler::JumpIfInstanceTypeIsNotSequentialOneByte(Register type,
3385 Register scratch,
3386 Label* failure) {
3387 const int kFlatOneByteStringMask =
Steve Block6ded16b2010-05-10 14:33:55 +01003388 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003389 const int kFlatOneByteStringTag =
3390 kStringTag | kOneByteStringTag | kSeqStringTag;
3391 and_(scratch, type, Operand(kFlatOneByteStringMask));
3392 cmp(scratch, Operand(kFlatOneByteStringTag));
Steve Block6ded16b2010-05-10 14:33:55 +01003393 b(ne, failure);
3394}
3395
Steve Block44f0eee2011-05-26 01:26:41 +01003396static const int kRegisterPassedArguments = 4;
Steve Block6ded16b2010-05-10 14:33:55 +01003397
Steve Block44f0eee2011-05-26 01:26:41 +01003398
Ben Murdoch257744e2011-11-30 15:57:28 +00003399int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments,
3400 int num_double_arguments) {
3401 int stack_passed_words = 0;
3402 if (use_eabi_hardfloat()) {
3403 // In the hard floating point calling convention, we can use
3404 // all double registers to pass doubles.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003405 if (num_double_arguments > DoubleRegister::NumRegisters()) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003406 stack_passed_words +=
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003407 2 * (num_double_arguments - DoubleRegister::NumRegisters());
Ben Murdoch257744e2011-11-30 15:57:28 +00003408 }
3409 } else {
3410 // In the soft floating point calling convention, every double
3411 // argument is passed using two registers.
3412 num_reg_arguments += 2 * num_double_arguments;
3413 }
Steve Block6ded16b2010-05-10 14:33:55 +01003414 // Up to four simple arguments are passed in registers r0..r3.
Ben Murdoch257744e2011-11-30 15:57:28 +00003415 if (num_reg_arguments > kRegisterPassedArguments) {
3416 stack_passed_words += num_reg_arguments - kRegisterPassedArguments;
3417 }
3418 return stack_passed_words;
3419}
3420
3421
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003422void MacroAssembler::EmitSeqStringSetCharCheck(Register string,
3423 Register index,
3424 Register value,
3425 uint32_t encoding_mask) {
3426 Label is_object;
3427 SmiTst(string);
3428 Check(ne, kNonObject);
3429
3430 ldr(ip, FieldMemOperand(string, HeapObject::kMapOffset));
3431 ldrb(ip, FieldMemOperand(ip, Map::kInstanceTypeOffset));
3432
3433 and_(ip, ip, Operand(kStringRepresentationMask | kStringEncodingMask));
3434 cmp(ip, Operand(encoding_mask));
3435 Check(eq, kUnexpectedStringType);
3436
3437 // The index is assumed to be untagged coming in, tag it to compare with the
3438 // string length without using a temp register, it is restored at the end of
3439 // this function.
3440 Label index_tag_ok, index_tag_bad;
3441 TrySmiTag(index, index, &index_tag_bad);
3442 b(&index_tag_ok);
3443 bind(&index_tag_bad);
3444 Abort(kIndexIsTooLarge);
3445 bind(&index_tag_ok);
3446
3447 ldr(ip, FieldMemOperand(string, String::kLengthOffset));
3448 cmp(index, ip);
3449 Check(lt, kIndexIsTooLarge);
3450
3451 cmp(index, Operand(Smi::FromInt(0)));
3452 Check(ge, kIndexIsNegative);
3453
3454 SmiUntag(index, index);
3455}
3456
3457
Ben Murdoch257744e2011-11-30 15:57:28 +00003458void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
3459 int num_double_arguments,
3460 Register scratch) {
3461 int frame_alignment = ActivationFrameAlignment();
3462 int stack_passed_arguments = CalculateStackPassedWords(
3463 num_reg_arguments, num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01003464 if (frame_alignment > kPointerSize) {
3465 // Make stack end at alignment and make room for num_arguments - 4 words
3466 // and the original value of sp.
3467 mov(scratch, sp);
3468 sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003469 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Steve Block6ded16b2010-05-10 14:33:55 +01003470 and_(sp, sp, Operand(-frame_alignment));
3471 str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
3472 } else {
3473 sub(sp, sp, Operand(stack_passed_arguments * kPointerSize));
3474 }
3475}
3476
3477
Ben Murdoch257744e2011-11-30 15:57:28 +00003478void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
3479 Register scratch) {
3480 PrepareCallCFunction(num_reg_arguments, 0, scratch);
3481}
3482
3483
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003484void MacroAssembler::MovToFloatParameter(DwVfpRegister src) {
3485 DCHECK(src.is(d0));
3486 if (!use_eabi_hardfloat()) {
3487 vmov(r0, r1, src);
Ben Murdoch257744e2011-11-30 15:57:28 +00003488 }
3489}
3490
3491
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003492// On ARM this is just a synonym to make the purpose clear.
3493void MacroAssembler::MovToFloatResult(DwVfpRegister src) {
3494 MovToFloatParameter(src);
Ben Murdoch257744e2011-11-30 15:57:28 +00003495}
3496
3497
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003498void MacroAssembler::MovToFloatParameters(DwVfpRegister src1,
3499 DwVfpRegister src2) {
3500 DCHECK(src1.is(d0));
3501 DCHECK(src2.is(d1));
3502 if (!use_eabi_hardfloat()) {
3503 vmov(r0, r1, src1);
3504 vmov(r2, r3, src2);
Ben Murdoch257744e2011-11-30 15:57:28 +00003505 }
3506}
3507
3508
3509void MacroAssembler::CallCFunction(ExternalReference function,
3510 int num_reg_arguments,
3511 int num_double_arguments) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003512 mov(ip, Operand(function));
3513 CallCFunctionHelper(ip, num_reg_arguments, num_double_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00003514}
3515
3516
3517void MacroAssembler::CallCFunction(Register function,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003518 int num_reg_arguments,
3519 int num_double_arguments) {
3520 CallCFunctionHelper(function, num_reg_arguments, num_double_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00003521}
3522
3523
Steve Block6ded16b2010-05-10 14:33:55 +01003524void MacroAssembler::CallCFunction(ExternalReference function,
3525 int num_arguments) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003526 CallCFunction(function, num_arguments, 0);
Steve Block44f0eee2011-05-26 01:26:41 +01003527}
3528
Ben Murdoch257744e2011-11-30 15:57:28 +00003529
Steve Block44f0eee2011-05-26 01:26:41 +01003530void MacroAssembler::CallCFunction(Register function,
Steve Block44f0eee2011-05-26 01:26:41 +01003531 int num_arguments) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003532 CallCFunction(function, num_arguments, 0);
Steve Block6ded16b2010-05-10 14:33:55 +01003533}
3534
3535
Steve Block44f0eee2011-05-26 01:26:41 +01003536void MacroAssembler::CallCFunctionHelper(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00003537 int num_reg_arguments,
3538 int num_double_arguments) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003539 DCHECK(has_frame());
Steve Block6ded16b2010-05-10 14:33:55 +01003540 // Make sure that the stack is aligned before calling a C function unless
3541 // running in the simulator. The simulator has its own alignment check which
3542 // provides more information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003543#if V8_HOST_ARCH_ARM
Steve Block44f0eee2011-05-26 01:26:41 +01003544 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003545 int frame_alignment = base::OS::ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +01003546 int frame_alignment_mask = frame_alignment - 1;
3547 if (frame_alignment > kPointerSize) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003548 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Steve Block6ded16b2010-05-10 14:33:55 +01003549 Label alignment_as_expected;
3550 tst(sp, Operand(frame_alignment_mask));
3551 b(eq, &alignment_as_expected);
3552 // Don't use Check here, as it will call Runtime_Abort possibly
3553 // re-entering here.
3554 stop("Unexpected alignment");
3555 bind(&alignment_as_expected);
3556 }
3557 }
3558#endif
3559
3560 // Just call directly. The function called cannot cause a GC, or
3561 // allow preemption, so the return address in the link register
3562 // stays correct.
3563 Call(function);
Ben Murdoch257744e2011-11-30 15:57:28 +00003564 int stack_passed_arguments = CalculateStackPassedWords(
3565 num_reg_arguments, num_double_arguments);
3566 if (ActivationFrameAlignment() > kPointerSize) {
Steve Block6ded16b2010-05-10 14:33:55 +01003567 ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
3568 } else {
3569 add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize)));
3570 }
3571}
3572
3573
Steve Block1e0659c2011-05-24 12:43:12 +01003574void MacroAssembler::GetRelocatedValueLocation(Register ldr_location,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003575 Register result,
3576 Register scratch) {
3577 Label small_constant_pool_load, load_result;
Steve Block1e0659c2011-05-24 12:43:12 +01003578 ldr(result, MemOperand(ldr_location));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003579
3580 if (FLAG_enable_ool_constant_pool) {
3581 // Check if this is an extended constant pool load.
3582 and_(scratch, result, Operand(GetConsantPoolLoadMask()));
3583 teq(scratch, Operand(GetConsantPoolLoadPattern()));
3584 b(eq, &small_constant_pool_load);
3585 if (emit_debug_code()) {
3586 // Check that the instruction sequence is:
3587 // movw reg, #offset_low
3588 // movt reg, #offset_high
3589 // ldr reg, [pp, reg]
3590 Instr patterns[] = {GetMovWPattern(), GetMovTPattern(),
3591 GetLdrPpRegOffsetPattern()};
3592 for (int i = 0; i < 3; i++) {
3593 ldr(result, MemOperand(ldr_location, i * kInstrSize));
3594 and_(result, result, Operand(patterns[i]));
3595 cmp(result, Operand(patterns[i]));
3596 Check(eq, kTheInstructionToPatchShouldBeALoadFromConstantPool);
3597 }
3598 // Result was clobbered. Restore it.
3599 ldr(result, MemOperand(ldr_location));
3600 }
3601
3602 // Get the offset into the constant pool. First extract movw immediate into
3603 // result.
3604 and_(scratch, result, Operand(0xfff));
3605 mov(ip, Operand(result, LSR, 4));
3606 and_(ip, ip, Operand(0xf000));
3607 orr(result, scratch, Operand(ip));
3608 // Then extract movt immediate and or into result.
3609 ldr(scratch, MemOperand(ldr_location, kInstrSize));
3610 and_(ip, scratch, Operand(0xf0000));
3611 orr(result, result, Operand(ip, LSL, 12));
3612 and_(scratch, scratch, Operand(0xfff));
3613 orr(result, result, Operand(scratch, LSL, 16));
3614
3615 b(&load_result);
3616 }
3617
3618 bind(&small_constant_pool_load);
Steve Block44f0eee2011-05-26 01:26:41 +01003619 if (emit_debug_code()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003620 // Check that the instruction is a ldr reg, [<pc or pp> + offset] .
3621 and_(result, result, Operand(GetConsantPoolLoadPattern()));
3622 cmp(result, Operand(GetConsantPoolLoadPattern()));
3623 Check(eq, kTheInstructionToPatchShouldBeALoadFromConstantPool);
Steve Block1e0659c2011-05-24 12:43:12 +01003624 // Result was clobbered. Restore it.
3625 ldr(result, MemOperand(ldr_location));
3626 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003627
3628 // Get the offset into the constant pool.
3629 const uint32_t kLdrOffsetMask = (1 << 12) - 1;
Steve Block1e0659c2011-05-24 12:43:12 +01003630 and_(result, result, Operand(kLdrOffsetMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003631
3632 bind(&load_result);
3633 // Get the address of the constant.
3634 if (FLAG_enable_ool_constant_pool) {
3635 add(result, pp, Operand(result));
3636 } else {
3637 add(result, ldr_location, Operand(result));
3638 add(result, result, Operand(Instruction::kPCReadOffset));
3639 }
Steve Block1e0659c2011-05-24 12:43:12 +01003640}
3641
3642
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003643void MacroAssembler::CheckPageFlag(
3644 Register object,
3645 Register scratch,
3646 int mask,
3647 Condition cc,
3648 Label* condition_met) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003649 Bfc(scratch, object, 0, kPageSizeBits);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003650 ldr(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset));
3651 tst(scratch, Operand(mask));
3652 b(cc, condition_met);
3653}
3654
3655
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003656void MacroAssembler::CheckMapDeprecated(Handle<Map> map,
3657 Register scratch,
3658 Label* if_deprecated) {
3659 if (map->CanBeDeprecated()) {
3660 mov(scratch, Operand(map));
3661 ldr(scratch, FieldMemOperand(scratch, Map::kBitField3Offset));
3662 tst(scratch, Operand(Map::Deprecated::kMask));
3663 b(ne, if_deprecated);
3664 }
3665}
3666
3667
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003668void MacroAssembler::JumpIfBlack(Register object,
3669 Register scratch0,
3670 Register scratch1,
3671 Label* on_black) {
3672 HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003673 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003674}
3675
3676
3677void MacroAssembler::HasColor(Register object,
3678 Register bitmap_scratch,
3679 Register mask_scratch,
3680 Label* has_color,
3681 int first_bit,
3682 int second_bit) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003683 DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, no_reg));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003684
3685 GetMarkBits(object, bitmap_scratch, mask_scratch);
3686
3687 Label other_color, word_boundary;
3688 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3689 tst(ip, Operand(mask_scratch));
3690 b(first_bit == 1 ? eq : ne, &other_color);
3691 // Shift left 1 by adding.
3692 add(mask_scratch, mask_scratch, Operand(mask_scratch), SetCC);
3693 b(eq, &word_boundary);
3694 tst(ip, Operand(mask_scratch));
3695 b(second_bit == 1 ? ne : eq, has_color);
3696 jmp(&other_color);
3697
3698 bind(&word_boundary);
3699 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize));
3700 tst(ip, Operand(1));
3701 b(second_bit == 1 ? ne : eq, has_color);
3702 bind(&other_color);
3703}
3704
3705
3706// Detect some, but not all, common pointer-free objects. This is used by the
3707// incremental write barrier which doesn't care about oddballs (they are always
3708// marked black immediately so this code is not hit).
3709void MacroAssembler::JumpIfDataObject(Register value,
3710 Register scratch,
3711 Label* not_data_object) {
3712 Label is_data_object;
3713 ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
3714 CompareRoot(scratch, Heap::kHeapNumberMapRootIndex);
3715 b(eq, &is_data_object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003716 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
3717 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003718 // If it's a string and it's not a cons string then it's an object containing
3719 // no GC pointers.
3720 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
3721 tst(scratch, Operand(kIsIndirectStringMask | kIsNotStringMask));
3722 b(ne, not_data_object);
3723 bind(&is_data_object);
3724}
3725
3726
3727void MacroAssembler::GetMarkBits(Register addr_reg,
3728 Register bitmap_reg,
3729 Register mask_reg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003730 DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003731 and_(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask));
3732 Ubfx(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2);
3733 const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2;
3734 Ubfx(ip, addr_reg, kLowBits, kPageSizeBits - kLowBits);
3735 add(bitmap_reg, bitmap_reg, Operand(ip, LSL, kPointerSizeLog2));
3736 mov(ip, Operand(1));
3737 mov(mask_reg, Operand(ip, LSL, mask_reg));
3738}
3739
3740
3741void MacroAssembler::EnsureNotWhite(
3742 Register value,
3743 Register bitmap_scratch,
3744 Register mask_scratch,
3745 Register load_scratch,
3746 Label* value_is_white_and_not_data) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003747 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, ip));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003748 GetMarkBits(value, bitmap_scratch, mask_scratch);
3749
3750 // If the value is black or grey we don't need to do anything.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003751 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
3752 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
3753 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
3754 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003755
3756 Label done;
3757
3758 // Since both black and grey have a 1 in the first position and white does
3759 // not have a 1 there we only need to check one bit.
3760 ldr(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3761 tst(mask_scratch, load_scratch);
3762 b(ne, &done);
3763
3764 if (emit_debug_code()) {
3765 // Check for impossible bit pattern.
3766 Label ok;
3767 // LSL may overflow, making the check conservative.
3768 tst(load_scratch, Operand(mask_scratch, LSL, 1));
3769 b(eq, &ok);
3770 stop("Impossible marking bit pattern");
3771 bind(&ok);
3772 }
3773
3774 // Value is white. We check whether it is data that doesn't need scanning.
3775 // Currently only checks for HeapNumber and non-cons strings.
3776 Register map = load_scratch; // Holds map while checking type.
3777 Register length = load_scratch; // Holds length of object after testing type.
3778 Label is_data_object;
3779
3780 // Check for heap-number
3781 ldr(map, FieldMemOperand(value, HeapObject::kMapOffset));
3782 CompareRoot(map, Heap::kHeapNumberMapRootIndex);
3783 mov(length, Operand(HeapNumber::kSize), LeaveCC, eq);
3784 b(eq, &is_data_object);
3785
3786 // Check for strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003787 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
3788 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003789 // If it's a string and it's not a cons string then it's an object containing
3790 // no GC pointers.
3791 Register instance_type = load_scratch;
3792 ldrb(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset));
3793 tst(instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask));
3794 b(ne, value_is_white_and_not_data);
3795 // It's a non-indirect (non-cons and non-slice) string.
3796 // If it's external, the length is just ExternalString::kSize.
3797 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2).
3798 // External strings are the only ones with the kExternalStringTag bit
3799 // set.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003800 DCHECK_EQ(0, kSeqStringTag & kExternalStringTag);
3801 DCHECK_EQ(0, kConsStringTag & kExternalStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003802 tst(instance_type, Operand(kExternalStringTag));
3803 mov(length, Operand(ExternalString::kSize), LeaveCC, ne);
3804 b(ne, &is_data_object);
3805
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003806 // Sequential string, either Latin1 or UC16.
3807 // For Latin1 (char-size of 1) we shift the smi tag away to get the length.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003808 // For UC16 (char-size of 2) we just leave the smi tag in place, thereby
3809 // getting the length multiplied by 2.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003810 DCHECK(kOneByteStringTag == 4 && kStringEncodingMask == 4);
3811 DCHECK(kSmiTag == 0 && kSmiTagSize == 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003812 ldr(ip, FieldMemOperand(value, String::kLengthOffset));
3813 tst(instance_type, Operand(kStringEncodingMask));
3814 mov(ip, Operand(ip, LSR, 1), LeaveCC, ne);
3815 add(length, ip, Operand(SeqString::kHeaderSize + kObjectAlignmentMask));
3816 and_(length, length, Operand(~kObjectAlignmentMask));
3817
3818 bind(&is_data_object);
3819 // Value is a data object, and it is white. Mark it black. Since we know
3820 // that the object is white we can make it black by flipping one bit.
3821 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3822 orr(ip, ip, Operand(mask_scratch));
3823 str(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3824
3825 and_(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask));
3826 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
3827 add(ip, ip, Operand(length));
3828 str(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
3829
3830 bind(&done);
3831}
3832
3833
Ben Murdoch257744e2011-11-30 15:57:28 +00003834void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) {
3835 Usat(output_reg, 8, Operand(input_reg));
3836}
3837
3838
3839void MacroAssembler::ClampDoubleToUint8(Register result_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003840 DwVfpRegister input_reg,
3841 LowDwVfpRegister double_scratch) {
Ben Murdoch257744e2011-11-30 15:57:28 +00003842 Label done;
Ben Murdoch257744e2011-11-30 15:57:28 +00003843
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003844 // Handle inputs >= 255 (including +infinity).
3845 Vmov(double_scratch, 255.0, result_reg);
Ben Murdoch257744e2011-11-30 15:57:28 +00003846 mov(result_reg, Operand(255));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003847 VFPCompareAndSetFlags(input_reg, double_scratch);
3848 b(ge, &done);
Ben Murdoch257744e2011-11-30 15:57:28 +00003849
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003850 // For inputs < 255 (including negative) vcvt_u32_f64 with round-to-nearest
3851 // rounding mode will provide the correct result.
3852 vcvt_u32_f64(double_scratch.low(), input_reg, kFPSCRRounding);
3853 vmov(result_reg, double_scratch.low());
3854
Ben Murdoch257744e2011-11-30 15:57:28 +00003855 bind(&done);
3856}
3857
3858
3859void MacroAssembler::LoadInstanceDescriptors(Register map,
3860 Register descriptors) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003861 ldr(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset));
3862}
3863
3864
3865void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) {
3866 ldr(dst, FieldMemOperand(map, Map::kBitField3Offset));
3867 DecodeField<Map::NumberOfOwnDescriptorsBits>(dst);
3868}
3869
3870
3871void MacroAssembler::EnumLength(Register dst, Register map) {
3872 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0);
3873 ldr(dst, FieldMemOperand(map, Map::kBitField3Offset));
3874 and_(dst, dst, Operand(Map::EnumLengthBits::kMask));
3875 SmiTag(dst);
Ben Murdoch257744e2011-11-30 15:57:28 +00003876}
3877
3878
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003879void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003880 Register empty_fixed_array_value = r6;
3881 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003882 Label next, start;
3883 mov(r2, r0);
3884
3885 // Check if the enum length field is properly initialized, indicating that
3886 // there is an enum cache.
3887 ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset));
3888
3889 EnumLength(r3, r1);
3890 cmp(r3, Operand(Smi::FromInt(kInvalidEnumCacheSentinel)));
3891 b(eq, call_runtime);
3892
3893 jmp(&start);
3894
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003895 bind(&next);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003896 ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003897
3898 // For all objects but the receiver, check that the cache is empty.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003899 EnumLength(r3, r1);
3900 cmp(r3, Operand(Smi::FromInt(0)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003901 b(ne, call_runtime);
3902
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003903 bind(&start);
3904
3905 // Check that there are no elements. Register r2 contains the current JS
3906 // object we've reached through the prototype chain.
3907 Label no_elements;
3908 ldr(r2, FieldMemOperand(r2, JSObject::kElementsOffset));
3909 cmp(r2, empty_fixed_array_value);
3910 b(eq, &no_elements);
3911
3912 // Second chance, the object may be using the empty slow element dictionary.
3913 CompareRoot(r2, Heap::kEmptySlowElementDictionaryRootIndex);
3914 b(ne, call_runtime);
3915
3916 bind(&no_elements);
3917 ldr(r2, FieldMemOperand(r1, Map::kPrototypeOffset));
3918 cmp(r2, null_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003919 b(ne, &next);
3920}
3921
3922
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003923void MacroAssembler::TestJSArrayForAllocationMemento(
3924 Register receiver_reg,
3925 Register scratch_reg,
3926 Label* no_memento_found) {
3927 ExternalReference new_space_start =
3928 ExternalReference::new_space_start(isolate());
3929 ExternalReference new_space_allocation_top =
3930 ExternalReference::new_space_allocation_top_address(isolate());
3931 add(scratch_reg, receiver_reg,
3932 Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag));
3933 cmp(scratch_reg, Operand(new_space_start));
3934 b(lt, no_memento_found);
3935 mov(ip, Operand(new_space_allocation_top));
3936 ldr(ip, MemOperand(ip));
3937 cmp(scratch_reg, ip);
3938 b(gt, no_memento_found);
3939 ldr(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize));
3940 cmp(scratch_reg,
3941 Operand(isolate()->factory()->allocation_memento_map()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003942}
3943
3944
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003945Register GetRegisterThatIsNotOneOf(Register reg1,
3946 Register reg2,
3947 Register reg3,
3948 Register reg4,
3949 Register reg5,
3950 Register reg6) {
3951 RegList regs = 0;
3952 if (reg1.is_valid()) regs |= reg1.bit();
3953 if (reg2.is_valid()) regs |= reg2.bit();
3954 if (reg3.is_valid()) regs |= reg3.bit();
3955 if (reg4.is_valid()) regs |= reg4.bit();
3956 if (reg5.is_valid()) regs |= reg5.bit();
3957 if (reg6.is_valid()) regs |= reg6.bit();
3958
3959 for (int i = 0; i < Register::NumAllocatableRegisters(); i++) {
3960 Register candidate = Register::FromAllocationIndex(i);
3961 if (regs & candidate.bit()) continue;
3962 return candidate;
3963 }
3964 UNREACHABLE();
3965 return no_reg;
3966}
3967
3968
3969void MacroAssembler::JumpIfDictionaryInPrototypeChain(
3970 Register object,
3971 Register scratch0,
3972 Register scratch1,
3973 Label* found) {
3974 DCHECK(!scratch1.is(scratch0));
3975 Factory* factory = isolate()->factory();
3976 Register current = scratch0;
3977 Label loop_again;
3978
3979 // scratch contained elements pointer.
3980 mov(current, object);
3981
3982 // Loop based on the map going up the prototype chain.
3983 bind(&loop_again);
3984 ldr(current, FieldMemOperand(current, HeapObject::kMapOffset));
3985 ldr(scratch1, FieldMemOperand(current, Map::kBitField2Offset));
3986 DecodeField<Map::ElementsKindBits>(scratch1);
3987 cmp(scratch1, Operand(DICTIONARY_ELEMENTS));
3988 b(eq, found);
3989 ldr(current, FieldMemOperand(current, Map::kPrototypeOffset));
3990 cmp(current, Operand(factory->null_value()));
3991 b(ne, &loop_again);
3992}
3993
3994
3995#ifdef DEBUG
3996bool AreAliased(Register reg1,
3997 Register reg2,
3998 Register reg3,
3999 Register reg4,
4000 Register reg5,
4001 Register reg6,
4002 Register reg7,
4003 Register reg8) {
4004 int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() +
4005 reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid() +
4006 reg7.is_valid() + reg8.is_valid();
4007
4008 RegList regs = 0;
4009 if (reg1.is_valid()) regs |= reg1.bit();
4010 if (reg2.is_valid()) regs |= reg2.bit();
4011 if (reg3.is_valid()) regs |= reg3.bit();
4012 if (reg4.is_valid()) regs |= reg4.bit();
4013 if (reg5.is_valid()) regs |= reg5.bit();
4014 if (reg6.is_valid()) regs |= reg6.bit();
4015 if (reg7.is_valid()) regs |= reg7.bit();
4016 if (reg8.is_valid()) regs |= reg8.bit();
4017 int n_of_non_aliasing_regs = NumRegs(regs);
4018
4019 return n_of_valid_regs != n_of_non_aliasing_regs;
4020}
4021#endif
4022
4023
4024CodePatcher::CodePatcher(byte* address,
4025 int instructions,
4026 FlushICache flush_cache)
Steve Blocka7e24c12009-10-30 11:49:00 +00004027 : address_(address),
Steve Blocka7e24c12009-10-30 11:49:00 +00004028 size_(instructions * Assembler::kInstrSize),
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004029 masm_(NULL, address, size_ + Assembler::kGap),
4030 flush_cache_(flush_cache) {
Steve Blocka7e24c12009-10-30 11:49:00 +00004031 // Create a new macro assembler pointing to the address of the code to patch.
4032 // The size is adjusted with kGap on order for the assembler to generate size
4033 // bytes of instructions without failing with buffer size constraints.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004034 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
Steve Blocka7e24c12009-10-30 11:49:00 +00004035}
4036
4037
4038CodePatcher::~CodePatcher() {
4039 // Indicate that code has changed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004040 if (flush_cache_ == FLUSH) {
4041 CpuFeatures::FlushICache(address_, size_);
4042 }
Steve Blocka7e24c12009-10-30 11:49:00 +00004043
4044 // Check that the code was patched as expected.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004045 DCHECK(masm_.pc_ == address_ + size_);
4046 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
Steve Blocka7e24c12009-10-30 11:49:00 +00004047}
4048
4049
Steve Block1e0659c2011-05-24 12:43:12 +01004050void CodePatcher::Emit(Instr instr) {
4051 masm()->emit(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00004052}
4053
4054
4055void CodePatcher::Emit(Address addr) {
4056 masm()->emit(reinterpret_cast<Instr>(addr));
4057}
Steve Block1e0659c2011-05-24 12:43:12 +01004058
4059
4060void CodePatcher::EmitCondition(Condition cond) {
4061 Instr instr = Assembler::instr_at(masm_.pc_);
4062 instr = (instr & ~kCondMask) | cond;
4063 masm_.emit(instr);
4064}
Steve Blocka7e24c12009-10-30 11:49:00 +00004065
4066
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004067void MacroAssembler::TruncatingDiv(Register result,
4068 Register dividend,
4069 int32_t divisor) {
4070 DCHECK(!dividend.is(result));
4071 DCHECK(!dividend.is(ip));
4072 DCHECK(!result.is(ip));
4073 base::MagicNumbersForDivision<uint32_t> mag =
4074 base::SignedDivisionByConstant(static_cast<uint32_t>(divisor));
4075 mov(ip, Operand(mag.multiplier));
4076 smull(ip, result, dividend, ip);
4077 bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0;
4078 if (divisor > 0 && neg) {
4079 add(result, result, Operand(dividend));
4080 }
4081 if (divisor < 0 && !neg && mag.multiplier > 0) {
4082 sub(result, result, Operand(dividend));
4083 }
4084 if (mag.shift > 0) mov(result, Operand(result, ASR, mag.shift));
4085 add(result, result, Operand(dividend, LSR, 31));
4086}
4087
4088
Steve Blocka7e24c12009-10-30 11:49:00 +00004089} } // namespace v8::internal
Leon Clarkef7060e22010-06-03 12:02:55 +01004090
4091#endif // V8_TARGET_ARCH_ARM