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_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 6 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/assembler.h" |
| 9 | #include "src/bailout-reason.h" |
| 10 | #include "src/frames.h" |
| 11 | #include "src/globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | // Give alias names to registers for calling conventions. |
| 17 | const Register kReturnRegister0 = {Register::kCode_eax}; |
| 18 | const Register kReturnRegister1 = {Register::kCode_edx}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 19 | const Register kReturnRegister2 = {Register::kCode_edi}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 20 | const Register kJSFunctionRegister = {Register::kCode_edi}; |
| 21 | const Register kContextRegister = {Register::kCode_esi}; |
| 22 | const Register kInterpreterAccumulatorRegister = {Register::kCode_eax}; |
| 23 | const Register kInterpreterRegisterFileRegister = {Register::kCode_edx}; |
| 24 | const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_ecx}; |
| 25 | const Register kInterpreterBytecodeArrayRegister = {Register::kCode_edi}; |
| 26 | const Register kJavaScriptCallArgCountRegister = {Register::kCode_eax}; |
| 27 | const Register kJavaScriptCallNewTargetRegister = {Register::kCode_edx}; |
| 28 | const Register kRuntimeCallFunctionRegister = {Register::kCode_ebx}; |
| 29 | const Register kRuntimeCallArgCountRegister = {Register::kCode_eax}; |
| 30 | |
| 31 | // Spill slots used by interpreter dispatch calling convention. |
| 32 | const int kInterpreterDispatchTableSpillSlot = -1; |
| 33 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 34 | // Convenience for platform-independent signatures. We do not normally |
| 35 | // distinguish memory operands from other operands on ia32. |
| 36 | typedef Operand MemOperand; |
| 37 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 38 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 39 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | enum PointersToHereCheck { |
| 41 | kPointersToHereMaybeInteresting, |
| 42 | kPointersToHereAreAlwaysInteresting |
| 43 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 44 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | enum RegisterValueType { REGISTER_VALUE_IS_SMI, REGISTER_VALUE_IS_INT32 }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | |
| 47 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg, |
| 49 | Register reg4 = no_reg, Register reg5 = no_reg, |
| 50 | Register reg6 = no_reg, Register reg7 = no_reg, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | Register reg8 = no_reg); |
| 52 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 53 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | // MacroAssembler implements a collection of frequently used macros. |
| 55 | class MacroAssembler: public Assembler { |
| 56 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | MacroAssembler(Isolate* isolate, void* buffer, int size, |
| 58 | CodeObjectRequired create_code_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | void Load(Register dst, const Operand& src, Representation r); |
| 61 | void Store(Register src, const Operand& dst, Representation r); |
| 62 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 63 | // Load a register with a long value as efficiently as possible. |
| 64 | void Set(Register dst, int32_t x) { |
| 65 | if (x == 0) { |
| 66 | xor_(dst, dst); |
| 67 | } else { |
| 68 | mov(dst, Immediate(x)); |
| 69 | } |
| 70 | } |
| 71 | void Set(const Operand& dst, int32_t x) { mov(dst, Immediate(x)); } |
| 72 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | // Operations on roots in the root-array. |
| 74 | void LoadRoot(Register destination, Heap::RootListIndex index); |
| 75 | void StoreRoot(Register source, Register scratch, Heap::RootListIndex index); |
| 76 | void CompareRoot(Register with, Register scratch, Heap::RootListIndex index); |
| 77 | // These methods can only be used with constant roots (i.e. non-writable |
| 78 | // and not in new space). |
| 79 | void CompareRoot(Register with, Heap::RootListIndex index); |
| 80 | void CompareRoot(const Operand& with, Heap::RootListIndex index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | void PushRoot(Heap::RootListIndex index); |
| 82 | |
| 83 | // Compare the object in a register to a value and jump if they are equal. |
| 84 | void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal, |
| 85 | Label::Distance if_equal_distance = Label::kFar) { |
| 86 | CompareRoot(with, index); |
| 87 | j(equal, if_equal, if_equal_distance); |
| 88 | } |
| 89 | void JumpIfRoot(const Operand& with, Heap::RootListIndex index, |
| 90 | Label* if_equal, |
| 91 | Label::Distance if_equal_distance = Label::kFar) { |
| 92 | CompareRoot(with, index); |
| 93 | j(equal, if_equal, if_equal_distance); |
| 94 | } |
| 95 | |
| 96 | // Compare the object in a register to a value and jump if they are not equal. |
| 97 | void JumpIfNotRoot(Register with, Heap::RootListIndex index, |
| 98 | Label* if_not_equal, |
| 99 | Label::Distance if_not_equal_distance = Label::kFar) { |
| 100 | CompareRoot(with, index); |
| 101 | j(not_equal, if_not_equal, if_not_equal_distance); |
| 102 | } |
| 103 | void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index, |
| 104 | Label* if_not_equal, |
| 105 | Label::Distance if_not_equal_distance = Label::kFar) { |
| 106 | CompareRoot(with, index); |
| 107 | j(not_equal, if_not_equal, if_not_equal_distance); |
| 108 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 110 | // These functions do not arrange the registers in any particular order so |
| 111 | // they are not useful for calls that can cause a GC. The caller can |
| 112 | // exclude up to 3 registers that do not need to be saved and restored. |
| 113 | void PushCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg, |
| 114 | Register exclusion2 = no_reg, |
| 115 | Register exclusion3 = no_reg); |
| 116 | void PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg, |
| 117 | Register exclusion2 = no_reg, |
| 118 | Register exclusion3 = no_reg); |
| 119 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 120 | // --------------------------------------------------------------------------- |
| 121 | // GC Support |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 122 | enum RememberedSetFinalAction { kReturnAtEnd, kFallThroughAtEnd }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 124 | // Record in the remembered set the fact that we have a pointer to new space |
| 125 | // at the address pointed to by the addr register. Only works if addr is not |
| 126 | // in new space. |
| 127 | void RememberedSetHelper(Register object, // Used for debug code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 128 | Register addr, Register scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 129 | SaveFPRegsMode save_fp, |
| 130 | RememberedSetFinalAction and_then); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 131 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | void CheckPageFlag(Register object, Register scratch, int mask, Condition cc, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 133 | Label* condition_met, |
| 134 | Label::Distance condition_met_distance = Label::kFar); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | void CheckPageFlagForMap( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 137 | Handle<Map> map, int mask, Condition cc, Label* condition_met, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | Label::Distance condition_met_distance = Label::kFar); |
| 139 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 140 | // Check if object is in new space. Jumps if the object is not in new space. |
| 141 | // The register scratch can be object itself, but scratch will be clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 142 | void JumpIfNotInNewSpace(Register object, Register scratch, Label* branch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 143 | Label::Distance distance = Label::kFar) { |
| 144 | InNewSpace(object, scratch, zero, branch, distance); |
| 145 | } |
| 146 | |
| 147 | // Check if object is in new space. Jumps if the object is in new space. |
| 148 | // The register scratch can be object itself, but it will be clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 149 | void JumpIfInNewSpace(Register object, Register scratch, Label* branch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 150 | Label::Distance distance = Label::kFar) { |
| 151 | InNewSpace(object, scratch, not_zero, branch, distance); |
| 152 | } |
| 153 | |
| 154 | // Check if an object has a given incremental marking color. Also uses ecx! |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 155 | void HasColor(Register object, Register scratch0, Register scratch1, |
| 156 | Label* has_color, Label::Distance has_color_distance, |
| 157 | int first_bit, int second_bit); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 158 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 159 | void JumpIfBlack(Register object, Register scratch0, Register scratch1, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 160 | Label* on_black, |
| 161 | Label::Distance on_black_distance = Label::kFar); |
| 162 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | // Checks the color of an object. If the object is white we jump to the |
| 164 | // incremental marker. |
| 165 | void JumpIfWhite(Register value, Register scratch1, Register scratch2, |
| 166 | Label* value_is_white, Label::Distance distance); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 167 | |
| 168 | // Notify the garbage collector that we wrote a pointer into an object. |
| 169 | // |object| is the object being stored into, |value| is the object being |
| 170 | // stored. value and scratch registers are clobbered by the operation. |
| 171 | // The offset is the offset from the start of the object, not the offset from |
| 172 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 173 | void RecordWriteField( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | Register object, int offset, Register value, Register scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 175 | SaveFPRegsMode save_fp, |
| 176 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 178 | PointersToHereCheck pointers_to_here_check_for_value = |
| 179 | kPointersToHereMaybeInteresting); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 180 | |
| 181 | // As above, but the offset has the tag presubtracted. For use with |
| 182 | // Operand(reg, off). |
| 183 | void RecordWriteContextSlot( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 184 | Register context, int offset, Register value, Register scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 185 | SaveFPRegsMode save_fp, |
| 186 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 188 | PointersToHereCheck pointers_to_here_check_for_value = |
| 189 | kPointersToHereMaybeInteresting) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 190 | RecordWriteField(context, offset + kHeapObjectTag, value, scratch, save_fp, |
| 191 | remembered_set_action, smi_check, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Notify the garbage collector that we wrote a pointer into a fixed array. |
| 196 | // |array| is the array being stored into, |value| is the |
| 197 | // object being stored. |index| is the array index represented as a |
| 198 | // Smi. All registers are clobbered by the operation RecordWriteArray |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 199 | // filters out smis so it does not update the write barrier if the |
| 200 | // value is a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 201 | void RecordWriteArray( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 202 | Register array, Register value, Register index, SaveFPRegsMode save_fp, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 203 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 205 | PointersToHereCheck pointers_to_here_check_for_value = |
| 206 | kPointersToHereMaybeInteresting); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 207 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 208 | // For page containing |object| mark region covering |address| |
| 209 | // dirty. |object| is the object being stored into, |value| is the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 210 | // object being stored. The address and value registers are clobbered by the |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 211 | // operation. RecordWrite filters out smis so it does not update the |
| 212 | // write barrier if the value is a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 213 | void RecordWrite( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 214 | Register object, Register address, Register value, SaveFPRegsMode save_fp, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 215 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 217 | PointersToHereCheck pointers_to_here_check_for_value = |
| 218 | kPointersToHereMaybeInteresting); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 219 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 220 | // Notify the garbage collector that we wrote a code entry into a |
| 221 | // JSFunction. Only scratch is clobbered by the operation. |
| 222 | void RecordWriteCodeEntryField(Register js_function, Register code_entry, |
| 223 | Register scratch); |
| 224 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 225 | // For page containing |object| mark the region covering the object's map |
| 226 | // dirty. |object| is the object being stored into, |map| is the Map object |
| 227 | // that was stored. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 228 | void RecordWriteForMap(Register object, Handle<Map> map, Register scratch1, |
| 229 | Register scratch2, SaveFPRegsMode save_fp); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 231 | // --------------------------------------------------------------------------- |
| 232 | // Debugger Support |
| 233 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 234 | void DebugBreak(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 235 | |
| 236 | // Generates function and stub prologue code. |
| 237 | void StubPrologue(); |
| 238 | void Prologue(bool code_pre_aging); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 239 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 240 | // Enter specific kind of exit frame. Expects the number of |
| 241 | // arguments in register eax and sets up the number of arguments in |
| 242 | // register edi and the pointer to the first argument in register |
| 243 | // esi. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 244 | void EnterExitFrame(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 245 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 246 | void EnterApiExitFrame(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 247 | |
| 248 | // Leave the current exit frame. Expects the return value in |
| 249 | // register eax:edx (untouched) and the pointer to the first |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 250 | // argument in register esi (if pop_arguments == true). |
| 251 | void LeaveExitFrame(bool save_doubles, bool pop_arguments = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 252 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 253 | // Leave the current exit frame. Expects the return value in |
| 254 | // register eax (untouched). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 255 | void LeaveApiExitFrame(bool restore_context); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 256 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 257 | // Find the function context up the context chain. |
| 258 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 259 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | // Load the global proxy from the current context. |
| 261 | void LoadGlobalProxy(Register dst); |
| 262 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 263 | // Conditionally load the cached Array transitioned map of type |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 264 | // transitioned_kind from the native context if the map in register |
| 265 | // 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] | 266 | // expected_kind. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 267 | void LoadTransitionedArrayMapConditional(ElementsKind expected_kind, |
| 268 | ElementsKind transitioned_kind, |
| 269 | Register map_in_out, |
| 270 | Register scratch, |
| 271 | Label* no_map_match); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 272 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 273 | // Load the global function with the given index. |
| 274 | void LoadGlobalFunction(int index, Register function); |
| 275 | |
| 276 | // Load the initial map from the global function. The registers |
| 277 | // function and map can be the same. |
| 278 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 279 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 280 | // Push and pop the registers that can hold pointers. |
| 281 | void PushSafepointRegisters() { pushad(); } |
| 282 | void PopSafepointRegisters() { popad(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 283 | // Store the value in register/immediate src in the safepoint |
| 284 | // register stack slot for register dst. |
| 285 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
| 286 | void StoreToSafepointRegisterSlot(Register dst, Immediate src); |
| 287 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 288 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 289 | // Nop, because ia32 does not have a root register. |
| 290 | void InitializeRootRegister() {} |
| 291 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 292 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | void CmpHeapObject(Register reg, Handle<HeapObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 294 | void PushHeapObject(Handle<HeapObject> object); |
| 295 | |
| 296 | void LoadObject(Register result, Handle<Object> object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 297 | AllowDeferredHandleDereference heap_object_check; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 298 | if (object->IsHeapObject()) { |
| 299 | LoadHeapObject(result, Handle<HeapObject>::cast(object)); |
| 300 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | Move(result, Immediate(object)); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void CmpObject(Register reg, Handle<Object> object) { |
| 306 | AllowDeferredHandleDereference heap_object_check; |
| 307 | if (object->IsHeapObject()) { |
| 308 | CmpHeapObject(reg, Handle<HeapObject>::cast(object)); |
| 309 | } else { |
| 310 | cmp(reg, Immediate(object)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 314 | // Compare the given value and the value of weak cell. |
| 315 | void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch); |
| 316 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 317 | void GetWeakValue(Register value, Handle<WeakCell> cell); |
| 318 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 319 | // Load the value of the weak cell in the value register. Branch to the given |
| 320 | // miss label if the weak cell was cleared. |
| 321 | void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss); |
| 322 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 323 | // --------------------------------------------------------------------------- |
| 324 | // JavaScript invokes |
| 325 | |
| 326 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 327 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 328 | void InvokeFunctionCode(Register function, Register new_target, |
| 329 | const ParameterCount& expected, |
| 330 | const ParameterCount& actual, InvokeFlag flag, |
| 331 | const CallWrapper& call_wrapper); |
| 332 | |
| 333 | void FloodFunctionIfStepping(Register fun, Register new_target, |
| 334 | const ParameterCount& expected, |
| 335 | const ParameterCount& actual); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 336 | |
| 337 | // Invoke the JavaScript function in the given register. Changes the |
| 338 | // current context to the context in the function before invoking. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 339 | void InvokeFunction(Register function, Register new_target, |
| 340 | const ParameterCount& actual, InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 341 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | void InvokeFunction(Register function, const ParameterCount& expected, |
| 344 | const ParameterCount& actual, InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 345 | const CallWrapper& call_wrapper); |
| 346 | |
| 347 | void InvokeFunction(Handle<JSFunction> function, |
| 348 | const ParameterCount& expected, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 349 | const ParameterCount& actual, InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 350 | const CallWrapper& call_wrapper); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 351 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 352 | // Expression support |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 353 | // cvtsi2sd instruction only writes to the low 64-bit of dst register, which |
| 354 | // hinders register renaming and makes dependence chains longer. So we use |
| 355 | // xorps to clear the dst register before cvtsi2sd to solve this issue. |
| 356 | void Cvtsi2sd(XMMRegister dst, Register src) { Cvtsi2sd(dst, Operand(src)); } |
| 357 | void Cvtsi2sd(XMMRegister dst, const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 359 | void Cvtui2ss(XMMRegister dst, Register src, Register tmp); |
| 360 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 361 | // Support for constant splitting. |
| 362 | bool IsUnsafeImmediate(const Immediate& x); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | void SafeMove(Register dst, const Immediate& x); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 364 | void SafePush(const Immediate& x); |
| 365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | // Compare object type for heap object. |
| 367 | // Incoming register is heap_object and outgoing register is map. |
| 368 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 369 | |
| 370 | // Compare instance type for map. |
| 371 | void CmpInstanceType(Register map, InstanceType type); |
| 372 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 373 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 374 | // Jump to the specified label if it does not. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 375 | void CheckFastElements(Register map, Label* fail, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 376 | Label::Distance distance = Label::kFar); |
| 377 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 378 | // Check if a map for a JSObject indicates that the object can have both smi |
| 379 | // and HeapObject elements. Jump to the specified label if it does not. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 380 | void CheckFastObjectElements(Register map, Label* fail, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 381 | Label::Distance distance = Label::kFar); |
| 382 | |
| 383 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 384 | // elements. Jump to the specified label if it does not. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 385 | void CheckFastSmiElements(Register map, Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 386 | Label::Distance distance = Label::kFar); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 387 | |
| 388 | // Check to see if maybe_number can be stored as a double in |
| 389 | // FastDoubleElements. If it can, store it at the index specified by key in |
| 390 | // the FastDoubleElements array elements, otherwise jump to fail. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 391 | void StoreNumberToDoubleElements(Register maybe_number, Register elements, |
| 392 | Register key, Register scratch1, |
| 393 | XMMRegister scratch2, Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | int offset = 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 395 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 396 | // Compare an object's map with the specified map. |
| 397 | void CompareMap(Register obj, Handle<Map> map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 398 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 399 | // Check if the map of an object is equal to a specified map and branch to |
| 400 | // label if not. Skip the smi check if not required (object is known to be a |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 401 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
| 402 | // against maps that are ElementsKind transition maps of the specified map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 403 | void CheckMap(Register obj, Handle<Map> map, Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | SmiCheckType smi_check_type); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 405 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 406 | // Check if the map of an object is equal to a specified weak map and branch |
| 407 | // to a specified target if equal. Skip the smi check if not required |
| 408 | // (object is known to be a heap object) |
| 409 | void DispatchWeakMap(Register obj, Register scratch1, Register scratch2, |
| 410 | Handle<WeakCell> cell, Handle<Code> success, |
| 411 | SmiCheckType smi_check_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 412 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 413 | // Check if the object in register heap_object is a string. Afterwards the |
| 414 | // register map contains the object map and the register instance_type |
| 415 | // contains the instance_type. The registers map and instance_type can be the |
| 416 | // same in which case it contains the instance type afterwards. Either of the |
| 417 | // registers map and instance_type can be the same as heap_object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | Condition IsObjectStringType(Register heap_object, Register map, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 419 | Register instance_type); |
| 420 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 421 | // Check if the object in register heap_object is a name. Afterwards the |
| 422 | // register map contains the object map and the register instance_type |
| 423 | // contains the instance_type. The registers map and instance_type can be the |
| 424 | // same in which case it contains the instance type afterwards. Either of the |
| 425 | // registers map and instance_type can be the same as heap_object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 426 | Condition IsObjectNameType(Register heap_object, Register map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | Register instance_type); |
| 428 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 429 | // FCmp is similar to integer cmp, but requires unsigned |
| 430 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 431 | void FCmp(); |
| 432 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 433 | void ClampUint8(Register reg); |
| 434 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 435 | void ClampDoubleToUint8(XMMRegister input_reg, XMMRegister scratch_reg, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 436 | Register result_reg); |
| 437 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | void SlowTruncateToI(Register result_reg, Register input_reg, |
| 439 | int offset = HeapNumber::kValueOffset - kHeapObjectTag); |
| 440 | |
| 441 | void TruncateHeapNumberToI(Register result_reg, Register input_reg); |
| 442 | void TruncateDoubleToI(Register result_reg, XMMRegister input_reg); |
| 443 | |
| 444 | void DoubleToI(Register result_reg, XMMRegister input_reg, |
| 445 | XMMRegister scratch, MinusZeroMode minus_zero_mode, |
| 446 | Label* lost_precision, Label* is_nan, Label* minus_zero, |
| 447 | Label::Distance dst = Label::kFar); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 448 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 449 | // Smi tagging support. |
| 450 | void SmiTag(Register reg) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 451 | STATIC_ASSERT(kSmiTag == 0); |
| 452 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 453 | add(reg, reg); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 454 | } |
| 455 | void SmiUntag(Register reg) { |
| 456 | sar(reg, kSmiTagSize); |
| 457 | } |
| 458 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 459 | // Modifies the register even if it does not contain a Smi! |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 460 | void SmiUntag(Register reg, Label* is_smi) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 461 | STATIC_ASSERT(kSmiTagSize == 1); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 462 | sar(reg, kSmiTagSize); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 463 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 464 | j(not_carry, is_smi); |
| 465 | } |
| 466 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 467 | void LoadUint32(XMMRegister dst, Register src) { |
| 468 | LoadUint32(dst, Operand(src)); |
| 469 | } |
| 470 | void LoadUint32(XMMRegister dst, const Operand& src); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 471 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 472 | // Jump the register contains a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 473 | inline void JumpIfSmi(Register value, Label* smi_label, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 474 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 475 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 476 | j(zero, smi_label, distance); |
| 477 | } |
| 478 | // Jump if the operand is a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 479 | inline void JumpIfSmi(Operand value, Label* smi_label, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 480 | Label::Distance distance = Label::kFar) { |
| 481 | test(value, Immediate(kSmiTagMask)); |
| 482 | j(zero, smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 483 | } |
| 484 | // Jump if register contain a non-smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 485 | inline void JumpIfNotSmi(Register value, Label* not_smi_label, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 486 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 487 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 488 | j(not_zero, not_smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 489 | } |
| 490 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 491 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 492 | void EnumLength(Register dst, Register map); |
| 493 | void NumberOfOwnDescriptors(Register dst, Register map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 494 | void LoadAccessor(Register dst, Register holder, int accessor_index, |
| 495 | AccessorComponent accessor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 496 | |
| 497 | template<typename Field> |
| 498 | void DecodeField(Register reg) { |
| 499 | static const int shift = Field::kShift; |
| 500 | static const int mask = Field::kMask >> Field::kShift; |
| 501 | if (shift != 0) { |
| 502 | sar(reg, shift); |
| 503 | } |
| 504 | and_(reg, Immediate(mask)); |
| 505 | } |
| 506 | |
| 507 | template<typename Field> |
| 508 | void DecodeFieldToSmi(Register reg) { |
| 509 | static const int shift = Field::kShift; |
| 510 | static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize; |
| 511 | STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0); |
| 512 | STATIC_ASSERT(kSmiTag == 0); |
| 513 | if (shift < kSmiTagSize) { |
| 514 | shl(reg, kSmiTagSize - shift); |
| 515 | } else if (shift > kSmiTagSize) { |
| 516 | sar(reg, shift - kSmiTagSize); |
| 517 | } |
| 518 | and_(reg, Immediate(mask)); |
| 519 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 520 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 521 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 522 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 523 | // Abort execution if argument is not a number, enabled via --debug-code. |
| 524 | void AssertNumber(Register object); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 525 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | // Abort execution if argument is not a smi, enabled via --debug-code. |
| 527 | void AssertSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 528 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | // Abort execution if argument is a smi, enabled via --debug-code. |
| 530 | void AssertNotSmi(Register object); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | // Abort execution if argument is not a string, enabled via --debug-code. |
| 533 | void AssertString(Register object); |
| 534 | |
| 535 | // Abort execution if argument is not a name, enabled via --debug-code. |
| 536 | void AssertName(Register object); |
| 537 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 538 | // Abort execution if argument is not a JSFunction, enabled via --debug-code. |
| 539 | void AssertFunction(Register object); |
| 540 | |
| 541 | // Abort execution if argument is not a JSBoundFunction, |
| 542 | // enabled via --debug-code. |
| 543 | void AssertBoundFunction(Register object); |
| 544 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 545 | // Abort execution if argument is not a JSReceiver, enabled via --debug-code. |
| 546 | void AssertReceiver(Register object); |
| 547 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 548 | // Abort execution if argument is not undefined or an AllocationSite, enabled |
| 549 | // via --debug-code. |
| 550 | void AssertUndefinedOrAllocationSite(Register object); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 551 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | // --------------------------------------------------------------------------- |
| 553 | // Exception handling |
| 554 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 555 | // Push a new stack handler and link it into stack handler chain. |
| 556 | void PushStackHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 558 | // Unlink the stack handler on top of the stack from the stack handler chain. |
| 559 | void PopStackHandler(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 560 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 561 | // --------------------------------------------------------------------------- |
| 562 | // Inline caching support |
| 563 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | // Generate code for checking access rights - used for security checks |
| 565 | // on access to global objects across environments. The holder register |
| 566 | // is left untouched, but the scratch register is clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 567 | void CheckAccessGlobalProxy(Register holder_reg, Register scratch1, |
| 568 | Register scratch2, Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 569 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 570 | void GetNumberHash(Register r0, Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 572 | void LoadFromNumberDictionary(Label* miss, Register elements, Register key, |
| 573 | Register r0, Register r1, Register r2, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 574 | Register result); |
| 575 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 576 | // --------------------------------------------------------------------------- |
| 577 | // Allocation support |
| 578 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 579 | // Allocate an object in new space or old space. If the given space |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 580 | // is exhausted control continues at the gc_required label. The allocated |
| 581 | // object is returned in result and end of the new object is returned in |
| 582 | // result_end. The register scratch can be passed as no_reg in which case |
| 583 | // an additional object reference will be added to the reloc info. The |
| 584 | // returned pointers in result and result_end have not yet been tagged as |
| 585 | // heap objects. If result_contains_top_on_entry is true the content of |
| 586 | // result is known to be the allocation top on entry (could be result_end |
| 587 | // 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] | 588 | // should be no_reg as it is never used. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 589 | void Allocate(int object_size, Register result, Register result_end, |
| 590 | Register scratch, Label* gc_required, AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 591 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 592 | void Allocate(int header_size, ScaleFactor element_size, |
| 593 | Register element_count, RegisterValueType element_count_type, |
| 594 | Register result, Register result_end, Register scratch, |
| 595 | Label* gc_required, AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 597 | void Allocate(Register object_size, Register result, Register result_end, |
| 598 | Register scratch, Label* gc_required, AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 599 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 600 | // Allocate a heap number in new space with undefined value. The |
| 601 | // register scratch2 can be passed as no_reg; the others must be |
| 602 | // valid registers. Returns tagged pointer in result register, or |
| 603 | // jumps to gc_required if new space is full. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 604 | void AllocateHeapNumber(Register result, Register scratch1, Register scratch2, |
| 605 | Label* gc_required, MutableMode mode = IMMUTABLE); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 606 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 607 | // Allocate a sequential string. All the header fields of the string object |
| 608 | // are initialized. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 609 | void AllocateTwoByteString(Register result, Register length, |
| 610 | Register scratch1, Register scratch2, |
| 611 | Register scratch3, Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 612 | void AllocateOneByteString(Register result, Register length, |
| 613 | Register scratch1, Register scratch2, |
| 614 | Register scratch3, Label* gc_required); |
| 615 | void AllocateOneByteString(Register result, int length, Register scratch1, |
| 616 | Register scratch2, Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 617 | |
| 618 | // Allocate a raw cons string object. Only the map field of the result is |
| 619 | // initialized. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 620 | void AllocateTwoByteConsString(Register result, Register scratch1, |
| 621 | Register scratch2, Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 622 | void AllocateOneByteConsString(Register result, Register scratch1, |
| 623 | Register scratch2, Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 624 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 625 | // Allocate a raw sliced string object. Only the map field of the result is |
| 626 | // initialized. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 627 | void AllocateTwoByteSlicedString(Register result, Register scratch1, |
| 628 | Register scratch2, Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 629 | void AllocateOneByteSlicedString(Register result, Register scratch1, |
| 630 | Register scratch2, Label* gc_required); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 631 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 632 | // Allocate and initialize a JSValue wrapper with the specified {constructor} |
| 633 | // and {value}. |
| 634 | void AllocateJSValue(Register result, Register constructor, Register value, |
| 635 | Register scratch, Label* gc_required); |
| 636 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 637 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 638 | // long or aligned copies. |
| 639 | // The contents of index and scratch are destroyed. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 640 | void CopyBytes(Register source, Register destination, Register length, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 641 | Register scratch); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 642 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 643 | // Initialize fields with filler values. Fields starting at |current_address| |
| 644 | // not including |end_address| are overwritten with the value in |filler|. At |
| 645 | // the end the loop, |current_address| takes the value of |end_address|. |
| 646 | void InitializeFieldsWithFiller(Register current_address, |
| 647 | Register end_address, Register filler); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 648 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 649 | // --------------------------------------------------------------------------- |
| 650 | // Support functions. |
| 651 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 652 | // Check a boolean-bit of a Smi field. |
| 653 | void BooleanBitTest(Register object, int field_offset, int bit_index); |
| 654 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 655 | // Check if result is zero and op is negative. |
| 656 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 657 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 658 | // Check if result is zero and any of op1 and op2 are negative. |
| 659 | // Register scratch is destroyed, and it must be different from op2. |
| 660 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 661 | Register scratch, Label* then_label); |
| 662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 663 | // Machine code version of Map::GetConstructor(). |
| 664 | // |temp| holds |result|'s map when done. |
| 665 | void GetMapConstructor(Register result, Register map, Register temp); |
| 666 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 667 | // Try to get function prototype of a function and puts the value in |
| 668 | // the result register. Checks that the function really is a |
| 669 | // function and jumps to the miss label if the fast checks fail. The |
| 670 | // function register will be untouched; the other registers may be |
| 671 | // clobbered. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 672 | void TryGetFunctionPrototype(Register function, Register result, |
| 673 | Register scratch, Label* miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 674 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 675 | // Picks out an array index from the hash field. |
| 676 | // Register use: |
| 677 | // hash - holds the index's hash. Clobbered. |
| 678 | // index - holds the overwritten index on exit. |
| 679 | void IndexFromHash(Register hash, Register index); |
| 680 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 681 | // --------------------------------------------------------------------------- |
| 682 | // Runtime calls |
| 683 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 684 | // Call a code stub. Generate the code if necessary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 685 | void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 686 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 687 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 688 | void TailCallStub(CodeStub* stub); |
| 689 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 690 | // Return from a code stub after popping its arguments. |
| 691 | void StubReturn(int argc); |
| 692 | |
| 693 | // Call a runtime routine. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 694 | void CallRuntime(const Runtime::Function* f, int num_arguments, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 695 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 696 | void CallRuntimeSaveDoubles(Runtime::FunctionId fid) { |
| 697 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 698 | CallRuntime(function, function->nargs, kSaveFPRegs); |
| 699 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | |
| 701 | // Convenience function: Same as above, but takes the fid instead. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 702 | void CallRuntime(Runtime::FunctionId fid, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 703 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 704 | const Runtime::Function* function = Runtime::FunctionForId(fid); |
| 705 | CallRuntime(function, function->nargs, save_doubles); |
| 706 | } |
| 707 | |
| 708 | // Convenience function: Same as above, but takes the fid instead. |
| 709 | void CallRuntime(Runtime::FunctionId fid, int num_arguments, |
| 710 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 711 | CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 712 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 714 | // Convenience function: call an external reference. |
| 715 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 716 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 717 | // Convenience function: tail call a runtime routine (jump). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 718 | void TailCallRuntime(Runtime::FunctionId fid); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 720 | // Before calling a C-function from generated code, align arguments on stack. |
| 721 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 722 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 723 | // Some compilers/platforms require the stack to be aligned when calling |
| 724 | // C++ code. |
| 725 | // Needs a scratch register to do some arithmetic. This register will be |
| 726 | // trashed. |
| 727 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 728 | |
| 729 | // Calls a C function and cleans up the space for arguments allocated |
| 730 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 731 | // garbage collection, since that might move the code and invalidate the |
| 732 | // return address (unless this is somehow accounted for by the called |
| 733 | // function). |
| 734 | void CallCFunction(ExternalReference function, int num_arguments); |
| 735 | void CallCFunction(Register function, int num_arguments); |
| 736 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 737 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 738 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 739 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 740 | // --------------------------------------------------------------------------- |
| 741 | // Utilities |
| 742 | |
| 743 | void Ret(); |
| 744 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 745 | // Return and drop arguments from stack, where the number of arguments |
| 746 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 747 | void Ret(int bytes_dropped, Register scratch); |
| 748 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 749 | // Emit code to discard a non-negative number of pointer-sized elements |
| 750 | // from the stack, clobbering only the esp register. |
| 751 | void Drop(int element_count); |
| 752 | |
| 753 | void Call(Label* target) { call(target); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 754 | void Call(Handle<Code> target, RelocInfo::Mode rmode) { call(target, rmode); } |
| 755 | void Jump(Handle<Code> target, RelocInfo::Mode rmode) { jmp(target, rmode); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | void Push(Register src) { push(src); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 757 | void Push(const Operand& src) { push(src); } |
| 758 | void Push(Immediate value) { push(value); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 759 | void Pop(Register dst) { pop(dst); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 760 | void Pop(const Operand& dst) { pop(dst); } |
| 761 | void PushReturnAddressFrom(Register src) { push(src); } |
| 762 | void PopReturnAddressTo(Register dst) { pop(dst); } |
| 763 | |
| 764 | // Non-SSE2 instructions. |
| 765 | void Pextrd(Register dst, XMMRegister src, int8_t imm8); |
| 766 | void Pinsrd(XMMRegister dst, Register src, int8_t imm8) { |
| 767 | Pinsrd(dst, Operand(src), imm8); |
| 768 | } |
| 769 | void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8); |
| 770 | |
| 771 | void Lzcnt(Register dst, Register src) { Lzcnt(dst, Operand(src)); } |
| 772 | void Lzcnt(Register dst, const Operand& src); |
| 773 | |
| 774 | void Tzcnt(Register dst, Register src) { Tzcnt(dst, Operand(src)); } |
| 775 | void Tzcnt(Register dst, const Operand& src); |
| 776 | |
| 777 | void Popcnt(Register dst, Register src) { Popcnt(dst, Operand(src)); } |
| 778 | void Popcnt(Register dst, const Operand& src); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 779 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 780 | // Emit call to the code we are currently generating. |
| 781 | void CallSelf() { |
| 782 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 783 | call(self, RelocInfo::CODE_TARGET); |
| 784 | } |
| 785 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 786 | // Move if the registers are not identical. |
| 787 | void Move(Register target, Register source); |
| 788 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 789 | // Move a constant into a destination using the most efficient encoding. |
| 790 | void Move(Register dst, const Immediate& x); |
| 791 | void Move(const Operand& dst, const Immediate& x); |
| 792 | |
| 793 | // Move an immediate into an XMM register. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 794 | void Move(XMMRegister dst, uint32_t src); |
| 795 | void Move(XMMRegister dst, uint64_t src); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 796 | void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 797 | void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 798 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 799 | void Move(Register dst, Smi* source) { Move(dst, Immediate(source)); } |
| 800 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 801 | // Push a handle value. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 802 | void Push(Handle<Object> handle) { push(Immediate(handle)); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 803 | void Push(Smi* smi) { Push(Immediate(smi)); } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 804 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 805 | Handle<Object> CodeObject() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 806 | DCHECK(!code_object_.is_null()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 807 | return code_object_; |
| 808 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 809 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 810 | // Emit code for a truncating division by a constant. The dividend register is |
| 811 | // unchanged, the result is in edx, and eax gets clobbered. |
| 812 | void TruncatingDiv(Register dividend, int32_t divisor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 813 | |
| 814 | // --------------------------------------------------------------------------- |
| 815 | // StatsCounter support |
| 816 | |
| 817 | void SetCounter(StatsCounter* counter, int value); |
| 818 | void IncrementCounter(StatsCounter* counter, int value); |
| 819 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 820 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 821 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 823 | // --------------------------------------------------------------------------- |
| 824 | // Debugging |
| 825 | |
| 826 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 827 | // Use --debug_code to enable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | void Assert(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 830 | void AssertFastElements(Register elements); |
| 831 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 832 | // Like Assert(), but always enabled. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 833 | void Check(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | |
| 835 | // Print a message to stdout and abort execution. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 836 | void Abort(BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 837 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 838 | // Check that the stack is aligned. |
| 839 | void CheckStackAlignment(); |
| 840 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 841 | // Verify restrictions about code generated in stubs. |
| 842 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 843 | bool generating_stub() { return generating_stub_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 844 | void set_has_frame(bool value) { has_frame_ = value; } |
| 845 | bool has_frame() { return has_frame_; } |
| 846 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 847 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 848 | // --------------------------------------------------------------------------- |
| 849 | // String utilities. |
| 850 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 851 | // Check whether the instance type represents a flat one-byte string. Jump to |
| 852 | // the label if not. If the instance type can be scratched specify same |
| 853 | // register for both instance type and scratch. |
| 854 | void JumpIfInstanceTypeIsNotSequentialOneByte( |
| 855 | Register instance_type, Register scratch, |
| 856 | Label* on_not_flat_one_byte_string); |
| 857 | |
| 858 | // Checks if both objects are sequential one-byte strings, and jumps to label |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 859 | // if either is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 860 | void JumpIfNotBothSequentialOneByteStrings( |
| 861 | Register object1, Register object2, Register scratch1, Register scratch2, |
| 862 | Label* on_not_flat_one_byte_strings); |
| 863 | |
| 864 | // Checks if the given register or operand is a unique name |
| 865 | void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name, |
| 866 | Label::Distance distance = Label::kFar) { |
| 867 | JumpIfNotUniqueNameInstanceType(Operand(reg), not_unique_name, distance); |
| 868 | } |
| 869 | |
| 870 | void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name, |
| 871 | Label::Distance distance = Label::kFar); |
| 872 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 873 | void EmitSeqStringSetCharCheck(Register string, Register index, |
| 874 | Register value, uint32_t encoding_mask); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 875 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 876 | static int SafepointRegisterStackIndex(Register reg) { |
| 877 | return SafepointRegisterStackIndex(reg.code()); |
| 878 | } |
| 879 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 880 | // Load the type feedback vector from a JavaScript frame. |
| 881 | void EmitLoadTypeFeedbackVector(Register vector); |
| 882 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 883 | // Activation support. |
| 884 | void EnterFrame(StackFrame::Type type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 885 | void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 886 | void LeaveFrame(StackFrame::Type type); |
| 887 | |
| 888 | // Expects object in eax and returns map with validated enum cache |
| 889 | // in eax. Assumes that any other register can be used as a scratch. |
| 890 | void CheckEnumCache(Label* call_runtime); |
| 891 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 892 | // AllocationMemento support. Arrays may have an associated |
| 893 | // AllocationMemento object that can be checked for in order to pretransition |
| 894 | // to another type. |
| 895 | // On entry, receiver_reg should point to the array object. |
| 896 | // scratch_reg gets clobbered. |
| 897 | // If allocation info is present, conditional code is set to equal. |
| 898 | void TestJSArrayForAllocationMemento(Register receiver_reg, |
| 899 | Register scratch_reg, |
| 900 | Label* no_memento_found); |
| 901 | |
| 902 | void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, |
| 903 | Register scratch_reg, |
| 904 | Label* memento_found) { |
| 905 | Label no_memento_found; |
| 906 | TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, |
| 907 | &no_memento_found); |
| 908 | j(equal, memento_found); |
| 909 | bind(&no_memento_found); |
| 910 | } |
| 911 | |
| 912 | // Jumps to found label if a prototype map has dictionary elements. |
| 913 | void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0, |
| 914 | Register scratch1, Label* found); |
| 915 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 916 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 917 | bool generating_stub_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 918 | bool has_frame_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 919 | // This handle will be patched with the code object on installation. |
| 920 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 921 | |
| 922 | // Helper functions for generating invokes. |
| 923 | void InvokePrologue(const ParameterCount& expected, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 924 | const ParameterCount& actual, Label* done, |
| 925 | bool* definitely_mismatches, InvokeFlag flag, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 926 | Label::Distance done_distance, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 927 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 928 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 929 | void EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 930 | void EnterExitFrameEpilogue(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 931 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 932 | void LeaveExitFrameEpilogue(bool restore_context); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 933 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | // Allocation support helpers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 935 | void LoadAllocationTopHelper(Register result, Register scratch, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 936 | AllocationFlags flags); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 937 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 938 | void UpdateAllocationTopHelper(Register result_end, Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | AllocationFlags flags); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 940 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 941 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | void InNewSpace(Register object, Register scratch, Condition cc, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 943 | Label* condition_met, |
| 944 | Label::Distance condition_met_distance = Label::kFar); |
| 945 | |
| 946 | // Helper for finding the mark bits for an address. Afterwards, the |
| 947 | // bitmap register points at the word with the mark bits and the mask |
| 948 | // the position of the first bit. Uses ecx as scratch and leaves addr_reg |
| 949 | // unchanged. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 950 | inline void GetMarkBits(Register addr_reg, Register bitmap_reg, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 951 | Register mask_reg); |
| 952 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 953 | // Compute memory operands for safepoint stack slots. |
| 954 | Operand SafepointRegisterSlot(Register reg); |
| 955 | static int SafepointRegisterStackIndex(int reg_code); |
| 956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 957 | // Needs access to SafepointRegisterStackIndex for compiled frame |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 958 | // traversal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 959 | friend class StandardFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 960 | }; |
| 961 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 962 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 963 | // debugging and other types of instrumentation. When using the code patcher |
| 964 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 965 | // relocation information. If any of these constraints are violated it causes |
| 966 | // an assertion. |
| 967 | class CodePatcher { |
| 968 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 969 | CodePatcher(Isolate* isolate, byte* address, int size); |
| 970 | ~CodePatcher(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 971 | |
| 972 | // Macro assembler to emit code. |
| 973 | MacroAssembler* masm() { return &masm_; } |
| 974 | |
| 975 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 976 | byte* address_; // The address of the code being patched. |
| 977 | int size_; // Number of bytes of the expected patch size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 978 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 979 | }; |
| 980 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | // ----------------------------------------------------------------------------- |
| 982 | // Static helper functions. |
| 983 | |
| 984 | // Generate an Operand for loading a field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 985 | inline Operand FieldOperand(Register object, int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | return Operand(object, offset - kHeapObjectTag); |
| 987 | } |
| 988 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 989 | // Generate an Operand for loading an indexed field from an object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 990 | inline Operand FieldOperand(Register object, Register index, ScaleFactor scale, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 991 | int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 992 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 993 | } |
| 994 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 995 | inline Operand FixedArrayElementOperand(Register array, Register index_as_smi, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | int additional_offset = 0) { |
| 997 | int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize; |
| 998 | return FieldOperand(array, index_as_smi, times_half_pointer_size, offset); |
| 999 | } |
| 1000 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1001 | inline Operand ContextOperand(Register context, int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1002 | return Operand(context, Context::SlotOffset(index)); |
| 1003 | } |
| 1004 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1005 | inline Operand ContextOperand(Register context, Register index) { |
| 1006 | return Operand(context, index, times_pointer_size, Context::SlotOffset(0)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1009 | inline Operand NativeContextOperand() { |
| 1010 | return ContextOperand(esi, Context::NATIVE_CONTEXT_INDEX); |
| 1011 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1012 | |
| 1013 | #ifdef GENERATED_CODE_COVERAGE |
| 1014 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 1015 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1016 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1017 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1018 | #define ACCESS_MASM(masm) { \ |
| 1019 | byte* ia32_coverage_function = \ |
| 1020 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 1021 | masm->pushfd(); \ |
| 1022 | masm->pushad(); \ |
| 1023 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 1024 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 1025 | masm->pop(eax); \ |
| 1026 | masm->popad(); \ |
| 1027 | masm->popfd(); \ |
| 1028 | } \ |
| 1029 | masm-> |
| 1030 | #else |
| 1031 | #define ACCESS_MASM(masm) masm-> |
| 1032 | #endif |
| 1033 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1034 | } // namespace internal |
| 1035 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1036 | |
| 1037 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |