Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ |
| 6 | #define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/assembler.h" |
| 9 | #include "src/globals.h" |
| 10 | #include "src/mips/assembler-mips.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | // Give alias names to registers for calling conventions. |
| 16 | const Register kReturnRegister0 = {Register::kCode_v0}; |
| 17 | const Register kReturnRegister1 = {Register::kCode_v1}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 18 | const Register kReturnRegister2 = {Register::kCode_a0}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | const Register kJSFunctionRegister = {Register::kCode_a1}; |
| 20 | const Register kContextRegister = {Register::kCpRegister}; |
| 21 | const Register kInterpreterAccumulatorRegister = {Register::kCode_v0}; |
| 22 | const Register kInterpreterRegisterFileRegister = {Register::kCode_t3}; |
| 23 | const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_t4}; |
| 24 | const Register kInterpreterBytecodeArrayRegister = {Register::kCode_t5}; |
| 25 | const Register kInterpreterDispatchTableRegister = {Register::kCode_t6}; |
| 26 | const Register kJavaScriptCallArgCountRegister = {Register::kCode_a0}; |
| 27 | const Register kJavaScriptCallNewTargetRegister = {Register::kCode_a3}; |
| 28 | const Register kRuntimeCallFunctionRegister = {Register::kCode_a1}; |
| 29 | const Register kRuntimeCallArgCountRegister = {Register::kCode_a0}; |
| 30 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 31 | // Forward declaration. |
| 32 | class JumpTarget; |
| 33 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 34 | // Reserved Register Usage Summary. |
| 35 | // |
| 36 | // Registers t8, t9, and at are reserved for use by the MacroAssembler. |
| 37 | // |
| 38 | // The programmer should know that the MacroAssembler may clobber these three, |
| 39 | // but won't touch other registers except in special cases. |
| 40 | // |
| 41 | // Per the MIPS ABI, register t9 must be used for indirect function call |
| 42 | // via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when |
| 43 | // trying to update gp register for position-independent-code. Whenever |
| 44 | // MIPS generated code calls C code, it must be via t9 register. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 45 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 46 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | // Flags used for LeaveExitFrame function. |
| 48 | enum LeaveExitFrameMode { |
| 49 | EMIT_RETURN = true, |
| 50 | NO_EMIT_RETURN = false |
| 51 | }; |
| 52 | |
| 53 | // Flags used for AllocateHeapNumber |
| 54 | enum TaggingMode { |
| 55 | // Tag the result. |
| 56 | TAG_RESULT, |
| 57 | // Don't tag |
| 58 | DONT_TAG_RESULT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | // Flags used for the ObjectToDoubleFPURegister function. |
| 62 | enum ObjectToDoubleFlags { |
| 63 | // No special flags. |
| 64 | NO_OBJECT_TO_DOUBLE_FLAGS = 0, |
| 65 | // Object is known to be a non smi. |
| 66 | OBJECT_NOT_SMI = 1 << 0, |
| 67 | // Don't load NaNs or infinities, branch to the non number case instead. |
| 68 | AVOID_NANS_AND_INFINITIES = 1 << 1 |
| 69 | }; |
| 70 | |
| 71 | // Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls. |
| 72 | enum BranchDelaySlot { |
| 73 | USE_DELAY_SLOT, |
| 74 | PROTECT |
| 75 | }; |
| 76 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 77 | // Flags used for the li macro-assembler function. |
| 78 | enum LiFlags { |
| 79 | // If the constant value can be represented in just 16 bits, then |
| 80 | // optimize the li to use a single instruction, rather than lui/ori pair. |
| 81 | OPTIMIZE_SIZE = 0, |
| 82 | // Always use 2 instructions (lui/ori pair), even if the constant could |
| 83 | // be loaded with just one, so that this value is patchable later. |
| 84 | CONSTANT_SIZE = 1 |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 89 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | enum PointersToHereCheck { |
| 91 | kPointersToHereMaybeInteresting, |
| 92 | kPointersToHereAreAlwaysInteresting |
| 93 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 94 | enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved }; |
| 95 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 96 | Register GetRegisterThatIsNotOneOf(Register reg1, |
| 97 | Register reg2 = no_reg, |
| 98 | Register reg3 = no_reg, |
| 99 | Register reg4 = no_reg, |
| 100 | Register reg5 = no_reg, |
| 101 | Register reg6 = no_reg); |
| 102 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 103 | bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg, |
| 104 | Register reg4 = no_reg, Register reg5 = no_reg, |
| 105 | Register reg6 = no_reg, Register reg7 = no_reg, |
| 106 | Register reg8 = no_reg, Register reg9 = no_reg, |
| 107 | Register reg10 = no_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 108 | |
| 109 | |
| 110 | // ----------------------------------------------------------------------------- |
| 111 | // Static helper functions. |
| 112 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 113 | inline MemOperand ContextMemOperand(Register context, int index) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 114 | return MemOperand(context, Context::SlotOffset(index)); |
| 115 | } |
| 116 | |
| 117 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 118 | inline MemOperand NativeContextMemOperand() { |
| 119 | return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
| 123 | // Generate a MemOperand for loading a field from an object. |
| 124 | inline MemOperand FieldMemOperand(Register object, int offset) { |
| 125 | return MemOperand(object, offset - kHeapObjectTag); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | // Generate a MemOperand for storing arguments 5..N on the stack |
| 130 | // when calling CallCFunction(). |
| 131 | inline MemOperand CFunctionArgumentOperand(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | DCHECK(index > kCArgSlotCount); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 133 | // Argument 5 takes the slot just past the four Arg-slots. |
| 134 | int offset = (index - 5) * kPointerSize + kCArgsSlotsSize; |
| 135 | return MemOperand(sp, offset); |
| 136 | } |
| 137 | |
| 138 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 139 | // MacroAssembler implements a collection of frequently used macros. |
| 140 | class MacroAssembler: public Assembler { |
| 141 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 142 | MacroAssembler(Isolate* isolate, void* buffer, int size, |
| 143 | CodeObjectRequired create_code_object); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 144 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 145 | // Arguments macros. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 146 | #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2 |
| 147 | #define COND_ARGS cond, r1, r2 |
| 148 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 149 | // Cases when relocation is not needed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 150 | #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \ |
| 151 | void Name(target_type target, BranchDelaySlot bd = PROTECT); \ |
| 152 | inline void Name(BranchDelaySlot bd, target_type target) { \ |
| 153 | Name(target, bd); \ |
| 154 | } \ |
| 155 | void Name(target_type target, \ |
| 156 | COND_TYPED_ARGS, \ |
| 157 | BranchDelaySlot bd = PROTECT); \ |
| 158 | inline void Name(BranchDelaySlot bd, \ |
| 159 | target_type target, \ |
| 160 | COND_TYPED_ARGS) { \ |
| 161 | Name(target, COND_ARGS, bd); \ |
| 162 | } |
| 163 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 164 | #define DECLARE_BRANCH_PROTOTYPES(Name) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 165 | DECLARE_NORELOC_PROTOTYPE(Name, Label*) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 166 | DECLARE_NORELOC_PROTOTYPE(Name, int32_t) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 167 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 168 | DECLARE_BRANCH_PROTOTYPES(Branch) |
| 169 | DECLARE_BRANCH_PROTOTYPES(BranchAndLink) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 170 | DECLARE_BRANCH_PROTOTYPES(BranchShort) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 171 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 172 | #undef DECLARE_BRANCH_PROTOTYPES |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 173 | #undef COND_TYPED_ARGS |
| 174 | #undef COND_ARGS |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 175 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 176 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 177 | // Jump, Call, and Ret pseudo instructions implementing inter-working. |
| 178 | #define COND_ARGS Condition cond = al, Register rs = zero_reg, \ |
| 179 | const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT |
| 180 | |
| 181 | void Jump(Register target, COND_ARGS); |
| 182 | void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS); |
| 183 | void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS); |
| 184 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 185 | static int CallSize(Register target, COND_ARGS); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 186 | void Call(Register target, COND_ARGS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 187 | static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 188 | void Call(Address target, RelocInfo::Mode rmode, COND_ARGS); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 189 | int CallSize(Handle<Code> code, |
| 190 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 191 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 192 | COND_ARGS); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 193 | void Call(Handle<Code> code, |
| 194 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 195 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 196 | COND_ARGS); |
| 197 | void Ret(COND_ARGS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 198 | inline void Ret(BranchDelaySlot bd, Condition cond = al, |
| 199 | Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) { |
| 200 | Ret(cond, rs, rt, bd); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | bool IsNear(Label* L, Condition cond, int rs_reg); |
| 204 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 205 | void Branch(Label* L, |
| 206 | Condition cond, |
| 207 | Register rs, |
| 208 | Heap::RootListIndex index, |
| 209 | BranchDelaySlot bdslot = PROTECT); |
| 210 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 211 | // GetLabelFunction must be lambda '[](size_t index) -> Label*' or a |
| 212 | // functor/function with 'Label *func(size_t index)' declaration. |
| 213 | template <typename Func> |
| 214 | void GenerateSwitchTable(Register index, size_t case_count, |
| 215 | Func GetLabelFunction); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 216 | #undef COND_ARGS |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 217 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 218 | // Emit code to discard a non-negative number of pointer-sized elements |
| 219 | // from the stack, clobbering only the sp register. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 220 | void Drop(int count, |
| 221 | Condition cond = cc_always, |
| 222 | Register reg = no_reg, |
| 223 | const Operand& op = Operand(no_reg)); |
| 224 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 225 | // Trivial case of DropAndRet that utilizes the delay slot and only emits |
| 226 | // 2 instructions. |
| 227 | void DropAndRet(int drop); |
| 228 | |
| 229 | void DropAndRet(int drop, |
| 230 | Condition cond, |
| 231 | Register reg, |
| 232 | const Operand& op); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 233 | |
| 234 | // Swap two registers. If the scratch register is omitted then a slightly |
| 235 | // less efficient form using xor instead of mov is emitted. |
| 236 | void Swap(Register reg1, Register reg2, Register scratch = no_reg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 237 | |
| 238 | void Call(Label* target); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 240 | void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); } |
| 241 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 242 | inline void Move(Register dst, Register src) { |
| 243 | if (!dst.is(src)) { |
| 244 | mov(dst, src); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | inline void Move(FPURegister dst, FPURegister src) { |
| 249 | if (!dst.is(src)) { |
| 250 | mov_d(dst, src); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | inline void Move(Register dst_low, Register dst_high, FPURegister src) { |
| 255 | mfc1(dst_low, src); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 256 | Mfhc1(dst_high, src); |
| 257 | } |
| 258 | |
| 259 | inline void FmoveHigh(Register dst_high, FPURegister src) { |
| 260 | Mfhc1(dst_high, src); |
| 261 | } |
| 262 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 263 | inline void FmoveHigh(FPURegister dst, Register src_high) { |
| 264 | Mthc1(src_high, dst); |
| 265 | } |
| 266 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 267 | inline void FmoveLow(Register dst_low, FPURegister src) { |
| 268 | mfc1(dst_low, src); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | void FmoveLow(FPURegister dst, Register src_low); |
| 272 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 273 | inline void Move(FPURegister dst, Register src_low, Register src_high) { |
| 274 | mtc1(src_low, dst); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 275 | Mthc1(src_high, dst); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 276 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 277 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 278 | void Move(FPURegister dst, float imm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 279 | void Move(FPURegister dst, double imm); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 280 | |
| 281 | // Conditional move. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 282 | void Movz(Register rd, Register rs, Register rt); |
| 283 | void Movn(Register rd, Register rs, Register rt); |
| 284 | void Movt(Register rd, Register rs, uint16_t cc = 0); |
| 285 | void Movf(Register rd, Register rs, uint16_t cc = 0); |
| 286 | |
| 287 | void Clz(Register rd, Register rs); |
| 288 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 289 | // Jump unconditionally to given label. |
| 290 | // We NEED a nop in the branch delay slot, as it used by v8, for example in |
| 291 | // CodeGenerator::ProcessDeferred(). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 292 | // Currently the branch delay slot is filled by the MacroAssembler. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 293 | // Use rather b(Label) for code generation. |
| 294 | void jmp(Label* L) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 295 | Branch(L); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | void Load(Register dst, const MemOperand& src, Representation r); |
| 299 | void Store(Register src, const MemOperand& dst, Representation r); |
| 300 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 301 | void PushRoot(Heap::RootListIndex index) { |
| 302 | LoadRoot(at, index); |
| 303 | Push(at); |
| 304 | } |
| 305 | |
| 306 | // Compare the object in a register to a value and jump if they are equal. |
| 307 | void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) { |
| 308 | LoadRoot(at, index); |
| 309 | Branch(if_equal, eq, with, Operand(at)); |
| 310 | } |
| 311 | |
| 312 | // Compare the object in a register to a value and jump if they are not equal. |
| 313 | void JumpIfNotRoot(Register with, Heap::RootListIndex index, |
| 314 | Label* if_not_equal) { |
| 315 | LoadRoot(at, index); |
| 316 | Branch(if_not_equal, ne, with, Operand(at)); |
| 317 | } |
| 318 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 319 | // Load an object from the root table. |
| 320 | void LoadRoot(Register destination, |
| 321 | Heap::RootListIndex index); |
| 322 | void LoadRoot(Register destination, |
| 323 | Heap::RootListIndex index, |
| 324 | Condition cond, Register src1, const Operand& src2); |
| 325 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 326 | // Store an object to the root table. |
| 327 | void StoreRoot(Register source, |
| 328 | Heap::RootListIndex index); |
| 329 | void StoreRoot(Register source, |
| 330 | Heap::RootListIndex index, |
| 331 | Condition cond, Register src1, const Operand& src2); |
| 332 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 333 | // --------------------------------------------------------------------------- |
| 334 | // GC Support |
| 335 | |
| 336 | void IncrementalMarkingRecordWriteHelper(Register object, |
| 337 | Register value, |
| 338 | Register address); |
| 339 | |
| 340 | enum RememberedSetFinalAction { |
| 341 | kReturnAtEnd, |
| 342 | kFallThroughAtEnd |
| 343 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 344 | |
| 345 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 346 | // Record in the remembered set the fact that we have a pointer to new space |
| 347 | // at the address pointed to by the addr register. Only works if addr is not |
| 348 | // in new space. |
| 349 | void RememberedSetHelper(Register object, // Used for debug code. |
| 350 | Register addr, |
| 351 | Register scratch, |
| 352 | SaveFPRegsMode save_fp, |
| 353 | RememberedSetFinalAction and_then); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 354 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 355 | void CheckPageFlag(Register object, |
| 356 | Register scratch, |
| 357 | int mask, |
| 358 | Condition cc, |
| 359 | Label* condition_met); |
| 360 | |
| 361 | // Check if object is in new space. Jumps if the object is not in new space. |
| 362 | // The register scratch can be object itself, but it will be clobbered. |
| 363 | void JumpIfNotInNewSpace(Register object, |
| 364 | Register scratch, |
| 365 | Label* branch) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 366 | InNewSpace(object, scratch, eq, branch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // Check if object is in new space. Jumps if the object is in new space. |
| 370 | // The register scratch can be object itself, but scratch will be clobbered. |
| 371 | void JumpIfInNewSpace(Register object, |
| 372 | Register scratch, |
| 373 | Label* branch) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 374 | InNewSpace(object, scratch, ne, branch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // Check if an object has a given incremental marking color. |
| 378 | void HasColor(Register object, |
| 379 | Register scratch0, |
| 380 | Register scratch1, |
| 381 | Label* has_color, |
| 382 | int first_bit, |
| 383 | int second_bit); |
| 384 | |
| 385 | void JumpIfBlack(Register object, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 386 | Register scratch0, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 387 | Register scratch1, |
| 388 | Label* on_black); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 389 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 390 | // Checks the color of an object. If the object is white we jump to the |
| 391 | // incremental marker. |
| 392 | void JumpIfWhite(Register value, Register scratch1, Register scratch2, |
| 393 | Register scratch3, Label* value_is_white); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 394 | |
| 395 | // Notify the garbage collector that we wrote a pointer into an object. |
| 396 | // |object| is the object being stored into, |value| is the object being |
| 397 | // stored. value and scratch registers are clobbered by the operation. |
| 398 | // The offset is the offset from the start of the object, not the offset from |
| 399 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 400 | void RecordWriteField( |
| 401 | Register object, |
| 402 | int offset, |
| 403 | Register value, |
| 404 | Register scratch, |
| 405 | RAStatus ra_status, |
| 406 | SaveFPRegsMode save_fp, |
| 407 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 409 | PointersToHereCheck pointers_to_here_check_for_value = |
| 410 | kPointersToHereMaybeInteresting); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 411 | |
| 412 | // As above, but the offset has the tag presubtracted. For use with |
| 413 | // MemOperand(reg, off). |
| 414 | inline void RecordWriteContextSlot( |
| 415 | Register context, |
| 416 | int offset, |
| 417 | Register value, |
| 418 | Register scratch, |
| 419 | RAStatus ra_status, |
| 420 | SaveFPRegsMode save_fp, |
| 421 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 422 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 423 | PointersToHereCheck pointers_to_here_check_for_value = |
| 424 | kPointersToHereMaybeInteresting) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 425 | RecordWriteField(context, |
| 426 | offset + kHeapObjectTag, |
| 427 | value, |
| 428 | scratch, |
| 429 | ra_status, |
| 430 | save_fp, |
| 431 | remembered_set_action, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 432 | smi_check, |
| 433 | pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 436 | // Notify the garbage collector that we wrote a code entry into a |
| 437 | // JSFunction. Only scratch is clobbered by the operation. |
| 438 | void RecordWriteCodeEntryField(Register js_function, Register code_entry, |
| 439 | Register scratch); |
| 440 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | void RecordWriteForMap( |
| 442 | Register object, |
| 443 | Register map, |
| 444 | Register dst, |
| 445 | RAStatus ra_status, |
| 446 | SaveFPRegsMode save_fp); |
| 447 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 448 | // For a given |object| notify the garbage collector that the slot |address| |
| 449 | // has been written. |value| is the object being stored. The value and |
| 450 | // address registers are clobbered by the operation. |
| 451 | void RecordWrite( |
| 452 | Register object, |
| 453 | Register address, |
| 454 | Register value, |
| 455 | RAStatus ra_status, |
| 456 | SaveFPRegsMode save_fp, |
| 457 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 458 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 459 | PointersToHereCheck pointers_to_here_check_for_value = |
| 460 | kPointersToHereMaybeInteresting); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 461 | |
| 462 | |
| 463 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 464 | // Inline caching support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 465 | |
| 466 | // Generate code for checking access rights - used for security checks |
| 467 | // on access to global objects across environments. The holder register |
| 468 | // is left untouched, whereas both scratch registers are clobbered. |
| 469 | void CheckAccessGlobalProxy(Register holder_reg, |
| 470 | Register scratch, |
| 471 | Label* miss); |
| 472 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 473 | void GetNumberHash(Register reg0, Register scratch); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 474 | |
| 475 | void LoadFromNumberDictionary(Label* miss, |
| 476 | Register elements, |
| 477 | Register key, |
| 478 | Register result, |
| 479 | Register reg0, |
| 480 | Register reg1, |
| 481 | Register reg2); |
| 482 | |
| 483 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 484 | inline void MarkCode(NopMarkerTypes type) { |
| 485 | nop(type); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 488 | // Check if the given instruction is a 'type' marker. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 489 | // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 490 | // nop(type)). These instructions are generated to mark special location in |
| 491 | // the code, like some special IC code. |
| 492 | static inline bool IsMarkedCode(Instr instr, int type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 493 | DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 494 | return IsNop(instr, type); |
| 495 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 496 | |
| 497 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 498 | static inline int GetCodeMarker(Instr instr) { |
| 499 | uint32_t opcode = ((instr & kOpcodeMask)); |
| 500 | uint32_t rt = ((instr & kRtFieldMask) >> kRtShift); |
| 501 | uint32_t rs = ((instr & kRsFieldMask) >> kRsShift); |
| 502 | uint32_t sa = ((instr & kSaFieldMask) >> kSaShift); |
| 503 | |
| 504 | // Return <n> if we have a sll zero_reg, zero_reg, n |
| 505 | // else return -1. |
| 506 | bool sllzz = (opcode == SLL && |
| 507 | rt == static_cast<uint32_t>(ToNumber(zero_reg)) && |
| 508 | rs == static_cast<uint32_t>(ToNumber(zero_reg))); |
| 509 | int type = |
| 510 | (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 511 | DCHECK((type == -1) || |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 512 | ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER))); |
| 513 | return type; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | |
| 518 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 519 | // Allocation support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 520 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | // Allocate an object in new space or old space. The object_size is |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 522 | // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS |
| 523 | // is passed. If the space is exhausted control continues at the gc_required |
| 524 | // label. The allocated object is returned in result. If the flag |
| 525 | // tag_allocated_object is true the result is tagged as as a heap object. |
| 526 | // All registers are clobbered also when control continues at the gc_required |
| 527 | // label. |
| 528 | void Allocate(int object_size, |
| 529 | Register result, |
| 530 | Register scratch1, |
| 531 | Register scratch2, |
| 532 | Label* gc_required, |
| 533 | AllocationFlags flags); |
| 534 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 535 | void Allocate(Register object_size, Register result, Register result_new, |
| 536 | Register scratch, Label* gc_required, AllocationFlags flags); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 537 | |
| 538 | void AllocateTwoByteString(Register result, |
| 539 | Register length, |
| 540 | Register scratch1, |
| 541 | Register scratch2, |
| 542 | Register scratch3, |
| 543 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | void AllocateOneByteString(Register result, Register length, |
| 545 | Register scratch1, Register scratch2, |
| 546 | Register scratch3, Label* gc_required); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 547 | void AllocateTwoByteConsString(Register result, |
| 548 | Register length, |
| 549 | Register scratch1, |
| 550 | Register scratch2, |
| 551 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 552 | void AllocateOneByteConsString(Register result, Register length, |
| 553 | Register scratch1, Register scratch2, |
| 554 | Label* gc_required); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 555 | void AllocateTwoByteSlicedString(Register result, |
| 556 | Register length, |
| 557 | Register scratch1, |
| 558 | Register scratch2, |
| 559 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 560 | void AllocateOneByteSlicedString(Register result, Register length, |
| 561 | Register scratch1, Register scratch2, |
| 562 | Label* gc_required); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 563 | |
| 564 | // Allocates a heap number or jumps to the gc_required label if the young |
| 565 | // space is full and a scavenge is needed. All registers are clobbered also |
| 566 | // when control continues at the gc_required label. |
| 567 | void AllocateHeapNumber(Register result, |
| 568 | Register scratch1, |
| 569 | Register scratch2, |
| 570 | Register heap_number_map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 571 | Label* gc_required, |
| 572 | TaggingMode tagging_mode = TAG_RESULT, |
| 573 | MutableMode mode = IMMUTABLE); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 574 | void AllocateHeapNumberWithValue(Register result, |
| 575 | FPURegister value, |
| 576 | Register scratch1, |
| 577 | Register scratch2, |
| 578 | Label* gc_required); |
| 579 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 580 | // Allocate and initialize a JSValue wrapper with the specified {constructor} |
| 581 | // and {value}. |
| 582 | void AllocateJSValue(Register result, Register constructor, Register value, |
| 583 | Register scratch1, Register scratch2, |
| 584 | Label* gc_required); |
| 585 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 586 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 587 | // Instruction macros. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 588 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 589 | #define DEFINE_INSTRUCTION(instr) \ |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 590 | void instr(Register rd, Register rs, const Operand& rt); \ |
| 591 | void instr(Register rd, Register rs, Register rt) { \ |
| 592 | instr(rd, rs, Operand(rt)); \ |
| 593 | } \ |
| 594 | void instr(Register rs, Register rt, int32_t j) { \ |
| 595 | instr(rs, rt, Operand(j)); \ |
| 596 | } |
| 597 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 598 | #define DEFINE_INSTRUCTION2(instr) \ |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 599 | void instr(Register rs, const Operand& rt); \ |
| 600 | void instr(Register rs, Register rt) { \ |
| 601 | instr(rs, Operand(rt)); \ |
| 602 | } \ |
| 603 | void instr(Register rs, int32_t j) { \ |
| 604 | instr(rs, Operand(j)); \ |
| 605 | } |
| 606 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 607 | #define DEFINE_INSTRUCTION3(instr) \ |
| 608 | void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \ |
| 609 | void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \ |
| 610 | instr(rd_hi, rd_lo, rs, Operand(rt)); \ |
| 611 | } \ |
| 612 | void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \ |
| 613 | instr(rd_hi, rd_lo, rs, Operand(j)); \ |
| 614 | } |
| 615 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 616 | DEFINE_INSTRUCTION(Addu); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 617 | DEFINE_INSTRUCTION(Subu); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 618 | DEFINE_INSTRUCTION(Mul); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 619 | DEFINE_INSTRUCTION(Div); |
| 620 | DEFINE_INSTRUCTION(Divu); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | DEFINE_INSTRUCTION(Mod); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 622 | DEFINE_INSTRUCTION(Modu); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 623 | DEFINE_INSTRUCTION(Mulh); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 624 | DEFINE_INSTRUCTION2(Mult); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 625 | DEFINE_INSTRUCTION(Mulhu); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 626 | DEFINE_INSTRUCTION2(Multu); |
| 627 | DEFINE_INSTRUCTION2(Div); |
| 628 | DEFINE_INSTRUCTION2(Divu); |
| 629 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 630 | DEFINE_INSTRUCTION3(Div); |
| 631 | DEFINE_INSTRUCTION3(Mul); |
| 632 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 633 | DEFINE_INSTRUCTION(And); |
| 634 | DEFINE_INSTRUCTION(Or); |
| 635 | DEFINE_INSTRUCTION(Xor); |
| 636 | DEFINE_INSTRUCTION(Nor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 637 | DEFINE_INSTRUCTION2(Neg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 638 | |
| 639 | DEFINE_INSTRUCTION(Slt); |
| 640 | DEFINE_INSTRUCTION(Sltu); |
| 641 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 642 | // MIPS32 R2 instruction macro. |
| 643 | DEFINE_INSTRUCTION(Ror); |
| 644 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 645 | #undef DEFINE_INSTRUCTION |
| 646 | #undef DEFINE_INSTRUCTION2 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 647 | #undef DEFINE_INSTRUCTION3 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 648 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 649 | void Lsa(Register rd, Register rs, Register rt, uint8_t sa, |
| 650 | Register scratch = at); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | void Pref(int32_t hint, const MemOperand& rs); |
| 652 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 653 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 654 | // --------------------------------------------------------------------------- |
| 655 | // Pseudo-instructions. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 656 | |
| 657 | void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 658 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | void Ulw(Register rd, const MemOperand& rs); |
| 660 | void Usw(Register rd, const MemOperand& rs); |
| 661 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 662 | // Load int32 in the rd register. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 663 | void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE); |
| 664 | inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) { |
| 665 | li(rd, Operand(j), mode); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 666 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 668 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 669 | // Push multiple registers on the stack. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 670 | // Registers are saved in numerical order, with higher numbered registers |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 671 | // saved in higher memory addresses. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 672 | void MultiPush(RegList regs); |
| 673 | void MultiPushReversed(RegList regs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 674 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 675 | void MultiPushFPU(RegList regs); |
| 676 | void MultiPushReversedFPU(RegList regs); |
| 677 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 678 | void push(Register src) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 679 | Addu(sp, sp, Operand(-kPointerSize)); |
| 680 | sw(src, MemOperand(sp, 0)); |
| 681 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 682 | void Push(Register src) { push(src); } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 683 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 684 | // Push a handle. |
| 685 | void Push(Handle<Object> handle); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 686 | void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 687 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 688 | // Push two registers. Pushes leftmost register first (to highest address). |
| 689 | void Push(Register src1, Register src2) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 690 | Subu(sp, sp, Operand(2 * kPointerSize)); |
| 691 | sw(src1, MemOperand(sp, 1 * kPointerSize)); |
| 692 | sw(src2, MemOperand(sp, 0 * kPointerSize)); |
| 693 | } |
| 694 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 695 | // Push three registers. Pushes leftmost register first (to highest address). |
| 696 | void Push(Register src1, Register src2, Register src3) { |
| 697 | Subu(sp, sp, Operand(3 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 698 | sw(src1, MemOperand(sp, 2 * kPointerSize)); |
| 699 | sw(src2, MemOperand(sp, 1 * kPointerSize)); |
| 700 | sw(src3, MemOperand(sp, 0 * kPointerSize)); |
| 701 | } |
| 702 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 703 | // Push four registers. Pushes leftmost register first (to highest address). |
| 704 | void Push(Register src1, Register src2, Register src3, Register src4) { |
| 705 | Subu(sp, sp, Operand(4 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 706 | sw(src1, MemOperand(sp, 3 * kPointerSize)); |
| 707 | sw(src2, MemOperand(sp, 2 * kPointerSize)); |
| 708 | sw(src3, MemOperand(sp, 1 * kPointerSize)); |
| 709 | sw(src4, MemOperand(sp, 0 * kPointerSize)); |
| 710 | } |
| 711 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 712 | // Push five registers. Pushes leftmost register first (to highest address). |
| 713 | void Push(Register src1, Register src2, Register src3, Register src4, |
| 714 | Register src5) { |
| 715 | Subu(sp, sp, Operand(5 * kPointerSize)); |
| 716 | sw(src1, MemOperand(sp, 4 * kPointerSize)); |
| 717 | sw(src2, MemOperand(sp, 3 * kPointerSize)); |
| 718 | sw(src3, MemOperand(sp, 2 * kPointerSize)); |
| 719 | sw(src4, MemOperand(sp, 1 * kPointerSize)); |
| 720 | sw(src5, MemOperand(sp, 0 * kPointerSize)); |
| 721 | } |
| 722 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 723 | void Push(Register src, Condition cond, Register tst1, Register tst2) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 724 | // Since we don't have conditional execution we use a Branch. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 725 | Branch(3, cond, tst1, Operand(tst2)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 726 | Subu(sp, sp, Operand(kPointerSize)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 727 | sw(src, MemOperand(sp, 0)); |
| 728 | } |
| 729 | |
| 730 | // Pops multiple values from the stack and load them in the |
| 731 | // registers specified in regs. Pop order is the opposite as in MultiPush. |
| 732 | void MultiPop(RegList regs); |
| 733 | void MultiPopReversed(RegList regs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 734 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 735 | void MultiPopFPU(RegList regs); |
| 736 | void MultiPopReversedFPU(RegList regs); |
| 737 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 738 | void pop(Register dst) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 739 | lw(dst, MemOperand(sp, 0)); |
| 740 | Addu(sp, sp, Operand(kPointerSize)); |
| 741 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 742 | void Pop(Register dst) { pop(dst); } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 743 | |
| 744 | // Pop two registers. Pops rightmost register first (from lower address). |
| 745 | void Pop(Register src1, Register src2) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 746 | DCHECK(!src1.is(src2)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 747 | lw(src2, MemOperand(sp, 0 * kPointerSize)); |
| 748 | lw(src1, MemOperand(sp, 1 * kPointerSize)); |
| 749 | Addu(sp, sp, 2 * kPointerSize); |
| 750 | } |
| 751 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 752 | // Pop three registers. Pops rightmost register first (from lower address). |
| 753 | void Pop(Register src1, Register src2, Register src3) { |
| 754 | lw(src3, MemOperand(sp, 0 * kPointerSize)); |
| 755 | lw(src2, MemOperand(sp, 1 * kPointerSize)); |
| 756 | lw(src1, MemOperand(sp, 2 * kPointerSize)); |
| 757 | Addu(sp, sp, 3 * kPointerSize); |
| 758 | } |
| 759 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 760 | void Pop(uint32_t count = 1) { |
| 761 | Addu(sp, sp, Operand(count * kPointerSize)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 764 | // Push and pop the registers that can hold pointers, as defined by the |
| 765 | // RegList constant kSafepointSavedRegisters. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 766 | void PushSafepointRegisters(); |
| 767 | void PopSafepointRegisters(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 768 | // Store value in register src in the safepoint stack slot for |
| 769 | // register dst. |
| 770 | void StoreToSafepointRegisterSlot(Register src, Register dst); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 771 | // Load the value of the src register from its safepoint stack slot |
| 772 | // into register dst. |
| 773 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 774 | |
| 775 | // MIPS32 R2 instruction macro. |
| 776 | void Ins(Register rt, Register rs, uint16_t pos, uint16_t size); |
| 777 | void Ext(Register rt, Register rs, uint16_t pos, uint16_t size); |
| 778 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 779 | // --------------------------------------------------------------------------- |
| 780 | // FPU macros. These do not handle special cases like NaN or +- inf. |
| 781 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 782 | // Convert unsigned word to double. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 783 | void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 784 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 785 | // Convert single to unsigned word. |
| 786 | void Trunc_uw_s(FPURegister fd, FPURegister fs, FPURegister scratch); |
| 787 | void Trunc_uw_s(FPURegister fd, Register rs, FPURegister scratch); |
| 788 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 789 | // Convert double to unsigned word. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 790 | void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch); |
| 791 | void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 792 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 793 | void Trunc_w_d(FPURegister fd, FPURegister fs); |
| 794 | void Round_w_d(FPURegister fd, FPURegister fs); |
| 795 | void Floor_w_d(FPURegister fd, FPURegister fs); |
| 796 | void Ceil_w_d(FPURegister fd, FPURegister fs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 797 | |
| 798 | // FP32 mode: Move the general purpose register into |
| 799 | // the high part of the double-register pair. |
| 800 | // FP64 mode: Move the general-purpose register into |
| 801 | // the higher 32 bits of the 64-bit coprocessor register, |
| 802 | // while leaving the low bits unchanged. |
| 803 | void Mthc1(Register rt, FPURegister fs); |
| 804 | |
| 805 | // FP32 mode: move the high part of the double-register pair into |
| 806 | // general purpose register. |
| 807 | // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into |
| 808 | // general-purpose register. |
| 809 | void Mfhc1(Register rt, FPURegister fs); |
| 810 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 811 | // Wrapper functions for the different cmp/branch types. |
| 812 | inline void BranchF32(Label* target, Label* nan, Condition cc, |
| 813 | FPURegister cmp1, FPURegister cmp2, |
| 814 | BranchDelaySlot bd = PROTECT) { |
| 815 | BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd); |
| 816 | } |
| 817 | |
| 818 | inline void BranchF64(Label* target, Label* nan, Condition cc, |
| 819 | FPURegister cmp1, FPURegister cmp2, |
| 820 | BranchDelaySlot bd = PROTECT) { |
| 821 | BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd); |
| 822 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 823 | |
| 824 | // Alternate (inline) version for better readability with USE_DELAY_SLOT. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 825 | inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan, |
| 826 | Condition cc, FPURegister cmp1, FPURegister cmp2) { |
| 827 | BranchF64(target, nan, cc, cmp1, cmp2, bd); |
| 828 | } |
| 829 | |
| 830 | inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan, |
| 831 | Condition cc, FPURegister cmp1, FPURegister cmp2) { |
| 832 | BranchF32(target, nan, cc, cmp1, cmp2, bd); |
| 833 | } |
| 834 | |
| 835 | // Alias functions for backward compatibility. |
| 836 | inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1, |
| 837 | FPURegister cmp2, BranchDelaySlot bd = PROTECT) { |
| 838 | BranchF64(target, nan, cc, cmp1, cmp2, bd); |
| 839 | } |
| 840 | |
| 841 | inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan, |
| 842 | Condition cc, FPURegister cmp1, FPURegister cmp2) { |
| 843 | BranchF64(bd, target, nan, cc, cmp1, cmp2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 844 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 845 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 846 | // Truncates a double using a specific rounding mode, and writes the value |
| 847 | // to the result register. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 848 | // The except_flag will contain any exceptions caused by the instruction. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 849 | // If check_inexact is kDontCheckForInexactConversion, then the inexact |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 850 | // exception is masked. |
| 851 | void EmitFPUTruncate(FPURoundingMode rounding_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | Register result, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 853 | DoubleRegister double_input, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 854 | Register scratch, |
| 855 | DoubleRegister double_scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 856 | Register except_flag, |
| 857 | CheckForInexactConversion check_inexact |
| 858 | = kDontCheckForInexactConversion); |
| 859 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 860 | // Performs a truncating conversion of a floating point number as used by |
| 861 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it |
| 862 | // succeeds, otherwise falls through if result is saturated. On return |
| 863 | // 'result' either holds answer, or is clobbered on fall through. |
| 864 | // |
| 865 | // Only public for the test code in test-code-stubs-arm.cc. |
| 866 | void TryInlineTruncateDoubleToI(Register result, |
| 867 | DoubleRegister input, |
| 868 | Label* done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 869 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 870 | // Performs a truncating conversion of a floating point number as used by |
| 871 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 872 | // Exits with 'result' holding the answer. |
| 873 | void TruncateDoubleToI(Register result, DoubleRegister double_input); |
| 874 | |
| 875 | // Performs a truncating conversion of a heap number as used by |
| 876 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input' |
| 877 | // must be different registers. Exits with 'result' holding the answer. |
| 878 | void TruncateHeapNumberToI(Register result, Register object); |
| 879 | |
| 880 | // Converts the smi or heap number in object to an int32 using the rules |
| 881 | // for ToInt32 as described in ECMAScript 9.5.: the value is truncated |
| 882 | // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be |
| 883 | // different registers. |
| 884 | void TruncateNumberToI(Register object, |
| 885 | Register result, |
| 886 | Register heap_number_map, |
| 887 | Register scratch, |
| 888 | Label* not_int32); |
| 889 | |
| 890 | // Loads the number from object into dst register. |
| 891 | // If |object| is neither smi nor heap number, |not_number| is jumped to |
| 892 | // with |object| still intact. |
| 893 | void LoadNumber(Register object, |
| 894 | FPURegister dst, |
| 895 | Register heap_number_map, |
| 896 | Register scratch, |
| 897 | Label* not_number); |
| 898 | |
| 899 | // Loads the number from object into double_dst in the double format. |
| 900 | // Control will jump to not_int32 if the value cannot be exactly represented |
| 901 | // by a 32-bit integer. |
| 902 | // Floating point value in the 32-bit integer range that are not exact integer |
| 903 | // won't be loaded. |
| 904 | void LoadNumberAsInt32Double(Register object, |
| 905 | DoubleRegister double_dst, |
| 906 | Register heap_number_map, |
| 907 | Register scratch1, |
| 908 | Register scratch2, |
| 909 | FPURegister double_scratch, |
| 910 | Label* not_int32); |
| 911 | |
| 912 | // Loads the number from object into dst as a 32-bit integer. |
| 913 | // Control will jump to not_int32 if the object cannot be exactly represented |
| 914 | // by a 32-bit integer. |
| 915 | // Floating point value in the 32-bit integer range that are not exact integer |
| 916 | // won't be converted. |
| 917 | void LoadNumberAsInt32(Register object, |
| 918 | Register dst, |
| 919 | Register heap_number_map, |
| 920 | Register scratch1, |
| 921 | Register scratch2, |
| 922 | FPURegister double_scratch0, |
| 923 | FPURegister double_scratch1, |
| 924 | Label* not_int32); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 925 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 926 | // Enter exit frame. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 927 | // argc - argument count to be dropped by LeaveExitFrame. |
| 928 | // save_doubles - saves FPU registers on stack, currently disabled. |
| 929 | // stack_space - extra stack space. |
| 930 | void EnterExitFrame(bool save_doubles, |
| 931 | int stack_space = 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 932 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 933 | // Leave the current exit frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 934 | void LeaveExitFrame(bool save_doubles, Register arg_count, |
| 935 | bool restore_context, bool do_return = NO_EMIT_RETURN, |
| 936 | bool argument_count_is_length = false); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 937 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 938 | // Get the actual activation frame alignment for target environment. |
| 939 | static int ActivationFrameAlignment(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 940 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 941 | // Make sure the stack is aligned. Only emits code in debug mode. |
| 942 | void AssertStackIsAligned(); |
| 943 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 944 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 945 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 946 | // Load the global object from the current context. |
| 947 | void LoadGlobalObject(Register dst) { |
| 948 | LoadNativeContextSlot(Context::EXTENSION_INDEX, dst); |
| 949 | } |
| 950 | |
| 951 | // Load the global proxy from the current context. |
| 952 | void LoadGlobalProxy(Register dst) { |
| 953 | LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst); |
| 954 | } |
| 955 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 956 | // Conditionally load the cached Array transitioned map of type |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 957 | // transitioned_kind from the native context if the map in register |
| 958 | // map_in_out is the cached Array map in the native context of |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 959 | // expected_kind. |
| 960 | void LoadTransitionedArrayMapConditional( |
| 961 | ElementsKind expected_kind, |
| 962 | ElementsKind transitioned_kind, |
| 963 | Register map_in_out, |
| 964 | Register scratch, |
| 965 | Label* no_map_match); |
| 966 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 967 | void LoadNativeContextSlot(int index, Register dst); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 968 | |
| 969 | // Load the initial map from the global function. The registers |
| 970 | // function and map can be the same, function is then overwritten. |
| 971 | void LoadGlobalFunctionInitialMap(Register function, |
| 972 | Register map, |
| 973 | Register scratch); |
| 974 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 975 | void InitializeRootRegister() { |
| 976 | ExternalReference roots_array_start = |
| 977 | ExternalReference::roots_array_start(isolate()); |
| 978 | li(kRootRegister, Operand(roots_array_start)); |
| 979 | } |
| 980 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 981 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 982 | // JavaScript invokes. |
| 983 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 984 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 985 | |
| 986 | void InvokeFunctionCode(Register function, Register new_target, |
| 987 | const ParameterCount& expected, |
| 988 | const ParameterCount& actual, InvokeFlag flag, |
| 989 | const CallWrapper& call_wrapper); |
| 990 | |
| 991 | void FloodFunctionIfStepping(Register fun, Register new_target, |
| 992 | const ParameterCount& expected, |
| 993 | const ParameterCount& actual); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 994 | |
| 995 | // Invoke the JavaScript function in the given register. Changes the |
| 996 | // current context to the context in the function before invoking. |
| 997 | void InvokeFunction(Register function, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 998 | Register new_target, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 999 | const ParameterCount& actual, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1000 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | const CallWrapper& call_wrapper); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1002 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | void InvokeFunction(Register function, |
| 1004 | const ParameterCount& expected, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1005 | const ParameterCount& actual, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1006 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1007 | const CallWrapper& call_wrapper); |
| 1008 | |
| 1009 | void InvokeFunction(Handle<JSFunction> function, |
| 1010 | const ParameterCount& expected, |
| 1011 | const ParameterCount& actual, |
| 1012 | InvokeFlag flag, |
| 1013 | const CallWrapper& call_wrapper); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1014 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1015 | void IsObjectJSStringType(Register object, |
| 1016 | Register scratch, |
| 1017 | Label* fail); |
| 1018 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1019 | void IsObjectNameType(Register object, |
| 1020 | Register scratch, |
| 1021 | Label* fail); |
| 1022 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1023 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1024 | // Debugger Support. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1025 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1026 | void DebugBreak(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1027 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1028 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1029 | // Exception handling. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1030 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | // Push a new stack handler and link into stack handler chain. |
| 1032 | void PushStackHandler(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1033 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1034 | // Unlink the stack handler on top of the stack from the stack handler chain. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1035 | // Must preserve the result register. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1036 | void PopStackHandler(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1037 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1038 | // Copies a number of bytes from src to dst. All registers are clobbered. On |
| 1039 | // exit src and dst will point to the place just after where the last byte was |
| 1040 | // read or written and length will be zero. |
| 1041 | void CopyBytes(Register src, |
| 1042 | Register dst, |
| 1043 | Register length, |
| 1044 | Register scratch); |
| 1045 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1046 | // Initialize fields with filler values. Fields starting at |current_address| |
| 1047 | // not including |end_address| are overwritten with the value in |filler|. At |
| 1048 | // the end the loop, |current_address| takes the value of |end_address|. |
| 1049 | void InitializeFieldsWithFiller(Register current_address, |
| 1050 | Register end_address, Register filler); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1051 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1052 | // ------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1053 | // Support functions. |
| 1054 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1055 | // Machine code version of Map::GetConstructor(). |
| 1056 | // |temp| holds |result|'s map when done, and |temp2| its instance type. |
| 1057 | void GetMapConstructor(Register result, Register map, Register temp, |
| 1058 | Register temp2); |
| 1059 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1060 | // Try to get function prototype of a function and puts the value in |
| 1061 | // the result register. Checks that the function really is a |
| 1062 | // function and jumps to the miss label if the fast checks fail. The |
| 1063 | // function register will be untouched; the other registers may be |
| 1064 | // clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1065 | void TryGetFunctionPrototype(Register function, Register result, |
| 1066 | Register scratch, Label* miss); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1067 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1068 | void GetObjectType(Register function, |
| 1069 | Register map, |
| 1070 | Register type_reg); |
| 1071 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1072 | void GetInstanceType(Register object_map, Register object_instance_type) { |
| 1073 | lbu(object_instance_type, |
| 1074 | FieldMemOperand(object_map, Map::kInstanceTypeOffset)); |
| 1075 | } |
| 1076 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1077 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 1078 | // Jump to the specified label if it does not. |
| 1079 | void CheckFastElements(Register map, |
| 1080 | Register scratch, |
| 1081 | Label* fail); |
| 1082 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1083 | // Check if a map for a JSObject indicates that the object can have both smi |
| 1084 | // and HeapObject elements. Jump to the specified label if it does not. |
| 1085 | void CheckFastObjectElements(Register map, |
| 1086 | Register scratch, |
| 1087 | Label* fail); |
| 1088 | |
| 1089 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 1090 | // elements. Jump to the specified label if it does not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1091 | void CheckFastSmiElements(Register map, |
| 1092 | Register scratch, |
| 1093 | Label* fail); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1094 | |
| 1095 | // Check to see if maybe_number can be stored as a double in |
| 1096 | // FastDoubleElements. If it can, store it at the index specified by key in |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1097 | // the FastDoubleElements array elements. Otherwise jump to fail. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1098 | void StoreNumberToDoubleElements(Register value_reg, |
| 1099 | Register key_reg, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1100 | Register elements_reg, |
| 1101 | Register scratch1, |
| 1102 | Register scratch2, |
| 1103 | Register scratch3, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1104 | Label* fail, |
| 1105 | int elements_offset = 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1106 | |
| 1107 | // Compare an object's map with the specified map and its transitioned |
| 1108 | // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to |
| 1109 | // "branch_to" if the result of the comparison is "cond". If multiple map |
| 1110 | // compares are required, the compare sequences branches to early_success. |
| 1111 | void CompareMapAndBranch(Register obj, |
| 1112 | Register scratch, |
| 1113 | Handle<Map> map, |
| 1114 | Label* early_success, |
| 1115 | Condition cond, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1116 | Label* branch_to); |
| 1117 | |
| 1118 | // As above, but the map of the object is already loaded into the register |
| 1119 | // which is preserved by the code generated. |
| 1120 | void CompareMapAndBranch(Register obj_map, |
| 1121 | Handle<Map> map, |
| 1122 | Label* early_success, |
| 1123 | Condition cond, |
| 1124 | Label* branch_to); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1125 | |
| 1126 | // Check if the map of an object is equal to a specified map and branch to |
| 1127 | // label if not. Skip the smi check if not required (object is known to be a |
| 1128 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
| 1129 | // against maps that are ElementsKind transition maps of the specificed map. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1130 | void CheckMap(Register obj, |
| 1131 | Register scratch, |
| 1132 | Handle<Map> map, |
| 1133 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1134 | SmiCheckType smi_check_type); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1135 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1136 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1137 | void CheckMap(Register obj, |
| 1138 | Register scratch, |
| 1139 | Heap::RootListIndex index, |
| 1140 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1141 | SmiCheckType smi_check_type); |
| 1142 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1143 | // Check if the map of an object is equal to a specified weak map and branch |
| 1144 | // to a specified target if equal. Skip the smi check if not required |
| 1145 | // (object is known to be a heap object) |
| 1146 | void DispatchWeakMap(Register obj, Register scratch1, Register scratch2, |
| 1147 | Handle<WeakCell> cell, Handle<Code> success, |
| 1148 | SmiCheckType smi_check_type); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1149 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1150 | // Get value of the weak cell. |
| 1151 | void GetWeakValue(Register value, Handle<WeakCell> cell); |
| 1152 | |
| 1153 | // Load the value of the weak cell in the value register. Branch to the |
| 1154 | // given miss label is the weak cell was cleared. |
| 1155 | void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1156 | |
| 1157 | // Load and check the instance type of an object for being a string. |
| 1158 | // Loads the type into the second argument register. |
| 1159 | // Returns a condition that will be enabled if the object was a string. |
| 1160 | Condition IsObjectStringType(Register obj, |
| 1161 | Register type, |
| 1162 | Register result) { |
| 1163 | lw(type, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1164 | lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset)); |
| 1165 | And(type, type, Operand(kIsNotStringMask)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1166 | DCHECK_EQ(0u, kStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1167 | return eq; |
| 1168 | } |
| 1169 | |
| 1170 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1171 | // Picks out an array index from the hash field. |
| 1172 | // Register use: |
| 1173 | // hash - holds the index's hash. Clobbered. |
| 1174 | // index - holds the overwritten index on exit. |
| 1175 | void IndexFromHash(Register hash, Register index); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1176 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1177 | // Get the number of least significant bits from a register. |
| 1178 | void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits); |
| 1179 | void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits); |
| 1180 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1181 | // Load the value of a number object into a FPU double register. If the |
| 1182 | // object is not a number a jump to the label not_number is performed |
| 1183 | // and the FPU double register is unchanged. |
| 1184 | void ObjectToDoubleFPURegister( |
| 1185 | Register object, |
| 1186 | FPURegister value, |
| 1187 | Register scratch1, |
| 1188 | Register scratch2, |
| 1189 | Register heap_number_map, |
| 1190 | Label* not_number, |
| 1191 | ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS); |
| 1192 | |
| 1193 | // Load the value of a smi object into a FPU double register. The register |
| 1194 | // scratch1 can be the same register as smi in which case smi will hold the |
| 1195 | // untagged value afterwards. |
| 1196 | void SmiToDoubleFPURegister(Register smi, |
| 1197 | FPURegister value, |
| 1198 | Register scratch1); |
| 1199 | |
| 1200 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1201 | // Overflow handling functions. |
| 1202 | // Usage: first call the appropriate arithmetic function, then call one of the |
| 1203 | // jump functions with the overflow_dst register as the second parameter. |
| 1204 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1205 | inline void AddBranchOvf(Register dst, Register left, const Operand& right, |
| 1206 | Label* overflow_label, Register scratch = at) { |
| 1207 | AddBranchOvf(dst, left, right, overflow_label, nullptr, scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1210 | inline void AddBranchNoOvf(Register dst, Register left, const Operand& right, |
| 1211 | Label* no_overflow_label, Register scratch = at) { |
| 1212 | AddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1215 | void AddBranchOvf(Register dst, Register left, const Operand& right, |
| 1216 | Label* overflow_label, Label* no_overflow_label, |
| 1217 | Register scratch = at); |
| 1218 | |
| 1219 | void AddBranchOvf(Register dst, Register left, Register right, |
| 1220 | Label* overflow_label, Label* no_overflow_label, |
| 1221 | Register scratch = at); |
| 1222 | |
| 1223 | |
| 1224 | inline void SubBranchOvf(Register dst, Register left, const Operand& right, |
| 1225 | Label* overflow_label, Register scratch = at) { |
| 1226 | SubBranchOvf(dst, left, right, overflow_label, nullptr, scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1229 | inline void SubBranchNoOvf(Register dst, Register left, const Operand& right, |
| 1230 | Label* no_overflow_label, Register scratch = at) { |
| 1231 | SubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1234 | void SubBranchOvf(Register dst, Register left, const Operand& right, |
| 1235 | Label* overflow_label, Label* no_overflow_label, |
| 1236 | Register scratch = at); |
| 1237 | |
| 1238 | void SubBranchOvf(Register dst, Register left, Register right, |
| 1239 | Label* overflow_label, Label* no_overflow_label, |
| 1240 | Register scratch = at); |
| 1241 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1242 | // ------------------------------------------------------------------------- |
| 1243 | // Runtime calls. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1244 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1245 | // See comments at the beginning of CEntryStub::Generate. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1246 | inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); } |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1247 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1248 | inline void PrepareCEntryFunction(const ExternalReference& ref) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1249 | li(a1, Operand(ref)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1250 | } |
| 1251 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1252 | #define COND_ARGS Condition cond = al, Register rs = zero_reg, \ |
| 1253 | const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT |
| 1254 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1255 | // Call a code stub. |
| 1256 | void CallStub(CodeStub* stub, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1257 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 1258 | COND_ARGS); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1259 | |
| 1260 | // Tail call a code stub (jump). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1261 | void TailCallStub(CodeStub* stub, COND_ARGS); |
| 1262 | |
| 1263 | #undef COND_ARGS |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1264 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1265 | void CallJSExitStub(CodeStub* stub); |
| 1266 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1267 | // Call a runtime routine. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1268 | void CallRuntime(const Runtime::Function* f, int num_arguments, |
| 1269 | SaveFPRegsMode save_doubles = kDontSaveFPRegs, |
| 1270 | BranchDelaySlot bd = PROTECT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1271 | void CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
| 1272 | const Runtime::Function* function = Runtime::FunctionForId(id); |
| 1273 | CallRuntime(function, function->nargs, kSaveFPRegs); |
| 1274 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1275 | |
| 1276 | // Convenience function: Same as above, but takes the fid instead. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1277 | void CallRuntime(Runtime::FunctionId fid, |
| 1278 | SaveFPRegsMode save_doubles = kDontSaveFPRegs, |
| 1279 | BranchDelaySlot bd = PROTECT) { |
| 1280 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
| 1281 | CallRuntime(function, function->nargs, save_doubles, bd); |
| 1282 | } |
| 1283 | |
| 1284 | // Convenience function: Same as above, but takes the fid instead. |
| 1285 | void CallRuntime(Runtime::FunctionId id, int num_arguments, |
| 1286 | SaveFPRegsMode save_doubles = kDontSaveFPRegs, |
| 1287 | BranchDelaySlot bd = PROTECT) { |
| 1288 | CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1289 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1290 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1291 | // Convenience function: call an external reference. |
| 1292 | void CallExternalReference(const ExternalReference& ext, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1293 | int num_arguments, |
| 1294 | BranchDelaySlot bd = PROTECT); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1295 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1296 | |
| 1297 | // Convenience function: tail call a runtime routine (jump). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1298 | void TailCallRuntime(Runtime::FunctionId fid); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1299 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1300 | int CalculateStackPassedWords(int num_reg_arguments, |
| 1301 | int num_double_arguments); |
| 1302 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1303 | // Before calling a C-function from generated code, align arguments on stack |
| 1304 | // and add space for the four mips argument slots. |
| 1305 | // After aligning the frame, non-register arguments must be stored on the |
| 1306 | // stack, after the argument-slots using helper: CFunctionArgumentOperand(). |
| 1307 | // The argument count assumes all arguments are word sized. |
| 1308 | // Some compilers/platforms require the stack to be aligned when calling |
| 1309 | // C++ code. |
| 1310 | // Needs a scratch register to do some arithmetic. This register will be |
| 1311 | // trashed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1312 | void PrepareCallCFunction(int num_reg_arguments, |
| 1313 | int num_double_registers, |
| 1314 | Register scratch); |
| 1315 | void PrepareCallCFunction(int num_reg_arguments, |
| 1316 | Register scratch); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1317 | |
| 1318 | // Arguments 1-4 are placed in registers a0 thru a3 respectively. |
| 1319 | // Arguments 5..n are stored to stack using following: |
| 1320 | // sw(t0, CFunctionArgumentOperand(5)); |
| 1321 | |
| 1322 | // Calls a C function and cleans up the space for arguments allocated |
| 1323 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 1324 | // garbage collection, since that might move the code and invalidate the |
| 1325 | // return address (unless this is somehow accounted for by the called |
| 1326 | // function). |
| 1327 | void CallCFunction(ExternalReference function, int num_arguments); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1328 | void CallCFunction(Register function, int num_arguments); |
| 1329 | void CallCFunction(ExternalReference function, |
| 1330 | int num_reg_arguments, |
| 1331 | int num_double_arguments); |
| 1332 | void CallCFunction(Register function, |
| 1333 | int num_reg_arguments, |
| 1334 | int num_double_arguments); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | void MovFromFloatResult(DoubleRegister dst); |
| 1336 | void MovFromFloatParameter(DoubleRegister dst); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1337 | |
| 1338 | // There are two ways of passing double arguments on MIPS, depending on |
| 1339 | // whether soft or hard floating point ABI is used. These functions |
| 1340 | // abstract parameter passing for the three different ways we call |
| 1341 | // C functions from generated code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1342 | void MovToFloatParameter(DoubleRegister src); |
| 1343 | void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2); |
| 1344 | void MovToFloatResult(DoubleRegister src); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1345 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1346 | // Jump to the builtin routine. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1347 | void JumpToExternalReference(const ExternalReference& builtin, |
| 1348 | BranchDelaySlot bd = PROTECT); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1349 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1350 | struct Unresolved { |
| 1351 | int pc; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1352 | uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1353 | const char* name; |
| 1354 | }; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1355 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1356 | Handle<Object> CodeObject() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1357 | DCHECK(!code_object_.is_null()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1358 | return code_object_; |
| 1359 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1361 | // Emit code for a truncating division by a constant. The dividend register is |
| 1362 | // unchanged and at gets clobbered. Dividend and result must be different. |
| 1363 | void TruncatingDiv(Register result, Register dividend, int32_t divisor); |
| 1364 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1365 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1366 | // StatsCounter support. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1367 | |
| 1368 | void SetCounter(StatsCounter* counter, int value, |
| 1369 | Register scratch1, Register scratch2); |
| 1370 | void IncrementCounter(StatsCounter* counter, int value, |
| 1371 | Register scratch1, Register scratch2); |
| 1372 | void DecrementCounter(StatsCounter* counter, int value, |
| 1373 | Register scratch1, Register scratch2); |
| 1374 | |
| 1375 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1376 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1377 | // Debugging. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1378 | |
| 1379 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 1380 | // Use --debug_code to enable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1381 | void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1382 | void AssertFastElements(Register elements); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1383 | |
| 1384 | // Like Assert(), but always enabled. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1385 | void Check(Condition cc, BailoutReason reason, Register rs, Operand rt); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1386 | |
| 1387 | // Print a message to stdout and abort execution. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1388 | void Abort(BailoutReason msg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1389 | |
| 1390 | // Verify restrictions about code generated in stubs. |
| 1391 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 1392 | bool generating_stub() { return generating_stub_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1393 | void set_has_frame(bool value) { has_frame_ = value; } |
| 1394 | bool has_frame() { return has_frame_; } |
| 1395 | inline bool AllowThisStubCall(CodeStub* stub); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1396 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1397 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1398 | // Number utilities. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1399 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1400 | // Check whether the value of reg is a power of two and not zero. If not |
| 1401 | // control continues at the label not_power_of_two. If reg is a power of two |
| 1402 | // the register scratch contains the value of (reg - 1) when control falls |
| 1403 | // through. |
| 1404 | void JumpIfNotPowerOfTwoOrZero(Register reg, |
| 1405 | Register scratch, |
| 1406 | Label* not_power_of_two_or_zero); |
| 1407 | |
| 1408 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1409 | // Smi utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1410 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1411 | void SmiTag(Register reg) { |
| 1412 | Addu(reg, reg, reg); |
| 1413 | } |
| 1414 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1415 | void SmiTag(Register dst, Register src) { Addu(dst, src, src); } |
| 1416 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1417 | // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow(). |
| 1418 | void SmiTagCheckOverflow(Register reg, Register overflow); |
| 1419 | void SmiTagCheckOverflow(Register dst, Register src, Register overflow); |
| 1420 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1421 | void BranchOnOverflow(Label* label, Register overflow_check, |
| 1422 | BranchDelaySlot bd = PROTECT) { |
| 1423 | Branch(label, lt, overflow_check, Operand(zero_reg), bd); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1426 | void BranchOnNoOverflow(Label* label, Register overflow_check, |
| 1427 | BranchDelaySlot bd = PROTECT) { |
| 1428 | Branch(label, ge, overflow_check, Operand(zero_reg), bd); |
| 1429 | } |
| 1430 | |
| 1431 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1432 | // Try to convert int32 to smi. If the value is to large, preserve |
| 1433 | // the original value and jump to not_a_smi. Destroys scratch and |
| 1434 | // sets flags. |
| 1435 | void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) { |
| 1436 | TrySmiTag(reg, reg, scratch, not_a_smi); |
| 1437 | } |
| 1438 | void TrySmiTag(Register dst, |
| 1439 | Register src, |
| 1440 | Register scratch, |
| 1441 | Label* not_a_smi) { |
| 1442 | SmiTagCheckOverflow(at, src, scratch); |
| 1443 | BranchOnOverflow(not_a_smi, scratch); |
| 1444 | mov(dst, at); |
| 1445 | } |
| 1446 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1447 | void SmiUntag(Register reg) { |
| 1448 | sra(reg, reg, kSmiTagSize); |
| 1449 | } |
| 1450 | |
| 1451 | void SmiUntag(Register dst, Register src) { |
| 1452 | sra(dst, src, kSmiTagSize); |
| 1453 | } |
| 1454 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1455 | // Test if the register contains a smi. |
| 1456 | inline void SmiTst(Register value, Register scratch) { |
| 1457 | And(scratch, value, Operand(kSmiTagMask)); |
| 1458 | } |
| 1459 | inline void NonNegativeSmiTst(Register value, Register scratch) { |
| 1460 | And(scratch, value, Operand(kSmiTagMask | kSmiSignMask)); |
| 1461 | } |
| 1462 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1463 | // Untag the source value into destination and jump if source is a smi. |
| 1464 | // Souce and destination can be the same register. |
| 1465 | void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case); |
| 1466 | |
| 1467 | // Untag the source value into destination and jump if source is not a smi. |
| 1468 | // Souce and destination can be the same register. |
| 1469 | void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case); |
| 1470 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1471 | // Jump the register contains a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1472 | void JumpIfSmi(Register value, |
| 1473 | Label* smi_label, |
| 1474 | Register scratch = at, |
| 1475 | BranchDelaySlot bd = PROTECT); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1476 | |
| 1477 | // Jump if the register contains a non-smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1478 | void JumpIfNotSmi(Register value, |
| 1479 | Label* not_smi_label, |
| 1480 | Register scratch = at, |
| 1481 | BranchDelaySlot bd = PROTECT); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1482 | |
| 1483 | // Jump if either of the registers contain a non-smi. |
| 1484 | void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi); |
| 1485 | // Jump if either of the registers contain a smi. |
| 1486 | void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi); |
| 1487 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1488 | // Abort execution if argument is a smi, enabled via --debug-code. |
| 1489 | void AssertNotSmi(Register object); |
| 1490 | void AssertSmi(Register object); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1491 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1492 | // Abort execution if argument is not a string, enabled via --debug-code. |
| 1493 | void AssertString(Register object); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1494 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1495 | // Abort execution if argument is not a name, enabled via --debug-code. |
| 1496 | void AssertName(Register object); |
| 1497 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1498 | // Abort execution if argument is not a JSFunction, enabled via --debug-code. |
| 1499 | void AssertFunction(Register object); |
| 1500 | |
| 1501 | // Abort execution if argument is not a JSBoundFunction, |
| 1502 | // enabled via --debug-code. |
| 1503 | void AssertBoundFunction(Register object); |
| 1504 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1505 | // Abort execution if argument is not a JSReceiver, enabled via --debug-code. |
| 1506 | void AssertReceiver(Register object); |
| 1507 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1508 | // Abort execution if argument is not undefined or an AllocationSite, enabled |
| 1509 | // via --debug-code. |
| 1510 | void AssertUndefinedOrAllocationSite(Register object, Register scratch); |
| 1511 | |
| 1512 | // Abort execution if reg is not the root value with the given index, |
| 1513 | // enabled via --debug-code. |
| 1514 | void AssertIsRoot(Register reg, Heap::RootListIndex index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1515 | |
| 1516 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1517 | // HeapNumber utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1518 | |
| 1519 | void JumpIfNotHeapNumber(Register object, |
| 1520 | Register heap_number_map, |
| 1521 | Register scratch, |
| 1522 | Label* on_not_heap_number); |
| 1523 | |
| 1524 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1525 | // String utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1526 | |
| 1527 | // Checks if both instance types are sequential ASCII strings and jumps to |
| 1528 | // label if either is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | void JumpIfBothInstanceTypesAreNotSequentialOneByte( |
| 1530 | Register first_object_instance_type, Register second_object_instance_type, |
| 1531 | Register scratch1, Register scratch2, Label* failure); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1533 | // Check if instance type is sequential one-byte string and jump to label if |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1534 | // it is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1535 | void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch, |
| 1536 | Label* failure); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1537 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1538 | void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1539 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1540 | void EmitSeqStringSetCharCheck(Register string, |
| 1541 | Register index, |
| 1542 | Register value, |
| 1543 | Register scratch, |
| 1544 | uint32_t encoding_mask); |
| 1545 | |
| 1546 | // Checks if both objects are sequential one-byte strings and jumps to label |
| 1547 | // if either is not. Assumes that neither object is a smi. |
| 1548 | void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first, |
| 1549 | Register second, |
| 1550 | Register scratch1, |
| 1551 | Register scratch2, |
| 1552 | Label* failure); |
| 1553 | |
| 1554 | // Checks if both objects are sequential one-byte strings and jumps to label |
| 1555 | // if either is not. |
| 1556 | void JumpIfNotBothSequentialOneByteStrings(Register first, Register second, |
| 1557 | Register scratch1, |
| 1558 | Register scratch2, |
| 1559 | Label* not_flat_one_byte_strings); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1560 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1561 | void ClampUint8(Register output_reg, Register input_reg); |
| 1562 | |
| 1563 | void ClampDoubleToUint8(Register result_reg, |
| 1564 | DoubleRegister input_reg, |
| 1565 | DoubleRegister temp_double_reg); |
| 1566 | |
| 1567 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1568 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1569 | void EnumLength(Register dst, Register map); |
| 1570 | void NumberOfOwnDescriptors(Register dst, Register map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1571 | void LoadAccessor(Register dst, Register holder, int accessor_index, |
| 1572 | AccessorComponent accessor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1573 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1574 | template<typename Field> |
| 1575 | void DecodeField(Register dst, Register src) { |
| 1576 | Ext(dst, src, Field::kShift, Field::kSize); |
| 1577 | } |
| 1578 | |
| 1579 | template<typename Field> |
| 1580 | void DecodeField(Register reg) { |
| 1581 | DecodeField<Field>(reg, reg); |
| 1582 | } |
| 1583 | |
| 1584 | template<typename Field> |
| 1585 | void DecodeFieldToSmi(Register dst, Register src) { |
| 1586 | static const int shift = Field::kShift; |
| 1587 | static const int mask = Field::kMask >> shift << kSmiTagSize; |
| 1588 | STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0); |
| 1589 | STATIC_ASSERT(kSmiTag == 0); |
| 1590 | if (shift < kSmiTagSize) { |
| 1591 | sll(dst, src, kSmiTagSize - shift); |
| 1592 | And(dst, dst, Operand(mask)); |
| 1593 | } else if (shift > kSmiTagSize) { |
| 1594 | srl(dst, src, shift - kSmiTagSize); |
| 1595 | And(dst, dst, Operand(mask)); |
| 1596 | } else { |
| 1597 | And(dst, src, Operand(mask)); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | template<typename Field> |
| 1602 | void DecodeFieldToSmi(Register reg) { |
| 1603 | DecodeField<Field>(reg, reg); |
| 1604 | } |
| 1605 | |
| 1606 | // Generates function and stub prologue code. |
| 1607 | void StubPrologue(); |
| 1608 | void Prologue(bool code_pre_aging); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1609 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1610 | // Load the type feedback vector from a JavaScript frame. |
| 1611 | void EmitLoadTypeFeedbackVector(Register vector); |
| 1612 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1613 | // Activation support. |
| 1614 | void EnterFrame(StackFrame::Type type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1615 | void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1616 | void LeaveFrame(StackFrame::Type type); |
| 1617 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1618 | // Expects object in a0 and returns map with validated enum cache |
| 1619 | // in a0. Assumes that any other register can be used as a scratch. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1620 | void CheckEnumCache(Label* call_runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1621 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1622 | // AllocationMemento support. Arrays may have an associated |
| 1623 | // AllocationMemento object that can be checked for in order to pretransition |
| 1624 | // to another type. |
| 1625 | // On entry, receiver_reg should point to the array object. |
| 1626 | // scratch_reg gets clobbered. |
| 1627 | // If allocation info is present, jump to allocation_memento_present. |
| 1628 | void TestJSArrayForAllocationMemento( |
| 1629 | Register receiver_reg, |
| 1630 | Register scratch_reg, |
| 1631 | Label* no_memento_found, |
| 1632 | Condition cond = al, |
| 1633 | Label* allocation_memento_present = NULL); |
| 1634 | |
| 1635 | void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, |
| 1636 | Register scratch_reg, |
| 1637 | Label* memento_found) { |
| 1638 | Label no_memento_found; |
| 1639 | TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, |
| 1640 | &no_memento_found, eq, memento_found); |
| 1641 | bind(&no_memento_found); |
| 1642 | } |
| 1643 | |
| 1644 | // Jumps to found label if a prototype map has dictionary elements. |
| 1645 | void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0, |
| 1646 | Register scratch1, Label* found); |
| 1647 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1648 | bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; } |
| 1649 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1650 | private: |
| 1651 | void CallCFunctionHelper(Register function, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1652 | int num_reg_arguments, |
| 1653 | int num_double_arguments); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1654 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1655 | inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch); |
| 1656 | inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits); |
| 1657 | void BranchShortHelperR6(int32_t offset, Label* L); |
| 1658 | void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot); |
| 1659 | bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond, |
| 1660 | Register rs, const Operand& rt); |
| 1661 | bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs, |
| 1662 | const Operand& rt, BranchDelaySlot bdslot); |
| 1663 | bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs, |
| 1664 | const Operand& rt, BranchDelaySlot bdslot); |
| 1665 | |
| 1666 | void BranchAndLinkShortHelperR6(int32_t offset, Label* L); |
| 1667 | void BranchAndLinkShortHelper(int16_t offset, Label* L, |
| 1668 | BranchDelaySlot bdslot); |
| 1669 | void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1670 | void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1671 | bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond, |
| 1672 | Register rs, const Operand& rt); |
| 1673 | bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond, |
| 1674 | Register rs, const Operand& rt, |
| 1675 | BranchDelaySlot bdslot); |
| 1676 | bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond, |
| 1677 | Register rs, const Operand& rt, |
| 1678 | BranchDelaySlot bdslot); |
| 1679 | void BranchLong(Label* L, BranchDelaySlot bdslot); |
| 1680 | void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot); |
| 1681 | |
| 1682 | // Common implementation of BranchF functions for the different formats. |
| 1683 | void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan, |
| 1684 | Condition cc, FPURegister cmp1, FPURegister cmp2, |
| 1685 | BranchDelaySlot bd = PROTECT); |
| 1686 | |
| 1687 | void BranchShortF(SecondaryField sizeField, Label* target, Condition cc, |
| 1688 | FPURegister cmp1, FPURegister cmp2, |
| 1689 | BranchDelaySlot bd = PROTECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1690 | |
| 1691 | // Helper functions for generating invokes. |
| 1692 | void InvokePrologue(const ParameterCount& expected, |
| 1693 | const ParameterCount& actual, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1694 | Label* done, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1695 | bool* definitely_mismatches, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1696 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1697 | const CallWrapper& call_wrapper); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1698 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1699 | void InitializeNewString(Register string, |
| 1700 | Register length, |
| 1701 | Heap::RootListIndex map_index, |
| 1702 | Register scratch1, |
| 1703 | Register scratch2); |
| 1704 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1705 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1706 | void InNewSpace(Register object, Register scratch, |
| 1707 | Condition cond, // ne for new space, eq otherwise. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1708 | Label* branch); |
| 1709 | |
| 1710 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1711 | // bitmap register points at the word with the mark bits and the mask |
| 1712 | // the position of the first bit. Leaves addr_reg unchanged. |
| 1713 | inline void GetMarkBits(Register addr_reg, |
| 1714 | Register bitmap_reg, |
| 1715 | Register mask_reg); |
| 1716 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1717 | // Compute memory operands for safepoint stack slots. |
| 1718 | static int SafepointRegisterStackIndex(int reg_code); |
| 1719 | MemOperand SafepointRegisterSlot(Register reg); |
| 1720 | MemOperand SafepointRegistersAndDoublesSlot(Register reg); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1721 | |
| 1722 | bool generating_stub_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1723 | bool has_frame_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1724 | bool has_double_zero_reg_set_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1725 | // This handle will be patched with the code object on installation. |
| 1726 | Handle<Object> code_object_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1727 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1728 | // Needs access to SafepointRegisterStackIndex for compiled frame |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1729 | // traversal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1730 | friend class StandardFrame; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1731 | }; |
| 1732 | |
| 1733 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1734 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1735 | // debugging and other types of instrumentation. When using the code patcher |
| 1736 | // the exact number of bytes specified must be emitted. It is not legal to emit |
| 1737 | // relocation information. If any of these constraints are violated it causes |
| 1738 | // an assertion to fail. |
| 1739 | class CodePatcher { |
| 1740 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1741 | enum FlushICache { |
| 1742 | FLUSH, |
| 1743 | DONT_FLUSH |
| 1744 | }; |
| 1745 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1746 | CodePatcher(Isolate* isolate, byte* address, int instructions, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1747 | FlushICache flush_cache = FLUSH); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1748 | ~CodePatcher(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1749 | |
| 1750 | // Macro assembler to emit code. |
| 1751 | MacroAssembler* masm() { return &masm_; } |
| 1752 | |
| 1753 | // Emit an instruction directly. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1754 | void Emit(Instr instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1755 | |
| 1756 | // Emit an address directly. |
| 1757 | void Emit(Address addr); |
| 1758 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1759 | // Change the condition part of an instruction leaving the rest of the current |
| 1760 | // instruction unchanged. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1761 | void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1762 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1763 | private: |
| 1764 | byte* address_; // The address of the code being patched. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1765 | int size_; // Number of bytes of the expected patch size. |
| 1766 | MacroAssembler masm_; // Macro assembler used to generate the code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1767 | FlushICache flush_cache_; // Whether to flush the I cache after patching. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1768 | }; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1769 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1770 | template <typename Func> |
| 1771 | void MacroAssembler::GenerateSwitchTable(Register index, size_t case_count, |
| 1772 | Func GetLabelFunction) { |
| 1773 | if (kArchVariant >= kMips32r6) { |
| 1774 | BlockTrampolinePoolFor(case_count + 5); |
| 1775 | addiupc(at, 5); |
| 1776 | lsa(at, at, index, kPointerSizeLog2); |
| 1777 | lw(at, MemOperand(at)); |
| 1778 | } else { |
| 1779 | Label here; |
| 1780 | BlockTrampolinePoolFor(case_count + 6); |
| 1781 | bal(&here); |
| 1782 | sll(at, index, kPointerSizeLog2); // Branch delay slot. |
| 1783 | bind(&here); |
| 1784 | addu(at, at, ra); |
| 1785 | lw(at, MemOperand(at, 4 * v8::internal::Assembler::kInstrSize)); |
| 1786 | } |
| 1787 | jr(at); |
| 1788 | nop(); // Branch delay slot nop. |
| 1789 | for (size_t index = 0; index < case_count; ++index) { |
| 1790 | dd(GetLabelFunction(index)); |
| 1791 | } |
| 1792 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1793 | |
| 1794 | #ifdef GENERATED_CODE_COVERAGE |
| 1795 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1796 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1797 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1798 | #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> |
| 1799 | #else |
| 1800 | #define ACCESS_MASM(masm) masm-> |
| 1801 | #endif |
| 1802 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1803 | } // namespace internal |
| 1804 | } // namespace v8 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1805 | |
| 1806 | #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ |