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