1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
11 // - Redistribution in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
15 // - Neither the name of Sun Microsystems or the names of contributors may
16 // be used to endorse or promote products derived from this software without
17 // specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // The original source code covered by the above license above has been
32 // modified significantly by Google Inc.
33 // Copyright 2012 the V8 project authors. All rights reserved.
36 #ifndef V8_MIPS_ASSEMBLER_MIPS_H_
37 #define V8_MIPS_ASSEMBLER_MIPS_H_
43 #include "src/assembler.h"
44 #include "src/compiler.h"
45 #include "src/mips64/constants-mips64.h"
52 // 1) We would prefer to use an enum, but enum values are assignment-
53 // compatible with int, which has caused code-generation bugs.
55 // 2) We would prefer to use a class instead of a struct but we don't like
56 // the register initialization to depend on the particular initialization
57 // order (which appears to be different on OS X, Linux, and Windows for the
58 // installed versions of C++ we tried). Using a struct permits C-style
59 // "initialization". Also, the Register objects cannot be const as this
60 // forces initialization stubs in MSVC, making us dependent on initialization
63 // 3) By not using an enum, we are possibly preventing the compiler from
64 // doing certain constant folds, which may significantly reduce the
65 // code generated for some assembly instructions (because they boil down
66 // to a few constants). If this is a problem, we could change the code
67 // such that we use an enum in optimized mode, and the struct in debug
68 // mode. This way we get the compile-time error checking in debug mode
69 // and best performance in optimized code.
72 // -----------------------------------------------------------------------------
73 // Implementation of Register and FPURegister.
77 static const int kNumRegisters = v8::internal::kNumRegisters;
78 static const int kMaxNumAllocatableRegisters = 14; // v0 through t2 and cp.
79 static const int kSizeInBytes = 8;
80 static const int kCpRegister = 23; // cp (s7) is the 23rd register.
82 #if defined(V8_TARGET_LITTLE_ENDIAN)
83 static const int kMantissaOffset = 0;
84 static const int kExponentOffset = 4;
85 #elif defined(V8_TARGET_BIG_ENDIAN)
86 static const int kMantissaOffset = 4;
87 static const int kExponentOffset = 0;
89 #error Unknown endianness
92 inline static int NumAllocatableRegisters();
94 static int ToAllocationIndex(Register reg) {
95 DCHECK((reg.code() - 2) < (kMaxNumAllocatableRegisters - 1) ||
96 reg.is(from_code(kCpRegister)));
97 return reg.is(from_code(kCpRegister)) ?
98 kMaxNumAllocatableRegisters - 1 : // Return last index for 'cp'.
99 reg.code() - 2; // zero_reg and 'at' are skipped.
102 static Register FromAllocationIndex(int index) {
103 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
104 return index == kMaxNumAllocatableRegisters - 1 ?
105 from_code(kCpRegister) : // Last index is always the 'cp' register.
106 from_code(index + 2); // zero_reg and 'at' are skipped.
109 static const char* AllocationIndexToString(int index) {
110 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
111 const char* const names[] = {
130 static Register from_code(int code) {
131 Register r = { code };
135 bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; }
136 bool is(Register reg) const { return code_ == reg.code_; }
146 // Unfortunately we can't make this private in a struct.
150 #define REGISTER(N, C) \
151 const int kRegister_ ## N ## _Code = C; \
152 const Register N = { C }
154 REGISTER(no_reg, -1);
156 REGISTER(zero_reg, 0);
157 // at: Reserved for synthetic instructions.
159 // v0, v1: Used when returning multiple values from subroutines.
162 // a0 - a4: Used to pass non-FP parameters.
167 // a4 - a7 t0 - t3: Can be used without reservation, act as temporary registers
168 // and are allowed to be destroyed by subroutines.
177 // s0 - s7: Subroutine register variables. Subroutines that write to these
178 // registers must restore their values before exiting so that the caller can
179 // expect the values to be preserved.
190 // k0, k1: Reserved for system calls and interrupt handlers.
195 // sp: Stack pointer.
197 // fp: Frame pointer.
199 // ra: Return address pointer.
205 int ToNumber(Register reg);
207 Register ToRegister(int num);
209 // Coprocessor register.
211 static const int kMaxNumRegisters = v8::internal::kNumFPURegisters;
213 // TODO(plind): Warning, inconsistent numbering here. kNumFPURegisters refers
214 // to number of 32-bit FPU regs, but kNumAllocatableRegisters refers to
215 // number of Double regs (64-bit regs, or FPU-reg-pairs).
217 // A few double registers are reserved: one as a scratch register and one to
220 // f30: scratch register.
221 static const int kNumReservedRegisters = 2;
222 static const int kMaxNumAllocatableRegisters = kMaxNumRegisters / 2 -
223 kNumReservedRegisters;
225 inline static int NumRegisters();
226 inline static int NumAllocatableRegisters();
228 // TODO(turbofan): Proper support for float32.
229 inline static int NumAllocatableAliasedRegisters();
231 inline static int ToAllocationIndex(FPURegister reg);
232 static const char* AllocationIndexToString(int index);
234 static FPURegister FromAllocationIndex(int index) {
235 DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters);
236 return from_code(index * 2);
239 static FPURegister from_code(int code) {
240 FPURegister r = { code };
244 bool is_valid() const { return 0 <= code_ && code_ < kMaxNumRegisters ; }
245 bool is(FPURegister creg) const { return code_ == creg.code_; }
246 FPURegister low() const {
247 // TODO(plind): Create DCHECK for FR=0 mode. This usage suspect for FR=1.
248 // Find low reg of a Double-reg pair, which is the reg itself.
249 DCHECK(code_ % 2 == 0); // Specified Double reg must be even.
252 DCHECK(reg.is_valid());
255 FPURegister high() const {
256 // TODO(plind): Create DCHECK for FR=0 mode. This usage illegal in FR=1.
257 // Find high reg of a Doubel-reg pair, which is reg + 1.
258 DCHECK(code_ % 2 == 0); // Specified Double reg must be even.
260 reg.code_ = code_ + 1;
261 DCHECK(reg.is_valid());
273 void setcode(int f) {
277 // Unfortunately we can't make this private in a struct.
281 // V8 now supports the O32 ABI, and the FPU Registers are organized as 32
282 // 32-bit registers, f0 through f31. When used as 'double' they are used
283 // in pairs, starting with the even numbered register. So a double operation
284 // on f0 really uses f0 and f1.
285 // (Modern mips hardware also supports 32 64-bit registers, via setting
286 // (privileged) Status Register FR bit to 1. This is used by the N32 ABI,
287 // but it is not in common use. Someday we will want to support this in v8.)
289 // For O32 ABI, Floats and Doubles refer to same set of 32 32-bit registers.
290 typedef FPURegister DoubleRegister;
291 typedef FPURegister FloatRegister;
293 const FPURegister no_freg = { -1 };
295 const FPURegister f0 = { 0 }; // Return value in hard float mode.
296 const FPURegister f1 = { 1 };
297 const FPURegister f2 = { 2 };
298 const FPURegister f3 = { 3 };
299 const FPURegister f4 = { 4 };
300 const FPURegister f5 = { 5 };
301 const FPURegister f6 = { 6 };
302 const FPURegister f7 = { 7 };
303 const FPURegister f8 = { 8 };
304 const FPURegister f9 = { 9 };
305 const FPURegister f10 = { 10 };
306 const FPURegister f11 = { 11 };
307 const FPURegister f12 = { 12 }; // Arg 0 in hard float mode.
308 const FPURegister f13 = { 13 };
309 const FPURegister f14 = { 14 }; // Arg 1 in hard float mode.
310 const FPURegister f15 = { 15 };
311 const FPURegister f16 = { 16 };
312 const FPURegister f17 = { 17 };
313 const FPURegister f18 = { 18 };
314 const FPURegister f19 = { 19 };
315 const FPURegister f20 = { 20 };
316 const FPURegister f21 = { 21 };
317 const FPURegister f22 = { 22 };
318 const FPURegister f23 = { 23 };
319 const FPURegister f24 = { 24 };
320 const FPURegister f25 = { 25 };
321 const FPURegister f26 = { 26 };
322 const FPURegister f27 = { 27 };
323 const FPURegister f28 = { 28 };
324 const FPURegister f29 = { 29 };
325 const FPURegister f30 = { 30 };
326 const FPURegister f31 = { 31 };
329 // cp is assumed to be a callee saved register.
330 // Defined using #define instead of "static const Register&" because Clang
331 // complains otherwise when a compilation unit that includes this header
332 // doesn't use the variables.
333 #define kRootRegister s6
335 #define kLithiumScratchReg s3
336 #define kLithiumScratchReg2 s4
337 #define kLithiumScratchDouble f30
338 #define kDoubleRegZero f28
339 // Used on mips64r6 for compare operations.
340 // We use the last non-callee saved odd register for N64 ABI
341 #define kDoubleCompareReg f23
343 // FPU (coprocessor 1) control registers.
344 // Currently only FCSR (#31) is implemented.
345 struct FPUControlRegister {
346 bool is_valid() const { return code_ == kFCSRRegister; }
347 bool is(FPUControlRegister creg) const { return code_ == creg.code_; }
356 void setcode(int f) {
360 // Unfortunately we can't make this private in a struct.
364 const FPUControlRegister no_fpucreg = { kInvalidFPUControlRegister };
365 const FPUControlRegister FCSR = { kFCSRRegister };
368 // -----------------------------------------------------------------------------
369 // Machine instruction Operands.
370 const int kSmiShift = kSmiTagSize + kSmiShiftSize;
371 const uint64_t kSmiShiftMask = (1UL << kSmiShift) - 1;
372 // Class Operand represents a shifter operand in data processing instructions.
373 class Operand BASE_EMBEDDED {
376 INLINE(explicit Operand(int64_t immediate,
377 RelocInfo::Mode rmode = RelocInfo::NONE64));
378 INLINE(explicit Operand(const ExternalReference& f));
379 INLINE(explicit Operand(const char* s));
380 INLINE(explicit Operand(Object** opp));
381 INLINE(explicit Operand(Context** cpp));
382 explicit Operand(Handle<Object> handle);
383 INLINE(explicit Operand(Smi* value));
386 INLINE(explicit Operand(Register rm));
388 // Return true if this is a register operand.
389 INLINE(bool is_reg() const);
391 inline int64_t immediate() const {
396 Register rm() const { return rm_; }
400 int64_t imm64_; // Valid if rm_ == no_reg.
401 RelocInfo::Mode rmode_;
403 friend class Assembler;
404 friend class MacroAssembler;
408 // On MIPS we have only one adressing mode with base_reg + offset.
409 // Class MemOperand represents a memory operand in load and store instructions.
410 class MemOperand : public Operand {
412 // Immediate value attached to offset.
414 offset_minus_one = -1,
418 explicit MemOperand(Register rn, int32_t offset = 0);
419 explicit MemOperand(Register rn, int32_t unit, int32_t multiplier,
420 OffsetAddend offset_addend = offset_zero);
421 int32_t offset() const { return offset_; }
423 bool OffsetIsInt16Encodable() const {
424 return is_int16(offset_);
430 friend class Assembler;
434 class Assembler : public AssemblerBase {
436 // Create an assembler. Instructions and relocation information are emitted
437 // into a buffer, with the instructions starting from the beginning and the
438 // relocation information starting from the end of the buffer. See CodeDesc
439 // for a detailed comment on the layout (globals.h).
441 // If the provided buffer is NULL, the assembler allocates and grows its own
442 // buffer, and buffer_size determines the initial buffer size. The buffer is
443 // owned by the assembler and deallocated upon destruction of the assembler.
445 // If the provided buffer is not NULL, the assembler uses the provided buffer
446 // for code generation and assumes its size to be buffer_size. If the buffer
447 // is too small, a fatal error occurs. No deallocation of the buffer is done
448 // upon destruction of the assembler.
449 Assembler(Isolate* isolate, void* buffer, int buffer_size);
450 virtual ~Assembler() { }
452 // GetCode emits any pending (non-emitted) code and fills the descriptor
453 // desc. GetCode() is idempotent; it returns the same result if no other
454 // Assembler functions are invoked in between GetCode() calls.
455 void GetCode(CodeDesc* desc);
457 // Label operations & relative jumps (PPUM Appendix D).
459 // Takes a branch opcode (cc) and a label (L) and generates
460 // either a backward branch or a forward branch and links it
461 // to the label fixup chain. Usage:
463 // Label L; // unbound label
464 // j(cc, &L); // forward branch to unbound label
465 // bind(&L); // bind label to the current pc
466 // j(cc, &L); // backward branch to bound label
467 // bind(&L); // illegal: a label may be bound only once
469 // Note: The same Label can be used for forward and backward branches
470 // but it may be bound only once.
471 void bind(Label* L); // Binds an unbound label L to current code position.
472 // Determines if Label is bound and near enough so that branch instruction
473 // can be used to reach it, instead of jump instruction.
474 bool is_near(Label* L);
476 // Returns the branch offset to the given label from the current code
477 // position. Links the label to the current position if it is still unbound.
478 // Manages the jump elimination optimization if the second parameter is true.
479 int32_t branch_offset(Label* L, bool jump_elimination_allowed);
480 int32_t branch_offset_compact(Label* L, bool jump_elimination_allowed);
481 int32_t branch_offset21(Label* L, bool jump_elimination_allowed);
482 int32_t branch_offset21_compact(Label* L, bool jump_elimination_allowed);
483 int32_t shifted_branch_offset(Label* L, bool jump_elimination_allowed) {
484 int32_t o = branch_offset(L, jump_elimination_allowed);
485 DCHECK((o & 3) == 0); // Assert the offset is aligned.
488 int32_t shifted_branch_offset_compact(Label* L,
489 bool jump_elimination_allowed) {
490 int32_t o = branch_offset_compact(L, jump_elimination_allowed);
491 DCHECK((o & 3) == 0); // Assert the offset is aligned.
494 uint64_t jump_address(Label* L);
495 uint64_t jump_offset(Label* L);
497 // Puts a labels target address at the given position.
498 // The high 8 bits are set to zero.
499 void label_at_put(Label* L, int at_offset);
501 // Read/Modify the code target address in the branch/call instruction at pc.
502 static Address target_address_at(Address pc);
503 static void set_target_address_at(Address pc,
505 ICacheFlushMode icache_flush_mode =
506 FLUSH_ICACHE_IF_NEEDED);
507 // On MIPS there is no Constant Pool so we skip that parameter.
508 INLINE(static Address target_address_at(Address pc, Address constant_pool)) {
509 return target_address_at(pc);
511 INLINE(static void set_target_address_at(
512 Address pc, Address constant_pool, Address target,
513 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED)) {
514 set_target_address_at(pc, target, icache_flush_mode);
516 INLINE(static Address target_address_at(Address pc, Code* code)) {
517 Address constant_pool = code ? code->constant_pool() : NULL;
518 return target_address_at(pc, constant_pool);
520 INLINE(static void set_target_address_at(Address pc,
523 ICacheFlushMode icache_flush_mode =
524 FLUSH_ICACHE_IF_NEEDED)) {
525 Address constant_pool = code ? code->constant_pool() : NULL;
526 set_target_address_at(pc, constant_pool, target, icache_flush_mode);
529 // Return the code target address at a call site from the return address
530 // of that call in the instruction stream.
531 inline static Address target_address_from_return_address(Address pc);
533 static void JumpLabelToJumpRegister(Address pc);
535 static void QuietNaN(HeapObject* nan);
537 // This sets the branch destination (which gets loaded at the call address).
538 // This is for calls and branches within generated code. The serializer
539 // has already deserialized the lui/ori instructions etc.
540 inline static void deserialization_set_special_target_at(
541 Address instruction_payload, Code* code, Address target) {
542 set_target_address_at(
543 instruction_payload - kInstructionsFor64BitConstant * kInstrSize,
548 // This sets the internal reference at the pc.
549 inline static void deserialization_set_target_internal_reference_at(
550 Address pc, Address target,
551 RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
553 // Size of an instruction.
554 static const int kInstrSize = sizeof(Instr);
556 // Difference between address of current opcode and target address offset.
557 static const int kBranchPCOffset = 4;
559 // Here we are patching the address in the LUI/ORI instruction pair.
560 // These values are used in the serialization process and must be zero for
561 // MIPS platform, as Code, Embedded Object or External-reference pointers
562 // are split across two consecutive instructions and don't exist separately
563 // in the code, so the serializer should not step forwards in memory after
564 // a target is resolved and written.
565 static const int kSpecialTargetSize = 0;
567 // Number of consecutive instructions used to store 32bit/64bit constant.
568 // This constant was used in RelocInfo::target_address_address() function
569 // to tell serializer address of the instruction that follows
570 // LUI/ORI instruction pair.
571 static const int kInstructionsFor32BitConstant = 2;
572 static const int kInstructionsFor64BitConstant = 4;
574 // Distance between the instruction referring to the address of the call
575 // target and the return address.
576 static const int kCallTargetAddressOffset = 6 * kInstrSize;
578 // Distance between start of patched debug break slot and the emitted address
580 static const int kPatchDebugBreakSlotAddressOffset = 6 * kInstrSize;
582 // Difference between address of current opcode and value read from pc
584 static const int kPcLoadDelta = 4;
586 static const int kDebugBreakSlotInstructions = 6;
587 static const int kDebugBreakSlotLength =
588 kDebugBreakSlotInstructions * kInstrSize;
591 // ---------------------------------------------------------------------------
594 // Insert the smallest number of nop instructions
595 // possible to align the pc offset to a multiple
596 // of m. m must be a power of 2 (>= 4).
598 // Insert the smallest number of zero bytes possible to align the pc offset
599 // to a mulitple of m. m must be a power of 2 (>= 2).
600 void DataAlign(int m);
601 // Aligns code to something that's optimal for a jump target for the platform.
602 void CodeTargetAlign();
604 // Different nop operations are used by the code generator to detect certain
605 // states of the generated code.
606 enum NopMarkerTypes {
610 PROPERTY_ACCESS_INLINED,
611 PROPERTY_ACCESS_INLINED_CONTEXT,
612 PROPERTY_ACCESS_INLINED_CONTEXT_DONT_DELETE,
615 FIRST_IC_MARKER = PROPERTY_ACCESS_INLINED,
617 CODE_AGE_MARKER_NOP = 6,
618 CODE_AGE_SEQUENCE_NOP
621 // Type == 0 is the default non-marking nop. For mips this is a
622 // sll(zero_reg, zero_reg, 0). We use rt_reg == at for non-zero
623 // marking, to avoid conflict with ssnop and ehb instructions.
624 void nop(unsigned int type = 0) {
626 Register nop_rt_reg = (type == 0) ? zero_reg : at;
627 sll(zero_reg, nop_rt_reg, type, true);
631 // --------Branch-and-jump-instructions----------
632 // We don't use likely variant of instructions.
633 void b(int16_t offset);
634 void b(Label* L) { b(branch_offset(L, false)>>2); }
635 void bal(int16_t offset);
636 void bal(Label* L) { bal(branch_offset(L, false)>>2); }
637 void bc(int32_t offset);
638 void bc(Label* L) { bc(branch_offset(L, false) >> 2); }
639 void balc(int32_t offset);
640 void balc(Label* L) { balc(branch_offset(L, false) >> 2); }
642 void beq(Register rs, Register rt, int16_t offset);
643 void beq(Register rs, Register rt, Label* L) {
644 beq(rs, rt, branch_offset(L, false) >> 2);
646 void bgez(Register rs, int16_t offset);
647 void bgezc(Register rt, int16_t offset);
648 void bgezc(Register rt, Label* L) {
649 bgezc(rt, branch_offset_compact(L, false)>>2);
651 void bgeuc(Register rs, Register rt, int16_t offset);
652 void bgeuc(Register rs, Register rt, Label* L) {
653 bgeuc(rs, rt, branch_offset_compact(L, false)>>2);
655 void bgec(Register rs, Register rt, int16_t offset);
656 void bgec(Register rs, Register rt, Label* L) {
657 bgec(rs, rt, branch_offset_compact(L, false)>>2);
659 void bgezal(Register rs, int16_t offset);
660 void bgezalc(Register rt, int16_t offset);
661 void bgezalc(Register rt, Label* L) {
662 bgezalc(rt, branch_offset_compact(L, false)>>2);
664 void bgezall(Register rs, int16_t offset);
665 void bgezall(Register rs, Label* L) {
666 bgezall(rs, branch_offset(L, false)>>2);
668 void bgtz(Register rs, int16_t offset);
669 void bgtzc(Register rt, int16_t offset);
670 void bgtzc(Register rt, Label* L) {
671 bgtzc(rt, branch_offset_compact(L, false)>>2);
673 void blez(Register rs, int16_t offset);
674 void blezc(Register rt, int16_t offset);
675 void blezc(Register rt, Label* L) {
676 blezc(rt, branch_offset_compact(L, false)>>2);
678 void bltz(Register rs, int16_t offset);
679 void bltzc(Register rt, int16_t offset);
680 void bltzc(Register rt, Label* L) {
681 bltzc(rt, branch_offset_compact(L, false)>>2);
683 void bltuc(Register rs, Register rt, int16_t offset);
684 void bltuc(Register rs, Register rt, Label* L) {
685 bltuc(rs, rt, branch_offset_compact(L, false)>>2);
687 void bltc(Register rs, Register rt, int16_t offset);
688 void bltc(Register rs, Register rt, Label* L) {
689 bltc(rs, rt, branch_offset_compact(L, false)>>2);
692 void bltzal(Register rs, int16_t offset);
693 void blezalc(Register rt, int16_t offset);
694 void blezalc(Register rt, Label* L) {
695 blezalc(rt, branch_offset_compact(L, false)>>2);
697 void bltzalc(Register rt, int16_t offset);
698 void bltzalc(Register rt, Label* L) {
699 bltzalc(rt, branch_offset_compact(L, false)>>2);
701 void bgtzalc(Register rt, int16_t offset);
702 void bgtzalc(Register rt, Label* L) {
703 bgtzalc(rt, branch_offset_compact(L, false)>>2);
705 void beqzalc(Register rt, int16_t offset);
706 void beqzalc(Register rt, Label* L) {
707 beqzalc(rt, branch_offset_compact(L, false)>>2);
709 void beqc(Register rs, Register rt, int16_t offset);
710 void beqc(Register rs, Register rt, Label* L) {
711 beqc(rs, rt, branch_offset_compact(L, false)>>2);
713 void beqzc(Register rs, int32_t offset);
714 void beqzc(Register rs, Label* L) {
715 beqzc(rs, branch_offset21_compact(L, false)>>2);
717 void bnezalc(Register rt, int16_t offset);
718 void bnezalc(Register rt, Label* L) {
719 bnezalc(rt, branch_offset_compact(L, false)>>2);
721 void bnec(Register rs, Register rt, int16_t offset);
722 void bnec(Register rs, Register rt, Label* L) {
723 bnec(rs, rt, branch_offset_compact(L, false)>>2);
725 void bnezc(Register rt, int32_t offset);
726 void bnezc(Register rt, Label* L) {
727 bnezc(rt, branch_offset21_compact(L, false)>>2);
729 void bne(Register rs, Register rt, int16_t offset);
730 void bne(Register rs, Register rt, Label* L) {
731 bne(rs, rt, branch_offset(L, false)>>2);
733 void bovc(Register rs, Register rt, int16_t offset);
734 void bovc(Register rs, Register rt, Label* L) {
735 bovc(rs, rt, branch_offset_compact(L, false)>>2);
737 void bnvc(Register rs, Register rt, int16_t offset);
738 void bnvc(Register rs, Register rt, Label* L) {
739 bnvc(rs, rt, branch_offset_compact(L, false)>>2);
742 // Never use the int16_t b(l)cond version with a branch offset
743 // instead of using the Label* version.
745 // Jump targets must be in the current 256 MB-aligned region. i.e. 28 bits.
746 void j(int64_t target);
747 void jal(int64_t target);
748 void j(Label* target);
749 void jal(Label* target);
750 void jalr(Register rs, Register rd = ra);
751 void jr(Register target);
752 void jic(Register rt, int16_t offset);
753 void jialc(Register rt, int16_t offset);
756 // -------Data-processing-instructions---------
759 void addu(Register rd, Register rs, Register rt);
760 void subu(Register rd, Register rs, Register rt);
762 void div(Register rs, Register rt);
763 void divu(Register rs, Register rt);
764 void ddiv(Register rs, Register rt);
765 void ddivu(Register rs, Register rt);
766 void div(Register rd, Register rs, Register rt);
767 void divu(Register rd, Register rs, Register rt);
768 void ddiv(Register rd, Register rs, Register rt);
769 void ddivu(Register rd, Register rs, Register rt);
770 void mod(Register rd, Register rs, Register rt);
771 void modu(Register rd, Register rs, Register rt);
772 void dmod(Register rd, Register rs, Register rt);
773 void dmodu(Register rd, Register rs, Register rt);
775 void mul(Register rd, Register rs, Register rt);
776 void muh(Register rd, Register rs, Register rt);
777 void mulu(Register rd, Register rs, Register rt);
778 void muhu(Register rd, Register rs, Register rt);
779 void mult(Register rs, Register rt);
780 void multu(Register rs, Register rt);
781 void dmul(Register rd, Register rs, Register rt);
782 void dmuh(Register rd, Register rs, Register rt);
783 void dmulu(Register rd, Register rs, Register rt);
784 void dmuhu(Register rd, Register rs, Register rt);
785 void daddu(Register rd, Register rs, Register rt);
786 void dsubu(Register rd, Register rs, Register rt);
787 void dmult(Register rs, Register rt);
788 void dmultu(Register rs, Register rt);
790 void addiu(Register rd, Register rs, int32_t j);
791 void daddiu(Register rd, Register rs, int32_t j);
794 void and_(Register rd, Register rs, Register rt);
795 void or_(Register rd, Register rs, Register rt);
796 void xor_(Register rd, Register rs, Register rt);
797 void nor(Register rd, Register rs, Register rt);
799 void andi(Register rd, Register rs, int32_t j);
800 void ori(Register rd, Register rs, int32_t j);
801 void xori(Register rd, Register rs, int32_t j);
802 void lui(Register rd, int32_t j);
803 void aui(Register rs, Register rt, int32_t j);
804 void daui(Register rs, Register rt, int32_t j);
805 void dahi(Register rs, int32_t j);
806 void dati(Register rs, int32_t j);
809 // Please note: sll(zero_reg, zero_reg, x) instructions are reserved as nop
810 // and may cause problems in normal code. coming_from_nop makes sure this
812 void sll(Register rd, Register rt, uint16_t sa, bool coming_from_nop = false);
813 void sllv(Register rd, Register rt, Register rs);
814 void srl(Register rd, Register rt, uint16_t sa);
815 void srlv(Register rd, Register rt, Register rs);
816 void sra(Register rt, Register rd, uint16_t sa);
817 void srav(Register rt, Register rd, Register rs);
818 void rotr(Register rd, Register rt, uint16_t sa);
819 void rotrv(Register rd, Register rt, Register rs);
820 void dsll(Register rd, Register rt, uint16_t sa);
821 void dsllv(Register rd, Register rt, Register rs);
822 void dsrl(Register rd, Register rt, uint16_t sa);
823 void dsrlv(Register rd, Register rt, Register rs);
824 void drotr(Register rd, Register rt, uint16_t sa);
825 void drotrv(Register rd, Register rt, Register rs);
826 void dsra(Register rt, Register rd, uint16_t sa);
827 void dsrav(Register rd, Register rt, Register rs);
828 void dsll32(Register rt, Register rd, uint16_t sa);
829 void dsrl32(Register rt, Register rd, uint16_t sa);
830 void dsra32(Register rt, Register rd, uint16_t sa);
833 // ------------Memory-instructions-------------
835 void lb(Register rd, const MemOperand& rs);
836 void lbu(Register rd, const MemOperand& rs);
837 void lh(Register rd, const MemOperand& rs);
838 void lhu(Register rd, const MemOperand& rs);
839 void lw(Register rd, const MemOperand& rs);
840 void lwu(Register rd, const MemOperand& rs);
841 void lwl(Register rd, const MemOperand& rs);
842 void lwr(Register rd, const MemOperand& rs);
843 void sb(Register rd, const MemOperand& rs);
844 void sh(Register rd, const MemOperand& rs);
845 void sw(Register rd, const MemOperand& rs);
846 void swl(Register rd, const MemOperand& rs);
847 void swr(Register rd, const MemOperand& rs);
848 void ldl(Register rd, const MemOperand& rs);
849 void ldr(Register rd, const MemOperand& rs);
850 void sdl(Register rd, const MemOperand& rs);
851 void sdr(Register rd, const MemOperand& rs);
852 void ld(Register rd, const MemOperand& rs);
853 void sd(Register rd, const MemOperand& rs);
856 // ---------PC-Relative-instructions-----------
858 void addiupc(Register rs, int32_t imm19);
859 void lwpc(Register rs, int32_t offset19);
860 void lwupc(Register rs, int32_t offset19);
861 void ldpc(Register rs, int32_t offset18);
862 void auipc(Register rs, int16_t imm16);
863 void aluipc(Register rs, int16_t imm16);
866 // ----------------Prefetch--------------------
868 void pref(int32_t hint, const MemOperand& rs);
871 // -------------Misc-instructions--------------
873 // Break / Trap instructions.
874 void break_(uint32_t code, bool break_as_stop = false);
875 void stop(const char* msg, uint32_t code = kMaxStopCode);
876 void tge(Register rs, Register rt, uint16_t code);
877 void tgeu(Register rs, Register rt, uint16_t code);
878 void tlt(Register rs, Register rt, uint16_t code);
879 void tltu(Register rs, Register rt, uint16_t code);
880 void teq(Register rs, Register rt, uint16_t code);
881 void tne(Register rs, Register rt, uint16_t code);
883 // Move from HI/LO register.
884 void mfhi(Register rd);
885 void mflo(Register rd);
888 void slt(Register rd, Register rs, Register rt);
889 void sltu(Register rd, Register rs, Register rt);
890 void slti(Register rd, Register rs, int32_t j);
891 void sltiu(Register rd, Register rs, int32_t j);
894 void movz(Register rd, Register rs, Register rt);
895 void movn(Register rd, Register rs, Register rt);
896 void movt(Register rd, Register rs, uint16_t cc = 0);
897 void movf(Register rd, Register rs, uint16_t cc = 0);
899 void sel(SecondaryField fmt, FPURegister fd, FPURegister fs, FPURegister ft);
900 void sel_s(FPURegister fd, FPURegister fs, FPURegister ft);
901 void sel_d(FPURegister fd, FPURegister fs, FPURegister ft);
902 void seleqz(Register rd, Register rs, Register rt);
903 void seleqz(SecondaryField fmt, FPURegister fd, FPURegister fs,
905 void selnez(Register rs, Register rt, Register rd);
906 void selnez(SecondaryField fmt, FPURegister fd, FPURegister fs,
908 void seleqz_d(FPURegister fd, FPURegister fs, FPURegister ft);
909 void seleqz_s(FPURegister fd, FPURegister fs, FPURegister ft);
910 void selnez_d(FPURegister fd, FPURegister fs, FPURegister ft);
911 void selnez_s(FPURegister fd, FPURegister fs, FPURegister ft);
913 void movz_s(FPURegister fd, FPURegister fs, Register rt);
914 void movz_d(FPURegister fd, FPURegister fs, Register rt);
915 void movt_s(FPURegister fd, FPURegister fs, uint16_t cc);
916 void movt_d(FPURegister fd, FPURegister fs, uint16_t cc);
917 void movf_s(FPURegister fd, FPURegister fs, uint16_t cc);
918 void movf_d(FPURegister fd, FPURegister fs, uint16_t cc);
919 void movn_s(FPURegister fd, FPURegister fs, Register rt);
920 void movn_d(FPURegister fd, FPURegister fs, Register rt);
922 void clz(Register rd, Register rs);
923 void ins_(Register rt, Register rs, uint16_t pos, uint16_t size);
924 void ext_(Register rt, Register rs, uint16_t pos, uint16_t size);
925 void dext_(Register rt, Register rs, uint16_t pos, uint16_t size);
926 void bitswap(Register rd, Register rt);
927 void dbitswap(Register rd, Register rt);
928 void align(Register rd, Register rs, Register rt, uint8_t bp);
929 void dalign(Register rd, Register rs, Register rt, uint8_t bp);
931 // --------Coprocessor-instructions----------------
933 // Load, store, and move.
934 void lwc1(FPURegister fd, const MemOperand& src);
935 void ldc1(FPURegister fd, const MemOperand& src);
937 void swc1(FPURegister fs, const MemOperand& dst);
938 void sdc1(FPURegister fs, const MemOperand& dst);
940 void mtc1(Register rt, FPURegister fs);
941 void mthc1(Register rt, FPURegister fs);
942 void dmtc1(Register rt, FPURegister fs);
944 void mfc1(Register rt, FPURegister fs);
945 void mfhc1(Register rt, FPURegister fs);
946 void dmfc1(Register rt, FPURegister fs);
948 void ctc1(Register rt, FPUControlRegister fs);
949 void cfc1(Register rt, FPUControlRegister fs);
952 void add_s(FPURegister fd, FPURegister fs, FPURegister ft);
953 void add_d(FPURegister fd, FPURegister fs, FPURegister ft);
954 void sub_s(FPURegister fd, FPURegister fs, FPURegister ft);
955 void sub_d(FPURegister fd, FPURegister fs, FPURegister ft);
956 void mul_s(FPURegister fd, FPURegister fs, FPURegister ft);
957 void mul_d(FPURegister fd, FPURegister fs, FPURegister ft);
958 void madd_d(FPURegister fd, FPURegister fr, FPURegister fs, FPURegister ft);
959 void div_s(FPURegister fd, FPURegister fs, FPURegister ft);
960 void div_d(FPURegister fd, FPURegister fs, FPURegister ft);
961 void abs_s(FPURegister fd, FPURegister fs);
962 void abs_d(FPURegister fd, FPURegister fs);
963 void mov_d(FPURegister fd, FPURegister fs);
964 void mov_s(FPURegister fd, FPURegister fs);
965 void neg_s(FPURegister fd, FPURegister fs);
966 void neg_d(FPURegister fd, FPURegister fs);
967 void sqrt_s(FPURegister fd, FPURegister fs);
968 void sqrt_d(FPURegister fd, FPURegister fs);
969 void rsqrt_s(FPURegister fd, FPURegister fs);
970 void rsqrt_d(FPURegister fd, FPURegister fs);
971 void recip_d(FPURegister fd, FPURegister fs);
972 void recip_s(FPURegister fd, FPURegister fs);
975 void cvt_w_s(FPURegister fd, FPURegister fs);
976 void cvt_w_d(FPURegister fd, FPURegister fs);
977 void trunc_w_s(FPURegister fd, FPURegister fs);
978 void trunc_w_d(FPURegister fd, FPURegister fs);
979 void round_w_s(FPURegister fd, FPURegister fs);
980 void round_w_d(FPURegister fd, FPURegister fs);
981 void floor_w_s(FPURegister fd, FPURegister fs);
982 void floor_w_d(FPURegister fd, FPURegister fs);
983 void ceil_w_s(FPURegister fd, FPURegister fs);
984 void ceil_w_d(FPURegister fd, FPURegister fs);
985 void rint_s(FPURegister fd, FPURegister fs);
986 void rint_d(FPURegister fd, FPURegister fs);
987 void rint(SecondaryField fmt, FPURegister fd, FPURegister fs);
990 void cvt_l_s(FPURegister fd, FPURegister fs);
991 void cvt_l_d(FPURegister fd, FPURegister fs);
992 void trunc_l_s(FPURegister fd, FPURegister fs);
993 void trunc_l_d(FPURegister fd, FPURegister fs);
994 void round_l_s(FPURegister fd, FPURegister fs);
995 void round_l_d(FPURegister fd, FPURegister fs);
996 void floor_l_s(FPURegister fd, FPURegister fs);
997 void floor_l_d(FPURegister fd, FPURegister fs);
998 void ceil_l_s(FPURegister fd, FPURegister fs);
999 void ceil_l_d(FPURegister fd, FPURegister fs);
1001 void class_s(FPURegister fd, FPURegister fs);
1002 void class_d(FPURegister fd, FPURegister fs);
1004 void min(SecondaryField fmt, FPURegister fd, FPURegister fs, FPURegister ft);
1005 void mina(SecondaryField fmt, FPURegister fd, FPURegister fs, FPURegister ft);
1006 void max(SecondaryField fmt, FPURegister fd, FPURegister fs, FPURegister ft);
1007 void maxa(SecondaryField fmt, FPURegister fd, FPURegister fs, FPURegister ft);
1008 void min_s(FPURegister fd, FPURegister fs, FPURegister ft);
1009 void min_d(FPURegister fd, FPURegister fs, FPURegister ft);
1010 void max_s(FPURegister fd, FPURegister fs, FPURegister ft);
1011 void max_d(FPURegister fd, FPURegister fs, FPURegister ft);
1012 void mina_s(FPURegister fd, FPURegister fs, FPURegister ft);
1013 void mina_d(FPURegister fd, FPURegister fs, FPURegister ft);
1014 void maxa_s(FPURegister fd, FPURegister fs, FPURegister ft);
1015 void maxa_d(FPURegister fd, FPURegister fs, FPURegister ft);
1017 void cvt_s_w(FPURegister fd, FPURegister fs);
1018 void cvt_s_l(FPURegister fd, FPURegister fs);
1019 void cvt_s_d(FPURegister fd, FPURegister fs);
1021 void cvt_d_w(FPURegister fd, FPURegister fs);
1022 void cvt_d_l(FPURegister fd, FPURegister fs);
1023 void cvt_d_s(FPURegister fd, FPURegister fs);
1025 // Conditions and branches for MIPSr6.
1026 void cmp(FPUCondition cond, SecondaryField fmt,
1027 FPURegister fd, FPURegister ft, FPURegister fs);
1028 void cmp_s(FPUCondition cond, FPURegister fd, FPURegister fs, FPURegister ft);
1029 void cmp_d(FPUCondition cond, FPURegister fd, FPURegister fs, FPURegister ft);
1031 void bc1eqz(int16_t offset, FPURegister ft);
1032 void bc1eqz(Label* L, FPURegister ft) {
1033 bc1eqz(branch_offset(L, false)>>2, ft);
1035 void bc1nez(int16_t offset, FPURegister ft);
1036 void bc1nez(Label* L, FPURegister ft) {
1037 bc1nez(branch_offset(L, false)>>2, ft);
1040 // Conditions and branches for non MIPSr6.
1041 void c(FPUCondition cond, SecondaryField fmt,
1042 FPURegister ft, FPURegister fs, uint16_t cc = 0);
1043 void c_s(FPUCondition cond, FPURegister ft, FPURegister fs, uint16_t cc = 0);
1044 void c_d(FPUCondition cond, FPURegister ft, FPURegister fs, uint16_t cc = 0);
1046 void bc1f(int16_t offset, uint16_t cc = 0);
1047 void bc1f(Label* L, uint16_t cc = 0) {
1048 bc1f(branch_offset(L, false)>>2, cc);
1050 void bc1t(int16_t offset, uint16_t cc = 0);
1051 void bc1t(Label* L, uint16_t cc = 0) {
1052 bc1t(branch_offset(L, false)>>2, cc);
1054 void fcmp(FPURegister src1, const double src2, FPUCondition cond);
1056 // Check the code size generated from label to here.
1057 int SizeOfCodeGeneratedSince(Label* label) {
1058 return pc_offset() - label->pos();
1061 // Check the number of instructions generated from label to here.
1062 int InstructionsGeneratedSince(Label* label) {
1063 return SizeOfCodeGeneratedSince(label) / kInstrSize;
1066 // Class for scoping postponing the trampoline pool generation.
1067 class BlockTrampolinePoolScope {
1069 explicit BlockTrampolinePoolScope(Assembler* assem) : assem_(assem) {
1070 assem_->StartBlockTrampolinePool();
1072 ~BlockTrampolinePoolScope() {
1073 assem_->EndBlockTrampolinePool();
1079 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockTrampolinePoolScope);
1082 // Class for postponing the assembly buffer growth. Typically used for
1083 // sequences of instructions that must be emitted as a unit, before
1084 // buffer growth (and relocation) can occur.
1085 // This blocking scope is not nestable.
1086 class BlockGrowBufferScope {
1088 explicit BlockGrowBufferScope(Assembler* assem) : assem_(assem) {
1089 assem_->StartBlockGrowBuffer();
1091 ~BlockGrowBufferScope() {
1092 assem_->EndBlockGrowBuffer();
1098 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockGrowBufferScope);
1103 // Mark generator continuation.
1104 void RecordGeneratorContinuation();
1106 // Mark address of a debug break slot.
1107 void RecordDebugBreakSlot(RelocInfo::Mode mode, int argc = 0);
1109 // Record the AST id of the CallIC being compiled, so that it can be placed
1110 // in the relocation information.
1111 void SetRecordedAstId(TypeFeedbackId ast_id) {
1112 DCHECK(recorded_ast_id_.IsNone());
1113 recorded_ast_id_ = ast_id;
1116 TypeFeedbackId RecordedAstId() {
1117 DCHECK(!recorded_ast_id_.IsNone());
1118 return recorded_ast_id_;
1121 void ClearRecordedAstId() { recorded_ast_id_ = TypeFeedbackId::None(); }
1123 // Record a comment relocation entry that can be used by a disassembler.
1124 // Use --code-comments to enable.
1125 void RecordComment(const char* msg);
1127 // Record a deoptimization reason that can be used by a log or cpu profiler.
1128 // Use --trace-deopt to enable.
1129 void RecordDeoptReason(const int reason, const SourcePosition position);
1131 static int RelocateInternalReference(RelocInfo::Mode rmode, byte* pc,
1134 // Writes a single byte or word of data in the code stream. Used for
1135 // inline tables, e.g., jump-tables.
1136 void db(uint8_t data);
1137 void dd(uint32_t data);
1138 void dq(uint64_t data);
1139 void dp(uintptr_t data) { dq(data); }
1140 void dd(Label* label);
1142 // Emits the address of the code stub's first instruction.
1143 void emit_code_stub_address(Code* stub);
1145 PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1147 // Postpone the generation of the trampoline pool for the specified number of
1149 void BlockTrampolinePoolFor(int instructions);
1151 // Check if there is less than kGap bytes available in the buffer.
1152 // If this is the case, we need to grow the buffer before emitting
1153 // an instruction or relocation information.
1154 inline bool overflow() const { return pc_ >= reloc_info_writer.pos() - kGap; }
1156 // Get the number of bytes available in the buffer.
1157 inline intptr_t available_space() const {
1158 return reloc_info_writer.pos() - pc_;
1161 // Read/patch instructions.
1162 static Instr instr_at(byte* pc) { return *reinterpret_cast<Instr*>(pc); }
1163 static void instr_at_put(byte* pc, Instr instr) {
1164 *reinterpret_cast<Instr*>(pc) = instr;
1166 Instr instr_at(int pos) { return *reinterpret_cast<Instr*>(buffer_ + pos); }
1167 void instr_at_put(int pos, Instr instr) {
1168 *reinterpret_cast<Instr*>(buffer_ + pos) = instr;
1171 // Check if an instruction is a branch of some kind.
1172 static bool IsBranch(Instr instr);
1173 static bool IsBeq(Instr instr);
1174 static bool IsBne(Instr instr);
1176 static bool IsJump(Instr instr);
1177 static bool IsJ(Instr instr);
1178 static bool IsLui(Instr instr);
1179 static bool IsOri(Instr instr);
1181 static bool IsJal(Instr instr);
1182 static bool IsJr(Instr instr);
1183 static bool IsJalr(Instr instr);
1185 static bool IsNop(Instr instr, unsigned int type);
1186 static bool IsPop(Instr instr);
1187 static bool IsPush(Instr instr);
1188 static bool IsLwRegFpOffset(Instr instr);
1189 static bool IsSwRegFpOffset(Instr instr);
1190 static bool IsLwRegFpNegOffset(Instr instr);
1191 static bool IsSwRegFpNegOffset(Instr instr);
1193 static Register GetRtReg(Instr instr);
1194 static Register GetRsReg(Instr instr);
1195 static Register GetRdReg(Instr instr);
1197 static uint32_t GetRt(Instr instr);
1198 static uint32_t GetRtField(Instr instr);
1199 static uint32_t GetRs(Instr instr);
1200 static uint32_t GetRsField(Instr instr);
1201 static uint32_t GetRd(Instr instr);
1202 static uint32_t GetRdField(Instr instr);
1203 static uint32_t GetSa(Instr instr);
1204 static uint32_t GetSaField(Instr instr);
1205 static uint32_t GetOpcodeField(Instr instr);
1206 static uint32_t GetFunction(Instr instr);
1207 static uint32_t GetFunctionField(Instr instr);
1208 static uint32_t GetImmediate16(Instr instr);
1209 static uint32_t GetLabelConst(Instr instr);
1211 static int32_t GetBranchOffset(Instr instr);
1212 static bool IsLw(Instr instr);
1213 static int16_t GetLwOffset(Instr instr);
1214 static Instr SetLwOffset(Instr instr, int16_t offset);
1216 static bool IsSw(Instr instr);
1217 static Instr SetSwOffset(Instr instr, int16_t offset);
1218 static bool IsAddImmediate(Instr instr);
1219 static Instr SetAddImmediateOffset(Instr instr, int16_t offset);
1221 static bool IsAndImmediate(Instr instr);
1222 static bool IsEmittedConstant(Instr instr);
1224 void CheckTrampolinePool();
1226 void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1227 ConstantPoolEntry::Access access,
1228 ConstantPoolEntry::Type type) {
1229 // No embedded constant pool support.
1234 // Relocation for a type-recording IC has the AST id added to it. This
1235 // member variable is a way to pass the information from the call site to
1236 // the relocation info.
1237 TypeFeedbackId recorded_ast_id_;
1239 inline static void set_target_internal_reference_encoded_at(Address pc,
1242 int64_t buffer_space() const { return reloc_info_writer.pos() - pc_; }
1244 // Decode branch instruction at pos and return branch target pos.
1245 int target_at(int pos, bool is_internal);
1247 // Patch branch instruction at pos to branch to given branch target pos.
1248 void target_at_put(int pos, int target_pos, bool is_internal);
1250 // Say if we need to relocate with this mode.
1251 bool MustUseReg(RelocInfo::Mode rmode);
1253 // Record reloc info for current pc_.
1254 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1256 // Block the emission of the trampoline pool before pc_offset.
1257 void BlockTrampolinePoolBefore(int pc_offset) {
1258 if (no_trampoline_pool_before_ < pc_offset)
1259 no_trampoline_pool_before_ = pc_offset;
1262 void StartBlockTrampolinePool() {
1263 trampoline_pool_blocked_nesting_++;
1266 void EndBlockTrampolinePool() {
1267 trampoline_pool_blocked_nesting_--;
1270 bool is_trampoline_pool_blocked() const {
1271 return trampoline_pool_blocked_nesting_ > 0;
1274 bool has_exception() const {
1275 return internal_trampoline_exception_;
1278 void DoubleAsTwoUInt32(double d, uint32_t* lo, uint32_t* hi);
1280 bool is_trampoline_emitted() const {
1281 return trampoline_emitted_;
1284 // Temporarily block automatic assembly buffer growth.
1285 void StartBlockGrowBuffer() {
1286 DCHECK(!block_buffer_growth_);
1287 block_buffer_growth_ = true;
1290 void EndBlockGrowBuffer() {
1291 DCHECK(block_buffer_growth_);
1292 block_buffer_growth_ = false;
1295 bool is_buffer_growth_blocked() const {
1296 return block_buffer_growth_;
1300 // Buffer size and constant pool distance are checked together at regular
1301 // intervals of kBufferCheckInterval emitted bytes.
1302 static const int kBufferCheckInterval = 1*KB/2;
1305 // The relocation writer's position is at least kGap bytes below the end of
1306 // the generated instructions. This is so that multi-instruction sequences do
1307 // not have to check for overflow. The same is true for writes of large
1308 // relocation info entries.
1309 static const int kGap = 32;
1312 // Repeated checking whether the trampoline pool should be emitted is rather
1313 // expensive. By default we only check again once a number of instructions
1314 // has been generated.
1315 static const int kCheckConstIntervalInst = 32;
1316 static const int kCheckConstInterval = kCheckConstIntervalInst * kInstrSize;
1318 int next_buffer_check_; // pc offset of next buffer check.
1320 // Emission of the trampoline pool may be blocked in some code sequences.
1321 int trampoline_pool_blocked_nesting_; // Block emission if this is not zero.
1322 int no_trampoline_pool_before_; // Block emission before this pc offset.
1324 // Keep track of the last emitted pool to guarantee a maximal distance.
1325 int last_trampoline_pool_end_; // pc offset of the end of the last pool.
1327 // Automatic growth of the assembly buffer may be blocked for some sequences.
1328 bool block_buffer_growth_; // Block growth when true.
1330 // Relocation information generation.
1331 // Each relocation is encoded as a variable size value.
1332 static const int kMaxRelocSize = RelocInfoWriter::kMaxSize;
1333 RelocInfoWriter reloc_info_writer;
1335 // The bound position, before this we cannot do instruction elimination.
1336 int last_bound_pos_;
1339 inline void CheckBuffer();
1341 inline void emit(Instr x);
1342 inline void emit(uint64_t x);
1343 inline void CheckTrampolinePoolQuick(int extra_instructions = 0);
1345 // Instruction generation.
1346 // We have 3 different kind of encoding layout on MIPS.
1347 // However due to many different types of objects encoded in the same fields
1348 // we have quite a few aliases for each mode.
1349 // Using the same structure to refer to Register and FPURegister would spare a
1350 // few aliases, but mixing both does not look clean to me.
1351 // Anyway we could surely implement this differently.
1353 void GenInstrRegister(Opcode opcode,
1358 SecondaryField func = NULLSF);
1360 void GenInstrRegister(Opcode opcode,
1365 SecondaryField func);
1367 void GenInstrRegister(Opcode opcode,
1372 SecondaryField func = NULLSF);
1374 void GenInstrRegister(Opcode opcode,
1379 SecondaryField func = NULLSF);
1381 void GenInstrRegister(Opcode opcode,
1386 SecondaryField func = NULLSF);
1388 void GenInstrRegister(Opcode opcode,
1391 FPUControlRegister fs,
1392 SecondaryField func = NULLSF);
1395 void GenInstrImmediate(Opcode opcode,
1399 void GenInstrImmediate(Opcode opcode,
1403 void GenInstrImmediate(Opcode opcode,
1407 void GenInstrImmediate(Opcode opcode, Register rs, int32_t j);
1408 void GenInstrImmediate(Opcode opcode, int32_t offset26);
1411 void GenInstrJump(Opcode opcode,
1415 void LoadRegPlusOffsetToAt(const MemOperand& src);
1418 void print(Label* L);
1419 void bind_to(Label* L, int pos);
1420 void next(Label* L, bool is_internal);
1422 // One trampoline consists of:
1423 // - space for trampoline slots,
1424 // - space for labels.
1426 // Space for trampoline slots is equal to slot_count * 2 * kInstrSize.
1427 // Space for trampoline slots preceeds space for labels. Each label is of one
1428 // instruction size, so total amount for labels is equal to
1429 // label_count * kInstrSize.
1435 free_slot_count_ = 0;
1438 Trampoline(int start, int slot_count) {
1441 free_slot_count_ = slot_count;
1442 end_ = start + slot_count * kTrampolineSlotsSize;
1451 int trampoline_slot = kInvalidSlotPos;
1452 if (free_slot_count_ <= 0) {
1453 // We have run out of space on trampolines.
1454 // Make sure we fail in debug mode, so we become aware of each case
1455 // when this happens.
1457 // Internal exception will be caught.
1459 trampoline_slot = next_slot_;
1461 next_slot_ += kTrampolineSlotsSize;
1463 return trampoline_slot;
1470 int free_slot_count_;
1473 int32_t get_trampoline_entry(int32_t pos);
1474 int unbound_labels_count_;
1475 // After trampoline is emitted, long branches are used in generated code for
1476 // the forward branches whose target offsets could be beyond reach of branch
1477 // instruction. We use this information to trigger different mode of
1478 // branch instruction generation, where we use jump instructions rather
1479 // than regular branch instructions.
1480 bool trampoline_emitted_;
1481 static const int kTrampolineSlotsSize = 2 * kInstrSize;
1482 static const int kMaxBranchOffset = (1 << (18 - 1)) - 1;
1483 static const int kInvalidSlotPos = -1;
1485 // Internal reference positions, required for unbounded internal reference
1487 std::set<int64_t> internal_reference_positions_;
1489 Trampoline trampoline_;
1490 bool internal_trampoline_exception_;
1492 friend class RegExpMacroAssemblerMIPS;
1493 friend class RelocInfo;
1494 friend class CodePatcher;
1495 friend class BlockTrampolinePoolScope;
1497 PositionsRecorder positions_recorder_;
1498 friend class PositionsRecorder;
1499 friend class EnsureSpace;
1503 class EnsureSpace BASE_EMBEDDED {
1505 explicit EnsureSpace(Assembler* assembler) {
1506 assembler->CheckBuffer();
1510 } // namespace internal
1513 #endif // V8_ARM_ASSEMBLER_MIPS_H_