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