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