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