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