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