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. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 6 | #define V8_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/assembler.h" |
| 9 | #include "src/bailout-reason.h" |
| 10 | #include "src/frames.h" |
| 11 | #include "src/globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 16 | // Give alias names to registers for calling conventions. |
| 17 | const Register kReturnRegister0 = {Register::kCode_r0}; |
| 18 | const Register kReturnRegister1 = {Register::kCode_r1}; |
| 19 | const Register kJSFunctionRegister = {Register::kCode_r1}; |
| 20 | const Register kContextRegister = {Register::kCode_r7}; |
| 21 | const Register kInterpreterAccumulatorRegister = {Register::kCode_r0}; |
| 22 | const Register kInterpreterRegisterFileRegister = {Register::kCode_r4}; |
| 23 | const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r5}; |
| 24 | const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r6}; |
| 25 | const Register kInterpreterDispatchTableRegister = {Register::kCode_r8}; |
| 26 | const Register kJavaScriptCallArgCountRegister = {Register::kCode_r0}; |
| 27 | const Register kJavaScriptCallNewTargetRegister = {Register::kCode_r3}; |
| 28 | const Register kRuntimeCallFunctionRegister = {Register::kCode_r1}; |
| 29 | const Register kRuntimeCallArgCountRegister = {Register::kCode_r0}; |
| 30 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 31 | // ---------------------------------------------------------------------------- |
| 32 | // Static helper functions |
| 33 | |
| 34 | // Generate a MemOperand for loading a field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 35 | inline MemOperand FieldMemOperand(Register object, int offset) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 36 | return MemOperand(object, offset - kHeapObjectTag); |
| 37 | } |
| 38 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | |
| 40 | // Give alias names to registers |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 41 | const Register cp = {Register::kCode_r7}; // JavaScript context pointer. |
| 42 | const Register pp = {Register::kCode_r8}; // Constant pool pointer. |
| 43 | const Register kRootRegister = {Register::kCode_r10}; // Roots array pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | // Flags used for AllocateHeapNumber |
| 46 | enum TaggingMode { |
| 47 | // Tag the result. |
| 48 | TAG_RESULT, |
| 49 | // Don't tag |
| 50 | DONT_TAG_RESULT |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 54 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 55 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | enum PointersToHereCheck { |
| 57 | kPointersToHereMaybeInteresting, |
| 58 | kPointersToHereAreAlwaysInteresting |
| 59 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 60 | enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved }; |
| 61 | |
| 62 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | Register GetRegisterThatIsNotOneOf(Register reg1, |
| 64 | Register reg2 = no_reg, |
| 65 | Register reg3 = no_reg, |
| 66 | Register reg4 = no_reg, |
| 67 | Register reg5 = no_reg, |
| 68 | Register reg6 = no_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 69 | |
| 70 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | #ifdef DEBUG |
| 72 | bool AreAliased(Register reg1, |
| 73 | Register reg2, |
| 74 | Register reg3 = no_reg, |
| 75 | Register reg4 = no_reg, |
| 76 | Register reg5 = no_reg, |
| 77 | Register reg6 = no_reg, |
| 78 | Register reg7 = no_reg, |
| 79 | Register reg8 = no_reg); |
| 80 | #endif |
| 81 | |
| 82 | |
| 83 | enum TargetAddressStorageMode { |
| 84 | CAN_INLINE_TARGET_ADDRESS, |
| 85 | NEVER_INLINE_TARGET_ADDRESS |
| 86 | }; |
| 87 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | // MacroAssembler implements a collection of frequently used macros. |
| 89 | class MacroAssembler: public Assembler { |
| 90 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 91 | MacroAssembler(Isolate* isolate, void* buffer, int size, |
| 92 | CodeObjectRequired create_code_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 94 | |
| 95 | // Returns the size of a call in instructions. Note, the value returned is |
| 96 | // only valid as long as no entries are added to the constant pool between |
| 97 | // checking the call size and emitting the actual call. |
| 98 | static int CallSize(Register target, Condition cond = al); |
| 99 | int CallSize(Address target, RelocInfo::Mode rmode, Condition cond = al); |
| 100 | int CallStubSize(CodeStub* stub, |
| 101 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 102 | Condition cond = al); |
| 103 | static int CallSizeNotPredictableCodeSize(Isolate* isolate, |
| 104 | Address target, |
| 105 | RelocInfo::Mode rmode, |
| 106 | Condition cond = al); |
| 107 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 108 | // Jump, Call, and Ret pseudo instructions implementing inter-working. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | void Jump(Register target, Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 110 | void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); |
| 112 | void Call(Register target, Condition cond = al); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | void Call(Address target, RelocInfo::Mode rmode, |
| 114 | Condition cond = al, |
| 115 | TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS); |
| 116 | int CallSize(Handle<Code> code, |
| 117 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 118 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 119 | Condition cond = al); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 120 | void Call(Handle<Code> code, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 121 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 123 | Condition cond = al, |
| 124 | TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 125 | void Ret(Condition cond = al); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 126 | |
| 127 | // Emit code to discard a non-negative number of pointer-sized elements |
| 128 | // from the stack, clobbering only the sp register. |
| 129 | void Drop(int count, Condition cond = al); |
| 130 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 131 | void Ret(int drop, Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 132 | |
| 133 | // Swap two registers. If the scratch register is omitted then a slightly |
| 134 | // less efficient form using xor instead of mov is emitted. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 135 | void Swap(Register reg1, |
| 136 | Register reg2, |
| 137 | Register scratch = no_reg, |
| 138 | Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 139 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | void Mls(Register dst, Register src1, Register src2, Register srcA, |
| 141 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 142 | void And(Register dst, Register src1, const Operand& src2, |
| 143 | Condition cond = al); |
| 144 | void Ubfx(Register dst, Register src, int lsb, int width, |
| 145 | Condition cond = al); |
| 146 | void Sbfx(Register dst, Register src, int lsb, int width, |
| 147 | Condition cond = al); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 148 | // The scratch register is not used for ARMv7. |
| 149 | // scratch can be the same register as src (in which case it is trashed), but |
| 150 | // not the same as dst. |
| 151 | void Bfi(Register dst, |
| 152 | Register src, |
| 153 | Register scratch, |
| 154 | int lsb, |
| 155 | int width, |
| 156 | Condition cond = al); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 157 | void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 158 | void Usat(Register dst, int satpos, const Operand& src, |
| 159 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 160 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 161 | void Call(Label* target); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | void Push(Register src) { push(src); } |
| 163 | void Pop(Register dst) { pop(dst); } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 164 | |
| 165 | // Register move. May do nothing if the registers are identical. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 166 | void Move(Register dst, Smi* smi) { mov(dst, Operand(smi)); } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 167 | void Move(Register dst, Handle<Object> value); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 168 | void Move(Register dst, Register src, Condition cond = al); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | void Move(Register dst, const Operand& src, SBit sbit = LeaveCC, |
| 170 | Condition cond = al) { |
| 171 | if (!src.is_reg() || !src.rm().is(dst) || sbit != LeaveCC) { |
| 172 | mov(dst, src, sbit, cond); |
| 173 | } |
| 174 | } |
| 175 | void Move(DwVfpRegister dst, DwVfpRegister src); |
| 176 | |
| 177 | void Load(Register dst, const MemOperand& src, Representation r); |
| 178 | void Store(Register src, const MemOperand& dst, Representation r); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 179 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 180 | // Load an object from the root table. |
| 181 | void LoadRoot(Register destination, |
| 182 | Heap::RootListIndex index, |
| 183 | Condition cond = al); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 184 | // Store an object to the root table. |
| 185 | void StoreRoot(Register source, |
| 186 | Heap::RootListIndex index, |
| 187 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 188 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 189 | // --------------------------------------------------------------------------- |
| 190 | // GC Support |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 191 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 192 | void IncrementalMarkingRecordWriteHelper(Register object, |
| 193 | Register value, |
| 194 | Register address); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 195 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 196 | enum RememberedSetFinalAction { |
| 197 | kReturnAtEnd, |
| 198 | kFallThroughAtEnd |
| 199 | }; |
| 200 | |
| 201 | // Record in the remembered set the fact that we have a pointer to new space |
| 202 | // at the address pointed to by the addr register. Only works if addr is not |
| 203 | // in new space. |
| 204 | void RememberedSetHelper(Register object, // Used for debug code. |
| 205 | Register addr, |
| 206 | Register scratch, |
| 207 | SaveFPRegsMode save_fp, |
| 208 | RememberedSetFinalAction and_then); |
| 209 | |
| 210 | void CheckPageFlag(Register object, |
| 211 | Register scratch, |
| 212 | int mask, |
| 213 | Condition cc, |
| 214 | Label* condition_met); |
| 215 | |
| 216 | // Check if object is in new space. Jumps if the object is not in new space. |
| 217 | // The register scratch can be object itself, but scratch will be clobbered. |
| 218 | void JumpIfNotInNewSpace(Register object, |
| 219 | Register scratch, |
| 220 | Label* branch) { |
| 221 | InNewSpace(object, scratch, ne, branch); |
| 222 | } |
| 223 | |
| 224 | // Check if object is in new space. Jumps if the object is in new space. |
| 225 | // The register scratch can be object itself, but it will be clobbered. |
| 226 | void JumpIfInNewSpace(Register object, |
| 227 | Register scratch, |
| 228 | Label* branch) { |
| 229 | InNewSpace(object, scratch, eq, branch); |
| 230 | } |
| 231 | |
| 232 | // Check if an object has a given incremental marking color. |
| 233 | void HasColor(Register object, |
| 234 | Register scratch0, |
| 235 | Register scratch1, |
| 236 | Label* has_color, |
| 237 | int first_bit, |
| 238 | int second_bit); |
| 239 | |
| 240 | void JumpIfBlack(Register object, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 241 | Register scratch0, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 242 | Register scratch1, |
| 243 | Label* on_black); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 244 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 245 | // Checks the color of an object. If the object is white we jump to the |
| 246 | // incremental marker. |
| 247 | void JumpIfWhite(Register value, Register scratch1, Register scratch2, |
| 248 | Register scratch3, Label* value_is_white); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 249 | |
| 250 | // Notify the garbage collector that we wrote a pointer into an object. |
| 251 | // |object| is the object being stored into, |value| is the object being |
| 252 | // stored. value and scratch registers are clobbered by the operation. |
| 253 | // The offset is the offset from the start of the object, not the offset from |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 254 | // the tagged HeapObject pointer. For use with FieldMemOperand(reg, off). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 255 | void RecordWriteField( |
| 256 | Register object, |
| 257 | int offset, |
| 258 | Register value, |
| 259 | Register scratch, |
| 260 | LinkRegisterStatus lr_status, |
| 261 | SaveFPRegsMode save_fp, |
| 262 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 263 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 264 | PointersToHereCheck pointers_to_here_check_for_value = |
| 265 | kPointersToHereMaybeInteresting); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 266 | |
| 267 | // As above, but the offset has the tag presubtracted. For use with |
| 268 | // MemOperand(reg, off). |
| 269 | inline void RecordWriteContextSlot( |
| 270 | Register context, |
| 271 | int offset, |
| 272 | Register value, |
| 273 | Register scratch, |
| 274 | LinkRegisterStatus lr_status, |
| 275 | SaveFPRegsMode save_fp, |
| 276 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 278 | PointersToHereCheck pointers_to_here_check_for_value = |
| 279 | kPointersToHereMaybeInteresting) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 280 | RecordWriteField(context, |
| 281 | offset + kHeapObjectTag, |
| 282 | value, |
| 283 | scratch, |
| 284 | lr_status, |
| 285 | save_fp, |
| 286 | remembered_set_action, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 287 | smi_check, |
| 288 | pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | void RecordWriteForMap( |
| 292 | Register object, |
| 293 | Register map, |
| 294 | Register dst, |
| 295 | LinkRegisterStatus lr_status, |
| 296 | SaveFPRegsMode save_fp); |
| 297 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 298 | // For a given |object| notify the garbage collector that the slot |address| |
| 299 | // has been written. |value| is the object being stored. The value and |
| 300 | // address registers are clobbered by the operation. |
| 301 | void RecordWrite( |
| 302 | Register object, |
| 303 | Register address, |
| 304 | Register value, |
| 305 | LinkRegisterStatus lr_status, |
| 306 | SaveFPRegsMode save_fp, |
| 307 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 309 | PointersToHereCheck pointers_to_here_check_for_value = |
| 310 | kPointersToHereMaybeInteresting); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 311 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 312 | // Push a handle. |
| 313 | void Push(Handle<Object> handle); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 315 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 316 | // Push two registers. Pushes leftmost register first (to highest address). |
| 317 | void Push(Register src1, Register src2, Condition cond = al) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 318 | DCHECK(!src1.is(src2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 319 | if (src1.code() > src2.code()) { |
| 320 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 321 | } else { |
| 322 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 323 | str(src2, MemOperand(sp, 4, NegPreIndex), cond); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Push three registers. Pushes leftmost register first (to highest address). |
| 328 | void Push(Register src1, Register src2, Register src3, Condition cond = al) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 329 | DCHECK(!AreAliased(src1, src2, src3)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 330 | if (src1.code() > src2.code()) { |
| 331 | if (src2.code() > src3.code()) { |
| 332 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 333 | } else { |
| 334 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 335 | str(src3, MemOperand(sp, 4, NegPreIndex), cond); |
| 336 | } |
| 337 | } else { |
| 338 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 339 | Push(src2, src3, cond); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // Push four registers. Pushes leftmost register first (to highest address). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 344 | void Push(Register src1, |
| 345 | Register src2, |
| 346 | Register src3, |
| 347 | Register src4, |
| 348 | Condition cond = al) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 349 | DCHECK(!AreAliased(src1, src2, src3, src4)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 350 | if (src1.code() > src2.code()) { |
| 351 | if (src2.code() > src3.code()) { |
| 352 | if (src3.code() > src4.code()) { |
| 353 | stm(db_w, |
| 354 | sp, |
| 355 | src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 356 | cond); |
| 357 | } else { |
| 358 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 359 | str(src4, MemOperand(sp, 4, NegPreIndex), cond); |
| 360 | } |
| 361 | } else { |
| 362 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 363 | Push(src3, src4, cond); |
| 364 | } |
| 365 | } else { |
| 366 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 367 | Push(src2, src3, src4, cond); |
| 368 | } |
| 369 | } |
| 370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 371 | // Push five registers. Pushes leftmost register first (to highest address). |
| 372 | void Push(Register src1, Register src2, Register src3, Register src4, |
| 373 | Register src5, Condition cond = al) { |
| 374 | DCHECK(!AreAliased(src1, src2, src3, src4, src5)); |
| 375 | if (src1.code() > src2.code()) { |
| 376 | if (src2.code() > src3.code()) { |
| 377 | if (src3.code() > src4.code()) { |
| 378 | if (src4.code() > src5.code()) { |
| 379 | stm(db_w, sp, |
| 380 | src1.bit() | src2.bit() | src3.bit() | src4.bit() | src5.bit(), |
| 381 | cond); |
| 382 | } else { |
| 383 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 384 | cond); |
| 385 | str(src5, MemOperand(sp, 4, NegPreIndex), cond); |
| 386 | } |
| 387 | } else { |
| 388 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 389 | Push(src4, src5, cond); |
| 390 | } |
| 391 | } else { |
| 392 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 393 | Push(src3, src4, src5, cond); |
| 394 | } |
| 395 | } else { |
| 396 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 397 | Push(src2, src3, src4, src5, cond); |
| 398 | } |
| 399 | } |
| 400 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 401 | // Pop two registers. Pops rightmost register first (from lower address). |
| 402 | void Pop(Register src1, Register src2, Condition cond = al) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | DCHECK(!src1.is(src2)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 404 | if (src1.code() > src2.code()) { |
| 405 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 406 | } else { |
| 407 | ldr(src2, MemOperand(sp, 4, PostIndex), cond); |
| 408 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
| 409 | } |
| 410 | } |
| 411 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 412 | // Pop three registers. Pops rightmost register first (from lower address). |
| 413 | void Pop(Register src1, Register src2, Register src3, Condition cond = al) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 414 | DCHECK(!AreAliased(src1, src2, src3)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 415 | if (src1.code() > src2.code()) { |
| 416 | if (src2.code() > src3.code()) { |
| 417 | ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 418 | } else { |
| 419 | ldr(src3, MemOperand(sp, 4, PostIndex), cond); |
| 420 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 421 | } |
| 422 | } else { |
| 423 | Pop(src2, src3, cond); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
| 428 | // Pop four registers. Pops rightmost register first (from lower address). |
| 429 | void Pop(Register src1, |
| 430 | Register src2, |
| 431 | Register src3, |
| 432 | Register src4, |
| 433 | Condition cond = al) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 434 | DCHECK(!AreAliased(src1, src2, src3, src4)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 435 | if (src1.code() > src2.code()) { |
| 436 | if (src2.code() > src3.code()) { |
| 437 | if (src3.code() > src4.code()) { |
| 438 | ldm(ia_w, |
| 439 | sp, |
| 440 | src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 441 | cond); |
| 442 | } else { |
| 443 | ldr(src4, MemOperand(sp, 4, PostIndex), cond); |
| 444 | ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 445 | } |
| 446 | } else { |
| 447 | Pop(src3, src4, cond); |
| 448 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 449 | } |
| 450 | } else { |
| 451 | Pop(src2, src3, src4, cond); |
| 452 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
| 453 | } |
| 454 | } |
| 455 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | // Push a fixed frame, consisting of lr, fp, constant pool (if |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 457 | // FLAG_enable_embedded_constant_pool), context and JS function / marker id if |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 458 | // marker_reg is a valid register. |
| 459 | void PushFixedFrame(Register marker_reg = no_reg); |
| 460 | void PopFixedFrame(Register marker_reg = no_reg); |
| 461 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 462 | // Push and pop the registers that can hold pointers, as defined by the |
| 463 | // RegList constant kSafepointSavedRegisters. |
| 464 | void PushSafepointRegisters(); |
| 465 | void PopSafepointRegisters(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 466 | // Store value in register src in the safepoint stack slot for |
| 467 | // register dst. |
| 468 | void StoreToSafepointRegisterSlot(Register src, Register dst); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 469 | // Load the value of the src register from its safepoint stack slot |
| 470 | // into register dst. |
| 471 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 472 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 473 | // Load two consecutive registers with two consecutive memory locations. |
| 474 | void Ldrd(Register dst1, |
| 475 | Register dst2, |
| 476 | const MemOperand& src, |
| 477 | Condition cond = al); |
| 478 | |
| 479 | // Store two consecutive registers to two consecutive memory locations. |
| 480 | void Strd(Register src1, |
| 481 | Register src2, |
| 482 | const MemOperand& dst, |
| 483 | Condition cond = al); |
| 484 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 485 | // Ensure that FPSCR contains values needed by JavaScript. |
| 486 | // We need the NaNModeControlBit to be sure that operations like |
| 487 | // vadd and vsub generate the Canonical NaN (if a NaN must be generated). |
| 488 | // In VFP3 it will be always the Canonical NaN. |
| 489 | // In VFP2 it will be either the Canonical NaN or the negative version |
| 490 | // of the Canonical NaN. It doesn't matter if we have two values. The aim |
| 491 | // is to be sure to never generate the hole NaN. |
| 492 | void VFPEnsureFPSCRState(Register scratch); |
| 493 | |
| 494 | // If the value is a NaN, canonicalize the value else, do nothing. |
| 495 | void VFPCanonicalizeNaN(const DwVfpRegister dst, |
| 496 | const DwVfpRegister src, |
| 497 | const Condition cond = al); |
| 498 | void VFPCanonicalizeNaN(const DwVfpRegister value, |
| 499 | const Condition cond = al) { |
| 500 | VFPCanonicalizeNaN(value, value, cond); |
| 501 | } |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 502 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 503 | // Compare single values and move the result to the normal condition flags. |
| 504 | void VFPCompareAndSetFlags(const SwVfpRegister src1, const SwVfpRegister src2, |
| 505 | const Condition cond = al); |
| 506 | void VFPCompareAndSetFlags(const SwVfpRegister src1, const float src2, |
| 507 | const Condition cond = al); |
| 508 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 509 | // Compare double values and move the result to the normal condition flags. |
| 510 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 511 | const DwVfpRegister src2, |
| 512 | const Condition cond = al); |
| 513 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 514 | const double src2, |
| 515 | const Condition cond = al); |
| 516 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 517 | // Compare single values and then load the fpscr flags to a register. |
| 518 | void VFPCompareAndLoadFlags(const SwVfpRegister src1, |
| 519 | const SwVfpRegister src2, |
| 520 | const Register fpscr_flags, |
| 521 | const Condition cond = al); |
| 522 | void VFPCompareAndLoadFlags(const SwVfpRegister src1, const float src2, |
| 523 | const Register fpscr_flags, |
| 524 | const Condition cond = al); |
| 525 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 526 | // Compare double values and then load the fpscr flags to a register. |
| 527 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 528 | const DwVfpRegister src2, |
| 529 | const Register fpscr_flags, |
| 530 | const Condition cond = al); |
| 531 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 532 | const double src2, |
| 533 | const Register fpscr_flags, |
| 534 | const Condition cond = al); |
| 535 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 536 | void Vmov(const DwVfpRegister dst, |
| 537 | const double imm, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 538 | const Register scratch = no_reg); |
| 539 | |
| 540 | void VmovHigh(Register dst, DwVfpRegister src); |
| 541 | void VmovHigh(DwVfpRegister dst, Register src); |
| 542 | void VmovLow(Register dst, DwVfpRegister src); |
| 543 | void VmovLow(DwVfpRegister dst, Register src); |
| 544 | |
| 545 | // Loads the number from object into dst register. |
| 546 | // If |object| is neither smi nor heap number, |not_number| is jumped to |
| 547 | // with |object| still intact. |
| 548 | void LoadNumber(Register object, |
| 549 | LowDwVfpRegister dst, |
| 550 | Register heap_number_map, |
| 551 | Register scratch, |
| 552 | Label* not_number); |
| 553 | |
| 554 | // Loads the number from object into double_dst in the double format. |
| 555 | // Control will jump to not_int32 if the value cannot be exactly represented |
| 556 | // by a 32-bit integer. |
| 557 | // Floating point value in the 32-bit integer range that are not exact integer |
| 558 | // won't be loaded. |
| 559 | void LoadNumberAsInt32Double(Register object, |
| 560 | DwVfpRegister double_dst, |
| 561 | Register heap_number_map, |
| 562 | Register scratch, |
| 563 | LowDwVfpRegister double_scratch, |
| 564 | Label* not_int32); |
| 565 | |
| 566 | // Loads the number from object into dst as a 32-bit integer. |
| 567 | // Control will jump to not_int32 if the object cannot be exactly represented |
| 568 | // by a 32-bit integer. |
| 569 | // Floating point value in the 32-bit integer range that are not exact integer |
| 570 | // won't be converted. |
| 571 | void LoadNumberAsInt32(Register object, |
| 572 | Register dst, |
| 573 | Register heap_number_map, |
| 574 | Register scratch, |
| 575 | DwVfpRegister double_scratch0, |
| 576 | LowDwVfpRegister double_scratch1, |
| 577 | Label* not_int32); |
| 578 | |
| 579 | // Generates function and stub prologue code. |
| 580 | void StubPrologue(); |
| 581 | void Prologue(bool code_pre_aging); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 582 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 583 | // Enter exit frame. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 584 | // stack_space - extra stack space, used for alignment before call to C. |
| 585 | void EnterExitFrame(bool save_doubles, int stack_space = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | |
| 587 | // Leave the current exit frame. Expects the return value in r0. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 588 | // Expect the number of values, pushed prior to the exit frame, to |
| 589 | // remove in a register (or no_reg, if there is nothing to remove). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 590 | void LeaveExitFrame(bool save_doubles, Register argument_count, |
| 591 | bool restore_context, |
| 592 | bool argument_count_is_length = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 594 | // Get the actual activation frame alignment for target environment. |
| 595 | static int ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 597 | void LoadContext(Register dst, int context_chain_length); |
| 598 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 599 | // Load the global object from the current context. |
| 600 | void LoadGlobalObject(Register dst) { |
| 601 | LoadNativeContextSlot(Context::EXTENSION_INDEX, dst); |
| 602 | } |
| 603 | |
| 604 | // Load the global proxy from the current context. |
| 605 | void LoadGlobalProxy(Register dst) { |
| 606 | LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst); |
| 607 | } |
| 608 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 609 | // Conditionally load the cached Array transitioned map of type |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 610 | // transitioned_kind from the native context if the map in register |
| 611 | // 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] | 612 | // expected_kind. |
| 613 | void LoadTransitionedArrayMapConditional( |
| 614 | ElementsKind expected_kind, |
| 615 | ElementsKind transitioned_kind, |
| 616 | Register map_in_out, |
| 617 | Register scratch, |
| 618 | Label* no_map_match); |
| 619 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 620 | void LoadNativeContextSlot(int index, Register dst); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 621 | |
| 622 | // Load the initial map from the global function. The registers |
| 623 | // function and map can be the same, function is then overwritten. |
| 624 | void LoadGlobalFunctionInitialMap(Register function, |
| 625 | Register map, |
| 626 | Register scratch); |
| 627 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 628 | void InitializeRootRegister() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 629 | ExternalReference roots_array_start = |
| 630 | ExternalReference::roots_array_start(isolate()); |
| 631 | mov(kRootRegister, Operand(roots_array_start)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 634 | // --------------------------------------------------------------------------- |
| 635 | // JavaScript invokes |
| 636 | |
| 637 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 638 | void InvokeFunctionCode(Register function, Register new_target, |
| 639 | const ParameterCount& expected, |
| 640 | const ParameterCount& actual, InvokeFlag flag, |
| 641 | const CallWrapper& call_wrapper); |
| 642 | |
| 643 | void FloodFunctionIfStepping(Register fun, Register new_target, |
| 644 | const ParameterCount& expected, |
| 645 | const ParameterCount& actual); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | |
| 647 | // Invoke the JavaScript function in the given register. Changes the |
| 648 | // current context to the context in the function before invoking. |
| 649 | void InvokeFunction(Register function, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 650 | Register new_target, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 652 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 653 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 654 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 655 | void InvokeFunction(Register function, |
| 656 | const ParameterCount& expected, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 657 | const ParameterCount& actual, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 658 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | const CallWrapper& call_wrapper); |
| 660 | |
| 661 | void InvokeFunction(Handle<JSFunction> function, |
| 662 | const ParameterCount& expected, |
| 663 | const ParameterCount& actual, |
| 664 | InvokeFlag flag, |
| 665 | const CallWrapper& call_wrapper); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 666 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 667 | void IsObjectJSStringType(Register object, |
| 668 | Register scratch, |
| 669 | Label* fail); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 670 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 671 | void IsObjectNameType(Register object, |
| 672 | Register scratch, |
| 673 | Label* fail); |
| 674 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | // --------------------------------------------------------------------------- |
| 676 | // Debugger Support |
| 677 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 678 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 679 | |
| 680 | // --------------------------------------------------------------------------- |
| 681 | // Exception handling |
| 682 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 683 | // Push a new stack handler and link into stack handler chain. |
| 684 | void PushStackHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 685 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 686 | // Unlink the stack handler on top of the stack from the stack handler chain. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 687 | // Must preserve the result register. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 688 | void PopStackHandler(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 689 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 690 | // --------------------------------------------------------------------------- |
| 691 | // Inline caching support |
| 692 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 693 | // Generate code for checking access rights - used for security checks |
| 694 | // on access to global objects across environments. The holder register |
| 695 | // is left untouched, whereas both scratch registers are clobbered. |
| 696 | void CheckAccessGlobalProxy(Register holder_reg, |
| 697 | Register scratch, |
| 698 | Label* miss); |
| 699 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 700 | void GetNumberHash(Register t0, Register scratch); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 701 | |
| 702 | void LoadFromNumberDictionary(Label* miss, |
| 703 | Register elements, |
| 704 | Register key, |
| 705 | Register result, |
| 706 | Register t0, |
| 707 | Register t1, |
| 708 | Register t2); |
| 709 | |
| 710 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 711 | inline void MarkCode(NopMarkerTypes type) { |
| 712 | nop(type); |
| 713 | } |
| 714 | |
| 715 | // Check if the given instruction is a 'type' marker. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 716 | // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type)) |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 717 | // These instructions are generated to mark special location in the code, |
| 718 | // like some special IC code. |
| 719 | static inline bool IsMarkedCode(Instr instr, int type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 720 | DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 721 | return IsNop(instr, type); |
| 722 | } |
| 723 | |
| 724 | |
| 725 | static inline int GetCodeMarker(Instr instr) { |
| 726 | int dst_reg_offset = 12; |
| 727 | int dst_mask = 0xf << dst_reg_offset; |
| 728 | int src_mask = 0xf; |
| 729 | int dst_reg = (instr & dst_mask) >> dst_reg_offset; |
| 730 | int src_reg = instr & src_mask; |
| 731 | uint32_t non_register_mask = ~(dst_mask | src_mask); |
| 732 | uint32_t mov_mask = al | 13 << 21; |
| 733 | |
| 734 | // Return <n> if we have a mov rn rn, else return -1. |
| 735 | int type = ((instr & non_register_mask) == mov_mask) && |
| 736 | (dst_reg == src_reg) && |
| 737 | (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER) |
| 738 | ? src_reg |
| 739 | : -1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 740 | DCHECK((type == -1) || |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 741 | ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER))); |
| 742 | return type; |
| 743 | } |
| 744 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | |
| 746 | // --------------------------------------------------------------------------- |
| 747 | // Allocation support |
| 748 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 749 | // 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] | 750 | // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS |
| 751 | // is passed. If the space is exhausted control continues at the gc_required |
| 752 | // label. The allocated object is returned in result. If the flag |
| 753 | // tag_allocated_object is true the result is tagged as as a heap object. |
| 754 | // All registers are clobbered also when control continues at the gc_required |
| 755 | // label. |
| 756 | void Allocate(int object_size, |
| 757 | Register result, |
| 758 | Register scratch1, |
| 759 | Register scratch2, |
| 760 | Label* gc_required, |
| 761 | AllocationFlags flags); |
| 762 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 763 | void Allocate(Register object_size, Register result, Register result_end, |
| 764 | Register scratch, Label* gc_required, AllocationFlags flags); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 765 | |
| 766 | void AllocateTwoByteString(Register result, |
| 767 | Register length, |
| 768 | Register scratch1, |
| 769 | Register scratch2, |
| 770 | Register scratch3, |
| 771 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 772 | void AllocateOneByteString(Register result, Register length, |
| 773 | Register scratch1, Register scratch2, |
| 774 | Register scratch3, Label* gc_required); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 775 | void AllocateTwoByteConsString(Register result, |
| 776 | Register length, |
| 777 | Register scratch1, |
| 778 | Register scratch2, |
| 779 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 780 | void AllocateOneByteConsString(Register result, Register length, |
| 781 | Register scratch1, Register scratch2, |
| 782 | Label* gc_required); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 783 | void AllocateTwoByteSlicedString(Register result, |
| 784 | Register length, |
| 785 | Register scratch1, |
| 786 | Register scratch2, |
| 787 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | void AllocateOneByteSlicedString(Register result, Register length, |
| 789 | Register scratch1, Register scratch2, |
| 790 | Label* gc_required); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 791 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 792 | // Allocates a heap number or jumps to the gc_required label if the young |
| 793 | // space is full and a scavenge is needed. All registers are clobbered also |
| 794 | // when control continues at the gc_required label. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 795 | void AllocateHeapNumber(Register result, |
| 796 | Register scratch1, |
| 797 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 798 | Register heap_number_map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 799 | Label* gc_required, |
| 800 | TaggingMode tagging_mode = TAG_RESULT, |
| 801 | MutableMode mode = IMMUTABLE); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 802 | void AllocateHeapNumberWithValue(Register result, |
| 803 | DwVfpRegister value, |
| 804 | Register scratch1, |
| 805 | Register scratch2, |
| 806 | Register heap_number_map, |
| 807 | Label* gc_required); |
| 808 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 809 | // Allocate and initialize a JSValue wrapper with the specified {constructor} |
| 810 | // and {value}. |
| 811 | void AllocateJSValue(Register result, Register constructor, Register value, |
| 812 | Register scratch1, Register scratch2, |
| 813 | Label* gc_required); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 814 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 815 | // Copies a number of bytes from src to dst. All registers are clobbered. On |
| 816 | // exit src and dst will point to the place just after where the last byte was |
| 817 | // read or written and length will be zero. |
| 818 | void CopyBytes(Register src, |
| 819 | Register dst, |
| 820 | Register length, |
| 821 | Register scratch); |
| 822 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 823 | // Initialize fields with filler values. Fields starting at |current_address| |
| 824 | // not including |end_address| are overwritten with the value in |filler|. At |
| 825 | // the end the loop, |current_address| takes the value of |end_address|. |
| 826 | void InitializeFieldsWithFiller(Register current_address, |
| 827 | Register end_address, Register filler); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 828 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | // --------------------------------------------------------------------------- |
| 830 | // Support functions. |
| 831 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 832 | // Machine code version of Map::GetConstructor(). |
| 833 | // |temp| holds |result|'s map when done, and |temp2| its instance type. |
| 834 | void GetMapConstructor(Register result, Register map, Register temp, |
| 835 | Register temp2); |
| 836 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 837 | // Try to get function prototype of a function and puts the value in |
| 838 | // the result register. Checks that the function really is a |
| 839 | // function and jumps to the miss label if the fast checks fail. The |
| 840 | // function register will be untouched; the other registers may be |
| 841 | // clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 842 | void TryGetFunctionPrototype(Register function, Register result, |
| 843 | Register scratch, Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | |
| 845 | // Compare object type for heap object. heap_object contains a non-Smi |
| 846 | // whose object type should be compared with the given type. This both |
| 847 | // sets the flags and leaves the object type in the type_reg register. |
| 848 | // It leaves the map in the map register (unless the type_reg and map register |
| 849 | // are the same register). It leaves the heap object in the heap_object |
| 850 | // register unless the heap_object register is the same register as one of the |
| 851 | // other registers. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | // Type_reg can be no_reg. In that case ip is used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 853 | void CompareObjectType(Register heap_object, |
| 854 | Register map, |
| 855 | Register type_reg, |
| 856 | InstanceType type); |
| 857 | |
| 858 | // Compare instance type in a map. map contains a valid map object whose |
| 859 | // object type should be compared with the given type. This both |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 860 | // sets the flags and leaves the object type in the type_reg register. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 861 | void CompareInstanceType(Register map, |
| 862 | Register type_reg, |
| 863 | InstanceType type); |
| 864 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 865 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 866 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 867 | // Jump to the specified label if it does not. |
| 868 | void CheckFastElements(Register map, |
| 869 | Register scratch, |
| 870 | Label* fail); |
| 871 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 872 | // Check if a map for a JSObject indicates that the object can have both smi |
| 873 | // and HeapObject elements. Jump to the specified label if it does not. |
| 874 | void CheckFastObjectElements(Register map, |
| 875 | Register scratch, |
| 876 | Label* fail); |
| 877 | |
| 878 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 879 | // elements. Jump to the specified label if it does not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 880 | void CheckFastSmiElements(Register map, |
| 881 | Register scratch, |
| 882 | Label* fail); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 883 | |
| 884 | // Check to see if maybe_number can be stored as a double in |
| 885 | // 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] | 886 | // the FastDoubleElements array elements. Otherwise jump to fail. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 887 | void StoreNumberToDoubleElements(Register value_reg, |
| 888 | Register key_reg, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 889 | Register elements_reg, |
| 890 | Register scratch1, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 891 | LowDwVfpRegister double_scratch, |
| 892 | Label* fail, |
| 893 | int elements_offset = 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 894 | |
| 895 | // Compare an object's map with the specified map and its transitioned |
| 896 | // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are |
| 897 | // set with result of map compare. If multiple map compares are required, the |
| 898 | // compare sequences branches to early_success. |
| 899 | void CompareMap(Register obj, |
| 900 | Register scratch, |
| 901 | Handle<Map> map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 902 | Label* early_success); |
| 903 | |
| 904 | // As above, but the map of the object is already loaded into the register |
| 905 | // which is preserved by the code generated. |
| 906 | void CompareMap(Register obj_map, |
| 907 | Handle<Map> map, |
| 908 | Label* early_success); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 909 | |
| 910 | // Check if the map of an object is equal to a specified map and branch to |
| 911 | // label if not. Skip the smi check if not required (object is known to be a |
| 912 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
| 913 | // against maps that are ElementsKind transition maps of the specified map. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 914 | void CheckMap(Register obj, |
| 915 | Register scratch, |
| 916 | Handle<Map> map, |
| 917 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 918 | SmiCheckType smi_check_type); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 919 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 920 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 921 | void CheckMap(Register obj, |
| 922 | Register scratch, |
| 923 | Heap::RootListIndex index, |
| 924 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 925 | SmiCheckType smi_check_type); |
| 926 | |
| 927 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 928 | // Check if the map of an object is equal to a specified weak map and branch |
| 929 | // to a specified target if equal. Skip the smi check if not required |
| 930 | // (object is known to be a heap object) |
| 931 | void DispatchWeakMap(Register obj, Register scratch1, Register scratch2, |
| 932 | Handle<WeakCell> cell, Handle<Code> success, |
| 933 | SmiCheckType smi_check_type); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 934 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 935 | // Compare the given value and the value of weak cell. |
| 936 | void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch); |
| 937 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 938 | void GetWeakValue(Register value, Handle<WeakCell> cell); |
| 939 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 940 | // Load the value of the weak cell in the value register. Branch to the given |
| 941 | // miss label if the weak cell was cleared. |
| 942 | void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 943 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 944 | // Compare the object in a register to a value from the root list. |
| 945 | // Uses the ip register as scratch. |
| 946 | void CompareRoot(Register obj, Heap::RootListIndex index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 947 | void PushRoot(Heap::RootListIndex index) { |
| 948 | LoadRoot(ip, index); |
| 949 | Push(ip); |
| 950 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 951 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 952 | // Compare the object in a register to a value and jump if they are equal. |
| 953 | void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) { |
| 954 | CompareRoot(with, index); |
| 955 | b(eq, if_equal); |
| 956 | } |
| 957 | |
| 958 | // Compare the object in a register to a value and jump if they are not equal. |
| 959 | void JumpIfNotRoot(Register with, Heap::RootListIndex index, |
| 960 | Label* if_not_equal) { |
| 961 | CompareRoot(with, index); |
| 962 | b(ne, if_not_equal); |
| 963 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 964 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 965 | // Load and check the instance type of an object for being a string. |
| 966 | // Loads the type into the second argument register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 967 | // Returns a condition that will be enabled if the object was a string |
| 968 | // and the passed-in condition passed. If the passed-in condition failed |
| 969 | // then flags remain unchanged. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 970 | Condition IsObjectStringType(Register obj, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 971 | Register type, |
| 972 | Condition cond = al) { |
| 973 | ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond); |
| 974 | ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond); |
| 975 | tst(type, Operand(kIsNotStringMask), cond); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 976 | DCHECK_EQ(0u, kStringTag); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 977 | return eq; |
| 978 | } |
| 979 | |
| 980 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 981 | // Picks out an array index from the hash field. |
| 982 | // Register use: |
| 983 | // hash - holds the index's hash. Clobbered. |
| 984 | // index - holds the overwritten index on exit. |
| 985 | void IndexFromHash(Register hash, Register index); |
| 986 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 987 | // Get the number of least significant bits from a register |
| 988 | void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 989 | void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 990 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 991 | // Load the value of a smi object into a double register. |
| 992 | // The register value must be between d0 and d15. |
| 993 | void SmiToDouble(LowDwVfpRegister value, Register smi); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 994 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 995 | // Check if a double can be exactly represented as a signed 32-bit integer. |
| 996 | // Z flag set to one if true. |
| 997 | void TestDoubleIsInt32(DwVfpRegister double_input, |
| 998 | LowDwVfpRegister double_scratch); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 999 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1000 | // Try to convert a double to a signed 32-bit integer. |
| 1001 | // Z flag set to one and result assigned if the conversion is exact. |
| 1002 | void TryDoubleToInt32Exact(Register result, |
| 1003 | DwVfpRegister double_input, |
| 1004 | LowDwVfpRegister double_scratch); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1005 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1006 | // Floor a double and writes the value to the result register. |
| 1007 | // Go to exact if the conversion is exact (to be able to test -0), |
| 1008 | // fall through calling code if an overflow occurred, else go to done. |
| 1009 | // In return, input_high is loaded with high bits of input. |
| 1010 | void TryInt32Floor(Register result, |
| 1011 | DwVfpRegister double_input, |
| 1012 | Register input_high, |
| 1013 | LowDwVfpRegister double_scratch, |
| 1014 | Label* done, |
| 1015 | Label* exact); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1016 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1017 | // Performs a truncating conversion of a floating point number as used by |
| 1018 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it |
| 1019 | // succeeds, otherwise falls through if result is saturated. On return |
| 1020 | // 'result' either holds answer, or is clobbered on fall through. |
| 1021 | // |
| 1022 | // Only public for the test code in test-code-stubs-arm.cc. |
| 1023 | void TryInlineTruncateDoubleToI(Register result, |
| 1024 | DwVfpRegister input, |
| 1025 | Label* done); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1026 | |
| 1027 | // Performs a truncating conversion of a floating point number as used by |
| 1028 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1029 | // Exits with 'result' holding the answer. |
| 1030 | void TruncateDoubleToI(Register result, DwVfpRegister double_input); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1031 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1032 | // Performs a truncating conversion of a heap number as used by |
| 1033 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input' |
| 1034 | // must be different registers. Exits with 'result' holding the answer. |
| 1035 | void TruncateHeapNumberToI(Register result, Register object); |
| 1036 | |
| 1037 | // Converts the smi or heap number in object to an int32 using the rules |
| 1038 | // for ToInt32 as described in ECMAScript 9.5.: the value is truncated |
| 1039 | // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be |
| 1040 | // different registers. |
| 1041 | void TruncateNumberToI(Register object, |
| 1042 | Register result, |
| 1043 | Register heap_number_map, |
| 1044 | Register scratch1, |
| 1045 | Label* not_int32); |
| 1046 | |
| 1047 | // Check whether d16-d31 are available on the CPU. The result is given by the |
| 1048 | // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise. |
| 1049 | void CheckFor32DRegs(Register scratch); |
| 1050 | |
| 1051 | // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double |
| 1052 | // values to location, saving [d0..(d15|d31)]. |
| 1053 | void SaveFPRegs(Register location, Register scratch); |
| 1054 | |
| 1055 | // Does a runtime check for 16/32 FP registers. Either way, pops 32 double |
| 1056 | // values to location, restoring [d0..(d15|d31)]. |
| 1057 | void RestoreFPRegs(Register location, Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1058 | |
| 1059 | // --------------------------------------------------------------------------- |
| 1060 | // Runtime calls |
| 1061 | |
| 1062 | // Call a code stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1063 | void CallStub(CodeStub* stub, |
| 1064 | TypeFeedbackId ast_id = TypeFeedbackId::None(), |
| 1065 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1066 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1067 | // Call a code stub. |
| 1068 | void TailCallStub(CodeStub* stub, Condition cond = al); |
| 1069 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1070 | // Call a runtime routine. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1071 | void CallRuntime(const Runtime::Function* f, |
| 1072 | int num_arguments, |
| 1073 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1074 | void CallRuntimeSaveDoubles(Runtime::FunctionId fid) { |
| 1075 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1076 | CallRuntime(function, function->nargs, kSaveFPRegs); |
| 1077 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1078 | |
| 1079 | // Convenience function: Same as above, but takes the fid instead. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1080 | void CallRuntime(Runtime::FunctionId fid, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1081 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1082 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
| 1083 | CallRuntime(function, function->nargs, save_doubles); |
| 1084 | } |
| 1085 | |
| 1086 | // Convenience function: Same as above, but takes the fid instead. |
| 1087 | void CallRuntime(Runtime::FunctionId fid, int num_arguments, |
| 1088 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 1089 | CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1090 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1091 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1092 | // Convenience function: call an external reference. |
| 1093 | void CallExternalReference(const ExternalReference& ext, |
| 1094 | int num_arguments); |
| 1095 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1096 | // Convenience function: tail call a runtime routine (jump). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1097 | void TailCallRuntime(Runtime::FunctionId fid); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1098 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1099 | int CalculateStackPassedWords(int num_reg_arguments, |
| 1100 | int num_double_arguments); |
| 1101 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1102 | // Before calling a C-function from generated code, align arguments on stack. |
| 1103 | // After aligning the frame, non-register arguments must be stored in |
| 1104 | // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1105 | // are word sized. If double arguments are used, this function assumes that |
| 1106 | // all double arguments are stored before core registers; otherwise the |
| 1107 | // correct alignment of the double values is not guaranteed. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1108 | // Some compilers/platforms require the stack to be aligned when calling |
| 1109 | // C++ code. |
| 1110 | // Needs a scratch register to do some arithmetic. This register will be |
| 1111 | // trashed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1112 | void PrepareCallCFunction(int num_reg_arguments, |
| 1113 | int num_double_registers, |
| 1114 | Register scratch); |
| 1115 | void PrepareCallCFunction(int num_reg_arguments, |
| 1116 | Register scratch); |
| 1117 | |
| 1118 | // There are two ways of passing double arguments on ARM, depending on |
| 1119 | // whether soft or hard floating point ABI is used. These functions |
| 1120 | // abstract parameter passing for the three different ways we call |
| 1121 | // C functions from generated code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1122 | void MovToFloatParameter(DwVfpRegister src); |
| 1123 | void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2); |
| 1124 | void MovToFloatResult(DwVfpRegister src); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1125 | |
| 1126 | // Calls a C function and cleans up the space for arguments allocated |
| 1127 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 1128 | // garbage collection, since that might move the code and invalidate the |
| 1129 | // return address (unless this is somehow accounted for by the called |
| 1130 | // function). |
| 1131 | void CallCFunction(ExternalReference function, int num_arguments); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1132 | void CallCFunction(Register function, int num_arguments); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1133 | void CallCFunction(ExternalReference function, |
| 1134 | int num_reg_arguments, |
| 1135 | int num_double_arguments); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1136 | void CallCFunction(Register function, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1137 | int num_reg_arguments, |
| 1138 | int num_double_arguments); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1139 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1140 | void MovFromFloatParameter(DwVfpRegister dst); |
| 1141 | void MovFromFloatResult(DwVfpRegister dst); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1142 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1143 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1144 | void JumpToExternalReference(const ExternalReference& builtin); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1146 | // Invoke specified builtin JavaScript function. |
| 1147 | void InvokeBuiltin(int native_context_index, InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1148 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1150 | Handle<Object> CodeObject() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1151 | DCHECK(!code_object_.is_null()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1152 | return code_object_; |
| 1153 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1154 | |
| 1155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1156 | // Emit code for a truncating division by a constant. The dividend register is |
| 1157 | // unchanged and ip gets clobbered. Dividend and result must be different. |
| 1158 | void TruncatingDiv(Register result, Register dividend, int32_t divisor); |
| 1159 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1160 | // --------------------------------------------------------------------------- |
| 1161 | // StatsCounter support |
| 1162 | |
| 1163 | void SetCounter(StatsCounter* counter, int value, |
| 1164 | Register scratch1, Register scratch2); |
| 1165 | void IncrementCounter(StatsCounter* counter, int value, |
| 1166 | Register scratch1, Register scratch2); |
| 1167 | void DecrementCounter(StatsCounter* counter, int value, |
| 1168 | Register scratch1, Register scratch2); |
| 1169 | |
| 1170 | |
| 1171 | // --------------------------------------------------------------------------- |
| 1172 | // Debugging |
| 1173 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1174 | // Calls Abort(msg) if the condition cond is not satisfied. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1175 | // Use --debug_code to enable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1176 | void Assert(Condition cond, BailoutReason reason); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1177 | void AssertFastElements(Register elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Like Assert(), but always enabled. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1180 | void Check(Condition cond, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1181 | |
| 1182 | // Print a message to stdout and abort execution. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1183 | void Abort(BailoutReason msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1184 | |
| 1185 | // Verify restrictions about code generated in stubs. |
| 1186 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 1187 | bool generating_stub() { return generating_stub_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1188 | void set_has_frame(bool value) { has_frame_ = value; } |
| 1189 | bool has_frame() { return has_frame_; } |
| 1190 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1191 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1192 | // EABI variant for double arguments in use. |
| 1193 | bool use_eabi_hardfloat() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1194 | #ifdef __arm__ |
| 1195 | return base::OS::ArmUsingHardFloat(); |
| 1196 | #elif USE_EABI_HARDFLOAT |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1197 | return true; |
| 1198 | #else |
| 1199 | return false; |
| 1200 | #endif |
| 1201 | } |
| 1202 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1203 | // --------------------------------------------------------------------------- |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1204 | // Number utilities |
| 1205 | |
| 1206 | // Check whether the value of reg is a power of two and not zero. If not |
| 1207 | // control continues at the label not_power_of_two. If reg is a power of two |
| 1208 | // the register scratch contains the value of (reg - 1) when control falls |
| 1209 | // through. |
| 1210 | void JumpIfNotPowerOfTwoOrZero(Register reg, |
| 1211 | Register scratch, |
| 1212 | Label* not_power_of_two_or_zero); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1213 | // Check whether the value of reg is a power of two and not zero. |
| 1214 | // Control falls through if it is, with scratch containing the mask |
| 1215 | // value (reg - 1). |
| 1216 | // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is |
| 1217 | // zero or negative, or jumps to the 'not_power_of_two' label if the value is |
| 1218 | // strictly positive but not a power of two. |
| 1219 | void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg, |
| 1220 | Register scratch, |
| 1221 | Label* zero_and_neg, |
| 1222 | Label* not_power_of_two); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1223 | |
| 1224 | // --------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1225 | // Smi utilities |
| 1226 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1227 | void SmiTag(Register reg, SBit s = LeaveCC) { |
| 1228 | add(reg, reg, Operand(reg), s); |
| 1229 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1230 | void SmiTag(Register dst, Register src, SBit s = LeaveCC) { |
| 1231 | add(dst, src, Operand(src), s); |
| 1232 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1233 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1234 | // Try to convert int32 to smi. If the value is to large, preserve |
| 1235 | // the original value and jump to not_a_smi. Destroys scratch and |
| 1236 | // sets flags. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1237 | void TrySmiTag(Register reg, Label* not_a_smi) { |
| 1238 | TrySmiTag(reg, reg, not_a_smi); |
| 1239 | } |
| 1240 | void TrySmiTag(Register reg, Register src, Label* not_a_smi) { |
| 1241 | SmiTag(ip, src, SetCC); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1242 | b(vs, not_a_smi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1243 | mov(reg, ip); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1246 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1247 | void SmiUntag(Register reg, SBit s = LeaveCC) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1248 | mov(reg, Operand::SmiUntag(reg), s); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1249 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1250 | void SmiUntag(Register dst, Register src, SBit s = LeaveCC) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1251 | mov(dst, Operand::SmiUntag(src), s); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1252 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1253 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1254 | // Untag the source value into destination and jump if source is a smi. |
| 1255 | // Souce and destination can be the same register. |
| 1256 | void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case); |
| 1257 | |
| 1258 | // Untag the source value into destination and jump if source is not a smi. |
| 1259 | // Souce and destination can be the same register. |
| 1260 | void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case); |
| 1261 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1262 | // Test if the register contains a smi (Z == 0 (eq) if true). |
| 1263 | inline void SmiTst(Register value) { |
| 1264 | tst(value, Operand(kSmiTagMask)); |
| 1265 | } |
| 1266 | inline void NonNegativeSmiTst(Register value) { |
| 1267 | tst(value, Operand(kSmiTagMask | kSmiSignMask)); |
| 1268 | } |
| 1269 | // Jump if the register contains a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1270 | inline void JumpIfSmi(Register value, Label* smi_label) { |
| 1271 | tst(value, Operand(kSmiTagMask)); |
| 1272 | b(eq, smi_label); |
| 1273 | } |
| 1274 | // Jump if either of the registers contain a non-smi. |
| 1275 | inline void JumpIfNotSmi(Register value, Label* not_smi_label) { |
| 1276 | tst(value, Operand(kSmiTagMask)); |
| 1277 | b(ne, not_smi_label); |
| 1278 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1279 | // Jump if either of the registers contain a non-smi. |
| 1280 | void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi); |
| 1281 | // Jump if either of the registers contain a smi. |
| 1282 | void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi); |
| 1283 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1284 | // Abort execution if argument is a smi, enabled via --debug-code. |
| 1285 | void AssertNotSmi(Register object); |
| 1286 | void AssertSmi(Register object); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1287 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1288 | // Abort execution if argument is not a string, enabled via --debug-code. |
| 1289 | void AssertString(Register object); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1291 | // Abort execution if argument is not a name, enabled via --debug-code. |
| 1292 | void AssertName(Register object); |
| 1293 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1294 | // Abort execution if argument is not a JSFunction, enabled via --debug-code. |
| 1295 | void AssertFunction(Register object); |
| 1296 | |
| 1297 | // Abort execution if argument is not a JSBoundFunction, |
| 1298 | // enabled via --debug-code. |
| 1299 | void AssertBoundFunction(Register object); |
| 1300 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1301 | // Abort execution if argument is not undefined or an AllocationSite, enabled |
| 1302 | // via --debug-code. |
| 1303 | void AssertUndefinedOrAllocationSite(Register object, Register scratch); |
| 1304 | |
| 1305 | // Abort execution if reg is not the root value with the given index, |
| 1306 | // enabled via --debug-code. |
| 1307 | void AssertIsRoot(Register reg, Heap::RootListIndex index); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1308 | |
| 1309 | // --------------------------------------------------------------------------- |
| 1310 | // HeapNumber utilities |
| 1311 | |
| 1312 | void JumpIfNotHeapNumber(Register object, |
| 1313 | Register heap_number_map, |
| 1314 | Register scratch, |
| 1315 | Label* on_not_heap_number); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1316 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1317 | // --------------------------------------------------------------------------- |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1318 | // String utilities |
| 1319 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1320 | // Checks if both objects are sequential one-byte strings and jumps to label |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1321 | // if either is not. Assumes that neither object is a smi. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1322 | void JumpIfNonSmisNotBothSequentialOneByteStrings(Register object1, |
| 1323 | Register object2, |
| 1324 | Register scratch1, |
| 1325 | Register scratch2, |
| 1326 | Label* failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1328 | // Checks if both objects are sequential one-byte strings and jumps to label |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1329 | // if either is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1330 | void JumpIfNotBothSequentialOneByteStrings(Register first, Register second, |
| 1331 | Register scratch1, |
| 1332 | Register scratch2, |
| 1333 | Label* not_flat_one_byte_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1334 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | // Checks if both instance types are sequential one-byte strings and jumps to |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1336 | // label if either is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1337 | void JumpIfBothInstanceTypesAreNotSequentialOneByte( |
| 1338 | Register first_object_instance_type, Register second_object_instance_type, |
| 1339 | Register scratch1, Register scratch2, Label* failure); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1340 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1341 | // Check if instance type is sequential one-byte string and jump to label if |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1342 | // it is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1343 | void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch, |
| 1344 | Label* failure); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1345 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1346 | void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name); |
| 1347 | |
| 1348 | void EmitSeqStringSetCharCheck(Register string, |
| 1349 | Register index, |
| 1350 | Register value, |
| 1351 | uint32_t encoding_mask); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1352 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1353 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1354 | void ClampUint8(Register output_reg, Register input_reg); |
| 1355 | |
| 1356 | void ClampDoubleToUint8(Register result_reg, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1357 | DwVfpRegister input_reg, |
| 1358 | LowDwVfpRegister double_scratch); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1359 | |
| 1360 | |
| 1361 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1362 | void EnumLength(Register dst, Register map); |
| 1363 | void NumberOfOwnDescriptors(Register dst, Register map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1364 | void LoadAccessor(Register dst, Register holder, int accessor_index, |
| 1365 | AccessorComponent accessor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1366 | |
| 1367 | template<typename Field> |
| 1368 | void DecodeField(Register dst, Register src) { |
| 1369 | Ubfx(dst, src, Field::kShift, Field::kSize); |
| 1370 | } |
| 1371 | |
| 1372 | template<typename Field> |
| 1373 | void DecodeField(Register reg) { |
| 1374 | DecodeField<Field>(reg, reg); |
| 1375 | } |
| 1376 | |
| 1377 | template<typename Field> |
| 1378 | void DecodeFieldToSmi(Register dst, Register src) { |
| 1379 | static const int shift = Field::kShift; |
| 1380 | static const int mask = Field::kMask >> shift << kSmiTagSize; |
| 1381 | STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0); |
| 1382 | STATIC_ASSERT(kSmiTag == 0); |
| 1383 | if (shift < kSmiTagSize) { |
| 1384 | mov(dst, Operand(src, LSL, kSmiTagSize - shift)); |
| 1385 | and_(dst, dst, Operand(mask)); |
| 1386 | } else if (shift > kSmiTagSize) { |
| 1387 | mov(dst, Operand(src, LSR, shift - kSmiTagSize)); |
| 1388 | and_(dst, dst, Operand(mask)); |
| 1389 | } else { |
| 1390 | and_(dst, src, Operand(mask)); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | template<typename Field> |
| 1395 | void DecodeFieldToSmi(Register reg) { |
| 1396 | DecodeField<Field>(reg, reg); |
| 1397 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1398 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1399 | // Load the type feedback vector from a JavaScript frame. |
| 1400 | void EmitLoadTypeFeedbackVector(Register vector); |
| 1401 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1402 | // Activation support. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1403 | void EnterFrame(StackFrame::Type type, |
| 1404 | bool load_constant_pool_pointer_reg = false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1405 | // Returns the pc offset at which the frame ends. |
| 1406 | int LeaveFrame(StackFrame::Type type); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1407 | |
| 1408 | // Expects object in r0 and returns map with validated enum cache |
| 1409 | // in r0. Assumes that any other register can be used as a scratch. |
| 1410 | void CheckEnumCache(Register null_value, Label* call_runtime); |
| 1411 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1412 | // AllocationMemento support. Arrays may have an associated |
| 1413 | // AllocationMemento object that can be checked for in order to pretransition |
| 1414 | // to another type. |
| 1415 | // On entry, receiver_reg should point to the array object. |
| 1416 | // scratch_reg gets clobbered. |
| 1417 | // If allocation info is present, condition flags are set to eq. |
| 1418 | void TestJSArrayForAllocationMemento(Register receiver_reg, |
| 1419 | Register scratch_reg, |
| 1420 | Label* no_memento_found); |
| 1421 | |
| 1422 | void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, |
| 1423 | Register scratch_reg, |
| 1424 | Label* memento_found) { |
| 1425 | Label no_memento_found; |
| 1426 | TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, |
| 1427 | &no_memento_found); |
| 1428 | b(eq, memento_found); |
| 1429 | bind(&no_memento_found); |
| 1430 | } |
| 1431 | |
| 1432 | // Jumps to found label if a prototype map has dictionary elements. |
| 1433 | void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0, |
| 1434 | Register scratch1, Label* found); |
| 1435 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1436 | // Loads the constant pool pointer (pp) register. |
| 1437 | void LoadConstantPoolPointerRegisterFromCodeTargetAddress( |
| 1438 | Register code_target_address); |
| 1439 | void LoadConstantPoolPointerRegister(); |
| 1440 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1441 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1442 | void CallCFunctionHelper(Register function, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1443 | int num_reg_arguments, |
| 1444 | int num_double_arguments); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1445 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1446 | void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1447 | |
| 1448 | // Helper functions for generating invokes. |
| 1449 | void InvokePrologue(const ParameterCount& expected, |
| 1450 | const ParameterCount& actual, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1451 | Label* done, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1452 | bool* definitely_mismatches, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1453 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1454 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1455 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1456 | void InitializeNewString(Register string, |
| 1457 | Register length, |
| 1458 | Heap::RootListIndex map_index, |
| 1459 | Register scratch1, |
| 1460 | Register scratch2); |
| 1461 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1462 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 1463 | void InNewSpace(Register object, |
| 1464 | Register scratch, |
| 1465 | Condition cond, // eq for new space, ne otherwise. |
| 1466 | Label* branch); |
| 1467 | |
| 1468 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1469 | // bitmap register points at the word with the mark bits and the mask |
| 1470 | // the position of the first bit. Leaves addr_reg unchanged. |
| 1471 | inline void GetMarkBits(Register addr_reg, |
| 1472 | Register bitmap_reg, |
| 1473 | Register mask_reg); |
| 1474 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1475 | // Compute memory operands for safepoint stack slots. |
| 1476 | static int SafepointRegisterStackIndex(int reg_code); |
| 1477 | MemOperand SafepointRegisterSlot(Register reg); |
| 1478 | MemOperand SafepointRegistersAndDoublesSlot(Register reg); |
| 1479 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1480 | bool generating_stub_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1481 | bool has_frame_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1482 | // This handle will be patched with the code object on installation. |
| 1483 | Handle<Object> code_object_; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1484 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1485 | // Needs access to SafepointRegisterStackIndex for compiled frame |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1486 | // traversal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1487 | friend class StandardFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1488 | }; |
| 1489 | |
| 1490 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1492 | // debugging and other types of instrumentation. When using the code patcher |
| 1493 | // the exact number of bytes specified must be emitted. It is not legal to emit |
| 1494 | // relocation information. If any of these constraints are violated it causes |
| 1495 | // an assertion to fail. |
| 1496 | class CodePatcher { |
| 1497 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1498 | enum FlushICache { |
| 1499 | FLUSH, |
| 1500 | DONT_FLUSH |
| 1501 | }; |
| 1502 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1503 | CodePatcher(Isolate* isolate, byte* address, int instructions, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1504 | FlushICache flush_cache = FLUSH); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1505 | ~CodePatcher(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1506 | |
| 1507 | // Macro assembler to emit code. |
| 1508 | MacroAssembler* masm() { return &masm_; } |
| 1509 | |
| 1510 | // Emit an instruction directly. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1511 | void Emit(Instr instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1512 | |
| 1513 | // Emit an address directly. |
| 1514 | void Emit(Address addr); |
| 1515 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1516 | // Emit the condition part of an instruction leaving the rest of the current |
| 1517 | // instruction unchanged. |
| 1518 | void EmitCondition(Condition cond); |
| 1519 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1520 | private: |
| 1521 | byte* address_; // The address of the code being patched. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1522 | int size_; // Number of bytes of the expected patch size. |
| 1523 | MacroAssembler masm_; // Macro assembler used to generate the code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1524 | FlushICache flush_cache_; // Whether to flush the I cache after patching. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1525 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1526 | |
| 1527 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1528 | // ----------------------------------------------------------------------------- |
| 1529 | // Static helper functions. |
| 1530 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1531 | inline MemOperand ContextMemOperand(Register context, int index = 0) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1532 | return MemOperand(context, Context::SlotOffset(index)); |
| 1533 | } |
| 1534 | |
| 1535 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1536 | inline MemOperand NativeContextMemOperand() { |
| 1537 | return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1541 | #ifdef GENERATED_CODE_COVERAGE |
| 1542 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1543 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1544 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1545 | #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> |
| 1546 | #else |
| 1547 | #define ACCESS_MASM(masm) masm-> |
| 1548 | #endif |
| 1549 | |
| 1550 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1551 | } // namespace internal |
| 1552 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1553 | |
| 1554 | #endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_ |