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