erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 28 | #ifndef V8_X64_MACRO_ASSEMBLER_X64_H_ |
| 29 | #define V8_X64_MACRO_ASSEMBLER_X64_H_ |
| 30 | |
| 31 | #include "assembler.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 32 | #include "frames.h" |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 33 | #include "v8globals.h" |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 37 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 38 | // Flags used for the AllocateInNewSpace functions. |
| 39 | enum AllocationFlags { |
| 40 | // No special flags. |
| 41 | NO_ALLOCATION_FLAGS = 0, |
| 42 | // Return the pointer to the allocated already tagged as a heap object. |
| 43 | TAG_OBJECT = 1 << 0, |
| 44 | // The content of the result register already contains the allocation top in |
| 45 | // new space. |
| 46 | RESULT_CONTAINS_TOP = 1 << 1 |
| 47 | }; |
| 48 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 49 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 50 | // Default scratch register used by MacroAssembler (and other code that needs |
| 51 | // a spare register). The register isn't callee save, and not used by the |
| 52 | // function calling convention. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 53 | const Register kScratchRegister = { 10 }; // r10. |
| 54 | const Register kSmiConstantRegister = { 12 }; // r12 (callee save). |
| 55 | const Register kRootRegister = { 13 }; // r13 (callee save). |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 56 | // Value of smi in kSmiConstantRegister. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 57 | const int kSmiConstantRegisterValue = 1; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 58 | // Actual value of root register is offset from the root array's start |
| 59 | // to take advantage of negitive 8-bit displacement values. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 60 | const int kRootRegisterBias = 128; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 61 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 62 | // Convenience for platform-independent signatures. |
| 63 | typedef Operand MemOperand; |
| 64 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 65 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 66 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
| 67 | |
| 68 | bool AreAliased(Register r1, Register r2, Register r3, Register r4); |
| 69 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 70 | // Forward declaration. |
| 71 | class JumpTarget; |
| 72 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 73 | struct SmiIndex { |
| 74 | SmiIndex(Register index_register, ScaleFactor scale) |
| 75 | : reg(index_register), |
| 76 | scale(scale) {} |
| 77 | Register reg; |
| 78 | ScaleFactor scale; |
| 79 | }; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 80 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 81 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 82 | // MacroAssembler implements a collection of frequently used macros. |
| 83 | class MacroAssembler: public Assembler { |
| 84 | public: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 85 | // The isolate parameter can be NULL if the macro assembler should |
| 86 | // not use isolate-dependent functionality. In this case, it's the |
| 87 | // responsibility of the caller to never invoke such function on the |
| 88 | // macro assembler. |
| 89 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 90 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | // Prevent the use of the RootArray during the lifetime of this |
| 92 | // scope object. |
| 93 | class NoRootArrayScope BASE_EMBEDDED { |
| 94 | public: |
| 95 | explicit NoRootArrayScope(MacroAssembler* assembler) |
| 96 | : variable_(&assembler->root_array_available_), |
| 97 | old_value_(assembler->root_array_available_) { |
| 98 | assembler->root_array_available_ = false; |
| 99 | } |
| 100 | ~NoRootArrayScope() { |
| 101 | *variable_ = old_value_; |
| 102 | } |
| 103 | private: |
| 104 | bool* variable_; |
| 105 | bool old_value_; |
| 106 | }; |
| 107 | |
| 108 | // Operand pointing to an external reference. |
| 109 | // May emit code to set up the scratch register. The operand is |
| 110 | // only guaranteed to be correct as long as the scratch register |
| 111 | // isn't changed. |
| 112 | // If the operand is used more than once, use a scratch register |
| 113 | // that is guaranteed not to be clobbered. |
| 114 | Operand ExternalOperand(ExternalReference reference, |
| 115 | Register scratch = kScratchRegister); |
| 116 | // Loads and stores the value of an external reference. |
| 117 | // Special case code for load and store to take advantage of |
| 118 | // load_rax/store_rax if possible/necessary. |
| 119 | // For other operations, just use: |
| 120 | // Operand operand = ExternalOperand(extref); |
| 121 | // operation(operand, ..); |
| 122 | void Load(Register destination, ExternalReference source); |
| 123 | void Store(ExternalReference destination, Register source); |
| 124 | // Loads the address of the external reference into the destination |
| 125 | // register. |
| 126 | void LoadAddress(Register destination, ExternalReference source); |
| 127 | // Returns the size of the code generated by LoadAddress. |
| 128 | // Used by CallSize(ExternalReference) to find the size of a call. |
| 129 | int LoadAddressSize(ExternalReference source); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame^] | 130 | // Pushes the address of the external reference onto the stack. |
| 131 | void PushAddress(ExternalReference source); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 132 | |
| 133 | // Operations on roots in the root-array. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 134 | void LoadRoot(Register destination, Heap::RootListIndex index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 135 | void StoreRoot(Register source, Heap::RootListIndex index); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 136 | // Load a root value where the index (or part of it) is variable. |
| 137 | // The variable_offset register is added to the fixed_offset value |
| 138 | // to get the index into the root-array. |
| 139 | void LoadRootIndexed(Register destination, |
| 140 | Register variable_offset, |
| 141 | int fixed_offset); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 142 | void CompareRoot(Register with, Heap::RootListIndex index); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 143 | void CompareRoot(const Operand& with, Heap::RootListIndex index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 144 | void PushRoot(Heap::RootListIndex index); |
| 145 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 146 | // These functions do not arrange the registers in any particular order so |
| 147 | // they are not useful for calls that can cause a GC. The caller can |
| 148 | // exclude up to 3 registers that do not need to be saved and restored. |
| 149 | void PushCallerSaved(SaveFPRegsMode fp_mode, |
| 150 | Register exclusion1 = no_reg, |
| 151 | Register exclusion2 = no_reg, |
| 152 | Register exclusion3 = no_reg); |
| 153 | void PopCallerSaved(SaveFPRegsMode fp_mode, |
| 154 | Register exclusion1 = no_reg, |
| 155 | Register exclusion2 = no_reg, |
| 156 | Register exclusion3 = no_reg); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 157 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 158 | // --------------------------------------------------------------------------- |
| 159 | // GC Support |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 160 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 161 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 162 | enum RememberedSetFinalAction { |
| 163 | kReturnAtEnd, |
| 164 | kFallThroughAtEnd |
| 165 | }; |
| 166 | |
| 167 | // Record in the remembered set the fact that we have a pointer to new space |
| 168 | // at the address pointed to by the addr register. Only works if addr is not |
| 169 | // in new space. |
| 170 | void RememberedSetHelper(Register object, // Used for debug code. |
| 171 | Register addr, |
| 172 | Register scratch, |
| 173 | SaveFPRegsMode save_fp, |
| 174 | RememberedSetFinalAction and_then); |
| 175 | |
| 176 | void CheckPageFlag(Register object, |
| 177 | Register scratch, |
| 178 | int mask, |
| 179 | Condition cc, |
| 180 | Label* condition_met, |
| 181 | Label::Distance condition_met_distance = Label::kFar); |
| 182 | |
| 183 | // Check if object is in new space. Jumps if the object is not in new space. |
| 184 | // The register scratch can be object itself, but scratch will be clobbered. |
| 185 | void JumpIfNotInNewSpace(Register object, |
| 186 | Register scratch, |
| 187 | Label* branch, |
| 188 | Label::Distance distance = Label::kFar) { |
| 189 | InNewSpace(object, scratch, not_equal, branch, distance); |
| 190 | } |
| 191 | |
| 192 | // Check if object is in new space. Jumps if the object is in new space. |
| 193 | // The register scratch can be object itself, but it will be clobbered. |
| 194 | void JumpIfInNewSpace(Register object, |
| 195 | Register scratch, |
| 196 | Label* branch, |
| 197 | Label::Distance distance = Label::kFar) { |
| 198 | InNewSpace(object, scratch, equal, branch, distance); |
| 199 | } |
| 200 | |
| 201 | // Check if an object has the black incremental marking color. Also uses rcx! |
| 202 | void JumpIfBlack(Register object, |
| 203 | Register scratch0, |
| 204 | Register scratch1, |
| 205 | Label* on_black, |
| 206 | Label::Distance on_black_distance = Label::kFar); |
| 207 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 208 | // Detects conservatively whether an object is data-only, i.e. it does need to |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 209 | // be scanned by the garbage collector. |
| 210 | void JumpIfDataObject(Register value, |
| 211 | Register scratch, |
| 212 | Label* not_data_object, |
| 213 | Label::Distance not_data_object_distance); |
| 214 | |
| 215 | // Checks the color of an object. If the object is already grey or black |
| 216 | // then we just fall through, since it is already live. If it is white and |
| 217 | // we can determine that it doesn't need to be scanned, then we just mark it |
| 218 | // black and fall through. For the rest we jump to the label so the |
| 219 | // incremental marker can fix its assumptions. |
| 220 | void EnsureNotWhite(Register object, |
| 221 | Register scratch1, |
| 222 | Register scratch2, |
| 223 | Label* object_is_white_and_not_data, |
| 224 | Label::Distance distance); |
| 225 | |
| 226 | // Notify the garbage collector that we wrote a pointer into an object. |
| 227 | // |object| is the object being stored into, |value| is the object being |
| 228 | // stored. value and scratch registers are clobbered by the operation. |
| 229 | // The offset is the offset from the start of the object, not the offset from |
| 230 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 231 | void RecordWriteField( |
| 232 | Register object, |
| 233 | int offset, |
| 234 | Register value, |
| 235 | Register scratch, |
| 236 | SaveFPRegsMode save_fp, |
| 237 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 238 | SmiCheck smi_check = INLINE_SMI_CHECK); |
| 239 | |
| 240 | // As above, but the offset has the tag presubtracted. For use with |
| 241 | // Operand(reg, off). |
| 242 | void RecordWriteContextSlot( |
| 243 | Register context, |
| 244 | int offset, |
| 245 | Register value, |
| 246 | Register scratch, |
| 247 | SaveFPRegsMode save_fp, |
| 248 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 249 | SmiCheck smi_check = INLINE_SMI_CHECK) { |
| 250 | RecordWriteField(context, |
| 251 | offset + kHeapObjectTag, |
| 252 | value, |
| 253 | scratch, |
| 254 | save_fp, |
| 255 | remembered_set_action, |
| 256 | smi_check); |
| 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 |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 261 | // object being stored. |index| is the array index represented as a non-smi. |
| 262 | // All registers are clobbered by the operation RecordWriteArray |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 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, |
| 271 | SmiCheck smi_check = INLINE_SMI_CHECK); |
| 272 | |
| 273 | // For page containing |object| mark region covering |address| |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 274 | // dirty. |object| is the object being stored into, |value| is the |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 275 | // object being stored. The address and value registers are clobbered by the |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 276 | // operation. RecordWrite filters out smis so it does not update |
| 277 | // the write barrier if the value is a smi. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 278 | void RecordWrite( |
| 279 | Register object, |
| 280 | Register address, |
| 281 | Register value, |
| 282 | SaveFPRegsMode save_fp, |
| 283 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 284 | SmiCheck smi_check = INLINE_SMI_CHECK); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 285 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 286 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 287 | // --------------------------------------------------------------------------- |
| 288 | // Debugger Support |
| 289 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 290 | void DebugBreak(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 291 | #endif |
| 292 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 293 | // Enter specific kind of exit frame; either in normal or |
| 294 | // debug mode. Expects the number of arguments in register rax and |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 295 | // sets up the number of arguments in register rdi and the pointer |
| 296 | // to the first argument in register rsi. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 297 | // |
| 298 | // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack |
| 299 | // accessible via StackSpaceOperand. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 300 | void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 301 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 302 | // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize |
| 303 | // memory (not GCed) on the stack accessible via StackSpaceOperand. |
| 304 | void EnterApiExitFrame(int arg_stack_space); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 305 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 306 | // Leave the current exit frame. Expects/provides the return value in |
| 307 | // register rax:rdx (untouched) and the pointer to the first |
| 308 | // argument in register rsi. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 309 | void LeaveExitFrame(bool save_doubles = false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 310 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 311 | // Leave the current exit frame. Expects/provides the return value in |
| 312 | // register rax (untouched). |
| 313 | void LeaveApiExitFrame(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 314 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 315 | // Push and pop the registers that can hold pointers. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 316 | void PushSafepointRegisters() { Pushad(); } |
| 317 | void PopSafepointRegisters() { Popad(); } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 318 | // Store the value in register src in the safepoint register stack |
| 319 | // slot for register dst. |
| 320 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 321 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 322 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 323 | void InitializeRootRegister() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 324 | ExternalReference roots_array_start = |
| 325 | ExternalReference::roots_array_start(isolate()); |
| 326 | movq(kRootRegister, roots_array_start); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 327 | addq(kRootRegister, Immediate(kRootRegisterBias)); |
| 328 | } |
| 329 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 330 | // --------------------------------------------------------------------------- |
| 331 | // JavaScript invokes |
| 332 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 333 | // Set up call kind marking in rcx. The method takes rcx as an |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 334 | // explicit first parameter to make the code more readable at the |
| 335 | // call sites. |
| 336 | void SetCallKind(Register dst, CallKind kind); |
| 337 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 338 | // Invoke the JavaScript function code by either calling or jumping. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 339 | void InvokeCode(Register code, |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 340 | const ParameterCount& expected, |
| 341 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 342 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 343 | const CallWrapper& call_wrapper, |
| 344 | CallKind call_kind); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 345 | |
| 346 | void InvokeCode(Handle<Code> code, |
| 347 | const ParameterCount& expected, |
| 348 | const ParameterCount& actual, |
| 349 | RelocInfo::Mode rmode, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 350 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 351 | const CallWrapper& call_wrapper, |
| 352 | CallKind call_kind); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 353 | |
| 354 | // Invoke the JavaScript function in the given register. Changes the |
| 355 | // current context to the context in the function before invoking. |
| 356 | void InvokeFunction(Register function, |
| 357 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 358 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 359 | const CallWrapper& call_wrapper, |
| 360 | CallKind call_kind); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 361 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 362 | void InvokeFunction(Handle<JSFunction> function, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 363 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 364 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 365 | const CallWrapper& call_wrapper, |
| 366 | CallKind call_kind); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 367 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 368 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 369 | // the unresolved list if the name does not resolve. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 370 | void InvokeBuiltin(Builtins::JavaScript id, |
| 371 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 372 | const CallWrapper& call_wrapper = NullCallWrapper()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 373 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 374 | // Store the function for the given builtin in the target register. |
| 375 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 376 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 377 | // Store the code object for the given builtin in the target register. |
| 378 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 379 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 380 | |
| 381 | // --------------------------------------------------------------------------- |
| 382 | // Smi tagging, untagging and operations on tagged smis. |
| 383 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 384 | void InitializeSmiConstantRegister() { |
| 385 | movq(kSmiConstantRegister, |
| 386 | reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)), |
| 387 | RelocInfo::NONE); |
| 388 | } |
| 389 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 390 | // Conversions between tagged smi values and non-tagged integer values. |
| 391 | |
| 392 | // Tag an integer value. The result must be known to be a valid smi value. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 393 | // Only uses the low 32 bits of the src register. Sets the N and Z flags |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 394 | // based on the value of the resulting smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 395 | void Integer32ToSmi(Register dst, Register src); |
| 396 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 397 | // Stores an integer32 value into a memory field that already holds a smi. |
| 398 | void Integer32ToSmiField(const Operand& dst, Register src); |
| 399 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 400 | // Adds constant to src and tags the result as a smi. |
| 401 | // Result must be a valid smi. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 402 | void Integer64PlusConstantToSmi(Register dst, Register src, int constant); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 403 | |
| 404 | // Convert smi to 32-bit integer. I.e., not sign extended into |
| 405 | // high 32 bits of destination. |
| 406 | void SmiToInteger32(Register dst, Register src); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 407 | void SmiToInteger32(Register dst, const Operand& src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 408 | |
| 409 | // Convert smi to 64-bit integer (sign extended if necessary). |
| 410 | void SmiToInteger64(Register dst, Register src); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 411 | void SmiToInteger64(Register dst, const Operand& src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 412 | |
| 413 | // Multiply a positive smi's integer value by a power of two. |
| 414 | // Provides result as 64-bit integer value. |
| 415 | void PositiveSmiTimesPowerOfTwoToInteger64(Register dst, |
| 416 | Register src, |
| 417 | int power); |
| 418 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 419 | // Divide a positive smi's integer value by a power of two. |
| 420 | // Provides result as 32-bit integer value. |
| 421 | void PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 422 | Register src, |
| 423 | int power); |
| 424 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 425 | // Perform the logical or of two smi values and return a smi value. |
| 426 | // If either argument is not a smi, jump to on_not_smis and retain |
| 427 | // the original values of source registers. The destination register |
| 428 | // may be changed if it's not one of the source registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 429 | void SmiOrIfSmis(Register dst, |
| 430 | Register src1, |
| 431 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 432 | Label* on_not_smis, |
| 433 | Label::Distance near_jump = Label::kFar); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 434 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 435 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 436 | // Simple comparison of smis. Both sides must be known smis to use these, |
| 437 | // otherwise use Cmp. |
| 438 | void SmiCompare(Register smi1, Register smi2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 439 | void SmiCompare(Register dst, Smi* src); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 440 | void SmiCompare(Register dst, const Operand& src); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 441 | void SmiCompare(const Operand& dst, Register src); |
| 442 | void SmiCompare(const Operand& dst, Smi* src); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 443 | // Compare the int32 in src register to the value of the smi stored at dst. |
| 444 | void SmiCompareInteger32(const Operand& dst, Register src); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 445 | // Sets sign and zero flags depending on value of smi in register. |
| 446 | void SmiTest(Register src); |
| 447 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 448 | // Functions performing a check on a known or potential smi. Returns |
| 449 | // a condition that is satisfied if the check is successful. |
| 450 | |
| 451 | // Is the value a tagged smi. |
| 452 | Condition CheckSmi(Register src); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 453 | Condition CheckSmi(const Operand& src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 454 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 455 | // Is the value a non-negative tagged smi. |
| 456 | Condition CheckNonNegativeSmi(Register src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 457 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 458 | // Are both values tagged smis. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 459 | Condition CheckBothSmi(Register first, Register second); |
| 460 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 461 | // Are both values non-negative tagged smis. |
| 462 | Condition CheckBothNonNegativeSmi(Register first, Register second); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 463 | |
| 464 | // Are either value a tagged smi. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 465 | Condition CheckEitherSmi(Register first, |
| 466 | Register second, |
| 467 | Register scratch = kScratchRegister); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 468 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 469 | // Is the value the minimum smi value (since we are using |
| 470 | // two's complement numbers, negating the value is known to yield |
| 471 | // a non-smi value). |
| 472 | Condition CheckIsMinSmi(Register src); |
| 473 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 474 | // Checks whether an 32-bit integer value is a valid for conversion |
| 475 | // to a smi. |
| 476 | Condition CheckInteger32ValidSmiValue(Register src); |
| 477 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 478 | // Checks whether an 32-bit unsigned integer value is a valid for |
| 479 | // conversion to a smi. |
| 480 | Condition CheckUInteger32ValidSmiValue(Register src); |
| 481 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 482 | // Check whether src is a Smi, and set dst to zero if it is a smi, |
| 483 | // and to one if it isn't. |
| 484 | void CheckSmiToIndicator(Register dst, Register src); |
| 485 | void CheckSmiToIndicator(Register dst, const Operand& src); |
| 486 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 487 | // Test-and-jump functions. Typically combines a check function |
| 488 | // above with a conditional jump. |
| 489 | |
| 490 | // Jump if the value cannot be represented by a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 491 | void JumpIfNotValidSmiValue(Register src, Label* on_invalid, |
| 492 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 493 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 494 | // Jump if the unsigned integer value cannot be represented by a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 495 | void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid, |
| 496 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 497 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 498 | // Jump to label if the value is a tagged smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 499 | void JumpIfSmi(Register src, |
| 500 | Label* on_smi, |
| 501 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 502 | |
| 503 | // Jump to label if the value is not a tagged smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 504 | void JumpIfNotSmi(Register src, |
| 505 | Label* on_not_smi, |
| 506 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 507 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 508 | // Jump to label if the value is not a non-negative tagged smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 509 | void JumpUnlessNonNegativeSmi(Register src, |
| 510 | Label* on_not_smi, |
| 511 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 512 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 513 | // Jump to label if the value, which must be a tagged smi, has value equal |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 514 | // to the constant. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 515 | void JumpIfSmiEqualsConstant(Register src, |
| 516 | Smi* constant, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 517 | Label* on_equals, |
| 518 | Label::Distance near_jump = Label::kFar); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 519 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 520 | // Jump if either or both register are not smi values. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 521 | void JumpIfNotBothSmi(Register src1, |
| 522 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 523 | Label* on_not_both_smi, |
| 524 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 525 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 526 | // Jump if either or both register are not non-negative smi values. |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 527 | void JumpUnlessBothNonNegativeSmi(Register src1, Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 528 | Label* on_not_both_smi, |
| 529 | Label::Distance near_jump = Label::kFar); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 530 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 531 | // Operations on tagged smi values. |
| 532 | |
| 533 | // Smis represent a subset of integers. The subset is always equivalent to |
| 534 | // a two's complement interpretation of a fixed number of bits. |
| 535 | |
| 536 | // Optimistically adds an integer constant to a supposed smi. |
| 537 | // If the src is not a smi, or the result is not a smi, jump to |
| 538 | // the label. |
| 539 | void SmiTryAddConstant(Register dst, |
| 540 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 541 | Smi* constant, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 542 | Label* on_not_smi_result, |
| 543 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 544 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 545 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 546 | // No overflow testing on the result is done. |
| 547 | void SmiAddConstant(Register dst, Register src, Smi* constant); |
| 548 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 549 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 550 | // No overflow testing on the result is done. |
| 551 | void SmiAddConstant(const Operand& dst, Smi* constant); |
| 552 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 553 | // Add an integer constant to a tagged smi, giving a tagged smi as result, |
| 554 | // or jumping to a label if the result cannot be represented by a smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 555 | void SmiAddConstant(Register dst, |
| 556 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 557 | Smi* constant, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 558 | Label* on_not_smi_result, |
| 559 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 560 | |
| 561 | // Subtract an integer constant from a tagged smi, giving a tagged smi as |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 562 | // result. No testing on the result is done. Sets the N and Z flags |
| 563 | // based on the value of the resulting integer. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 564 | void SmiSubConstant(Register dst, Register src, Smi* constant); |
| 565 | |
| 566 | // Subtract an integer constant from a tagged smi, giving a tagged smi as |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 567 | // result, or jumping to a label if the result cannot be represented by a smi. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 568 | void SmiSubConstant(Register dst, |
| 569 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 570 | Smi* constant, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 571 | Label* on_not_smi_result, |
| 572 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 573 | |
| 574 | // Negating a smi can give a negative zero or too large positive value. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 575 | // NOTICE: This operation jumps on success, not failure! |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 576 | void SmiNeg(Register dst, |
| 577 | Register src, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 578 | Label* on_smi_result, |
| 579 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 580 | |
| 581 | // Adds smi values and return the result as a smi. |
| 582 | // If dst is src1, then src1 will be destroyed, even if |
| 583 | // the operation is unsuccessful. |
| 584 | void SmiAdd(Register dst, |
| 585 | Register src1, |
| 586 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 587 | Label* on_not_smi_result, |
| 588 | Label::Distance near_jump = Label::kFar); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 589 | void SmiAdd(Register dst, |
| 590 | Register src1, |
| 591 | const Operand& src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 592 | Label* on_not_smi_result, |
| 593 | Label::Distance near_jump = Label::kFar); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 594 | |
| 595 | void SmiAdd(Register dst, |
| 596 | Register src1, |
| 597 | Register src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 598 | |
| 599 | // Subtracts smi values and return the result as a smi. |
| 600 | // If dst is src1, then src1 will be destroyed, even if |
| 601 | // the operation is unsuccessful. |
| 602 | void SmiSub(Register dst, |
| 603 | Register src1, |
| 604 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 605 | Label* on_not_smi_result, |
| 606 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 607 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 608 | void SmiSub(Register dst, |
| 609 | Register src1, |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 610 | Register src2); |
| 611 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 612 | void SmiSub(Register dst, |
| 613 | Register src1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 614 | const Operand& src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 615 | Label* on_not_smi_result, |
| 616 | Label::Distance near_jump = Label::kFar); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 617 | |
| 618 | void SmiSub(Register dst, |
| 619 | Register src1, |
| 620 | const Operand& src2); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 621 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 622 | // Multiplies smi values and return the result as a smi, |
| 623 | // if possible. |
| 624 | // If dst is src1, then src1 will be destroyed, even if |
| 625 | // the operation is unsuccessful. |
| 626 | void SmiMul(Register dst, |
| 627 | Register src1, |
| 628 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 629 | Label* on_not_smi_result, |
| 630 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 631 | |
| 632 | // Divides one smi by another and returns the quotient. |
| 633 | // Clobbers rax and rdx registers. |
| 634 | void SmiDiv(Register dst, |
| 635 | Register src1, |
| 636 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 637 | Label* on_not_smi_result, |
| 638 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 639 | |
| 640 | // Divides one smi by another and returns the remainder. |
| 641 | // Clobbers rax and rdx registers. |
| 642 | void SmiMod(Register dst, |
| 643 | Register src1, |
| 644 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 645 | Label* on_not_smi_result, |
| 646 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 647 | |
| 648 | // Bitwise operations. |
| 649 | void SmiNot(Register dst, Register src); |
| 650 | void SmiAnd(Register dst, Register src1, Register src2); |
| 651 | void SmiOr(Register dst, Register src1, Register src2); |
| 652 | void SmiXor(Register dst, Register src1, Register src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 653 | void SmiAndConstant(Register dst, Register src1, Smi* constant); |
| 654 | void SmiOrConstant(Register dst, Register src1, Smi* constant); |
| 655 | void SmiXorConstant(Register dst, Register src1, Smi* constant); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 656 | |
| 657 | void SmiShiftLeftConstant(Register dst, |
| 658 | Register src, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 659 | int shift_value); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 660 | void SmiShiftLogicalRightConstant(Register dst, |
| 661 | Register src, |
| 662 | int shift_value, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 663 | Label* on_not_smi_result, |
| 664 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 665 | void SmiShiftArithmeticRightConstant(Register dst, |
| 666 | Register src, |
| 667 | int shift_value); |
| 668 | |
| 669 | // Shifts a smi value to the left, and returns the result if that is a smi. |
| 670 | // Uses and clobbers rcx, so dst may not be rcx. |
| 671 | void SmiShiftLeft(Register dst, |
| 672 | Register src1, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 673 | Register src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 674 | // Shifts a smi value to the right, shifting in zero bits at the top, and |
| 675 | // returns the unsigned intepretation of the result if that is a smi. |
| 676 | // Uses and clobbers rcx, so dst may not be rcx. |
| 677 | void SmiShiftLogicalRight(Register dst, |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 678 | Register src1, |
| 679 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 680 | Label* on_not_smi_result, |
| 681 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 682 | // Shifts a smi value to the right, sign extending the top, and |
| 683 | // returns the signed intepretation of the result. That will always |
| 684 | // be a valid smi value, since it's numerically smaller than the |
| 685 | // original. |
| 686 | // Uses and clobbers rcx, so dst may not be rcx. |
| 687 | void SmiShiftArithmeticRight(Register dst, |
| 688 | Register src1, |
| 689 | Register src2); |
| 690 | |
| 691 | // Specialized operations |
| 692 | |
| 693 | // Select the non-smi register of two registers where exactly one is a |
| 694 | // smi. If neither are smis, jump to the failure label. |
| 695 | void SelectNonSmi(Register dst, |
| 696 | Register src1, |
| 697 | Register src2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 698 | Label* on_not_smis, |
| 699 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 700 | |
| 701 | // Converts, if necessary, a smi to a combination of number and |
| 702 | // multiplier to be used as a scaled index. |
| 703 | // The src register contains a *positive* smi value. The shift is the |
| 704 | // power of two to multiply the index value by (e.g. |
| 705 | // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2). |
| 706 | // The returned index register may be either src or dst, depending |
| 707 | // on what is most efficient. If src and dst are different registers, |
| 708 | // src is always unchanged. |
| 709 | SmiIndex SmiToIndex(Register dst, Register src, int shift); |
| 710 | |
| 711 | // Converts a positive smi to a negative index. |
| 712 | SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift); |
| 713 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 714 | // Add the value of a smi in memory to an int32 register. |
| 715 | // Sets flags as a normal add. |
| 716 | void AddSmiField(Register dst, const Operand& src); |
| 717 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 718 | // Basic Smi operations. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 719 | void Move(Register dst, Smi* source) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 720 | LoadSmiConstant(dst, source); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | void Move(const Operand& dst, Smi* source) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 724 | Register constant = GetSmiConstant(source); |
| 725 | movq(dst, constant); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 726 | } |
| 727 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 728 | void Push(Smi* smi); |
| 729 | void Test(const Operand& dst, Smi* source); |
| 730 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 731 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 732 | // --------------------------------------------------------------------------- |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 733 | // String macros. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 734 | |
| 735 | // If object is a string, its map is loaded into object_map. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 736 | void JumpIfNotString(Register object, |
| 737 | Register object_map, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 738 | Label* not_string, |
| 739 | Label::Distance near_jump = Label::kFar); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 740 | |
| 741 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 742 | void JumpIfNotBothSequentialAsciiStrings( |
| 743 | Register first_object, |
| 744 | Register second_object, |
| 745 | Register scratch1, |
| 746 | Register scratch2, |
| 747 | Label* on_not_both_flat_ascii, |
| 748 | Label::Distance near_jump = Label::kFar); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 749 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 750 | // Check whether the instance type represents a flat ASCII string. Jump to the |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 751 | // label if not. If the instance type can be scratched specify same register |
| 752 | // for both instance type and scratch. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 753 | void JumpIfInstanceTypeIsNotSequentialAscii( |
| 754 | Register instance_type, |
| 755 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 756 | Label*on_not_flat_ascii_string, |
| 757 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 758 | |
| 759 | void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 760 | Register first_object_instance_type, |
| 761 | Register second_object_instance_type, |
| 762 | Register scratch1, |
| 763 | Register scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 764 | Label* on_fail, |
| 765 | Label::Distance near_jump = Label::kFar); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 766 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 767 | // --------------------------------------------------------------------------- |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 768 | // Macro instructions. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 769 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 770 | // Load a register with a long value as efficiently as possible. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 771 | void Set(Register dst, int64_t x); |
| 772 | void Set(const Operand& dst, int64_t x); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 773 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 774 | // Move if the registers are not identical. |
| 775 | void Move(Register target, Register source); |
| 776 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 777 | // Bit-field support. |
| 778 | void TestBit(const Operand& dst, int bit_index); |
| 779 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 780 | // Handle support |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 781 | void Move(Register dst, Handle<Object> source); |
| 782 | void Move(const Operand& dst, Handle<Object> source); |
| 783 | void Cmp(Register dst, Handle<Object> source); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 784 | void Cmp(const Operand& dst, Handle<Object> source); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 785 | void Cmp(Register dst, Smi* src); |
| 786 | void Cmp(const Operand& dst, Smi* src); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 787 | void Push(Handle<Object> source); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 788 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 789 | // Load a heap object and handle the case of new-space objects by |
| 790 | // indirecting via a global cell. |
| 791 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
| 792 | void PushHeapObject(Handle<HeapObject> object); |
| 793 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 794 | void LoadObject(Register result, Handle<Object> object) { |
| 795 | if (object->IsHeapObject()) { |
| 796 | LoadHeapObject(result, Handle<HeapObject>::cast(object)); |
| 797 | } else { |
| 798 | Move(result, object); |
| 799 | } |
| 800 | } |
| 801 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 802 | // Load a global cell into a register. |
| 803 | void LoadGlobalCell(Register dst, Handle<JSGlobalPropertyCell> cell); |
| 804 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 805 | // Emit code to discard a non-negative number of pointer-sized elements |
| 806 | // from the stack, clobbering only the rsp register. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 807 | void Drop(int stack_elements); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 808 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 809 | void Call(Label* target) { call(target); } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 810 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 811 | // Control Flow |
| 812 | void Jump(Address destination, RelocInfo::Mode rmode); |
| 813 | void Jump(ExternalReference ext); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 814 | void Jump(Handle<Code> code_object, RelocInfo::Mode rmode); |
| 815 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 816 | void Call(Address destination, RelocInfo::Mode rmode); |
| 817 | void Call(ExternalReference ext); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 818 | void Call(Handle<Code> code_object, |
| 819 | RelocInfo::Mode rmode, |
| 820 | unsigned ast_id = kNoASTId); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 821 | |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 822 | // The size of the code generated for different call instructions. |
| 823 | int CallSize(Address destination, RelocInfo::Mode rmode) { |
| 824 | return kCallInstructionLength; |
| 825 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 826 | int CallSize(ExternalReference ext); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 827 | int CallSize(Handle<Code> code_object) { |
| 828 | // Code calls use 32-bit relative addressing. |
| 829 | return kShortCallInstructionLength; |
| 830 | } |
| 831 | int CallSize(Register target) { |
| 832 | // Opcode: REX_opt FF /2 m64 |
| 833 | return (target.high_bit() != 0) ? 3 : 2; |
| 834 | } |
| 835 | int CallSize(const Operand& target) { |
| 836 | // Opcode: REX_opt FF /2 m64 |
| 837 | return (target.requires_rex() ? 2 : 1) + target.operand_size(); |
| 838 | } |
| 839 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 840 | // Emit call to the code we are currently generating. |
| 841 | void CallSelf() { |
| 842 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 843 | Call(self, RelocInfo::CODE_TARGET); |
| 844 | } |
| 845 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 846 | // Non-x64 instructions. |
| 847 | // Push/pop all general purpose registers. |
| 848 | // Does not push rsp/rbp nor any of the assembler's special purpose registers |
| 849 | // (kScratchRegister, kSmiConstantRegister, kRootRegister). |
| 850 | void Pushad(); |
| 851 | void Popad(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 852 | // Sets the stack as after performing Popad, without actually loading the |
| 853 | // registers. |
| 854 | void Dropad(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 855 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 856 | // Compare object type for heap object. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 857 | // Always use unsigned comparisons: above and below, not less and greater. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 858 | // Incoming register is heap_object and outgoing register is map. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 859 | // They may be the same register, and may be kScratchRegister. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 860 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 861 | |
| 862 | // Compare instance type for map. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 863 | // Always use unsigned comparisons: above and below, not less and greater. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 864 | void CmpInstanceType(Register map, InstanceType type); |
| 865 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 866 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 867 | // Jump to the specified label if it does not. |
| 868 | void CheckFastElements(Register map, |
| 869 | Label* fail, |
| 870 | Label::Distance distance = Label::kFar); |
| 871 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 872 | // Check if a map for a JSObject indicates that the object can have both smi |
| 873 | // and HeapObject elements. Jump to the specified label if it does not. |
| 874 | void CheckFastObjectElements(Register map, |
| 875 | Label* fail, |
| 876 | Label::Distance distance = Label::kFar); |
| 877 | |
| 878 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 879 | // elements. Jump to the specified label if it does not. |
| 880 | void CheckFastSmiOnlyElements(Register map, |
| 881 | Label* fail, |
| 882 | Label::Distance distance = Label::kFar); |
| 883 | |
| 884 | // Check to see if maybe_number can be stored as a double in |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 885 | // FastDoubleElements. If it can, store it at the index specified by index in |
| 886 | // the FastDoubleElements array elements, otherwise jump to fail. Note that |
| 887 | // index must not be smi-tagged. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 888 | void StoreNumberToDoubleElements(Register maybe_number, |
| 889 | Register elements, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 890 | Register index, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 891 | XMMRegister xmm_scratch, |
| 892 | Label* fail); |
| 893 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 894 | // Compare an object's map with the specified map and its transitioned |
| 895 | // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. FLAGS are set with |
| 896 | // result of map compare. If multiple map compares are required, the compare |
| 897 | // sequences branches to early_success. |
| 898 | void CompareMap(Register obj, |
| 899 | Handle<Map> map, |
| 900 | Label* early_success, |
| 901 | CompareMapMode mode = REQUIRE_EXACT_MAP); |
| 902 | |
| 903 | // Check if the map of an object is equal to a specified map and branch to |
| 904 | // label if not. Skip the smi check if not required (object is known to be a |
| 905 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 906 | // against maps that are ElementsKind transition maps of the specified map. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 907 | void CheckMap(Register obj, |
| 908 | Handle<Map> map, |
| 909 | Label* fail, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 910 | SmiCheckType smi_check_type, |
| 911 | CompareMapMode mode = REQUIRE_EXACT_MAP); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 912 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 913 | // Check if the map of an object is equal to a specified map and branch to a |
| 914 | // specified target if equal. Skip the smi check if not required (object is |
| 915 | // known to be a heap object) |
| 916 | void DispatchMap(Register obj, |
| 917 | Handle<Map> map, |
| 918 | Handle<Code> success, |
| 919 | SmiCheckType smi_check_type); |
| 920 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 921 | // Check if the object in register heap_object is a string. Afterwards the |
| 922 | // register map contains the object map and the register instance_type |
| 923 | // contains the instance_type. The registers map and instance_type can be the |
| 924 | // same in which case it contains the instance type afterwards. Either of the |
| 925 | // registers map and instance_type can be the same as heap_object. |
| 926 | Condition IsObjectStringType(Register heap_object, |
| 927 | Register map, |
| 928 | Register instance_type); |
| 929 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 930 | // FCmp compares and pops the two values on top of the FPU stack. |
| 931 | // The flag results are similar to integer cmp, but requires unsigned |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 932 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 933 | void FCmp(); |
| 934 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 935 | void ClampUint8(Register reg); |
| 936 | |
| 937 | void ClampDoubleToUint8(XMMRegister input_reg, |
| 938 | XMMRegister temp_xmm_reg, |
| 939 | Register result_reg, |
| 940 | Register temp_reg); |
| 941 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 942 | void LoadInstanceDescriptors(Register map, Register descriptors); |
| 943 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 944 | // Abort execution if argument is not a number. Used in debug code. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 945 | void AbortIfNotNumber(Register object); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 946 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 947 | // Abort execution if argument is a smi. Used in debug code. |
| 948 | void AbortIfSmi(Register object); |
| 949 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 950 | // Abort execution if argument is not a smi. Used in debug code. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 951 | void AbortIfNotSmi(Register object); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 952 | void AbortIfNotSmi(const Operand& object); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 953 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 954 | // Abort execution if a 64 bit register containing a 32 bit payload does not |
| 955 | // have zeros in the top 32 bits. |
| 956 | void AbortIfNotZeroExtended(Register reg); |
| 957 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 958 | // Abort execution if argument is a string. Used in debug code. |
| 959 | void AbortIfNotString(Register object); |
| 960 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 961 | // Abort execution if argument is not the root value with the given index. |
| 962 | void AbortIfNotRootValue(Register src, |
| 963 | Heap::RootListIndex root_value_index, |
| 964 | const char* message); |
| 965 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 966 | // --------------------------------------------------------------------------- |
| 967 | // Exception handling |
| 968 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 969 | // Push a new try handler and link it into try handler chain. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 970 | void PushTryHandler(StackHandler::Kind kind, int handler_index); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 971 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 972 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 973 | void PopTryHandler(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 974 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 975 | // Activate the top handler in the try hander chain and pass the |
| 976 | // thrown value. |
| 977 | void Throw(Register value); |
| 978 | |
| 979 | // Propagate an uncatchable exception out of the current JS stack. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 980 | void ThrowUncatchable(Register value); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 981 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 982 | // --------------------------------------------------------------------------- |
| 983 | // Inline caching support |
| 984 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 985 | // Generate code for checking access rights - used for security checks |
| 986 | // on access to global objects across environments. The holder register |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 987 | // is left untouched, but the scratch register and kScratchRegister, |
| 988 | // which must be different, are clobbered. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 989 | void CheckAccessGlobalProxy(Register holder_reg, |
| 990 | Register scratch, |
| 991 | Label* miss); |
| 992 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 993 | void GetNumberHash(Register r0, Register scratch); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 994 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 995 | void LoadFromNumberDictionary(Label* miss, |
| 996 | Register elements, |
| 997 | Register key, |
| 998 | Register r0, |
| 999 | Register r1, |
| 1000 | Register r2, |
| 1001 | Register result); |
| 1002 | |
| 1003 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1004 | // --------------------------------------------------------------------------- |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1005 | // Allocation support |
| 1006 | |
| 1007 | // Allocate an object in new space. If the new space is exhausted control |
| 1008 | // continues at the gc_required label. The allocated object is returned in |
| 1009 | // result and end of the new object is returned in result_end. The register |
| 1010 | // scratch can be passed as no_reg in which case an additional object |
| 1011 | // reference will be added to the reloc info. The returned pointers in result |
| 1012 | // and result_end have not yet been tagged as heap objects. If |
| 1013 | // result_contains_top_on_entry is true the content of result is known to be |
| 1014 | // the allocation top on entry (could be result_end from a previous call to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1015 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1016 | // should be no_reg as it is never used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1017 | void AllocateInNewSpace(int object_size, |
| 1018 | Register result, |
| 1019 | Register result_end, |
| 1020 | Register scratch, |
| 1021 | Label* gc_required, |
| 1022 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1023 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1024 | void AllocateInNewSpace(int header_size, |
| 1025 | ScaleFactor element_size, |
| 1026 | Register element_count, |
| 1027 | Register result, |
| 1028 | Register result_end, |
| 1029 | Register scratch, |
| 1030 | Label* gc_required, |
| 1031 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1032 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1033 | void AllocateInNewSpace(Register object_size, |
| 1034 | Register result, |
| 1035 | Register result_end, |
| 1036 | Register scratch, |
| 1037 | Label* gc_required, |
| 1038 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1039 | |
| 1040 | // Undo allocation in new space. The object passed and objects allocated after |
| 1041 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 1042 | // object(s) no longer allocated as they would be invalid when allocation is |
| 1043 | // un-done. |
| 1044 | void UndoAllocationInNewSpace(Register object); |
| 1045 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1046 | // Allocate a heap number in new space with undefined value. Returns |
| 1047 | // tagged pointer in result register, or jumps to gc_required if new |
| 1048 | // space is full. |
| 1049 | void AllocateHeapNumber(Register result, |
| 1050 | Register scratch, |
| 1051 | Label* gc_required); |
| 1052 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1053 | // Allocate a sequential string. All the header fields of the string object |
| 1054 | // are initialized. |
| 1055 | void AllocateTwoByteString(Register result, |
| 1056 | Register length, |
| 1057 | Register scratch1, |
| 1058 | Register scratch2, |
| 1059 | Register scratch3, |
| 1060 | Label* gc_required); |
| 1061 | void AllocateAsciiString(Register result, |
| 1062 | Register length, |
| 1063 | Register scratch1, |
| 1064 | Register scratch2, |
| 1065 | Register scratch3, |
| 1066 | Label* gc_required); |
| 1067 | |
| 1068 | // Allocate a raw cons string object. Only the map field of the result is |
| 1069 | // initialized. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1070 | void AllocateTwoByteConsString(Register result, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1071 | Register scratch1, |
| 1072 | Register scratch2, |
| 1073 | Label* gc_required); |
| 1074 | void AllocateAsciiConsString(Register result, |
| 1075 | Register scratch1, |
| 1076 | Register scratch2, |
| 1077 | Label* gc_required); |
| 1078 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1079 | // Allocate a raw sliced string object. Only the map field of the result is |
| 1080 | // initialized. |
| 1081 | void AllocateTwoByteSlicedString(Register result, |
| 1082 | Register scratch1, |
| 1083 | Register scratch2, |
| 1084 | Label* gc_required); |
| 1085 | void AllocateAsciiSlicedString(Register result, |
| 1086 | Register scratch1, |
| 1087 | Register scratch2, |
| 1088 | Label* gc_required); |
| 1089 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1090 | // --------------------------------------------------------------------------- |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1091 | // Support functions. |
| 1092 | |
| 1093 | // Check if result is zero and op is negative. |
| 1094 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 1095 | |
| 1096 | // Check if result is zero and op is negative in code using jump targets. |
| 1097 | void NegativeZeroTest(CodeGenerator* cgen, |
| 1098 | Register result, |
| 1099 | Register op, |
| 1100 | JumpTarget* then_target); |
| 1101 | |
| 1102 | // Check if result is zero and any of op1 and op2 are negative. |
| 1103 | // Register scratch is destroyed, and it must be different from op2. |
| 1104 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 1105 | Register scratch, Label* then_label); |
| 1106 | |
| 1107 | // Try to get function prototype of a function and puts the value in |
| 1108 | // the result register. Checks that the function really is a |
| 1109 | // function and jumps to the miss label if the fast checks fail. The |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1110 | // function register will be untouched; the other register may be |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1111 | // clobbered. |
| 1112 | void TryGetFunctionPrototype(Register function, |
| 1113 | Register result, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1114 | Label* miss, |
| 1115 | bool miss_on_bound_function = false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1116 | |
| 1117 | // Generates code for reporting that an illegal operation has |
| 1118 | // occurred. |
| 1119 | void IllegalOperation(int num_arguments); |
| 1120 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1121 | // Picks out an array index from the hash field. |
| 1122 | // Register use: |
| 1123 | // hash - holds the index's hash. Clobbered. |
| 1124 | // index - holds the overwritten index on exit. |
| 1125 | void IndexFromHash(Register hash, Register index); |
| 1126 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1127 | // Find the function context up the context chain. |
| 1128 | void LoadContext(Register dst, int context_chain_length); |
| 1129 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 1130 | // Conditionally load the cached Array transitioned map of type |
| 1131 | // transitioned_kind from the global context if the map in register |
| 1132 | // map_in_out is the cached Array map in the global context of |
| 1133 | // expected_kind. |
| 1134 | void LoadTransitionedArrayMapConditional( |
| 1135 | ElementsKind expected_kind, |
| 1136 | ElementsKind transitioned_kind, |
| 1137 | Register map_in_out, |
| 1138 | Register scratch, |
| 1139 | Label* no_map_match); |
| 1140 | |
| 1141 | // Load the initial map for new Arrays from a JSFunction. |
| 1142 | void LoadInitialArrayMap(Register function_in, |
| 1143 | Register scratch, |
| 1144 | Register map_out); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1145 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1146 | // Load the global function with the given index. |
| 1147 | void LoadGlobalFunction(int index, Register function); |
| 1148 | |
| 1149 | // Load the initial map from the global function. The registers |
| 1150 | // function and map can be the same. |
| 1151 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 1152 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1153 | // --------------------------------------------------------------------------- |
| 1154 | // Runtime calls |
| 1155 | |
| 1156 | // Call a code stub. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1157 | void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1158 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1159 | // Tail call a code stub (jump). |
| 1160 | void TailCallStub(CodeStub* stub); |
| 1161 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1162 | // Return from a code stub after popping its arguments. |
| 1163 | void StubReturn(int argc); |
| 1164 | |
| 1165 | // Call a runtime routine. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1166 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1167 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1168 | // Call a runtime function and save the value of XMM registers. |
| 1169 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
| 1170 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1171 | // Convenience function: Same as above, but takes the fid instead. |
| 1172 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 1173 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1174 | // Convenience function: call an external reference. |
| 1175 | void CallExternalReference(const ExternalReference& ext, |
| 1176 | int num_arguments); |
| 1177 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1178 | // Tail call of a runtime routine (jump). |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1179 | // Like JumpToExternalReference, but also takes care of passing the number |
| 1180 | // of parameters. |
| 1181 | void TailCallExternalReference(const ExternalReference& ext, |
| 1182 | int num_arguments, |
| 1183 | int result_size); |
| 1184 | |
| 1185 | // Convenience function: tail call a runtime routine (jump). |
| 1186 | void TailCallRuntime(Runtime::FunctionId fid, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1187 | int num_arguments, |
| 1188 | int result_size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1189 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1190 | // Jump to a runtime routine. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1191 | void JumpToExternalReference(const ExternalReference& ext, int result_size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1192 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1193 | // Prepares stack to put arguments (aligns and so on). WIN64 calling |
| 1194 | // convention requires to put the pointer to the return value slot into |
| 1195 | // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves |
| 1196 | // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1197 | // inside the exit frame (not GCed) accessible via StackSpaceOperand. |
| 1198 | void PrepareCallApiFunction(int arg_stack_space); |
| 1199 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1200 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 1201 | // from handle and propagates exceptions. Clobbers r14, r15, rbx and |
| 1202 | // caller-save registers. Restores context. On return removes |
| 1203 | // stack_space * kPointerSize (GCed). |
| 1204 | void CallApiFunctionAndReturn(Address function_address, int stack_space); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1205 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1206 | // Before calling a C-function from generated code, align arguments on stack. |
| 1207 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 1208 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 1209 | // The number of slots reserved for arguments depends on platform. On Windows |
| 1210 | // stack slots are reserved for the arguments passed in registers. On other |
| 1211 | // platforms stack slots are only reserved for the arguments actually passed |
| 1212 | // on the stack. |
| 1213 | void PrepareCallCFunction(int num_arguments); |
| 1214 | |
| 1215 | // Calls a C function and cleans up the space for arguments allocated |
| 1216 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 1217 | // garbage collection, since that might move the code and invalidate the |
| 1218 | // return address (unless this is somehow accounted for by the called |
| 1219 | // function). |
| 1220 | void CallCFunction(ExternalReference function, int num_arguments); |
| 1221 | void CallCFunction(Register function, int num_arguments); |
| 1222 | |
| 1223 | // Calculate the number of stack slots to reserve for arguments when calling a |
| 1224 | // C function. |
| 1225 | int ArgumentStackSlotsForCFunctionCall(int num_arguments); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1226 | |
| 1227 | // --------------------------------------------------------------------------- |
| 1228 | // Utilities |
| 1229 | |
| 1230 | void Ret(); |
| 1231 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1232 | // Return and drop arguments from stack, where the number of arguments |
| 1233 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 1234 | void Ret(int bytes_dropped, Register scratch); |
| 1235 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1236 | Handle<Object> CodeObject() { |
| 1237 | ASSERT(!code_object_.is_null()); |
| 1238 | return code_object_; |
| 1239 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1240 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1241 | // Copy length bytes from source to destination. |
| 1242 | // Uses scratch register internally (if you have a low-eight register |
| 1243 | // free, do use it, otherwise kScratchRegister will be used). |
| 1244 | // The min_length is a minimum limit on the value that length will have. |
| 1245 | // The algorithm has some special cases that might be omitted if the string |
| 1246 | // is known to always be long. |
| 1247 | void CopyBytes(Register destination, |
| 1248 | Register source, |
| 1249 | Register length, |
| 1250 | int min_length = 0, |
| 1251 | Register scratch = kScratchRegister); |
| 1252 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1253 | // Initialize fields with filler values. Fields starting at |start_offset| |
| 1254 | // not including end_offset are overwritten with the value in |filler|. At |
| 1255 | // the end the loop, |start_offset| takes the value of |end_offset|. |
| 1256 | void InitializeFieldsWithFiller(Register start_offset, |
| 1257 | Register end_offset, |
| 1258 | Register filler); |
| 1259 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1260 | |
| 1261 | // --------------------------------------------------------------------------- |
| 1262 | // StatsCounter support |
| 1263 | |
| 1264 | void SetCounter(StatsCounter* counter, int value); |
| 1265 | void IncrementCounter(StatsCounter* counter, int value); |
| 1266 | void DecrementCounter(StatsCounter* counter, int value); |
| 1267 | |
| 1268 | |
| 1269 | // --------------------------------------------------------------------------- |
| 1270 | // Debugging |
| 1271 | |
| 1272 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 1273 | // Use --debug_code to enable. |
| 1274 | void Assert(Condition cc, const char* msg); |
| 1275 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1276 | void AssertFastElements(Register elements); |
| 1277 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1278 | // Like Assert(), but always enabled. |
| 1279 | void Check(Condition cc, const char* msg); |
| 1280 | |
| 1281 | // Print a message to stdout and abort execution. |
| 1282 | void Abort(const char* msg); |
| 1283 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1284 | // Check that the stack is aligned. |
| 1285 | void CheckStackAlignment(); |
| 1286 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1287 | // Verify restrictions about code generated in stubs. |
| 1288 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 1289 | bool generating_stub() { return generating_stub_; } |
| 1290 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 1291 | bool allow_stub_calls() { return allow_stub_calls_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1292 | void set_has_frame(bool value) { has_frame_ = value; } |
| 1293 | bool has_frame() { return has_frame_; } |
| 1294 | inline bool AllowThisStubCall(CodeStub* stub); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1295 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1296 | static int SafepointRegisterStackIndex(Register reg) { |
| 1297 | return SafepointRegisterStackIndex(reg.code()); |
| 1298 | } |
| 1299 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1300 | // Activation support. |
| 1301 | void EnterFrame(StackFrame::Type type); |
| 1302 | void LeaveFrame(StackFrame::Type type); |
| 1303 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1304 | // Expects object in rax and returns map with validated enum cache |
| 1305 | // in rax. Assumes that any other register can be used as a scratch. |
| 1306 | void CheckEnumCache(Register null_value, |
| 1307 | Label* call_runtime); |
| 1308 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1309 | private: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1310 | // Order general registers are pushed by Pushad. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1311 | // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1312 | static const int kSafepointPushRegisterIndices[Register::kNumRegisters]; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1313 | static const int kNumSafepointSavedRegisters = 11; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1314 | static const int kSmiShift = kSmiTagSize + kSmiShiftSize; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1315 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1316 | bool generating_stub_; |
| 1317 | bool allow_stub_calls_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1318 | bool has_frame_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1319 | bool root_array_available_; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1320 | |
| 1321 | // Returns a register holding the smi value. The register MUST NOT be |
| 1322 | // modified. It may be the "smi 1 constant" register. |
| 1323 | Register GetSmiConstant(Smi* value); |
| 1324 | |
| 1325 | // Moves the smi value to the destination register. |
| 1326 | void LoadSmiConstant(Register dst, Smi* value); |
| 1327 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1328 | // This handle will be patched with the code object on installation. |
| 1329 | Handle<Object> code_object_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Helper functions for generating invokes. |
| 1332 | void InvokePrologue(const ParameterCount& expected, |
| 1333 | const ParameterCount& actual, |
| 1334 | Handle<Code> code_constant, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1335 | Register code_register, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1336 | Label* done, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1337 | bool* definitely_mismatches, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1338 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1339 | Label::Distance near_jump = Label::kFar, |
| 1340 | const CallWrapper& call_wrapper = NullCallWrapper(), |
| 1341 | CallKind call_kind = CALL_AS_METHOD); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1342 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1343 | void EnterExitFramePrologue(bool save_rax); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1344 | |
| 1345 | // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack |
| 1346 | // accessible via StackSpaceOperand. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1347 | void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1348 | |
| 1349 | void LeaveExitFrameEpilogue(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1350 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1351 | // Allocation support helpers. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1352 | // Loads the top of new-space into the result register. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1353 | // Otherwise the address of the new-space top is loaded into scratch (if |
| 1354 | // scratch is valid), and the new-space top is loaded into result. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1355 | void LoadAllocationTopHelper(Register result, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1356 | Register scratch, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1357 | AllocationFlags flags); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1358 | // Update allocation top with value in result_end register. |
| 1359 | // If scratch is valid, it contains the address of the allocation top. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1360 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1361 | |
| 1362 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 1363 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 1364 | // possibly returns a failure object indicating an allocation failure. |
| 1365 | Object* PopHandleScopeHelper(Register saved, |
| 1366 | Register scratch, |
| 1367 | bool gc_allowed); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1368 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1369 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 1370 | void InNewSpace(Register object, |
| 1371 | Register scratch, |
| 1372 | Condition cc, |
| 1373 | Label* branch, |
| 1374 | Label::Distance distance = Label::kFar); |
| 1375 | |
| 1376 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1377 | // bitmap register points at the word with the mark bits and the mask |
| 1378 | // the position of the first bit. Uses rcx as scratch and leaves addr_reg |
| 1379 | // unchanged. |
| 1380 | inline void GetMarkBits(Register addr_reg, |
| 1381 | Register bitmap_reg, |
| 1382 | Register mask_reg); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1383 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1384 | // Helper for throwing exceptions. Compute a handler address and jump to |
| 1385 | // it. See the implementation for register usage. |
| 1386 | void JumpToHandlerEntry(); |
| 1387 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1388 | // Compute memory operands for safepoint stack slots. |
| 1389 | Operand SafepointRegisterSlot(Register reg); |
| 1390 | static int SafepointRegisterStackIndex(int reg_code) { |
| 1391 | return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1; |
| 1392 | } |
| 1393 | |
| 1394 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 1395 | // traversal. |
| 1396 | friend class OptimizedFrame; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1397 | }; |
| 1398 | |
| 1399 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1400 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1401 | // debugging and other types of instrumentation. When using the code patcher |
| 1402 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 1403 | // relocation information. If any of these constraints are violated it causes |
| 1404 | // an assertion. |
| 1405 | class CodePatcher { |
| 1406 | public: |
| 1407 | CodePatcher(byte* address, int size); |
| 1408 | virtual ~CodePatcher(); |
| 1409 | |
| 1410 | // Macro assembler to emit code. |
| 1411 | MacroAssembler* masm() { return &masm_; } |
| 1412 | |
| 1413 | private: |
| 1414 | byte* address_; // The address of the code being patched. |
| 1415 | int size_; // Number of bytes of the expected patch size. |
| 1416 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1417 | }; |
| 1418 | |
| 1419 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1420 | // ----------------------------------------------------------------------------- |
| 1421 | // Static helper functions. |
| 1422 | |
| 1423 | // Generate an Operand for loading a field from an object. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1424 | inline Operand FieldOperand(Register object, int offset) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1425 | return Operand(object, offset - kHeapObjectTag); |
| 1426 | } |
| 1427 | |
| 1428 | |
| 1429 | // Generate an Operand for loading an indexed field from an object. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1430 | inline Operand FieldOperand(Register object, |
| 1431 | Register index, |
| 1432 | ScaleFactor scale, |
| 1433 | int offset) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1434 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 1435 | } |
| 1436 | |
| 1437 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1438 | inline Operand ContextOperand(Register context, int index) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1439 | return Operand(context, Context::SlotOffset(index)); |
| 1440 | } |
| 1441 | |
| 1442 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1443 | inline Operand GlobalObjectOperand() { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1444 | return ContextOperand(rsi, Context::GLOBAL_INDEX); |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | // Provides access to exit frame stack space (not GCed). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1449 | inline Operand StackSpaceOperand(int index) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1450 | #ifdef _WIN64 |
| 1451 | const int kShaddowSpace = 4; |
| 1452 | return Operand(rsp, (index + kShaddowSpace) * kPointerSize); |
| 1453 | #else |
| 1454 | return Operand(rsp, index * kPointerSize); |
| 1455 | #endif |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1460 | #ifdef GENERATED_CODE_COVERAGE |
| 1461 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 1462 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1463 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1464 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1465 | #define ACCESS_MASM(masm) { \ |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1466 | byte* x64_coverage_function = \ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1467 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 1468 | masm->pushfd(); \ |
| 1469 | masm->pushad(); \ |
| 1470 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1471 | masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1472 | masm->pop(rax); \ |
| 1473 | masm->popad(); \ |
| 1474 | masm->popfd(); \ |
| 1475 | } \ |
| 1476 | masm-> |
| 1477 | #else |
| 1478 | #define ACCESS_MASM(masm) masm-> |
| 1479 | #endif |
| 1480 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1481 | } } // namespace v8::internal |
| 1482 | |
| 1483 | #endif // V8_X64_MACRO_ASSEMBLER_X64_H_ |