V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
macro-assembler-arm.h
1 // Copyright 2012 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 INCLUDED_FROM_MACRO_ASSEMBLER_H
6 #error This header must be included via macro-assembler.h
7 #endif
8 
9 #ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_
10 #define V8_ARM_MACRO_ASSEMBLER_ARM_H_
11 
12 #include "src/arm/assembler-arm.h"
13 #include "src/bailout-reason.h"
14 #include "src/contexts.h"
15 #include "src/globals.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 // Give alias names to registers for calling conventions.
21 constexpr Register kReturnRegister0 = r0;
22 constexpr Register kReturnRegister1 = r1;
23 constexpr Register kReturnRegister2 = r2;
24 constexpr Register kJSFunctionRegister = r1;
25 constexpr Register kContextRegister = r7;
26 constexpr Register kAllocateSizeRegister = r1;
27 constexpr Register kSpeculationPoisonRegister = r9;
28 constexpr Register kInterpreterAccumulatorRegister = r0;
29 constexpr Register kInterpreterBytecodeOffsetRegister = r5;
30 constexpr Register kInterpreterBytecodeArrayRegister = r6;
31 constexpr Register kInterpreterDispatchTableRegister = r8;
32 
33 constexpr Register kJavaScriptCallArgCountRegister = r0;
34 constexpr Register kJavaScriptCallCodeStartRegister = r2;
35 constexpr Register kJavaScriptCallTargetRegister = kJSFunctionRegister;
36 constexpr Register kJavaScriptCallNewTargetRegister = r3;
37 constexpr Register kJavaScriptCallExtraArg1Register = r2;
38 
39 constexpr Register kOffHeapTrampolineRegister = ip;
40 constexpr Register kRuntimeCallFunctionRegister = r1;
41 constexpr Register kRuntimeCallArgCountRegister = r0;
42 constexpr Register kRuntimeCallArgvRegister = r2;
43 constexpr Register kWasmInstanceRegister = r3;
44 constexpr Register kWasmCompileLazyFuncIndexRegister = r4;
45 
46 // ----------------------------------------------------------------------------
47 // Static helper functions
48 
49 // Generate a MemOperand for loading a field from an object.
50 inline MemOperand FieldMemOperand(Register object, int offset) {
51  return MemOperand(object, offset - kHeapObjectTag);
52 }
53 
54 
55 // Give alias names to registers
56 constexpr Register cp = r7; // JavaScript context pointer.
57 constexpr Register kRootRegister = r10; // Roots array pointer.
58 
59 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
60 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
61 enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
62 
63 
64 Register GetRegisterThatIsNotOneOf(Register reg1,
65  Register reg2 = no_reg,
66  Register reg3 = no_reg,
67  Register reg4 = no_reg,
68  Register reg5 = no_reg,
69  Register reg6 = no_reg);
70 
71 enum TargetAddressStorageMode {
72  CAN_INLINE_TARGET_ADDRESS,
73  NEVER_INLINE_TARGET_ADDRESS
74 };
75 
76 class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
77  public:
78  TurboAssembler(const AssemblerOptions& options, void* buffer, int buffer_size)
79  : TurboAssemblerBase(options, buffer, buffer_size) {}
80 
81  TurboAssembler(Isolate* isolate, const AssemblerOptions& options,
82  void* buffer, int buffer_size,
83  CodeObjectRequired create_code_object)
84  : TurboAssemblerBase(isolate, options, buffer, buffer_size,
85  create_code_object) {}
86 
87  // Activation support.
88  void EnterFrame(StackFrame::Type type,
89  bool load_constant_pool_pointer_reg = false);
90  // Returns the pc offset at which the frame ends.
91  int LeaveFrame(StackFrame::Type type);
92 
93  // Push a fixed frame, consisting of lr, fp
94  void PushCommonFrame(Register marker_reg = no_reg);
95 
96  // Generates function and stub prologue code.
97  void StubPrologue(StackFrame::Type type);
98  void Prologue();
99 
100  // Push a standard frame, consisting of lr, fp, context and JS function
101  void PushStandardFrame(Register function_reg);
102 
103  void InitializeRootRegister();
104 
105  void Push(Register src) { push(src); }
106 
107  void Push(Handle<HeapObject> handle);
108  void Push(Smi smi);
109 
110  // Push two registers. Pushes leftmost register first (to highest address).
111  void Push(Register src1, Register src2, Condition cond = al) {
112  if (src1.code() > src2.code()) {
113  stm(db_w, sp, src1.bit() | src2.bit(), cond);
114  } else {
115  str(src1, MemOperand(sp, 4, NegPreIndex), cond);
116  str(src2, MemOperand(sp, 4, NegPreIndex), cond);
117  }
118  }
119 
120  // Push three registers. Pushes leftmost register first (to highest address).
121  void Push(Register src1, Register src2, Register src3, Condition cond = al) {
122  if (src1.code() > src2.code()) {
123  if (src2.code() > src3.code()) {
124  stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
125  } else {
126  stm(db_w, sp, src1.bit() | src2.bit(), cond);
127  str(src3, MemOperand(sp, 4, NegPreIndex), cond);
128  }
129  } else {
130  str(src1, MemOperand(sp, 4, NegPreIndex), cond);
131  Push(src2, src3, cond);
132  }
133  }
134 
135  // Push four registers. Pushes leftmost register first (to highest address).
136  void Push(Register src1, Register src2, Register src3, Register src4,
137  Condition cond = al) {
138  if (src1.code() > src2.code()) {
139  if (src2.code() > src3.code()) {
140  if (src3.code() > src4.code()) {
141  stm(db_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(),
142  cond);
143  } else {
144  stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
145  str(src4, MemOperand(sp, 4, NegPreIndex), cond);
146  }
147  } else {
148  stm(db_w, sp, src1.bit() | src2.bit(), cond);
149  Push(src3, src4, cond);
150  }
151  } else {
152  str(src1, MemOperand(sp, 4, NegPreIndex), cond);
153  Push(src2, src3, src4, cond);
154  }
155  }
156 
157  // Push five registers. Pushes leftmost register first (to highest address).
158  void Push(Register src1, Register src2, Register src3, Register src4,
159  Register src5, Condition cond = al) {
160  if (src1.code() > src2.code()) {
161  if (src2.code() > src3.code()) {
162  if (src3.code() > src4.code()) {
163  if (src4.code() > src5.code()) {
164  stm(db_w, sp,
165  src1.bit() | src2.bit() | src3.bit() | src4.bit() | src5.bit(),
166  cond);
167  } else {
168  stm(db_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(),
169  cond);
170  str(src5, MemOperand(sp, 4, NegPreIndex), cond);
171  }
172  } else {
173  stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
174  Push(src4, src5, cond);
175  }
176  } else {
177  stm(db_w, sp, src1.bit() | src2.bit(), cond);
178  Push(src3, src4, src5, cond);
179  }
180  } else {
181  str(src1, MemOperand(sp, 4, NegPreIndex), cond);
182  Push(src2, src3, src4, src5, cond);
183  }
184  }
185 
186  void Pop(Register dst) { pop(dst); }
187 
188  // Pop two registers. Pops rightmost register first (from lower address).
189  void Pop(Register src1, Register src2, Condition cond = al) {
190  DCHECK(src1 != src2);
191  if (src1.code() > src2.code()) {
192  ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
193  } else {
194  ldr(src2, MemOperand(sp, 4, PostIndex), cond);
195  ldr(src1, MemOperand(sp, 4, PostIndex), cond);
196  }
197  }
198 
199  // Pop three registers. Pops rightmost register first (from lower address).
200  void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
201  DCHECK(!AreAliased(src1, src2, src3));
202  if (src1.code() > src2.code()) {
203  if (src2.code() > src3.code()) {
204  ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
205  } else {
206  ldr(src3, MemOperand(sp, 4, PostIndex), cond);
207  ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
208  }
209  } else {
210  Pop(src2, src3, cond);
211  ldr(src1, MemOperand(sp, 4, PostIndex), cond);
212  }
213  }
214 
215  // Pop four registers. Pops rightmost register first (from lower address).
216  void Pop(Register src1, Register src2, Register src3, Register src4,
217  Condition cond = al) {
218  DCHECK(!AreAliased(src1, src2, src3, src4));
219  if (src1.code() > src2.code()) {
220  if (src2.code() > src3.code()) {
221  if (src3.code() > src4.code()) {
222  ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(),
223  cond);
224  } else {
225  ldr(src4, MemOperand(sp, 4, PostIndex), cond);
226  ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
227  }
228  } else {
229  Pop(src3, src4, cond);
230  ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
231  }
232  } else {
233  Pop(src2, src3, src4, cond);
234  ldr(src1, MemOperand(sp, 4, PostIndex), cond);
235  }
236  }
237 
238  // Before calling a C-function from generated code, align arguments on stack.
239  // After aligning the frame, non-register arguments must be stored in
240  // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
241  // are word sized. If double arguments are used, this function assumes that
242  // all double arguments are stored before core registers; otherwise the
243  // correct alignment of the double values is not guaranteed.
244  // Some compilers/platforms require the stack to be aligned when calling
245  // C++ code.
246  // Needs a scratch register to do some arithmetic. This register will be
247  // trashed.
248  void PrepareCallCFunction(int num_reg_arguments, int num_double_registers = 0,
249  Register scratch = no_reg);
250 
251  // Removes current frame and its arguments from the stack preserving
252  // the arguments and a return address pushed to the stack for the next call.
253  // Both |callee_args_count| and |caller_args_count_reg| do not include
254  // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
255  // is trashed.
256  void PrepareForTailCall(const ParameterCount& callee_args_count,
257  Register caller_args_count_reg, Register scratch0,
258  Register scratch1);
259 
260  // There are two ways of passing double arguments on ARM, depending on
261  // whether soft or hard floating point ABI is used. These functions
262  // abstract parameter passing for the three different ways we call
263  // C functions from generated code.
264  void MovToFloatParameter(DwVfpRegister src);
265  void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
266  void MovToFloatResult(DwVfpRegister src);
267 
268  // Calls a C function and cleans up the space for arguments allocated
269  // by PrepareCallCFunction. The called function is not allowed to trigger a
270  // garbage collection, since that might move the code and invalidate the
271  // return address (unless this is somehow accounted for by the called
272  // function).
273  void CallCFunction(ExternalReference function, int num_arguments);
274  void CallCFunction(Register function, int num_arguments);
275  void CallCFunction(ExternalReference function, int num_reg_arguments,
276  int num_double_arguments);
277  void CallCFunction(Register function, int num_reg_arguments,
278  int num_double_arguments);
279 
280  void MovFromFloatParameter(DwVfpRegister dst);
281  void MovFromFloatResult(DwVfpRegister dst);
282 
283  // Calls Abort(msg) if the condition cond is not satisfied.
284  // Use --debug-code to enable.
285  void Assert(Condition cond, AbortReason reason);
286 
287  // Like Assert(), but without condition.
288  // Use --debug-code to enable.
289  void AssertUnreachable(AbortReason reason);
290 
291  // Like Assert(), but always enabled.
292  void Check(Condition cond, AbortReason reason);
293 
294  // Print a message to stdout and abort execution.
295  void Abort(AbortReason msg);
296 
297  inline bool AllowThisStubCall(CodeStub* stub);
298 
299  void LslPair(Register dst_low, Register dst_high, Register src_low,
300  Register src_high, Register shift);
301  void LslPair(Register dst_low, Register dst_high, Register src_low,
302  Register src_high, uint32_t shift);
303  void LsrPair(Register dst_low, Register dst_high, Register src_low,
304  Register src_high, Register shift);
305  void LsrPair(Register dst_low, Register dst_high, Register src_low,
306  Register src_high, uint32_t shift);
307  void AsrPair(Register dst_low, Register dst_high, Register src_low,
308  Register src_high, Register shift);
309  void AsrPair(Register dst_low, Register dst_high, Register src_low,
310  Register src_high, uint32_t shift);
311 
312  void LoadFromConstantsTable(Register destination,
313  int constant_index) override;
314  void LoadRootRegisterOffset(Register destination, intptr_t offset) override;
315  void LoadRootRelative(Register destination, int32_t offset) override;
316 
317  // Call a runtime routine. This expects {centry} to contain a fitting CEntry
318  // builtin for the target runtime function and uses an indirect call.
319  void CallRuntimeWithCEntry(Runtime::FunctionId fid, Register centry);
320 
321  // Jump, Call, and Ret pseudo instructions implementing inter-working.
322  void Call(Register target, Condition cond = al);
323  void Call(Address target, RelocInfo::Mode rmode, Condition cond = al,
324  TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS,
325  bool check_constant_pool = true);
326  void Call(Handle<Code> code, RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
327  Condition cond = al,
328  TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS,
329  bool check_constant_pool = true);
330  void Call(Label* target);
331 
332  // This should only be used when assembling a deoptimizer call because of
333  // the CheckConstPool invocation, which is only needed for deoptimization.
334  void CallForDeoptimization(Address target, int deopt_id,
335  RelocInfo::Mode rmode) {
336  USE(deopt_id);
337  Call(target, rmode);
338  CheckConstPool(false, false);
339  }
340 
341  // Emit code to discard a non-negative number of pointer-sized elements
342  // from the stack, clobbering only the sp register.
343  void Drop(int count, Condition cond = al);
344  void Drop(Register count, Condition cond = al);
345 
346  void Ret(Condition cond = al);
347  void Ret(int drop, Condition cond = al);
348 
349  // Compare single values and move the result to the normal condition flags.
350  void VFPCompareAndSetFlags(const SwVfpRegister src1, const SwVfpRegister src2,
351  const Condition cond = al);
352  void VFPCompareAndSetFlags(const SwVfpRegister src1, const float src2,
353  const Condition cond = al);
354 
355  // Compare double values and move the result to the normal condition flags.
356  void VFPCompareAndSetFlags(const DwVfpRegister src1, const DwVfpRegister src2,
357  const Condition cond = al);
358  void VFPCompareAndSetFlags(const DwVfpRegister src1, const double src2,
359  const Condition cond = al);
360 
361  // If the value is a NaN, canonicalize the value else, do nothing.
362  void VFPCanonicalizeNaN(const DwVfpRegister dst, const DwVfpRegister src,
363  const Condition cond = al);
364  void VFPCanonicalizeNaN(const DwVfpRegister value,
365  const Condition cond = al) {
366  VFPCanonicalizeNaN(value, value, cond);
367  }
368 
369  void VmovHigh(Register dst, DwVfpRegister src);
370  void VmovHigh(DwVfpRegister dst, Register src);
371  void VmovLow(Register dst, DwVfpRegister src);
372  void VmovLow(DwVfpRegister dst, Register src);
373 
374  void CheckPageFlag(Register object, Register scratch, int mask, Condition cc,
375  Label* condition_met);
376 
377  // Check whether d16-d31 are available on the CPU. The result is given by the
378  // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
379  void CheckFor32DRegs(Register scratch);
380 
381  void SaveRegisters(RegList registers);
382  void RestoreRegisters(RegList registers);
383 
384  void CallRecordWriteStub(Register object, Register address,
385  RememberedSetAction remembered_set_action,
386  SaveFPRegsMode fp_mode);
387  void CallRecordWriteStub(Register object, Register address,
388  RememberedSetAction remembered_set_action,
389  SaveFPRegsMode fp_mode, Address wasm_target);
390 
391  // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
392  // values to location, saving [d0..(d15|d31)].
393  void SaveFPRegs(Register location, Register scratch);
394 
395  // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
396  // values to location, restoring [d0..(d15|d31)].
397  void RestoreFPRegs(Register location, Register scratch);
398 
399  // Calculate how much stack space (in bytes) are required to store caller
400  // registers excluding those specified in the arguments.
401  int RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
402  Register exclusion1 = no_reg,
403  Register exclusion2 = no_reg,
404  Register exclusion3 = no_reg) const;
405 
406  // Push caller saved registers on the stack, and return the number of bytes
407  // stack pointer is adjusted.
408  int PushCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg,
409  Register exclusion2 = no_reg,
410  Register exclusion3 = no_reg);
411  // Restore caller saved registers from the stack, and return the number of
412  // bytes stack pointer is adjusted.
413  int PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg,
414  Register exclusion2 = no_reg,
415  Register exclusion3 = no_reg);
416  void Jump(Register target, Condition cond = al);
417  void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
418  void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
419 
420  // Perform a floating-point min or max operation with the
421  // (IEEE-754-compatible) semantics of ARM64's fmin/fmax. Some cases, typically
422  // NaNs or +/-0.0, are expected to be rare and are handled in out-of-line
423  // code. The specific behaviour depends on supported instructions.
424  //
425  // These functions assume (and assert) that left!=right. It is permitted
426  // for the result to alias either input register.
427  void FloatMax(SwVfpRegister result, SwVfpRegister left, SwVfpRegister right,
428  Label* out_of_line);
429  void FloatMin(SwVfpRegister result, SwVfpRegister left, SwVfpRegister right,
430  Label* out_of_line);
431  void FloatMax(DwVfpRegister result, DwVfpRegister left, DwVfpRegister right,
432  Label* out_of_line);
433  void FloatMin(DwVfpRegister result, DwVfpRegister left, DwVfpRegister right,
434  Label* out_of_line);
435 
436  // Generate out-of-line cases for the macros above.
437  void FloatMaxOutOfLine(SwVfpRegister result, SwVfpRegister left,
438  SwVfpRegister right);
439  void FloatMinOutOfLine(SwVfpRegister result, SwVfpRegister left,
440  SwVfpRegister right);
441  void FloatMaxOutOfLine(DwVfpRegister result, DwVfpRegister left,
442  DwVfpRegister right);
443  void FloatMinOutOfLine(DwVfpRegister result, DwVfpRegister left,
444  DwVfpRegister right);
445 
446  void ExtractLane(Register dst, QwNeonRegister src, NeonDataType dt, int lane);
447  void ExtractLane(Register dst, DwVfpRegister src, NeonDataType dt, int lane);
448  void ExtractLane(SwVfpRegister dst, QwNeonRegister src, int lane);
449  void ReplaceLane(QwNeonRegister dst, QwNeonRegister src, Register src_lane,
450  NeonDataType dt, int lane);
451  void ReplaceLane(QwNeonRegister dst, QwNeonRegister src,
452  SwVfpRegister src_lane, int lane);
453 
454  // Register move. May do nothing if the registers are identical.
455  void Move(Register dst, Smi smi);
456  void Move(Register dst, Handle<HeapObject> value);
457  void Move(Register dst, ExternalReference reference);
458  void Move(Register dst, Register src, Condition cond = al);
459  void Move(Register dst, const Operand& src, SBit sbit = LeaveCC,
460  Condition cond = al) {
461  if (!src.IsRegister() || src.rm() != dst || sbit != LeaveCC) {
462  mov(dst, src, sbit, cond);
463  }
464  }
465  void Move(SwVfpRegister dst, SwVfpRegister src, Condition cond = al);
466  void Move(DwVfpRegister dst, DwVfpRegister src, Condition cond = al);
467  void Move(QwNeonRegister dst, QwNeonRegister src);
468 
469  // Simulate s-register moves for imaginary s32 - s63 registers.
470  void VmovExtended(Register dst, int src_code);
471  void VmovExtended(int dst_code, Register src);
472  // Move between s-registers and imaginary s-registers.
473  void VmovExtended(int dst_code, int src_code);
474  void VmovExtended(int dst_code, const MemOperand& src);
475  void VmovExtended(const MemOperand& dst, int src_code);
476 
477  // Register swap. Note that the register operands should be distinct.
478  void Swap(Register srcdst0, Register srcdst1);
479  void Swap(DwVfpRegister srcdst0, DwVfpRegister srcdst1);
480  void Swap(QwNeonRegister srcdst0, QwNeonRegister srcdst1);
481 
482  // Get the actual activation frame alignment for target environment.
483  static int ActivationFrameAlignment();
484 
485  void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al);
486 
487  void SmiUntag(Register reg, SBit s = LeaveCC) {
488  mov(reg, Operand::SmiUntag(reg), s);
489  }
490  void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
491  mov(dst, Operand::SmiUntag(src), s);
492  }
493 
494  // Load an object from the root table.
495  void LoadRoot(Register destination, RootIndex index) override {
496  LoadRoot(destination, index, al);
497  }
498  void LoadRoot(Register destination, RootIndex index, Condition cond);
499 
500  // Jump if the register contains a smi.
501  void JumpIfSmi(Register value, Label* smi_label);
502 
503  void JumpIfEqual(Register x, int32_t y, Label* dest);
504  void JumpIfLessThan(Register x, int32_t y, Label* dest);
505 
506  // Performs a truncating conversion of a floating point number as used by
507  // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
508  // succeeds, otherwise falls through if result is saturated. On return
509  // 'result' either holds answer, or is clobbered on fall through.
510  //
511  // Only public for the test code in test-code-stubs-arm.cc.
512  void TryInlineTruncateDoubleToI(Register result, DwVfpRegister input,
513  Label* done);
514 
515  // Performs a truncating conversion of a floating point number as used by
516  // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
517  // Exits with 'result' holding the answer.
518  void TruncateDoubleToI(Isolate* isolate, Zone* zone, Register result,
519  DwVfpRegister double_input, StubCallMode stub_mode);
520 
521  // EABI variant for double arguments in use.
522  bool use_eabi_hardfloat() {
523 #ifdef __arm__
524  return base::OS::ArmUsingHardFloat();
525 #elif USE_EABI_HARDFLOAT
526  return true;
527 #else
528  return false;
529 #endif
530  }
531 
532  // Compute the start of the generated instruction stream from the current PC.
533  // This is an alternative to embedding the {CodeObject} handle as a reference.
534  void ComputeCodeStartAddress(Register dst);
535 
536  void ResetSpeculationPoisonRegister();
537 
538  private:
539  // Compare single values and then load the fpscr flags to a register.
540  void VFPCompareAndLoadFlags(const SwVfpRegister src1,
541  const SwVfpRegister src2,
542  const Register fpscr_flags,
543  const Condition cond = al);
544  void VFPCompareAndLoadFlags(const SwVfpRegister src1, const float src2,
545  const Register fpscr_flags,
546  const Condition cond = al);
547 
548  // Compare double values and then load the fpscr flags to a register.
549  void VFPCompareAndLoadFlags(const DwVfpRegister src1,
550  const DwVfpRegister src2,
551  const Register fpscr_flags,
552  const Condition cond = al);
553  void VFPCompareAndLoadFlags(const DwVfpRegister src1, const double src2,
554  const Register fpscr_flags,
555  const Condition cond = al);
556 
557  void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
558 
559  // Implementation helpers for FloatMin and FloatMax.
560  template <typename T>
561  void FloatMaxHelper(T result, T left, T right, Label* out_of_line);
562  template <typename T>
563  void FloatMinHelper(T result, T left, T right, Label* out_of_line);
564  template <typename T>
565  void FloatMaxOutOfLineHelper(T result, T left, T right);
566  template <typename T>
567  void FloatMinOutOfLineHelper(T result, T left, T right);
568 
569  int CalculateStackPassedWords(int num_reg_arguments,
570  int num_double_arguments);
571 
572  void CallCFunctionHelper(Register function, int num_reg_arguments,
573  int num_double_arguments);
574 
575  void CallRecordWriteStub(Register object, Register address,
576  RememberedSetAction remembered_set_action,
577  SaveFPRegsMode fp_mode, Handle<Code> code_target,
578  Address wasm_target);
579 };
580 
581 // MacroAssembler implements a collection of frequently used macros.
583  public:
584  MacroAssembler(const AssemblerOptions& options, void* buffer, int size)
585  : TurboAssembler(options, buffer, size) {}
586 
587  MacroAssembler(Isolate* isolate, void* buffer, int size,
588  CodeObjectRequired create_code_object)
589  : MacroAssembler(isolate, AssemblerOptions::Default(isolate), buffer,
590  size, create_code_object) {}
591 
592  MacroAssembler(Isolate* isolate, const AssemblerOptions& options,
593  void* buffer, int size, CodeObjectRequired create_code_object);
594 
595  void Mls(Register dst, Register src1, Register src2, Register srcA,
596  Condition cond = al);
597  void And(Register dst, Register src1, const Operand& src2,
598  Condition cond = al);
599  void Ubfx(Register dst, Register src, int lsb, int width,
600  Condition cond = al);
601  void Sbfx(Register dst, Register src, int lsb, int width,
602  Condition cond = al);
603 
604  void Load(Register dst, const MemOperand& src, Representation r);
605  void Store(Register src, const MemOperand& dst, Representation r);
606 
607  // ---------------------------------------------------------------------------
608  // GC Support
609 
610  // Check if object is in new space. Jumps if the object is not in new space.
611  // The register scratch can be object itself, but scratch will be clobbered.
612  void JumpIfNotInNewSpace(Register object, Register scratch, Label* branch) {
613  InNewSpace(object, scratch, eq, branch);
614  }
615 
616  // Check if object is in new space. Jumps if the object is in new space.
617  // The register scratch can be object itself, but it will be clobbered.
618  void JumpIfInNewSpace(Register object, Register scratch, Label* branch) {
619  InNewSpace(object, scratch, ne, branch);
620  }
621 
622  // Check if an object has a given incremental marking color.
623  void HasColor(Register object, Register scratch0, Register scratch1,
624  Label* has_color, int first_bit, int second_bit);
625 
626  void JumpIfBlack(Register object, Register scratch0, Register scratch1,
627  Label* on_black);
628 
629  // Checks the color of an object. If the object is white we jump to the
630  // incremental marker.
631  void JumpIfWhite(Register value, Register scratch1, Register scratch2,
632  Register scratch3, Label* value_is_white);
633 
634  // Notify the garbage collector that we wrote a pointer into an object.
635  // |object| is the object being stored into, |value| is the object being
636  // stored. value and scratch registers are clobbered by the operation.
637  // The offset is the offset from the start of the object, not the offset from
638  // the tagged HeapObject pointer. For use with FieldMemOperand(reg, off).
639  void RecordWriteField(
640  Register object, int offset, Register value, Register scratch,
641  LinkRegisterStatus lr_status, SaveFPRegsMode save_fp,
642  RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
643  SmiCheck smi_check = INLINE_SMI_CHECK);
644 
645  // For a given |object| notify the garbage collector that the slot |address|
646  // has been written. |value| is the object being stored. The value and
647  // address registers are clobbered by the operation.
648  void RecordWrite(
649  Register object, Register address, Register value,
650  LinkRegisterStatus lr_status, SaveFPRegsMode save_fp,
651  RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
652  SmiCheck smi_check = INLINE_SMI_CHECK);
653 
654  // Push and pop the registers that can hold pointers, as defined by the
655  // RegList constant kSafepointSavedRegisters.
656  void PushSafepointRegisters();
657  void PopSafepointRegisters();
658 
659  // Enter exit frame.
660  // stack_space - extra stack space, used for alignment before call to C.
661  void EnterExitFrame(bool save_doubles, int stack_space = 0,
662  StackFrame::Type frame_type = StackFrame::EXIT);
663 
664  // Leave the current exit frame. Expects the return value in r0.
665  // Expect the number of values, pushed prior to the exit frame, to
666  // remove in a register (or no_reg, if there is nothing to remove).
667  void LeaveExitFrame(bool save_doubles, Register argument_count,
668  bool argument_count_is_length = false);
669 
670  // Load the global proxy from the current context.
671  void LoadGlobalProxy(Register dst);
672 
673  void LoadNativeContextSlot(int index, Register dst);
674 
675  // ---------------------------------------------------------------------------
676  // JavaScript invokes
677 
678  // Invoke the JavaScript function code by either calling or jumping.
679  void InvokeFunctionCode(Register function, Register new_target,
680  const ParameterCount& expected,
681  const ParameterCount& actual, InvokeFlag flag);
682 
683  // On function call, call into the debugger if necessary.
684  void CheckDebugHook(Register fun, Register new_target,
685  const ParameterCount& expected,
686  const ParameterCount& actual);
687 
688  // Invoke the JavaScript function in the given register. Changes the
689  // current context to the context in the function before invoking.
690  void InvokeFunction(Register function, Register new_target,
691  const ParameterCount& actual, InvokeFlag flag);
692 
693  void InvokeFunction(Register function, const ParameterCount& expected,
694  const ParameterCount& actual, InvokeFlag flag);
695 
696  // Frame restart support
697  void MaybeDropFrames();
698 
699  // Exception handling
700 
701  // Push a new stack handler and link into stack handler chain.
702  void PushStackHandler();
703 
704  // Unlink the stack handler on top of the stack from the stack handler chain.
705  // Must preserve the result register.
706  void PopStackHandler();
707 
708  // ---------------------------------------------------------------------------
709  // Support functions.
710 
711  // Compare object type for heap object. heap_object contains a non-Smi
712  // whose object type should be compared with the given type. This both
713  // sets the flags and leaves the object type in the type_reg register.
714  // It leaves the map in the map register (unless the type_reg and map register
715  // are the same register). It leaves the heap object in the heap_object
716  // register unless the heap_object register is the same register as one of the
717  // other registers.
718  // Type_reg can be no_reg. In that case a scratch register is used.
719  void CompareObjectType(Register heap_object,
720  Register map,
721  Register type_reg,
722  InstanceType type);
723 
724  // Compare instance type in a map. map contains a valid map object whose
725  // object type should be compared with the given type. This both
726  // sets the flags and leaves the object type in the type_reg register.
727  void CompareInstanceType(Register map,
728  Register type_reg,
729  InstanceType type);
730 
731  // Compare the object in a register to a value from the root list.
732  // Acquires a scratch register.
733  void CompareRoot(Register obj, RootIndex index);
734  void PushRoot(RootIndex index) {
735  UseScratchRegisterScope temps(this);
736  Register scratch = temps.Acquire();
737  LoadRoot(scratch, index);
738  Push(scratch);
739  }
740 
741  // Compare the object in a register to a value and jump if they are equal.
742  void JumpIfRoot(Register with, RootIndex index, Label* if_equal) {
743  CompareRoot(with, index);
744  b(eq, if_equal);
745  }
746 
747  // Compare the object in a register to a value and jump if they are not equal.
748  void JumpIfNotRoot(Register with, RootIndex index, Label* if_not_equal) {
749  CompareRoot(with, index);
750  b(ne, if_not_equal);
751  }
752 
753  // Try to convert a double to a signed 32-bit integer.
754  // Z flag set to one and result assigned if the conversion is exact.
755  void TryDoubleToInt32Exact(Register result,
756  DwVfpRegister double_input,
757  LowDwVfpRegister double_scratch);
758 
759  // ---------------------------------------------------------------------------
760  // Runtime calls
761 
762  // Call a code stub.
763  void CallStub(CodeStub* stub,
764  Condition cond = al);
765 
766  // Call a code stub.
767  void TailCallStub(CodeStub* stub, Condition cond = al);
768 
769  // Call a runtime routine.
770  void CallRuntime(const Runtime::Function* f,
771  int num_arguments,
772  SaveFPRegsMode save_doubles = kDontSaveFPRegs);
773 
774  // Convenience function: Same as above, but takes the fid instead.
775  void CallRuntime(Runtime::FunctionId fid,
776  SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
777  const Runtime::Function* function = Runtime::FunctionForId(fid);
778  CallRuntime(function, function->nargs, save_doubles);
779  }
780 
781  // Convenience function: Same as above, but takes the fid instead.
782  void CallRuntime(Runtime::FunctionId fid, int num_arguments,
783  SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
784  CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
785  }
786 
787  // Convenience function: tail call a runtime routine (jump).
788  void TailCallRuntime(Runtime::FunctionId fid);
789 
790  // Jump to a runtime routine.
791  void JumpToExternalReference(const ExternalReference& builtin,
792  bool builtin_exit_frame = false);
793 
794  // Generates a trampoline to jump to the off-heap instruction stream.
795  void JumpToInstructionStream(Address entry);
796 
797  // ---------------------------------------------------------------------------
798  // In-place weak references.
799  void LoadWeakValue(Register out, Register in, Label* target_if_cleared);
800 
801  // ---------------------------------------------------------------------------
802  // StatsCounter support
803 
804  void IncrementCounter(StatsCounter* counter, int value,
805  Register scratch1, Register scratch2);
806  void DecrementCounter(StatsCounter* counter, int value,
807  Register scratch1, Register scratch2);
808 
809  // ---------------------------------------------------------------------------
810  // Smi utilities
811 
812  void SmiTag(Register reg, SBit s = LeaveCC);
813  void SmiTag(Register dst, Register src, SBit s = LeaveCC);
814 
815  // Untag the source value into destination and jump if source is a smi.
816  // Souce and destination can be the same register.
817  void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
818 
819  // Test if the register contains a smi (Z == 0 (eq) if true).
820  void SmiTst(Register value);
821  // Jump if either of the registers contain a non-smi.
822  void JumpIfNotSmi(Register value, Label* not_smi_label);
823  // Jump if either of the registers contain a smi.
824  void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
825 
826  // Abort execution if argument is a smi, enabled via --debug-code.
827  void AssertNotSmi(Register object);
828  void AssertSmi(Register object);
829 
830  // Abort execution if argument is not a Constructor, enabled via --debug-code.
831  void AssertConstructor(Register object);
832 
833  // Abort execution if argument is not a JSFunction, enabled via --debug-code.
834  void AssertFunction(Register object);
835 
836  // Abort execution if argument is not a JSBoundFunction,
837  // enabled via --debug-code.
838  void AssertBoundFunction(Register object);
839 
840  // Abort execution if argument is not a JSGeneratorObject (or subclass),
841  // enabled via --debug-code.
842  void AssertGeneratorObject(Register object);
843 
844  // Abort execution if argument is not undefined or an AllocationSite, enabled
845  // via --debug-code.
846  void AssertUndefinedOrAllocationSite(Register object, Register scratch);
847 
848  template<typename Field>
849  void DecodeField(Register dst, Register src) {
850  Ubfx(dst, src, Field::kShift, Field::kSize);
851  }
852 
853  template<typename Field>
854  void DecodeField(Register reg) {
855  DecodeField<Field>(reg, reg);
856  }
857 
858  private:
859  // Helper functions for generating invokes.
860  void InvokePrologue(const ParameterCount& expected,
861  const ParameterCount& actual, Label* done,
862  bool* definitely_mismatches, InvokeFlag flag);
863 
864  // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
865  void InNewSpace(Register object,
866  Register scratch,
867  Condition cond, // eq for new space, ne otherwise.
868  Label* branch);
869 
870  // Compute memory operands for safepoint stack slots.
871  static int SafepointRegisterStackIndex(int reg_code);
872 
873  // Needs access to SafepointRegisterStackIndex for compiled frame
874  // traversal.
875  friend class StandardFrame;
876 };
877 
878 // -----------------------------------------------------------------------------
879 // Static helper functions.
880 
881 inline MemOperand ContextMemOperand(Register context, int index = 0) {
882  return MemOperand(context, Context::SlotOffset(index));
883 }
884 
885 
886 inline MemOperand NativeContextMemOperand() {
887  return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
888 }
889 
890 #define ACCESS_MASM(masm) masm->
891 
892 } // namespace internal
893 } // namespace v8
894 
895 #endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_
Definition: libplatform.h:13