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