1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef CPU_AARCH64_VM_MACROASSEMBLER_AARCH64_HPP
  27 #define CPU_AARCH64_VM_MACROASSEMBLER_AARCH64_HPP
  28 
  29 #include "asm/assembler.hpp"
  30 
  31 // MacroAssembler extends Assembler by frequently used macros.
  32 //
  33 // Instructions for which a 'better' code sequence exists depending
  34 // on arguments should also go in here.
  35 
  36 class MacroAssembler: public Assembler {
  37   friend class LIR_Assembler;
  38 
  39  public:
  40   using Assembler::mov;
  41   using Assembler::movi;
  42 
  43  protected:
  44 
  45   // Support for VM calls
  46   //
  47   // This is the base routine called by the different versions of call_VM_leaf. The interpreter
  48   // may customize this version by overriding it for its purposes (e.g., to save/restore
  49   // additional registers when doing a VM call).
  50   virtual void call_VM_leaf_base(
  51     address entry_point,               // the entry point
  52     int     number_of_arguments,        // the number of arguments to pop after the call
  53     Label *retaddr = NULL
  54   );
  55 
  56   virtual void call_VM_leaf_base(
  57     address entry_point,               // the entry point
  58     int     number_of_arguments,        // the number of arguments to pop after the call
  59     Label &retaddr) {
  60     call_VM_leaf_base(entry_point, number_of_arguments, &retaddr);
  61   }
  62 
  63   // This is the base routine called by the different versions of call_VM. The interpreter
  64   // may customize this version by overriding it for its purposes (e.g., to save/restore
  65   // additional registers when doing a VM call).
  66   //
  67   // If no java_thread register is specified (noreg) than rthread will be used instead. call_VM_base
  68   // returns the register which contains the thread upon return. If a thread register has been
  69   // specified, the return value will correspond to that register. If no last_java_sp is specified
  70   // (noreg) than rsp will be used instead.
  71   virtual void call_VM_base(           // returns the register containing the thread upon return
  72     Register oop_result,               // where an oop-result ends up if any; use noreg otherwise
  73     Register java_thread,              // the thread if computed before     ; use noreg otherwise
  74     Register last_java_sp,             // to set up last_Java_frame in stubs; use noreg otherwise
  75     address  entry_point,              // the entry point
  76     int      number_of_arguments,      // the number of arguments (w/o thread) to pop after the call
  77     bool     check_exceptions          // whether to check for pending exceptions after return
  78   );
  79 
  80   // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
  81   // The implementation is only non-empty for the InterpreterMacroAssembler,
  82   // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
  83   virtual void check_and_handle_popframe(Register java_thread);
  84   virtual void check_and_handle_earlyret(Register java_thread);
  85 
  86   void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions = true);
  87 
  88   // Maximum size of class area in Metaspace when compressed
  89   uint64_t use_XOR_for_compressed_class_base;
  90 
  91  public:
  92   MacroAssembler(CodeBuffer* code) : Assembler(code) {
  93     use_XOR_for_compressed_class_base
  94       = (operand_valid_for_logical_immediate(false /*is32*/,
  95                                              (uint64_t)Universe::narrow_klass_base())
  96          && ((uint64_t)Universe::narrow_klass_base()
  97              > (1u << log2_intptr(CompressedClassSpaceSize))));
  98   }
  99 
 100   // Biased locking support
 101   // lock_reg and obj_reg must be loaded up with the appropriate values.
 102   // swap_reg is killed.
 103   // tmp_reg must be supplied and must not be rscratch1 or rscratch2
 104   // Optional slow case is for implementations (interpreter and C1) which branch to
 105   // slow case directly. Leaves condition codes set for C2's Fast_Lock node.
 106   // Returns offset of first potentially-faulting instruction for null
 107   // check info (currently consumed only by C1). If
 108   // swap_reg_contains_mark is true then returns -1 as it is assumed
 109   // the calling code has already passed any potential faults.
 110   int biased_locking_enter(Register lock_reg, Register obj_reg,
 111                            Register swap_reg, Register tmp_reg,
 112                            bool swap_reg_contains_mark,
 113                            Label& done, Label* slow_case = NULL,
 114                            BiasedLockingCounters* counters = NULL);
 115   void biased_locking_exit (Register obj_reg, Register temp_reg, Label& done);
 116 
 117 
 118   // Helper functions for statistics gathering.
 119   // Unconditional atomic increment.
 120   void atomic_incw(Register counter_addr, Register tmp, Register tmp2);
 121   void atomic_incw(Address counter_addr, Register tmp1, Register tmp2, Register tmp3) {
 122     lea(tmp1, counter_addr);
 123     atomic_incw(tmp1, tmp2, tmp3);
 124   }
 125   // Load Effective Address
 126   void lea(Register r, const Address &a) {
 127     InstructionMark im(this);
 128     code_section()->relocate(inst_mark(), a.rspec());
 129     a.lea(this, r);
 130   }
 131 
 132   void addmw(Address a, Register incr, Register scratch) {
 133     ldrw(scratch, a);
 134     addw(scratch, scratch, incr);
 135     strw(scratch, a);
 136   }
 137 
 138   // Add constant to memory word
 139   void addmw(Address a, int imm, Register scratch) {
 140     ldrw(scratch, a);
 141     if (imm > 0)
 142       addw(scratch, scratch, (unsigned)imm);
 143     else
 144       subw(scratch, scratch, (unsigned)-imm);
 145     strw(scratch, a);
 146   }
 147 
 148   void bind(Label& L) {
 149     Assembler::bind(L);
 150     code()->clear_last_membar();
 151   }
 152 
 153   void membar(Membar_mask_bits order_constraint);
 154 
 155   // Frame creation and destruction shared between JITs.
 156   void build_frame(int framesize);
 157   void remove_frame(int framesize);
 158 
 159   virtual void _call_Unimplemented(address call_site) {
 160     mov(rscratch2, call_site);
 161     haltsim();
 162   }
 163 
 164 #define call_Unimplemented() _call_Unimplemented((address)__PRETTY_FUNCTION__)
 165 
 166   virtual void notify(int type);
 167 
 168   // aliases defined in AARCH64 spec
 169 
 170   template<class T>
 171   inline void cmpw(Register Rd, T imm)  { subsw(zr, Rd, imm); }
 172   inline void cmp(Register Rd, unsigned imm)  { subs(zr, Rd, imm); }
 173 
 174   inline void cmnw(Register Rd, unsigned imm) { addsw(zr, Rd, imm); }
 175   inline void cmn(Register Rd, unsigned imm) { adds(zr, Rd, imm); }
 176 
 177   void cset(Register Rd, Assembler::Condition cond) {
 178     csinc(Rd, zr, zr, ~cond);
 179   }
 180   void csetw(Register Rd, Assembler::Condition cond) {
 181     csincw(Rd, zr, zr, ~cond);
 182   }
 183 
 184   void cneg(Register Rd, Register Rn, Assembler::Condition cond) {
 185     csneg(Rd, Rn, Rn, ~cond);
 186   }
 187   void cnegw(Register Rd, Register Rn, Assembler::Condition cond) {
 188     csnegw(Rd, Rn, Rn, ~cond);
 189   }
 190 
 191   inline void movw(Register Rd, Register Rn) {
 192     if (Rd == sp || Rn == sp) {
 193       addw(Rd, Rn, 0U);
 194     } else {
 195       orrw(Rd, zr, Rn);
 196     }
 197   }
 198   inline void mov(Register Rd, Register Rn) {
 199     assert(Rd != r31_sp && Rn != r31_sp, "should be");
 200     if (Rd == Rn) {
 201     } else if (Rd == sp || Rn == sp) {
 202       add(Rd, Rn, 0U);
 203     } else {
 204       orr(Rd, zr, Rn);
 205     }
 206   }
 207 
 208   inline void moviw(Register Rd, unsigned imm) { orrw(Rd, zr, imm); }
 209   inline void movi(Register Rd, unsigned imm) { orr(Rd, zr, imm); }
 210 
 211   inline void tstw(Register Rd, Register Rn) { andsw(zr, Rd, Rn); }
 212   inline void tst(Register Rd, Register Rn) { ands(zr, Rd, Rn); }
 213 
 214   inline void tstw(Register Rd, uint64_t imm) { andsw(zr, Rd, imm); }
 215   inline void tst(Register Rd, uint64_t imm) { ands(zr, Rd, imm); }
 216 
 217   inline void bfiw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 218     bfmw(Rd, Rn, ((32 - lsb) & 31), (width - 1));
 219   }
 220   inline void bfi(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 221     bfm(Rd, Rn, ((64 - lsb) & 63), (width - 1));
 222   }
 223 
 224   inline void bfxilw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 225     bfmw(Rd, Rn, lsb, (lsb + width - 1));
 226   }
 227   inline void bfxil(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 228     bfm(Rd, Rn, lsb , (lsb + width - 1));
 229   }
 230 
 231   inline void sbfizw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 232     sbfmw(Rd, Rn, ((32 - lsb) & 31), (width - 1));
 233   }
 234   inline void sbfiz(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 235     sbfm(Rd, Rn, ((64 - lsb) & 63), (width - 1));
 236   }
 237 
 238   inline void sbfxw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 239     sbfmw(Rd, Rn, lsb, (lsb + width - 1));
 240   }
 241   inline void sbfx(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 242     sbfm(Rd, Rn, lsb , (lsb + width - 1));
 243   }
 244 
 245   inline void ubfizw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 246     ubfmw(Rd, Rn, ((32 - lsb) & 31), (width - 1));
 247   }
 248   inline void ubfiz(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 249     ubfm(Rd, Rn, ((64 - lsb) & 63), (width - 1));
 250   }
 251 
 252   inline void ubfxw(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 253     ubfmw(Rd, Rn, lsb, (lsb + width - 1));
 254   }
 255   inline void ubfx(Register Rd, Register Rn, unsigned lsb, unsigned width) {
 256     ubfm(Rd, Rn, lsb , (lsb + width - 1));
 257   }
 258 
 259   inline void asrw(Register Rd, Register Rn, unsigned imm) {
 260     sbfmw(Rd, Rn, imm, 31);
 261   }
 262 
 263   inline void asr(Register Rd, Register Rn, unsigned imm) {
 264     sbfm(Rd, Rn, imm, 63);
 265   }
 266 
 267   inline void lslw(Register Rd, Register Rn, unsigned imm) {
 268     ubfmw(Rd, Rn, ((32 - imm) & 31), (31 - imm));
 269   }
 270 
 271   inline void lsl(Register Rd, Register Rn, unsigned imm) {
 272     ubfm(Rd, Rn, ((64 - imm) & 63), (63 - imm));
 273   }
 274 
 275   inline void lsrw(Register Rd, Register Rn, unsigned imm) {
 276     ubfmw(Rd, Rn, imm, 31);
 277   }
 278 
 279   inline void lsr(Register Rd, Register Rn, unsigned imm) {
 280     ubfm(Rd, Rn, imm, 63);
 281   }
 282 
 283   inline void rorw(Register Rd, Register Rn, unsigned imm) {
 284     extrw(Rd, Rn, Rn, imm);
 285   }
 286 
 287   inline void ror(Register Rd, Register Rn, unsigned imm) {
 288     extr(Rd, Rn, Rn, imm);
 289   }
 290 
 291   inline void sxtbw(Register Rd, Register Rn) {
 292     sbfmw(Rd, Rn, 0, 7);
 293   }
 294   inline void sxthw(Register Rd, Register Rn) {
 295     sbfmw(Rd, Rn, 0, 15);
 296   }
 297   inline void sxtb(Register Rd, Register Rn) {
 298     sbfm(Rd, Rn, 0, 7);
 299   }
 300   inline void sxth(Register Rd, Register Rn) {
 301     sbfm(Rd, Rn, 0, 15);
 302   }
 303   inline void sxtw(Register Rd, Register Rn) {
 304     sbfm(Rd, Rn, 0, 31);
 305   }
 306 
 307   inline void uxtbw(Register Rd, Register Rn) {
 308     ubfmw(Rd, Rn, 0, 7);
 309   }
 310   inline void uxthw(Register Rd, Register Rn) {
 311     ubfmw(Rd, Rn, 0, 15);
 312   }
 313   inline void uxtb(Register Rd, Register Rn) {
 314     ubfm(Rd, Rn, 0, 7);
 315   }
 316   inline void uxth(Register Rd, Register Rn) {
 317     ubfm(Rd, Rn, 0, 15);
 318   }
 319   inline void uxtw(Register Rd, Register Rn) {
 320     ubfm(Rd, Rn, 0, 31);
 321   }
 322 
 323   inline void cmnw(Register Rn, Register Rm) {
 324     addsw(zr, Rn, Rm);
 325   }
 326   inline void cmn(Register Rn, Register Rm) {
 327     adds(zr, Rn, Rm);
 328   }
 329 
 330   inline void cmpw(Register Rn, Register Rm) {
 331     subsw(zr, Rn, Rm);
 332   }
 333   inline void cmp(Register Rn, Register Rm) {
 334     subs(zr, Rn, Rm);
 335   }
 336 
 337   inline void negw(Register Rd, Register Rn) {
 338     subw(Rd, zr, Rn);
 339   }
 340 
 341   inline void neg(Register Rd, Register Rn) {
 342     sub(Rd, zr, Rn);
 343   }
 344 
 345   inline void negsw(Register Rd, Register Rn) {
 346     subsw(Rd, zr, Rn);
 347   }
 348 
 349   inline void negs(Register Rd, Register Rn) {
 350     subs(Rd, zr, Rn);
 351   }
 352 
 353   inline void cmnw(Register Rn, Register Rm, enum shift_kind kind, unsigned shift = 0) {
 354     addsw(zr, Rn, Rm, kind, shift);
 355   }
 356   inline void cmn(Register Rn, Register Rm, enum shift_kind kind, unsigned shift = 0) {
 357     adds(zr, Rn, Rm, kind, shift);
 358   }
 359 
 360   inline void cmpw(Register Rn, Register Rm, enum shift_kind kind, unsigned shift = 0) {
 361     subsw(zr, Rn, Rm, kind, shift);
 362   }
 363   inline void cmp(Register Rn, Register Rm, enum shift_kind kind, unsigned shift = 0) {
 364     subs(zr, Rn, Rm, kind, shift);
 365   }
 366 
 367   inline void negw(Register Rd, Register Rn, enum shift_kind kind, unsigned shift = 0) {
 368     subw(Rd, zr, Rn, kind, shift);
 369   }
 370 
 371   inline void neg(Register Rd, Register Rn, enum shift_kind kind, unsigned shift = 0) {
 372     sub(Rd, zr, Rn, kind, shift);
 373   }
 374 
 375   inline void negsw(Register Rd, Register Rn, enum shift_kind kind, unsigned shift = 0) {
 376     subsw(Rd, zr, Rn, kind, shift);
 377   }
 378 
 379   inline void negs(Register Rd, Register Rn, enum shift_kind kind, unsigned shift = 0) {
 380     subs(Rd, zr, Rn, kind, shift);
 381   }
 382 
 383   inline void mnegw(Register Rd, Register Rn, Register Rm) {
 384     msubw(Rd, Rn, Rm, zr);
 385   }
 386   inline void mneg(Register Rd, Register Rn, Register Rm) {
 387     msub(Rd, Rn, Rm, zr);
 388   }
 389 
 390   inline void mulw(Register Rd, Register Rn, Register Rm) {
 391     maddw(Rd, Rn, Rm, zr);
 392   }
 393   inline void mul(Register Rd, Register Rn, Register Rm) {
 394     madd(Rd, Rn, Rm, zr);
 395   }
 396 
 397   inline void smnegl(Register Rd, Register Rn, Register Rm) {
 398     smsubl(Rd, Rn, Rm, zr);
 399   }
 400   inline void smull(Register Rd, Register Rn, Register Rm) {
 401     smaddl(Rd, Rn, Rm, zr);
 402   }
 403 
 404   inline void umnegl(Register Rd, Register Rn, Register Rm) {
 405     umsubl(Rd, Rn, Rm, zr);
 406   }
 407   inline void umull(Register Rd, Register Rn, Register Rm) {
 408     umaddl(Rd, Rn, Rm, zr);
 409   }
 410 
 411 #define WRAP(INSN)                                                            \
 412   void INSN(Register Rd, Register Rn, Register Rm, Register Ra) {             \
 413     if ((VM_Version::features() & VM_Version::CPU_A53MAC) && Ra != zr)        \
 414       nop();                                                                  \
 415     Assembler::INSN(Rd, Rn, Rm, Ra);                                          \
 416   }
 417 
 418   WRAP(madd) WRAP(msub) WRAP(maddw) WRAP(msubw)
 419   WRAP(smaddl) WRAP(smsubl) WRAP(umaddl) WRAP(umsubl)
 420 #undef WRAP
 421 
 422 
 423   // macro assembly operations needed for aarch64
 424 
 425   // first two private routines for loading 32 bit or 64 bit constants
 426 private:
 427 
 428   void mov_immediate64(Register dst, u_int64_t imm64);
 429   void mov_immediate32(Register dst, u_int32_t imm32);
 430 
 431   int push(unsigned int bitset, Register stack);
 432   int pop(unsigned int bitset, Register stack);
 433 
 434   void mov(Register dst, Address a);
 435 
 436 public:
 437   void push(RegSet regs, Register stack) { if (regs.bits()) push(regs.bits(), stack); }
 438   void pop(RegSet regs, Register stack) { if (regs.bits()) pop(regs.bits(), stack); }
 439 
 440   // Push and pop everything that might be clobbered by a native
 441   // runtime call except rscratch1 and rscratch2.  (They are always
 442   // scratch, so we don't have to protect them.)  Only save the lower
 443   // 64 bits of each vector register.
 444   void push_call_clobbered_registers();
 445   void pop_call_clobbered_registers();
 446 
 447   // now mov instructions for loading absolute addresses and 32 or
 448   // 64 bit integers
 449 
 450   inline void mov(Register dst, address addr)
 451   {
 452     mov_immediate64(dst, (u_int64_t)addr);
 453   }
 454 
 455   inline void mov(Register dst, u_int64_t imm64)
 456   {
 457     mov_immediate64(dst, imm64);
 458   }
 459 
 460   inline void movw(Register dst, u_int32_t imm32)
 461   {
 462     mov_immediate32(dst, imm32);
 463   }
 464 
 465   inline void mov(Register dst, long l)
 466   {
 467     mov(dst, (u_int64_t)l);
 468   }
 469 
 470   inline void mov(Register dst, int i)
 471   {
 472     mov(dst, (long)i);
 473   }
 474 
 475   void mov(Register dst, RegisterOrConstant src) {
 476     if (src.is_register())
 477       mov(dst, src.as_register());
 478     else
 479       mov(dst, src.as_constant());
 480   }
 481 
 482   void movptr(Register r, uintptr_t imm64);
 483 
 484   void mov(FloatRegister Vd, SIMD_Arrangement T, u_int32_t imm32);
 485 
 486   void mov(FloatRegister Vd, SIMD_Arrangement T, FloatRegister Vn) {
 487     orr(Vd, T, Vn, Vn);
 488   }
 489 
 490 public:
 491 
 492   // Generalized Test Bit And Branch, including a "far" variety which
 493   // spans more than 32KiB.
 494   void tbr(Condition cond, Register Rt, int bitpos, Label &dest, bool far = false) {
 495     assert(cond == EQ || cond == NE, "must be");
 496 
 497     if (far)
 498       cond = ~cond;
 499 
 500     void (Assembler::* branch)(Register Rt, int bitpos, Label &L);
 501     if (cond == Assembler::EQ)
 502       branch = &Assembler::tbz;
 503     else
 504       branch = &Assembler::tbnz;
 505 
 506     if (far) {
 507       Label L;
 508       (this->*branch)(Rt, bitpos, L);
 509       b(dest);
 510       bind(L);
 511     } else {
 512       (this->*branch)(Rt, bitpos, dest);
 513     }
 514   }
 515 
 516   // macro instructions for accessing and updating floating point
 517   // status register
 518   //
 519   // FPSR : op1 == 011
 520   //        CRn == 0100
 521   //        CRm == 0100
 522   //        op2 == 001
 523 
 524   inline void get_fpsr(Register reg)
 525   {
 526     mrs(0b11, 0b0100, 0b0100, 0b001, reg);
 527   }
 528 
 529   inline void set_fpsr(Register reg)
 530   {
 531     msr(0b011, 0b0100, 0b0100, 0b001, reg);
 532   }
 533 
 534   inline void clear_fpsr()
 535   {
 536     msr(0b011, 0b0100, 0b0100, 0b001, zr);
 537   }
 538 
 539   // DCZID_EL0: op1 == 011
 540   //            CRn == 0000
 541   //            CRm == 0000
 542   //            op2 == 111
 543   inline void get_dczid_el0(Register reg)
 544   {
 545     mrs(0b011, 0b0000, 0b0000, 0b111, reg);
 546   }
 547 
 548   // idiv variant which deals with MINLONG as dividend and -1 as divisor
 549   int corrected_idivl(Register result, Register ra, Register rb,
 550                       bool want_remainder, Register tmp = rscratch1);
 551   int corrected_idivq(Register result, Register ra, Register rb,
 552                       bool want_remainder, Register tmp = rscratch1);
 553 
 554   // Support for NULL-checks
 555   //
 556   // Generates code that causes a NULL OS exception if the content of reg is NULL.
 557   // If the accessed location is M[reg + offset] and the offset is known, provide the
 558   // offset. No explicit code generation is needed if the offset is within a certain
 559   // range (0 <= offset <= page_size).
 560 
 561   virtual void null_check(Register reg, int offset = -1);
 562   static bool needs_explicit_null_check(intptr_t offset);
 563 
 564   static address target_addr_for_insn(address insn_addr, unsigned insn);
 565   static address target_addr_for_insn(address insn_addr) {
 566     unsigned insn = *(unsigned*)insn_addr;
 567     return target_addr_for_insn(insn_addr, insn);
 568   }
 569 
 570   // Required platform-specific helpers for Label::patch_instructions.
 571   // They _shadow_ the declarations in AbstractAssembler, which are undefined.
 572   static int pd_patch_instruction_size(address branch, address target);
 573   static void pd_patch_instruction(address branch, address target) {
 574     pd_patch_instruction_size(branch, target);
 575   }
 576   static address pd_call_destination(address branch) {
 577     return target_addr_for_insn(branch);
 578   }
 579 #ifndef PRODUCT
 580   static void pd_print_patched_instruction(address branch);
 581 #endif
 582 
 583   static int patch_oop(address insn_addr, address o);
 584 
 585   address emit_trampoline_stub(int insts_call_instruction_offset, address target);
 586 
 587   // The following 4 methods return the offset of the appropriate move instruction
 588 
 589   // Support for fast byte/short loading with zero extension (depending on particular CPU)
 590   int load_unsigned_byte(Register dst, Address src);
 591   int load_unsigned_short(Register dst, Address src);
 592 
 593   // Support for fast byte/short loading with sign extension (depending on particular CPU)
 594   int load_signed_byte(Register dst, Address src);
 595   int load_signed_short(Register dst, Address src);
 596 
 597   int load_signed_byte32(Register dst, Address src);
 598   int load_signed_short32(Register dst, Address src);
 599 
 600   // Support for sign-extension (hi:lo = extend_sign(lo))
 601   void extend_sign(Register hi, Register lo);
 602 
 603   // Load and store values by size and signed-ness
 604   void load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed, Register dst2 = noreg);
 605   void store_sized_value(Address dst, Register src, size_t size_in_bytes, Register src2 = noreg);
 606 
 607   // Support for inc/dec with optimal instruction selection depending on value
 608 
 609   // x86_64 aliases an unqualified register/address increment and
 610   // decrement to call incrementq and decrementq but also supports
 611   // explicitly sized calls to incrementq/decrementq or
 612   // incrementl/decrementl
 613 
 614   // for aarch64 the proper convention would be to use
 615   // increment/decrement for 64 bit operatons and
 616   // incrementw/decrementw for 32 bit operations. so when porting
 617   // x86_64 code we can leave calls to increment/decrement as is,
 618   // replace incrementq/decrementq with increment/decrement and
 619   // replace incrementl/decrementl with incrementw/decrementw.
 620 
 621   // n.b. increment/decrement calls with an Address destination will
 622   // need to use a scratch register to load the value to be
 623   // incremented. increment/decrement calls which add or subtract a
 624   // constant value greater than 2^12 will need to use a 2nd scratch
 625   // register to hold the constant. so, a register increment/decrement
 626   // may trash rscratch2 and an address increment/decrement trash
 627   // rscratch and rscratch2
 628 
 629   void decrementw(Address dst, int value = 1);
 630   void decrementw(Register reg, int value = 1);
 631 
 632   void decrement(Register reg, int value = 1);
 633   void decrement(Address dst, int value = 1);
 634 
 635   void incrementw(Address dst, int value = 1);
 636   void incrementw(Register reg, int value = 1);
 637 
 638   void increment(Register reg, int value = 1);
 639   void increment(Address dst, int value = 1);
 640 
 641 
 642   // Alignment
 643   void align(int modulus);
 644 
 645   // Stack frame creation/removal
 646   void enter()
 647   {
 648     stp(rfp, lr, Address(pre(sp, -2 * wordSize)));
 649     mov(rfp, sp);
 650   }
 651   void leave()
 652   {
 653     mov(sp, rfp);
 654     ldp(rfp, lr, Address(post(sp, 2 * wordSize)));
 655   }
 656 
 657   // Support for getting the JavaThread pointer (i.e.; a reference to thread-local information)
 658   // The pointer will be loaded into the thread register.
 659   void get_thread(Register thread);
 660 
 661 
 662   // Support for VM calls
 663   //
 664   // It is imperative that all calls into the VM are handled via the call_VM macros.
 665   // They make sure that the stack linkage is setup correctly. call_VM's correspond
 666   // to ENTRY/ENTRY_X entry points while call_VM_leaf's correspond to LEAF entry points.
 667 
 668 
 669   void call_VM(Register oop_result,
 670                address entry_point,
 671                bool check_exceptions = true);
 672   void call_VM(Register oop_result,
 673                address entry_point,
 674                Register arg_1,
 675                bool check_exceptions = true);
 676   void call_VM(Register oop_result,
 677                address entry_point,
 678                Register arg_1, Register arg_2,
 679                bool check_exceptions = true);
 680   void call_VM(Register oop_result,
 681                address entry_point,
 682                Register arg_1, Register arg_2, Register arg_3,
 683                bool check_exceptions = true);
 684 
 685   // Overloadings with last_Java_sp
 686   void call_VM(Register oop_result,
 687                Register last_java_sp,
 688                address entry_point,
 689                int number_of_arguments = 0,
 690                bool check_exceptions = true);
 691   void call_VM(Register oop_result,
 692                Register last_java_sp,
 693                address entry_point,
 694                Register arg_1, bool
 695                check_exceptions = true);
 696   void call_VM(Register oop_result,
 697                Register last_java_sp,
 698                address entry_point,
 699                Register arg_1, Register arg_2,
 700                bool check_exceptions = true);
 701   void call_VM(Register oop_result,
 702                Register last_java_sp,
 703                address entry_point,
 704                Register arg_1, Register arg_2, Register arg_3,
 705                bool check_exceptions = true);
 706 
 707   void get_vm_result  (Register oop_result, Register thread);
 708   void get_vm_result_2(Register metadata_result, Register thread);
 709 
 710   // These always tightly bind to MacroAssembler::call_VM_base
 711   // bypassing the virtual implementation
 712   void super_call_VM(Register oop_result, Register last_java_sp, address entry_point, int number_of_arguments = 0, bool check_exceptions = true);
 713   void super_call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions = true);
 714   void super_call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
 715   void super_call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true);
 716   void super_call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, Register arg_4, bool check_exceptions = true);
 717 
 718   void call_VM_leaf(address entry_point,
 719                     int number_of_arguments = 0);
 720   void call_VM_leaf(address entry_point,
 721                     Register arg_1);
 722   void call_VM_leaf(address entry_point,
 723                     Register arg_1, Register arg_2);
 724   void call_VM_leaf(address entry_point,
 725                     Register arg_1, Register arg_2, Register arg_3);
 726 
 727   // These always tightly bind to MacroAssembler::call_VM_leaf_base
 728   // bypassing the virtual implementation
 729   void super_call_VM_leaf(address entry_point);
 730   void super_call_VM_leaf(address entry_point, Register arg_1);
 731   void super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2);
 732   void super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3);
 733   void super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3, Register arg_4);
 734 
 735   // last Java Frame (fills frame anchor)
 736   void set_last_Java_frame(Register last_java_sp,
 737                            Register last_java_fp,
 738                            address last_java_pc,
 739                            Register scratch);
 740 
 741   void set_last_Java_frame(Register last_java_sp,
 742                            Register last_java_fp,
 743                            Label &last_java_pc,
 744                            Register scratch);
 745 
 746   void set_last_Java_frame(Register last_java_sp,
 747                            Register last_java_fp,
 748                            Register last_java_pc,
 749                            Register scratch);
 750 
 751   void reset_last_Java_frame(Register thread, bool clearfp, bool clear_pc);
 752 
 753   // thread in the default location (r15_thread on 64bit)
 754   void reset_last_Java_frame(bool clear_fp, bool clear_pc);
 755 
 756   // Stores
 757   void store_check(Register obj);                // store check for obj - register is destroyed afterwards
 758   void store_check(Register obj, Address dst);   // same as above, dst is exact store location (reg. is destroyed)
 759 
 760 #if INCLUDE_ALL_GCS
 761 
 762   void g1_write_barrier_pre(Register obj,
 763                             Register pre_val,
 764                             Register thread,
 765                             Register tmp,
 766                             bool tosca_live,
 767                             bool expand_call);
 768 
 769   void g1_write_barrier_post(Register store_addr,
 770                              Register new_val,
 771                              Register thread,
 772                              Register tmp,
 773                              Register tmp2);
 774 
 775 #endif // INCLUDE_ALL_GCS
 776 
 777   // oop manipulations
 778   void load_klass(Register dst, Register src);
 779   void store_klass(Register dst, Register src);
 780   void cmp_klass(Register oop, Register trial_klass, Register tmp);
 781 
 782   void load_mirror(Register dst, Register method);
 783 
 784   void load_heap_oop(Register dst, Address src);
 785 
 786   void load_heap_oop_not_null(Register dst, Address src);
 787   void store_heap_oop(Address dst, Register src);
 788 
 789   // currently unimplemented
 790   // Used for storing NULL. All other oop constants should be
 791   // stored using routines that take a jobject.
 792   void store_heap_oop_null(Address dst);
 793 
 794   void load_prototype_header(Register dst, Register src);
 795 
 796   void store_klass_gap(Register dst, Register src);
 797 
 798   // This dummy is to prevent a call to store_heap_oop from
 799   // converting a zero (like NULL) into a Register by giving
 800   // the compiler two choices it can't resolve
 801 
 802   void store_heap_oop(Address dst, void* dummy);
 803 
 804   void encode_heap_oop(Register d, Register s);
 805   void encode_heap_oop(Register r) { encode_heap_oop(r, r); }
 806   void decode_heap_oop(Register d, Register s);
 807   void decode_heap_oop(Register r) { decode_heap_oop(r, r); }
 808   void encode_heap_oop_not_null(Register r);
 809   void decode_heap_oop_not_null(Register r);
 810   void encode_heap_oop_not_null(Register dst, Register src);
 811   void decode_heap_oop_not_null(Register dst, Register src);
 812 
 813   void set_narrow_oop(Register dst, jobject obj);
 814 
 815   void encode_klass_not_null(Register r);
 816   void decode_klass_not_null(Register r);
 817   void encode_klass_not_null(Register dst, Register src);
 818   void decode_klass_not_null(Register dst, Register src);
 819 
 820   void set_narrow_klass(Register dst, Klass* k);
 821 
 822   // if heap base register is used - reinit it with the correct value
 823   void reinit_heapbase();
 824 
 825   DEBUG_ONLY(void verify_heapbase(const char* msg);)
 826 
 827   void push_CPU_state(bool save_vectors = false);
 828   void pop_CPU_state(bool restore_vectors = false) ;
 829 
 830   // Round up to a power of two
 831   void round_to(Register reg, int modulus);
 832 
 833   // allocation
 834   void eden_allocate(
 835     Register obj,                      // result: pointer to object after successful allocation
 836     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 837     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 838     Register t1,                       // temp register
 839     Label&   slow_case                 // continuation point if fast allocation fails
 840   );
 841   void tlab_allocate(
 842     Register obj,                      // result: pointer to object after successful allocation
 843     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 844     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 845     Register t1,                       // temp register
 846     Register t2,                       // temp register
 847     Label&   slow_case                 // continuation point if fast allocation fails
 848   );
 849   Register tlab_refill(Label& retry_tlab, Label& try_eden, Label& slow_case); // returns TLS address
 850   void verify_tlab();
 851 
 852   void incr_allocated_bytes(Register thread,
 853                             Register var_size_in_bytes, int con_size_in_bytes,
 854                             Register t1 = noreg);
 855 
 856   // interface method calling
 857   void lookup_interface_method(Register recv_klass,
 858                                Register intf_klass,
 859                                RegisterOrConstant itable_index,
 860                                Register method_result,
 861                                Register scan_temp,
 862                                Label& no_such_interface);
 863 
 864   // virtual method calling
 865   // n.b. x86 allows RegisterOrConstant for vtable_index
 866   void lookup_virtual_method(Register recv_klass,
 867                              RegisterOrConstant vtable_index,
 868                              Register method_result);
 869 
 870   // Test sub_klass against super_klass, with fast and slow paths.
 871 
 872   // The fast path produces a tri-state answer: yes / no / maybe-slow.
 873   // One of the three labels can be NULL, meaning take the fall-through.
 874   // If super_check_offset is -1, the value is loaded up from super_klass.
 875   // No registers are killed, except temp_reg.
 876   void check_klass_subtype_fast_path(Register sub_klass,
 877                                      Register super_klass,
 878                                      Register temp_reg,
 879                                      Label* L_success,
 880                                      Label* L_failure,
 881                                      Label* L_slow_path,
 882                 RegisterOrConstant super_check_offset = RegisterOrConstant(-1));
 883 
 884   // The rest of the type check; must be wired to a corresponding fast path.
 885   // It does not repeat the fast path logic, so don't use it standalone.
 886   // The temp_reg and temp2_reg can be noreg, if no temps are available.
 887   // Updates the sub's secondary super cache as necessary.
 888   // If set_cond_codes, condition codes will be Z on success, NZ on failure.
 889   void check_klass_subtype_slow_path(Register sub_klass,
 890                                      Register super_klass,
 891                                      Register temp_reg,
 892                                      Register temp2_reg,
 893                                      Label* L_success,
 894                                      Label* L_failure,
 895                                      bool set_cond_codes = false);
 896 
 897   // Simplified, combined version, good for typical uses.
 898   // Falls through on failure.
 899   void check_klass_subtype(Register sub_klass,
 900                            Register super_klass,
 901                            Register temp_reg,
 902                            Label& L_success);
 903 
 904   Address argument_address(RegisterOrConstant arg_slot, int extra_slot_offset = 0);
 905 
 906 
 907   // Debugging
 908 
 909   // only if +VerifyOops
 910   void verify_oop(Register reg, const char* s = "broken oop");
 911   void verify_oop_addr(Address addr, const char * s = "broken oop addr");
 912 
 913 // TODO: verify method and klass metadata (compare against vptr?)
 914   void _verify_method_ptr(Register reg, const char * msg, const char * file, int line) {}
 915   void _verify_klass_ptr(Register reg, const char * msg, const char * file, int line){}
 916 
 917 #define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)
 918 #define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)
 919 
 920   // only if +VerifyFPU
 921   void verify_FPU(int stack_depth, const char* s = "illegal FPU state");
 922 
 923   // prints msg, dumps registers and stops execution
 924   void stop(const char* msg);
 925 
 926   // prints msg and continues
 927   void warn(const char* msg);
 928 
 929   static void debug64(char* msg, int64_t pc, int64_t regs[]);
 930 
 931   void untested()                                { stop("untested"); }
 932 
 933   void unimplemented(const char* what = "")      { char* b = new char[1024];  jio_snprintf(b, 1024, "unimplemented: %s", what);  stop(b); }
 934 
 935   void should_not_reach_here()                   { stop("should not reach here"); }
 936 
 937   // Stack overflow checking
 938   void bang_stack_with_offset(int offset) {
 939     // stack grows down, caller passes positive offset
 940     assert(offset > 0, "must bang with negative offset");
 941     mov(rscratch2, -offset);
 942     str(zr, Address(sp, rscratch2));
 943   }
 944 
 945   // Writes to stack successive pages until offset reached to check for
 946   // stack overflow + shadow pages.  Also, clobbers tmp
 947   void bang_stack_size(Register size, Register tmp);
 948 
 949   virtual RegisterOrConstant delayed_value_impl(intptr_t* delayed_value_addr,
 950                                                 Register tmp,
 951                                                 int offset);
 952 
 953   // Support for serializing memory accesses between threads
 954   void serialize_memory(Register thread, Register tmp);
 955 
 956   // Arithmetics
 957 
 958   void addptr(const Address &dst, int32_t src);
 959   void cmpptr(Register src1, Address src2);
 960 
 961   // Various forms of CAS
 962 
 963   void cmpxchgptr(Register oldv, Register newv, Register addr, Register tmp,
 964                   Label &suceed, Label *fail);
 965 
 966   void cmpxchgw(Register oldv, Register newv, Register addr, Register tmp,
 967                   Label &suceed, Label *fail);
 968 
 969   void atomic_add(Register prev, RegisterOrConstant incr, Register addr);
 970   void atomic_addw(Register prev, RegisterOrConstant incr, Register addr);
 971   void atomic_addal(Register prev, RegisterOrConstant incr, Register addr);
 972   void atomic_addalw(Register prev, RegisterOrConstant incr, Register addr);
 973 
 974   void atomic_xchg(Register prev, Register newv, Register addr);
 975   void atomic_xchgw(Register prev, Register newv, Register addr);
 976   void atomic_xchgal(Register prev, Register newv, Register addr);
 977   void atomic_xchgalw(Register prev, Register newv, Register addr);
 978 
 979   void orptr(Address adr, RegisterOrConstant src) {
 980     ldr(rscratch2, adr);
 981     if (src.is_register())
 982       orr(rscratch2, rscratch2, src.as_register());
 983     else
 984       orr(rscratch2, rscratch2, src.as_constant());
 985     str(rscratch2, adr);
 986   }
 987 
 988   // A generic CAS; success or failure is in the EQ flag.
 989   void cmpxchg(Register addr, Register expected, Register new_val,
 990                enum operand_size size,
 991                bool acquire, bool release,
 992                Register tmp = rscratch1);
 993 
 994   // Calls
 995 
 996   address trampoline_call(Address entry, CodeBuffer *cbuf = NULL);
 997 
 998   static bool far_branches() {
 999     return ReservedCodeCacheSize > branch_range;
1000   }
1001 
1002   // Jumps that can reach anywhere in the code cache.
1003   // Trashes tmp.
1004   void far_call(Address entry, CodeBuffer *cbuf = NULL, Register tmp = rscratch1);
1005   void far_jump(Address entry, CodeBuffer *cbuf = NULL, Register tmp = rscratch1);
1006 
1007   static int far_branch_size() {
1008     if (far_branches()) {
1009       return 3 * 4;  // adrp, add, br
1010     } else {
1011       return 4;
1012     }
1013   }
1014 
1015   // Emit the CompiledIC call idiom
1016   address ic_call(address entry, jint method_index = 0);
1017 
1018 public:
1019 
1020   // Data
1021 
1022   void mov_metadata(Register dst, Metadata* obj);
1023   Address allocate_metadata_address(Metadata* obj);
1024   Address constant_oop_address(jobject obj);
1025 
1026   void movoop(Register dst, jobject obj, bool immediate = false);
1027 
1028   // CRC32 code for java.util.zip.CRC32::updateBytes() instrinsic.
1029   void kernel_crc32(Register crc, Register buf, Register len,
1030         Register table0, Register table1, Register table2, Register table3,
1031         Register tmp, Register tmp2, Register tmp3);
1032   // CRC32 code for java.util.zip.CRC32C::updateBytes() instrinsic.
1033   void kernel_crc32c(Register crc, Register buf, Register len,
1034         Register table0, Register table1, Register table2, Register table3,
1035         Register tmp, Register tmp2, Register tmp3);
1036 
1037   // Stack push and pop individual 64 bit registers
1038   void push(Register src);
1039   void pop(Register dst);
1040 
1041   // push all registers onto the stack
1042   void pusha();
1043   void popa();
1044 
1045   void repne_scan(Register addr, Register value, Register count,
1046                   Register scratch);
1047   void repne_scanw(Register addr, Register value, Register count,
1048                    Register scratch);
1049 
1050   typedef void (MacroAssembler::* add_sub_imm_insn)(Register Rd, Register Rn, unsigned imm);
1051   typedef void (MacroAssembler::* add_sub_reg_insn)(Register Rd, Register Rn, Register Rm, enum shift_kind kind, unsigned shift);
1052 
1053   // If a constant does not fit in an immediate field, generate some
1054   // number of MOV instructions and then perform the operation
1055   void wrap_add_sub_imm_insn(Register Rd, Register Rn, unsigned imm,
1056                              add_sub_imm_insn insn1,
1057                              add_sub_reg_insn insn2);
1058   // Seperate vsn which sets the flags
1059   void wrap_adds_subs_imm_insn(Register Rd, Register Rn, unsigned imm,
1060                              add_sub_imm_insn insn1,
1061                              add_sub_reg_insn insn2);
1062 
1063 #define WRAP(INSN)                                                      \
1064   void INSN(Register Rd, Register Rn, unsigned imm) {                   \
1065     wrap_add_sub_imm_insn(Rd, Rn, imm, &Assembler::INSN, &Assembler::INSN); \
1066   }                                                                     \
1067                                                                         \
1068   void INSN(Register Rd, Register Rn, Register Rm,                      \
1069              enum shift_kind kind, unsigned shift = 0) {                \
1070     Assembler::INSN(Rd, Rn, Rm, kind, shift);                           \
1071   }                                                                     \
1072                                                                         \
1073   void INSN(Register Rd, Register Rn, Register Rm) {                    \
1074     Assembler::INSN(Rd, Rn, Rm);                                        \
1075   }                                                                     \
1076                                                                         \
1077   void INSN(Register Rd, Register Rn, Register Rm,                      \
1078            ext::operation option, int amount = 0) {                     \
1079     Assembler::INSN(Rd, Rn, Rm, option, amount);                        \
1080   }
1081 
1082   WRAP(add) WRAP(addw) WRAP(sub) WRAP(subw)
1083 
1084 #undef WRAP
1085 #define WRAP(INSN)                                                      \
1086   void INSN(Register Rd, Register Rn, unsigned imm) {                   \
1087     wrap_adds_subs_imm_insn(Rd, Rn, imm, &Assembler::INSN, &Assembler::INSN); \
1088   }                                                                     \
1089                                                                         \
1090   void INSN(Register Rd, Register Rn, Register Rm,                      \
1091              enum shift_kind kind, unsigned shift = 0) {                \
1092     Assembler::INSN(Rd, Rn, Rm, kind, shift);                           \
1093   }                                                                     \
1094                                                                         \
1095   void INSN(Register Rd, Register Rn, Register Rm) {                    \
1096     Assembler::INSN(Rd, Rn, Rm);                                        \
1097   }                                                                     \
1098                                                                         \
1099   void INSN(Register Rd, Register Rn, Register Rm,                      \
1100            ext::operation option, int amount = 0) {                     \
1101     Assembler::INSN(Rd, Rn, Rm, option, amount);                        \
1102   }
1103 
1104   WRAP(adds) WRAP(addsw) WRAP(subs) WRAP(subsw)
1105 
1106   void add(Register Rd, Register Rn, RegisterOrConstant increment);
1107   void addw(Register Rd, Register Rn, RegisterOrConstant increment);
1108   void sub(Register Rd, Register Rn, RegisterOrConstant decrement);
1109   void subw(Register Rd, Register Rn, RegisterOrConstant decrement);
1110 
1111   void adrp(Register reg1, const Address &dest, unsigned long &byte_offset);
1112 
1113   void tableswitch(Register index, jint lowbound, jint highbound,
1114                    Label &jumptable, Label &jumptable_end, int stride = 1) {
1115     adr(rscratch1, jumptable);
1116     subsw(rscratch2, index, lowbound);
1117     subsw(zr, rscratch2, highbound - lowbound);
1118     br(Assembler::HS, jumptable_end);
1119     add(rscratch1, rscratch1, rscratch2,
1120         ext::sxtw, exact_log2(stride * Assembler::instruction_size));
1121     br(rscratch1);
1122   }
1123 
1124   // Form an address from base + offset in Rd.  Rd may or may not
1125   // actually be used: you must use the Address that is returned.  It
1126   // is up to you to ensure that the shift provided matches the size
1127   // of your data.
1128   Address form_address(Register Rd, Register base, long byte_offset, int shift);
1129 
1130   // Return true iff an address is within the 48-bit AArch64 address
1131   // space.
1132   bool is_valid_AArch64_address(address a) {
1133     return ((uint64_t)a >> 48) == 0;
1134   }
1135 
1136   // Load the base of the cardtable byte map into reg.
1137   void load_byte_map_base(Register reg);
1138 
1139   // Prolog generator routines to support switch between x86 code and
1140   // generated ARM code
1141 
1142   // routine to generate an x86 prolog for a stub function which
1143   // bootstraps into the generated ARM code which directly follows the
1144   // stub
1145   //
1146 
1147   public:
1148   // enum used for aarch64--x86 linkage to define return type of x86 function
1149   enum ret_type { ret_type_void, ret_type_integral, ret_type_float, ret_type_double};
1150 
1151 #ifdef BUILTIN_SIM
1152   void c_stub_prolog(int gp_arg_count, int fp_arg_count, int ret_type, address *prolog_ptr = NULL);
1153 #else
1154   void c_stub_prolog(int gp_arg_count, int fp_arg_count, int ret_type) { }
1155 #endif
1156 
1157   // special version of call_VM_leaf_base needed for aarch64 simulator
1158   // where we need to specify both the gp and fp arg counts and the
1159   // return type so that the linkage routine from aarch64 to x86 and
1160   // back knows which aarch64 registers to copy to x86 registers and
1161   // which x86 result register to copy back to an aarch64 register
1162 
1163   void call_VM_leaf_base1(
1164     address  entry_point,             // the entry point
1165     int      number_of_gp_arguments,  // the number of gp reg arguments to pass
1166     int      number_of_fp_arguments,  // the number of fp reg arguments to pass
1167     ret_type type,                    // the return type for the call
1168     Label*   retaddr = NULL
1169   );
1170 
1171   void ldr_constant(Register dest, const Address &const_addr) {
1172     if (NearCpool) {
1173       ldr(dest, const_addr);
1174     } else {
1175       unsigned long offset;
1176       adrp(dest, InternalAddress(const_addr.target()), offset);
1177       ldr(dest, Address(dest, offset));
1178     }
1179   }
1180 
1181   address read_polling_page(Register r, address page, relocInfo::relocType rtype);
1182   address read_polling_page(Register r, relocInfo::relocType rtype);
1183 
1184   // CRC32 code for java.util.zip.CRC32::updateBytes() instrinsic.
1185   void update_byte_crc32(Register crc, Register val, Register table);
1186   void update_word_crc32(Register crc, Register v, Register tmp,
1187         Register table0, Register table1, Register table2, Register table3,
1188         bool upper = false);
1189 
1190   void string_compare_simd(Register str1, Register str2,
1191                       Register cnt1, Register cnt2, Register result,
1192                       FloatRegister vtmp1, FloatRegister vtmp2,
1193                       FloatRegister vtmpZ, int ae);
1194   void string_compare(Register str1, Register str2,
1195                       Register cnt1, Register cnt2, Register result,
1196                       Register tmp1, int ae);
1197 
1198   void arrays_equals(Register a1, Register a2,
1199                      Register result, Register cnt1,
1200                      int elem_size, bool is_string);
1201 
1202   void fill_words(Register base, Register cnt, Register value);
1203   void zero_words(Register base, u_int64_t cnt);
1204   void zero_words(Register base, Register cnt);
1205   void block_zero(Register base, Register cnt, bool is_large = false);
1206 
1207   void byte_array_inflate(Register src, Register dst, Register len,
1208                           FloatRegister vtmp1, FloatRegister vtmp2,
1209                           FloatRegister vtmp3, Register tmp4);
1210 
1211   void char_array_compress(Register src, Register dst, Register len,
1212                            FloatRegister tmp1Reg, FloatRegister tmp2Reg,
1213                            FloatRegister tmp3Reg, FloatRegister tmp4Reg,
1214                            Register result);
1215 
1216   void encode_iso_array(Register src, Register dst,
1217                         Register len, Register result,
1218                         FloatRegister Vtmp1, FloatRegister Vtmp2,
1219                         FloatRegister Vtmp3, FloatRegister Vtmp4);
1220   void string_indexof(Register str1, Register str2,
1221                       Register cnt1, Register cnt2,
1222                       Register tmp1, Register tmp2,
1223                       Register tmp3, Register tmp4,
1224                       int int_cnt1, Register result);
1225 private:
1226   void add2_with_carry(Register final_dest_hi, Register dest_hi, Register dest_lo,
1227                        Register src1, Register src2);
1228   void add2_with_carry(Register dest_hi, Register dest_lo, Register src1, Register src2) {
1229     add2_with_carry(dest_hi, dest_hi, dest_lo, src1, src2);
1230   }
1231   void multiply_64_x_64_loop(Register x, Register xstart, Register x_xstart,
1232                              Register y, Register y_idx, Register z,
1233                              Register carry, Register product,
1234                              Register idx, Register kdx);
1235   void multiply_128_x_128_loop(Register y, Register z,
1236                                Register carry, Register carry2,
1237                                Register idx, Register jdx,
1238                                Register yz_idx1, Register yz_idx2,
1239                                Register tmp, Register tmp3, Register tmp4,
1240                                Register tmp7, Register product_hi);
1241 public:
1242   void multiply_to_len(Register x, Register xlen, Register y, Register ylen, Register z,
1243                        Register zlen, Register tmp1, Register tmp2, Register tmp3,
1244                        Register tmp4, Register tmp5, Register tmp6, Register tmp7);
1245   // ISB may be needed because of a safepoint
1246   void maybe_isb() { isb(); }
1247 
1248 private:
1249   // Return the effective address r + (r1 << ext) + offset.
1250   // Uses rscratch2.
1251   Address offsetted_address(Register r, Register r1, Address::extend ext,
1252                             int offset, int size);
1253 
1254 private:
1255   // Returns an address on the stack which is reachable with a ldr/str of size
1256   // Uses rscratch2 if the address is not directly reachable
1257   Address spill_address(int size, int offset, Register tmp=rscratch2);
1258 
1259 public:
1260   void spill(Register Rx, bool is64, int offset) {
1261     if (is64) {
1262       str(Rx, spill_address(8, offset));
1263     } else {
1264       strw(Rx, spill_address(4, offset));
1265     }
1266   }
1267   void spill(FloatRegister Vx, SIMD_RegVariant T, int offset) {
1268     str(Vx, T, spill_address(1 << (int)T, offset));
1269   }
1270   void unspill(Register Rx, bool is64, int offset) {
1271     if (is64) {
1272       ldr(Rx, spill_address(8, offset));
1273     } else {
1274       ldrw(Rx, spill_address(4, offset));
1275     }
1276   }
1277   void unspill(FloatRegister Vx, SIMD_RegVariant T, int offset) {
1278     ldr(Vx, T, spill_address(1 << (int)T, offset));
1279   }
1280   void spill_copy128(int src_offset, int dst_offset,
1281                      Register tmp1=rscratch1, Register tmp2=rscratch2) {
1282     if (src_offset < 512 && (src_offset & 7) == 0 &&
1283         dst_offset < 512 && (dst_offset & 7) == 0) {
1284       ldp(tmp1, tmp2, Address(sp, src_offset));
1285       stp(tmp1, tmp2, Address(sp, dst_offset));
1286     } else {
1287       unspill(tmp1, true, src_offset);
1288       spill(tmp1, true, dst_offset);
1289       unspill(tmp1, true, src_offset+8);
1290       spill(tmp1, true, dst_offset+8);
1291     }
1292   }
1293 };
1294 
1295 #ifdef ASSERT
1296 inline bool AbstractAssembler::pd_check_instruction_mark() { return false; }
1297 #endif
1298 
1299 /**
1300  * class SkipIfEqual:
1301  *
1302  * Instantiating this class will result in assembly code being output that will
1303  * jump around any code emitted between the creation of the instance and it's
1304  * automatic destruction at the end of a scope block, depending on the value of
1305  * the flag passed to the constructor, which will be checked at run-time.
1306  */
1307 class SkipIfEqual {
1308  private:
1309   MacroAssembler* _masm;
1310   Label _label;
1311 
1312  public:
1313    SkipIfEqual(MacroAssembler*, const bool* flag_addr, bool value);
1314    ~SkipIfEqual();
1315 };
1316 
1317 struct tableswitch {
1318   Register _reg;
1319   int _insn_index; jint _first_key; jint _last_key;
1320   Label _after;
1321   Label _branches;
1322 };
1323 
1324 #endif // CPU_AARCH64_VM_MACROASSEMBLER_AARCH64_HPP