Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
| 28 | #ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 29 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 32 | #include "frames.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 33 | #include "v8globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 38 | // Flags used for the AllocateInNewSpace functions. |
| 39 | enum AllocationFlags { |
| 40 | // No special flags. |
| 41 | NO_ALLOCATION_FLAGS = 0, |
| 42 | // Return the pointer to the allocated already tagged as a heap object. |
| 43 | TAG_OBJECT = 1 << 0, |
| 44 | // The content of the result register already contains the allocation top in |
| 45 | // new space. |
| 46 | RESULT_CONTAINS_TOP = 1 << 1 |
| 47 | }; |
| 48 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 49 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 50 | // Convenience for platform-independent signatures. We do not normally |
| 51 | // distinguish memory operands from other operands on ia32. |
| 52 | typedef Operand MemOperand; |
| 53 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 54 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 55 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
| 56 | |
| 57 | |
| 58 | bool AreAliased(Register r1, Register r2, Register r3, Register r4); |
| 59 | |
| 60 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | // MacroAssembler implements a collection of frequently used macros. |
| 62 | class MacroAssembler: public Assembler { |
| 63 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 64 | // The isolate parameter can be NULL if the macro assembler should |
| 65 | // not use isolate-dependent functionality. In this case, it's the |
| 66 | // responsibility of the caller to never invoke such function on the |
| 67 | // macro assembler. |
| 68 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 69 | |
| 70 | // --------------------------------------------------------------------------- |
| 71 | // GC Support |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 72 | enum RememberedSetFinalAction { |
| 73 | kReturnAtEnd, |
| 74 | kFallThroughAtEnd |
| 75 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 76 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 77 | // Record in the remembered set the fact that we have a pointer to new space |
| 78 | // at the address pointed to by the addr register. Only works if addr is not |
| 79 | // in new space. |
| 80 | void RememberedSetHelper(Register object, // Used for debug code. |
| 81 | Register addr, |
| 82 | Register scratch, |
| 83 | SaveFPRegsMode save_fp, |
| 84 | RememberedSetFinalAction and_then); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 85 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 86 | void CheckPageFlag(Register object, |
| 87 | Register scratch, |
| 88 | int mask, |
| 89 | Condition cc, |
| 90 | Label* condition_met, |
| 91 | Label::Distance condition_met_distance = Label::kFar); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 92 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 93 | // Check if object is in new space. Jumps if the object is not in new space. |
| 94 | // The register scratch can be object itself, but scratch will be clobbered. |
| 95 | void JumpIfNotInNewSpace(Register object, |
| 96 | Register scratch, |
| 97 | Label* branch, |
| 98 | Label::Distance distance = Label::kFar) { |
| 99 | InNewSpace(object, scratch, zero, branch, distance); |
| 100 | } |
| 101 | |
| 102 | // Check if object is in new space. Jumps if the object is in new space. |
| 103 | // The register scratch can be object itself, but it will be clobbered. |
| 104 | void JumpIfInNewSpace(Register object, |
| 105 | Register scratch, |
| 106 | Label* branch, |
| 107 | Label::Distance distance = Label::kFar) { |
| 108 | InNewSpace(object, scratch, not_zero, branch, distance); |
| 109 | } |
| 110 | |
| 111 | // Check if an object has a given incremental marking color. Also uses ecx! |
| 112 | void HasColor(Register object, |
| 113 | Register scratch0, |
| 114 | Register scratch1, |
| 115 | Label* has_color, |
| 116 | Label::Distance has_color_distance, |
| 117 | int first_bit, |
| 118 | int second_bit); |
| 119 | |
| 120 | void JumpIfBlack(Register object, |
| 121 | Register scratch0, |
| 122 | Register scratch1, |
| 123 | Label* on_black, |
| 124 | Label::Distance on_black_distance = Label::kFar); |
| 125 | |
| 126 | // Checks the color of an object. If the object is already grey or black |
| 127 | // then we just fall through, since it is already live. If it is white and |
| 128 | // we can determine that it doesn't need to be scanned, then we just mark it |
| 129 | // black and fall through. For the rest we jump to the label so the |
| 130 | // incremental marker can fix its assumptions. |
| 131 | void EnsureNotWhite(Register object, |
| 132 | Register scratch1, |
| 133 | Register scratch2, |
| 134 | Label* object_is_white_and_not_data, |
| 135 | Label::Distance distance); |
| 136 | |
| 137 | // Notify the garbage collector that we wrote a pointer into an object. |
| 138 | // |object| is the object being stored into, |value| is the object being |
| 139 | // stored. value and scratch registers are clobbered by the operation. |
| 140 | // The offset is the offset from the start of the object, not the offset from |
| 141 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 142 | void RecordWriteField( |
| 143 | Register object, |
| 144 | int offset, |
| 145 | Register value, |
| 146 | Register scratch, |
| 147 | SaveFPRegsMode save_fp, |
| 148 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 149 | SmiCheck smi_check = INLINE_SMI_CHECK); |
| 150 | |
| 151 | // As above, but the offset has the tag presubtracted. For use with |
| 152 | // Operand(reg, off). |
| 153 | void RecordWriteContextSlot( |
| 154 | Register context, |
| 155 | int offset, |
| 156 | Register value, |
| 157 | Register scratch, |
| 158 | SaveFPRegsMode save_fp, |
| 159 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 160 | SmiCheck smi_check = INLINE_SMI_CHECK) { |
| 161 | RecordWriteField(context, |
| 162 | offset + kHeapObjectTag, |
| 163 | value, |
| 164 | scratch, |
| 165 | save_fp, |
| 166 | remembered_set_action, |
| 167 | smi_check); |
| 168 | } |
| 169 | |
| 170 | // Notify the garbage collector that we wrote a pointer into a fixed array. |
| 171 | // |array| is the array being stored into, |value| is the |
| 172 | // object being stored. |index| is the array index represented as a |
| 173 | // Smi. All registers are clobbered by the operation RecordWriteArray |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 174 | // filters out smis so it does not update the write barrier if the |
| 175 | // value is a smi. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 176 | void RecordWriteArray( |
| 177 | Register array, |
| 178 | Register value, |
| 179 | Register index, |
| 180 | SaveFPRegsMode save_fp, |
| 181 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 182 | SmiCheck smi_check = INLINE_SMI_CHECK); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 184 | // For page containing |object| mark region covering |address| |
| 185 | // dirty. |object| is the object being stored into, |value| is the |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 186 | // object being stored. The address and value registers are clobbered by the |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 187 | // operation. RecordWrite filters out smis so it does not update the |
| 188 | // write barrier if the value is a smi. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 189 | void RecordWrite( |
| 190 | Register object, |
| 191 | Register address, |
| 192 | Register value, |
| 193 | SaveFPRegsMode save_fp, |
| 194 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 195 | SmiCheck smi_check = INLINE_SMI_CHECK); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 196 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 197 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 198 | // --------------------------------------------------------------------------- |
| 199 | // Debugger Support |
| 200 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 201 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | #endif |
| 203 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 204 | // Enter specific kind of exit frame. Expects the number of |
| 205 | // arguments in register eax and sets up the number of arguments in |
| 206 | // register edi and the pointer to the first argument in register |
| 207 | // esi. |
| 208 | void EnterExitFrame(bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 209 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 210 | void EnterApiExitFrame(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | |
| 212 | // Leave the current exit frame. Expects the return value in |
| 213 | // register eax:edx (untouched) and the pointer to the first |
| 214 | // argument in register esi. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 215 | void LeaveExitFrame(bool save_doubles); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 216 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 217 | // Leave the current exit frame. Expects the return value in |
| 218 | // register eax (untouched). |
| 219 | void LeaveApiExitFrame(); |
| 220 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 221 | // Find the function context up the context chain. |
| 222 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 223 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 224 | // Load the global function with the given index. |
| 225 | void LoadGlobalFunction(int index, Register function); |
| 226 | |
| 227 | // Load the initial map from the global function. The registers |
| 228 | // function and map can be the same. |
| 229 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 230 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 231 | // Push and pop the registers that can hold pointers. |
| 232 | void PushSafepointRegisters() { pushad(); } |
| 233 | void PopSafepointRegisters() { popad(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 234 | // Store the value in register/immediate src in the safepoint |
| 235 | // register stack slot for register dst. |
| 236 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
| 237 | void StoreToSafepointRegisterSlot(Register dst, Immediate src); |
| 238 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 239 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | // --------------------------------------------------------------------------- |
| 241 | // JavaScript invokes |
| 242 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 243 | // Setup call kind marking in ecx. The method takes ecx as an |
| 244 | // explicit first parameter to make the code more readable at the |
| 245 | // call sites. |
| 246 | void SetCallKind(Register dst, CallKind kind); |
| 247 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 249 | void InvokeCode(Register code, |
| 250 | const ParameterCount& expected, |
| 251 | const ParameterCount& actual, |
| 252 | InvokeFlag flag, |
| 253 | const CallWrapper& call_wrapper, |
| 254 | CallKind call_kind) { |
| 255 | InvokeCode(Operand(code), expected, actual, flag, call_wrapper, call_kind); |
| 256 | } |
| 257 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | void InvokeCode(const Operand& code, |
| 259 | const ParameterCount& expected, |
| 260 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 261 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 262 | const CallWrapper& call_wrapper, |
| 263 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 264 | |
| 265 | void InvokeCode(Handle<Code> code, |
| 266 | const ParameterCount& expected, |
| 267 | const ParameterCount& actual, |
| 268 | RelocInfo::Mode rmode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 269 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 270 | const CallWrapper& call_wrapper, |
| 271 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 272 | |
| 273 | // Invoke the JavaScript function in the given register. Changes the |
| 274 | // current context to the context in the function before invoking. |
| 275 | void InvokeFunction(Register function, |
| 276 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 277 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 278 | const CallWrapper& call_wrapper, |
| 279 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 280 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 281 | void InvokeFunction(Handle<JSFunction> function, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 282 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 283 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 284 | const CallWrapper& call_wrapper, |
| 285 | CallKind call_kind); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 286 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 287 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 288 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 289 | void InvokeBuiltin(Builtins::JavaScript id, |
| 290 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 291 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 292 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 293 | // Store the function for the given builtin in the target register. |
| 294 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 295 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 296 | // Store the code object for the given builtin in the target register. |
| 297 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 298 | |
| 299 | // Expression support |
| 300 | void Set(Register dst, const Immediate& x); |
| 301 | void Set(const Operand& dst, const Immediate& x); |
| 302 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 303 | // Support for constant splitting. |
| 304 | bool IsUnsafeImmediate(const Immediate& x); |
| 305 | void SafeSet(Register dst, const Immediate& x); |
| 306 | void SafePush(const Immediate& x); |
| 307 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 308 | // Compare a register against a known root, e.g. undefined, null, true, ... |
| 309 | void CompareRoot(Register with, Heap::RootListIndex index); |
| 310 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | // Compare object type for heap object. |
| 312 | // Incoming register is heap_object and outgoing register is map. |
| 313 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 314 | |
| 315 | // Compare instance type for map. |
| 316 | void CmpInstanceType(Register map, InstanceType type); |
| 317 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 318 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 319 | // Jump to the specified label if it does not. |
| 320 | void CheckFastElements(Register map, |
| 321 | Label* fail, |
| 322 | Label::Distance distance = Label::kFar); |
| 323 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 324 | // Check if a map for a JSObject indicates that the object can have both smi |
| 325 | // and HeapObject elements. Jump to the specified label if it does not. |
| 326 | void CheckFastObjectElements(Register map, |
| 327 | Label* fail, |
| 328 | Label::Distance distance = Label::kFar); |
| 329 | |
| 330 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 331 | // elements. Jump to the specified label if it does not. |
| 332 | void CheckFastSmiOnlyElements(Register map, |
| 333 | Label* fail, |
| 334 | Label::Distance distance = Label::kFar); |
| 335 | |
| 336 | // Check to see if maybe_number can be stored as a double in |
| 337 | // FastDoubleElements. If it can, store it at the index specified by key in |
| 338 | // the FastDoubleElements array elements, otherwise jump to fail. |
| 339 | void StoreNumberToDoubleElements(Register maybe_number, |
| 340 | Register elements, |
| 341 | Register key, |
| 342 | Register scratch1, |
| 343 | XMMRegister scratch2, |
| 344 | Label* fail, |
| 345 | bool specialize_for_processor); |
| 346 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 347 | // Check if the map of an object is equal to a specified map and branch to |
| 348 | // label if not. Skip the smi check if not required (object is known to be a |
| 349 | // heap object) |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 350 | void CheckMap(Register obj, |
| 351 | Handle<Map> map, |
| 352 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 353 | SmiCheckType smi_check_type); |
| 354 | |
| 355 | // Check if the map of an object is equal to a specified map and branch to a |
| 356 | // specified target if equal. Skip the smi check if not required (object is |
| 357 | // known to be a heap object) |
| 358 | void DispatchMap(Register obj, |
| 359 | Handle<Map> map, |
| 360 | Handle<Code> success, |
| 361 | SmiCheckType smi_check_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 362 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 363 | // Check if the object in register heap_object is a string. Afterwards the |
| 364 | // register map contains the object map and the register instance_type |
| 365 | // contains the instance_type. The registers map and instance_type can be the |
| 366 | // same in which case it contains the instance type afterwards. Either of the |
| 367 | // registers map and instance_type can be the same as heap_object. |
| 368 | Condition IsObjectStringType(Register heap_object, |
| 369 | Register map, |
| 370 | Register instance_type); |
| 371 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 372 | // Check if a heap object's type is in the JSObject range, not including |
| 373 | // JSFunction. The object's map will be loaded in the map register. |
| 374 | // Any or all of the three registers may be the same. |
| 375 | // The contents of the scratch register will always be overwritten. |
| 376 | void IsObjectJSObjectType(Register heap_object, |
| 377 | Register map, |
| 378 | Register scratch, |
| 379 | Label* fail); |
| 380 | |
| 381 | // The contents of the scratch register will be overwritten. |
| 382 | void IsInstanceJSObjectType(Register map, Register scratch, Label* fail); |
| 383 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | // FCmp is similar to integer cmp, but requires unsigned |
| 385 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 386 | void FCmp(); |
| 387 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 388 | void ClampUint8(Register reg); |
| 389 | |
| 390 | void ClampDoubleToUint8(XMMRegister input_reg, |
| 391 | XMMRegister scratch_reg, |
| 392 | Register result_reg); |
| 393 | |
| 394 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 395 | // Smi tagging support. |
| 396 | void SmiTag(Register reg) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 397 | STATIC_ASSERT(kSmiTag == 0); |
| 398 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 399 | add(reg, reg); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 400 | } |
| 401 | void SmiUntag(Register reg) { |
| 402 | sar(reg, kSmiTagSize); |
| 403 | } |
| 404 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 405 | // Modifies the register even if it does not contain a Smi! |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 406 | void SmiUntag(Register reg, Label* is_smi) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 407 | STATIC_ASSERT(kSmiTagSize == 1); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 408 | sar(reg, kSmiTagSize); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 409 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 410 | j(not_carry, is_smi); |
| 411 | } |
| 412 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 413 | // Jump the register contains a smi. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 414 | inline void JumpIfSmi(Register value, |
| 415 | Label* smi_label, |
| 416 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 417 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 418 | j(zero, smi_label, distance); |
| 419 | } |
| 420 | // Jump if the operand is a smi. |
| 421 | inline void JumpIfSmi(Operand value, |
| 422 | Label* smi_label, |
| 423 | Label::Distance distance = Label::kFar) { |
| 424 | test(value, Immediate(kSmiTagMask)); |
| 425 | j(zero, smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 426 | } |
| 427 | // Jump if register contain a non-smi. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 428 | inline void JumpIfNotSmi(Register value, |
| 429 | Label* not_smi_label, |
| 430 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 431 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 432 | j(not_zero, not_smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 435 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 436 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 437 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 438 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 439 | // Abort execution if argument is not a number. Used in debug code. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 440 | void AbortIfNotNumber(Register object); |
| 441 | |
| 442 | // Abort execution if argument is not a smi. Used in debug code. |
| 443 | void AbortIfNotSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 444 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 445 | // Abort execution if argument is a smi. Used in debug code. |
| 446 | void AbortIfSmi(Register object); |
| 447 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 448 | // Abort execution if argument is a string. Used in debug code. |
| 449 | void AbortIfNotString(Register object); |
| 450 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | // --------------------------------------------------------------------------- |
| 452 | // Exception handling |
| 453 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 454 | // Push a new try handler and link it into try handler chain. |
| 455 | void PushTryHandler(CodeLocation try_location, |
| 456 | HandlerType type, |
| 457 | int handler_index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 459 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 460 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 461 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 462 | // Activate the top handler in the try hander chain. |
| 463 | void Throw(Register value); |
| 464 | |
| 465 | void ThrowUncatchable(UncatchableExceptionType type, Register value); |
| 466 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 467 | // --------------------------------------------------------------------------- |
| 468 | // Inline caching support |
| 469 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | // Generate code for checking access rights - used for security checks |
| 471 | // on access to global objects across environments. The holder register |
| 472 | // is left untouched, but the scratch register is clobbered. |
| 473 | void CheckAccessGlobalProxy(Register holder_reg, |
| 474 | Register scratch, |
| 475 | Label* miss); |
| 476 | |
| 477 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 478 | void LoadFromNumberDictionary(Label* miss, |
| 479 | Register elements, |
| 480 | Register key, |
| 481 | Register r0, |
| 482 | Register r1, |
| 483 | Register r2, |
| 484 | Register result); |
| 485 | |
| 486 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 487 | // --------------------------------------------------------------------------- |
| 488 | // Allocation support |
| 489 | |
| 490 | // Allocate an object in new space. If the new space is exhausted control |
| 491 | // continues at the gc_required label. The allocated object is returned in |
| 492 | // result and end of the new object is returned in result_end. The register |
| 493 | // scratch can be passed as no_reg in which case an additional object |
| 494 | // reference will be added to the reloc info. The returned pointers in result |
| 495 | // and result_end have not yet been tagged as heap objects. If |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 496 | // result_contains_top_on_entry is true the content of result is known to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | // the allocation top on entry (could be result_end from a previous call to |
| 498 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
| 499 | // should be no_reg as it is never used. |
| 500 | void AllocateInNewSpace(int object_size, |
| 501 | Register result, |
| 502 | Register result_end, |
| 503 | Register scratch, |
| 504 | Label* gc_required, |
| 505 | AllocationFlags flags); |
| 506 | |
| 507 | void AllocateInNewSpace(int header_size, |
| 508 | ScaleFactor element_size, |
| 509 | Register element_count, |
| 510 | Register result, |
| 511 | Register result_end, |
| 512 | Register scratch, |
| 513 | Label* gc_required, |
| 514 | AllocationFlags flags); |
| 515 | |
| 516 | void AllocateInNewSpace(Register object_size, |
| 517 | Register result, |
| 518 | Register result_end, |
| 519 | Register scratch, |
| 520 | Label* gc_required, |
| 521 | AllocationFlags flags); |
| 522 | |
| 523 | // Undo allocation in new space. The object passed and objects allocated after |
| 524 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 525 | // object(s) no longer allocated as they would be invalid when allocation is |
| 526 | // un-done. |
| 527 | void UndoAllocationInNewSpace(Register object); |
| 528 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 529 | // Allocate a heap number in new space with undefined value. The |
| 530 | // register scratch2 can be passed as no_reg; the others must be |
| 531 | // valid registers. Returns tagged pointer in result register, or |
| 532 | // jumps to gc_required if new space is full. |
| 533 | void AllocateHeapNumber(Register result, |
| 534 | Register scratch1, |
| 535 | Register scratch2, |
| 536 | Label* gc_required); |
| 537 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 538 | // Allocate a sequential string. All the header fields of the string object |
| 539 | // are initialized. |
| 540 | void AllocateTwoByteString(Register result, |
| 541 | Register length, |
| 542 | Register scratch1, |
| 543 | Register scratch2, |
| 544 | Register scratch3, |
| 545 | Label* gc_required); |
| 546 | void AllocateAsciiString(Register result, |
| 547 | Register length, |
| 548 | Register scratch1, |
| 549 | Register scratch2, |
| 550 | Register scratch3, |
| 551 | Label* gc_required); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 552 | void AllocateAsciiString(Register result, |
| 553 | int length, |
| 554 | Register scratch1, |
| 555 | Register scratch2, |
| 556 | Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 557 | |
| 558 | // Allocate a raw cons string object. Only the map field of the result is |
| 559 | // initialized. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 560 | void AllocateTwoByteConsString(Register result, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 561 | Register scratch1, |
| 562 | Register scratch2, |
| 563 | Label* gc_required); |
| 564 | void AllocateAsciiConsString(Register result, |
| 565 | Register scratch1, |
| 566 | Register scratch2, |
| 567 | Label* gc_required); |
| 568 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 569 | // Allocate a raw sliced string object. Only the map field of the result is |
| 570 | // initialized. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 571 | void AllocateTwoByteSlicedString(Register result, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 572 | Register scratch1, |
| 573 | Register scratch2, |
| 574 | Label* gc_required); |
| 575 | void AllocateAsciiSlicedString(Register result, |
| 576 | Register scratch1, |
| 577 | Register scratch2, |
| 578 | Label* gc_required); |
| 579 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 580 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 581 | // long or aligned copies. |
| 582 | // The contents of index and scratch are destroyed. |
| 583 | void CopyBytes(Register source, |
| 584 | Register destination, |
| 585 | Register length, |
| 586 | Register scratch); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 587 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 588 | // Initialize fields with filler values. Fields starting at |start_offset| |
| 589 | // not including end_offset are overwritten with the value in |filler|. At |
| 590 | // the end the loop, |start_offset| takes the value of |end_offset|. |
| 591 | void InitializeFieldsWithFiller(Register start_offset, |
| 592 | Register end_offset, |
| 593 | Register filler); |
| 594 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | // --------------------------------------------------------------------------- |
| 596 | // Support functions. |
| 597 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 598 | // Check a boolean-bit of a Smi field. |
| 599 | void BooleanBitTest(Register object, int field_offset, int bit_index); |
| 600 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 601 | // Check if result is zero and op is negative. |
| 602 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 603 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | // Check if result is zero and any of op1 and op2 are negative. |
| 605 | // Register scratch is destroyed, and it must be different from op2. |
| 606 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 607 | Register scratch, Label* then_label); |
| 608 | |
| 609 | // Try to get function prototype of a function and puts the value in |
| 610 | // the result register. Checks that the function really is a |
| 611 | // function and jumps to the miss label if the fast checks fail. The |
| 612 | // function register will be untouched; the other registers may be |
| 613 | // clobbered. |
| 614 | void TryGetFunctionPrototype(Register function, |
| 615 | Register result, |
| 616 | Register scratch, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 617 | Label* miss, |
| 618 | bool miss_on_bound_function = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 619 | |
| 620 | // Generates code for reporting that an illegal operation has |
| 621 | // occurred. |
| 622 | void IllegalOperation(int num_arguments); |
| 623 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 624 | // Picks out an array index from the hash field. |
| 625 | // Register use: |
| 626 | // hash - holds the index's hash. Clobbered. |
| 627 | // index - holds the overwritten index on exit. |
| 628 | void IndexFromHash(Register hash, Register index); |
| 629 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 630 | // --------------------------------------------------------------------------- |
| 631 | // Runtime calls |
| 632 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 633 | // Call a code stub. Generate the code if necessary. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 634 | void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 635 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 636 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 637 | void TailCallStub(CodeStub* stub); |
| 638 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 639 | // Return from a code stub after popping its arguments. |
| 640 | void StubReturn(int argc); |
| 641 | |
| 642 | // Call a runtime routine. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 643 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 644 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 645 | |
| 646 | // Convenience function: Same as above, but takes the fid instead. |
| 647 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 648 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 649 | // Convenience function: call an external reference. |
| 650 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 651 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 652 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 653 | // Like JumpToExternalReference, but also takes care of passing the number |
| 654 | // of parameters. |
| 655 | void TailCallExternalReference(const ExternalReference& ext, |
| 656 | int num_arguments, |
| 657 | int result_size); |
| 658 | |
| 659 | // Convenience function: tail call a runtime routine (jump). |
| 660 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | int num_arguments, |
| 662 | int result_size); |
| 663 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 664 | // Before calling a C-function from generated code, align arguments on stack. |
| 665 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 666 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 667 | // Some compilers/platforms require the stack to be aligned when calling |
| 668 | // C++ code. |
| 669 | // Needs a scratch register to do some arithmetic. This register will be |
| 670 | // trashed. |
| 671 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 672 | |
| 673 | // Calls a C function and cleans up the space for arguments allocated |
| 674 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 675 | // garbage collection, since that might move the code and invalidate the |
| 676 | // return address (unless this is somehow accounted for by the called |
| 677 | // function). |
| 678 | void CallCFunction(ExternalReference function, int num_arguments); |
| 679 | void CallCFunction(Register function, int num_arguments); |
| 680 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 681 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 682 | // space for return value if needed (assumes the return value is a handle). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 683 | // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1) |
| 684 | // etc. Saves context (esi). If space was reserved for return value then |
| 685 | // stores the pointer to the reserved slot into esi. |
| 686 | void PrepareCallApiFunction(int argc); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 687 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 688 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 689 | // from handle and propagates exceptions. Clobbers ebx, edi and |
| 690 | // caller-save registers. Restores context. On return removes |
| 691 | // stack_space * kPointerSize (GCed). |
| 692 | void CallApiFunctionAndReturn(Address function_address, int stack_space); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 693 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 694 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 695 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 696 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 697 | // --------------------------------------------------------------------------- |
| 698 | // Utilities |
| 699 | |
| 700 | void Ret(); |
| 701 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 702 | // Return and drop arguments from stack, where the number of arguments |
| 703 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 704 | void Ret(int bytes_dropped, Register scratch); |
| 705 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 706 | // Emit code to discard a non-negative number of pointer-sized elements |
| 707 | // from the stack, clobbering only the esp register. |
| 708 | void Drop(int element_count); |
| 709 | |
| 710 | void Call(Label* target) { call(target); } |
| 711 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 712 | // Emit call to the code we are currently generating. |
| 713 | void CallSelf() { |
| 714 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 715 | call(self, RelocInfo::CODE_TARGET); |
| 716 | } |
| 717 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 718 | // Move if the registers are not identical. |
| 719 | void Move(Register target, Register source); |
| 720 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 721 | void Move(Register target, Handle<Object> value); |
| 722 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 723 | // Push a handle value. |
| 724 | void Push(Handle<Object> handle) { push(handle); } |
| 725 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 726 | Handle<Object> CodeObject() { |
| 727 | ASSERT(!code_object_.is_null()); |
| 728 | return code_object_; |
| 729 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 730 | |
| 731 | |
| 732 | // --------------------------------------------------------------------------- |
| 733 | // StatsCounter support |
| 734 | |
| 735 | void SetCounter(StatsCounter* counter, int value); |
| 736 | void IncrementCounter(StatsCounter* counter, int value); |
| 737 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 738 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 739 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 740 | |
| 741 | |
| 742 | // --------------------------------------------------------------------------- |
| 743 | // Debugging |
| 744 | |
| 745 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 746 | // Use --debug_code to enable. |
| 747 | void Assert(Condition cc, const char* msg); |
| 748 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 749 | void AssertFastElements(Register elements); |
| 750 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 751 | // Like Assert(), but always enabled. |
| 752 | void Check(Condition cc, const char* msg); |
| 753 | |
| 754 | // Print a message to stdout and abort execution. |
| 755 | void Abort(const char* msg); |
| 756 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 757 | // Check that the stack is aligned. |
| 758 | void CheckStackAlignment(); |
| 759 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 760 | // Verify restrictions about code generated in stubs. |
| 761 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 762 | bool generating_stub() { return generating_stub_; } |
| 763 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 764 | bool allow_stub_calls() { return allow_stub_calls_; } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 765 | void set_has_frame(bool value) { has_frame_ = value; } |
| 766 | bool has_frame() { return has_frame_; } |
| 767 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 768 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 769 | // --------------------------------------------------------------------------- |
| 770 | // String utilities. |
| 771 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 772 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 773 | // label if not. If the instance type can be scratched specify same register |
| 774 | // for both instance type and scratch. |
| 775 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 776 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 777 | Label* on_not_flat_ascii_string); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 778 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 779 | // Checks if both objects are sequential ASCII strings, and jumps to label |
| 780 | // if either is not. |
| 781 | void JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 782 | Register object2, |
| 783 | Register scratch1, |
| 784 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 785 | Label* on_not_flat_ascii_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 786 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 787 | static int SafepointRegisterStackIndex(Register reg) { |
| 788 | return SafepointRegisterStackIndex(reg.code()); |
| 789 | } |
| 790 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 791 | // Activation support. |
| 792 | void EnterFrame(StackFrame::Type type); |
| 793 | void LeaveFrame(StackFrame::Type type); |
| 794 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 795 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 796 | bool generating_stub_; |
| 797 | bool allow_stub_calls_; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 798 | bool has_frame_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 799 | // This handle will be patched with the code object on installation. |
| 800 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | |
| 802 | // Helper functions for generating invokes. |
| 803 | void InvokePrologue(const ParameterCount& expected, |
| 804 | const ParameterCount& actual, |
| 805 | Handle<Code> code_constant, |
| 806 | const Operand& code_operand, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 807 | Label* done, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 808 | InvokeFlag flag, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 809 | Label::Distance done_distance, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 810 | const CallWrapper& call_wrapper = NullCallWrapper(), |
| 811 | CallKind call_kind = CALL_AS_METHOD); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 813 | void EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 814 | void EnterExitFrameEpilogue(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 815 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 816 | void LeaveExitFrameEpilogue(); |
| 817 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | // Allocation support helpers. |
| 819 | void LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | Register scratch, |
| 821 | AllocationFlags flags); |
| 822 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 823 | |
| 824 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 825 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 826 | // possibly returns a failure object indicating an allocation failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 827 | MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved, |
| 828 | Register scratch, |
| 829 | bool gc_allowed); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 830 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 831 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 832 | void InNewSpace(Register object, |
| 833 | Register scratch, |
| 834 | Condition cc, |
| 835 | Label* condition_met, |
| 836 | Label::Distance condition_met_distance = Label::kFar); |
| 837 | |
| 838 | // Helper for finding the mark bits for an address. Afterwards, the |
| 839 | // bitmap register points at the word with the mark bits and the mask |
| 840 | // the position of the first bit. Uses ecx as scratch and leaves addr_reg |
| 841 | // unchanged. |
| 842 | inline void GetMarkBits(Register addr_reg, |
| 843 | Register bitmap_reg, |
| 844 | Register mask_reg); |
| 845 | |
| 846 | // Helper for throwing exceptions. Compute a handler address and jump to |
| 847 | // it. See the implementation for register usage. |
| 848 | void JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 849 | |
| 850 | // Compute memory operands for safepoint stack slots. |
| 851 | Operand SafepointRegisterSlot(Register reg); |
| 852 | static int SafepointRegisterStackIndex(int reg_code); |
| 853 | |
| 854 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 855 | // traversal. |
| 856 | friend class OptimizedFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 857 | }; |
| 858 | |
| 859 | |
| 860 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 861 | // debugging and other types of instrumentation. When using the code patcher |
| 862 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 863 | // relocation information. If any of these constraints are violated it causes |
| 864 | // an assertion. |
| 865 | class CodePatcher { |
| 866 | public: |
| 867 | CodePatcher(byte* address, int size); |
| 868 | virtual ~CodePatcher(); |
| 869 | |
| 870 | // Macro assembler to emit code. |
| 871 | MacroAssembler* masm() { return &masm_; } |
| 872 | |
| 873 | private: |
| 874 | byte* address_; // The address of the code being patched. |
| 875 | int size_; // Number of bytes of the expected patch size. |
| 876 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 877 | }; |
| 878 | |
| 879 | |
| 880 | // ----------------------------------------------------------------------------- |
| 881 | // Static helper functions. |
| 882 | |
| 883 | // Generate an Operand for loading a field from an object. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 884 | inline Operand FieldOperand(Register object, int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 885 | return Operand(object, offset - kHeapObjectTag); |
| 886 | } |
| 887 | |
| 888 | |
| 889 | // Generate an Operand for loading an indexed field from an object. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 890 | inline Operand FieldOperand(Register object, |
| 891 | Register index, |
| 892 | ScaleFactor scale, |
| 893 | int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 894 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 895 | } |
| 896 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 897 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 898 | inline Operand ContextOperand(Register context, int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 899 | return Operand(context, Context::SlotOffset(index)); |
| 900 | } |
| 901 | |
| 902 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 903 | inline Operand GlobalObjectOperand() { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 904 | return ContextOperand(esi, Context::GLOBAL_INDEX); |
| 905 | } |
| 906 | |
| 907 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 908 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 909 | Operand ApiParameterOperand(int index); |
| 910 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | |
| 912 | #ifdef GENERATED_CODE_COVERAGE |
| 913 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 914 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 915 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 916 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 917 | #define ACCESS_MASM(masm) { \ |
| 918 | byte* ia32_coverage_function = \ |
| 919 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 920 | masm->pushfd(); \ |
| 921 | masm->pushad(); \ |
| 922 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 923 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 924 | masm->pop(eax); \ |
| 925 | masm->popad(); \ |
| 926 | masm->popfd(); \ |
| 927 | } \ |
| 928 | masm-> |
| 929 | #else |
| 930 | #define ACCESS_MASM(masm) masm-> |
| 931 | #endif |
| 932 | |
| 933 | |
| 934 | } } // namespace v8::internal |
| 935 | |
| 936 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |