ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1 | // Copyright 2009 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" |
| 32 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 35 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 36 | // Flags used for the AllocateInNewSpace functions. |
| 37 | enum AllocationFlags { |
| 38 | // No special flags. |
| 39 | NO_ALLOCATION_FLAGS = 0, |
| 40 | // Return the pointer to the allocated already tagged as a heap object. |
| 41 | TAG_OBJECT = 1 << 0, |
| 42 | // The content of the result register already contains the allocation top in |
| 43 | // new space. |
| 44 | RESULT_CONTAINS_TOP = 1 << 1 |
| 45 | }; |
| 46 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 47 | // Default scratch register used by MacroAssembler (and other code that needs |
| 48 | // a spare register). The register isn't callee save, and not used by the |
| 49 | // function calling convention. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 50 | static const Register kScratchRegister = { 10 }; // r10. |
| 51 | static const Register kSmiConstantRegister = { 15 }; // r15 (callee save). |
| 52 | static const Register kRootRegister = { 13 }; // r13 (callee save). |
| 53 | // Value of smi in kSmiConstantRegister. |
| 54 | static const int kSmiConstantRegisterValue = 1; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 55 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 56 | // Convenience for platform-independent signatures. |
| 57 | typedef Operand MemOperand; |
| 58 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 59 | // Forward declaration. |
| 60 | class JumpTarget; |
| 61 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 62 | struct SmiIndex { |
| 63 | SmiIndex(Register index_register, ScaleFactor scale) |
| 64 | : reg(index_register), |
| 65 | scale(scale) {} |
| 66 | Register reg; |
| 67 | ScaleFactor scale; |
| 68 | }; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 69 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 70 | // MacroAssembler implements a collection of frequently used macros. |
| 71 | class MacroAssembler: public Assembler { |
| 72 | public: |
| 73 | MacroAssembler(void* buffer, int size); |
| 74 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 75 | void LoadRoot(Register destination, Heap::RootListIndex index); |
| 76 | void CompareRoot(Register with, Heap::RootListIndex index); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 77 | void CompareRoot(Operand with, Heap::RootListIndex index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 78 | void PushRoot(Heap::RootListIndex index); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 79 | void StoreRoot(Register source, Heap::RootListIndex index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 80 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 81 | // --------------------------------------------------------------------------- |
| 82 | // GC Support |
| 83 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 84 | // For page containing |object| mark region covering |addr| dirty. |
| 85 | // RecordWriteHelper only works if the object is not in new |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 86 | // space. |
| 87 | void RecordWriteHelper(Register object, |
| 88 | Register addr, |
| 89 | Register scratch); |
| 90 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 91 | // Check if object is in new space. The condition cc can be equal or |
| 92 | // not_equal. If it is equal a jump will be done if the object is on new |
| 93 | // space. The register scratch can be object itself, but it will be clobbered. |
| 94 | void InNewSpace(Register object, |
| 95 | Register scratch, |
| 96 | Condition cc, |
| 97 | Label* branch); |
| 98 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 99 | // For page containing |object| mark region covering [object+offset] |
| 100 | // dirty. |object| is the object being stored into, |value| is the |
| 101 | // object being stored. If |offset| is zero, then the |scratch| |
| 102 | // register contains the array index into the elements array |
| 103 | // represented as a Smi. All registers are clobbered by the |
| 104 | // operation. RecordWrite filters out smis so it does not update the |
| 105 | // write barrier if the value is a smi. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 106 | void RecordWrite(Register object, |
| 107 | int offset, |
| 108 | Register value, |
| 109 | Register scratch); |
| 110 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 111 | // For page containing |object| mark region covering [address] |
| 112 | // dirty. |object| is the object being stored into, |value| is the |
| 113 | // object being stored. All registers are clobbered by the |
| 114 | // operation. RecordWrite filters out smis so it does not update |
| 115 | // the write barrier if the value is a smi. |
| 116 | void RecordWrite(Register object, |
| 117 | Register address, |
| 118 | Register value); |
| 119 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 120 | // 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] | 121 | // The value is known to not be a smi. |
| 122 | // object is the object being stored into, value is the object being stored. |
| 123 | // If offset is zero, then the scratch register contains the array index into |
| 124 | // the elements array represented as a Smi. |
| 125 | // All registers are clobbered by the operation. |
| 126 | void RecordWriteNonSmi(Register object, |
| 127 | int offset, |
| 128 | Register value, |
| 129 | Register scratch); |
| 130 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 131 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 132 | // --------------------------------------------------------------------------- |
| 133 | // Debugger Support |
| 134 | |
| 135 | void SaveRegistersToMemory(RegList regs); |
| 136 | void RestoreRegistersFromMemory(RegList regs); |
| 137 | void PushRegistersFromMemory(RegList regs); |
| 138 | void PopRegistersToMemory(RegList regs); |
| 139 | void CopyRegistersFromStackToMemory(Register base, |
| 140 | Register scratch, |
| 141 | RegList regs); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 142 | void DebugBreak(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | // --------------------------------------------------------------------------- |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 146 | // Stack limit support |
| 147 | |
| 148 | // Do simple test for stack overflow. This doesn't handle an overflow. |
| 149 | void StackLimitCheck(Label* on_stack_limit_hit); |
| 150 | |
| 151 | // --------------------------------------------------------------------------- |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 152 | // Activation frames |
| 153 | |
| 154 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 155 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 156 | |
| 157 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 158 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 159 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 160 | // Enter specific kind of exit frame; either in normal or |
| 161 | // debug mode. Expects the number of arguments in register rax and |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 162 | // sets up the number of arguments in register rdi and the pointer |
| 163 | // to the first argument in register rsi. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 164 | void EnterExitFrame(ExitFrame::Mode mode, int result_size = 1); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 165 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 166 | void EnterApiExitFrame(ExitFrame::Mode mode, |
| 167 | int stack_space, |
| 168 | int argc, |
| 169 | int result_size = 1); |
| 170 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 171 | // Leave the current exit frame. Expects/provides the return value in |
| 172 | // register rax:rdx (untouched) and the pointer to the first |
| 173 | // argument in register rsi. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 174 | void LeaveExitFrame(ExitFrame::Mode mode, int result_size = 1); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 175 | |
| 176 | |
| 177 | // --------------------------------------------------------------------------- |
| 178 | // JavaScript invokes |
| 179 | |
| 180 | // Invoke the JavaScript function code by either calling or jumping. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 181 | void InvokeCode(Register code, |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 182 | const ParameterCount& expected, |
| 183 | const ParameterCount& actual, |
| 184 | InvokeFlag flag); |
| 185 | |
| 186 | void InvokeCode(Handle<Code> code, |
| 187 | const ParameterCount& expected, |
| 188 | const ParameterCount& actual, |
| 189 | RelocInfo::Mode rmode, |
| 190 | InvokeFlag flag); |
| 191 | |
| 192 | // Invoke the JavaScript function in the given register. Changes the |
| 193 | // current context to the context in the function before invoking. |
| 194 | void InvokeFunction(Register function, |
| 195 | const ParameterCount& actual, |
| 196 | InvokeFlag flag); |
| 197 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 198 | void InvokeFunction(JSFunction* function, |
| 199 | const ParameterCount& actual, |
| 200 | InvokeFlag flag); |
| 201 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 202 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 203 | // the unresolved list if the name does not resolve. |
| 204 | void InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag); |
| 205 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame^] | 206 | // Store the function for the given builtin in the target register. |
| 207 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 208 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 209 | // Store the code object for the given builtin in the target register. |
| 210 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 211 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 212 | |
| 213 | // --------------------------------------------------------------------------- |
| 214 | // Smi tagging, untagging and operations on tagged smis. |
| 215 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 216 | void InitializeSmiConstantRegister() { |
| 217 | movq(kSmiConstantRegister, |
| 218 | reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)), |
| 219 | RelocInfo::NONE); |
| 220 | } |
| 221 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 222 | // Conversions between tagged smi values and non-tagged integer values. |
| 223 | |
| 224 | // 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] | 225 | // Only uses the low 32 bits of the src register. Sets the N and Z flags |
| 226 | // based on the value of the resulting integer. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 227 | void Integer32ToSmi(Register dst, Register src); |
| 228 | |
| 229 | // Tag an integer value if possible, or jump the integer value cannot be |
| 230 | // represented as a smi. Only uses the low 32 bit of the src registers. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 231 | // NOTICE: Destroys the dst register even if unsuccessful! |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 232 | void Integer32ToSmi(Register dst, Register src, Label* on_overflow); |
| 233 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 234 | // Stores an integer32 value into a memory field that already holds a smi. |
| 235 | void Integer32ToSmiField(const Operand& dst, Register src); |
| 236 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 237 | // Adds constant to src and tags the result as a smi. |
| 238 | // Result must be a valid smi. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 239 | void Integer64PlusConstantToSmi(Register dst, Register src, int constant); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 240 | |
| 241 | // Convert smi to 32-bit integer. I.e., not sign extended into |
| 242 | // high 32 bits of destination. |
| 243 | void SmiToInteger32(Register dst, Register src); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 244 | void SmiToInteger32(Register dst, const Operand& src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 245 | |
| 246 | // Convert smi to 64-bit integer (sign extended if necessary). |
| 247 | void SmiToInteger64(Register dst, Register src); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 248 | void SmiToInteger64(Register dst, const Operand& src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 249 | |
| 250 | // Multiply a positive smi's integer value by a power of two. |
| 251 | // Provides result as 64-bit integer value. |
| 252 | void PositiveSmiTimesPowerOfTwoToInteger64(Register dst, |
| 253 | Register src, |
| 254 | int power); |
| 255 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 256 | // Divide a positive smi's integer value by a power of two. |
| 257 | // Provides result as 32-bit integer value. |
| 258 | void PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 259 | Register src, |
| 260 | int power); |
| 261 | |
| 262 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 263 | // Simple comparison of smis. |
| 264 | void SmiCompare(Register dst, Register src); |
| 265 | void SmiCompare(Register dst, Smi* src); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 266 | void SmiCompare(Register dst, const Operand& src); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 267 | void SmiCompare(const Operand& dst, Register src); |
| 268 | void SmiCompare(const Operand& dst, Smi* src); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 269 | // Compare the int32 in src register to the value of the smi stored at dst. |
| 270 | void SmiCompareInteger32(const Operand& dst, Register src); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 271 | // Sets sign and zero flags depending on value of smi in register. |
| 272 | void SmiTest(Register src); |
| 273 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 274 | // Functions performing a check on a known or potential smi. Returns |
| 275 | // a condition that is satisfied if the check is successful. |
| 276 | |
| 277 | // Is the value a tagged smi. |
| 278 | Condition CheckSmi(Register src); |
| 279 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 280 | // Is the value a positive tagged smi. |
| 281 | Condition CheckPositiveSmi(Register src); |
| 282 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 283 | // Are both values tagged smis. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 284 | Condition CheckBothSmi(Register first, Register second); |
| 285 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 286 | // Are both values tagged smis. |
| 287 | Condition CheckBothPositiveSmi(Register first, Register second); |
| 288 | |
| 289 | // Are either value a tagged smi. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 290 | Condition CheckEitherSmi(Register first, |
| 291 | Register second, |
| 292 | Register scratch = kScratchRegister); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 293 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 294 | // Is the value the minimum smi value (since we are using |
| 295 | // two's complement numbers, negating the value is known to yield |
| 296 | // a non-smi value). |
| 297 | Condition CheckIsMinSmi(Register src); |
| 298 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 299 | // Checks whether an 32-bit integer value is a valid for conversion |
| 300 | // to a smi. |
| 301 | Condition CheckInteger32ValidSmiValue(Register src); |
| 302 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 303 | // Checks whether an 32-bit unsigned integer value is a valid for |
| 304 | // conversion to a smi. |
| 305 | Condition CheckUInteger32ValidSmiValue(Register src); |
| 306 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 307 | // Test-and-jump functions. Typically combines a check function |
| 308 | // above with a conditional jump. |
| 309 | |
| 310 | // Jump if the value cannot be represented by a smi. |
| 311 | void JumpIfNotValidSmiValue(Register src, Label* on_invalid); |
| 312 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 313 | // Jump if the unsigned integer value cannot be represented by a smi. |
| 314 | void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid); |
| 315 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 316 | // Jump to label if the value is a tagged smi. |
| 317 | void JumpIfSmi(Register src, Label* on_smi); |
| 318 | |
| 319 | // Jump to label if the value is not a tagged smi. |
| 320 | void JumpIfNotSmi(Register src, Label* on_not_smi); |
| 321 | |
| 322 | // Jump to label if the value is not a positive tagged smi. |
| 323 | void JumpIfNotPositiveSmi(Register src, Label* on_not_smi); |
| 324 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 325 | // 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] | 326 | // to the constant. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 327 | void JumpIfSmiEqualsConstant(Register src, Smi* constant, Label* on_equals); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 328 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 329 | // Jump if either or both register are not smi values. |
| 330 | void JumpIfNotBothSmi(Register src1, Register src2, Label* on_not_both_smi); |
| 331 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 332 | // Jump if either or both register are not positive smi values. |
| 333 | void JumpIfNotBothPositiveSmi(Register src1, Register src2, |
| 334 | Label* on_not_both_smi); |
| 335 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 336 | // Operations on tagged smi values. |
| 337 | |
| 338 | // Smis represent a subset of integers. The subset is always equivalent to |
| 339 | // a two's complement interpretation of a fixed number of bits. |
| 340 | |
| 341 | // Optimistically adds an integer constant to a supposed smi. |
| 342 | // If the src is not a smi, or the result is not a smi, jump to |
| 343 | // the label. |
| 344 | void SmiTryAddConstant(Register dst, |
| 345 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 346 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 347 | Label* on_not_smi_result); |
| 348 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 349 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 350 | // No overflow testing on the result is done. |
| 351 | void SmiAddConstant(Register dst, Register src, Smi* constant); |
| 352 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 353 | // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 354 | // No overflow testing on the result is done. |
| 355 | void SmiAddConstant(const Operand& dst, Smi* constant); |
| 356 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 357 | // Add an integer constant to a tagged smi, giving a tagged smi as result, |
| 358 | // 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] | 359 | void SmiAddConstant(Register dst, |
| 360 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 361 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 362 | Label* on_not_smi_result); |
| 363 | |
| 364 | // 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] | 365 | // result. No testing on the result is done. Sets the N and Z flags |
| 366 | // based on the value of the resulting integer. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 367 | void SmiSubConstant(Register dst, Register src, Smi* constant); |
| 368 | |
| 369 | // 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] | 370 | // 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] | 371 | void SmiSubConstant(Register dst, |
| 372 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 373 | Smi* constant, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 374 | Label* on_not_smi_result); |
| 375 | |
| 376 | // 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] | 377 | // NOTICE: This operation jumps on success, not failure! |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 378 | void SmiNeg(Register dst, |
| 379 | Register src, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 380 | Label* on_smi_result); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 381 | |
| 382 | // Adds smi values and return the result as a smi. |
| 383 | // If dst is src1, then src1 will be destroyed, even if |
| 384 | // the operation is unsuccessful. |
| 385 | void SmiAdd(Register dst, |
| 386 | Register src1, |
| 387 | Register src2, |
| 388 | Label* on_not_smi_result); |
| 389 | |
| 390 | // Subtracts smi values and return the result as a smi. |
| 391 | // If dst is src1, then src1 will be destroyed, even if |
| 392 | // the operation is unsuccessful. |
| 393 | void SmiSub(Register dst, |
| 394 | Register src1, |
| 395 | Register src2, |
| 396 | Label* on_not_smi_result); |
| 397 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 398 | void SmiSub(Register dst, |
| 399 | Register src1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 400 | const Operand& src2, |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 401 | Label* on_not_smi_result); |
| 402 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 403 | // Multiplies smi values and return the result as a smi, |
| 404 | // if possible. |
| 405 | // If dst is src1, then src1 will be destroyed, even if |
| 406 | // the operation is unsuccessful. |
| 407 | void SmiMul(Register dst, |
| 408 | Register src1, |
| 409 | Register src2, |
| 410 | Label* on_not_smi_result); |
| 411 | |
| 412 | // Divides one smi by another and returns the quotient. |
| 413 | // Clobbers rax and rdx registers. |
| 414 | void SmiDiv(Register dst, |
| 415 | Register src1, |
| 416 | Register src2, |
| 417 | Label* on_not_smi_result); |
| 418 | |
| 419 | // Divides one smi by another and returns the remainder. |
| 420 | // Clobbers rax and rdx registers. |
| 421 | void SmiMod(Register dst, |
| 422 | Register src1, |
| 423 | Register src2, |
| 424 | Label* on_not_smi_result); |
| 425 | |
| 426 | // Bitwise operations. |
| 427 | void SmiNot(Register dst, Register src); |
| 428 | void SmiAnd(Register dst, Register src1, Register src2); |
| 429 | void SmiOr(Register dst, Register src1, Register src2); |
| 430 | void SmiXor(Register dst, Register src1, Register src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 431 | void SmiAndConstant(Register dst, Register src1, Smi* constant); |
| 432 | void SmiOrConstant(Register dst, Register src1, Smi* constant); |
| 433 | void SmiXorConstant(Register dst, Register src1, Smi* constant); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 434 | |
| 435 | void SmiShiftLeftConstant(Register dst, |
| 436 | Register src, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 437 | int shift_value); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 438 | void SmiShiftLogicalRightConstant(Register dst, |
| 439 | Register src, |
| 440 | int shift_value, |
| 441 | Label* on_not_smi_result); |
| 442 | void SmiShiftArithmeticRightConstant(Register dst, |
| 443 | Register src, |
| 444 | int shift_value); |
| 445 | |
| 446 | // Shifts a smi value to the left, and returns the result if that is a smi. |
| 447 | // Uses and clobbers rcx, so dst may not be rcx. |
| 448 | void SmiShiftLeft(Register dst, |
| 449 | Register src1, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 450 | Register src2); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 451 | // Shifts a smi value to the right, shifting in zero bits at the top, and |
| 452 | // returns the unsigned intepretation of the result if that is a smi. |
| 453 | // Uses and clobbers rcx, so dst may not be rcx. |
| 454 | void SmiShiftLogicalRight(Register dst, |
| 455 | Register src1, |
| 456 | Register src2, |
| 457 | Label* on_not_smi_result); |
| 458 | // Shifts a smi value to the right, sign extending the top, and |
| 459 | // returns the signed intepretation of the result. That will always |
| 460 | // be a valid smi value, since it's numerically smaller than the |
| 461 | // original. |
| 462 | // Uses and clobbers rcx, so dst may not be rcx. |
| 463 | void SmiShiftArithmeticRight(Register dst, |
| 464 | Register src1, |
| 465 | Register src2); |
| 466 | |
| 467 | // Specialized operations |
| 468 | |
| 469 | // Select the non-smi register of two registers where exactly one is a |
| 470 | // smi. If neither are smis, jump to the failure label. |
| 471 | void SelectNonSmi(Register dst, |
| 472 | Register src1, |
| 473 | Register src2, |
| 474 | Label* on_not_smis); |
| 475 | |
| 476 | // Converts, if necessary, a smi to a combination of number and |
| 477 | // multiplier to be used as a scaled index. |
| 478 | // The src register contains a *positive* smi value. The shift is the |
| 479 | // power of two to multiply the index value by (e.g. |
| 480 | // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2). |
| 481 | // The returned index register may be either src or dst, depending |
| 482 | // on what is most efficient. If src and dst are different registers, |
| 483 | // src is always unchanged. |
| 484 | SmiIndex SmiToIndex(Register dst, Register src, int shift); |
| 485 | |
| 486 | // Converts a positive smi to a negative index. |
| 487 | SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift); |
| 488 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 489 | // Basic Smi operations. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 490 | void Move(Register dst, Smi* source) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 491 | LoadSmiConstant(dst, source); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void Move(const Operand& dst, Smi* source) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 495 | Register constant = GetSmiConstant(source); |
| 496 | movq(dst, constant); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 497 | } |
| 498 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 499 | void Push(Smi* smi); |
| 500 | void Test(const Operand& dst, Smi* source); |
| 501 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 502 | // --------------------------------------------------------------------------- |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 503 | // String macros. |
| 504 | void JumpIfNotBothSequentialAsciiStrings(Register first_object, |
| 505 | Register second_object, |
| 506 | Register scratch1, |
| 507 | Register scratch2, |
| 508 | Label* on_not_both_flat_ascii); |
| 509 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 510 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 511 | // label if not. If the instance type can be scratched specify same register |
| 512 | // for both instance type and scratch. |
| 513 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 514 | Register scratch, |
| 515 | Label *on_not_flat_ascii_string); |
| 516 | |
| 517 | void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 518 | Register first_object_instance_type, |
| 519 | Register second_object_instance_type, |
| 520 | Register scratch1, |
| 521 | Register scratch2, |
| 522 | Label* on_fail); |
| 523 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 524 | // --------------------------------------------------------------------------- |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 525 | // Macro instructions. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 526 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 527 | // Load a register with a long value as efficiently as possible. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 528 | void Set(Register dst, int64_t x); |
| 529 | void Set(const Operand& dst, int64_t x); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 530 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 531 | // Handle support |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 532 | void Move(Register dst, Handle<Object> source); |
| 533 | void Move(const Operand& dst, Handle<Object> source); |
| 534 | void Cmp(Register dst, Handle<Object> source); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 535 | void Cmp(const Operand& dst, Handle<Object> source); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 536 | void Push(Handle<Object> source); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 537 | |
| 538 | // Emit code to discard a non-negative number of pointer-sized elements |
| 539 | // from the stack, clobbering only the rsp register. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 540 | void Drop(int stack_elements); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 541 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 542 | void Call(Label* target) { call(target); } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 543 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 544 | // Control Flow |
| 545 | void Jump(Address destination, RelocInfo::Mode rmode); |
| 546 | void Jump(ExternalReference ext); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 547 | void Jump(Handle<Code> code_object, RelocInfo::Mode rmode); |
| 548 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 549 | void Call(Address destination, RelocInfo::Mode rmode); |
| 550 | void Call(ExternalReference ext); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 551 | void Call(Handle<Code> code_object, RelocInfo::Mode rmode); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 552 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 553 | // Compare object type for heap object. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 554 | // Always use unsigned comparisons: above and below, not less and greater. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 555 | // Incoming register is heap_object and outgoing register is map. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 556 | // They may be the same register, and may be kScratchRegister. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 557 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 558 | |
| 559 | // Compare instance type for map. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 560 | // Always use unsigned comparisons: above and below, not less and greater. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 561 | void CmpInstanceType(Register map, InstanceType type); |
| 562 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 563 | // Check if the map of an object is equal to a specified map and |
| 564 | // branch to label if not. Skip the smi check if not required |
| 565 | // (object is known to be a heap object) |
| 566 | void CheckMap(Register obj, |
| 567 | Handle<Map> map, |
| 568 | Label* fail, |
| 569 | bool is_heap_object); |
| 570 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 571 | // Check if the object in register heap_object is a string. Afterwards the |
| 572 | // register map contains the object map and the register instance_type |
| 573 | // contains the instance_type. The registers map and instance_type can be the |
| 574 | // same in which case it contains the instance type afterwards. Either of the |
| 575 | // registers map and instance_type can be the same as heap_object. |
| 576 | Condition IsObjectStringType(Register heap_object, |
| 577 | Register map, |
| 578 | Register instance_type); |
| 579 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 580 | // FCmp compares and pops the two values on top of the FPU stack. |
| 581 | // The flag results are similar to integer cmp, but requires unsigned |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 582 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 583 | void FCmp(); |
| 584 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 585 | // 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] | 586 | void AbortIfNotNumber(Register object); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 587 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 588 | // Abort execution if argument is a smi. Used in debug code. |
| 589 | void AbortIfSmi(Register object); |
| 590 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 591 | // 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] | 592 | void AbortIfNotSmi(Register object); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 593 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 594 | // Abort execution if argument is not the root value with the given index. |
| 595 | void AbortIfNotRootValue(Register src, |
| 596 | Heap::RootListIndex root_value_index, |
| 597 | const char* message); |
| 598 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 599 | // --------------------------------------------------------------------------- |
| 600 | // Exception handling |
| 601 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 602 | // Push a new try handler and link into try handler chain. The return |
| 603 | // address must be pushed before calling this helper. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 604 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 605 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 606 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 607 | void PopTryHandler(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 608 | |
| 609 | // --------------------------------------------------------------------------- |
| 610 | // Inline caching support |
| 611 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 612 | // Generate code for checking access rights - used for security checks |
| 613 | // on access to global objects across environments. The holder register |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 614 | // is left untouched, but the scratch register and kScratchRegister, |
| 615 | // which must be different, are clobbered. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 616 | void CheckAccessGlobalProxy(Register holder_reg, |
| 617 | Register scratch, |
| 618 | Label* miss); |
| 619 | |
| 620 | |
| 621 | // --------------------------------------------------------------------------- |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 622 | // Allocation support |
| 623 | |
| 624 | // Allocate an object in new space. If the new space is exhausted control |
| 625 | // continues at the gc_required label. The allocated object is returned in |
| 626 | // result and end of the new object is returned in result_end. The register |
| 627 | // scratch can be passed as no_reg in which case an additional object |
| 628 | // reference will be added to the reloc info. The returned pointers in result |
| 629 | // and result_end have not yet been tagged as heap objects. If |
| 630 | // result_contains_top_on_entry is true the content of result is known to be |
| 631 | // 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] | 632 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 633 | // should be no_reg as it is never used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 634 | void AllocateInNewSpace(int object_size, |
| 635 | Register result, |
| 636 | Register result_end, |
| 637 | Register scratch, |
| 638 | Label* gc_required, |
| 639 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 640 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 641 | void AllocateInNewSpace(int header_size, |
| 642 | ScaleFactor element_size, |
| 643 | Register element_count, |
| 644 | Register result, |
| 645 | Register result_end, |
| 646 | Register scratch, |
| 647 | Label* gc_required, |
| 648 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 649 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 650 | void AllocateInNewSpace(Register object_size, |
| 651 | Register result, |
| 652 | Register result_end, |
| 653 | Register scratch, |
| 654 | Label* gc_required, |
| 655 | AllocationFlags flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 656 | |
| 657 | // Undo allocation in new space. The object passed and objects allocated after |
| 658 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 659 | // object(s) no longer allocated as they would be invalid when allocation is |
| 660 | // un-done. |
| 661 | void UndoAllocationInNewSpace(Register object); |
| 662 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 663 | // Allocate a heap number in new space with undefined value. Returns |
| 664 | // tagged pointer in result register, or jumps to gc_required if new |
| 665 | // space is full. |
| 666 | void AllocateHeapNumber(Register result, |
| 667 | Register scratch, |
| 668 | Label* gc_required); |
| 669 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 670 | // Allocate a sequential string. All the header fields of the string object |
| 671 | // are initialized. |
| 672 | void AllocateTwoByteString(Register result, |
| 673 | Register length, |
| 674 | Register scratch1, |
| 675 | Register scratch2, |
| 676 | Register scratch3, |
| 677 | Label* gc_required); |
| 678 | void AllocateAsciiString(Register result, |
| 679 | Register length, |
| 680 | Register scratch1, |
| 681 | Register scratch2, |
| 682 | Register scratch3, |
| 683 | Label* gc_required); |
| 684 | |
| 685 | // Allocate a raw cons string object. Only the map field of the result is |
| 686 | // initialized. |
| 687 | void AllocateConsString(Register result, |
| 688 | Register scratch1, |
| 689 | Register scratch2, |
| 690 | Label* gc_required); |
| 691 | void AllocateAsciiConsString(Register result, |
| 692 | Register scratch1, |
| 693 | Register scratch2, |
| 694 | Label* gc_required); |
| 695 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 696 | // --------------------------------------------------------------------------- |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 697 | // Support functions. |
| 698 | |
| 699 | // Check if result is zero and op is negative. |
| 700 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 701 | |
| 702 | // Check if result is zero and op is negative in code using jump targets. |
| 703 | void NegativeZeroTest(CodeGenerator* cgen, |
| 704 | Register result, |
| 705 | Register op, |
| 706 | JumpTarget* then_target); |
| 707 | |
| 708 | // Check if result is zero and any of op1 and op2 are negative. |
| 709 | // Register scratch is destroyed, and it must be different from op2. |
| 710 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 711 | Register scratch, Label* then_label); |
| 712 | |
| 713 | // Try to get function prototype of a function and puts the value in |
| 714 | // the result register. Checks that the function really is a |
| 715 | // 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] | 716 | // function register will be untouched; the other register may be |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 717 | // clobbered. |
| 718 | void TryGetFunctionPrototype(Register function, |
| 719 | Register result, |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 720 | Label* miss); |
| 721 | |
| 722 | // Generates code for reporting that an illegal operation has |
| 723 | // occurred. |
| 724 | void IllegalOperation(int num_arguments); |
| 725 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 726 | // Find the function context up the context chain. |
| 727 | void LoadContext(Register dst, int context_chain_length); |
| 728 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 729 | // --------------------------------------------------------------------------- |
| 730 | // Runtime calls |
| 731 | |
| 732 | // Call a code stub. |
| 733 | void CallStub(CodeStub* stub); |
| 734 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 735 | // Call a code stub and return the code object called. Try to generate |
| 736 | // the code if necessary. Do not perform a GC but instead return a retry |
| 737 | // after GC failure. |
| 738 | Object* TryCallStub(CodeStub* stub); |
| 739 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 740 | // Tail call a code stub (jump). |
| 741 | void TailCallStub(CodeStub* stub); |
| 742 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 743 | // Tail call a code stub (jump) and return the code object called. Try to |
| 744 | // generate the code if necessary. Do not perform a GC but instead return |
| 745 | // a retry after GC failure. |
| 746 | Object* TryTailCallStub(CodeStub* stub); |
| 747 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 748 | // Return from a code stub after popping its arguments. |
| 749 | void StubReturn(int argc); |
| 750 | |
| 751 | // Call a runtime routine. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 752 | void CallRuntime(Runtime::Function* f, int num_arguments); |
| 753 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 754 | // Call a runtime function, returning the CodeStub object called. |
| 755 | // Try to generate the stub code if necessary. Do not perform a GC |
| 756 | // but instead return a retry after GC failure. |
| 757 | Object* TryCallRuntime(Runtime::Function* f, int num_arguments); |
| 758 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 759 | // Convenience function: Same as above, but takes the fid instead. |
| 760 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 761 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 762 | // Convenience function: Same as above, but takes the fid instead. |
| 763 | Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments); |
| 764 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 765 | // Convenience function: call an external reference. |
| 766 | void CallExternalReference(const ExternalReference& ext, |
| 767 | int num_arguments); |
| 768 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 769 | // Tail call of a runtime routine (jump). |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 770 | // Like JumpToExternalReference, but also takes care of passing the number |
| 771 | // of parameters. |
| 772 | void TailCallExternalReference(const ExternalReference& ext, |
| 773 | int num_arguments, |
| 774 | int result_size); |
| 775 | |
| 776 | // Convenience function: tail call a runtime routine (jump). |
| 777 | void TailCallRuntime(Runtime::FunctionId fid, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 778 | int num_arguments, |
| 779 | int result_size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 780 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 781 | void PushHandleScope(Register scratch); |
| 782 | |
| 783 | // Pops a handle scope using the specified scratch register and |
| 784 | // ensuring that saved register is left unchanged. |
| 785 | void PopHandleScope(Register saved, Register scratch); |
| 786 | |
| 787 | // As PopHandleScope, but does not perform a GC. Instead, returns a |
| 788 | // retry after GC failure object if GC is necessary. |
| 789 | Object* TryPopHandleScope(Register saved, Register scratch); |
| 790 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 791 | // Jump to a runtime routine. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 792 | void JumpToExternalReference(const ExternalReference& ext, int result_size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 793 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 794 | // Before calling a C-function from generated code, align arguments on stack. |
| 795 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 796 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 797 | // The number of slots reserved for arguments depends on platform. On Windows |
| 798 | // stack slots are reserved for the arguments passed in registers. On other |
| 799 | // platforms stack slots are only reserved for the arguments actually passed |
| 800 | // on the stack. |
| 801 | void PrepareCallCFunction(int num_arguments); |
| 802 | |
| 803 | // Calls a C function and cleans up the space for arguments allocated |
| 804 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 805 | // garbage collection, since that might move the code and invalidate the |
| 806 | // return address (unless this is somehow accounted for by the called |
| 807 | // function). |
| 808 | void CallCFunction(ExternalReference function, int num_arguments); |
| 809 | void CallCFunction(Register function, int num_arguments); |
| 810 | |
| 811 | // Calculate the number of stack slots to reserve for arguments when calling a |
| 812 | // C function. |
| 813 | int ArgumentStackSlotsForCFunctionCall(int num_arguments); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 814 | |
| 815 | // --------------------------------------------------------------------------- |
| 816 | // Utilities |
| 817 | |
| 818 | void Ret(); |
| 819 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 820 | Handle<Object> CodeObject() { return code_object_; } |
| 821 | |
| 822 | |
| 823 | // --------------------------------------------------------------------------- |
| 824 | // StatsCounter support |
| 825 | |
| 826 | void SetCounter(StatsCounter* counter, int value); |
| 827 | void IncrementCounter(StatsCounter* counter, int value); |
| 828 | void DecrementCounter(StatsCounter* counter, int value); |
| 829 | |
| 830 | |
| 831 | // --------------------------------------------------------------------------- |
| 832 | // Debugging |
| 833 | |
| 834 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 835 | // Use --debug_code to enable. |
| 836 | void Assert(Condition cc, const char* msg); |
| 837 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 838 | void AssertFastElements(Register elements); |
| 839 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 840 | // Like Assert(), but always enabled. |
| 841 | void Check(Condition cc, const char* msg); |
| 842 | |
| 843 | // Print a message to stdout and abort execution. |
| 844 | void Abort(const char* msg); |
| 845 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 846 | // Check that the stack is aligned. |
| 847 | void CheckStackAlignment(); |
| 848 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 849 | // Verify restrictions about code generated in stubs. |
| 850 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 851 | bool generating_stub() { return generating_stub_; } |
| 852 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 853 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 854 | |
| 855 | private: |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 856 | bool generating_stub_; |
| 857 | bool allow_stub_calls_; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 858 | |
| 859 | // Returns a register holding the smi value. The register MUST NOT be |
| 860 | // modified. It may be the "smi 1 constant" register. |
| 861 | Register GetSmiConstant(Smi* value); |
| 862 | |
| 863 | // Moves the smi value to the destination register. |
| 864 | void LoadSmiConstant(Register dst, Smi* value); |
| 865 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 866 | // This handle will be patched with the code object on installation. |
| 867 | Handle<Object> code_object_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 868 | |
| 869 | // Helper functions for generating invokes. |
| 870 | void InvokePrologue(const ParameterCount& expected, |
| 871 | const ParameterCount& actual, |
| 872 | Handle<Code> code_constant, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 873 | Register code_register, |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 874 | Label* done, |
| 875 | InvokeFlag flag); |
| 876 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 877 | // Activation support. |
| 878 | void EnterFrame(StackFrame::Type type); |
| 879 | void LeaveFrame(StackFrame::Type type); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 880 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 881 | void EnterExitFramePrologue(ExitFrame::Mode mode, bool save_rax); |
| 882 | void EnterExitFrameEpilogue(ExitFrame::Mode mode, int result_size, int argc); |
| 883 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 884 | // Allocation support helpers. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 885 | // Loads the top of new-space into the result register. |
| 886 | // If flags contains RESULT_CONTAINS_TOP then result_end is valid and |
| 887 | // already contains the top of new-space, and scratch is invalid. |
| 888 | // Otherwise the address of the new-space top is loaded into scratch (if |
| 889 | // 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] | 890 | void LoadAllocationTopHelper(Register result, |
| 891 | Register result_end, |
| 892 | Register scratch, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 893 | AllocationFlags flags); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 894 | // Update allocation top with value in result_end register. |
| 895 | // 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] | 896 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 897 | |
| 898 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 899 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 900 | // possibly returns a failure object indicating an allocation failure. |
| 901 | Object* PopHandleScopeHelper(Register saved, |
| 902 | Register scratch, |
| 903 | bool gc_allowed); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 904 | }; |
| 905 | |
| 906 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 907 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 908 | // debugging and other types of instrumentation. When using the code patcher |
| 909 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 910 | // relocation information. If any of these constraints are violated it causes |
| 911 | // an assertion. |
| 912 | class CodePatcher { |
| 913 | public: |
| 914 | CodePatcher(byte* address, int size); |
| 915 | virtual ~CodePatcher(); |
| 916 | |
| 917 | // Macro assembler to emit code. |
| 918 | MacroAssembler* masm() { return &masm_; } |
| 919 | |
| 920 | private: |
| 921 | byte* address_; // The address of the code being patched. |
| 922 | int size_; // Number of bytes of the expected patch size. |
| 923 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 924 | }; |
| 925 | |
| 926 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 927 | // ----------------------------------------------------------------------------- |
| 928 | // Static helper functions. |
| 929 | |
| 930 | // Generate an Operand for loading a field from an object. |
| 931 | static inline Operand FieldOperand(Register object, int offset) { |
| 932 | return Operand(object, offset - kHeapObjectTag); |
| 933 | } |
| 934 | |
| 935 | |
| 936 | // Generate an Operand for loading an indexed field from an object. |
| 937 | static inline Operand FieldOperand(Register object, |
| 938 | Register index, |
| 939 | ScaleFactor scale, |
| 940 | int offset) { |
| 941 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 942 | } |
| 943 | |
| 944 | |
| 945 | #ifdef GENERATED_CODE_COVERAGE |
| 946 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 947 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 948 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 949 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 950 | #define ACCESS_MASM(masm) { \ |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 951 | byte* x64_coverage_function = \ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 952 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 953 | masm->pushfd(); \ |
| 954 | masm->pushad(); \ |
| 955 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 956 | masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 957 | masm->pop(rax); \ |
| 958 | masm->popad(); \ |
| 959 | masm->popfd(); \ |
| 960 | } \ |
| 961 | masm-> |
| 962 | #else |
| 963 | #define ACCESS_MASM(masm) masm-> |
| 964 | #endif |
| 965 | |
| 966 | |
| 967 | } } // namespace v8::internal |
| 968 | |
| 969 | #endif // V8_X64_MACRO_ASSEMBLER_X64_H_ |