blob: 83f62164458936deeaa46eac60dbfc34302a4cb4 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_
6#define V8_IA32_MACRO_ASSEMBLER_IA32_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/assembler.h"
9#include "src/bailout-reason.h"
10#include "src/frames.h"
11#include "src/globals.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000012
13namespace v8 {
14namespace internal {
15
Leon Clarkee46be812010-01-19 14:06:41 +000016// Convenience for platform-independent signatures. We do not normally
17// distinguish memory operands from other operands on ia32.
18typedef Operand MemOperand;
19
Ben Murdoch3ef787d2012-04-12 10:51:47 +010020enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
21enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022enum PointersToHereCheck {
23 kPointersToHereMaybeInteresting,
24 kPointersToHereAreAlwaysInteresting
25};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010026
27
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028enum RegisterValueType {
29 REGISTER_VALUE_IS_SMI,
30 REGISTER_VALUE_IS_INT32
31};
32
33
34#ifdef DEBUG
35bool 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 Murdoch3ef787d2012-04-12 10:51:47 +010044
45
Steve Blocka7e24c12009-10-30 11:49:00 +000046// MacroAssembler implements a collection of frequently used macros.
47class MacroAssembler: public Assembler {
48 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +010049 // 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 Blocka7e24c12009-10-30 11:49:00 +000054
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 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 Blocka7e24c12009-10-30 11:49:00 +000067 // ---------------------------------------------------------------------------
68 // GC Support
Ben Murdoch3ef787d2012-04-12 10:51:47 +010069 enum RememberedSetFinalAction {
70 kReturnAtEnd,
71 kFallThroughAtEnd
72 };
Steve Blocka7e24c12009-10-30 11:49:00 +000073
Ben Murdoch3ef787d2012-04-12 10:51:47 +010074 // 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 Block6ded16b2010-05-10 14:33:55 +010082
Ben Murdoch3ef787d2012-04-12 10:51:47 +010083 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 Block6ded16b2010-05-10 14:33:55 +010089
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090 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 Murdoch3ef787d2012-04-12 10:51:47 +010097 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000153 SmiCheck smi_check = INLINE_SMI_CHECK,
154 PointersToHereCheck pointers_to_here_check_for_value =
155 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100156
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 Murdochb8a8cc12014-11-26 15:28:44 +0000166 SmiCheck smi_check = INLINE_SMI_CHECK,
167 PointersToHereCheck pointers_to_here_check_for_value =
168 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100169 RecordWriteField(context,
170 offset + kHeapObjectTag,
171 value,
172 scratch,
173 save_fp,
174 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 smi_check,
176 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100177 }
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 Block8defd9f2010-07-08 12:39:36 +0100183 // filters out smis so it does not update the write barrier if the
184 // value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100185 void RecordWriteArray(
186 Register array,
187 Register value,
188 Register index,
189 SaveFPRegsMode save_fp,
190 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000191 SmiCheck smi_check = INLINE_SMI_CHECK,
192 PointersToHereCheck pointers_to_here_check_for_value =
193 kPointersToHereMaybeInteresting);
Steve Blocka7e24c12009-10-30 11:49:00 +0000194
Steve Block8defd9f2010-07-08 12:39:36 +0100195 // For page containing |object| mark region covering |address|
196 // dirty. |object| is the object being stored into, |value| is the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100197 // object being stored. The address and value registers are clobbered by the
Steve Block8defd9f2010-07-08 12:39:36 +0100198 // operation. RecordWrite filters out smis so it does not update the
199 // write barrier if the value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100200 void RecordWrite(
201 Register object,
202 Register address,
203 Register value,
204 SaveFPRegsMode save_fp,
205 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000206 SmiCheck smi_check = INLINE_SMI_CHECK,
207 PointersToHereCheck pointers_to_here_check_for_value =
208 kPointersToHereMaybeInteresting);
Steve Block8defd9f2010-07-08 12:39:36 +0100209
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210 // 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 Blocka7e24c12009-10-30 11:49:00 +0000220 // ---------------------------------------------------------------------------
221 // Debugger Support
222
Andrei Popescu402d9372010-02-26 13:31:12 +0000223 void DebugBreak();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224
225 // Generates function and stub prologue code.
226 void StubPrologue();
227 void Prologue(bool code_pre_aging);
Steve Blocka7e24c12009-10-30 11:49:00 +0000228
Ben Murdochb0fe1622011-05-05 13:52:32 +0100229 // 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 Blockd0582a62009-12-15 09:54:21 +0000234
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800235 void EnterApiExitFrame(int argc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000236
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 Murdochb0fe1622011-05-05 13:52:32 +0100240 void LeaveExitFrame(bool save_doubles);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800242 // Leave the current exit frame. Expects the return value in
243 // register eax (untouched).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244 void LeaveApiExitFrame(bool restore_context);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800245
Steve Blockd0582a62009-12-15 09:54:21 +0000246 // Find the function context up the context chain.
247 void LoadContext(Register dst, int context_chain_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000248
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100249 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 // 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 Murdoch3ef787d2012-04-12 10:51:47 +0100252 // 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 Monsen80d68ea2010-09-08 11:05:35 +0100260 // 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 Murdochb0fe1622011-05-05 13:52:32 +0100267 // Push and pop the registers that can hold pointers.
268 void PushSafepointRegisters() { pushad(); }
269 void PopSafepointRegisters() { popad(); }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100270 // 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 Murdochb0fe1622011-05-05 13:52:32 +0100275
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100276 void LoadHeapObject(Register result, Handle<HeapObject> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000277 void CmpHeapObject(Register reg, Handle<HeapObject> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100278 void PushHeapObject(Handle<HeapObject> object);
279
280 void LoadObject(Register result, Handle<Object> object) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000281 AllowDeferredHandleDereference heap_object_check;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100282 if (object->IsHeapObject()) {
283 LoadHeapObject(result, Handle<HeapObject>::cast(object));
284 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000285 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 Murdoch3ef787d2012-04-12 10:51:47 +0100295 }
296 }
297
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400298 // 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 Blocka7e24c12009-10-30 11:49:00 +0000305 // ---------------------------------------------------------------------------
306 // JavaScript invokes
307
308 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100309 void InvokeCode(Register code,
310 const ParameterCount& expected,
311 const ParameterCount& actual,
312 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313 const CallWrapper& call_wrapper) {
314 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100315 }
316
Steve Blocka7e24c12009-10-30 11:49:00 +0000317 void InvokeCode(const Operand& code,
318 const ParameterCount& expected,
319 const ParameterCount& actual,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100320 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
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 Murdochb0fe1622011-05-05 13:52:32 +0100327 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000328 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000329
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000330 void InvokeFunction(Register function,
331 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000332 const ParameterCount& actual,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100333 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000334 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 Popescu402d9372010-02-26 13:31:12 +0000341
Steve Blocka7e24c12009-10-30 11:49:00 +0000342 // Invoke specified builtin JavaScript function. Adds an entry to
343 // the unresolved list if the name does not resolve.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100344 void InvokeBuiltin(Builtins::JavaScript id,
345 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000346 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Steve Block791712a2010-08-27 10:21:07 +0100348 // Store the function for the given builtin in the target register.
349 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
350
Steve Blocka7e24c12009-10-30 11:49:00 +0000351 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000355 // 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 Blocka7e24c12009-10-30 11:49:00 +0000360
Steve Block053d10c2011-06-13 19:13:29 +0100361 // Support for constant splitting.
362 bool IsUnsafeImmediate(const Immediate& x);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363 void SafeMove(Register dst, const Immediate& x);
Steve Block053d10c2011-06-13 19:13:29 +0100364 void SafePush(const Immediate& x);
365
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 // 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 Murdoch3fb3ca82011-12-02 17:19:32 +0000373 // 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 Murdoch3ef787d2012-04-12 10:51:47 +0100379 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000387 void CheckFastSmiElements(Register map,
388 Label* fail,
389 Label::Distance distance = Label::kFar);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100390
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 Murdochb8a8cc12014-11-26 15:28:44 +0000400 int offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100401
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000402 // Compare an object's map with the specified map.
403 void CompareMap(Register obj, Handle<Map> map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100404
Ben Murdoch257744e2011-11-30 15:57:28 +0000405 // 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 Murdoch3ef787d2012-04-12 10:51:47 +0100407 // 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 Popescu31002712010-02-23 13:46:05 +0000409 void CheckMap(Register obj,
410 Handle<Map> map,
411 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000412 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000413
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400414 // 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 Popescu31002712010-02-23 13:46:05 +0000420
Leon Clarkee46be812010-01-19 14:06:41 +0000421 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000430 // 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 Murdoch7f4d5bd2010-06-15 11:15:29 +0100439 // 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 Blocka7e24c12009-10-30 11:49:00 +0000451 // 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 Murdoch257744e2011-11-30 15:57:28 +0000455 void ClampUint8(Register reg);
456
457 void ClampDoubleToUint8(XMMRegister input_reg,
458 XMMRegister scratch_reg,
459 Register result_reg);
460
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 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 Murdoch257744e2011-11-30 15:57:28 +0000471
Leon Clarkee46be812010-01-19 14:06:41 +0000472 // Smi tagging support.
473 void SmiTag(Register reg) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000474 STATIC_ASSERT(kSmiTag == 0);
475 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100476 add(reg, reg);
Leon Clarkee46be812010-01-19 14:06:41 +0000477 }
478 void SmiUntag(Register reg) {
479 sar(reg, kSmiTagSize);
480 }
481
Iain Merrick75681382010-08-19 15:07:18 +0100482 // Modifies the register even if it does not contain a Smi!
Iain Merrick75681382010-08-19 15:07:18 +0100483 void SmiUntag(Register reg, Label* is_smi) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000484 STATIC_ASSERT(kSmiTagSize == 1);
Iain Merrick75681382010-08-19 15:07:18 +0100485 sar(reg, kSmiTagSize);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000486 STATIC_ASSERT(kSmiTag == 0);
Iain Merrick75681382010-08-19 15:07:18 +0100487 j(not_carry, is_smi);
488 }
489
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400490 void LoadUint32(XMMRegister dst, Register src) {
491 LoadUint32(dst, Operand(src));
492 }
493 void LoadUint32(XMMRegister dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000494
Steve Block1e0659c2011-05-24 12:43:12 +0100495 // Jump the register contains a smi.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000496 inline void JumpIfSmi(Register value,
497 Label* smi_label,
498 Label::Distance distance = Label::kFar) {
Steve Block1e0659c2011-05-24 12:43:12 +0100499 test(value, Immediate(kSmiTagMask));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000500 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 Block1e0659c2011-05-24 12:43:12 +0100508 }
509 // Jump if register contain a non-smi.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000510 inline void JumpIfNotSmi(Register value,
511 Label* not_smi_label,
512 Label::Distance distance = Label::kFar) {
Steve Block1e0659c2011-05-24 12:43:12 +0100513 test(value, Immediate(kSmiTagMask));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000514 j(not_zero, not_smi_label, distance);
Steve Block1e0659c2011-05-24 12:43:12 +0100515 }
516
Ben Murdoch257744e2011-11-30 15:57:28 +0000517 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000518 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 Merrick75681382010-08-19 15:07:18 +0100544
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100545 void LoadPowerOf2(XMMRegister dst, Register scratch, int power);
546
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000547 // Abort execution if argument is not a number, enabled via --debug-code.
548 void AssertNumber(Register object);
Steve Block6ded16b2010-05-10 14:33:55 +0100549
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550 // Abort execution if argument is not a smi, enabled via --debug-code.
551 void AssertSmi(Register object);
Andrei Popescu402d9372010-02-26 13:31:12 +0000552
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000553 // Abort execution if argument is a smi, enabled via --debug-code.
554 void AssertNotSmi(Register object);
Iain Merrick75681382010-08-19 15:07:18 +0100555
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000556 // 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 Monsen80d68ea2010-09-08 11:05:35 +0100565
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 // ---------------------------------------------------------------------------
567 // Exception handling
568
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100569 // Push a new try handler and link it into try handler chain.
570 void PushTryHandler(StackHandler::Kind kind, int handler_index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000571
Leon Clarkee46be812010-01-19 14:06:41 +0000572 // Unlink the stack handler on top of the stack from the try handler chain.
573 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000574
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100575 // Throw to the top handler in the try hander chain.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100576 void Throw(Register value);
577
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100578 // Throw past all JS frames to the top JS entry frame.
579 void ThrowUncatchable(Register value);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100580
Steve Blocka7e24c12009-10-30 11:49:00 +0000581 // ---------------------------------------------------------------------------
582 // Inline caching support
583
Steve Blocka7e24c12009-10-30 11:49:00 +0000584 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000588 Register scratch1,
589 Register scratch2,
Steve Blocka7e24c12009-10-30 11:49:00 +0000590 Label* miss);
591
Ben Murdochc7cc0282012-03-05 14:35:55 +0000592 void GetNumberHash(Register r0, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000594 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 Blocka7e24c12009-10-30 11:49:00 +0000603 // ---------------------------------------------------------------------------
604 // Allocation support
605
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000606 // 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 Blocka7e24c12009-10-30 11:49:00 +0000615 // should be no_reg as it is never used.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000616 void Allocate(int object_size,
617 Register result,
618 Register result_end,
619 Register scratch,
620 Label* gc_required,
621 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000622
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000623 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 Blocka7e24c12009-10-30 11:49:00 +0000632
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000633 void Allocate(Register object_size,
634 Register result,
635 Register result_end,
636 Register scratch,
637 Label* gc_required,
638 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000639
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 Block3ce2e202009-11-05 08:53:23 +0000646 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000653 Label* gc_required,
654 MutableMode mode = IMMUTABLE);
Steve Block3ce2e202009-11-05 08:53:23 +0000655
Steve Blockd0582a62009-12-15 09:54:21 +0000656 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000664 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 Blockd0582a62009-12-15 09:54:21 +0000669
670 // Allocate a raw cons string object. Only the map field of the result is
671 // initialized.
Ben Murdoch589d6972011-11-30 16:04:58 +0000672 void AllocateTwoByteConsString(Register result,
Steve Blockd0582a62009-12-15 09:54:21 +0000673 Register scratch1,
674 Register scratch2,
675 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000676 void AllocateOneByteConsString(Register result, Register scratch1,
677 Register scratch2, Label* gc_required);
Steve Blockd0582a62009-12-15 09:54:21 +0000678
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000679 // Allocate a raw sliced string object. Only the map field of the result is
680 // initialized.
Ben Murdoch589d6972011-11-30 16:04:58 +0000681 void AllocateTwoByteSlicedString(Register result,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000682 Register scratch1,
683 Register scratch2,
684 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000685 void AllocateOneByteSlicedString(Register result, Register scratch1,
686 Register scratch2, Label* gc_required);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000687
Ben Murdochb8e0da22011-05-16 14:20:40 +0100688 // 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) Wang8a31eba2010-12-06 19:01:33 -0800695
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100696 // 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 Blocka7e24c12009-10-30 11:49:00 +0000703 // ---------------------------------------------------------------------------
704 // Support functions.
705
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100706 // Check a boolean-bit of a Smi field.
707 void BooleanBitTest(Register object, int field_offset, int bit_index);
708
Steve Blocka7e24c12009-10-30 11:49:00 +0000709 // Check if result is zero and op is negative.
710 void NegativeZeroTest(Register result, Register op, Label* then_label);
711
Steve Blocka7e24c12009-10-30 11:49:00 +0000712 // 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 Murdoch3ef787d2012-04-12 10:51:47 +0100725 Label* miss,
726 bool miss_on_bound_function = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000727
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100728 // 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 Blocka7e24c12009-10-30 11:49:00 +0000734 // ---------------------------------------------------------------------------
735 // Runtime calls
736
Leon Clarkee46be812010-01-19 14:06:41 +0000737 // Call a code stub. Generate the code if necessary.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000738 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000739
Leon Clarkee46be812010-01-19 14:06:41 +0000740 // Tail call a code stub (jump). Generate the code if necessary.
Steve Blockd0582a62009-12-15 09:54:21 +0000741 void TailCallStub(CodeStub* stub);
742
Steve Blocka7e24c12009-10-30 11:49:00 +0000743 // Return from a code stub after popping its arguments.
744 void StubReturn(int argc);
745
746 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000747 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 Blocka7e24c12009-10-30 11:49:00 +0000754
755 // Convenience function: Same as above, but takes the fid instead.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000756 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 Blocka7e24c12009-10-30 11:49:00 +0000761
Ben Murdochbb769b22010-08-11 14:56:33 +0100762 // Convenience function: call an external reference.
763 void CallExternalReference(ExternalReference ref, int num_arguments);
764
Steve Blocka7e24c12009-10-30 11:49:00 +0000765 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100766 // 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 Blocka7e24c12009-10-30 11:49:00 +0000774 int num_arguments,
775 int result_size);
776
Steve Block6ded16b2010-05-10 14:33:55 +0100777 // 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 Reck59135872010-11-02 12:39:01 -0700794 // 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 Murdoch3fb3ca82011-12-02 17:19:32 +0000796 // 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 Blockd0582a62009-12-15 09:54:21 +0000800
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100801 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000805 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 Clarkee46be812010-01-19 14:06:41 +0000811
Steve Blocka7e24c12009-10-30 11:49:00 +0000812 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100813 void JumpToExternalReference(const ExternalReference& ext);
Steve Blocka7e24c12009-10-30 11:49:00 +0000814
Steve Blocka7e24c12009-10-30 11:49:00 +0000815 // ---------------------------------------------------------------------------
816 // Utilities
817
818 void Ret();
819
Steve Block1e0659c2011-05-24 12:43:12 +0100820 // 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 Clarkee46be812010-01-19 14:06:41 +0000824 // 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 Murdochb8a8cc12014-11-26 15:28:44 +0000829 void Push(Register src) { push(src); }
830 void Pop(Register dst) { pop(dst); }
Leon Clarkee46be812010-01-19 14:06:41 +0000831
Ben Murdochb0fe1622011-05-05 13:52:32 +0100832 // 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 Monsen0d5e1162010-09-30 15:31:59 +0100838 // Move if the registers are not identical.
839 void Move(Register target, Register source);
840
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000841 // 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 Bernierd0a1eb72015-03-24 16:35:39 -0400846 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 Murdochb8a8cc12014-11-26 15:28:44 +0000849
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000850 // Push a handle value.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100851 void Push(Handle<Object> handle) { push(Immediate(handle)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000852 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000853
Ben Murdoch8b112d22011-06-08 16:22:53 +0100854 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000855 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100856 return code_object_;
857 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000858
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000859 // 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 Blocka7e24c12009-10-30 11:49:00 +0000862
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 Clarked91b9f72010-01-27 17:25:45 +0000869 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
870 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000871
872
873 // ---------------------------------------------------------------------------
874 // Debugging
875
876 // Calls Abort(msg) if the condition cc is not satisfied.
877 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000878 void Assert(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000879
Iain Merrick75681382010-08-19 15:07:18 +0100880 void AssertFastElements(Register elements);
881
Steve Blocka7e24c12009-10-30 11:49:00 +0000882 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000883 void Check(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000884
885 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886 void Abort(BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000887
Steve Block6ded16b2010-05-10 14:33:55 +0100888 // Check that the stack is aligned.
889 void CheckStackAlignment();
890
Steve Blocka7e24c12009-10-30 11:49:00 +0000891 // 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 Murdoch3ef787d2012-04-12 10:51:47 +0100894 void set_has_frame(bool value) { has_frame_ = value; }
895 bool has_frame() { return has_frame_; }
896 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +0000897
Leon Clarked91b9f72010-01-27 17:25:45 +0000898 // ---------------------------------------------------------------------------
899 // String utilities.
900
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901 // 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 Popescu402d9372010-02-26 13:31:12 +0000911
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000912 // 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 Clarked91b9f72010-01-27 17:25:45 +0000920 // if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000921 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 Clarked91b9f72010-01-27 17:25:45 +0000938
Ben Murdoch8b112d22011-06-08 16:22:53 +0100939 static int SafepointRegisterStackIndex(Register reg) {
940 return SafepointRegisterStackIndex(reg.code());
941 }
942
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100943 // Activation support.
944 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400945 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100946 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 Murdochb8a8cc12014-11-26 15:28:44 +0000952 // 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 Blocka7e24c12009-10-30 11:49:00 +0000976 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000977 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100978 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +0000979 // This handle will be patched with the code object on installation.
980 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000981
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 Murdoch257744e2011-11-30 15:57:28 +0000987 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100988 bool* definitely_mismatches,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100989 InvokeFlag flag,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100990 Label::Distance done_distance,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000991 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +0000992
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100993 void EnterExitFramePrologue();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100994 void EnterExitFrameEpilogue(int argc, bool save_doubles);
Steve Blockd0582a62009-12-15 09:54:21 +0000995
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000996 void LeaveExitFrameEpilogue(bool restore_context);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800997
Steve Blocka7e24c12009-10-30 11:49:00 +0000998 // Allocation support helpers.
999 void LoadAllocationTopHelper(Register result,
Steve Blocka7e24c12009-10-30 11:49:00 +00001000 Register scratch,
1001 AllocationFlags flags);
Leon Clarkee46be812010-01-19 14:06:41 +00001002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 void UpdateAllocationTopHelper(Register result_end,
1004 Register scratch,
1005 AllocationFlags flags);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001006
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001007 // 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 Murdoche0cee9b2011-05-25 10:26:03 +01001025
1026 // Compute memory operands for safepoint stack slots.
1027 Operand SafepointRegisterSlot(Register reg);
1028 static int SafepointRegisterStackIndex(int reg_code);
1029
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001030 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001031 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001032 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001033};
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.
1041class 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 Murdoch3ef787d2012-04-12 10:51:47 +01001060inline Operand FieldOperand(Register object, int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001061 return Operand(object, offset - kHeapObjectTag);
1062}
1063
1064
1065// Generate an Operand for loading an indexed field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001066inline Operand FieldOperand(Register object,
1067 Register index,
1068 ScaleFactor scale,
1069 int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001070 return Operand(object, index, scale, offset - kHeapObjectTag);
1071}
1072
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001073
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074inline 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 Murdoch3ef787d2012-04-12 10:51:47 +01001082inline Operand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001083 return Operand(context, Context::SlotOffset(index));
1084}
1085
1086
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001087inline Operand GlobalObjectOperand() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001088 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001089}
1090
1091
John Reck59135872010-11-02 12:39:01 -07001092// Generates an Operand for saving parameters after PrepareCallApiFunction.
1093Operand ApiParameterOperand(int index);
1094
Steve Blocka7e24c12009-10-30 11:49:00 +00001095
1096#ifdef GENERATED_CODE_COVERAGE
1097extern 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_