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