1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <limits.h> // For LONG_MIN, LONG_MAX.
6
7 #include "src/v8.h"
8
9 #if V8_TARGET_ARCH_ARM
10
11 #include "src/bootstrapper.h"
12 #include "src/codegen.h"
13 #include "src/cpu-profiler.h"
14 #include "src/debug.h"
15 #include "src/isolate-inl.h"
16 #include "src/runtime.h"
17
18 namespace v8 {
19 namespace internal {
20
MacroAssembler(Isolate * arg_isolate,void * buffer,int size)21 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size)
22 : Assembler(arg_isolate, buffer, size),
23 generating_stub_(false),
24 has_frame_(false) {
25 if (isolate() != NULL) {
26 code_object_ = Handle<Object>(isolate()->heap()->undefined_value(),
27 isolate());
28 }
29 }
30
31
Jump(Register target,Condition cond)32 void MacroAssembler::Jump(Register target, Condition cond) {
33 bx(target, cond);
34 }
35
36
Jump(intptr_t target,RelocInfo::Mode rmode,Condition cond)37 void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
38 Condition cond) {
39 ASSERT(RelocInfo::IsCodeTarget(rmode));
40 mov(pc, Operand(target, rmode), LeaveCC, cond);
41 }
42
43
Jump(Address target,RelocInfo::Mode rmode,Condition cond)44 void MacroAssembler::Jump(Address target, RelocInfo::Mode rmode,
45 Condition cond) {
46 ASSERT(!RelocInfo::IsCodeTarget(rmode));
47 Jump(reinterpret_cast<intptr_t>(target), rmode, cond);
48 }
49
50
Jump(Handle<Code> code,RelocInfo::Mode rmode,Condition cond)51 void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
52 Condition cond) {
53 ASSERT(RelocInfo::IsCodeTarget(rmode));
54 // 'code' is always generated ARM code, never THUMB code
55 AllowDeferredHandleDereference embedding_raw_address;
56 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
57 }
58
59
CallSize(Register target,Condition cond)60 int MacroAssembler::CallSize(Register target, Condition cond) {
61 return kInstrSize;
62 }
63
64
Call(Register target,Condition cond)65 void MacroAssembler::Call(Register target, Condition cond) {
66 // Block constant pool for the call instruction sequence.
67 BlockConstPoolScope block_const_pool(this);
68 Label start;
69 bind(&start);
70 blx(target, cond);
71 ASSERT_EQ(CallSize(target, cond), SizeOfCodeGeneratedSince(&start));
72 }
73
74
CallSize(Address target,RelocInfo::Mode rmode,Condition cond)75 int MacroAssembler::CallSize(
76 Address target, RelocInfo::Mode rmode, Condition cond) {
77 int size = 2 * kInstrSize;
78 Instr mov_instr = cond | MOV | LeaveCC;
79 intptr_t immediate = reinterpret_cast<intptr_t>(target);
80 if (!Operand(immediate, rmode).is_single_instruction(this, mov_instr)) {
81 size += kInstrSize;
82 }
83 return size;
84 }
85
86
CallStubSize(CodeStub * stub,TypeFeedbackId ast_id,Condition cond)87 int MacroAssembler::CallStubSize(
88 CodeStub* stub, TypeFeedbackId ast_id, Condition cond) {
89 return CallSize(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id, cond);
90 }
91
92
CallSizeNotPredictableCodeSize(Isolate * isolate,Address target,RelocInfo::Mode rmode,Condition cond)93 int MacroAssembler::CallSizeNotPredictableCodeSize(Isolate* isolate,
94 Address target,
95 RelocInfo::Mode rmode,
96 Condition cond) {
97 int size = 2 * kInstrSize;
98 Instr mov_instr = cond | MOV | LeaveCC;
99 intptr_t immediate = reinterpret_cast<intptr_t>(target);
100 if (!Operand(immediate, rmode).is_single_instruction(NULL, mov_instr)) {
101 size += kInstrSize;
102 }
103 return size;
104 }
105
106
Call(Address target,RelocInfo::Mode rmode,Condition cond,TargetAddressStorageMode mode)107 void MacroAssembler::Call(Address target,
108 RelocInfo::Mode rmode,
109 Condition cond,
110 TargetAddressStorageMode mode) {
111 // Block constant pool for the call instruction sequence.
112 BlockConstPoolScope block_const_pool(this);
113 Label start;
114 bind(&start);
115
116 bool old_predictable_code_size = predictable_code_size();
117 if (mode == NEVER_INLINE_TARGET_ADDRESS) {
118 set_predictable_code_size(true);
119 }
120
121 #ifdef DEBUG
122 // Check the expected size before generating code to ensure we assume the same
123 // constant pool availability (e.g., whether constant pool is full or not).
124 int expected_size = CallSize(target, rmode, cond);
125 #endif
126
127 // Call sequence on V7 or later may be :
128 // movw ip, #... @ call address low 16
129 // movt ip, #... @ call address high 16
130 // blx ip
131 // @ return address
132 // Or for pre-V7 or values that may be back-patched
133 // to avoid ICache flushes:
134 // ldr ip, [pc, #...] @ call address
135 // blx ip
136 // @ return address
137
138 // Statement positions are expected to be recorded when the target
139 // address is loaded. The mov method will automatically record
140 // positions when pc is the target, since this is not the case here
141 // we have to do it explicitly.
142 positions_recorder()->WriteRecordedPositions();
143
144 mov(ip, Operand(reinterpret_cast<int32_t>(target), rmode));
145 blx(ip, cond);
146
147 ASSERT_EQ(expected_size, SizeOfCodeGeneratedSince(&start));
148 if (mode == NEVER_INLINE_TARGET_ADDRESS) {
149 set_predictable_code_size(old_predictable_code_size);
150 }
151 }
152
153
CallSize(Handle<Code> code,RelocInfo::Mode rmode,TypeFeedbackId ast_id,Condition cond)154 int MacroAssembler::CallSize(Handle<Code> code,
155 RelocInfo::Mode rmode,
156 TypeFeedbackId ast_id,
157 Condition cond) {
158 AllowDeferredHandleDereference using_raw_address;
159 return CallSize(reinterpret_cast<Address>(code.location()), rmode, cond);
160 }
161
162
Call(Handle<Code> code,RelocInfo::Mode rmode,TypeFeedbackId ast_id,Condition cond,TargetAddressStorageMode mode)163 void MacroAssembler::Call(Handle<Code> code,
164 RelocInfo::Mode rmode,
165 TypeFeedbackId ast_id,
166 Condition cond,
167 TargetAddressStorageMode mode) {
168 Label start;
169 bind(&start);
170 ASSERT(RelocInfo::IsCodeTarget(rmode));
171 if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) {
172 SetRecordedAstId(ast_id);
173 rmode = RelocInfo::CODE_TARGET_WITH_ID;
174 }
175 // 'code' is always generated ARM code, never THUMB code
176 AllowDeferredHandleDereference embedding_raw_address;
177 Call(reinterpret_cast<Address>(code.location()), rmode, cond, mode);
178 }
179
180
Ret(Condition cond)181 void MacroAssembler::Ret(Condition cond) {
182 bx(lr, cond);
183 }
184
185
Drop(int count,Condition cond)186 void MacroAssembler::Drop(int count, Condition cond) {
187 if (count > 0) {
188 add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond);
189 }
190 }
191
192
Ret(int drop,Condition cond)193 void MacroAssembler::Ret(int drop, Condition cond) {
194 Drop(drop, cond);
195 Ret(cond);
196 }
197
198
Swap(Register reg1,Register reg2,Register scratch,Condition cond)199 void MacroAssembler::Swap(Register reg1,
200 Register reg2,
201 Register scratch,
202 Condition cond) {
203 if (scratch.is(no_reg)) {
204 eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
205 eor(reg2, reg2, Operand(reg1), LeaveCC, cond);
206 eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
207 } else {
208 mov(scratch, reg1, LeaveCC, cond);
209 mov(reg1, reg2, LeaveCC, cond);
210 mov(reg2, scratch, LeaveCC, cond);
211 }
212 }
213
214
Call(Label * target)215 void MacroAssembler::Call(Label* target) {
216 bl(target);
217 }
218
219
Push(Handle<Object> handle)220 void MacroAssembler::Push(Handle<Object> handle) {
221 mov(ip, Operand(handle));
222 push(ip);
223 }
224
225
Move(Register dst,Handle<Object> value)226 void MacroAssembler::Move(Register dst, Handle<Object> value) {
227 AllowDeferredHandleDereference smi_check;
228 if (value->IsSmi()) {
229 mov(dst, Operand(value));
230 } else {
231 ASSERT(value->IsHeapObject());
232 if (isolate()->heap()->InNewSpace(*value)) {
233 Handle<Cell> cell = isolate()->factory()->NewCell(value);
234 mov(dst, Operand(cell));
235 ldr(dst, FieldMemOperand(dst, Cell::kValueOffset));
236 } else {
237 mov(dst, Operand(value));
238 }
239 }
240 }
241
242
Move(Register dst,Register src,Condition cond)243 void MacroAssembler::Move(Register dst, Register src, Condition cond) {
244 if (!dst.is(src)) {
245 mov(dst, src, LeaveCC, cond);
246 }
247 }
248
249
Move(DwVfpRegister dst,DwVfpRegister src)250 void MacroAssembler::Move(DwVfpRegister dst, DwVfpRegister src) {
251 if (!dst.is(src)) {
252 vmov(dst, src);
253 }
254 }
255
256
Mls(Register dst,Register src1,Register src2,Register srcA,Condition cond)257 void MacroAssembler::Mls(Register dst, Register src1, Register src2,
258 Register srcA, Condition cond) {
259 if (CpuFeatures::IsSupported(MLS)) {
260 CpuFeatureScope scope(this, MLS);
261 mls(dst, src1, src2, srcA, cond);
262 } else {
263 ASSERT(!dst.is(srcA));
264 mul(ip, src1, src2, LeaveCC, cond);
265 sub(dst, srcA, ip, LeaveCC, cond);
266 }
267 }
268
269
And(Register dst,Register src1,const Operand & src2,Condition cond)270 void MacroAssembler::And(Register dst, Register src1, const Operand& src2,
271 Condition cond) {
272 if (!src2.is_reg() &&
273 !src2.must_output_reloc_info(this) &&
274 src2.immediate() == 0) {
275 mov(dst, Operand::Zero(), LeaveCC, cond);
276 } else if (!src2.is_single_instruction(this) &&
277 !src2.must_output_reloc_info(this) &&
278 CpuFeatures::IsSupported(ARMv7) &&
279 IsPowerOf2(src2.immediate() + 1)) {
280 ubfx(dst, src1, 0,
281 WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond);
282 } else {
283 and_(dst, src1, src2, LeaveCC, cond);
284 }
285 }
286
287
Ubfx(Register dst,Register src1,int lsb,int width,Condition cond)288 void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width,
289 Condition cond) {
290 ASSERT(lsb < 32);
291 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
292 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
293 and_(dst, src1, Operand(mask), LeaveCC, cond);
294 if (lsb != 0) {
295 mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond);
296 }
297 } else {
298 ubfx(dst, src1, lsb, width, cond);
299 }
300 }
301
302
Sbfx(Register dst,Register src1,int lsb,int width,Condition cond)303 void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width,
304 Condition cond) {
305 ASSERT(lsb < 32);
306 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
307 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
308 and_(dst, src1, Operand(mask), LeaveCC, cond);
309 int shift_up = 32 - lsb - width;
310 int shift_down = lsb + shift_up;
311 if (shift_up != 0) {
312 mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond);
313 }
314 if (shift_down != 0) {
315 mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond);
316 }
317 } else {
318 sbfx(dst, src1, lsb, width, cond);
319 }
320 }
321
322
Bfi(Register dst,Register src,Register scratch,int lsb,int width,Condition cond)323 void MacroAssembler::Bfi(Register dst,
324 Register src,
325 Register scratch,
326 int lsb,
327 int width,
328 Condition cond) {
329 ASSERT(0 <= lsb && lsb < 32);
330 ASSERT(0 <= width && width < 32);
331 ASSERT(lsb + width < 32);
332 ASSERT(!scratch.is(dst));
333 if (width == 0) return;
334 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
335 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
336 bic(dst, dst, Operand(mask));
337 and_(scratch, src, Operand((1 << width) - 1));
338 mov(scratch, Operand(scratch, LSL, lsb));
339 orr(dst, dst, scratch);
340 } else {
341 bfi(dst, src, lsb, width, cond);
342 }
343 }
344
345
Bfc(Register dst,Register src,int lsb,int width,Condition cond)346 void MacroAssembler::Bfc(Register dst, Register src, int lsb, int width,
347 Condition cond) {
348 ASSERT(lsb < 32);
349 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
350 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
351 bic(dst, src, Operand(mask));
352 } else {
353 Move(dst, src, cond);
354 bfc(dst, lsb, width, cond);
355 }
356 }
357
358
Usat(Register dst,int satpos,const Operand & src,Condition cond)359 void MacroAssembler::Usat(Register dst, int satpos, const Operand& src,
360 Condition cond) {
361 if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) {
362 ASSERT(!dst.is(pc) && !src.rm().is(pc));
363 ASSERT((satpos >= 0) && (satpos <= 31));
364
365 // These asserts are required to ensure compatibility with the ARMv7
366 // implementation.
367 ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL));
368 ASSERT(src.rs().is(no_reg));
369
370 Label done;
371 int satval = (1 << satpos) - 1;
372
373 if (cond != al) {
374 b(NegateCondition(cond), &done); // Skip saturate if !condition.
375 }
376 if (!(src.is_reg() && dst.is(src.rm()))) {
377 mov(dst, src);
378 }
379 tst(dst, Operand(~satval));
380 b(eq, &done);
381 mov(dst, Operand::Zero(), LeaveCC, mi); // 0 if negative.
382 mov(dst, Operand(satval), LeaveCC, pl); // satval if positive.
383 bind(&done);
384 } else {
385 usat(dst, satpos, src, cond);
386 }
387 }
388
389
Load(Register dst,const MemOperand & src,Representation r)390 void MacroAssembler::Load(Register dst,
391 const MemOperand& src,
392 Representation r) {
393 ASSERT(!r.IsDouble());
394 if (r.IsInteger8()) {
395 ldrsb(dst, src);
396 } else if (r.IsUInteger8()) {
397 ldrb(dst, src);
398 } else if (r.IsInteger16()) {
399 ldrsh(dst, src);
400 } else if (r.IsUInteger16()) {
401 ldrh(dst, src);
402 } else {
403 ldr(dst, src);
404 }
405 }
406
407
Store(Register src,const MemOperand & dst,Representation r)408 void MacroAssembler::Store(Register src,
409 const MemOperand& dst,
410 Representation r) {
411 ASSERT(!r.IsDouble());
412 if (r.IsInteger8() || r.IsUInteger8()) {
413 strb(src, dst);
414 } else if (r.IsInteger16() || r.IsUInteger16()) {
415 strh(src, dst);
416 } else {
417 if (r.IsHeapObject()) {
418 AssertNotSmi(src);
419 } else if (r.IsSmi()) {
420 AssertSmi(src);
421 }
422 str(src, dst);
423 }
424 }
425
426
LoadRoot(Register destination,Heap::RootListIndex index,Condition cond)427 void MacroAssembler::LoadRoot(Register destination,
428 Heap::RootListIndex index,
429 Condition cond) {
430 if (CpuFeatures::IsSupported(MOVW_MOVT_IMMEDIATE_LOADS) &&
431 isolate()->heap()->RootCanBeTreatedAsConstant(index) &&
432 !predictable_code_size()) {
433 // The CPU supports fast immediate values, and this root will never
434 // change. We will load it as a relocatable immediate value.
435 Handle<Object> root(&isolate()->heap()->roots_array_start()[index]);
436 mov(destination, Operand(root), LeaveCC, cond);
437 return;
438 }
439 ldr(destination, MemOperand(kRootRegister, index << kPointerSizeLog2), cond);
440 }
441
442
StoreRoot(Register source,Heap::RootListIndex index,Condition cond)443 void MacroAssembler::StoreRoot(Register source,
444 Heap::RootListIndex index,
445 Condition cond) {
446 str(source, MemOperand(kRootRegister, index << kPointerSizeLog2), cond);
447 }
448
449
InNewSpace(Register object,Register scratch,Condition cond,Label * branch)450 void MacroAssembler::InNewSpace(Register object,
451 Register scratch,
452 Condition cond,
453 Label* branch) {
454 ASSERT(cond == eq || cond == ne);
455 and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate())));
456 cmp(scratch, Operand(ExternalReference::new_space_start(isolate())));
457 b(cond, branch);
458 }
459
460
RecordWriteField(Register object,int offset,Register value,Register dst,LinkRegisterStatus lr_status,SaveFPRegsMode save_fp,RememberedSetAction remembered_set_action,SmiCheck smi_check,PointersToHereCheck pointers_to_here_check_for_value)461 void MacroAssembler::RecordWriteField(
462 Register object,
463 int offset,
464 Register value,
465 Register dst,
466 LinkRegisterStatus lr_status,
467 SaveFPRegsMode save_fp,
468 RememberedSetAction remembered_set_action,
469 SmiCheck smi_check,
470 PointersToHereCheck pointers_to_here_check_for_value) {
471 // First, check if a write barrier is even needed. The tests below
472 // catch stores of Smis.
473 Label done;
474
475 // Skip barrier if writing a smi.
476 if (smi_check == INLINE_SMI_CHECK) {
477 JumpIfSmi(value, &done);
478 }
479
480 // Although the object register is tagged, the offset is relative to the start
481 // of the object, so so offset must be a multiple of kPointerSize.
482 ASSERT(IsAligned(offset, kPointerSize));
483
484 add(dst, object, Operand(offset - kHeapObjectTag));
485 if (emit_debug_code()) {
486 Label ok;
487 tst(dst, Operand((1 << kPointerSizeLog2) - 1));
488 b(eq, &ok);
489 stop("Unaligned cell in write barrier");
490 bind(&ok);
491 }
492
493 RecordWrite(object,
494 dst,
495 value,
496 lr_status,
497 save_fp,
498 remembered_set_action,
499 OMIT_SMI_CHECK,
500 pointers_to_here_check_for_value);
501
502 bind(&done);
503
504 // Clobber clobbered input registers when running with the debug-code flag
505 // turned on to provoke errors.
506 if (emit_debug_code()) {
507 mov(value, Operand(BitCast<int32_t>(kZapValue + 4)));
508 mov(dst, Operand(BitCast<int32_t>(kZapValue + 8)));
509 }
510 }
511
512
513 // Will clobber 4 registers: object, map, dst, ip. The
514 // register 'object' contains a heap object pointer.
RecordWriteForMap(Register object,Register map,Register dst,LinkRegisterStatus lr_status,SaveFPRegsMode fp_mode)515 void MacroAssembler::RecordWriteForMap(Register object,
516 Register map,
517 Register dst,
518 LinkRegisterStatus lr_status,
519 SaveFPRegsMode fp_mode) {
520 if (emit_debug_code()) {
521 ldr(dst, FieldMemOperand(map, HeapObject::kMapOffset));
522 cmp(dst, Operand(isolate()->factory()->meta_map()));
523 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
524 }
525
526 if (!FLAG_incremental_marking) {
527 return;
528 }
529
530 // Count number of write barriers in generated code.
531 isolate()->counters()->write_barriers_static()->Increment();
532 // TODO(mstarzinger): Dynamic counter missing.
533
534 if (emit_debug_code()) {
535 ldr(ip, FieldMemOperand(object, HeapObject::kMapOffset));
536 cmp(ip, map);
537 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
538 }
539
540 Label done;
541
542 // A single check of the map's pages interesting flag suffices, since it is
543 // only set during incremental collection, and then it's also guaranteed that
544 // the from object's page's interesting flag is also set. This optimization
545 // relies on the fact that maps can never be in new space.
546 CheckPageFlag(map,
547 map, // Used as scratch.
548 MemoryChunk::kPointersToHereAreInterestingMask,
549 eq,
550 &done);
551
552 add(dst, object, Operand(HeapObject::kMapOffset - kHeapObjectTag));
553 if (emit_debug_code()) {
554 Label ok;
555 tst(dst, Operand((1 << kPointerSizeLog2) - 1));
556 b(eq, &ok);
557 stop("Unaligned cell in write barrier");
558 bind(&ok);
559 }
560
561 // Record the actual write.
562 if (lr_status == kLRHasNotBeenSaved) {
563 push(lr);
564 }
565 RecordWriteStub stub(isolate(), object, map, dst, OMIT_REMEMBERED_SET,
566 fp_mode);
567 CallStub(&stub);
568 if (lr_status == kLRHasNotBeenSaved) {
569 pop(lr);
570 }
571
572 bind(&done);
573
574 // Clobber clobbered registers when running with the debug-code flag
575 // turned on to provoke errors.
576 if (emit_debug_code()) {
577 mov(dst, Operand(BitCast<int32_t>(kZapValue + 12)));
578 mov(map, Operand(BitCast<int32_t>(kZapValue + 16)));
579 }
580 }
581
582
583 // Will clobber 4 registers: object, address, scratch, ip. The
584 // register 'object' contains a heap object pointer. The heap object
585 // tag is shifted away.
RecordWrite(Register object,Register address,Register value,LinkRegisterStatus lr_status,SaveFPRegsMode fp_mode,RememberedSetAction remembered_set_action,SmiCheck smi_check,PointersToHereCheck pointers_to_here_check_for_value)586 void MacroAssembler::RecordWrite(
587 Register object,
588 Register address,
589 Register value,
590 LinkRegisterStatus lr_status,
591 SaveFPRegsMode fp_mode,
592 RememberedSetAction remembered_set_action,
593 SmiCheck smi_check,
594 PointersToHereCheck pointers_to_here_check_for_value) {
595 ASSERT(!object.is(value));
596 if (emit_debug_code()) {
597 ldr(ip, MemOperand(address));
598 cmp(ip, value);
599 Check(eq, kWrongAddressOrValuePassedToRecordWrite);
600 }
601
602 if (remembered_set_action == OMIT_REMEMBERED_SET &&
603 !FLAG_incremental_marking) {
604 return;
605 }
606
607 // Count number of write barriers in generated code.
608 isolate()->counters()->write_barriers_static()->Increment();
609 // TODO(mstarzinger): Dynamic counter missing.
610
611 // First, check if a write barrier is even needed. The tests below
612 // catch stores of smis and stores into the young generation.
613 Label done;
614
615 if (smi_check == INLINE_SMI_CHECK) {
616 JumpIfSmi(value, &done);
617 }
618
619 if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) {
620 CheckPageFlag(value,
621 value, // Used as scratch.
622 MemoryChunk::kPointersToHereAreInterestingMask,
623 eq,
624 &done);
625 }
626 CheckPageFlag(object,
627 value, // Used as scratch.
628 MemoryChunk::kPointersFromHereAreInterestingMask,
629 eq,
630 &done);
631
632 // Record the actual write.
633 if (lr_status == kLRHasNotBeenSaved) {
634 push(lr);
635 }
636 RecordWriteStub stub(isolate(), object, value, address, remembered_set_action,
637 fp_mode);
638 CallStub(&stub);
639 if (lr_status == kLRHasNotBeenSaved) {
640 pop(lr);
641 }
642
643 bind(&done);
644
645 // Clobber clobbered registers when running with the debug-code flag
646 // turned on to provoke errors.
647 if (emit_debug_code()) {
648 mov(address, Operand(BitCast<int32_t>(kZapValue + 12)));
649 mov(value, Operand(BitCast<int32_t>(kZapValue + 16)));
650 }
651 }
652
653
RememberedSetHelper(Register object,Register address,Register scratch,SaveFPRegsMode fp_mode,RememberedSetFinalAction and_then)654 void MacroAssembler::RememberedSetHelper(Register object, // For debug tests.
655 Register address,
656 Register scratch,
657 SaveFPRegsMode fp_mode,
658 RememberedSetFinalAction and_then) {
659 Label done;
660 if (emit_debug_code()) {
661 Label ok;
662 JumpIfNotInNewSpace(object, scratch, &ok);
663 stop("Remembered set pointer is in new space");
664 bind(&ok);
665 }
666 // Load store buffer top.
667 ExternalReference store_buffer =
668 ExternalReference::store_buffer_top(isolate());
669 mov(ip, Operand(store_buffer));
670 ldr(scratch, MemOperand(ip));
671 // Store pointer to buffer and increment buffer top.
672 str(address, MemOperand(scratch, kPointerSize, PostIndex));
673 // Write back new top of buffer.
674 str(scratch, MemOperand(ip));
675 // Call stub on end of buffer.
676 // Check for end of buffer.
677 tst(scratch, Operand(StoreBuffer::kStoreBufferOverflowBit));
678 if (and_then == kFallThroughAtEnd) {
679 b(eq, &done);
680 } else {
681 ASSERT(and_then == kReturnAtEnd);
682 Ret(eq);
683 }
684 push(lr);
685 StoreBufferOverflowStub store_buffer_overflow =
686 StoreBufferOverflowStub(isolate(), fp_mode);
687 CallStub(&store_buffer_overflow);
688 pop(lr);
689 bind(&done);
690 if (and_then == kReturnAtEnd) {
691 Ret();
692 }
693 }
694
695
PushFixedFrame(Register marker_reg)696 void MacroAssembler::PushFixedFrame(Register marker_reg) {
697 ASSERT(!marker_reg.is_valid() || marker_reg.code() < cp.code());
698 stm(db_w, sp, (marker_reg.is_valid() ? marker_reg.bit() : 0) |
699 cp.bit() |
700 (FLAG_enable_ool_constant_pool ? pp.bit() : 0) |
701 fp.bit() |
702 lr.bit());
703 }
704
705
PopFixedFrame(Register marker_reg)706 void MacroAssembler::PopFixedFrame(Register marker_reg) {
707 ASSERT(!marker_reg.is_valid() || marker_reg.code() < cp.code());
708 ldm(ia_w, sp, (marker_reg.is_valid() ? marker_reg.bit() : 0) |
709 cp.bit() |
710 (FLAG_enable_ool_constant_pool ? pp.bit() : 0) |
711 fp.bit() |
712 lr.bit());
713 }
714
715
716 // Push and pop all registers that can hold pointers.
PushSafepointRegisters()717 void MacroAssembler::PushSafepointRegisters() {
718 // Safepoints expect a block of contiguous register values starting with r0:
719 ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters);
720 // Safepoints expect a block of kNumSafepointRegisters values on the
721 // stack, so adjust the stack for unsaved registers.
722 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
723 ASSERT(num_unsaved >= 0);
724 sub(sp, sp, Operand(num_unsaved * kPointerSize));
725 stm(db_w, sp, kSafepointSavedRegisters);
726 }
727
728
PopSafepointRegisters()729 void MacroAssembler::PopSafepointRegisters() {
730 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
731 ldm(ia_w, sp, kSafepointSavedRegisters);
732 add(sp, sp, Operand(num_unsaved * kPointerSize));
733 }
734
735
PushSafepointRegistersAndDoubles()736 void MacroAssembler::PushSafepointRegistersAndDoubles() {
737 // Number of d-regs not known at snapshot time.
738 ASSERT(!serializer_enabled());
739 PushSafepointRegisters();
740 // Only save allocatable registers.
741 ASSERT(kScratchDoubleReg.is(d15) && kDoubleRegZero.is(d14));
742 ASSERT(DwVfpRegister::NumReservedRegisters() == 2);
743 if (CpuFeatures::IsSupported(VFP32DREGS)) {
744 vstm(db_w, sp, d16, d31);
745 }
746 vstm(db_w, sp, d0, d13);
747 }
748
749
PopSafepointRegistersAndDoubles()750 void MacroAssembler::PopSafepointRegistersAndDoubles() {
751 // Number of d-regs not known at snapshot time.
752 ASSERT(!serializer_enabled());
753 // Only save allocatable registers.
754 ASSERT(kScratchDoubleReg.is(d15) && kDoubleRegZero.is(d14));
755 ASSERT(DwVfpRegister::NumReservedRegisters() == 2);
756 vldm(ia_w, sp, d0, d13);
757 if (CpuFeatures::IsSupported(VFP32DREGS)) {
758 vldm(ia_w, sp, d16, d31);
759 }
760 PopSafepointRegisters();
761 }
762
StoreToSafepointRegistersAndDoublesSlot(Register src,Register dst)763 void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src,
764 Register dst) {
765 str(src, SafepointRegistersAndDoublesSlot(dst));
766 }
767
768
StoreToSafepointRegisterSlot(Register src,Register dst)769 void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) {
770 str(src, SafepointRegisterSlot(dst));
771 }
772
773
LoadFromSafepointRegisterSlot(Register dst,Register src)774 void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) {
775 ldr(dst, SafepointRegisterSlot(src));
776 }
777
778
SafepointRegisterStackIndex(int reg_code)779 int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
780 // The registers are pushed starting with the highest encoding,
781 // which means that lowest encodings are closest to the stack pointer.
782 ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters);
783 return reg_code;
784 }
785
786
SafepointRegisterSlot(Register reg)787 MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
788 return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
789 }
790
791
SafepointRegistersAndDoublesSlot(Register reg)792 MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) {
793 // Number of d-regs not known at snapshot time.
794 ASSERT(!serializer_enabled());
795 // General purpose registers are pushed last on the stack.
796 int doubles_size = DwVfpRegister::NumAllocatableRegisters() * kDoubleSize;
797 int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize;
798 return MemOperand(sp, doubles_size + register_offset);
799 }
800
801
Ldrd(Register dst1,Register dst2,const MemOperand & src,Condition cond)802 void MacroAssembler::Ldrd(Register dst1, Register dst2,
803 const MemOperand& src, Condition cond) {
804 ASSERT(src.rm().is(no_reg));
805 ASSERT(!dst1.is(lr)); // r14.
806
807 // V8 does not use this addressing mode, so the fallback code
808 // below doesn't support it yet.
809 ASSERT((src.am() != PreIndex) && (src.am() != NegPreIndex));
810
811 // Generate two ldr instructions if ldrd is not available.
812 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() &&
813 (dst1.code() % 2 == 0) && (dst1.code() + 1 == dst2.code())) {
814 CpuFeatureScope scope(this, ARMv7);
815 ldrd(dst1, dst2, src, cond);
816 } else {
817 if ((src.am() == Offset) || (src.am() == NegOffset)) {
818 MemOperand src2(src);
819 src2.set_offset(src2.offset() + 4);
820 if (dst1.is(src.rn())) {
821 ldr(dst2, src2, cond);
822 ldr(dst1, src, cond);
823 } else {
824 ldr(dst1, src, cond);
825 ldr(dst2, src2, cond);
826 }
827 } else { // PostIndex or NegPostIndex.
828 ASSERT((src.am() == PostIndex) || (src.am() == NegPostIndex));
829 if (dst1.is(src.rn())) {
830 ldr(dst2, MemOperand(src.rn(), 4, Offset), cond);
831 ldr(dst1, src, cond);
832 } else {
833 MemOperand src2(src);
834 src2.set_offset(src2.offset() - 4);
835 ldr(dst1, MemOperand(src.rn(), 4, PostIndex), cond);
836 ldr(dst2, src2, cond);
837 }
838 }
839 }
840 }
841
842
Strd(Register src1,Register src2,const MemOperand & dst,Condition cond)843 void MacroAssembler::Strd(Register src1, Register src2,
844 const MemOperand& dst, Condition cond) {
845 ASSERT(dst.rm().is(no_reg));
846 ASSERT(!src1.is(lr)); // r14.
847
848 // V8 does not use this addressing mode, so the fallback code
849 // below doesn't support it yet.
850 ASSERT((dst.am() != PreIndex) && (dst.am() != NegPreIndex));
851
852 // Generate two str instructions if strd is not available.
853 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() &&
854 (src1.code() % 2 == 0) && (src1.code() + 1 == src2.code())) {
855 CpuFeatureScope scope(this, ARMv7);
856 strd(src1, src2, dst, cond);
857 } else {
858 MemOperand dst2(dst);
859 if ((dst.am() == Offset) || (dst.am() == NegOffset)) {
860 dst2.set_offset(dst2.offset() + 4);
861 str(src1, dst, cond);
862 str(src2, dst2, cond);
863 } else { // PostIndex or NegPostIndex.
864 ASSERT((dst.am() == PostIndex) || (dst.am() == NegPostIndex));
865 dst2.set_offset(dst2.offset() - 4);
866 str(src1, MemOperand(dst.rn(), 4, PostIndex), cond);
867 str(src2, dst2, cond);
868 }
869 }
870 }
871
872
VFPEnsureFPSCRState(Register scratch)873 void MacroAssembler::VFPEnsureFPSCRState(Register scratch) {
874 // If needed, restore wanted bits of FPSCR.
875 Label fpscr_done;
876 vmrs(scratch);
877 if (emit_debug_code()) {
878 Label rounding_mode_correct;
879 tst(scratch, Operand(kVFPRoundingModeMask));
880 b(eq, &rounding_mode_correct);
881 // Don't call Assert here, since Runtime_Abort could re-enter here.
882 stop("Default rounding mode not set");
883 bind(&rounding_mode_correct);
884 }
885 tst(scratch, Operand(kVFPDefaultNaNModeControlBit));
886 b(ne, &fpscr_done);
887 orr(scratch, scratch, Operand(kVFPDefaultNaNModeControlBit));
888 vmsr(scratch);
889 bind(&fpscr_done);
890 }
891
892
VFPCanonicalizeNaN(const DwVfpRegister dst,const DwVfpRegister src,const Condition cond)893 void MacroAssembler::VFPCanonicalizeNaN(const DwVfpRegister dst,
894 const DwVfpRegister src,
895 const Condition cond) {
896 vsub(dst, src, kDoubleRegZero, cond);
897 }
898
899
VFPCompareAndSetFlags(const DwVfpRegister src1,const DwVfpRegister src2,const Condition cond)900 void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
901 const DwVfpRegister src2,
902 const Condition cond) {
903 // Compare and move FPSCR flags to the normal condition flags.
904 VFPCompareAndLoadFlags(src1, src2, pc, cond);
905 }
906
VFPCompareAndSetFlags(const DwVfpRegister src1,const double src2,const Condition cond)907 void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
908 const double src2,
909 const Condition cond) {
910 // Compare and move FPSCR flags to the normal condition flags.
911 VFPCompareAndLoadFlags(src1, src2, pc, cond);
912 }
913
914
VFPCompareAndLoadFlags(const DwVfpRegister src1,const DwVfpRegister src2,const Register fpscr_flags,const Condition cond)915 void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
916 const DwVfpRegister src2,
917 const Register fpscr_flags,
918 const Condition cond) {
919 // Compare and load FPSCR.
920 vcmp(src1, src2, cond);
921 vmrs(fpscr_flags, cond);
922 }
923
VFPCompareAndLoadFlags(const DwVfpRegister src1,const double src2,const Register fpscr_flags,const Condition cond)924 void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
925 const double src2,
926 const Register fpscr_flags,
927 const Condition cond) {
928 // Compare and load FPSCR.
929 vcmp(src1, src2, cond);
930 vmrs(fpscr_flags, cond);
931 }
932
Vmov(const DwVfpRegister dst,const double imm,const Register scratch)933 void MacroAssembler::Vmov(const DwVfpRegister dst,
934 const double imm,
935 const Register scratch) {
936 static const DoubleRepresentation minus_zero(-0.0);
937 static const DoubleRepresentation zero(0.0);
938 DoubleRepresentation value_rep(imm);
939 // Handle special values first.
940 if (value_rep == zero) {
941 vmov(dst, kDoubleRegZero);
942 } else if (value_rep == minus_zero) {
943 vneg(dst, kDoubleRegZero);
944 } else {
945 vmov(dst, imm, scratch);
946 }
947 }
948
949
VmovHigh(Register dst,DwVfpRegister src)950 void MacroAssembler::VmovHigh(Register dst, DwVfpRegister src) {
951 if (src.code() < 16) {
952 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
953 vmov(dst, loc.high());
954 } else {
955 vmov(dst, VmovIndexHi, src);
956 }
957 }
958
959
VmovHigh(DwVfpRegister dst,Register src)960 void MacroAssembler::VmovHigh(DwVfpRegister dst, Register src) {
961 if (dst.code() < 16) {
962 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
963 vmov(loc.high(), src);
964 } else {
965 vmov(dst, VmovIndexHi, src);
966 }
967 }
968
969
VmovLow(Register dst,DwVfpRegister src)970 void MacroAssembler::VmovLow(Register dst, DwVfpRegister src) {
971 if (src.code() < 16) {
972 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(src.code());
973 vmov(dst, loc.low());
974 } else {
975 vmov(dst, VmovIndexLo, src);
976 }
977 }
978
979
VmovLow(DwVfpRegister dst,Register src)980 void MacroAssembler::VmovLow(DwVfpRegister dst, Register src) {
981 if (dst.code() < 16) {
982 const LowDwVfpRegister loc = LowDwVfpRegister::from_code(dst.code());
983 vmov(loc.low(), src);
984 } else {
985 vmov(dst, VmovIndexLo, src);
986 }
987 }
988
989
LoadConstantPoolPointerRegister()990 void MacroAssembler::LoadConstantPoolPointerRegister() {
991 if (FLAG_enable_ool_constant_pool) {
992 int constant_pool_offset = Code::kConstantPoolOffset - Code::kHeaderSize -
993 pc_offset() - Instruction::kPCReadOffset;
994 ASSERT(ImmediateFitsAddrMode2Instruction(constant_pool_offset));
995 ldr(pp, MemOperand(pc, constant_pool_offset));
996 }
997 }
998
999
StubPrologue()1000 void MacroAssembler::StubPrologue() {
1001 PushFixedFrame();
1002 Push(Smi::FromInt(StackFrame::STUB));
1003 // Adjust FP to point to saved FP.
1004 add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
1005 if (FLAG_enable_ool_constant_pool) {
1006 LoadConstantPoolPointerRegister();
1007 set_constant_pool_available(true);
1008 }
1009 }
1010
1011
Prologue(bool code_pre_aging)1012 void MacroAssembler::Prologue(bool code_pre_aging) {
1013 { PredictableCodeSizeScope predictible_code_size_scope(
1014 this, kNoCodeAgeSequenceLength);
1015 // The following three instructions must remain together and unmodified
1016 // for code aging to work properly.
1017 if (code_pre_aging) {
1018 // Pre-age the code.
1019 Code* stub = Code::GetPreAgedCodeAgeStub(isolate());
1020 add(r0, pc, Operand(-8));
1021 ldr(pc, MemOperand(pc, -4));
1022 emit_code_stub_address(stub);
1023 } else {
1024 PushFixedFrame(r1);
1025 nop(ip.code());
1026 // Adjust FP to point to saved FP.
1027 add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
1028 }
1029 }
1030 if (FLAG_enable_ool_constant_pool) {
1031 LoadConstantPoolPointerRegister();
1032 set_constant_pool_available(true);
1033 }
1034 }
1035
1036
EnterFrame(StackFrame::Type type,bool load_constant_pool)1037 void MacroAssembler::EnterFrame(StackFrame::Type type,
1038 bool load_constant_pool) {
1039 // r0-r3: preserved
1040 PushFixedFrame();
1041 if (FLAG_enable_ool_constant_pool && load_constant_pool) {
1042 LoadConstantPoolPointerRegister();
1043 }
1044 mov(ip, Operand(Smi::FromInt(type)));
1045 push(ip);
1046 mov(ip, Operand(CodeObject()));
1047 push(ip);
1048 // Adjust FP to point to saved FP.
1049 add(fp, sp,
1050 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
1051 }
1052
1053
LeaveFrame(StackFrame::Type type)1054 int MacroAssembler::LeaveFrame(StackFrame::Type type) {
1055 // r0: preserved
1056 // r1: preserved
1057 // r2: preserved
1058
1059 // Drop the execution stack down to the frame pointer and restore
1060 // the caller frame pointer, return address and constant pool pointer
1061 // (if FLAG_enable_ool_constant_pool).
1062 int frame_ends;
1063 if (FLAG_enable_ool_constant_pool) {
1064 add(sp, fp, Operand(StandardFrameConstants::kConstantPoolOffset));
1065 frame_ends = pc_offset();
1066 ldm(ia_w, sp, pp.bit() | fp.bit() | lr.bit());
1067 } else {
1068 mov(sp, fp);
1069 frame_ends = pc_offset();
1070 ldm(ia_w, sp, fp.bit() | lr.bit());
1071 }
1072 return frame_ends;
1073 }
1074
1075
EnterExitFrame(bool save_doubles,int stack_space)1076 void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) {
1077 // Set up the frame structure on the stack.
1078 ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement);
1079 ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset);
1080 ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset);
1081 Push(lr, fp);
1082 mov(fp, Operand(sp)); // Set up new frame pointer.
1083 // Reserve room for saved entry sp and code object.
1084 sub(sp, sp, Operand(ExitFrameConstants::kFrameSize));
1085 if (emit_debug_code()) {
1086 mov(ip, Operand::Zero());
1087 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
1088 }
1089 if (FLAG_enable_ool_constant_pool) {
1090 str(pp, MemOperand(fp, ExitFrameConstants::kConstantPoolOffset));
1091 }
1092 mov(ip, Operand(CodeObject()));
1093 str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset));
1094
1095 // Save the frame pointer and the context in top.
1096 mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1097 str(fp, MemOperand(ip));
1098 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
1099 str(cp, MemOperand(ip));
1100
1101 // Optionally save all double registers.
1102 if (save_doubles) {
1103 SaveFPRegs(sp, ip);
1104 // Note that d0 will be accessible at
1105 // fp - ExitFrameConstants::kFrameSize -
1106 // DwVfpRegister::kMaxNumRegisters * kDoubleSize,
1107 // since the sp slot, code slot and constant pool slot (if
1108 // FLAG_enable_ool_constant_pool) were pushed after the fp.
1109 }
1110
1111 // Reserve place for the return address and stack space and align the frame
1112 // preparing for calling the runtime function.
1113 const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
1114 sub(sp, sp, Operand((stack_space + 1) * kPointerSize));
1115 if (frame_alignment > 0) {
1116 ASSERT(IsPowerOf2(frame_alignment));
1117 and_(sp, sp, Operand(-frame_alignment));
1118 }
1119
1120 // Set the exit frame sp value to point just before the return address
1121 // location.
1122 add(ip, sp, Operand(kPointerSize));
1123 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
1124 }
1125
1126
InitializeNewString(Register string,Register length,Heap::RootListIndex map_index,Register scratch1,Register scratch2)1127 void MacroAssembler::InitializeNewString(Register string,
1128 Register length,
1129 Heap::RootListIndex map_index,
1130 Register scratch1,
1131 Register scratch2) {
1132 SmiTag(scratch1, length);
1133 LoadRoot(scratch2, map_index);
1134 str(scratch1, FieldMemOperand(string, String::kLengthOffset));
1135 mov(scratch1, Operand(String::kEmptyHashField));
1136 str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
1137 str(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
1138 }
1139
1140
ActivationFrameAlignment()1141 int MacroAssembler::ActivationFrameAlignment() {
1142 #if V8_HOST_ARCH_ARM
1143 // Running on the real platform. Use the alignment as mandated by the local
1144 // environment.
1145 // Note: This will break if we ever start generating snapshots on one ARM
1146 // platform for another ARM platform with a different alignment.
1147 return OS::ActivationFrameAlignment();
1148 #else // V8_HOST_ARCH_ARM
1149 // If we are using the simulator then we should always align to the expected
1150 // alignment. As the simulator is used to generate snapshots we do not know
1151 // if the target platform will need alignment, so this is controlled from a
1152 // flag.
1153 return FLAG_sim_stack_alignment;
1154 #endif // V8_HOST_ARCH_ARM
1155 }
1156
1157
LeaveExitFrame(bool save_doubles,Register argument_count,bool restore_context)1158 void MacroAssembler::LeaveExitFrame(bool save_doubles,
1159 Register argument_count,
1160 bool restore_context) {
1161 ConstantPoolUnavailableScope constant_pool_unavailable(this);
1162
1163 // Optionally restore all double registers.
1164 if (save_doubles) {
1165 // Calculate the stack location of the saved doubles and restore them.
1166 const int offset = ExitFrameConstants::kFrameSize;
1167 sub(r3, fp,
1168 Operand(offset + DwVfpRegister::kMaxNumRegisters * kDoubleSize));
1169 RestoreFPRegs(r3, ip);
1170 }
1171
1172 // Clear top frame.
1173 mov(r3, Operand::Zero());
1174 mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
1175 str(r3, MemOperand(ip));
1176
1177 // Restore current context from top and clear it in debug mode.
1178 if (restore_context) {
1179 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
1180 ldr(cp, MemOperand(ip));
1181 }
1182 #ifdef DEBUG
1183 mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
1184 str(r3, MemOperand(ip));
1185 #endif
1186
1187 // Tear down the exit frame, pop the arguments, and return.
1188 if (FLAG_enable_ool_constant_pool) {
1189 ldr(pp, MemOperand(fp, ExitFrameConstants::kConstantPoolOffset));
1190 }
1191 mov(sp, Operand(fp));
1192 ldm(ia_w, sp, fp.bit() | lr.bit());
1193 if (argument_count.is_valid()) {
1194 add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2));
1195 }
1196 }
1197
1198
MovFromFloatResult(const DwVfpRegister dst)1199 void MacroAssembler::MovFromFloatResult(const DwVfpRegister dst) {
1200 if (use_eabi_hardfloat()) {
1201 Move(dst, d0);
1202 } else {
1203 vmov(dst, r0, r1);
1204 }
1205 }
1206
1207
1208 // On ARM this is just a synonym to make the purpose clear.
MovFromFloatParameter(DwVfpRegister dst)1209 void MacroAssembler::MovFromFloatParameter(DwVfpRegister dst) {
1210 MovFromFloatResult(dst);
1211 }
1212
1213
InvokePrologue(const ParameterCount & expected,const ParameterCount & actual,Handle<Code> code_constant,Register code_reg,Label * done,bool * definitely_mismatches,InvokeFlag flag,const CallWrapper & call_wrapper)1214 void MacroAssembler::InvokePrologue(const ParameterCount& expected,
1215 const ParameterCount& actual,
1216 Handle<Code> code_constant,
1217 Register code_reg,
1218 Label* done,
1219 bool* definitely_mismatches,
1220 InvokeFlag flag,
1221 const CallWrapper& call_wrapper) {
1222 bool definitely_matches = false;
1223 *definitely_mismatches = false;
1224 Label regular_invoke;
1225
1226 // Check whether the expected and actual arguments count match. If not,
1227 // setup registers according to contract with ArgumentsAdaptorTrampoline:
1228 // r0: actual arguments count
1229 // r1: function (passed through to callee)
1230 // r2: expected arguments count
1231
1232 // The code below is made a lot easier because the calling code already sets
1233 // up actual and expected registers according to the contract if values are
1234 // passed in registers.
1235 ASSERT(actual.is_immediate() || actual.reg().is(r0));
1236 ASSERT(expected.is_immediate() || expected.reg().is(r2));
1237 ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3));
1238
1239 if (expected.is_immediate()) {
1240 ASSERT(actual.is_immediate());
1241 if (expected.immediate() == actual.immediate()) {
1242 definitely_matches = true;
1243 } else {
1244 mov(r0, Operand(actual.immediate()));
1245 const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
1246 if (expected.immediate() == sentinel) {
1247 // Don't worry about adapting arguments for builtins that
1248 // don't want that done. Skip adaption code by making it look
1249 // like we have a match between expected and actual number of
1250 // arguments.
1251 definitely_matches = true;
1252 } else {
1253 *definitely_mismatches = true;
1254 mov(r2, Operand(expected.immediate()));
1255 }
1256 }
1257 } else {
1258 if (actual.is_immediate()) {
1259 cmp(expected.reg(), Operand(actual.immediate()));
1260 b(eq, ®ular_invoke);
1261 mov(r0, Operand(actual.immediate()));
1262 } else {
1263 cmp(expected.reg(), Operand(actual.reg()));
1264 b(eq, ®ular_invoke);
1265 }
1266 }
1267
1268 if (!definitely_matches) {
1269 if (!code_constant.is_null()) {
1270 mov(r3, Operand(code_constant));
1271 add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
1272 }
1273
1274 Handle<Code> adaptor =
1275 isolate()->builtins()->ArgumentsAdaptorTrampoline();
1276 if (flag == CALL_FUNCTION) {
1277 call_wrapper.BeforeCall(CallSize(adaptor));
1278 Call(adaptor);
1279 call_wrapper.AfterCall();
1280 if (!*definitely_mismatches) {
1281 b(done);
1282 }
1283 } else {
1284 Jump(adaptor, RelocInfo::CODE_TARGET);
1285 }
1286 bind(®ular_invoke);
1287 }
1288 }
1289
1290
InvokeCode(Register code,const ParameterCount & expected,const ParameterCount & actual,InvokeFlag flag,const CallWrapper & call_wrapper)1291 void MacroAssembler::InvokeCode(Register code,
1292 const ParameterCount& expected,
1293 const ParameterCount& actual,
1294 InvokeFlag flag,
1295 const CallWrapper& call_wrapper) {
1296 // You can't call a function without a valid frame.
1297 ASSERT(flag == JUMP_FUNCTION || has_frame());
1298
1299 Label done;
1300 bool definitely_mismatches = false;
1301 InvokePrologue(expected, actual, Handle<Code>::null(), code,
1302 &done, &definitely_mismatches, flag,
1303 call_wrapper);
1304 if (!definitely_mismatches) {
1305 if (flag == CALL_FUNCTION) {
1306 call_wrapper.BeforeCall(CallSize(code));
1307 Call(code);
1308 call_wrapper.AfterCall();
1309 } else {
1310 ASSERT(flag == JUMP_FUNCTION);
1311 Jump(code);
1312 }
1313
1314 // Continue here if InvokePrologue does handle the invocation due to
1315 // mismatched parameter counts.
1316 bind(&done);
1317 }
1318 }
1319
1320
InvokeFunction(Register fun,const ParameterCount & actual,InvokeFlag flag,const CallWrapper & call_wrapper)1321 void MacroAssembler::InvokeFunction(Register fun,
1322 const ParameterCount& actual,
1323 InvokeFlag flag,
1324 const CallWrapper& call_wrapper) {
1325 // You can't call a function without a valid frame.
1326 ASSERT(flag == JUMP_FUNCTION || has_frame());
1327
1328 // Contract with called JS functions requires that function is passed in r1.
1329 ASSERT(fun.is(r1));
1330
1331 Register expected_reg = r2;
1332 Register code_reg = r3;
1333
1334 ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
1335 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
1336 ldr(expected_reg,
1337 FieldMemOperand(code_reg,
1338 SharedFunctionInfo::kFormalParameterCountOffset));
1339 SmiUntag(expected_reg);
1340 ldr(code_reg,
1341 FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
1342
1343 ParameterCount expected(expected_reg);
1344 InvokeCode(code_reg, expected, actual, flag, call_wrapper);
1345 }
1346
1347
InvokeFunction(Register function,const ParameterCount & expected,const ParameterCount & actual,InvokeFlag flag,const CallWrapper & call_wrapper)1348 void MacroAssembler::InvokeFunction(Register function,
1349 const ParameterCount& expected,
1350 const ParameterCount& actual,
1351 InvokeFlag flag,
1352 const CallWrapper& call_wrapper) {
1353 // You can't call a function without a valid frame.
1354 ASSERT(flag == JUMP_FUNCTION || has_frame());
1355
1356 // Contract with called JS functions requires that function is passed in r1.
1357 ASSERT(function.is(r1));
1358
1359 // Get the function and setup the context.
1360 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
1361
1362 // We call indirectly through the code field in the function to
1363 // allow recompilation to take effect without changing any of the
1364 // call sites.
1365 ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
1366 InvokeCode(r3, expected, actual, flag, call_wrapper);
1367 }
1368
1369
InvokeFunction(Handle<JSFunction> function,const ParameterCount & expected,const ParameterCount & actual,InvokeFlag flag,const CallWrapper & call_wrapper)1370 void MacroAssembler::InvokeFunction(Handle<JSFunction> function,
1371 const ParameterCount& expected,
1372 const ParameterCount& actual,
1373 InvokeFlag flag,
1374 const CallWrapper& call_wrapper) {
1375 Move(r1, function);
1376 InvokeFunction(r1, expected, actual, flag, call_wrapper);
1377 }
1378
1379
IsObjectJSObjectType(Register heap_object,Register map,Register scratch,Label * fail)1380 void MacroAssembler::IsObjectJSObjectType(Register heap_object,
1381 Register map,
1382 Register scratch,
1383 Label* fail) {
1384 ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
1385 IsInstanceJSObjectType(map, scratch, fail);
1386 }
1387
1388
IsInstanceJSObjectType(Register map,Register scratch,Label * fail)1389 void MacroAssembler::IsInstanceJSObjectType(Register map,
1390 Register scratch,
1391 Label* fail) {
1392 ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
1393 cmp(scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
1394 b(lt, fail);
1395 cmp(scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
1396 b(gt, fail);
1397 }
1398
1399
IsObjectJSStringType(Register object,Register scratch,Label * fail)1400 void MacroAssembler::IsObjectJSStringType(Register object,
1401 Register scratch,
1402 Label* fail) {
1403 ASSERT(kNotStringTag != 0);
1404
1405 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
1406 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1407 tst(scratch, Operand(kIsNotStringMask));
1408 b(ne, fail);
1409 }
1410
1411
IsObjectNameType(Register object,Register scratch,Label * fail)1412 void MacroAssembler::IsObjectNameType(Register object,
1413 Register scratch,
1414 Label* fail) {
1415 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
1416 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
1417 cmp(scratch, Operand(LAST_NAME_TYPE));
1418 b(hi, fail);
1419 }
1420
1421
DebugBreak()1422 void MacroAssembler::DebugBreak() {
1423 mov(r0, Operand::Zero());
1424 mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate())));
1425 CEntryStub ces(isolate(), 1);
1426 ASSERT(AllowThisStubCall(&ces));
1427 Call(ces.GetCode(), RelocInfo::DEBUG_BREAK);
1428 }
1429
1430
PushTryHandler(StackHandler::Kind kind,int handler_index)1431 void MacroAssembler::PushTryHandler(StackHandler::Kind kind,
1432 int handler_index) {
1433 // Adjust this code if not the case.
1434 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
1435 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
1436 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1437 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1438 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1439 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
1440
1441 // For the JSEntry handler, we must preserve r0-r4, r5-r6 are available.
1442 // We will build up the handler from the bottom by pushing on the stack.
1443 // Set up the code object (r5) and the state (r6) for pushing.
1444 unsigned state =
1445 StackHandler::IndexField::encode(handler_index) |
1446 StackHandler::KindField::encode(kind);
1447 mov(r5, Operand(CodeObject()));
1448 mov(r6, Operand(state));
1449
1450 // Push the frame pointer, context, state, and code object.
1451 if (kind == StackHandler::JS_ENTRY) {
1452 mov(cp, Operand(Smi::FromInt(0))); // Indicates no context.
1453 mov(ip, Operand::Zero()); // NULL frame pointer.
1454 stm(db_w, sp, r5.bit() | r6.bit() | cp.bit() | ip.bit());
1455 } else {
1456 stm(db_w, sp, r5.bit() | r6.bit() | cp.bit() | fp.bit());
1457 }
1458
1459 // Link the current handler as the next handler.
1460 mov(r6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1461 ldr(r5, MemOperand(r6));
1462 push(r5);
1463 // Set this new handler as the current one.
1464 str(sp, MemOperand(r6));
1465 }
1466
1467
PopTryHandler()1468 void MacroAssembler::PopTryHandler() {
1469 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
1470 pop(r1);
1471 mov(ip, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1472 add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
1473 str(r1, MemOperand(ip));
1474 }
1475
1476
JumpToHandlerEntry()1477 void MacroAssembler::JumpToHandlerEntry() {
1478 // Compute the handler entry address and jump to it. The handler table is
1479 // a fixed array of (smi-tagged) code offsets.
1480 // r0 = exception, r1 = code object, r2 = state.
1481
1482 ConstantPoolUnavailableScope constant_pool_unavailable(this);
1483 if (FLAG_enable_ool_constant_pool) {
1484 ldr(pp, FieldMemOperand(r1, Code::kConstantPoolOffset)); // Constant pool.
1485 }
1486 ldr(r3, FieldMemOperand(r1, Code::kHandlerTableOffset)); // Handler table.
1487 add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1488 mov(r2, Operand(r2, LSR, StackHandler::kKindWidth)); // Handler index.
1489 ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2)); // Smi-tagged offset.
1490 add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start.
1491 add(pc, r1, Operand::SmiUntag(r2)); // Jump
1492 }
1493
1494
Throw(Register value)1495 void MacroAssembler::Throw(Register value) {
1496 // Adjust this code if not the case.
1497 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
1498 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
1499 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1500 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1501 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1502 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
1503
1504 // The exception is expected in r0.
1505 if (!value.is(r0)) {
1506 mov(r0, value);
1507 }
1508 // Drop the stack pointer to the top of the top handler.
1509 mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1510 ldr(sp, MemOperand(r3));
1511 // Restore the next handler.
1512 pop(r2);
1513 str(r2, MemOperand(r3));
1514
1515 // Get the code object (r1) and state (r2). Restore the context and frame
1516 // pointer.
1517 ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit());
1518
1519 // If the handler is a JS frame, restore the context to the frame.
1520 // (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp
1521 // or cp.
1522 tst(cp, cp);
1523 str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne);
1524
1525 JumpToHandlerEntry();
1526 }
1527
1528
ThrowUncatchable(Register value)1529 void MacroAssembler::ThrowUncatchable(Register value) {
1530 // Adjust this code if not the case.
1531 STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
1532 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
1533 STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize);
1534 STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize);
1535 STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize);
1536 STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);
1537
1538 // The exception is expected in r0.
1539 if (!value.is(r0)) {
1540 mov(r0, value);
1541 }
1542 // Drop the stack pointer to the top of the top stack handler.
1543 mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
1544 ldr(sp, MemOperand(r3));
1545
1546 // Unwind the handlers until the ENTRY handler is found.
1547 Label fetch_next, check_kind;
1548 jmp(&check_kind);
1549 bind(&fetch_next);
1550 ldr(sp, MemOperand(sp, StackHandlerConstants::kNextOffset));
1551
1552 bind(&check_kind);
1553 STATIC_ASSERT(StackHandler::JS_ENTRY == 0);
1554 ldr(r2, MemOperand(sp, StackHandlerConstants::kStateOffset));
1555 tst(r2, Operand(StackHandler::KindField::kMask));
1556 b(ne, &fetch_next);
1557
1558 // Set the top handler address to next handler past the top ENTRY handler.
1559 pop(r2);
1560 str(r2, MemOperand(r3));
1561 // Get the code object (r1) and state (r2). Clear the context and frame
1562 // pointer (0 was saved in the handler).
1563 ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit());
1564
1565 JumpToHandlerEntry();
1566 }
1567
1568
CheckAccessGlobalProxy(Register holder_reg,Register scratch,Label * miss)1569 void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
1570 Register scratch,
1571 Label* miss) {
1572 Label same_contexts;
1573
1574 ASSERT(!holder_reg.is(scratch));
1575 ASSERT(!holder_reg.is(ip));
1576 ASSERT(!scratch.is(ip));
1577
1578 // Load current lexical context from the stack frame.
1579 ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
1580 // In debug mode, make sure the lexical context is set.
1581 #ifdef DEBUG
1582 cmp(scratch, Operand::Zero());
1583 Check(ne, kWeShouldNotHaveAnEmptyLexicalContext);
1584 #endif
1585
1586 // Load the native context of the current context.
1587 int offset =
1588 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize;
1589 ldr(scratch, FieldMemOperand(scratch, offset));
1590 ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
1591
1592 // Check the context is a native context.
1593 if (emit_debug_code()) {
1594 // Cannot use ip as a temporary in this verification code. Due to the fact
1595 // that ip is clobbered as part of cmp with an object Operand.
1596 push(holder_reg); // Temporarily save holder on the stack.
1597 // Read the first word and compare to the native_context_map.
1598 ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
1599 LoadRoot(ip, Heap::kNativeContextMapRootIndex);
1600 cmp(holder_reg, ip);
1601 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext);
1602 pop(holder_reg); // Restore holder.
1603 }
1604
1605 // Check if both contexts are the same.
1606 ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
1607 cmp(scratch, Operand(ip));
1608 b(eq, &same_contexts);
1609
1610 // Check the context is a native context.
1611 if (emit_debug_code()) {
1612 // Cannot use ip as a temporary in this verification code. Due to the fact
1613 // that ip is clobbered as part of cmp with an object Operand.
1614 push(holder_reg); // Temporarily save holder on the stack.
1615 mov(holder_reg, ip); // Move ip to its holding place.
1616 LoadRoot(ip, Heap::kNullValueRootIndex);
1617 cmp(holder_reg, ip);
1618 Check(ne, kJSGlobalProxyContextShouldNotBeNull);
1619
1620 ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
1621 LoadRoot(ip, Heap::kNativeContextMapRootIndex);
1622 cmp(holder_reg, ip);
1623 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext);
1624 // Restore ip is not needed. ip is reloaded below.
1625 pop(holder_reg); // Restore holder.
1626 // Restore ip to holder's context.
1627 ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
1628 }
1629
1630 // Check that the security token in the calling global object is
1631 // compatible with the security token in the receiving global
1632 // object.
1633 int token_offset = Context::kHeaderSize +
1634 Context::SECURITY_TOKEN_INDEX * kPointerSize;
1635
1636 ldr(scratch, FieldMemOperand(scratch, token_offset));
1637 ldr(ip, FieldMemOperand(ip, token_offset));
1638 cmp(scratch, Operand(ip));
1639 b(ne, miss);
1640
1641 bind(&same_contexts);
1642 }
1643
1644
1645 // Compute the hash code from the untagged key. This must be kept in sync with
1646 // ComputeIntegerHash in utils.h and KeyedLoadGenericElementStub in
1647 // code-stub-hydrogen.cc
GetNumberHash(Register t0,Register scratch)1648 void MacroAssembler::GetNumberHash(Register t0, Register scratch) {
1649 // First of all we assign the hash seed to scratch.
1650 LoadRoot(scratch, Heap::kHashSeedRootIndex);
1651 SmiUntag(scratch);
1652
1653 // Xor original key with a seed.
1654 eor(t0, t0, Operand(scratch));
1655
1656 // Compute the hash code from the untagged key. This must be kept in sync
1657 // with ComputeIntegerHash in utils.h.
1658 //
1659 // hash = ~hash + (hash << 15);
1660 mvn(scratch, Operand(t0));
1661 add(t0, scratch, Operand(t0, LSL, 15));
1662 // hash = hash ^ (hash >> 12);
1663 eor(t0, t0, Operand(t0, LSR, 12));
1664 // hash = hash + (hash << 2);
1665 add(t0, t0, Operand(t0, LSL, 2));
1666 // hash = hash ^ (hash >> 4);
1667 eor(t0, t0, Operand(t0, LSR, 4));
1668 // hash = hash * 2057;
1669 mov(scratch, Operand(t0, LSL, 11));
1670 add(t0, t0, Operand(t0, LSL, 3));
1671 add(t0, t0, scratch);
1672 // hash = hash ^ (hash >> 16);
1673 eor(t0, t0, Operand(t0, LSR, 16));
1674 }
1675
1676
LoadFromNumberDictionary(Label * miss,Register elements,Register key,Register result,Register t0,Register t1,Register t2)1677 void MacroAssembler::LoadFromNumberDictionary(Label* miss,
1678 Register elements,
1679 Register key,
1680 Register result,
1681 Register t0,
1682 Register t1,
1683 Register t2) {
1684 // Register use:
1685 //
1686 // elements - holds the slow-case elements of the receiver on entry.
1687 // Unchanged unless 'result' is the same register.
1688 //
1689 // key - holds the smi key on entry.
1690 // Unchanged unless 'result' is the same register.
1691 //
1692 // result - holds the result on exit if the load succeeded.
1693 // Allowed to be the same as 'key' or 'result'.
1694 // Unchanged on bailout so 'key' or 'result' can be used
1695 // in further computation.
1696 //
1697 // Scratch registers:
1698 //
1699 // t0 - holds the untagged key on entry and holds the hash once computed.
1700 //
1701 // t1 - used to hold the capacity mask of the dictionary
1702 //
1703 // t2 - used for the index into the dictionary.
1704 Label done;
1705
1706 GetNumberHash(t0, t1);
1707
1708 // Compute the capacity mask.
1709 ldr(t1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset));
1710 SmiUntag(t1);
1711 sub(t1, t1, Operand(1));
1712
1713 // Generate an unrolled loop that performs a few probes before giving up.
1714 for (int i = 0; i < kNumberDictionaryProbes; i++) {
1715 // Use t2 for index calculations and keep the hash intact in t0.
1716 mov(t2, t0);
1717 // Compute the masked index: (hash + i + i * i) & mask.
1718 if (i > 0) {
1719 add(t2, t2, Operand(SeededNumberDictionary::GetProbeOffset(i)));
1720 }
1721 and_(t2, t2, Operand(t1));
1722
1723 // Scale the index by multiplying by the element size.
1724 ASSERT(SeededNumberDictionary::kEntrySize == 3);
1725 add(t2, t2, Operand(t2, LSL, 1)); // t2 = t2 * 3
1726
1727 // Check if the key is identical to the name.
1728 add(t2, elements, Operand(t2, LSL, kPointerSizeLog2));
1729 ldr(ip, FieldMemOperand(t2, SeededNumberDictionary::kElementsStartOffset));
1730 cmp(key, Operand(ip));
1731 if (i != kNumberDictionaryProbes - 1) {
1732 b(eq, &done);
1733 } else {
1734 b(ne, miss);
1735 }
1736 }
1737
1738 bind(&done);
1739 // Check that the value is a normal property.
1740 // t2: elements + (index * kPointerSize)
1741 const int kDetailsOffset =
1742 SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize;
1743 ldr(t1, FieldMemOperand(t2, kDetailsOffset));
1744 tst(t1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask)));
1745 b(ne, miss);
1746
1747 // Get the value at the masked, scaled index and return.
1748 const int kValueOffset =
1749 SeededNumberDictionary::kElementsStartOffset + kPointerSize;
1750 ldr(result, FieldMemOperand(t2, kValueOffset));
1751 }
1752
1753
Allocate(int object_size,Register result,Register scratch1,Register scratch2,Label * gc_required,AllocationFlags flags)1754 void MacroAssembler::Allocate(int object_size,
1755 Register result,
1756 Register scratch1,
1757 Register scratch2,
1758 Label* gc_required,
1759 AllocationFlags flags) {
1760 ASSERT(object_size <= Page::kMaxRegularHeapObjectSize);
1761 if (!FLAG_inline_new) {
1762 if (emit_debug_code()) {
1763 // Trash the registers to simulate an allocation failure.
1764 mov(result, Operand(0x7091));
1765 mov(scratch1, Operand(0x7191));
1766 mov(scratch2, Operand(0x7291));
1767 }
1768 jmp(gc_required);
1769 return;
1770 }
1771
1772 ASSERT(!result.is(scratch1));
1773 ASSERT(!result.is(scratch2));
1774 ASSERT(!scratch1.is(scratch2));
1775 ASSERT(!scratch1.is(ip));
1776 ASSERT(!scratch2.is(ip));
1777
1778 // Make object size into bytes.
1779 if ((flags & SIZE_IN_WORDS) != 0) {
1780 object_size *= kPointerSize;
1781 }
1782 ASSERT_EQ(0, object_size & kObjectAlignmentMask);
1783
1784 // Check relative positions of allocation top and limit addresses.
1785 // The values must be adjacent in memory to allow the use of LDM.
1786 // Also, assert that the registers are numbered such that the values
1787 // are loaded in the correct order.
1788 ExternalReference allocation_top =
1789 AllocationUtils::GetAllocationTopReference(isolate(), flags);
1790 ExternalReference allocation_limit =
1791 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
1792
1793 intptr_t top =
1794 reinterpret_cast<intptr_t>(allocation_top.address());
1795 intptr_t limit =
1796 reinterpret_cast<intptr_t>(allocation_limit.address());
1797 ASSERT((limit - top) == kPointerSize);
1798 ASSERT(result.code() < ip.code());
1799
1800 // Set up allocation top address register.
1801 Register topaddr = scratch1;
1802 mov(topaddr, Operand(allocation_top));
1803
1804 // This code stores a temporary value in ip. This is OK, as the code below
1805 // does not need ip for implicit literal generation.
1806 if ((flags & RESULT_CONTAINS_TOP) == 0) {
1807 // Load allocation top into result and allocation limit into ip.
1808 ldm(ia, topaddr, result.bit() | ip.bit());
1809 } else {
1810 if (emit_debug_code()) {
1811 // Assert that result actually contains top on entry. ip is used
1812 // immediately below so this use of ip does not cause difference with
1813 // respect to register content between debug and release mode.
1814 ldr(ip, MemOperand(topaddr));
1815 cmp(result, ip);
1816 Check(eq, kUnexpectedAllocationTop);
1817 }
1818 // Load allocation limit into ip. Result already contains allocation top.
1819 ldr(ip, MemOperand(topaddr, limit - top));
1820 }
1821
1822 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1823 // Align the next allocation. Storing the filler map without checking top is
1824 // safe in new-space because the limit of the heap is aligned there.
1825 ASSERT((flags & PRETENURE_OLD_POINTER_SPACE) == 0);
1826 STATIC_ASSERT(kPointerAlignment * 2 == kDoubleAlignment);
1827 and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC);
1828 Label aligned;
1829 b(eq, &aligned);
1830 if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) {
1831 cmp(result, Operand(ip));
1832 b(hs, gc_required);
1833 }
1834 mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
1835 str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex));
1836 bind(&aligned);
1837 }
1838
1839 // Calculate new top and bail out if new space is exhausted. Use result
1840 // to calculate the new top. We must preserve the ip register at this
1841 // point, so we cannot just use add().
1842 ASSERT(object_size > 0);
1843 Register source = result;
1844 Condition cond = al;
1845 int shift = 0;
1846 while (object_size != 0) {
1847 if (((object_size >> shift) & 0x03) == 0) {
1848 shift += 2;
1849 } else {
1850 int bits = object_size & (0xff << shift);
1851 object_size -= bits;
1852 shift += 8;
1853 Operand bits_operand(bits);
1854 ASSERT(bits_operand.is_single_instruction(this));
1855 add(scratch2, source, bits_operand, SetCC, cond);
1856 source = scratch2;
1857 cond = cc;
1858 }
1859 }
1860 b(cs, gc_required);
1861 cmp(scratch2, Operand(ip));
1862 b(hi, gc_required);
1863 str(scratch2, MemOperand(topaddr));
1864
1865 // Tag object if requested.
1866 if ((flags & TAG_OBJECT) != 0) {
1867 add(result, result, Operand(kHeapObjectTag));
1868 }
1869 }
1870
1871
Allocate(Register object_size,Register result,Register scratch1,Register scratch2,Label * gc_required,AllocationFlags flags)1872 void MacroAssembler::Allocate(Register object_size,
1873 Register result,
1874 Register scratch1,
1875 Register scratch2,
1876 Label* gc_required,
1877 AllocationFlags flags) {
1878 if (!FLAG_inline_new) {
1879 if (emit_debug_code()) {
1880 // Trash the registers to simulate an allocation failure.
1881 mov(result, Operand(0x7091));
1882 mov(scratch1, Operand(0x7191));
1883 mov(scratch2, Operand(0x7291));
1884 }
1885 jmp(gc_required);
1886 return;
1887 }
1888
1889 // Assert that the register arguments are different and that none of
1890 // them are ip. ip is used explicitly in the code generated below.
1891 ASSERT(!result.is(scratch1));
1892 ASSERT(!result.is(scratch2));
1893 ASSERT(!scratch1.is(scratch2));
1894 ASSERT(!object_size.is(ip));
1895 ASSERT(!result.is(ip));
1896 ASSERT(!scratch1.is(ip));
1897 ASSERT(!scratch2.is(ip));
1898
1899 // Check relative positions of allocation top and limit addresses.
1900 // The values must be adjacent in memory to allow the use of LDM.
1901 // Also, assert that the registers are numbered such that the values
1902 // are loaded in the correct order.
1903 ExternalReference allocation_top =
1904 AllocationUtils::GetAllocationTopReference(isolate(), flags);
1905 ExternalReference allocation_limit =
1906 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
1907 intptr_t top =
1908 reinterpret_cast<intptr_t>(allocation_top.address());
1909 intptr_t limit =
1910 reinterpret_cast<intptr_t>(allocation_limit.address());
1911 ASSERT((limit - top) == kPointerSize);
1912 ASSERT(result.code() < ip.code());
1913
1914 // Set up allocation top address.
1915 Register topaddr = scratch1;
1916 mov(topaddr, Operand(allocation_top));
1917
1918 // This code stores a temporary value in ip. This is OK, as the code below
1919 // does not need ip for implicit literal generation.
1920 if ((flags & RESULT_CONTAINS_TOP) == 0) {
1921 // Load allocation top into result and allocation limit into ip.
1922 ldm(ia, topaddr, result.bit() | ip.bit());
1923 } else {
1924 if (emit_debug_code()) {
1925 // Assert that result actually contains top on entry. ip is used
1926 // immediately below so this use of ip does not cause difference with
1927 // respect to register content between debug and release mode.
1928 ldr(ip, MemOperand(topaddr));
1929 cmp(result, ip);
1930 Check(eq, kUnexpectedAllocationTop);
1931 }
1932 // Load allocation limit into ip. Result already contains allocation top.
1933 ldr(ip, MemOperand(topaddr, limit - top));
1934 }
1935
1936 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1937 // Align the next allocation. Storing the filler map without checking top is
1938 // safe in new-space because the limit of the heap is aligned there.
1939 ASSERT((flags & PRETENURE_OLD_POINTER_SPACE) == 0);
1940 ASSERT(kPointerAlignment * 2 == kDoubleAlignment);
1941 and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC);
1942 Label aligned;
1943 b(eq, &aligned);
1944 if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) {
1945 cmp(result, Operand(ip));
1946 b(hs, gc_required);
1947 }
1948 mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map()));
1949 str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex));
1950 bind(&aligned);
1951 }
1952
1953 // Calculate new top and bail out if new space is exhausted. Use result
1954 // to calculate the new top. Object size may be in words so a shift is
1955 // required to get the number of bytes.
1956 if ((flags & SIZE_IN_WORDS) != 0) {
1957 add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC);
1958 } else {
1959 add(scratch2, result, Operand(object_size), SetCC);
1960 }
1961 b(cs, gc_required);
1962 cmp(scratch2, Operand(ip));
1963 b(hi, gc_required);
1964
1965 // Update allocation top. result temporarily holds the new top.
1966 if (emit_debug_code()) {
1967 tst(scratch2, Operand(kObjectAlignmentMask));
1968 Check(eq, kUnalignedAllocationInNewSpace);
1969 }
1970 str(scratch2, MemOperand(topaddr));
1971
1972 // Tag object if requested.
1973 if ((flags & TAG_OBJECT) != 0) {
1974 add(result, result, Operand(kHeapObjectTag));
1975 }
1976 }
1977
1978
UndoAllocationInNewSpace(Register object,Register scratch)1979 void MacroAssembler::UndoAllocationInNewSpace(Register object,
1980 Register scratch) {
1981 ExternalReference new_space_allocation_top =
1982 ExternalReference::new_space_allocation_top_address(isolate());
1983
1984 // Make sure the object has no tag before resetting top.
1985 and_(object, object, Operand(~kHeapObjectTagMask));
1986 #ifdef DEBUG
1987 // Check that the object un-allocated is below the current top.
1988 mov(scratch, Operand(new_space_allocation_top));
1989 ldr(scratch, MemOperand(scratch));
1990 cmp(object, scratch);
1991 Check(lt, kUndoAllocationOfNonAllocatedMemory);
1992 #endif
1993 // Write the address of the object to un-allocate as the current top.
1994 mov(scratch, Operand(new_space_allocation_top));
1995 str(object, MemOperand(scratch));
1996 }
1997
1998
AllocateTwoByteString(Register result,Register length,Register scratch1,Register scratch2,Register scratch3,Label * gc_required)1999 void MacroAssembler::AllocateTwoByteString(Register result,
2000 Register length,
2001 Register scratch1,
2002 Register scratch2,
2003 Register scratch3,
2004 Label* gc_required) {
2005 // Calculate the number of bytes needed for the characters in the string while
2006 // observing object alignment.
2007 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2008 mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars.
2009 add(scratch1, scratch1,
2010 Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize));
2011 and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
2012
2013 // Allocate two-byte string in new space.
2014 Allocate(scratch1,
2015 result,
2016 scratch2,
2017 scratch3,
2018 gc_required,
2019 TAG_OBJECT);
2020
2021 // Set the map, length and hash field.
2022 InitializeNewString(result,
2023 length,
2024 Heap::kStringMapRootIndex,
2025 scratch1,
2026 scratch2);
2027 }
2028
2029
AllocateAsciiString(Register result,Register length,Register scratch1,Register scratch2,Register scratch3,Label * gc_required)2030 void MacroAssembler::AllocateAsciiString(Register result,
2031 Register length,
2032 Register scratch1,
2033 Register scratch2,
2034 Register scratch3,
2035 Label* gc_required) {
2036 // Calculate the number of bytes needed for the characters in the string while
2037 // observing object alignment.
2038 ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2039 ASSERT(kCharSize == 1);
2040 add(scratch1, length,
2041 Operand(kObjectAlignmentMask + SeqOneByteString::kHeaderSize));
2042 and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
2043
2044 // Allocate ASCII string in new space.
2045 Allocate(scratch1,
2046 result,
2047 scratch2,
2048 scratch3,
2049 gc_required,
2050 TAG_OBJECT);
2051
2052 // Set the map, length and hash field.
2053 InitializeNewString(result,
2054 length,
2055 Heap::kAsciiStringMapRootIndex,
2056 scratch1,
2057 scratch2);
2058 }
2059
2060
AllocateTwoByteConsString(Register result,Register length,Register scratch1,Register scratch2,Label * gc_required)2061 void MacroAssembler::AllocateTwoByteConsString(Register result,
2062 Register length,
2063 Register scratch1,
2064 Register scratch2,
2065 Label* gc_required) {
2066 Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required,
2067 TAG_OBJECT);
2068
2069 InitializeNewString(result,
2070 length,
2071 Heap::kConsStringMapRootIndex,
2072 scratch1,
2073 scratch2);
2074 }
2075
2076
AllocateAsciiConsString(Register result,Register length,Register scratch1,Register scratch2,Label * gc_required)2077 void MacroAssembler::AllocateAsciiConsString(Register result,
2078 Register length,
2079 Register scratch1,
2080 Register scratch2,
2081 Label* gc_required) {
2082 Allocate(ConsString::kSize,
2083 result,
2084 scratch1,
2085 scratch2,
2086 gc_required,
2087 TAG_OBJECT);
2088
2089 InitializeNewString(result,
2090 length,
2091 Heap::kConsAsciiStringMapRootIndex,
2092 scratch1,
2093 scratch2);
2094 }
2095
2096
AllocateTwoByteSlicedString(Register result,Register length,Register scratch1,Register scratch2,Label * gc_required)2097 void MacroAssembler::AllocateTwoByteSlicedString(Register result,
2098 Register length,
2099 Register scratch1,
2100 Register scratch2,
2101 Label* gc_required) {
2102 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
2103 TAG_OBJECT);
2104
2105 InitializeNewString(result,
2106 length,
2107 Heap::kSlicedStringMapRootIndex,
2108 scratch1,
2109 scratch2);
2110 }
2111
2112
AllocateAsciiSlicedString(Register result,Register length,Register scratch1,Register scratch2,Label * gc_required)2113 void MacroAssembler::AllocateAsciiSlicedString(Register result,
2114 Register length,
2115 Register scratch1,
2116 Register scratch2,
2117 Label* gc_required) {
2118 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
2119 TAG_OBJECT);
2120
2121 InitializeNewString(result,
2122 length,
2123 Heap::kSlicedAsciiStringMapRootIndex,
2124 scratch1,
2125 scratch2);
2126 }
2127
2128
CompareObjectType(Register object,Register map,Register type_reg,InstanceType type)2129 void MacroAssembler::CompareObjectType(Register object,
2130 Register map,
2131 Register type_reg,
2132 InstanceType type) {
2133 const Register temp = type_reg.is(no_reg) ? ip : type_reg;
2134
2135 ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
2136 CompareInstanceType(map, temp, type);
2137 }
2138
2139
CheckObjectTypeRange(Register object,Register map,InstanceType min_type,InstanceType max_type,Label * false_label)2140 void MacroAssembler::CheckObjectTypeRange(Register object,
2141 Register map,
2142 InstanceType min_type,
2143 InstanceType max_type,
2144 Label* false_label) {
2145 STATIC_ASSERT(Map::kInstanceTypeOffset < 4096);
2146 STATIC_ASSERT(LAST_TYPE < 256);
2147 ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
2148 ldrb(ip, FieldMemOperand(map, Map::kInstanceTypeOffset));
2149 sub(ip, ip, Operand(min_type));
2150 cmp(ip, Operand(max_type - min_type));
2151 b(hi, false_label);
2152 }
2153
2154
CompareInstanceType(Register map,Register type_reg,InstanceType type)2155 void MacroAssembler::CompareInstanceType(Register map,
2156 Register type_reg,
2157 InstanceType type) {
2158 // Registers map and type_reg can be ip. These two lines assert
2159 // that ip can be used with the two instructions (the constants
2160 // will never need ip).
2161 STATIC_ASSERT(Map::kInstanceTypeOffset < 4096);
2162 STATIC_ASSERT(LAST_TYPE < 256);
2163 ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
2164 cmp(type_reg, Operand(type));
2165 }
2166
2167
CompareRoot(Register obj,Heap::RootListIndex index)2168 void MacroAssembler::CompareRoot(Register obj,
2169 Heap::RootListIndex index) {
2170 ASSERT(!obj.is(ip));
2171 LoadRoot(ip, index);
2172 cmp(obj, ip);
2173 }
2174
2175
CheckFastElements(Register map,Register scratch,Label * fail)2176 void MacroAssembler::CheckFastElements(Register map,
2177 Register scratch,
2178 Label* fail) {
2179 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2180 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
2181 STATIC_ASSERT(FAST_ELEMENTS == 2);
2182 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
2183 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
2184 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue));
2185 b(hi, fail);
2186 }
2187
2188
CheckFastObjectElements(Register map,Register scratch,Label * fail)2189 void MacroAssembler::CheckFastObjectElements(Register map,
2190 Register scratch,
2191 Label* fail) {
2192 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2193 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
2194 STATIC_ASSERT(FAST_ELEMENTS == 2);
2195 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
2196 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
2197 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
2198 b(ls, fail);
2199 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue));
2200 b(hi, fail);
2201 }
2202
2203
CheckFastSmiElements(Register map,Register scratch,Label * fail)2204 void MacroAssembler::CheckFastSmiElements(Register map,
2205 Register scratch,
2206 Label* fail) {
2207 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
2208 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
2209 ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
2210 cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
2211 b(hi, fail);
2212 }
2213
2214
StoreNumberToDoubleElements(Register value_reg,Register key_reg,Register elements_reg,Register scratch1,LowDwVfpRegister double_scratch,Label * fail,int elements_offset)2215 void MacroAssembler::StoreNumberToDoubleElements(
2216 Register value_reg,
2217 Register key_reg,
2218 Register elements_reg,
2219 Register scratch1,
2220 LowDwVfpRegister double_scratch,
2221 Label* fail,
2222 int elements_offset) {
2223 Label smi_value, store;
2224
2225 // Handle smi values specially.
2226 JumpIfSmi(value_reg, &smi_value);
2227
2228 // Ensure that the object is a heap number
2229 CheckMap(value_reg,
2230 scratch1,
2231 isolate()->factory()->heap_number_map(),
2232 fail,
2233 DONT_DO_SMI_CHECK);
2234
2235 vldr(double_scratch, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
2236 // Force a canonical NaN.
2237 if (emit_debug_code()) {
2238 vmrs(ip);
2239 tst(ip, Operand(kVFPDefaultNaNModeControlBit));
2240 Assert(ne, kDefaultNaNModeNotSet);
2241 }
2242 VFPCanonicalizeNaN(double_scratch);
2243 b(&store);
2244
2245 bind(&smi_value);
2246 SmiToDouble(double_scratch, value_reg);
2247
2248 bind(&store);
2249 add(scratch1, elements_reg, Operand::DoubleOffsetFromSmiKey(key_reg));
2250 vstr(double_scratch,
2251 FieldMemOperand(scratch1,
2252 FixedDoubleArray::kHeaderSize - elements_offset));
2253 }
2254
2255
CompareMap(Register obj,Register scratch,Handle<Map> map,Label * early_success)2256 void MacroAssembler::CompareMap(Register obj,
2257 Register scratch,
2258 Handle<Map> map,
2259 Label* early_success) {
2260 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2261 CompareMap(scratch, map, early_success);
2262 }
2263
2264
CompareMap(Register obj_map,Handle<Map> map,Label * early_success)2265 void MacroAssembler::CompareMap(Register obj_map,
2266 Handle<Map> map,
2267 Label* early_success) {
2268 cmp(obj_map, Operand(map));
2269 }
2270
2271
CheckMap(Register obj,Register scratch,Handle<Map> map,Label * fail,SmiCheckType smi_check_type)2272 void MacroAssembler::CheckMap(Register obj,
2273 Register scratch,
2274 Handle<Map> map,
2275 Label* fail,
2276 SmiCheckType smi_check_type) {
2277 if (smi_check_type == DO_SMI_CHECK) {
2278 JumpIfSmi(obj, fail);
2279 }
2280
2281 Label success;
2282 CompareMap(obj, scratch, map, &success);
2283 b(ne, fail);
2284 bind(&success);
2285 }
2286
2287
CheckMap(Register obj,Register scratch,Heap::RootListIndex index,Label * fail,SmiCheckType smi_check_type)2288 void MacroAssembler::CheckMap(Register obj,
2289 Register scratch,
2290 Heap::RootListIndex index,
2291 Label* fail,
2292 SmiCheckType smi_check_type) {
2293 if (smi_check_type == DO_SMI_CHECK) {
2294 JumpIfSmi(obj, fail);
2295 }
2296 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2297 LoadRoot(ip, index);
2298 cmp(scratch, ip);
2299 b(ne, fail);
2300 }
2301
2302
DispatchMap(Register obj,Register scratch,Handle<Map> map,Handle<Code> success,SmiCheckType smi_check_type)2303 void MacroAssembler::DispatchMap(Register obj,
2304 Register scratch,
2305 Handle<Map> map,
2306 Handle<Code> success,
2307 SmiCheckType smi_check_type) {
2308 Label fail;
2309 if (smi_check_type == DO_SMI_CHECK) {
2310 JumpIfSmi(obj, &fail);
2311 }
2312 ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2313 mov(ip, Operand(map));
2314 cmp(scratch, ip);
2315 Jump(success, RelocInfo::CODE_TARGET, eq);
2316 bind(&fail);
2317 }
2318
2319
TryGetFunctionPrototype(Register function,Register result,Register scratch,Label * miss,bool miss_on_bound_function)2320 void MacroAssembler::TryGetFunctionPrototype(Register function,
2321 Register result,
2322 Register scratch,
2323 Label* miss,
2324 bool miss_on_bound_function) {
2325 // Check that the receiver isn't a smi.
2326 JumpIfSmi(function, miss);
2327
2328 // Check that the function really is a function. Load map into result reg.
2329 CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE);
2330 b(ne, miss);
2331
2332 if (miss_on_bound_function) {
2333 ldr(scratch,
2334 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
2335 ldr(scratch,
2336 FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset));
2337 tst(scratch,
2338 Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction)));
2339 b(ne, miss);
2340 }
2341
2342 // Make sure that the function has an instance prototype.
2343 Label non_instance;
2344 ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset));
2345 tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
2346 b(ne, &non_instance);
2347
2348 // Get the prototype or initial map from the function.
2349 ldr(result,
2350 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2351
2352 // If the prototype or initial map is the hole, don't return it and
2353 // simply miss the cache instead. This will allow us to allocate a
2354 // prototype object on-demand in the runtime system.
2355 LoadRoot(ip, Heap::kTheHoleValueRootIndex);
2356 cmp(result, ip);
2357 b(eq, miss);
2358
2359 // If the function does not have an initial map, we're done.
2360 Label done;
2361 CompareObjectType(result, scratch, scratch, MAP_TYPE);
2362 b(ne, &done);
2363
2364 // Get the prototype from the initial map.
2365 ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
2366 jmp(&done);
2367
2368 // Non-instance prototype: Fetch prototype from constructor field
2369 // in initial map.
2370 bind(&non_instance);
2371 ldr(result, FieldMemOperand(result, Map::kConstructorOffset));
2372
2373 // All done.
2374 bind(&done);
2375 }
2376
2377
CallStub(CodeStub * stub,TypeFeedbackId ast_id,Condition cond)2378 void MacroAssembler::CallStub(CodeStub* stub,
2379 TypeFeedbackId ast_id,
2380 Condition cond) {
2381 ASSERT(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs.
2382 Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id, cond);
2383 }
2384
2385
TailCallStub(CodeStub * stub,Condition cond)2386 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) {
2387 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond);
2388 }
2389
2390
AddressOffset(ExternalReference ref0,ExternalReference ref1)2391 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
2392 return ref0.address() - ref1.address();
2393 }
2394
2395
CallApiFunctionAndReturn(Register function_address,ExternalReference thunk_ref,int stack_space,MemOperand return_value_operand,MemOperand * context_restore_operand)2396 void MacroAssembler::CallApiFunctionAndReturn(
2397 Register function_address,
2398 ExternalReference thunk_ref,
2399 int stack_space,
2400 MemOperand return_value_operand,
2401 MemOperand* context_restore_operand) {
2402 ExternalReference next_address =
2403 ExternalReference::handle_scope_next_address(isolate());
2404 const int kNextOffset = 0;
2405 const int kLimitOffset = AddressOffset(
2406 ExternalReference::handle_scope_limit_address(isolate()),
2407 next_address);
2408 const int kLevelOffset = AddressOffset(
2409 ExternalReference::handle_scope_level_address(isolate()),
2410 next_address);
2411
2412 ASSERT(function_address.is(r1) || function_address.is(r2));
2413
2414 Label profiler_disabled;
2415 Label end_profiler_check;
2416 mov(r9, Operand(ExternalReference::is_profiling_address(isolate())));
2417 ldrb(r9, MemOperand(r9, 0));
2418 cmp(r9, Operand(0));
2419 b(eq, &profiler_disabled);
2420
2421 // Additional parameter is the address of the actual callback.
2422 mov(r3, Operand(thunk_ref));
2423 jmp(&end_profiler_check);
2424
2425 bind(&profiler_disabled);
2426 Move(r3, function_address);
2427 bind(&end_profiler_check);
2428
2429 // Allocate HandleScope in callee-save registers.
2430 mov(r9, Operand(next_address));
2431 ldr(r4, MemOperand(r9, kNextOffset));
2432 ldr(r5, MemOperand(r9, kLimitOffset));
2433 ldr(r6, MemOperand(r9, kLevelOffset));
2434 add(r6, r6, Operand(1));
2435 str(r6, MemOperand(r9, kLevelOffset));
2436
2437 if (FLAG_log_timer_events) {
2438 FrameScope frame(this, StackFrame::MANUAL);
2439 PushSafepointRegisters();
2440 PrepareCallCFunction(1, r0);
2441 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2442 CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1);
2443 PopSafepointRegisters();
2444 }
2445
2446 // Native call returns to the DirectCEntry stub which redirects to the
2447 // return address pushed on stack (could have moved after GC).
2448 // DirectCEntry stub itself is generated early and never moves.
2449 DirectCEntryStub stub(isolate());
2450 stub.GenerateCall(this, r3);
2451
2452 if (FLAG_log_timer_events) {
2453 FrameScope frame(this, StackFrame::MANUAL);
2454 PushSafepointRegisters();
2455 PrepareCallCFunction(1, r0);
2456 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2457 CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1);
2458 PopSafepointRegisters();
2459 }
2460
2461 Label promote_scheduled_exception;
2462 Label exception_handled;
2463 Label delete_allocated_handles;
2464 Label leave_exit_frame;
2465 Label return_value_loaded;
2466
2467 // load value from ReturnValue
2468 ldr(r0, return_value_operand);
2469 bind(&return_value_loaded);
2470 // No more valid handles (the result handle was the last one). Restore
2471 // previous handle scope.
2472 str(r4, MemOperand(r9, kNextOffset));
2473 if (emit_debug_code()) {
2474 ldr(r1, MemOperand(r9, kLevelOffset));
2475 cmp(r1, r6);
2476 Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
2477 }
2478 sub(r6, r6, Operand(1));
2479 str(r6, MemOperand(r9, kLevelOffset));
2480 ldr(ip, MemOperand(r9, kLimitOffset));
2481 cmp(r5, ip);
2482 b(ne, &delete_allocated_handles);
2483
2484 // Check if the function scheduled an exception.
2485 bind(&leave_exit_frame);
2486 LoadRoot(r4, Heap::kTheHoleValueRootIndex);
2487 mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate())));
2488 ldr(r5, MemOperand(ip));
2489 cmp(r4, r5);
2490 b(ne, &promote_scheduled_exception);
2491 bind(&exception_handled);
2492
2493 bool restore_context = context_restore_operand != NULL;
2494 if (restore_context) {
2495 ldr(cp, *context_restore_operand);
2496 }
2497 // LeaveExitFrame expects unwind space to be in a register.
2498 mov(r4, Operand(stack_space));
2499 LeaveExitFrame(false, r4, !restore_context);
2500 mov(pc, lr);
2501
2502 bind(&promote_scheduled_exception);
2503 {
2504 FrameScope frame(this, StackFrame::INTERNAL);
2505 CallExternalReference(
2506 ExternalReference(Runtime::kHiddenPromoteScheduledException, isolate()),
2507 0);
2508 }
2509 jmp(&exception_handled);
2510
2511 // HandleScope limit has changed. Delete allocated extensions.
2512 bind(&delete_allocated_handles);
2513 str(r5, MemOperand(r9, kLimitOffset));
2514 mov(r4, r0);
2515 PrepareCallCFunction(1, r5);
2516 mov(r0, Operand(ExternalReference::isolate_address(isolate())));
2517 CallCFunction(
2518 ExternalReference::delete_handle_scope_extensions(isolate()), 1);
2519 mov(r0, r4);
2520 jmp(&leave_exit_frame);
2521 }
2522
2523
AllowThisStubCall(CodeStub * stub)2524 bool MacroAssembler::AllowThisStubCall(CodeStub* stub) {
2525 return has_frame_ || !stub->SometimesSetsUpAFrame();
2526 }
2527
2528
IndexFromHash(Register hash,Register index)2529 void MacroAssembler::IndexFromHash(Register hash, Register index) {
2530 // If the hash field contains an array index pick it out. The assert checks
2531 // that the constants for the maximum number of digits for an array index
2532 // cached in the hash field and the number of bits reserved for it does not
2533 // conflict.
2534 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
2535 (1 << String::kArrayIndexValueBits));
2536 DecodeFieldToSmi<String::ArrayIndexValueBits>(index, hash);
2537 }
2538
2539
SmiToDouble(LowDwVfpRegister value,Register smi)2540 void MacroAssembler::SmiToDouble(LowDwVfpRegister value, Register smi) {
2541 if (CpuFeatures::IsSupported(VFP3)) {
2542 vmov(value.low(), smi);
2543 vcvt_f64_s32(value, 1);
2544 } else {
2545 SmiUntag(ip, smi);
2546 vmov(value.low(), ip);
2547 vcvt_f64_s32(value, value.low());
2548 }
2549 }
2550
2551
TestDoubleIsInt32(DwVfpRegister double_input,LowDwVfpRegister double_scratch)2552 void MacroAssembler::TestDoubleIsInt32(DwVfpRegister double_input,
2553 LowDwVfpRegister double_scratch) {
2554 ASSERT(!double_input.is(double_scratch));
2555 vcvt_s32_f64(double_scratch.low(), double_input);
2556 vcvt_f64_s32(double_scratch, double_scratch.low());
2557 VFPCompareAndSetFlags(double_input, double_scratch);
2558 }
2559
2560
TryDoubleToInt32Exact(Register result,DwVfpRegister double_input,LowDwVfpRegister double_scratch)2561 void MacroAssembler::TryDoubleToInt32Exact(Register result,
2562 DwVfpRegister double_input,
2563 LowDwVfpRegister double_scratch) {
2564 ASSERT(!double_input.is(double_scratch));
2565 vcvt_s32_f64(double_scratch.low(), double_input);
2566 vmov(result, double_scratch.low());
2567 vcvt_f64_s32(double_scratch, double_scratch.low());
2568 VFPCompareAndSetFlags(double_input, double_scratch);
2569 }
2570
2571
TryInt32Floor(Register result,DwVfpRegister double_input,Register input_high,LowDwVfpRegister double_scratch,Label * done,Label * exact)2572 void MacroAssembler::TryInt32Floor(Register result,
2573 DwVfpRegister double_input,
2574 Register input_high,
2575 LowDwVfpRegister double_scratch,
2576 Label* done,
2577 Label* exact) {
2578 ASSERT(!result.is(input_high));
2579 ASSERT(!double_input.is(double_scratch));
2580 Label negative, exception;
2581
2582 VmovHigh(input_high, double_input);
2583
2584 // Test for NaN and infinities.
2585 Sbfx(result, input_high,
2586 HeapNumber::kExponentShift, HeapNumber::kExponentBits);
2587 cmp(result, Operand(-1));
2588 b(eq, &exception);
2589 // Test for values that can be exactly represented as a
2590 // signed 32-bit integer.
2591 TryDoubleToInt32Exact(result, double_input, double_scratch);
2592 // If exact, return (result already fetched).
2593 b(eq, exact);
2594 cmp(input_high, Operand::Zero());
2595 b(mi, &negative);
2596
2597 // Input is in ]+0, +inf[.
2598 // If result equals 0x7fffffff input was out of range or
2599 // in ]0x7fffffff, 0x80000000[. We ignore this last case which
2600 // could fits into an int32, that means we always think input was
2601 // out of range and always go to exception.
2602 // If result < 0x7fffffff, go to done, result fetched.
2603 cmn(result, Operand(1));
2604 b(mi, &exception);
2605 b(done);
2606
2607 // Input is in ]-inf, -0[.
2608 // If x is a non integer negative number,
2609 // floor(x) <=> round_to_zero(x) - 1.
2610 bind(&negative);
2611 sub(result, result, Operand(1), SetCC);
2612 // If result is still negative, go to done, result fetched.
2613 // Else, we had an overflow and we fall through exception.
2614 b(mi, done);
2615 bind(&exception);
2616 }
2617
TryInlineTruncateDoubleToI(Register result,DwVfpRegister double_input,Label * done)2618 void MacroAssembler::TryInlineTruncateDoubleToI(Register result,
2619 DwVfpRegister double_input,
2620 Label* done) {
2621 LowDwVfpRegister double_scratch = kScratchDoubleReg;
2622 vcvt_s32_f64(double_scratch.low(), double_input);
2623 vmov(result, double_scratch.low());
2624
2625 // If result is not saturated (0x7fffffff or 0x80000000), we are done.
2626 sub(ip, result, Operand(1));
2627 cmp(ip, Operand(0x7ffffffe));
2628 b(lt, done);
2629 }
2630
2631
TruncateDoubleToI(Register result,DwVfpRegister double_input)2632 void MacroAssembler::TruncateDoubleToI(Register result,
2633 DwVfpRegister double_input) {
2634 Label done;
2635
2636 TryInlineTruncateDoubleToI(result, double_input, &done);
2637
2638 // If we fell through then inline version didn't succeed - call stub instead.
2639 push(lr);
2640 sub(sp, sp, Operand(kDoubleSize)); // Put input on stack.
2641 vstr(double_input, MemOperand(sp, 0));
2642
2643 DoubleToIStub stub(isolate(), sp, result, 0, true, true);
2644 CallStub(&stub);
2645
2646 add(sp, sp, Operand(kDoubleSize));
2647 pop(lr);
2648
2649 bind(&done);
2650 }
2651
2652
TruncateHeapNumberToI(Register result,Register object)2653 void MacroAssembler::TruncateHeapNumberToI(Register result,
2654 Register object) {
2655 Label done;
2656 LowDwVfpRegister double_scratch = kScratchDoubleReg;
2657 ASSERT(!result.is(object));
2658
2659 vldr(double_scratch,
2660 MemOperand(object, HeapNumber::kValueOffset - kHeapObjectTag));
2661 TryInlineTruncateDoubleToI(result, double_scratch, &done);
2662
2663 // If we fell through then inline version didn't succeed - call stub instead.
2664 push(lr);
2665 DoubleToIStub stub(isolate(),
2666 object,
2667 result,
2668 HeapNumber::kValueOffset - kHeapObjectTag,
2669 true,
2670 true);
2671 CallStub(&stub);
2672 pop(lr);
2673
2674 bind(&done);
2675 }
2676
2677
TruncateNumberToI(Register object,Register result,Register heap_number_map,Register scratch1,Label * not_number)2678 void MacroAssembler::TruncateNumberToI(Register object,
2679 Register result,
2680 Register heap_number_map,
2681 Register scratch1,
2682 Label* not_number) {
2683 Label done;
2684 ASSERT(!result.is(object));
2685
2686 UntagAndJumpIfSmi(result, object, &done);
2687 JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number);
2688 TruncateHeapNumberToI(result, object);
2689
2690 bind(&done);
2691 }
2692
2693
GetLeastBitsFromSmi(Register dst,Register src,int num_least_bits)2694 void MacroAssembler::GetLeastBitsFromSmi(Register dst,
2695 Register src,
2696 int num_least_bits) {
2697 if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size()) {
2698 ubfx(dst, src, kSmiTagSize, num_least_bits);
2699 } else {
2700 SmiUntag(dst, src);
2701 and_(dst, dst, Operand((1 << num_least_bits) - 1));
2702 }
2703 }
2704
2705
GetLeastBitsFromInt32(Register dst,Register src,int num_least_bits)2706 void MacroAssembler::GetLeastBitsFromInt32(Register dst,
2707 Register src,
2708 int num_least_bits) {
2709 and_(dst, src, Operand((1 << num_least_bits) - 1));
2710 }
2711
2712
CallRuntime(const Runtime::Function * f,int num_arguments,SaveFPRegsMode save_doubles)2713 void MacroAssembler::CallRuntime(const Runtime::Function* f,
2714 int num_arguments,
2715 SaveFPRegsMode save_doubles) {
2716 // All parameters are on the stack. r0 has the return value after call.
2717
2718 // If the expected number of arguments of the runtime function is
2719 // constant, we check that the actual number of arguments match the
2720 // expectation.
2721 CHECK(f->nargs < 0 || f->nargs == num_arguments);
2722
2723 // TODO(1236192): Most runtime routines don't need the number of
2724 // arguments passed in because it is constant. At some point we
2725 // should remove this need and make the runtime routine entry code
2726 // smarter.
2727 mov(r0, Operand(num_arguments));
2728 mov(r1, Operand(ExternalReference(f, isolate())));
2729 CEntryStub stub(isolate(), 1, save_doubles);
2730 CallStub(&stub);
2731 }
2732
2733
CallExternalReference(const ExternalReference & ext,int num_arguments)2734 void MacroAssembler::CallExternalReference(const ExternalReference& ext,
2735 int num_arguments) {
2736 mov(r0, Operand(num_arguments));
2737 mov(r1, Operand(ext));
2738
2739 CEntryStub stub(isolate(), 1);
2740 CallStub(&stub);
2741 }
2742
2743
TailCallExternalReference(const ExternalReference & ext,int num_arguments,int result_size)2744 void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
2745 int num_arguments,
2746 int result_size) {
2747 // TODO(1236192): Most runtime routines don't need the number of
2748 // arguments passed in because it is constant. At some point we
2749 // should remove this need and make the runtime routine entry code
2750 // smarter.
2751 mov(r0, Operand(num_arguments));
2752 JumpToExternalReference(ext);
2753 }
2754
2755
TailCallRuntime(Runtime::FunctionId fid,int num_arguments,int result_size)2756 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
2757 int num_arguments,
2758 int result_size) {
2759 TailCallExternalReference(ExternalReference(fid, isolate()),
2760 num_arguments,
2761 result_size);
2762 }
2763
2764
JumpToExternalReference(const ExternalReference & builtin)2765 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) {
2766 #if defined(__thumb__)
2767 // Thumb mode builtin.
2768 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1);
2769 #endif
2770 mov(r1, Operand(builtin));
2771 CEntryStub stub(isolate(), 1);
2772 Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
2773 }
2774
2775
InvokeBuiltin(Builtins::JavaScript id,InvokeFlag flag,const CallWrapper & call_wrapper)2776 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
2777 InvokeFlag flag,
2778 const CallWrapper& call_wrapper) {
2779 // You can't call a builtin without a valid frame.
2780 ASSERT(flag == JUMP_FUNCTION || has_frame());
2781
2782 GetBuiltinEntry(r2, id);
2783 if (flag == CALL_FUNCTION) {
2784 call_wrapper.BeforeCall(CallSize(r2));
2785 Call(r2);
2786 call_wrapper.AfterCall();
2787 } else {
2788 ASSERT(flag == JUMP_FUNCTION);
2789 Jump(r2);
2790 }
2791 }
2792
2793
GetBuiltinFunction(Register target,Builtins::JavaScript id)2794 void MacroAssembler::GetBuiltinFunction(Register target,
2795 Builtins::JavaScript id) {
2796 // Load the builtins object into target register.
2797 ldr(target,
2798 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2799 ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
2800 // Load the JavaScript builtin function from the builtins object.
2801 ldr(target, FieldMemOperand(target,
2802 JSBuiltinsObject::OffsetOfFunctionWithId(id)));
2803 }
2804
2805
GetBuiltinEntry(Register target,Builtins::JavaScript id)2806 void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
2807 ASSERT(!target.is(r1));
2808 GetBuiltinFunction(r1, id);
2809 // Load the code entry point from the builtins object.
2810 ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
2811 }
2812
2813
SetCounter(StatsCounter * counter,int value,Register scratch1,Register scratch2)2814 void MacroAssembler::SetCounter(StatsCounter* counter, int value,
2815 Register scratch1, Register scratch2) {
2816 if (FLAG_native_code_counters && counter->Enabled()) {
2817 mov(scratch1, Operand(value));
2818 mov(scratch2, Operand(ExternalReference(counter)));
2819 str(scratch1, MemOperand(scratch2));
2820 }
2821 }
2822
2823
IncrementCounter(StatsCounter * counter,int value,Register scratch1,Register scratch2)2824 void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
2825 Register scratch1, Register scratch2) {
2826 ASSERT(value > 0);
2827 if (FLAG_native_code_counters && counter->Enabled()) {
2828 mov(scratch2, Operand(ExternalReference(counter)));
2829 ldr(scratch1, MemOperand(scratch2));
2830 add(scratch1, scratch1, Operand(value));
2831 str(scratch1, MemOperand(scratch2));
2832 }
2833 }
2834
2835
DecrementCounter(StatsCounter * counter,int value,Register scratch1,Register scratch2)2836 void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
2837 Register scratch1, Register scratch2) {
2838 ASSERT(value > 0);
2839 if (FLAG_native_code_counters && counter->Enabled()) {
2840 mov(scratch2, Operand(ExternalReference(counter)));
2841 ldr(scratch1, MemOperand(scratch2));
2842 sub(scratch1, scratch1, Operand(value));
2843 str(scratch1, MemOperand(scratch2));
2844 }
2845 }
2846
2847
Assert(Condition cond,BailoutReason reason)2848 void MacroAssembler::Assert(Condition cond, BailoutReason reason) {
2849 if (emit_debug_code())
2850 Check(cond, reason);
2851 }
2852
2853
AssertFastElements(Register elements)2854 void MacroAssembler::AssertFastElements(Register elements) {
2855 if (emit_debug_code()) {
2856 ASSERT(!elements.is(ip));
2857 Label ok;
2858 push(elements);
2859 ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
2860 LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
2861 cmp(elements, ip);
2862 b(eq, &ok);
2863 LoadRoot(ip, Heap::kFixedDoubleArrayMapRootIndex);
2864 cmp(elements, ip);
2865 b(eq, &ok);
2866 LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex);
2867 cmp(elements, ip);
2868 b(eq, &ok);
2869 Abort(kJSObjectWithFastElementsMapHasSlowElements);
2870 bind(&ok);
2871 pop(elements);
2872 }
2873 }
2874
2875
Check(Condition cond,BailoutReason reason)2876 void MacroAssembler::Check(Condition cond, BailoutReason reason) {
2877 Label L;
2878 b(cond, &L);
2879 Abort(reason);
2880 // will not return here
2881 bind(&L);
2882 }
2883
2884
Abort(BailoutReason reason)2885 void MacroAssembler::Abort(BailoutReason reason) {
2886 Label abort_start;
2887 bind(&abort_start);
2888 #ifdef DEBUG
2889 const char* msg = GetBailoutReason(reason);
2890 if (msg != NULL) {
2891 RecordComment("Abort message: ");
2892 RecordComment(msg);
2893 }
2894
2895 if (FLAG_trap_on_abort) {
2896 stop(msg);
2897 return;
2898 }
2899 #endif
2900
2901 mov(r0, Operand(Smi::FromInt(reason)));
2902 push(r0);
2903
2904 // Disable stub call restrictions to always allow calls to abort.
2905 if (!has_frame_) {
2906 // We don't actually want to generate a pile of code for this, so just
2907 // claim there is a stack frame, without generating one.
2908 FrameScope scope(this, StackFrame::NONE);
2909 CallRuntime(Runtime::kAbort, 1);
2910 } else {
2911 CallRuntime(Runtime::kAbort, 1);
2912 }
2913 // will not return here
2914 if (is_const_pool_blocked()) {
2915 // If the calling code cares about the exact number of
2916 // instructions generated, we insert padding here to keep the size
2917 // of the Abort macro constant.
2918 static const int kExpectedAbortInstructions = 7;
2919 int abort_instructions = InstructionsGeneratedSince(&abort_start);
2920 ASSERT(abort_instructions <= kExpectedAbortInstructions);
2921 while (abort_instructions++ < kExpectedAbortInstructions) {
2922 nop();
2923 }
2924 }
2925 }
2926
2927
LoadContext(Register dst,int context_chain_length)2928 void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
2929 if (context_chain_length > 0) {
2930 // Move up the chain of contexts to the context containing the slot.
2931 ldr(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX)));
2932 for (int i = 1; i < context_chain_length; i++) {
2933 ldr(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX)));
2934 }
2935 } else {
2936 // Slot is in the current function context. Move it into the
2937 // destination register in case we store into it (the write barrier
2938 // cannot be allowed to destroy the context in esi).
2939 mov(dst, cp);
2940 }
2941 }
2942
2943
LoadTransitionedArrayMapConditional(ElementsKind expected_kind,ElementsKind transitioned_kind,Register map_in_out,Register scratch,Label * no_map_match)2944 void MacroAssembler::LoadTransitionedArrayMapConditional(
2945 ElementsKind expected_kind,
2946 ElementsKind transitioned_kind,
2947 Register map_in_out,
2948 Register scratch,
2949 Label* no_map_match) {
2950 // Load the global or builtins object from the current context.
2951 ldr(scratch,
2952 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2953 ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
2954
2955 // Check that the function's map is the same as the expected cached map.
2956 ldr(scratch,
2957 MemOperand(scratch,
2958 Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX)));
2959 size_t offset = expected_kind * kPointerSize +
2960 FixedArrayBase::kHeaderSize;
2961 ldr(ip, FieldMemOperand(scratch, offset));
2962 cmp(map_in_out, ip);
2963 b(ne, no_map_match);
2964
2965 // Use the transitioned cached map.
2966 offset = transitioned_kind * kPointerSize +
2967 FixedArrayBase::kHeaderSize;
2968 ldr(map_in_out, FieldMemOperand(scratch, offset));
2969 }
2970
2971
LoadGlobalFunction(int index,Register function)2972 void MacroAssembler::LoadGlobalFunction(int index, Register function) {
2973 // Load the global or builtins object from the current context.
2974 ldr(function,
2975 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
2976 // Load the native context from the global or builtins object.
2977 ldr(function, FieldMemOperand(function,
2978 GlobalObject::kNativeContextOffset));
2979 // Load the function from the native context.
2980 ldr(function, MemOperand(function, Context::SlotOffset(index)));
2981 }
2982
2983
LoadGlobalFunctionInitialMap(Register function,Register map,Register scratch)2984 void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
2985 Register map,
2986 Register scratch) {
2987 // Load the initial map. The global functions all have initial maps.
2988 ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2989 if (emit_debug_code()) {
2990 Label ok, fail;
2991 CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK);
2992 b(&ok);
2993 bind(&fail);
2994 Abort(kGlobalFunctionsMustHaveInitialMap);
2995 bind(&ok);
2996 }
2997 }
2998
2999
JumpIfNotPowerOfTwoOrZero(Register reg,Register scratch,Label * not_power_of_two_or_zero)3000 void MacroAssembler::JumpIfNotPowerOfTwoOrZero(
3001 Register reg,
3002 Register scratch,
3003 Label* not_power_of_two_or_zero) {
3004 sub(scratch, reg, Operand(1), SetCC);
3005 b(mi, not_power_of_two_or_zero);
3006 tst(scratch, reg);
3007 b(ne, not_power_of_two_or_zero);
3008 }
3009
3010
JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,Register scratch,Label * zero_and_neg,Label * not_power_of_two)3011 void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg(
3012 Register reg,
3013 Register scratch,
3014 Label* zero_and_neg,
3015 Label* not_power_of_two) {
3016 sub(scratch, reg, Operand(1), SetCC);
3017 b(mi, zero_and_neg);
3018 tst(scratch, reg);
3019 b(ne, not_power_of_two);
3020 }
3021
3022
JumpIfNotBothSmi(Register reg1,Register reg2,Label * on_not_both_smi)3023 void MacroAssembler::JumpIfNotBothSmi(Register reg1,
3024 Register reg2,
3025 Label* on_not_both_smi) {
3026 STATIC_ASSERT(kSmiTag == 0);
3027 tst(reg1, Operand(kSmiTagMask));
3028 tst(reg2, Operand(kSmiTagMask), eq);
3029 b(ne, on_not_both_smi);
3030 }
3031
3032
UntagAndJumpIfSmi(Register dst,Register src,Label * smi_case)3033 void MacroAssembler::UntagAndJumpIfSmi(
3034 Register dst, Register src, Label* smi_case) {
3035 STATIC_ASSERT(kSmiTag == 0);
3036 SmiUntag(dst, src, SetCC);
3037 b(cc, smi_case); // Shifter carry is not set for a smi.
3038 }
3039
3040
UntagAndJumpIfNotSmi(Register dst,Register src,Label * non_smi_case)3041 void MacroAssembler::UntagAndJumpIfNotSmi(
3042 Register dst, Register src, Label* non_smi_case) {
3043 STATIC_ASSERT(kSmiTag == 0);
3044 SmiUntag(dst, src, SetCC);
3045 b(cs, non_smi_case); // Shifter carry is set for a non-smi.
3046 }
3047
3048
JumpIfEitherSmi(Register reg1,Register reg2,Label * on_either_smi)3049 void MacroAssembler::JumpIfEitherSmi(Register reg1,
3050 Register reg2,
3051 Label* on_either_smi) {
3052 STATIC_ASSERT(kSmiTag == 0);
3053 tst(reg1, Operand(kSmiTagMask));
3054 tst(reg2, Operand(kSmiTagMask), ne);
3055 b(eq, on_either_smi);
3056 }
3057
3058
AssertNotSmi(Register object)3059 void MacroAssembler::AssertNotSmi(Register object) {
3060 if (emit_debug_code()) {
3061 STATIC_ASSERT(kSmiTag == 0);
3062 tst(object, Operand(kSmiTagMask));
3063 Check(ne, kOperandIsASmi);
3064 }
3065 }
3066
3067
AssertSmi(Register object)3068 void MacroAssembler::AssertSmi(Register object) {
3069 if (emit_debug_code()) {
3070 STATIC_ASSERT(kSmiTag == 0);
3071 tst(object, Operand(kSmiTagMask));
3072 Check(eq, kOperandIsNotSmi);
3073 }
3074 }
3075
3076
AssertString(Register object)3077 void MacroAssembler::AssertString(Register object) {
3078 if (emit_debug_code()) {
3079 STATIC_ASSERT(kSmiTag == 0);
3080 tst(object, Operand(kSmiTagMask));
3081 Check(ne, kOperandIsASmiAndNotAString);
3082 push(object);
3083 ldr(object, FieldMemOperand(object, HeapObject::kMapOffset));
3084 CompareInstanceType(object, object, FIRST_NONSTRING_TYPE);
3085 pop(object);
3086 Check(lo, kOperandIsNotAString);
3087 }
3088 }
3089
3090
AssertName(Register object)3091 void MacroAssembler::AssertName(Register object) {
3092 if (emit_debug_code()) {
3093 STATIC_ASSERT(kSmiTag == 0);
3094 tst(object, Operand(kSmiTagMask));
3095 Check(ne, kOperandIsASmiAndNotAName);
3096 push(object);
3097 ldr(object, FieldMemOperand(object, HeapObject::kMapOffset));
3098 CompareInstanceType(object, object, LAST_NAME_TYPE);
3099 pop(object);
3100 Check(le, kOperandIsNotAName);
3101 }
3102 }
3103
3104
AssertUndefinedOrAllocationSite(Register object,Register scratch)3105 void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
3106 Register scratch) {
3107 if (emit_debug_code()) {
3108 Label done_checking;
3109 AssertNotSmi(object);
3110 CompareRoot(object, Heap::kUndefinedValueRootIndex);
3111 b(eq, &done_checking);
3112 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
3113 CompareRoot(scratch, Heap::kAllocationSiteMapRootIndex);
3114 Assert(eq, kExpectedUndefinedOrCell);
3115 bind(&done_checking);
3116 }
3117 }
3118
3119
AssertIsRoot(Register reg,Heap::RootListIndex index)3120 void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) {
3121 if (emit_debug_code()) {
3122 CompareRoot(reg, index);
3123 Check(eq, kHeapNumberMapRegisterClobbered);
3124 }
3125 }
3126
3127
JumpIfNotHeapNumber(Register object,Register heap_number_map,Register scratch,Label * on_not_heap_number)3128 void MacroAssembler::JumpIfNotHeapNumber(Register object,
3129 Register heap_number_map,
3130 Register scratch,
3131 Label* on_not_heap_number) {
3132 ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
3133 AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
3134 cmp(scratch, heap_number_map);
3135 b(ne, on_not_heap_number);
3136 }
3137
3138
LookupNumberStringCache(Register object,Register result,Register scratch1,Register scratch2,Register scratch3,Label * not_found)3139 void MacroAssembler::LookupNumberStringCache(Register object,
3140 Register result,
3141 Register scratch1,
3142 Register scratch2,
3143 Register scratch3,
3144 Label* not_found) {
3145 // Use of registers. Register result is used as a temporary.
3146 Register number_string_cache = result;
3147 Register mask = scratch3;
3148
3149 // Load the number string cache.
3150 LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex);
3151
3152 // Make the hash mask from the length of the number string cache. It
3153 // contains two elements (number and string) for each cache entry.
3154 ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset));
3155 // Divide length by two (length is a smi).
3156 mov(mask, Operand(mask, ASR, kSmiTagSize + 1));
3157 sub(mask, mask, Operand(1)); // Make mask.
3158
3159 // Calculate the entry in the number string cache. The hash value in the
3160 // number string cache for smis is just the smi value, and the hash for
3161 // doubles is the xor of the upper and lower words. See
3162 // Heap::GetNumberStringCache.
3163 Label is_smi;
3164 Label load_result_from_cache;
3165 JumpIfSmi(object, &is_smi);
3166 CheckMap(object,
3167 scratch1,
3168 Heap::kHeapNumberMapRootIndex,
3169 not_found,
3170 DONT_DO_SMI_CHECK);
3171
3172 STATIC_ASSERT(8 == kDoubleSize);
3173 add(scratch1,
3174 object,
3175 Operand(HeapNumber::kValueOffset - kHeapObjectTag));
3176 ldm(ia, scratch1, scratch1.bit() | scratch2.bit());
3177 eor(scratch1, scratch1, Operand(scratch2));
3178 and_(scratch1, scratch1, Operand(mask));
3179
3180 // Calculate address of entry in string cache: each entry consists
3181 // of two pointer sized fields.
3182 add(scratch1,
3183 number_string_cache,
3184 Operand(scratch1, LSL, kPointerSizeLog2 + 1));
3185
3186 Register probe = mask;
3187 ldr(probe, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
3188 JumpIfSmi(probe, not_found);
3189 sub(scratch2, object, Operand(kHeapObjectTag));
3190 vldr(d0, scratch2, HeapNumber::kValueOffset);
3191 sub(probe, probe, Operand(kHeapObjectTag));
3192 vldr(d1, probe, HeapNumber::kValueOffset);
3193 VFPCompareAndSetFlags(d0, d1);
3194 b(ne, not_found); // The cache did not contain this value.
3195 b(&load_result_from_cache);
3196
3197 bind(&is_smi);
3198 Register scratch = scratch1;
3199 and_(scratch, mask, Operand(object, ASR, 1));
3200 // Calculate address of entry in string cache: each entry consists
3201 // of two pointer sized fields.
3202 add(scratch,
3203 number_string_cache,
3204 Operand(scratch, LSL, kPointerSizeLog2 + 1));
3205
3206 // Check if the entry is the smi we are looking for.
3207 ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3208 cmp(object, probe);
3209 b(ne, not_found);
3210
3211 // Get the result from the cache.
3212 bind(&load_result_from_cache);
3213 ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize));
3214 IncrementCounter(isolate()->counters()->number_to_string_native(),
3215 1,
3216 scratch1,
3217 scratch2);
3218 }
3219
3220
JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,Register second,Register scratch1,Register scratch2,Label * failure)3221 void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings(
3222 Register first,
3223 Register second,
3224 Register scratch1,
3225 Register scratch2,
3226 Label* failure) {
3227 // Test that both first and second are sequential ASCII strings.
3228 // Assume that they are non-smis.
3229 ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
3230 ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
3231 ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3232 ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
3233
3234 JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1,
3235 scratch2,
3236 scratch1,
3237 scratch2,
3238 failure);
3239 }
3240
JumpIfNotBothSequentialAsciiStrings(Register first,Register second,Register scratch1,Register scratch2,Label * failure)3241 void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first,
3242 Register second,
3243 Register scratch1,
3244 Register scratch2,
3245 Label* failure) {
3246 // Check that neither is a smi.
3247 and_(scratch1, first, Operand(second));
3248 JumpIfSmi(scratch1, failure);
3249 JumpIfNonSmisNotBothSequentialAsciiStrings(first,
3250 second,
3251 scratch1,
3252 scratch2,
3253 failure);
3254 }
3255
3256
JumpIfNotUniqueName(Register reg,Label * not_unique_name)3257 void MacroAssembler::JumpIfNotUniqueName(Register reg,
3258 Label* not_unique_name) {
3259 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3260 Label succeed;
3261 tst(reg, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3262 b(eq, &succeed);
3263 cmp(reg, Operand(SYMBOL_TYPE));
3264 b(ne, not_unique_name);
3265
3266 bind(&succeed);
3267 }
3268
3269
3270 // Allocates a heap number or jumps to the need_gc label if the young space
3271 // is full and a scavenge is needed.
AllocateHeapNumber(Register result,Register scratch1,Register scratch2,Register heap_number_map,Label * gc_required,TaggingMode tagging_mode)3272 void MacroAssembler::AllocateHeapNumber(Register result,
3273 Register scratch1,
3274 Register scratch2,
3275 Register heap_number_map,
3276 Label* gc_required,
3277 TaggingMode tagging_mode) {
3278 // Allocate an object in the heap for the heap number and tag it as a heap
3279 // object.
3280 Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required,
3281 tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS);
3282
3283 // Store heap number map in the allocated object.
3284 AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
3285 if (tagging_mode == TAG_RESULT) {
3286 str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
3287 } else {
3288 str(heap_number_map, MemOperand(result, HeapObject::kMapOffset));
3289 }
3290 }
3291
3292
AllocateHeapNumberWithValue(Register result,DwVfpRegister value,Register scratch1,Register scratch2,Register heap_number_map,Label * gc_required)3293 void MacroAssembler::AllocateHeapNumberWithValue(Register result,
3294 DwVfpRegister value,
3295 Register scratch1,
3296 Register scratch2,
3297 Register heap_number_map,
3298 Label* gc_required) {
3299 AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required);
3300 sub(scratch1, result, Operand(kHeapObjectTag));
3301 vstr(value, scratch1, HeapNumber::kValueOffset);
3302 }
3303
3304
3305 // Copies a fixed number of fields of heap objects from src to dst.
CopyFields(Register dst,Register src,LowDwVfpRegister double_scratch,int field_count)3306 void MacroAssembler::CopyFields(Register dst,
3307 Register src,
3308 LowDwVfpRegister double_scratch,
3309 int field_count) {
3310 int double_count = field_count / (DwVfpRegister::kSizeInBytes / kPointerSize);
3311 for (int i = 0; i < double_count; i++) {
3312 vldr(double_scratch, FieldMemOperand(src, i * DwVfpRegister::kSizeInBytes));
3313 vstr(double_scratch, FieldMemOperand(dst, i * DwVfpRegister::kSizeInBytes));
3314 }
3315
3316 STATIC_ASSERT(SwVfpRegister::kSizeInBytes == kPointerSize);
3317 STATIC_ASSERT(2 * SwVfpRegister::kSizeInBytes == DwVfpRegister::kSizeInBytes);
3318
3319 int remain = field_count % (DwVfpRegister::kSizeInBytes / kPointerSize);
3320 if (remain != 0) {
3321 vldr(double_scratch.low(),
3322 FieldMemOperand(src, (field_count - 1) * kPointerSize));
3323 vstr(double_scratch.low(),
3324 FieldMemOperand(dst, (field_count - 1) * kPointerSize));
3325 }
3326 }
3327
3328
CopyBytes(Register src,Register dst,Register length,Register scratch)3329 void MacroAssembler::CopyBytes(Register src,
3330 Register dst,
3331 Register length,
3332 Register scratch) {
3333 Label align_loop_1, word_loop, byte_loop, byte_loop_1, done;
3334
3335 // Align src before copying in word size chunks.
3336 cmp(length, Operand(kPointerSize));
3337 b(le, &byte_loop);
3338
3339 bind(&align_loop_1);
3340 tst(src, Operand(kPointerSize - 1));
3341 b(eq, &word_loop);
3342 ldrb(scratch, MemOperand(src, 1, PostIndex));
3343 strb(scratch, MemOperand(dst, 1, PostIndex));
3344 sub(length, length, Operand(1), SetCC);
3345 b(&align_loop_1);
3346 // Copy bytes in word size chunks.
3347 bind(&word_loop);
3348 if (emit_debug_code()) {
3349 tst(src, Operand(kPointerSize - 1));
3350 Assert(eq, kExpectingAlignmentForCopyBytes);
3351 }
3352 cmp(length, Operand(kPointerSize));
3353 b(lt, &byte_loop);
3354 ldr(scratch, MemOperand(src, kPointerSize, PostIndex));
3355 if (CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) {
3356 str(scratch, MemOperand(dst, kPointerSize, PostIndex));
3357 } else {
3358 strb(scratch, MemOperand(dst, 1, PostIndex));
3359 mov(scratch, Operand(scratch, LSR, 8));
3360 strb(scratch, MemOperand(dst, 1, PostIndex));
3361 mov(scratch, Operand(scratch, LSR, 8));
3362 strb(scratch, MemOperand(dst, 1, PostIndex));
3363 mov(scratch, Operand(scratch, LSR, 8));
3364 strb(scratch, MemOperand(dst, 1, PostIndex));
3365 }
3366 sub(length, length, Operand(kPointerSize));
3367 b(&word_loop);
3368
3369 // Copy the last bytes if any left.
3370 bind(&byte_loop);
3371 cmp(length, Operand::Zero());
3372 b(eq, &done);
3373 bind(&byte_loop_1);
3374 ldrb(scratch, MemOperand(src, 1, PostIndex));
3375 strb(scratch, MemOperand(dst, 1, PostIndex));
3376 sub(length, length, Operand(1), SetCC);
3377 b(ne, &byte_loop_1);
3378 bind(&done);
3379 }
3380
3381
InitializeFieldsWithFiller(Register start_offset,Register end_offset,Register filler)3382 void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
3383 Register end_offset,
3384 Register filler) {
3385 Label loop, entry;
3386 b(&entry);
3387 bind(&loop);
3388 str(filler, MemOperand(start_offset, kPointerSize, PostIndex));
3389 bind(&entry);
3390 cmp(start_offset, end_offset);
3391 b(lt, &loop);
3392 }
3393
3394
CheckFor32DRegs(Register scratch)3395 void MacroAssembler::CheckFor32DRegs(Register scratch) {
3396 mov(scratch, Operand(ExternalReference::cpu_features()));
3397 ldr(scratch, MemOperand(scratch));
3398 tst(scratch, Operand(1u << VFP32DREGS));
3399 }
3400
3401
SaveFPRegs(Register location,Register scratch)3402 void MacroAssembler::SaveFPRegs(Register location, Register scratch) {
3403 CheckFor32DRegs(scratch);
3404 vstm(db_w, location, d16, d31, ne);
3405 sub(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
3406 vstm(db_w, location, d0, d15);
3407 }
3408
3409
RestoreFPRegs(Register location,Register scratch)3410 void MacroAssembler::RestoreFPRegs(Register location, Register scratch) {
3411 CheckFor32DRegs(scratch);
3412 vldm(ia_w, location, d0, d15);
3413 vldm(ia_w, location, d16, d31, ne);
3414 add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq);
3415 }
3416
3417
JumpIfBothInstanceTypesAreNotSequentialAscii(Register first,Register second,Register scratch1,Register scratch2,Label * failure)3418 void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii(
3419 Register first,
3420 Register second,
3421 Register scratch1,
3422 Register scratch2,
3423 Label* failure) {
3424 const int kFlatAsciiStringMask =
3425 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
3426 const int kFlatAsciiStringTag =
3427 kStringTag | kOneByteStringTag | kSeqStringTag;
3428 and_(scratch1, first, Operand(kFlatAsciiStringMask));
3429 and_(scratch2, second, Operand(kFlatAsciiStringMask));
3430 cmp(scratch1, Operand(kFlatAsciiStringTag));
3431 // Ignore second test if first test failed.
3432 cmp(scratch2, Operand(kFlatAsciiStringTag), eq);
3433 b(ne, failure);
3434 }
3435
3436
JumpIfInstanceTypeIsNotSequentialAscii(Register type,Register scratch,Label * failure)3437 void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type,
3438 Register scratch,
3439 Label* failure) {
3440 const int kFlatAsciiStringMask =
3441 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
3442 const int kFlatAsciiStringTag =
3443 kStringTag | kOneByteStringTag | kSeqStringTag;
3444 and_(scratch, type, Operand(kFlatAsciiStringMask));
3445 cmp(scratch, Operand(kFlatAsciiStringTag));
3446 b(ne, failure);
3447 }
3448
3449 static const int kRegisterPassedArguments = 4;
3450
3451
CalculateStackPassedWords(int num_reg_arguments,int num_double_arguments)3452 int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments,
3453 int num_double_arguments) {
3454 int stack_passed_words = 0;
3455 if (use_eabi_hardfloat()) {
3456 // In the hard floating point calling convention, we can use
3457 // all double registers to pass doubles.
3458 if (num_double_arguments > DoubleRegister::NumRegisters()) {
3459 stack_passed_words +=
3460 2 * (num_double_arguments - DoubleRegister::NumRegisters());
3461 }
3462 } else {
3463 // In the soft floating point calling convention, every double
3464 // argument is passed using two registers.
3465 num_reg_arguments += 2 * num_double_arguments;
3466 }
3467 // Up to four simple arguments are passed in registers r0..r3.
3468 if (num_reg_arguments > kRegisterPassedArguments) {
3469 stack_passed_words += num_reg_arguments - kRegisterPassedArguments;
3470 }
3471 return stack_passed_words;
3472 }
3473
3474
EmitSeqStringSetCharCheck(Register string,Register index,Register value,uint32_t encoding_mask)3475 void MacroAssembler::EmitSeqStringSetCharCheck(Register string,
3476 Register index,
3477 Register value,
3478 uint32_t encoding_mask) {
3479 Label is_object;
3480 SmiTst(string);
3481 Check(ne, kNonObject);
3482
3483 ldr(ip, FieldMemOperand(string, HeapObject::kMapOffset));
3484 ldrb(ip, FieldMemOperand(ip, Map::kInstanceTypeOffset));
3485
3486 and_(ip, ip, Operand(kStringRepresentationMask | kStringEncodingMask));
3487 cmp(ip, Operand(encoding_mask));
3488 Check(eq, kUnexpectedStringType);
3489
3490 // The index is assumed to be untagged coming in, tag it to compare with the
3491 // string length without using a temp register, it is restored at the end of
3492 // this function.
3493 Label index_tag_ok, index_tag_bad;
3494 TrySmiTag(index, index, &index_tag_bad);
3495 b(&index_tag_ok);
3496 bind(&index_tag_bad);
3497 Abort(kIndexIsTooLarge);
3498 bind(&index_tag_ok);
3499
3500 ldr(ip, FieldMemOperand(string, String::kLengthOffset));
3501 cmp(index, ip);
3502 Check(lt, kIndexIsTooLarge);
3503
3504 cmp(index, Operand(Smi::FromInt(0)));
3505 Check(ge, kIndexIsNegative);
3506
3507 SmiUntag(index, index);
3508 }
3509
3510
PrepareCallCFunction(int num_reg_arguments,int num_double_arguments,Register scratch)3511 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
3512 int num_double_arguments,
3513 Register scratch) {
3514 int frame_alignment = ActivationFrameAlignment();
3515 int stack_passed_arguments = CalculateStackPassedWords(
3516 num_reg_arguments, num_double_arguments);
3517 if (frame_alignment > kPointerSize) {
3518 // Make stack end at alignment and make room for num_arguments - 4 words
3519 // and the original value of sp.
3520 mov(scratch, sp);
3521 sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
3522 ASSERT(IsPowerOf2(frame_alignment));
3523 and_(sp, sp, Operand(-frame_alignment));
3524 str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
3525 } else {
3526 sub(sp, sp, Operand(stack_passed_arguments * kPointerSize));
3527 }
3528 }
3529
3530
PrepareCallCFunction(int num_reg_arguments,Register scratch)3531 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
3532 Register scratch) {
3533 PrepareCallCFunction(num_reg_arguments, 0, scratch);
3534 }
3535
3536
MovToFloatParameter(DwVfpRegister src)3537 void MacroAssembler::MovToFloatParameter(DwVfpRegister src) {
3538 ASSERT(src.is(d0));
3539 if (!use_eabi_hardfloat()) {
3540 vmov(r0, r1, src);
3541 }
3542 }
3543
3544
3545 // On ARM this is just a synonym to make the purpose clear.
MovToFloatResult(DwVfpRegister src)3546 void MacroAssembler::MovToFloatResult(DwVfpRegister src) {
3547 MovToFloatParameter(src);
3548 }
3549
3550
MovToFloatParameters(DwVfpRegister src1,DwVfpRegister src2)3551 void MacroAssembler::MovToFloatParameters(DwVfpRegister src1,
3552 DwVfpRegister src2) {
3553 ASSERT(src1.is(d0));
3554 ASSERT(src2.is(d1));
3555 if (!use_eabi_hardfloat()) {
3556 vmov(r0, r1, src1);
3557 vmov(r2, r3, src2);
3558 }
3559 }
3560
3561
CallCFunction(ExternalReference function,int num_reg_arguments,int num_double_arguments)3562 void MacroAssembler::CallCFunction(ExternalReference function,
3563 int num_reg_arguments,
3564 int num_double_arguments) {
3565 mov(ip, Operand(function));
3566 CallCFunctionHelper(ip, num_reg_arguments, num_double_arguments);
3567 }
3568
3569
CallCFunction(Register function,int num_reg_arguments,int num_double_arguments)3570 void MacroAssembler::CallCFunction(Register function,
3571 int num_reg_arguments,
3572 int num_double_arguments) {
3573 CallCFunctionHelper(function, num_reg_arguments, num_double_arguments);
3574 }
3575
3576
CallCFunction(ExternalReference function,int num_arguments)3577 void MacroAssembler::CallCFunction(ExternalReference function,
3578 int num_arguments) {
3579 CallCFunction(function, num_arguments, 0);
3580 }
3581
3582
CallCFunction(Register function,int num_arguments)3583 void MacroAssembler::CallCFunction(Register function,
3584 int num_arguments) {
3585 CallCFunction(function, num_arguments, 0);
3586 }
3587
3588
CallCFunctionHelper(Register function,int num_reg_arguments,int num_double_arguments)3589 void MacroAssembler::CallCFunctionHelper(Register function,
3590 int num_reg_arguments,
3591 int num_double_arguments) {
3592 ASSERT(has_frame());
3593 // Make sure that the stack is aligned before calling a C function unless
3594 // running in the simulator. The simulator has its own alignment check which
3595 // provides more information.
3596 #if V8_HOST_ARCH_ARM
3597 if (emit_debug_code()) {
3598 int frame_alignment = OS::ActivationFrameAlignment();
3599 int frame_alignment_mask = frame_alignment - 1;
3600 if (frame_alignment > kPointerSize) {
3601 ASSERT(IsPowerOf2(frame_alignment));
3602 Label alignment_as_expected;
3603 tst(sp, Operand(frame_alignment_mask));
3604 b(eq, &alignment_as_expected);
3605 // Don't use Check here, as it will call Runtime_Abort possibly
3606 // re-entering here.
3607 stop("Unexpected alignment");
3608 bind(&alignment_as_expected);
3609 }
3610 }
3611 #endif
3612
3613 // Just call directly. The function called cannot cause a GC, or
3614 // allow preemption, so the return address in the link register
3615 // stays correct.
3616 Call(function);
3617 int stack_passed_arguments = CalculateStackPassedWords(
3618 num_reg_arguments, num_double_arguments);
3619 if (ActivationFrameAlignment() > kPointerSize) {
3620 ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
3621 } else {
3622 add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize)));
3623 }
3624 }
3625
3626
GetRelocatedValueLocation(Register ldr_location,Register result)3627 void MacroAssembler::GetRelocatedValueLocation(Register ldr_location,
3628 Register result) {
3629 const uint32_t kLdrOffsetMask = (1 << 12) - 1;
3630 ldr(result, MemOperand(ldr_location));
3631 if (emit_debug_code()) {
3632 // Check that the instruction is a ldr reg, [<pc or pp> + offset] .
3633 if (FLAG_enable_ool_constant_pool) {
3634 and_(result, result, Operand(kLdrPpPattern));
3635 cmp(result, Operand(kLdrPpPattern));
3636 Check(eq, kTheInstructionToPatchShouldBeALoadFromPp);
3637 } else {
3638 and_(result, result, Operand(kLdrPCPattern));
3639 cmp(result, Operand(kLdrPCPattern));
3640 Check(eq, kTheInstructionToPatchShouldBeALoadFromPc);
3641 }
3642 // Result was clobbered. Restore it.
3643 ldr(result, MemOperand(ldr_location));
3644 }
3645 // Get the address of the constant.
3646 and_(result, result, Operand(kLdrOffsetMask));
3647 if (FLAG_enable_ool_constant_pool) {
3648 add(result, pp, Operand(result));
3649 } else {
3650 add(result, ldr_location, Operand(result));
3651 add(result, result, Operand(Instruction::kPCReadOffset));
3652 }
3653 }
3654
3655
CheckPageFlag(Register object,Register scratch,int mask,Condition cc,Label * condition_met)3656 void MacroAssembler::CheckPageFlag(
3657 Register object,
3658 Register scratch,
3659 int mask,
3660 Condition cc,
3661 Label* condition_met) {
3662 Bfc(scratch, object, 0, kPageSizeBits);
3663 ldr(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset));
3664 tst(scratch, Operand(mask));
3665 b(cc, condition_met);
3666 }
3667
3668
CheckMapDeprecated(Handle<Map> map,Register scratch,Label * if_deprecated)3669 void MacroAssembler::CheckMapDeprecated(Handle<Map> map,
3670 Register scratch,
3671 Label* if_deprecated) {
3672 if (map->CanBeDeprecated()) {
3673 mov(scratch, Operand(map));
3674 ldr(scratch, FieldMemOperand(scratch, Map::kBitField3Offset));
3675 tst(scratch, Operand(Map::Deprecated::kMask));
3676 b(ne, if_deprecated);
3677 }
3678 }
3679
3680
JumpIfBlack(Register object,Register scratch0,Register scratch1,Label * on_black)3681 void MacroAssembler::JumpIfBlack(Register object,
3682 Register scratch0,
3683 Register scratch1,
3684 Label* on_black) {
3685 HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern.
3686 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0);
3687 }
3688
3689
HasColor(Register object,Register bitmap_scratch,Register mask_scratch,Label * has_color,int first_bit,int second_bit)3690 void MacroAssembler::HasColor(Register object,
3691 Register bitmap_scratch,
3692 Register mask_scratch,
3693 Label* has_color,
3694 int first_bit,
3695 int second_bit) {
3696 ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, no_reg));
3697
3698 GetMarkBits(object, bitmap_scratch, mask_scratch);
3699
3700 Label other_color, word_boundary;
3701 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3702 tst(ip, Operand(mask_scratch));
3703 b(first_bit == 1 ? eq : ne, &other_color);
3704 // Shift left 1 by adding.
3705 add(mask_scratch, mask_scratch, Operand(mask_scratch), SetCC);
3706 b(eq, &word_boundary);
3707 tst(ip, Operand(mask_scratch));
3708 b(second_bit == 1 ? ne : eq, has_color);
3709 jmp(&other_color);
3710
3711 bind(&word_boundary);
3712 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize));
3713 tst(ip, Operand(1));
3714 b(second_bit == 1 ? ne : eq, has_color);
3715 bind(&other_color);
3716 }
3717
3718
3719 // Detect some, but not all, common pointer-free objects. This is used by the
3720 // incremental write barrier which doesn't care about oddballs (they are always
3721 // marked black immediately so this code is not hit).
JumpIfDataObject(Register value,Register scratch,Label * not_data_object)3722 void MacroAssembler::JumpIfDataObject(Register value,
3723 Register scratch,
3724 Label* not_data_object) {
3725 Label is_data_object;
3726 ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
3727 CompareRoot(scratch, Heap::kHeapNumberMapRootIndex);
3728 b(eq, &is_data_object);
3729 ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
3730 ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
3731 // If it's a string and it's not a cons string then it's an object containing
3732 // no GC pointers.
3733 ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
3734 tst(scratch, Operand(kIsIndirectStringMask | kIsNotStringMask));
3735 b(ne, not_data_object);
3736 bind(&is_data_object);
3737 }
3738
3739
GetMarkBits(Register addr_reg,Register bitmap_reg,Register mask_reg)3740 void MacroAssembler::GetMarkBits(Register addr_reg,
3741 Register bitmap_reg,
3742 Register mask_reg) {
3743 ASSERT(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg));
3744 and_(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask));
3745 Ubfx(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2);
3746 const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2;
3747 Ubfx(ip, addr_reg, kLowBits, kPageSizeBits - kLowBits);
3748 add(bitmap_reg, bitmap_reg, Operand(ip, LSL, kPointerSizeLog2));
3749 mov(ip, Operand(1));
3750 mov(mask_reg, Operand(ip, LSL, mask_reg));
3751 }
3752
3753
EnsureNotWhite(Register value,Register bitmap_scratch,Register mask_scratch,Register load_scratch,Label * value_is_white_and_not_data)3754 void MacroAssembler::EnsureNotWhite(
3755 Register value,
3756 Register bitmap_scratch,
3757 Register mask_scratch,
3758 Register load_scratch,
3759 Label* value_is_white_and_not_data) {
3760 ASSERT(!AreAliased(value, bitmap_scratch, mask_scratch, ip));
3761 GetMarkBits(value, bitmap_scratch, mask_scratch);
3762
3763 // If the value is black or grey we don't need to do anything.
3764 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0);
3765 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0);
3766 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0);
3767 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
3768
3769 Label done;
3770
3771 // Since both black and grey have a 1 in the first position and white does
3772 // not have a 1 there we only need to check one bit.
3773 ldr(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3774 tst(mask_scratch, load_scratch);
3775 b(ne, &done);
3776
3777 if (emit_debug_code()) {
3778 // Check for impossible bit pattern.
3779 Label ok;
3780 // LSL may overflow, making the check conservative.
3781 tst(load_scratch, Operand(mask_scratch, LSL, 1));
3782 b(eq, &ok);
3783 stop("Impossible marking bit pattern");
3784 bind(&ok);
3785 }
3786
3787 // Value is white. We check whether it is data that doesn't need scanning.
3788 // Currently only checks for HeapNumber and non-cons strings.
3789 Register map = load_scratch; // Holds map while checking type.
3790 Register length = load_scratch; // Holds length of object after testing type.
3791 Label is_data_object;
3792
3793 // Check for heap-number
3794 ldr(map, FieldMemOperand(value, HeapObject::kMapOffset));
3795 CompareRoot(map, Heap::kHeapNumberMapRootIndex);
3796 mov(length, Operand(HeapNumber::kSize), LeaveCC, eq);
3797 b(eq, &is_data_object);
3798
3799 // Check for strings.
3800 ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
3801 ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
3802 // If it's a string and it's not a cons string then it's an object containing
3803 // no GC pointers.
3804 Register instance_type = load_scratch;
3805 ldrb(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset));
3806 tst(instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask));
3807 b(ne, value_is_white_and_not_data);
3808 // It's a non-indirect (non-cons and non-slice) string.
3809 // If it's external, the length is just ExternalString::kSize.
3810 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2).
3811 // External strings are the only ones with the kExternalStringTag bit
3812 // set.
3813 ASSERT_EQ(0, kSeqStringTag & kExternalStringTag);
3814 ASSERT_EQ(0, kConsStringTag & kExternalStringTag);
3815 tst(instance_type, Operand(kExternalStringTag));
3816 mov(length, Operand(ExternalString::kSize), LeaveCC, ne);
3817 b(ne, &is_data_object);
3818
3819 // Sequential string, either ASCII or UC16.
3820 // For ASCII (char-size of 1) we shift the smi tag away to get the length.
3821 // For UC16 (char-size of 2) we just leave the smi tag in place, thereby
3822 // getting the length multiplied by 2.
3823 ASSERT(kOneByteStringTag == 4 && kStringEncodingMask == 4);
3824 ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
3825 ldr(ip, FieldMemOperand(value, String::kLengthOffset));
3826 tst(instance_type, Operand(kStringEncodingMask));
3827 mov(ip, Operand(ip, LSR, 1), LeaveCC, ne);
3828 add(length, ip, Operand(SeqString::kHeaderSize + kObjectAlignmentMask));
3829 and_(length, length, Operand(~kObjectAlignmentMask));
3830
3831 bind(&is_data_object);
3832 // Value is a data object, and it is white. Mark it black. Since we know
3833 // that the object is white we can make it black by flipping one bit.
3834 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3835 orr(ip, ip, Operand(mask_scratch));
3836 str(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
3837
3838 and_(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask));
3839 ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
3840 add(ip, ip, Operand(length));
3841 str(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
3842
3843 bind(&done);
3844 }
3845
3846
ClampUint8(Register output_reg,Register input_reg)3847 void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) {
3848 Usat(output_reg, 8, Operand(input_reg));
3849 }
3850
3851
ClampDoubleToUint8(Register result_reg,DwVfpRegister input_reg,LowDwVfpRegister double_scratch)3852 void MacroAssembler::ClampDoubleToUint8(Register result_reg,
3853 DwVfpRegister input_reg,
3854 LowDwVfpRegister double_scratch) {
3855 Label done;
3856
3857 // Handle inputs >= 255 (including +infinity).
3858 Vmov(double_scratch, 255.0, result_reg);
3859 mov(result_reg, Operand(255));
3860 VFPCompareAndSetFlags(input_reg, double_scratch);
3861 b(ge, &done);
3862
3863 // For inputs < 255 (including negative) vcvt_u32_f64 with round-to-nearest
3864 // rounding mode will provide the correct result.
3865 vcvt_u32_f64(double_scratch.low(), input_reg, kFPSCRRounding);
3866 vmov(result_reg, double_scratch.low());
3867
3868 bind(&done);
3869 }
3870
3871
LoadInstanceDescriptors(Register map,Register descriptors)3872 void MacroAssembler::LoadInstanceDescriptors(Register map,
3873 Register descriptors) {
3874 ldr(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset));
3875 }
3876
3877
NumberOfOwnDescriptors(Register dst,Register map)3878 void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) {
3879 ldr(dst, FieldMemOperand(map, Map::kBitField3Offset));
3880 DecodeField<Map::NumberOfOwnDescriptorsBits>(dst);
3881 }
3882
3883
EnumLength(Register dst,Register map)3884 void MacroAssembler::EnumLength(Register dst, Register map) {
3885 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0);
3886 ldr(dst, FieldMemOperand(map, Map::kBitField3Offset));
3887 and_(dst, dst, Operand(Map::EnumLengthBits::kMask));
3888 SmiTag(dst);
3889 }
3890
3891
CheckEnumCache(Register null_value,Label * call_runtime)3892 void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) {
3893 Register empty_fixed_array_value = r6;
3894 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex);
3895 Label next, start;
3896 mov(r2, r0);
3897
3898 // Check if the enum length field is properly initialized, indicating that
3899 // there is an enum cache.
3900 ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset));
3901
3902 EnumLength(r3, r1);
3903 cmp(r3, Operand(Smi::FromInt(kInvalidEnumCacheSentinel)));
3904 b(eq, call_runtime);
3905
3906 jmp(&start);
3907
3908 bind(&next);
3909 ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset));
3910
3911 // For all objects but the receiver, check that the cache is empty.
3912 EnumLength(r3, r1);
3913 cmp(r3, Operand(Smi::FromInt(0)));
3914 b(ne, call_runtime);
3915
3916 bind(&start);
3917
3918 // Check that there are no elements. Register r2 contains the current JS
3919 // object we've reached through the prototype chain.
3920 Label no_elements;
3921 ldr(r2, FieldMemOperand(r2, JSObject::kElementsOffset));
3922 cmp(r2, empty_fixed_array_value);
3923 b(eq, &no_elements);
3924
3925 // Second chance, the object may be using the empty slow element dictionary.
3926 CompareRoot(r2, Heap::kEmptySlowElementDictionaryRootIndex);
3927 b(ne, call_runtime);
3928
3929 bind(&no_elements);
3930 ldr(r2, FieldMemOperand(r1, Map::kPrototypeOffset));
3931 cmp(r2, null_value);
3932 b(ne, &next);
3933 }
3934
3935
TestJSArrayForAllocationMemento(Register receiver_reg,Register scratch_reg,Label * no_memento_found)3936 void MacroAssembler::TestJSArrayForAllocationMemento(
3937 Register receiver_reg,
3938 Register scratch_reg,
3939 Label* no_memento_found) {
3940 ExternalReference new_space_start =
3941 ExternalReference::new_space_start(isolate());
3942 ExternalReference new_space_allocation_top =
3943 ExternalReference::new_space_allocation_top_address(isolate());
3944 add(scratch_reg, receiver_reg,
3945 Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag));
3946 cmp(scratch_reg, Operand(new_space_start));
3947 b(lt, no_memento_found);
3948 mov(ip, Operand(new_space_allocation_top));
3949 ldr(ip, MemOperand(ip));
3950 cmp(scratch_reg, ip);
3951 b(gt, no_memento_found);
3952 ldr(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize));
3953 cmp(scratch_reg,
3954 Operand(isolate()->factory()->allocation_memento_map()));
3955 }
3956
3957
GetRegisterThatIsNotOneOf(Register reg1,Register reg2,Register reg3,Register reg4,Register reg5,Register reg6)3958 Register GetRegisterThatIsNotOneOf(Register reg1,
3959 Register reg2,
3960 Register reg3,
3961 Register reg4,
3962 Register reg5,
3963 Register reg6) {
3964 RegList regs = 0;
3965 if (reg1.is_valid()) regs |= reg1.bit();
3966 if (reg2.is_valid()) regs |= reg2.bit();
3967 if (reg3.is_valid()) regs |= reg3.bit();
3968 if (reg4.is_valid()) regs |= reg4.bit();
3969 if (reg5.is_valid()) regs |= reg5.bit();
3970 if (reg6.is_valid()) regs |= reg6.bit();
3971
3972 for (int i = 0; i < Register::NumAllocatableRegisters(); i++) {
3973 Register candidate = Register::FromAllocationIndex(i);
3974 if (regs & candidate.bit()) continue;
3975 return candidate;
3976 }
3977 UNREACHABLE();
3978 return no_reg;
3979 }
3980
3981
JumpIfDictionaryInPrototypeChain(Register object,Register scratch0,Register scratch1,Label * found)3982 void MacroAssembler::JumpIfDictionaryInPrototypeChain(
3983 Register object,
3984 Register scratch0,
3985 Register scratch1,
3986 Label* found) {
3987 ASSERT(!scratch1.is(scratch0));
3988 Factory* factory = isolate()->factory();
3989 Register current = scratch0;
3990 Label loop_again;
3991
3992 // scratch contained elements pointer.
3993 mov(current, object);
3994
3995 // Loop based on the map going up the prototype chain.
3996 bind(&loop_again);
3997 ldr(current, FieldMemOperand(current, HeapObject::kMapOffset));
3998 ldr(scratch1, FieldMemOperand(current, Map::kBitField2Offset));
3999 DecodeField<Map::ElementsKindBits>(scratch1);
4000 cmp(scratch1, Operand(DICTIONARY_ELEMENTS));
4001 b(eq, found);
4002 ldr(current, FieldMemOperand(current, Map::kPrototypeOffset));
4003 cmp(current, Operand(factory->null_value()));
4004 b(ne, &loop_again);
4005 }
4006
4007
4008 #ifdef DEBUG
AreAliased(Register reg1,Register reg2,Register reg3,Register reg4,Register reg5,Register reg6)4009 bool AreAliased(Register reg1,
4010 Register reg2,
4011 Register reg3,
4012 Register reg4,
4013 Register reg5,
4014 Register reg6) {
4015 int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() +
4016 reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid();
4017
4018 RegList regs = 0;
4019 if (reg1.is_valid()) regs |= reg1.bit();
4020 if (reg2.is_valid()) regs |= reg2.bit();
4021 if (reg3.is_valid()) regs |= reg3.bit();
4022 if (reg4.is_valid()) regs |= reg4.bit();
4023 if (reg5.is_valid()) regs |= reg5.bit();
4024 if (reg6.is_valid()) regs |= reg6.bit();
4025 int n_of_non_aliasing_regs = NumRegs(regs);
4026
4027 return n_of_valid_regs != n_of_non_aliasing_regs;
4028 }
4029 #endif
4030
4031
CodePatcher(byte * address,int instructions,FlushICache flush_cache)4032 CodePatcher::CodePatcher(byte* address,
4033 int instructions,
4034 FlushICache flush_cache)
4035 : address_(address),
4036 size_(instructions * Assembler::kInstrSize),
4037 masm_(NULL, address, size_ + Assembler::kGap),
4038 flush_cache_(flush_cache) {
4039 // Create a new macro assembler pointing to the address of the code to patch.
4040 // The size is adjusted with kGap on order for the assembler to generate size
4041 // bytes of instructions without failing with buffer size constraints.
4042 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
4043 }
4044
4045
~CodePatcher()4046 CodePatcher::~CodePatcher() {
4047 // Indicate that code has changed.
4048 if (flush_cache_ == FLUSH) {
4049 CPU::FlushICache(address_, size_);
4050 }
4051
4052 // Check that the code was patched as expected.
4053 ASSERT(masm_.pc_ == address_ + size_);
4054 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
4055 }
4056
4057
Emit(Instr instr)4058 void CodePatcher::Emit(Instr instr) {
4059 masm()->emit(instr);
4060 }
4061
4062
Emit(Address addr)4063 void CodePatcher::Emit(Address addr) {
4064 masm()->emit(reinterpret_cast<Instr>(addr));
4065 }
4066
4067
EmitCondition(Condition cond)4068 void CodePatcher::EmitCondition(Condition cond) {
4069 Instr instr = Assembler::instr_at(masm_.pc_);
4070 instr = (instr & ~kCondMask) | cond;
4071 masm_.emit(instr);
4072 }
4073
4074
TruncatingDiv(Register result,Register dividend,int32_t divisor)4075 void MacroAssembler::TruncatingDiv(Register result,
4076 Register dividend,
4077 int32_t divisor) {
4078 ASSERT(!dividend.is(result));
4079 ASSERT(!dividend.is(ip));
4080 ASSERT(!result.is(ip));
4081 MultiplierAndShift ms(divisor);
4082 mov(ip, Operand(ms.multiplier()));
4083 smull(ip, result, dividend, ip);
4084 if (divisor > 0 && ms.multiplier() < 0) {
4085 add(result, result, Operand(dividend));
4086 }
4087 if (divisor < 0 && ms.multiplier() > 0) {
4088 sub(result, result, Operand(dividend));
4089 }
4090 if (ms.shift() > 0) mov(result, Operand(result, ASR, ms.shift()));
4091 add(result, result, Operand(dividend, LSR, 31));
4092 }
4093
4094
4095 } } // namespace v8::internal
4096
4097 #endif // V8_TARGET_ARCH_ARM
4098