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.
5 #include <limits.h> // For LONG_MIN, LONG_MAX.
7 #if V8_TARGET_ARCH_MIPS64
9 #include "src/base/division-by-constant.h"
10 #include "src/bootstrapper.h"
11 #include "src/codegen.h"
12 #include "src/cpu-profiler.h"
13 #include "src/debug/debug.h"
14 #include "src/runtime/runtime.h"
19 MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size)
20 : Assembler(arg_isolate, buffer, size),
21 generating_stub_(false),
23 has_double_zero_reg_set_(false) {
24 if (isolate() != NULL) {
25 code_object_ = Handle<Object>(isolate()->heap()->undefined_value(),
31 void MacroAssembler::Load(Register dst,
32 const MemOperand& src,
34 DCHECK(!r.IsDouble());
37 } else if (r.IsUInteger8()) {
39 } else if (r.IsInteger16()) {
41 } else if (r.IsUInteger16()) {
43 } else if (r.IsInteger32()) {
51 void MacroAssembler::Store(Register src,
52 const MemOperand& dst,
54 DCHECK(!r.IsDouble());
55 if (r.IsInteger8() || r.IsUInteger8()) {
57 } else if (r.IsInteger16() || r.IsUInteger16()) {
59 } else if (r.IsInteger32()) {
62 if (r.IsHeapObject()) {
64 } else if (r.IsSmi()) {
72 void MacroAssembler::LoadRoot(Register destination,
73 Heap::RootListIndex index) {
74 ld(destination, MemOperand(s6, index << kPointerSizeLog2));
78 void MacroAssembler::LoadRoot(Register destination,
79 Heap::RootListIndex index,
81 Register src1, const Operand& src2) {
82 Branch(2, NegateCondition(cond), src1, src2);
83 ld(destination, MemOperand(s6, index << kPointerSizeLog2));
87 void MacroAssembler::StoreRoot(Register source,
88 Heap::RootListIndex index) {
89 DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
90 sd(source, MemOperand(s6, index << kPointerSizeLog2));
94 void MacroAssembler::StoreRoot(Register source,
95 Heap::RootListIndex index,
97 Register src1, const Operand& src2) {
98 DCHECK(Heap::RootCanBeWrittenAfterInitialization(index));
99 Branch(2, NegateCondition(cond), src1, src2);
100 sd(source, MemOperand(s6, index << kPointerSizeLog2));
104 // Push and pop all registers that can hold pointers.
105 void MacroAssembler::PushSafepointRegisters() {
106 // Safepoints expect a block of kNumSafepointRegisters values on the
107 // stack, so adjust the stack for unsaved registers.
108 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
109 DCHECK(num_unsaved >= 0);
110 if (num_unsaved > 0) {
111 Dsubu(sp, sp, Operand(num_unsaved * kPointerSize));
113 MultiPush(kSafepointSavedRegisters);
117 void MacroAssembler::PopSafepointRegisters() {
118 const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
119 MultiPop(kSafepointSavedRegisters);
120 if (num_unsaved > 0) {
121 Daddu(sp, sp, Operand(num_unsaved * kPointerSize));
126 void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) {
127 sd(src, SafepointRegisterSlot(dst));
131 void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) {
132 ld(dst, SafepointRegisterSlot(src));
136 int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
137 // The registers are pushed starting with the highest encoding,
138 // which means that lowest encodings are closest to the stack pointer.
139 return kSafepointRegisterStackIndexMap[reg_code];
143 MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
144 return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
148 MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) {
149 UNIMPLEMENTED_MIPS();
150 // General purpose registers are pushed last on the stack.
151 int doubles_size = FPURegister::NumAllocatableRegisters() * kDoubleSize;
152 int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize;
153 return MemOperand(sp, doubles_size + register_offset);
157 void MacroAssembler::InNewSpace(Register object,
161 DCHECK(cc == eq || cc == ne);
162 And(scratch, object, Operand(ExternalReference::new_space_mask(isolate())));
163 Branch(branch, cc, scratch,
164 Operand(ExternalReference::new_space_start(isolate())));
168 // Clobbers object, dst, value, and ra, if (ra_status == kRAHasBeenSaved)
169 // The register 'object' contains a heap object pointer. The heap object
170 // tag is shifted away.
171 void MacroAssembler::RecordWriteField(
177 SaveFPRegsMode save_fp,
178 RememberedSetAction remembered_set_action,
180 PointersToHereCheck pointers_to_here_check_for_value) {
181 DCHECK(!AreAliased(value, dst, t8, object));
182 // First, check if a write barrier is even needed. The tests below
183 // catch stores of Smis.
186 // Skip barrier if writing a smi.
187 if (smi_check == INLINE_SMI_CHECK) {
188 JumpIfSmi(value, &done);
191 // Although the object register is tagged, the offset is relative to the start
192 // of the object, so so offset must be a multiple of kPointerSize.
193 DCHECK(IsAligned(offset, kPointerSize));
195 Daddu(dst, object, Operand(offset - kHeapObjectTag));
196 if (emit_debug_code()) {
198 And(t8, dst, Operand((1 << kPointerSizeLog2) - 1));
199 Branch(&ok, eq, t8, Operand(zero_reg));
200 stop("Unaligned cell in write barrier");
209 remembered_set_action,
211 pointers_to_here_check_for_value);
215 // Clobber clobbered input registers when running with the debug-code flag
216 // turned on to provoke errors.
217 if (emit_debug_code()) {
218 li(value, Operand(bit_cast<int64_t>(kZapValue + 4)));
219 li(dst, Operand(bit_cast<int64_t>(kZapValue + 8)));
224 // Clobbers object, dst, map, and ra, if (ra_status == kRAHasBeenSaved)
225 void MacroAssembler::RecordWriteForMap(Register object,
229 SaveFPRegsMode fp_mode) {
230 if (emit_debug_code()) {
232 ld(dst, FieldMemOperand(map, HeapObject::kMapOffset));
234 kWrongAddressOrValuePassedToRecordWrite,
236 Operand(isolate()->factory()->meta_map()));
239 if (!FLAG_incremental_marking) {
243 if (emit_debug_code()) {
244 ld(at, FieldMemOperand(object, HeapObject::kMapOffset));
246 kWrongAddressOrValuePassedToRecordWrite,
253 // A single check of the map's pages interesting flag suffices, since it is
254 // only set during incremental collection, and then it's also guaranteed that
255 // the from object's page's interesting flag is also set. This optimization
256 // relies on the fact that maps can never be in new space.
258 map, // Used as scratch.
259 MemoryChunk::kPointersToHereAreInterestingMask,
263 Daddu(dst, object, Operand(HeapObject::kMapOffset - kHeapObjectTag));
264 if (emit_debug_code()) {
266 And(at, dst, Operand((1 << kPointerSizeLog2) - 1));
267 Branch(&ok, eq, at, Operand(zero_reg));
268 stop("Unaligned cell in write barrier");
272 // Record the actual write.
273 if (ra_status == kRAHasNotBeenSaved) {
276 RecordWriteStub stub(isolate(), object, map, dst, OMIT_REMEMBERED_SET,
279 if (ra_status == kRAHasNotBeenSaved) {
285 // Count number of write barriers in generated code.
286 isolate()->counters()->write_barriers_static()->Increment();
287 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, at, dst);
289 // Clobber clobbered registers when running with the debug-code flag
290 // turned on to provoke errors.
291 if (emit_debug_code()) {
292 li(dst, Operand(bit_cast<int64_t>(kZapValue + 12)));
293 li(map, Operand(bit_cast<int64_t>(kZapValue + 16)));
298 // Clobbers object, address, value, and ra, if (ra_status == kRAHasBeenSaved)
299 // The register 'object' contains a heap object pointer. The heap object
300 // tag is shifted away.
301 void MacroAssembler::RecordWrite(
306 SaveFPRegsMode fp_mode,
307 RememberedSetAction remembered_set_action,
309 PointersToHereCheck pointers_to_here_check_for_value) {
310 DCHECK(!AreAliased(object, address, value, t8));
311 DCHECK(!AreAliased(object, address, value, t9));
313 if (emit_debug_code()) {
314 ld(at, MemOperand(address));
316 eq, kWrongAddressOrValuePassedToRecordWrite, at, Operand(value));
319 if (remembered_set_action == OMIT_REMEMBERED_SET &&
320 !FLAG_incremental_marking) {
324 // First, check if a write barrier is even needed. The tests below
325 // catch stores of smis and stores into the young generation.
328 if (smi_check == INLINE_SMI_CHECK) {
329 DCHECK_EQ(0, kSmiTag);
330 JumpIfSmi(value, &done);
333 if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) {
335 value, // Used as scratch.
336 MemoryChunk::kPointersToHereAreInterestingMask,
340 CheckPageFlag(object,
341 value, // Used as scratch.
342 MemoryChunk::kPointersFromHereAreInterestingMask,
346 // Record the actual write.
347 if (ra_status == kRAHasNotBeenSaved) {
350 RecordWriteStub stub(isolate(), object, value, address, remembered_set_action,
353 if (ra_status == kRAHasNotBeenSaved) {
359 // Count number of write barriers in generated code.
360 isolate()->counters()->write_barriers_static()->Increment();
361 IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1, at,
364 // Clobber clobbered registers when running with the debug-code flag
365 // turned on to provoke errors.
366 if (emit_debug_code()) {
367 li(address, Operand(bit_cast<int64_t>(kZapValue + 12)));
368 li(value, Operand(bit_cast<int64_t>(kZapValue + 16)));
373 void MacroAssembler::RememberedSetHelper(Register object, // For debug tests.
376 SaveFPRegsMode fp_mode,
377 RememberedSetFinalAction and_then) {
379 if (emit_debug_code()) {
381 JumpIfNotInNewSpace(object, scratch, &ok);
382 stop("Remembered set pointer is in new space");
385 // Load store buffer top.
386 ExternalReference store_buffer =
387 ExternalReference::store_buffer_top(isolate());
388 li(t8, Operand(store_buffer));
389 ld(scratch, MemOperand(t8));
390 // Store pointer to buffer and increment buffer top.
391 sd(address, MemOperand(scratch));
392 Daddu(scratch, scratch, kPointerSize);
393 // Write back new top of buffer.
394 sd(scratch, MemOperand(t8));
395 // Call stub on end of buffer.
396 // Check for end of buffer.
397 And(t8, scratch, Operand(StoreBuffer::kStoreBufferOverflowBit));
398 DCHECK(!scratch.is(t8));
399 if (and_then == kFallThroughAtEnd) {
400 Branch(&done, eq, t8, Operand(zero_reg));
402 DCHECK(and_then == kReturnAtEnd);
403 Ret(eq, t8, Operand(zero_reg));
406 StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode);
407 CallStub(&store_buffer_overflow);
410 if (and_then == kReturnAtEnd) {
416 // -----------------------------------------------------------------------------
417 // Allocation support.
420 void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
425 DCHECK(!holder_reg.is(scratch));
426 DCHECK(!holder_reg.is(at));
427 DCHECK(!scratch.is(at));
429 // Load current lexical context from the stack frame.
430 ld(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
431 // In debug mode, make sure the lexical context is set.
433 Check(ne, kWeShouldNotHaveAnEmptyLexicalContext,
434 scratch, Operand(zero_reg));
437 // Load the native context of the current context.
439 Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize;
440 ld(scratch, FieldMemOperand(scratch, offset));
441 ld(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
443 // Check the context is a native context.
444 if (emit_debug_code()) {
445 push(holder_reg); // Temporarily save holder on the stack.
446 // Read the first word and compare to the native_context_map.
447 ld(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
448 LoadRoot(at, Heap::kNativeContextMapRootIndex);
449 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext,
450 holder_reg, Operand(at));
451 pop(holder_reg); // Restore holder.
454 // Check if both contexts are the same.
455 ld(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
456 Branch(&same_contexts, eq, scratch, Operand(at));
458 // Check the context is a native context.
459 if (emit_debug_code()) {
460 push(holder_reg); // Temporarily save holder on the stack.
461 mov(holder_reg, at); // Move at to its holding place.
462 LoadRoot(at, Heap::kNullValueRootIndex);
463 Check(ne, kJSGlobalProxyContextShouldNotBeNull,
464 holder_reg, Operand(at));
466 ld(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
467 LoadRoot(at, Heap::kNativeContextMapRootIndex);
468 Check(eq, kJSGlobalObjectNativeContextShouldBeANativeContext,
469 holder_reg, Operand(at));
470 // Restore at is not needed. at is reloaded below.
471 pop(holder_reg); // Restore holder.
472 // Restore at to holder's context.
473 ld(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset));
476 // Check that the security token in the calling global object is
477 // compatible with the security token in the receiving global
479 int token_offset = Context::kHeaderSize +
480 Context::SECURITY_TOKEN_INDEX * kPointerSize;
482 ld(scratch, FieldMemOperand(scratch, token_offset));
483 ld(at, FieldMemOperand(at, token_offset));
484 Branch(miss, ne, scratch, Operand(at));
486 bind(&same_contexts);
490 // Compute the hash code from the untagged key. This must be kept in sync with
491 // ComputeIntegerHash in utils.h and KeyedLoadGenericStub in
492 // code-stub-hydrogen.cc
493 void MacroAssembler::GetNumberHash(Register reg0, Register scratch) {
494 // First of all we assign the hash seed to scratch.
495 LoadRoot(scratch, Heap::kHashSeedRootIndex);
498 // Xor original key with a seed.
499 xor_(reg0, reg0, scratch);
501 // Compute the hash code from the untagged key. This must be kept in sync
502 // with ComputeIntegerHash in utils.h.
504 // hash = ~hash + (hash << 15);
505 // The algorithm uses 32-bit integer values.
506 nor(scratch, reg0, zero_reg);
508 addu(reg0, scratch, at);
510 // hash = hash ^ (hash >> 12);
512 xor_(reg0, reg0, at);
514 // hash = hash + (hash << 2);
516 addu(reg0, reg0, at);
518 // hash = hash ^ (hash >> 4);
520 xor_(reg0, reg0, at);
522 // hash = hash * 2057;
523 sll(scratch, reg0, 11);
525 addu(reg0, reg0, at);
526 addu(reg0, reg0, scratch);
528 // hash = hash ^ (hash >> 16);
530 xor_(reg0, reg0, at);
531 And(reg0, reg0, Operand(0x3fffffff));
535 void MacroAssembler::LoadFromNumberDictionary(Label* miss,
544 // elements - holds the slow-case elements of the receiver on entry.
545 // Unchanged unless 'result' is the same register.
547 // key - holds the smi key on entry.
548 // Unchanged unless 'result' is the same register.
551 // result - holds the result on exit if the load succeeded.
552 // Allowed to be the same as 'key' or 'result'.
553 // Unchanged on bailout so 'key' or 'result' can be used
554 // in further computation.
556 // Scratch registers:
558 // reg0 - holds the untagged key on entry and holds the hash once computed.
560 // reg1 - Used to hold the capacity mask of the dictionary.
562 // reg2 - Used for the index into the dictionary.
563 // at - Temporary (avoid MacroAssembler instructions also using 'at').
566 GetNumberHash(reg0, reg1);
568 // Compute the capacity mask.
569 ld(reg1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset));
570 SmiUntag(reg1, reg1);
571 Dsubu(reg1, reg1, Operand(1));
573 // Generate an unrolled loop that performs a few probes before giving up.
574 for (int i = 0; i < kNumberDictionaryProbes; i++) {
575 // Use reg2 for index calculations and keep the hash intact in reg0.
577 // Compute the masked index: (hash + i + i * i) & mask.
579 Daddu(reg2, reg2, Operand(SeededNumberDictionary::GetProbeOffset(i)));
581 and_(reg2, reg2, reg1);
583 // Scale the index by multiplying by the element size.
584 DCHECK(SeededNumberDictionary::kEntrySize == 3);
585 dsll(at, reg2, 1); // 2x.
586 daddu(reg2, reg2, at); // reg2 = reg2 * 3.
588 // Check if the key is identical to the name.
589 dsll(at, reg2, kPointerSizeLog2);
590 daddu(reg2, elements, at);
592 ld(at, FieldMemOperand(reg2, SeededNumberDictionary::kElementsStartOffset));
593 if (i != kNumberDictionaryProbes - 1) {
594 Branch(&done, eq, key, Operand(at));
596 Branch(miss, ne, key, Operand(at));
601 // Check that the value is a field property.
602 // reg2: elements + (index * kPointerSize).
603 const int kDetailsOffset =
604 SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize;
605 ld(reg1, FieldMemOperand(reg2, kDetailsOffset));
607 And(at, reg1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask)));
608 Branch(miss, ne, at, Operand(zero_reg));
610 // Get the value at the masked, scaled index and return.
611 const int kValueOffset =
612 SeededNumberDictionary::kElementsStartOffset + kPointerSize;
613 ld(result, FieldMemOperand(reg2, kValueOffset));
617 // ---------------------------------------------------------------------------
618 // Instruction macros.
620 void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) {
622 addu(rd, rs, rt.rm());
624 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
625 addiu(rd, rs, static_cast<int32_t>(rt.imm64_));
627 // li handles the relocation.
636 void MacroAssembler::Daddu(Register rd, Register rs, const Operand& rt) {
638 daddu(rd, rs, rt.rm());
640 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
641 daddiu(rd, rs, static_cast<int32_t>(rt.imm64_));
643 // li handles the relocation.
652 void MacroAssembler::Subu(Register rd, Register rs, const Operand& rt) {
654 subu(rd, rs, rt.rm());
656 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
657 addiu(rd, rs, static_cast<int32_t>(
658 -rt.imm64_)); // No subiu instr, use addiu(x, y, -imm).
660 // li handles the relocation.
669 void MacroAssembler::Dsubu(Register rd, Register rs, const Operand& rt) {
671 dsubu(rd, rs, rt.rm());
673 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
675 static_cast<int32_t>(
676 -rt.imm64_)); // No subiu instr, use addiu(x, y, -imm).
678 // li handles the relocation.
687 void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) {
689 mul(rd, rs, rt.rm());
691 // li handles the relocation.
699 void MacroAssembler::Mulh(Register rd, Register rs, const Operand& rt) {
701 if (kArchVariant != kMips64r6) {
705 muh(rd, rs, rt.rm());
708 // li handles the relocation.
711 if (kArchVariant != kMips64r6) {
721 void MacroAssembler::Mulhu(Register rd, Register rs, const Operand& rt) {
723 if (kArchVariant != kMips64r6) {
727 muhu(rd, rs, rt.rm());
730 // li handles the relocation.
733 if (kArchVariant != kMips64r6) {
743 void MacroAssembler::Dmul(Register rd, Register rs, const Operand& rt) {
745 if (kArchVariant == kMips64r6) {
746 dmul(rd, rs, rt.rm());
752 // li handles the relocation.
755 if (kArchVariant == kMips64r6) {
765 void MacroAssembler::Dmulh(Register rd, Register rs, const Operand& rt) {
767 if (kArchVariant == kMips64r6) {
768 dmuh(rd, rs, rt.rm());
774 // li handles the relocation.
777 if (kArchVariant == kMips64r6) {
787 void MacroAssembler::Mult(Register rs, const Operand& rt) {
791 // li handles the relocation.
799 void MacroAssembler::Dmult(Register rs, const Operand& rt) {
803 // li handles the relocation.
811 void MacroAssembler::Multu(Register rs, const Operand& rt) {
815 // li handles the relocation.
823 void MacroAssembler::Dmultu(Register rs, const Operand& rt) {
827 // li handles the relocation.
835 void MacroAssembler::Div(Register rs, const Operand& rt) {
839 // li handles the relocation.
847 void MacroAssembler::Div(Register res, Register rs, const Operand& rt) {
849 if (kArchVariant != kMips64r6) {
853 div(res, rs, rt.rm());
856 // li handles the relocation.
859 if (kArchVariant != kMips64r6) {
869 void MacroAssembler::Mod(Register rd, Register rs, const Operand& rt) {
871 if (kArchVariant != kMips64r6) {
875 mod(rd, rs, rt.rm());
878 // li handles the relocation.
881 if (kArchVariant != kMips64r6) {
891 void MacroAssembler::Modu(Register rd, Register rs, const Operand& rt) {
893 if (kArchVariant != kMips64r6) {
897 modu(rd, rs, rt.rm());
900 // li handles the relocation.
903 if (kArchVariant != kMips64r6) {
913 void MacroAssembler::Ddiv(Register rs, const Operand& rt) {
917 // li handles the relocation.
925 void MacroAssembler::Ddiv(Register rd, Register rs, const Operand& rt) {
926 if (kArchVariant != kMips64r6) {
931 // li handles the relocation.
939 ddiv(rd, rs, rt.rm());
941 // li handles the relocation.
950 void MacroAssembler::Divu(Register rs, const Operand& rt) {
954 // li handles the relocation.
962 void MacroAssembler::Divu(Register res, Register rs, const Operand& rt) {
964 if (kArchVariant != kMips64r6) {
968 divu(res, rs, rt.rm());
971 // li handles the relocation.
974 if (kArchVariant != kMips64r6) {
984 void MacroAssembler::Ddivu(Register rs, const Operand& rt) {
988 // li handles the relocation.
996 void MacroAssembler::Ddivu(Register res, Register rs, const Operand& rt) {
998 if (kArchVariant != kMips64r6) {
1002 ddivu(res, rs, rt.rm());
1005 // li handles the relocation.
1008 if (kArchVariant != kMips64r6) {
1018 void MacroAssembler::Dmod(Register rd, Register rs, const Operand& rt) {
1019 if (kArchVariant != kMips64r6) {
1024 // li handles the relocation.
1032 dmod(rd, rs, rt.rm());
1034 // li handles the relocation.
1043 void MacroAssembler::Dmodu(Register rd, Register rs, const Operand& rt) {
1044 if (kArchVariant != kMips64r6) {
1049 // li handles the relocation.
1057 dmodu(rd, rs, rt.rm());
1059 // li handles the relocation.
1068 void MacroAssembler::And(Register rd, Register rs, const Operand& rt) {
1070 and_(rd, rs, rt.rm());
1072 if (is_uint16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
1073 andi(rd, rs, static_cast<int32_t>(rt.imm64_));
1075 // li handles the relocation.
1084 void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) {
1086 or_(rd, rs, rt.rm());
1088 if (is_uint16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
1089 ori(rd, rs, static_cast<int32_t>(rt.imm64_));
1091 // li handles the relocation.
1100 void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) {
1102 xor_(rd, rs, rt.rm());
1104 if (is_uint16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
1105 xori(rd, rs, static_cast<int32_t>(rt.imm64_));
1107 // li handles the relocation.
1116 void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) {
1118 nor(rd, rs, rt.rm());
1120 // li handles the relocation.
1128 void MacroAssembler::Neg(Register rs, const Operand& rt) {
1129 DCHECK(rt.is_reg());
1131 DCHECK(!at.is(rt.rm()));
1133 xor_(rs, rt.rm(), at);
1137 void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) {
1139 slt(rd, rs, rt.rm());
1141 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
1142 slti(rd, rs, static_cast<int32_t>(rt.imm64_));
1144 // li handles the relocation.
1153 void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) {
1155 sltu(rd, rs, rt.rm());
1157 if (is_int16(rt.imm64_) && !MustUseReg(rt.rmode_)) {
1158 sltiu(rd, rs, static_cast<int32_t>(rt.imm64_));
1160 // li handles the relocation.
1169 void MacroAssembler::Ror(Register rd, Register rs, const Operand& rt) {
1171 rotrv(rd, rs, rt.rm());
1173 rotr(rd, rs, rt.imm64_);
1178 void MacroAssembler::Dror(Register rd, Register rs, const Operand& rt) {
1180 drotrv(rd, rs, rt.rm());
1182 drotr(rd, rs, rt.imm64_);
1187 void MacroAssembler::Pref(int32_t hint, const MemOperand& rs) {
1192 // ------------Pseudo-instructions-------------
1194 void MacroAssembler::Ulw(Register rd, const MemOperand& rs) {
1196 lwl(rd, MemOperand(rs.rm(), rs.offset() + 3));
1200 void MacroAssembler::Usw(Register rd, const MemOperand& rs) {
1202 swl(rd, MemOperand(rs.rm(), rs.offset() + 3));
1206 // Do 64-bit load from unaligned address. Note this only handles
1207 // the specific case of 32-bit aligned, but not 64-bit aligned.
1208 void MacroAssembler::Uld(Register rd, const MemOperand& rs, Register scratch) {
1209 // Assert fail if the offset from start of object IS actually aligned.
1210 // ONLY use with known misalignment, since there is performance cost.
1211 DCHECK((rs.offset() + kHeapObjectTag) & (kPointerSize - 1));
1212 // TODO(plind): endian dependency.
1214 lw(scratch, MemOperand(rs.rm(), rs.offset() + kPointerSize / 2));
1215 dsll32(scratch, scratch, 0);
1216 Daddu(rd, rd, scratch);
1220 // Do 64-bit store to unaligned address. Note this only handles
1221 // the specific case of 32-bit aligned, but not 64-bit aligned.
1222 void MacroAssembler::Usd(Register rd, const MemOperand& rs, Register scratch) {
1223 // Assert fail if the offset from start of object IS actually aligned.
1224 // ONLY use with known misalignment, since there is performance cost.
1225 DCHECK((rs.offset() + kHeapObjectTag) & (kPointerSize - 1));
1226 // TODO(plind): endian dependency.
1228 dsrl32(scratch, rd, 0);
1229 sw(scratch, MemOperand(rs.rm(), rs.offset() + kPointerSize / 2));
1233 void MacroAssembler::li(Register dst, Handle<Object> value, LiFlags mode) {
1234 AllowDeferredHandleDereference smi_check;
1235 if (value->IsSmi()) {
1236 li(dst, Operand(value), mode);
1238 DCHECK(value->IsHeapObject());
1239 if (isolate()->heap()->InNewSpace(*value)) {
1240 Handle<Cell> cell = isolate()->factory()->NewCell(value);
1241 li(dst, Operand(cell));
1242 ld(dst, FieldMemOperand(dst, Cell::kValueOffset));
1244 li(dst, Operand(value));
1250 void MacroAssembler::li(Register rd, Operand j, LiFlags mode) {
1251 DCHECK(!j.is_reg());
1252 BlockTrampolinePoolScope block_trampoline_pool(this);
1253 if (!MustUseReg(j.rmode_) && mode == OPTIMIZE_SIZE) {
1254 // Normal load of an immediate value which does not need Relocation Info.
1255 if (is_int32(j.imm64_)) {
1256 if (is_int16(j.imm64_)) {
1257 daddiu(rd, zero_reg, (j.imm64_ & kImm16Mask));
1258 } else if (!(j.imm64_ & kHiMask)) {
1259 ori(rd, zero_reg, (j.imm64_ & kImm16Mask));
1260 } else if (!(j.imm64_ & kImm16Mask)) {
1261 lui(rd, (j.imm64_ >> kLuiShift) & kImm16Mask);
1263 lui(rd, (j.imm64_ >> kLuiShift) & kImm16Mask);
1264 ori(rd, rd, (j.imm64_ & kImm16Mask));
1267 if (is_int48(j.imm64_)) {
1268 if ((j.imm64_ >> 32) & kImm16Mask) {
1269 lui(rd, (j.imm64_ >> 32) & kImm16Mask);
1270 if ((j.imm64_ >> 16) & kImm16Mask) {
1271 ori(rd, rd, (j.imm64_ >> 16) & kImm16Mask);
1274 ori(rd, zero_reg, (j.imm64_ >> 16) & kImm16Mask);
1277 if (j.imm64_ & kImm16Mask) {
1278 ori(rd, rd, j.imm64_ & kImm16Mask);
1281 lui(rd, (j.imm64_ >> 48) & kImm16Mask);
1282 if ((j.imm64_ >> 32) & kImm16Mask) {
1283 ori(rd, rd, (j.imm64_ >> 32) & kImm16Mask);
1285 if ((j.imm64_ >> 16) & kImm16Mask) {
1287 ori(rd, rd, (j.imm64_ >> 16) & kImm16Mask);
1288 if (j.imm64_ & kImm16Mask) {
1290 ori(rd, rd, j.imm64_ & kImm16Mask);
1295 if (j.imm64_ & kImm16Mask) {
1297 ori(rd, rd, j.imm64_ & kImm16Mask);
1304 } else if (MustUseReg(j.rmode_)) {
1305 RecordRelocInfo(j.rmode_, j.imm64_);
1306 lui(rd, (j.imm64_ >> 32) & kImm16Mask);
1307 ori(rd, rd, (j.imm64_ >> 16) & kImm16Mask);
1309 ori(rd, rd, j.imm64_ & kImm16Mask);
1310 } else if (mode == ADDRESS_LOAD) {
1311 // We always need the same number of instructions as we may need to patch
1312 // this code to load another value which may need all 4 instructions.
1313 lui(rd, (j.imm64_ >> 32) & kImm16Mask);
1314 ori(rd, rd, (j.imm64_ >> 16) & kImm16Mask);
1316 ori(rd, rd, j.imm64_ & kImm16Mask);
1318 lui(rd, (j.imm64_ >> 48) & kImm16Mask);
1319 ori(rd, rd, (j.imm64_ >> 32) & kImm16Mask);
1321 ori(rd, rd, (j.imm64_ >> 16) & kImm16Mask);
1323 ori(rd, rd, j.imm64_ & kImm16Mask);
1328 void MacroAssembler::MultiPush(RegList regs) {
1329 int16_t num_to_push = NumberOfBitsSet(regs);
1330 int16_t stack_offset = num_to_push * kPointerSize;
1332 Dsubu(sp, sp, Operand(stack_offset));
1333 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1334 if ((regs & (1 << i)) != 0) {
1335 stack_offset -= kPointerSize;
1336 sd(ToRegister(i), MemOperand(sp, stack_offset));
1342 void MacroAssembler::MultiPushReversed(RegList regs) {
1343 int16_t num_to_push = NumberOfBitsSet(regs);
1344 int16_t stack_offset = num_to_push * kPointerSize;
1346 Dsubu(sp, sp, Operand(stack_offset));
1347 for (int16_t i = 0; i < kNumRegisters; i++) {
1348 if ((regs & (1 << i)) != 0) {
1349 stack_offset -= kPointerSize;
1350 sd(ToRegister(i), MemOperand(sp, stack_offset));
1356 void MacroAssembler::MultiPop(RegList regs) {
1357 int16_t stack_offset = 0;
1359 for (int16_t i = 0; i < kNumRegisters; i++) {
1360 if ((regs & (1 << i)) != 0) {
1361 ld(ToRegister(i), MemOperand(sp, stack_offset));
1362 stack_offset += kPointerSize;
1365 daddiu(sp, sp, stack_offset);
1369 void MacroAssembler::MultiPopReversed(RegList regs) {
1370 int16_t stack_offset = 0;
1372 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1373 if ((regs & (1 << i)) != 0) {
1374 ld(ToRegister(i), MemOperand(sp, stack_offset));
1375 stack_offset += kPointerSize;
1378 daddiu(sp, sp, stack_offset);
1382 void MacroAssembler::MultiPushFPU(RegList regs) {
1383 int16_t num_to_push = NumberOfBitsSet(regs);
1384 int16_t stack_offset = num_to_push * kDoubleSize;
1386 Dsubu(sp, sp, Operand(stack_offset));
1387 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1388 if ((regs & (1 << i)) != 0) {
1389 stack_offset -= kDoubleSize;
1390 sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1396 void MacroAssembler::MultiPushReversedFPU(RegList regs) {
1397 int16_t num_to_push = NumberOfBitsSet(regs);
1398 int16_t stack_offset = num_to_push * kDoubleSize;
1400 Dsubu(sp, sp, Operand(stack_offset));
1401 for (int16_t i = 0; i < kNumRegisters; i++) {
1402 if ((regs & (1 << i)) != 0) {
1403 stack_offset -= kDoubleSize;
1404 sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1410 void MacroAssembler::MultiPopFPU(RegList regs) {
1411 int16_t stack_offset = 0;
1413 for (int16_t i = 0; i < kNumRegisters; i++) {
1414 if ((regs & (1 << i)) != 0) {
1415 ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1416 stack_offset += kDoubleSize;
1419 daddiu(sp, sp, stack_offset);
1423 void MacroAssembler::MultiPopReversedFPU(RegList regs) {
1424 int16_t stack_offset = 0;
1426 for (int16_t i = kNumRegisters - 1; i >= 0; i--) {
1427 if ((regs & (1 << i)) != 0) {
1428 ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset));
1429 stack_offset += kDoubleSize;
1432 daddiu(sp, sp, stack_offset);
1436 void MacroAssembler::FlushICache(Register address, unsigned instructions) {
1437 RegList saved_regs = kJSCallerSaved | ra.bit();
1438 MultiPush(saved_regs);
1439 AllowExternalCallThatCantCauseGC scope(this);
1441 // Save to a0 in case address == a4.
1443 PrepareCallCFunction(2, a4);
1445 li(a1, instructions * kInstrSize);
1446 CallCFunction(ExternalReference::flush_icache_function(isolate()), 2);
1447 MultiPop(saved_regs);
1451 void MacroAssembler::Ext(Register rt,
1456 DCHECK(pos + size < 33);
1457 ext_(rt, rs, pos, size);
1461 void MacroAssembler::Dext(Register rt, Register rs, uint16_t pos,
1464 DCHECK(pos + size < 33);
1465 dext_(rt, rs, pos, size);
1469 void MacroAssembler::Ins(Register rt,
1474 DCHECK(pos + size <= 32);
1476 ins_(rt, rs, pos, size);
1480 void MacroAssembler::Cvt_d_uw(FPURegister fd,
1482 FPURegister scratch) {
1483 // Move the data from fs to t8.
1485 Cvt_d_uw(fd, t8, scratch);
1489 void MacroAssembler::Cvt_d_uw(FPURegister fd,
1491 FPURegister scratch) {
1492 // Convert rs to a FP value in fd (and fd + 1).
1493 // We do this by converting rs minus the MSB to avoid sign conversion,
1494 // then adding 2^31 to the result (if needed).
1496 DCHECK(!fd.is(scratch));
1500 // Save rs's MSB to t9.
1504 // Move the result to fd.
1506 mthc1(zero_reg, fd);
1508 // Convert fd to a real FP value.
1511 Label conversion_done;
1513 // If rs's MSB was 0, it's done.
1514 // Otherwise we need to add that to the FP register.
1515 Branch(&conversion_done, eq, t9, Operand(zero_reg));
1517 // Load 2^31 into f20 as its float representation.
1519 mtc1(zero_reg, scratch);
1522 add_d(fd, fd, scratch);
1524 bind(&conversion_done);
1528 void MacroAssembler::Round_l_d(FPURegister fd, FPURegister fs) {
1533 void MacroAssembler::Floor_l_d(FPURegister fd, FPURegister fs) {
1538 void MacroAssembler::Ceil_l_d(FPURegister fd, FPURegister fs) {
1543 void MacroAssembler::Trunc_l_d(FPURegister fd, FPURegister fs) {
1548 void MacroAssembler::Trunc_l_ud(FPURegister fd,
1550 FPURegister scratch) {
1554 li(at, 0x7fffffffffffffff);
1561 void MacroAssembler::Trunc_uw_d(FPURegister fd,
1563 FPURegister scratch) {
1564 Trunc_uw_d(fs, t8, scratch);
1569 void MacroAssembler::Trunc_w_d(FPURegister fd, FPURegister fs) {
1574 void MacroAssembler::Round_w_d(FPURegister fd, FPURegister fs) {
1579 void MacroAssembler::Floor_w_d(FPURegister fd, FPURegister fs) {
1584 void MacroAssembler::Ceil_w_d(FPURegister fd, FPURegister fs) {
1589 void MacroAssembler::Trunc_uw_d(FPURegister fd,
1591 FPURegister scratch) {
1592 DCHECK(!fd.is(scratch));
1595 // Load 2^31 into scratch as its float representation.
1597 mtc1(zero_reg, scratch);
1599 // Test if scratch > fd.
1600 // If fd < 2^31 we can convert it normally.
1601 Label simple_convert;
1602 BranchF(&simple_convert, NULL, lt, fd, scratch);
1604 // First we subtract 2^31 from fd, then trunc it to rs
1605 // and add 2^31 to rs.
1606 sub_d(scratch, fd, scratch);
1607 trunc_w_d(scratch, scratch);
1609 Or(rs, rs, 1 << 31);
1613 // Simple conversion.
1614 bind(&simple_convert);
1615 trunc_w_d(scratch, fd);
1622 void MacroAssembler::Madd_d(FPURegister fd, FPURegister fr, FPURegister fs,
1623 FPURegister ft, FPURegister scratch) {
1624 if (0) { // TODO(plind): find reasonable arch-variant symbol names.
1625 madd_d(fd, fr, fs, ft);
1627 // Can not change source regs's value.
1628 DCHECK(!fr.is(scratch) && !fs.is(scratch) && !ft.is(scratch));
1629 mul_d(scratch, fs, ft);
1630 add_d(fd, fr, scratch);
1635 void MacroAssembler::BranchFCommon(SecondaryField sizeField, Label* target,
1636 Label* nan, Condition cond, FPURegister cmp1,
1637 FPURegister cmp2, BranchDelaySlot bd) {
1638 BlockTrampolinePoolScope block_trampoline_pool(this);
1644 if (kArchVariant == kMips64r6) {
1645 sizeField = sizeField == D ? L : W;
1648 DCHECK(nan || target);
1649 // Check for unordered (NaN) cases.
1651 bool long_branch = nan->is_bound() ? is_near(nan) : is_trampoline_emitted();
1652 if (kArchVariant != kMips64r6) {
1655 c(UN, D, cmp1, cmp2);
1661 c(UN, D, cmp1, cmp2);
1663 if (bd == PROTECT) {
1668 // Use kDoubleCompareReg for comparison result. It has to be unavailable
1670 // register allocator.
1671 DCHECK(!cmp1.is(kDoubleCompareReg) && !cmp2.is(kDoubleCompareReg));
1674 cmp(UN, L, kDoubleCompareReg, cmp1, cmp2);
1675 bc1eqz(&skip, kDoubleCompareReg);
1680 cmp(UN, L, kDoubleCompareReg, cmp1, cmp2);
1681 bc1nez(nan, kDoubleCompareReg);
1682 if (bd == PROTECT) {
1691 target->is_bound() ? is_near(target) : is_trampoline_emitted();
1694 Condition neg_cond = NegateFpuCondition(cond);
1695 BranchShortF(sizeField, &skip, neg_cond, cmp1, cmp2, bd);
1699 BranchShortF(sizeField, target, cond, cmp1, cmp2, bd);
1705 void MacroAssembler::BranchShortF(SecondaryField sizeField, Label* target,
1706 Condition cc, FPURegister cmp1,
1707 FPURegister cmp2, BranchDelaySlot bd) {
1708 if (kArchVariant != kMips64r6) {
1709 BlockTrampolinePoolScope block_trampoline_pool(this);
1711 // Here NaN cases were either handled by this function or are assumed to
1712 // have been handled by the caller.
1715 c(OLT, sizeField, cmp1, cmp2);
1719 c(ULT, sizeField, cmp1, cmp2);
1723 c(ULE, sizeField, cmp1, cmp2);
1727 c(OLE, sizeField, cmp1, cmp2);
1731 c(ULT, sizeField, cmp1, cmp2);
1735 c(OLT, sizeField, cmp1, cmp2);
1739 c(OLE, sizeField, cmp1, cmp2);
1743 c(ULE, sizeField, cmp1, cmp2);
1747 c(EQ, sizeField, cmp1, cmp2);
1751 c(UEQ, sizeField, cmp1, cmp2);
1754 case ne: // Unordered or not equal.
1755 c(EQ, sizeField, cmp1, cmp2);
1759 c(UEQ, sizeField, cmp1, cmp2);
1767 BlockTrampolinePoolScope block_trampoline_pool(this);
1769 // Here NaN cases were either handled by this function or are assumed to
1770 // have been handled by the caller.
1771 // Unsigned conditions are treated as their signed counterpart.
1772 // Use kDoubleCompareReg for comparison result, it is valid in fp64 (FR =
1774 DCHECK(!cmp1.is(kDoubleCompareReg) && !cmp2.is(kDoubleCompareReg));
1777 cmp(OLT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1778 bc1nez(target, kDoubleCompareReg);
1781 cmp(ULT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1782 bc1nez(target, kDoubleCompareReg);
1785 cmp(ULE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1786 bc1eqz(target, kDoubleCompareReg);
1789 cmp(OLE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1790 bc1eqz(target, kDoubleCompareReg);
1793 cmp(ULT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1794 bc1eqz(target, kDoubleCompareReg);
1797 cmp(OLT, sizeField, kDoubleCompareReg, cmp1, cmp2);
1798 bc1eqz(target, kDoubleCompareReg);
1801 cmp(OLE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1802 bc1nez(target, kDoubleCompareReg);
1805 cmp(ULE, sizeField, kDoubleCompareReg, cmp1, cmp2);
1806 bc1nez(target, kDoubleCompareReg);
1809 cmp(EQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1810 bc1nez(target, kDoubleCompareReg);
1813 cmp(UEQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1814 bc1nez(target, kDoubleCompareReg);
1817 cmp(EQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1818 bc1eqz(target, kDoubleCompareReg);
1821 cmp(UEQ, sizeField, kDoubleCompareReg, cmp1, cmp2);
1822 bc1eqz(target, kDoubleCompareReg);
1830 if (bd == PROTECT) {
1836 void MacroAssembler::FmoveLow(FPURegister dst, Register src_low) {
1837 DCHECK(!src_low.is(at));
1844 void MacroAssembler::Move(FPURegister dst, float imm) {
1845 li(at, Operand(bit_cast<int32_t>(imm)));
1850 void MacroAssembler::Move(FPURegister dst, double imm) {
1851 static const DoubleRepresentation minus_zero(-0.0);
1852 static const DoubleRepresentation zero(0.0);
1853 DoubleRepresentation value_rep(imm);
1854 // Handle special values first.
1855 if (value_rep == zero && has_double_zero_reg_set_) {
1856 mov_d(dst, kDoubleRegZero);
1857 } else if (value_rep == minus_zero && has_double_zero_reg_set_) {
1858 neg_d(dst, kDoubleRegZero);
1861 DoubleAsTwoUInt32(imm, &lo, &hi);
1862 // Move the low part of the double into the lower bits of the corresponding
1865 if (!(lo & kImm16Mask)) {
1866 lui(at, (lo >> kLuiShift) & kImm16Mask);
1868 } else if (!(lo & kHiMask)) {
1869 ori(at, zero_reg, lo & kImm16Mask);
1872 lui(at, (lo >> kLuiShift) & kImm16Mask);
1873 ori(at, at, lo & kImm16Mask);
1877 mtc1(zero_reg, dst);
1879 // Move the high part of the double into the high bits of the corresponding
1882 if (!(hi & kImm16Mask)) {
1883 lui(at, (hi >> kLuiShift) & kImm16Mask);
1885 } else if (!(hi & kHiMask)) {
1886 ori(at, zero_reg, hi & kImm16Mask);
1889 lui(at, (hi >> kLuiShift) & kImm16Mask);
1890 ori(at, at, hi & kImm16Mask);
1894 mthc1(zero_reg, dst);
1896 if (dst.is(kDoubleRegZero)) has_double_zero_reg_set_ = true;
1901 void MacroAssembler::Movz(Register rd, Register rs, Register rt) {
1902 if (kArchVariant == kMips64r6) {
1904 Branch(&done, ne, rt, Operand(zero_reg));
1913 void MacroAssembler::Movn(Register rd, Register rs, Register rt) {
1914 if (kArchVariant == kMips64r6) {
1916 Branch(&done, eq, rt, Operand(zero_reg));
1925 void MacroAssembler::Movt(Register rd, Register rs, uint16_t cc) {
1930 void MacroAssembler::Movf(Register rd, Register rs, uint16_t cc) {
1935 void MacroAssembler::Clz(Register rd, Register rs) {
1940 void MacroAssembler::EmitFPUTruncate(FPURoundingMode rounding_mode,
1942 DoubleRegister double_input,
1944 DoubleRegister double_scratch,
1945 Register except_flag,
1946 CheckForInexactConversion check_inexact) {
1947 DCHECK(!result.is(scratch));
1948 DCHECK(!double_input.is(double_scratch));
1949 DCHECK(!except_flag.is(scratch));
1953 // Clear the except flag (0 = no exception)
1954 mov(except_flag, zero_reg);
1956 // Test for values that can be exactly represented as a signed 32-bit integer.
1957 cvt_w_d(double_scratch, double_input);
1958 mfc1(result, double_scratch);
1959 cvt_d_w(double_scratch, double_scratch);
1960 BranchF(&done, NULL, eq, double_input, double_scratch);
1962 int32_t except_mask = kFCSRFlagMask; // Assume interested in all exceptions.
1964 if (check_inexact == kDontCheckForInexactConversion) {
1965 // Ignore inexact exceptions.
1966 except_mask &= ~kFCSRInexactFlagMask;
1970 cfc1(scratch, FCSR);
1971 // Disable FPU exceptions.
1972 ctc1(zero_reg, FCSR);
1974 // Do operation based on rounding mode.
1975 switch (rounding_mode) {
1976 case kRoundToNearest:
1977 Round_w_d(double_scratch, double_input);
1980 Trunc_w_d(double_scratch, double_input);
1982 case kRoundToPlusInf:
1983 Ceil_w_d(double_scratch, double_input);
1985 case kRoundToMinusInf:
1986 Floor_w_d(double_scratch, double_input);
1988 } // End of switch-statement.
1991 cfc1(except_flag, FCSR);
1993 ctc1(scratch, FCSR);
1994 // Move the converted value into the result register.
1995 mfc1(result, double_scratch);
1997 // Check for fpu exceptions.
1998 And(except_flag, except_flag, Operand(except_mask));
2004 void MacroAssembler::TryInlineTruncateDoubleToI(Register result,
2005 DoubleRegister double_input,
2007 DoubleRegister single_scratch = kLithiumScratchDouble.low();
2008 Register scratch = at;
2009 Register scratch2 = t9;
2011 // Clear cumulative exception flags and save the FCSR.
2012 cfc1(scratch2, FCSR);
2013 ctc1(zero_reg, FCSR);
2014 // Try a conversion to a signed integer.
2015 trunc_w_d(single_scratch, double_input);
2016 mfc1(result, single_scratch);
2017 // Retrieve and restore the FCSR.
2018 cfc1(scratch, FCSR);
2019 ctc1(scratch2, FCSR);
2020 // Check for overflow and NaNs.
2023 kFCSROverflowFlagMask | kFCSRUnderflowFlagMask | kFCSRInvalidOpFlagMask);
2024 // If we had no exceptions we are done.
2025 Branch(done, eq, scratch, Operand(zero_reg));
2029 void MacroAssembler::TruncateDoubleToI(Register result,
2030 DoubleRegister double_input) {
2033 TryInlineTruncateDoubleToI(result, double_input, &done);
2035 // If we fell through then inline version didn't succeed - call stub instead.
2037 Dsubu(sp, sp, Operand(kDoubleSize)); // Put input on stack.
2038 sdc1(double_input, MemOperand(sp, 0));
2040 DoubleToIStub stub(isolate(), sp, result, 0, true, true);
2043 Daddu(sp, sp, Operand(kDoubleSize));
2050 void MacroAssembler::TruncateHeapNumberToI(Register result, Register object) {
2052 DoubleRegister double_scratch = f12;
2053 DCHECK(!result.is(object));
2055 ldc1(double_scratch,
2056 MemOperand(object, HeapNumber::kValueOffset - kHeapObjectTag));
2057 TryInlineTruncateDoubleToI(result, double_scratch, &done);
2059 // If we fell through then inline version didn't succeed - call stub instead.
2061 DoubleToIStub stub(isolate(),
2064 HeapNumber::kValueOffset - kHeapObjectTag,
2074 void MacroAssembler::TruncateNumberToI(Register object,
2076 Register heap_number_map,
2078 Label* not_number) {
2080 DCHECK(!result.is(object));
2082 UntagAndJumpIfSmi(result, object, &done);
2083 JumpIfNotHeapNumber(object, heap_number_map, scratch, not_number);
2084 TruncateHeapNumberToI(result, object);
2090 void MacroAssembler::GetLeastBitsFromSmi(Register dst,
2092 int num_least_bits) {
2093 // Ext(dst, src, kSmiTagSize, num_least_bits);
2095 And(dst, dst, Operand((1 << num_least_bits) - 1));
2099 void MacroAssembler::GetLeastBitsFromInt32(Register dst,
2101 int num_least_bits) {
2102 DCHECK(!src.is(dst));
2103 And(dst, src, Operand((1 << num_least_bits) - 1));
2107 // Emulated condtional branches do not emit a nop in the branch delay slot.
2109 // BRANCH_ARGS_CHECK checks that conditional jump arguments are correct.
2110 #define BRANCH_ARGS_CHECK(cond, rs, rt) DCHECK( \
2111 (cond == cc_always && rs.is(zero_reg) && rt.rm().is(zero_reg)) || \
2112 (cond != cc_always && (!rs.is(zero_reg) || !rt.rm().is(zero_reg))))
2115 void MacroAssembler::Branch(int16_t offset, BranchDelaySlot bdslot) {
2116 BranchShort(offset, bdslot);
2120 void MacroAssembler::Branch(int16_t offset, Condition cond, Register rs,
2122 BranchDelaySlot bdslot) {
2123 BranchShort(offset, cond, rs, rt, bdslot);
2127 void MacroAssembler::Branch(Label* L, BranchDelaySlot bdslot) {
2128 if (L->is_bound()) {
2130 BranchShort(L, bdslot);
2135 if (is_trampoline_emitted()) {
2138 BranchShort(L, bdslot);
2144 void MacroAssembler::Branch(Label* L, Condition cond, Register rs,
2146 BranchDelaySlot bdslot) {
2147 if (L->is_bound()) {
2149 BranchShort(L, cond, rs, rt, bdslot);
2151 if (cond != cc_always) {
2153 Condition neg_cond = NegateCondition(cond);
2154 BranchShort(&skip, neg_cond, rs, rt);
2162 if (is_trampoline_emitted()) {
2163 if (cond != cc_always) {
2165 Condition neg_cond = NegateCondition(cond);
2166 BranchShort(&skip, neg_cond, rs, rt);
2173 BranchShort(L, cond, rs, rt, bdslot);
2179 void MacroAssembler::Branch(Label* L,
2182 Heap::RootListIndex index,
2183 BranchDelaySlot bdslot) {
2184 LoadRoot(at, index);
2185 Branch(L, cond, rs, Operand(at), bdslot);
2189 void MacroAssembler::BranchShort(int16_t offset, BranchDelaySlot bdslot) {
2192 // Emit a nop in the branch delay slot if required.
2193 if (bdslot == PROTECT)
2198 void MacroAssembler::BranchShort(int16_t offset, Condition cond, Register rs,
2200 BranchDelaySlot bdslot) {
2201 BRANCH_ARGS_CHECK(cond, rs, rt);
2202 DCHECK(!rs.is(zero_reg));
2203 Register r2 = no_reg;
2204 Register scratch = at;
2207 // NOTE: 'at' can be clobbered by Branch but it is legal to use it as rs or
2209 BlockTrampolinePoolScope block_trampoline_pool(this);
2216 beq(rs, r2, offset);
2219 bne(rs, r2, offset);
2221 // Signed comparison.
2223 if (r2.is(zero_reg)) {
2226 slt(scratch, r2, rs);
2227 bne(scratch, zero_reg, offset);
2231 if (r2.is(zero_reg)) {
2234 slt(scratch, rs, r2);
2235 beq(scratch, zero_reg, offset);
2239 if (r2.is(zero_reg)) {
2242 slt(scratch, rs, r2);
2243 bne(scratch, zero_reg, offset);
2247 if (r2.is(zero_reg)) {
2250 slt(scratch, r2, rs);
2251 beq(scratch, zero_reg, offset);
2254 // Unsigned comparison.
2256 if (r2.is(zero_reg)) {
2257 bne(rs, zero_reg, offset);
2259 sltu(scratch, r2, rs);
2260 bne(scratch, zero_reg, offset);
2263 case Ugreater_equal:
2264 if (r2.is(zero_reg)) {
2267 sltu(scratch, rs, r2);
2268 beq(scratch, zero_reg, offset);
2272 if (r2.is(zero_reg)) {
2273 // No code needs to be emitted.
2276 sltu(scratch, rs, r2);
2277 bne(scratch, zero_reg, offset);
2281 if (r2.is(zero_reg)) {
2282 beq(rs, zero_reg, offset);
2284 sltu(scratch, r2, rs);
2285 beq(scratch, zero_reg, offset);
2292 // Be careful to always use shifted_branch_offset only just before the
2293 // branch instruction, as the location will be remember for patching the
2295 BlockTrampolinePoolScope block_trampoline_pool(this);
2301 if (rt.imm64_ == 0) {
2302 beq(rs, zero_reg, offset);
2304 // We don't want any other register but scratch clobbered.
2305 DCHECK(!scratch.is(rs));
2308 beq(rs, r2, offset);
2312 if (rt.imm64_ == 0) {
2313 bne(rs, zero_reg, offset);
2315 // We don't want any other register but scratch clobbered.
2316 DCHECK(!scratch.is(rs));
2319 bne(rs, r2, offset);
2322 // Signed comparison.
2324 if (rt.imm64_ == 0) {
2329 slt(scratch, r2, rs);
2330 bne(scratch, zero_reg, offset);
2334 if (rt.imm64_ == 0) {
2336 } else if (is_int16(rt.imm64_)) {
2337 slti(scratch, rs, static_cast<int32_t>(rt.imm64_));
2338 beq(scratch, zero_reg, offset);
2342 slt(scratch, rs, r2);
2343 beq(scratch, zero_reg, offset);
2347 if (rt.imm64_ == 0) {
2349 } else if (is_int16(rt.imm64_)) {
2350 slti(scratch, rs, static_cast<int32_t>(rt.imm64_));
2351 bne(scratch, zero_reg, offset);
2355 slt(scratch, rs, r2);
2356 bne(scratch, zero_reg, offset);
2360 if (rt.imm64_ == 0) {
2365 slt(scratch, r2, rs);
2366 beq(scratch, zero_reg, offset);
2369 // Unsigned comparison.
2371 if (rt.imm64_ == 0) {
2372 bne(rs, zero_reg, offset);
2376 sltu(scratch, r2, rs);
2377 bne(scratch, zero_reg, offset);
2380 case Ugreater_equal:
2381 if (rt.imm64_ == 0) {
2383 } else if (is_int16(rt.imm64_)) {
2384 sltiu(scratch, rs, static_cast<int32_t>(rt.imm64_));
2385 beq(scratch, zero_reg, offset);
2389 sltu(scratch, rs, r2);
2390 beq(scratch, zero_reg, offset);
2394 if (rt.imm64_ == 0) {
2395 // No code needs to be emitted.
2397 } else if (is_int16(rt.imm64_)) {
2398 sltiu(scratch, rs, static_cast<int32_t>(rt.imm64_));
2399 bne(scratch, zero_reg, offset);
2403 sltu(scratch, rs, r2);
2404 bne(scratch, zero_reg, offset);
2408 if (rt.imm64_ == 0) {
2409 beq(rs, zero_reg, offset);
2413 sltu(scratch, r2, rs);
2414 beq(scratch, zero_reg, offset);
2421 // Emit a nop in the branch delay slot if required.
2422 if (bdslot == PROTECT)
2427 void MacroAssembler::BranchShort(Label* L, BranchDelaySlot bdslot) {
2428 // We use branch_offset as an argument for the branch instructions to be sure
2429 // it is called just before generating the branch instruction, as needed.
2431 b(shifted_branch_offset(L, false));
2433 // Emit a nop in the branch delay slot if required.
2434 if (bdslot == PROTECT)
2439 void MacroAssembler::BranchShort(Label* L, Condition cond, Register rs,
2441 BranchDelaySlot bdslot) {
2442 BRANCH_ARGS_CHECK(cond, rs, rt);
2445 Register r2 = no_reg;
2446 Register scratch = at;
2448 BlockTrampolinePoolScope block_trampoline_pool(this);
2450 // Be careful to always use shifted_branch_offset only just before the
2451 // branch instruction, as the location will be remember for patching the
2455 offset = shifted_branch_offset(L, false);
2459 offset = shifted_branch_offset(L, false);
2460 beq(rs, r2, offset);
2463 offset = shifted_branch_offset(L, false);
2464 bne(rs, r2, offset);
2466 // Signed comparison.
2468 if (r2.is(zero_reg)) {
2469 offset = shifted_branch_offset(L, false);
2472 slt(scratch, r2, rs);
2473 offset = shifted_branch_offset(L, false);
2474 bne(scratch, zero_reg, offset);
2478 if (r2.is(zero_reg)) {
2479 offset = shifted_branch_offset(L, false);
2482 slt(scratch, rs, r2);
2483 offset = shifted_branch_offset(L, false);
2484 beq(scratch, zero_reg, offset);
2488 if (r2.is(zero_reg)) {
2489 offset = shifted_branch_offset(L, false);
2492 slt(scratch, rs, r2);
2493 offset = shifted_branch_offset(L, false);
2494 bne(scratch, zero_reg, offset);
2498 if (r2.is(zero_reg)) {
2499 offset = shifted_branch_offset(L, false);
2502 slt(scratch, r2, rs);
2503 offset = shifted_branch_offset(L, false);
2504 beq(scratch, zero_reg, offset);
2507 // Unsigned comparison.
2509 if (r2.is(zero_reg)) {
2510 offset = shifted_branch_offset(L, false);
2511 bne(rs, zero_reg, offset);
2513 sltu(scratch, r2, rs);
2514 offset = shifted_branch_offset(L, false);
2515 bne(scratch, zero_reg, offset);
2518 case Ugreater_equal:
2519 if (r2.is(zero_reg)) {
2520 offset = shifted_branch_offset(L, false);
2523 sltu(scratch, rs, r2);
2524 offset = shifted_branch_offset(L, false);
2525 beq(scratch, zero_reg, offset);
2529 if (r2.is(zero_reg)) {
2530 // No code needs to be emitted.
2533 sltu(scratch, rs, r2);
2534 offset = shifted_branch_offset(L, false);
2535 bne(scratch, zero_reg, offset);
2539 if (r2.is(zero_reg)) {
2540 offset = shifted_branch_offset(L, false);
2541 beq(rs, zero_reg, offset);
2543 sltu(scratch, r2, rs);
2544 offset = shifted_branch_offset(L, false);
2545 beq(scratch, zero_reg, offset);
2552 // Be careful to always use shifted_branch_offset only just before the
2553 // branch instruction, as the location will be remember for patching the
2555 BlockTrampolinePoolScope block_trampoline_pool(this);
2558 offset = shifted_branch_offset(L, false);
2562 if (rt.imm64_ == 0) {
2563 offset = shifted_branch_offset(L, false);
2564 beq(rs, zero_reg, offset);
2566 DCHECK(!scratch.is(rs));
2569 offset = shifted_branch_offset(L, false);
2570 beq(rs, r2, offset);
2574 if (rt.imm64_ == 0) {
2575 offset = shifted_branch_offset(L, false);
2576 bne(rs, zero_reg, offset);
2578 DCHECK(!scratch.is(rs));
2581 offset = shifted_branch_offset(L, false);
2582 bne(rs, r2, offset);
2585 // Signed comparison.
2587 if (rt.imm64_ == 0) {
2588 offset = shifted_branch_offset(L, false);
2591 DCHECK(!scratch.is(rs));
2594 slt(scratch, r2, rs);
2595 offset = shifted_branch_offset(L, false);
2596 bne(scratch, zero_reg, offset);
2600 if (rt.imm64_ == 0) {
2601 offset = shifted_branch_offset(L, false);
2603 } else if (is_int16(rt.imm64_)) {
2604 slti(scratch, rs, static_cast<int32_t>(rt.imm64_));
2605 offset = shifted_branch_offset(L, false);
2606 beq(scratch, zero_reg, offset);
2608 DCHECK(!scratch.is(rs));
2611 slt(scratch, rs, r2);
2612 offset = shifted_branch_offset(L, false);
2613 beq(scratch, zero_reg, offset);
2617 if (rt.imm64_ == 0) {
2618 offset = shifted_branch_offset(L, false);
2620 } else if (is_int16(rt.imm64_)) {
2621 slti(scratch, rs, static_cast<int32_t>(rt.imm64_));
2622 offset = shifted_branch_offset(L, false);
2623 bne(scratch, zero_reg, offset);
2625 DCHECK(!scratch.is(rs));
2628 slt(scratch, rs, r2);
2629 offset = shifted_branch_offset(L, false);
2630 bne(scratch, zero_reg, offset);
2634 if (rt.imm64_ == 0) {
2635 offset = shifted_branch_offset(L, false);
2638 DCHECK(!scratch.is(rs));
2641 slt(scratch, r2, rs);
2642 offset = shifted_branch_offset(L, false);
2643 beq(scratch, zero_reg, offset);
2646 // Unsigned comparison.
2648 if (rt.imm64_ == 0) {
2649 offset = shifted_branch_offset(L, false);
2650 bne(rs, zero_reg, offset);
2652 DCHECK(!scratch.is(rs));
2655 sltu(scratch, r2, rs);
2656 offset = shifted_branch_offset(L, false);
2657 bne(scratch, zero_reg, offset);
2660 case Ugreater_equal:
2661 if (rt.imm64_ == 0) {
2662 offset = shifted_branch_offset(L, false);
2664 } else if (is_int16(rt.imm64_)) {
2665 sltiu(scratch, rs, static_cast<int32_t>(rt.imm64_));
2666 offset = shifted_branch_offset(L, false);
2667 beq(scratch, zero_reg, offset);
2669 DCHECK(!scratch.is(rs));
2672 sltu(scratch, rs, r2);
2673 offset = shifted_branch_offset(L, false);
2674 beq(scratch, zero_reg, offset);
2678 if (rt.imm64_ == 0) {
2679 // No code needs to be emitted.
2681 } else if (is_int16(rt.imm64_)) {
2682 sltiu(scratch, rs, static_cast<int32_t>(rt.imm64_));
2683 offset = shifted_branch_offset(L, false);
2684 bne(scratch, zero_reg, offset);
2686 DCHECK(!scratch.is(rs));
2689 sltu(scratch, rs, r2);
2690 offset = shifted_branch_offset(L, false);
2691 bne(scratch, zero_reg, offset);
2695 if (rt.imm64_ == 0) {
2696 offset = shifted_branch_offset(L, false);
2697 beq(rs, zero_reg, offset);
2699 DCHECK(!scratch.is(rs));
2702 sltu(scratch, r2, rs);
2703 offset = shifted_branch_offset(L, false);
2704 beq(scratch, zero_reg, offset);
2711 // Check that offset could actually hold on an int16_t.
2712 DCHECK(is_int16(offset));
2713 // Emit a nop in the branch delay slot if required.
2714 if (bdslot == PROTECT)
2719 void MacroAssembler::BranchAndLink(int16_t offset, BranchDelaySlot bdslot) {
2720 BranchAndLinkShort(offset, bdslot);
2724 void MacroAssembler::BranchAndLink(int16_t offset, Condition cond, Register rs,
2726 BranchDelaySlot bdslot) {
2727 BranchAndLinkShort(offset, cond, rs, rt, bdslot);
2731 void MacroAssembler::BranchAndLink(Label* L, BranchDelaySlot bdslot) {
2732 if (L->is_bound()) {
2734 BranchAndLinkShort(L, bdslot);
2739 if (is_trampoline_emitted()) {
2742 BranchAndLinkShort(L, bdslot);
2748 void MacroAssembler::BranchAndLink(Label* L, Condition cond, Register rs,
2750 BranchDelaySlot bdslot) {
2751 if (L->is_bound()) {
2753 BranchAndLinkShort(L, cond, rs, rt, bdslot);
2756 Condition neg_cond = NegateCondition(cond);
2757 BranchShort(&skip, neg_cond, rs, rt);
2762 if (is_trampoline_emitted()) {
2764 Condition neg_cond = NegateCondition(cond);
2765 BranchShort(&skip, neg_cond, rs, rt);
2769 BranchAndLinkShort(L, cond, rs, rt, bdslot);
2775 // We need to use a bgezal or bltzal, but they can't be used directly with the
2776 // slt instructions. We could use sub or add instead but we would miss overflow
2777 // cases, so we keep slt and add an intermediate third instruction.
2778 void MacroAssembler::BranchAndLinkShort(int16_t offset,
2779 BranchDelaySlot bdslot) {
2782 // Emit a nop in the branch delay slot if required.
2783 if (bdslot == PROTECT)
2788 void MacroAssembler::BranchAndLinkShort(int16_t offset, Condition cond,
2789 Register rs, const Operand& rt,
2790 BranchDelaySlot bdslot) {
2791 BRANCH_ARGS_CHECK(cond, rs, rt);
2792 Register r2 = no_reg;
2793 Register scratch = at;
2797 } else if (cond != cc_always) {
2803 BlockTrampolinePoolScope block_trampoline_pool(this);
2819 // Signed comparison.
2822 slt(scratch, r2, rs);
2823 beq(scratch, zero_reg, 2);
2829 slt(scratch, rs, r2);
2830 bne(scratch, zero_reg, 2);
2836 slt(scratch, rs, r2);
2837 bne(scratch, zero_reg, 2);
2843 slt(scratch, r2, rs);
2844 bne(scratch, zero_reg, 2);
2850 // Unsigned comparison.
2853 sltu(scratch, r2, rs);
2854 beq(scratch, zero_reg, 2);
2858 case Ugreater_equal:
2860 sltu(scratch, rs, r2);
2861 bne(scratch, zero_reg, 2);
2867 sltu(scratch, rs, r2);
2868 bne(scratch, zero_reg, 2);
2874 sltu(scratch, r2, rs);
2875 bne(scratch, zero_reg, 2);
2883 // Emit a nop in the branch delay slot if required.
2884 if (bdslot == PROTECT)
2889 void MacroAssembler::BranchAndLinkShort(Label* L, BranchDelaySlot bdslot) {
2890 bal(shifted_branch_offset(L, false));
2892 // Emit a nop in the branch delay slot if required.
2893 if (bdslot == PROTECT)
2898 void MacroAssembler::BranchAndLinkShort(Label* L, Condition cond, Register rs,
2900 BranchDelaySlot bdslot) {
2901 BRANCH_ARGS_CHECK(cond, rs, rt);
2904 Register r2 = no_reg;
2905 Register scratch = at;
2908 } else if (cond != cc_always) {
2914 BlockTrampolinePoolScope block_trampoline_pool(this);
2917 offset = shifted_branch_offset(L, false);
2923 offset = shifted_branch_offset(L, false);
2929 offset = shifted_branch_offset(L, false);
2933 // Signed comparison.
2936 slt(scratch, r2, rs);
2937 beq(scratch, zero_reg, 2);
2939 offset = shifted_branch_offset(L, false);
2944 slt(scratch, rs, r2);
2945 bne(scratch, zero_reg, 2);
2947 offset = shifted_branch_offset(L, false);
2952 slt(scratch, rs, r2);
2953 bne(scratch, zero_reg, 2);
2955 offset = shifted_branch_offset(L, false);
2960 slt(scratch, r2, rs);
2961 bne(scratch, zero_reg, 2);
2963 offset = shifted_branch_offset(L, false);
2968 // Unsigned comparison.
2971 sltu(scratch, r2, rs);
2972 beq(scratch, zero_reg, 2);
2974 offset = shifted_branch_offset(L, false);
2977 case Ugreater_equal:
2979 sltu(scratch, rs, r2);
2980 bne(scratch, zero_reg, 2);
2982 offset = shifted_branch_offset(L, false);
2987 sltu(scratch, rs, r2);
2988 bne(scratch, zero_reg, 2);
2990 offset = shifted_branch_offset(L, false);
2995 sltu(scratch, r2, rs);
2996 bne(scratch, zero_reg, 2);
2998 offset = shifted_branch_offset(L, false);
3006 // Check that offset could actually hold on an int16_t.
3007 DCHECK(is_int16(offset));
3009 // Emit a nop in the branch delay slot if required.
3010 if (bdslot == PROTECT)
3015 void MacroAssembler::Jump(Register target,
3019 BranchDelaySlot bd) {
3020 BlockTrampolinePoolScope block_trampoline_pool(this);
3021 if (cond == cc_always) {
3024 BRANCH_ARGS_CHECK(cond, rs, rt);
3025 Branch(2, NegateCondition(cond), rs, rt);
3028 // Emit a nop in the branch delay slot if required.
3034 void MacroAssembler::Jump(intptr_t target,
3035 RelocInfo::Mode rmode,
3039 BranchDelaySlot bd) {
3041 if (cond != cc_always) {
3042 Branch(USE_DELAY_SLOT, &skip, NegateCondition(cond), rs, rt);
3044 // The first instruction of 'li' may be placed in the delay slot.
3045 // This is not an issue, t9 is expected to be clobbered anyway.
3046 li(t9, Operand(target, rmode));
3047 Jump(t9, al, zero_reg, Operand(zero_reg), bd);
3052 void MacroAssembler::Jump(Address target,
3053 RelocInfo::Mode rmode,
3057 BranchDelaySlot bd) {
3058 DCHECK(!RelocInfo::IsCodeTarget(rmode));
3059 Jump(reinterpret_cast<intptr_t>(target), rmode, cond, rs, rt, bd);
3063 void MacroAssembler::Jump(Handle<Code> code,
3064 RelocInfo::Mode rmode,
3068 BranchDelaySlot bd) {
3069 DCHECK(RelocInfo::IsCodeTarget(rmode));
3070 AllowDeferredHandleDereference embedding_raw_address;
3071 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond, rs, rt, bd);
3075 int MacroAssembler::CallSize(Register target,
3079 BranchDelaySlot bd) {
3082 if (cond == cc_always) {
3091 return size * kInstrSize;
3095 // Note: To call gcc-compiled C code on mips, you must call thru t9.
3096 void MacroAssembler::Call(Register target,
3100 BranchDelaySlot bd) {
3101 BlockTrampolinePoolScope block_trampoline_pool(this);
3104 if (cond == cc_always) {
3107 BRANCH_ARGS_CHECK(cond, rs, rt);
3108 Branch(2, NegateCondition(cond), rs, rt);
3111 // Emit a nop in the branch delay slot if required.
3115 DCHECK_EQ(CallSize(target, cond, rs, rt, bd),
3116 SizeOfCodeGeneratedSince(&start));
3120 int MacroAssembler::CallSize(Address target,
3121 RelocInfo::Mode rmode,
3125 BranchDelaySlot bd) {
3126 int size = CallSize(t9, cond, rs, rt, bd);
3127 return size + 4 * kInstrSize;
3131 void MacroAssembler::Call(Address target,
3132 RelocInfo::Mode rmode,
3136 BranchDelaySlot bd) {
3137 BlockTrampolinePoolScope block_trampoline_pool(this);
3140 int64_t target_int = reinterpret_cast<int64_t>(target);
3141 // Must record previous source positions before the
3142 // li() generates a new code target.
3143 positions_recorder()->WriteRecordedPositions();
3144 li(t9, Operand(target_int, rmode), ADDRESS_LOAD);
3145 Call(t9, cond, rs, rt, bd);
3146 DCHECK_EQ(CallSize(target, rmode, cond, rs, rt, bd),
3147 SizeOfCodeGeneratedSince(&start));
3151 int MacroAssembler::CallSize(Handle<Code> code,
3152 RelocInfo::Mode rmode,
3153 TypeFeedbackId ast_id,
3157 BranchDelaySlot bd) {
3158 AllowDeferredHandleDereference using_raw_address;
3159 return CallSize(reinterpret_cast<Address>(code.location()),
3160 rmode, cond, rs, rt, bd);
3164 void MacroAssembler::Call(Handle<Code> code,
3165 RelocInfo::Mode rmode,
3166 TypeFeedbackId ast_id,
3170 BranchDelaySlot bd) {
3171 BlockTrampolinePoolScope block_trampoline_pool(this);
3174 DCHECK(RelocInfo::IsCodeTarget(rmode));
3175 if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) {
3176 SetRecordedAstId(ast_id);
3177 rmode = RelocInfo::CODE_TARGET_WITH_ID;
3179 AllowDeferredHandleDereference embedding_raw_address;
3180 Call(reinterpret_cast<Address>(code.location()), rmode, cond, rs, rt, bd);
3181 DCHECK_EQ(CallSize(code, rmode, ast_id, cond, rs, rt, bd),
3182 SizeOfCodeGeneratedSince(&start));
3186 void MacroAssembler::Ret(Condition cond,
3189 BranchDelaySlot bd) {
3190 Jump(ra, cond, rs, rt, bd);
3194 void MacroAssembler::J(Label* L, BranchDelaySlot bdslot) {
3195 BlockTrampolinePoolScope block_trampoline_pool(this);
3197 BlockGrowBufferScope block_buf_growth(this);
3198 // Buffer growth (and relocation) must be blocked for internal references
3199 // until associated instructions are emitted and available to be patched.
3200 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3203 // Emit a nop in the branch delay slot if required.
3204 if (bdslot == PROTECT) nop();
3208 void MacroAssembler::Jal(Label* L, BranchDelaySlot bdslot) {
3209 BlockTrampolinePoolScope block_trampoline_pool(this);
3211 BlockGrowBufferScope block_buf_growth(this);
3212 // Buffer growth (and relocation) must be blocked for internal references
3213 // until associated instructions are emitted and available to be patched.
3214 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3217 // Emit a nop in the branch delay slot if required.
3218 if (bdslot == PROTECT) nop();
3222 void MacroAssembler::Jr(Label* L, BranchDelaySlot bdslot) {
3223 BlockTrampolinePoolScope block_trampoline_pool(this);
3226 imm64 = jump_address(L);
3227 { BlockGrowBufferScope block_buf_growth(this);
3228 // Buffer growth (and relocation) must be blocked for internal references
3229 // until associated instructions are emitted and available to be patched.
3230 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3231 li(at, Operand(imm64), ADDRESS_LOAD);
3235 // Emit a nop in the branch delay slot if required.
3236 if (bdslot == PROTECT)
3241 void MacroAssembler::Jalr(Label* L, BranchDelaySlot bdslot) {
3242 BlockTrampolinePoolScope block_trampoline_pool(this);
3245 imm64 = jump_address(L);
3246 { BlockGrowBufferScope block_buf_growth(this);
3247 // Buffer growth (and relocation) must be blocked for internal references
3248 // until associated instructions are emitted and available to be patched.
3249 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE_ENCODED);
3250 li(at, Operand(imm64), ADDRESS_LOAD);
3254 // Emit a nop in the branch delay slot if required.
3255 if (bdslot == PROTECT)
3260 void MacroAssembler::DropAndRet(int drop) {
3261 DCHECK(is_int16(drop * kPointerSize));
3262 Ret(USE_DELAY_SLOT);
3263 daddiu(sp, sp, drop * kPointerSize);
3266 void MacroAssembler::DropAndRet(int drop,
3269 const Operand& r2) {
3270 // Both Drop and Ret need to be conditional.
3272 if (cond != cc_always) {
3273 Branch(&skip, NegateCondition(cond), r1, r2);
3279 if (cond != cc_always) {
3285 void MacroAssembler::Drop(int count,
3288 const Operand& op) {
3296 Branch(&skip, NegateCondition(cond), reg, op);
3299 Daddu(sp, sp, Operand(count * kPointerSize));
3308 void MacroAssembler::Swap(Register reg1,
3311 if (scratch.is(no_reg)) {
3312 Xor(reg1, reg1, Operand(reg2));
3313 Xor(reg2, reg2, Operand(reg1));
3314 Xor(reg1, reg1, Operand(reg2));
3323 void MacroAssembler::Call(Label* target) {
3324 BranchAndLink(target);
3328 void MacroAssembler::Push(Handle<Object> handle) {
3329 li(at, Operand(handle));
3334 void MacroAssembler::PushRegisterAsTwoSmis(Register src, Register scratch) {
3335 DCHECK(!src.is(scratch));
3337 dsrl32(src, src, 0);
3338 dsll32(src, src, 0);
3340 dsll32(scratch, scratch, 0);
3345 void MacroAssembler::PopRegisterAsTwoSmis(Register dst, Register scratch) {
3346 DCHECK(!dst.is(scratch));
3348 dsrl32(scratch, scratch, 0);
3350 dsrl32(dst, dst, 0);
3351 dsll32(dst, dst, 0);
3352 or_(dst, dst, scratch);
3356 void MacroAssembler::DebugBreak() {
3357 PrepareCEntryArgs(0);
3358 PrepareCEntryFunction(
3359 ExternalReference(Runtime::kHandleDebuggerStatement, isolate()));
3360 CEntryStub ces(isolate(), 1);
3361 DCHECK(AllowThisStubCall(&ces));
3362 Call(ces.GetCode(), RelocInfo::DEBUGGER_STATEMENT);
3366 // ---------------------------------------------------------------------------
3367 // Exception handling.
3369 void MacroAssembler::PushStackHandler() {
3370 // Adjust this code if not the case.
3371 STATIC_ASSERT(StackHandlerConstants::kSize == 1 * kPointerSize);
3372 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
3374 // Link the current handler as the next handler.
3375 li(a6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
3376 ld(a5, MemOperand(a6));
3379 // Set this new handler as the current one.
3380 sd(sp, MemOperand(a6));
3384 void MacroAssembler::PopStackHandler() {
3385 STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
3387 Daddu(sp, sp, Operand(static_cast<int64_t>(StackHandlerConstants::kSize -
3389 li(at, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
3390 sd(a1, MemOperand(at));
3394 void MacroAssembler::Allocate(int object_size,
3399 AllocationFlags flags) {
3400 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize);
3401 if (!FLAG_inline_new) {
3402 if (emit_debug_code()) {
3403 // Trash the registers to simulate an allocation failure.
3405 li(scratch1, 0x7191);
3406 li(scratch2, 0x7291);
3412 DCHECK(!result.is(scratch1));
3413 DCHECK(!result.is(scratch2));
3414 DCHECK(!scratch1.is(scratch2));
3415 DCHECK(!scratch1.is(t9));
3416 DCHECK(!scratch2.is(t9));
3417 DCHECK(!result.is(t9));
3419 // Make object size into bytes.
3420 if ((flags & SIZE_IN_WORDS) != 0) {
3421 object_size *= kPointerSize;
3423 DCHECK(0 == (object_size & kObjectAlignmentMask));
3425 // Check relative positions of allocation top and limit addresses.
3426 // ARM adds additional checks to make sure the ldm instruction can be
3427 // used. On MIPS we don't have ldm so we don't need additional checks either.
3428 ExternalReference allocation_top =
3429 AllocationUtils::GetAllocationTopReference(isolate(), flags);
3430 ExternalReference allocation_limit =
3431 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
3434 reinterpret_cast<intptr_t>(allocation_top.address());
3436 reinterpret_cast<intptr_t>(allocation_limit.address());
3437 DCHECK((limit - top) == kPointerSize);
3439 // Set up allocation top address and object size registers.
3440 Register topaddr = scratch1;
3441 li(topaddr, Operand(allocation_top));
3443 // This code stores a temporary value in t9.
3444 if ((flags & RESULT_CONTAINS_TOP) == 0) {
3445 // Load allocation top into result and allocation limit into t9.
3446 ld(result, MemOperand(topaddr));
3447 ld(t9, MemOperand(topaddr, kPointerSize));
3449 if (emit_debug_code()) {
3450 // Assert that result actually contains top on entry. t9 is used
3451 // immediately below so this use of t9 does not cause difference with
3452 // respect to register content between debug and release mode.
3453 ld(t9, MemOperand(topaddr));
3454 Check(eq, kUnexpectedAllocationTop, result, Operand(t9));
3456 // Load allocation limit into t9. Result already contains allocation top.
3457 ld(t9, MemOperand(topaddr, static_cast<int32_t>(limit - top)));
3460 DCHECK(kPointerSize == kDoubleSize);
3461 if (emit_debug_code()) {
3462 And(at, result, Operand(kDoubleAlignmentMask));
3463 Check(eq, kAllocationIsNotDoubleAligned, at, Operand(zero_reg));
3466 // Calculate new top and bail out if new space is exhausted. Use result
3467 // to calculate the new top.
3468 Daddu(scratch2, result, Operand(object_size));
3469 Branch(gc_required, Ugreater, scratch2, Operand(t9));
3470 sd(scratch2, MemOperand(topaddr));
3472 // Tag object if requested.
3473 if ((flags & TAG_OBJECT) != 0) {
3474 Daddu(result, result, Operand(kHeapObjectTag));
3479 void MacroAssembler::Allocate(Register object_size,
3484 AllocationFlags flags) {
3485 if (!FLAG_inline_new) {
3486 if (emit_debug_code()) {
3487 // Trash the registers to simulate an allocation failure.
3489 li(scratch1, 0x7191);
3490 li(scratch2, 0x7291);
3496 DCHECK(!result.is(scratch1));
3497 DCHECK(!result.is(scratch2));
3498 DCHECK(!scratch1.is(scratch2));
3499 DCHECK(!object_size.is(t9));
3500 DCHECK(!scratch1.is(t9) && !scratch2.is(t9) && !result.is(t9));
3502 // Check relative positions of allocation top and limit addresses.
3503 // ARM adds additional checks to make sure the ldm instruction can be
3504 // used. On MIPS we don't have ldm so we don't need additional checks either.
3505 ExternalReference allocation_top =
3506 AllocationUtils::GetAllocationTopReference(isolate(), flags);
3507 ExternalReference allocation_limit =
3508 AllocationUtils::GetAllocationLimitReference(isolate(), flags);
3510 reinterpret_cast<intptr_t>(allocation_top.address());
3512 reinterpret_cast<intptr_t>(allocation_limit.address());
3513 DCHECK((limit - top) == kPointerSize);
3515 // Set up allocation top address and object size registers.
3516 Register topaddr = scratch1;
3517 li(topaddr, Operand(allocation_top));
3519 // This code stores a temporary value in t9.
3520 if ((flags & RESULT_CONTAINS_TOP) == 0) {
3521 // Load allocation top into result and allocation limit into t9.
3522 ld(result, MemOperand(topaddr));
3523 ld(t9, MemOperand(topaddr, kPointerSize));
3525 if (emit_debug_code()) {
3526 // Assert that result actually contains top on entry. t9 is used
3527 // immediately below so this use of t9 does not cause difference with
3528 // respect to register content between debug and release mode.
3529 ld(t9, MemOperand(topaddr));
3530 Check(eq, kUnexpectedAllocationTop, result, Operand(t9));
3532 // Load allocation limit into t9. Result already contains allocation top.
3533 ld(t9, MemOperand(topaddr, static_cast<int32_t>(limit - top)));
3536 DCHECK(kPointerSize == kDoubleSize);
3537 if (emit_debug_code()) {
3538 And(at, result, Operand(kDoubleAlignmentMask));
3539 Check(eq, kAllocationIsNotDoubleAligned, at, Operand(zero_reg));
3542 // Calculate new top and bail out if new space is exhausted. Use result
3543 // to calculate the new top. Object size may be in words so a shift is
3544 // required to get the number of bytes.
3545 if ((flags & SIZE_IN_WORDS) != 0) {
3546 dsll(scratch2, object_size, kPointerSizeLog2);
3547 Daddu(scratch2, result, scratch2);
3549 Daddu(scratch2, result, Operand(object_size));
3551 Branch(gc_required, Ugreater, scratch2, Operand(t9));
3553 // Update allocation top. result temporarily holds the new top.
3554 if (emit_debug_code()) {
3555 And(t9, scratch2, Operand(kObjectAlignmentMask));
3556 Check(eq, kUnalignedAllocationInNewSpace, t9, Operand(zero_reg));
3558 sd(scratch2, MemOperand(topaddr));
3560 // Tag object if requested.
3561 if ((flags & TAG_OBJECT) != 0) {
3562 Daddu(result, result, Operand(kHeapObjectTag));
3567 void MacroAssembler::AllocateTwoByteString(Register result,
3572 Label* gc_required) {
3573 // Calculate the number of bytes needed for the characters in the string while
3574 // observing object alignment.
3575 DCHECK((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3576 dsll(scratch1, length, 1); // Length in bytes, not chars.
3577 daddiu(scratch1, scratch1,
3578 kObjectAlignmentMask + SeqTwoByteString::kHeaderSize);
3579 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
3581 // Allocate two-byte string in new space.
3589 // Set the map, length and hash field.
3590 InitializeNewString(result,
3592 Heap::kStringMapRootIndex,
3598 void MacroAssembler::AllocateOneByteString(Register result, Register length,
3599 Register scratch1, Register scratch2,
3601 Label* gc_required) {
3602 // Calculate the number of bytes needed for the characters in the string
3603 // while observing object alignment.
3604 DCHECK((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3605 DCHECK(kCharSize == 1);
3606 daddiu(scratch1, length,
3607 kObjectAlignmentMask + SeqOneByteString::kHeaderSize);
3608 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
3610 // Allocate one-byte string in new space.
3618 // Set the map, length and hash field.
3619 InitializeNewString(result, length, Heap::kOneByteStringMapRootIndex,
3620 scratch1, scratch2);
3624 void MacroAssembler::AllocateTwoByteConsString(Register result,
3628 Label* gc_required) {
3629 Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required,
3631 InitializeNewString(result,
3633 Heap::kConsStringMapRootIndex,
3639 void MacroAssembler::AllocateOneByteConsString(Register result, Register length,
3642 Label* gc_required) {
3643 Allocate(ConsString::kSize,
3650 InitializeNewString(result, length, Heap::kConsOneByteStringMapRootIndex,
3651 scratch1, scratch2);
3655 void MacroAssembler::AllocateTwoByteSlicedString(Register result,
3659 Label* gc_required) {
3660 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
3663 InitializeNewString(result,
3665 Heap::kSlicedStringMapRootIndex,
3671 void MacroAssembler::AllocateOneByteSlicedString(Register result,
3675 Label* gc_required) {
3676 Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required,
3679 InitializeNewString(result, length, Heap::kSlicedOneByteStringMapRootIndex,
3680 scratch1, scratch2);
3684 void MacroAssembler::JumpIfNotUniqueNameInstanceType(Register reg,
3685 Label* not_unique_name) {
3686 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3688 And(at, reg, Operand(kIsNotStringMask | kIsNotInternalizedMask));
3689 Branch(&succeed, eq, at, Operand(zero_reg));
3690 Branch(not_unique_name, ne, reg, Operand(SYMBOL_TYPE));
3696 // Allocates a heap number or jumps to the label if the young space is full and
3697 // a scavenge is needed.
3698 void MacroAssembler::AllocateHeapNumber(Register result,
3701 Register heap_number_map,
3703 TaggingMode tagging_mode,
3705 // Allocate an object in the heap for the heap number and tag it as a heap
3707 Allocate(HeapNumber::kSize, result, scratch1, scratch2, need_gc,
3708 tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS);
3710 Heap::RootListIndex map_index = mode == MUTABLE
3711 ? Heap::kMutableHeapNumberMapRootIndex
3712 : Heap::kHeapNumberMapRootIndex;
3713 AssertIsRoot(heap_number_map, map_index);
3715 // Store heap number map in the allocated object.
3716 if (tagging_mode == TAG_RESULT) {
3717 sd(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
3719 sd(heap_number_map, MemOperand(result, HeapObject::kMapOffset));
3724 void MacroAssembler::AllocateHeapNumberWithValue(Register result,
3728 Label* gc_required) {
3729 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
3730 AllocateHeapNumber(result, scratch1, scratch2, t8, gc_required);
3731 sdc1(value, FieldMemOperand(result, HeapNumber::kValueOffset));
3735 // Copies a fixed number of fields of heap objects from src to dst.
3736 void MacroAssembler::CopyFields(Register dst,
3740 DCHECK((temps & dst.bit()) == 0);
3741 DCHECK((temps & src.bit()) == 0);
3742 // Primitive implementation using only one temporary register.
3744 Register tmp = no_reg;
3745 // Find a temp register in temps list.
3746 for (int i = 0; i < kNumRegisters; i++) {
3747 if ((temps & (1 << i)) != 0) {
3752 DCHECK(!tmp.is(no_reg));
3754 for (int i = 0; i < field_count; i++) {
3755 ld(tmp, FieldMemOperand(src, i * kPointerSize));
3756 sd(tmp, FieldMemOperand(dst, i * kPointerSize));
3761 void MacroAssembler::CopyBytes(Register src,
3765 Label align_loop_1, word_loop, byte_loop, byte_loop_1, done;
3767 // Align src before copying in word size chunks.
3768 Branch(&byte_loop, le, length, Operand(kPointerSize));
3769 bind(&align_loop_1);
3770 And(scratch, src, kPointerSize - 1);
3771 Branch(&word_loop, eq, scratch, Operand(zero_reg));
3772 lbu(scratch, MemOperand(src));
3774 sb(scratch, MemOperand(dst));
3776 Dsubu(length, length, Operand(1));
3777 Branch(&align_loop_1, ne, length, Operand(zero_reg));
3779 // Copy bytes in word size chunks.
3781 if (emit_debug_code()) {
3782 And(scratch, src, kPointerSize - 1);
3783 Assert(eq, kExpectingAlignmentForCopyBytes,
3784 scratch, Operand(zero_reg));
3786 Branch(&byte_loop, lt, length, Operand(kPointerSize));
3787 ld(scratch, MemOperand(src));
3788 Daddu(src, src, kPointerSize);
3790 // TODO(kalmard) check if this can be optimized to use sw in most cases.
3791 // Can't use unaligned access - copy byte by byte.
3792 sb(scratch, MemOperand(dst, 0));
3793 dsrl(scratch, scratch, 8);
3794 sb(scratch, MemOperand(dst, 1));
3795 dsrl(scratch, scratch, 8);
3796 sb(scratch, MemOperand(dst, 2));
3797 dsrl(scratch, scratch, 8);
3798 sb(scratch, MemOperand(dst, 3));
3799 dsrl(scratch, scratch, 8);
3800 sb(scratch, MemOperand(dst, 4));
3801 dsrl(scratch, scratch, 8);
3802 sb(scratch, MemOperand(dst, 5));
3803 dsrl(scratch, scratch, 8);
3804 sb(scratch, MemOperand(dst, 6));
3805 dsrl(scratch, scratch, 8);
3806 sb(scratch, MemOperand(dst, 7));
3809 Dsubu(length, length, Operand(kPointerSize));
3812 // Copy the last bytes if any left.
3814 Branch(&done, eq, length, Operand(zero_reg));
3816 lbu(scratch, MemOperand(src));
3818 sb(scratch, MemOperand(dst));
3820 Dsubu(length, length, Operand(1));
3821 Branch(&byte_loop_1, ne, length, Operand(zero_reg));
3826 void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
3827 Register end_offset,
3832 sd(filler, MemOperand(start_offset));
3833 Daddu(start_offset, start_offset, kPointerSize);
3835 Branch(&loop, ult, start_offset, Operand(end_offset));
3839 void MacroAssembler::CheckFastElements(Register map,
3842 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3843 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3844 STATIC_ASSERT(FAST_ELEMENTS == 2);
3845 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
3846 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3847 Branch(fail, hi, scratch,
3848 Operand(Map::kMaximumBitField2FastHoleyElementValue));
3852 void MacroAssembler::CheckFastObjectElements(Register map,
3855 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3856 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3857 STATIC_ASSERT(FAST_ELEMENTS == 2);
3858 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
3859 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3860 Branch(fail, ls, scratch,
3861 Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
3862 Branch(fail, hi, scratch,
3863 Operand(Map::kMaximumBitField2FastHoleyElementValue));
3867 void MacroAssembler::CheckFastSmiElements(Register map,
3870 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
3871 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
3872 lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset));
3873 Branch(fail, hi, scratch,
3874 Operand(Map::kMaximumBitField2FastHoleySmiElementValue));
3878 void MacroAssembler::StoreNumberToDoubleElements(Register value_reg,
3880 Register elements_reg,
3884 int elements_offset) {
3885 Label smi_value, done;
3887 // Handle smi values specially.
3888 JumpIfSmi(value_reg, &smi_value);
3890 // Ensure that the object is a heap number.
3893 Heap::kHeapNumberMapRootIndex,
3897 // Double value, turn potential sNaN into qNan.
3898 DoubleRegister double_result = f0;
3899 DoubleRegister double_scratch = f2;
3901 ldc1(double_result, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
3902 Branch(USE_DELAY_SLOT, &done); // Canonicalization is one instruction.
3903 FPUCanonicalizeNaN(double_result, double_result);
3906 // scratch1 is now effective address of the double element.
3907 // Untag and transfer.
3908 dsrl32(at, value_reg, 0);
3909 mtc1(at, double_scratch);
3910 cvt_d_w(double_result, double_scratch);
3913 Daddu(scratch1, elements_reg,
3914 Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag -
3916 dsra(scratch2, key_reg, 32 - kDoubleSizeLog2);
3917 Daddu(scratch1, scratch1, scratch2);
3918 sdc1(double_result, MemOperand(scratch1, 0));
3922 void MacroAssembler::CompareMapAndBranch(Register obj,
3925 Label* early_success,
3928 ld(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
3929 CompareMapAndBranch(scratch, map, early_success, cond, branch_to);
3933 void MacroAssembler::CompareMapAndBranch(Register obj_map,
3935 Label* early_success,
3938 Branch(branch_to, cond, obj_map, Operand(map));
3942 void MacroAssembler::CheckMap(Register obj,
3946 SmiCheckType smi_check_type) {
3947 if (smi_check_type == DO_SMI_CHECK) {
3948 JumpIfSmi(obj, fail);
3951 CompareMapAndBranch(obj, scratch, map, &success, ne, fail);
3956 void MacroAssembler::DispatchWeakMap(Register obj, Register scratch1,
3957 Register scratch2, Handle<WeakCell> cell,
3958 Handle<Code> success,
3959 SmiCheckType smi_check_type) {
3961 if (smi_check_type == DO_SMI_CHECK) {
3962 JumpIfSmi(obj, &fail);
3964 ld(scratch1, FieldMemOperand(obj, HeapObject::kMapOffset));
3965 GetWeakValue(scratch2, cell);
3966 Jump(success, RelocInfo::CODE_TARGET, eq, scratch1, Operand(scratch2));
3971 void MacroAssembler::CheckMap(Register obj,
3973 Heap::RootListIndex index,
3975 SmiCheckType smi_check_type) {
3976 if (smi_check_type == DO_SMI_CHECK) {
3977 JumpIfSmi(obj, fail);
3979 ld(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
3980 LoadRoot(at, index);
3981 Branch(fail, ne, scratch, Operand(at));
3985 void MacroAssembler::GetWeakValue(Register value, Handle<WeakCell> cell) {
3986 li(value, Operand(cell));
3987 ld(value, FieldMemOperand(value, WeakCell::kValueOffset));
3990 void MacroAssembler::FPUCanonicalizeNaN(const DoubleRegister dst,
3991 const DoubleRegister src) {
3992 sub_d(dst, src, kDoubleRegZero);
3995 void MacroAssembler::LoadWeakValue(Register value, Handle<WeakCell> cell,
3997 GetWeakValue(value, cell);
3998 JumpIfSmi(value, miss);
4002 void MacroAssembler::MovFromFloatResult(const DoubleRegister dst) {
4003 if (IsMipsSoftFloatABI) {
4006 Move(dst, f0); // Reg f0 is o32 ABI FP return value.
4011 void MacroAssembler::MovFromFloatParameter(const DoubleRegister dst) {
4012 if (IsMipsSoftFloatABI) {
4015 Move(dst, f12); // Reg f12 is o32 ABI FP first argument value.
4020 void MacroAssembler::MovToFloatParameter(DoubleRegister src) {
4021 if (!IsMipsSoftFloatABI) {
4029 void MacroAssembler::MovToFloatResult(DoubleRegister src) {
4030 if (!IsMipsSoftFloatABI) {
4038 void MacroAssembler::MovToFloatParameters(DoubleRegister src1,
4039 DoubleRegister src2) {
4040 if (!IsMipsSoftFloatABI) {
4041 const DoubleRegister fparg2 = (kMipsAbi == kN64) ? f13 : f14;
4043 DCHECK(!src1.is(fparg2));
4057 // -----------------------------------------------------------------------------
4058 // JavaScript invokes.
4060 void MacroAssembler::InvokePrologue(const ParameterCount& expected,
4061 const ParameterCount& actual,
4062 Handle<Code> code_constant,
4065 bool* definitely_mismatches,
4067 const CallWrapper& call_wrapper) {
4068 bool definitely_matches = false;
4069 *definitely_mismatches = false;
4070 Label regular_invoke;
4072 // Check whether the expected and actual arguments count match. If not,
4073 // setup registers according to contract with ArgumentsAdaptorTrampoline:
4074 // a0: actual arguments count
4075 // a1: function (passed through to callee)
4076 // a2: expected arguments count
4078 // The code below is made a lot easier because the calling code already sets
4079 // up actual and expected registers according to the contract if values are
4080 // passed in registers.
4081 DCHECK(actual.is_immediate() || actual.reg().is(a0));
4082 DCHECK(expected.is_immediate() || expected.reg().is(a2));
4083 DCHECK((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(a3));
4085 if (expected.is_immediate()) {
4086 DCHECK(actual.is_immediate());
4087 if (expected.immediate() == actual.immediate()) {
4088 definitely_matches = true;
4090 li(a0, Operand(actual.immediate()));
4091 const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
4092 if (expected.immediate() == sentinel) {
4093 // Don't worry about adapting arguments for builtins that
4094 // don't want that done. Skip adaption code by making it look
4095 // like we have a match between expected and actual number of
4097 definitely_matches = true;
4099 *definitely_mismatches = true;
4100 li(a2, Operand(expected.immediate()));
4103 } else if (actual.is_immediate()) {
4104 Branch(®ular_invoke, eq, expected.reg(), Operand(actual.immediate()));
4105 li(a0, Operand(actual.immediate()));
4107 Branch(®ular_invoke, eq, expected.reg(), Operand(actual.reg()));
4110 if (!definitely_matches) {
4111 if (!code_constant.is_null()) {
4112 li(a3, Operand(code_constant));
4113 daddiu(a3, a3, Code::kHeaderSize - kHeapObjectTag);
4116 Handle<Code> adaptor =
4117 isolate()->builtins()->ArgumentsAdaptorTrampoline();
4118 if (flag == CALL_FUNCTION) {
4119 call_wrapper.BeforeCall(CallSize(adaptor));
4121 call_wrapper.AfterCall();
4122 if (!*definitely_mismatches) {
4126 Jump(adaptor, RelocInfo::CODE_TARGET);
4128 bind(®ular_invoke);
4133 void MacroAssembler::InvokeCode(Register code,
4134 const ParameterCount& expected,
4135 const ParameterCount& actual,
4137 const CallWrapper& call_wrapper) {
4138 // You can't call a function without a valid frame.
4139 DCHECK(flag == JUMP_FUNCTION || has_frame());
4143 bool definitely_mismatches = false;
4144 InvokePrologue(expected, actual, Handle<Code>::null(), code,
4145 &done, &definitely_mismatches, flag,
4147 if (!definitely_mismatches) {
4148 if (flag == CALL_FUNCTION) {
4149 call_wrapper.BeforeCall(CallSize(code));
4151 call_wrapper.AfterCall();
4153 DCHECK(flag == JUMP_FUNCTION);
4156 // Continue here if InvokePrologue does handle the invocation due to
4157 // mismatched parameter counts.
4163 void MacroAssembler::InvokeFunction(Register function,
4164 const ParameterCount& actual,
4166 const CallWrapper& call_wrapper) {
4167 // You can't call a function without a valid frame.
4168 DCHECK(flag == JUMP_FUNCTION || has_frame());
4170 // Contract with called JS functions requires that function is passed in a1.
4171 DCHECK(function.is(a1));
4172 Register expected_reg = a2;
4173 Register code_reg = a3;
4174 ld(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
4175 ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4176 // The argument count is stored as int32_t on 64-bit platforms.
4177 // TODO(plind): Smi on 32-bit platforms.
4179 FieldMemOperand(code_reg,
4180 SharedFunctionInfo::kFormalParameterCountOffset));
4181 ld(code_reg, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4182 ParameterCount expected(expected_reg);
4183 InvokeCode(code_reg, expected, actual, flag, call_wrapper);
4187 void MacroAssembler::InvokeFunction(Register function,
4188 const ParameterCount& expected,
4189 const ParameterCount& actual,
4191 const CallWrapper& call_wrapper) {
4192 // You can't call a function without a valid frame.
4193 DCHECK(flag == JUMP_FUNCTION || has_frame());
4195 // Contract with called JS functions requires that function is passed in a1.
4196 DCHECK(function.is(a1));
4198 // Get the function and setup the context.
4199 ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
4201 // We call indirectly through the code field in the function to
4202 // allow recompilation to take effect without changing any of the
4204 ld(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4205 InvokeCode(a3, expected, actual, flag, call_wrapper);
4209 void MacroAssembler::InvokeFunction(Handle<JSFunction> function,
4210 const ParameterCount& expected,
4211 const ParameterCount& actual,
4213 const CallWrapper& call_wrapper) {
4215 InvokeFunction(a1, expected, actual, flag, call_wrapper);
4219 void MacroAssembler::IsObjectJSObjectType(Register heap_object,
4223 ld(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
4224 IsInstanceJSObjectType(map, scratch, fail);
4228 void MacroAssembler::IsInstanceJSObjectType(Register map,
4231 lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
4232 Branch(fail, lt, scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE));
4233 Branch(fail, gt, scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
4237 void MacroAssembler::IsObjectJSStringType(Register object,
4240 DCHECK(kNotStringTag != 0);
4242 ld(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4243 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4244 And(scratch, scratch, Operand(kIsNotStringMask));
4245 Branch(fail, ne, scratch, Operand(zero_reg));
4249 void MacroAssembler::IsObjectNameType(Register object,
4252 ld(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
4253 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
4254 Branch(fail, hi, scratch, Operand(LAST_NAME_TYPE));
4258 // ---------------------------------------------------------------------------
4259 // Support functions.
4262 void MacroAssembler::GetMapConstructor(Register result, Register map,
4263 Register temp, Register temp2) {
4265 ld(result, FieldMemOperand(map, Map::kConstructorOrBackPointerOffset));
4267 JumpIfSmi(result, &done);
4268 GetObjectType(result, temp, temp2);
4269 Branch(&done, ne, temp2, Operand(MAP_TYPE));
4270 ld(result, FieldMemOperand(result, Map::kConstructorOrBackPointerOffset));
4276 void MacroAssembler::TryGetFunctionPrototype(Register function, Register result,
4277 Register scratch, Label* miss) {
4278 // Get the prototype or initial map from the function.
4280 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
4282 // If the prototype or initial map is the hole, don't return it and
4283 // simply miss the cache instead. This will allow us to allocate a
4284 // prototype object on-demand in the runtime system.
4285 LoadRoot(t8, Heap::kTheHoleValueRootIndex);
4286 Branch(miss, eq, result, Operand(t8));
4288 // If the function does not have an initial map, we're done.
4290 GetObjectType(result, scratch, scratch);
4291 Branch(&done, ne, scratch, Operand(MAP_TYPE));
4293 // Get the prototype from the initial map.
4294 ld(result, FieldMemOperand(result, Map::kPrototypeOffset));
4301 void MacroAssembler::GetObjectType(Register object,
4303 Register type_reg) {
4304 ld(map, FieldMemOperand(object, HeapObject::kMapOffset));
4305 lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
4309 // -----------------------------------------------------------------------------
4312 void MacroAssembler::CallStub(CodeStub* stub,
4313 TypeFeedbackId ast_id,
4317 BranchDelaySlot bd) {
4318 DCHECK(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs.
4319 Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id,
4324 void MacroAssembler::TailCallStub(CodeStub* stub,
4328 BranchDelaySlot bd) {
4329 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond, r1, r2, bd);
4333 bool MacroAssembler::AllowThisStubCall(CodeStub* stub) {
4334 return has_frame_ || !stub->SometimesSetsUpAFrame();
4338 void MacroAssembler::IndexFromHash(Register hash, Register index) {
4339 // If the hash field contains an array index pick it out. The assert checks
4340 // that the constants for the maximum number of digits for an array index
4341 // cached in the hash field and the number of bits reserved for it does not
4343 DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) <
4344 (1 << String::kArrayIndexValueBits));
4345 DecodeFieldToSmi<String::ArrayIndexValueBits>(index, hash);
4349 void MacroAssembler::ObjectToDoubleFPURegister(Register object,
4353 Register heap_number_map,
4355 ObjectToDoubleFlags flags) {
4357 if ((flags & OBJECT_NOT_SMI) == 0) {
4359 JumpIfNotSmi(object, ¬_smi);
4360 // Remove smi tag and convert to double.
4361 // dsra(scratch1, object, kSmiTagSize);
4362 dsra32(scratch1, object, 0);
4363 mtc1(scratch1, result);
4364 cvt_d_w(result, result);
4368 // Check for heap number and load double value from it.
4369 ld(scratch1, FieldMemOperand(object, HeapObject::kMapOffset));
4370 Branch(not_number, ne, scratch1, Operand(heap_number_map));
4372 if ((flags & AVOID_NANS_AND_INFINITIES) != 0) {
4373 // If exponent is all ones the number is either a NaN or +/-Infinity.
4374 Register exponent = scratch1;
4375 Register mask_reg = scratch2;
4376 lwu(exponent, FieldMemOperand(object, HeapNumber::kExponentOffset));
4377 li(mask_reg, HeapNumber::kExponentMask);
4379 And(exponent, exponent, mask_reg);
4380 Branch(not_number, eq, exponent, Operand(mask_reg));
4382 ldc1(result, FieldMemOperand(object, HeapNumber::kValueOffset));
4387 void MacroAssembler::SmiToDoubleFPURegister(Register smi,
4389 Register scratch1) {
4390 dsra32(scratch1, smi, 0);
4391 mtc1(scratch1, value);
4392 cvt_d_w(value, value);
4396 void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
4397 const Operand& right,
4398 Register overflow_dst,
4400 if (right.is_reg()) {
4401 AdduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4404 li(t9, right); // Load right.
4405 mov(scratch, left); // Preserve left.
4406 addu(dst, left, t9); // Left is overwritten.
4407 xor_(scratch, dst, scratch); // Original left.
4408 xor_(overflow_dst, dst, t9);
4409 and_(overflow_dst, overflow_dst, scratch);
4412 addu(dst, left, t9);
4413 xor_(overflow_dst, dst, left);
4414 xor_(scratch, dst, t9);
4415 and_(overflow_dst, scratch, overflow_dst);
4421 void MacroAssembler::AdduAndCheckForOverflow(Register dst, Register left,
4423 Register overflow_dst,
4425 DCHECK(!dst.is(overflow_dst));
4426 DCHECK(!dst.is(scratch));
4427 DCHECK(!overflow_dst.is(scratch));
4428 DCHECK(!overflow_dst.is(left));
4429 DCHECK(!overflow_dst.is(right));
4431 if (left.is(right) && dst.is(left)) {
4432 DCHECK(!dst.is(t9));
4433 DCHECK(!scratch.is(t9));
4434 DCHECK(!left.is(t9));
4435 DCHECK(!right.is(t9));
4436 DCHECK(!overflow_dst.is(t9));
4442 mov(scratch, left); // Preserve left.
4443 addu(dst, left, right); // Left is overwritten.
4444 xor_(scratch, dst, scratch); // Original left.
4445 xor_(overflow_dst, dst, right);
4446 and_(overflow_dst, overflow_dst, scratch);
4447 } else if (dst.is(right)) {
4448 mov(scratch, right); // Preserve right.
4449 addu(dst, left, right); // Right is overwritten.
4450 xor_(scratch, dst, scratch); // Original right.
4451 xor_(overflow_dst, dst, left);
4452 and_(overflow_dst, overflow_dst, scratch);
4454 addu(dst, left, right);
4455 xor_(overflow_dst, dst, left);
4456 xor_(scratch, dst, right);
4457 and_(overflow_dst, scratch, overflow_dst);
4462 void MacroAssembler::DadduAndCheckForOverflow(Register dst, Register left,
4463 const Operand& right,
4464 Register overflow_dst,
4466 if (right.is_reg()) {
4467 DadduAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4470 li(t9, right); // Load right.
4471 mov(scratch, left); // Preserve left.
4472 daddu(dst, left, t9); // Left is overwritten.
4473 xor_(scratch, dst, scratch); // Original left.
4474 xor_(overflow_dst, dst, t9);
4475 and_(overflow_dst, overflow_dst, scratch);
4477 li(t9, right); // Load right.
4478 Daddu(dst, left, t9);
4479 xor_(overflow_dst, dst, left);
4480 xor_(scratch, dst, t9);
4481 and_(overflow_dst, scratch, overflow_dst);
4487 void MacroAssembler::DadduAndCheckForOverflow(Register dst, Register left,
4489 Register overflow_dst,
4491 DCHECK(!dst.is(overflow_dst));
4492 DCHECK(!dst.is(scratch));
4493 DCHECK(!overflow_dst.is(scratch));
4494 DCHECK(!overflow_dst.is(left));
4495 DCHECK(!overflow_dst.is(right));
4497 if (left.is(right) && dst.is(left)) {
4498 DCHECK(!dst.is(t9));
4499 DCHECK(!scratch.is(t9));
4500 DCHECK(!left.is(t9));
4501 DCHECK(!right.is(t9));
4502 DCHECK(!overflow_dst.is(t9));
4508 mov(scratch, left); // Preserve left.
4509 daddu(dst, left, right); // Left is overwritten.
4510 xor_(scratch, dst, scratch); // Original left.
4511 xor_(overflow_dst, dst, right);
4512 and_(overflow_dst, overflow_dst, scratch);
4513 } else if (dst.is(right)) {
4514 mov(scratch, right); // Preserve right.
4515 daddu(dst, left, right); // Right is overwritten.
4516 xor_(scratch, dst, scratch); // Original right.
4517 xor_(overflow_dst, dst, left);
4518 and_(overflow_dst, overflow_dst, scratch);
4520 daddu(dst, left, right);
4521 xor_(overflow_dst, dst, left);
4522 xor_(scratch, dst, right);
4523 and_(overflow_dst, scratch, overflow_dst);
4528 void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
4529 const Operand& right,
4530 Register overflow_dst,
4532 if (right.is_reg()) {
4533 SubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4536 li(t9, right); // Load right.
4537 mov(scratch, left); // Preserve left.
4538 Subu(dst, left, t9); // Left is overwritten.
4539 xor_(overflow_dst, dst, scratch); // scratch is original left.
4540 xor_(scratch, scratch, t9); // scratch is original left.
4541 and_(overflow_dst, scratch, overflow_dst);
4544 subu(dst, left, t9);
4545 xor_(overflow_dst, dst, left);
4546 xor_(scratch, left, t9);
4547 and_(overflow_dst, scratch, overflow_dst);
4553 void MacroAssembler::SubuAndCheckForOverflow(Register dst, Register left,
4555 Register overflow_dst,
4557 DCHECK(!dst.is(overflow_dst));
4558 DCHECK(!dst.is(scratch));
4559 DCHECK(!overflow_dst.is(scratch));
4560 DCHECK(!overflow_dst.is(left));
4561 DCHECK(!overflow_dst.is(right));
4562 DCHECK(!scratch.is(left));
4563 DCHECK(!scratch.is(right));
4565 // This happens with some crankshaft code. Since Subu works fine if
4566 // left == right, let's not make that restriction here.
4567 if (left.is(right)) {
4569 mov(overflow_dst, zero_reg);
4574 mov(scratch, left); // Preserve left.
4575 subu(dst, left, right); // Left is overwritten.
4576 xor_(overflow_dst, dst, scratch); // scratch is original left.
4577 xor_(scratch, scratch, right); // scratch is original left.
4578 and_(overflow_dst, scratch, overflow_dst);
4579 } else if (dst.is(right)) {
4580 mov(scratch, right); // Preserve right.
4581 subu(dst, left, right); // Right is overwritten.
4582 xor_(overflow_dst, dst, left);
4583 xor_(scratch, left, scratch); // Original right.
4584 and_(overflow_dst, scratch, overflow_dst);
4586 subu(dst, left, right);
4587 xor_(overflow_dst, dst, left);
4588 xor_(scratch, left, right);
4589 and_(overflow_dst, scratch, overflow_dst);
4594 void MacroAssembler::DsubuAndCheckForOverflow(Register dst, Register left,
4595 const Operand& right,
4596 Register overflow_dst,
4598 if (right.is_reg()) {
4599 DsubuAndCheckForOverflow(dst, left, right.rm(), overflow_dst, scratch);
4602 li(t9, right); // Load right.
4603 mov(scratch, left); // Preserve left.
4604 dsubu(dst, left, t9); // Left is overwritten.
4605 xor_(overflow_dst, dst, scratch); // scratch is original left.
4606 xor_(scratch, scratch, t9); // scratch is original left.
4607 and_(overflow_dst, scratch, overflow_dst);
4610 dsubu(dst, left, t9);
4611 xor_(overflow_dst, dst, left);
4612 xor_(scratch, left, t9);
4613 and_(overflow_dst, scratch, overflow_dst);
4619 void MacroAssembler::DsubuAndCheckForOverflow(Register dst, Register left,
4621 Register overflow_dst,
4623 DCHECK(!dst.is(overflow_dst));
4624 DCHECK(!dst.is(scratch));
4625 DCHECK(!overflow_dst.is(scratch));
4626 DCHECK(!overflow_dst.is(left));
4627 DCHECK(!overflow_dst.is(right));
4628 DCHECK(!scratch.is(left));
4629 DCHECK(!scratch.is(right));
4631 // This happens with some crankshaft code. Since Subu works fine if
4632 // left == right, let's not make that restriction here.
4633 if (left.is(right)) {
4635 mov(overflow_dst, zero_reg);
4640 mov(scratch, left); // Preserve left.
4641 dsubu(dst, left, right); // Left is overwritten.
4642 xor_(overflow_dst, dst, scratch); // scratch is original left.
4643 xor_(scratch, scratch, right); // scratch is original left.
4644 and_(overflow_dst, scratch, overflow_dst);
4645 } else if (dst.is(right)) {
4646 mov(scratch, right); // Preserve right.
4647 dsubu(dst, left, right); // Right is overwritten.
4648 xor_(overflow_dst, dst, left);
4649 xor_(scratch, left, scratch); // Original right.
4650 and_(overflow_dst, scratch, overflow_dst);
4652 dsubu(dst, left, right);
4653 xor_(overflow_dst, dst, left);
4654 xor_(scratch, left, right);
4655 and_(overflow_dst, scratch, overflow_dst);
4659 void MacroAssembler::CallRuntime(const Runtime::Function* f, int num_arguments,
4660 SaveFPRegsMode save_doubles,
4661 BranchDelaySlot bd) {
4662 // All parameters are on the stack. v0 has the return value after call.
4664 // If the expected number of arguments of the runtime function is
4665 // constant, we check that the actual number of arguments match the
4667 CHECK(f->nargs < 0 || f->nargs == num_arguments);
4669 // TODO(1236192): Most runtime routines don't need the number of
4670 // arguments passed in because it is constant. At some point we
4671 // should remove this need and make the runtime routine entry code
4673 PrepareCEntryArgs(num_arguments);
4674 PrepareCEntryFunction(ExternalReference(f, isolate()));
4675 CEntryStub stub(isolate(), 1, save_doubles);
4676 CallStub(&stub, TypeFeedbackId::None(), al, zero_reg, Operand(zero_reg), bd);
4680 void MacroAssembler::CallExternalReference(const ExternalReference& ext,
4682 BranchDelaySlot bd) {
4683 PrepareCEntryArgs(num_arguments);
4684 PrepareCEntryFunction(ext);
4686 CEntryStub stub(isolate(), 1);
4687 CallStub(&stub, TypeFeedbackId::None(), al, zero_reg, Operand(zero_reg), bd);
4691 void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
4694 // TODO(1236192): Most runtime routines don't need the number of
4695 // arguments passed in because it is constant. At some point we
4696 // should remove this need and make the runtime routine entry code
4698 PrepareCEntryArgs(num_arguments);
4699 JumpToExternalReference(ext);
4703 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
4706 TailCallExternalReference(ExternalReference(fid, isolate()),
4712 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin,
4713 BranchDelaySlot bd) {
4714 PrepareCEntryFunction(builtin);
4715 CEntryStub stub(isolate(), 1);
4716 Jump(stub.GetCode(),
4717 RelocInfo::CODE_TARGET,
4725 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
4727 const CallWrapper& call_wrapper) {
4728 // You can't call a builtin without a valid frame.
4729 DCHECK(flag == JUMP_FUNCTION || has_frame());
4731 GetBuiltinEntry(t9, id);
4732 if (flag == CALL_FUNCTION) {
4733 call_wrapper.BeforeCall(CallSize(t9));
4735 call_wrapper.AfterCall();
4737 DCHECK(flag == JUMP_FUNCTION);
4743 void MacroAssembler::GetBuiltinFunction(Register target,
4744 Builtins::JavaScript id) {
4745 // Load the builtins object into target register.
4746 ld(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4747 ld(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
4748 // Load the JavaScript builtin function from the builtins object.
4749 ld(target, FieldMemOperand(target,
4750 JSBuiltinsObject::OffsetOfFunctionWithId(id)));
4754 void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
4755 DCHECK(!target.is(a1));
4756 GetBuiltinFunction(a1, id);
4757 // Load the code entry point from the builtins object.
4758 ld(target, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
4762 void MacroAssembler::SetCounter(StatsCounter* counter, int value,
4763 Register scratch1, Register scratch2) {
4764 if (FLAG_native_code_counters && counter->Enabled()) {
4765 li(scratch1, Operand(value));
4766 li(scratch2, Operand(ExternalReference(counter)));
4767 sd(scratch1, MemOperand(scratch2));
4772 void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
4773 Register scratch1, Register scratch2) {
4775 if (FLAG_native_code_counters && counter->Enabled()) {
4776 li(scratch2, Operand(ExternalReference(counter)));
4777 ld(scratch1, MemOperand(scratch2));
4778 Daddu(scratch1, scratch1, Operand(value));
4779 sd(scratch1, MemOperand(scratch2));
4784 void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
4785 Register scratch1, Register scratch2) {
4787 if (FLAG_native_code_counters && counter->Enabled()) {
4788 li(scratch2, Operand(ExternalReference(counter)));
4789 ld(scratch1, MemOperand(scratch2));
4790 Dsubu(scratch1, scratch1, Operand(value));
4791 sd(scratch1, MemOperand(scratch2));
4796 // -----------------------------------------------------------------------------
4799 void MacroAssembler::Assert(Condition cc, BailoutReason reason,
4800 Register rs, Operand rt) {
4801 if (emit_debug_code())
4802 Check(cc, reason, rs, rt);
4806 void MacroAssembler::AssertFastElements(Register elements) {
4807 if (emit_debug_code()) {
4808 DCHECK(!elements.is(at));
4811 ld(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
4812 LoadRoot(at, Heap::kFixedArrayMapRootIndex);
4813 Branch(&ok, eq, elements, Operand(at));
4814 LoadRoot(at, Heap::kFixedDoubleArrayMapRootIndex);
4815 Branch(&ok, eq, elements, Operand(at));
4816 LoadRoot(at, Heap::kFixedCOWArrayMapRootIndex);
4817 Branch(&ok, eq, elements, Operand(at));
4818 Abort(kJSObjectWithFastElementsMapHasSlowElements);
4825 void MacroAssembler::Check(Condition cc, BailoutReason reason,
4826 Register rs, Operand rt) {
4828 Branch(&L, cc, rs, rt);
4830 // Will not return here.
4835 void MacroAssembler::Abort(BailoutReason reason) {
4839 const char* msg = GetBailoutReason(reason);
4841 RecordComment("Abort message: ");
4845 if (FLAG_trap_on_abort) {
4851 li(a0, Operand(Smi::FromInt(reason)));
4853 // Disable stub call restrictions to always allow calls to abort.
4855 // We don't actually want to generate a pile of code for this, so just
4856 // claim there is a stack frame, without generating one.
4857 FrameScope scope(this, StackFrame::NONE);
4858 CallRuntime(Runtime::kAbort, 1);
4860 CallRuntime(Runtime::kAbort, 1);
4862 // Will not return here.
4863 if (is_trampoline_pool_blocked()) {
4864 // If the calling code cares about the exact number of
4865 // instructions generated, we insert padding here to keep the size
4866 // of the Abort macro constant.
4867 // Currently in debug mode with debug_code enabled the number of
4868 // generated instructions is 10, so we use this as a maximum value.
4869 static const int kExpectedAbortInstructions = 10;
4870 int abort_instructions = InstructionsGeneratedSince(&abort_start);
4871 DCHECK(abort_instructions <= kExpectedAbortInstructions);
4872 while (abort_instructions++ < kExpectedAbortInstructions) {
4879 void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
4880 if (context_chain_length > 0) {
4881 // Move up the chain of contexts to the context containing the slot.
4882 ld(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX)));
4883 for (int i = 1; i < context_chain_length; i++) {
4884 ld(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX)));
4887 // Slot is in the current function context. Move it into the
4888 // destination register in case we store into it (the write barrier
4889 // cannot be allowed to destroy the context in esi).
4895 void MacroAssembler::LoadTransitionedArrayMapConditional(
4896 ElementsKind expected_kind,
4897 ElementsKind transitioned_kind,
4898 Register map_in_out,
4900 Label* no_map_match) {
4901 // Load the global or builtins object from the current context.
4903 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4904 ld(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
4906 // Check that the function's map is the same as the expected cached map.
4909 Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX)));
4910 int offset = expected_kind * kPointerSize + FixedArrayBase::kHeaderSize;
4911 ld(at, FieldMemOperand(scratch, offset));
4912 Branch(no_map_match, ne, map_in_out, Operand(at));
4914 // Use the transitioned cached map.
4915 offset = transitioned_kind * kPointerSize +
4916 FixedArrayBase::kHeaderSize;
4917 ld(map_in_out, FieldMemOperand(scratch, offset));
4921 void MacroAssembler::LoadGlobalFunction(int index, Register function) {
4922 // Load the global or builtins object from the current context.
4924 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
4925 // Load the native context from the global or builtins object.
4926 ld(function, FieldMemOperand(function,
4927 GlobalObject::kNativeContextOffset));
4928 // Load the function from the native context.
4929 ld(function, MemOperand(function, Context::SlotOffset(index)));
4933 void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
4936 // Load the initial map. The global functions all have initial maps.
4937 ld(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
4938 if (emit_debug_code()) {
4940 CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK);
4943 Abort(kGlobalFunctionsMustHaveInitialMap);
4949 void MacroAssembler::StubPrologue() {
4951 Push(Smi::FromInt(StackFrame::STUB));
4952 // Adjust FP to point to saved FP.
4953 Daddu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
4957 void MacroAssembler::Prologue(bool code_pre_aging) {
4958 PredictableCodeSizeScope predictible_code_size_scope(
4959 this, kNoCodeAgeSequenceLength);
4960 // The following three instructions must remain together and unmodified
4961 // for code aging to work properly.
4962 if (code_pre_aging) {
4963 // Pre-age the code.
4964 Code* stub = Code::GetPreAgedCodeAgeStub(isolate());
4965 nop(Assembler::CODE_AGE_MARKER_NOP);
4966 // Load the stub address to t9 and call it,
4967 // GetCodeAgeAndParity() extracts the stub address from this instruction.
4969 Operand(reinterpret_cast<uint64_t>(stub->instruction_start())),
4971 nop(); // Prevent jalr to jal optimization.
4973 nop(); // Branch delay slot nop.
4974 nop(); // Pad the empty space.
4976 Push(ra, fp, cp, a1);
4977 nop(Assembler::CODE_AGE_SEQUENCE_NOP);
4978 nop(Assembler::CODE_AGE_SEQUENCE_NOP);
4979 nop(Assembler::CODE_AGE_SEQUENCE_NOP);
4980 // Adjust fp to point to caller's fp.
4981 Daddu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
4986 void MacroAssembler::EnterFrame(StackFrame::Type type,
4987 bool load_constant_pool_pointer_reg) {
4988 // Out-of-line constant pool not implemented on mips64.
4993 void MacroAssembler::EnterFrame(StackFrame::Type type) {
4994 daddiu(sp, sp, -5 * kPointerSize);
4995 li(t8, Operand(Smi::FromInt(type)));
4996 li(t9, Operand(CodeObject()), CONSTANT_SIZE);
4997 sd(ra, MemOperand(sp, 4 * kPointerSize));
4998 sd(fp, MemOperand(sp, 3 * kPointerSize));
4999 sd(cp, MemOperand(sp, 2 * kPointerSize));
5000 sd(t8, MemOperand(sp, 1 * kPointerSize));
5001 sd(t9, MemOperand(sp, 0 * kPointerSize));
5002 // Adjust FP to point to saved FP.
5004 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
5008 void MacroAssembler::LeaveFrame(StackFrame::Type type) {
5010 ld(fp, MemOperand(sp, 0 * kPointerSize));
5011 ld(ra, MemOperand(sp, 1 * kPointerSize));
5012 daddiu(sp, sp, 2 * kPointerSize);
5016 void MacroAssembler::EnterExitFrame(bool save_doubles,
5018 // Set up the frame structure on the stack.
5019 STATIC_ASSERT(2 * kPointerSize == ExitFrameConstants::kCallerSPDisplacement);
5020 STATIC_ASSERT(1 * kPointerSize == ExitFrameConstants::kCallerPCOffset);
5021 STATIC_ASSERT(0 * kPointerSize == ExitFrameConstants::kCallerFPOffset);
5023 // This is how the stack will look:
5024 // fp + 2 (==kCallerSPDisplacement) - old stack's end
5025 // [fp + 1 (==kCallerPCOffset)] - saved old ra
5026 // [fp + 0 (==kCallerFPOffset)] - saved old fp
5027 // [fp - 1 (==kSPOffset)] - sp of the called function
5028 // [fp - 2 (==kCodeOffset)] - CodeObject
5029 // fp - (2 + stack_space + alignment) == sp == [fp - kSPOffset] - top of the
5030 // new stack (will contain saved ra)
5033 daddiu(sp, sp, -4 * kPointerSize);
5034 sd(ra, MemOperand(sp, 3 * kPointerSize));
5035 sd(fp, MemOperand(sp, 2 * kPointerSize));
5036 daddiu(fp, sp, 2 * kPointerSize); // Set up new frame pointer.
5038 if (emit_debug_code()) {
5039 sd(zero_reg, MemOperand(fp, ExitFrameConstants::kSPOffset));
5042 // Accessed from ExitFrame::code_slot.
5043 li(t8, Operand(CodeObject()), CONSTANT_SIZE);
5044 sd(t8, MemOperand(fp, ExitFrameConstants::kCodeOffset));
5046 // Save the frame pointer and the context in top.
5047 li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
5048 sd(fp, MemOperand(t8));
5049 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
5050 sd(cp, MemOperand(t8));
5052 const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
5054 // The stack is already aligned to 0 modulo 8 for stores with sdc1.
5055 int kNumOfSavedRegisters = FPURegister::kMaxNumRegisters / 2;
5056 int space = kNumOfSavedRegisters * kDoubleSize ;
5057 Dsubu(sp, sp, Operand(space));
5058 // Remember: we only need to save every 2nd double FPU value.
5059 for (int i = 0; i < kNumOfSavedRegisters; i++) {
5060 FPURegister reg = FPURegister::from_code(2 * i);
5061 sdc1(reg, MemOperand(sp, i * kDoubleSize));
5065 // Reserve place for the return address, stack space and an optional slot
5066 // (used by the DirectCEntryStub to hold the return value if a struct is
5067 // returned) and align the frame preparing for calling the runtime function.
5068 DCHECK(stack_space >= 0);
5069 Dsubu(sp, sp, Operand((stack_space + 2) * kPointerSize));
5070 if (frame_alignment > 0) {
5071 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5072 And(sp, sp, Operand(-frame_alignment)); // Align stack.
5075 // Set the exit frame sp value to point just before the return address
5077 daddiu(at, sp, kPointerSize);
5078 sd(at, MemOperand(fp, ExitFrameConstants::kSPOffset));
5082 void MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count,
5083 bool restore_context, bool do_return,
5084 bool argument_count_is_length) {
5085 // Optionally restore all double registers.
5087 // Remember: we only need to restore every 2nd double FPU value.
5088 int kNumOfSavedRegisters = FPURegister::kMaxNumRegisters / 2;
5089 Dsubu(t8, fp, Operand(ExitFrameConstants::kFrameSize +
5090 kNumOfSavedRegisters * kDoubleSize));
5091 for (int i = 0; i < kNumOfSavedRegisters; i++) {
5092 FPURegister reg = FPURegister::from_code(2 * i);
5093 ldc1(reg, MemOperand(t8, i * kDoubleSize));
5098 li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
5099 sd(zero_reg, MemOperand(t8));
5101 // Restore current context from top and clear it in debug mode.
5102 if (restore_context) {
5103 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
5104 ld(cp, MemOperand(t8));
5107 li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate())));
5108 sd(a3, MemOperand(t8));
5111 // Pop the arguments, restore registers, and return.
5112 mov(sp, fp); // Respect ABI stack constraint.
5113 ld(fp, MemOperand(sp, ExitFrameConstants::kCallerFPOffset));
5114 ld(ra, MemOperand(sp, ExitFrameConstants::kCallerPCOffset));
5116 if (argument_count.is_valid()) {
5117 if (argument_count_is_length) {
5118 daddu(sp, sp, argument_count);
5120 dsll(t8, argument_count, kPointerSizeLog2);
5126 Ret(USE_DELAY_SLOT);
5127 // If returning, the instruction in the delay slot will be the addiu below.
5129 daddiu(sp, sp, 2 * kPointerSize);
5133 void MacroAssembler::InitializeNewString(Register string,
5135 Heap::RootListIndex map_index,
5137 Register scratch2) {
5138 // dsll(scratch1, length, kSmiTagSize);
5139 dsll32(scratch1, length, 0);
5140 LoadRoot(scratch2, map_index);
5141 sd(scratch1, FieldMemOperand(string, String::kLengthOffset));
5142 li(scratch1, Operand(String::kEmptyHashField));
5143 sd(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
5144 sd(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
5148 int MacroAssembler::ActivationFrameAlignment() {
5149 #if V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64
5150 // Running on the real platform. Use the alignment as mandated by the local
5152 // Note: This will break if we ever start generating snapshots on one Mips
5153 // platform for another Mips platform with a different alignment.
5154 return base::OS::ActivationFrameAlignment();
5155 #else // V8_HOST_ARCH_MIPS
5156 // If we are using the simulator then we should always align to the expected
5157 // alignment. As the simulator is used to generate snapshots we do not know
5158 // if the target platform will need alignment, so this is controlled from a
5160 return FLAG_sim_stack_alignment;
5161 #endif // V8_HOST_ARCH_MIPS
5165 void MacroAssembler::AssertStackIsAligned() {
5166 if (emit_debug_code()) {
5167 const int frame_alignment = ActivationFrameAlignment();
5168 const int frame_alignment_mask = frame_alignment - 1;
5170 if (frame_alignment > kPointerSize) {
5171 Label alignment_as_expected;
5172 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5173 andi(at, sp, frame_alignment_mask);
5174 Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
5175 // Don't use Check here, as it will call Runtime_Abort re-entering here.
5176 stop("Unexpected stack alignment");
5177 bind(&alignment_as_expected);
5183 void MacroAssembler::JumpIfNotPowerOfTwoOrZero(
5186 Label* not_power_of_two_or_zero) {
5187 Dsubu(scratch, reg, Operand(1));
5188 Branch(USE_DELAY_SLOT, not_power_of_two_or_zero, lt,
5189 scratch, Operand(zero_reg));
5190 and_(at, scratch, reg); // In the delay slot.
5191 Branch(not_power_of_two_or_zero, ne, at, Operand(zero_reg));
5195 void MacroAssembler::SmiTagCheckOverflow(Register reg, Register overflow) {
5196 DCHECK(!reg.is(overflow));
5197 mov(overflow, reg); // Save original value.
5199 xor_(overflow, overflow, reg); // Overflow if (value ^ 2 * value) < 0.
5203 void MacroAssembler::SmiTagCheckOverflow(Register dst,
5205 Register overflow) {
5207 // Fall back to slower case.
5208 SmiTagCheckOverflow(dst, overflow);
5210 DCHECK(!dst.is(src));
5211 DCHECK(!dst.is(overflow));
5212 DCHECK(!src.is(overflow));
5214 xor_(overflow, dst, src); // Overflow if (value ^ 2 * value) < 0.
5219 void MacroAssembler::SmiLoadUntag(Register dst, MemOperand src) {
5220 if (SmiValuesAre32Bits()) {
5221 lw(dst, UntagSmiMemOperand(src.rm(), src.offset()));
5229 void MacroAssembler::SmiLoadScale(Register dst, MemOperand src, int scale) {
5230 if (SmiValuesAre32Bits()) {
5231 // TODO(plind): not clear if lw or ld faster here, need micro-benchmark.
5232 lw(dst, UntagSmiMemOperand(src.rm(), src.offset()));
5233 dsll(dst, dst, scale);
5236 DCHECK(scale >= kSmiTagSize);
5237 sll(dst, dst, scale - kSmiTagSize);
5242 // Returns 2 values: the Smi and a scaled version of the int within the Smi.
5243 void MacroAssembler::SmiLoadWithScale(Register d_smi,
5247 if (SmiValuesAre32Bits()) {
5249 dsra(d_scaled, d_smi, kSmiShift - scale);
5252 DCHECK(scale >= kSmiTagSize);
5253 sll(d_scaled, d_smi, scale - kSmiTagSize);
5258 // Returns 2 values: the untagged Smi (int32) and scaled version of that int.
5259 void MacroAssembler::SmiLoadUntagWithScale(Register d_int,
5263 if (SmiValuesAre32Bits()) {
5264 lw(d_int, UntagSmiMemOperand(src.rm(), src.offset()));
5265 dsll(d_scaled, d_int, scale);
5268 // Need both the int and the scaled in, so use two instructions.
5270 sll(d_scaled, d_int, scale);
5275 void MacroAssembler::UntagAndJumpIfSmi(Register dst,
5278 // DCHECK(!dst.is(src));
5279 JumpIfSmi(src, smi_case, at, USE_DELAY_SLOT);
5284 void MacroAssembler::UntagAndJumpIfNotSmi(Register dst,
5286 Label* non_smi_case) {
5287 // DCHECK(!dst.is(src));
5288 JumpIfNotSmi(src, non_smi_case, at, USE_DELAY_SLOT);
5292 void MacroAssembler::JumpIfSmi(Register value,
5295 BranchDelaySlot bd) {
5296 DCHECK_EQ(0, kSmiTag);
5297 andi(scratch, value, kSmiTagMask);
5298 Branch(bd, smi_label, eq, scratch, Operand(zero_reg));
5301 void MacroAssembler::JumpIfNotSmi(Register value,
5302 Label* not_smi_label,
5304 BranchDelaySlot bd) {
5305 DCHECK_EQ(0, kSmiTag);
5306 andi(scratch, value, kSmiTagMask);
5307 Branch(bd, not_smi_label, ne, scratch, Operand(zero_reg));
5311 void MacroAssembler::JumpIfNotBothSmi(Register reg1,
5313 Label* on_not_both_smi) {
5314 STATIC_ASSERT(kSmiTag == 0);
5315 // TODO(plind): Find some better to fix this assert issue.
5316 #if defined(__APPLE__)
5317 DCHECK_EQ(1, kSmiTagMask);
5319 DCHECK_EQ((int64_t)1, kSmiTagMask);
5321 or_(at, reg1, reg2);
5322 JumpIfNotSmi(at, on_not_both_smi);
5326 void MacroAssembler::JumpIfEitherSmi(Register reg1,
5328 Label* on_either_smi) {
5329 STATIC_ASSERT(kSmiTag == 0);
5330 // TODO(plind): Find some better to fix this assert issue.
5331 #if defined(__APPLE__)
5332 DCHECK_EQ(1, kSmiTagMask);
5334 DCHECK_EQ((int64_t)1, kSmiTagMask);
5336 // Both Smi tags must be 1 (not Smi).
5337 and_(at, reg1, reg2);
5338 JumpIfSmi(at, on_either_smi);
5342 void MacroAssembler::AssertNotSmi(Register object) {
5343 if (emit_debug_code()) {
5344 STATIC_ASSERT(kSmiTag == 0);
5345 andi(at, object, kSmiTagMask);
5346 Check(ne, kOperandIsASmi, at, Operand(zero_reg));
5351 void MacroAssembler::AssertSmi(Register object) {
5352 if (emit_debug_code()) {
5353 STATIC_ASSERT(kSmiTag == 0);
5354 andi(at, object, kSmiTagMask);
5355 Check(eq, kOperandIsASmi, at, Operand(zero_reg));
5360 void MacroAssembler::AssertString(Register object) {
5361 if (emit_debug_code()) {
5362 STATIC_ASSERT(kSmiTag == 0);
5364 Check(ne, kOperandIsASmiAndNotAString, a4, Operand(zero_reg));
5366 ld(object, FieldMemOperand(object, HeapObject::kMapOffset));
5367 lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset));
5368 Check(lo, kOperandIsNotAString, object, Operand(FIRST_NONSTRING_TYPE));
5374 void MacroAssembler::AssertName(Register object) {
5375 if (emit_debug_code()) {
5376 STATIC_ASSERT(kSmiTag == 0);
5378 Check(ne, kOperandIsASmiAndNotAName, a4, Operand(zero_reg));
5380 ld(object, FieldMemOperand(object, HeapObject::kMapOffset));
5381 lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset));
5382 Check(le, kOperandIsNotAName, object, Operand(LAST_NAME_TYPE));
5388 void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
5390 if (emit_debug_code()) {
5391 Label done_checking;
5392 AssertNotSmi(object);
5393 LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
5394 Branch(&done_checking, eq, object, Operand(scratch));
5396 ld(object, FieldMemOperand(object, HeapObject::kMapOffset));
5397 LoadRoot(scratch, Heap::kAllocationSiteMapRootIndex);
5398 Assert(eq, kExpectedUndefinedOrCell, object, Operand(scratch));
5400 bind(&done_checking);
5405 void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) {
5406 if (emit_debug_code()) {
5407 DCHECK(!reg.is(at));
5408 LoadRoot(at, index);
5409 Check(eq, kHeapNumberMapRegisterClobbered, reg, Operand(at));
5414 void MacroAssembler::JumpIfNotHeapNumber(Register object,
5415 Register heap_number_map,
5417 Label* on_not_heap_number) {
5418 ld(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
5419 AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
5420 Branch(on_not_heap_number, ne, scratch, Operand(heap_number_map));
5424 void MacroAssembler::LookupNumberStringCache(Register object,
5430 // Use of registers. Register result is used as a temporary.
5431 Register number_string_cache = result;
5432 Register mask = scratch3;
5434 // Load the number string cache.
5435 LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex);
5437 // Make the hash mask from the length of the number string cache. It
5438 // contains two elements (number and string) for each cache entry.
5439 ld(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset));
5440 // Divide length by two (length is a smi).
5441 // dsra(mask, mask, kSmiTagSize + 1);
5442 dsra32(mask, mask, 1);
5443 Daddu(mask, mask, -1); // Make mask.
5445 // Calculate the entry in the number string cache. The hash value in the
5446 // number string cache for smis is just the smi value, and the hash for
5447 // doubles is the xor of the upper and lower words. See
5448 // Heap::GetNumberStringCache.
5450 Label load_result_from_cache;
5451 JumpIfSmi(object, &is_smi);
5454 Heap::kHeapNumberMapRootIndex,
5458 STATIC_ASSERT(8 == kDoubleSize);
5461 Operand(HeapNumber::kValueOffset - kHeapObjectTag));
5462 ld(scratch2, MemOperand(scratch1, kPointerSize));
5463 ld(scratch1, MemOperand(scratch1, 0));
5464 Xor(scratch1, scratch1, Operand(scratch2));
5465 And(scratch1, scratch1, Operand(mask));
5467 // Calculate address of entry in string cache: each entry consists
5468 // of two pointer sized fields.
5469 dsll(scratch1, scratch1, kPointerSizeLog2 + 1);
5470 Daddu(scratch1, number_string_cache, scratch1);
5472 Register probe = mask;
5473 ld(probe, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
5474 JumpIfSmi(probe, not_found);
5475 ldc1(f12, FieldMemOperand(object, HeapNumber::kValueOffset));
5476 ldc1(f14, FieldMemOperand(probe, HeapNumber::kValueOffset));
5477 BranchF(&load_result_from_cache, NULL, eq, f12, f14);
5481 Register scratch = scratch1;
5482 // dsra(scratch, object, 1); // Shift away the tag.
5483 dsra32(scratch, scratch, 0);
5484 And(scratch, mask, Operand(scratch));
5486 // Calculate address of entry in string cache: each entry consists
5487 // of two pointer sized fields.
5488 dsll(scratch, scratch, kPointerSizeLog2 + 1);
5489 Daddu(scratch, number_string_cache, scratch);
5491 // Check if the entry is the smi we are looking for.
5492 ld(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize));
5493 Branch(not_found, ne, object, Operand(probe));
5495 // Get the result from the cache.
5496 bind(&load_result_from_cache);
5497 ld(result, FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize));
5499 IncrementCounter(isolate()->counters()->number_to_string_native(),
5506 void MacroAssembler::JumpIfNonSmisNotBothSequentialOneByteStrings(
5507 Register first, Register second, Register scratch1, Register scratch2,
5509 // Test that both first and second are sequential one-byte strings.
5510 // Assume that they are non-smis.
5511 ld(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
5512 ld(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
5513 lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
5514 lbu(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
5516 JumpIfBothInstanceTypesAreNotSequentialOneByte(scratch1, scratch2, scratch1,
5521 void MacroAssembler::JumpIfNotBothSequentialOneByteStrings(Register first,
5526 // Check that neither is a smi.
5527 STATIC_ASSERT(kSmiTag == 0);
5528 And(scratch1, first, Operand(second));
5529 JumpIfSmi(scratch1, failure);
5530 JumpIfNonSmisNotBothSequentialOneByteStrings(first, second, scratch1,
5535 void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialOneByte(
5536 Register first, Register second, Register scratch1, Register scratch2,
5538 const int kFlatOneByteStringMask =
5539 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
5540 const int kFlatOneByteStringTag =
5541 kStringTag | kOneByteStringTag | kSeqStringTag;
5542 DCHECK(kFlatOneByteStringTag <= 0xffff); // Ensure this fits 16-bit immed.
5543 andi(scratch1, first, kFlatOneByteStringMask);
5544 Branch(failure, ne, scratch1, Operand(kFlatOneByteStringTag));
5545 andi(scratch2, second, kFlatOneByteStringMask);
5546 Branch(failure, ne, scratch2, Operand(kFlatOneByteStringTag));
5550 void MacroAssembler::JumpIfInstanceTypeIsNotSequentialOneByte(Register type,
5553 const int kFlatOneByteStringMask =
5554 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
5555 const int kFlatOneByteStringTag =
5556 kStringTag | kOneByteStringTag | kSeqStringTag;
5557 And(scratch, type, Operand(kFlatOneByteStringMask));
5558 Branch(failure, ne, scratch, Operand(kFlatOneByteStringTag));
5562 static const int kRegisterPassedArguments = (kMipsAbi == kN64) ? 8 : 4;
5564 int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments,
5565 int num_double_arguments) {
5566 int stack_passed_words = 0;
5567 num_reg_arguments += 2 * num_double_arguments;
5569 // O32: Up to four simple arguments are passed in registers a0..a3.
5570 // N64: Up to eight simple arguments are passed in registers a0..a7.
5571 if (num_reg_arguments > kRegisterPassedArguments) {
5572 stack_passed_words += num_reg_arguments - kRegisterPassedArguments;
5574 stack_passed_words += kCArgSlotCount;
5575 return stack_passed_words;
5579 void MacroAssembler::EmitSeqStringSetCharCheck(Register string,
5583 uint32_t encoding_mask) {
5586 Check(ne, kNonObject, at, Operand(zero_reg));
5588 ld(at, FieldMemOperand(string, HeapObject::kMapOffset));
5589 lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset));
5591 andi(at, at, kStringRepresentationMask | kStringEncodingMask);
5592 li(scratch, Operand(encoding_mask));
5593 Check(eq, kUnexpectedStringType, at, Operand(scratch));
5595 // TODO(plind): requires Smi size check code for mips32.
5597 ld(at, FieldMemOperand(string, String::kLengthOffset));
5598 Check(lt, kIndexIsTooLarge, index, Operand(at));
5600 DCHECK(Smi::FromInt(0) == 0);
5601 Check(ge, kIndexIsNegative, index, Operand(zero_reg));
5605 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
5606 int num_double_arguments,
5608 int frame_alignment = ActivationFrameAlignment();
5610 // n64: Up to eight simple arguments in a0..a3, a4..a7, No argument slots.
5611 // O32: Up to four simple arguments are passed in registers a0..a3.
5612 // Those four arguments must have reserved argument slots on the stack for
5613 // mips, even though those argument slots are not normally used.
5614 // Both ABIs: Remaining arguments are pushed on the stack, above (higher
5615 // address than) the (O32) argument slots. (arg slot calculation handled by
5616 // CalculateStackPassedWords()).
5617 int stack_passed_arguments = CalculateStackPassedWords(
5618 num_reg_arguments, num_double_arguments);
5619 if (frame_alignment > kPointerSize) {
5620 // Make stack end at alignment and make room for num_arguments - 4 words
5621 // and the original value of sp.
5623 Dsubu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
5624 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5625 And(sp, sp, Operand(-frame_alignment));
5626 sd(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
5628 Dsubu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
5633 void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
5635 PrepareCallCFunction(num_reg_arguments, 0, scratch);
5639 void MacroAssembler::CallCFunction(ExternalReference function,
5640 int num_reg_arguments,
5641 int num_double_arguments) {
5642 li(t8, Operand(function));
5643 CallCFunctionHelper(t8, num_reg_arguments, num_double_arguments);
5647 void MacroAssembler::CallCFunction(Register function,
5648 int num_reg_arguments,
5649 int num_double_arguments) {
5650 CallCFunctionHelper(function, num_reg_arguments, num_double_arguments);
5654 void MacroAssembler::CallCFunction(ExternalReference function,
5655 int num_arguments) {
5656 CallCFunction(function, num_arguments, 0);
5660 void MacroAssembler::CallCFunction(Register function,
5661 int num_arguments) {
5662 CallCFunction(function, num_arguments, 0);
5666 void MacroAssembler::CallCFunctionHelper(Register function,
5667 int num_reg_arguments,
5668 int num_double_arguments) {
5669 DCHECK(has_frame());
5670 // Make sure that the stack is aligned before calling a C function unless
5671 // running in the simulator. The simulator has its own alignment check which
5672 // provides more information.
5673 // The argument stots are presumed to have been set up by
5674 // PrepareCallCFunction. The C function must be called via t9, for mips ABI.
5676 #if V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64
5677 if (emit_debug_code()) {
5678 int frame_alignment = base::OS::ActivationFrameAlignment();
5679 int frame_alignment_mask = frame_alignment - 1;
5680 if (frame_alignment > kPointerSize) {
5681 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
5682 Label alignment_as_expected;
5683 And(at, sp, Operand(frame_alignment_mask));
5684 Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
5685 // Don't use Check here, as it will call Runtime_Abort possibly
5686 // re-entering here.
5687 stop("Unexpected alignment in CallCFunction");
5688 bind(&alignment_as_expected);
5691 #endif // V8_HOST_ARCH_MIPS
5693 // Just call directly. The function called cannot cause a GC, or
5694 // allow preemption, so the return address in the link register
5697 if (!function.is(t9)) {
5704 int stack_passed_arguments = CalculateStackPassedWords(
5705 num_reg_arguments, num_double_arguments);
5707 if (base::OS::ActivationFrameAlignment() > kPointerSize) {
5708 ld(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
5710 Daddu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
5715 #undef BRANCH_ARGS_CHECK
5718 void MacroAssembler::CheckPageFlag(
5723 Label* condition_met) {
5724 And(scratch, object, Operand(~Page::kPageAlignmentMask));
5725 ld(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset));
5726 And(scratch, scratch, Operand(mask));
5727 Branch(condition_met, cc, scratch, Operand(zero_reg));
5731 void MacroAssembler::JumpIfBlack(Register object,
5735 HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern.
5736 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
5740 void MacroAssembler::HasColor(Register object,
5741 Register bitmap_scratch,
5742 Register mask_scratch,
5746 DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, t8));
5747 DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, t9));
5749 GetMarkBits(object, bitmap_scratch, mask_scratch);
5752 // Note that we are using a 4-byte aligned 8-byte load.
5753 Uld(t9, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5754 And(t8, t9, Operand(mask_scratch));
5755 Branch(&other_color, first_bit == 1 ? eq : ne, t8, Operand(zero_reg));
5756 // Shift left 1 by adding.
5757 Daddu(mask_scratch, mask_scratch, Operand(mask_scratch));
5758 And(t8, t9, Operand(mask_scratch));
5759 Branch(has_color, second_bit == 1 ? ne : eq, t8, Operand(zero_reg));
5765 // Detect some, but not all, common pointer-free objects. This is used by the
5766 // incremental write barrier which doesn't care about oddballs (they are always
5767 // marked black immediately so this code is not hit).
5768 void MacroAssembler::JumpIfDataObject(Register value,
5770 Label* not_data_object) {
5771 DCHECK(!AreAliased(value, scratch, t8, no_reg));
5772 Label is_data_object;
5773 ld(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
5774 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
5775 Branch(&is_data_object, eq, t8, Operand(scratch));
5776 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
5777 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
5778 // If it's a string and it's not a cons string then it's an object containing
5780 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
5781 And(t8, scratch, Operand(kIsIndirectStringMask | kIsNotStringMask));
5782 Branch(not_data_object, ne, t8, Operand(zero_reg));
5783 bind(&is_data_object);
5787 void MacroAssembler::GetMarkBits(Register addr_reg,
5788 Register bitmap_reg,
5789 Register mask_reg) {
5790 DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg));
5791 // addr_reg is divided into fields:
5792 // |63 page base 20|19 high 8|7 shift 3|2 0|
5793 // 'high' gives the index of the cell holding color bits for the object.
5794 // 'shift' gives the offset in the cell for this object's color.
5795 And(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask));
5796 Ext(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2);
5797 const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2;
5798 Ext(t8, addr_reg, kLowBits, kPageSizeBits - kLowBits);
5799 dsll(t8, t8, Bitmap::kBytesPerCellLog2);
5800 Daddu(bitmap_reg, bitmap_reg, t8);
5802 dsllv(mask_reg, t8, mask_reg);
5806 void MacroAssembler::EnsureNotWhite(
5808 Register bitmap_scratch,
5809 Register mask_scratch,
5810 Register load_scratch,
5811 Label* value_is_white_and_not_data) {
5812 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, t8));
5813 GetMarkBits(value, bitmap_scratch, mask_scratch);
5815 // If the value is black or grey we don't need to do anything.
5816 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
5817 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
5818 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
5819 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
5823 // Since both black and grey have a 1 in the first position and white does
5824 // not have a 1 there we only need to check one bit.
5825 // Note that we are using a 4-byte aligned 8-byte load.
5826 Uld(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5827 And(t8, mask_scratch, load_scratch);
5828 Branch(&done, ne, t8, Operand(zero_reg));
5830 if (emit_debug_code()) {
5831 // Check for impossible bit pattern.
5833 // sll may overflow, making the check conservative.
5834 dsll(t8, mask_scratch, 1);
5835 And(t8, load_scratch, t8);
5836 Branch(&ok, eq, t8, Operand(zero_reg));
5837 stop("Impossible marking bit pattern");
5841 // Value is white. We check whether it is data that doesn't need scanning.
5842 // Currently only checks for HeapNumber and non-cons strings.
5843 Register map = load_scratch; // Holds map while checking type.
5844 Register length = load_scratch; // Holds length of object after testing type.
5845 Label is_data_object;
5847 // Check for heap-number
5848 ld(map, FieldMemOperand(value, HeapObject::kMapOffset));
5849 LoadRoot(t8, Heap::kHeapNumberMapRootIndex);
5852 Branch(&skip, ne, t8, Operand(map));
5853 li(length, HeapNumber::kSize);
5854 Branch(&is_data_object);
5858 // Check for strings.
5859 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1);
5860 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80);
5861 // If it's a string and it's not a cons string then it's an object containing
5863 Register instance_type = load_scratch;
5864 lbu(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset));
5865 And(t8, instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask));
5866 Branch(value_is_white_and_not_data, ne, t8, Operand(zero_reg));
5867 // It's a non-indirect (non-cons and non-slice) string.
5868 // If it's external, the length is just ExternalString::kSize.
5869 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2).
5870 // External strings are the only ones with the kExternalStringTag bit
5872 DCHECK_EQ(0, kSeqStringTag & kExternalStringTag);
5873 DCHECK_EQ(0, kConsStringTag & kExternalStringTag);
5874 And(t8, instance_type, Operand(kExternalStringTag));
5877 Branch(&skip, eq, t8, Operand(zero_reg));
5878 li(length, ExternalString::kSize);
5879 Branch(&is_data_object);
5883 // Sequential string, either Latin1 or UC16.
5884 // For Latin1 (char-size of 1) we shift the smi tag away to get the length.
5885 // For UC16 (char-size of 2) we just leave the smi tag in place, thereby
5886 // getting the length multiplied by 2.
5887 DCHECK(kOneByteStringTag == 4 && kStringEncodingMask == 4);
5888 DCHECK(kSmiTag == 0 && kSmiTagSize == 1);
5889 lw(t9, UntagSmiFieldMemOperand(value, String::kLengthOffset));
5890 And(t8, instance_type, Operand(kStringEncodingMask));
5893 Branch(&skip, ne, t8, Operand(zero_reg));
5894 // Adjust length for UC16.
5898 Daddu(length, t9, Operand(SeqString::kHeaderSize + kObjectAlignmentMask));
5899 DCHECK(!length.is(t8));
5900 And(length, length, Operand(~kObjectAlignmentMask));
5902 bind(&is_data_object);
5903 // Value is a data object, and it is white. Mark it black. Since we know
5904 // that the object is white we can make it black by flipping one bit.
5905 Uld(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5906 Or(t8, t8, Operand(mask_scratch));
5907 Usd(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize));
5909 And(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask));
5910 Uld(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
5911 Daddu(t8, t8, Operand(length));
5912 Usd(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset));
5918 void MacroAssembler::LoadInstanceDescriptors(Register map,
5919 Register descriptors) {
5920 ld(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset));
5924 void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) {
5925 ld(dst, FieldMemOperand(map, Map::kBitField3Offset));
5926 DecodeField<Map::NumberOfOwnDescriptorsBits>(dst);
5930 void MacroAssembler::EnumLength(Register dst, Register map) {
5931 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0);
5932 ld(dst, FieldMemOperand(map, Map::kBitField3Offset));
5933 And(dst, dst, Operand(Map::EnumLengthBits::kMask));
5938 void MacroAssembler::LoadAccessor(Register dst, Register holder,
5940 AccessorComponent accessor) {
5941 ld(dst, FieldMemOperand(holder, HeapObject::kMapOffset));
5942 LoadInstanceDescriptors(dst, dst);
5944 FieldMemOperand(dst, DescriptorArray::GetValueOffset(accessor_index)));
5945 int offset = accessor == ACCESSOR_GETTER ? AccessorPair::kGetterOffset
5946 : AccessorPair::kSetterOffset;
5947 ld(dst, FieldMemOperand(dst, offset));
5951 void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) {
5952 Register empty_fixed_array_value = a6;
5953 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex);
5957 // Check if the enum length field is properly initialized, indicating that
5958 // there is an enum cache.
5959 ld(a1, FieldMemOperand(a2, HeapObject::kMapOffset));
5963 call_runtime, eq, a3, Operand(Smi::FromInt(kInvalidEnumCacheSentinel)));
5968 ld(a1, FieldMemOperand(a2, HeapObject::kMapOffset));
5970 // For all objects but the receiver, check that the cache is empty.
5972 Branch(call_runtime, ne, a3, Operand(Smi::FromInt(0)));
5976 // Check that there are no elements. Register a2 contains the current JS
5977 // object we've reached through the prototype chain.
5979 ld(a2, FieldMemOperand(a2, JSObject::kElementsOffset));
5980 Branch(&no_elements, eq, a2, Operand(empty_fixed_array_value));
5982 // Second chance, the object may be using the empty slow element dictionary.
5983 LoadRoot(at, Heap::kEmptySlowElementDictionaryRootIndex);
5984 Branch(call_runtime, ne, a2, Operand(at));
5987 ld(a2, FieldMemOperand(a1, Map::kPrototypeOffset));
5988 Branch(&next, ne, a2, Operand(null_value));
5992 void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) {
5993 DCHECK(!output_reg.is(input_reg));
5995 li(output_reg, Operand(255));
5996 // Normal branch: nop in delay slot.
5997 Branch(&done, gt, input_reg, Operand(output_reg));
5998 // Use delay slot in this branch.
5999 Branch(USE_DELAY_SLOT, &done, lt, input_reg, Operand(zero_reg));
6000 mov(output_reg, zero_reg); // In delay slot.
6001 mov(output_reg, input_reg); // Value is in range 0..255.
6006 void MacroAssembler::ClampDoubleToUint8(Register result_reg,
6007 DoubleRegister input_reg,
6008 DoubleRegister temp_double_reg) {
6013 Move(temp_double_reg, 0.0);
6014 BranchF(&above_zero, NULL, gt, input_reg, temp_double_reg);
6016 // Double value is less than zero, NaN or Inf, return 0.
6017 mov(result_reg, zero_reg);
6020 // Double value is >= 255, return 255.
6022 Move(temp_double_reg, 255.0);
6023 BranchF(&in_bounds, NULL, le, input_reg, temp_double_reg);
6024 li(result_reg, Operand(255));
6027 // In 0-255 range, round and truncate.
6029 cvt_w_d(temp_double_reg, input_reg);
6030 mfc1(result_reg, temp_double_reg);
6035 void MacroAssembler::TestJSArrayForAllocationMemento(
6036 Register receiver_reg,
6037 Register scratch_reg,
6038 Label* no_memento_found,
6040 Label* allocation_memento_present) {
6041 ExternalReference new_space_start =
6042 ExternalReference::new_space_start(isolate());
6043 ExternalReference new_space_allocation_top =
6044 ExternalReference::new_space_allocation_top_address(isolate());
6045 Daddu(scratch_reg, receiver_reg,
6046 Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag));
6047 Branch(no_memento_found, lt, scratch_reg, Operand(new_space_start));
6048 li(at, Operand(new_space_allocation_top));
6049 ld(at, MemOperand(at));
6050 Branch(no_memento_found, gt, scratch_reg, Operand(at));
6051 ld(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize));
6052 if (allocation_memento_present) {
6053 Branch(allocation_memento_present, cond, scratch_reg,
6054 Operand(isolate()->factory()->allocation_memento_map()));
6059 Register GetRegisterThatIsNotOneOf(Register reg1,
6066 if (reg1.is_valid()) regs |= reg1.bit();
6067 if (reg2.is_valid()) regs |= reg2.bit();
6068 if (reg3.is_valid()) regs |= reg3.bit();
6069 if (reg4.is_valid()) regs |= reg4.bit();
6070 if (reg5.is_valid()) regs |= reg5.bit();
6071 if (reg6.is_valid()) regs |= reg6.bit();
6073 for (int i = 0; i < Register::NumAllocatableRegisters(); i++) {
6074 Register candidate = Register::FromAllocationIndex(i);
6075 if (regs & candidate.bit()) continue;
6083 void MacroAssembler::JumpIfDictionaryInPrototypeChain(
6088 DCHECK(!scratch1.is(scratch0));
6089 Factory* factory = isolate()->factory();
6090 Register current = scratch0;
6091 Label loop_again, end;
6093 // Scratch contained elements pointer.
6094 Move(current, object);
6095 ld(current, FieldMemOperand(current, HeapObject::kMapOffset));
6096 ld(current, FieldMemOperand(current, Map::kPrototypeOffset));
6097 Branch(&end, eq, current, Operand(factory->null_value()));
6099 // Loop based on the map going up the prototype chain.
6101 ld(current, FieldMemOperand(current, HeapObject::kMapOffset));
6102 lbu(scratch1, FieldMemOperand(current, Map::kInstanceTypeOffset));
6103 STATIC_ASSERT(JS_VALUE_TYPE < JS_OBJECT_TYPE);
6104 STATIC_ASSERT(JS_PROXY_TYPE < JS_OBJECT_TYPE);
6105 Branch(found, lo, scratch1, Operand(JS_OBJECT_TYPE));
6106 lb(scratch1, FieldMemOperand(current, Map::kBitField2Offset));
6107 DecodeField<Map::ElementsKindBits>(scratch1);
6108 Branch(found, eq, scratch1, Operand(DICTIONARY_ELEMENTS));
6109 ld(current, FieldMemOperand(current, Map::kPrototypeOffset));
6110 Branch(&loop_again, ne, current, Operand(factory->null_value()));
6116 bool AreAliased(Register reg1,
6124 int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() +
6125 reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid() +
6126 reg7.is_valid() + reg8.is_valid();
6129 if (reg1.is_valid()) regs |= reg1.bit();
6130 if (reg2.is_valid()) regs |= reg2.bit();
6131 if (reg3.is_valid()) regs |= reg3.bit();
6132 if (reg4.is_valid()) regs |= reg4.bit();
6133 if (reg5.is_valid()) regs |= reg5.bit();
6134 if (reg6.is_valid()) regs |= reg6.bit();
6135 if (reg7.is_valid()) regs |= reg7.bit();
6136 if (reg8.is_valid()) regs |= reg8.bit();
6137 int n_of_non_aliasing_regs = NumRegs(regs);
6139 return n_of_valid_regs != n_of_non_aliasing_regs;
6143 CodePatcher::CodePatcher(byte* address,
6145 FlushICache flush_cache)
6146 : address_(address),
6147 size_(instructions * Assembler::kInstrSize),
6148 masm_(NULL, address, size_ + Assembler::kGap),
6149 flush_cache_(flush_cache) {
6150 // Create a new macro assembler pointing to the address of the code to patch.
6151 // The size is adjusted with kGap on order for the assembler to generate size
6152 // bytes of instructions without failing with buffer size constraints.
6153 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
6157 CodePatcher::~CodePatcher() {
6158 // Indicate that code has changed.
6159 if (flush_cache_ == FLUSH) {
6160 CpuFeatures::FlushICache(address_, size_);
6162 // Check that the code was patched as expected.
6163 DCHECK(masm_.pc_ == address_ + size_);
6164 DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
6168 void CodePatcher::Emit(Instr instr) {
6169 masm()->emit(instr);
6173 void CodePatcher::Emit(Address addr) {
6174 // masm()->emit(reinterpret_cast<Instr>(addr));
6178 void CodePatcher::ChangeBranchCondition(Condition cond) {
6179 Instr instr = Assembler::instr_at(masm_.pc_);
6180 DCHECK(Assembler::IsBranch(instr));
6181 uint32_t opcode = Assembler::GetOpcodeField(instr);
6182 // Currently only the 'eq' and 'ne' cond values are supported and the simple
6183 // branch instructions (with opcode being the branch type).
6184 // There are some special cases (see Assembler::IsBranch()) so extending this
6186 DCHECK(opcode == BEQ ||
6194 opcode = (cond == eq) ? BEQ : BNE;
6195 instr = (instr & ~kOpcodeMask) | opcode;
6200 void MacroAssembler::TruncatingDiv(Register result,
6203 DCHECK(!dividend.is(result));
6204 DCHECK(!dividend.is(at));
6205 DCHECK(!result.is(at));
6206 base::MagicNumbersForDivision<uint32_t> mag =
6207 base::SignedDivisionByConstant(static_cast<uint32_t>(divisor));
6208 li(at, Operand(static_cast<int32_t>(mag.multiplier)));
6209 Mulh(result, dividend, Operand(at));
6210 bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0;
6211 if (divisor > 0 && neg) {
6212 Addu(result, result, Operand(dividend));
6214 if (divisor < 0 && !neg && mag.multiplier > 0) {
6215 Subu(result, result, Operand(dividend));
6217 if (mag.shift > 0) sra(result, result, mag.shift);
6218 srl(at, dividend, 31);
6219 Addu(result, result, Operand(at));
6223 } // namespace internal
6226 #endif // V8_TARGET_ARCH_MIPS64