Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 6 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/assembler.h" |
| 9 | #include "src/bailout-reason.h" |
| 10 | #include "src/frames.h" |
| 11 | #include "src/globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 16 | // Convenience for platform-independent signatures. We do not normally |
| 17 | // distinguish memory operands from other operands on ia32. |
| 18 | typedef Operand MemOperand; |
| 19 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 20 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 21 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | enum PointersToHereCheck { |
| 23 | kPointersToHereMaybeInteresting, |
| 24 | kPointersToHereAreAlwaysInteresting |
| 25 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 26 | |
| 27 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | enum RegisterValueType { |
| 29 | REGISTER_VALUE_IS_SMI, |
| 30 | REGISTER_VALUE_IS_INT32 |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | #ifdef DEBUG |
| 35 | bool AreAliased(Register reg1, |
| 36 | Register reg2, |
| 37 | Register reg3 = no_reg, |
| 38 | Register reg4 = no_reg, |
| 39 | Register reg5 = no_reg, |
| 40 | Register reg6 = no_reg, |
| 41 | Register reg7 = no_reg, |
| 42 | Register reg8 = no_reg); |
| 43 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 44 | |
| 45 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | // MacroAssembler implements a collection of frequently used macros. |
| 47 | class MacroAssembler: public Assembler { |
| 48 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 49 | // The isolate parameter can be NULL if the macro assembler should |
| 50 | // not use isolate-dependent functionality. In this case, it's the |
| 51 | // responsibility of the caller to never invoke such function on the |
| 52 | // macro assembler. |
| 53 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | void Load(Register dst, const Operand& src, Representation r); |
| 56 | void Store(Register src, const Operand& dst, Representation r); |
| 57 | |
| 58 | // Operations on roots in the root-array. |
| 59 | void LoadRoot(Register destination, Heap::RootListIndex index); |
| 60 | void StoreRoot(Register source, Register scratch, Heap::RootListIndex index); |
| 61 | void CompareRoot(Register with, Register scratch, Heap::RootListIndex index); |
| 62 | // These methods can only be used with constant roots (i.e. non-writable |
| 63 | // and not in new space). |
| 64 | void CompareRoot(Register with, Heap::RootListIndex index); |
| 65 | void CompareRoot(const Operand& with, Heap::RootListIndex index); |
| 66 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | // --------------------------------------------------------------------------- |
| 68 | // GC Support |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 69 | enum RememberedSetFinalAction { |
| 70 | kReturnAtEnd, |
| 71 | kFallThroughAtEnd |
| 72 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 73 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 74 | // Record in the remembered set the fact that we have a pointer to new space |
| 75 | // at the address pointed to by the addr register. Only works if addr is not |
| 76 | // in new space. |
| 77 | void RememberedSetHelper(Register object, // Used for debug code. |
| 78 | Register addr, |
| 79 | Register scratch, |
| 80 | SaveFPRegsMode save_fp, |
| 81 | RememberedSetFinalAction and_then); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 82 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 83 | void CheckPageFlag(Register object, |
| 84 | Register scratch, |
| 85 | int mask, |
| 86 | Condition cc, |
| 87 | Label* condition_met, |
| 88 | Label::Distance condition_met_distance = Label::kFar); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 89 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | void CheckPageFlagForMap( |
| 91 | Handle<Map> map, |
| 92 | int mask, |
| 93 | Condition cc, |
| 94 | Label* condition_met, |
| 95 | Label::Distance condition_met_distance = Label::kFar); |
| 96 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 97 | // Check if object is in new space. Jumps if the object is not in new space. |
| 98 | // The register scratch can be object itself, but scratch will be clobbered. |
| 99 | void JumpIfNotInNewSpace(Register object, |
| 100 | Register scratch, |
| 101 | Label* branch, |
| 102 | Label::Distance distance = Label::kFar) { |
| 103 | InNewSpace(object, scratch, zero, branch, distance); |
| 104 | } |
| 105 | |
| 106 | // Check if object is in new space. Jumps if the object is in new space. |
| 107 | // The register scratch can be object itself, but it will be clobbered. |
| 108 | void JumpIfInNewSpace(Register object, |
| 109 | Register scratch, |
| 110 | Label* branch, |
| 111 | Label::Distance distance = Label::kFar) { |
| 112 | InNewSpace(object, scratch, not_zero, branch, distance); |
| 113 | } |
| 114 | |
| 115 | // Check if an object has a given incremental marking color. Also uses ecx! |
| 116 | void HasColor(Register object, |
| 117 | Register scratch0, |
| 118 | Register scratch1, |
| 119 | Label* has_color, |
| 120 | Label::Distance has_color_distance, |
| 121 | int first_bit, |
| 122 | int second_bit); |
| 123 | |
| 124 | void JumpIfBlack(Register object, |
| 125 | Register scratch0, |
| 126 | Register scratch1, |
| 127 | Label* on_black, |
| 128 | Label::Distance on_black_distance = Label::kFar); |
| 129 | |
| 130 | // Checks the color of an object. If the object is already grey or black |
| 131 | // then we just fall through, since it is already live. If it is white and |
| 132 | // we can determine that it doesn't need to be scanned, then we just mark it |
| 133 | // black and fall through. For the rest we jump to the label so the |
| 134 | // incremental marker can fix its assumptions. |
| 135 | void EnsureNotWhite(Register object, |
| 136 | Register scratch1, |
| 137 | Register scratch2, |
| 138 | Label* object_is_white_and_not_data, |
| 139 | Label::Distance distance); |
| 140 | |
| 141 | // Notify the garbage collector that we wrote a pointer into an object. |
| 142 | // |object| is the object being stored into, |value| is the object being |
| 143 | // stored. value and scratch registers are clobbered by the operation. |
| 144 | // The offset is the offset from the start of the object, not the offset from |
| 145 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 146 | void RecordWriteField( |
| 147 | Register object, |
| 148 | int offset, |
| 149 | Register value, |
| 150 | Register scratch, |
| 151 | SaveFPRegsMode save_fp, |
| 152 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 153 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 154 | PointersToHereCheck pointers_to_here_check_for_value = |
| 155 | kPointersToHereMaybeInteresting); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 156 | |
| 157 | // As above, but the offset has the tag presubtracted. For use with |
| 158 | // Operand(reg, off). |
| 159 | void RecordWriteContextSlot( |
| 160 | Register context, |
| 161 | int offset, |
| 162 | Register value, |
| 163 | Register scratch, |
| 164 | SaveFPRegsMode save_fp, |
| 165 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 166 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 167 | PointersToHereCheck pointers_to_here_check_for_value = |
| 168 | kPointersToHereMaybeInteresting) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 169 | RecordWriteField(context, |
| 170 | offset + kHeapObjectTag, |
| 171 | value, |
| 172 | scratch, |
| 173 | save_fp, |
| 174 | remembered_set_action, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 175 | smi_check, |
| 176 | pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // Notify the garbage collector that we wrote a pointer into a fixed array. |
| 180 | // |array| is the array being stored into, |value| is the |
| 181 | // object being stored. |index| is the array index represented as a |
| 182 | // Smi. All registers are clobbered by the operation RecordWriteArray |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 183 | // filters out smis so it does not update the write barrier if the |
| 184 | // value is a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 185 | void RecordWriteArray( |
| 186 | Register array, |
| 187 | Register value, |
| 188 | Register index, |
| 189 | SaveFPRegsMode save_fp, |
| 190 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 192 | PointersToHereCheck pointers_to_here_check_for_value = |
| 193 | kPointersToHereMaybeInteresting); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 194 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 195 | // For page containing |object| mark region covering |address| |
| 196 | // dirty. |object| is the object being stored into, |value| is the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 197 | // object being stored. The address and value registers are clobbered by the |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 198 | // operation. RecordWrite filters out smis so it does not update the |
| 199 | // write barrier if the value is a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 200 | void RecordWrite( |
| 201 | Register object, |
| 202 | Register address, |
| 203 | Register value, |
| 204 | SaveFPRegsMode save_fp, |
| 205 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 206 | SmiCheck smi_check = INLINE_SMI_CHECK, |
| 207 | PointersToHereCheck pointers_to_here_check_for_value = |
| 208 | kPointersToHereMaybeInteresting); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | // For page containing |object| mark the region covering the object's map |
| 211 | // dirty. |object| is the object being stored into, |map| is the Map object |
| 212 | // that was stored. |
| 213 | void RecordWriteForMap( |
| 214 | Register object, |
| 215 | Handle<Map> map, |
| 216 | Register scratch1, |
| 217 | Register scratch2, |
| 218 | SaveFPRegsMode save_fp); |
| 219 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | // --------------------------------------------------------------------------- |
| 221 | // Debugger Support |
| 222 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 223 | void DebugBreak(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 224 | |
| 225 | // Generates function and stub prologue code. |
| 226 | void StubPrologue(); |
| 227 | void Prologue(bool code_pre_aging); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 228 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 229 | // Enter specific kind of exit frame. Expects the number of |
| 230 | // arguments in register eax and sets up the number of arguments in |
| 231 | // register edi and the pointer to the first argument in register |
| 232 | // esi. |
| 233 | void EnterExitFrame(bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 234 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 235 | void EnterApiExitFrame(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 236 | |
| 237 | // Leave the current exit frame. Expects the return value in |
| 238 | // register eax:edx (untouched) and the pointer to the first |
| 239 | // argument in register esi. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 240 | void LeaveExitFrame(bool save_doubles); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 242 | // Leave the current exit frame. Expects the return value in |
| 243 | // register eax (untouched). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | void LeaveApiExitFrame(bool restore_context); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 245 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 246 | // Find the function context up the context chain. |
| 247 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 249 | // Conditionally load the cached Array transitioned map of type |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 250 | // transitioned_kind from the native context if the map in register |
| 251 | // map_in_out is the cached Array map in the native context of |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 252 | // expected_kind. |
| 253 | void LoadTransitionedArrayMapConditional( |
| 254 | ElementsKind expected_kind, |
| 255 | ElementsKind transitioned_kind, |
| 256 | Register map_in_out, |
| 257 | Register scratch, |
| 258 | Label* no_map_match); |
| 259 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 260 | // Load the global function with the given index. |
| 261 | void LoadGlobalFunction(int index, Register function); |
| 262 | |
| 263 | // Load the initial map from the global function. The registers |
| 264 | // function and map can be the same. |
| 265 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 266 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 267 | // Push and pop the registers that can hold pointers. |
| 268 | void PushSafepointRegisters() { pushad(); } |
| 269 | void PopSafepointRegisters() { popad(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 270 | // Store the value in register/immediate src in the safepoint |
| 271 | // register stack slot for register dst. |
| 272 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
| 273 | void StoreToSafepointRegisterSlot(Register dst, Immediate src); |
| 274 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 275 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 276 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | void CmpHeapObject(Register reg, Handle<HeapObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 278 | void PushHeapObject(Handle<HeapObject> object); |
| 279 | |
| 280 | void LoadObject(Register result, Handle<Object> object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 281 | AllowDeferredHandleDereference heap_object_check; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 282 | if (object->IsHeapObject()) { |
| 283 | LoadHeapObject(result, Handle<HeapObject>::cast(object)); |
| 284 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 285 | Move(result, Immediate(object)); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void CmpObject(Register reg, Handle<Object> object) { |
| 290 | AllowDeferredHandleDereference heap_object_check; |
| 291 | if (object->IsHeapObject()) { |
| 292 | CmpHeapObject(reg, Handle<HeapObject>::cast(object)); |
| 293 | } else { |
| 294 | cmp(reg, Immediate(object)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 298 | // Compare the given value and the value of weak cell. |
| 299 | void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch); |
| 300 | |
| 301 | // Load the value of the weak cell in the value register. Branch to the given |
| 302 | // miss label if the weak cell was cleared. |
| 303 | void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss); |
| 304 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | // --------------------------------------------------------------------------- |
| 306 | // JavaScript invokes |
| 307 | |
| 308 | // Invoke the JavaScript function code by either calling or jumping. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 309 | void InvokeCode(Register code, |
| 310 | const ParameterCount& expected, |
| 311 | const ParameterCount& actual, |
| 312 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 313 | const CallWrapper& call_wrapper) { |
| 314 | InvokeCode(Operand(code), expected, actual, flag, call_wrapper); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | void InvokeCode(const Operand& code, |
| 318 | const ParameterCount& expected, |
| 319 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 320 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | |
| 323 | // Invoke the JavaScript function in the given register. Changes the |
| 324 | // current context to the context in the function before invoking. |
| 325 | void InvokeFunction(Register function, |
| 326 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 327 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | const CallWrapper& call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 330 | void InvokeFunction(Register function, |
| 331 | const ParameterCount& expected, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 332 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 333 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | const CallWrapper& call_wrapper); |
| 335 | |
| 336 | void InvokeFunction(Handle<JSFunction> function, |
| 337 | const ParameterCount& expected, |
| 338 | const ParameterCount& actual, |
| 339 | InvokeFlag flag, |
| 340 | const CallWrapper& call_wrapper); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 341 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 343 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 344 | void InvokeBuiltin(Builtins::JavaScript id, |
| 345 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 346 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 347 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 348 | // Store the function for the given builtin in the target register. |
| 349 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 350 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 351 | // Store the code object for the given builtin in the target register. |
| 352 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 353 | |
| 354 | // Expression support |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | // cvtsi2sd instruction only writes to the low 64-bit of dst register, which |
| 356 | // hinders register renaming and makes dependence chains longer. So we use |
| 357 | // xorps to clear the dst register before cvtsi2sd to solve this issue. |
| 358 | void Cvtsi2sd(XMMRegister dst, Register src) { Cvtsi2sd(dst, Operand(src)); } |
| 359 | void Cvtsi2sd(XMMRegister dst, const Operand& src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 360 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 361 | // Support for constant splitting. |
| 362 | bool IsUnsafeImmediate(const Immediate& x); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | void SafeMove(Register dst, const Immediate& x); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 364 | void SafePush(const Immediate& x); |
| 365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | // Compare object type for heap object. |
| 367 | // Incoming register is heap_object and outgoing register is map. |
| 368 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 369 | |
| 370 | // Compare instance type for map. |
| 371 | void CmpInstanceType(Register map, InstanceType type); |
| 372 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 373 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 374 | // Jump to the specified label if it does not. |
| 375 | void CheckFastElements(Register map, |
| 376 | Label* fail, |
| 377 | Label::Distance distance = Label::kFar); |
| 378 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 379 | // Check if a map for a JSObject indicates that the object can have both smi |
| 380 | // and HeapObject elements. Jump to the specified label if it does not. |
| 381 | void CheckFastObjectElements(Register map, |
| 382 | Label* fail, |
| 383 | Label::Distance distance = Label::kFar); |
| 384 | |
| 385 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 386 | // elements. Jump to the specified label if it does not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | void CheckFastSmiElements(Register map, |
| 388 | Label* fail, |
| 389 | Label::Distance distance = Label::kFar); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 390 | |
| 391 | // Check to see if maybe_number can be stored as a double in |
| 392 | // FastDoubleElements. If it can, store it at the index specified by key in |
| 393 | // the FastDoubleElements array elements, otherwise jump to fail. |
| 394 | void StoreNumberToDoubleElements(Register maybe_number, |
| 395 | Register elements, |
| 396 | Register key, |
| 397 | Register scratch1, |
| 398 | XMMRegister scratch2, |
| 399 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 400 | int offset = 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 401 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 402 | // Compare an object's map with the specified map. |
| 403 | void CompareMap(Register obj, Handle<Map> map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 404 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 405 | // Check if the map of an object is equal to a specified map and branch to |
| 406 | // label if not. Skip the smi check if not required (object is known to be a |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 407 | // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match |
| 408 | // against maps that are ElementsKind transition maps of the specified map. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 409 | void CheckMap(Register obj, |
| 410 | Handle<Map> map, |
| 411 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 412 | SmiCheckType smi_check_type); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 413 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 414 | // Check if the map of an object is equal to a specified weak map and branch |
| 415 | // to a specified target if equal. Skip the smi check if not required |
| 416 | // (object is known to be a heap object) |
| 417 | void DispatchWeakMap(Register obj, Register scratch1, Register scratch2, |
| 418 | Handle<WeakCell> cell, Handle<Code> success, |
| 419 | SmiCheckType smi_check_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 420 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 421 | // Check if the object in register heap_object is a string. Afterwards the |
| 422 | // register map contains the object map and the register instance_type |
| 423 | // contains the instance_type. The registers map and instance_type can be the |
| 424 | // same in which case it contains the instance type afterwards. Either of the |
| 425 | // registers map and instance_type can be the same as heap_object. |
| 426 | Condition IsObjectStringType(Register heap_object, |
| 427 | Register map, |
| 428 | Register instance_type); |
| 429 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | // Check if the object in register heap_object is a name. Afterwards the |
| 431 | // register map contains the object map and the register instance_type |
| 432 | // contains the instance_type. The registers map and instance_type can be the |
| 433 | // same in which case it contains the instance type afterwards. Either of the |
| 434 | // registers map and instance_type can be the same as heap_object. |
| 435 | Condition IsObjectNameType(Register heap_object, |
| 436 | Register map, |
| 437 | Register instance_type); |
| 438 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 439 | // Check if a heap object's type is in the JSObject range, not including |
| 440 | // JSFunction. The object's map will be loaded in the map register. |
| 441 | // Any or all of the three registers may be the same. |
| 442 | // The contents of the scratch register will always be overwritten. |
| 443 | void IsObjectJSObjectType(Register heap_object, |
| 444 | Register map, |
| 445 | Register scratch, |
| 446 | Label* fail); |
| 447 | |
| 448 | // The contents of the scratch register will be overwritten. |
| 449 | void IsInstanceJSObjectType(Register map, Register scratch, Label* fail); |
| 450 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | // FCmp is similar to integer cmp, but requires unsigned |
| 452 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 453 | void FCmp(); |
| 454 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 455 | void ClampUint8(Register reg); |
| 456 | |
| 457 | void ClampDoubleToUint8(XMMRegister input_reg, |
| 458 | XMMRegister scratch_reg, |
| 459 | Register result_reg); |
| 460 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | void SlowTruncateToI(Register result_reg, Register input_reg, |
| 462 | int offset = HeapNumber::kValueOffset - kHeapObjectTag); |
| 463 | |
| 464 | void TruncateHeapNumberToI(Register result_reg, Register input_reg); |
| 465 | void TruncateDoubleToI(Register result_reg, XMMRegister input_reg); |
| 466 | |
| 467 | void DoubleToI(Register result_reg, XMMRegister input_reg, |
| 468 | XMMRegister scratch, MinusZeroMode minus_zero_mode, |
| 469 | Label* lost_precision, Label* is_nan, Label* minus_zero, |
| 470 | Label::Distance dst = Label::kFar); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 471 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 472 | // Smi tagging support. |
| 473 | void SmiTag(Register reg) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 474 | STATIC_ASSERT(kSmiTag == 0); |
| 475 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 476 | add(reg, reg); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 477 | } |
| 478 | void SmiUntag(Register reg) { |
| 479 | sar(reg, kSmiTagSize); |
| 480 | } |
| 481 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 482 | // Modifies the register even if it does not contain a Smi! |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 483 | void SmiUntag(Register reg, Label* is_smi) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 484 | STATIC_ASSERT(kSmiTagSize == 1); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 485 | sar(reg, kSmiTagSize); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 486 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 487 | j(not_carry, is_smi); |
| 488 | } |
| 489 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 490 | void LoadUint32(XMMRegister dst, Register src) { |
| 491 | LoadUint32(dst, Operand(src)); |
| 492 | } |
| 493 | void LoadUint32(XMMRegister dst, const Operand& src); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 494 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 495 | // Jump the register contains a smi. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 496 | inline void JumpIfSmi(Register value, |
| 497 | Label* smi_label, |
| 498 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 499 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 500 | j(zero, smi_label, distance); |
| 501 | } |
| 502 | // Jump if the operand is a smi. |
| 503 | inline void JumpIfSmi(Operand value, |
| 504 | Label* smi_label, |
| 505 | Label::Distance distance = Label::kFar) { |
| 506 | test(value, Immediate(kSmiTagMask)); |
| 507 | j(zero, smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 508 | } |
| 509 | // Jump if register contain a non-smi. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 510 | inline void JumpIfNotSmi(Register value, |
| 511 | Label* not_smi_label, |
| 512 | Label::Distance distance = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 513 | test(value, Immediate(kSmiTagMask)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 514 | j(not_zero, not_smi_label, distance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 517 | void LoadInstanceDescriptors(Register map, Register descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 518 | void EnumLength(Register dst, Register map); |
| 519 | void NumberOfOwnDescriptors(Register dst, Register map); |
| 520 | |
| 521 | template<typename Field> |
| 522 | void DecodeField(Register reg) { |
| 523 | static const int shift = Field::kShift; |
| 524 | static const int mask = Field::kMask >> Field::kShift; |
| 525 | if (shift != 0) { |
| 526 | sar(reg, shift); |
| 527 | } |
| 528 | and_(reg, Immediate(mask)); |
| 529 | } |
| 530 | |
| 531 | template<typename Field> |
| 532 | void DecodeFieldToSmi(Register reg) { |
| 533 | static const int shift = Field::kShift; |
| 534 | static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize; |
| 535 | STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0); |
| 536 | STATIC_ASSERT(kSmiTag == 0); |
| 537 | if (shift < kSmiTagSize) { |
| 538 | shl(reg, kSmiTagSize - shift); |
| 539 | } else if (shift > kSmiTagSize) { |
| 540 | sar(reg, shift - kSmiTagSize); |
| 541 | } |
| 542 | and_(reg, Immediate(mask)); |
| 543 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 544 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 545 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 546 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 547 | // Abort execution if argument is not a number, enabled via --debug-code. |
| 548 | void AssertNumber(Register object); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 549 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 550 | // Abort execution if argument is not a smi, enabled via --debug-code. |
| 551 | void AssertSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 552 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 553 | // Abort execution if argument is a smi, enabled via --debug-code. |
| 554 | void AssertNotSmi(Register object); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 555 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 556 | // Abort execution if argument is not a string, enabled via --debug-code. |
| 557 | void AssertString(Register object); |
| 558 | |
| 559 | // Abort execution if argument is not a name, enabled via --debug-code. |
| 560 | void AssertName(Register object); |
| 561 | |
| 562 | // Abort execution if argument is not undefined or an AllocationSite, enabled |
| 563 | // via --debug-code. |
| 564 | void AssertUndefinedOrAllocationSite(Register object); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 565 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | // --------------------------------------------------------------------------- |
| 567 | // Exception handling |
| 568 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 569 | // Push a new try handler and link it into try handler chain. |
| 570 | void PushTryHandler(StackHandler::Kind kind, int handler_index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 572 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 573 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 575 | // Throw to the top handler in the try hander chain. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 576 | void Throw(Register value); |
| 577 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 578 | // Throw past all JS frames to the top JS entry frame. |
| 579 | void ThrowUncatchable(Register value); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 580 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | // --------------------------------------------------------------------------- |
| 582 | // Inline caching support |
| 583 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | // Generate code for checking access rights - used for security checks |
| 585 | // on access to global objects across environments. The holder register |
| 586 | // is left untouched, but the scratch register is clobbered. |
| 587 | void CheckAccessGlobalProxy(Register holder_reg, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | Register scratch1, |
| 589 | Register scratch2, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | Label* miss); |
| 591 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 592 | void GetNumberHash(Register r0, Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 594 | void LoadFromNumberDictionary(Label* miss, |
| 595 | Register elements, |
| 596 | Register key, |
| 597 | Register r0, |
| 598 | Register r1, |
| 599 | Register r2, |
| 600 | Register result); |
| 601 | |
| 602 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 603 | // --------------------------------------------------------------------------- |
| 604 | // Allocation support |
| 605 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 606 | // Allocate an object in new space or old pointer space. If the given space |
| 607 | // is exhausted control continues at the gc_required label. The allocated |
| 608 | // object is returned in result and end of the new object is returned in |
| 609 | // result_end. The register scratch can be passed as no_reg in which case |
| 610 | // an additional object reference will be added to the reloc info. The |
| 611 | // returned pointers in result and result_end have not yet been tagged as |
| 612 | // heap objects. If result_contains_top_on_entry is true the content of |
| 613 | // result is known to be the allocation top on entry (could be result_end |
| 614 | // from a previous call). If result_contains_top_on_entry is true scratch |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 615 | // should be no_reg as it is never used. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 616 | void Allocate(int object_size, |
| 617 | Register result, |
| 618 | Register result_end, |
| 619 | Register scratch, |
| 620 | Label* gc_required, |
| 621 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 622 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 623 | void Allocate(int header_size, |
| 624 | ScaleFactor element_size, |
| 625 | Register element_count, |
| 626 | RegisterValueType element_count_type, |
| 627 | Register result, |
| 628 | Register result_end, |
| 629 | Register scratch, |
| 630 | Label* gc_required, |
| 631 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 633 | void Allocate(Register object_size, |
| 634 | Register result, |
| 635 | Register result_end, |
| 636 | Register scratch, |
| 637 | Label* gc_required, |
| 638 | AllocationFlags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 639 | |
| 640 | // Undo allocation in new space. The object passed and objects allocated after |
| 641 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 642 | // object(s) no longer allocated as they would be invalid when allocation is |
| 643 | // un-done. |
| 644 | void UndoAllocationInNewSpace(Register object); |
| 645 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 646 | // Allocate a heap number in new space with undefined value. The |
| 647 | // register scratch2 can be passed as no_reg; the others must be |
| 648 | // valid registers. Returns tagged pointer in result register, or |
| 649 | // jumps to gc_required if new space is full. |
| 650 | void AllocateHeapNumber(Register result, |
| 651 | Register scratch1, |
| 652 | Register scratch2, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 653 | Label* gc_required, |
| 654 | MutableMode mode = IMMUTABLE); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 655 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 656 | // Allocate a sequential string. All the header fields of the string object |
| 657 | // are initialized. |
| 658 | void AllocateTwoByteString(Register result, |
| 659 | Register length, |
| 660 | Register scratch1, |
| 661 | Register scratch2, |
| 662 | Register scratch3, |
| 663 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 664 | void AllocateOneByteString(Register result, Register length, |
| 665 | Register scratch1, Register scratch2, |
| 666 | Register scratch3, Label* gc_required); |
| 667 | void AllocateOneByteString(Register result, int length, Register scratch1, |
| 668 | Register scratch2, Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 669 | |
| 670 | // Allocate a raw cons string object. Only the map field of the result is |
| 671 | // initialized. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 672 | void AllocateTwoByteConsString(Register result, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 673 | Register scratch1, |
| 674 | Register scratch2, |
| 675 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 676 | void AllocateOneByteConsString(Register result, Register scratch1, |
| 677 | Register scratch2, Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 678 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 679 | // Allocate a raw sliced string object. Only the map field of the result is |
| 680 | // initialized. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 681 | void AllocateTwoByteSlicedString(Register result, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 682 | Register scratch1, |
| 683 | Register scratch2, |
| 684 | Label* gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 685 | void AllocateOneByteSlicedString(Register result, Register scratch1, |
| 686 | Register scratch2, Label* gc_required); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 687 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 688 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 689 | // long or aligned copies. |
| 690 | // The contents of index and scratch are destroyed. |
| 691 | void CopyBytes(Register source, |
| 692 | Register destination, |
| 693 | Register length, |
| 694 | Register scratch); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 695 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 696 | // Initialize fields with filler values. Fields starting at |start_offset| |
| 697 | // not including end_offset are overwritten with the value in |filler|. At |
| 698 | // the end the loop, |start_offset| takes the value of |end_offset|. |
| 699 | void InitializeFieldsWithFiller(Register start_offset, |
| 700 | Register end_offset, |
| 701 | Register filler); |
| 702 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 703 | // --------------------------------------------------------------------------- |
| 704 | // Support functions. |
| 705 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 706 | // Check a boolean-bit of a Smi field. |
| 707 | void BooleanBitTest(Register object, int field_offset, int bit_index); |
| 708 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 709 | // Check if result is zero and op is negative. |
| 710 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 711 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 712 | // Check if result is zero and any of op1 and op2 are negative. |
| 713 | // Register scratch is destroyed, and it must be different from op2. |
| 714 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 715 | Register scratch, Label* then_label); |
| 716 | |
| 717 | // Try to get function prototype of a function and puts the value in |
| 718 | // the result register. Checks that the function really is a |
| 719 | // function and jumps to the miss label if the fast checks fail. The |
| 720 | // function register will be untouched; the other registers may be |
| 721 | // clobbered. |
| 722 | void TryGetFunctionPrototype(Register function, |
| 723 | Register result, |
| 724 | Register scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 725 | Label* miss, |
| 726 | bool miss_on_bound_function = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 727 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 728 | // Picks out an array index from the hash field. |
| 729 | // Register use: |
| 730 | // hash - holds the index's hash. Clobbered. |
| 731 | // index - holds the overwritten index on exit. |
| 732 | void IndexFromHash(Register hash, Register index); |
| 733 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | // --------------------------------------------------------------------------- |
| 735 | // Runtime calls |
| 736 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 737 | // Call a code stub. Generate the code if necessary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 738 | void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 739 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 740 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 741 | void TailCallStub(CodeStub* stub); |
| 742 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 743 | // Return from a code stub after popping its arguments. |
| 744 | void StubReturn(int argc); |
| 745 | |
| 746 | // Call a runtime routine. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 747 | void CallRuntime(const Runtime::Function* f, |
| 748 | int num_arguments, |
| 749 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
| 750 | void CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
| 751 | const Runtime::Function* function = Runtime::FunctionForId(id); |
| 752 | CallRuntime(function, function->nargs, kSaveFPRegs); |
| 753 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 754 | |
| 755 | // Convenience function: Same as above, but takes the fid instead. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | void CallRuntime(Runtime::FunctionId id, |
| 757 | int num_arguments, |
| 758 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 759 | CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles); |
| 760 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 762 | // Convenience function: call an external reference. |
| 763 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 764 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 765 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 766 | // Like JumpToExternalReference, but also takes care of passing the number |
| 767 | // of parameters. |
| 768 | void TailCallExternalReference(const ExternalReference& ext, |
| 769 | int num_arguments, |
| 770 | int result_size); |
| 771 | |
| 772 | // Convenience function: tail call a runtime routine (jump). |
| 773 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 774 | int num_arguments, |
| 775 | int result_size); |
| 776 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 777 | // Before calling a C-function from generated code, align arguments on stack. |
| 778 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 779 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 780 | // Some compilers/platforms require the stack to be aligned when calling |
| 781 | // C++ code. |
| 782 | // Needs a scratch register to do some arithmetic. This register will be |
| 783 | // trashed. |
| 784 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 785 | |
| 786 | // Calls a C function and cleans up the space for arguments allocated |
| 787 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 788 | // garbage collection, since that might move the code and invalidate the |
| 789 | // return address (unless this is somehow accounted for by the called |
| 790 | // function). |
| 791 | void CallCFunction(ExternalReference function, int num_arguments); |
| 792 | void CallCFunction(Register function, int num_arguments); |
| 793 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 794 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 795 | // 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] | 796 | // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1) |
| 797 | // etc. Saves context (esi). If space was reserved for return value then |
| 798 | // stores the pointer to the reserved slot into esi. |
| 799 | void PrepareCallApiFunction(int argc); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 800 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 801 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 802 | // from handle and propagates exceptions. Clobbers ebx, edi and |
| 803 | // caller-save registers. Restores context. On return removes |
| 804 | // stack_space * kPointerSize (GCed). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 805 | void CallApiFunctionAndReturn(Register function_address, |
| 806 | ExternalReference thunk_ref, |
| 807 | Operand thunk_last_arg, |
| 808 | int stack_space, |
| 809 | Operand return_value_operand, |
| 810 | Operand* context_restore_operand); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 811 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 813 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 814 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 815 | // --------------------------------------------------------------------------- |
| 816 | // Utilities |
| 817 | |
| 818 | void Ret(); |
| 819 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 820 | // Return and drop arguments from stack, where the number of arguments |
| 821 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 822 | void Ret(int bytes_dropped, Register scratch); |
| 823 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 824 | // Emit code to discard a non-negative number of pointer-sized elements |
| 825 | // from the stack, clobbering only the esp register. |
| 826 | void Drop(int element_count); |
| 827 | |
| 828 | void Call(Label* target) { call(target); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 829 | void Push(Register src) { push(src); } |
| 830 | void Pop(Register dst) { pop(dst); } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 831 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 832 | // Emit call to the code we are currently generating. |
| 833 | void CallSelf() { |
| 834 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 835 | call(self, RelocInfo::CODE_TARGET); |
| 836 | } |
| 837 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 838 | // Move if the registers are not identical. |
| 839 | void Move(Register target, Register source); |
| 840 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 841 | // Move a constant into a destination using the most efficient encoding. |
| 842 | void Move(Register dst, const Immediate& x); |
| 843 | void Move(const Operand& dst, const Immediate& x); |
| 844 | |
| 845 | // Move an immediate into an XMM register. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 846 | void Move(XMMRegister dst, uint32_t src); |
| 847 | void Move(XMMRegister dst, uint64_t src); |
| 848 | void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 849 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 850 | // Push a handle value. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 851 | void Push(Handle<Object> handle) { push(Immediate(handle)); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 853 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 854 | Handle<Object> CodeObject() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 855 | DCHECK(!code_object_.is_null()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 856 | return code_object_; |
| 857 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 858 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | // Emit code for a truncating division by a constant. The dividend register is |
| 860 | // unchanged, the result is in edx, and eax gets clobbered. |
| 861 | void TruncatingDiv(Register dividend, int32_t divisor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 862 | |
| 863 | // --------------------------------------------------------------------------- |
| 864 | // StatsCounter support |
| 865 | |
| 866 | void SetCounter(StatsCounter* counter, int value); |
| 867 | void IncrementCounter(StatsCounter* counter, int value); |
| 868 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 869 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 870 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 871 | |
| 872 | |
| 873 | // --------------------------------------------------------------------------- |
| 874 | // Debugging |
| 875 | |
| 876 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 877 | // Use --debug_code to enable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 878 | void Assert(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 880 | void AssertFastElements(Register elements); |
| 881 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 882 | // Like Assert(), but always enabled. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 883 | void Check(Condition cc, BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 884 | |
| 885 | // Print a message to stdout and abort execution. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | void Abort(BailoutReason reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 887 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 888 | // Check that the stack is aligned. |
| 889 | void CheckStackAlignment(); |
| 890 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 891 | // Verify restrictions about code generated in stubs. |
| 892 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 893 | bool generating_stub() { return generating_stub_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 894 | void set_has_frame(bool value) { has_frame_ = value; } |
| 895 | bool has_frame() { return has_frame_; } |
| 896 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 897 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 898 | // --------------------------------------------------------------------------- |
| 899 | // String utilities. |
| 900 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 901 | // Generate code to do a lookup in the number string cache. If the number in |
| 902 | // the register object is found in the cache the generated code falls through |
| 903 | // with the result in the result register. The object and the result register |
| 904 | // can be the same. If the number is not found in the cache the code jumps to |
| 905 | // the label not_found with only the content of register object unchanged. |
| 906 | void LookupNumberStringCache(Register object, |
| 907 | Register result, |
| 908 | Register scratch1, |
| 909 | Register scratch2, |
| 910 | Label* not_found); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 911 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 912 | // Check whether the instance type represents a flat one-byte string. Jump to |
| 913 | // the label if not. If the instance type can be scratched specify same |
| 914 | // register for both instance type and scratch. |
| 915 | void JumpIfInstanceTypeIsNotSequentialOneByte( |
| 916 | Register instance_type, Register scratch, |
| 917 | Label* on_not_flat_one_byte_string); |
| 918 | |
| 919 | // Checks if both objects are sequential one-byte strings, and jumps to label |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 920 | // if either is not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 921 | void JumpIfNotBothSequentialOneByteStrings( |
| 922 | Register object1, Register object2, Register scratch1, Register scratch2, |
| 923 | Label* on_not_flat_one_byte_strings); |
| 924 | |
| 925 | // Checks if the given register or operand is a unique name |
| 926 | void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name, |
| 927 | Label::Distance distance = Label::kFar) { |
| 928 | JumpIfNotUniqueNameInstanceType(Operand(reg), not_unique_name, distance); |
| 929 | } |
| 930 | |
| 931 | void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name, |
| 932 | Label::Distance distance = Label::kFar); |
| 933 | |
| 934 | void EmitSeqStringSetCharCheck(Register string, |
| 935 | Register index, |
| 936 | Register value, |
| 937 | uint32_t encoding_mask); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 938 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 939 | static int SafepointRegisterStackIndex(Register reg) { |
| 940 | return SafepointRegisterStackIndex(reg.code()); |
| 941 | } |
| 942 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 943 | // Activation support. |
| 944 | void EnterFrame(StackFrame::Type type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 945 | void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 946 | void LeaveFrame(StackFrame::Type type); |
| 947 | |
| 948 | // Expects object in eax and returns map with validated enum cache |
| 949 | // in eax. Assumes that any other register can be used as a scratch. |
| 950 | void CheckEnumCache(Label* call_runtime); |
| 951 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 952 | // AllocationMemento support. Arrays may have an associated |
| 953 | // AllocationMemento object that can be checked for in order to pretransition |
| 954 | // to another type. |
| 955 | // On entry, receiver_reg should point to the array object. |
| 956 | // scratch_reg gets clobbered. |
| 957 | // If allocation info is present, conditional code is set to equal. |
| 958 | void TestJSArrayForAllocationMemento(Register receiver_reg, |
| 959 | Register scratch_reg, |
| 960 | Label* no_memento_found); |
| 961 | |
| 962 | void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, |
| 963 | Register scratch_reg, |
| 964 | Label* memento_found) { |
| 965 | Label no_memento_found; |
| 966 | TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, |
| 967 | &no_memento_found); |
| 968 | j(equal, memento_found); |
| 969 | bind(&no_memento_found); |
| 970 | } |
| 971 | |
| 972 | // Jumps to found label if a prototype map has dictionary elements. |
| 973 | void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0, |
| 974 | Register scratch1, Label* found); |
| 975 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 976 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 977 | bool generating_stub_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 978 | bool has_frame_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 979 | // This handle will be patched with the code object on installation. |
| 980 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | |
| 982 | // Helper functions for generating invokes. |
| 983 | void InvokePrologue(const ParameterCount& expected, |
| 984 | const ParameterCount& actual, |
| 985 | Handle<Code> code_constant, |
| 986 | const Operand& code_operand, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 987 | Label* done, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 988 | bool* definitely_mismatches, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 989 | InvokeFlag flag, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 990 | Label::Distance done_distance, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 991 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 992 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 993 | void EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 994 | void EnterExitFrameEpilogue(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 995 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | void LeaveExitFrameEpilogue(bool restore_context); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 997 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 998 | // Allocation support helpers. |
| 999 | void LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1000 | Register scratch, |
| 1001 | AllocationFlags flags); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1002 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | void UpdateAllocationTopHelper(Register result_end, |
| 1004 | Register scratch, |
| 1005 | AllocationFlags flags); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1006 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1007 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 1008 | void InNewSpace(Register object, |
| 1009 | Register scratch, |
| 1010 | Condition cc, |
| 1011 | Label* condition_met, |
| 1012 | Label::Distance condition_met_distance = Label::kFar); |
| 1013 | |
| 1014 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1015 | // bitmap register points at the word with the mark bits and the mask |
| 1016 | // the position of the first bit. Uses ecx as scratch and leaves addr_reg |
| 1017 | // unchanged. |
| 1018 | inline void GetMarkBits(Register addr_reg, |
| 1019 | Register bitmap_reg, |
| 1020 | Register mask_reg); |
| 1021 | |
| 1022 | // Helper for throwing exceptions. Compute a handler address and jump to |
| 1023 | // it. See the implementation for register usage. |
| 1024 | void JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1025 | |
| 1026 | // Compute memory operands for safepoint stack slots. |
| 1027 | Operand SafepointRegisterSlot(Register reg); |
| 1028 | static int SafepointRegisterStackIndex(int reg_code); |
| 1029 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1030 | // Needs access to SafepointRegisterStackIndex for compiled frame |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1031 | // traversal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1032 | friend class StandardFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1033 | }; |
| 1034 | |
| 1035 | |
| 1036 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1037 | // debugging and other types of instrumentation. When using the code patcher |
| 1038 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 1039 | // relocation information. If any of these constraints are violated it causes |
| 1040 | // an assertion. |
| 1041 | class CodePatcher { |
| 1042 | public: |
| 1043 | CodePatcher(byte* address, int size); |
| 1044 | virtual ~CodePatcher(); |
| 1045 | |
| 1046 | // Macro assembler to emit code. |
| 1047 | MacroAssembler* masm() { return &masm_; } |
| 1048 | |
| 1049 | private: |
| 1050 | byte* address_; // The address of the code being patched. |
| 1051 | int size_; // Number of bytes of the expected patch size. |
| 1052 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1053 | }; |
| 1054 | |
| 1055 | |
| 1056 | // ----------------------------------------------------------------------------- |
| 1057 | // Static helper functions. |
| 1058 | |
| 1059 | // Generate an Operand for loading a field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1060 | inline Operand FieldOperand(Register object, int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1061 | return Operand(object, offset - kHeapObjectTag); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | // Generate an Operand for loading an indexed field from an object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1066 | inline Operand FieldOperand(Register object, |
| 1067 | Register index, |
| 1068 | ScaleFactor scale, |
| 1069 | int offset) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1070 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 1071 | } |
| 1072 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1073 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1074 | inline Operand FixedArrayElementOperand(Register array, |
| 1075 | Register index_as_smi, |
| 1076 | int additional_offset = 0) { |
| 1077 | int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize; |
| 1078 | return FieldOperand(array, index_as_smi, times_half_pointer_size, offset); |
| 1079 | } |
| 1080 | |
| 1081 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1082 | inline Operand ContextOperand(Register context, int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1083 | return Operand(context, Context::SlotOffset(index)); |
| 1084 | } |
| 1085 | |
| 1086 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1087 | inline Operand GlobalObjectOperand() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1088 | return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1092 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 1093 | Operand ApiParameterOperand(int index); |
| 1094 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1095 | |
| 1096 | #ifdef GENERATED_CODE_COVERAGE |
| 1097 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 1098 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1099 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1100 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1101 | #define ACCESS_MASM(masm) { \ |
| 1102 | byte* ia32_coverage_function = \ |
| 1103 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 1104 | masm->pushfd(); \ |
| 1105 | masm->pushad(); \ |
| 1106 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 1107 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 1108 | masm->pop(eax); \ |
| 1109 | masm->popad(); \ |
| 1110 | masm->popfd(); \ |
| 1111 | } \ |
| 1112 | masm-> |
| 1113 | #else |
| 1114 | #define ACCESS_MASM(masm) masm-> |
| 1115 | #endif |
| 1116 | |
| 1117 | |
| 1118 | } } // namespace v8::internal |
| 1119 | |
| 1120 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |