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