1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_PPC_MACRO_ASSEMBLER_PPC_H_
6 #define V8_PPC_MACRO_ASSEMBLER_PPC_H_
7
8 #include "src/assembler.h"
9 #include "src/bailout-reason.h"
10 #include "src/frames.h"
11 #include "src/globals.h"
12
13 namespace v8 {
14 namespace internal {
15
16 // Give alias names to registers for calling conventions.
17 const Register kReturnRegister0 = {Register::kCode_r3};
18 const Register kReturnRegister1 = {Register::kCode_r4};
19 const Register kJSFunctionRegister = {Register::kCode_r4};
20 const Register kContextRegister = {Register::kCode_r30};
21 const Register kInterpreterAccumulatorRegister = {Register::kCode_r3};
22 const Register kInterpreterRegisterFileRegister = {Register::kCode_r14};
23 const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r15};
24 const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r16};
25 const Register kInterpreterDispatchTableRegister = {Register::kCode_r17};
26 const Register kJavaScriptCallArgCountRegister = {Register::kCode_r3};
27 const Register kJavaScriptCallNewTargetRegister = {Register::kCode_r6};
28 const Register kRuntimeCallFunctionRegister = {Register::kCode_r4};
29 const Register kRuntimeCallArgCountRegister = {Register::kCode_r3};
30
31 // ----------------------------------------------------------------------------
32 // Static helper functions
33
34 // Generate a MemOperand for loading a field from an object.
FieldMemOperand(Register object,int offset)35 inline MemOperand FieldMemOperand(Register object, int offset) {
36 return MemOperand(object, offset - kHeapObjectTag);
37 }
38
39
40 // Flags used for AllocateHeapNumber
41 enum TaggingMode {
42 // Tag the result.
43 TAG_RESULT,
44 // Don't tag
45 DONT_TAG_RESULT
46 };
47
48
49 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
50 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
51 enum PointersToHereCheck {
52 kPointersToHereMaybeInteresting,
53 kPointersToHereAreAlwaysInteresting
54 };
55 enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
56
57
58 Register GetRegisterThatIsNotOneOf(Register reg1, Register reg2 = no_reg,
59 Register reg3 = no_reg,
60 Register reg4 = no_reg,
61 Register reg5 = no_reg,
62 Register reg6 = no_reg);
63
64
65 #ifdef DEBUG
66 bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
67 Register reg4 = no_reg, Register reg5 = no_reg,
68 Register reg6 = no_reg, Register reg7 = no_reg,
69 Register reg8 = no_reg, Register reg9 = no_reg,
70 Register reg10 = no_reg);
71 #endif
72
73 // These exist to provide portability between 32 and 64bit
74 #if V8_TARGET_ARCH_PPC64
75 #define LoadPU ldu
76 #define LoadPX ldx
77 #define LoadPUX ldux
78 #define StorePU stdu
79 #define StorePX stdx
80 #define StorePUX stdux
81 #define ShiftLeftImm sldi
82 #define ShiftRightImm srdi
83 #define ClearLeftImm clrldi
84 #define ClearRightImm clrrdi
85 #define ShiftRightArithImm sradi
86 #define ShiftLeft_ sld
87 #define ShiftRight_ srd
88 #define ShiftRightArith srad
89 #define Mul mulld
90 #define Div divd
91 #else
92 #define LoadPU lwzu
93 #define LoadPX lwzx
94 #define LoadPUX lwzux
95 #define StorePU stwu
96 #define StorePX stwx
97 #define StorePUX stwux
98 #define ShiftLeftImm slwi
99 #define ShiftRightImm srwi
100 #define ClearLeftImm clrlwi
101 #define ClearRightImm clrrwi
102 #define ShiftRightArithImm srawi
103 #define ShiftLeft_ slw
104 #define ShiftRight_ srw
105 #define ShiftRightArith sraw
106 #define Mul mullw
107 #define Div divw
108 #endif
109
110
111 // MacroAssembler implements a collection of frequently used macros.
112 class MacroAssembler : public Assembler {
113 public:
114 MacroAssembler(Isolate* isolate, void* buffer, int size,
115 CodeObjectRequired create_code_object);
116
117
118 // Returns the size of a call in instructions. Note, the value returned is
119 // only valid as long as no entries are added to the constant pool between
120 // checking the call size and emitting the actual call.
121 static int CallSize(Register target);
122 int CallSize(Address target, RelocInfo::Mode rmode, Condition cond = al);
123 static int CallSizeNotPredictableCodeSize(Address target,
124 RelocInfo::Mode rmode,
125 Condition cond = al);
126
127 // Jump, Call, and Ret pseudo instructions implementing inter-working.
128 void Jump(Register target);
129 void JumpToJSEntry(Register target);
130 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al,
131 CRegister cr = cr7);
132 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
133 void Call(Register target);
134 void CallJSEntry(Register target);
135 void Call(Address target, RelocInfo::Mode rmode, Condition cond = al);
136 int CallSize(Handle<Code> code,
137 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
138 TypeFeedbackId ast_id = TypeFeedbackId::None(),
139 Condition cond = al);
140 void Call(Handle<Code> code, RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
141 TypeFeedbackId ast_id = TypeFeedbackId::None(),
142 Condition cond = al);
Ret()143 void Ret() { blr(); }
144 void Ret(Condition cond, CRegister cr = cr7) { bclr(cond, cr); }
145
146 // Emit code to discard a non-negative number of pointer-sized elements
147 // from the stack, clobbering only the sp register.
148 void Drop(int count);
149
Ret(int drop)150 void Ret(int drop) {
151 Drop(drop);
152 blr();
153 }
154
155 void Call(Label* target);
156
157 // Emit call to the code we are currently generating.
CallSelf()158 void CallSelf() {
159 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
160 Call(self, RelocInfo::CODE_TARGET);
161 }
162
163 // Register move. May do nothing if the registers are identical.
164 void Move(Register dst, Handle<Object> value);
165 void Move(Register dst, Register src, Condition cond = al);
166 void Move(DoubleRegister dst, DoubleRegister src);
167
168 void MultiPush(RegList regs, Register location = sp);
169 void MultiPop(RegList regs, Register location = sp);
170
171 void MultiPushDoubles(RegList dregs, Register location = sp);
172 void MultiPopDoubles(RegList dregs, Register location = sp);
173
174 // Load an object from the root table.
175 void LoadRoot(Register destination, Heap::RootListIndex index,
176 Condition cond = al);
177 // Store an object to the root table.
178 void StoreRoot(Register source, Heap::RootListIndex index,
179 Condition cond = al);
180
181 // ---------------------------------------------------------------------------
182 // GC Support
183
184 void IncrementalMarkingRecordWriteHelper(Register object, Register value,
185 Register address);
186
187 enum RememberedSetFinalAction { kReturnAtEnd, kFallThroughAtEnd };
188
189 // Record in the remembered set the fact that we have a pointer to new space
190 // at the address pointed to by the addr register. Only works if addr is not
191 // in new space.
192 void RememberedSetHelper(Register object, // Used for debug code.
193 Register addr, Register scratch,
194 SaveFPRegsMode save_fp,
195 RememberedSetFinalAction and_then);
196
197 void CheckPageFlag(Register object, Register scratch, int mask, Condition cc,
198 Label* condition_met);
199
200 // Check if object is in new space. Jumps if the object is not in new space.
201 // The register scratch can be object itself, but scratch will be clobbered.
JumpIfNotInNewSpace(Register object,Register scratch,Label * branch)202 void JumpIfNotInNewSpace(Register object, Register scratch, Label* branch) {
203 InNewSpace(object, scratch, ne, branch);
204 }
205
206 // Check if object is in new space. Jumps if the object is in new space.
207 // The register scratch can be object itself, but it will be clobbered.
JumpIfInNewSpace(Register object,Register scratch,Label * branch)208 void JumpIfInNewSpace(Register object, Register scratch, Label* branch) {
209 InNewSpace(object, scratch, eq, branch);
210 }
211
212 // Check if an object has a given incremental marking color.
213 void HasColor(Register object, Register scratch0, Register scratch1,
214 Label* has_color, int first_bit, int second_bit);
215
216 void JumpIfBlack(Register object, Register scratch0, Register scratch1,
217 Label* on_black);
218
219 // Checks the color of an object. If the object is white we jump to the
220 // incremental marker.
221 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
222 Register scratch3, Label* value_is_white);
223
224 // Notify the garbage collector that we wrote a pointer into an object.
225 // |object| is the object being stored into, |value| is the object being
226 // stored. value and scratch registers are clobbered by the operation.
227 // The offset is the offset from the start of the object, not the offset from
228 // the tagged HeapObject pointer. For use with FieldMemOperand(reg, off).
229 void RecordWriteField(
230 Register object, int offset, Register value, Register scratch,
231 LinkRegisterStatus lr_status, SaveFPRegsMode save_fp,
232 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
233 SmiCheck smi_check = INLINE_SMI_CHECK,
234 PointersToHereCheck pointers_to_here_check_for_value =
235 kPointersToHereMaybeInteresting);
236
237 // As above, but the offset has the tag presubtracted. For use with
238 // MemOperand(reg, off).
239 inline void RecordWriteContextSlot(
240 Register context, int offset, Register value, Register scratch,
241 LinkRegisterStatus lr_status, SaveFPRegsMode save_fp,
242 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
243 SmiCheck smi_check = INLINE_SMI_CHECK,
244 PointersToHereCheck pointers_to_here_check_for_value =
245 kPointersToHereMaybeInteresting) {
246 RecordWriteField(context, offset + kHeapObjectTag, value, scratch,
247 lr_status, save_fp, remembered_set_action, smi_check,
248 pointers_to_here_check_for_value);
249 }
250
251 void RecordWriteForMap(Register object, Register map, Register dst,
252 LinkRegisterStatus lr_status, SaveFPRegsMode save_fp);
253
254 // For a given |object| notify the garbage collector that the slot |address|
255 // has been written. |value| is the object being stored. The value and
256 // address registers are clobbered by the operation.
257 void RecordWrite(
258 Register object, Register address, Register value,
259 LinkRegisterStatus lr_status, SaveFPRegsMode save_fp,
260 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
261 SmiCheck smi_check = INLINE_SMI_CHECK,
262 PointersToHereCheck pointers_to_here_check_for_value =
263 kPointersToHereMaybeInteresting);
264
Push(Register src)265 void Push(Register src) { push(src); }
266
267 // Push a handle.
268 void Push(Handle<Object> handle);
Push(Smi * smi)269 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
270
271 // Push two registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2)272 void Push(Register src1, Register src2) {
273 StorePU(src2, MemOperand(sp, -2 * kPointerSize));
274 StoreP(src1, MemOperand(sp, kPointerSize));
275 }
276
277 // Push three registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3)278 void Push(Register src1, Register src2, Register src3) {
279 StorePU(src3, MemOperand(sp, -3 * kPointerSize));
280 StoreP(src2, MemOperand(sp, kPointerSize));
281 StoreP(src1, MemOperand(sp, 2 * kPointerSize));
282 }
283
284 // Push four registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3,Register src4)285 void Push(Register src1, Register src2, Register src3, Register src4) {
286 StorePU(src4, MemOperand(sp, -4 * kPointerSize));
287 StoreP(src3, MemOperand(sp, kPointerSize));
288 StoreP(src2, MemOperand(sp, 2 * kPointerSize));
289 StoreP(src1, MemOperand(sp, 3 * kPointerSize));
290 }
291
292 // Push five registers. Pushes leftmost register first (to highest address).
Push(Register src1,Register src2,Register src3,Register src4,Register src5)293 void Push(Register src1, Register src2, Register src3, Register src4,
294 Register src5) {
295 StorePU(src5, MemOperand(sp, -5 * kPointerSize));
296 StoreP(src4, MemOperand(sp, kPointerSize));
297 StoreP(src3, MemOperand(sp, 2 * kPointerSize));
298 StoreP(src2, MemOperand(sp, 3 * kPointerSize));
299 StoreP(src1, MemOperand(sp, 4 * kPointerSize));
300 }
301
Pop(Register dst)302 void Pop(Register dst) { pop(dst); }
303
304 // Pop two registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2)305 void Pop(Register src1, Register src2) {
306 LoadP(src2, MemOperand(sp, 0));
307 LoadP(src1, MemOperand(sp, kPointerSize));
308 addi(sp, sp, Operand(2 * kPointerSize));
309 }
310
311 // Pop three registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2,Register src3)312 void Pop(Register src1, Register src2, Register src3) {
313 LoadP(src3, MemOperand(sp, 0));
314 LoadP(src2, MemOperand(sp, kPointerSize));
315 LoadP(src1, MemOperand(sp, 2 * kPointerSize));
316 addi(sp, sp, Operand(3 * kPointerSize));
317 }
318
319 // Pop four registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2,Register src3,Register src4)320 void Pop(Register src1, Register src2, Register src3, Register src4) {
321 LoadP(src4, MemOperand(sp, 0));
322 LoadP(src3, MemOperand(sp, kPointerSize));
323 LoadP(src2, MemOperand(sp, 2 * kPointerSize));
324 LoadP(src1, MemOperand(sp, 3 * kPointerSize));
325 addi(sp, sp, Operand(4 * kPointerSize));
326 }
327
328 // Pop five registers. Pops rightmost register first (from lower address).
Pop(Register src1,Register src2,Register src3,Register src4,Register src5)329 void Pop(Register src1, Register src2, Register src3, Register src4,
330 Register src5) {
331 LoadP(src5, MemOperand(sp, 0));
332 LoadP(src4, MemOperand(sp, kPointerSize));
333 LoadP(src3, MemOperand(sp, 2 * kPointerSize));
334 LoadP(src2, MemOperand(sp, 3 * kPointerSize));
335 LoadP(src1, MemOperand(sp, 4 * kPointerSize));
336 addi(sp, sp, Operand(5 * kPointerSize));
337 }
338
339 // Push a fixed frame, consisting of lr, fp, context and
340 // JS function / marker id if marker_reg is a valid register.
341 void PushFixedFrame(Register marker_reg = no_reg);
342 void PopFixedFrame(Register marker_reg = no_reg);
343
344 // Push and pop the registers that can hold pointers, as defined by the
345 // RegList constant kSafepointSavedRegisters.
346 void PushSafepointRegisters();
347 void PopSafepointRegisters();
348 // Store value in register src in the safepoint stack slot for
349 // register dst.
350 void StoreToSafepointRegisterSlot(Register src, Register dst);
351 // Load the value of the src register from its safepoint stack slot
352 // into register dst.
353 void LoadFromSafepointRegisterSlot(Register dst, Register src);
354
355 // Flush the I-cache from asm code. You should use CpuFeatures::FlushICache
356 // from C.
357 // Does not handle errors.
358 void FlushICache(Register address, size_t size, Register scratch);
359
360 // If the value is a NaN, canonicalize the value else, do nothing.
361 void CanonicalizeNaN(const DoubleRegister dst, const DoubleRegister src);
CanonicalizeNaN(const DoubleRegister value)362 void CanonicalizeNaN(const DoubleRegister value) {
363 CanonicalizeNaN(value, value);
364 }
365
366 // Converts the integer (untagged smi) in |src| to a double, storing
367 // the result to |double_dst|
368 void ConvertIntToDouble(Register src, DoubleRegister double_dst);
369
370 // Converts the unsigned integer (untagged smi) in |src| to
371 // a double, storing the result to |double_dst|
372 void ConvertUnsignedIntToDouble(Register src, DoubleRegister double_dst);
373
374 // Converts the integer (untagged smi) in |src| to
375 // a float, storing the result in |dst|
376 // Warning: The value in |int_scrach| will be changed in the process!
377 void ConvertIntToFloat(const DoubleRegister dst, const Register src,
378 const Register int_scratch);
379
380 #if V8_TARGET_ARCH_PPC64
381 void ConvertInt64ToFloat(Register src, DoubleRegister double_dst);
382 void ConvertInt64ToDouble(Register src, DoubleRegister double_dst);
383 void ConvertUnsignedInt64ToFloat(Register src, DoubleRegister double_dst);
384 void ConvertUnsignedInt64ToDouble(Register src, DoubleRegister double_dst);
385 #endif
386
387 // Converts the double_input to an integer. Note that, upon return,
388 // the contents of double_dst will also hold the fixed point representation.
389 void ConvertDoubleToInt64(const DoubleRegister double_input,
390 #if !V8_TARGET_ARCH_PPC64
391 const Register dst_hi,
392 #endif
393 const Register dst, const DoubleRegister double_dst,
394 FPRoundingMode rounding_mode = kRoundToZero);
395
396 #if V8_TARGET_ARCH_PPC64
397 // Converts the double_input to an unsigned integer. Note that, upon return,
398 // the contents of double_dst will also hold the fixed point representation.
399 void ConvertDoubleToUnsignedInt64(
400 const DoubleRegister double_input, const Register dst,
401 const DoubleRegister double_dst,
402 FPRoundingMode rounding_mode = kRoundToZero);
403 #endif
404
405 // Generates function and stub prologue code.
406 void StubPrologue(Register base = no_reg, int prologue_offset = 0);
407 void Prologue(bool code_pre_aging, Register base, int prologue_offset = 0);
408
409 // Enter exit frame.
410 // stack_space - extra stack space, used for parameters before call to C.
411 // At least one slot (for the return address) should be provided.
412 void EnterExitFrame(bool save_doubles, int stack_space = 1);
413
414 // Leave the current exit frame. Expects the return value in r0.
415 // Expect the number of values, pushed prior to the exit frame, to
416 // remove in a register (or no_reg, if there is nothing to remove).
417 void LeaveExitFrame(bool save_doubles, Register argument_count,
418 bool restore_context,
419 bool argument_count_is_length = false);
420
421 // Get the actual activation frame alignment for target environment.
422 static int ActivationFrameAlignment();
423
424 void LoadContext(Register dst, int context_chain_length);
425
426 // Load the global object from the current context.
LoadGlobalObject(Register dst)427 void LoadGlobalObject(Register dst) {
428 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
429 }
430
431 // Load the global proxy from the current context.
LoadGlobalProxy(Register dst)432 void LoadGlobalProxy(Register dst) {
433 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
434 }
435
436 // Conditionally load the cached Array transitioned map of type
437 // transitioned_kind from the native context if the map in register
438 // map_in_out is the cached Array map in the native context of
439 // expected_kind.
440 void LoadTransitionedArrayMapConditional(ElementsKind expected_kind,
441 ElementsKind transitioned_kind,
442 Register map_in_out,
443 Register scratch,
444 Label* no_map_match);
445
446 void LoadNativeContextSlot(int index, Register dst);
447
448 // Load the initial map from the global function. The registers
449 // function and map can be the same, function is then overwritten.
450 void LoadGlobalFunctionInitialMap(Register function, Register map,
451 Register scratch);
452
InitializeRootRegister()453 void InitializeRootRegister() {
454 ExternalReference roots_array_start =
455 ExternalReference::roots_array_start(isolate());
456 mov(kRootRegister, Operand(roots_array_start));
457 }
458
459 // ----------------------------------------------------------------
460 // new PPC macro-assembler interfaces that are slightly higher level
461 // than assembler-ppc and may generate variable length sequences
462
463 // load a literal signed int value <value> to GPR <dst>
464 void LoadIntLiteral(Register dst, int value);
465
466 // load an SMI value <value> to GPR <dst>
467 void LoadSmiLiteral(Register dst, Smi* smi);
468
469 // load a literal double value <value> to FPR <result>
470 void LoadDoubleLiteral(DoubleRegister result, double value, Register scratch);
471
472 void LoadWord(Register dst, const MemOperand& mem, Register scratch);
473 void LoadWordArith(Register dst, const MemOperand& mem,
474 Register scratch = no_reg);
475 void StoreWord(Register src, const MemOperand& mem, Register scratch);
476
477 void LoadHalfWord(Register dst, const MemOperand& mem, Register scratch);
478 void LoadHalfWordArith(Register dst, const MemOperand& mem,
479 Register scratch = no_reg);
480 void StoreHalfWord(Register src, const MemOperand& mem, Register scratch);
481
482 void LoadByte(Register dst, const MemOperand& mem, Register scratch);
483 void StoreByte(Register src, const MemOperand& mem, Register scratch);
484
485 void LoadRepresentation(Register dst, const MemOperand& mem, Representation r,
486 Register scratch = no_reg);
487 void StoreRepresentation(Register src, const MemOperand& mem,
488 Representation r, Register scratch = no_reg);
489
490 void LoadDouble(DoubleRegister dst, const MemOperand& mem, Register scratch);
491 void StoreDouble(DoubleRegister src, const MemOperand& mem, Register scratch);
492
493 // Move values between integer and floating point registers.
494 void MovIntToDouble(DoubleRegister dst, Register src, Register scratch);
495 void MovUnsignedIntToDouble(DoubleRegister dst, Register src,
496 Register scratch);
497 void MovInt64ToDouble(DoubleRegister dst,
498 #if !V8_TARGET_ARCH_PPC64
499 Register src_hi,
500 #endif
501 Register src);
502 #if V8_TARGET_ARCH_PPC64
503 void MovInt64ComponentsToDouble(DoubleRegister dst, Register src_hi,
504 Register src_lo, Register scratch);
505 #endif
506 void InsertDoubleLow(DoubleRegister dst, Register src, Register scratch);
507 void InsertDoubleHigh(DoubleRegister dst, Register src, Register scratch);
508 void MovDoubleLowToInt(Register dst, DoubleRegister src);
509 void MovDoubleHighToInt(Register dst, DoubleRegister src);
510 void MovDoubleToInt64(
511 #if !V8_TARGET_ARCH_PPC64
512 Register dst_hi,
513 #endif
514 Register dst, DoubleRegister src);
515 void MovIntToFloat(DoubleRegister dst, Register src);
516 void MovFloatToInt(Register dst, DoubleRegister src);
517
518 void Add(Register dst, Register src, intptr_t value, Register scratch);
519 void Cmpi(Register src1, const Operand& src2, Register scratch,
520 CRegister cr = cr7);
521 void Cmpli(Register src1, const Operand& src2, Register scratch,
522 CRegister cr = cr7);
523 void Cmpwi(Register src1, const Operand& src2, Register scratch,
524 CRegister cr = cr7);
525 void Cmplwi(Register src1, const Operand& src2, Register scratch,
526 CRegister cr = cr7);
527 void And(Register ra, Register rs, const Operand& rb, RCBit rc = LeaveRC);
528 void Or(Register ra, Register rs, const Operand& rb, RCBit rc = LeaveRC);
529 void Xor(Register ra, Register rs, const Operand& rb, RCBit rc = LeaveRC);
530
531 void AddSmiLiteral(Register dst, Register src, Smi* smi, Register scratch);
532 void SubSmiLiteral(Register dst, Register src, Smi* smi, Register scratch);
533 void CmpSmiLiteral(Register src1, Smi* smi, Register scratch,
534 CRegister cr = cr7);
535 void CmplSmiLiteral(Register src1, Smi* smi, Register scratch,
536 CRegister cr = cr7);
537 void AndSmiLiteral(Register dst, Register src, Smi* smi, Register scratch,
538 RCBit rc = LeaveRC);
539
540 // Set new rounding mode RN to FPSCR
541 void SetRoundingMode(FPRoundingMode RN);
542
543 // reset rounding mode to default (kRoundToNearest)
544 void ResetRoundingMode();
545
546 // These exist to provide portability between 32 and 64bit
547 void LoadP(Register dst, const MemOperand& mem, Register scratch = no_reg);
548 void StoreP(Register src, const MemOperand& mem, Register scratch = no_reg);
549
550 // ---------------------------------------------------------------------------
551 // JavaScript invokes
552
553 // Invoke the JavaScript function code by either calling or jumping.
554 void InvokeFunctionCode(Register function, Register new_target,
555 const ParameterCount& expected,
556 const ParameterCount& actual, InvokeFlag flag,
557 const CallWrapper& call_wrapper);
558
559 void FloodFunctionIfStepping(Register fun, Register new_target,
560 const ParameterCount& expected,
561 const ParameterCount& actual);
562
563 // Invoke the JavaScript function in the given register. Changes the
564 // current context to the context in the function before invoking.
565 void InvokeFunction(Register function, Register new_target,
566 const ParameterCount& actual, InvokeFlag flag,
567 const CallWrapper& call_wrapper);
568
569 void InvokeFunction(Register function, const ParameterCount& expected,
570 const ParameterCount& actual, InvokeFlag flag,
571 const CallWrapper& call_wrapper);
572
573 void InvokeFunction(Handle<JSFunction> function,
574 const ParameterCount& expected,
575 const ParameterCount& actual, InvokeFlag flag,
576 const CallWrapper& call_wrapper);
577
578 void IsObjectJSStringType(Register object, Register scratch, Label* fail);
579
580 void IsObjectNameType(Register object, Register scratch, Label* fail);
581
582 // ---------------------------------------------------------------------------
583 // Debugger Support
584
585 void DebugBreak();
586
587 // ---------------------------------------------------------------------------
588 // Exception handling
589
590 // Push a new stack handler and link into stack handler chain.
591 void PushStackHandler();
592
593 // Unlink the stack handler on top of the stack from the stack handler chain.
594 // Must preserve the result register.
595 void PopStackHandler();
596
597 // ---------------------------------------------------------------------------
598 // Inline caching support
599
600 // Generate code for checking access rights - used for security checks
601 // on access to global objects across environments. The holder register
602 // is left untouched, whereas both scratch registers are clobbered.
603 void CheckAccessGlobalProxy(Register holder_reg, Register scratch,
604 Label* miss);
605
606 void GetNumberHash(Register t0, Register scratch);
607
608 void LoadFromNumberDictionary(Label* miss, Register elements, Register key,
609 Register result, Register t0, Register t1,
610 Register t2);
611
612
MarkCode(NopMarkerTypes type)613 inline void MarkCode(NopMarkerTypes type) { nop(type); }
614
615 // Check if the given instruction is a 'type' marker.
616 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
617 // These instructions are generated to mark special location in the code,
618 // like some special IC code.
IsMarkedCode(Instr instr,int type)619 static inline bool IsMarkedCode(Instr instr, int type) {
620 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
621 return IsNop(instr, type);
622 }
623
624
GetCodeMarker(Instr instr)625 static inline int GetCodeMarker(Instr instr) {
626 int dst_reg_offset = 12;
627 int dst_mask = 0xf << dst_reg_offset;
628 int src_mask = 0xf;
629 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
630 int src_reg = instr & src_mask;
631 uint32_t non_register_mask = ~(dst_mask | src_mask);
632 uint32_t mov_mask = al | 13 << 21;
633
634 // Return <n> if we have a mov rn rn, else return -1.
635 int type = ((instr & non_register_mask) == mov_mask) &&
636 (dst_reg == src_reg) && (FIRST_IC_MARKER <= dst_reg) &&
637 (dst_reg < LAST_CODE_MARKER)
638 ? src_reg
639 : -1;
640 DCHECK((type == -1) ||
641 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
642 return type;
643 }
644
645
646 // ---------------------------------------------------------------------------
647 // Allocation support
648
649 // Allocate an object in new space or old space. The object_size is
650 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
651 // is passed. If the space is exhausted control continues at the gc_required
652 // label. The allocated object is returned in result. If the flag
653 // tag_allocated_object is true the result is tagged as as a heap object.
654 // All registers are clobbered also when control continues at the gc_required
655 // label.
656 void Allocate(int object_size, Register result, Register scratch1,
657 Register scratch2, Label* gc_required, AllocationFlags flags);
658
659 void Allocate(Register object_size, Register result, Register result_end,
660 Register scratch, Label* gc_required, AllocationFlags flags);
661
662 void AllocateTwoByteString(Register result, Register length,
663 Register scratch1, Register scratch2,
664 Register scratch3, Label* gc_required);
665 void AllocateOneByteString(Register result, Register length,
666 Register scratch1, Register scratch2,
667 Register scratch3, Label* gc_required);
668 void AllocateTwoByteConsString(Register result, Register length,
669 Register scratch1, Register scratch2,
670 Label* gc_required);
671 void AllocateOneByteConsString(Register result, Register length,
672 Register scratch1, Register scratch2,
673 Label* gc_required);
674 void AllocateTwoByteSlicedString(Register result, Register length,
675 Register scratch1, Register scratch2,
676 Label* gc_required);
677 void AllocateOneByteSlicedString(Register result, Register length,
678 Register scratch1, Register scratch2,
679 Label* gc_required);
680
681 // Allocates a heap number or jumps to the gc_required label if the young
682 // space is full and a scavenge is needed. All registers are clobbered also
683 // when control continues at the gc_required label.
684 void AllocateHeapNumber(Register result, Register scratch1, Register scratch2,
685 Register heap_number_map, Label* gc_required,
686 TaggingMode tagging_mode = TAG_RESULT,
687 MutableMode mode = IMMUTABLE);
688 void AllocateHeapNumberWithValue(Register result, DoubleRegister value,
689 Register scratch1, Register scratch2,
690 Register heap_number_map,
691 Label* gc_required);
692
693 // Allocate and initialize a JSValue wrapper with the specified {constructor}
694 // and {value}.
695 void AllocateJSValue(Register result, Register constructor, Register value,
696 Register scratch1, Register scratch2,
697 Label* gc_required);
698
699 // Copies a number of bytes from src to dst. All registers are clobbered. On
700 // exit src and dst will point to the place just after where the last byte was
701 // read or written and length will be zero.
702 void CopyBytes(Register src, Register dst, Register length, Register scratch);
703
704 // Initialize fields with filler values. |count| fields starting at
705 // |current_address| are overwritten with the value in |filler|. At the end
706 // the loop, |current_address| points at the next uninitialized field.
707 // |count| is assumed to be non-zero.
708 void InitializeNFieldsWithFiller(Register current_address, Register count,
709 Register filler);
710
711 // Initialize fields with filler values. Fields starting at |current_address|
712 // not including |end_address| are overwritten with the value in |filler|. At
713 // the end the loop, |current_address| takes the value of |end_address|.
714 void InitializeFieldsWithFiller(Register current_address,
715 Register end_address, Register filler);
716
717 // ---------------------------------------------------------------------------
718 // Support functions.
719
720 // Machine code version of Map::GetConstructor().
721 // |temp| holds |result|'s map when done, and |temp2| its instance type.
722 void GetMapConstructor(Register result, Register map, Register temp,
723 Register temp2);
724
725 // Try to get function prototype of a function and puts the value in
726 // the result register. Checks that the function really is a
727 // function and jumps to the miss label if the fast checks fail. The
728 // function register will be untouched; the other registers may be
729 // clobbered.
730 void TryGetFunctionPrototype(Register function, Register result,
731 Register scratch, Label* miss);
732
733 // Compare object type for heap object. heap_object contains a non-Smi
734 // whose object type should be compared with the given type. This both
735 // sets the flags and leaves the object type in the type_reg register.
736 // It leaves the map in the map register (unless the type_reg and map register
737 // are the same register). It leaves the heap object in the heap_object
738 // register unless the heap_object register is the same register as one of the
739 // other registers.
740 // Type_reg can be no_reg. In that case ip is used.
741 void CompareObjectType(Register heap_object, Register map, Register type_reg,
742 InstanceType type);
743
744 // Compare instance type in a map. map contains a valid map object whose
745 // object type should be compared with the given type. This both
746 // sets the flags and leaves the object type in the type_reg register.
747 void CompareInstanceType(Register map, Register type_reg, InstanceType type);
748
749
750 // Check if a map for a JSObject indicates that the object has fast elements.
751 // Jump to the specified label if it does not.
752 void CheckFastElements(Register map, Register scratch, Label* fail);
753
754 // Check if a map for a JSObject indicates that the object can have both smi
755 // and HeapObject elements. Jump to the specified label if it does not.
756 void CheckFastObjectElements(Register map, Register scratch, Label* fail);
757
758 // Check if a map for a JSObject indicates that the object has fast smi only
759 // elements. Jump to the specified label if it does not.
760 void CheckFastSmiElements(Register map, Register scratch, Label* fail);
761
762 // Check to see if maybe_number can be stored as a double in
763 // FastDoubleElements. If it can, store it at the index specified by key in
764 // the FastDoubleElements array elements. Otherwise jump to fail.
765 void StoreNumberToDoubleElements(Register value_reg, Register key_reg,
766 Register elements_reg, Register scratch1,
767 DoubleRegister double_scratch, Label* fail,
768 int elements_offset = 0);
769
770 // Compare an object's map with the specified map and its transitioned
771 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
772 // set with result of map compare. If multiple map compares are required, the
773 // compare sequences branches to early_success.
774 void CompareMap(Register obj, Register scratch, Handle<Map> map,
775 Label* early_success);
776
777 // As above, but the map of the object is already loaded into the register
778 // which is preserved by the code generated.
779 void CompareMap(Register obj_map, Handle<Map> map, Label* early_success);
780
781 // Check if the map of an object is equal to a specified map and branch to
782 // label if not. Skip the smi check if not required (object is known to be a
783 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
784 // against maps that are ElementsKind transition maps of the specified map.
785 void CheckMap(Register obj, Register scratch, Handle<Map> map, Label* fail,
786 SmiCheckType smi_check_type);
787
788
789 void CheckMap(Register obj, Register scratch, Heap::RootListIndex index,
790 Label* fail, SmiCheckType smi_check_type);
791
792
793 // Check if the map of an object is equal to a specified weak map and branch
794 // to a specified target if equal. Skip the smi check if not required
795 // (object is known to be a heap object)
796 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
797 Handle<WeakCell> cell, Handle<Code> success,
798 SmiCheckType smi_check_type);
799
800 // Compare the given value and the value of weak cell.
801 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch,
802 CRegister cr = cr7);
803
804 void GetWeakValue(Register value, Handle<WeakCell> cell);
805
806 // Load the value of the weak cell in the value register. Branch to the given
807 // miss label if the weak cell was cleared.
808 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
809
810 // Compare the object in a register to a value from the root list.
811 // Uses the ip register as scratch.
812 void CompareRoot(Register obj, Heap::RootListIndex index);
PushRoot(Heap::RootListIndex index)813 void PushRoot(Heap::RootListIndex index) {
814 LoadRoot(r0, index);
815 Push(r0);
816 }
817
818 // Compare the object in a register to a value and jump if they are equal.
JumpIfRoot(Register with,Heap::RootListIndex index,Label * if_equal)819 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
820 CompareRoot(with, index);
821 beq(if_equal);
822 }
823
824 // Compare the object in a register to a value and jump if they are not equal.
JumpIfNotRoot(Register with,Heap::RootListIndex index,Label * if_not_equal)825 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
826 Label* if_not_equal) {
827 CompareRoot(with, index);
828 bne(if_not_equal);
829 }
830
831 // Load and check the instance type of an object for being a string.
832 // Loads the type into the second argument register.
833 // Returns a condition that will be enabled if the object was a string.
IsObjectStringType(Register obj,Register type)834 Condition IsObjectStringType(Register obj, Register type) {
835 LoadP(type, FieldMemOperand(obj, HeapObject::kMapOffset));
836 lbz(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
837 andi(r0, type, Operand(kIsNotStringMask));
838 DCHECK_EQ(0u, kStringTag);
839 return eq;
840 }
841
842
843 // Picks out an array index from the hash field.
844 // Register use:
845 // hash - holds the index's hash. Clobbered.
846 // index - holds the overwritten index on exit.
847 void IndexFromHash(Register hash, Register index);
848
849 // Get the number of least significant bits from a register
850 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
851 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
852
853 // Load the value of a smi object into a double register.
854 void SmiToDouble(DoubleRegister value, Register smi);
855
856 // Check if a double can be exactly represented as a signed 32-bit integer.
857 // CR_EQ in cr7 is set if true.
858 void TestDoubleIsInt32(DoubleRegister double_input, Register scratch1,
859 Register scratch2, DoubleRegister double_scratch);
860
861 // Try to convert a double to a signed 32-bit integer.
862 // CR_EQ in cr7 is set and result assigned if the conversion is exact.
863 void TryDoubleToInt32Exact(Register result, DoubleRegister double_input,
864 Register scratch, DoubleRegister double_scratch);
865
866 // Floor a double and writes the value to the result register.
867 // Go to exact if the conversion is exact (to be able to test -0),
868 // fall through calling code if an overflow occurred, else go to done.
869 // In return, input_high is loaded with high bits of input.
870 void TryInt32Floor(Register result, DoubleRegister double_input,
871 Register input_high, Register scratch,
872 DoubleRegister double_scratch, Label* done, Label* exact);
873
874 // Performs a truncating conversion of a floating point number as used by
875 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
876 // succeeds, otherwise falls through if result is saturated. On return
877 // 'result' either holds answer, or is clobbered on fall through.
878 //
879 // Only public for the test code in test-code-stubs-arm.cc.
880 void TryInlineTruncateDoubleToI(Register result, DoubleRegister input,
881 Label* done);
882
883 // Performs a truncating conversion of a floating point number as used by
884 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
885 // Exits with 'result' holding the answer.
886 void TruncateDoubleToI(Register result, DoubleRegister double_input);
887
888 // Performs a truncating conversion of a heap number as used by
889 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
890 // must be different registers. Exits with 'result' holding the answer.
891 void TruncateHeapNumberToI(Register result, Register object);
892
893 // Converts the smi or heap number in object to an int32 using the rules
894 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
895 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
896 // different registers.
897 void TruncateNumberToI(Register object, Register result,
898 Register heap_number_map, Register scratch1,
899 Label* not_int32);
900
901 // Overflow handling functions.
902 // Usage: call the appropriate arithmetic function and then call one of the
903 // flow control functions with the corresponding label.
904
905 // Compute dst = left + right, setting condition codes. dst may be same as
906 // either left or right (or a unique register). left and right must not be
907 // the same register.
908 void AddAndCheckForOverflow(Register dst, Register left, Register right,
909 Register overflow_dst, Register scratch = r0);
910 void AddAndCheckForOverflow(Register dst, Register left, intptr_t right,
911 Register overflow_dst, Register scratch = r0);
912
913 // Compute dst = left - right, setting condition codes. dst may be same as
914 // either left or right (or a unique register). left and right must not be
915 // the same register.
916 void SubAndCheckForOverflow(Register dst, Register left, Register right,
917 Register overflow_dst, Register scratch = r0);
918
BranchOnOverflow(Label * label)919 void BranchOnOverflow(Label* label) { blt(label, cr0); }
920
BranchOnNoOverflow(Label * label)921 void BranchOnNoOverflow(Label* label) { bge(label, cr0); }
922
RetOnOverflow(void)923 void RetOnOverflow(void) { Ret(lt, cr0); }
924
RetOnNoOverflow(void)925 void RetOnNoOverflow(void) { Ret(ge, cr0); }
926
927 // ---------------------------------------------------------------------------
928 // Runtime calls
929
930 // Call a code stub.
931 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None(),
932 Condition cond = al);
933
934 // Call a code stub.
935 void TailCallStub(CodeStub* stub, Condition cond = al);
936
937 // Call a runtime routine.
938 void CallRuntime(const Runtime::Function* f, int num_arguments,
939 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
CallRuntimeSaveDoubles(Runtime::FunctionId fid)940 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
941 const Runtime::Function* function = Runtime::FunctionForId(fid);
942 CallRuntime(function, function->nargs, kSaveFPRegs);
943 }
944
945 // Convenience function: Same as above, but takes the fid instead.
946 void CallRuntime(Runtime::FunctionId fid,
947 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
948 const Runtime::Function* function = Runtime::FunctionForId(fid);
949 CallRuntime(function, function->nargs, save_doubles);
950 }
951
952 // Convenience function: Same as above, but takes the fid instead.
953 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
954 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
955 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
956 }
957
958 // Convenience function: call an external reference.
959 void CallExternalReference(const ExternalReference& ext, int num_arguments);
960
961 // Convenience function: tail call a runtime routine (jump).
962 void TailCallRuntime(Runtime::FunctionId fid);
963
964 int CalculateStackPassedWords(int num_reg_arguments,
965 int num_double_arguments);
966
967 // Before calling a C-function from generated code, align arguments on stack.
968 // After aligning the frame, non-register arguments must be stored in
969 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
970 // are word sized. If double arguments are used, this function assumes that
971 // all double arguments are stored before core registers; otherwise the
972 // correct alignment of the double values is not guaranteed.
973 // Some compilers/platforms require the stack to be aligned when calling
974 // C++ code.
975 // Needs a scratch register to do some arithmetic. This register will be
976 // trashed.
977 void PrepareCallCFunction(int num_reg_arguments, int num_double_registers,
978 Register scratch);
979 void PrepareCallCFunction(int num_reg_arguments, Register scratch);
980
981 // There are two ways of passing double arguments on ARM, depending on
982 // whether soft or hard floating point ABI is used. These functions
983 // abstract parameter passing for the three different ways we call
984 // C functions from generated code.
985 void MovToFloatParameter(DoubleRegister src);
986 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
987 void MovToFloatResult(DoubleRegister src);
988
989 // Calls a C function and cleans up the space for arguments allocated
990 // by PrepareCallCFunction. The called function is not allowed to trigger a
991 // garbage collection, since that might move the code and invalidate the
992 // return address (unless this is somehow accounted for by the called
993 // function).
994 void CallCFunction(ExternalReference function, int num_arguments);
995 void CallCFunction(Register function, int num_arguments);
996 void CallCFunction(ExternalReference function, int num_reg_arguments,
997 int num_double_arguments);
998 void CallCFunction(Register function, int num_reg_arguments,
999 int num_double_arguments);
1000
1001 void MovFromFloatParameter(DoubleRegister dst);
1002 void MovFromFloatResult(DoubleRegister dst);
1003
1004 // Jump to a runtime routine.
1005 void JumpToExternalReference(const ExternalReference& builtin);
1006
1007 // Invoke specified builtin JavaScript function.
1008 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
1009 const CallWrapper& call_wrapper = NullCallWrapper());
1010
CodeObject()1011 Handle<Object> CodeObject() {
1012 DCHECK(!code_object_.is_null());
1013 return code_object_;
1014 }
1015
1016
1017 // Emit code for a truncating division by a constant. The dividend register is
1018 // unchanged and ip gets clobbered. Dividend and result must be different.
1019 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1020
1021 // ---------------------------------------------------------------------------
1022 // StatsCounter support
1023
1024 void SetCounter(StatsCounter* counter, int value, Register scratch1,
1025 Register scratch2);
1026 void IncrementCounter(StatsCounter* counter, int value, Register scratch1,
1027 Register scratch2);
1028 void DecrementCounter(StatsCounter* counter, int value, Register scratch1,
1029 Register scratch2);
1030
1031
1032 // ---------------------------------------------------------------------------
1033 // Debugging
1034
1035 // Calls Abort(msg) if the condition cond is not satisfied.
1036 // Use --debug_code to enable.
1037 void Assert(Condition cond, BailoutReason reason, CRegister cr = cr7);
1038 void AssertFastElements(Register elements);
1039
1040 // Like Assert(), but always enabled.
1041 void Check(Condition cond, BailoutReason reason, CRegister cr = cr7);
1042
1043 // Print a message to stdout and abort execution.
1044 void Abort(BailoutReason reason);
1045
1046 // Verify restrictions about code generated in stubs.
set_generating_stub(bool value)1047 void set_generating_stub(bool value) { generating_stub_ = value; }
generating_stub()1048 bool generating_stub() { return generating_stub_; }
set_has_frame(bool value)1049 void set_has_frame(bool value) { has_frame_ = value; }
has_frame()1050 bool has_frame() { return has_frame_; }
1051 inline bool AllowThisStubCall(CodeStub* stub);
1052
1053 // ---------------------------------------------------------------------------
1054 // Number utilities
1055
1056 // Check whether the value of reg is a power of two and not zero. If not
1057 // control continues at the label not_power_of_two. If reg is a power of two
1058 // the register scratch contains the value of (reg - 1) when control falls
1059 // through.
1060 void JumpIfNotPowerOfTwoOrZero(Register reg, Register scratch,
1061 Label* not_power_of_two_or_zero);
1062 // Check whether the value of reg is a power of two and not zero.
1063 // Control falls through if it is, with scratch containing the mask
1064 // value (reg - 1).
1065 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1066 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1067 // strictly positive but not a power of two.
1068 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg, Register scratch,
1069 Label* zero_and_neg,
1070 Label* not_power_of_two);
1071
1072 // ---------------------------------------------------------------------------
1073 // Bit testing/extraction
1074 //
1075 // Bit numbering is such that the least significant bit is bit 0
1076 // (for consistency between 32/64-bit).
1077
1078 // Extract consecutive bits (defined by rangeStart - rangeEnd) from src
1079 // and place them into the least significant bits of dst.
1080 inline void ExtractBitRange(Register dst, Register src, int rangeStart,
1081 int rangeEnd, RCBit rc = LeaveRC) {
1082 DCHECK(rangeStart >= rangeEnd && rangeStart < kBitsPerPointer);
1083 int rotate = (rangeEnd == 0) ? 0 : kBitsPerPointer - rangeEnd;
1084 int width = rangeStart - rangeEnd + 1;
1085 if (rc == SetRC && rangeEnd == 0 && width <= 16) {
1086 andi(dst, src, Operand((1 << width) - 1));
1087 } else {
1088 #if V8_TARGET_ARCH_PPC64
1089 rldicl(dst, src, rotate, kBitsPerPointer - width, rc);
1090 #else
1091 rlwinm(dst, src, rotate, kBitsPerPointer - width, kBitsPerPointer - 1,
1092 rc);
1093 #endif
1094 }
1095 }
1096
1097 inline void ExtractBit(Register dst, Register src, uint32_t bitNumber,
1098 RCBit rc = LeaveRC) {
1099 ExtractBitRange(dst, src, bitNumber, bitNumber, rc);
1100 }
1101
1102 // Extract consecutive bits (defined by mask) from src and place them
1103 // into the least significant bits of dst.
1104 inline void ExtractBitMask(Register dst, Register src, uintptr_t mask,
1105 RCBit rc = LeaveRC) {
1106 int start = kBitsPerPointer - 1;
1107 int end;
1108 uintptr_t bit = (1L << start);
1109
1110 while (bit && (mask & bit) == 0) {
1111 start--;
1112 bit >>= 1;
1113 }
1114 end = start;
1115 bit >>= 1;
1116
1117 while (bit && (mask & bit)) {
1118 end--;
1119 bit >>= 1;
1120 }
1121
1122 // 1-bits in mask must be contiguous
1123 DCHECK(bit == 0 || (mask & ((bit << 1) - 1)) == 0);
1124
1125 ExtractBitRange(dst, src, start, end, rc);
1126 }
1127
1128 // Test single bit in value.
1129 inline void TestBit(Register value, int bitNumber, Register scratch = r0) {
1130 ExtractBitRange(scratch, value, bitNumber, bitNumber, SetRC);
1131 }
1132
1133 // Test consecutive bit range in value. Range is defined by
1134 // rangeStart - rangeEnd.
1135 inline void TestBitRange(Register value, int rangeStart, int rangeEnd,
1136 Register scratch = r0) {
1137 ExtractBitRange(scratch, value, rangeStart, rangeEnd, SetRC);
1138 }
1139
1140 // Test consecutive bit range in value. Range is defined by mask.
1141 inline void TestBitMask(Register value, uintptr_t mask,
1142 Register scratch = r0) {
1143 ExtractBitMask(scratch, value, mask, SetRC);
1144 }
1145
1146
1147 // ---------------------------------------------------------------------------
1148 // Smi utilities
1149
1150 // Shift left by kSmiShift
1151 void SmiTag(Register reg, RCBit rc = LeaveRC) { SmiTag(reg, reg, rc); }
1152 void SmiTag(Register dst, Register src, RCBit rc = LeaveRC) {
1153 ShiftLeftImm(dst, src, Operand(kSmiShift), rc);
1154 }
1155
1156 #if !V8_TARGET_ARCH_PPC64
1157 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1158 void SmiTagCheckOverflow(Register reg, Register overflow);
1159 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1160
JumpIfNotSmiCandidate(Register value,Register scratch,Label * not_smi_label)1161 inline void JumpIfNotSmiCandidate(Register value, Register scratch,
1162 Label* not_smi_label) {
1163 // High bits must be identical to fit into an Smi
1164 STATIC_ASSERT(kSmiShift == 1);
1165 addis(scratch, value, Operand(0x40000000u >> 16));
1166 cmpi(scratch, Operand::Zero());
1167 blt(not_smi_label);
1168 }
1169 #endif
TestUnsignedSmiCandidate(Register value,Register scratch)1170 inline void TestUnsignedSmiCandidate(Register value, Register scratch) {
1171 // The test is different for unsigned int values. Since we need
1172 // the value to be in the range of a positive smi, we can't
1173 // handle any of the high bits being set in the value.
1174 TestBitRange(value, kBitsPerPointer - 1, kBitsPerPointer - 1 - kSmiShift,
1175 scratch);
1176 }
JumpIfNotUnsignedSmiCandidate(Register value,Register scratch,Label * not_smi_label)1177 inline void JumpIfNotUnsignedSmiCandidate(Register value, Register scratch,
1178 Label* not_smi_label) {
1179 TestUnsignedSmiCandidate(value, scratch);
1180 bne(not_smi_label, cr0);
1181 }
1182
1183 void SmiUntag(Register reg, RCBit rc = LeaveRC) { SmiUntag(reg, reg, rc); }
1184
1185 void SmiUntag(Register dst, Register src, RCBit rc = LeaveRC) {
1186 ShiftRightArithImm(dst, src, kSmiShift, rc);
1187 }
1188
SmiToPtrArrayOffset(Register dst,Register src)1189 void SmiToPtrArrayOffset(Register dst, Register src) {
1190 #if V8_TARGET_ARCH_PPC64
1191 STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kPointerSizeLog2);
1192 ShiftRightArithImm(dst, src, kSmiShift - kPointerSizeLog2);
1193 #else
1194 STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kPointerSizeLog2);
1195 ShiftLeftImm(dst, src, Operand(kPointerSizeLog2 - kSmiShift));
1196 #endif
1197 }
1198
SmiToByteArrayOffset(Register dst,Register src)1199 void SmiToByteArrayOffset(Register dst, Register src) { SmiUntag(dst, src); }
1200
SmiToShortArrayOffset(Register dst,Register src)1201 void SmiToShortArrayOffset(Register dst, Register src) {
1202 #if V8_TARGET_ARCH_PPC64
1203 STATIC_ASSERT(kSmiTag == 0 && kSmiShift > 1);
1204 ShiftRightArithImm(dst, src, kSmiShift - 1);
1205 #else
1206 STATIC_ASSERT(kSmiTag == 0 && kSmiShift == 1);
1207 if (!dst.is(src)) {
1208 mr(dst, src);
1209 }
1210 #endif
1211 }
1212
SmiToIntArrayOffset(Register dst,Register src)1213 void SmiToIntArrayOffset(Register dst, Register src) {
1214 #if V8_TARGET_ARCH_PPC64
1215 STATIC_ASSERT(kSmiTag == 0 && kSmiShift > 2);
1216 ShiftRightArithImm(dst, src, kSmiShift - 2);
1217 #else
1218 STATIC_ASSERT(kSmiTag == 0 && kSmiShift < 2);
1219 ShiftLeftImm(dst, src, Operand(2 - kSmiShift));
1220 #endif
1221 }
1222
1223 #define SmiToFloatArrayOffset SmiToIntArrayOffset
1224
SmiToDoubleArrayOffset(Register dst,Register src)1225 void SmiToDoubleArrayOffset(Register dst, Register src) {
1226 #if V8_TARGET_ARCH_PPC64
1227 STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kDoubleSizeLog2);
1228 ShiftRightArithImm(dst, src, kSmiShift - kDoubleSizeLog2);
1229 #else
1230 STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kDoubleSizeLog2);
1231 ShiftLeftImm(dst, src, Operand(kDoubleSizeLog2 - kSmiShift));
1232 #endif
1233 }
1234
SmiToArrayOffset(Register dst,Register src,int elementSizeLog2)1235 void SmiToArrayOffset(Register dst, Register src, int elementSizeLog2) {
1236 if (kSmiShift < elementSizeLog2) {
1237 ShiftLeftImm(dst, src, Operand(elementSizeLog2 - kSmiShift));
1238 } else if (kSmiShift > elementSizeLog2) {
1239 ShiftRightArithImm(dst, src, kSmiShift - elementSizeLog2);
1240 } else if (!dst.is(src)) {
1241 mr(dst, src);
1242 }
1243 }
1244
IndexToArrayOffset(Register dst,Register src,int elementSizeLog2,bool isSmi)1245 void IndexToArrayOffset(Register dst, Register src, int elementSizeLog2,
1246 bool isSmi) {
1247 if (isSmi) {
1248 SmiToArrayOffset(dst, src, elementSizeLog2);
1249 } else {
1250 ShiftLeftImm(dst, src, Operand(elementSizeLog2));
1251 }
1252 }
1253
1254 // Untag the source value into destination and jump if source is a smi.
1255 // Souce and destination can be the same register.
1256 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1257
1258 // Untag the source value into destination and jump if source is not a smi.
1259 // Souce and destination can be the same register.
1260 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1261
TestIfSmi(Register value,Register scratch)1262 inline void TestIfSmi(Register value, Register scratch) {
1263 TestBitRange(value, kSmiTagSize - 1, 0, scratch);
1264 }
1265
TestIfPositiveSmi(Register value,Register scratch)1266 inline void TestIfPositiveSmi(Register value, Register scratch) {
1267 #if V8_TARGET_ARCH_PPC64
1268 rldicl(scratch, value, 1, kBitsPerPointer - (1 + kSmiTagSize), SetRC);
1269 #else
1270 rlwinm(scratch, value, 1, kBitsPerPointer - (1 + kSmiTagSize),
1271 kBitsPerPointer - 1, SetRC);
1272 #endif
1273 }
1274
1275 // Jump the register contains a smi.
JumpIfSmi(Register value,Label * smi_label)1276 inline void JumpIfSmi(Register value, Label* smi_label) {
1277 TestIfSmi(value, r0);
1278 beq(smi_label, cr0); // branch if SMI
1279 }
1280 // Jump if either of the registers contain a non-smi.
JumpIfNotSmi(Register value,Label * not_smi_label)1281 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1282 TestIfSmi(value, r0);
1283 bne(not_smi_label, cr0);
1284 }
1285 // Jump if either of the registers contain a non-smi.
1286 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1287 // Jump if either of the registers contain a smi.
1288 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1289
1290 // Abort execution if argument is a smi, enabled via --debug-code.
1291 void AssertNotSmi(Register object);
1292 void AssertSmi(Register object);
1293
1294
1295 #if V8_TARGET_ARCH_PPC64
1296 inline void TestIfInt32(Register value, Register scratch,
1297 CRegister cr = cr7) {
1298 // High bits must be identical to fit into an 32-bit integer
1299 extsw(scratch, value);
1300 cmp(scratch, value, cr);
1301 }
1302 #else
1303 inline void TestIfInt32(Register hi_word, Register lo_word, Register scratch,
1304 CRegister cr = cr7) {
1305 // High bits must be identical to fit into an 32-bit integer
1306 srawi(scratch, lo_word, 31);
1307 cmp(scratch, hi_word, cr);
1308 }
1309 #endif
1310
1311 #if V8_TARGET_ARCH_PPC64
1312 // Ensure it is permissable to read/write int value directly from
1313 // upper half of the smi.
1314 STATIC_ASSERT(kSmiTag == 0);
1315 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32);
1316 #endif
1317 #if V8_TARGET_ARCH_PPC64 && V8_TARGET_LITTLE_ENDIAN
1318 #define SmiWordOffset(offset) (offset + kPointerSize / 2)
1319 #else
1320 #define SmiWordOffset(offset) offset
1321 #endif
1322
1323 // Abort execution if argument is not a string, enabled via --debug-code.
1324 void AssertString(Register object);
1325
1326 // Abort execution if argument is not a name, enabled via --debug-code.
1327 void AssertName(Register object);
1328
1329 void AssertFunction(Register object);
1330
1331 // Abort execution if argument is not a JSBoundFunction,
1332 // enabled via --debug-code.
1333 void AssertBoundFunction(Register object);
1334
1335 // Abort execution if argument is not undefined or an AllocationSite, enabled
1336 // via --debug-code.
1337 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1338
1339 // Abort execution if reg is not the root value with the given index,
1340 // enabled via --debug-code.
1341 void AssertIsRoot(Register reg, Heap::RootListIndex index);
1342
1343 // ---------------------------------------------------------------------------
1344 // HeapNumber utilities
1345
1346 void JumpIfNotHeapNumber(Register object, Register heap_number_map,
1347 Register scratch, Label* on_not_heap_number);
1348
1349 // ---------------------------------------------------------------------------
1350 // String utilities
1351
1352 // Checks if both objects are sequential one-byte strings and jumps to label
1353 // if either is not. Assumes that neither object is a smi.
1354 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register object1,
1355 Register object2,
1356 Register scratch1,
1357 Register scratch2,
1358 Label* failure);
1359
1360 // Checks if both objects are sequential one-byte strings and jumps to label
1361 // if either is not.
1362 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1363 Register scratch1,
1364 Register scratch2,
1365 Label* not_flat_one_byte_strings);
1366
1367 // Checks if both instance types are sequential one-byte strings and jumps to
1368 // label if either is not.
1369 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1370 Register first_object_instance_type, Register second_object_instance_type,
1371 Register scratch1, Register scratch2, Label* failure);
1372
1373 // Check if instance type is sequential one-byte string and jump to label if
1374 // it is not.
1375 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1376 Label* failure);
1377
1378 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1379
1380 void EmitSeqStringSetCharCheck(Register string, Register index,
1381 Register value, uint32_t encoding_mask);
1382
1383 // ---------------------------------------------------------------------------
1384 // Patching helpers.
1385
1386 // Decode offset from constant pool load instruction(s).
1387 // Caller must place the instruction word at <location> in <result>.
1388 void DecodeConstantPoolOffset(Register result, Register location);
1389
1390 void ClampUint8(Register output_reg, Register input_reg);
1391
1392 // Saturate a value into 8-bit unsigned integer
1393 // if input_value < 0, output_value is 0
1394 // if input_value > 255, output_value is 255
1395 // otherwise output_value is the (int)input_value (round to nearest)
1396 void ClampDoubleToUint8(Register result_reg, DoubleRegister input_reg,
1397 DoubleRegister temp_double_reg);
1398
1399
1400 void LoadInstanceDescriptors(Register map, Register descriptors);
1401 void EnumLength(Register dst, Register map);
1402 void NumberOfOwnDescriptors(Register dst, Register map);
1403 void LoadAccessor(Register dst, Register holder, int accessor_index,
1404 AccessorComponent accessor);
1405
1406 template <typename Field>
1407 void DecodeField(Register dst, Register src, RCBit rc = LeaveRC) {
1408 ExtractBitRange(dst, src, Field::kShift + Field::kSize - 1, Field::kShift,
1409 rc);
1410 }
1411
1412 template <typename Field>
1413 void DecodeField(Register reg, RCBit rc = LeaveRC) {
1414 DecodeField<Field>(reg, reg, rc);
1415 }
1416
1417 template <typename Field>
DecodeFieldToSmi(Register dst,Register src)1418 void DecodeFieldToSmi(Register dst, Register src) {
1419 #if V8_TARGET_ARCH_PPC64
1420 DecodeField<Field>(dst, src);
1421 SmiTag(dst);
1422 #else
1423 // 32-bit can do this in one instruction:
1424 int start = Field::kSize + kSmiShift - 1;
1425 int end = kSmiShift;
1426 int rotate = kSmiShift - Field::kShift;
1427 if (rotate < 0) {
1428 rotate += kBitsPerPointer;
1429 }
1430 rlwinm(dst, src, rotate, kBitsPerPointer - start - 1,
1431 kBitsPerPointer - end - 1);
1432 #endif
1433 }
1434
1435 template <typename Field>
DecodeFieldToSmi(Register reg)1436 void DecodeFieldToSmi(Register reg) {
1437 DecodeFieldToSmi<Field>(reg, reg);
1438 }
1439
1440 // Load the type feedback vector from a JavaScript frame.
1441 void EmitLoadTypeFeedbackVector(Register vector);
1442
1443 // Activation support.
1444 void EnterFrame(StackFrame::Type type,
1445 bool load_constant_pool_pointer_reg = false);
1446 // Returns the pc offset at which the frame ends.
1447 int LeaveFrame(StackFrame::Type type, int stack_adjustment = 0);
1448
1449 // Expects object in r0 and returns map with validated enum cache
1450 // in r0. Assumes that any other register can be used as a scratch.
1451 void CheckEnumCache(Register null_value, Label* call_runtime);
1452
1453 // AllocationMemento support. Arrays may have an associated
1454 // AllocationMemento object that can be checked for in order to pretransition
1455 // to another type.
1456 // On entry, receiver_reg should point to the array object.
1457 // scratch_reg gets clobbered.
1458 // If allocation info is present, condition flags are set to eq.
1459 void TestJSArrayForAllocationMemento(Register receiver_reg,
1460 Register scratch_reg,
1461 Label* no_memento_found);
1462
JumpIfJSArrayHasAllocationMemento(Register receiver_reg,Register scratch_reg,Label * memento_found)1463 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1464 Register scratch_reg,
1465 Label* memento_found) {
1466 Label no_memento_found;
1467 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1468 &no_memento_found);
1469 beq(memento_found);
1470 bind(&no_memento_found);
1471 }
1472
1473 // Jumps to found label if a prototype map has dictionary elements.
1474 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1475 Register scratch1, Label* found);
1476
1477 // Loads the constant pool pointer (kConstantPoolRegister).
1478 void LoadConstantPoolPointerRegisterFromCodeTargetAddress(
1479 Register code_target_address);
1480 void LoadConstantPoolPointerRegister();
1481 void LoadConstantPoolPointerRegister(Register base, int code_entry_delta = 0);
1482
AbortConstantPoolBuilding()1483 void AbortConstantPoolBuilding() {
1484 #ifdef DEBUG
1485 // Avoid DCHECK(!is_linked()) failure in ~Label()
1486 bind(ConstantPoolPosition());
1487 #endif
1488 }
1489
1490 private:
1491 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1492
1493 void CallCFunctionHelper(Register function, int num_reg_arguments,
1494 int num_double_arguments);
1495
1496 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al,
1497 CRegister cr = cr7);
1498
1499 // Helper functions for generating invokes.
1500 void InvokePrologue(const ParameterCount& expected,
1501 const ParameterCount& actual, Label* done,
1502 bool* definitely_mismatches, InvokeFlag flag,
1503 const CallWrapper& call_wrapper);
1504
1505 void InitializeNewString(Register string, Register length,
1506 Heap::RootListIndex map_index, Register scratch1,
1507 Register scratch2);
1508
1509 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1510 void InNewSpace(Register object, Register scratch,
1511 Condition cond, // eq for new space, ne otherwise.
1512 Label* branch);
1513
1514 // Helper for finding the mark bits for an address. Afterwards, the
1515 // bitmap register points at the word with the mark bits and the mask
1516 // the position of the first bit. Leaves addr_reg unchanged.
1517 inline void GetMarkBits(Register addr_reg, Register bitmap_reg,
1518 Register mask_reg);
1519
1520 static const RegList kSafepointSavedRegisters;
1521 static const int kNumSafepointSavedRegisters;
1522
1523 // Compute memory operands for safepoint stack slots.
1524 static int SafepointRegisterStackIndex(int reg_code);
1525 MemOperand SafepointRegisterSlot(Register reg);
1526 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1527
1528 bool generating_stub_;
1529 bool has_frame_;
1530 // This handle will be patched with the code object on installation.
1531 Handle<Object> code_object_;
1532
1533 // Needs access to SafepointRegisterStackIndex for compiled frame
1534 // traversal.
1535 friend class StandardFrame;
1536 };
1537
1538
1539 // The code patcher is used to patch (typically) small parts of code e.g. for
1540 // debugging and other types of instrumentation. When using the code patcher
1541 // the exact number of bytes specified must be emitted. It is not legal to emit
1542 // relocation information. If any of these constraints are violated it causes
1543 // an assertion to fail.
1544 class CodePatcher {
1545 public:
1546 enum FlushICache { FLUSH, DONT_FLUSH };
1547
1548 CodePatcher(Isolate* isolate, byte* address, int instructions,
1549 FlushICache flush_cache = FLUSH);
1550 ~CodePatcher();
1551
1552 // Macro assembler to emit code.
masm()1553 MacroAssembler* masm() { return &masm_; }
1554
1555 // Emit an instruction directly.
1556 void Emit(Instr instr);
1557
1558 // Emit the condition part of an instruction leaving the rest of the current
1559 // instruction unchanged.
1560 void EmitCondition(Condition cond);
1561
1562 private:
1563 byte* address_; // The address of the code being patched.
1564 int size_; // Number of bytes of the expected patch size.
1565 MacroAssembler masm_; // Macro assembler used to generate the code.
1566 FlushICache flush_cache_; // Whether to flush the I cache after patching.
1567 };
1568
1569
1570 // -----------------------------------------------------------------------------
1571 // Static helper functions.
1572
1573 inline MemOperand ContextMemOperand(Register context, int index = 0) {
1574 return MemOperand(context, Context::SlotOffset(index));
1575 }
1576
1577
NativeContextMemOperand()1578 inline MemOperand NativeContextMemOperand() {
1579 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
1580 }
1581
1582
1583 #ifdef GENERATED_CODE_COVERAGE
1584 #define CODE_COVERAGE_STRINGIFY(x) #x
1585 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1586 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1587 #define ACCESS_MASM(masm) \
1588 masm->stop(__FILE_LINE__); \
1589 masm->
1590 #else
1591 #define ACCESS_MASM(masm) masm->
1592 #endif
1593 } // namespace internal
1594 } // namespace v8
1595
1596 #endif // V8_PPC_MACRO_ASSEMBLER_PPC_H_
1597