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_X64_MACRO_ASSEMBLER_X64_H_ |
| 6 | #define V8_X64_MACRO_ASSEMBLER_X64_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" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/base/flags.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/frames.h" |
| 12 | #include "src/globals.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/x64/frames-x64.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 18 | // Give alias names to registers for calling conventions. |
| 19 | const Register kReturnRegister0 = {Register::kCode_rax}; |
| 20 | const Register kReturnRegister1 = {Register::kCode_rdx}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 21 | const Register kReturnRegister2 = {Register::kCode_r8}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | const Register kJSFunctionRegister = {Register::kCode_rdi}; |
| 23 | const Register kContextRegister = {Register::kCode_rsi}; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 24 | const Register kAllocateSizeRegister = {Register::kCode_rdx}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 25 | const Register kInterpreterAccumulatorRegister = {Register::kCode_rax}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r12}; |
| 27 | const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r14}; |
| 28 | const Register kInterpreterDispatchTableRegister = {Register::kCode_r15}; |
| 29 | const Register kJavaScriptCallArgCountRegister = {Register::kCode_rax}; |
| 30 | const Register kJavaScriptCallNewTargetRegister = {Register::kCode_rdx}; |
| 31 | const Register kRuntimeCallFunctionRegister = {Register::kCode_rbx}; |
| 32 | const Register kRuntimeCallArgCountRegister = {Register::kCode_rax}; |
| 33 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | // Default scratch register used by MacroAssembler (and other code that needs |
| 35 | // a spare register). The register isn't callee save, and not used by the |
| 36 | // function calling convention. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 37 | const Register kScratchRegister = { 10 }; // r10. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 38 | const Register kRootRegister = { 13 }; // r13 (callee save). |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 39 | // Actual value of root register is offset from the root array's start |
| 40 | // to take advantage of negitive 8-bit displacement values. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 41 | const int kRootRegisterBias = 128; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 43 | // Convenience for platform-independent signatures. |
| 44 | typedef Operand MemOperand; |
| 45 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 46 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 47 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 48 | enum PointersToHereCheck { |
| 49 | kPointersToHereMaybeInteresting, |
| 50 | kPointersToHereAreAlwaysInteresting |
| 51 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 52 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | enum class SmiOperationConstraint { |
| 54 | kPreserveSourceRegister = 1 << 0, |
| 55 | kBailoutOnNoOverflow = 1 << 1, |
| 56 | kBailoutOnOverflow = 1 << 2 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 59 | enum class ReturnAddressState { kOnStack, kNotOnStack }; |
| 60 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 61 | typedef base::Flags<SmiOperationConstraint> SmiOperationConstraints; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 63 | DEFINE_OPERATORS_FOR_FLAGS(SmiOperationConstraints) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | |
| 65 | #ifdef DEBUG |
| 66 | bool AreAliased(Register reg1, |
| 67 | Register reg2, |
| 68 | Register reg3 = no_reg, |
| 69 | Register reg4 = no_reg, |
| 70 | Register reg5 = no_reg, |
| 71 | Register reg6 = no_reg, |
| 72 | Register reg7 = no_reg, |
| 73 | Register reg8 = no_reg); |
| 74 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 75 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 76 | // Forward declaration. |
| 77 | class JumpTarget; |
| 78 | |
| 79 | struct SmiIndex { |
| 80 | SmiIndex(Register index_register, ScaleFactor scale) |
| 81 | : reg(index_register), |
| 82 | scale(scale) {} |
| 83 | Register reg; |
| 84 | ScaleFactor scale; |
| 85 | }; |
| 86 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 87 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | // MacroAssembler implements a collection of frequently used macros. |
| 89 | class MacroAssembler: public Assembler { |
| 90 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | MacroAssembler(Isolate* isolate, void* buffer, int size, |
| 92 | CodeObjectRequired create_code_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 94 | // Prevent the use of the RootArray during the lifetime of this |
| 95 | // scope object. |
| 96 | class NoRootArrayScope BASE_EMBEDDED { |
| 97 | public: |
| 98 | explicit NoRootArrayScope(MacroAssembler* assembler) |
| 99 | : variable_(&assembler->root_array_available_), |
| 100 | old_value_(assembler->root_array_available_) { |
| 101 | assembler->root_array_available_ = false; |
| 102 | } |
| 103 | ~NoRootArrayScope() { |
| 104 | *variable_ = old_value_; |
| 105 | } |
| 106 | private: |
| 107 | bool* variable_; |
| 108 | bool old_value_; |
| 109 | }; |
| 110 | |
| 111 | // Operand pointing to an external reference. |
| 112 | // May emit code to set up the scratch register. The operand is |
| 113 | // only guaranteed to be correct as long as the scratch register |
| 114 | // isn't changed. |
| 115 | // If the operand is used more than once, use a scratch register |
| 116 | // that is guaranteed not to be clobbered. |
| 117 | Operand ExternalOperand(ExternalReference reference, |
| 118 | Register scratch = kScratchRegister); |
| 119 | // Loads and stores the value of an external reference. |
| 120 | // Special case code for load and store to take advantage of |
| 121 | // load_rax/store_rax if possible/necessary. |
| 122 | // For other operations, just use: |
| 123 | // Operand operand = ExternalOperand(extref); |
| 124 | // operation(operand, ..); |
| 125 | void Load(Register destination, ExternalReference source); |
| 126 | void Store(ExternalReference destination, Register source); |
| 127 | // Loads the address of the external reference into the destination |
| 128 | // register. |
| 129 | void LoadAddress(Register destination, ExternalReference source); |
| 130 | // Returns the size of the code generated by LoadAddress. |
| 131 | // Used by CallSize(ExternalReference) to find the size of a call. |
| 132 | int LoadAddressSize(ExternalReference source); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | // Pushes the address of the external reference onto the stack. |
| 134 | void PushAddress(ExternalReference source); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 135 | |
| 136 | // Operations on roots in the root-array. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 137 | void LoadRoot(Register destination, Heap::RootListIndex index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 138 | void LoadRoot(const Operand& destination, Heap::RootListIndex index) { |
| 139 | LoadRoot(kScratchRegister, index); |
| 140 | movp(destination, kScratchRegister); |
| 141 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 142 | void StoreRoot(Register source, Heap::RootListIndex index); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 143 | // Load a root value where the index (or part of it) is variable. |
| 144 | // The variable_offset register is added to the fixed_offset value |
| 145 | // to get the index into the root-array. |
| 146 | void LoadRootIndexed(Register destination, |
| 147 | Register variable_offset, |
| 148 | int fixed_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 149 | void CompareRoot(Register with, Heap::RootListIndex index); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 150 | void CompareRoot(const Operand& with, Heap::RootListIndex index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 151 | void PushRoot(Heap::RootListIndex index); |
| 152 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | // Compare the object in a register to a value and jump if they are equal. |
| 154 | void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal, |
| 155 | Label::Distance if_equal_distance = Label::kFar) { |
| 156 | CompareRoot(with, index); |
| 157 | j(equal, if_equal, if_equal_distance); |
| 158 | } |
| 159 | void JumpIfRoot(const Operand& with, Heap::RootListIndex index, |
| 160 | Label* if_equal, |
| 161 | Label::Distance if_equal_distance = Label::kFar) { |
| 162 | CompareRoot(with, index); |
| 163 | j(equal, if_equal, if_equal_distance); |
| 164 | } |
| 165 | |
| 166 | // Compare the object in a register to a value and jump if they are not equal. |
| 167 | void JumpIfNotRoot(Register with, Heap::RootListIndex index, |
| 168 | Label* if_not_equal, |
| 169 | Label::Distance if_not_equal_distance = Label::kFar) { |
| 170 | CompareRoot(with, index); |
| 171 | j(not_equal, if_not_equal, if_not_equal_distance); |
| 172 | } |
| 173 | void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index, |
| 174 | Label* if_not_equal, |
| 175 | Label::Distance if_not_equal_distance = Label::kFar) { |
| 176 | CompareRoot(with, index); |
| 177 | j(not_equal, if_not_equal, if_not_equal_distance); |
| 178 | } |
| 179 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 180 | // These functions do not arrange the registers in any particular order so |
| 181 | // they are not useful for calls that can cause a GC. The caller can |
| 182 | // exclude up to 3 registers that do not need to be saved and restored. |
| 183 | void PushCallerSaved(SaveFPRegsMode fp_mode, |
| 184 | Register exclusion1 = no_reg, |
| 185 | Register exclusion2 = no_reg, |
| 186 | Register exclusion3 = no_reg); |
| 187 | void PopCallerSaved(SaveFPRegsMode fp_mode, |
| 188 | Register exclusion1 = no_reg, |
| 189 | Register exclusion2 = no_reg, |
| 190 | Register exclusion3 = no_reg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 191 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 192 | // --------------------------------------------------------------------------- |
| 193 | // GC Support |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 194 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 195 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 196 | enum RememberedSetFinalAction { |
| 197 | kReturnAtEnd, |
| 198 | kFallThroughAtEnd |
| 199 | }; |
| 200 | |
| 201 | // Record in the remembered set the fact that we have a pointer to new space |
| 202 | // at the address pointed to by the addr register. Only works if addr is not |
| 203 | // in new space. |
| 204 | void RememberedSetHelper(Register object, // Used for debug code. |
| 205 | Register addr, |
| 206 | Register scratch, |
| 207 | SaveFPRegsMode save_fp, |
| 208 | RememberedSetFinalAction and_then); |
| 209 | |
| 210 | void CheckPageFlag(Register object, |
| 211 | Register scratch, |
| 212 | int mask, |
| 213 | Condition cc, |
| 214 | Label* condition_met, |
| 215 | Label::Distance condition_met_distance = Label::kFar); |
| 216 | |
| 217 | // Check if object is in new space. Jumps if the object is not in new space. |
| 218 | // The register scratch can be object itself, but scratch will be clobbered. |
| 219 | void JumpIfNotInNewSpace(Register object, |
| 220 | Register scratch, |
| 221 | Label* branch, |
| 222 | Label::Distance distance = Label::kFar) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 223 | InNewSpace(object, scratch, zero, branch, distance); |
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, |
| 231 | Label::Distance distance = Label::kFar) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 232 | InNewSpace(object, scratch, not_zero, branch, distance); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // Check if an object has the black incremental marking color. Also uses rcx! |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 236 | void JumpIfBlack(Register object, Register bitmap_scratch, |
| 237 | Register mask_scratch, Label* on_black, |
| 238 | Label::Distance on_black_distance); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 240 | // Checks the color of an object. If the object is white we jump to the |
| 241 | // incremental marker. |
| 242 | void JumpIfWhite(Register value, Register scratch1, Register scratch2, |
| 243 | Label* value_is_white, Label::Distance distance); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 244 | |
| 245 | // Notify the garbage collector that we wrote a pointer into an object. |
| 246 | // |object| is the object being stored into, |value| is the object being |
| 247 | // stored. value and scratch registers are clobbered by the operation. |
| 248 | // The offset is the offset from the start of the object, not the offset from |
| 249 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 250 | void RecordWriteField( |
| 251 | Register object, |
| 252 | int offset, |
| 253 | Register value, |
| 254 | Register scratch, |
| 255 | SaveFPRegsMode save_fp, |
| 256 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 257 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 258 | PointersToHereCheck pointers_to_here_check_for_value = |
| 259 | kPointersToHereMaybeInteresting); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 260 | |
| 261 | // As above, but the offset has the tag presubtracted. For use with |
| 262 | // Operand(reg, off). |
| 263 | void RecordWriteContextSlot( |
| 264 | Register context, |
| 265 | int offset, |
| 266 | Register value, |
| 267 | Register scratch, |
| 268 | SaveFPRegsMode save_fp, |
| 269 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 270 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 271 | PointersToHereCheck pointers_to_here_check_for_value = |
| 272 | kPointersToHereMaybeInteresting) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 273 | RecordWriteField(context, |
| 274 | offset + kHeapObjectTag, |
| 275 | value, |
| 276 | scratch, |
| 277 | save_fp, |
| 278 | remembered_set_action, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | smi_check, |
| 280 | pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | // Notify the garbage collector that we wrote a pointer into a fixed array. |
| 284 | // |array| is the array being stored into, |value| is the |
| 285 | // object being stored. |index| is the array index represented as a non-smi. |
| 286 | // All registers are clobbered by the operation RecordWriteArray |
| 287 | // filters out smis so it does not update the write barrier if the |
| 288 | // value is a smi. |
| 289 | void RecordWriteArray( |
| 290 | Register array, |
| 291 | Register value, |
| 292 | Register index, |
| 293 | SaveFPRegsMode save_fp, |
| 294 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 295 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 296 | PointersToHereCheck pointers_to_here_check_for_value = |
| 297 | kPointersToHereMaybeInteresting); |
| 298 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 299 | // Notify the garbage collector that we wrote a code entry into a |
| 300 | // JSFunction. Only scratch is clobbered by the operation. |
| 301 | void RecordWriteCodeEntryField(Register js_function, Register code_entry, |
| 302 | Register scratch); |
| 303 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 304 | void RecordWriteForMap( |
| 305 | Register object, |
| 306 | Register map, |
| 307 | Register dst, |
| 308 | SaveFPRegsMode save_fp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 309 | |
| 310 | // For page containing |object| mark region covering |address| |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 311 | // dirty. |object| is the object being stored into, |value| is the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 312 | // object being stored. The address and value registers are clobbered by the |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 313 | // operation. RecordWrite filters out smis so it does not update |
| 314 | // the write barrier if the value is a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 315 | void RecordWrite( |
| 316 | Register object, |
| 317 | Register address, |
| 318 | Register value, |
| 319 | SaveFPRegsMode save_fp, |
| 320 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 322 | PointersToHereCheck pointers_to_here_check_for_value = |
| 323 | kPointersToHereMaybeInteresting); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 324 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 325 | // --------------------------------------------------------------------------- |
| 326 | // Debugger Support |
| 327 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 328 | void DebugBreak(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 329 | |
| 330 | // Generates function and stub prologue code. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 331 | void StubPrologue(StackFrame::Type type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | void Prologue(bool code_pre_aging); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 333 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 334 | // Enter specific kind of exit frame; either in normal or |
| 335 | // debug mode. Expects the number of arguments in register rax and |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 336 | // sets up the number of arguments in register rdi and the pointer |
| 337 | // to the first argument in register rsi. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 338 | // |
| 339 | // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack |
| 340 | // accessible via StackSpaceOperand. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 341 | void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 343 | // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize |
| 344 | // memory (not GCed) on the stack accessible via StackSpaceOperand. |
| 345 | void EnterApiExitFrame(int arg_stack_space); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 346 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 347 | // Leave the current exit frame. Expects/provides the return value in |
| 348 | // register rax:rdx (untouched) and the pointer to the first |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 349 | // argument in register rsi (if pop_arguments == true). |
| 350 | void LeaveExitFrame(bool save_doubles = false, bool pop_arguments = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 351 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 352 | // Leave the current exit frame. Expects/provides the return value in |
| 353 | // register rax (untouched). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 354 | void LeaveApiExitFrame(bool restore_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 355 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 356 | // Push and pop the registers that can hold pointers. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 357 | void PushSafepointRegisters() { Pushad(); } |
| 358 | void PopSafepointRegisters() { Popad(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 359 | // Store the value in register src in the safepoint register stack |
| 360 | // slot for register dst. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 361 | void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 362 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
| 363 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 364 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 365 | void InitializeRootRegister() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 366 | ExternalReference roots_array_start = |
| 367 | ExternalReference::roots_array_start(isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | Move(kRootRegister, roots_array_start); |
| 369 | addp(kRootRegister, Immediate(kRootRegisterBias)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 370 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 371 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | // --------------------------------------------------------------------------- |
| 373 | // JavaScript invokes |
| 374 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 375 | // Removes current frame and its arguments from the stack preserving |
| 376 | // the arguments and a return address pushed to the stack for the next call. |
| 377 | // |ra_state| defines whether return address is already pushed to stack or |
| 378 | // not. Both |callee_args_count| and |caller_args_count_reg| do not include |
| 379 | // receiver. |callee_args_count| is not modified, |caller_args_count_reg| |
| 380 | // is trashed. |
| 381 | void PrepareForTailCall(const ParameterCount& callee_args_count, |
| 382 | Register caller_args_count_reg, Register scratch0, |
| 383 | Register scratch1, ReturnAddressState ra_state); |
| 384 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 386 | void InvokeFunctionCode(Register function, Register new_target, |
| 387 | const ParameterCount& expected, |
| 388 | const ParameterCount& actual, InvokeFlag flag, |
| 389 | const CallWrapper& call_wrapper); |
| 390 | |
| 391 | void FloodFunctionIfStepping(Register fun, Register new_target, |
| 392 | const ParameterCount& expected, |
| 393 | const ParameterCount& actual); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 394 | |
| 395 | // Invoke the JavaScript function in the given register. Changes the |
| 396 | // current context to the context in the function before invoking. |
| 397 | void InvokeFunction(Register function, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 398 | Register new_target, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 399 | const ParameterCount& actual, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 400 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 402 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | void InvokeFunction(Register function, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | Register new_target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 405 | const ParameterCount& expected, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 406 | const ParameterCount& actual, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 407 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | const CallWrapper& call_wrapper); |
| 409 | |
| 410 | void InvokeFunction(Handle<JSFunction> function, |
| 411 | const ParameterCount& expected, |
| 412 | const ParameterCount& actual, |
| 413 | InvokeFlag flag, |
| 414 | const CallWrapper& call_wrapper); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 415 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 416 | // --------------------------------------------------------------------------- |
| 417 | // Smi tagging, untagging and operations on tagged smis. |
| 418 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | // Support for constant splitting. |
| 420 | bool IsUnsafeInt(const int32_t x); |
| 421 | void SafeMove(Register dst, Smi* src); |
| 422 | void SafePush(Smi* src); |
| 423 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | // Conversions between tagged smi values and non-tagged integer values. |
| 425 | |
| 426 | // Tag an integer value. The result must be known to be a valid smi value. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 427 | // Only uses the low 32 bits of the src register. Sets the N and Z flags |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 428 | // based on the value of the resulting smi. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 429 | void Integer32ToSmi(Register dst, Register src); |
| 430 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 431 | // Stores an integer32 value into a memory field that already holds a smi. |
| 432 | void Integer32ToSmiField(const Operand& dst, Register src); |
| 433 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 434 | // Adds constant to src and tags the result as a smi. |
| 435 | // Result must be a valid smi. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 436 | void Integer64PlusConstantToSmi(Register dst, Register src, int constant); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | |
| 438 | // Convert smi to 32-bit integer. I.e., not sign extended into |
| 439 | // high 32 bits of destination. |
| 440 | void SmiToInteger32(Register dst, Register src); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 441 | void SmiToInteger32(Register dst, const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 442 | |
| 443 | // Convert smi to 64-bit integer (sign extended if necessary). |
| 444 | void SmiToInteger64(Register dst, Register src); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 445 | void SmiToInteger64(Register dst, const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 446 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 447 | // Convert smi to double. |
| 448 | void SmiToDouble(XMMRegister dst, Register src) { |
| 449 | SmiToInteger32(kScratchRegister, src); |
| 450 | Cvtlsi2sd(dst, kScratchRegister); |
| 451 | } |
| 452 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | // Multiply a positive smi's integer value by a power of two. |
| 454 | // Provides result as 64-bit integer value. |
| 455 | void PositiveSmiTimesPowerOfTwoToInteger64(Register dst, |
| 456 | Register src, |
| 457 | int power); |
| 458 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 459 | // Divide a positive smi's integer value by a power of two. |
| 460 | // Provides result as 32-bit integer value. |
| 461 | void PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 462 | Register src, |
| 463 | int power); |
| 464 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 465 | // Perform the logical or of two smi values and return a smi value. |
| 466 | // If either argument is not a smi, jump to on_not_smis and retain |
| 467 | // the original values of source registers. The destination register |
| 468 | // may be changed if it's not one of the source registers. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 469 | void SmiOrIfSmis(Register dst, |
| 470 | Register src1, |
| 471 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 472 | Label* on_not_smis, |
| 473 | Label::Distance near_jump = Label::kFar); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 474 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 475 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 476 | // Simple comparison of smis. Both sides must be known smis to use these, |
| 477 | // otherwise use Cmp. |
| 478 | void SmiCompare(Register smi1, Register smi2); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 479 | void SmiCompare(Register dst, Smi* src); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 480 | void SmiCompare(Register dst, const Operand& src); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 481 | void SmiCompare(const Operand& dst, Register src); |
| 482 | void SmiCompare(const Operand& dst, Smi* src); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 483 | // Compare the int32 in src register to the value of the smi stored at dst. |
| 484 | void SmiCompareInteger32(const Operand& dst, Register src); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 485 | // Sets sign and zero flags depending on value of smi in register. |
| 486 | void SmiTest(Register src); |
| 487 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | // Functions performing a check on a known or potential smi. Returns |
| 489 | // a condition that is satisfied if the check is successful. |
| 490 | |
| 491 | // Is the value a tagged smi. |
| 492 | Condition CheckSmi(Register src); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 493 | Condition CheckSmi(const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 494 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 495 | // Is the value a non-negative tagged smi. |
| 496 | Condition CheckNonNegativeSmi(Register src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 498 | // Are both values tagged smis. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | Condition CheckBothSmi(Register first, Register second); |
| 500 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 501 | // Are both values non-negative tagged smis. |
| 502 | Condition CheckBothNonNegativeSmi(Register first, Register second); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 503 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 504 | // Are either value a tagged smi. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 505 | Condition CheckEitherSmi(Register first, |
| 506 | Register second, |
| 507 | Register scratch = kScratchRegister); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 508 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 509 | // Checks whether an 32-bit integer value is a valid for conversion |
| 510 | // to a smi. |
| 511 | Condition CheckInteger32ValidSmiValue(Register src); |
| 512 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 513 | // Checks whether an 32-bit unsigned integer value is a valid for |
| 514 | // conversion to a smi. |
| 515 | Condition CheckUInteger32ValidSmiValue(Register src); |
| 516 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 517 | // Check whether src is a Smi, and set dst to zero if it is a smi, |
| 518 | // and to one if it isn't. |
| 519 | void CheckSmiToIndicator(Register dst, Register src); |
| 520 | void CheckSmiToIndicator(Register dst, const Operand& src); |
| 521 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | // Test-and-jump functions. Typically combines a check function |
| 523 | // above with a conditional jump. |
| 524 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 525 | // Jump if the value can be represented by a smi. |
| 526 | void JumpIfValidSmiValue(Register src, Label* on_valid, |
| 527 | Label::Distance near_jump = Label::kFar); |
| 528 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | // Jump if the value cannot be represented by a smi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 530 | void JumpIfNotValidSmiValue(Register src, Label* on_invalid, |
| 531 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | // Jump if the unsigned integer value can be represented by a smi. |
| 534 | void JumpIfUIntValidSmiValue(Register src, Label* on_valid, |
| 535 | Label::Distance near_jump = Label::kFar); |
| 536 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 537 | // Jump if the unsigned integer value cannot be represented by a smi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 538 | void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid, |
| 539 | Label::Distance near_jump = Label::kFar); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 540 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 541 | // Jump to label if the value is a tagged smi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 542 | void JumpIfSmi(Register src, |
| 543 | Label* on_smi, |
| 544 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | |
| 546 | // Jump to label if the value is not a tagged smi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 547 | void JumpIfNotSmi(Register src, |
| 548 | Label* on_not_smi, |
| 549 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 551 | // Jump to label if the value is not a non-negative tagged smi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 552 | void JumpUnlessNonNegativeSmi(Register src, |
| 553 | Label* on_not_smi, |
| 554 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 556 | // Jump to label if the value, which must be a tagged smi, has value equal |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | // to the constant. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 558 | void JumpIfSmiEqualsConstant(Register src, |
| 559 | Smi* constant, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 560 | Label* on_equals, |
| 561 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 562 | |
| 563 | // Jump if either or both register are not smi values. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 564 | void JumpIfNotBothSmi(Register src1, |
| 565 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 566 | Label* on_not_both_smi, |
| 567 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 569 | // Jump if either or both register are not non-negative smi values. |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 570 | void JumpUnlessBothNonNegativeSmi(Register src1, Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 571 | Label* on_not_both_smi, |
| 572 | Label::Distance near_jump = Label::kFar); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 573 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | // Operations on tagged smi values. |
| 575 | |
| 576 | // Smis represent a subset of integers. The subset is always equivalent to |
| 577 | // a two's complement interpretation of a fixed number of bits. |
| 578 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 579 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 580 | // No overflow testing on the result is done. |
| 581 | void SmiAddConstant(Register dst, Register src, Smi* constant); |
| 582 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 583 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 584 | // No overflow testing on the result is done. |
| 585 | void SmiAddConstant(const Operand& dst, Smi* constant); |
| 586 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | // Add an integer constant to a tagged smi, giving a tagged smi as result, |
| 588 | // or jumping to a label if the result cannot be represented by a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 589 | void SmiAddConstant(Register dst, Register src, Smi* constant, |
| 590 | SmiOperationConstraints constraints, Label* bailout_label, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 591 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | |
| 593 | // Subtract an integer constant from a tagged smi, giving a tagged smi as |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 594 | // result. No testing on the result is done. Sets the N and Z flags |
| 595 | // based on the value of the resulting integer. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 596 | void SmiSubConstant(Register dst, Register src, Smi* constant); |
| 597 | |
| 598 | // Subtract an integer constant from a tagged smi, giving a tagged smi as |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 599 | // result, or jumping to a label if the result cannot be represented by a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 600 | void SmiSubConstant(Register dst, Register src, Smi* constant, |
| 601 | SmiOperationConstraints constraints, Label* bailout_label, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 602 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 603 | |
| 604 | // Negating a smi can give a negative zero or too large positive value. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 605 | // NOTICE: This operation jumps on success, not failure! |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | void SmiNeg(Register dst, |
| 607 | Register src, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 608 | Label* on_smi_result, |
| 609 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | |
| 611 | // Adds smi values and return the result as a smi. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 612 | // If dst is src1, then src1 will be destroyed if the operation is |
| 613 | // successful, otherwise kept intact. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 614 | void SmiAdd(Register dst, |
| 615 | Register src1, |
| 616 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 617 | Label* on_not_smi_result, |
| 618 | Label::Distance near_jump = Label::kFar); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 619 | void SmiAdd(Register dst, |
| 620 | Register src1, |
| 621 | const Operand& src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 622 | Label* on_not_smi_result, |
| 623 | Label::Distance near_jump = Label::kFar); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 624 | |
| 625 | void SmiAdd(Register dst, |
| 626 | Register src1, |
| 627 | Register src2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | |
| 629 | // Subtracts smi values and return the result as a smi. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 630 | // If dst is src1, then src1 will be destroyed if the operation is |
| 631 | // successful, otherwise kept intact. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | void SmiSub(Register dst, |
| 633 | Register src1, |
| 634 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 635 | Label* on_not_smi_result, |
| 636 | Label::Distance near_jump = Label::kFar); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | void SmiSub(Register dst, |
| 638 | Register src1, |
| 639 | const Operand& src2, |
| 640 | Label* on_not_smi_result, |
| 641 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 643 | void SmiSub(Register dst, |
| 644 | Register src1, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 645 | Register src2); |
| 646 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 647 | void SmiSub(Register dst, |
| 648 | Register src1, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 649 | const Operand& src2); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 650 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | // Multiplies smi values and return the result as a smi, |
| 652 | // if possible. |
| 653 | // If dst is src1, then src1 will be destroyed, even if |
| 654 | // the operation is unsuccessful. |
| 655 | void SmiMul(Register dst, |
| 656 | Register src1, |
| 657 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 658 | Label* on_not_smi_result, |
| 659 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 660 | |
| 661 | // Divides one smi by another and returns the quotient. |
| 662 | // Clobbers rax and rdx registers. |
| 663 | void SmiDiv(Register dst, |
| 664 | Register src1, |
| 665 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 666 | Label* on_not_smi_result, |
| 667 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | |
| 669 | // Divides one smi by another and returns the remainder. |
| 670 | // Clobbers rax and rdx registers. |
| 671 | void SmiMod(Register dst, |
| 672 | Register src1, |
| 673 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 674 | Label* on_not_smi_result, |
| 675 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 676 | |
| 677 | // Bitwise operations. |
| 678 | void SmiNot(Register dst, Register src); |
| 679 | void SmiAnd(Register dst, Register src1, Register src2); |
| 680 | void SmiOr(Register dst, Register src1, Register src2); |
| 681 | void SmiXor(Register dst, Register src1, Register src2); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 682 | void SmiAndConstant(Register dst, Register src1, Smi* constant); |
| 683 | void SmiOrConstant(Register dst, Register src1, Smi* constant); |
| 684 | void SmiXorConstant(Register dst, Register src1, Smi* constant); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 685 | |
| 686 | void SmiShiftLeftConstant(Register dst, |
| 687 | Register src, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 688 | int shift_value, |
| 689 | Label* on_not_smi_result = NULL, |
| 690 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 691 | void SmiShiftLogicalRightConstant(Register dst, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 692 | Register src, |
| 693 | int shift_value, |
| 694 | Label* on_not_smi_result, |
| 695 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 696 | void SmiShiftArithmeticRightConstant(Register dst, |
| 697 | Register src, |
| 698 | int shift_value); |
| 699 | |
| 700 | // Shifts a smi value to the left, and returns the result if that is a smi. |
| 701 | // Uses and clobbers rcx, so dst may not be rcx. |
| 702 | void SmiShiftLeft(Register dst, |
| 703 | Register src1, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | Register src2, |
| 705 | Label* on_not_smi_result = NULL, |
| 706 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 707 | // Shifts a smi value to the right, shifting in zero bits at the top, and |
| 708 | // returns the unsigned intepretation of the result if that is a smi. |
| 709 | // Uses and clobbers rcx, so dst may not be rcx. |
| 710 | void SmiShiftLogicalRight(Register dst, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 711 | Register src1, |
| 712 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 713 | Label* on_not_smi_result, |
| 714 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | // Shifts a smi value to the right, sign extending the top, and |
| 716 | // returns the signed intepretation of the result. That will always |
| 717 | // be a valid smi value, since it's numerically smaller than the |
| 718 | // original. |
| 719 | // Uses and clobbers rcx, so dst may not be rcx. |
| 720 | void SmiShiftArithmeticRight(Register dst, |
| 721 | Register src1, |
| 722 | Register src2); |
| 723 | |
| 724 | // Specialized operations |
| 725 | |
| 726 | // Select the non-smi register of two registers where exactly one is a |
| 727 | // smi. If neither are smis, jump to the failure label. |
| 728 | void SelectNonSmi(Register dst, |
| 729 | Register src1, |
| 730 | Register src2, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 731 | Label* on_not_smis, |
| 732 | Label::Distance near_jump = Label::kFar); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 733 | |
| 734 | // Converts, if necessary, a smi to a combination of number and |
| 735 | // multiplier to be used as a scaled index. |
| 736 | // The src register contains a *positive* smi value. The shift is the |
| 737 | // power of two to multiply the index value by (e.g. |
| 738 | // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2). |
| 739 | // The returned index register may be either src or dst, depending |
| 740 | // on what is most efficient. If src and dst are different registers, |
| 741 | // src is always unchanged. |
| 742 | SmiIndex SmiToIndex(Register dst, Register src, int shift); |
| 743 | |
| 744 | // Converts a positive smi to a negative index. |
| 745 | SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift); |
| 746 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 747 | // Add the value of a smi in memory to an int32 register. |
| 748 | // Sets flags as a normal add. |
| 749 | void AddSmiField(Register dst, const Operand& src); |
| 750 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 751 | // Basic Smi operations. |
| 752 | void Move(Register dst, Smi* source) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 753 | LoadSmiConstant(dst, source); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | void Move(const Operand& dst, Smi* source) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 757 | Register constant = GetSmiConstant(source); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 758 | movp(dst, constant); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | void Push(Smi* smi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 762 | |
| 763 | // Save away a raw integer with pointer size on the stack as two integers |
| 764 | // masquerading as smis so that the garbage collector skips visiting them. |
| 765 | void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister); |
| 766 | // Reconstruct a raw integer with pointer size from two integers masquerading |
| 767 | // as smis on the top of stack. |
| 768 | void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister); |
| 769 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 770 | void Test(const Operand& dst, Smi* source); |
| 771 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 772 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 773 | // --------------------------------------------------------------------------- |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 774 | // String macros. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 775 | |
| 776 | // If object is a string, its map is loaded into object_map. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 777 | void JumpIfNotString(Register object, |
| 778 | Register object_map, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 779 | Label* not_string, |
| 780 | Label::Distance near_jump = Label::kFar); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 781 | |
| 782 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 783 | void JumpIfNotBothSequentialOneByteStrings( |
| 784 | Register first_object, Register second_object, Register scratch1, |
| 785 | Register scratch2, Label* on_not_both_flat_one_byte, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 786 | Label::Distance near_jump = Label::kFar); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 787 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | // Check whether the instance type represents a flat one-byte string. Jump |
| 789 | // to the label if not. If the instance type can be scratched specify same |
| 790 | // register for both instance type and scratch. |
| 791 | void JumpIfInstanceTypeIsNotSequentialOneByte( |
| 792 | Register instance_type, Register scratch, |
| 793 | Label* on_not_flat_one_byte_string, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 794 | Label::Distance near_jump = Label::kFar); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 795 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 796 | void JumpIfBothInstanceTypesAreNotSequentialOneByte( |
| 797 | Register first_object_instance_type, Register second_object_instance_type, |
| 798 | Register scratch1, Register scratch2, Label* on_fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 799 | Label::Distance near_jump = Label::kFar); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 800 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 801 | void EmitSeqStringSetCharCheck(Register string, |
| 802 | Register index, |
| 803 | Register value, |
| 804 | uint32_t encoding_mask); |
| 805 | |
| 806 | // Checks if the given register or operand is a unique name |
| 807 | void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name, |
| 808 | Label::Distance distance = Label::kFar); |
| 809 | void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name, |
| 810 | Label::Distance distance = Label::kFar); |
| 811 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 812 | // --------------------------------------------------------------------------- |
| 813 | // Macro instructions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 814 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 815 | // Load/store with specific representation. |
| 816 | void Load(Register dst, const Operand& src, Representation r); |
| 817 | void Store(const Operand& dst, Register src, Representation r); |
| 818 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 819 | // Load a register with a long value as efficiently as possible. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | void Set(Register dst, int64_t x); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 821 | void Set(const Operand& dst, intptr_t x); |
| 822 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 823 | void Cvtss2sd(XMMRegister dst, XMMRegister src); |
| 824 | void Cvtss2sd(XMMRegister dst, const Operand& src); |
| 825 | void Cvtsd2ss(XMMRegister dst, XMMRegister src); |
| 826 | void Cvtsd2ss(XMMRegister dst, const Operand& src); |
| 827 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | // cvtsi2sd instruction only writes to the low 64-bit of dst register, which |
| 829 | // hinders register renaming and makes dependence chains longer. So we use |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 830 | // xorpd to clear the dst register before cvtsi2sd to solve this issue. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 831 | void Cvtlsi2sd(XMMRegister dst, Register src); |
| 832 | void Cvtlsi2sd(XMMRegister dst, const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 833 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 834 | void Cvtlsi2ss(XMMRegister dst, Register src); |
| 835 | void Cvtlsi2ss(XMMRegister dst, const Operand& src); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 836 | void Cvtqsi2ss(XMMRegister dst, Register src); |
| 837 | void Cvtqsi2ss(XMMRegister dst, const Operand& src); |
| 838 | |
| 839 | void Cvtqsi2sd(XMMRegister dst, Register src); |
| 840 | void Cvtqsi2sd(XMMRegister dst, const Operand& src); |
| 841 | |
| 842 | void Cvtqui2ss(XMMRegister dst, Register src, Register tmp); |
| 843 | void Cvtqui2sd(XMMRegister dst, Register src, Register tmp); |
| 844 | |
| 845 | void Cvtsd2si(Register dst, XMMRegister src); |
| 846 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 847 | void Cvttss2si(Register dst, XMMRegister src); |
| 848 | void Cvttss2si(Register dst, const Operand& src); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 849 | void Cvttsd2si(Register dst, XMMRegister src); |
| 850 | void Cvttsd2si(Register dst, const Operand& src); |
| 851 | void Cvttss2siq(Register dst, XMMRegister src); |
| 852 | void Cvttss2siq(Register dst, const Operand& src); |
| 853 | void Cvttsd2siq(Register dst, XMMRegister src); |
| 854 | void Cvttsd2siq(Register dst, const Operand& src); |
| 855 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 856 | // Move if the registers are not identical. |
| 857 | void Move(Register target, Register source); |
| 858 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | // TestBit and Load SharedFunctionInfo special field. |
| 860 | void TestBitSharedFunctionInfoSpecialField(Register base, |
| 861 | int offset, |
| 862 | int bit_index); |
| 863 | void LoadSharedFunctionInfoSpecialField(Register dst, |
| 864 | Register base, |
| 865 | int offset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 866 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 867 | // Handle support |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 868 | void Move(Register dst, Handle<Object> source); |
| 869 | void Move(const Operand& dst, Handle<Object> source); |
| 870 | void Cmp(Register dst, Handle<Object> source); |
| 871 | void Cmp(const Operand& dst, Handle<Object> source); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 872 | void Cmp(Register dst, Smi* src); |
| 873 | void Cmp(const Operand& dst, Smi* src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 874 | void Push(Handle<Object> source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 875 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 876 | // Load a heap object and handle the case of new-space objects by |
| 877 | // indirecting via a global cell. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 878 | void MoveHeapObject(Register result, Handle<Object> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 879 | |
| 880 | // Load a global cell into a register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 881 | void LoadGlobalCell(Register dst, Handle<Cell> cell); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 882 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 883 | // Compare the given value and the value of weak cell. |
| 884 | void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch); |
| 885 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 886 | void GetWeakValue(Register value, Handle<WeakCell> cell); |
| 887 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 888 | // Load the value of the weak cell in the value register. Branch to the given |
| 889 | // miss label if the weak cell was cleared. |
| 890 | void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss); |
| 891 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 892 | // Emit code to discard a non-negative number of pointer-sized elements |
| 893 | // from the stack, clobbering only the rsp register. |
| 894 | void Drop(int stack_elements); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 895 | // Emit code to discard a positive number of pointer-sized elements |
| 896 | // from the stack under the return address which remains on the top, |
| 897 | // clobbering the rsp register. |
| 898 | void DropUnderReturnAddress(int stack_elements, |
| 899 | Register scratch = kScratchRegister); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 900 | |
| 901 | void Call(Label* target) { call(target); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 902 | void Push(Register src); |
| 903 | void Push(const Operand& src); |
| 904 | void PushQuad(const Operand& src); |
| 905 | void Push(Immediate value); |
| 906 | void PushImm32(int32_t imm32); |
| 907 | void Pop(Register dst); |
| 908 | void Pop(const Operand& dst); |
| 909 | void PopQuad(const Operand& dst); |
| 910 | void PushReturnAddressFrom(Register src) { pushq(src); } |
| 911 | void PopReturnAddressTo(Register dst) { popq(dst); } |
| 912 | void Move(Register dst, ExternalReference ext) { |
| 913 | movp(dst, reinterpret_cast<void*>(ext.address()), |
| 914 | RelocInfo::EXTERNAL_REFERENCE); |
| 915 | } |
| 916 | |
| 917 | // Loads a pointer into a register with a relocation mode. |
| 918 | void Move(Register dst, void* ptr, RelocInfo::Mode rmode) { |
| 919 | // This method must not be used with heap object references. The stored |
| 920 | // address is not GC safe. Use the handle version instead. |
| 921 | DCHECK(rmode > RelocInfo::LAST_GCED_ENUM); |
| 922 | movp(dst, ptr, rmode); |
| 923 | } |
| 924 | |
| 925 | void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) { |
| 926 | AllowDeferredHandleDereference using_raw_address; |
| 927 | DCHECK(!RelocInfo::IsNone(rmode)); |
| 928 | DCHECK(value->IsHeapObject()); |
| 929 | DCHECK(!isolate()->heap()->InNewSpace(*value)); |
| 930 | movp(dst, reinterpret_cast<void*>(value.location()), rmode); |
| 931 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 932 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 933 | void Move(XMMRegister dst, uint32_t src); |
| 934 | void Move(XMMRegister dst, uint64_t src); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 935 | void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); } |
| 936 | void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); } |
| 937 | |
| 938 | #define AVX_OP2_WITH_TYPE(macro_name, name, src_type) \ |
| 939 | void macro_name(XMMRegister dst, src_type src) { \ |
| 940 | if (CpuFeatures::IsSupported(AVX)) { \ |
| 941 | CpuFeatureScope scope(this, AVX); \ |
| 942 | v##name(dst, dst, src); \ |
| 943 | } else { \ |
| 944 | name(dst, src); \ |
| 945 | } \ |
| 946 | } |
| 947 | #define AVX_OP2_X(macro_name, name) \ |
| 948 | AVX_OP2_WITH_TYPE(macro_name, name, XMMRegister) |
| 949 | #define AVX_OP2_O(macro_name, name) \ |
| 950 | AVX_OP2_WITH_TYPE(macro_name, name, const Operand&) |
| 951 | #define AVX_OP2_XO(macro_name, name) \ |
| 952 | AVX_OP2_X(macro_name, name) \ |
| 953 | AVX_OP2_O(macro_name, name) |
| 954 | |
| 955 | AVX_OP2_XO(Addsd, addsd) |
| 956 | AVX_OP2_XO(Subsd, subsd) |
| 957 | AVX_OP2_XO(Mulsd, mulsd) |
| 958 | AVX_OP2_XO(Divsd, divsd) |
| 959 | AVX_OP2_X(Andpd, andpd) |
| 960 | AVX_OP2_X(Orpd, orpd) |
| 961 | AVX_OP2_X(Xorpd, xorpd) |
| 962 | AVX_OP2_X(Pcmpeqd, pcmpeqd) |
| 963 | AVX_OP2_WITH_TYPE(Psllq, psllq, byte) |
| 964 | AVX_OP2_WITH_TYPE(Psrlq, psrlq, byte) |
| 965 | |
| 966 | #undef AVX_OP2_O |
| 967 | #undef AVX_OP2_X |
| 968 | #undef AVX_OP2_XO |
| 969 | #undef AVX_OP2_WITH_TYPE |
| 970 | |
| 971 | void Movsd(XMMRegister dst, XMMRegister src); |
| 972 | void Movsd(XMMRegister dst, const Operand& src); |
| 973 | void Movsd(const Operand& dst, XMMRegister src); |
| 974 | void Movss(XMMRegister dst, XMMRegister src); |
| 975 | void Movss(XMMRegister dst, const Operand& src); |
| 976 | void Movss(const Operand& dst, XMMRegister src); |
| 977 | |
| 978 | void Movd(XMMRegister dst, Register src); |
| 979 | void Movd(XMMRegister dst, const Operand& src); |
| 980 | void Movd(Register dst, XMMRegister src); |
| 981 | void Movq(XMMRegister dst, Register src); |
| 982 | void Movq(Register dst, XMMRegister src); |
| 983 | |
| 984 | void Movaps(XMMRegister dst, XMMRegister src); |
| 985 | void Movapd(XMMRegister dst, XMMRegister src); |
| 986 | void Movmskpd(Register dst, XMMRegister src); |
| 987 | |
| 988 | void Roundss(XMMRegister dst, XMMRegister src, RoundingMode mode); |
| 989 | void Roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode); |
| 990 | void Sqrtsd(XMMRegister dst, XMMRegister src); |
| 991 | void Sqrtsd(XMMRegister dst, const Operand& src); |
| 992 | |
| 993 | void Ucomiss(XMMRegister src1, XMMRegister src2); |
| 994 | void Ucomiss(XMMRegister src1, const Operand& src2); |
| 995 | void Ucomisd(XMMRegister src1, XMMRegister src2); |
| 996 | void Ucomisd(XMMRegister src1, const Operand& src2); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 997 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 998 | // Control Flow |
| 999 | void Jump(Address destination, RelocInfo::Mode rmode); |
| 1000 | void Jump(ExternalReference ext); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | void Jump(const Operand& op); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1002 | void Jump(Handle<Code> code_object, RelocInfo::Mode rmode); |
| 1003 | |
| 1004 | void Call(Address destination, RelocInfo::Mode rmode); |
| 1005 | void Call(ExternalReference ext); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1006 | void Call(const Operand& op); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1007 | void Call(Handle<Code> code_object, |
| 1008 | RelocInfo::Mode rmode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1009 | TypeFeedbackId ast_id = TypeFeedbackId::None()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1010 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1011 | // The size of the code generated for different call instructions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1012 | int CallSize(Address destination) { |
| 1013 | return kCallSequenceLength; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1014 | } |
| 1015 | int CallSize(ExternalReference ext); |
| 1016 | int CallSize(Handle<Code> code_object) { |
| 1017 | // Code calls use 32-bit relative addressing. |
| 1018 | return kShortCallInstructionLength; |
| 1019 | } |
| 1020 | int CallSize(Register target) { |
| 1021 | // Opcode: REX_opt FF /2 m64 |
| 1022 | return (target.high_bit() != 0) ? 3 : 2; |
| 1023 | } |
| 1024 | int CallSize(const Operand& target) { |
| 1025 | // Opcode: REX_opt FF /2 m64 |
| 1026 | return (target.requires_rex() ? 2 : 1) + target.operand_size(); |
| 1027 | } |
| 1028 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1029 | // Non-SSE2 instructions. |
| 1030 | void Pextrd(Register dst, XMMRegister src, int8_t imm8); |
| 1031 | void Pinsrd(XMMRegister dst, Register src, int8_t imm8); |
| 1032 | void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8); |
| 1033 | |
| 1034 | void Lzcntq(Register dst, Register src); |
| 1035 | void Lzcntq(Register dst, const Operand& src); |
| 1036 | |
| 1037 | void Lzcntl(Register dst, Register src); |
| 1038 | void Lzcntl(Register dst, const Operand& src); |
| 1039 | |
| 1040 | void Tzcntq(Register dst, Register src); |
| 1041 | void Tzcntq(Register dst, const Operand& src); |
| 1042 | |
| 1043 | void Tzcntl(Register dst, Register src); |
| 1044 | void Tzcntl(Register dst, const Operand& src); |
| 1045 | |
| 1046 | void Popcntl(Register dst, Register src); |
| 1047 | void Popcntl(Register dst, const Operand& src); |
| 1048 | |
| 1049 | void Popcntq(Register dst, Register src); |
| 1050 | void Popcntq(Register dst, const Operand& src); |
| 1051 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1052 | // Non-x64 instructions. |
| 1053 | // Push/pop all general purpose registers. |
| 1054 | // Does not push rsp/rbp nor any of the assembler's special purpose registers |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1055 | // (kScratchRegister, kRootRegister). |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1056 | void Pushad(); |
| 1057 | void Popad(); |
| 1058 | // Sets the stack as after performing Popad, without actually loading the |
| 1059 | // registers. |
| 1060 | void Dropad(); |
| 1061 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1062 | // Compare object type for heap object. |
| 1063 | // Always use unsigned comparisons: above and below, not less and greater. |
| 1064 | // Incoming register is heap_object and outgoing register is map. |
| 1065 | // They may be the same register, and may be kScratchRegister. |
| 1066 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 1067 | |
| 1068 | // Compare instance type for map. |
| 1069 | // Always use unsigned comparisons: above and below, not less and greater. |
| 1070 | void CmpInstanceType(Register map, InstanceType type); |
| 1071 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1072 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 1073 | // Jump to the specified label if it does not. |
| 1074 | void CheckFastElements(Register map, |
| 1075 | Label* fail, |
| 1076 | Label::Distance distance = Label::kFar); |
| 1077 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1078 | // Check if a map for a JSObject indicates that the object can have both smi |
| 1079 | // and HeapObject elements. Jump to the specified label if it does not. |
| 1080 | void CheckFastObjectElements(Register map, |
| 1081 | Label* fail, |
| 1082 | Label::Distance distance = Label::kFar); |
| 1083 | |
| 1084 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 1085 | // elements. Jump to the specified label if it does not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1086 | void CheckFastSmiElements(Register map, |
| 1087 | Label* fail, |
| 1088 | Label::Distance distance = Label::kFar); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1089 | |
| 1090 | // Check to see if maybe_number can be stored as a double in |
| 1091 | // FastDoubleElements. If it can, store it at the index specified by index in |
| 1092 | // the FastDoubleElements array elements, otherwise jump to fail. Note that |
| 1093 | // index must not be smi-tagged. |
| 1094 | void StoreNumberToDoubleElements(Register maybe_number, |
| 1095 | Register elements, |
| 1096 | Register index, |
| 1097 | XMMRegister xmm_scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1098 | Label* fail, |
| 1099 | int elements_offset = 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1100 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1101 | // Compare an object's map with the specified map. |
| 1102 | void CompareMap(Register obj, Handle<Map> map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1103 | |
| 1104 | // Check if the map of an object is equal to a specified map and branch to |
| 1105 | // label if not. Skip the smi check if not required (object is known to be a |
| 1106 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
| 1107 | // against maps that are ElementsKind transition maps of the specified map. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1108 | void CheckMap(Register obj, |
| 1109 | Handle<Map> map, |
| 1110 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1111 | SmiCheckType smi_check_type); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1112 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1113 | // Check if the map of an object is equal to a specified weak map and branch |
| 1114 | // to a specified target if equal. Skip the smi check if not required |
| 1115 | // (object is known to be a heap object) |
| 1116 | void DispatchWeakMap(Register obj, Register scratch1, Register scratch2, |
| 1117 | Handle<WeakCell> cell, Handle<Code> success, |
| 1118 | SmiCheckType smi_check_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1119 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1120 | // Check if the object in register heap_object is a string. Afterwards the |
| 1121 | // register map contains the object map and the register instance_type |
| 1122 | // contains the instance_type. The registers map and instance_type can be the |
| 1123 | // same in which case it contains the instance type afterwards. Either of the |
| 1124 | // registers map and instance_type can be the same as heap_object. |
| 1125 | Condition IsObjectStringType(Register heap_object, |
| 1126 | Register map, |
| 1127 | Register instance_type); |
| 1128 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1129 | // Check if the object in register heap_object is a name. Afterwards the |
| 1130 | // register map contains the object map and the register instance_type |
| 1131 | // contains the instance_type. The registers map and instance_type can be the |
| 1132 | // same in which case it contains the instance type afterwards. Either of the |
| 1133 | // registers map and instance_type can be the same as heap_object. |
| 1134 | Condition IsObjectNameType(Register heap_object, |
| 1135 | Register map, |
| 1136 | Register instance_type); |
| 1137 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1138 | // FCmp compares and pops the two values on top of the FPU stack. |
| 1139 | // The flag results are similar to integer cmp, but requires unsigned |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1140 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 1141 | void FCmp(); |
| 1142 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1143 | void ClampUint8(Register reg); |
| 1144 | |
| 1145 | void ClampDoubleToUint8(XMMRegister input_reg, |
| 1146 | XMMRegister temp_xmm_reg, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1147 | Register result_reg); |
| 1148 | |
| 1149 | void SlowTruncateToI(Register result_reg, Register input_reg, |
| 1150 | int offset = HeapNumber::kValueOffset - kHeapObjectTag); |
| 1151 | |
| 1152 | void TruncateHeapNumberToI(Register result_reg, Register input_reg); |
| 1153 | void TruncateDoubleToI(Register result_reg, XMMRegister input_reg); |
| 1154 | |
| 1155 | void DoubleToI(Register result_reg, XMMRegister input_reg, |
| 1156 | XMMRegister scratch, MinusZeroMode minus_zero_mode, |
| 1157 | Label* lost_precision, Label* is_nan, Label* minus_zero, |
| 1158 | Label::Distance dst = Label::kFar); |
| 1159 | |
| 1160 | void LoadUint32(XMMRegister dst, Register src); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1161 | |
| 1162 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1163 | void EnumLength(Register dst, Register map); |
| 1164 | void NumberOfOwnDescriptors(Register dst, Register map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1165 | void LoadAccessor(Register dst, Register holder, int accessor_index, |
| 1166 | AccessorComponent accessor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1167 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1168 | template<typename Field> |
| 1169 | void DecodeField(Register reg) { |
| 1170 | static const int shift = Field::kShift; |
| 1171 | static const int mask = Field::kMask >> Field::kShift; |
| 1172 | if (shift != 0) { |
| 1173 | shrp(reg, Immediate(shift)); |
| 1174 | } |
| 1175 | andp(reg, Immediate(mask)); |
| 1176 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1177 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1178 | template<typename Field> |
| 1179 | void DecodeFieldToSmi(Register reg) { |
| 1180 | if (SmiValuesAre32Bits()) { |
| 1181 | andp(reg, Immediate(Field::kMask)); |
| 1182 | shlp(reg, Immediate(kSmiShift - Field::kShift)); |
| 1183 | } else { |
| 1184 | static const int shift = Field::kShift; |
| 1185 | static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize; |
| 1186 | DCHECK(SmiValuesAre31Bits()); |
| 1187 | DCHECK(kSmiShift == kSmiTagSize); |
| 1188 | DCHECK((mask & 0x80000000u) == 0); |
| 1189 | if (shift < kSmiShift) { |
| 1190 | shlp(reg, Immediate(kSmiShift - shift)); |
| 1191 | } else if (shift > kSmiShift) { |
| 1192 | sarp(reg, Immediate(shift - kSmiShift)); |
| 1193 | } |
| 1194 | andp(reg, Immediate(mask)); |
| 1195 | } |
| 1196 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1197 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1198 | // Abort execution if argument is not a number, enabled via --debug-code. |
| 1199 | void AssertNumber(Register object); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1200 | void AssertNotNumber(Register object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1201 | |
| 1202 | // Abort execution if argument is a smi, enabled via --debug-code. |
| 1203 | void AssertNotSmi(Register object); |
| 1204 | |
| 1205 | // Abort execution if argument is not a smi, enabled via --debug-code. |
| 1206 | void AssertSmi(Register object); |
| 1207 | void AssertSmi(const Operand& object); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1208 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1209 | // Abort execution if a 64 bit register containing a 32 bit payload does not |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1210 | // have zeros in the top 32 bits, enabled via --debug-code. |
| 1211 | void AssertZeroExtended(Register reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1213 | // Abort execution if argument is not a string, enabled via --debug-code. |
| 1214 | void AssertString(Register object); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1215 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1216 | // Abort execution if argument is not a name, enabled via --debug-code. |
| 1217 | void AssertName(Register object); |
| 1218 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1219 | // Abort execution if argument is not a JSFunction, enabled via --debug-code. |
| 1220 | void AssertFunction(Register object); |
| 1221 | |
| 1222 | // Abort execution if argument is not a JSBoundFunction, |
| 1223 | // enabled via --debug-code. |
| 1224 | void AssertBoundFunction(Register object); |
| 1225 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1226 | // Abort execution if argument is not a JSGeneratorObject, |
| 1227 | // enabled via --debug-code. |
| 1228 | void AssertGeneratorObject(Register object); |
| 1229 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1230 | // Abort execution if argument is not a JSReceiver, enabled via --debug-code. |
| 1231 | void AssertReceiver(Register object); |
| 1232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1233 | // Abort execution if argument is not undefined or an AllocationSite, enabled |
| 1234 | // via --debug-code. |
| 1235 | void AssertUndefinedOrAllocationSite(Register object); |
| 1236 | |
| 1237 | // Abort execution if argument is not the root value with the given index, |
| 1238 | // enabled via --debug-code. |
| 1239 | void AssertRootValue(Register src, |
| 1240 | Heap::RootListIndex root_value_index, |
| 1241 | BailoutReason reason); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1242 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1243 | // --------------------------------------------------------------------------- |
| 1244 | // Exception handling |
| 1245 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1246 | // Push a new stack handler and link it into stack handler chain. |
| 1247 | void PushStackHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1248 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1249 | // Unlink the stack handler on top of the stack from the stack handler chain. |
| 1250 | void PopStackHandler(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1252 | // --------------------------------------------------------------------------- |
| 1253 | // Inline caching support |
| 1254 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1255 | // Generate code for checking access rights - used for security checks |
| 1256 | // on access to global objects across environments. The holder register |
| 1257 | // is left untouched, but the scratch register and kScratchRegister, |
| 1258 | // which must be different, are clobbered. |
| 1259 | void CheckAccessGlobalProxy(Register holder_reg, |
| 1260 | Register scratch, |
| 1261 | Label* miss); |
| 1262 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1263 | void GetNumberHash(Register r0, Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1264 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1265 | void LoadFromNumberDictionary(Label* miss, |
| 1266 | Register elements, |
| 1267 | Register key, |
| 1268 | Register r0, |
| 1269 | Register r1, |
| 1270 | Register r2, |
| 1271 | Register result); |
| 1272 | |
| 1273 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1274 | // --------------------------------------------------------------------------- |
| 1275 | // Allocation support |
| 1276 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1277 | // Allocate an object in new space or old space. If the given space |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1278 | // is exhausted control continues at the gc_required label. The allocated |
| 1279 | // object is returned in result and end of the new object is returned in |
| 1280 | // result_end. The register scratch can be passed as no_reg in which case |
| 1281 | // an additional object reference will be added to the reloc info. The |
| 1282 | // returned pointers in result and result_end have not yet been tagged as |
| 1283 | // heap objects. If result_contains_top_on_entry is true the content of |
| 1284 | // result is known to be the allocation top on entry (could be result_end |
| 1285 | // from a previous call). If result_contains_top_on_entry is true scratch |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1286 | // should be no_reg as it is never used. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1287 | void Allocate(int object_size, |
| 1288 | Register result, |
| 1289 | Register result_end, |
| 1290 | Register scratch, |
| 1291 | Label* gc_required, |
| 1292 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1293 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1294 | void Allocate(int header_size, |
| 1295 | ScaleFactor element_size, |
| 1296 | Register element_count, |
| 1297 | Register result, |
| 1298 | Register result_end, |
| 1299 | Register scratch, |
| 1300 | Label* gc_required, |
| 1301 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1302 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1303 | void Allocate(Register object_size, |
| 1304 | Register result, |
| 1305 | Register result_end, |
| 1306 | Register scratch, |
| 1307 | Label* gc_required, |
| 1308 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1309 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1310 | // FastAllocate is right now only used for folded allocations. It just |
| 1311 | // increments the top pointer without checking against limit. This can only |
| 1312 | // be done if it was proved earlier that the allocation will succeed. |
| 1313 | void FastAllocate(int object_size, Register result, Register result_end, |
| 1314 | AllocationFlags flags); |
| 1315 | |
| 1316 | void FastAllocate(Register object_size, Register result, Register result_end, |
| 1317 | AllocationFlags flags); |
| 1318 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1319 | // Allocate a heap number in new space with undefined value. Returns |
| 1320 | // tagged pointer in result register, or jumps to gc_required if new |
| 1321 | // space is full. |
| 1322 | void AllocateHeapNumber(Register result, |
| 1323 | Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1324 | Label* gc_required, |
| 1325 | MutableMode mode = IMMUTABLE); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1326 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1327 | // Allocate a sequential string. All the header fields of the string object |
| 1328 | // are initialized. |
| 1329 | void AllocateTwoByteString(Register result, |
| 1330 | Register length, |
| 1331 | Register scratch1, |
| 1332 | Register scratch2, |
| 1333 | Register scratch3, |
| 1334 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | void AllocateOneByteString(Register result, Register length, |
| 1336 | Register scratch1, Register scratch2, |
| 1337 | Register scratch3, Label* gc_required); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1338 | |
| 1339 | // Allocate a raw cons string object. Only the map field of the result is |
| 1340 | // initialized. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1341 | void AllocateTwoByteConsString(Register result, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1342 | Register scratch1, |
| 1343 | Register scratch2, |
| 1344 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1345 | void AllocateOneByteConsString(Register result, Register scratch1, |
| 1346 | Register scratch2, Label* gc_required); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1347 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1348 | // Allocate a raw sliced string object. Only the map field of the result is |
| 1349 | // initialized. |
| 1350 | void AllocateTwoByteSlicedString(Register result, |
| 1351 | Register scratch1, |
| 1352 | Register scratch2, |
| 1353 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1354 | void AllocateOneByteSlicedString(Register result, Register scratch1, |
| 1355 | Register scratch2, Label* gc_required); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1356 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1357 | // Allocate and initialize a JSValue wrapper with the specified {constructor} |
| 1358 | // and {value}. |
| 1359 | void AllocateJSValue(Register result, Register constructor, Register value, |
| 1360 | Register scratch, Label* gc_required); |
| 1361 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1362 | // --------------------------------------------------------------------------- |
| 1363 | // Support functions. |
| 1364 | |
| 1365 | // Check if result is zero and op is negative. |
| 1366 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 1367 | |
| 1368 | // Check if result is zero and op is negative in code using jump targets. |
| 1369 | void NegativeZeroTest(CodeGenerator* cgen, |
| 1370 | Register result, |
| 1371 | Register op, |
| 1372 | JumpTarget* then_target); |
| 1373 | |
| 1374 | // Check if result is zero and any of op1 and op2 are negative. |
| 1375 | // Register scratch is destroyed, and it must be different from op2. |
| 1376 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 1377 | Register scratch, Label* then_label); |
| 1378 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1379 | // Machine code version of Map::GetConstructor(). |
| 1380 | // |temp| holds |result|'s map when done. |
| 1381 | void GetMapConstructor(Register result, Register map, Register temp); |
| 1382 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1383 | // Try to get function prototype of a function and puts the value in |
| 1384 | // the result register. Checks that the function really is a |
| 1385 | // function and jumps to the miss label if the fast checks fail. The |
| 1386 | // function register will be untouched; the other register may be |
| 1387 | // clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1388 | void TryGetFunctionPrototype(Register function, Register result, Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1389 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1390 | // Picks out an array index from the hash field. |
| 1391 | // Register use: |
| 1392 | // hash - holds the index's hash. Clobbered. |
| 1393 | // index - holds the overwritten index on exit. |
| 1394 | void IndexFromHash(Register hash, Register index); |
| 1395 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1396 | // Find the function context up the context chain. |
| 1397 | void LoadContext(Register dst, int context_chain_length); |
| 1398 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1399 | // Load the global object from the current context. |
| 1400 | void LoadGlobalObject(Register dst) { |
| 1401 | LoadNativeContextSlot(Context::EXTENSION_INDEX, dst); |
| 1402 | } |
| 1403 | |
| 1404 | // Load the global proxy from the current context. |
| 1405 | void LoadGlobalProxy(Register dst) { |
| 1406 | LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst); |
| 1407 | } |
| 1408 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1409 | // Conditionally load the cached Array transitioned map of type |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1410 | // transitioned_kind from the native context if the map in register |
| 1411 | // 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] | 1412 | // expected_kind. |
| 1413 | void LoadTransitionedArrayMapConditional( |
| 1414 | ElementsKind expected_kind, |
| 1415 | ElementsKind transitioned_kind, |
| 1416 | Register map_in_out, |
| 1417 | Register scratch, |
| 1418 | Label* no_map_match); |
| 1419 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1420 | // Load the native context slot with the current index. |
| 1421 | void LoadNativeContextSlot(int index, Register dst); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1422 | |
| 1423 | // Load the initial map from the global function. The registers |
| 1424 | // function and map can be the same. |
| 1425 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 1426 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1427 | // --------------------------------------------------------------------------- |
| 1428 | // Runtime calls |
| 1429 | |
| 1430 | // Call a code stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1431 | void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1432 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1433 | // Tail call a code stub (jump). |
| 1434 | void TailCallStub(CodeStub* stub); |
| 1435 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1436 | // Return from a code stub after popping its arguments. |
| 1437 | void StubReturn(int argc); |
| 1438 | |
| 1439 | // Call a runtime routine. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1440 | void CallRuntime(const Runtime::Function* f, |
| 1441 | int num_arguments, |
| 1442 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1443 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1444 | // Call a runtime function and save the value of XMM registers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1445 | void CallRuntimeSaveDoubles(Runtime::FunctionId fid) { |
| 1446 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1447 | CallRuntime(function, function->nargs, kSaveFPRegs); |
| 1448 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1449 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1450 | // Convenience function: Same as above, but takes the fid instead. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1451 | void CallRuntime(Runtime::FunctionId fid, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1452 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1453 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
| 1454 | CallRuntime(function, function->nargs, save_doubles); |
| 1455 | } |
| 1456 | |
| 1457 | // Convenience function: Same as above, but takes the fid instead. |
| 1458 | void CallRuntime(Runtime::FunctionId fid, int num_arguments, |
| 1459 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 1460 | CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1461 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1462 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1463 | // Convenience function: call an external reference. |
| 1464 | void CallExternalReference(const ExternalReference& ext, |
| 1465 | int num_arguments); |
| 1466 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1467 | // Convenience function: tail call a runtime routine (jump) |
| 1468 | void TailCallRuntime(Runtime::FunctionId fid); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1469 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1470 | // Jump to a runtime routines |
| 1471 | void JumpToExternalReference(const ExternalReference& ext); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1472 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1473 | // Before calling a C-function from generated code, align arguments on stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1474 | // After aligning the frame, arguments must be stored in rsp[0], rsp[8], |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1475 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 1476 | // The number of slots reserved for arguments depends on platform. On Windows |
| 1477 | // stack slots are reserved for the arguments passed in registers. On other |
| 1478 | // platforms stack slots are only reserved for the arguments actually passed |
| 1479 | // on the stack. |
| 1480 | void PrepareCallCFunction(int num_arguments); |
| 1481 | |
| 1482 | // Calls a C function and cleans up the space for arguments allocated |
| 1483 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 1484 | // garbage collection, since that might move the code and invalidate the |
| 1485 | // return address (unless this is somehow accounted for by the called |
| 1486 | // function). |
| 1487 | void CallCFunction(ExternalReference function, int num_arguments); |
| 1488 | void CallCFunction(Register function, int num_arguments); |
| 1489 | |
| 1490 | // Calculate the number of stack slots to reserve for arguments when calling a |
| 1491 | // C function. |
| 1492 | int ArgumentStackSlotsForCFunctionCall(int num_arguments); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1493 | |
| 1494 | // --------------------------------------------------------------------------- |
| 1495 | // Utilities |
| 1496 | |
| 1497 | void Ret(); |
| 1498 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1499 | // Return and drop arguments from stack, where the number of arguments |
| 1500 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 1501 | void Ret(int bytes_dropped, Register scratch); |
| 1502 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1503 | Handle<Object> CodeObject() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1504 | DCHECK(!code_object_.is_null()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1505 | return code_object_; |
| 1506 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1507 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1508 | // Copy length bytes from source to destination. |
| 1509 | // Uses scratch register internally (if you have a low-eight register |
| 1510 | // free, do use it, otherwise kScratchRegister will be used). |
| 1511 | // The min_length is a minimum limit on the value that length will have. |
| 1512 | // The algorithm has some special cases that might be omitted if the string |
| 1513 | // is known to always be long. |
| 1514 | void CopyBytes(Register destination, |
| 1515 | Register source, |
| 1516 | Register length, |
| 1517 | int min_length = 0, |
| 1518 | Register scratch = kScratchRegister); |
| 1519 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1520 | // Initialize fields with filler values. Fields starting at |current_address| |
| 1521 | // not including |end_address| are overwritten with the value in |filler|. At |
| 1522 | // the end the loop, |current_address| takes the value of |end_address|. |
| 1523 | void InitializeFieldsWithFiller(Register current_address, |
| 1524 | Register end_address, Register filler); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1525 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1526 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1527 | // Emit code for a truncating division by a constant. The dividend register is |
| 1528 | // unchanged, the result is in rdx, and rax gets clobbered. |
| 1529 | void TruncatingDiv(Register dividend, int32_t divisor); |
| 1530 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1531 | // --------------------------------------------------------------------------- |
| 1532 | // StatsCounter support |
| 1533 | |
| 1534 | void SetCounter(StatsCounter* counter, int value); |
| 1535 | void IncrementCounter(StatsCounter* counter, int value); |
| 1536 | void DecrementCounter(StatsCounter* counter, int value); |
| 1537 | |
| 1538 | |
| 1539 | // --------------------------------------------------------------------------- |
| 1540 | // Debugging |
| 1541 | |
| 1542 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 1543 | // Use --debug_code to enable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1544 | void Assert(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1545 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1546 | void AssertFastElements(Register elements); |
| 1547 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1548 | // Like Assert(), but always enabled. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1549 | void Check(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1550 | |
| 1551 | // Print a message to stdout and abort execution. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1552 | void Abort(BailoutReason msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1553 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1554 | // Check that the stack is aligned. |
| 1555 | void CheckStackAlignment(); |
| 1556 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1557 | // Verify restrictions about code generated in stubs. |
| 1558 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 1559 | bool generating_stub() { return generating_stub_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1560 | void set_has_frame(bool value) { has_frame_ = value; } |
| 1561 | bool has_frame() { return has_frame_; } |
| 1562 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1563 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1564 | static int SafepointRegisterStackIndex(Register reg) { |
| 1565 | return SafepointRegisterStackIndex(reg.code()); |
| 1566 | } |
| 1567 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1568 | // Load the type feedback vector from a JavaScript frame. |
| 1569 | void EmitLoadTypeFeedbackVector(Register vector); |
| 1570 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1571 | // Activation support. |
| 1572 | void EnterFrame(StackFrame::Type type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1573 | void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1574 | void LeaveFrame(StackFrame::Type type); |
| 1575 | |
| 1576 | // Expects object in rax and returns map with validated enum cache |
| 1577 | // in rax. Assumes that any other register can be used as a scratch. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1578 | void CheckEnumCache(Label* call_runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1579 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1580 | // AllocationMemento support. Arrays may have an associated |
| 1581 | // AllocationMemento object that can be checked for in order to pretransition |
| 1582 | // to another type. |
| 1583 | // On entry, receiver_reg should point to the array object. |
| 1584 | // scratch_reg gets clobbered. |
| 1585 | // If allocation info is present, condition flags are set to equal. |
| 1586 | void TestJSArrayForAllocationMemento(Register receiver_reg, |
| 1587 | Register scratch_reg, |
| 1588 | Label* no_memento_found); |
| 1589 | |
| 1590 | void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, |
| 1591 | Register scratch_reg, |
| 1592 | Label* memento_found) { |
| 1593 | Label no_memento_found; |
| 1594 | TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, |
| 1595 | &no_memento_found); |
| 1596 | j(equal, memento_found); |
| 1597 | bind(&no_memento_found); |
| 1598 | } |
| 1599 | |
| 1600 | // Jumps to found label if a prototype map has dictionary elements. |
| 1601 | void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0, |
| 1602 | Register scratch1, Label* found); |
| 1603 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1604 | private: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1605 | // Order general registers are pushed by Pushad. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1606 | // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1607 | static const int kSafepointPushRegisterIndices[Register::kNumRegisters]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1608 | static const int kNumSafepointSavedRegisters = 12; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1609 | static const int kSmiShift = kSmiTagSize + kSmiShiftSize; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1610 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1611 | bool generating_stub_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1612 | bool has_frame_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1613 | bool root_array_available_; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1614 | |
| 1615 | // Returns a register holding the smi value. The register MUST NOT be |
| 1616 | // modified. It may be the "smi 1 constant" register. |
| 1617 | Register GetSmiConstant(Smi* value); |
| 1618 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1619 | int64_t RootRegisterDelta(ExternalReference other); |
| 1620 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1621 | // Moves the smi value to the destination register. |
| 1622 | void LoadSmiConstant(Register dst, Smi* value); |
| 1623 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1624 | // This handle will be patched with the code object on installation. |
| 1625 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1626 | |
| 1627 | // Helper functions for generating invokes. |
| 1628 | void InvokePrologue(const ParameterCount& expected, |
| 1629 | const ParameterCount& actual, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1630 | Label* done, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1631 | bool* definitely_mismatches, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1632 | InvokeFlag flag, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1633 | Label::Distance near_jump, |
| 1634 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1635 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1636 | void EnterExitFramePrologue(bool save_rax); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1637 | |
| 1638 | // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack |
| 1639 | // accessible via StackSpaceOperand. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1640 | void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1641 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | void LeaveExitFrameEpilogue(bool restore_context); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1643 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1644 | // Allocation support helpers. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1645 | // Loads the top of new-space into the result register. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1646 | // Otherwise the address of the new-space top is loaded into scratch (if |
| 1647 | // scratch is valid), and the new-space top is loaded into result. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1648 | void LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1649 | Register scratch, |
| 1650 | AllocationFlags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1651 | |
| 1652 | void MakeSureDoubleAlignedHelper(Register result, |
| 1653 | Register scratch, |
| 1654 | Label* gc_required, |
| 1655 | AllocationFlags flags); |
| 1656 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1657 | // Update allocation top with value in result_end register. |
| 1658 | // If scratch is valid, it contains the address of the allocation top. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1659 | void UpdateAllocationTopHelper(Register result_end, |
| 1660 | Register scratch, |
| 1661 | AllocationFlags flags); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1662 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1663 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 1664 | void InNewSpace(Register object, |
| 1665 | Register scratch, |
| 1666 | Condition cc, |
| 1667 | Label* branch, |
| 1668 | Label::Distance distance = Label::kFar); |
| 1669 | |
| 1670 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1671 | // bitmap register points at the word with the mark bits and the mask |
| 1672 | // the position of the first bit. Uses rcx as scratch and leaves addr_reg |
| 1673 | // unchanged. |
| 1674 | inline void GetMarkBits(Register addr_reg, |
| 1675 | Register bitmap_reg, |
| 1676 | Register mask_reg); |
| 1677 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1678 | // Compute memory operands for safepoint stack slots. |
| 1679 | Operand SafepointRegisterSlot(Register reg); |
| 1680 | static int SafepointRegisterStackIndex(int reg_code) { |
| 1681 | return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1; |
| 1682 | } |
| 1683 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1684 | // Needs access to SafepointRegisterStackIndex for compiled frame |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1685 | // traversal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1686 | friend class StandardFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1687 | }; |
| 1688 | |
| 1689 | |
| 1690 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1691 | // debugging and other types of instrumentation. When using the code patcher |
| 1692 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 1693 | // relocation information. If any of these constraints are violated it causes |
| 1694 | // an assertion. |
| 1695 | class CodePatcher { |
| 1696 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1697 | CodePatcher(Isolate* isolate, byte* address, int size); |
| 1698 | ~CodePatcher(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Macro assembler to emit code. |
| 1701 | MacroAssembler* masm() { return &masm_; } |
| 1702 | |
| 1703 | private: |
| 1704 | byte* address_; // The address of the code being patched. |
| 1705 | int size_; // Number of bytes of the expected patch size. |
| 1706 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1707 | }; |
| 1708 | |
| 1709 | |
| 1710 | // ----------------------------------------------------------------------------- |
| 1711 | // Static helper functions. |
| 1712 | |
| 1713 | // Generate an Operand for loading a field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1714 | inline Operand FieldOperand(Register object, int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1715 | return Operand(object, offset - kHeapObjectTag); |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | // Generate an Operand for loading an indexed field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1720 | inline Operand FieldOperand(Register object, |
| 1721 | Register index, |
| 1722 | ScaleFactor scale, |
| 1723 | int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1724 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 1725 | } |
| 1726 | |
| 1727 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1728 | inline Operand ContextOperand(Register context, int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1729 | return Operand(context, Context::SlotOffset(index)); |
| 1730 | } |
| 1731 | |
| 1732 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1733 | inline Operand ContextOperand(Register context, Register index) { |
| 1734 | return Operand(context, index, times_pointer_size, Context::SlotOffset(0)); |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | inline Operand NativeContextOperand() { |
| 1739 | return ContextOperand(rsi, Context::NATIVE_CONTEXT_INDEX); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | // Provides access to exit frame stack space (not GCed). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1744 | inline Operand StackSpaceOperand(int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1745 | #ifdef _WIN64 |
| 1746 | const int kShaddowSpace = 4; |
| 1747 | return Operand(rsp, (index + kShaddowSpace) * kPointerSize); |
| 1748 | #else |
| 1749 | return Operand(rsp, index * kPointerSize); |
| 1750 | #endif |
| 1751 | } |
| 1752 | |
| 1753 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1754 | inline Operand StackOperandForReturnAddress(int32_t disp) { |
| 1755 | return Operand(rsp, disp); |
| 1756 | } |
| 1757 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1758 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1759 | #ifdef GENERATED_CODE_COVERAGE |
| 1760 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 1761 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1762 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1763 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1764 | #define ACCESS_MASM(masm) { \ |
| 1765 | Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \ |
| 1766 | masm->pushfq(); \ |
| 1767 | masm->Pushad(); \ |
| 1768 | masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 1769 | masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \ |
| 1770 | masm->Pop(rax); \ |
| 1771 | masm->Popad(); \ |
| 1772 | masm->popfq(); \ |
| 1773 | } \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1774 | masm-> |
| 1775 | #else |
| 1776 | #define ACCESS_MASM(masm) masm-> |
| 1777 | #endif |
| 1778 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1779 | } // namespace internal |
| 1780 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1781 | |
| 1782 | #endif // V8_X64_MACRO_ASSEMBLER_X64_H_ |