1 /*
    2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
    3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4  *
    5  * This code is free software; you can redistribute it and/or modify it
    6  * under the terms of the GNU General Public License version 2 only, as
    7  * published by the Free Software Foundation.
    8  *
    9  * This code is distributed in the hope that it will be useful, but WITHOUT
   10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12  * version 2 for more details (a copy is included in the LICENSE file that
   13  * accompanied this code).
   14  *
   15  * You should have received a copy of the GNU General Public License version
   16  * 2 along with this work; if not, write to the Free Software Foundation,
   17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18  *
   19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20  * or visit www.oracle.com if you need additional information or have any
   21  * questions.
   22  *
   23  */
   24 
   25 #include "precompiled.hpp"
   26 #include "asm/assembler.hpp"
   27 #include "asm/assembler.inline.hpp"
   28 #include "code/compiledIC.hpp"
   29 #include "compiler/compiler_globals.hpp"
   30 #include "compiler/disassembler.hpp"
   31 #include "crc32c.h"
   32 #include "gc/shared/barrierSet.hpp"
   33 #include "gc/shared/barrierSetAssembler.hpp"
   34 #include "gc/shared/collectedHeap.inline.hpp"
   35 #include "gc/shared/tlab_globals.hpp"
   36 #include "interpreter/bytecodeHistogram.hpp"
   37 #include "interpreter/interpreter.hpp"
   38 #include "interpreter/interpreterRuntime.hpp"
   39 #include "jvm.h"
   40 #include "memory/resourceArea.hpp"
   41 #include "memory/universe.hpp"
   42 #include "oops/accessDecorators.hpp"
   43 #include "oops/compressedKlass.inline.hpp"
   44 #include "oops/compressedOops.inline.hpp"
   45 #include "oops/klass.inline.hpp"
   46 #include "prims/methodHandles.hpp"
   47 #include "runtime/continuation.hpp"
   48 #include "runtime/interfaceSupport.inline.hpp"
   49 #include "runtime/javaThread.hpp"
   50 #include "runtime/jniHandles.hpp"
   51 #include "runtime/objectMonitor.hpp"
   52 #include "runtime/os.hpp"
   53 #include "runtime/safepoint.hpp"
   54 #include "runtime/safepointMechanism.hpp"
   55 #include "runtime/sharedRuntime.hpp"
   56 #include "runtime/stubRoutines.hpp"
   57 #include "utilities/checkedCast.hpp"
   58 #include "utilities/macros.hpp"
   59 
   60 #ifdef PRODUCT
   61 #define BLOCK_COMMENT(str) /* nothing */
   62 #define STOP(error) stop(error)
   63 #else
   64 #define BLOCK_COMMENT(str) block_comment(str)
   65 #define STOP(error) block_comment(error); stop(error)
   66 #endif
   67 
   68 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
   69 
   70 #ifdef ASSERT
   71 bool AbstractAssembler::pd_check_instruction_mark() { return true; }
   72 #endif
   73 
   74 static const Assembler::Condition reverse[] = {
   75     Assembler::noOverflow     /* overflow      = 0x0 */ ,
   76     Assembler::overflow       /* noOverflow    = 0x1 */ ,
   77     Assembler::aboveEqual     /* carrySet      = 0x2, below         = 0x2 */ ,
   78     Assembler::below          /* aboveEqual    = 0x3, carryClear    = 0x3 */ ,
   79     Assembler::notZero        /* zero          = 0x4, equal         = 0x4 */ ,
   80     Assembler::zero           /* notZero       = 0x5, notEqual      = 0x5 */ ,
   81     Assembler::above          /* belowEqual    = 0x6 */ ,
   82     Assembler::belowEqual     /* above         = 0x7 */ ,
   83     Assembler::positive       /* negative      = 0x8 */ ,
   84     Assembler::negative       /* positive      = 0x9 */ ,
   85     Assembler::noParity       /* parity        = 0xa */ ,
   86     Assembler::parity         /* noParity      = 0xb */ ,
   87     Assembler::greaterEqual   /* less          = 0xc */ ,
   88     Assembler::less           /* greaterEqual  = 0xd */ ,
   89     Assembler::greater        /* lessEqual     = 0xe */ ,
   90     Assembler::lessEqual      /* greater       = 0xf, */
   91 
   92 };
   93 
   94 
   95 // Implementation of MacroAssembler
   96 
   97 // First all the versions that have distinct versions depending on 32/64 bit
   98 // Unless the difference is trivial (1 line or so).
   99 
  100 #ifndef _LP64
  101 
  102 // 32bit versions
  103 
  104 Address MacroAssembler::as_Address(AddressLiteral adr) {
  105   return Address(adr.target(), adr.rspec());
  106 }
  107 
  108 Address MacroAssembler::as_Address(ArrayAddress adr, Register rscratch) {
  109   assert(rscratch == noreg, "");
  110   return Address::make_array(adr);
  111 }
  112 
  113 void MacroAssembler::call_VM_leaf_base(address entry_point,
  114                                        int number_of_arguments) {
  115   call(RuntimeAddress(entry_point));
  116   increment(rsp, number_of_arguments * wordSize);
  117 }
  118 
  119 void MacroAssembler::cmpklass(Address src1, Metadata* obj) {
  120   cmp_literal32(src1, (int32_t)obj, metadata_Relocation::spec_for_immediate());
  121 }
  122 
  123 
  124 void MacroAssembler::cmpklass(Register src1, Metadata* obj) {
  125   cmp_literal32(src1, (int32_t)obj, metadata_Relocation::spec_for_immediate());
  126 }
  127 
  128 void MacroAssembler::cmpoop(Address src1, jobject obj) {
  129   cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
  130 }
  131 
  132 void MacroAssembler::cmpoop(Register src1, jobject obj, Register rscratch) {
  133   assert(rscratch == noreg, "redundant");
  134   cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
  135 }
  136 
  137 void MacroAssembler::extend_sign(Register hi, Register lo) {
  138   // According to Intel Doc. AP-526, "Integer Divide", p.18.
  139   if (VM_Version::is_P6() && hi == rdx && lo == rax) {
  140     cdql();
  141   } else {
  142     movl(hi, lo);
  143     sarl(hi, 31);
  144   }
  145 }
  146 
  147 void MacroAssembler::jC2(Register tmp, Label& L) {
  148   // set parity bit if FPU flag C2 is set (via rax)
  149   save_rax(tmp);
  150   fwait(); fnstsw_ax();
  151   sahf();
  152   restore_rax(tmp);
  153   // branch
  154   jcc(Assembler::parity, L);
  155 }
  156 
  157 void MacroAssembler::jnC2(Register tmp, Label& L) {
  158   // set parity bit if FPU flag C2 is set (via rax)
  159   save_rax(tmp);
  160   fwait(); fnstsw_ax();
  161   sahf();
  162   restore_rax(tmp);
  163   // branch
  164   jcc(Assembler::noParity, L);
  165 }
  166 
  167 // 32bit can do a case table jump in one instruction but we no longer allow the base
  168 // to be installed in the Address class
  169 void MacroAssembler::jump(ArrayAddress entry, Register rscratch) {
  170   assert(rscratch == noreg, "not needed");
  171   jmp(as_Address(entry, noreg));
  172 }
  173 
  174 // Note: y_lo will be destroyed
  175 void MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
  176   // Long compare for Java (semantics as described in JVM spec.)
  177   Label high, low, done;
  178 
  179   cmpl(x_hi, y_hi);
  180   jcc(Assembler::less, low);
  181   jcc(Assembler::greater, high);
  182   // x_hi is the return register
  183   xorl(x_hi, x_hi);
  184   cmpl(x_lo, y_lo);
  185   jcc(Assembler::below, low);
  186   jcc(Assembler::equal, done);
  187 
  188   bind(high);
  189   xorl(x_hi, x_hi);
  190   increment(x_hi);
  191   jmp(done);
  192 
  193   bind(low);
  194   xorl(x_hi, x_hi);
  195   decrementl(x_hi);
  196 
  197   bind(done);
  198 }
  199 
  200 void MacroAssembler::lea(Register dst, AddressLiteral src) {
  201   mov_literal32(dst, (int32_t)src.target(), src.rspec());
  202 }
  203 
  204 void MacroAssembler::lea(Address dst, AddressLiteral adr, Register rscratch) {
  205   assert(rscratch == noreg, "not needed");
  206 
  207   // leal(dst, as_Address(adr));
  208   // see note in movl as to why we must use a move
  209   mov_literal32(dst, (int32_t)adr.target(), adr.rspec());
  210 }
  211 
  212 void MacroAssembler::leave() {
  213   mov(rsp, rbp);
  214   pop(rbp);
  215 }
  216 
  217 void MacroAssembler::lmul(int x_rsp_offset, int y_rsp_offset) {
  218   // Multiplication of two Java long values stored on the stack
  219   // as illustrated below. Result is in rdx:rax.
  220   //
  221   // rsp ---> [  ??  ] \               \
  222   //            ....    | y_rsp_offset  |
  223   //          [ y_lo ] /  (in bytes)    | x_rsp_offset
  224   //          [ y_hi ]                  | (in bytes)
  225   //            ....                    |
  226   //          [ x_lo ]                 /
  227   //          [ x_hi ]
  228   //            ....
  229   //
  230   // Basic idea: lo(result) = lo(x_lo * y_lo)
  231   //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
  232   Address x_hi(rsp, x_rsp_offset + wordSize); Address x_lo(rsp, x_rsp_offset);
  233   Address y_hi(rsp, y_rsp_offset + wordSize); Address y_lo(rsp, y_rsp_offset);
  234   Label quick;
  235   // load x_hi, y_hi and check if quick
  236   // multiplication is possible
  237   movl(rbx, x_hi);
  238   movl(rcx, y_hi);
  239   movl(rax, rbx);
  240   orl(rbx, rcx);                                 // rbx, = 0 <=> x_hi = 0 and y_hi = 0
  241   jcc(Assembler::zero, quick);                   // if rbx, = 0 do quick multiply
  242   // do full multiplication
  243   // 1st step
  244   mull(y_lo);                                    // x_hi * y_lo
  245   movl(rbx, rax);                                // save lo(x_hi * y_lo) in rbx,
  246   // 2nd step
  247   movl(rax, x_lo);
  248   mull(rcx);                                     // x_lo * y_hi
  249   addl(rbx, rax);                                // add lo(x_lo * y_hi) to rbx,
  250   // 3rd step
  251   bind(quick);                                   // note: rbx, = 0 if quick multiply!
  252   movl(rax, x_lo);
  253   mull(y_lo);                                    // x_lo * y_lo
  254   addl(rdx, rbx);                                // correct hi(x_lo * y_lo)
  255 }
  256 
  257 void MacroAssembler::lneg(Register hi, Register lo) {
  258   negl(lo);
  259   adcl(hi, 0);
  260   negl(hi);
  261 }
  262 
  263 void MacroAssembler::lshl(Register hi, Register lo) {
  264   // Java shift left long support (semantics as described in JVM spec., p.305)
  265   // (basic idea for shift counts s >= n: x << s == (x << n) << (s - n))
  266   // shift value is in rcx !
  267   assert(hi != rcx, "must not use rcx");
  268   assert(lo != rcx, "must not use rcx");
  269   const Register s = rcx;                        // shift count
  270   const int      n = BitsPerWord;
  271   Label L;
  272   andl(s, 0x3f);                                 // s := s & 0x3f (s < 0x40)
  273   cmpl(s, n);                                    // if (s < n)
  274   jcc(Assembler::less, L);                       // else (s >= n)
  275   movl(hi, lo);                                  // x := x << n
  276   xorl(lo, lo);
  277   // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
  278   bind(L);                                       // s (mod n) < n
  279   shldl(hi, lo);                                 // x := x << s
  280   shll(lo);
  281 }
  282 
  283 
  284 void MacroAssembler::lshr(Register hi, Register lo, bool sign_extension) {
  285   // Java shift right long support (semantics as described in JVM spec., p.306 & p.310)
  286   // (basic idea for shift counts s >= n: x >> s == (x >> n) >> (s - n))
  287   assert(hi != rcx, "must not use rcx");
  288   assert(lo != rcx, "must not use rcx");
  289   const Register s = rcx;                        // shift count
  290   const int      n = BitsPerWord;
  291   Label L;
  292   andl(s, 0x3f);                                 // s := s & 0x3f (s < 0x40)
  293   cmpl(s, n);                                    // if (s < n)
  294   jcc(Assembler::less, L);                       // else (s >= n)
  295   movl(lo, hi);                                  // x := x >> n
  296   if (sign_extension) sarl(hi, 31);
  297   else                xorl(hi, hi);
  298   // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
  299   bind(L);                                       // s (mod n) < n
  300   shrdl(lo, hi);                                 // x := x >> s
  301   if (sign_extension) sarl(hi);
  302   else                shrl(hi);
  303 }
  304 
  305 void MacroAssembler::movoop(Register dst, jobject obj) {
  306   mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
  307 }
  308 
  309 void MacroAssembler::movoop(Address dst, jobject obj, Register rscratch) {
  310   assert(rscratch == noreg, "redundant");
  311   mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
  312 }
  313 
  314 void MacroAssembler::mov_metadata(Register dst, Metadata* obj) {
  315   mov_literal32(dst, (int32_t)obj, metadata_Relocation::spec_for_immediate());
  316 }
  317 
  318 void MacroAssembler::mov_metadata(Address dst, Metadata* obj, Register rscratch) {
  319   assert(rscratch == noreg, "redundant");
  320   mov_literal32(dst, (int32_t)obj, metadata_Relocation::spec_for_immediate());
  321 }
  322 
  323 void MacroAssembler::movptr(Register dst, AddressLiteral src) {
  324   if (src.is_lval()) {
  325     mov_literal32(dst, (intptr_t)src.target(), src.rspec());
  326   } else {
  327     movl(dst, as_Address(src));
  328   }
  329 }
  330 
  331 void MacroAssembler::movptr(ArrayAddress dst, Register src, Register rscratch) {
  332   assert(rscratch == noreg, "redundant");
  333   movl(as_Address(dst, noreg), src);
  334 }
  335 
  336 void MacroAssembler::movptr(Register dst, ArrayAddress src) {
  337   movl(dst, as_Address(src, noreg));
  338 }
  339 
  340 void MacroAssembler::movptr(Address dst, intptr_t src, Register rscratch) {
  341   assert(rscratch == noreg, "redundant");
  342   movl(dst, src);
  343 }
  344 
  345 void MacroAssembler::pushoop(jobject obj, Register rscratch) {
  346   assert(rscratch == noreg, "redundant");
  347   push_literal32((int32_t)obj, oop_Relocation::spec_for_immediate());
  348 }
  349 
  350 void MacroAssembler::pushklass(Metadata* obj, Register rscratch) {
  351   assert(rscratch == noreg, "redundant");
  352   push_literal32((int32_t)obj, metadata_Relocation::spec_for_immediate());
  353 }
  354 
  355 void MacroAssembler::pushptr(AddressLiteral src, Register rscratch) {
  356   assert(rscratch == noreg, "redundant");
  357   if (src.is_lval()) {
  358     push_literal32((int32_t)src.target(), src.rspec());
  359   } else {
  360     pushl(as_Address(src));
  361   }
  362 }
  363 
  364 static void pass_arg0(MacroAssembler* masm, Register arg) {
  365   masm->push(arg);
  366 }
  367 
  368 static void pass_arg1(MacroAssembler* masm, Register arg) {
  369   masm->push(arg);
  370 }
  371 
  372 static void pass_arg2(MacroAssembler* masm, Register arg) {
  373   masm->push(arg);
  374 }
  375 
  376 static void pass_arg3(MacroAssembler* masm, Register arg) {
  377   masm->push(arg);
  378 }
  379 
  380 #ifndef PRODUCT
  381 extern "C" void findpc(intptr_t x);
  382 #endif
  383 
  384 void MacroAssembler::debug32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg) {
  385   // In order to get locks to work, we need to fake a in_VM state
  386   JavaThread* thread = JavaThread::current();
  387   JavaThreadState saved_state = thread->thread_state();
  388   thread->set_thread_state(_thread_in_vm);
  389   if (ShowMessageBoxOnError) {
  390     JavaThread* thread = JavaThread::current();
  391     JavaThreadState saved_state = thread->thread_state();
  392     thread->set_thread_state(_thread_in_vm);
  393     if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
  394       ttyLocker ttyl;
  395       BytecodeCounter::print();
  396     }
  397     // To see where a verify_oop failed, get $ebx+40/X for this frame.
  398     // This is the value of eip which points to where verify_oop will return.
  399     if (os::message_box(msg, "Execution stopped, print registers?")) {
  400       print_state32(rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax, eip);
  401       BREAKPOINT;
  402     }
  403   }
  404   fatal("DEBUG MESSAGE: %s", msg);
  405 }
  406 
  407 void MacroAssembler::print_state32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip) {
  408   ttyLocker ttyl;
  409   DebuggingContext debugging{};
  410   tty->print_cr("eip = 0x%08x", eip);
  411 #ifndef PRODUCT
  412   if ((WizardMode || Verbose) && PrintMiscellaneous) {
  413     tty->cr();
  414     findpc(eip);
  415     tty->cr();
  416   }
  417 #endif
  418 #define PRINT_REG(rax) \
  419   { tty->print("%s = ", #rax); os::print_location(tty, rax); }
  420   PRINT_REG(rax);
  421   PRINT_REG(rbx);
  422   PRINT_REG(rcx);
  423   PRINT_REG(rdx);
  424   PRINT_REG(rdi);
  425   PRINT_REG(rsi);
  426   PRINT_REG(rbp);
  427   PRINT_REG(rsp);
  428 #undef PRINT_REG
  429   // Print some words near top of staack.
  430   int* dump_sp = (int*) rsp;
  431   for (int col1 = 0; col1 < 8; col1++) {
  432     tty->print("(rsp+0x%03x) 0x%08x: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp);
  433     os::print_location(tty, *dump_sp++);
  434   }
  435   for (int row = 0; row < 16; row++) {
  436     tty->print("(rsp+0x%03x) 0x%08x: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp);
  437     for (int col = 0; col < 8; col++) {
  438       tty->print(" 0x%08x", *dump_sp++);
  439     }
  440     tty->cr();
  441   }
  442   // Print some instructions around pc:
  443   Disassembler::decode((address)eip-64, (address)eip);
  444   tty->print_cr("--------");
  445   Disassembler::decode((address)eip, (address)eip+32);
  446 }
  447 
  448 void MacroAssembler::stop(const char* msg) {
  449   // push address of message
  450   ExternalAddress message((address)msg);
  451   pushptr(message.addr(), noreg);
  452   { Label L; call(L, relocInfo::none); bind(L); }     // push eip
  453   pusha();                                            // push registers
  454   call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug32)));
  455   hlt();
  456 }
  457 
  458 void MacroAssembler::warn(const char* msg) {
  459   push_CPU_state();
  460 
  461   // push address of message
  462   ExternalAddress message((address)msg);
  463   pushptr(message.addr(), noreg);
  464 
  465   call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning)));
  466   addl(rsp, wordSize);       // discard argument
  467   pop_CPU_state();
  468 }
  469 
  470 void MacroAssembler::print_state() {
  471   { Label L; call(L, relocInfo::none); bind(L); }     // push eip
  472   pusha();                                            // push registers
  473 
  474   push_CPU_state();
  475   call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::print_state32)));
  476   pop_CPU_state();
  477 
  478   popa();
  479   addl(rsp, wordSize);
  480 }
  481 
  482 #else // _LP64
  483 
  484 // 64 bit versions
  485 
  486 Address MacroAssembler::as_Address(AddressLiteral adr) {
  487   // amd64 always does this as a pc-rel
  488   // we can be absolute or disp based on the instruction type
  489   // jmp/call are displacements others are absolute
  490   assert(!adr.is_lval(), "must be rval");
  491   assert(reachable(adr), "must be");
  492   return Address(checked_cast<int32_t>(adr.target() - pc()), adr.target(), adr.reloc());
  493 
  494 }
  495 
  496 Address MacroAssembler::as_Address(ArrayAddress adr, Register rscratch) {
  497   AddressLiteral base = adr.base();
  498   lea(rscratch, base);
  499   Address index = adr.index();
  500   assert(index._disp == 0, "must not have disp"); // maybe it can?
  501   Address array(rscratch, index._index, index._scale, index._disp);
  502   return array;
  503 }
  504 
  505 void MacroAssembler::call_VM_leaf_base(address entry_point, int num_args) {
  506   Label L, E;
  507 
  508 #ifdef _WIN64
  509   // Windows always allocates space for it's register args
  510   assert(num_args <= 4, "only register arguments supported");
  511   subq(rsp,  frame::arg_reg_save_area_bytes);
  512 #endif
  513 
  514   // Align stack if necessary
  515   testl(rsp, 15);
  516   jcc(Assembler::zero, L);
  517 
  518   subq(rsp, 8);
  519   call(RuntimeAddress(entry_point));
  520   addq(rsp, 8);
  521   jmp(E);
  522 
  523   bind(L);
  524   call(RuntimeAddress(entry_point));
  525 
  526   bind(E);
  527 
  528 #ifdef _WIN64
  529   // restore stack pointer
  530   addq(rsp, frame::arg_reg_save_area_bytes);
  531 #endif
  532 }
  533 
  534 void MacroAssembler::cmp64(Register src1, AddressLiteral src2, Register rscratch) {
  535   assert(!src2.is_lval(), "should use cmpptr");
  536   assert(rscratch != noreg || always_reachable(src2), "missing");
  537 
  538   if (reachable(src2)) {
  539     cmpq(src1, as_Address(src2));
  540   } else {
  541     lea(rscratch, src2);
  542     Assembler::cmpq(src1, Address(rscratch, 0));
  543   }
  544 }
  545 
  546 int MacroAssembler::corrected_idivq(Register reg) {
  547   // Full implementation of Java ldiv and lrem; checks for special
  548   // case as described in JVM spec., p.243 & p.271.  The function
  549   // returns the (pc) offset of the idivl instruction - may be needed
  550   // for implicit exceptions.
  551   //
  552   //         normal case                           special case
  553   //
  554   // input : rax: dividend                         min_long
  555   //         reg: divisor   (may not be eax/edx)   -1
  556   //
  557   // output: rax: quotient  (= rax idiv reg)       min_long
  558   //         rdx: remainder (= rax irem reg)       0
  559   assert(reg != rax && reg != rdx, "reg cannot be rax or rdx register");
  560   static const int64_t min_long = 0x8000000000000000;
  561   Label normal_case, special_case;
  562 
  563   // check for special case
  564   cmp64(rax, ExternalAddress((address) &min_long), rdx /*rscratch*/);
  565   jcc(Assembler::notEqual, normal_case);
  566   xorl(rdx, rdx); // prepare rdx for possible special case (where
  567                   // remainder = 0)
  568   cmpq(reg, -1);
  569   jcc(Assembler::equal, special_case);
  570 
  571   // handle normal case
  572   bind(normal_case);
  573   cdqq();
  574   int idivq_offset = offset();
  575   idivq(reg);
  576 
  577   // normal and special case exit
  578   bind(special_case);
  579 
  580   return idivq_offset;
  581 }
  582 
  583 void MacroAssembler::decrementq(Register reg, int value) {
  584   if (value == min_jint) { subq(reg, value); return; }
  585   if (value <  0) { incrementq(reg, -value); return; }
  586   if (value == 0) {                        ; return; }
  587   if (value == 1 && UseIncDec) { decq(reg) ; return; }
  588   /* else */      { subq(reg, value)       ; return; }
  589 }
  590 
  591 void MacroAssembler::decrementq(Address dst, int value) {
  592   if (value == min_jint) { subq(dst, value); return; }
  593   if (value <  0) { incrementq(dst, -value); return; }
  594   if (value == 0) {                        ; return; }
  595   if (value == 1 && UseIncDec) { decq(dst) ; return; }
  596   /* else */      { subq(dst, value)       ; return; }
  597 }
  598 
  599 void MacroAssembler::incrementq(AddressLiteral dst, Register rscratch) {
  600   assert(rscratch != noreg || always_reachable(dst), "missing");
  601 
  602   if (reachable(dst)) {
  603     incrementq(as_Address(dst));
  604   } else {
  605     lea(rscratch, dst);
  606     incrementq(Address(rscratch, 0));
  607   }
  608 }
  609 
  610 void MacroAssembler::incrementq(Register reg, int value) {
  611   if (value == min_jint) { addq(reg, value); return; }
  612   if (value <  0) { decrementq(reg, -value); return; }
  613   if (value == 0) {                        ; return; }
  614   if (value == 1 && UseIncDec) { incq(reg) ; return; }
  615   /* else */      { addq(reg, value)       ; return; }
  616 }
  617 
  618 void MacroAssembler::incrementq(Address dst, int value) {
  619   if (value == min_jint) { addq(dst, value); return; }
  620   if (value <  0) { decrementq(dst, -value); return; }
  621   if (value == 0) {                        ; return; }
  622   if (value == 1 && UseIncDec) { incq(dst) ; return; }
  623   /* else */      { addq(dst, value)       ; return; }
  624 }
  625 
  626 // 32bit can do a case table jump in one instruction but we no longer allow the base
  627 // to be installed in the Address class
  628 void MacroAssembler::jump(ArrayAddress entry, Register rscratch) {
  629   lea(rscratch, entry.base());
  630   Address dispatch = entry.index();
  631   assert(dispatch._base == noreg, "must be");
  632   dispatch._base = rscratch;
  633   jmp(dispatch);
  634 }
  635 
  636 void MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
  637   ShouldNotReachHere(); // 64bit doesn't use two regs
  638   cmpq(x_lo, y_lo);
  639 }
  640 
  641 void MacroAssembler::lea(Register dst, AddressLiteral src) {
  642   mov_literal64(dst, (intptr_t)src.target(), src.rspec());
  643 }
  644 
  645 void MacroAssembler::lea(Address dst, AddressLiteral adr, Register rscratch) {
  646   lea(rscratch, adr);
  647   movptr(dst, rscratch);
  648 }
  649 
  650 void MacroAssembler::leave() {
  651   // %%% is this really better? Why not on 32bit too?
  652   emit_int8((unsigned char)0xC9); // LEAVE
  653 }
  654 
  655 void MacroAssembler::lneg(Register hi, Register lo) {
  656   ShouldNotReachHere(); // 64bit doesn't use two regs
  657   negq(lo);
  658 }
  659 
  660 void MacroAssembler::movoop(Register dst, jobject obj) {
  661   mov_literal64(dst, (intptr_t)obj, oop_Relocation::spec_for_immediate());
  662 }
  663 
  664 void MacroAssembler::movoop(Address dst, jobject obj, Register rscratch) {
  665   mov_literal64(rscratch, (intptr_t)obj, oop_Relocation::spec_for_immediate());
  666   movq(dst, rscratch);
  667 }
  668 
  669 void MacroAssembler::mov_metadata(Register dst, Metadata* obj) {
  670   mov_literal64(dst, (intptr_t)obj, metadata_Relocation::spec_for_immediate());
  671 }
  672 
  673 void MacroAssembler::mov_metadata(Address dst, Metadata* obj, Register rscratch) {
  674   mov_literal64(rscratch, (intptr_t)obj, metadata_Relocation::spec_for_immediate());
  675   movq(dst, rscratch);
  676 }
  677 
  678 void MacroAssembler::movptr(Register dst, AddressLiteral src) {
  679   if (src.is_lval()) {
  680     mov_literal64(dst, (intptr_t)src.target(), src.rspec());
  681   } else {
  682     if (reachable(src)) {
  683       movq(dst, as_Address(src));
  684     } else {
  685       lea(dst, src);
  686       movq(dst, Address(dst, 0));
  687     }
  688   }
  689 }
  690 
  691 void MacroAssembler::movptr(ArrayAddress dst, Register src, Register rscratch) {
  692   movq(as_Address(dst, rscratch), src);
  693 }
  694 
  695 void MacroAssembler::movptr(Register dst, ArrayAddress src) {
  696   movq(dst, as_Address(src, dst /*rscratch*/));
  697 }
  698 
  699 // src should NEVER be a real pointer. Use AddressLiteral for true pointers
  700 void MacroAssembler::movptr(Address dst, intptr_t src, Register rscratch) {
  701   if (is_simm32(src)) {
  702     movptr(dst, checked_cast<int32_t>(src));
  703   } else {
  704     mov64(rscratch, src);
  705     movq(dst, rscratch);
  706   }
  707 }
  708 
  709 void MacroAssembler::pushoop(jobject obj, Register rscratch) {
  710   movoop(rscratch, obj);
  711   push(rscratch);
  712 }
  713 
  714 void MacroAssembler::pushklass(Metadata* obj, Register rscratch) {
  715   mov_metadata(rscratch, obj);
  716   push(rscratch);
  717 }
  718 
  719 void MacroAssembler::pushptr(AddressLiteral src, Register rscratch) {
  720   lea(rscratch, src);
  721   if (src.is_lval()) {
  722     push(rscratch);
  723   } else {
  724     pushq(Address(rscratch, 0));
  725   }
  726 }
  727 
  728 void MacroAssembler::reset_last_Java_frame(bool clear_fp) {
  729   reset_last_Java_frame(r15_thread, clear_fp);
  730 }
  731 
  732 void MacroAssembler::set_last_Java_frame(Register last_java_sp,
  733                                          Register last_java_fp,
  734                                          address  last_java_pc,
  735                                          Register rscratch) {
  736   set_last_Java_frame(r15_thread, last_java_sp, last_java_fp, last_java_pc, rscratch);
  737 }
  738 
  739 static void pass_arg0(MacroAssembler* masm, Register arg) {
  740   if (c_rarg0 != arg ) {
  741     masm->mov(c_rarg0, arg);
  742   }
  743 }
  744 
  745 static void pass_arg1(MacroAssembler* masm, Register arg) {
  746   if (c_rarg1 != arg ) {
  747     masm->mov(c_rarg1, arg);
  748   }
  749 }
  750 
  751 static void pass_arg2(MacroAssembler* masm, Register arg) {
  752   if (c_rarg2 != arg ) {
  753     masm->mov(c_rarg2, arg);
  754   }
  755 }
  756 
  757 static void pass_arg3(MacroAssembler* masm, Register arg) {
  758   if (c_rarg3 != arg ) {
  759     masm->mov(c_rarg3, arg);
  760   }
  761 }
  762 
  763 void MacroAssembler::stop(const char* msg) {
  764   if (ShowMessageBoxOnError) {
  765     address rip = pc();
  766     pusha(); // get regs on stack
  767     lea(c_rarg1, InternalAddress(rip));
  768     movq(c_rarg2, rsp); // pass pointer to regs array
  769   }
  770   lea(c_rarg0, ExternalAddress((address) msg));
  771   andq(rsp, -16); // align stack as required by ABI
  772   call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64)));
  773   hlt();
  774 }
  775 
  776 void MacroAssembler::warn(const char* msg) {
  777   push(rbp);
  778   movq(rbp, rsp);
  779   andq(rsp, -16);     // align stack as required by push_CPU_state and call
  780   push_CPU_state();   // keeps alignment at 16 bytes
  781 
  782   lea(c_rarg0, ExternalAddress((address) msg));
  783   call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning)));
  784 
  785   pop_CPU_state();
  786   mov(rsp, rbp);
  787   pop(rbp);
  788 }
  789 
  790 void MacroAssembler::print_state() {
  791   address rip = pc();
  792   pusha();            // get regs on stack
  793   push(rbp);
  794   movq(rbp, rsp);
  795   andq(rsp, -16);     // align stack as required by push_CPU_state and call
  796   push_CPU_state();   // keeps alignment at 16 bytes
  797 
  798   lea(c_rarg0, InternalAddress(rip));
  799   lea(c_rarg1, Address(rbp, wordSize)); // pass pointer to regs array
  800   call_VM_leaf(CAST_FROM_FN_PTR(address, MacroAssembler::print_state64), c_rarg0, c_rarg1);
  801 
  802   pop_CPU_state();
  803   mov(rsp, rbp);
  804   pop(rbp);
  805   popa();
  806 }
  807 
  808 #ifndef PRODUCT
  809 extern "C" void findpc(intptr_t x);
  810 #endif
  811 
  812 void MacroAssembler::debug64(char* msg, int64_t pc, int64_t regs[]) {
  813   // In order to get locks to work, we need to fake a in_VM state
  814   if (ShowMessageBoxOnError) {
  815     JavaThread* thread = JavaThread::current();
  816     JavaThreadState saved_state = thread->thread_state();
  817     thread->set_thread_state(_thread_in_vm);
  818 #ifndef PRODUCT
  819     if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
  820       ttyLocker ttyl;
  821       BytecodeCounter::print();
  822     }
  823 #endif
  824     // To see where a verify_oop failed, get $ebx+40/X for this frame.
  825     // XXX correct this offset for amd64
  826     // This is the value of eip which points to where verify_oop will return.
  827     if (os::message_box(msg, "Execution stopped, print registers?")) {
  828       print_state64(pc, regs);
  829       BREAKPOINT;
  830     }
  831   }
  832   fatal("DEBUG MESSAGE: %s", msg);
  833 }
  834 
  835 void MacroAssembler::print_state64(int64_t pc, int64_t regs[]) {
  836   ttyLocker ttyl;
  837   DebuggingContext debugging{};
  838   tty->print_cr("rip = 0x%016lx", (intptr_t)pc);
  839 #ifndef PRODUCT
  840   tty->cr();
  841   findpc(pc);
  842   tty->cr();
  843 #endif
  844 #define PRINT_REG(rax, value) \
  845   { tty->print("%s = ", #rax); os::print_location(tty, value); }
  846   PRINT_REG(rax, regs[15]);
  847   PRINT_REG(rbx, regs[12]);
  848   PRINT_REG(rcx, regs[14]);
  849   PRINT_REG(rdx, regs[13]);
  850   PRINT_REG(rdi, regs[8]);
  851   PRINT_REG(rsi, regs[9]);
  852   PRINT_REG(rbp, regs[10]);
  853   // rsp is actually not stored by pusha(), compute the old rsp from regs (rsp after pusha): regs + 16 = old rsp
  854   PRINT_REG(rsp, (intptr_t)(&regs[16]));
  855   PRINT_REG(r8 , regs[7]);
  856   PRINT_REG(r9 , regs[6]);
  857   PRINT_REG(r10, regs[5]);
  858   PRINT_REG(r11, regs[4]);
  859   PRINT_REG(r12, regs[3]);
  860   PRINT_REG(r13, regs[2]);
  861   PRINT_REG(r14, regs[1]);
  862   PRINT_REG(r15, regs[0]);
  863 #undef PRINT_REG
  864   // Print some words near the top of the stack.
  865   int64_t* rsp = &regs[16];
  866   int64_t* dump_sp = rsp;
  867   for (int col1 = 0; col1 < 8; col1++) {
  868     tty->print("(rsp+0x%03x) 0x%016lx: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp);
  869     os::print_location(tty, *dump_sp++);
  870   }
  871   for (int row = 0; row < 25; row++) {
  872     tty->print("(rsp+0x%03x) 0x%016lx: ", (int)((intptr_t)dump_sp - (intptr_t)rsp), (intptr_t)dump_sp);
  873     for (int col = 0; col < 4; col++) {
  874       tty->print(" 0x%016lx", (intptr_t)*dump_sp++);
  875     }
  876     tty->cr();
  877   }
  878   // Print some instructions around pc:
  879   Disassembler::decode((address)pc-64, (address)pc);
  880   tty->print_cr("--------");
  881   Disassembler::decode((address)pc, (address)pc+32);
  882 }
  883 
  884 // The java_calling_convention describes stack locations as ideal slots on
  885 // a frame with no abi restrictions. Since we must observe abi restrictions
  886 // (like the placement of the register window) the slots must be biased by
  887 // the following value.
  888 static int reg2offset_in(VMReg r) {
  889   // Account for saved rbp and return address
  890   // This should really be in_preserve_stack_slots
  891   return (r->reg2stack() + 4) * VMRegImpl::stack_slot_size;
  892 }
  893 
  894 static int reg2offset_out(VMReg r) {
  895   return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size;
  896 }
  897 
  898 // A long move
  899 void MacroAssembler::long_move(VMRegPair src, VMRegPair dst, Register tmp, int in_stk_bias, int out_stk_bias) {
  900 
  901   // The calling conventions assures us that each VMregpair is either
  902   // all really one physical register or adjacent stack slots.
  903 
  904   if (src.is_single_phys_reg() ) {
  905     if (dst.is_single_phys_reg()) {
  906       if (dst.first() != src.first()) {
  907         mov(dst.first()->as_Register(), src.first()->as_Register());
  908       }
  909     } else {
  910       assert(dst.is_single_reg(), "not a stack pair: (%s, %s), (%s, %s)",
  911              src.first()->name(), src.second()->name(), dst.first()->name(), dst.second()->name());
  912       movq(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), src.first()->as_Register());
  913     }
  914   } else if (dst.is_single_phys_reg()) {
  915     assert(src.is_single_reg(),  "not a stack pair");
  916     movq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  917   } else {
  918     assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
  919     movq(tmp, Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  920     movq(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), tmp);
  921   }
  922 }
  923 
  924 // A double move
  925 void MacroAssembler::double_move(VMRegPair src, VMRegPair dst, Register tmp, int in_stk_bias, int out_stk_bias) {
  926 
  927   // The calling conventions assures us that each VMregpair is either
  928   // all really one physical register or adjacent stack slots.
  929 
  930   if (src.is_single_phys_reg() ) {
  931     if (dst.is_single_phys_reg()) {
  932       // In theory these overlap but the ordering is such that this is likely a nop
  933       if ( src.first() != dst.first()) {
  934         movdbl(dst.first()->as_XMMRegister(), src.first()->as_XMMRegister());
  935       }
  936     } else {
  937       assert(dst.is_single_reg(), "not a stack pair");
  938       movdbl(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), src.first()->as_XMMRegister());
  939     }
  940   } else if (dst.is_single_phys_reg()) {
  941     assert(src.is_single_reg(),  "not a stack pair");
  942     movdbl(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  943   } else {
  944     assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
  945     movq(tmp, Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  946     movq(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), tmp);
  947   }
  948 }
  949 
  950 
  951 // A float arg may have to do float reg int reg conversion
  952 void MacroAssembler::float_move(VMRegPair src, VMRegPair dst, Register tmp, int in_stk_bias, int out_stk_bias) {
  953   assert(!src.second()->is_valid() && !dst.second()->is_valid(), "bad float_move");
  954 
  955   // The calling conventions assures us that each VMregpair is either
  956   // all really one physical register or adjacent stack slots.
  957 
  958   if (src.first()->is_stack()) {
  959     if (dst.first()->is_stack()) {
  960       movl(tmp, Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  961       movptr(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), tmp);
  962     } else {
  963       // stack to reg
  964       assert(dst.first()->is_XMMRegister(), "only expect xmm registers as parameters");
  965       movflt(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  966     }
  967   } else if (dst.first()->is_stack()) {
  968     // reg to stack
  969     assert(src.first()->is_XMMRegister(), "only expect xmm registers as parameters");
  970     movflt(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), src.first()->as_XMMRegister());
  971   } else {
  972     // reg to reg
  973     // In theory these overlap but the ordering is such that this is likely a nop
  974     if ( src.first() != dst.first()) {
  975       movdbl(dst.first()->as_XMMRegister(),  src.first()->as_XMMRegister());
  976     }
  977   }
  978 }
  979 
  980 // On 64 bit we will store integer like items to the stack as
  981 // 64 bits items (x86_32/64 abi) even though java would only store
  982 // 32bits for a parameter. On 32bit it will simply be 32 bits
  983 // So this routine will do 32->32 on 32bit and 32->64 on 64bit
  984 void MacroAssembler::move32_64(VMRegPair src, VMRegPair dst, Register tmp, int in_stk_bias, int out_stk_bias) {
  985   if (src.first()->is_stack()) {
  986     if (dst.first()->is_stack()) {
  987       // stack to stack
  988       movslq(tmp, Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  989       movq(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), tmp);
  990     } else {
  991       // stack to reg
  992       movslq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first()) + in_stk_bias));
  993     }
  994   } else if (dst.first()->is_stack()) {
  995     // reg to stack
  996     // Do we really have to sign extend???
  997     // __ movslq(src.first()->as_Register(), src.first()->as_Register());
  998     movq(Address(rsp, reg2offset_out(dst.first()) + out_stk_bias), src.first()->as_Register());
  999   } else {
 1000     // Do we really have to sign extend???
 1001     // __ movslq(dst.first()->as_Register(), src.first()->as_Register());
 1002     if (dst.first() != src.first()) {
 1003       movq(dst.first()->as_Register(), src.first()->as_Register());
 1004     }
 1005   }
 1006 }
 1007 
 1008 void MacroAssembler::move_ptr(VMRegPair src, VMRegPair dst) {
 1009   if (src.first()->is_stack()) {
 1010     if (dst.first()->is_stack()) {
 1011       // stack to stack
 1012       movq(rax, Address(rbp, reg2offset_in(src.first())));
 1013       movq(Address(rsp, reg2offset_out(dst.first())), rax);
 1014     } else {
 1015       // stack to reg
 1016       movq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first())));
 1017     }
 1018   } else if (dst.first()->is_stack()) {
 1019     // reg to stack
 1020     movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
 1021   } else {
 1022     if (dst.first() != src.first()) {
 1023       movq(dst.first()->as_Register(), src.first()->as_Register());
 1024     }
 1025   }
 1026 }
 1027 
 1028 // An oop arg. Must pass a handle not the oop itself
 1029 void MacroAssembler::object_move(OopMap* map,
 1030                         int oop_handle_offset,
 1031                         int framesize_in_slots,
 1032                         VMRegPair src,
 1033                         VMRegPair dst,
 1034                         bool is_receiver,
 1035                         int* receiver_offset) {
 1036 
 1037   // must pass a handle. First figure out the location we use as a handle
 1038 
 1039   Register rHandle = dst.first()->is_stack() ? rax : dst.first()->as_Register();
 1040 
 1041   // See if oop is null if it is we need no handle
 1042 
 1043   if (src.first()->is_stack()) {
 1044 
 1045     // Oop is already on the stack as an argument
 1046     int offset_in_older_frame = src.first()->reg2stack() + SharedRuntime::out_preserve_stack_slots();
 1047     map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + framesize_in_slots));
 1048     if (is_receiver) {
 1049       *receiver_offset = (offset_in_older_frame + framesize_in_slots) * VMRegImpl::stack_slot_size;
 1050     }
 1051 
 1052     cmpptr(Address(rbp, reg2offset_in(src.first())), NULL_WORD);
 1053     lea(rHandle, Address(rbp, reg2offset_in(src.first())));
 1054     // conditionally move a null
 1055     cmovptr(Assembler::equal, rHandle, Address(rbp, reg2offset_in(src.first())));
 1056   } else {
 1057 
 1058     // Oop is in a register we must store it to the space we reserve
 1059     // on the stack for oop_handles and pass a handle if oop is non-null
 1060 
 1061     const Register rOop = src.first()->as_Register();
 1062     int oop_slot;
 1063     if (rOop == j_rarg0)
 1064       oop_slot = 0;
 1065     else if (rOop == j_rarg1)
 1066       oop_slot = 1;
 1067     else if (rOop == j_rarg2)
 1068       oop_slot = 2;
 1069     else if (rOop == j_rarg3)
 1070       oop_slot = 3;
 1071     else if (rOop == j_rarg4)
 1072       oop_slot = 4;
 1073     else {
 1074       assert(rOop == j_rarg5, "wrong register");
 1075       oop_slot = 5;
 1076     }
 1077 
 1078     oop_slot = oop_slot * VMRegImpl::slots_per_word + oop_handle_offset;
 1079     int offset = oop_slot*VMRegImpl::stack_slot_size;
 1080 
 1081     map->set_oop(VMRegImpl::stack2reg(oop_slot));
 1082     // Store oop in handle area, may be null
 1083     movptr(Address(rsp, offset), rOop);
 1084     if (is_receiver) {
 1085       *receiver_offset = offset;
 1086     }
 1087 
 1088     cmpptr(rOop, NULL_WORD);
 1089     lea(rHandle, Address(rsp, offset));
 1090     // conditionally move a null from the handle area where it was just stored
 1091     cmovptr(Assembler::equal, rHandle, Address(rsp, offset));
 1092   }
 1093 
 1094   // If arg is on the stack then place it otherwise it is already in correct reg.
 1095   if (dst.first()->is_stack()) {
 1096     movptr(Address(rsp, reg2offset_out(dst.first())), rHandle);
 1097   }
 1098 }
 1099 
 1100 #endif // _LP64
 1101 
 1102 // Now versions that are common to 32/64 bit
 1103 
 1104 void MacroAssembler::addptr(Register dst, int32_t imm32) {
 1105   LP64_ONLY(addq(dst, imm32)) NOT_LP64(addl(dst, imm32));
 1106 }
 1107 
 1108 void MacroAssembler::addptr(Register dst, Register src) {
 1109   LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src));
 1110 }
 1111 
 1112 void MacroAssembler::addptr(Address dst, Register src) {
 1113   LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src));
 1114 }
 1115 
 1116 void MacroAssembler::addsd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1117   assert(rscratch != noreg || always_reachable(src), "missing");
 1118 
 1119   if (reachable(src)) {
 1120     Assembler::addsd(dst, as_Address(src));
 1121   } else {
 1122     lea(rscratch, src);
 1123     Assembler::addsd(dst, Address(rscratch, 0));
 1124   }
 1125 }
 1126 
 1127 void MacroAssembler::addss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1128   assert(rscratch != noreg || always_reachable(src), "missing");
 1129 
 1130   if (reachable(src)) {
 1131     addss(dst, as_Address(src));
 1132   } else {
 1133     lea(rscratch, src);
 1134     addss(dst, Address(rscratch, 0));
 1135   }
 1136 }
 1137 
 1138 void MacroAssembler::addpd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1139   assert(rscratch != noreg || always_reachable(src), "missing");
 1140 
 1141   if (reachable(src)) {
 1142     Assembler::addpd(dst, as_Address(src));
 1143   } else {
 1144     lea(rscratch, src);
 1145     Assembler::addpd(dst, Address(rscratch, 0));
 1146   }
 1147 }
 1148 
 1149 // See 8273459.  Function for ensuring 64-byte alignment, intended for stubs only.
 1150 // Stub code is generated once and never copied.
 1151 // NMethods can't use this because they get copied and we can't force alignment > 32 bytes.
 1152 void MacroAssembler::align64() {
 1153   align(64, (uint)(uintptr_t)pc());
 1154 }
 1155 
 1156 void MacroAssembler::align32() {
 1157   align(32, (uint)(uintptr_t)pc());
 1158 }
 1159 
 1160 void MacroAssembler::align(uint modulus) {
 1161   // 8273459: Ensure alignment is possible with current segment alignment
 1162   assert(modulus <= (uintx)CodeEntryAlignment, "Alignment must be <= CodeEntryAlignment");
 1163   align(modulus, offset());
 1164 }
 1165 
 1166 void MacroAssembler::align(uint modulus, uint target) {
 1167   if (target % modulus != 0) {
 1168     nop(modulus - (target % modulus));
 1169   }
 1170 }
 1171 
 1172 void MacroAssembler::push_f(XMMRegister r) {
 1173   subptr(rsp, wordSize);
 1174   movflt(Address(rsp, 0), r);
 1175 }
 1176 
 1177 void MacroAssembler::pop_f(XMMRegister r) {
 1178   movflt(r, Address(rsp, 0));
 1179   addptr(rsp, wordSize);
 1180 }
 1181 
 1182 void MacroAssembler::push_d(XMMRegister r) {
 1183   subptr(rsp, 2 * wordSize);
 1184   movdbl(Address(rsp, 0), r);
 1185 }
 1186 
 1187 void MacroAssembler::pop_d(XMMRegister r) {
 1188   movdbl(r, Address(rsp, 0));
 1189   addptr(rsp, 2 * Interpreter::stackElementSize);
 1190 }
 1191 
 1192 void MacroAssembler::andpd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1193   // Used in sign-masking with aligned address.
 1194   assert((UseAVX > 0) || (((intptr_t)src.target() & 15) == 0), "SSE mode requires address alignment 16 bytes");
 1195   assert(rscratch != noreg || always_reachable(src), "missing");
 1196 
 1197   if (reachable(src)) {
 1198     Assembler::andpd(dst, as_Address(src));
 1199   } else {
 1200     lea(rscratch, src);
 1201     Assembler::andpd(dst, Address(rscratch, 0));
 1202   }
 1203 }
 1204 
 1205 void MacroAssembler::andps(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1206   // Used in sign-masking with aligned address.
 1207   assert((UseAVX > 0) || (((intptr_t)src.target() & 15) == 0), "SSE mode requires address alignment 16 bytes");
 1208   assert(rscratch != noreg || always_reachable(src), "missing");
 1209 
 1210   if (reachable(src)) {
 1211     Assembler::andps(dst, as_Address(src));
 1212   } else {
 1213     lea(rscratch, src);
 1214     Assembler::andps(dst, Address(rscratch, 0));
 1215   }
 1216 }
 1217 
 1218 void MacroAssembler::andptr(Register dst, int32_t imm32) {
 1219   LP64_ONLY(andq(dst, imm32)) NOT_LP64(andl(dst, imm32));
 1220 }
 1221 
 1222 #ifdef _LP64
 1223 void MacroAssembler::andq(Register dst, AddressLiteral src, Register rscratch) {
 1224   assert(rscratch != noreg || always_reachable(src), "missing");
 1225 
 1226   if (reachable(src)) {
 1227     andq(dst, as_Address(src));
 1228   } else {
 1229     lea(rscratch, src);
 1230     andq(dst, Address(rscratch, 0));
 1231   }
 1232 }
 1233 #endif
 1234 
 1235 void MacroAssembler::atomic_incl(Address counter_addr) {
 1236   lock();
 1237   incrementl(counter_addr);
 1238 }
 1239 
 1240 void MacroAssembler::atomic_incl(AddressLiteral counter_addr, Register rscratch) {
 1241   assert(rscratch != noreg || always_reachable(counter_addr), "missing");
 1242 
 1243   if (reachable(counter_addr)) {
 1244     atomic_incl(as_Address(counter_addr));
 1245   } else {
 1246     lea(rscratch, counter_addr);
 1247     atomic_incl(Address(rscratch, 0));
 1248   }
 1249 }
 1250 
 1251 #ifdef _LP64
 1252 void MacroAssembler::atomic_incq(Address counter_addr) {
 1253   lock();
 1254   incrementq(counter_addr);
 1255 }
 1256 
 1257 void MacroAssembler::atomic_incq(AddressLiteral counter_addr, Register rscratch) {
 1258   assert(rscratch != noreg || always_reachable(counter_addr), "missing");
 1259 
 1260   if (reachable(counter_addr)) {
 1261     atomic_incq(as_Address(counter_addr));
 1262   } else {
 1263     lea(rscratch, counter_addr);
 1264     atomic_incq(Address(rscratch, 0));
 1265   }
 1266 }
 1267 #endif
 1268 
 1269 // Writes to stack successive pages until offset reached to check for
 1270 // stack overflow + shadow pages.  This clobbers tmp.
 1271 void MacroAssembler::bang_stack_size(Register size, Register tmp) {
 1272   movptr(tmp, rsp);
 1273   // Bang stack for total size given plus shadow page size.
 1274   // Bang one page at a time because large size can bang beyond yellow and
 1275   // red zones.
 1276   Label loop;
 1277   bind(loop);
 1278   movl(Address(tmp, (-(int)os::vm_page_size())), size );
 1279   subptr(tmp, (int)os::vm_page_size());
 1280   subl(size, (int)os::vm_page_size());
 1281   jcc(Assembler::greater, loop);
 1282 
 1283   // Bang down shadow pages too.
 1284   // At this point, (tmp-0) is the last address touched, so don't
 1285   // touch it again.  (It was touched as (tmp-pagesize) but then tmp
 1286   // was post-decremented.)  Skip this address by starting at i=1, and
 1287   // touch a few more pages below.  N.B.  It is important to touch all
 1288   // the way down including all pages in the shadow zone.
 1289   for (int i = 1; i < ((int)StackOverflow::stack_shadow_zone_size() / (int)os::vm_page_size()); i++) {
 1290     // this could be any sized move but this is can be a debugging crumb
 1291     // so the bigger the better.
 1292     movptr(Address(tmp, (-i*(int)os::vm_page_size())), size );
 1293   }
 1294 }
 1295 
 1296 void MacroAssembler::reserved_stack_check() {
 1297   // testing if reserved zone needs to be enabled
 1298   Label no_reserved_zone_enabling;
 1299   Register thread = NOT_LP64(rsi) LP64_ONLY(r15_thread);
 1300   NOT_LP64(get_thread(rsi);)
 1301 
 1302   cmpptr(rsp, Address(thread, JavaThread::reserved_stack_activation_offset()));
 1303   jcc(Assembler::below, no_reserved_zone_enabling);
 1304 
 1305   call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), thread);
 1306   jump(RuntimeAddress(SharedRuntime::throw_delayed_StackOverflowError_entry()));
 1307   should_not_reach_here();
 1308 
 1309   bind(no_reserved_zone_enabling);
 1310 }
 1311 
 1312 void MacroAssembler::c2bool(Register x) {
 1313   // implements x == 0 ? 0 : 1
 1314   // note: must only look at least-significant byte of x
 1315   //       since C-style booleans are stored in one byte
 1316   //       only! (was bug)
 1317   andl(x, 0xFF);
 1318   setb(Assembler::notZero, x);
 1319 }
 1320 
 1321 // Wouldn't need if AddressLiteral version had new name
 1322 void MacroAssembler::call(Label& L, relocInfo::relocType rtype) {
 1323   Assembler::call(L, rtype);
 1324 }
 1325 
 1326 void MacroAssembler::call(Register entry) {
 1327   Assembler::call(entry);
 1328 }
 1329 
 1330 void MacroAssembler::call(AddressLiteral entry, Register rscratch) {
 1331   assert(rscratch != noreg || always_reachable(entry), "missing");
 1332 
 1333   if (reachable(entry)) {
 1334     Assembler::call_literal(entry.target(), entry.rspec());
 1335   } else {
 1336     lea(rscratch, entry);
 1337     Assembler::call(rscratch);
 1338   }
 1339 }
 1340 
 1341 void MacroAssembler::ic_call(address entry, jint method_index) {
 1342   RelocationHolder rh = virtual_call_Relocation::spec(pc(), method_index);
 1343 #ifdef _LP64
 1344   // Needs full 64-bit immediate for later patching.
 1345   mov64(rax, (int64_t)Universe::non_oop_word());
 1346 #else
 1347   movptr(rax, (intptr_t)Universe::non_oop_word());
 1348 #endif
 1349   call(AddressLiteral(entry, rh));
 1350 }
 1351 
 1352 int MacroAssembler::ic_check_size() {
 1353   return
 1354       LP64_ONLY(UseCompactObjectHeaders ? 17 : 14) NOT_LP64(12);
 1355 }
 1356 
 1357 int MacroAssembler::ic_check(int end_alignment) {
 1358   Register receiver = LP64_ONLY(j_rarg0) NOT_LP64(rcx);
 1359   Register data = rax;
 1360   Register temp = LP64_ONLY(rscratch1) NOT_LP64(rbx);
 1361 
 1362   // The UEP of a code blob ensures that the VEP is padded. However, the padding of the UEP is placed
 1363   // before the inline cache check, so we don't have to execute any nop instructions when dispatching
 1364   // through the UEP, yet we can ensure that the VEP is aligned appropriately. That's why we align
 1365   // before the inline cache check here, and not after
 1366   align(end_alignment, offset() + ic_check_size());
 1367 
 1368   int uep_offset = offset();
 1369 
 1370 #ifdef _LP64
 1371   if (UseCompactObjectHeaders) {
 1372     load_narrow_klass_compact(temp, receiver);
 1373     cmpl(temp, Address(data, CompiledICData::speculated_klass_offset()));
 1374   } else
 1375 #endif
 1376   if (UseCompressedClassPointers) {
 1377     movl(temp, Address(receiver, oopDesc::klass_offset_in_bytes()));
 1378     cmpl(temp, Address(data, CompiledICData::speculated_klass_offset()));
 1379   } else {
 1380     movptr(temp, Address(receiver, oopDesc::klass_offset_in_bytes()));
 1381     cmpptr(temp, Address(data, CompiledICData::speculated_klass_offset()));
 1382   }
 1383 
 1384   // if inline cache check fails, then jump to runtime routine
 1385   jump_cc(Assembler::notEqual, RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
 1386   assert((offset() % end_alignment) == 0, "Misaligned verified entry point (%d, %d, %d)", uep_offset, offset(), end_alignment);
 1387 
 1388   return uep_offset;
 1389 }
 1390 
 1391 void MacroAssembler::emit_static_call_stub() {
 1392   // Static stub relocation also tags the Method* in the code-stream.
 1393   mov_metadata(rbx, (Metadata*) nullptr);  // Method is zapped till fixup time.
 1394   // This is recognized as unresolved by relocs/nativeinst/ic code.
 1395   jump(RuntimeAddress(pc()));
 1396 }
 1397 
 1398 // Implementation of call_VM versions
 1399 
 1400 void MacroAssembler::call_VM(Register oop_result,
 1401                              address entry_point,
 1402                              bool check_exceptions) {
 1403   Label C, E;
 1404   call(C, relocInfo::none);
 1405   jmp(E);
 1406 
 1407   bind(C);
 1408   call_VM_helper(oop_result, entry_point, 0, check_exceptions);
 1409   ret(0);
 1410 
 1411   bind(E);
 1412 }
 1413 
 1414 void MacroAssembler::call_VM(Register oop_result,
 1415                              address entry_point,
 1416                              Register arg_1,
 1417                              bool check_exceptions) {
 1418   Label C, E;
 1419   call(C, relocInfo::none);
 1420   jmp(E);
 1421 
 1422   bind(C);
 1423   pass_arg1(this, arg_1);
 1424   call_VM_helper(oop_result, entry_point, 1, check_exceptions);
 1425   ret(0);
 1426 
 1427   bind(E);
 1428 }
 1429 
 1430 void MacroAssembler::call_VM(Register oop_result,
 1431                              address entry_point,
 1432                              Register arg_1,
 1433                              Register arg_2,
 1434                              bool check_exceptions) {
 1435   Label C, E;
 1436   call(C, relocInfo::none);
 1437   jmp(E);
 1438 
 1439   bind(C);
 1440 
 1441   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
 1442 
 1443   pass_arg2(this, arg_2);
 1444   pass_arg1(this, arg_1);
 1445   call_VM_helper(oop_result, entry_point, 2, check_exceptions);
 1446   ret(0);
 1447 
 1448   bind(E);
 1449 }
 1450 
 1451 void MacroAssembler::call_VM(Register oop_result,
 1452                              address entry_point,
 1453                              Register arg_1,
 1454                              Register arg_2,
 1455                              Register arg_3,
 1456                              bool check_exceptions) {
 1457   Label C, E;
 1458   call(C, relocInfo::none);
 1459   jmp(E);
 1460 
 1461   bind(C);
 1462 
 1463   LP64_ONLY(assert_different_registers(arg_1, c_rarg2, c_rarg3));
 1464   LP64_ONLY(assert_different_registers(arg_2, c_rarg3));
 1465   pass_arg3(this, arg_3);
 1466   pass_arg2(this, arg_2);
 1467   pass_arg1(this, arg_1);
 1468   call_VM_helper(oop_result, entry_point, 3, check_exceptions);
 1469   ret(0);
 1470 
 1471   bind(E);
 1472 }
 1473 
 1474 void MacroAssembler::call_VM(Register oop_result,
 1475                              Register last_java_sp,
 1476                              address entry_point,
 1477                              int number_of_arguments,
 1478                              bool check_exceptions) {
 1479   Register thread = LP64_ONLY(r15_thread) NOT_LP64(noreg);
 1480   call_VM_base(oop_result, thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
 1481 }
 1482 
 1483 void MacroAssembler::call_VM(Register oop_result,
 1484                              Register last_java_sp,
 1485                              address entry_point,
 1486                              Register arg_1,
 1487                              bool check_exceptions) {
 1488   pass_arg1(this, arg_1);
 1489   call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
 1490 }
 1491 
 1492 void MacroAssembler::call_VM(Register oop_result,
 1493                              Register last_java_sp,
 1494                              address entry_point,
 1495                              Register arg_1,
 1496                              Register arg_2,
 1497                              bool check_exceptions) {
 1498 
 1499   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
 1500   pass_arg2(this, arg_2);
 1501   pass_arg1(this, arg_1);
 1502   call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions);
 1503 }
 1504 
 1505 void MacroAssembler::call_VM(Register oop_result,
 1506                              Register last_java_sp,
 1507                              address entry_point,
 1508                              Register arg_1,
 1509                              Register arg_2,
 1510                              Register arg_3,
 1511                              bool check_exceptions) {
 1512   LP64_ONLY(assert_different_registers(arg_1, c_rarg2, c_rarg3));
 1513   LP64_ONLY(assert_different_registers(arg_2, c_rarg3));
 1514   pass_arg3(this, arg_3);
 1515   pass_arg2(this, arg_2);
 1516   pass_arg1(this, arg_1);
 1517   call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions);
 1518 }
 1519 
 1520 void MacroAssembler::super_call_VM(Register oop_result,
 1521                                    Register last_java_sp,
 1522                                    address entry_point,
 1523                                    int number_of_arguments,
 1524                                    bool check_exceptions) {
 1525   Register thread = LP64_ONLY(r15_thread) NOT_LP64(noreg);
 1526   MacroAssembler::call_VM_base(oop_result, thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
 1527 }
 1528 
 1529 void MacroAssembler::super_call_VM(Register oop_result,
 1530                                    Register last_java_sp,
 1531                                    address entry_point,
 1532                                    Register arg_1,
 1533                                    bool check_exceptions) {
 1534   pass_arg1(this, arg_1);
 1535   super_call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
 1536 }
 1537 
 1538 void MacroAssembler::super_call_VM(Register oop_result,
 1539                                    Register last_java_sp,
 1540                                    address entry_point,
 1541                                    Register arg_1,
 1542                                    Register arg_2,
 1543                                    bool check_exceptions) {
 1544 
 1545   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
 1546   pass_arg2(this, arg_2);
 1547   pass_arg1(this, arg_1);
 1548   super_call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions);
 1549 }
 1550 
 1551 void MacroAssembler::super_call_VM(Register oop_result,
 1552                                    Register last_java_sp,
 1553                                    address entry_point,
 1554                                    Register arg_1,
 1555                                    Register arg_2,
 1556                                    Register arg_3,
 1557                                    bool check_exceptions) {
 1558   LP64_ONLY(assert_different_registers(arg_1, c_rarg2, c_rarg3));
 1559   LP64_ONLY(assert_different_registers(arg_2, c_rarg3));
 1560   pass_arg3(this, arg_3);
 1561   pass_arg2(this, arg_2);
 1562   pass_arg1(this, arg_1);
 1563   super_call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions);
 1564 }
 1565 
 1566 void MacroAssembler::call_VM_base(Register oop_result,
 1567                                   Register java_thread,
 1568                                   Register last_java_sp,
 1569                                   address  entry_point,
 1570                                   int      number_of_arguments,
 1571                                   bool     check_exceptions) {
 1572   // determine java_thread register
 1573   if (!java_thread->is_valid()) {
 1574 #ifdef _LP64
 1575     java_thread = r15_thread;
 1576 #else
 1577     java_thread = rdi;
 1578     get_thread(java_thread);
 1579 #endif // LP64
 1580   }
 1581   // determine last_java_sp register
 1582   if (!last_java_sp->is_valid()) {
 1583     last_java_sp = rsp;
 1584   }
 1585   // debugging support
 1586   assert(number_of_arguments >= 0   , "cannot have negative number of arguments");
 1587   LP64_ONLY(assert(java_thread == r15_thread, "unexpected register"));
 1588 #ifdef ASSERT
 1589   // TraceBytecodes does not use r12 but saves it over the call, so don't verify
 1590   // r12 is the heapbase.
 1591   LP64_ONLY(if (UseCompressedOops && !TraceBytecodes) verify_heapbase("call_VM_base: heap base corrupted?");)
 1592 #endif // ASSERT
 1593 
 1594   assert(java_thread != oop_result  , "cannot use the same register for java_thread & oop_result");
 1595   assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
 1596 
 1597   // push java thread (becomes first argument of C function)
 1598 
 1599   NOT_LP64(push(java_thread); number_of_arguments++);
 1600   LP64_ONLY(mov(c_rarg0, r15_thread));
 1601 
 1602   // set last Java frame before call
 1603   assert(last_java_sp != rbp, "can't use ebp/rbp");
 1604 
 1605   // Only interpreter should have to set fp
 1606   set_last_Java_frame(java_thread, last_java_sp, rbp, nullptr, rscratch1);
 1607 
 1608   // do the call, remove parameters
 1609   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
 1610 
 1611   // restore the thread (cannot use the pushed argument since arguments
 1612   // may be overwritten by C code generated by an optimizing compiler);
 1613   // however can use the register value directly if it is callee saved.
 1614   if (LP64_ONLY(true ||) java_thread == rdi || java_thread == rsi) {
 1615     // rdi & rsi (also r15) are callee saved -> nothing to do
 1616 #ifdef ASSERT
 1617     guarantee(java_thread != rax, "change this code");
 1618     push(rax);
 1619     { Label L;
 1620       get_thread(rax);
 1621       cmpptr(java_thread, rax);
 1622       jcc(Assembler::equal, L);
 1623       STOP("MacroAssembler::call_VM_base: rdi not callee saved?");
 1624       bind(L);
 1625     }
 1626     pop(rax);
 1627 #endif
 1628   } else {
 1629     get_thread(java_thread);
 1630   }
 1631   // reset last Java frame
 1632   // Only interpreter should have to clear fp
 1633   reset_last_Java_frame(java_thread, true);
 1634 
 1635    // C++ interp handles this in the interpreter
 1636   check_and_handle_popframe(java_thread);
 1637   check_and_handle_earlyret(java_thread);
 1638 
 1639   if (check_exceptions) {
 1640     // check for pending exceptions (java_thread is set upon return)
 1641     cmpptr(Address(java_thread, Thread::pending_exception_offset()), NULL_WORD);
 1642 #ifndef _LP64
 1643     jump_cc(Assembler::notEqual,
 1644             RuntimeAddress(StubRoutines::forward_exception_entry()));
 1645 #else
 1646     // This used to conditionally jump to forward_exception however it is
 1647     // possible if we relocate that the branch will not reach. So we must jump
 1648     // around so we can always reach
 1649 
 1650     Label ok;
 1651     jcc(Assembler::equal, ok);
 1652     jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
 1653     bind(ok);
 1654 #endif // LP64
 1655   }
 1656 
 1657   // get oop result if there is one and reset the value in the thread
 1658   if (oop_result->is_valid()) {
 1659     get_vm_result(oop_result, java_thread);
 1660   }
 1661 }
 1662 
 1663 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
 1664 
 1665   // Calculate the value for last_Java_sp
 1666   // somewhat subtle. call_VM does an intermediate call
 1667   // which places a return address on the stack just under the
 1668   // stack pointer as the user finished with it. This allows
 1669   // use to retrieve last_Java_pc from last_Java_sp[-1].
 1670   // On 32bit we then have to push additional args on the stack to accomplish
 1671   // the actual requested call. On 64bit call_VM only can use register args
 1672   // so the only extra space is the return address that call_VM created.
 1673   // This hopefully explains the calculations here.
 1674 
 1675 #ifdef _LP64
 1676   // We've pushed one address, correct last_Java_sp
 1677   lea(rax, Address(rsp, wordSize));
 1678 #else
 1679   lea(rax, Address(rsp, (1 + number_of_arguments) * wordSize));
 1680 #endif // LP64
 1681 
 1682   call_VM_base(oop_result, noreg, rax, entry_point, number_of_arguments, check_exceptions);
 1683 
 1684 }
 1685 
 1686 // Use this method when MacroAssembler version of call_VM_leaf_base() should be called from Interpreter.
 1687 void MacroAssembler::call_VM_leaf0(address entry_point) {
 1688   MacroAssembler::call_VM_leaf_base(entry_point, 0);
 1689 }
 1690 
 1691 void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
 1692   call_VM_leaf_base(entry_point, number_of_arguments);
 1693 }
 1694 
 1695 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0) {
 1696   pass_arg0(this, arg_0);
 1697   call_VM_leaf(entry_point, 1);
 1698 }
 1699 
 1700 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1) {
 1701 
 1702   LP64_ONLY(assert_different_registers(arg_0, c_rarg1));
 1703   pass_arg1(this, arg_1);
 1704   pass_arg0(this, arg_0);
 1705   call_VM_leaf(entry_point, 2);
 1706 }
 1707 
 1708 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
 1709   LP64_ONLY(assert_different_registers(arg_0, c_rarg1, c_rarg2));
 1710   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
 1711   pass_arg2(this, arg_2);
 1712   pass_arg1(this, arg_1);
 1713   pass_arg0(this, arg_0);
 1714   call_VM_leaf(entry_point, 3);
 1715 }
 1716 
 1717 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2, Register arg_3) {
 1718   LP64_ONLY(assert_different_registers(arg_0, c_rarg1, c_rarg2, c_rarg3));
 1719   LP64_ONLY(assert_different_registers(arg_1, c_rarg2, c_rarg3));
 1720   LP64_ONLY(assert_different_registers(arg_2, c_rarg3));
 1721   pass_arg3(this, arg_3);
 1722   pass_arg2(this, arg_2);
 1723   pass_arg1(this, arg_1);
 1724   pass_arg0(this, arg_0);
 1725   call_VM_leaf(entry_point, 3);
 1726 }
 1727 
 1728 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0) {
 1729   pass_arg0(this, arg_0);
 1730   MacroAssembler::call_VM_leaf_base(entry_point, 1);
 1731 }
 1732 
 1733 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1) {
 1734   LP64_ONLY(assert_different_registers(arg_0, c_rarg1));
 1735   pass_arg1(this, arg_1);
 1736   pass_arg0(this, arg_0);
 1737   MacroAssembler::call_VM_leaf_base(entry_point, 2);
 1738 }
 1739 
 1740 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
 1741   LP64_ONLY(assert_different_registers(arg_0, c_rarg1, c_rarg2));
 1742   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
 1743   pass_arg2(this, arg_2);
 1744   pass_arg1(this, arg_1);
 1745   pass_arg0(this, arg_0);
 1746   MacroAssembler::call_VM_leaf_base(entry_point, 3);
 1747 }
 1748 
 1749 void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2, Register arg_3) {
 1750   LP64_ONLY(assert_different_registers(arg_0, c_rarg1, c_rarg2, c_rarg3));
 1751   LP64_ONLY(assert_different_registers(arg_1, c_rarg2, c_rarg3));
 1752   LP64_ONLY(assert_different_registers(arg_2, c_rarg3));
 1753   pass_arg3(this, arg_3);
 1754   pass_arg2(this, arg_2);
 1755   pass_arg1(this, arg_1);
 1756   pass_arg0(this, arg_0);
 1757   MacroAssembler::call_VM_leaf_base(entry_point, 4);
 1758 }
 1759 
 1760 void MacroAssembler::get_vm_result(Register oop_result, Register java_thread) {
 1761   movptr(oop_result, Address(java_thread, JavaThread::vm_result_offset()));
 1762   movptr(Address(java_thread, JavaThread::vm_result_offset()), NULL_WORD);
 1763   verify_oop_msg(oop_result, "broken oop in call_VM_base");
 1764 }
 1765 
 1766 void MacroAssembler::get_vm_result_2(Register metadata_result, Register java_thread) {
 1767   movptr(metadata_result, Address(java_thread, JavaThread::vm_result_2_offset()));
 1768   movptr(Address(java_thread, JavaThread::vm_result_2_offset()), NULL_WORD);
 1769 }
 1770 
 1771 void MacroAssembler::check_and_handle_earlyret(Register java_thread) {
 1772 }
 1773 
 1774 void MacroAssembler::check_and_handle_popframe(Register java_thread) {
 1775 }
 1776 
 1777 void MacroAssembler::cmp32(AddressLiteral src1, int32_t imm, Register rscratch) {
 1778   assert(rscratch != noreg || always_reachable(src1), "missing");
 1779 
 1780   if (reachable(src1)) {
 1781     cmpl(as_Address(src1), imm);
 1782   } else {
 1783     lea(rscratch, src1);
 1784     cmpl(Address(rscratch, 0), imm);
 1785   }
 1786 }
 1787 
 1788 void MacroAssembler::cmp32(Register src1, AddressLiteral src2, Register rscratch) {
 1789   assert(!src2.is_lval(), "use cmpptr");
 1790   assert(rscratch != noreg || always_reachable(src2), "missing");
 1791 
 1792   if (reachable(src2)) {
 1793     cmpl(src1, as_Address(src2));
 1794   } else {
 1795     lea(rscratch, src2);
 1796     cmpl(src1, Address(rscratch, 0));
 1797   }
 1798 }
 1799 
 1800 void MacroAssembler::cmp32(Register src1, int32_t imm) {
 1801   Assembler::cmpl(src1, imm);
 1802 }
 1803 
 1804 void MacroAssembler::cmp32(Register src1, Address src2) {
 1805   Assembler::cmpl(src1, src2);
 1806 }
 1807 
 1808 void MacroAssembler::cmpsd2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
 1809   ucomisd(opr1, opr2);
 1810 
 1811   Label L;
 1812   if (unordered_is_less) {
 1813     movl(dst, -1);
 1814     jcc(Assembler::parity, L);
 1815     jcc(Assembler::below , L);
 1816     movl(dst, 0);
 1817     jcc(Assembler::equal , L);
 1818     increment(dst);
 1819   } else { // unordered is greater
 1820     movl(dst, 1);
 1821     jcc(Assembler::parity, L);
 1822     jcc(Assembler::above , L);
 1823     movl(dst, 0);
 1824     jcc(Assembler::equal , L);
 1825     decrementl(dst);
 1826   }
 1827   bind(L);
 1828 }
 1829 
 1830 void MacroAssembler::cmpss2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
 1831   ucomiss(opr1, opr2);
 1832 
 1833   Label L;
 1834   if (unordered_is_less) {
 1835     movl(dst, -1);
 1836     jcc(Assembler::parity, L);
 1837     jcc(Assembler::below , L);
 1838     movl(dst, 0);
 1839     jcc(Assembler::equal , L);
 1840     increment(dst);
 1841   } else { // unordered is greater
 1842     movl(dst, 1);
 1843     jcc(Assembler::parity, L);
 1844     jcc(Assembler::above , L);
 1845     movl(dst, 0);
 1846     jcc(Assembler::equal , L);
 1847     decrementl(dst);
 1848   }
 1849   bind(L);
 1850 }
 1851 
 1852 
 1853 void MacroAssembler::cmp8(AddressLiteral src1, int imm, Register rscratch) {
 1854   assert(rscratch != noreg || always_reachable(src1), "missing");
 1855 
 1856   if (reachable(src1)) {
 1857     cmpb(as_Address(src1), imm);
 1858   } else {
 1859     lea(rscratch, src1);
 1860     cmpb(Address(rscratch, 0), imm);
 1861   }
 1862 }
 1863 
 1864 void MacroAssembler::cmpptr(Register src1, AddressLiteral src2, Register rscratch) {
 1865 #ifdef _LP64
 1866   assert(rscratch != noreg || always_reachable(src2), "missing");
 1867 
 1868   if (src2.is_lval()) {
 1869     movptr(rscratch, src2);
 1870     Assembler::cmpq(src1, rscratch);
 1871   } else if (reachable(src2)) {
 1872     cmpq(src1, as_Address(src2));
 1873   } else {
 1874     lea(rscratch, src2);
 1875     Assembler::cmpq(src1, Address(rscratch, 0));
 1876   }
 1877 #else
 1878   assert(rscratch == noreg, "not needed");
 1879   if (src2.is_lval()) {
 1880     cmp_literal32(src1, (int32_t)src2.target(), src2.rspec());
 1881   } else {
 1882     cmpl(src1, as_Address(src2));
 1883   }
 1884 #endif // _LP64
 1885 }
 1886 
 1887 void MacroAssembler::cmpptr(Address src1, AddressLiteral src2, Register rscratch) {
 1888   assert(src2.is_lval(), "not a mem-mem compare");
 1889 #ifdef _LP64
 1890   // moves src2's literal address
 1891   movptr(rscratch, src2);
 1892   Assembler::cmpq(src1, rscratch);
 1893 #else
 1894   assert(rscratch == noreg, "not needed");
 1895   cmp_literal32(src1, (int32_t)src2.target(), src2.rspec());
 1896 #endif // _LP64
 1897 }
 1898 
 1899 void MacroAssembler::cmpoop(Register src1, Register src2) {
 1900   cmpptr(src1, src2);
 1901 }
 1902 
 1903 void MacroAssembler::cmpoop(Register src1, Address src2) {
 1904   cmpptr(src1, src2);
 1905 }
 1906 
 1907 #ifdef _LP64
 1908 void MacroAssembler::cmpoop(Register src1, jobject src2, Register rscratch) {
 1909   movoop(rscratch, src2);
 1910   cmpptr(src1, rscratch);
 1911 }
 1912 #endif
 1913 
 1914 void MacroAssembler::locked_cmpxchgptr(Register reg, AddressLiteral adr, Register rscratch) {
 1915   assert(rscratch != noreg || always_reachable(adr), "missing");
 1916 
 1917   if (reachable(adr)) {
 1918     lock();
 1919     cmpxchgptr(reg, as_Address(adr));
 1920   } else {
 1921     lea(rscratch, adr);
 1922     lock();
 1923     cmpxchgptr(reg, Address(rscratch, 0));
 1924   }
 1925 }
 1926 
 1927 void MacroAssembler::cmpxchgptr(Register reg, Address adr) {
 1928   LP64_ONLY(cmpxchgq(reg, adr)) NOT_LP64(cmpxchgl(reg, adr));
 1929 }
 1930 
 1931 void MacroAssembler::comisd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1932   assert(rscratch != noreg || always_reachable(src), "missing");
 1933 
 1934   if (reachable(src)) {
 1935     Assembler::comisd(dst, as_Address(src));
 1936   } else {
 1937     lea(rscratch, src);
 1938     Assembler::comisd(dst, Address(rscratch, 0));
 1939   }
 1940 }
 1941 
 1942 void MacroAssembler::comiss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 1943   assert(rscratch != noreg || always_reachable(src), "missing");
 1944 
 1945   if (reachable(src)) {
 1946     Assembler::comiss(dst, as_Address(src));
 1947   } else {
 1948     lea(rscratch, src);
 1949     Assembler::comiss(dst, Address(rscratch, 0));
 1950   }
 1951 }
 1952 
 1953 
 1954 void MacroAssembler::cond_inc32(Condition cond, AddressLiteral counter_addr, Register rscratch) {
 1955   assert(rscratch != noreg || always_reachable(counter_addr), "missing");
 1956 
 1957   Condition negated_cond = negate_condition(cond);
 1958   Label L;
 1959   jcc(negated_cond, L);
 1960   pushf(); // Preserve flags
 1961   atomic_incl(counter_addr, rscratch);
 1962   popf();
 1963   bind(L);
 1964 }
 1965 
 1966 int MacroAssembler::corrected_idivl(Register reg) {
 1967   // Full implementation of Java idiv and irem; checks for
 1968   // special case as described in JVM spec., p.243 & p.271.
 1969   // The function returns the (pc) offset of the idivl
 1970   // instruction - may be needed for implicit exceptions.
 1971   //
 1972   //         normal case                           special case
 1973   //
 1974   // input : rax,: dividend                         min_int
 1975   //         reg: divisor   (may not be rax,/rdx)   -1
 1976   //
 1977   // output: rax,: quotient  (= rax, idiv reg)       min_int
 1978   //         rdx: remainder (= rax, irem reg)       0
 1979   assert(reg != rax && reg != rdx, "reg cannot be rax, or rdx register");
 1980   const int min_int = 0x80000000;
 1981   Label normal_case, special_case;
 1982 
 1983   // check for special case
 1984   cmpl(rax, min_int);
 1985   jcc(Assembler::notEqual, normal_case);
 1986   xorl(rdx, rdx); // prepare rdx for possible special case (where remainder = 0)
 1987   cmpl(reg, -1);
 1988   jcc(Assembler::equal, special_case);
 1989 
 1990   // handle normal case
 1991   bind(normal_case);
 1992   cdql();
 1993   int idivl_offset = offset();
 1994   idivl(reg);
 1995 
 1996   // normal and special case exit
 1997   bind(special_case);
 1998 
 1999   return idivl_offset;
 2000 }
 2001 
 2002 
 2003 
 2004 void MacroAssembler::decrementl(Register reg, int value) {
 2005   if (value == min_jint) {subl(reg, value) ; return; }
 2006   if (value <  0) { incrementl(reg, -value); return; }
 2007   if (value == 0) {                        ; return; }
 2008   if (value == 1 && UseIncDec) { decl(reg) ; return; }
 2009   /* else */      { subl(reg, value)       ; return; }
 2010 }
 2011 
 2012 void MacroAssembler::decrementl(Address dst, int value) {
 2013   if (value == min_jint) {subl(dst, value) ; return; }
 2014   if (value <  0) { incrementl(dst, -value); return; }
 2015   if (value == 0) {                        ; return; }
 2016   if (value == 1 && UseIncDec) { decl(dst) ; return; }
 2017   /* else */      { subl(dst, value)       ; return; }
 2018 }
 2019 
 2020 void MacroAssembler::division_with_shift (Register reg, int shift_value) {
 2021   assert(shift_value > 0, "illegal shift value");
 2022   Label _is_positive;
 2023   testl (reg, reg);
 2024   jcc (Assembler::positive, _is_positive);
 2025   int offset = (1 << shift_value) - 1 ;
 2026 
 2027   if (offset == 1) {
 2028     incrementl(reg);
 2029   } else {
 2030     addl(reg, offset);
 2031   }
 2032 
 2033   bind (_is_positive);
 2034   sarl(reg, shift_value);
 2035 }
 2036 
 2037 void MacroAssembler::divsd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2038   assert(rscratch != noreg || always_reachable(src), "missing");
 2039 
 2040   if (reachable(src)) {
 2041     Assembler::divsd(dst, as_Address(src));
 2042   } else {
 2043     lea(rscratch, src);
 2044     Assembler::divsd(dst, Address(rscratch, 0));
 2045   }
 2046 }
 2047 
 2048 void MacroAssembler::divss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2049   assert(rscratch != noreg || always_reachable(src), "missing");
 2050 
 2051   if (reachable(src)) {
 2052     Assembler::divss(dst, as_Address(src));
 2053   } else {
 2054     lea(rscratch, src);
 2055     Assembler::divss(dst, Address(rscratch, 0));
 2056   }
 2057 }
 2058 
 2059 void MacroAssembler::enter() {
 2060   push(rbp);
 2061   mov(rbp, rsp);
 2062 }
 2063 
 2064 void MacroAssembler::post_call_nop() {
 2065   if (!Continuations::enabled()) {
 2066     return;
 2067   }
 2068   InstructionMark im(this);
 2069   relocate(post_call_nop_Relocation::spec());
 2070   InlineSkippedInstructionsCounter skipCounter(this);
 2071   emit_int8((uint8_t)0x0f);
 2072   emit_int8((uint8_t)0x1f);
 2073   emit_int8((uint8_t)0x84);
 2074   emit_int8((uint8_t)0x00);
 2075   emit_int32(0x00);
 2076 }
 2077 
 2078 // A 5 byte nop that is safe for patching (see patch_verified_entry)
 2079 void MacroAssembler::fat_nop() {
 2080   if (UseAddressNop) {
 2081     addr_nop_5();
 2082   } else {
 2083     emit_int8((uint8_t)0x26); // es:
 2084     emit_int8((uint8_t)0x2e); // cs:
 2085     emit_int8((uint8_t)0x64); // fs:
 2086     emit_int8((uint8_t)0x65); // gs:
 2087     emit_int8((uint8_t)0x90);
 2088   }
 2089 }
 2090 
 2091 #ifndef _LP64
 2092 void MacroAssembler::fcmp(Register tmp) {
 2093   fcmp(tmp, 1, true, true);
 2094 }
 2095 
 2096 void MacroAssembler::fcmp(Register tmp, int index, bool pop_left, bool pop_right) {
 2097   assert(!pop_right || pop_left, "usage error");
 2098   if (VM_Version::supports_cmov()) {
 2099     assert(tmp == noreg, "unneeded temp");
 2100     if (pop_left) {
 2101       fucomip(index);
 2102     } else {
 2103       fucomi(index);
 2104     }
 2105     if (pop_right) {
 2106       fpop();
 2107     }
 2108   } else {
 2109     assert(tmp != noreg, "need temp");
 2110     if (pop_left) {
 2111       if (pop_right) {
 2112         fcompp();
 2113       } else {
 2114         fcomp(index);
 2115       }
 2116     } else {
 2117       fcom(index);
 2118     }
 2119     // convert FPU condition into eflags condition via rax,
 2120     save_rax(tmp);
 2121     fwait(); fnstsw_ax();
 2122     sahf();
 2123     restore_rax(tmp);
 2124   }
 2125   // condition codes set as follows:
 2126   //
 2127   // CF (corresponds to C0) if x < y
 2128   // PF (corresponds to C2) if unordered
 2129   // ZF (corresponds to C3) if x = y
 2130 }
 2131 
 2132 void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less) {
 2133   fcmp2int(dst, unordered_is_less, 1, true, true);
 2134 }
 2135 
 2136 void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less, int index, bool pop_left, bool pop_right) {
 2137   fcmp(VM_Version::supports_cmov() ? noreg : dst, index, pop_left, pop_right);
 2138   Label L;
 2139   if (unordered_is_less) {
 2140     movl(dst, -1);
 2141     jcc(Assembler::parity, L);
 2142     jcc(Assembler::below , L);
 2143     movl(dst, 0);
 2144     jcc(Assembler::equal , L);
 2145     increment(dst);
 2146   } else { // unordered is greater
 2147     movl(dst, 1);
 2148     jcc(Assembler::parity, L);
 2149     jcc(Assembler::above , L);
 2150     movl(dst, 0);
 2151     jcc(Assembler::equal , L);
 2152     decrementl(dst);
 2153   }
 2154   bind(L);
 2155 }
 2156 
 2157 void MacroAssembler::fld_d(AddressLiteral src) {
 2158   fld_d(as_Address(src));
 2159 }
 2160 
 2161 void MacroAssembler::fld_s(AddressLiteral src) {
 2162   fld_s(as_Address(src));
 2163 }
 2164 
 2165 void MacroAssembler::fldcw(AddressLiteral src) {
 2166   fldcw(as_Address(src));
 2167 }
 2168 
 2169 void MacroAssembler::fpop() {
 2170   ffree();
 2171   fincstp();
 2172 }
 2173 
 2174 void MacroAssembler::fremr(Register tmp) {
 2175   save_rax(tmp);
 2176   { Label L;
 2177     bind(L);
 2178     fprem();
 2179     fwait(); fnstsw_ax();
 2180     sahf();
 2181     jcc(Assembler::parity, L);
 2182   }
 2183   restore_rax(tmp);
 2184   // Result is in ST0.
 2185   // Note: fxch & fpop to get rid of ST1
 2186   // (otherwise FPU stack could overflow eventually)
 2187   fxch(1);
 2188   fpop();
 2189 }
 2190 
 2191 void MacroAssembler::empty_FPU_stack() {
 2192   if (VM_Version::supports_mmx()) {
 2193     emms();
 2194   } else {
 2195     for (int i = 8; i-- > 0; ) ffree(i);
 2196   }
 2197 }
 2198 #endif // !LP64
 2199 
 2200 void MacroAssembler::mulpd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2201   assert(rscratch != noreg || always_reachable(src), "missing");
 2202   if (reachable(src)) {
 2203     Assembler::mulpd(dst, as_Address(src));
 2204   } else {
 2205     lea(rscratch, src);
 2206     Assembler::mulpd(dst, Address(rscratch, 0));
 2207   }
 2208 }
 2209 
 2210 void MacroAssembler::load_float(Address src) {
 2211 #ifdef _LP64
 2212   movflt(xmm0, src);
 2213 #else
 2214   if (UseSSE >= 1) {
 2215     movflt(xmm0, src);
 2216   } else {
 2217     fld_s(src);
 2218   }
 2219 #endif // LP64
 2220 }
 2221 
 2222 void MacroAssembler::store_float(Address dst) {
 2223 #ifdef _LP64
 2224   movflt(dst, xmm0);
 2225 #else
 2226   if (UseSSE >= 1) {
 2227     movflt(dst, xmm0);
 2228   } else {
 2229     fstp_s(dst);
 2230   }
 2231 #endif // LP64
 2232 }
 2233 
 2234 void MacroAssembler::load_double(Address src) {
 2235 #ifdef _LP64
 2236   movdbl(xmm0, src);
 2237 #else
 2238   if (UseSSE >= 2) {
 2239     movdbl(xmm0, src);
 2240   } else {
 2241     fld_d(src);
 2242   }
 2243 #endif // LP64
 2244 }
 2245 
 2246 void MacroAssembler::store_double(Address dst) {
 2247 #ifdef _LP64
 2248   movdbl(dst, xmm0);
 2249 #else
 2250   if (UseSSE >= 2) {
 2251     movdbl(dst, xmm0);
 2252   } else {
 2253     fstp_d(dst);
 2254   }
 2255 #endif // LP64
 2256 }
 2257 
 2258 // dst = c = a * b + c
 2259 void MacroAssembler::fmad(XMMRegister dst, XMMRegister a, XMMRegister b, XMMRegister c) {
 2260   Assembler::vfmadd231sd(c, a, b);
 2261   if (dst != c) {
 2262     movdbl(dst, c);
 2263   }
 2264 }
 2265 
 2266 // dst = c = a * b + c
 2267 void MacroAssembler::fmaf(XMMRegister dst, XMMRegister a, XMMRegister b, XMMRegister c) {
 2268   Assembler::vfmadd231ss(c, a, b);
 2269   if (dst != c) {
 2270     movflt(dst, c);
 2271   }
 2272 }
 2273 
 2274 // dst = c = a * b + c
 2275 void MacroAssembler::vfmad(XMMRegister dst, XMMRegister a, XMMRegister b, XMMRegister c, int vector_len) {
 2276   Assembler::vfmadd231pd(c, a, b, vector_len);
 2277   if (dst != c) {
 2278     vmovdqu(dst, c);
 2279   }
 2280 }
 2281 
 2282 // dst = c = a * b + c
 2283 void MacroAssembler::vfmaf(XMMRegister dst, XMMRegister a, XMMRegister b, XMMRegister c, int vector_len) {
 2284   Assembler::vfmadd231ps(c, a, b, vector_len);
 2285   if (dst != c) {
 2286     vmovdqu(dst, c);
 2287   }
 2288 }
 2289 
 2290 // dst = c = a * b + c
 2291 void MacroAssembler::vfmad(XMMRegister dst, XMMRegister a, Address b, XMMRegister c, int vector_len) {
 2292   Assembler::vfmadd231pd(c, a, b, vector_len);
 2293   if (dst != c) {
 2294     vmovdqu(dst, c);
 2295   }
 2296 }
 2297 
 2298 // dst = c = a * b + c
 2299 void MacroAssembler::vfmaf(XMMRegister dst, XMMRegister a, Address b, XMMRegister c, int vector_len) {
 2300   Assembler::vfmadd231ps(c, a, b, vector_len);
 2301   if (dst != c) {
 2302     vmovdqu(dst, c);
 2303   }
 2304 }
 2305 
 2306 void MacroAssembler::incrementl(AddressLiteral dst, Register rscratch) {
 2307   assert(rscratch != noreg || always_reachable(dst), "missing");
 2308 
 2309   if (reachable(dst)) {
 2310     incrementl(as_Address(dst));
 2311   } else {
 2312     lea(rscratch, dst);
 2313     incrementl(Address(rscratch, 0));
 2314   }
 2315 }
 2316 
 2317 void MacroAssembler::incrementl(ArrayAddress dst, Register rscratch) {
 2318   incrementl(as_Address(dst, rscratch));
 2319 }
 2320 
 2321 void MacroAssembler::incrementl(Register reg, int value) {
 2322   if (value == min_jint) {addl(reg, value) ; return; }
 2323   if (value <  0) { decrementl(reg, -value); return; }
 2324   if (value == 0) {                        ; return; }
 2325   if (value == 1 && UseIncDec) { incl(reg) ; return; }
 2326   /* else */      { addl(reg, value)       ; return; }
 2327 }
 2328 
 2329 void MacroAssembler::incrementl(Address dst, int value) {
 2330   if (value == min_jint) {addl(dst, value) ; return; }
 2331   if (value <  0) { decrementl(dst, -value); return; }
 2332   if (value == 0) {                        ; return; }
 2333   if (value == 1 && UseIncDec) { incl(dst) ; return; }
 2334   /* else */      { addl(dst, value)       ; return; }
 2335 }
 2336 
 2337 void MacroAssembler::jump(AddressLiteral dst, Register rscratch) {
 2338   assert(rscratch != noreg || always_reachable(dst), "missing");
 2339   assert(!dst.rspec().reloc()->is_data(), "should not use ExternalAddress for jump");
 2340   if (reachable(dst)) {
 2341     jmp_literal(dst.target(), dst.rspec());
 2342   } else {
 2343     lea(rscratch, dst);
 2344     jmp(rscratch);
 2345   }
 2346 }
 2347 
 2348 void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst, Register rscratch) {
 2349   assert(rscratch != noreg || always_reachable(dst), "missing");
 2350   assert(!dst.rspec().reloc()->is_data(), "should not use ExternalAddress for jump_cc");
 2351   if (reachable(dst)) {
 2352     InstructionMark im(this);
 2353     relocate(dst.reloc());
 2354     const int short_size = 2;
 2355     const int long_size = 6;
 2356     int offs = (intptr_t)dst.target() - ((intptr_t)pc());
 2357     if (dst.reloc() == relocInfo::none && is8bit(offs - short_size)) {
 2358       // 0111 tttn #8-bit disp
 2359       emit_int8(0x70 | cc);
 2360       emit_int8((offs - short_size) & 0xFF);
 2361     } else {
 2362       // 0000 1111 1000 tttn #32-bit disp
 2363       emit_int8(0x0F);
 2364       emit_int8((unsigned char)(0x80 | cc));
 2365       emit_int32(offs - long_size);
 2366     }
 2367   } else {
 2368 #ifdef ASSERT
 2369     warning("reversing conditional branch");
 2370 #endif /* ASSERT */
 2371     Label skip;
 2372     jccb(reverse[cc], skip);
 2373     lea(rscratch, dst);
 2374     Assembler::jmp(rscratch);
 2375     bind(skip);
 2376   }
 2377 }
 2378 
 2379 void MacroAssembler::ldmxcsr(AddressLiteral src, Register rscratch) {
 2380   assert(rscratch != noreg || always_reachable(src), "missing");
 2381 
 2382   if (reachable(src)) {
 2383     Assembler::ldmxcsr(as_Address(src));
 2384   } else {
 2385     lea(rscratch, src);
 2386     Assembler::ldmxcsr(Address(rscratch, 0));
 2387   }
 2388 }
 2389 
 2390 int MacroAssembler::load_signed_byte(Register dst, Address src) {
 2391   int off;
 2392   if (LP64_ONLY(true ||) VM_Version::is_P6()) {
 2393     off = offset();
 2394     movsbl(dst, src); // movsxb
 2395   } else {
 2396     off = load_unsigned_byte(dst, src);
 2397     shll(dst, 24);
 2398     sarl(dst, 24);
 2399   }
 2400   return off;
 2401 }
 2402 
 2403 // Note: load_signed_short used to be called load_signed_word.
 2404 // Although the 'w' in x86 opcodes refers to the term "word" in the assembler
 2405 // manual, which means 16 bits, that usage is found nowhere in HotSpot code.
 2406 // The term "word" in HotSpot means a 32- or 64-bit machine word.
 2407 int MacroAssembler::load_signed_short(Register dst, Address src) {
 2408   int off;
 2409   if (LP64_ONLY(true ||) VM_Version::is_P6()) {
 2410     // This is dubious to me since it seems safe to do a signed 16 => 64 bit
 2411     // version but this is what 64bit has always done. This seems to imply
 2412     // that users are only using 32bits worth.
 2413     off = offset();
 2414     movswl(dst, src); // movsxw
 2415   } else {
 2416     off = load_unsigned_short(dst, src);
 2417     shll(dst, 16);
 2418     sarl(dst, 16);
 2419   }
 2420   return off;
 2421 }
 2422 
 2423 int MacroAssembler::load_unsigned_byte(Register dst, Address src) {
 2424   // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
 2425   // and "3.9 Partial Register Penalties", p. 22).
 2426   int off;
 2427   if (LP64_ONLY(true || ) VM_Version::is_P6() || src.uses(dst)) {
 2428     off = offset();
 2429     movzbl(dst, src); // movzxb
 2430   } else {
 2431     xorl(dst, dst);
 2432     off = offset();
 2433     movb(dst, src);
 2434   }
 2435   return off;
 2436 }
 2437 
 2438 // Note: load_unsigned_short used to be called load_unsigned_word.
 2439 int MacroAssembler::load_unsigned_short(Register dst, Address src) {
 2440   // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
 2441   // and "3.9 Partial Register Penalties", p. 22).
 2442   int off;
 2443   if (LP64_ONLY(true ||) VM_Version::is_P6() || src.uses(dst)) {
 2444     off = offset();
 2445     movzwl(dst, src); // movzxw
 2446   } else {
 2447     xorl(dst, dst);
 2448     off = offset();
 2449     movw(dst, src);
 2450   }
 2451   return off;
 2452 }
 2453 
 2454 void MacroAssembler::load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed, Register dst2) {
 2455   switch (size_in_bytes) {
 2456 #ifndef _LP64
 2457   case  8:
 2458     assert(dst2 != noreg, "second dest register required");
 2459     movl(dst,  src);
 2460     movl(dst2, src.plus_disp(BytesPerInt));
 2461     break;
 2462 #else
 2463   case  8:  movq(dst, src); break;
 2464 #endif
 2465   case  4:  movl(dst, src); break;
 2466   case  2:  is_signed ? load_signed_short(dst, src) : load_unsigned_short(dst, src); break;
 2467   case  1:  is_signed ? load_signed_byte( dst, src) : load_unsigned_byte( dst, src); break;
 2468   default:  ShouldNotReachHere();
 2469   }
 2470 }
 2471 
 2472 void MacroAssembler::store_sized_value(Address dst, Register src, size_t size_in_bytes, Register src2) {
 2473   switch (size_in_bytes) {
 2474 #ifndef _LP64
 2475   case  8:
 2476     assert(src2 != noreg, "second source register required");
 2477     movl(dst,                        src);
 2478     movl(dst.plus_disp(BytesPerInt), src2);
 2479     break;
 2480 #else
 2481   case  8:  movq(dst, src); break;
 2482 #endif
 2483   case  4:  movl(dst, src); break;
 2484   case  2:  movw(dst, src); break;
 2485   case  1:  movb(dst, src); break;
 2486   default:  ShouldNotReachHere();
 2487   }
 2488 }
 2489 
 2490 void MacroAssembler::mov32(AddressLiteral dst, Register src, Register rscratch) {
 2491   assert(rscratch != noreg || always_reachable(dst), "missing");
 2492 
 2493   if (reachable(dst)) {
 2494     movl(as_Address(dst), src);
 2495   } else {
 2496     lea(rscratch, dst);
 2497     movl(Address(rscratch, 0), src);
 2498   }
 2499 }
 2500 
 2501 void MacroAssembler::mov32(Register dst, AddressLiteral src) {
 2502   if (reachable(src)) {
 2503     movl(dst, as_Address(src));
 2504   } else {
 2505     lea(dst, src);
 2506     movl(dst, Address(dst, 0));
 2507   }
 2508 }
 2509 
 2510 // C++ bool manipulation
 2511 
 2512 void MacroAssembler::movbool(Register dst, Address src) {
 2513   if(sizeof(bool) == 1)
 2514     movb(dst, src);
 2515   else if(sizeof(bool) == 2)
 2516     movw(dst, src);
 2517   else if(sizeof(bool) == 4)
 2518     movl(dst, src);
 2519   else
 2520     // unsupported
 2521     ShouldNotReachHere();
 2522 }
 2523 
 2524 void MacroAssembler::movbool(Address dst, bool boolconst) {
 2525   if(sizeof(bool) == 1)
 2526     movb(dst, (int) boolconst);
 2527   else if(sizeof(bool) == 2)
 2528     movw(dst, (int) boolconst);
 2529   else if(sizeof(bool) == 4)
 2530     movl(dst, (int) boolconst);
 2531   else
 2532     // unsupported
 2533     ShouldNotReachHere();
 2534 }
 2535 
 2536 void MacroAssembler::movbool(Address dst, Register src) {
 2537   if(sizeof(bool) == 1)
 2538     movb(dst, src);
 2539   else if(sizeof(bool) == 2)
 2540     movw(dst, src);
 2541   else if(sizeof(bool) == 4)
 2542     movl(dst, src);
 2543   else
 2544     // unsupported
 2545     ShouldNotReachHere();
 2546 }
 2547 
 2548 void MacroAssembler::movdl(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2549   assert(rscratch != noreg || always_reachable(src), "missing");
 2550 
 2551   if (reachable(src)) {
 2552     movdl(dst, as_Address(src));
 2553   } else {
 2554     lea(rscratch, src);
 2555     movdl(dst, Address(rscratch, 0));
 2556   }
 2557 }
 2558 
 2559 void MacroAssembler::movq(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2560   assert(rscratch != noreg || always_reachable(src), "missing");
 2561 
 2562   if (reachable(src)) {
 2563     movq(dst, as_Address(src));
 2564   } else {
 2565     lea(rscratch, src);
 2566     movq(dst, Address(rscratch, 0));
 2567   }
 2568 }
 2569 
 2570 void MacroAssembler::movdbl(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2571   assert(rscratch != noreg || always_reachable(src), "missing");
 2572 
 2573   if (reachable(src)) {
 2574     if (UseXmmLoadAndClearUpper) {
 2575       movsd (dst, as_Address(src));
 2576     } else {
 2577       movlpd(dst, as_Address(src));
 2578     }
 2579   } else {
 2580     lea(rscratch, src);
 2581     if (UseXmmLoadAndClearUpper) {
 2582       movsd (dst, Address(rscratch, 0));
 2583     } else {
 2584       movlpd(dst, Address(rscratch, 0));
 2585     }
 2586   }
 2587 }
 2588 
 2589 void MacroAssembler::movflt(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2590   assert(rscratch != noreg || always_reachable(src), "missing");
 2591 
 2592   if (reachable(src)) {
 2593     movss(dst, as_Address(src));
 2594   } else {
 2595     lea(rscratch, src);
 2596     movss(dst, Address(rscratch, 0));
 2597   }
 2598 }
 2599 
 2600 void MacroAssembler::movptr(Register dst, Register src) {
 2601   LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
 2602 }
 2603 
 2604 void MacroAssembler::movptr(Register dst, Address src) {
 2605   LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
 2606 }
 2607 
 2608 // src should NEVER be a real pointer. Use AddressLiteral for true pointers
 2609 void MacroAssembler::movptr(Register dst, intptr_t src) {
 2610 #ifdef _LP64
 2611   if (is_uimm32(src)) {
 2612     movl(dst, checked_cast<uint32_t>(src));
 2613   } else if (is_simm32(src)) {
 2614     movq(dst, checked_cast<int32_t>(src));
 2615   } else {
 2616     mov64(dst, src);
 2617   }
 2618 #else
 2619   movl(dst, src);
 2620 #endif
 2621 }
 2622 
 2623 void MacroAssembler::movptr(Address dst, Register src) {
 2624   LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
 2625 }
 2626 
 2627 void MacroAssembler::movptr(Address dst, int32_t src) {
 2628   LP64_ONLY(movslq(dst, src)) NOT_LP64(movl(dst, src));
 2629 }
 2630 
 2631 void MacroAssembler::movdqu(Address dst, XMMRegister src) {
 2632   assert(((src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2633   Assembler::movdqu(dst, src);
 2634 }
 2635 
 2636 void MacroAssembler::movdqu(XMMRegister dst, Address src) {
 2637   assert(((dst->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2638   Assembler::movdqu(dst, src);
 2639 }
 2640 
 2641 void MacroAssembler::movdqu(XMMRegister dst, XMMRegister src) {
 2642   assert(((dst->encoding() < 16  && src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2643   Assembler::movdqu(dst, src);
 2644 }
 2645 
 2646 void MacroAssembler::movdqu(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2647   assert(rscratch != noreg || always_reachable(src), "missing");
 2648 
 2649   if (reachable(src)) {
 2650     movdqu(dst, as_Address(src));
 2651   } else {
 2652     lea(rscratch, src);
 2653     movdqu(dst, Address(rscratch, 0));
 2654   }
 2655 }
 2656 
 2657 void MacroAssembler::vmovdqu(Address dst, XMMRegister src) {
 2658   assert(((src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2659   Assembler::vmovdqu(dst, src);
 2660 }
 2661 
 2662 void MacroAssembler::vmovdqu(XMMRegister dst, Address src) {
 2663   assert(((dst->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2664   Assembler::vmovdqu(dst, src);
 2665 }
 2666 
 2667 void MacroAssembler::vmovdqu(XMMRegister dst, XMMRegister src) {
 2668   assert(((dst->encoding() < 16  && src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 2669   Assembler::vmovdqu(dst, src);
 2670 }
 2671 
 2672 void MacroAssembler::vmovdqu(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2673   assert(rscratch != noreg || always_reachable(src), "missing");
 2674 
 2675   if (reachable(src)) {
 2676     vmovdqu(dst, as_Address(src));
 2677   }
 2678   else {
 2679     lea(rscratch, src);
 2680     vmovdqu(dst, Address(rscratch, 0));
 2681   }
 2682 }
 2683 
 2684 void MacroAssembler::vmovdqu(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 2685   assert(rscratch != noreg || always_reachable(src), "missing");
 2686 
 2687   if (vector_len == AVX_512bit) {
 2688     evmovdquq(dst, src, AVX_512bit, rscratch);
 2689   } else if (vector_len == AVX_256bit) {
 2690     vmovdqu(dst, src, rscratch);
 2691   } else {
 2692     movdqu(dst, src, rscratch);
 2693   }
 2694 }
 2695 
 2696 void MacroAssembler::kmov(KRegister dst, Address src) {
 2697   if (VM_Version::supports_avx512bw()) {
 2698     kmovql(dst, src);
 2699   } else {
 2700     assert(VM_Version::supports_evex(), "");
 2701     kmovwl(dst, src);
 2702   }
 2703 }
 2704 
 2705 void MacroAssembler::kmov(Address dst, KRegister src) {
 2706   if (VM_Version::supports_avx512bw()) {
 2707     kmovql(dst, src);
 2708   } else {
 2709     assert(VM_Version::supports_evex(), "");
 2710     kmovwl(dst, src);
 2711   }
 2712 }
 2713 
 2714 void MacroAssembler::kmov(KRegister dst, KRegister src) {
 2715   if (VM_Version::supports_avx512bw()) {
 2716     kmovql(dst, src);
 2717   } else {
 2718     assert(VM_Version::supports_evex(), "");
 2719     kmovwl(dst, src);
 2720   }
 2721 }
 2722 
 2723 void MacroAssembler::kmov(Register dst, KRegister src) {
 2724   if (VM_Version::supports_avx512bw()) {
 2725     kmovql(dst, src);
 2726   } else {
 2727     assert(VM_Version::supports_evex(), "");
 2728     kmovwl(dst, src);
 2729   }
 2730 }
 2731 
 2732 void MacroAssembler::kmov(KRegister dst, Register src) {
 2733   if (VM_Version::supports_avx512bw()) {
 2734     kmovql(dst, src);
 2735   } else {
 2736     assert(VM_Version::supports_evex(), "");
 2737     kmovwl(dst, src);
 2738   }
 2739 }
 2740 
 2741 void MacroAssembler::kmovql(KRegister dst, AddressLiteral src, Register rscratch) {
 2742   assert(rscratch != noreg || always_reachable(src), "missing");
 2743 
 2744   if (reachable(src)) {
 2745     kmovql(dst, as_Address(src));
 2746   } else {
 2747     lea(rscratch, src);
 2748     kmovql(dst, Address(rscratch, 0));
 2749   }
 2750 }
 2751 
 2752 void MacroAssembler::kmovwl(KRegister dst, AddressLiteral src, Register rscratch) {
 2753   assert(rscratch != noreg || always_reachable(src), "missing");
 2754 
 2755   if (reachable(src)) {
 2756     kmovwl(dst, as_Address(src));
 2757   } else {
 2758     lea(rscratch, src);
 2759     kmovwl(dst, Address(rscratch, 0));
 2760   }
 2761 }
 2762 
 2763 void MacroAssembler::evmovdqub(XMMRegister dst, KRegister mask, AddressLiteral src, bool merge,
 2764                                int vector_len, Register rscratch) {
 2765   assert(rscratch != noreg || always_reachable(src), "missing");
 2766 
 2767   if (reachable(src)) {
 2768     Assembler::evmovdqub(dst, mask, as_Address(src), merge, vector_len);
 2769   } else {
 2770     lea(rscratch, src);
 2771     Assembler::evmovdqub(dst, mask, Address(rscratch, 0), merge, vector_len);
 2772   }
 2773 }
 2774 
 2775 void MacroAssembler::evmovdquw(XMMRegister dst, KRegister mask, AddressLiteral src, bool merge,
 2776                                int vector_len, Register rscratch) {
 2777   assert(rscratch != noreg || always_reachable(src), "missing");
 2778 
 2779   if (reachable(src)) {
 2780     Assembler::evmovdquw(dst, mask, as_Address(src), merge, vector_len);
 2781   } else {
 2782     lea(rscratch, src);
 2783     Assembler::evmovdquw(dst, mask, Address(rscratch, 0), merge, vector_len);
 2784   }
 2785 }
 2786 
 2787 void MacroAssembler::evmovdqul(XMMRegister dst, KRegister mask, AddressLiteral src, bool merge, int vector_len, Register rscratch) {
 2788   assert(rscratch != noreg || always_reachable(src), "missing");
 2789 
 2790   if (reachable(src)) {
 2791     Assembler::evmovdqul(dst, mask, as_Address(src), merge, vector_len);
 2792   } else {
 2793     lea(rscratch, src);
 2794     Assembler::evmovdqul(dst, mask, Address(rscratch, 0), merge, vector_len);
 2795   }
 2796 }
 2797 
 2798 void MacroAssembler::evmovdquq(XMMRegister dst, KRegister mask, AddressLiteral src, bool merge, int vector_len, Register rscratch) {
 2799   assert(rscratch != noreg || always_reachable(src), "missing");
 2800 
 2801   if (reachable(src)) {
 2802     Assembler::evmovdquq(dst, mask, as_Address(src), merge, vector_len);
 2803   } else {
 2804     lea(rscratch, src);
 2805     Assembler::evmovdquq(dst, mask, Address(rscratch, 0), merge, vector_len);
 2806   }
 2807 }
 2808 
 2809 void MacroAssembler::evmovdquq(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 2810   assert(rscratch != noreg || always_reachable(src), "missing");
 2811 
 2812   if (reachable(src)) {
 2813     Assembler::evmovdquq(dst, as_Address(src), vector_len);
 2814   } else {
 2815     lea(rscratch, src);
 2816     Assembler::evmovdquq(dst, Address(rscratch, 0), vector_len);
 2817   }
 2818 }
 2819 
 2820 void MacroAssembler::movdqa(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2821   assert(rscratch != noreg || always_reachable(src), "missing");
 2822 
 2823   if (reachable(src)) {
 2824     Assembler::movdqa(dst, as_Address(src));
 2825   } else {
 2826     lea(rscratch, src);
 2827     Assembler::movdqa(dst, Address(rscratch, 0));
 2828   }
 2829 }
 2830 
 2831 void MacroAssembler::movsd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2832   assert(rscratch != noreg || always_reachable(src), "missing");
 2833 
 2834   if (reachable(src)) {
 2835     Assembler::movsd(dst, as_Address(src));
 2836   } else {
 2837     lea(rscratch, src);
 2838     Assembler::movsd(dst, Address(rscratch, 0));
 2839   }
 2840 }
 2841 
 2842 void MacroAssembler::movss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2843   assert(rscratch != noreg || always_reachable(src), "missing");
 2844 
 2845   if (reachable(src)) {
 2846     Assembler::movss(dst, as_Address(src));
 2847   } else {
 2848     lea(rscratch, src);
 2849     Assembler::movss(dst, Address(rscratch, 0));
 2850   }
 2851 }
 2852 
 2853 void MacroAssembler::movddup(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2854   assert(rscratch != noreg || always_reachable(src), "missing");
 2855 
 2856   if (reachable(src)) {
 2857     Assembler::movddup(dst, as_Address(src));
 2858   } else {
 2859     lea(rscratch, src);
 2860     Assembler::movddup(dst, Address(rscratch, 0));
 2861   }
 2862 }
 2863 
 2864 void MacroAssembler::vmovddup(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 2865   assert(rscratch != noreg || always_reachable(src), "missing");
 2866 
 2867   if (reachable(src)) {
 2868     Assembler::vmovddup(dst, as_Address(src), vector_len);
 2869   } else {
 2870     lea(rscratch, src);
 2871     Assembler::vmovddup(dst, Address(rscratch, 0), vector_len);
 2872   }
 2873 }
 2874 
 2875 void MacroAssembler::mulsd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2876   assert(rscratch != noreg || always_reachable(src), "missing");
 2877 
 2878   if (reachable(src)) {
 2879     Assembler::mulsd(dst, as_Address(src));
 2880   } else {
 2881     lea(rscratch, src);
 2882     Assembler::mulsd(dst, Address(rscratch, 0));
 2883   }
 2884 }
 2885 
 2886 void MacroAssembler::mulss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 2887   assert(rscratch != noreg || always_reachable(src), "missing");
 2888 
 2889   if (reachable(src)) {
 2890     Assembler::mulss(dst, as_Address(src));
 2891   } else {
 2892     lea(rscratch, src);
 2893     Assembler::mulss(dst, Address(rscratch, 0));
 2894   }
 2895 }
 2896 
 2897 void MacroAssembler::null_check(Register reg, int offset) {
 2898   if (needs_explicit_null_check(offset)) {
 2899     // provoke OS null exception if reg is null by
 2900     // accessing M[reg] w/o changing any (non-CC) registers
 2901     // NOTE: cmpl is plenty here to provoke a segv
 2902     cmpptr(rax, Address(reg, 0));
 2903     // Note: should probably use testl(rax, Address(reg, 0));
 2904     //       may be shorter code (however, this version of
 2905     //       testl needs to be implemented first)
 2906   } else {
 2907     // nothing to do, (later) access of M[reg + offset]
 2908     // will provoke OS null exception if reg is null
 2909   }
 2910 }
 2911 
 2912 void MacroAssembler::os_breakpoint() {
 2913   // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
 2914   // (e.g., MSVC can't call ps() otherwise)
 2915   call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
 2916 }
 2917 
 2918 void MacroAssembler::unimplemented(const char* what) {
 2919   const char* buf = nullptr;
 2920   {
 2921     ResourceMark rm;
 2922     stringStream ss;
 2923     ss.print("unimplemented: %s", what);
 2924     buf = code_string(ss.as_string());
 2925   }
 2926   stop(buf);
 2927 }
 2928 
 2929 #ifdef _LP64
 2930 #define XSTATE_BV 0x200
 2931 #endif
 2932 
 2933 void MacroAssembler::pop_CPU_state() {
 2934   pop_FPU_state();
 2935   pop_IU_state();
 2936 }
 2937 
 2938 void MacroAssembler::pop_FPU_state() {
 2939 #ifndef _LP64
 2940   frstor(Address(rsp, 0));
 2941 #else
 2942   fxrstor(Address(rsp, 0));
 2943 #endif
 2944   addptr(rsp, FPUStateSizeInWords * wordSize);
 2945 }
 2946 
 2947 void MacroAssembler::pop_IU_state() {
 2948   popa();
 2949   LP64_ONLY(addq(rsp, 8));
 2950   popf();
 2951 }
 2952 
 2953 // Save Integer and Float state
 2954 // Warning: Stack must be 16 byte aligned (64bit)
 2955 void MacroAssembler::push_CPU_state() {
 2956   push_IU_state();
 2957   push_FPU_state();
 2958 }
 2959 
 2960 void MacroAssembler::push_FPU_state() {
 2961   subptr(rsp, FPUStateSizeInWords * wordSize);
 2962 #ifndef _LP64
 2963   fnsave(Address(rsp, 0));
 2964   fwait();
 2965 #else
 2966   fxsave(Address(rsp, 0));
 2967 #endif // LP64
 2968 }
 2969 
 2970 void MacroAssembler::push_IU_state() {
 2971   // Push flags first because pusha kills them
 2972   pushf();
 2973   // Make sure rsp stays 16-byte aligned
 2974   LP64_ONLY(subq(rsp, 8));
 2975   pusha();
 2976 }
 2977 
 2978 void MacroAssembler::push_cont_fastpath() {
 2979   if (!Continuations::enabled()) return;
 2980 
 2981 #ifndef _LP64
 2982   Register rthread = rax;
 2983   Register rrealsp = rbx;
 2984   push(rthread);
 2985   push(rrealsp);
 2986 
 2987   get_thread(rthread);
 2988 
 2989   // The code below wants the original RSP.
 2990   // Move it back after the pushes above.
 2991   movptr(rrealsp, rsp);
 2992   addptr(rrealsp, 2*wordSize);
 2993 #else
 2994   Register rthread = r15_thread;
 2995   Register rrealsp = rsp;
 2996 #endif
 2997 
 2998   Label done;
 2999   cmpptr(rrealsp, Address(rthread, JavaThread::cont_fastpath_offset()));
 3000   jccb(Assembler::belowEqual, done);
 3001   movptr(Address(rthread, JavaThread::cont_fastpath_offset()), rrealsp);
 3002   bind(done);
 3003 
 3004 #ifndef _LP64
 3005   pop(rrealsp);
 3006   pop(rthread);
 3007 #endif
 3008 }
 3009 
 3010 void MacroAssembler::pop_cont_fastpath() {
 3011   if (!Continuations::enabled()) return;
 3012 
 3013 #ifndef _LP64
 3014   Register rthread = rax;
 3015   Register rrealsp = rbx;
 3016   push(rthread);
 3017   push(rrealsp);
 3018 
 3019   get_thread(rthread);
 3020 
 3021   // The code below wants the original RSP.
 3022   // Move it back after the pushes above.
 3023   movptr(rrealsp, rsp);
 3024   addptr(rrealsp, 2*wordSize);
 3025 #else
 3026   Register rthread = r15_thread;
 3027   Register rrealsp = rsp;
 3028 #endif
 3029 
 3030   Label done;
 3031   cmpptr(rrealsp, Address(rthread, JavaThread::cont_fastpath_offset()));
 3032   jccb(Assembler::below, done);
 3033   movptr(Address(rthread, JavaThread::cont_fastpath_offset()), 0);
 3034   bind(done);
 3035 
 3036 #ifndef _LP64
 3037   pop(rrealsp);
 3038   pop(rthread);
 3039 #endif
 3040 }
 3041 
 3042 void MacroAssembler::inc_held_monitor_count() {
 3043 #ifdef _LP64
 3044   incrementq(Address(r15_thread, JavaThread::held_monitor_count_offset()));
 3045 #endif
 3046 }
 3047 
 3048 void MacroAssembler::dec_held_monitor_count() {
 3049 #ifdef _LP64
 3050   decrementq(Address(r15_thread, JavaThread::held_monitor_count_offset()));
 3051 #endif
 3052 }
 3053 
 3054 #ifdef ASSERT
 3055 void MacroAssembler::stop_if_in_cont(Register cont, const char* name) {
 3056 #ifdef _LP64
 3057   Label no_cont;
 3058   movptr(cont, Address(r15_thread, JavaThread::cont_entry_offset()));
 3059   testl(cont, cont);
 3060   jcc(Assembler::zero, no_cont);
 3061   stop(name);
 3062   bind(no_cont);
 3063 #else
 3064   Unimplemented();
 3065 #endif
 3066 }
 3067 #endif
 3068 
 3069 void MacroAssembler::reset_last_Java_frame(Register java_thread, bool clear_fp) { // determine java_thread register
 3070   if (!java_thread->is_valid()) {
 3071     java_thread = rdi;
 3072     get_thread(java_thread);
 3073   }
 3074   // we must set sp to zero to clear frame
 3075   movptr(Address(java_thread, JavaThread::last_Java_sp_offset()), NULL_WORD);
 3076   // must clear fp, so that compiled frames are not confused; it is
 3077   // possible that we need it only for debugging
 3078   if (clear_fp) {
 3079     movptr(Address(java_thread, JavaThread::last_Java_fp_offset()), NULL_WORD);
 3080   }
 3081   // Always clear the pc because it could have been set by make_walkable()
 3082   movptr(Address(java_thread, JavaThread::last_Java_pc_offset()), NULL_WORD);
 3083   vzeroupper();
 3084 }
 3085 
 3086 void MacroAssembler::restore_rax(Register tmp) {
 3087   if (tmp == noreg) pop(rax);
 3088   else if (tmp != rax) mov(rax, tmp);
 3089 }
 3090 
 3091 void MacroAssembler::round_to(Register reg, int modulus) {
 3092   addptr(reg, modulus - 1);
 3093   andptr(reg, -modulus);
 3094 }
 3095 
 3096 void MacroAssembler::save_rax(Register tmp) {
 3097   if (tmp == noreg) push(rax);
 3098   else if (tmp != rax) mov(tmp, rax);
 3099 }
 3100 
 3101 void MacroAssembler::safepoint_poll(Label& slow_path, Register thread_reg, bool at_return, bool in_nmethod) {
 3102   if (at_return) {
 3103     // Note that when in_nmethod is set, the stack pointer is incremented before the poll. Therefore,
 3104     // we may safely use rsp instead to perform the stack watermark check.
 3105     cmpptr(in_nmethod ? rsp : rbp, Address(thread_reg, JavaThread::polling_word_offset()));
 3106     jcc(Assembler::above, slow_path);
 3107     return;
 3108   }
 3109   testb(Address(thread_reg, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
 3110   jcc(Assembler::notZero, slow_path); // handshake bit set implies poll
 3111 }
 3112 
 3113 // Calls to C land
 3114 //
 3115 // When entering C land, the rbp, & rsp of the last Java frame have to be recorded
 3116 // in the (thread-local) JavaThread object. When leaving C land, the last Java fp
 3117 // has to be reset to 0. This is required to allow proper stack traversal.
 3118 void MacroAssembler::set_last_Java_frame(Register java_thread,
 3119                                          Register last_java_sp,
 3120                                          Register last_java_fp,
 3121                                          address  last_java_pc,
 3122                                          Register rscratch) {
 3123   vzeroupper();
 3124   // determine java_thread register
 3125   if (!java_thread->is_valid()) {
 3126     java_thread = rdi;
 3127     get_thread(java_thread);
 3128   }
 3129   // determine last_java_sp register
 3130   if (!last_java_sp->is_valid()) {
 3131     last_java_sp = rsp;
 3132   }
 3133   // last_java_fp is optional
 3134   if (last_java_fp->is_valid()) {
 3135     movptr(Address(java_thread, JavaThread::last_Java_fp_offset()), last_java_fp);
 3136   }
 3137   // last_java_pc is optional
 3138   if (last_java_pc != nullptr) {
 3139     Address java_pc(java_thread,
 3140                     JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset());
 3141     lea(java_pc, InternalAddress(last_java_pc), rscratch);
 3142   }
 3143   movptr(Address(java_thread, JavaThread::last_Java_sp_offset()), last_java_sp);
 3144 }
 3145 
 3146 #ifdef _LP64
 3147 void MacroAssembler::set_last_Java_frame(Register last_java_sp,
 3148                                          Register last_java_fp,
 3149                                          Label &L,
 3150                                          Register scratch) {
 3151   lea(scratch, L);
 3152   movptr(Address(r15_thread, JavaThread::last_Java_pc_offset()), scratch);
 3153   set_last_Java_frame(r15_thread, last_java_sp, last_java_fp, nullptr, scratch);
 3154 }
 3155 #endif
 3156 
 3157 void MacroAssembler::shlptr(Register dst, int imm8) {
 3158   LP64_ONLY(shlq(dst, imm8)) NOT_LP64(shll(dst, imm8));
 3159 }
 3160 
 3161 void MacroAssembler::shrptr(Register dst, int imm8) {
 3162   LP64_ONLY(shrq(dst, imm8)) NOT_LP64(shrl(dst, imm8));
 3163 }
 3164 
 3165 void MacroAssembler::sign_extend_byte(Register reg) {
 3166   if (LP64_ONLY(true ||) (VM_Version::is_P6() && reg->has_byte_register())) {
 3167     movsbl(reg, reg); // movsxb
 3168   } else {
 3169     shll(reg, 24);
 3170     sarl(reg, 24);
 3171   }
 3172 }
 3173 
 3174 void MacroAssembler::sign_extend_short(Register reg) {
 3175   if (LP64_ONLY(true ||) VM_Version::is_P6()) {
 3176     movswl(reg, reg); // movsxw
 3177   } else {
 3178     shll(reg, 16);
 3179     sarl(reg, 16);
 3180   }
 3181 }
 3182 
 3183 void MacroAssembler::testl(Address dst, int32_t imm32) {
 3184   if (imm32 >= 0 && is8bit(imm32)) {
 3185     testb(dst, imm32);
 3186   } else {
 3187     Assembler::testl(dst, imm32);
 3188   }
 3189 }
 3190 
 3191 void MacroAssembler::testl(Register dst, int32_t imm32) {
 3192   if (imm32 >= 0 && is8bit(imm32) && dst->has_byte_register()) {
 3193     testb(dst, imm32);
 3194   } else {
 3195     Assembler::testl(dst, imm32);
 3196   }
 3197 }
 3198 
 3199 void MacroAssembler::testl(Register dst, AddressLiteral src) {
 3200   assert(always_reachable(src), "Address should be reachable");
 3201   testl(dst, as_Address(src));
 3202 }
 3203 
 3204 #ifdef _LP64
 3205 
 3206 void MacroAssembler::testq(Address dst, int32_t imm32) {
 3207   if (imm32 >= 0) {
 3208     testl(dst, imm32);
 3209   } else {
 3210     Assembler::testq(dst, imm32);
 3211   }
 3212 }
 3213 
 3214 void MacroAssembler::testq(Register dst, int32_t imm32) {
 3215   if (imm32 >= 0) {
 3216     testl(dst, imm32);
 3217   } else {
 3218     Assembler::testq(dst, imm32);
 3219   }
 3220 }
 3221 
 3222 #endif
 3223 
 3224 void MacroAssembler::pcmpeqb(XMMRegister dst, XMMRegister src) {
 3225   assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3226   Assembler::pcmpeqb(dst, src);
 3227 }
 3228 
 3229 void MacroAssembler::pcmpeqw(XMMRegister dst, XMMRegister src) {
 3230   assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3231   Assembler::pcmpeqw(dst, src);
 3232 }
 3233 
 3234 void MacroAssembler::pcmpestri(XMMRegister dst, Address src, int imm8) {
 3235   assert((dst->encoding() < 16),"XMM register should be 0-15");
 3236   Assembler::pcmpestri(dst, src, imm8);
 3237 }
 3238 
 3239 void MacroAssembler::pcmpestri(XMMRegister dst, XMMRegister src, int imm8) {
 3240   assert((dst->encoding() < 16 && src->encoding() < 16),"XMM register should be 0-15");
 3241   Assembler::pcmpestri(dst, src, imm8);
 3242 }
 3243 
 3244 void MacroAssembler::pmovzxbw(XMMRegister dst, XMMRegister src) {
 3245   assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3246   Assembler::pmovzxbw(dst, src);
 3247 }
 3248 
 3249 void MacroAssembler::pmovzxbw(XMMRegister dst, Address src) {
 3250   assert(((dst->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3251   Assembler::pmovzxbw(dst, src);
 3252 }
 3253 
 3254 void MacroAssembler::pmovmskb(Register dst, XMMRegister src) {
 3255   assert((src->encoding() < 16),"XMM register should be 0-15");
 3256   Assembler::pmovmskb(dst, src);
 3257 }
 3258 
 3259 void MacroAssembler::ptest(XMMRegister dst, XMMRegister src) {
 3260   assert((dst->encoding() < 16 && src->encoding() < 16),"XMM register should be 0-15");
 3261   Assembler::ptest(dst, src);
 3262 }
 3263 
 3264 void MacroAssembler::sqrtss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3265   assert(rscratch != noreg || always_reachable(src), "missing");
 3266 
 3267   if (reachable(src)) {
 3268     Assembler::sqrtss(dst, as_Address(src));
 3269   } else {
 3270     lea(rscratch, src);
 3271     Assembler::sqrtss(dst, Address(rscratch, 0));
 3272   }
 3273 }
 3274 
 3275 void MacroAssembler::subsd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3276   assert(rscratch != noreg || always_reachable(src), "missing");
 3277 
 3278   if (reachable(src)) {
 3279     Assembler::subsd(dst, as_Address(src));
 3280   } else {
 3281     lea(rscratch, src);
 3282     Assembler::subsd(dst, Address(rscratch, 0));
 3283   }
 3284 }
 3285 
 3286 void MacroAssembler::roundsd(XMMRegister dst, AddressLiteral src, int32_t rmode, Register rscratch) {
 3287   assert(rscratch != noreg || always_reachable(src), "missing");
 3288 
 3289   if (reachable(src)) {
 3290     Assembler::roundsd(dst, as_Address(src), rmode);
 3291   } else {
 3292     lea(rscratch, src);
 3293     Assembler::roundsd(dst, Address(rscratch, 0), rmode);
 3294   }
 3295 }
 3296 
 3297 void MacroAssembler::subss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3298   assert(rscratch != noreg || always_reachable(src), "missing");
 3299 
 3300   if (reachable(src)) {
 3301     Assembler::subss(dst, as_Address(src));
 3302   } else {
 3303     lea(rscratch, src);
 3304     Assembler::subss(dst, Address(rscratch, 0));
 3305   }
 3306 }
 3307 
 3308 void MacroAssembler::ucomisd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3309   assert(rscratch != noreg || always_reachable(src), "missing");
 3310 
 3311   if (reachable(src)) {
 3312     Assembler::ucomisd(dst, as_Address(src));
 3313   } else {
 3314     lea(rscratch, src);
 3315     Assembler::ucomisd(dst, Address(rscratch, 0));
 3316   }
 3317 }
 3318 
 3319 void MacroAssembler::ucomiss(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3320   assert(rscratch != noreg || always_reachable(src), "missing");
 3321 
 3322   if (reachable(src)) {
 3323     Assembler::ucomiss(dst, as_Address(src));
 3324   } else {
 3325     lea(rscratch, src);
 3326     Assembler::ucomiss(dst, Address(rscratch, 0));
 3327   }
 3328 }
 3329 
 3330 void MacroAssembler::xorpd(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3331   assert(rscratch != noreg || always_reachable(src), "missing");
 3332 
 3333   // Used in sign-bit flipping with aligned address.
 3334   assert((UseAVX > 0) || (((intptr_t)src.target() & 15) == 0), "SSE mode requires address alignment 16 bytes");
 3335   if (reachable(src)) {
 3336     Assembler::xorpd(dst, as_Address(src));
 3337   } else {
 3338     lea(rscratch, src);
 3339     Assembler::xorpd(dst, Address(rscratch, 0));
 3340   }
 3341 }
 3342 
 3343 void MacroAssembler::xorpd(XMMRegister dst, XMMRegister src) {
 3344   if (UseAVX > 2 && !VM_Version::supports_avx512dq() && (dst->encoding() == src->encoding())) {
 3345     Assembler::vpxor(dst, dst, src, Assembler::AVX_512bit);
 3346   }
 3347   else {
 3348     Assembler::xorpd(dst, src);
 3349   }
 3350 }
 3351 
 3352 void MacroAssembler::xorps(XMMRegister dst, XMMRegister src) {
 3353   if (UseAVX > 2 && !VM_Version::supports_avx512dq() && (dst->encoding() == src->encoding())) {
 3354     Assembler::vpxor(dst, dst, src, Assembler::AVX_512bit);
 3355   } else {
 3356     Assembler::xorps(dst, src);
 3357   }
 3358 }
 3359 
 3360 void MacroAssembler::xorps(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3361   assert(rscratch != noreg || always_reachable(src), "missing");
 3362 
 3363   // Used in sign-bit flipping with aligned address.
 3364   assert((UseAVX > 0) || (((intptr_t)src.target() & 15) == 0), "SSE mode requires address alignment 16 bytes");
 3365   if (reachable(src)) {
 3366     Assembler::xorps(dst, as_Address(src));
 3367   } else {
 3368     lea(rscratch, src);
 3369     Assembler::xorps(dst, Address(rscratch, 0));
 3370   }
 3371 }
 3372 
 3373 void MacroAssembler::pshufb(XMMRegister dst, AddressLiteral src, Register rscratch) {
 3374   assert(rscratch != noreg || always_reachable(src), "missing");
 3375 
 3376   // Used in sign-bit flipping with aligned address.
 3377   bool aligned_adr = (((intptr_t)src.target() & 15) == 0);
 3378   assert((UseAVX > 0) || aligned_adr, "SSE mode requires address alignment 16 bytes");
 3379   if (reachable(src)) {
 3380     Assembler::pshufb(dst, as_Address(src));
 3381   } else {
 3382     lea(rscratch, src);
 3383     Assembler::pshufb(dst, Address(rscratch, 0));
 3384   }
 3385 }
 3386 
 3387 // AVX 3-operands instructions
 3388 
 3389 void MacroAssembler::vaddsd(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3390   assert(rscratch != noreg || always_reachable(src), "missing");
 3391 
 3392   if (reachable(src)) {
 3393     vaddsd(dst, nds, as_Address(src));
 3394   } else {
 3395     lea(rscratch, src);
 3396     vaddsd(dst, nds, Address(rscratch, 0));
 3397   }
 3398 }
 3399 
 3400 void MacroAssembler::vaddss(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3401   assert(rscratch != noreg || always_reachable(src), "missing");
 3402 
 3403   if (reachable(src)) {
 3404     vaddss(dst, nds, as_Address(src));
 3405   } else {
 3406     lea(rscratch, src);
 3407     vaddss(dst, nds, Address(rscratch, 0));
 3408   }
 3409 }
 3410 
 3411 void MacroAssembler::vpaddb(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3412   assert(UseAVX > 0, "requires some form of AVX");
 3413   assert(rscratch != noreg || always_reachable(src), "missing");
 3414 
 3415   if (reachable(src)) {
 3416     Assembler::vpaddb(dst, nds, as_Address(src), vector_len);
 3417   } else {
 3418     lea(rscratch, src);
 3419     Assembler::vpaddb(dst, nds, Address(rscratch, 0), vector_len);
 3420   }
 3421 }
 3422 
 3423 void MacroAssembler::vpaddd(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3424   assert(UseAVX > 0, "requires some form of AVX");
 3425   assert(rscratch != noreg || always_reachable(src), "missing");
 3426 
 3427   if (reachable(src)) {
 3428     Assembler::vpaddd(dst, nds, as_Address(src), vector_len);
 3429   } else {
 3430     lea(rscratch, src);
 3431     Assembler::vpaddd(dst, nds, Address(rscratch, 0), vector_len);
 3432   }
 3433 }
 3434 
 3435 void MacroAssembler::vabsss(XMMRegister dst, XMMRegister nds, XMMRegister src, AddressLiteral negate_field, int vector_len, Register rscratch) {
 3436   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vldq()),"XMM register should be 0-15");
 3437   assert(rscratch != noreg || always_reachable(negate_field), "missing");
 3438 
 3439   vandps(dst, nds, negate_field, vector_len, rscratch);
 3440 }
 3441 
 3442 void MacroAssembler::vabssd(XMMRegister dst, XMMRegister nds, XMMRegister src, AddressLiteral negate_field, int vector_len, Register rscratch) {
 3443   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vldq()),"XMM register should be 0-15");
 3444   assert(rscratch != noreg || always_reachable(negate_field), "missing");
 3445 
 3446   vandpd(dst, nds, negate_field, vector_len, rscratch);
 3447 }
 3448 
 3449 void MacroAssembler::vpaddb(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3450   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3451   Assembler::vpaddb(dst, nds, src, vector_len);
 3452 }
 3453 
 3454 void MacroAssembler::vpaddb(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3455   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3456   Assembler::vpaddb(dst, nds, src, vector_len);
 3457 }
 3458 
 3459 void MacroAssembler::vpaddw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3460   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3461   Assembler::vpaddw(dst, nds, src, vector_len);
 3462 }
 3463 
 3464 void MacroAssembler::vpaddw(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3465   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3466   Assembler::vpaddw(dst, nds, src, vector_len);
 3467 }
 3468 
 3469 void MacroAssembler::vpand(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3470   assert(rscratch != noreg || always_reachable(src), "missing");
 3471 
 3472   if (reachable(src)) {
 3473     Assembler::vpand(dst, nds, as_Address(src), vector_len);
 3474   } else {
 3475     lea(rscratch, src);
 3476     Assembler::vpand(dst, nds, Address(rscratch, 0), vector_len);
 3477   }
 3478 }
 3479 
 3480 void MacroAssembler::vpbroadcastd(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 3481   assert(rscratch != noreg || always_reachable(src), "missing");
 3482 
 3483   if (reachable(src)) {
 3484     Assembler::vpbroadcastd(dst, as_Address(src), vector_len);
 3485   } else {
 3486     lea(rscratch, src);
 3487     Assembler::vpbroadcastd(dst, Address(rscratch, 0), vector_len);
 3488   }
 3489 }
 3490 
 3491 void MacroAssembler::vbroadcasti128(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 3492   assert(rscratch != noreg || always_reachable(src), "missing");
 3493 
 3494   if (reachable(src)) {
 3495     Assembler::vbroadcasti128(dst, as_Address(src), vector_len);
 3496   } else {
 3497     lea(rscratch, src);
 3498     Assembler::vbroadcasti128(dst, Address(rscratch, 0), vector_len);
 3499   }
 3500 }
 3501 
 3502 void MacroAssembler::vpbroadcastq(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 3503   assert(rscratch != noreg || always_reachable(src), "missing");
 3504 
 3505   if (reachable(src)) {
 3506     Assembler::vpbroadcastq(dst, as_Address(src), vector_len);
 3507   } else {
 3508     lea(rscratch, src);
 3509     Assembler::vpbroadcastq(dst, Address(rscratch, 0), vector_len);
 3510   }
 3511 }
 3512 
 3513 void MacroAssembler::vbroadcastsd(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 3514   assert(rscratch != noreg || always_reachable(src), "missing");
 3515 
 3516   if (reachable(src)) {
 3517     Assembler::vbroadcastsd(dst, as_Address(src), vector_len);
 3518   } else {
 3519     lea(rscratch, src);
 3520     Assembler::vbroadcastsd(dst, Address(rscratch, 0), vector_len);
 3521   }
 3522 }
 3523 
 3524 void MacroAssembler::vbroadcastss(XMMRegister dst, AddressLiteral src, int vector_len, Register rscratch) {
 3525   assert(rscratch != noreg || always_reachable(src), "missing");
 3526 
 3527   if (reachable(src)) {
 3528     Assembler::vbroadcastss(dst, as_Address(src), vector_len);
 3529   } else {
 3530     lea(rscratch, src);
 3531     Assembler::vbroadcastss(dst, Address(rscratch, 0), vector_len);
 3532   }
 3533 }
 3534 
 3535 // Vector float blend
 3536 // vblendvps(XMMRegister dst, XMMRegister nds, XMMRegister src, XMMRegister mask, int vector_len, bool compute_mask = true, XMMRegister scratch = xnoreg)
 3537 void MacroAssembler::vblendvps(XMMRegister dst, XMMRegister src1, XMMRegister src2, XMMRegister mask, int vector_len, bool compute_mask, XMMRegister scratch) {
 3538   // WARN: Allow dst == (src1|src2), mask == scratch
 3539   bool blend_emulation = EnableX86ECoreOpts && UseAVX > 1;
 3540   bool scratch_available = scratch != xnoreg && scratch != src1 && scratch != src2 && scratch != dst;
 3541   bool dst_available = dst != mask && (dst != src1 || dst != src2);
 3542   if (blend_emulation && scratch_available && dst_available) {
 3543     if (compute_mask) {
 3544       vpsrad(scratch, mask, 32, vector_len);
 3545       mask = scratch;
 3546     }
 3547     if (dst == src1) {
 3548       vpandn(dst,     mask, src1, vector_len); // if mask == 0, src1
 3549       vpand (scratch, mask, src2, vector_len); // if mask == 1, src2
 3550     } else {
 3551       vpand (dst,     mask, src2, vector_len); // if mask == 1, src2
 3552       vpandn(scratch, mask, src1, vector_len); // if mask == 0, src1
 3553     }
 3554     vpor(dst, dst, scratch, vector_len);
 3555   } else {
 3556     Assembler::vblendvps(dst, src1, src2, mask, vector_len);
 3557   }
 3558 }
 3559 
 3560 // vblendvpd(XMMRegister dst, XMMRegister nds, XMMRegister src, XMMRegister mask, int vector_len, bool compute_mask = true, XMMRegister scratch = xnoreg)
 3561 void MacroAssembler::vblendvpd(XMMRegister dst, XMMRegister src1, XMMRegister src2, XMMRegister mask, int vector_len, bool compute_mask, XMMRegister scratch) {
 3562   // WARN: Allow dst == (src1|src2), mask == scratch
 3563   bool blend_emulation = EnableX86ECoreOpts && UseAVX > 1;
 3564   bool scratch_available = scratch != xnoreg && scratch != src1 && scratch != src2 && scratch != dst && (!compute_mask || scratch != mask);
 3565   bool dst_available = dst != mask && (dst != src1 || dst != src2);
 3566   if (blend_emulation && scratch_available && dst_available) {
 3567     if (compute_mask) {
 3568       vpxor(scratch, scratch, scratch, vector_len);
 3569       vpcmpgtq(scratch, scratch, mask, vector_len);
 3570       mask = scratch;
 3571     }
 3572     if (dst == src1) {
 3573       vpandn(dst,     mask, src1, vector_len); // if mask == 0, src
 3574       vpand (scratch, mask, src2, vector_len); // if mask == 1, src2
 3575     } else {
 3576       vpand (dst,     mask, src2, vector_len); // if mask == 1, src2
 3577       vpandn(scratch, mask, src1, vector_len); // if mask == 0, src
 3578     }
 3579     vpor(dst, dst, scratch, vector_len);
 3580   } else {
 3581     Assembler::vblendvpd(dst, src1, src2, mask, vector_len);
 3582   }
 3583 }
 3584 
 3585 void MacroAssembler::vpcmpeqb(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3586   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3587   Assembler::vpcmpeqb(dst, nds, src, vector_len);
 3588 }
 3589 
 3590 void MacroAssembler::vpcmpeqb(XMMRegister dst, XMMRegister src1, Address src2, int vector_len) {
 3591   assert(((dst->encoding() < 16 && src1->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3592   Assembler::vpcmpeqb(dst, src1, src2, vector_len);
 3593 }
 3594 
 3595 void MacroAssembler::vpcmpeqw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3596   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3597   Assembler::vpcmpeqw(dst, nds, src, vector_len);
 3598 }
 3599 
 3600 void MacroAssembler::vpcmpeqw(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3601   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3602   Assembler::vpcmpeqw(dst, nds, src, vector_len);
 3603 }
 3604 
 3605 void MacroAssembler::evpcmpeqd(KRegister kdst, KRegister mask, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3606   assert(rscratch != noreg || always_reachable(src), "missing");
 3607 
 3608   if (reachable(src)) {
 3609     Assembler::evpcmpeqd(kdst, mask, nds, as_Address(src), vector_len);
 3610   } else {
 3611     lea(rscratch, src);
 3612     Assembler::evpcmpeqd(kdst, mask, nds, Address(rscratch, 0), vector_len);
 3613   }
 3614 }
 3615 
 3616 void MacroAssembler::evpcmpd(KRegister kdst, KRegister mask, XMMRegister nds, AddressLiteral src,
 3617                              int comparison, bool is_signed, int vector_len, Register rscratch) {
 3618   assert(rscratch != noreg || always_reachable(src), "missing");
 3619 
 3620   if (reachable(src)) {
 3621     Assembler::evpcmpd(kdst, mask, nds, as_Address(src), comparison, is_signed, vector_len);
 3622   } else {
 3623     lea(rscratch, src);
 3624     Assembler::evpcmpd(kdst, mask, nds, Address(rscratch, 0), comparison, is_signed, vector_len);
 3625   }
 3626 }
 3627 
 3628 void MacroAssembler::evpcmpq(KRegister kdst, KRegister mask, XMMRegister nds, AddressLiteral src,
 3629                              int comparison, bool is_signed, int vector_len, Register rscratch) {
 3630   assert(rscratch != noreg || always_reachable(src), "missing");
 3631 
 3632   if (reachable(src)) {
 3633     Assembler::evpcmpq(kdst, mask, nds, as_Address(src), comparison, is_signed, vector_len);
 3634   } else {
 3635     lea(rscratch, src);
 3636     Assembler::evpcmpq(kdst, mask, nds, Address(rscratch, 0), comparison, is_signed, vector_len);
 3637   }
 3638 }
 3639 
 3640 void MacroAssembler::evpcmpb(KRegister kdst, KRegister mask, XMMRegister nds, AddressLiteral src,
 3641                              int comparison, bool is_signed, int vector_len, Register rscratch) {
 3642   assert(rscratch != noreg || always_reachable(src), "missing");
 3643 
 3644   if (reachable(src)) {
 3645     Assembler::evpcmpb(kdst, mask, nds, as_Address(src), comparison, is_signed, vector_len);
 3646   } else {
 3647     lea(rscratch, src);
 3648     Assembler::evpcmpb(kdst, mask, nds, Address(rscratch, 0), comparison, is_signed, vector_len);
 3649   }
 3650 }
 3651 
 3652 void MacroAssembler::evpcmpw(KRegister kdst, KRegister mask, XMMRegister nds, AddressLiteral src,
 3653                              int comparison, bool is_signed, int vector_len, Register rscratch) {
 3654   assert(rscratch != noreg || always_reachable(src), "missing");
 3655 
 3656   if (reachable(src)) {
 3657     Assembler::evpcmpw(kdst, mask, nds, as_Address(src), comparison, is_signed, vector_len);
 3658   } else {
 3659     lea(rscratch, src);
 3660     Assembler::evpcmpw(kdst, mask, nds, Address(rscratch, 0), comparison, is_signed, vector_len);
 3661   }
 3662 }
 3663 
 3664 void MacroAssembler::vpcmpCC(XMMRegister dst, XMMRegister nds, XMMRegister src, int cond_encoding, Width width, int vector_len) {
 3665   if (width == Assembler::Q) {
 3666     Assembler::vpcmpCCq(dst, nds, src, cond_encoding, vector_len);
 3667   } else {
 3668     Assembler::vpcmpCCbwd(dst, nds, src, cond_encoding, vector_len);
 3669   }
 3670 }
 3671 
 3672 void MacroAssembler::vpcmpCCW(XMMRegister dst, XMMRegister nds, XMMRegister src, XMMRegister xtmp, ComparisonPredicate cond, Width width, int vector_len) {
 3673   int eq_cond_enc = 0x29;
 3674   int gt_cond_enc = 0x37;
 3675   if (width != Assembler::Q) {
 3676     eq_cond_enc = 0x74 + width;
 3677     gt_cond_enc = 0x64 + width;
 3678   }
 3679   switch (cond) {
 3680   case eq:
 3681     vpcmpCC(dst, nds, src, eq_cond_enc, width, vector_len);
 3682     break;
 3683   case neq:
 3684     vpcmpCC(dst, nds, src, eq_cond_enc, width, vector_len);
 3685     vallones(xtmp, vector_len);
 3686     vpxor(dst, xtmp, dst, vector_len);
 3687     break;
 3688   case le:
 3689     vpcmpCC(dst, nds, src, gt_cond_enc, width, vector_len);
 3690     vallones(xtmp, vector_len);
 3691     vpxor(dst, xtmp, dst, vector_len);
 3692     break;
 3693   case nlt:
 3694     vpcmpCC(dst, src, nds, gt_cond_enc, width, vector_len);
 3695     vallones(xtmp, vector_len);
 3696     vpxor(dst, xtmp, dst, vector_len);
 3697     break;
 3698   case lt:
 3699     vpcmpCC(dst, src, nds, gt_cond_enc, width, vector_len);
 3700     break;
 3701   case nle:
 3702     vpcmpCC(dst, nds, src, gt_cond_enc, width, vector_len);
 3703     break;
 3704   default:
 3705     assert(false, "Should not reach here");
 3706   }
 3707 }
 3708 
 3709 void MacroAssembler::vpmovzxbw(XMMRegister dst, Address src, int vector_len) {
 3710   assert(((dst->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3711   Assembler::vpmovzxbw(dst, src, vector_len);
 3712 }
 3713 
 3714 void MacroAssembler::vpmovmskb(Register dst, XMMRegister src, int vector_len) {
 3715   assert((src->encoding() < 16),"XMM register should be 0-15");
 3716   Assembler::vpmovmskb(dst, src, vector_len);
 3717 }
 3718 
 3719 void MacroAssembler::vpmullw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3720   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3721   Assembler::vpmullw(dst, nds, src, vector_len);
 3722 }
 3723 
 3724 void MacroAssembler::vpmullw(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3725   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3726   Assembler::vpmullw(dst, nds, src, vector_len);
 3727 }
 3728 
 3729 void MacroAssembler::vpmulld(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3730   assert((UseAVX > 0), "AVX support is needed");
 3731   assert(rscratch != noreg || always_reachable(src), "missing");
 3732 
 3733   if (reachable(src)) {
 3734     Assembler::vpmulld(dst, nds, as_Address(src), vector_len);
 3735   } else {
 3736     lea(rscratch, src);
 3737     Assembler::vpmulld(dst, nds, Address(rscratch, 0), vector_len);
 3738   }
 3739 }
 3740 
 3741 void MacroAssembler::vpsubb(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3742   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3743   Assembler::vpsubb(dst, nds, src, vector_len);
 3744 }
 3745 
 3746 void MacroAssembler::vpsubb(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3747   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3748   Assembler::vpsubb(dst, nds, src, vector_len);
 3749 }
 3750 
 3751 void MacroAssembler::vpsubw(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len) {
 3752   assert(((dst->encoding() < 16 && src->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3753   Assembler::vpsubw(dst, nds, src, vector_len);
 3754 }
 3755 
 3756 void MacroAssembler::vpsubw(XMMRegister dst, XMMRegister nds, Address src, int vector_len) {
 3757   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3758   Assembler::vpsubw(dst, nds, src, vector_len);
 3759 }
 3760 
 3761 void MacroAssembler::vpsraw(XMMRegister dst, XMMRegister nds, XMMRegister shift, int vector_len) {
 3762   assert(((dst->encoding() < 16 && shift->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3763   Assembler::vpsraw(dst, nds, shift, vector_len);
 3764 }
 3765 
 3766 void MacroAssembler::vpsraw(XMMRegister dst, XMMRegister nds, int shift, int vector_len) {
 3767   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3768   Assembler::vpsraw(dst, nds, shift, vector_len);
 3769 }
 3770 
 3771 void MacroAssembler::evpsraq(XMMRegister dst, XMMRegister nds, XMMRegister shift, int vector_len) {
 3772   assert(UseAVX > 2,"");
 3773   if (!VM_Version::supports_avx512vl() && vector_len < 2) {
 3774      vector_len = 2;
 3775   }
 3776   Assembler::evpsraq(dst, nds, shift, vector_len);
 3777 }
 3778 
 3779 void MacroAssembler::evpsraq(XMMRegister dst, XMMRegister nds, int shift, int vector_len) {
 3780   assert(UseAVX > 2,"");
 3781   if (!VM_Version::supports_avx512vl() && vector_len < 2) {
 3782      vector_len = 2;
 3783   }
 3784   Assembler::evpsraq(dst, nds, shift, vector_len);
 3785 }
 3786 
 3787 void MacroAssembler::vpsrlw(XMMRegister dst, XMMRegister nds, XMMRegister shift, int vector_len) {
 3788   assert(((dst->encoding() < 16 && shift->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3789   Assembler::vpsrlw(dst, nds, shift, vector_len);
 3790 }
 3791 
 3792 void MacroAssembler::vpsrlw(XMMRegister dst, XMMRegister nds, int shift, int vector_len) {
 3793   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3794   Assembler::vpsrlw(dst, nds, shift, vector_len);
 3795 }
 3796 
 3797 void MacroAssembler::vpsllw(XMMRegister dst, XMMRegister nds, XMMRegister shift, int vector_len) {
 3798   assert(((dst->encoding() < 16 && shift->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3799   Assembler::vpsllw(dst, nds, shift, vector_len);
 3800 }
 3801 
 3802 void MacroAssembler::vpsllw(XMMRegister dst, XMMRegister nds, int shift, int vector_len) {
 3803   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3804   Assembler::vpsllw(dst, nds, shift, vector_len);
 3805 }
 3806 
 3807 void MacroAssembler::vptest(XMMRegister dst, XMMRegister src) {
 3808   assert((dst->encoding() < 16 && src->encoding() < 16),"XMM register should be 0-15");
 3809   Assembler::vptest(dst, src);
 3810 }
 3811 
 3812 void MacroAssembler::punpcklbw(XMMRegister dst, XMMRegister src) {
 3813   assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3814   Assembler::punpcklbw(dst, src);
 3815 }
 3816 
 3817 void MacroAssembler::pshufd(XMMRegister dst, Address src, int mode) {
 3818   assert(((dst->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
 3819   Assembler::pshufd(dst, src, mode);
 3820 }
 3821 
 3822 void MacroAssembler::pshuflw(XMMRegister dst, XMMRegister src, int mode) {
 3823   assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vlbw()),"XMM register should be 0-15");
 3824   Assembler::pshuflw(dst, src, mode);
 3825 }
 3826 
 3827 void MacroAssembler::vandpd(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3828   assert(rscratch != noreg || always_reachable(src), "missing");
 3829 
 3830   if (reachable(src)) {
 3831     vandpd(dst, nds, as_Address(src), vector_len);
 3832   } else {
 3833     lea(rscratch, src);
 3834     vandpd(dst, nds, Address(rscratch, 0), vector_len);
 3835   }
 3836 }
 3837 
 3838 void MacroAssembler::vandps(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3839   assert(rscratch != noreg || always_reachable(src), "missing");
 3840 
 3841   if (reachable(src)) {
 3842     vandps(dst, nds, as_Address(src), vector_len);
 3843   } else {
 3844     lea(rscratch, src);
 3845     vandps(dst, nds, Address(rscratch, 0), vector_len);
 3846   }
 3847 }
 3848 
 3849 void MacroAssembler::evpord(XMMRegister dst, KRegister mask, XMMRegister nds, AddressLiteral src,
 3850                             bool merge, int vector_len, Register rscratch) {
 3851   assert(rscratch != noreg || always_reachable(src), "missing");
 3852 
 3853   if (reachable(src)) {
 3854     Assembler::evpord(dst, mask, nds, as_Address(src), merge, vector_len);
 3855   } else {
 3856     lea(rscratch, src);
 3857     Assembler::evpord(dst, mask, nds, Address(rscratch, 0), merge, vector_len);
 3858   }
 3859 }
 3860 
 3861 void MacroAssembler::vdivsd(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3862   assert(rscratch != noreg || always_reachable(src), "missing");
 3863 
 3864   if (reachable(src)) {
 3865     vdivsd(dst, nds, as_Address(src));
 3866   } else {
 3867     lea(rscratch, src);
 3868     vdivsd(dst, nds, Address(rscratch, 0));
 3869   }
 3870 }
 3871 
 3872 void MacroAssembler::vdivss(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3873   assert(rscratch != noreg || always_reachable(src), "missing");
 3874 
 3875   if (reachable(src)) {
 3876     vdivss(dst, nds, as_Address(src));
 3877   } else {
 3878     lea(rscratch, src);
 3879     vdivss(dst, nds, Address(rscratch, 0));
 3880   }
 3881 }
 3882 
 3883 void MacroAssembler::vmulsd(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3884   assert(rscratch != noreg || always_reachable(src), "missing");
 3885 
 3886   if (reachable(src)) {
 3887     vmulsd(dst, nds, as_Address(src));
 3888   } else {
 3889     lea(rscratch, src);
 3890     vmulsd(dst, nds, Address(rscratch, 0));
 3891   }
 3892 }
 3893 
 3894 void MacroAssembler::vmulss(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3895   assert(rscratch != noreg || always_reachable(src), "missing");
 3896 
 3897   if (reachable(src)) {
 3898     vmulss(dst, nds, as_Address(src));
 3899   } else {
 3900     lea(rscratch, src);
 3901     vmulss(dst, nds, Address(rscratch, 0));
 3902   }
 3903 }
 3904 
 3905 void MacroAssembler::vsubsd(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3906   assert(rscratch != noreg || always_reachable(src), "missing");
 3907 
 3908   if (reachable(src)) {
 3909     vsubsd(dst, nds, as_Address(src));
 3910   } else {
 3911     lea(rscratch, src);
 3912     vsubsd(dst, nds, Address(rscratch, 0));
 3913   }
 3914 }
 3915 
 3916 void MacroAssembler::vsubss(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3917   assert(rscratch != noreg || always_reachable(src), "missing");
 3918 
 3919   if (reachable(src)) {
 3920     vsubss(dst, nds, as_Address(src));
 3921   } else {
 3922     lea(rscratch, src);
 3923     vsubss(dst, nds, Address(rscratch, 0));
 3924   }
 3925 }
 3926 
 3927 void MacroAssembler::vnegatess(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3928   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vldq()),"XMM register should be 0-15");
 3929   assert(rscratch != noreg || always_reachable(src), "missing");
 3930 
 3931   vxorps(dst, nds, src, Assembler::AVX_128bit, rscratch);
 3932 }
 3933 
 3934 void MacroAssembler::vnegatesd(XMMRegister dst, XMMRegister nds, AddressLiteral src, Register rscratch) {
 3935   assert(((dst->encoding() < 16 && nds->encoding() < 16) || VM_Version::supports_avx512vldq()),"XMM register should be 0-15");
 3936   assert(rscratch != noreg || always_reachable(src), "missing");
 3937 
 3938   vxorpd(dst, nds, src, Assembler::AVX_128bit, rscratch);
 3939 }
 3940 
 3941 void MacroAssembler::vxorpd(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3942   assert(rscratch != noreg || always_reachable(src), "missing");
 3943 
 3944   if (reachable(src)) {
 3945     vxorpd(dst, nds, as_Address(src), vector_len);
 3946   } else {
 3947     lea(rscratch, src);
 3948     vxorpd(dst, nds, Address(rscratch, 0), vector_len);
 3949   }
 3950 }
 3951 
 3952 void MacroAssembler::vxorps(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3953   assert(rscratch != noreg || always_reachable(src), "missing");
 3954 
 3955   if (reachable(src)) {
 3956     vxorps(dst, nds, as_Address(src), vector_len);
 3957   } else {
 3958     lea(rscratch, src);
 3959     vxorps(dst, nds, Address(rscratch, 0), vector_len);
 3960   }
 3961 }
 3962 
 3963 void MacroAssembler::vpxor(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3964   assert(rscratch != noreg || always_reachable(src), "missing");
 3965 
 3966   if (UseAVX > 1 || (vector_len < 1)) {
 3967     if (reachable(src)) {
 3968       Assembler::vpxor(dst, nds, as_Address(src), vector_len);
 3969     } else {
 3970       lea(rscratch, src);
 3971       Assembler::vpxor(dst, nds, Address(rscratch, 0), vector_len);
 3972     }
 3973   } else {
 3974     MacroAssembler::vxorpd(dst, nds, src, vector_len, rscratch);
 3975   }
 3976 }
 3977 
 3978 void MacroAssembler::vpermd(XMMRegister dst,  XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
 3979   assert(rscratch != noreg || always_reachable(src), "missing");
 3980 
 3981   if (reachable(src)) {
 3982     Assembler::vpermd(dst, nds, as_Address(src), vector_len);
 3983   } else {
 3984     lea(rscratch, src);
 3985     Assembler::vpermd(dst, nds, Address(rscratch, 0), vector_len);
 3986   }
 3987 }
 3988 
 3989 void MacroAssembler::clear_jobject_tag(Register possibly_non_local) {
 3990   const int32_t inverted_mask = ~static_cast<int32_t>(JNIHandles::tag_mask);
 3991   STATIC_ASSERT(inverted_mask == -4); // otherwise check this code
 3992   // The inverted mask is sign-extended
 3993   andptr(possibly_non_local, inverted_mask);
 3994 }
 3995 
 3996 void MacroAssembler::resolve_jobject(Register value,
 3997                                      Register thread,
 3998                                      Register tmp) {
 3999   assert_different_registers(value, thread, tmp);
 4000   Label done, tagged, weak_tagged;
 4001   testptr(value, value);
 4002   jcc(Assembler::zero, done);           // Use null as-is.
 4003   testptr(value, JNIHandles::tag_mask); // Test for tag.
 4004   jcc(Assembler::notZero, tagged);
 4005 
 4006   // Resolve local handle
 4007   access_load_at(T_OBJECT, IN_NATIVE | AS_RAW, value, Address(value, 0), tmp, thread);
 4008   verify_oop(value);
 4009   jmp(done);
 4010 
 4011   bind(tagged);
 4012   testptr(value, JNIHandles::TypeTag::weak_global); // Test for weak tag.
 4013   jcc(Assembler::notZero, weak_tagged);
 4014 
 4015   // Resolve global handle
 4016   access_load_at(T_OBJECT, IN_NATIVE, value, Address(value, -JNIHandles::TypeTag::global), tmp, thread);
 4017   verify_oop(value);
 4018   jmp(done);
 4019 
 4020   bind(weak_tagged);
 4021   // Resolve jweak.
 4022   access_load_at(T_OBJECT, IN_NATIVE | ON_PHANTOM_OOP_REF,
 4023                  value, Address(value, -JNIHandles::TypeTag::weak_global), tmp, thread);
 4024   verify_oop(value);
 4025 
 4026   bind(done);
 4027 }
 4028 
 4029 void MacroAssembler::resolve_global_jobject(Register value,
 4030                                             Register thread,
 4031                                             Register tmp) {
 4032   assert_different_registers(value, thread, tmp);
 4033   Label done;
 4034 
 4035   testptr(value, value);
 4036   jcc(Assembler::zero, done);           // Use null as-is.
 4037 
 4038 #ifdef ASSERT
 4039   {
 4040     Label valid_global_tag;
 4041     testptr(value, JNIHandles::TypeTag::global); // Test for global tag.
 4042     jcc(Assembler::notZero, valid_global_tag);
 4043     stop("non global jobject using resolve_global_jobject");
 4044     bind(valid_global_tag);
 4045   }
 4046 #endif
 4047 
 4048   // Resolve global handle
 4049   access_load_at(T_OBJECT, IN_NATIVE, value, Address(value, -JNIHandles::TypeTag::global), tmp, thread);
 4050   verify_oop(value);
 4051 
 4052   bind(done);
 4053 }
 4054 
 4055 void MacroAssembler::subptr(Register dst, int32_t imm32) {
 4056   LP64_ONLY(subq(dst, imm32)) NOT_LP64(subl(dst, imm32));
 4057 }
 4058 
 4059 // Force generation of a 4 byte immediate value even if it fits into 8bit
 4060 void MacroAssembler::subptr_imm32(Register dst, int32_t imm32) {
 4061   LP64_ONLY(subq_imm32(dst, imm32)) NOT_LP64(subl_imm32(dst, imm32));
 4062 }
 4063 
 4064 void MacroAssembler::subptr(Register dst, Register src) {
 4065   LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src));
 4066 }
 4067 
 4068 // C++ bool manipulation
 4069 void MacroAssembler::testbool(Register dst) {
 4070   if(sizeof(bool) == 1)
 4071     testb(dst, 0xff);
 4072   else if(sizeof(bool) == 2) {
 4073     // testw implementation needed for two byte bools
 4074     ShouldNotReachHere();
 4075   } else if(sizeof(bool) == 4)
 4076     testl(dst, dst);
 4077   else
 4078     // unsupported
 4079     ShouldNotReachHere();
 4080 }
 4081 
 4082 void MacroAssembler::testptr(Register dst, Register src) {
 4083   LP64_ONLY(testq(dst, src)) NOT_LP64(testl(dst, src));
 4084 }
 4085 
 4086 // Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
 4087 void MacroAssembler::tlab_allocate(Register thread, Register obj,
 4088                                    Register var_size_in_bytes,
 4089                                    int con_size_in_bytes,
 4090                                    Register t1,
 4091                                    Register t2,
 4092                                    Label& slow_case) {
 4093   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
 4094   bs->tlab_allocate(this, thread, obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
 4095 }
 4096 
 4097 RegSet MacroAssembler::call_clobbered_gp_registers() {
 4098   RegSet regs;
 4099 #ifdef _LP64
 4100   regs += RegSet::of(rax, rcx, rdx);
 4101 #ifndef _WINDOWS
 4102   regs += RegSet::of(rsi, rdi);
 4103 #endif
 4104   regs += RegSet::range(r8, r11);
 4105 #else
 4106   regs += RegSet::of(rax, rcx, rdx);
 4107 #endif
 4108 #ifdef _LP64
 4109   if (UseAPX) {
 4110     regs += RegSet::range(r16, as_Register(Register::number_of_registers - 1));
 4111   }
 4112 #endif
 4113   return regs;
 4114 }
 4115 
 4116 XMMRegSet MacroAssembler::call_clobbered_xmm_registers() {
 4117   int num_xmm_registers = XMMRegister::available_xmm_registers();
 4118 #if defined(_WINDOWS)
 4119   XMMRegSet result = XMMRegSet::range(xmm0, xmm5);
 4120   if (num_xmm_registers > 16) {
 4121      result += XMMRegSet::range(xmm16, as_XMMRegister(num_xmm_registers - 1));
 4122   }
 4123   return result;
 4124 #else
 4125   return XMMRegSet::range(xmm0, as_XMMRegister(num_xmm_registers - 1));
 4126 #endif
 4127 }
 4128 
 4129 static int FPUSaveAreaSize = align_up(108, StackAlignmentInBytes); // 108 bytes needed for FPU state by fsave/frstor
 4130 
 4131 #ifndef _LP64
 4132 static bool use_x87_registers() { return UseSSE < 2; }
 4133 #endif
 4134 static bool use_xmm_registers() { return UseSSE >= 1; }
 4135 
 4136 // C1 only ever uses the first double/float of the XMM register.
 4137 static int xmm_save_size() { return UseSSE >= 2 ? sizeof(double) : sizeof(float); }
 4138 
 4139 static void save_xmm_register(MacroAssembler* masm, int offset, XMMRegister reg) {
 4140   if (UseSSE == 1) {
 4141     masm->movflt(Address(rsp, offset), reg);
 4142   } else {
 4143     masm->movdbl(Address(rsp, offset), reg);
 4144   }
 4145 }
 4146 
 4147 static void restore_xmm_register(MacroAssembler* masm, int offset, XMMRegister reg) {
 4148   if (UseSSE == 1) {
 4149     masm->movflt(reg, Address(rsp, offset));
 4150   } else {
 4151     masm->movdbl(reg, Address(rsp, offset));
 4152   }
 4153 }
 4154 
 4155 static int register_section_sizes(RegSet gp_registers, XMMRegSet xmm_registers,
 4156                                   bool save_fpu, int& gp_area_size,
 4157                                   int& fp_area_size, int& xmm_area_size) {
 4158 
 4159   gp_area_size = align_up(gp_registers.size() * Register::max_slots_per_register * VMRegImpl::stack_slot_size,
 4160                          StackAlignmentInBytes);
 4161 #ifdef _LP64
 4162   fp_area_size = 0;
 4163 #else
 4164   fp_area_size = (save_fpu && use_x87_registers()) ? FPUSaveAreaSize : 0;
 4165 #endif
 4166   xmm_area_size = (save_fpu && use_xmm_registers()) ? xmm_registers.size() * xmm_save_size() : 0;
 4167 
 4168   return gp_area_size + fp_area_size + xmm_area_size;
 4169 }
 4170 
 4171 void MacroAssembler::push_call_clobbered_registers_except(RegSet exclude, bool save_fpu) {
 4172   block_comment("push_call_clobbered_registers start");
 4173   // Regular registers
 4174   RegSet gp_registers_to_push = call_clobbered_gp_registers() - exclude;
 4175 
 4176   int gp_area_size;
 4177   int fp_area_size;
 4178   int xmm_area_size;
 4179   int total_save_size = register_section_sizes(gp_registers_to_push, call_clobbered_xmm_registers(), save_fpu,
 4180                                                gp_area_size, fp_area_size, xmm_area_size);
 4181   subptr(rsp, total_save_size);
 4182 
 4183   push_set(gp_registers_to_push, 0);
 4184 
 4185 #ifndef _LP64
 4186   if (save_fpu && use_x87_registers()) {
 4187     fnsave(Address(rsp, gp_area_size));
 4188     fwait();
 4189   }
 4190 #endif
 4191   if (save_fpu && use_xmm_registers()) {
 4192     push_set(call_clobbered_xmm_registers(), gp_area_size + fp_area_size);
 4193   }
 4194 
 4195   block_comment("push_call_clobbered_registers end");
 4196 }
 4197 
 4198 void MacroAssembler::pop_call_clobbered_registers_except(RegSet exclude, bool restore_fpu) {
 4199   block_comment("pop_call_clobbered_registers start");
 4200 
 4201   RegSet gp_registers_to_pop = call_clobbered_gp_registers() - exclude;
 4202 
 4203   int gp_area_size;
 4204   int fp_area_size;
 4205   int xmm_area_size;
 4206   int total_save_size = register_section_sizes(gp_registers_to_pop, call_clobbered_xmm_registers(), restore_fpu,
 4207                                                gp_area_size, fp_area_size, xmm_area_size);
 4208 
 4209   if (restore_fpu && use_xmm_registers()) {
 4210     pop_set(call_clobbered_xmm_registers(), gp_area_size + fp_area_size);
 4211   }
 4212 #ifndef _LP64
 4213   if (restore_fpu && use_x87_registers()) {
 4214     frstor(Address(rsp, gp_area_size));
 4215   }
 4216 #endif
 4217 
 4218   pop_set(gp_registers_to_pop, 0);
 4219 
 4220   addptr(rsp, total_save_size);
 4221 
 4222   vzeroupper();
 4223 
 4224   block_comment("pop_call_clobbered_registers end");
 4225 }
 4226 
 4227 void MacroAssembler::push_set(XMMRegSet set, int offset) {
 4228   assert(is_aligned(set.size() * xmm_save_size(), StackAlignmentInBytes), "must be");
 4229   int spill_offset = offset;
 4230 
 4231   for (RegSetIterator<XMMRegister> it = set.begin(); *it != xnoreg; ++it) {
 4232     save_xmm_register(this, spill_offset, *it);
 4233     spill_offset += xmm_save_size();
 4234   }
 4235 }
 4236 
 4237 void MacroAssembler::pop_set(XMMRegSet set, int offset) {
 4238   int restore_size = set.size() * xmm_save_size();
 4239   assert(is_aligned(restore_size, StackAlignmentInBytes), "must be");
 4240 
 4241   int restore_offset = offset + restore_size - xmm_save_size();
 4242 
 4243   for (ReverseRegSetIterator<XMMRegister> it = set.rbegin(); *it != xnoreg; ++it) {
 4244     restore_xmm_register(this, restore_offset, *it);
 4245     restore_offset -= xmm_save_size();
 4246   }
 4247 }
 4248 
 4249 void MacroAssembler::push_set(RegSet set, int offset) {
 4250   int spill_offset;
 4251   if (offset == -1) {
 4252     int register_push_size = set.size() * Register::max_slots_per_register * VMRegImpl::stack_slot_size;
 4253     int aligned_size = align_up(register_push_size, StackAlignmentInBytes);
 4254     subptr(rsp, aligned_size);
 4255     spill_offset = 0;
 4256   } else {
 4257     spill_offset = offset;
 4258   }
 4259 
 4260   for (RegSetIterator<Register> it = set.begin(); *it != noreg; ++it) {
 4261     movptr(Address(rsp, spill_offset), *it);
 4262     spill_offset += Register::max_slots_per_register * VMRegImpl::stack_slot_size;
 4263   }
 4264 }
 4265 
 4266 void MacroAssembler::pop_set(RegSet set, int offset) {
 4267 
 4268   int gp_reg_size = Register::max_slots_per_register * VMRegImpl::stack_slot_size;
 4269   int restore_size = set.size() * gp_reg_size;
 4270   int aligned_size = align_up(restore_size, StackAlignmentInBytes);
 4271 
 4272   int restore_offset;
 4273   if (offset == -1) {
 4274     restore_offset = restore_size - gp_reg_size;
 4275   } else {
 4276     restore_offset = offset + restore_size - gp_reg_size;
 4277   }
 4278   for (ReverseRegSetIterator<Register> it = set.rbegin(); *it != noreg; ++it) {
 4279     movptr(*it, Address(rsp, restore_offset));
 4280     restore_offset -= gp_reg_size;
 4281   }
 4282 
 4283   if (offset == -1) {
 4284     addptr(rsp, aligned_size);
 4285   }
 4286 }
 4287 
 4288 // Preserves the contents of address, destroys the contents length_in_bytes and temp.
 4289 void MacroAssembler::zero_memory(Register address, Register length_in_bytes, int offset_in_bytes, Register temp) {
 4290   assert(address != length_in_bytes && address != temp && temp != length_in_bytes, "registers must be different");
 4291   assert((offset_in_bytes & (BytesPerWord - 1)) == 0, "offset must be a multiple of BytesPerWord");
 4292   Label done;
 4293 
 4294   testptr(length_in_bytes, length_in_bytes);
 4295   jcc(Assembler::zero, done);
 4296 
 4297   // initialize topmost word, divide index by 2, check if odd and test if zero
 4298   // note: for the remaining code to work, index must be a multiple of BytesPerWord
 4299 #ifdef ASSERT
 4300   {
 4301     Label L;
 4302     testptr(length_in_bytes, BytesPerWord - 1);
 4303     jcc(Assembler::zero, L);
 4304     stop("length must be a multiple of BytesPerWord");
 4305     bind(L);
 4306   }
 4307 #endif
 4308   Register index = length_in_bytes;
 4309   xorptr(temp, temp);    // use _zero reg to clear memory (shorter code)
 4310   if (UseIncDec) {
 4311     shrptr(index, 3);  // divide by 8/16 and set carry flag if bit 2 was set
 4312   } else {
 4313     shrptr(index, 2);  // use 2 instructions to avoid partial flag stall
 4314     shrptr(index, 1);
 4315   }
 4316 #ifndef _LP64
 4317   // index could have not been a multiple of 8 (i.e., bit 2 was set)
 4318   {
 4319     Label even;
 4320     // note: if index was a multiple of 8, then it cannot
 4321     //       be 0 now otherwise it must have been 0 before
 4322     //       => if it is even, we don't need to check for 0 again
 4323     jcc(Assembler::carryClear, even);
 4324     // clear topmost word (no jump would be needed if conditional assignment worked here)
 4325     movptr(Address(address, index, Address::times_8, offset_in_bytes - 0*BytesPerWord), temp);
 4326     // index could be 0 now, must check again
 4327     jcc(Assembler::zero, done);
 4328     bind(even);
 4329   }
 4330 #endif // !_LP64
 4331   // initialize remaining object fields: index is a multiple of 2 now
 4332   {
 4333     Label loop;
 4334     bind(loop);
 4335     movptr(Address(address, index, Address::times_8, offset_in_bytes - 1*BytesPerWord), temp);
 4336     NOT_LP64(movptr(Address(address, index, Address::times_8, offset_in_bytes - 2*BytesPerWord), temp);)
 4337     decrement(index);
 4338     jcc(Assembler::notZero, loop);
 4339   }
 4340 
 4341   bind(done);
 4342 }
 4343 
 4344 // Look up the method for a megamorphic invokeinterface call.
 4345 // The target method is determined by <intf_klass, itable_index>.
 4346 // The receiver klass is in recv_klass.
 4347 // On success, the result will be in method_result, and execution falls through.
 4348 // On failure, execution transfers to the given label.
 4349 void MacroAssembler::lookup_interface_method(Register recv_klass,
 4350                                              Register intf_klass,
 4351                                              RegisterOrConstant itable_index,
 4352                                              Register method_result,
 4353                                              Register scan_temp,
 4354                                              Label& L_no_such_interface,
 4355                                              bool return_method) {
 4356   assert_different_registers(recv_klass, intf_klass, scan_temp);
 4357   assert_different_registers(method_result, intf_klass, scan_temp);
 4358   assert(recv_klass != method_result || !return_method,
 4359          "recv_klass can be destroyed when method isn't needed");
 4360 
 4361   assert(itable_index.is_constant() || itable_index.as_register() == method_result,
 4362          "caller must use same register for non-constant itable index as for method");
 4363 
 4364   // Compute start of first itableOffsetEntry (which is at the end of the vtable)
 4365   int vtable_base = in_bytes(Klass::vtable_start_offset());
 4366   int itentry_off = in_bytes(itableMethodEntry::method_offset());
 4367   int scan_step   = itableOffsetEntry::size() * wordSize;
 4368   int vte_size    = vtableEntry::size_in_bytes();
 4369   Address::ScaleFactor times_vte_scale = Address::times_ptr;
 4370   assert(vte_size == wordSize, "else adjust times_vte_scale");
 4371 
 4372   movl(scan_temp, Address(recv_klass, Klass::vtable_length_offset()));
 4373 
 4374   // Could store the aligned, prescaled offset in the klass.
 4375   lea(scan_temp, Address(recv_klass, scan_temp, times_vte_scale, vtable_base));
 4376 
 4377   if (return_method) {
 4378     // Adjust recv_klass by scaled itable_index, so we can free itable_index.
 4379     assert(itableMethodEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
 4380     lea(recv_klass, Address(recv_klass, itable_index, Address::times_ptr, itentry_off));
 4381   }
 4382 
 4383   // for (scan = klass->itable(); scan->interface() != nullptr; scan += scan_step) {
 4384   //   if (scan->interface() == intf) {
 4385   //     result = (klass + scan->offset() + itable_index);
 4386   //   }
 4387   // }
 4388   Label search, found_method;
 4389 
 4390   for (int peel = 1; peel >= 0; peel--) {
 4391     movptr(method_result, Address(scan_temp, itableOffsetEntry::interface_offset()));
 4392     cmpptr(intf_klass, method_result);
 4393 
 4394     if (peel) {
 4395       jccb(Assembler::equal, found_method);
 4396     } else {
 4397       jccb(Assembler::notEqual, search);
 4398       // (invert the test to fall through to found_method...)
 4399     }
 4400 
 4401     if (!peel)  break;
 4402 
 4403     bind(search);
 4404 
 4405     // Check that the previous entry is non-null.  A null entry means that
 4406     // the receiver class doesn't implement the interface, and wasn't the
 4407     // same as when the caller was compiled.
 4408     testptr(method_result, method_result);
 4409     jcc(Assembler::zero, L_no_such_interface);
 4410     addptr(scan_temp, scan_step);
 4411   }
 4412 
 4413   bind(found_method);
 4414 
 4415   if (return_method) {
 4416     // Got a hit.
 4417     movl(scan_temp, Address(scan_temp, itableOffsetEntry::offset_offset()));
 4418     movptr(method_result, Address(recv_klass, scan_temp, Address::times_1));
 4419   }
 4420 }
 4421 
 4422 // Look up the method for a megamorphic invokeinterface call in a single pass over itable:
 4423 // - check recv_klass (actual object class) is a subtype of resolved_klass from CompiledICData
 4424 // - find a holder_klass (class that implements the method) vtable offset and get the method from vtable by index
 4425 // The target method is determined by <holder_klass, itable_index>.
 4426 // The receiver klass is in recv_klass.
 4427 // On success, the result will be in method_result, and execution falls through.
 4428 // On failure, execution transfers to the given label.
 4429 void MacroAssembler::lookup_interface_method_stub(Register recv_klass,
 4430                                                   Register holder_klass,
 4431                                                   Register resolved_klass,
 4432                                                   Register method_result,
 4433                                                   Register scan_temp,
 4434                                                   Register temp_reg2,
 4435                                                   Register receiver,
 4436                                                   int itable_index,
 4437                                                   Label& L_no_such_interface) {
 4438   assert_different_registers(recv_klass, method_result, holder_klass, resolved_klass, scan_temp, temp_reg2, receiver);
 4439   Register temp_itbl_klass = method_result;
 4440   Register temp_reg = (temp_reg2 == noreg ? recv_klass : temp_reg2); // reuse recv_klass register on 32-bit x86 impl
 4441 
 4442   int vtable_base = in_bytes(Klass::vtable_start_offset());
 4443   int itentry_off = in_bytes(itableMethodEntry::method_offset());
 4444   int scan_step = itableOffsetEntry::size() * wordSize;
 4445   int vte_size = vtableEntry::size_in_bytes();
 4446   int ioffset = in_bytes(itableOffsetEntry::interface_offset());
 4447   int ooffset = in_bytes(itableOffsetEntry::offset_offset());
 4448   Address::ScaleFactor times_vte_scale = Address::times_ptr;
 4449   assert(vte_size == wordSize, "adjust times_vte_scale");
 4450 
 4451   Label L_loop_scan_resolved_entry, L_resolved_found, L_holder_found;
 4452 
 4453   // temp_itbl_klass = recv_klass.itable[0]
 4454   // scan_temp = &recv_klass.itable[0] + step
 4455   movl(scan_temp, Address(recv_klass, Klass::vtable_length_offset()));
 4456   movptr(temp_itbl_klass, Address(recv_klass, scan_temp, times_vte_scale, vtable_base + ioffset));
 4457   lea(scan_temp, Address(recv_klass, scan_temp, times_vte_scale, vtable_base + ioffset + scan_step));
 4458   xorptr(temp_reg, temp_reg);
 4459 
 4460   // Initial checks:
 4461   //   - if (holder_klass != resolved_klass), go to "scan for resolved"
 4462   //   - if (itable[0] == 0), no such interface
 4463   //   - if (itable[0] == holder_klass), shortcut to "holder found"
 4464   cmpptr(holder_klass, resolved_klass);
 4465   jccb(Assembler::notEqual, L_loop_scan_resolved_entry);
 4466   testptr(temp_itbl_klass, temp_itbl_klass);
 4467   jccb(Assembler::zero, L_no_such_interface);
 4468   cmpptr(holder_klass, temp_itbl_klass);
 4469   jccb(Assembler::equal, L_holder_found);
 4470 
 4471   // Loop: Look for holder_klass record in itable
 4472   //   do {
 4473   //     tmp = itable[index];
 4474   //     index += step;
 4475   //     if (tmp == holder_klass) {
 4476   //       goto L_holder_found; // Found!
 4477   //     }
 4478   //   } while (tmp != 0);
 4479   //   goto L_no_such_interface // Not found.
 4480   Label L_scan_holder;
 4481   bind(L_scan_holder);
 4482     movptr(temp_itbl_klass, Address(scan_temp, 0));
 4483     addptr(scan_temp, scan_step);
 4484     cmpptr(holder_klass, temp_itbl_klass);
 4485     jccb(Assembler::equal, L_holder_found);
 4486     testptr(temp_itbl_klass, temp_itbl_klass);
 4487     jccb(Assembler::notZero, L_scan_holder);
 4488 
 4489   jmpb(L_no_such_interface);
 4490 
 4491   // Loop: Look for resolved_class record in itable
 4492   //   do {
 4493   //     tmp = itable[index];
 4494   //     index += step;
 4495   //     if (tmp == holder_klass) {
 4496   //        // Also check if we have met a holder klass
 4497   //        holder_tmp = itable[index-step-ioffset];
 4498   //     }
 4499   //     if (tmp == resolved_klass) {
 4500   //        goto L_resolved_found;  // Found!
 4501   //     }
 4502   //   } while (tmp != 0);
 4503   //   goto L_no_such_interface // Not found.
 4504   //
 4505   Label L_loop_scan_resolved;
 4506   bind(L_loop_scan_resolved);
 4507     movptr(temp_itbl_klass, Address(scan_temp, 0));
 4508     addptr(scan_temp, scan_step);
 4509     bind(L_loop_scan_resolved_entry);
 4510     cmpptr(holder_klass, temp_itbl_klass);
 4511     cmovl(Assembler::equal, temp_reg, Address(scan_temp, ooffset - ioffset - scan_step));
 4512     cmpptr(resolved_klass, temp_itbl_klass);
 4513     jccb(Assembler::equal, L_resolved_found);
 4514     testptr(temp_itbl_klass, temp_itbl_klass);
 4515     jccb(Assembler::notZero, L_loop_scan_resolved);
 4516 
 4517   jmpb(L_no_such_interface);
 4518 
 4519   Label L_ready;
 4520 
 4521   // See if we already have a holder klass. If not, go and scan for it.
 4522   bind(L_resolved_found);
 4523   testptr(temp_reg, temp_reg);
 4524   jccb(Assembler::zero, L_scan_holder);
 4525   jmpb(L_ready);
 4526 
 4527   bind(L_holder_found);
 4528   movl(temp_reg, Address(scan_temp, ooffset - ioffset - scan_step));
 4529 
 4530   // Finally, temp_reg contains holder_klass vtable offset
 4531   bind(L_ready);
 4532   assert(itableMethodEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
 4533   if (temp_reg2 == noreg) { // recv_klass register is clobbered for 32-bit x86 impl
 4534     load_klass(scan_temp, receiver, noreg);
 4535     movptr(method_result, Address(scan_temp, temp_reg, Address::times_1, itable_index * wordSize + itentry_off));
 4536   } else {
 4537     movptr(method_result, Address(recv_klass, temp_reg, Address::times_1, itable_index * wordSize + itentry_off));
 4538   }
 4539 }
 4540 
 4541 
 4542 // virtual method calling
 4543 void MacroAssembler::lookup_virtual_method(Register recv_klass,
 4544                                            RegisterOrConstant vtable_index,
 4545                                            Register method_result) {
 4546   const ByteSize base = Klass::vtable_start_offset();
 4547   assert(vtableEntry::size() * wordSize == wordSize, "else adjust the scaling in the code below");
 4548   Address vtable_entry_addr(recv_klass,
 4549                             vtable_index, Address::times_ptr,
 4550                             base + vtableEntry::method_offset());
 4551   movptr(method_result, vtable_entry_addr);
 4552 }
 4553 
 4554 
 4555 void MacroAssembler::check_klass_subtype(Register sub_klass,
 4556                            Register super_klass,
 4557                            Register temp_reg,
 4558                            Label& L_success) {
 4559   Label L_failure;
 4560   check_klass_subtype_fast_path(sub_klass, super_klass, temp_reg,        &L_success, &L_failure, nullptr);
 4561   check_klass_subtype_slow_path(sub_klass, super_klass, temp_reg, noreg, &L_success, nullptr);
 4562   bind(L_failure);
 4563 }
 4564 
 4565 
 4566 void MacroAssembler::check_klass_subtype_fast_path(Register sub_klass,
 4567                                                    Register super_klass,
 4568                                                    Register temp_reg,
 4569                                                    Label* L_success,
 4570                                                    Label* L_failure,
 4571                                                    Label* L_slow_path,
 4572                                         RegisterOrConstant super_check_offset) {
 4573   assert_different_registers(sub_klass, super_klass, temp_reg);
 4574   bool must_load_sco = (super_check_offset.constant_or_zero() == -1);
 4575   if (super_check_offset.is_register()) {
 4576     assert_different_registers(sub_klass, super_klass,
 4577                                super_check_offset.as_register());
 4578   } else if (must_load_sco) {
 4579     assert(temp_reg != noreg, "supply either a temp or a register offset");
 4580   }
 4581 
 4582   Label L_fallthrough;
 4583   int label_nulls = 0;
 4584   if (L_success == nullptr)   { L_success   = &L_fallthrough; label_nulls++; }
 4585   if (L_failure == nullptr)   { L_failure   = &L_fallthrough; label_nulls++; }
 4586   if (L_slow_path == nullptr) { L_slow_path = &L_fallthrough; label_nulls++; }
 4587   assert(label_nulls <= 1, "at most one null in the batch");
 4588 
 4589   int sc_offset = in_bytes(Klass::secondary_super_cache_offset());
 4590   int sco_offset = in_bytes(Klass::super_check_offset_offset());
 4591   Address super_check_offset_addr(super_klass, sco_offset);
 4592 
 4593   // Hacked jcc, which "knows" that L_fallthrough, at least, is in
 4594   // range of a jccb.  If this routine grows larger, reconsider at
 4595   // least some of these.
 4596 #define local_jcc(assembler_cond, label)                                \
 4597   if (&(label) == &L_fallthrough)  jccb(assembler_cond, label);         \
 4598   else                             jcc( assembler_cond, label) /*omit semi*/
 4599 
 4600   // Hacked jmp, which may only be used just before L_fallthrough.
 4601 #define final_jmp(label)                                                \
 4602   if (&(label) == &L_fallthrough) { /*do nothing*/ }                    \
 4603   else                            jmp(label)                /*omit semi*/
 4604 
 4605   // If the pointers are equal, we are done (e.g., String[] elements).
 4606   // This self-check enables sharing of secondary supertype arrays among
 4607   // non-primary types such as array-of-interface.  Otherwise, each such
 4608   // type would need its own customized SSA.
 4609   // We move this check to the front of the fast path because many
 4610   // type checks are in fact trivially successful in this manner,
 4611   // so we get a nicely predicted branch right at the start of the check.
 4612   cmpptr(sub_klass, super_klass);
 4613   local_jcc(Assembler::equal, *L_success);
 4614 
 4615   // Check the supertype display:
 4616   if (must_load_sco) {
 4617     // Positive movl does right thing on LP64.
 4618     movl(temp_reg, super_check_offset_addr);
 4619     super_check_offset = RegisterOrConstant(temp_reg);
 4620   }
 4621   Address super_check_addr(sub_klass, super_check_offset, Address::times_1, 0);
 4622   cmpptr(super_klass, super_check_addr); // load displayed supertype
 4623 
 4624   // This check has worked decisively for primary supers.
 4625   // Secondary supers are sought in the super_cache ('super_cache_addr').
 4626   // (Secondary supers are interfaces and very deeply nested subtypes.)
 4627   // This works in the same check above because of a tricky aliasing
 4628   // between the super_cache and the primary super display elements.
 4629   // (The 'super_check_addr' can address either, as the case requires.)
 4630   // Note that the cache is updated below if it does not help us find
 4631   // what we need immediately.
 4632   // So if it was a primary super, we can just fail immediately.
 4633   // Otherwise, it's the slow path for us (no success at this point).
 4634 
 4635   if (super_check_offset.is_register()) {
 4636     local_jcc(Assembler::equal, *L_success);
 4637     cmpl(super_check_offset.as_register(), sc_offset);
 4638     if (L_failure == &L_fallthrough) {
 4639       local_jcc(Assembler::equal, *L_slow_path);
 4640     } else {
 4641       local_jcc(Assembler::notEqual, *L_failure);
 4642       final_jmp(*L_slow_path);
 4643     }
 4644   } else if (super_check_offset.as_constant() == sc_offset) {
 4645     // Need a slow path; fast failure is impossible.
 4646     if (L_slow_path == &L_fallthrough) {
 4647       local_jcc(Assembler::equal, *L_success);
 4648     } else {
 4649       local_jcc(Assembler::notEqual, *L_slow_path);
 4650       final_jmp(*L_success);
 4651     }
 4652   } else {
 4653     // No slow path; it's a fast decision.
 4654     if (L_failure == &L_fallthrough) {
 4655       local_jcc(Assembler::equal, *L_success);
 4656     } else {
 4657       local_jcc(Assembler::notEqual, *L_failure);
 4658       final_jmp(*L_success);
 4659     }
 4660   }
 4661 
 4662   bind(L_fallthrough);
 4663 
 4664 #undef local_jcc
 4665 #undef final_jmp
 4666 }
 4667 
 4668 
 4669 void MacroAssembler::check_klass_subtype_slow_path_linear(Register sub_klass,
 4670                                                           Register super_klass,
 4671                                                           Register temp_reg,
 4672                                                           Register temp2_reg,
 4673                                                           Label* L_success,
 4674                                                           Label* L_failure,
 4675                                                           bool set_cond_codes) {
 4676   assert_different_registers(sub_klass, super_klass, temp_reg);
 4677   if (temp2_reg != noreg)
 4678     assert_different_registers(sub_klass, super_klass, temp_reg, temp2_reg);
 4679 #define IS_A_TEMP(reg) ((reg) == temp_reg || (reg) == temp2_reg)
 4680 
 4681   Label L_fallthrough;
 4682   int label_nulls = 0;
 4683   if (L_success == nullptr)   { L_success   = &L_fallthrough; label_nulls++; }
 4684   if (L_failure == nullptr)   { L_failure   = &L_fallthrough; label_nulls++; }
 4685   assert(label_nulls <= 1, "at most one null in the batch");
 4686 
 4687   // a couple of useful fields in sub_klass:
 4688   int ss_offset = in_bytes(Klass::secondary_supers_offset());
 4689   int sc_offset = in_bytes(Klass::secondary_super_cache_offset());
 4690   Address secondary_supers_addr(sub_klass, ss_offset);
 4691   Address super_cache_addr(     sub_klass, sc_offset);
 4692 
 4693   // Do a linear scan of the secondary super-klass chain.
 4694   // This code is rarely used, so simplicity is a virtue here.
 4695   // The repne_scan instruction uses fixed registers, which we must spill.
 4696   // Don't worry too much about pre-existing connections with the input regs.
 4697 
 4698   assert(sub_klass != rax, "killed reg"); // killed by mov(rax, super)
 4699   assert(sub_klass != rcx, "killed reg"); // killed by lea(rcx, &pst_counter)
 4700 
 4701   // Get super_klass value into rax (even if it was in rdi or rcx).
 4702   bool pushed_rax = false, pushed_rcx = false, pushed_rdi = false;
 4703   if (super_klass != rax) {
 4704     if (!IS_A_TEMP(rax)) { push(rax); pushed_rax = true; }
 4705     mov(rax, super_klass);
 4706   }
 4707   if (!IS_A_TEMP(rcx)) { push(rcx); pushed_rcx = true; }
 4708   if (!IS_A_TEMP(rdi)) { push(rdi); pushed_rdi = true; }
 4709 
 4710 #ifndef PRODUCT
 4711   uint* pst_counter = &SharedRuntime::_partial_subtype_ctr;
 4712   ExternalAddress pst_counter_addr((address) pst_counter);
 4713   NOT_LP64(  incrementl(pst_counter_addr) );
 4714   LP64_ONLY( lea(rcx, pst_counter_addr) );
 4715   LP64_ONLY( incrementl(Address(rcx, 0)) );
 4716 #endif //PRODUCT
 4717 
 4718   // We will consult the secondary-super array.
 4719   movptr(rdi, secondary_supers_addr);
 4720   // Load the array length.  (Positive movl does right thing on LP64.)
 4721   movl(rcx, Address(rdi, Array<Klass*>::length_offset_in_bytes()));
 4722   // Skip to start of data.
 4723   addptr(rdi, Array<Klass*>::base_offset_in_bytes());
 4724 
 4725   // Scan RCX words at [RDI] for an occurrence of RAX.
 4726   // Set NZ/Z based on last compare.
 4727   // Z flag value will not be set by 'repne' if RCX == 0 since 'repne' does
 4728   // not change flags (only scas instruction which is repeated sets flags).
 4729   // Set Z = 0 (not equal) before 'repne' to indicate that class was not found.
 4730 
 4731     testptr(rax,rax); // Set Z = 0
 4732     repne_scan();
 4733 
 4734   // Unspill the temp. registers:
 4735   if (pushed_rdi)  pop(rdi);
 4736   if (pushed_rcx)  pop(rcx);
 4737   if (pushed_rax)  pop(rax);
 4738 
 4739   if (set_cond_codes) {
 4740     // Special hack for the AD files:  rdi is guaranteed non-zero.
 4741     assert(!pushed_rdi, "rdi must be left non-null");
 4742     // Also, the condition codes are properly set Z/NZ on succeed/failure.
 4743   }
 4744 
 4745   if (L_failure == &L_fallthrough)
 4746         jccb(Assembler::notEqual, *L_failure);
 4747   else  jcc(Assembler::notEqual, *L_failure);
 4748 
 4749   // Success.  Cache the super we found and proceed in triumph.
 4750   movptr(super_cache_addr, super_klass);
 4751 
 4752   if (L_success != &L_fallthrough) {
 4753     jmp(*L_success);
 4754   }
 4755 
 4756 #undef IS_A_TEMP
 4757 
 4758   bind(L_fallthrough);
 4759 }
 4760 
 4761 #ifndef _LP64
 4762 
 4763 // 32-bit x86 only: always use the linear search.
 4764 void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass,
 4765                                                    Register super_klass,
 4766                                                    Register temp_reg,
 4767                                                    Register temp2_reg,
 4768                                                    Label* L_success,
 4769                                                    Label* L_failure,
 4770                                                    bool set_cond_codes) {
 4771   check_klass_subtype_slow_path_linear
 4772     (sub_klass, super_klass, temp_reg, temp2_reg, L_success, L_failure, set_cond_codes);
 4773 }
 4774 
 4775 #else // _LP64
 4776 
 4777 void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass,
 4778                                                    Register super_klass,
 4779                                                    Register temp_reg,
 4780                                                    Register temp2_reg,
 4781                                                    Label* L_success,
 4782                                                    Label* L_failure,
 4783                                                    bool set_cond_codes) {
 4784   assert(set_cond_codes == false, "must be false on 64-bit x86");
 4785   check_klass_subtype_slow_path
 4786     (sub_klass, super_klass, temp_reg, temp2_reg, noreg, noreg,
 4787      L_success, L_failure);
 4788 }
 4789 
 4790 void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass,
 4791                                                    Register super_klass,
 4792                                                    Register temp_reg,
 4793                                                    Register temp2_reg,
 4794                                                    Register temp3_reg,
 4795                                                    Register temp4_reg,
 4796                                                    Label* L_success,
 4797                                                    Label* L_failure) {
 4798   if (UseSecondarySupersTable) {
 4799     check_klass_subtype_slow_path_table
 4800       (sub_klass, super_klass, temp_reg, temp2_reg, temp3_reg, temp4_reg,
 4801        L_success, L_failure);
 4802   } else {
 4803     check_klass_subtype_slow_path_linear
 4804       (sub_klass, super_klass, temp_reg, temp2_reg, L_success, L_failure, /*set_cond_codes*/false);
 4805   }
 4806 }
 4807 
 4808 Register MacroAssembler::allocate_if_noreg(Register r,
 4809                                   RegSetIterator<Register> &available_regs,
 4810                                   RegSet &regs_to_push) {
 4811   if (!r->is_valid()) {
 4812     r = *available_regs++;
 4813     regs_to_push += r;
 4814   }
 4815   return r;
 4816 }
 4817 
 4818 void MacroAssembler::check_klass_subtype_slow_path_table(Register sub_klass,
 4819                                                          Register super_klass,
 4820                                                          Register temp_reg,
 4821                                                          Register temp2_reg,
 4822                                                          Register temp3_reg,
 4823                                                          Register result_reg,
 4824                                                          Label* L_success,
 4825                                                          Label* L_failure) {
 4826   // NB! Callers may assume that, when temp2_reg is a valid register,
 4827   // this code sets it to a nonzero value.
 4828   bool temp2_reg_was_valid = temp2_reg->is_valid();
 4829 
 4830   RegSet temps = RegSet::of(temp_reg, temp2_reg, temp3_reg);
 4831 
 4832   Label L_fallthrough;
 4833   int label_nulls = 0;
 4834   if (L_success == nullptr)   { L_success   = &L_fallthrough; label_nulls++; }
 4835   if (L_failure == nullptr)   { L_failure   = &L_fallthrough; label_nulls++; }
 4836   assert(label_nulls <= 1, "at most one null in the batch");
 4837 
 4838   BLOCK_COMMENT("check_klass_subtype_slow_path_table");
 4839 
 4840   RegSetIterator<Register> available_regs
 4841     = (RegSet::of(rax, rcx, rdx, r8) + r9 + r10 + r11 + r12 - temps - sub_klass - super_klass).begin();
 4842 
 4843   RegSet pushed_regs;
 4844 
 4845   temp_reg = allocate_if_noreg(temp_reg, available_regs, pushed_regs);
 4846   temp2_reg = allocate_if_noreg(temp2_reg, available_regs, pushed_regs);
 4847   temp3_reg = allocate_if_noreg(temp3_reg, available_regs, pushed_regs);
 4848   result_reg = allocate_if_noreg(result_reg, available_regs, pushed_regs);
 4849   Register temp4_reg = allocate_if_noreg(noreg, available_regs, pushed_regs);
 4850 
 4851   assert_different_registers(sub_klass, super_klass, temp_reg, temp2_reg, temp3_reg, result_reg);
 4852 
 4853   {
 4854 
 4855     int register_push_size = pushed_regs.size() * Register::max_slots_per_register * VMRegImpl::stack_slot_size;
 4856     int aligned_size = align_up(register_push_size, StackAlignmentInBytes);
 4857     subptr(rsp, aligned_size);
 4858     push_set(pushed_regs, 0);
 4859 
 4860     lookup_secondary_supers_table_var(sub_klass,
 4861                                       super_klass,
 4862                                       temp_reg, temp2_reg, temp3_reg, temp4_reg, result_reg);
 4863     cmpq(result_reg, 0);
 4864 
 4865     // Unspill the temp. registers:
 4866     pop_set(pushed_regs, 0);
 4867     // Increment SP but do not clobber flags.
 4868     lea(rsp, Address(rsp, aligned_size));
 4869   }
 4870 
 4871   if (temp2_reg_was_valid) {
 4872     movq(temp2_reg, 1);
 4873   }
 4874 
 4875   jcc(Assembler::notEqual, *L_failure);
 4876 
 4877   if (L_success != &L_fallthrough) {
 4878     jmp(*L_success);
 4879   }
 4880 
 4881   bind(L_fallthrough);
 4882 }
 4883 
 4884 // population_count variant for running without the POPCNT
 4885 // instruction, which was introduced with SSE4.2 in 2008.
 4886 void MacroAssembler::population_count(Register dst, Register src,
 4887                                       Register scratch1, Register scratch2) {
 4888   assert_different_registers(src, scratch1, scratch2);
 4889   if (UsePopCountInstruction) {
 4890     Assembler::popcntq(dst, src);
 4891   } else {
 4892     assert_different_registers(src, scratch1, scratch2);
 4893     assert_different_registers(dst, scratch1, scratch2);
 4894     Label loop, done;
 4895 
 4896     mov(scratch1, src);
 4897     // dst = 0;
 4898     // while(scratch1 != 0) {
 4899     //   dst++;
 4900     //   scratch1 &= (scratch1 - 1);
 4901     // }
 4902     xorl(dst, dst);
 4903     testq(scratch1, scratch1);
 4904     jccb(Assembler::equal, done);
 4905     {
 4906       bind(loop);
 4907       incq(dst);
 4908       movq(scratch2, scratch1);
 4909       decq(scratch2);
 4910       andq(scratch1, scratch2);
 4911       jccb(Assembler::notEqual, loop);
 4912     }
 4913     bind(done);
 4914   }
 4915 #ifdef ASSERT
 4916   mov64(scratch1, 0xCafeBabeDeadBeef);
 4917   movq(scratch2, scratch1);
 4918 #endif
 4919 }
 4920 
 4921 // Ensure that the inline code and the stub are using the same registers.
 4922 #define LOOKUP_SECONDARY_SUPERS_TABLE_REGISTERS                      \
 4923 do {                                                                 \
 4924   assert(r_super_klass  == rax, "mismatch");                         \
 4925   assert(r_array_base   == rbx, "mismatch");                         \
 4926   assert(r_array_length == rcx, "mismatch");                         \
 4927   assert(r_array_index  == rdx, "mismatch");                         \
 4928   assert(r_sub_klass    == rsi || r_sub_klass == noreg, "mismatch"); \
 4929   assert(r_bitmap       == r11 || r_bitmap    == noreg, "mismatch"); \
 4930   assert(result         == rdi || result      == noreg, "mismatch"); \
 4931 } while(0)
 4932 
 4933 // Versions of salq and rorq that don't need count to be in rcx
 4934 
 4935 void MacroAssembler::salq(Register dest, Register count) {
 4936   if (count == rcx) {
 4937     Assembler::salq(dest);
 4938   } else {
 4939     assert_different_registers(rcx, dest);
 4940     xchgq(rcx, count);
 4941     Assembler::salq(dest);
 4942     xchgq(rcx, count);
 4943   }
 4944 }
 4945 
 4946 void MacroAssembler::rorq(Register dest, Register count) {
 4947   if (count == rcx) {
 4948     Assembler::rorq(dest);
 4949   } else {
 4950     assert_different_registers(rcx, dest);
 4951     xchgq(rcx, count);
 4952     Assembler::rorq(dest);
 4953     xchgq(rcx, count);
 4954   }
 4955 }
 4956 
 4957 // Return true: we succeeded in generating this code
 4958 //
 4959 // At runtime, return 0 in result if r_super_klass is a superclass of
 4960 // r_sub_klass, otherwise return nonzero. Use this if you know the
 4961 // super_klass_slot of the class you're looking for. This is always
 4962 // the case for instanceof and checkcast.
 4963 void MacroAssembler::lookup_secondary_supers_table_const(Register r_sub_klass,
 4964                                                          Register r_super_klass,
 4965                                                          Register temp1,
 4966                                                          Register temp2,
 4967                                                          Register temp3,
 4968                                                          Register temp4,
 4969                                                          Register result,
 4970                                                          u1 super_klass_slot) {
 4971   assert_different_registers(r_sub_klass, r_super_klass, temp1, temp2, temp3, temp4, result);
 4972 
 4973   Label L_fallthrough, L_success, L_failure;
 4974 
 4975   BLOCK_COMMENT("lookup_secondary_supers_table {");
 4976 
 4977   const Register
 4978     r_array_index  = temp1,
 4979     r_array_length = temp2,
 4980     r_array_base   = temp3,
 4981     r_bitmap       = temp4;
 4982 
 4983   LOOKUP_SECONDARY_SUPERS_TABLE_REGISTERS;
 4984 
 4985   xorq(result, result); // = 0
 4986 
 4987   movq(r_bitmap, Address(r_sub_klass, Klass::secondary_supers_bitmap_offset()));
 4988   movq(r_array_index, r_bitmap);
 4989 
 4990   // First check the bitmap to see if super_klass might be present. If
 4991   // the bit is zero, we are certain that super_klass is not one of
 4992   // the secondary supers.
 4993   u1 bit = super_klass_slot;
 4994   {
 4995     // NB: If the count in a x86 shift instruction is 0, the flags are
 4996     // not affected, so we do a testq instead.
 4997     int shift_count = Klass::SECONDARY_SUPERS_TABLE_MASK - bit;
 4998     if (shift_count != 0) {
 4999       salq(r_array_index, shift_count);
 5000     } else {
 5001       testq(r_array_index, r_array_index);
 5002     }
 5003   }
 5004   // We test the MSB of r_array_index, i.e. its sign bit
 5005   jcc(Assembler::positive, L_failure);
 5006 
 5007   // Get the first array index that can contain super_klass into r_array_index.
 5008   if (bit != 0) {
 5009     population_count(r_array_index, r_array_index, temp2, temp3);
 5010   } else {
 5011     movl(r_array_index, 1);
 5012   }
 5013   // NB! r_array_index is off by 1. It is compensated by keeping r_array_base off by 1 word.
 5014 
 5015   // We will consult the secondary-super array.
 5016   movptr(r_array_base, Address(r_sub_klass, in_bytes(Klass::secondary_supers_offset())));
 5017 
 5018   // We're asserting that the first word in an Array<Klass*> is the
 5019   // length, and the second word is the first word of the data. If
 5020   // that ever changes, r_array_base will have to be adjusted here.
 5021   assert(Array<Klass*>::base_offset_in_bytes() == wordSize, "Adjust this code");
 5022   assert(Array<Klass*>::length_offset_in_bytes() == 0, "Adjust this code");
 5023 
 5024   cmpq(r_super_klass, Address(r_array_base, r_array_index, Address::times_8));
 5025   jccb(Assembler::equal, L_success);
 5026 
 5027   // Is there another entry to check? Consult the bitmap.
 5028   btq(r_bitmap, (bit + 1) & Klass::SECONDARY_SUPERS_TABLE_MASK);
 5029   jccb(Assembler::carryClear, L_failure);
 5030 
 5031   // Linear probe. Rotate the bitmap so that the next bit to test is
 5032   // in Bit 1.
 5033   if (bit != 0) {
 5034     rorq(r_bitmap, bit);
 5035   }
 5036 
 5037   // Calls into the stub generated by lookup_secondary_supers_table_slow_path.
 5038   // Arguments: r_super_klass, r_array_base, r_array_index, r_bitmap.
 5039   // Kills: r_array_length.
 5040   // Returns: result.
 5041   call(RuntimeAddress(StubRoutines::lookup_secondary_supers_table_slow_path_stub()));
 5042   // Result (0/1) is in rdi
 5043   jmpb(L_fallthrough);
 5044 
 5045   bind(L_failure);
 5046   incq(result); // 0 => 1
 5047 
 5048   bind(L_success);
 5049   // result = 0;
 5050 
 5051   bind(L_fallthrough);
 5052   BLOCK_COMMENT("} lookup_secondary_supers_table");
 5053 
 5054   if (VerifySecondarySupers) {
 5055     verify_secondary_supers_table(r_sub_klass, r_super_klass, result,
 5056                                   temp1, temp2, temp3);
 5057   }
 5058 }
 5059 
 5060 // At runtime, return 0 in result if r_super_klass is a superclass of
 5061 // r_sub_klass, otherwise return nonzero. Use this version of
 5062 // lookup_secondary_supers_table() if you don't know ahead of time
 5063 // which superclass will be searched for. Used by interpreter and
 5064 // runtime stubs. It is larger and has somewhat greater latency than
 5065 // the version above, which takes a constant super_klass_slot.
 5066 void MacroAssembler::lookup_secondary_supers_table_var(Register r_sub_klass,
 5067                                                        Register r_super_klass,
 5068                                                        Register temp1,
 5069                                                        Register temp2,
 5070                                                        Register temp3,
 5071                                                        Register temp4,
 5072                                                        Register result) {
 5073   assert_different_registers(r_sub_klass, r_super_klass, temp1, temp2, temp3, temp4, result);
 5074   assert_different_registers(r_sub_klass, r_super_klass, rcx);
 5075   RegSet temps = RegSet::of(temp1, temp2, temp3, temp4);
 5076 
 5077   Label L_fallthrough, L_success, L_failure;
 5078 
 5079   BLOCK_COMMENT("lookup_secondary_supers_table {");
 5080 
 5081   RegSetIterator<Register> available_regs = (temps - rcx).begin();
 5082 
 5083   // FIXME. Once we are sure that all paths reaching this point really
 5084   // do pass rcx as one of our temps we can get rid of the following
 5085   // workaround.
 5086   assert(temps.contains(rcx), "fix this code");
 5087 
 5088   // We prefer to have our shift count in rcx. If rcx is one of our
 5089   // temps, use it for slot. If not, pick any of our temps.
 5090   Register slot;
 5091   if (!temps.contains(rcx)) {
 5092     slot = *available_regs++;
 5093   } else {
 5094     slot = rcx;
 5095   }
 5096 
 5097   const Register r_array_index = *available_regs++;
 5098   const Register r_bitmap      = *available_regs++;
 5099 
 5100   // The logic above guarantees this property, but we state it here.
 5101   assert_different_registers(r_array_index, r_bitmap, rcx);
 5102 
 5103   movq(r_bitmap, Address(r_sub_klass, Klass::secondary_supers_bitmap_offset()));
 5104   movq(r_array_index, r_bitmap);
 5105 
 5106   // First check the bitmap to see if super_klass might be present. If
 5107   // the bit is zero, we are certain that super_klass is not one of
 5108   // the secondary supers.
 5109   movb(slot, Address(r_super_klass, Klass::hash_slot_offset()));
 5110   xorl(slot, (u1)(Klass::SECONDARY_SUPERS_TABLE_SIZE - 1)); // slot ^ 63 === 63 - slot (mod 64)
 5111   salq(r_array_index, slot);
 5112 
 5113   testq(r_array_index, r_array_index);
 5114   // We test the MSB of r_array_index, i.e. its sign bit
 5115   jcc(Assembler::positive, L_failure);
 5116 
 5117   const Register r_array_base = *available_regs++;
 5118 
 5119   // Get the first array index that can contain super_klass into r_array_index.
 5120   // Note: Clobbers r_array_base and slot.
 5121   population_count(r_array_index, r_array_index, /*temp2*/r_array_base, /*temp3*/slot);
 5122 
 5123   // NB! r_array_index is off by 1. It is compensated by keeping r_array_base off by 1 word.
 5124 
 5125   // We will consult the secondary-super array.
 5126   movptr(r_array_base, Address(r_sub_klass, in_bytes(Klass::secondary_supers_offset())));
 5127 
 5128   // We're asserting that the first word in an Array<Klass*> is the
 5129   // length, and the second word is the first word of the data. If
 5130   // that ever changes, r_array_base will have to be adjusted here.
 5131   assert(Array<Klass*>::base_offset_in_bytes() == wordSize, "Adjust this code");
 5132   assert(Array<Klass*>::length_offset_in_bytes() == 0, "Adjust this code");
 5133 
 5134   cmpq(r_super_klass, Address(r_array_base, r_array_index, Address::times_8));
 5135   jccb(Assembler::equal, L_success);
 5136 
 5137   // Restore slot to its true value
 5138   movb(slot, Address(r_super_klass, Klass::hash_slot_offset()));
 5139 
 5140   // Linear probe. Rotate the bitmap so that the next bit to test is
 5141   // in Bit 1.
 5142   rorq(r_bitmap, slot);
 5143 
 5144   // Is there another entry to check? Consult the bitmap.
 5145   btq(r_bitmap, 1);
 5146   jccb(Assembler::carryClear, L_failure);
 5147 
 5148   // Calls into the stub generated by lookup_secondary_supers_table_slow_path.
 5149   // Arguments: r_super_klass, r_array_base, r_array_index, r_bitmap.
 5150   // Kills: r_array_length.
 5151   // Returns: result.
 5152   lookup_secondary_supers_table_slow_path(r_super_klass,
 5153                                           r_array_base,
 5154                                           r_array_index,
 5155                                           r_bitmap,
 5156                                           /*temp1*/result,
 5157                                           /*temp2*/slot,
 5158                                           &L_success,
 5159                                           nullptr);
 5160 
 5161   bind(L_failure);
 5162   movq(result, 1);
 5163   jmpb(L_fallthrough);
 5164 
 5165   bind(L_success);
 5166   xorq(result, result); // = 0
 5167 
 5168   bind(L_fallthrough);
 5169   BLOCK_COMMENT("} lookup_secondary_supers_table");
 5170 
 5171   if (VerifySecondarySupers) {
 5172     verify_secondary_supers_table(r_sub_klass, r_super_klass, result,
 5173                                   temp1, temp2, temp3);
 5174   }
 5175 }
 5176 
 5177 void MacroAssembler::repne_scanq(Register addr, Register value, Register count, Register limit,
 5178                                  Label* L_success, Label* L_failure) {
 5179   Label L_loop, L_fallthrough;
 5180   {
 5181     int label_nulls = 0;
 5182     if (L_success == nullptr) { L_success = &L_fallthrough; label_nulls++; }
 5183     if (L_failure == nullptr) { L_failure = &L_fallthrough; label_nulls++; }
 5184     assert(label_nulls <= 1, "at most one null in the batch");
 5185   }
 5186   bind(L_loop);
 5187   cmpq(value, Address(addr, count, Address::times_8));
 5188   jcc(Assembler::equal, *L_success);
 5189   addl(count, 1);
 5190   cmpl(count, limit);
 5191   jcc(Assembler::less, L_loop);
 5192 
 5193   if (&L_fallthrough != L_failure) {
 5194     jmp(*L_failure);
 5195   }
 5196   bind(L_fallthrough);
 5197 }
 5198 
 5199 // Called by code generated by check_klass_subtype_slow_path
 5200 // above. This is called when there is a collision in the hashed
 5201 // lookup in the secondary supers array.
 5202 void MacroAssembler::lookup_secondary_supers_table_slow_path(Register r_super_klass,
 5203                                                              Register r_array_base,
 5204                                                              Register r_array_index,
 5205                                                              Register r_bitmap,
 5206                                                              Register temp1,
 5207                                                              Register temp2,
 5208                                                              Label* L_success,
 5209                                                              Label* L_failure) {
 5210   assert_different_registers(r_super_klass, r_array_base, r_array_index, r_bitmap, temp1, temp2);
 5211 
 5212   const Register
 5213     r_array_length = temp1,
 5214     r_sub_klass    = noreg,
 5215     result         = noreg;
 5216 
 5217   Label L_fallthrough;
 5218   int label_nulls = 0;
 5219   if (L_success == nullptr)   { L_success   = &L_fallthrough; label_nulls++; }
 5220   if (L_failure == nullptr)   { L_failure   = &L_fallthrough; label_nulls++; }
 5221   assert(label_nulls <= 1, "at most one null in the batch");
 5222 
 5223   // Load the array length.
 5224   movl(r_array_length, Address(r_array_base, Array<Klass*>::length_offset_in_bytes()));
 5225   // And adjust the array base to point to the data.
 5226   // NB! Effectively increments current slot index by 1.
 5227   assert(Array<Klass*>::base_offset_in_bytes() == wordSize, "");
 5228   addptr(r_array_base, Array<Klass*>::base_offset_in_bytes());
 5229 
 5230   // Linear probe
 5231   Label L_huge;
 5232 
 5233   // The bitmap is full to bursting.
 5234   // Implicit invariant: BITMAP_FULL implies (length > 0)
 5235   cmpl(r_array_length, (int32_t)Klass::SECONDARY_SUPERS_TABLE_SIZE - 2);
 5236   jcc(Assembler::greater, L_huge);
 5237 
 5238   // NB! Our caller has checked bits 0 and 1 in the bitmap. The
 5239   // current slot (at secondary_supers[r_array_index]) has not yet
 5240   // been inspected, and r_array_index may be out of bounds if we
 5241   // wrapped around the end of the array.
 5242 
 5243   { // This is conventional linear probing, but instead of terminating
 5244     // when a null entry is found in the table, we maintain a bitmap
 5245     // in which a 0 indicates missing entries.
 5246     // The check above guarantees there are 0s in the bitmap, so the loop
 5247     // eventually terminates.
 5248 
 5249     xorl(temp2, temp2); // = 0;
 5250 
 5251     Label L_again;
 5252     bind(L_again);
 5253 
 5254     // Check for array wraparound.
 5255     cmpl(r_array_index, r_array_length);
 5256     cmovl(Assembler::greaterEqual, r_array_index, temp2);
 5257 
 5258     cmpq(r_super_klass, Address(r_array_base, r_array_index, Address::times_8));
 5259     jcc(Assembler::equal, *L_success);
 5260 
 5261     // If the next bit in bitmap is zero, we're done.
 5262     btq(r_bitmap, 2); // look-ahead check (Bit 2); Bits 0 and 1 are tested by now
 5263     jcc(Assembler::carryClear, *L_failure);
 5264 
 5265     rorq(r_bitmap, 1); // Bits 1/2 => 0/1
 5266     addl(r_array_index, 1);
 5267 
 5268     jmp(L_again);
 5269   }
 5270 
 5271   { // Degenerate case: more than 64 secondary supers.
 5272     // FIXME: We could do something smarter here, maybe a vectorized
 5273     // comparison or a binary search, but is that worth any added
 5274     // complexity?
 5275     bind(L_huge);
 5276     xorl(r_array_index, r_array_index); // = 0
 5277     repne_scanq(r_array_base, r_super_klass, r_array_index, r_array_length,
 5278                 L_success,
 5279                 (&L_fallthrough != L_failure ? L_failure : nullptr));
 5280 
 5281     bind(L_fallthrough);
 5282   }
 5283 }
 5284 
 5285 struct VerifyHelperArguments {
 5286   Klass* _super;
 5287   Klass* _sub;
 5288   intptr_t _linear_result;
 5289   intptr_t _table_result;
 5290 };
 5291 
 5292 static void verify_secondary_supers_table_helper(const char* msg, VerifyHelperArguments* args) {
 5293   Klass::on_secondary_supers_verification_failure(args->_super,
 5294                                                   args->_sub,
 5295                                                   args->_linear_result,
 5296                                                   args->_table_result,
 5297                                                   msg);
 5298 }
 5299 
 5300 // Make sure that the hashed lookup and a linear scan agree.
 5301 void MacroAssembler::verify_secondary_supers_table(Register r_sub_klass,
 5302                                                    Register r_super_klass,
 5303                                                    Register result,
 5304                                                    Register temp1,
 5305                                                    Register temp2,
 5306                                                    Register temp3) {
 5307   const Register
 5308       r_array_index  = temp1,
 5309       r_array_length = temp2,
 5310       r_array_base   = temp3,
 5311       r_bitmap       = noreg;
 5312 
 5313   BLOCK_COMMENT("verify_secondary_supers_table {");
 5314 
 5315   Label L_success, L_failure, L_check, L_done;
 5316 
 5317   movptr(r_array_base, Address(r_sub_klass, in_bytes(Klass::secondary_supers_offset())));
 5318   movl(r_array_length, Address(r_array_base, Array<Klass*>::length_offset_in_bytes()));
 5319   // And adjust the array base to point to the data.
 5320   addptr(r_array_base, Array<Klass*>::base_offset_in_bytes());
 5321 
 5322   testl(r_array_length, r_array_length); // array_length == 0?
 5323   jcc(Assembler::zero, L_failure);
 5324 
 5325   movl(r_array_index, 0);
 5326   repne_scanq(r_array_base, r_super_klass, r_array_index, r_array_length, &L_success);
 5327   // fall through to L_failure
 5328 
 5329   const Register linear_result = r_array_index; // reuse temp1
 5330 
 5331   bind(L_failure); // not present
 5332   movl(linear_result, 1);
 5333   jmp(L_check);
 5334 
 5335   bind(L_success); // present
 5336   movl(linear_result, 0);
 5337 
 5338   bind(L_check);
 5339   cmpl(linear_result, result);
 5340   jcc(Assembler::equal, L_done);
 5341 
 5342   { // To avoid calling convention issues, build a record on the stack
 5343     // and pass the pointer to that instead.
 5344     push(result);
 5345     push(linear_result);
 5346     push(r_sub_klass);
 5347     push(r_super_klass);
 5348     movptr(c_rarg1, rsp);
 5349     movptr(c_rarg0, (uintptr_t) "mismatch");
 5350     call(RuntimeAddress(CAST_FROM_FN_PTR(address, verify_secondary_supers_table_helper)));
 5351     should_not_reach_here();
 5352   }
 5353   bind(L_done);
 5354 
 5355   BLOCK_COMMENT("} verify_secondary_supers_table");
 5356 }
 5357 
 5358 #undef LOOKUP_SECONDARY_SUPERS_TABLE_REGISTERS
 5359 
 5360 #endif // LP64
 5361 
 5362 void MacroAssembler::clinit_barrier(Register klass, Register thread, Label* L_fast_path, Label* L_slow_path) {
 5363   assert(L_fast_path != nullptr || L_slow_path != nullptr, "at least one is required");
 5364 
 5365   Label L_fallthrough;
 5366   if (L_fast_path == nullptr) {
 5367     L_fast_path = &L_fallthrough;
 5368   } else if (L_slow_path == nullptr) {
 5369     L_slow_path = &L_fallthrough;
 5370   }
 5371 
 5372   // Fast path check: class is fully initialized.
 5373   // init_state needs acquire, but x86 is TSO, and so we are already good.
 5374   cmpb(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
 5375   jcc(Assembler::equal, *L_fast_path);
 5376 
 5377   // Fast path check: current thread is initializer thread
 5378   cmpptr(thread, Address(klass, InstanceKlass::init_thread_offset()));
 5379   if (L_slow_path == &L_fallthrough) {
 5380     jcc(Assembler::equal, *L_fast_path);
 5381     bind(*L_slow_path);
 5382   } else if (L_fast_path == &L_fallthrough) {
 5383     jcc(Assembler::notEqual, *L_slow_path);
 5384     bind(*L_fast_path);
 5385   } else {
 5386     Unimplemented();
 5387   }
 5388 }
 5389 
 5390 void MacroAssembler::cmov32(Condition cc, Register dst, Address src) {
 5391   if (VM_Version::supports_cmov()) {
 5392     cmovl(cc, dst, src);
 5393   } else {
 5394     Label L;
 5395     jccb(negate_condition(cc), L);
 5396     movl(dst, src);
 5397     bind(L);
 5398   }
 5399 }
 5400 
 5401 void MacroAssembler::cmov32(Condition cc, Register dst, Register src) {
 5402   if (VM_Version::supports_cmov()) {
 5403     cmovl(cc, dst, src);
 5404   } else {
 5405     Label L;
 5406     jccb(negate_condition(cc), L);
 5407     movl(dst, src);
 5408     bind(L);
 5409   }
 5410 }
 5411 
 5412 void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file, int line) {
 5413   if (!VerifyOops) return;
 5414 
 5415   BLOCK_COMMENT("verify_oop {");
 5416 #ifdef _LP64
 5417   push(rscratch1);
 5418 #endif
 5419   push(rax);                          // save rax
 5420   push(reg);                          // pass register argument
 5421 
 5422   // Pass register number to verify_oop_subroutine
 5423   const char* b = nullptr;
 5424   {
 5425     ResourceMark rm;
 5426     stringStream ss;
 5427     ss.print("verify_oop: %s: %s (%s:%d)", reg->name(), s, file, line);
 5428     b = code_string(ss.as_string());
 5429   }
 5430   AddressLiteral buffer((address) b, external_word_Relocation::spec_for_immediate());
 5431   pushptr(buffer.addr(), rscratch1);
 5432 
 5433   // call indirectly to solve generation ordering problem
 5434   movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
 5435   call(rax);
 5436   // Caller pops the arguments (oop, message) and restores rax, r10
 5437   BLOCK_COMMENT("} verify_oop");
 5438 }
 5439 
 5440 void MacroAssembler::vallones(XMMRegister dst, int vector_len) {
 5441   if (UseAVX > 2 && (vector_len == Assembler::AVX_512bit || VM_Version::supports_avx512vl())) {
 5442     // Only pcmpeq has dependency breaking treatment (i.e the execution can begin without
 5443     // waiting for the previous result on dst), not vpcmpeqd, so just use vpternlog
 5444     vpternlogd(dst, 0xFF, dst, dst, vector_len);
 5445   } else if (VM_Version::supports_avx()) {
 5446     vpcmpeqd(dst, dst, dst, vector_len);
 5447   } else {
 5448     pcmpeqd(dst, dst);
 5449   }
 5450 }
 5451 
 5452 Address MacroAssembler::argument_address(RegisterOrConstant arg_slot,
 5453                                          int extra_slot_offset) {
 5454   // cf. TemplateTable::prepare_invoke(), if (load_receiver).
 5455   int stackElementSize = Interpreter::stackElementSize;
 5456   int offset = Interpreter::expr_offset_in_bytes(extra_slot_offset+0);
 5457 #ifdef ASSERT
 5458   int offset1 = Interpreter::expr_offset_in_bytes(extra_slot_offset+1);
 5459   assert(offset1 - offset == stackElementSize, "correct arithmetic");
 5460 #endif
 5461   Register             scale_reg    = noreg;
 5462   Address::ScaleFactor scale_factor = Address::no_scale;
 5463   if (arg_slot.is_constant()) {
 5464     offset += arg_slot.as_constant() * stackElementSize;
 5465   } else {
 5466     scale_reg    = arg_slot.as_register();
 5467     scale_factor = Address::times(stackElementSize);
 5468   }
 5469   offset += wordSize;           // return PC is on stack
 5470   return Address(rsp, scale_reg, scale_factor, offset);
 5471 }
 5472 
 5473 void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* file, int line) {
 5474   if (!VerifyOops) return;
 5475 
 5476 #ifdef _LP64
 5477   push(rscratch1);
 5478 #endif
 5479   push(rax); // save rax,
 5480   // addr may contain rsp so we will have to adjust it based on the push
 5481   // we just did (and on 64 bit we do two pushes)
 5482   // NOTE: 64bit seemed to have had a bug in that it did movq(addr, rax); which
 5483   // stores rax into addr which is backwards of what was intended.
 5484   if (addr.uses(rsp)) {
 5485     lea(rax, addr);
 5486     pushptr(Address(rax, LP64_ONLY(2 *) BytesPerWord));
 5487   } else {
 5488     pushptr(addr);
 5489   }
 5490 
 5491   // Pass register number to verify_oop_subroutine
 5492   const char* b = nullptr;
 5493   {
 5494     ResourceMark rm;
 5495     stringStream ss;
 5496     ss.print("verify_oop_addr: %s (%s:%d)", s, file, line);
 5497     b = code_string(ss.as_string());
 5498   }
 5499   AddressLiteral buffer((address) b, external_word_Relocation::spec_for_immediate());
 5500   pushptr(buffer.addr(), rscratch1);
 5501 
 5502   // call indirectly to solve generation ordering problem
 5503   movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
 5504   call(rax);
 5505   // Caller pops the arguments (addr, message) and restores rax, r10.
 5506 }
 5507 
 5508 void MacroAssembler::verify_tlab() {
 5509 #ifdef ASSERT
 5510   if (UseTLAB && VerifyOops) {
 5511     Label next, ok;
 5512     Register t1 = rsi;
 5513     Register thread_reg = NOT_LP64(rbx) LP64_ONLY(r15_thread);
 5514 
 5515     push(t1);
 5516     NOT_LP64(push(thread_reg));
 5517     NOT_LP64(get_thread(thread_reg));
 5518 
 5519     movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
 5520     cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())));
 5521     jcc(Assembler::aboveEqual, next);
 5522     STOP("assert(top >= start)");
 5523     should_not_reach_here();
 5524 
 5525     bind(next);
 5526     movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
 5527     cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
 5528     jcc(Assembler::aboveEqual, ok);
 5529     STOP("assert(top <= end)");
 5530     should_not_reach_here();
 5531 
 5532     bind(ok);
 5533     NOT_LP64(pop(thread_reg));
 5534     pop(t1);
 5535   }
 5536 #endif
 5537 }
 5538 
 5539 class ControlWord {
 5540  public:
 5541   int32_t _value;
 5542 
 5543   int  rounding_control() const        { return  (_value >> 10) & 3      ; }
 5544   int  precision_control() const       { return  (_value >>  8) & 3      ; }
 5545   bool precision() const               { return ((_value >>  5) & 1) != 0; }
 5546   bool underflow() const               { return ((_value >>  4) & 1) != 0; }
 5547   bool overflow() const                { return ((_value >>  3) & 1) != 0; }
 5548   bool zero_divide() const             { return ((_value >>  2) & 1) != 0; }
 5549   bool denormalized() const            { return ((_value >>  1) & 1) != 0; }
 5550   bool invalid() const                 { return ((_value >>  0) & 1) != 0; }
 5551 
 5552   void print() const {
 5553     // rounding control
 5554     const char* rc;
 5555     switch (rounding_control()) {
 5556       case 0: rc = "round near"; break;
 5557       case 1: rc = "round down"; break;
 5558       case 2: rc = "round up  "; break;
 5559       case 3: rc = "chop      "; break;
 5560       default:
 5561         rc = nullptr; // silence compiler warnings
 5562         fatal("Unknown rounding control: %d", rounding_control());
 5563     };
 5564     // precision control
 5565     const char* pc;
 5566     switch (precision_control()) {
 5567       case 0: pc = "24 bits "; break;
 5568       case 1: pc = "reserved"; break;
 5569       case 2: pc = "53 bits "; break;
 5570       case 3: pc = "64 bits "; break;
 5571       default:
 5572         pc = nullptr; // silence compiler warnings
 5573         fatal("Unknown precision control: %d", precision_control());
 5574     };
 5575     // flags
 5576     char f[9];
 5577     f[0] = ' ';
 5578     f[1] = ' ';
 5579     f[2] = (precision   ()) ? 'P' : 'p';
 5580     f[3] = (underflow   ()) ? 'U' : 'u';
 5581     f[4] = (overflow    ()) ? 'O' : 'o';
 5582     f[5] = (zero_divide ()) ? 'Z' : 'z';
 5583     f[6] = (denormalized()) ? 'D' : 'd';
 5584     f[7] = (invalid     ()) ? 'I' : 'i';
 5585     f[8] = '\x0';
 5586     // output
 5587     printf("%04x  masks = %s, %s, %s", _value & 0xFFFF, f, rc, pc);
 5588   }
 5589 
 5590 };
 5591 
 5592 class StatusWord {
 5593  public:
 5594   int32_t _value;
 5595 
 5596   bool busy() const                    { return ((_value >> 15) & 1) != 0; }
 5597   bool C3() const                      { return ((_value >> 14) & 1) != 0; }
 5598   bool C2() const                      { return ((_value >> 10) & 1) != 0; }
 5599   bool C1() const                      { return ((_value >>  9) & 1) != 0; }
 5600   bool C0() const                      { return ((_value >>  8) & 1) != 0; }
 5601   int  top() const                     { return  (_value >> 11) & 7      ; }
 5602   bool error_status() const            { return ((_value >>  7) & 1) != 0; }
 5603   bool stack_fault() const             { return ((_value >>  6) & 1) != 0; }
 5604   bool precision() const               { return ((_value >>  5) & 1) != 0; }
 5605   bool underflow() const               { return ((_value >>  4) & 1) != 0; }
 5606   bool overflow() const                { return ((_value >>  3) & 1) != 0; }
 5607   bool zero_divide() const             { return ((_value >>  2) & 1) != 0; }
 5608   bool denormalized() const            { return ((_value >>  1) & 1) != 0; }
 5609   bool invalid() const                 { return ((_value >>  0) & 1) != 0; }
 5610 
 5611   void print() const {
 5612     // condition codes
 5613     char c[5];
 5614     c[0] = (C3()) ? '3' : '-';
 5615     c[1] = (C2()) ? '2' : '-';
 5616     c[2] = (C1()) ? '1' : '-';
 5617     c[3] = (C0()) ? '0' : '-';
 5618     c[4] = '\x0';
 5619     // flags
 5620     char f[9];
 5621     f[0] = (error_status()) ? 'E' : '-';
 5622     f[1] = (stack_fault ()) ? 'S' : '-';
 5623     f[2] = (precision   ()) ? 'P' : '-';
 5624     f[3] = (underflow   ()) ? 'U' : '-';
 5625     f[4] = (overflow    ()) ? 'O' : '-';
 5626     f[5] = (zero_divide ()) ? 'Z' : '-';
 5627     f[6] = (denormalized()) ? 'D' : '-';
 5628     f[7] = (invalid     ()) ? 'I' : '-';
 5629     f[8] = '\x0';
 5630     // output
 5631     printf("%04x  flags = %s, cc =  %s, top = %d", _value & 0xFFFF, f, c, top());
 5632   }
 5633 
 5634 };
 5635 
 5636 class TagWord {
 5637  public:
 5638   int32_t _value;
 5639 
 5640   int tag_at(int i) const              { return (_value >> (i*2)) & 3; }
 5641 
 5642   void print() const {
 5643     printf("%04x", _value & 0xFFFF);
 5644   }
 5645 
 5646 };
 5647 
 5648 class FPU_Register {
 5649  public:
 5650   int32_t _m0;
 5651   int32_t _m1;
 5652   int16_t _ex;
 5653 
 5654   bool is_indefinite() const           {
 5655     return _ex == -1 && _m1 == (int32_t)0xC0000000 && _m0 == 0;
 5656   }
 5657 
 5658   void print() const {
 5659     char  sign = (_ex < 0) ? '-' : '+';
 5660     const char* kind = (_ex == 0x7FFF || _ex == (int16_t)-1) ? "NaN" : "   ";
 5661     printf("%c%04hx.%08x%08x  %s", sign, _ex, _m1, _m0, kind);
 5662   };
 5663 
 5664 };
 5665 
 5666 class FPU_State {
 5667  public:
 5668   enum {
 5669     register_size       = 10,
 5670     number_of_registers =  8,
 5671     register_mask       =  7
 5672   };
 5673 
 5674   ControlWord  _control_word;
 5675   StatusWord   _status_word;
 5676   TagWord      _tag_word;
 5677   int32_t      _error_offset;
 5678   int32_t      _error_selector;
 5679   int32_t      _data_offset;
 5680   int32_t      _data_selector;
 5681   int8_t       _register[register_size * number_of_registers];
 5682 
 5683   int tag_for_st(int i) const          { return _tag_word.tag_at((_status_word.top() + i) & register_mask); }
 5684   FPU_Register* st(int i) const        { return (FPU_Register*)&_register[register_size * i]; }
 5685 
 5686   const char* tag_as_string(int tag) const {
 5687     switch (tag) {
 5688       case 0: return "valid";
 5689       case 1: return "zero";
 5690       case 2: return "special";
 5691       case 3: return "empty";
 5692     }
 5693     ShouldNotReachHere();
 5694     return nullptr;
 5695   }
 5696 
 5697   void print() const {
 5698     // print computation registers
 5699     { int t = _status_word.top();
 5700       for (int i = 0; i < number_of_registers; i++) {
 5701         int j = (i - t) & register_mask;
 5702         printf("%c r%d = ST%d = ", (j == 0 ? '*' : ' '), i, j);
 5703         st(j)->print();
 5704         printf(" %s\n", tag_as_string(_tag_word.tag_at(i)));
 5705       }
 5706     }
 5707     printf("\n");
 5708     // print control registers
 5709     printf("ctrl = "); _control_word.print(); printf("\n");
 5710     printf("stat = "); _status_word .print(); printf("\n");
 5711     printf("tags = "); _tag_word    .print(); printf("\n");
 5712   }
 5713 
 5714 };
 5715 
 5716 class Flag_Register {
 5717  public:
 5718   int32_t _value;
 5719 
 5720   bool overflow() const                { return ((_value >> 11) & 1) != 0; }
 5721   bool direction() const               { return ((_value >> 10) & 1) != 0; }
 5722   bool sign() const                    { return ((_value >>  7) & 1) != 0; }
 5723   bool zero() const                    { return ((_value >>  6) & 1) != 0; }
 5724   bool auxiliary_carry() const         { return ((_value >>  4) & 1) != 0; }
 5725   bool parity() const                  { return ((_value >>  2) & 1) != 0; }
 5726   bool carry() const                   { return ((_value >>  0) & 1) != 0; }
 5727 
 5728   void print() const {
 5729     // flags
 5730     char f[8];
 5731     f[0] = (overflow       ()) ? 'O' : '-';
 5732     f[1] = (direction      ()) ? 'D' : '-';
 5733     f[2] = (sign           ()) ? 'S' : '-';
 5734     f[3] = (zero           ()) ? 'Z' : '-';
 5735     f[4] = (auxiliary_carry()) ? 'A' : '-';
 5736     f[5] = (parity         ()) ? 'P' : '-';
 5737     f[6] = (carry          ()) ? 'C' : '-';
 5738     f[7] = '\x0';
 5739     // output
 5740     printf("%08x  flags = %s", _value, f);
 5741   }
 5742 
 5743 };
 5744 
 5745 class IU_Register {
 5746  public:
 5747   int32_t _value;
 5748 
 5749   void print() const {
 5750     printf("%08x  %11d", _value, _value);
 5751   }
 5752 
 5753 };
 5754 
 5755 class IU_State {
 5756  public:
 5757   Flag_Register _eflags;
 5758   IU_Register   _rdi;
 5759   IU_Register   _rsi;
 5760   IU_Register   _rbp;
 5761   IU_Register   _rsp;
 5762   IU_Register   _rbx;
 5763   IU_Register   _rdx;
 5764   IU_Register   _rcx;
 5765   IU_Register   _rax;
 5766 
 5767   void print() const {
 5768     // computation registers
 5769     printf("rax,  = "); _rax.print(); printf("\n");
 5770     printf("rbx,  = "); _rbx.print(); printf("\n");
 5771     printf("rcx  = "); _rcx.print(); printf("\n");
 5772     printf("rdx  = "); _rdx.print(); printf("\n");
 5773     printf("rdi  = "); _rdi.print(); printf("\n");
 5774     printf("rsi  = "); _rsi.print(); printf("\n");
 5775     printf("rbp,  = "); _rbp.print(); printf("\n");
 5776     printf("rsp  = "); _rsp.print(); printf("\n");
 5777     printf("\n");
 5778     // control registers
 5779     printf("flgs = "); _eflags.print(); printf("\n");
 5780   }
 5781 };
 5782 
 5783 
 5784 class CPU_State {
 5785  public:
 5786   FPU_State _fpu_state;
 5787   IU_State  _iu_state;
 5788 
 5789   void print() const {
 5790     printf("--------------------------------------------------\n");
 5791     _iu_state .print();
 5792     printf("\n");
 5793     _fpu_state.print();
 5794     printf("--------------------------------------------------\n");
 5795   }
 5796 
 5797 };
 5798 
 5799 
 5800 static void _print_CPU_state(CPU_State* state) {
 5801   state->print();
 5802 };
 5803 
 5804 
 5805 void MacroAssembler::print_CPU_state() {
 5806   push_CPU_state();
 5807   push(rsp);                // pass CPU state
 5808   call(RuntimeAddress(CAST_FROM_FN_PTR(address, _print_CPU_state)));
 5809   addptr(rsp, wordSize);       // discard argument
 5810   pop_CPU_state();
 5811 }
 5812 
 5813 
 5814 #ifndef _LP64
 5815 static bool _verify_FPU(int stack_depth, char* s, CPU_State* state) {
 5816   static int counter = 0;
 5817   FPU_State* fs = &state->_fpu_state;
 5818   counter++;
 5819   // For leaf calls, only verify that the top few elements remain empty.
 5820   // We only need 1 empty at the top for C2 code.
 5821   if( stack_depth < 0 ) {
 5822     if( fs->tag_for_st(7) != 3 ) {
 5823       printf("FPR7 not empty\n");
 5824       state->print();
 5825       assert(false, "error");
 5826       return false;
 5827     }
 5828     return true;                // All other stack states do not matter
 5829   }
 5830 
 5831   assert((fs->_control_word._value & 0xffff) == StubRoutines::x86::fpu_cntrl_wrd_std(),
 5832          "bad FPU control word");
 5833 
 5834   // compute stack depth
 5835   int i = 0;
 5836   while (i < FPU_State::number_of_registers && fs->tag_for_st(i)  < 3) i++;
 5837   int d = i;
 5838   while (i < FPU_State::number_of_registers && fs->tag_for_st(i) == 3) i++;
 5839   // verify findings
 5840   if (i != FPU_State::number_of_registers) {
 5841     // stack not contiguous
 5842     printf("%s: stack not contiguous at ST%d\n", s, i);
 5843     state->print();
 5844     assert(false, "error");
 5845     return false;
 5846   }
 5847   // check if computed stack depth corresponds to expected stack depth
 5848   if (stack_depth < 0) {
 5849     // expected stack depth is -stack_depth or less
 5850     if (d > -stack_depth) {
 5851       // too many elements on the stack
 5852       printf("%s: <= %d stack elements expected but found %d\n", s, -stack_depth, d);
 5853       state->print();
 5854       assert(false, "error");
 5855       return false;
 5856     }
 5857   } else {
 5858     // expected stack depth is stack_depth
 5859     if (d != stack_depth) {
 5860       // wrong stack depth
 5861       printf("%s: %d stack elements expected but found %d\n", s, stack_depth, d);
 5862       state->print();
 5863       assert(false, "error");
 5864       return false;
 5865     }
 5866   }
 5867   // everything is cool
 5868   return true;
 5869 }
 5870 
 5871 void MacroAssembler::verify_FPU(int stack_depth, const char* s) {
 5872   if (!VerifyFPU) return;
 5873   push_CPU_state();
 5874   push(rsp);                // pass CPU state
 5875   ExternalAddress msg((address) s);
 5876   // pass message string s
 5877   pushptr(msg.addr(), noreg);
 5878   push(stack_depth);        // pass stack depth
 5879   call(RuntimeAddress(CAST_FROM_FN_PTR(address, _verify_FPU)));
 5880   addptr(rsp, 3 * wordSize);   // discard arguments
 5881   // check for error
 5882   { Label L;
 5883     testl(rax, rax);
 5884     jcc(Assembler::notZero, L);
 5885     int3();                  // break if error condition
 5886     bind(L);
 5887   }
 5888   pop_CPU_state();
 5889 }
 5890 #endif // _LP64
 5891 
 5892 void MacroAssembler::restore_cpu_control_state_after_jni(Register rscratch) {
 5893   // Either restore the MXCSR register after returning from the JNI Call
 5894   // or verify that it wasn't changed (with -Xcheck:jni flag).
 5895   if (VM_Version::supports_sse()) {
 5896     if (RestoreMXCSROnJNICalls) {
 5897       ldmxcsr(ExternalAddress(StubRoutines::x86::addr_mxcsr_std()), rscratch);
 5898     } else if (CheckJNICalls) {
 5899       call(RuntimeAddress(StubRoutines::x86::verify_mxcsr_entry()));
 5900     }
 5901   }
 5902   // Clear upper bits of YMM registers to avoid SSE <-> AVX transition penalty.
 5903   vzeroupper();
 5904 
 5905 #ifndef _LP64
 5906   // Either restore the x87 floating pointer control word after returning
 5907   // from the JNI call or verify that it wasn't changed.
 5908   if (CheckJNICalls) {
 5909     call(RuntimeAddress(StubRoutines::x86::verify_fpu_cntrl_wrd_entry()));
 5910   }
 5911 #endif // _LP64
 5912 }
 5913 
 5914 // ((OopHandle)result).resolve();
 5915 void MacroAssembler::resolve_oop_handle(Register result, Register tmp) {
 5916   assert_different_registers(result, tmp);
 5917 
 5918   // Only 64 bit platforms support GCs that require a tmp register
 5919   // Only IN_HEAP loads require a thread_tmp register
 5920   // OopHandle::resolve is an indirection like jobject.
 5921   access_load_at(T_OBJECT, IN_NATIVE,
 5922                  result, Address(result, 0), tmp, /*tmp_thread*/noreg);
 5923 }
 5924 
 5925 // ((WeakHandle)result).resolve();
 5926 void MacroAssembler::resolve_weak_handle(Register rresult, Register rtmp) {
 5927   assert_different_registers(rresult, rtmp);
 5928   Label resolved;
 5929 
 5930   // A null weak handle resolves to null.
 5931   cmpptr(rresult, 0);
 5932   jcc(Assembler::equal, resolved);
 5933 
 5934   // Only 64 bit platforms support GCs that require a tmp register
 5935   // Only IN_HEAP loads require a thread_tmp register
 5936   // WeakHandle::resolve is an indirection like jweak.
 5937   access_load_at(T_OBJECT, IN_NATIVE | ON_PHANTOM_OOP_REF,
 5938                  rresult, Address(rresult, 0), rtmp, /*tmp_thread*/noreg);
 5939   bind(resolved);
 5940 }
 5941 
 5942 void MacroAssembler::load_mirror(Register mirror, Register method, Register tmp) {
 5943   // get mirror
 5944   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
 5945   load_method_holder(mirror, method);
 5946   movptr(mirror, Address(mirror, mirror_offset));
 5947   resolve_oop_handle(mirror, tmp);
 5948 }
 5949 
 5950 void MacroAssembler::load_method_holder_cld(Register rresult, Register rmethod) {
 5951   load_method_holder(rresult, rmethod);
 5952   movptr(rresult, Address(rresult, InstanceKlass::class_loader_data_offset()));
 5953 }
 5954 
 5955 void MacroAssembler::load_method_holder(Register holder, Register method) {
 5956   movptr(holder, Address(method, Method::const_offset()));                      // ConstMethod*
 5957   movptr(holder, Address(holder, ConstMethod::constants_offset()));             // ConstantPool*
 5958   movptr(holder, Address(holder, ConstantPool::pool_holder_offset()));          // InstanceKlass*
 5959 }
 5960 
 5961 #ifdef _LP64
 5962 void MacroAssembler::load_narrow_klass_compact(Register dst, Register src) {
 5963   assert(UseCompactObjectHeaders, "expect compact object headers");
 5964   movl(dst, Address(src, oopDesc::mark_offset_in_bytes()));
 5965   shrl(dst, markWord::klass_shift);
 5966 }
 5967 #endif
 5968 
 5969 void MacroAssembler::load_klass(Register dst, Register src, Register tmp) {
 5970   assert_different_registers(src, tmp);
 5971   assert_different_registers(dst, tmp);
 5972 #ifdef _LP64
 5973   if (UseCompactObjectHeaders) {
 5974     load_narrow_klass_compact(dst, src);
 5975     decode_klass_not_null(dst, tmp);
 5976   } else if (UseCompressedClassPointers) {
 5977     movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
 5978     decode_klass_not_null(dst, tmp);
 5979   } else
 5980 #endif
 5981   {
 5982     movptr(dst, Address(src, oopDesc::klass_offset_in_bytes()));
 5983   }
 5984 }
 5985 
 5986 void MacroAssembler::store_klass(Register dst, Register src, Register tmp) {
 5987   assert(!UseCompactObjectHeaders, "not with compact headers");
 5988   assert_different_registers(src, tmp);
 5989   assert_different_registers(dst, tmp);
 5990 #ifdef _LP64
 5991   if (UseCompressedClassPointers) {
 5992     encode_klass_not_null(src, tmp);
 5993     movl(Address(dst, oopDesc::klass_offset_in_bytes()), src);
 5994   } else
 5995 #endif
 5996     movptr(Address(dst, oopDesc::klass_offset_in_bytes()), src);
 5997 }
 5998 
 5999 void MacroAssembler::cmp_klass(Register klass, Register obj, Register tmp) {
 6000 #ifdef _LP64
 6001   if (UseCompactObjectHeaders) {
 6002     assert(tmp != noreg, "need tmp");
 6003     assert_different_registers(klass, obj, tmp);
 6004     load_narrow_klass_compact(tmp, obj);
 6005     cmpl(klass, tmp);
 6006   } else if (UseCompressedClassPointers) {
 6007     cmpl(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
 6008   } else
 6009 #endif
 6010   {
 6011     cmpptr(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
 6012   }
 6013 }
 6014 
 6015 void MacroAssembler::cmp_klasses_from_objects(Register obj1, Register obj2, Register tmp1, Register tmp2) {
 6016 #ifdef _LP64
 6017   if (UseCompactObjectHeaders) {
 6018     assert(tmp2 != noreg, "need tmp2");
 6019     assert_different_registers(obj1, obj2, tmp1, tmp2);
 6020     load_narrow_klass_compact(tmp1, obj1);
 6021     load_narrow_klass_compact(tmp2, obj2);
 6022     cmpl(tmp1, tmp2);
 6023   } else if (UseCompressedClassPointers) {
 6024     movl(tmp1, Address(obj1, oopDesc::klass_offset_in_bytes()));
 6025     cmpl(tmp1, Address(obj2, oopDesc::klass_offset_in_bytes()));
 6026   } else
 6027 #endif
 6028   {
 6029     movptr(tmp1, Address(obj1, oopDesc::klass_offset_in_bytes()));
 6030     cmpptr(tmp1, Address(obj2, oopDesc::klass_offset_in_bytes()));
 6031   }
 6032 }
 6033 
 6034 void MacroAssembler::access_load_at(BasicType type, DecoratorSet decorators, Register dst, Address src,
 6035                                     Register tmp1, Register thread_tmp) {
 6036   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
 6037   decorators = AccessInternal::decorator_fixup(decorators, type);
 6038   bool as_raw = (decorators & AS_RAW) != 0;
 6039   if (as_raw) {
 6040     bs->BarrierSetAssembler::load_at(this, decorators, type, dst, src, tmp1, thread_tmp);
 6041   } else {
 6042     bs->load_at(this, decorators, type, dst, src, tmp1, thread_tmp);
 6043   }
 6044 }
 6045 
 6046 void MacroAssembler::access_store_at(BasicType type, DecoratorSet decorators, Address dst, Register val,
 6047                                      Register tmp1, Register tmp2, Register tmp3) {
 6048   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
 6049   decorators = AccessInternal::decorator_fixup(decorators, type);
 6050   bool as_raw = (decorators & AS_RAW) != 0;
 6051   if (as_raw) {
 6052     bs->BarrierSetAssembler::store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
 6053   } else {
 6054     bs->store_at(this, decorators, type, dst, val, tmp1, tmp2, tmp3);
 6055   }
 6056 }
 6057 
 6058 void MacroAssembler::load_heap_oop(Register dst, Address src, Register tmp1,
 6059                                    Register thread_tmp, DecoratorSet decorators) {
 6060   access_load_at(T_OBJECT, IN_HEAP | decorators, dst, src, tmp1, thread_tmp);
 6061 }
 6062 
 6063 // Doesn't do verification, generates fixed size code
 6064 void MacroAssembler::load_heap_oop_not_null(Register dst, Address src, Register tmp1,
 6065                                             Register thread_tmp, DecoratorSet decorators) {
 6066   access_load_at(T_OBJECT, IN_HEAP | IS_NOT_NULL | decorators, dst, src, tmp1, thread_tmp);
 6067 }
 6068 
 6069 void MacroAssembler::store_heap_oop(Address dst, Register val, Register tmp1,
 6070                                     Register tmp2, Register tmp3, DecoratorSet decorators) {
 6071   access_store_at(T_OBJECT, IN_HEAP | decorators, dst, val, tmp1, tmp2, tmp3);
 6072 }
 6073 
 6074 // Used for storing nulls.
 6075 void MacroAssembler::store_heap_oop_null(Address dst) {
 6076   access_store_at(T_OBJECT, IN_HEAP, dst, noreg, noreg, noreg, noreg);
 6077 }
 6078 
 6079 #ifdef _LP64
 6080 void MacroAssembler::store_klass_gap(Register dst, Register src) {
 6081   assert(!UseCompactObjectHeaders, "Don't use with compact headers");
 6082   if (UseCompressedClassPointers) {
 6083     // Store to klass gap in destination
 6084     movl(Address(dst, oopDesc::klass_gap_offset_in_bytes()), src);
 6085   }
 6086 }
 6087 
 6088 #ifdef ASSERT
 6089 void MacroAssembler::verify_heapbase(const char* msg) {
 6090   assert (UseCompressedOops, "should be compressed");
 6091   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6092   if (CheckCompressedOops) {
 6093     Label ok;
 6094     ExternalAddress src2(CompressedOops::base_addr());
 6095     const bool is_src2_reachable = reachable(src2);
 6096     if (!is_src2_reachable) {
 6097       push(rscratch1);  // cmpptr trashes rscratch1
 6098     }
 6099     cmpptr(r12_heapbase, src2, rscratch1);
 6100     jcc(Assembler::equal, ok);
 6101     STOP(msg);
 6102     bind(ok);
 6103     if (!is_src2_reachable) {
 6104       pop(rscratch1);
 6105     }
 6106   }
 6107 }
 6108 #endif
 6109 
 6110 // Algorithm must match oop.inline.hpp encode_heap_oop.
 6111 void MacroAssembler::encode_heap_oop(Register r) {
 6112 #ifdef ASSERT
 6113   verify_heapbase("MacroAssembler::encode_heap_oop: heap base corrupted?");
 6114 #endif
 6115   verify_oop_msg(r, "broken oop in encode_heap_oop");
 6116   if (CompressedOops::base() == nullptr) {
 6117     if (CompressedOops::shift() != 0) {
 6118       assert (LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6119       shrq(r, LogMinObjAlignmentInBytes);
 6120     }
 6121     return;
 6122   }
 6123   testq(r, r);
 6124   cmovq(Assembler::equal, r, r12_heapbase);
 6125   subq(r, r12_heapbase);
 6126   shrq(r, LogMinObjAlignmentInBytes);
 6127 }
 6128 
 6129 void MacroAssembler::encode_heap_oop_not_null(Register r) {
 6130 #ifdef ASSERT
 6131   verify_heapbase("MacroAssembler::encode_heap_oop_not_null: heap base corrupted?");
 6132   if (CheckCompressedOops) {
 6133     Label ok;
 6134     testq(r, r);
 6135     jcc(Assembler::notEqual, ok);
 6136     STOP("null oop passed to encode_heap_oop_not_null");
 6137     bind(ok);
 6138   }
 6139 #endif
 6140   verify_oop_msg(r, "broken oop in encode_heap_oop_not_null");
 6141   if (CompressedOops::base() != nullptr) {
 6142     subq(r, r12_heapbase);
 6143   }
 6144   if (CompressedOops::shift() != 0) {
 6145     assert (LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6146     shrq(r, LogMinObjAlignmentInBytes);
 6147   }
 6148 }
 6149 
 6150 void MacroAssembler::encode_heap_oop_not_null(Register dst, Register src) {
 6151 #ifdef ASSERT
 6152   verify_heapbase("MacroAssembler::encode_heap_oop_not_null2: heap base corrupted?");
 6153   if (CheckCompressedOops) {
 6154     Label ok;
 6155     testq(src, src);
 6156     jcc(Assembler::notEqual, ok);
 6157     STOP("null oop passed to encode_heap_oop_not_null2");
 6158     bind(ok);
 6159   }
 6160 #endif
 6161   verify_oop_msg(src, "broken oop in encode_heap_oop_not_null2");
 6162   if (dst != src) {
 6163     movq(dst, src);
 6164   }
 6165   if (CompressedOops::base() != nullptr) {
 6166     subq(dst, r12_heapbase);
 6167   }
 6168   if (CompressedOops::shift() != 0) {
 6169     assert (LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6170     shrq(dst, LogMinObjAlignmentInBytes);
 6171   }
 6172 }
 6173 
 6174 void  MacroAssembler::decode_heap_oop(Register r) {
 6175 #ifdef ASSERT
 6176   verify_heapbase("MacroAssembler::decode_heap_oop: heap base corrupted?");
 6177 #endif
 6178   if (CompressedOops::base() == nullptr) {
 6179     if (CompressedOops::shift() != 0) {
 6180       assert (LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6181       shlq(r, LogMinObjAlignmentInBytes);
 6182     }
 6183   } else {
 6184     Label done;
 6185     shlq(r, LogMinObjAlignmentInBytes);
 6186     jccb(Assembler::equal, done);
 6187     addq(r, r12_heapbase);
 6188     bind(done);
 6189   }
 6190   verify_oop_msg(r, "broken oop in decode_heap_oop");
 6191 }
 6192 
 6193 void  MacroAssembler::decode_heap_oop_not_null(Register r) {
 6194   // Note: it will change flags
 6195   assert (UseCompressedOops, "should only be used for compressed headers");
 6196   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6197   // Cannot assert, unverified entry point counts instructions (see .ad file)
 6198   // vtableStubs also counts instructions in pd_code_size_limit.
 6199   // Also do not verify_oop as this is called by verify_oop.
 6200   if (CompressedOops::shift() != 0) {
 6201     assert(LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6202     shlq(r, LogMinObjAlignmentInBytes);
 6203     if (CompressedOops::base() != nullptr) {
 6204       addq(r, r12_heapbase);
 6205     }
 6206   } else {
 6207     assert (CompressedOops::base() == nullptr, "sanity");
 6208   }
 6209 }
 6210 
 6211 void  MacroAssembler::decode_heap_oop_not_null(Register dst, Register src) {
 6212   // Note: it will change flags
 6213   assert (UseCompressedOops, "should only be used for compressed headers");
 6214   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6215   // Cannot assert, unverified entry point counts instructions (see .ad file)
 6216   // vtableStubs also counts instructions in pd_code_size_limit.
 6217   // Also do not verify_oop as this is called by verify_oop.
 6218   if (CompressedOops::shift() != 0) {
 6219     assert(LogMinObjAlignmentInBytes == CompressedOops::shift(), "decode alg wrong");
 6220     if (LogMinObjAlignmentInBytes == Address::times_8) {
 6221       leaq(dst, Address(r12_heapbase, src, Address::times_8, 0));
 6222     } else {
 6223       if (dst != src) {
 6224         movq(dst, src);
 6225       }
 6226       shlq(dst, LogMinObjAlignmentInBytes);
 6227       if (CompressedOops::base() != nullptr) {
 6228         addq(dst, r12_heapbase);
 6229       }
 6230     }
 6231   } else {
 6232     assert (CompressedOops::base() == nullptr, "sanity");
 6233     if (dst != src) {
 6234       movq(dst, src);
 6235     }
 6236   }
 6237 }
 6238 
 6239 void MacroAssembler::encode_klass_not_null(Register r, Register tmp) {
 6240   assert_different_registers(r, tmp);
 6241   if (CompressedKlassPointers::base() != nullptr) {
 6242     mov64(tmp, (int64_t)CompressedKlassPointers::base());
 6243     subq(r, tmp);
 6244   }
 6245   if (CompressedKlassPointers::shift() != 0) {
 6246     shrq(r, CompressedKlassPointers::shift());
 6247   }
 6248 }
 6249 
 6250 void MacroAssembler::encode_and_move_klass_not_null(Register dst, Register src) {
 6251   assert_different_registers(src, dst);
 6252   if (CompressedKlassPointers::base() != nullptr) {
 6253     mov64(dst, -(int64_t)CompressedKlassPointers::base());
 6254     addq(dst, src);
 6255   } else {
 6256     movptr(dst, src);
 6257   }
 6258   if (CompressedKlassPointers::shift() != 0) {
 6259     shrq(dst, CompressedKlassPointers::shift());
 6260   }
 6261 }
 6262 
 6263 void  MacroAssembler::decode_klass_not_null(Register r, Register tmp) {
 6264   assert_different_registers(r, tmp);
 6265   // Note: it will change flags
 6266   assert(UseCompressedClassPointers, "should only be used for compressed headers");
 6267   // Cannot assert, unverified entry point counts instructions (see .ad file)
 6268   // vtableStubs also counts instructions in pd_code_size_limit.
 6269   // Also do not verify_oop as this is called by verify_oop.
 6270   if (CompressedKlassPointers::shift() != 0) {
 6271     shlq(r, CompressedKlassPointers::shift());
 6272   }
 6273   if (CompressedKlassPointers::base() != nullptr) {
 6274     mov64(tmp, (int64_t)CompressedKlassPointers::base());
 6275     addq(r, tmp);
 6276   }
 6277 }
 6278 
 6279 void  MacroAssembler::decode_and_move_klass_not_null(Register dst, Register src) {
 6280   assert_different_registers(src, dst);
 6281   // Note: it will change flags
 6282   assert (UseCompressedClassPointers, "should only be used for compressed headers");
 6283   // Cannot assert, unverified entry point counts instructions (see .ad file)
 6284   // vtableStubs also counts instructions in pd_code_size_limit.
 6285   // Also do not verify_oop as this is called by verify_oop.
 6286 
 6287   if (CompressedKlassPointers::base() == nullptr &&
 6288       CompressedKlassPointers::shift() == 0) {
 6289     // The best case scenario is that there is no base or shift. Then it is already
 6290     // a pointer that needs nothing but a register rename.
 6291     movl(dst, src);
 6292   } else {
 6293     if (CompressedKlassPointers::shift() <= Address::times_8) {
 6294       if (CompressedKlassPointers::base() != nullptr) {
 6295         mov64(dst, (int64_t)CompressedKlassPointers::base());
 6296       } else {
 6297         xorq(dst, dst);
 6298       }
 6299       if (CompressedKlassPointers::shift() != 0) {
 6300         assert(CompressedKlassPointers::shift() == Address::times_8, "klass not aligned on 64bits?");
 6301         leaq(dst, Address(dst, src, Address::times_8, 0));
 6302       } else {
 6303         addq(dst, src);
 6304       }
 6305     } else {
 6306       if (CompressedKlassPointers::base() != nullptr) {
 6307         const uint64_t base_right_shifted =
 6308             (uint64_t)CompressedKlassPointers::base() >> CompressedKlassPointers::shift();
 6309         mov64(dst, base_right_shifted);
 6310       } else {
 6311         xorq(dst, dst);
 6312       }
 6313       addq(dst, src);
 6314       shlq(dst, CompressedKlassPointers::shift());
 6315     }
 6316   }
 6317 }
 6318 
 6319 void  MacroAssembler::set_narrow_oop(Register dst, jobject obj) {
 6320   assert (UseCompressedOops, "should only be used for compressed headers");
 6321   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6322   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6323   int oop_index = oop_recorder()->find_index(obj);
 6324   RelocationHolder rspec = oop_Relocation::spec(oop_index);
 6325   mov_narrow_oop(dst, oop_index, rspec);
 6326 }
 6327 
 6328 void  MacroAssembler::set_narrow_oop(Address dst, jobject obj) {
 6329   assert (UseCompressedOops, "should only be used for compressed headers");
 6330   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6331   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6332   int oop_index = oop_recorder()->find_index(obj);
 6333   RelocationHolder rspec = oop_Relocation::spec(oop_index);
 6334   mov_narrow_oop(dst, oop_index, rspec);
 6335 }
 6336 
 6337 void  MacroAssembler::set_narrow_klass(Register dst, Klass* k) {
 6338   assert (UseCompressedClassPointers, "should only be used for compressed headers");
 6339   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6340   int klass_index = oop_recorder()->find_index(k);
 6341   RelocationHolder rspec = metadata_Relocation::spec(klass_index);
 6342   mov_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
 6343 }
 6344 
 6345 void  MacroAssembler::set_narrow_klass(Address dst, Klass* k) {
 6346   assert (UseCompressedClassPointers, "should only be used for compressed headers");
 6347   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6348   int klass_index = oop_recorder()->find_index(k);
 6349   RelocationHolder rspec = metadata_Relocation::spec(klass_index);
 6350   mov_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
 6351 }
 6352 
 6353 void  MacroAssembler::cmp_narrow_oop(Register dst, jobject obj) {
 6354   assert (UseCompressedOops, "should only be used for compressed headers");
 6355   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6356   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6357   int oop_index = oop_recorder()->find_index(obj);
 6358   RelocationHolder rspec = oop_Relocation::spec(oop_index);
 6359   Assembler::cmp_narrow_oop(dst, oop_index, rspec);
 6360 }
 6361 
 6362 void  MacroAssembler::cmp_narrow_oop(Address dst, jobject obj) {
 6363   assert (UseCompressedOops, "should only be used for compressed headers");
 6364   assert (Universe::heap() != nullptr, "java heap should be initialized");
 6365   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6366   int oop_index = oop_recorder()->find_index(obj);
 6367   RelocationHolder rspec = oop_Relocation::spec(oop_index);
 6368   Assembler::cmp_narrow_oop(dst, oop_index, rspec);
 6369 }
 6370 
 6371 void  MacroAssembler::cmp_narrow_klass(Register dst, Klass* k) {
 6372   assert (UseCompressedClassPointers, "should only be used for compressed headers");
 6373   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6374   int klass_index = oop_recorder()->find_index(k);
 6375   RelocationHolder rspec = metadata_Relocation::spec(klass_index);
 6376   Assembler::cmp_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
 6377 }
 6378 
 6379 void  MacroAssembler::cmp_narrow_klass(Address dst, Klass* k) {
 6380   assert (UseCompressedClassPointers, "should only be used for compressed headers");
 6381   assert (oop_recorder() != nullptr, "this assembler needs an OopRecorder");
 6382   int klass_index = oop_recorder()->find_index(k);
 6383   RelocationHolder rspec = metadata_Relocation::spec(klass_index);
 6384   Assembler::cmp_narrow_oop(dst, CompressedKlassPointers::encode(k), rspec);
 6385 }
 6386 
 6387 void MacroAssembler::reinit_heapbase() {
 6388   if (UseCompressedOops) {
 6389     if (Universe::heap() != nullptr) {
 6390       if (CompressedOops::base() == nullptr) {
 6391         MacroAssembler::xorptr(r12_heapbase, r12_heapbase);
 6392       } else {
 6393         mov64(r12_heapbase, (int64_t)CompressedOops::base());
 6394       }
 6395     } else {
 6396       movptr(r12_heapbase, ExternalAddress(CompressedOops::base_addr()));
 6397     }
 6398   }
 6399 }
 6400 
 6401 #endif // _LP64
 6402 
 6403 #if COMPILER2_OR_JVMCI
 6404 
 6405 // clear memory of size 'cnt' qwords, starting at 'base' using XMM/YMM/ZMM registers
 6406 void MacroAssembler::xmm_clear_mem(Register base, Register cnt, Register rtmp, XMMRegister xtmp, KRegister mask) {
 6407   // cnt - number of qwords (8-byte words).
 6408   // base - start address, qword aligned.
 6409   Label L_zero_64_bytes, L_loop, L_sloop, L_tail, L_end;
 6410   bool use64byteVector = (MaxVectorSize == 64) && (VM_Version::avx3_threshold() == 0);
 6411   if (use64byteVector) {
 6412     vpxor(xtmp, xtmp, xtmp, AVX_512bit);
 6413   } else if (MaxVectorSize >= 32) {
 6414     vpxor(xtmp, xtmp, xtmp, AVX_256bit);
 6415   } else {
 6416     pxor(xtmp, xtmp);
 6417   }
 6418   jmp(L_zero_64_bytes);
 6419 
 6420   BIND(L_loop);
 6421   if (MaxVectorSize >= 32) {
 6422     fill64(base, 0, xtmp, use64byteVector);
 6423   } else {
 6424     movdqu(Address(base,  0), xtmp);
 6425     movdqu(Address(base, 16), xtmp);
 6426     movdqu(Address(base, 32), xtmp);
 6427     movdqu(Address(base, 48), xtmp);
 6428   }
 6429   addptr(base, 64);
 6430 
 6431   BIND(L_zero_64_bytes);
 6432   subptr(cnt, 8);
 6433   jccb(Assembler::greaterEqual, L_loop);
 6434 
 6435   // Copy trailing 64 bytes
 6436   if (use64byteVector) {
 6437     addptr(cnt, 8);
 6438     jccb(Assembler::equal, L_end);
 6439     fill64_masked(3, base, 0, xtmp, mask, cnt, rtmp, true);
 6440     jmp(L_end);
 6441   } else {
 6442     addptr(cnt, 4);
 6443     jccb(Assembler::less, L_tail);
 6444     if (MaxVectorSize >= 32) {
 6445       vmovdqu(Address(base, 0), xtmp);
 6446     } else {
 6447       movdqu(Address(base,  0), xtmp);
 6448       movdqu(Address(base, 16), xtmp);
 6449     }
 6450   }
 6451   addptr(base, 32);
 6452   subptr(cnt, 4);
 6453 
 6454   BIND(L_tail);
 6455   addptr(cnt, 4);
 6456   jccb(Assembler::lessEqual, L_end);
 6457   if (UseAVX > 2 && MaxVectorSize >= 32 && VM_Version::supports_avx512vl()) {
 6458     fill32_masked(3, base, 0, xtmp, mask, cnt, rtmp);
 6459   } else {
 6460     decrement(cnt);
 6461 
 6462     BIND(L_sloop);
 6463     movq(Address(base, 0), xtmp);
 6464     addptr(base, 8);
 6465     decrement(cnt);
 6466     jccb(Assembler::greaterEqual, L_sloop);
 6467   }
 6468   BIND(L_end);
 6469 }
 6470 
 6471 // Clearing constant sized memory using YMM/ZMM registers.
 6472 void MacroAssembler::clear_mem(Register base, int cnt, Register rtmp, XMMRegister xtmp, KRegister mask) {
 6473   assert(UseAVX > 2 && VM_Version::supports_avx512vl(), "");
 6474   bool use64byteVector = (MaxVectorSize > 32) && (VM_Version::avx3_threshold() == 0);
 6475 
 6476   int vector64_count = (cnt & (~0x7)) >> 3;
 6477   cnt = cnt & 0x7;
 6478   const int fill64_per_loop = 4;
 6479   const int max_unrolled_fill64 = 8;
 6480 
 6481   // 64 byte initialization loop.
 6482   vpxor(xtmp, xtmp, xtmp, use64byteVector ? AVX_512bit : AVX_256bit);
 6483   int start64 = 0;
 6484   if (vector64_count > max_unrolled_fill64) {
 6485     Label LOOP;
 6486     Register index = rtmp;
 6487 
 6488     start64 = vector64_count - (vector64_count % fill64_per_loop);
 6489 
 6490     movl(index, 0);
 6491     BIND(LOOP);
 6492     for (int i = 0; i < fill64_per_loop; i++) {
 6493       fill64(Address(base, index, Address::times_1, i * 64), xtmp, use64byteVector);
 6494     }
 6495     addl(index, fill64_per_loop * 64);
 6496     cmpl(index, start64 * 64);
 6497     jccb(Assembler::less, LOOP);
 6498   }
 6499   for (int i = start64; i < vector64_count; i++) {
 6500     fill64(base, i * 64, xtmp, use64byteVector);
 6501   }
 6502 
 6503   // Clear remaining 64 byte tail.
 6504   int disp = vector64_count * 64;
 6505   if (cnt) {
 6506     switch (cnt) {
 6507       case 1:
 6508         movq(Address(base, disp), xtmp);
 6509         break;
 6510       case 2:
 6511         evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_128bit);
 6512         break;
 6513       case 3:
 6514         movl(rtmp, 0x7);
 6515         kmovwl(mask, rtmp);
 6516         evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_256bit);
 6517         break;
 6518       case 4:
 6519         evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
 6520         break;
 6521       case 5:
 6522         if (use64byteVector) {
 6523           movl(rtmp, 0x1F);
 6524           kmovwl(mask, rtmp);
 6525           evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_512bit);
 6526         } else {
 6527           evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
 6528           movq(Address(base, disp + 32), xtmp);
 6529         }
 6530         break;
 6531       case 6:
 6532         if (use64byteVector) {
 6533           movl(rtmp, 0x3F);
 6534           kmovwl(mask, rtmp);
 6535           evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_512bit);
 6536         } else {
 6537           evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
 6538           evmovdqu(T_LONG, k0, Address(base, disp + 32), xtmp, false, Assembler::AVX_128bit);
 6539         }
 6540         break;
 6541       case 7:
 6542         if (use64byteVector) {
 6543           movl(rtmp, 0x7F);
 6544           kmovwl(mask, rtmp);
 6545           evmovdqu(T_LONG, mask, Address(base, disp), xtmp, true, Assembler::AVX_512bit);
 6546         } else {
 6547           evmovdqu(T_LONG, k0, Address(base, disp), xtmp, false, Assembler::AVX_256bit);
 6548           movl(rtmp, 0x7);
 6549           kmovwl(mask, rtmp);
 6550           evmovdqu(T_LONG, mask, Address(base, disp + 32), xtmp, true, Assembler::AVX_256bit);
 6551         }
 6552         break;
 6553       default:
 6554         fatal("Unexpected length : %d\n",cnt);
 6555         break;
 6556     }
 6557   }
 6558 }
 6559 
 6560 void MacroAssembler::clear_mem(Register base, Register cnt, Register tmp, XMMRegister xtmp,
 6561                                bool is_large, KRegister mask) {
 6562   // cnt      - number of qwords (8-byte words).
 6563   // base     - start address, qword aligned.
 6564   // is_large - if optimizers know cnt is larger than InitArrayShortSize
 6565   assert(base==rdi, "base register must be edi for rep stos");
 6566   assert(tmp==rax,   "tmp register must be eax for rep stos");
 6567   assert(cnt==rcx,   "cnt register must be ecx for rep stos");
 6568   assert(InitArrayShortSize % BytesPerLong == 0,
 6569     "InitArrayShortSize should be the multiple of BytesPerLong");
 6570 
 6571   Label DONE;
 6572   if (!is_large || !UseXMMForObjInit) {
 6573     xorptr(tmp, tmp);
 6574   }
 6575 
 6576   if (!is_large) {
 6577     Label LOOP, LONG;
 6578     cmpptr(cnt, InitArrayShortSize/BytesPerLong);
 6579     jccb(Assembler::greater, LONG);
 6580 
 6581     NOT_LP64(shlptr(cnt, 1);) // convert to number of 32-bit words for 32-bit VM
 6582 
 6583     decrement(cnt);
 6584     jccb(Assembler::negative, DONE); // Zero length
 6585 
 6586     // Use individual pointer-sized stores for small counts:
 6587     BIND(LOOP);
 6588     movptr(Address(base, cnt, Address::times_ptr), tmp);
 6589     decrement(cnt);
 6590     jccb(Assembler::greaterEqual, LOOP);
 6591     jmpb(DONE);
 6592 
 6593     BIND(LONG);
 6594   }
 6595 
 6596   // Use longer rep-prefixed ops for non-small counts:
 6597   if (UseFastStosb) {
 6598     shlptr(cnt, 3); // convert to number of bytes
 6599     rep_stosb();
 6600   } else if (UseXMMForObjInit) {
 6601     xmm_clear_mem(base, cnt, tmp, xtmp, mask);
 6602   } else {
 6603     NOT_LP64(shlptr(cnt, 1);) // convert to number of 32-bit words for 32-bit VM
 6604     rep_stos();
 6605   }
 6606 
 6607   BIND(DONE);
 6608 }
 6609 
 6610 #endif //COMPILER2_OR_JVMCI
 6611 
 6612 
 6613 void MacroAssembler::generate_fill(BasicType t, bool aligned,
 6614                                    Register to, Register value, Register count,
 6615                                    Register rtmp, XMMRegister xtmp) {
 6616   ShortBranchVerifier sbv(this);
 6617   assert_different_registers(to, value, count, rtmp);
 6618   Label L_exit;
 6619   Label L_fill_2_bytes, L_fill_4_bytes;
 6620 
 6621 #if defined(COMPILER2) && defined(_LP64)
 6622   if(MaxVectorSize >=32 &&
 6623      VM_Version::supports_avx512vlbw() &&
 6624      VM_Version::supports_bmi2()) {
 6625     generate_fill_avx3(t, to, value, count, rtmp, xtmp);
 6626     return;
 6627   }
 6628 #endif
 6629 
 6630   int shift = -1;
 6631   switch (t) {
 6632     case T_BYTE:
 6633       shift = 2;
 6634       break;
 6635     case T_SHORT:
 6636       shift = 1;
 6637       break;
 6638     case T_INT:
 6639       shift = 0;
 6640       break;
 6641     default: ShouldNotReachHere();
 6642   }
 6643 
 6644   if (t == T_BYTE) {
 6645     andl(value, 0xff);
 6646     movl(rtmp, value);
 6647     shll(rtmp, 8);
 6648     orl(value, rtmp);
 6649   }
 6650   if (t == T_SHORT) {
 6651     andl(value, 0xffff);
 6652   }
 6653   if (t == T_BYTE || t == T_SHORT) {
 6654     movl(rtmp, value);
 6655     shll(rtmp, 16);
 6656     orl(value, rtmp);
 6657   }
 6658 
 6659   cmpptr(count, 2<<shift); // Short arrays (< 8 bytes) fill by element
 6660   jcc(Assembler::below, L_fill_4_bytes); // use unsigned cmp
 6661   if (!UseUnalignedLoadStores && !aligned && (t == T_BYTE || t == T_SHORT)) {
 6662     Label L_skip_align2;
 6663     // align source address at 4 bytes address boundary
 6664     if (t == T_BYTE) {
 6665       Label L_skip_align1;
 6666       // One byte misalignment happens only for byte arrays
 6667       testptr(to, 1);
 6668       jccb(Assembler::zero, L_skip_align1);
 6669       movb(Address(to, 0), value);
 6670       increment(to);
 6671       decrement(count);
 6672       BIND(L_skip_align1);
 6673     }
 6674     // Two bytes misalignment happens only for byte and short (char) arrays
 6675     testptr(to, 2);
 6676     jccb(Assembler::zero, L_skip_align2);
 6677     movw(Address(to, 0), value);
 6678     addptr(to, 2);
 6679     subptr(count, 1<<(shift-1));
 6680     BIND(L_skip_align2);
 6681   }
 6682   if (UseSSE < 2) {
 6683     Label L_fill_32_bytes_loop, L_check_fill_8_bytes, L_fill_8_bytes_loop, L_fill_8_bytes;
 6684     // Fill 32-byte chunks
 6685     subptr(count, 8 << shift);
 6686     jcc(Assembler::less, L_check_fill_8_bytes);
 6687     align(16);
 6688 
 6689     BIND(L_fill_32_bytes_loop);
 6690 
 6691     for (int i = 0; i < 32; i += 4) {
 6692       movl(Address(to, i), value);
 6693     }
 6694 
 6695     addptr(to, 32);
 6696     subptr(count, 8 << shift);
 6697     jcc(Assembler::greaterEqual, L_fill_32_bytes_loop);
 6698     BIND(L_check_fill_8_bytes);
 6699     addptr(count, 8 << shift);
 6700     jccb(Assembler::zero, L_exit);
 6701     jmpb(L_fill_8_bytes);
 6702 
 6703     //
 6704     // length is too short, just fill qwords
 6705     //
 6706     BIND(L_fill_8_bytes_loop);
 6707     movl(Address(to, 0), value);
 6708     movl(Address(to, 4), value);
 6709     addptr(to, 8);
 6710     BIND(L_fill_8_bytes);
 6711     subptr(count, 1 << (shift + 1));
 6712     jcc(Assembler::greaterEqual, L_fill_8_bytes_loop);
 6713     // fall through to fill 4 bytes
 6714   } else {
 6715     Label L_fill_32_bytes;
 6716     if (!UseUnalignedLoadStores) {
 6717       // align to 8 bytes, we know we are 4 byte aligned to start
 6718       testptr(to, 4);
 6719       jccb(Assembler::zero, L_fill_32_bytes);
 6720       movl(Address(to, 0), value);
 6721       addptr(to, 4);
 6722       subptr(count, 1<<shift);
 6723     }
 6724     BIND(L_fill_32_bytes);
 6725     {
 6726       assert( UseSSE >= 2, "supported cpu only" );
 6727       Label L_fill_32_bytes_loop, L_check_fill_8_bytes, L_fill_8_bytes_loop, L_fill_8_bytes;
 6728       movdl(xtmp, value);
 6729       if (UseAVX >= 2 && UseUnalignedLoadStores) {
 6730         Label L_check_fill_32_bytes;
 6731         if (UseAVX > 2) {
 6732           // Fill 64-byte chunks
 6733           Label L_fill_64_bytes_loop_avx3, L_check_fill_64_bytes_avx2;
 6734 
 6735           // If number of bytes to fill < VM_Version::avx3_threshold(), perform fill using AVX2
 6736           cmpptr(count, VM_Version::avx3_threshold());
 6737           jccb(Assembler::below, L_check_fill_64_bytes_avx2);
 6738 
 6739           vpbroadcastd(xtmp, xtmp, Assembler::AVX_512bit);
 6740 
 6741           subptr(count, 16 << shift);
 6742           jccb(Assembler::less, L_check_fill_32_bytes);
 6743           align(16);
 6744 
 6745           BIND(L_fill_64_bytes_loop_avx3);
 6746           evmovdqul(Address(to, 0), xtmp, Assembler::AVX_512bit);
 6747           addptr(to, 64);
 6748           subptr(count, 16 << shift);
 6749           jcc(Assembler::greaterEqual, L_fill_64_bytes_loop_avx3);
 6750           jmpb(L_check_fill_32_bytes);
 6751 
 6752           BIND(L_check_fill_64_bytes_avx2);
 6753         }
 6754         // Fill 64-byte chunks
 6755         Label L_fill_64_bytes_loop;
 6756         vpbroadcastd(xtmp, xtmp, Assembler::AVX_256bit);
 6757 
 6758         subptr(count, 16 << shift);
 6759         jcc(Assembler::less, L_check_fill_32_bytes);
 6760         align(16);
 6761 
 6762         BIND(L_fill_64_bytes_loop);
 6763         vmovdqu(Address(to, 0), xtmp);
 6764         vmovdqu(Address(to, 32), xtmp);
 6765         addptr(to, 64);
 6766         subptr(count, 16 << shift);
 6767         jcc(Assembler::greaterEqual, L_fill_64_bytes_loop);
 6768 
 6769         BIND(L_check_fill_32_bytes);
 6770         addptr(count, 8 << shift);
 6771         jccb(Assembler::less, L_check_fill_8_bytes);
 6772         vmovdqu(Address(to, 0), xtmp);
 6773         addptr(to, 32);
 6774         subptr(count, 8 << shift);
 6775 
 6776         BIND(L_check_fill_8_bytes);
 6777         // clean upper bits of YMM registers
 6778         movdl(xtmp, value);
 6779         pshufd(xtmp, xtmp, 0);
 6780       } else {
 6781         // Fill 32-byte chunks
 6782         pshufd(xtmp, xtmp, 0);
 6783 
 6784         subptr(count, 8 << shift);
 6785         jcc(Assembler::less, L_check_fill_8_bytes);
 6786         align(16);
 6787 
 6788         BIND(L_fill_32_bytes_loop);
 6789 
 6790         if (UseUnalignedLoadStores) {
 6791           movdqu(Address(to, 0), xtmp);
 6792           movdqu(Address(to, 16), xtmp);
 6793         } else {
 6794           movq(Address(to, 0), xtmp);
 6795           movq(Address(to, 8), xtmp);
 6796           movq(Address(to, 16), xtmp);
 6797           movq(Address(to, 24), xtmp);
 6798         }
 6799 
 6800         addptr(to, 32);
 6801         subptr(count, 8 << shift);
 6802         jcc(Assembler::greaterEqual, L_fill_32_bytes_loop);
 6803 
 6804         BIND(L_check_fill_8_bytes);
 6805       }
 6806       addptr(count, 8 << shift);
 6807       jccb(Assembler::zero, L_exit);
 6808       jmpb(L_fill_8_bytes);
 6809 
 6810       //
 6811       // length is too short, just fill qwords
 6812       //
 6813       BIND(L_fill_8_bytes_loop);
 6814       movq(Address(to, 0), xtmp);
 6815       addptr(to, 8);
 6816       BIND(L_fill_8_bytes);
 6817       subptr(count, 1 << (shift + 1));
 6818       jcc(Assembler::greaterEqual, L_fill_8_bytes_loop);
 6819     }
 6820   }
 6821   // fill trailing 4 bytes
 6822   BIND(L_fill_4_bytes);
 6823   testl(count, 1<<shift);
 6824   jccb(Assembler::zero, L_fill_2_bytes);
 6825   movl(Address(to, 0), value);
 6826   if (t == T_BYTE || t == T_SHORT) {
 6827     Label L_fill_byte;
 6828     addptr(to, 4);
 6829     BIND(L_fill_2_bytes);
 6830     // fill trailing 2 bytes
 6831     testl(count, 1<<(shift-1));
 6832     jccb(Assembler::zero, L_fill_byte);
 6833     movw(Address(to, 0), value);
 6834     if (t == T_BYTE) {
 6835       addptr(to, 2);
 6836       BIND(L_fill_byte);
 6837       // fill trailing byte
 6838       testl(count, 1);
 6839       jccb(Assembler::zero, L_exit);
 6840       movb(Address(to, 0), value);
 6841     } else {
 6842       BIND(L_fill_byte);
 6843     }
 6844   } else {
 6845     BIND(L_fill_2_bytes);
 6846   }
 6847   BIND(L_exit);
 6848 }
 6849 
 6850 void MacroAssembler::evpbroadcast(BasicType type, XMMRegister dst, Register src, int vector_len) {
 6851   switch(type) {
 6852     case T_BYTE:
 6853     case T_BOOLEAN:
 6854       evpbroadcastb(dst, src, vector_len);
 6855       break;
 6856     case T_SHORT:
 6857     case T_CHAR:
 6858       evpbroadcastw(dst, src, vector_len);
 6859       break;
 6860     case T_INT:
 6861     case T_FLOAT:
 6862       evpbroadcastd(dst, src, vector_len);
 6863       break;
 6864     case T_LONG:
 6865     case T_DOUBLE:
 6866       evpbroadcastq(dst, src, vector_len);
 6867       break;
 6868     default:
 6869       fatal("Unhandled type : %s", type2name(type));
 6870       break;
 6871   }
 6872 }
 6873 
 6874 // encode char[] to byte[] in ISO_8859_1 or ASCII
 6875    //@IntrinsicCandidate
 6876    //private static int implEncodeISOArray(byte[] sa, int sp,
 6877    //byte[] da, int dp, int len) {
 6878    //  int i = 0;
 6879    //  for (; i < len; i++) {
 6880    //    char c = StringUTF16.getChar(sa, sp++);
 6881    //    if (c > '\u00FF')
 6882    //      break;
 6883    //    da[dp++] = (byte)c;
 6884    //  }
 6885    //  return i;
 6886    //}
 6887    //
 6888    //@IntrinsicCandidate
 6889    //private static int implEncodeAsciiArray(char[] sa, int sp,
 6890    //    byte[] da, int dp, int len) {
 6891    //  int i = 0;
 6892    //  for (; i < len; i++) {
 6893    //    char c = sa[sp++];
 6894    //    if (c >= '\u0080')
 6895    //      break;
 6896    //    da[dp++] = (byte)c;
 6897    //  }
 6898    //  return i;
 6899    //}
 6900 void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
 6901   XMMRegister tmp1Reg, XMMRegister tmp2Reg,
 6902   XMMRegister tmp3Reg, XMMRegister tmp4Reg,
 6903   Register tmp5, Register result, bool ascii) {
 6904 
 6905   // rsi: src
 6906   // rdi: dst
 6907   // rdx: len
 6908   // rcx: tmp5
 6909   // rax: result
 6910   ShortBranchVerifier sbv(this);
 6911   assert_different_registers(src, dst, len, tmp5, result);
 6912   Label L_done, L_copy_1_char, L_copy_1_char_exit;
 6913 
 6914   int mask = ascii ? 0xff80ff80 : 0xff00ff00;
 6915   int short_mask = ascii ? 0xff80 : 0xff00;
 6916 
 6917   // set result
 6918   xorl(result, result);
 6919   // check for zero length
 6920   testl(len, len);
 6921   jcc(Assembler::zero, L_done);
 6922 
 6923   movl(result, len);
 6924 
 6925   // Setup pointers
 6926   lea(src, Address(src, len, Address::times_2)); // char[]
 6927   lea(dst, Address(dst, len, Address::times_1)); // byte[]
 6928   negptr(len);
 6929 
 6930   if (UseSSE42Intrinsics || UseAVX >= 2) {
 6931     Label L_copy_8_chars, L_copy_8_chars_exit;
 6932     Label L_chars_16_check, L_copy_16_chars, L_copy_16_chars_exit;
 6933 
 6934     if (UseAVX >= 2) {
 6935       Label L_chars_32_check, L_copy_32_chars, L_copy_32_chars_exit;
 6936       movl(tmp5, mask);   // create mask to test for Unicode or non-ASCII chars in vector
 6937       movdl(tmp1Reg, tmp5);
 6938       vpbroadcastd(tmp1Reg, tmp1Reg, Assembler::AVX_256bit);
 6939       jmp(L_chars_32_check);
 6940 
 6941       bind(L_copy_32_chars);
 6942       vmovdqu(tmp3Reg, Address(src, len, Address::times_2, -64));
 6943       vmovdqu(tmp4Reg, Address(src, len, Address::times_2, -32));
 6944       vpor(tmp2Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
 6945       vptest(tmp2Reg, tmp1Reg);       // check for Unicode or non-ASCII chars in vector
 6946       jccb(Assembler::notZero, L_copy_32_chars_exit);
 6947       vpackuswb(tmp3Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
 6948       vpermq(tmp4Reg, tmp3Reg, 0xD8, /* vector_len */ 1);
 6949       vmovdqu(Address(dst, len, Address::times_1, -32), tmp4Reg);
 6950 
 6951       bind(L_chars_32_check);
 6952       addptr(len, 32);
 6953       jcc(Assembler::lessEqual, L_copy_32_chars);
 6954 
 6955       bind(L_copy_32_chars_exit);
 6956       subptr(len, 16);
 6957       jccb(Assembler::greater, L_copy_16_chars_exit);
 6958 
 6959     } else if (UseSSE42Intrinsics) {
 6960       movl(tmp5, mask);   // create mask to test for Unicode or non-ASCII chars in vector
 6961       movdl(tmp1Reg, tmp5);
 6962       pshufd(tmp1Reg, tmp1Reg, 0);
 6963       jmpb(L_chars_16_check);
 6964     }
 6965 
 6966     bind(L_copy_16_chars);
 6967     if (UseAVX >= 2) {
 6968       vmovdqu(tmp2Reg, Address(src, len, Address::times_2, -32));
 6969       vptest(tmp2Reg, tmp1Reg);
 6970       jcc(Assembler::notZero, L_copy_16_chars_exit);
 6971       vpackuswb(tmp2Reg, tmp2Reg, tmp1Reg, /* vector_len */ 1);
 6972       vpermq(tmp3Reg, tmp2Reg, 0xD8, /* vector_len */ 1);
 6973     } else {
 6974       if (UseAVX > 0) {
 6975         movdqu(tmp3Reg, Address(src, len, Address::times_2, -32));
 6976         movdqu(tmp4Reg, Address(src, len, Address::times_2, -16));
 6977         vpor(tmp2Reg, tmp3Reg, tmp4Reg, /* vector_len */ 0);
 6978       } else {
 6979         movdqu(tmp3Reg, Address(src, len, Address::times_2, -32));
 6980         por(tmp2Reg, tmp3Reg);
 6981         movdqu(tmp4Reg, Address(src, len, Address::times_2, -16));
 6982         por(tmp2Reg, tmp4Reg);
 6983       }
 6984       ptest(tmp2Reg, tmp1Reg);       // check for Unicode or non-ASCII chars in vector
 6985       jccb(Assembler::notZero, L_copy_16_chars_exit);
 6986       packuswb(tmp3Reg, tmp4Reg);
 6987     }
 6988     movdqu(Address(dst, len, Address::times_1, -16), tmp3Reg);
 6989 
 6990     bind(L_chars_16_check);
 6991     addptr(len, 16);
 6992     jcc(Assembler::lessEqual, L_copy_16_chars);
 6993 
 6994     bind(L_copy_16_chars_exit);
 6995     if (UseAVX >= 2) {
 6996       // clean upper bits of YMM registers
 6997       vpxor(tmp2Reg, tmp2Reg);
 6998       vpxor(tmp3Reg, tmp3Reg);
 6999       vpxor(tmp4Reg, tmp4Reg);
 7000       movdl(tmp1Reg, tmp5);
 7001       pshufd(tmp1Reg, tmp1Reg, 0);
 7002     }
 7003     subptr(len, 8);
 7004     jccb(Assembler::greater, L_copy_8_chars_exit);
 7005 
 7006     bind(L_copy_8_chars);
 7007     movdqu(tmp3Reg, Address(src, len, Address::times_2, -16));
 7008     ptest(tmp3Reg, tmp1Reg);
 7009     jccb(Assembler::notZero, L_copy_8_chars_exit);
 7010     packuswb(tmp3Reg, tmp1Reg);
 7011     movq(Address(dst, len, Address::times_1, -8), tmp3Reg);
 7012     addptr(len, 8);
 7013     jccb(Assembler::lessEqual, L_copy_8_chars);
 7014 
 7015     bind(L_copy_8_chars_exit);
 7016     subptr(len, 8);
 7017     jccb(Assembler::zero, L_done);
 7018   }
 7019 
 7020   bind(L_copy_1_char);
 7021   load_unsigned_short(tmp5, Address(src, len, Address::times_2, 0));
 7022   testl(tmp5, short_mask);      // check if Unicode or non-ASCII char
 7023   jccb(Assembler::notZero, L_copy_1_char_exit);
 7024   movb(Address(dst, len, Address::times_1, 0), tmp5);
 7025   addptr(len, 1);
 7026   jccb(Assembler::less, L_copy_1_char);
 7027 
 7028   bind(L_copy_1_char_exit);
 7029   addptr(result, len); // len is negative count of not processed elements
 7030 
 7031   bind(L_done);
 7032 }
 7033 
 7034 #ifdef _LP64
 7035 /**
 7036  * Helper for multiply_to_len().
 7037  */
 7038 void MacroAssembler::add2_with_carry(Register dest_hi, Register dest_lo, Register src1, Register src2) {
 7039   addq(dest_lo, src1);
 7040   adcq(dest_hi, 0);
 7041   addq(dest_lo, src2);
 7042   adcq(dest_hi, 0);
 7043 }
 7044 
 7045 /**
 7046  * Multiply 64 bit by 64 bit first loop.
 7047  */
 7048 void MacroAssembler::multiply_64_x_64_loop(Register x, Register xstart, Register x_xstart,
 7049                                            Register y, Register y_idx, Register z,
 7050                                            Register carry, Register product,
 7051                                            Register idx, Register kdx) {
 7052   //
 7053   //  jlong carry, x[], y[], z[];
 7054   //  for (int idx=ystart, kdx=ystart+1+xstart; idx >= 0; idx-, kdx--) {
 7055   //    huge_128 product = y[idx] * x[xstart] + carry;
 7056   //    z[kdx] = (jlong)product;
 7057   //    carry  = (jlong)(product >>> 64);
 7058   //  }
 7059   //  z[xstart] = carry;
 7060   //
 7061 
 7062   Label L_first_loop, L_first_loop_exit;
 7063   Label L_one_x, L_one_y, L_multiply;
 7064 
 7065   decrementl(xstart);
 7066   jcc(Assembler::negative, L_one_x);
 7067 
 7068   movq(x_xstart, Address(x, xstart, Address::times_4,  0));
 7069   rorq(x_xstart, 32); // convert big-endian to little-endian
 7070 
 7071   bind(L_first_loop);
 7072   decrementl(idx);
 7073   jcc(Assembler::negative, L_first_loop_exit);
 7074   decrementl(idx);
 7075   jcc(Assembler::negative, L_one_y);
 7076   movq(y_idx, Address(y, idx, Address::times_4,  0));
 7077   rorq(y_idx, 32); // convert big-endian to little-endian
 7078   bind(L_multiply);
 7079   movq(product, x_xstart);
 7080   mulq(y_idx); // product(rax) * y_idx -> rdx:rax
 7081   addq(product, carry);
 7082   adcq(rdx, 0);
 7083   subl(kdx, 2);
 7084   movl(Address(z, kdx, Address::times_4,  4), product);
 7085   shrq(product, 32);
 7086   movl(Address(z, kdx, Address::times_4,  0), product);
 7087   movq(carry, rdx);
 7088   jmp(L_first_loop);
 7089 
 7090   bind(L_one_y);
 7091   movl(y_idx, Address(y,  0));
 7092   jmp(L_multiply);
 7093 
 7094   bind(L_one_x);
 7095   movl(x_xstart, Address(x,  0));
 7096   jmp(L_first_loop);
 7097 
 7098   bind(L_first_loop_exit);
 7099 }
 7100 
 7101 /**
 7102  * Multiply 64 bit by 64 bit and add 128 bit.
 7103  */
 7104 void MacroAssembler::multiply_add_128_x_128(Register x_xstart, Register y, Register z,
 7105                                             Register yz_idx, Register idx,
 7106                                             Register carry, Register product, int offset) {
 7107   //     huge_128 product = (y[idx] * x_xstart) + z[kdx] + carry;
 7108   //     z[kdx] = (jlong)product;
 7109 
 7110   movq(yz_idx, Address(y, idx, Address::times_4,  offset));
 7111   rorq(yz_idx, 32); // convert big-endian to little-endian
 7112   movq(product, x_xstart);
 7113   mulq(yz_idx);     // product(rax) * yz_idx -> rdx:product(rax)
 7114   movq(yz_idx, Address(z, idx, Address::times_4,  offset));
 7115   rorq(yz_idx, 32); // convert big-endian to little-endian
 7116 
 7117   add2_with_carry(rdx, product, carry, yz_idx);
 7118 
 7119   movl(Address(z, idx, Address::times_4,  offset+4), product);
 7120   shrq(product, 32);
 7121   movl(Address(z, idx, Address::times_4,  offset), product);
 7122 
 7123 }
 7124 
 7125 /**
 7126  * Multiply 128 bit by 128 bit. Unrolled inner loop.
 7127  */
 7128 void MacroAssembler::multiply_128_x_128_loop(Register x_xstart, Register y, Register z,
 7129                                              Register yz_idx, Register idx, Register jdx,
 7130                                              Register carry, Register product,
 7131                                              Register carry2) {
 7132   //   jlong carry, x[], y[], z[];
 7133   //   int kdx = ystart+1;
 7134   //   for (int idx=ystart-2; idx >= 0; idx -= 2) { // Third loop
 7135   //     huge_128 product = (y[idx+1] * x_xstart) + z[kdx+idx+1] + carry;
 7136   //     z[kdx+idx+1] = (jlong)product;
 7137   //     jlong carry2  = (jlong)(product >>> 64);
 7138   //     product = (y[idx] * x_xstart) + z[kdx+idx] + carry2;
 7139   //     z[kdx+idx] = (jlong)product;
 7140   //     carry  = (jlong)(product >>> 64);
 7141   //   }
 7142   //   idx += 2;
 7143   //   if (idx > 0) {
 7144   //     product = (y[idx] * x_xstart) + z[kdx+idx] + carry;
 7145   //     z[kdx+idx] = (jlong)product;
 7146   //     carry  = (jlong)(product >>> 64);
 7147   //   }
 7148   //
 7149 
 7150   Label L_third_loop, L_third_loop_exit, L_post_third_loop_done;
 7151 
 7152   movl(jdx, idx);
 7153   andl(jdx, 0xFFFFFFFC);
 7154   shrl(jdx, 2);
 7155 
 7156   bind(L_third_loop);
 7157   subl(jdx, 1);
 7158   jcc(Assembler::negative, L_third_loop_exit);
 7159   subl(idx, 4);
 7160 
 7161   multiply_add_128_x_128(x_xstart, y, z, yz_idx, idx, carry, product, 8);
 7162   movq(carry2, rdx);
 7163 
 7164   multiply_add_128_x_128(x_xstart, y, z, yz_idx, idx, carry2, product, 0);
 7165   movq(carry, rdx);
 7166   jmp(L_third_loop);
 7167 
 7168   bind (L_third_loop_exit);
 7169 
 7170   andl (idx, 0x3);
 7171   jcc(Assembler::zero, L_post_third_loop_done);
 7172 
 7173   Label L_check_1;
 7174   subl(idx, 2);
 7175   jcc(Assembler::negative, L_check_1);
 7176 
 7177   multiply_add_128_x_128(x_xstart, y, z, yz_idx, idx, carry, product, 0);
 7178   movq(carry, rdx);
 7179 
 7180   bind (L_check_1);
 7181   addl (idx, 0x2);
 7182   andl (idx, 0x1);
 7183   subl(idx, 1);
 7184   jcc(Assembler::negative, L_post_third_loop_done);
 7185 
 7186   movl(yz_idx, Address(y, idx, Address::times_4,  0));
 7187   movq(product, x_xstart);
 7188   mulq(yz_idx); // product(rax) * yz_idx -> rdx:product(rax)
 7189   movl(yz_idx, Address(z, idx, Address::times_4,  0));
 7190 
 7191   add2_with_carry(rdx, product, yz_idx, carry);
 7192 
 7193   movl(Address(z, idx, Address::times_4,  0), product);
 7194   shrq(product, 32);
 7195 
 7196   shlq(rdx, 32);
 7197   orq(product, rdx);
 7198   movq(carry, product);
 7199 
 7200   bind(L_post_third_loop_done);
 7201 }
 7202 
 7203 /**
 7204  * Multiply 128 bit by 128 bit using BMI2. Unrolled inner loop.
 7205  *
 7206  */
 7207 void MacroAssembler::multiply_128_x_128_bmi2_loop(Register y, Register z,
 7208                                                   Register carry, Register carry2,
 7209                                                   Register idx, Register jdx,
 7210                                                   Register yz_idx1, Register yz_idx2,
 7211                                                   Register tmp, Register tmp3, Register tmp4) {
 7212   assert(UseBMI2Instructions, "should be used only when BMI2 is available");
 7213 
 7214   //   jlong carry, x[], y[], z[];
 7215   //   int kdx = ystart+1;
 7216   //   for (int idx=ystart-2; idx >= 0; idx -= 2) { // Third loop
 7217   //     huge_128 tmp3 = (y[idx+1] * rdx) + z[kdx+idx+1] + carry;
 7218   //     jlong carry2  = (jlong)(tmp3 >>> 64);
 7219   //     huge_128 tmp4 = (y[idx]   * rdx) + z[kdx+idx] + carry2;
 7220   //     carry  = (jlong)(tmp4 >>> 64);
 7221   //     z[kdx+idx+1] = (jlong)tmp3;
 7222   //     z[kdx+idx] = (jlong)tmp4;
 7223   //   }
 7224   //   idx += 2;
 7225   //   if (idx > 0) {
 7226   //     yz_idx1 = (y[idx] * rdx) + z[kdx+idx] + carry;
 7227   //     z[kdx+idx] = (jlong)yz_idx1;
 7228   //     carry  = (jlong)(yz_idx1 >>> 64);
 7229   //   }
 7230   //
 7231 
 7232   Label L_third_loop, L_third_loop_exit, L_post_third_loop_done;
 7233 
 7234   movl(jdx, idx);
 7235   andl(jdx, 0xFFFFFFFC);
 7236   shrl(jdx, 2);
 7237 
 7238   bind(L_third_loop);
 7239   subl(jdx, 1);
 7240   jcc(Assembler::negative, L_third_loop_exit);
 7241   subl(idx, 4);
 7242 
 7243   movq(yz_idx1,  Address(y, idx, Address::times_4,  8));
 7244   rorxq(yz_idx1, yz_idx1, 32); // convert big-endian to little-endian
 7245   movq(yz_idx2, Address(y, idx, Address::times_4,  0));
 7246   rorxq(yz_idx2, yz_idx2, 32);
 7247 
 7248   mulxq(tmp4, tmp3, yz_idx1);  //  yz_idx1 * rdx -> tmp4:tmp3
 7249   mulxq(carry2, tmp, yz_idx2); //  yz_idx2 * rdx -> carry2:tmp
 7250 
 7251   movq(yz_idx1,  Address(z, idx, Address::times_4,  8));
 7252   rorxq(yz_idx1, yz_idx1, 32);
 7253   movq(yz_idx2, Address(z, idx, Address::times_4,  0));
 7254   rorxq(yz_idx2, yz_idx2, 32);
 7255 
 7256   if (VM_Version::supports_adx()) {
 7257     adcxq(tmp3, carry);
 7258     adoxq(tmp3, yz_idx1);
 7259 
 7260     adcxq(tmp4, tmp);
 7261     adoxq(tmp4, yz_idx2);
 7262 
 7263     movl(carry, 0); // does not affect flags
 7264     adcxq(carry2, carry);
 7265     adoxq(carry2, carry);
 7266   } else {
 7267     add2_with_carry(tmp4, tmp3, carry, yz_idx1);
 7268     add2_with_carry(carry2, tmp4, tmp, yz_idx2);
 7269   }
 7270   movq(carry, carry2);
 7271 
 7272   movl(Address(z, idx, Address::times_4, 12), tmp3);
 7273   shrq(tmp3, 32);
 7274   movl(Address(z, idx, Address::times_4,  8), tmp3);
 7275 
 7276   movl(Address(z, idx, Address::times_4,  4), tmp4);
 7277   shrq(tmp4, 32);
 7278   movl(Address(z, idx, Address::times_4,  0), tmp4);
 7279 
 7280   jmp(L_third_loop);
 7281 
 7282   bind (L_third_loop_exit);
 7283 
 7284   andl (idx, 0x3);
 7285   jcc(Assembler::zero, L_post_third_loop_done);
 7286 
 7287   Label L_check_1;
 7288   subl(idx, 2);
 7289   jcc(Assembler::negative, L_check_1);
 7290 
 7291   movq(yz_idx1, Address(y, idx, Address::times_4,  0));
 7292   rorxq(yz_idx1, yz_idx1, 32);
 7293   mulxq(tmp4, tmp3, yz_idx1); //  yz_idx1 * rdx -> tmp4:tmp3
 7294   movq(yz_idx2, Address(z, idx, Address::times_4,  0));
 7295   rorxq(yz_idx2, yz_idx2, 32);
 7296 
 7297   add2_with_carry(tmp4, tmp3, carry, yz_idx2);
 7298 
 7299   movl(Address(z, idx, Address::times_4,  4), tmp3);
 7300   shrq(tmp3, 32);
 7301   movl(Address(z, idx, Address::times_4,  0), tmp3);
 7302   movq(carry, tmp4);
 7303 
 7304   bind (L_check_1);
 7305   addl (idx, 0x2);
 7306   andl (idx, 0x1);
 7307   subl(idx, 1);
 7308   jcc(Assembler::negative, L_post_third_loop_done);
 7309   movl(tmp4, Address(y, idx, Address::times_4,  0));
 7310   mulxq(carry2, tmp3, tmp4);  //  tmp4 * rdx -> carry2:tmp3
 7311   movl(tmp4, Address(z, idx, Address::times_4,  0));
 7312 
 7313   add2_with_carry(carry2, tmp3, tmp4, carry);
 7314 
 7315   movl(Address(z, idx, Address::times_4,  0), tmp3);
 7316   shrq(tmp3, 32);
 7317 
 7318   shlq(carry2, 32);
 7319   orq(tmp3, carry2);
 7320   movq(carry, tmp3);
 7321 
 7322   bind(L_post_third_loop_done);
 7323 }
 7324 
 7325 /**
 7326  * Code for BigInteger::multiplyToLen() intrinsic.
 7327  *
 7328  * rdi: x
 7329  * rax: xlen
 7330  * rsi: y
 7331  * rcx: ylen
 7332  * r8:  z
 7333  * r11: tmp0
 7334  * r12: tmp1
 7335  * r13: tmp2
 7336  * r14: tmp3
 7337  * r15: tmp4
 7338  * rbx: tmp5
 7339  *
 7340  */
 7341 void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Register ylen, Register z, Register tmp0,
 7342                                      Register tmp1, Register tmp2, Register tmp3, Register tmp4, Register tmp5) {
 7343   ShortBranchVerifier sbv(this);
 7344   assert_different_registers(x, xlen, y, ylen, z, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, rdx);
 7345 
 7346   push(tmp0);
 7347   push(tmp1);
 7348   push(tmp2);
 7349   push(tmp3);
 7350   push(tmp4);
 7351   push(tmp5);
 7352 
 7353   push(xlen);
 7354 
 7355   const Register idx = tmp1;
 7356   const Register kdx = tmp2;
 7357   const Register xstart = tmp3;
 7358 
 7359   const Register y_idx = tmp4;
 7360   const Register carry = tmp5;
 7361   const Register product  = xlen;
 7362   const Register x_xstart = tmp0;
 7363 
 7364   // First Loop.
 7365   //
 7366   //  final static long LONG_MASK = 0xffffffffL;
 7367   //  int xstart = xlen - 1;
 7368   //  int ystart = ylen - 1;
 7369   //  long carry = 0;
 7370   //  for (int idx=ystart, kdx=ystart+1+xstart; idx >= 0; idx-, kdx--) {
 7371   //    long product = (y[idx] & LONG_MASK) * (x[xstart] & LONG_MASK) + carry;
 7372   //    z[kdx] = (int)product;
 7373   //    carry = product >>> 32;
 7374   //  }
 7375   //  z[xstart] = (int)carry;
 7376   //
 7377 
 7378   movl(idx, ylen);               // idx = ylen;
 7379   lea(kdx, Address(xlen, ylen)); // kdx = xlen+ylen;
 7380   xorq(carry, carry);            // carry = 0;
 7381 
 7382   Label L_done;
 7383 
 7384   movl(xstart, xlen);
 7385   decrementl(xstart);
 7386   jcc(Assembler::negative, L_done);
 7387 
 7388   multiply_64_x_64_loop(x, xstart, x_xstart, y, y_idx, z, carry, product, idx, kdx);
 7389 
 7390   Label L_second_loop;
 7391   testl(kdx, kdx);
 7392   jcc(Assembler::zero, L_second_loop);
 7393 
 7394   Label L_carry;
 7395   subl(kdx, 1);
 7396   jcc(Assembler::zero, L_carry);
 7397 
 7398   movl(Address(z, kdx, Address::times_4,  0), carry);
 7399   shrq(carry, 32);
 7400   subl(kdx, 1);
 7401 
 7402   bind(L_carry);
 7403   movl(Address(z, kdx, Address::times_4,  0), carry);
 7404 
 7405   // Second and third (nested) loops.
 7406   //
 7407   // for (int i = xstart-1; i >= 0; i--) { // Second loop
 7408   //   carry = 0;
 7409   //   for (int jdx=ystart, k=ystart+1+i; jdx >= 0; jdx--, k--) { // Third loop
 7410   //     long product = (y[jdx] & LONG_MASK) * (x[i] & LONG_MASK) +
 7411   //                    (z[k] & LONG_MASK) + carry;
 7412   //     z[k] = (int)product;
 7413   //     carry = product >>> 32;
 7414   //   }
 7415   //   z[i] = (int)carry;
 7416   // }
 7417   //
 7418   // i = xlen, j = tmp1, k = tmp2, carry = tmp5, x[i] = rdx
 7419 
 7420   const Register jdx = tmp1;
 7421 
 7422   bind(L_second_loop);
 7423   xorl(carry, carry);    // carry = 0;
 7424   movl(jdx, ylen);       // j = ystart+1
 7425 
 7426   subl(xstart, 1);       // i = xstart-1;
 7427   jcc(Assembler::negative, L_done);
 7428 
 7429   push (z);
 7430 
 7431   Label L_last_x;
 7432   lea(z, Address(z, xstart, Address::times_4, 4)); // z = z + k - j
 7433   subl(xstart, 1);       // i = xstart-1;
 7434   jcc(Assembler::negative, L_last_x);
 7435 
 7436   if (UseBMI2Instructions) {
 7437     movq(rdx,  Address(x, xstart, Address::times_4,  0));
 7438     rorxq(rdx, rdx, 32); // convert big-endian to little-endian
 7439   } else {
 7440     movq(x_xstart, Address(x, xstart, Address::times_4,  0));
 7441     rorq(x_xstart, 32);  // convert big-endian to little-endian
 7442   }
 7443 
 7444   Label L_third_loop_prologue;
 7445   bind(L_third_loop_prologue);
 7446 
 7447   push (x);
 7448   push (xstart);
 7449   push (ylen);
 7450 
 7451 
 7452   if (UseBMI2Instructions) {
 7453     multiply_128_x_128_bmi2_loop(y, z, carry, x, jdx, ylen, product, tmp2, x_xstart, tmp3, tmp4);
 7454   } else { // !UseBMI2Instructions
 7455     multiply_128_x_128_loop(x_xstart, y, z, y_idx, jdx, ylen, carry, product, x);
 7456   }
 7457 
 7458   pop(ylen);
 7459   pop(xlen);
 7460   pop(x);
 7461   pop(z);
 7462 
 7463   movl(tmp3, xlen);
 7464   addl(tmp3, 1);
 7465   movl(Address(z, tmp3, Address::times_4,  0), carry);
 7466   subl(tmp3, 1);
 7467   jccb(Assembler::negative, L_done);
 7468 
 7469   shrq(carry, 32);
 7470   movl(Address(z, tmp3, Address::times_4,  0), carry);
 7471   jmp(L_second_loop);
 7472 
 7473   // Next infrequent code is moved outside loops.
 7474   bind(L_last_x);
 7475   if (UseBMI2Instructions) {
 7476     movl(rdx, Address(x,  0));
 7477   } else {
 7478     movl(x_xstart, Address(x,  0));
 7479   }
 7480   jmp(L_third_loop_prologue);
 7481 
 7482   bind(L_done);
 7483 
 7484   pop(xlen);
 7485 
 7486   pop(tmp5);
 7487   pop(tmp4);
 7488   pop(tmp3);
 7489   pop(tmp2);
 7490   pop(tmp1);
 7491   pop(tmp0);
 7492 }
 7493 
 7494 void MacroAssembler::vectorized_mismatch(Register obja, Register objb, Register length, Register log2_array_indxscale,
 7495   Register result, Register tmp1, Register tmp2, XMMRegister rymm0, XMMRegister rymm1, XMMRegister rymm2){
 7496   assert(UseSSE42Intrinsics, "SSE4.2 must be enabled.");
 7497   Label VECTOR16_LOOP, VECTOR8_LOOP, VECTOR4_LOOP;
 7498   Label VECTOR8_TAIL, VECTOR4_TAIL;
 7499   Label VECTOR32_NOT_EQUAL, VECTOR16_NOT_EQUAL, VECTOR8_NOT_EQUAL, VECTOR4_NOT_EQUAL;
 7500   Label SAME_TILL_END, DONE;
 7501   Label BYTES_LOOP, BYTES_TAIL, BYTES_NOT_EQUAL;
 7502 
 7503   //scale is in rcx in both Win64 and Unix
 7504   ShortBranchVerifier sbv(this);
 7505 
 7506   shlq(length);
 7507   xorq(result, result);
 7508 
 7509   if ((AVX3Threshold == 0) && (UseAVX > 2) &&
 7510       VM_Version::supports_avx512vlbw()) {
 7511     Label VECTOR64_LOOP, VECTOR64_NOT_EQUAL, VECTOR32_TAIL;
 7512 
 7513     cmpq(length, 64);
 7514     jcc(Assembler::less, VECTOR32_TAIL);
 7515 
 7516     movq(tmp1, length);
 7517     andq(tmp1, 0x3F);      // tail count
 7518     andq(length, ~(0x3F)); //vector count
 7519 
 7520     bind(VECTOR64_LOOP);
 7521     // AVX512 code to compare 64 byte vectors.
 7522     evmovdqub(rymm0, Address(obja, result), Assembler::AVX_512bit);
 7523     evpcmpeqb(k7, rymm0, Address(objb, result), Assembler::AVX_512bit);
 7524     kortestql(k7, k7);
 7525     jcc(Assembler::aboveEqual, VECTOR64_NOT_EQUAL);     // mismatch
 7526     addq(result, 64);
 7527     subq(length, 64);
 7528     jccb(Assembler::notZero, VECTOR64_LOOP);
 7529 
 7530     //bind(VECTOR64_TAIL);
 7531     testq(tmp1, tmp1);
 7532     jcc(Assembler::zero, SAME_TILL_END);
 7533 
 7534     //bind(VECTOR64_TAIL);
 7535     // AVX512 code to compare up to 63 byte vectors.
 7536     mov64(tmp2, 0xFFFFFFFFFFFFFFFF);
 7537     shlxq(tmp2, tmp2, tmp1);
 7538     notq(tmp2);
 7539     kmovql(k3, tmp2);
 7540 
 7541     evmovdqub(rymm0, k3, Address(obja, result), false, Assembler::AVX_512bit);
 7542     evpcmpeqb(k7, k3, rymm0, Address(objb, result), Assembler::AVX_512bit);
 7543 
 7544     ktestql(k7, k3);
 7545     jcc(Assembler::below, SAME_TILL_END);     // not mismatch
 7546 
 7547     bind(VECTOR64_NOT_EQUAL);
 7548     kmovql(tmp1, k7);
 7549     notq(tmp1);
 7550     tzcntq(tmp1, tmp1);
 7551     addq(result, tmp1);
 7552     shrq(result);
 7553     jmp(DONE);
 7554     bind(VECTOR32_TAIL);
 7555   }
 7556 
 7557   cmpq(length, 8);
 7558   jcc(Assembler::equal, VECTOR8_LOOP);
 7559   jcc(Assembler::less, VECTOR4_TAIL);
 7560 
 7561   if (UseAVX >= 2) {
 7562     Label VECTOR16_TAIL, VECTOR32_LOOP;
 7563 
 7564     cmpq(length, 16);
 7565     jcc(Assembler::equal, VECTOR16_LOOP);
 7566     jcc(Assembler::less, VECTOR8_LOOP);
 7567 
 7568     cmpq(length, 32);
 7569     jccb(Assembler::less, VECTOR16_TAIL);
 7570 
 7571     subq(length, 32);
 7572     bind(VECTOR32_LOOP);
 7573     vmovdqu(rymm0, Address(obja, result));
 7574     vmovdqu(rymm1, Address(objb, result));
 7575     vpxor(rymm2, rymm0, rymm1, Assembler::AVX_256bit);
 7576     vptest(rymm2, rymm2);
 7577     jcc(Assembler::notZero, VECTOR32_NOT_EQUAL);//mismatch found
 7578     addq(result, 32);
 7579     subq(length, 32);
 7580     jcc(Assembler::greaterEqual, VECTOR32_LOOP);
 7581     addq(length, 32);
 7582     jcc(Assembler::equal, SAME_TILL_END);
 7583     //falling through if less than 32 bytes left //close the branch here.
 7584 
 7585     bind(VECTOR16_TAIL);
 7586     cmpq(length, 16);
 7587     jccb(Assembler::less, VECTOR8_TAIL);
 7588     bind(VECTOR16_LOOP);
 7589     movdqu(rymm0, Address(obja, result));
 7590     movdqu(rymm1, Address(objb, result));
 7591     vpxor(rymm2, rymm0, rymm1, Assembler::AVX_128bit);
 7592     ptest(rymm2, rymm2);
 7593     jcc(Assembler::notZero, VECTOR16_NOT_EQUAL);//mismatch found
 7594     addq(result, 16);
 7595     subq(length, 16);
 7596     jcc(Assembler::equal, SAME_TILL_END);
 7597     //falling through if less than 16 bytes left
 7598   } else {//regular intrinsics
 7599 
 7600     cmpq(length, 16);
 7601     jccb(Assembler::less, VECTOR8_TAIL);
 7602 
 7603     subq(length, 16);
 7604     bind(VECTOR16_LOOP);
 7605     movdqu(rymm0, Address(obja, result));
 7606     movdqu(rymm1, Address(objb, result));
 7607     pxor(rymm0, rymm1);
 7608     ptest(rymm0, rymm0);
 7609     jcc(Assembler::notZero, VECTOR16_NOT_EQUAL);//mismatch found
 7610     addq(result, 16);
 7611     subq(length, 16);
 7612     jccb(Assembler::greaterEqual, VECTOR16_LOOP);
 7613     addq(length, 16);
 7614     jcc(Assembler::equal, SAME_TILL_END);
 7615     //falling through if less than 16 bytes left
 7616   }
 7617 
 7618   bind(VECTOR8_TAIL);
 7619   cmpq(length, 8);
 7620   jccb(Assembler::less, VECTOR4_TAIL);
 7621   bind(VECTOR8_LOOP);
 7622   movq(tmp1, Address(obja, result));
 7623   movq(tmp2, Address(objb, result));
 7624   xorq(tmp1, tmp2);
 7625   testq(tmp1, tmp1);
 7626   jcc(Assembler::notZero, VECTOR8_NOT_EQUAL);//mismatch found
 7627   addq(result, 8);
 7628   subq(length, 8);
 7629   jcc(Assembler::equal, SAME_TILL_END);
 7630   //falling through if less than 8 bytes left
 7631 
 7632   bind(VECTOR4_TAIL);
 7633   cmpq(length, 4);
 7634   jccb(Assembler::less, BYTES_TAIL);
 7635   bind(VECTOR4_LOOP);
 7636   movl(tmp1, Address(obja, result));
 7637   xorl(tmp1, Address(objb, result));
 7638   testl(tmp1, tmp1);
 7639   jcc(Assembler::notZero, VECTOR4_NOT_EQUAL);//mismatch found
 7640   addq(result, 4);
 7641   subq(length, 4);
 7642   jcc(Assembler::equal, SAME_TILL_END);
 7643   //falling through if less than 4 bytes left
 7644 
 7645   bind(BYTES_TAIL);
 7646   bind(BYTES_LOOP);
 7647   load_unsigned_byte(tmp1, Address(obja, result));
 7648   load_unsigned_byte(tmp2, Address(objb, result));
 7649   xorl(tmp1, tmp2);
 7650   testl(tmp1, tmp1);
 7651   jcc(Assembler::notZero, BYTES_NOT_EQUAL);//mismatch found
 7652   decq(length);
 7653   jcc(Assembler::zero, SAME_TILL_END);
 7654   incq(result);
 7655   load_unsigned_byte(tmp1, Address(obja, result));
 7656   load_unsigned_byte(tmp2, Address(objb, result));
 7657   xorl(tmp1, tmp2);
 7658   testl(tmp1, tmp1);
 7659   jcc(Assembler::notZero, BYTES_NOT_EQUAL);//mismatch found
 7660   decq(length);
 7661   jcc(Assembler::zero, SAME_TILL_END);
 7662   incq(result);
 7663   load_unsigned_byte(tmp1, Address(obja, result));
 7664   load_unsigned_byte(tmp2, Address(objb, result));
 7665   xorl(tmp1, tmp2);
 7666   testl(tmp1, tmp1);
 7667   jcc(Assembler::notZero, BYTES_NOT_EQUAL);//mismatch found
 7668   jmp(SAME_TILL_END);
 7669 
 7670   if (UseAVX >= 2) {
 7671     bind(VECTOR32_NOT_EQUAL);
 7672     vpcmpeqb(rymm2, rymm2, rymm2, Assembler::AVX_256bit);
 7673     vpcmpeqb(rymm0, rymm0, rymm1, Assembler::AVX_256bit);
 7674     vpxor(rymm0, rymm0, rymm2, Assembler::AVX_256bit);
 7675     vpmovmskb(tmp1, rymm0);
 7676     bsfq(tmp1, tmp1);
 7677     addq(result, tmp1);
 7678     shrq(result);
 7679     jmp(DONE);
 7680   }
 7681 
 7682   bind(VECTOR16_NOT_EQUAL);
 7683   if (UseAVX >= 2) {
 7684     vpcmpeqb(rymm2, rymm2, rymm2, Assembler::AVX_128bit);
 7685     vpcmpeqb(rymm0, rymm0, rymm1, Assembler::AVX_128bit);
 7686     pxor(rymm0, rymm2);
 7687   } else {
 7688     pcmpeqb(rymm2, rymm2);
 7689     pxor(rymm0, rymm1);
 7690     pcmpeqb(rymm0, rymm1);
 7691     pxor(rymm0, rymm2);
 7692   }
 7693   pmovmskb(tmp1, rymm0);
 7694   bsfq(tmp1, tmp1);
 7695   addq(result, tmp1);
 7696   shrq(result);
 7697   jmpb(DONE);
 7698 
 7699   bind(VECTOR8_NOT_EQUAL);
 7700   bind(VECTOR4_NOT_EQUAL);
 7701   bsfq(tmp1, tmp1);
 7702   shrq(tmp1, 3);
 7703   addq(result, tmp1);
 7704   bind(BYTES_NOT_EQUAL);
 7705   shrq(result);
 7706   jmpb(DONE);
 7707 
 7708   bind(SAME_TILL_END);
 7709   mov64(result, -1);
 7710 
 7711   bind(DONE);
 7712 }
 7713 
 7714 //Helper functions for square_to_len()
 7715 
 7716 /**
 7717  * Store the squares of x[], right shifted one bit (divided by 2) into z[]
 7718  * Preserves x and z and modifies rest of the registers.
 7719  */
 7720 void MacroAssembler::square_rshift(Register x, Register xlen, Register z, Register tmp1, Register tmp3, Register tmp4, Register tmp5, Register rdxReg, Register raxReg) {
 7721   // Perform square and right shift by 1
 7722   // Handle odd xlen case first, then for even xlen do the following
 7723   // jlong carry = 0;
 7724   // for (int j=0, i=0; j < xlen; j+=2, i+=4) {
 7725   //     huge_128 product = x[j:j+1] * x[j:j+1];
 7726   //     z[i:i+1] = (carry << 63) | (jlong)(product >>> 65);
 7727   //     z[i+2:i+3] = (jlong)(product >>> 1);
 7728   //     carry = (jlong)product;
 7729   // }
 7730 
 7731   xorq(tmp5, tmp5);     // carry
 7732   xorq(rdxReg, rdxReg);
 7733   xorl(tmp1, tmp1);     // index for x
 7734   xorl(tmp4, tmp4);     // index for z
 7735 
 7736   Label L_first_loop, L_first_loop_exit;
 7737 
 7738   testl(xlen, 1);
 7739   jccb(Assembler::zero, L_first_loop); //jump if xlen is even
 7740 
 7741   // Square and right shift by 1 the odd element using 32 bit multiply
 7742   movl(raxReg, Address(x, tmp1, Address::times_4, 0));
 7743   imulq(raxReg, raxReg);
 7744   shrq(raxReg, 1);
 7745   adcq(tmp5, 0);
 7746   movq(Address(z, tmp4, Address::times_4, 0), raxReg);
 7747   incrementl(tmp1);
 7748   addl(tmp4, 2);
 7749 
 7750   // Square and  right shift by 1 the rest using 64 bit multiply
 7751   bind(L_first_loop);
 7752   cmpptr(tmp1, xlen);
 7753   jccb(Assembler::equal, L_first_loop_exit);
 7754 
 7755   // Square
 7756   movq(raxReg, Address(x, tmp1, Address::times_4,  0));
 7757   rorq(raxReg, 32);    // convert big-endian to little-endian
 7758   mulq(raxReg);        // 64-bit multiply rax * rax -> rdx:rax
 7759 
 7760   // Right shift by 1 and save carry
 7761   shrq(tmp5, 1);       // rdx:rax:tmp5 = (tmp5:rdx:rax) >>> 1
 7762   rcrq(rdxReg, 1);
 7763   rcrq(raxReg, 1);
 7764   adcq(tmp5, 0);
 7765 
 7766   // Store result in z
 7767   movq(Address(z, tmp4, Address::times_4, 0), rdxReg);
 7768   movq(Address(z, tmp4, Address::times_4, 8), raxReg);
 7769 
 7770   // Update indices for x and z
 7771   addl(tmp1, 2);
 7772   addl(tmp4, 4);
 7773   jmp(L_first_loop);
 7774 
 7775   bind(L_first_loop_exit);
 7776 }
 7777 
 7778 
 7779 /**
 7780  * Perform the following multiply add operation using BMI2 instructions
 7781  * carry:sum = sum + op1*op2 + carry
 7782  * op2 should be in rdx
 7783  * op2 is preserved, all other registers are modified
 7784  */
 7785 void MacroAssembler::multiply_add_64_bmi2(Register sum, Register op1, Register op2, Register carry, Register tmp2) {
 7786   // assert op2 is rdx
 7787   mulxq(tmp2, op1, op1);  //  op1 * op2 -> tmp2:op1
 7788   addq(sum, carry);
 7789   adcq(tmp2, 0);
 7790   addq(sum, op1);
 7791   adcq(tmp2, 0);
 7792   movq(carry, tmp2);
 7793 }
 7794 
 7795 /**
 7796  * Perform the following multiply add operation:
 7797  * carry:sum = sum + op1*op2 + carry
 7798  * Preserves op1, op2 and modifies rest of registers
 7799  */
 7800 void MacroAssembler::multiply_add_64(Register sum, Register op1, Register op2, Register carry, Register rdxReg, Register raxReg) {
 7801   // rdx:rax = op1 * op2
 7802   movq(raxReg, op2);
 7803   mulq(op1);
 7804 
 7805   //  rdx:rax = sum + carry + rdx:rax
 7806   addq(sum, carry);
 7807   adcq(rdxReg, 0);
 7808   addq(sum, raxReg);
 7809   adcq(rdxReg, 0);
 7810 
 7811   // carry:sum = rdx:sum
 7812   movq(carry, rdxReg);
 7813 }
 7814 
 7815 /**
 7816  * Add 64 bit long carry into z[] with carry propagation.
 7817  * Preserves z and carry register values and modifies rest of registers.
 7818  *
 7819  */
 7820 void MacroAssembler::add_one_64(Register z, Register zlen, Register carry, Register tmp1) {
 7821   Label L_fourth_loop, L_fourth_loop_exit;
 7822 
 7823   movl(tmp1, 1);
 7824   subl(zlen, 2);
 7825   addq(Address(z, zlen, Address::times_4, 0), carry);
 7826 
 7827   bind(L_fourth_loop);
 7828   jccb(Assembler::carryClear, L_fourth_loop_exit);
 7829   subl(zlen, 2);
 7830   jccb(Assembler::negative, L_fourth_loop_exit);
 7831   addq(Address(z, zlen, Address::times_4, 0), tmp1);
 7832   jmp(L_fourth_loop);
 7833   bind(L_fourth_loop_exit);
 7834 }
 7835 
 7836 /**
 7837  * Shift z[] left by 1 bit.
 7838  * Preserves x, len, z and zlen registers and modifies rest of the registers.
 7839  *
 7840  */
 7841 void MacroAssembler::lshift_by_1(Register x, Register len, Register z, Register zlen, Register tmp1, Register tmp2, Register tmp3, Register tmp4) {
 7842 
 7843   Label L_fifth_loop, L_fifth_loop_exit;
 7844 
 7845   // Fifth loop
 7846   // Perform primitiveLeftShift(z, zlen, 1)
 7847 
 7848   const Register prev_carry = tmp1;
 7849   const Register new_carry = tmp4;
 7850   const Register value = tmp2;
 7851   const Register zidx = tmp3;
 7852 
 7853   // int zidx, carry;
 7854   // long value;
 7855   // carry = 0;
 7856   // for (zidx = zlen-2; zidx >=0; zidx -= 2) {
 7857   //    (carry:value)  = (z[i] << 1) | carry ;
 7858   //    z[i] = value;
 7859   // }
 7860 
 7861   movl(zidx, zlen);
 7862   xorl(prev_carry, prev_carry); // clear carry flag and prev_carry register
 7863 
 7864   bind(L_fifth_loop);
 7865   decl(zidx);  // Use decl to preserve carry flag
 7866   decl(zidx);
 7867   jccb(Assembler::negative, L_fifth_loop_exit);
 7868 
 7869   if (UseBMI2Instructions) {
 7870      movq(value, Address(z, zidx, Address::times_4, 0));
 7871      rclq(value, 1);
 7872      rorxq(value, value, 32);
 7873      movq(Address(z, zidx, Address::times_4,  0), value);  // Store back in big endian form
 7874   }
 7875   else {
 7876     // clear new_carry
 7877     xorl(new_carry, new_carry);
 7878 
 7879     // Shift z[i] by 1, or in previous carry and save new carry
 7880     movq(value, Address(z, zidx, Address::times_4, 0));
 7881     shlq(value, 1);
 7882     adcl(new_carry, 0);
 7883 
 7884     orq(value, prev_carry);
 7885     rorq(value, 0x20);
 7886     movq(Address(z, zidx, Address::times_4,  0), value);  // Store back in big endian form
 7887 
 7888     // Set previous carry = new carry
 7889     movl(prev_carry, new_carry);
 7890   }
 7891   jmp(L_fifth_loop);
 7892 
 7893   bind(L_fifth_loop_exit);
 7894 }
 7895 
 7896 
 7897 /**
 7898  * Code for BigInteger::squareToLen() intrinsic
 7899  *
 7900  * rdi: x
 7901  * rsi: len
 7902  * r8:  z
 7903  * rcx: zlen
 7904  * r12: tmp1
 7905  * r13: tmp2
 7906  * r14: tmp3
 7907  * r15: tmp4
 7908  * rbx: tmp5
 7909  *
 7910  */
 7911 void MacroAssembler::square_to_len(Register x, Register len, Register z, Register zlen, Register tmp1, Register tmp2, Register tmp3, Register tmp4, Register tmp5, Register rdxReg, Register raxReg) {
 7912 
 7913   Label L_second_loop, L_second_loop_exit, L_third_loop, L_third_loop_exit, L_last_x, L_multiply;
 7914   push(tmp1);
 7915   push(tmp2);
 7916   push(tmp3);
 7917   push(tmp4);
 7918   push(tmp5);
 7919 
 7920   // First loop
 7921   // Store the squares, right shifted one bit (i.e., divided by 2).
 7922   square_rshift(x, len, z, tmp1, tmp3, tmp4, tmp5, rdxReg, raxReg);
 7923 
 7924   // Add in off-diagonal sums.
 7925   //
 7926   // Second, third (nested) and fourth loops.
 7927   // zlen +=2;
 7928   // for (int xidx=len-2,zidx=zlen-4; xidx > 0; xidx-=2,zidx-=4) {
 7929   //    carry = 0;
 7930   //    long op2 = x[xidx:xidx+1];
 7931   //    for (int j=xidx-2,k=zidx; j >= 0; j-=2) {
 7932   //       k -= 2;
 7933   //       long op1 = x[j:j+1];
 7934   //       long sum = z[k:k+1];
 7935   //       carry:sum = multiply_add_64(sum, op1, op2, carry, tmp_regs);
 7936   //       z[k:k+1] = sum;
 7937   //    }
 7938   //    add_one_64(z, k, carry, tmp_regs);
 7939   // }
 7940 
 7941   const Register carry = tmp5;
 7942   const Register sum = tmp3;
 7943   const Register op1 = tmp4;
 7944   Register op2 = tmp2;
 7945 
 7946   push(zlen);
 7947   push(len);
 7948   addl(zlen,2);
 7949   bind(L_second_loop);
 7950   xorq(carry, carry);
 7951   subl(zlen, 4);
 7952   subl(len, 2);
 7953   push(zlen);
 7954   push(len);
 7955   cmpl(len, 0);
 7956   jccb(Assembler::lessEqual, L_second_loop_exit);
 7957 
 7958   // Multiply an array by one 64 bit long.
 7959   if (UseBMI2Instructions) {
 7960     op2 = rdxReg;
 7961     movq(op2, Address(x, len, Address::times_4,  0));
 7962     rorxq(op2, op2, 32);
 7963   }
 7964   else {
 7965     movq(op2, Address(x, len, Address::times_4,  0));
 7966     rorq(op2, 32);
 7967   }
 7968 
 7969   bind(L_third_loop);
 7970   decrementl(len);
 7971   jccb(Assembler::negative, L_third_loop_exit);
 7972   decrementl(len);
 7973   jccb(Assembler::negative, L_last_x);
 7974 
 7975   movq(op1, Address(x, len, Address::times_4,  0));
 7976   rorq(op1, 32);
 7977 
 7978   bind(L_multiply);
 7979   subl(zlen, 2);
 7980   movq(sum, Address(z, zlen, Address::times_4,  0));
 7981 
 7982   // Multiply 64 bit by 64 bit and add 64 bits lower half and upper 64 bits as carry.
 7983   if (UseBMI2Instructions) {
 7984     multiply_add_64_bmi2(sum, op1, op2, carry, tmp2);
 7985   }
 7986   else {
 7987     multiply_add_64(sum, op1, op2, carry, rdxReg, raxReg);
 7988   }
 7989 
 7990   movq(Address(z, zlen, Address::times_4, 0), sum);
 7991 
 7992   jmp(L_third_loop);
 7993   bind(L_third_loop_exit);
 7994 
 7995   // Fourth loop
 7996   // Add 64 bit long carry into z with carry propagation.
 7997   // Uses offsetted zlen.
 7998   add_one_64(z, zlen, carry, tmp1);
 7999 
 8000   pop(len);
 8001   pop(zlen);
 8002   jmp(L_second_loop);
 8003 
 8004   // Next infrequent code is moved outside loops.
 8005   bind(L_last_x);
 8006   movl(op1, Address(x, 0));
 8007   jmp(L_multiply);
 8008 
 8009   bind(L_second_loop_exit);
 8010   pop(len);
 8011   pop(zlen);
 8012   pop(len);
 8013   pop(zlen);
 8014 
 8015   // Fifth loop
 8016   // Shift z left 1 bit.
 8017   lshift_by_1(x, len, z, zlen, tmp1, tmp2, tmp3, tmp4);
 8018 
 8019   // z[zlen-1] |= x[len-1] & 1;
 8020   movl(tmp3, Address(x, len, Address::times_4, -4));
 8021   andl(tmp3, 1);
 8022   orl(Address(z, zlen, Address::times_4,  -4), tmp3);
 8023 
 8024   pop(tmp5);
 8025   pop(tmp4);
 8026   pop(tmp3);
 8027   pop(tmp2);
 8028   pop(tmp1);
 8029 }
 8030 
 8031 /**
 8032  * Helper function for mul_add()
 8033  * Multiply the in[] by int k and add to out[] starting at offset offs using
 8034  * 128 bit by 32 bit multiply and return the carry in tmp5.
 8035  * Only quad int aligned length of in[] is operated on in this function.
 8036  * k is in rdxReg for BMI2Instructions, for others it is in tmp2.
 8037  * This function preserves out, in and k registers.
 8038  * len and offset point to the appropriate index in "in" & "out" correspondingly
 8039  * tmp5 has the carry.
 8040  * other registers are temporary and are modified.
 8041  *
 8042  */
 8043 void MacroAssembler::mul_add_128_x_32_loop(Register out, Register in,
 8044   Register offset, Register len, Register tmp1, Register tmp2, Register tmp3,
 8045   Register tmp4, Register tmp5, Register rdxReg, Register raxReg) {
 8046 
 8047   Label L_first_loop, L_first_loop_exit;
 8048 
 8049   movl(tmp1, len);
 8050   shrl(tmp1, 2);
 8051 
 8052   bind(L_first_loop);
 8053   subl(tmp1, 1);
 8054   jccb(Assembler::negative, L_first_loop_exit);
 8055 
 8056   subl(len, 4);
 8057   subl(offset, 4);
 8058 
 8059   Register op2 = tmp2;
 8060   const Register sum = tmp3;
 8061   const Register op1 = tmp4;
 8062   const Register carry = tmp5;
 8063 
 8064   if (UseBMI2Instructions) {
 8065     op2 = rdxReg;
 8066   }
 8067 
 8068   movq(op1, Address(in, len, Address::times_4,  8));
 8069   rorq(op1, 32);
 8070   movq(sum, Address(out, offset, Address::times_4,  8));
 8071   rorq(sum, 32);
 8072   if (UseBMI2Instructions) {
 8073     multiply_add_64_bmi2(sum, op1, op2, carry, raxReg);
 8074   }
 8075   else {
 8076     multiply_add_64(sum, op1, op2, carry, rdxReg, raxReg);
 8077   }
 8078   // Store back in big endian from little endian
 8079   rorq(sum, 0x20);
 8080   movq(Address(out, offset, Address::times_4,  8), sum);
 8081 
 8082   movq(op1, Address(in, len, Address::times_4,  0));
 8083   rorq(op1, 32);
 8084   movq(sum, Address(out, offset, Address::times_4,  0));
 8085   rorq(sum, 32);
 8086   if (UseBMI2Instructions) {
 8087     multiply_add_64_bmi2(sum, op1, op2, carry, raxReg);
 8088   }
 8089   else {
 8090     multiply_add_64(sum, op1, op2, carry, rdxReg, raxReg);
 8091   }
 8092   // Store back in big endian from little endian
 8093   rorq(sum, 0x20);
 8094   movq(Address(out, offset, Address::times_4,  0), sum);
 8095 
 8096   jmp(L_first_loop);
 8097   bind(L_first_loop_exit);
 8098 }
 8099 
 8100 /**
 8101  * Code for BigInteger::mulAdd() intrinsic
 8102  *
 8103  * rdi: out
 8104  * rsi: in
 8105  * r11: offs (out.length - offset)
 8106  * rcx: len
 8107  * r8:  k
 8108  * r12: tmp1
 8109  * r13: tmp2
 8110  * r14: tmp3
 8111  * r15: tmp4
 8112  * rbx: tmp5
 8113  * Multiply the in[] by word k and add to out[], return the carry in rax
 8114  */
 8115 void MacroAssembler::mul_add(Register out, Register in, Register offs,
 8116    Register len, Register k, Register tmp1, Register tmp2, Register tmp3,
 8117    Register tmp4, Register tmp5, Register rdxReg, Register raxReg) {
 8118 
 8119   Label L_carry, L_last_in, L_done;
 8120 
 8121 // carry = 0;
 8122 // for (int j=len-1; j >= 0; j--) {
 8123 //    long product = (in[j] & LONG_MASK) * kLong +
 8124 //                   (out[offs] & LONG_MASK) + carry;
 8125 //    out[offs--] = (int)product;
 8126 //    carry = product >>> 32;
 8127 // }
 8128 //
 8129   push(tmp1);
 8130   push(tmp2);
 8131   push(tmp3);
 8132   push(tmp4);
 8133   push(tmp5);
 8134 
 8135   Register op2 = tmp2;
 8136   const Register sum = tmp3;
 8137   const Register op1 = tmp4;
 8138   const Register carry =  tmp5;
 8139 
 8140   if (UseBMI2Instructions) {
 8141     op2 = rdxReg;
 8142     movl(op2, k);
 8143   }
 8144   else {
 8145     movl(op2, k);
 8146   }
 8147 
 8148   xorq(carry, carry);
 8149 
 8150   //First loop
 8151 
 8152   //Multiply in[] by k in a 4 way unrolled loop using 128 bit by 32 bit multiply
 8153   //The carry is in tmp5
 8154   mul_add_128_x_32_loop(out, in, offs, len, tmp1, tmp2, tmp3, tmp4, tmp5, rdxReg, raxReg);
 8155 
 8156   //Multiply the trailing in[] entry using 64 bit by 32 bit, if any
 8157   decrementl(len);
 8158   jccb(Assembler::negative, L_carry);
 8159   decrementl(len);
 8160   jccb(Assembler::negative, L_last_in);
 8161 
 8162   movq(op1, Address(in, len, Address::times_4,  0));
 8163   rorq(op1, 32);
 8164 
 8165   subl(offs, 2);
 8166   movq(sum, Address(out, offs, Address::times_4,  0));
 8167   rorq(sum, 32);
 8168 
 8169   if (UseBMI2Instructions) {
 8170     multiply_add_64_bmi2(sum, op1, op2, carry, raxReg);
 8171   }
 8172   else {
 8173     multiply_add_64(sum, op1, op2, carry, rdxReg, raxReg);
 8174   }
 8175 
 8176   // Store back in big endian from little endian
 8177   rorq(sum, 0x20);
 8178   movq(Address(out, offs, Address::times_4,  0), sum);
 8179 
 8180   testl(len, len);
 8181   jccb(Assembler::zero, L_carry);
 8182 
 8183   //Multiply the last in[] entry, if any
 8184   bind(L_last_in);
 8185   movl(op1, Address(in, 0));
 8186   movl(sum, Address(out, offs, Address::times_4,  -4));
 8187 
 8188   movl(raxReg, k);
 8189   mull(op1); //tmp4 * eax -> edx:eax
 8190   addl(sum, carry);
 8191   adcl(rdxReg, 0);
 8192   addl(sum, raxReg);
 8193   adcl(rdxReg, 0);
 8194   movl(carry, rdxReg);
 8195 
 8196   movl(Address(out, offs, Address::times_4,  -4), sum);
 8197 
 8198   bind(L_carry);
 8199   //return tmp5/carry as carry in rax
 8200   movl(rax, carry);
 8201 
 8202   bind(L_done);
 8203   pop(tmp5);
 8204   pop(tmp4);
 8205   pop(tmp3);
 8206   pop(tmp2);
 8207   pop(tmp1);
 8208 }
 8209 #endif
 8210 
 8211 /**
 8212  * Emits code to update CRC-32 with a byte value according to constants in table
 8213  *
 8214  * @param [in,out]crc   Register containing the crc.
 8215  * @param [in]val       Register containing the byte to fold into the CRC.
 8216  * @param [in]table     Register containing the table of crc constants.
 8217  *
 8218  * uint32_t crc;
 8219  * val = crc_table[(val ^ crc) & 0xFF];
 8220  * crc = val ^ (crc >> 8);
 8221  *
 8222  */
 8223 void MacroAssembler::update_byte_crc32(Register crc, Register val, Register table) {
 8224   xorl(val, crc);
 8225   andl(val, 0xFF);
 8226   shrl(crc, 8); // unsigned shift
 8227   xorl(crc, Address(table, val, Address::times_4, 0));
 8228 }
 8229 
 8230 /**
 8231  * Fold 128-bit data chunk
 8232  */
 8233 void MacroAssembler::fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, Register buf, int offset) {
 8234   if (UseAVX > 0) {
 8235     vpclmulhdq(xtmp, xK, xcrc); // [123:64]
 8236     vpclmulldq(xcrc, xK, xcrc); // [63:0]
 8237     vpxor(xcrc, xcrc, Address(buf, offset), 0 /* vector_len */);
 8238     pxor(xcrc, xtmp);
 8239   } else {
 8240     movdqa(xtmp, xcrc);
 8241     pclmulhdq(xtmp, xK);   // [123:64]
 8242     pclmulldq(xcrc, xK);   // [63:0]
 8243     pxor(xcrc, xtmp);
 8244     movdqu(xtmp, Address(buf, offset));
 8245     pxor(xcrc, xtmp);
 8246   }
 8247 }
 8248 
 8249 void MacroAssembler::fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, XMMRegister xbuf) {
 8250   if (UseAVX > 0) {
 8251     vpclmulhdq(xtmp, xK, xcrc);
 8252     vpclmulldq(xcrc, xK, xcrc);
 8253     pxor(xcrc, xbuf);
 8254     pxor(xcrc, xtmp);
 8255   } else {
 8256     movdqa(xtmp, xcrc);
 8257     pclmulhdq(xtmp, xK);
 8258     pclmulldq(xcrc, xK);
 8259     pxor(xcrc, xbuf);
 8260     pxor(xcrc, xtmp);
 8261   }
 8262 }
 8263 
 8264 /**
 8265  * 8-bit folds to compute 32-bit CRC
 8266  *
 8267  * uint64_t xcrc;
 8268  * timesXtoThe32[xcrc & 0xFF] ^ (xcrc >> 8);
 8269  */
 8270 void MacroAssembler::fold_8bit_crc32(XMMRegister xcrc, Register table, XMMRegister xtmp, Register tmp) {
 8271   movdl(tmp, xcrc);
 8272   andl(tmp, 0xFF);
 8273   movdl(xtmp, Address(table, tmp, Address::times_4, 0));
 8274   psrldq(xcrc, 1); // unsigned shift one byte
 8275   pxor(xcrc, xtmp);
 8276 }
 8277 
 8278 /**
 8279  * uint32_t crc;
 8280  * timesXtoThe32[crc & 0xFF] ^ (crc >> 8);
 8281  */
 8282 void MacroAssembler::fold_8bit_crc32(Register crc, Register table, Register tmp) {
 8283   movl(tmp, crc);
 8284   andl(tmp, 0xFF);
 8285   shrl(crc, 8);
 8286   xorl(crc, Address(table, tmp, Address::times_4, 0));
 8287 }
 8288 
 8289 /**
 8290  * @param crc   register containing existing CRC (32-bit)
 8291  * @param buf   register pointing to input byte buffer (byte*)
 8292  * @param len   register containing number of bytes
 8293  * @param table register that will contain address of CRC table
 8294  * @param tmp   scratch register
 8295  */
 8296 void MacroAssembler::kernel_crc32(Register crc, Register buf, Register len, Register table, Register tmp) {
 8297   assert_different_registers(crc, buf, len, table, tmp, rax);
 8298 
 8299   Label L_tail, L_tail_restore, L_tail_loop, L_exit, L_align_loop, L_aligned;
 8300   Label L_fold_tail, L_fold_128b, L_fold_512b, L_fold_512b_loop, L_fold_tail_loop;
 8301 
 8302   // For EVEX with VL and BW, provide a standard mask, VL = 128 will guide the merge
 8303   // context for the registers used, where all instructions below are using 128-bit mode
 8304   // On EVEX without VL and BW, these instructions will all be AVX.
 8305   lea(table, ExternalAddress(StubRoutines::crc_table_addr()));
 8306   notl(crc); // ~crc
 8307   cmpl(len, 16);
 8308   jcc(Assembler::less, L_tail);
 8309 
 8310   // Align buffer to 16 bytes
 8311   movl(tmp, buf);
 8312   andl(tmp, 0xF);
 8313   jccb(Assembler::zero, L_aligned);
 8314   subl(tmp,  16);
 8315   addl(len, tmp);
 8316 
 8317   align(4);
 8318   BIND(L_align_loop);
 8319   movsbl(rax, Address(buf, 0)); // load byte with sign extension
 8320   update_byte_crc32(crc, rax, table);
 8321   increment(buf);
 8322   incrementl(tmp);
 8323   jccb(Assembler::less, L_align_loop);
 8324 
 8325   BIND(L_aligned);
 8326   movl(tmp, len); // save
 8327   shrl(len, 4);
 8328   jcc(Assembler::zero, L_tail_restore);
 8329 
 8330   // Fold crc into first bytes of vector
 8331   movdqa(xmm1, Address(buf, 0));
 8332   movdl(rax, xmm1);
 8333   xorl(crc, rax);
 8334   if (VM_Version::supports_sse4_1()) {
 8335     pinsrd(xmm1, crc, 0);
 8336   } else {
 8337     pinsrw(xmm1, crc, 0);
 8338     shrl(crc, 16);
 8339     pinsrw(xmm1, crc, 1);
 8340   }
 8341   addptr(buf, 16);
 8342   subl(len, 4); // len > 0
 8343   jcc(Assembler::less, L_fold_tail);
 8344 
 8345   movdqa(xmm2, Address(buf,  0));
 8346   movdqa(xmm3, Address(buf, 16));
 8347   movdqa(xmm4, Address(buf, 32));
 8348   addptr(buf, 48);
 8349   subl(len, 3);
 8350   jcc(Assembler::lessEqual, L_fold_512b);
 8351 
 8352   // Fold total 512 bits of polynomial on each iteration,
 8353   // 128 bits per each of 4 parallel streams.
 8354   movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 32), rscratch1);
 8355 
 8356   align32();
 8357   BIND(L_fold_512b_loop);
 8358   fold_128bit_crc32(xmm1, xmm0, xmm5, buf,  0);
 8359   fold_128bit_crc32(xmm2, xmm0, xmm5, buf, 16);
 8360   fold_128bit_crc32(xmm3, xmm0, xmm5, buf, 32);
 8361   fold_128bit_crc32(xmm4, xmm0, xmm5, buf, 48);
 8362   addptr(buf, 64);
 8363   subl(len, 4);
 8364   jcc(Assembler::greater, L_fold_512b_loop);
 8365 
 8366   // Fold 512 bits to 128 bits.
 8367   BIND(L_fold_512b);
 8368   movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 16), rscratch1);
 8369   fold_128bit_crc32(xmm1, xmm0, xmm5, xmm2);
 8370   fold_128bit_crc32(xmm1, xmm0, xmm5, xmm3);
 8371   fold_128bit_crc32(xmm1, xmm0, xmm5, xmm4);
 8372 
 8373   // Fold the rest of 128 bits data chunks
 8374   BIND(L_fold_tail);
 8375   addl(len, 3);
 8376   jccb(Assembler::lessEqual, L_fold_128b);
 8377   movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 16), rscratch1);
 8378 
 8379   BIND(L_fold_tail_loop);
 8380   fold_128bit_crc32(xmm1, xmm0, xmm5, buf,  0);
 8381   addptr(buf, 16);
 8382   decrementl(len);
 8383   jccb(Assembler::greater, L_fold_tail_loop);
 8384 
 8385   // Fold 128 bits in xmm1 down into 32 bits in crc register.
 8386   BIND(L_fold_128b);
 8387   movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr()), rscratch1);
 8388   if (UseAVX > 0) {
 8389     vpclmulqdq(xmm2, xmm0, xmm1, 0x1);
 8390     vpand(xmm3, xmm0, xmm2, 0 /* vector_len */);
 8391     vpclmulqdq(xmm0, xmm0, xmm3, 0x1);
 8392   } else {
 8393     movdqa(xmm2, xmm0);
 8394     pclmulqdq(xmm2, xmm1, 0x1);
 8395     movdqa(xmm3, xmm0);
 8396     pand(xmm3, xmm2);
 8397     pclmulqdq(xmm0, xmm3, 0x1);
 8398   }
 8399   psrldq(xmm1, 8);
 8400   psrldq(xmm2, 4);
 8401   pxor(xmm0, xmm1);
 8402   pxor(xmm0, xmm2);
 8403 
 8404   // 8 8-bit folds to compute 32-bit CRC.
 8405   for (int j = 0; j < 4; j++) {
 8406     fold_8bit_crc32(xmm0, table, xmm1, rax);
 8407   }
 8408   movdl(crc, xmm0); // mov 32 bits to general register
 8409   for (int j = 0; j < 4; j++) {
 8410     fold_8bit_crc32(crc, table, rax);
 8411   }
 8412 
 8413   BIND(L_tail_restore);
 8414   movl(len, tmp); // restore
 8415   BIND(L_tail);
 8416   andl(len, 0xf);
 8417   jccb(Assembler::zero, L_exit);
 8418 
 8419   // Fold the rest of bytes
 8420   align(4);
 8421   BIND(L_tail_loop);
 8422   movsbl(rax, Address(buf, 0)); // load byte with sign extension
 8423   update_byte_crc32(crc, rax, table);
 8424   increment(buf);
 8425   decrementl(len);
 8426   jccb(Assembler::greater, L_tail_loop);
 8427 
 8428   BIND(L_exit);
 8429   notl(crc); // ~c
 8430 }
 8431 
 8432 #ifdef _LP64
 8433 // Helper function for AVX 512 CRC32
 8434 // Fold 512-bit data chunks
 8435 void MacroAssembler::fold512bit_crc32_avx512(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, Register buf,
 8436                                              Register pos, int offset) {
 8437   evmovdquq(xmm3, Address(buf, pos, Address::times_1, offset), Assembler::AVX_512bit);
 8438   evpclmulqdq(xtmp, xcrc, xK, 0x10, Assembler::AVX_512bit); // [123:64]
 8439   evpclmulqdq(xmm2, xcrc, xK, 0x01, Assembler::AVX_512bit); // [63:0]
 8440   evpxorq(xcrc, xtmp, xmm2, Assembler::AVX_512bit /* vector_len */);
 8441   evpxorq(xcrc, xcrc, xmm3, Assembler::AVX_512bit /* vector_len */);
 8442 }
 8443 
 8444 // Helper function for AVX 512 CRC32
 8445 // Compute CRC32 for < 256B buffers
 8446 void MacroAssembler::kernel_crc32_avx512_256B(Register crc, Register buf, Register len, Register table, Register pos,
 8447                                               Register tmp1, Register tmp2, Label& L_barrett, Label& L_16B_reduction_loop,
 8448                                               Label& L_get_last_two_xmms, Label& L_128_done, Label& L_cleanup) {
 8449 
 8450   Label L_less_than_32, L_exact_16_left, L_less_than_16_left;
 8451   Label L_less_than_8_left, L_less_than_4_left, L_less_than_2_left, L_zero_left;
 8452   Label L_only_less_than_4, L_only_less_than_3, L_only_less_than_2;
 8453 
 8454   // check if there is enough buffer to be able to fold 16B at a time
 8455   cmpl(len, 32);
 8456   jcc(Assembler::less, L_less_than_32);
 8457 
 8458   // if there is, load the constants
 8459   movdqu(xmm10, Address(table, 1 * 16));    //rk1 and rk2 in xmm10
 8460   movdl(xmm0, crc);                        // get the initial crc value
 8461   movdqu(xmm7, Address(buf, pos, Address::times_1, 0 * 16)); //load the plaintext
 8462   pxor(xmm7, xmm0);
 8463 
 8464   // update the buffer pointer
 8465   addl(pos, 16);
 8466   //update the counter.subtract 32 instead of 16 to save one instruction from the loop
 8467   subl(len, 32);
 8468   jmp(L_16B_reduction_loop);
 8469 
 8470   bind(L_less_than_32);
 8471   //mov initial crc to the return value. this is necessary for zero - length buffers.
 8472   movl(rax, crc);
 8473   testl(len, len);
 8474   jcc(Assembler::equal, L_cleanup);
 8475 
 8476   movdl(xmm0, crc);                        //get the initial crc value
 8477 
 8478   cmpl(len, 16);
 8479   jcc(Assembler::equal, L_exact_16_left);
 8480   jcc(Assembler::less, L_less_than_16_left);
 8481 
 8482   movdqu(xmm7, Address(buf, pos, Address::times_1, 0 * 16)); //load the plaintext
 8483   pxor(xmm7, xmm0);                       //xor the initial crc value
 8484   addl(pos, 16);
 8485   subl(len, 16);
 8486   movdqu(xmm10, Address(table, 1 * 16));    // rk1 and rk2 in xmm10
 8487   jmp(L_get_last_two_xmms);
 8488 
 8489   bind(L_less_than_16_left);
 8490   //use stack space to load data less than 16 bytes, zero - out the 16B in memory first.
 8491   pxor(xmm1, xmm1);
 8492   movptr(tmp1, rsp);
 8493   movdqu(Address(tmp1, 0 * 16), xmm1);
 8494 
 8495   cmpl(len, 4);
 8496   jcc(Assembler::less, L_only_less_than_4);
 8497 
 8498   //backup the counter value
 8499   movl(tmp2, len);
 8500   cmpl(len, 8);
 8501   jcc(Assembler::less, L_less_than_8_left);
 8502 
 8503   //load 8 Bytes
 8504   movq(rax, Address(buf, pos, Address::times_1, 0 * 16));
 8505   movq(Address(tmp1, 0 * 16), rax);
 8506   addptr(tmp1, 8);
 8507   subl(len, 8);
 8508   addl(pos, 8);
 8509 
 8510   bind(L_less_than_8_left);
 8511   cmpl(len, 4);
 8512   jcc(Assembler::less, L_less_than_4_left);
 8513 
 8514   //load 4 Bytes
 8515   movl(rax, Address(buf, pos, Address::times_1, 0));
 8516   movl(Address(tmp1, 0 * 16), rax);
 8517   addptr(tmp1, 4);
 8518   subl(len, 4);
 8519   addl(pos, 4);
 8520 
 8521   bind(L_less_than_4_left);
 8522   cmpl(len, 2);
 8523   jcc(Assembler::less, L_less_than_2_left);
 8524 
 8525   // load 2 Bytes
 8526   movw(rax, Address(buf, pos, Address::times_1, 0));
 8527   movl(Address(tmp1, 0 * 16), rax);
 8528   addptr(tmp1, 2);
 8529   subl(len, 2);
 8530   addl(pos, 2);
 8531 
 8532   bind(L_less_than_2_left);
 8533   cmpl(len, 1);
 8534   jcc(Assembler::less, L_zero_left);
 8535 
 8536   // load 1 Byte
 8537   movb(rax, Address(buf, pos, Address::times_1, 0));
 8538   movb(Address(tmp1, 0 * 16), rax);
 8539 
 8540   bind(L_zero_left);
 8541   movdqu(xmm7, Address(rsp, 0));
 8542   pxor(xmm7, xmm0);                       //xor the initial crc value
 8543 
 8544   lea(rax, ExternalAddress(StubRoutines::x86::shuf_table_crc32_avx512_addr()));
 8545   movdqu(xmm0, Address(rax, tmp2));
 8546   pshufb(xmm7, xmm0);
 8547   jmp(L_128_done);
 8548 
 8549   bind(L_exact_16_left);
 8550   movdqu(xmm7, Address(buf, pos, Address::times_1, 0));
 8551   pxor(xmm7, xmm0);                       //xor the initial crc value
 8552   jmp(L_128_done);
 8553 
 8554   bind(L_only_less_than_4);
 8555   cmpl(len, 3);
 8556   jcc(Assembler::less, L_only_less_than_3);
 8557 
 8558   // load 3 Bytes
 8559   movb(rax, Address(buf, pos, Address::times_1, 0));
 8560   movb(Address(tmp1, 0), rax);
 8561 
 8562   movb(rax, Address(buf, pos, Address::times_1, 1));
 8563   movb(Address(tmp1, 1), rax);
 8564 
 8565   movb(rax, Address(buf, pos, Address::times_1, 2));
 8566   movb(Address(tmp1, 2), rax);
 8567 
 8568   movdqu(xmm7, Address(rsp, 0));
 8569   pxor(xmm7, xmm0);                     //xor the initial crc value
 8570 
 8571   pslldq(xmm7, 0x5);
 8572   jmp(L_barrett);
 8573   bind(L_only_less_than_3);
 8574   cmpl(len, 2);
 8575   jcc(Assembler::less, L_only_less_than_2);
 8576 
 8577   // load 2 Bytes
 8578   movb(rax, Address(buf, pos, Address::times_1, 0));
 8579   movb(Address(tmp1, 0), rax);
 8580 
 8581   movb(rax, Address(buf, pos, Address::times_1, 1));
 8582   movb(Address(tmp1, 1), rax);
 8583 
 8584   movdqu(xmm7, Address(rsp, 0));
 8585   pxor(xmm7, xmm0);                     //xor the initial crc value
 8586 
 8587   pslldq(xmm7, 0x6);
 8588   jmp(L_barrett);
 8589 
 8590   bind(L_only_less_than_2);
 8591   //load 1 Byte
 8592   movb(rax, Address(buf, pos, Address::times_1, 0));
 8593   movb(Address(tmp1, 0), rax);
 8594 
 8595   movdqu(xmm7, Address(rsp, 0));
 8596   pxor(xmm7, xmm0);                     //xor the initial crc value
 8597 
 8598   pslldq(xmm7, 0x7);
 8599 }
 8600 
 8601 /**
 8602 * Compute CRC32 using AVX512 instructions
 8603 * param crc   register containing existing CRC (32-bit)
 8604 * param buf   register pointing to input byte buffer (byte*)
 8605 * param len   register containing number of bytes
 8606 * param table address of crc or crc32c table
 8607 * param tmp1  scratch register
 8608 * param tmp2  scratch register
 8609 * return rax  result register
 8610 *
 8611 * This routine is identical for crc32c with the exception of the precomputed constant
 8612 * table which will be passed as the table argument.  The calculation steps are
 8613 * the same for both variants.
 8614 */
 8615 void MacroAssembler::kernel_crc32_avx512(Register crc, Register buf, Register len, Register table, Register tmp1, Register tmp2) {
 8616   assert_different_registers(crc, buf, len, table, tmp1, tmp2, rax, r12);
 8617 
 8618   Label L_tail, L_tail_restore, L_tail_loop, L_exit, L_align_loop, L_aligned;
 8619   Label L_fold_tail, L_fold_128b, L_fold_512b, L_fold_512b_loop, L_fold_tail_loop;
 8620   Label L_less_than_256, L_fold_128_B_loop, L_fold_256_B_loop;
 8621   Label L_fold_128_B_register, L_final_reduction_for_128, L_16B_reduction_loop;
 8622   Label L_128_done, L_get_last_two_xmms, L_barrett, L_cleanup;
 8623 
 8624   const Register pos = r12;
 8625   push(r12);
 8626   subptr(rsp, 16 * 2 + 8);
 8627 
 8628   // For EVEX with VL and BW, provide a standard mask, VL = 128 will guide the merge
 8629   // context for the registers used, where all instructions below are using 128-bit mode
 8630   // On EVEX without VL and BW, these instructions will all be AVX.
 8631   movl(pos, 0);
 8632 
 8633   // check if smaller than 256B
 8634   cmpl(len, 256);
 8635   jcc(Assembler::less, L_less_than_256);
 8636 
 8637   // load the initial crc value
 8638   movdl(xmm10, crc);
 8639 
 8640   // receive the initial 64B data, xor the initial crc value
 8641   evmovdquq(xmm0, Address(buf, pos, Address::times_1, 0 * 64), Assembler::AVX_512bit);
 8642   evmovdquq(xmm4, Address(buf, pos, Address::times_1, 1 * 64), Assembler::AVX_512bit);
 8643   evpxorq(xmm0, xmm0, xmm10, Assembler::AVX_512bit);
 8644   evbroadcasti32x4(xmm10, Address(table, 2 * 16), Assembler::AVX_512bit); //zmm10 has rk3 and rk4
 8645 
 8646   subl(len, 256);
 8647   cmpl(len, 256);
 8648   jcc(Assembler::less, L_fold_128_B_loop);
 8649 
 8650   evmovdquq(xmm7, Address(buf, pos, Address::times_1, 2 * 64), Assembler::AVX_512bit);
 8651   evmovdquq(xmm8, Address(buf, pos, Address::times_1, 3 * 64), Assembler::AVX_512bit);
 8652   evbroadcasti32x4(xmm16, Address(table, 0 * 16), Assembler::AVX_512bit); //zmm16 has rk-1 and rk-2
 8653   subl(len, 256);
 8654 
 8655   bind(L_fold_256_B_loop);
 8656   addl(pos, 256);
 8657   fold512bit_crc32_avx512(xmm0, xmm16, xmm1, buf, pos, 0 * 64);
 8658   fold512bit_crc32_avx512(xmm4, xmm16, xmm1, buf, pos, 1 * 64);
 8659   fold512bit_crc32_avx512(xmm7, xmm16, xmm1, buf, pos, 2 * 64);
 8660   fold512bit_crc32_avx512(xmm8, xmm16, xmm1, buf, pos, 3 * 64);
 8661 
 8662   subl(len, 256);
 8663   jcc(Assembler::greaterEqual, L_fold_256_B_loop);
 8664 
 8665   // Fold 256 into 128
 8666   addl(pos, 256);
 8667   evpclmulqdq(xmm1, xmm0, xmm10, 0x01, Assembler::AVX_512bit);
 8668   evpclmulqdq(xmm2, xmm0, xmm10, 0x10, Assembler::AVX_512bit);
 8669   vpternlogq(xmm7, 0x96, xmm1, xmm2, Assembler::AVX_512bit); // xor ABC
 8670 
 8671   evpclmulqdq(xmm5, xmm4, xmm10, 0x01, Assembler::AVX_512bit);
 8672   evpclmulqdq(xmm6, xmm4, xmm10, 0x10, Assembler::AVX_512bit);
 8673   vpternlogq(xmm8, 0x96, xmm5, xmm6, Assembler::AVX_512bit); // xor ABC
 8674 
 8675   evmovdquq(xmm0, xmm7, Assembler::AVX_512bit);
 8676   evmovdquq(xmm4, xmm8, Assembler::AVX_512bit);
 8677 
 8678   addl(len, 128);
 8679   jmp(L_fold_128_B_register);
 8680 
 8681   // at this section of the code, there is 128 * x + y(0 <= y<128) bytes of buffer.The fold_128_B_loop
 8682   // loop will fold 128B at a time until we have 128 + y Bytes of buffer
 8683 
 8684   // fold 128B at a time.This section of the code folds 8 xmm registers in parallel
 8685   bind(L_fold_128_B_loop);
 8686   addl(pos, 128);
 8687   fold512bit_crc32_avx512(xmm0, xmm10, xmm1, buf, pos, 0 * 64);
 8688   fold512bit_crc32_avx512(xmm4, xmm10, xmm1, buf, pos, 1 * 64);
 8689 
 8690   subl(len, 128);
 8691   jcc(Assembler::greaterEqual, L_fold_128_B_loop);
 8692 
 8693   addl(pos, 128);
 8694 
 8695   // at this point, the buffer pointer is pointing at the last y Bytes of the buffer, where 0 <= y < 128
 8696   // the 128B of folded data is in 8 of the xmm registers : xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7
 8697   bind(L_fold_128_B_register);
 8698   evmovdquq(xmm16, Address(table, 5 * 16), Assembler::AVX_512bit); // multiply by rk9-rk16
 8699   evmovdquq(xmm11, Address(table, 9 * 16), Assembler::AVX_512bit); // multiply by rk17-rk20, rk1,rk2, 0,0
 8700   evpclmulqdq(xmm1, xmm0, xmm16, 0x01, Assembler::AVX_512bit);
 8701   evpclmulqdq(xmm2, xmm0, xmm16, 0x10, Assembler::AVX_512bit);
 8702   // save last that has no multiplicand
 8703   vextracti64x2(xmm7, xmm4, 3);
 8704 
 8705   evpclmulqdq(xmm5, xmm4, xmm11, 0x01, Assembler::AVX_512bit);
 8706   evpclmulqdq(xmm6, xmm4, xmm11, 0x10, Assembler::AVX_512bit);
 8707   // Needed later in reduction loop
 8708   movdqu(xmm10, Address(table, 1 * 16));
 8709   vpternlogq(xmm1, 0x96, xmm2, xmm5, Assembler::AVX_512bit); // xor ABC
 8710   vpternlogq(xmm1, 0x96, xmm6, xmm7, Assembler::AVX_512bit); // xor ABC
 8711 
 8712   // Swap 1,0,3,2 - 01 00 11 10
 8713   evshufi64x2(xmm8, xmm1, xmm1, 0x4e, Assembler::AVX_512bit);
 8714   evpxorq(xmm8, xmm8, xmm1, Assembler::AVX_256bit);
 8715   vextracti128(xmm5, xmm8, 1);
 8716   evpxorq(xmm7, xmm5, xmm8, Assembler::AVX_128bit);
 8717 
 8718   // instead of 128, we add 128 - 16 to the loop counter to save 1 instruction from the loop
 8719   // instead of a cmp instruction, we use the negative flag with the jl instruction
 8720   addl(len, 128 - 16);
 8721   jcc(Assembler::less, L_final_reduction_for_128);
 8722 
 8723   bind(L_16B_reduction_loop);
 8724   vpclmulqdq(xmm8, xmm7, xmm10, 0x01);
 8725   vpclmulqdq(xmm7, xmm7, xmm10, 0x10);
 8726   vpxor(xmm7, xmm7, xmm8, Assembler::AVX_128bit);
 8727   movdqu(xmm0, Address(buf, pos, Address::times_1, 0 * 16));
 8728   vpxor(xmm7, xmm7, xmm0, Assembler::AVX_128bit);
 8729   addl(pos, 16);
 8730   subl(len, 16);
 8731   jcc(Assembler::greaterEqual, L_16B_reduction_loop);
 8732 
 8733   bind(L_final_reduction_for_128);
 8734   addl(len, 16);
 8735   jcc(Assembler::equal, L_128_done);
 8736 
 8737   bind(L_get_last_two_xmms);
 8738   movdqu(xmm2, xmm7);
 8739   addl(pos, len);
 8740   movdqu(xmm1, Address(buf, pos, Address::times_1, -16));
 8741   subl(pos, len);
 8742 
 8743   // get rid of the extra data that was loaded before
 8744   // load the shift constant
 8745   lea(rax, ExternalAddress(StubRoutines::x86::shuf_table_crc32_avx512_addr()));
 8746   movdqu(xmm0, Address(rax, len));
 8747   addl(rax, len);
 8748 
 8749   vpshufb(xmm7, xmm7, xmm0, Assembler::AVX_128bit);
 8750   //Change mask to 512
 8751   vpxor(xmm0, xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_avx512_addr() + 2 * 16), Assembler::AVX_128bit, tmp2);
 8752   vpshufb(xmm2, xmm2, xmm0, Assembler::AVX_128bit);
 8753 
 8754   blendvpb(xmm2, xmm2, xmm1, xmm0, Assembler::AVX_128bit);
 8755   vpclmulqdq(xmm8, xmm7, xmm10, 0x01);
 8756   vpclmulqdq(xmm7, xmm7, xmm10, 0x10);
 8757   vpxor(xmm7, xmm7, xmm8, Assembler::AVX_128bit);
 8758   vpxor(xmm7, xmm7, xmm2, Assembler::AVX_128bit);
 8759 
 8760   bind(L_128_done);
 8761   // compute crc of a 128-bit value
 8762   movdqu(xmm10, Address(table, 3 * 16));
 8763   movdqu(xmm0, xmm7);
 8764 
 8765   // 64b fold
 8766   vpclmulqdq(xmm7, xmm7, xmm10, 0x0);
 8767   vpsrldq(xmm0, xmm0, 0x8, Assembler::AVX_128bit);
 8768   vpxor(xmm7, xmm7, xmm0, Assembler::AVX_128bit);
 8769 
 8770   // 32b fold
 8771   movdqu(xmm0, xmm7);
 8772   vpslldq(xmm7, xmm7, 0x4, Assembler::AVX_128bit);
 8773   vpclmulqdq(xmm7, xmm7, xmm10, 0x10);
 8774   vpxor(xmm7, xmm7, xmm0, Assembler::AVX_128bit);
 8775   jmp(L_barrett);
 8776 
 8777   bind(L_less_than_256);
 8778   kernel_crc32_avx512_256B(crc, buf, len, table, pos, tmp1, tmp2, L_barrett, L_16B_reduction_loop, L_get_last_two_xmms, L_128_done, L_cleanup);
 8779 
 8780   //barrett reduction
 8781   bind(L_barrett);
 8782   vpand(xmm7, xmm7, ExternalAddress(StubRoutines::x86::crc_by128_masks_avx512_addr() + 1 * 16), Assembler::AVX_128bit, tmp2);
 8783   movdqu(xmm1, xmm7);
 8784   movdqu(xmm2, xmm7);
 8785   movdqu(xmm10, Address(table, 4 * 16));
 8786 
 8787   pclmulqdq(xmm7, xmm10, 0x0);
 8788   pxor(xmm7, xmm2);
 8789   vpand(xmm7, xmm7, ExternalAddress(StubRoutines::x86::crc_by128_masks_avx512_addr()), Assembler::AVX_128bit, tmp2);
 8790   movdqu(xmm2, xmm7);
 8791   pclmulqdq(xmm7, xmm10, 0x10);
 8792   pxor(xmm7, xmm2);
 8793   pxor(xmm7, xmm1);
 8794   pextrd(crc, xmm7, 2);
 8795 
 8796   bind(L_cleanup);
 8797   addptr(rsp, 16 * 2 + 8);
 8798   pop(r12);
 8799 }
 8800 
 8801 // S. Gueron / Information Processing Letters 112 (2012) 184
 8802 // Algorithm 4: Computing carry-less multiplication using a precomputed lookup table.
 8803 // Input: A 32 bit value B = [byte3, byte2, byte1, byte0].
 8804 // Output: the 64-bit carry-less product of B * CONST
 8805 void MacroAssembler::crc32c_ipl_alg4(Register in, uint32_t n,
 8806                                      Register tmp1, Register tmp2, Register tmp3) {
 8807   lea(tmp3, ExternalAddress(StubRoutines::crc32c_table_addr()));
 8808   if (n > 0) {
 8809     addq(tmp3, n * 256 * 8);
 8810   }
 8811   //    Q1 = TABLEExt[n][B & 0xFF];
 8812   movl(tmp1, in);
 8813   andl(tmp1, 0x000000FF);
 8814   shll(tmp1, 3);
 8815   addq(tmp1, tmp3);
 8816   movq(tmp1, Address(tmp1, 0));
 8817 
 8818   //    Q2 = TABLEExt[n][B >> 8 & 0xFF];
 8819   movl(tmp2, in);
 8820   shrl(tmp2, 8);
 8821   andl(tmp2, 0x000000FF);
 8822   shll(tmp2, 3);
 8823   addq(tmp2, tmp3);
 8824   movq(tmp2, Address(tmp2, 0));
 8825 
 8826   shlq(tmp2, 8);
 8827   xorq(tmp1, tmp2);
 8828 
 8829   //    Q3 = TABLEExt[n][B >> 16 & 0xFF];
 8830   movl(tmp2, in);
 8831   shrl(tmp2, 16);
 8832   andl(tmp2, 0x000000FF);
 8833   shll(tmp2, 3);
 8834   addq(tmp2, tmp3);
 8835   movq(tmp2, Address(tmp2, 0));
 8836 
 8837   shlq(tmp2, 16);
 8838   xorq(tmp1, tmp2);
 8839 
 8840   //    Q4 = TABLEExt[n][B >> 24 & 0xFF];
 8841   shrl(in, 24);
 8842   andl(in, 0x000000FF);
 8843   shll(in, 3);
 8844   addq(in, tmp3);
 8845   movq(in, Address(in, 0));
 8846 
 8847   shlq(in, 24);
 8848   xorq(in, tmp1);
 8849   //    return Q1 ^ Q2 << 8 ^ Q3 << 16 ^ Q4 << 24;
 8850 }
 8851 
 8852 void MacroAssembler::crc32c_pclmulqdq(XMMRegister w_xtmp1,
 8853                                       Register in_out,
 8854                                       uint32_t const_or_pre_comp_const_index, bool is_pclmulqdq_supported,
 8855                                       XMMRegister w_xtmp2,
 8856                                       Register tmp1,
 8857                                       Register n_tmp2, Register n_tmp3) {
 8858   if (is_pclmulqdq_supported) {
 8859     movdl(w_xtmp1, in_out); // modified blindly
 8860 
 8861     movl(tmp1, const_or_pre_comp_const_index);
 8862     movdl(w_xtmp2, tmp1);
 8863     pclmulqdq(w_xtmp1, w_xtmp2, 0);
 8864 
 8865     movdq(in_out, w_xtmp1);
 8866   } else {
 8867     crc32c_ipl_alg4(in_out, const_or_pre_comp_const_index, tmp1, n_tmp2, n_tmp3);
 8868   }
 8869 }
 8870 
 8871 // Recombination Alternative 2: No bit-reflections
 8872 // T1 = (CRC_A * U1) << 1
 8873 // T2 = (CRC_B * U2) << 1
 8874 // C1 = T1 >> 32
 8875 // C2 = T2 >> 32
 8876 // T1 = T1 & 0xFFFFFFFF
 8877 // T2 = T2 & 0xFFFFFFFF
 8878 // T1 = CRC32(0, T1)
 8879 // T2 = CRC32(0, T2)
 8880 // C1 = C1 ^ T1
 8881 // C2 = C2 ^ T2
 8882 // CRC = C1 ^ C2 ^ CRC_C
 8883 void MacroAssembler::crc32c_rec_alt2(uint32_t const_or_pre_comp_const_index_u1, uint32_t const_or_pre_comp_const_index_u2, bool is_pclmulqdq_supported, Register in_out, Register in1, Register in2,
 8884                                      XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 8885                                      Register tmp1, Register tmp2,
 8886                                      Register n_tmp3) {
 8887   crc32c_pclmulqdq(w_xtmp1, in_out, const_or_pre_comp_const_index_u1, is_pclmulqdq_supported, w_xtmp3, tmp1, tmp2, n_tmp3);
 8888   crc32c_pclmulqdq(w_xtmp2, in1, const_or_pre_comp_const_index_u2, is_pclmulqdq_supported, w_xtmp3, tmp1, tmp2, n_tmp3);
 8889   shlq(in_out, 1);
 8890   movl(tmp1, in_out);
 8891   shrq(in_out, 32);
 8892   xorl(tmp2, tmp2);
 8893   crc32(tmp2, tmp1, 4);
 8894   xorl(in_out, tmp2); // we don't care about upper 32 bit contents here
 8895   shlq(in1, 1);
 8896   movl(tmp1, in1);
 8897   shrq(in1, 32);
 8898   xorl(tmp2, tmp2);
 8899   crc32(tmp2, tmp1, 4);
 8900   xorl(in1, tmp2);
 8901   xorl(in_out, in1);
 8902   xorl(in_out, in2);
 8903 }
 8904 
 8905 // Set N to predefined value
 8906 // Subtract from a length of a buffer
 8907 // execute in a loop:
 8908 // CRC_A = 0xFFFFFFFF, CRC_B = 0, CRC_C = 0
 8909 // for i = 1 to N do
 8910 //  CRC_A = CRC32(CRC_A, A[i])
 8911 //  CRC_B = CRC32(CRC_B, B[i])
 8912 //  CRC_C = CRC32(CRC_C, C[i])
 8913 // end for
 8914 // Recombine
 8915 void MacroAssembler::crc32c_proc_chunk(uint32_t size, uint32_t const_or_pre_comp_const_index_u1, uint32_t const_or_pre_comp_const_index_u2, bool is_pclmulqdq_supported,
 8916                                        Register in_out1, Register in_out2, Register in_out3,
 8917                                        Register tmp1, Register tmp2, Register tmp3,
 8918                                        XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 8919                                        Register tmp4, Register tmp5,
 8920                                        Register n_tmp6) {
 8921   Label L_processPartitions;
 8922   Label L_processPartition;
 8923   Label L_exit;
 8924 
 8925   bind(L_processPartitions);
 8926   cmpl(in_out1, 3 * size);
 8927   jcc(Assembler::less, L_exit);
 8928     xorl(tmp1, tmp1);
 8929     xorl(tmp2, tmp2);
 8930     movq(tmp3, in_out2);
 8931     addq(tmp3, size);
 8932 
 8933     bind(L_processPartition);
 8934       crc32(in_out3, Address(in_out2, 0), 8);
 8935       crc32(tmp1, Address(in_out2, size), 8);
 8936       crc32(tmp2, Address(in_out2, size * 2), 8);
 8937       addq(in_out2, 8);
 8938       cmpq(in_out2, tmp3);
 8939       jcc(Assembler::less, L_processPartition);
 8940     crc32c_rec_alt2(const_or_pre_comp_const_index_u1, const_or_pre_comp_const_index_u2, is_pclmulqdq_supported, in_out3, tmp1, tmp2,
 8941             w_xtmp1, w_xtmp2, w_xtmp3,
 8942             tmp4, tmp5,
 8943             n_tmp6);
 8944     addq(in_out2, 2 * size);
 8945     subl(in_out1, 3 * size);
 8946     jmp(L_processPartitions);
 8947 
 8948   bind(L_exit);
 8949 }
 8950 #else
 8951 void MacroAssembler::crc32c_ipl_alg4(Register in_out, uint32_t n,
 8952                                      Register tmp1, Register tmp2, Register tmp3,
 8953                                      XMMRegister xtmp1, XMMRegister xtmp2) {
 8954   lea(tmp3, ExternalAddress(StubRoutines::crc32c_table_addr()));
 8955   if (n > 0) {
 8956     addl(tmp3, n * 256 * 8);
 8957   }
 8958   //    Q1 = TABLEExt[n][B & 0xFF];
 8959   movl(tmp1, in_out);
 8960   andl(tmp1, 0x000000FF);
 8961   shll(tmp1, 3);
 8962   addl(tmp1, tmp3);
 8963   movq(xtmp1, Address(tmp1, 0));
 8964 
 8965   //    Q2 = TABLEExt[n][B >> 8 & 0xFF];
 8966   movl(tmp2, in_out);
 8967   shrl(tmp2, 8);
 8968   andl(tmp2, 0x000000FF);
 8969   shll(tmp2, 3);
 8970   addl(tmp2, tmp3);
 8971   movq(xtmp2, Address(tmp2, 0));
 8972 
 8973   psllq(xtmp2, 8);
 8974   pxor(xtmp1, xtmp2);
 8975 
 8976   //    Q3 = TABLEExt[n][B >> 16 & 0xFF];
 8977   movl(tmp2, in_out);
 8978   shrl(tmp2, 16);
 8979   andl(tmp2, 0x000000FF);
 8980   shll(tmp2, 3);
 8981   addl(tmp2, tmp3);
 8982   movq(xtmp2, Address(tmp2, 0));
 8983 
 8984   psllq(xtmp2, 16);
 8985   pxor(xtmp1, xtmp2);
 8986 
 8987   //    Q4 = TABLEExt[n][B >> 24 & 0xFF];
 8988   shrl(in_out, 24);
 8989   andl(in_out, 0x000000FF);
 8990   shll(in_out, 3);
 8991   addl(in_out, tmp3);
 8992   movq(xtmp2, Address(in_out, 0));
 8993 
 8994   psllq(xtmp2, 24);
 8995   pxor(xtmp1, xtmp2); // Result in CXMM
 8996   //    return Q1 ^ Q2 << 8 ^ Q3 << 16 ^ Q4 << 24;
 8997 }
 8998 
 8999 void MacroAssembler::crc32c_pclmulqdq(XMMRegister w_xtmp1,
 9000                                       Register in_out,
 9001                                       uint32_t const_or_pre_comp_const_index, bool is_pclmulqdq_supported,
 9002                                       XMMRegister w_xtmp2,
 9003                                       Register tmp1,
 9004                                       Register n_tmp2, Register n_tmp3) {
 9005   if (is_pclmulqdq_supported) {
 9006     movdl(w_xtmp1, in_out);
 9007 
 9008     movl(tmp1, const_or_pre_comp_const_index);
 9009     movdl(w_xtmp2, tmp1);
 9010     pclmulqdq(w_xtmp1, w_xtmp2, 0);
 9011     // Keep result in XMM since GPR is 32 bit in length
 9012   } else {
 9013     crc32c_ipl_alg4(in_out, const_or_pre_comp_const_index, tmp1, n_tmp2, n_tmp3, w_xtmp1, w_xtmp2);
 9014   }
 9015 }
 9016 
 9017 void MacroAssembler::crc32c_rec_alt2(uint32_t const_or_pre_comp_const_index_u1, uint32_t const_or_pre_comp_const_index_u2, bool is_pclmulqdq_supported, Register in_out, Register in1, Register in2,
 9018                                      XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 9019                                      Register tmp1, Register tmp2,
 9020                                      Register n_tmp3) {
 9021   crc32c_pclmulqdq(w_xtmp1, in_out, const_or_pre_comp_const_index_u1, is_pclmulqdq_supported, w_xtmp3, tmp1, tmp2, n_tmp3);
 9022   crc32c_pclmulqdq(w_xtmp2, in1, const_or_pre_comp_const_index_u2, is_pclmulqdq_supported, w_xtmp3, tmp1, tmp2, n_tmp3);
 9023 
 9024   psllq(w_xtmp1, 1);
 9025   movdl(tmp1, w_xtmp1);
 9026   psrlq(w_xtmp1, 32);
 9027   movdl(in_out, w_xtmp1);
 9028 
 9029   xorl(tmp2, tmp2);
 9030   crc32(tmp2, tmp1, 4);
 9031   xorl(in_out, tmp2);
 9032 
 9033   psllq(w_xtmp2, 1);
 9034   movdl(tmp1, w_xtmp2);
 9035   psrlq(w_xtmp2, 32);
 9036   movdl(in1, w_xtmp2);
 9037 
 9038   xorl(tmp2, tmp2);
 9039   crc32(tmp2, tmp1, 4);
 9040   xorl(in1, tmp2);
 9041   xorl(in_out, in1);
 9042   xorl(in_out, in2);
 9043 }
 9044 
 9045 void MacroAssembler::crc32c_proc_chunk(uint32_t size, uint32_t const_or_pre_comp_const_index_u1, uint32_t const_or_pre_comp_const_index_u2, bool is_pclmulqdq_supported,
 9046                                        Register in_out1, Register in_out2, Register in_out3,
 9047                                        Register tmp1, Register tmp2, Register tmp3,
 9048                                        XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 9049                                        Register tmp4, Register tmp5,
 9050                                        Register n_tmp6) {
 9051   Label L_processPartitions;
 9052   Label L_processPartition;
 9053   Label L_exit;
 9054 
 9055   bind(L_processPartitions);
 9056   cmpl(in_out1, 3 * size);
 9057   jcc(Assembler::less, L_exit);
 9058     xorl(tmp1, tmp1);
 9059     xorl(tmp2, tmp2);
 9060     movl(tmp3, in_out2);
 9061     addl(tmp3, size);
 9062 
 9063     bind(L_processPartition);
 9064       crc32(in_out3, Address(in_out2, 0), 4);
 9065       crc32(tmp1, Address(in_out2, size), 4);
 9066       crc32(tmp2, Address(in_out2, size*2), 4);
 9067       crc32(in_out3, Address(in_out2, 0+4), 4);
 9068       crc32(tmp1, Address(in_out2, size+4), 4);
 9069       crc32(tmp2, Address(in_out2, size*2+4), 4);
 9070       addl(in_out2, 8);
 9071       cmpl(in_out2, tmp3);
 9072       jcc(Assembler::less, L_processPartition);
 9073 
 9074         push(tmp3);
 9075         push(in_out1);
 9076         push(in_out2);
 9077         tmp4 = tmp3;
 9078         tmp5 = in_out1;
 9079         n_tmp6 = in_out2;
 9080 
 9081       crc32c_rec_alt2(const_or_pre_comp_const_index_u1, const_or_pre_comp_const_index_u2, is_pclmulqdq_supported, in_out3, tmp1, tmp2,
 9082             w_xtmp1, w_xtmp2, w_xtmp3,
 9083             tmp4, tmp5,
 9084             n_tmp6);
 9085 
 9086         pop(in_out2);
 9087         pop(in_out1);
 9088         pop(tmp3);
 9089 
 9090     addl(in_out2, 2 * size);
 9091     subl(in_out1, 3 * size);
 9092     jmp(L_processPartitions);
 9093 
 9094   bind(L_exit);
 9095 }
 9096 #endif //LP64
 9097 
 9098 #ifdef _LP64
 9099 // Algorithm 2: Pipelined usage of the CRC32 instruction.
 9100 // Input: A buffer I of L bytes.
 9101 // Output: the CRC32C value of the buffer.
 9102 // Notations:
 9103 // Write L = 24N + r, with N = floor (L/24).
 9104 // r = L mod 24 (0 <= r < 24).
 9105 // Consider I as the concatenation of A|B|C|R, where A, B, C, each,
 9106 // N quadwords, and R consists of r bytes.
 9107 // A[j] = I [8j+7:8j], j= 0, 1, ..., N-1
 9108 // B[j] = I [N + 8j+7:N + 8j], j= 0, 1, ..., N-1
 9109 // C[j] = I [2N + 8j+7:2N + 8j], j= 0, 1, ..., N-1
 9110 // if r > 0 R[j] = I [3N +j], j= 0, 1, ...,r-1
 9111 void MacroAssembler::crc32c_ipl_alg2_alt2(Register in_out, Register in1, Register in2,
 9112                                           Register tmp1, Register tmp2, Register tmp3,
 9113                                           Register tmp4, Register tmp5, Register tmp6,
 9114                                           XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 9115                                           bool is_pclmulqdq_supported) {
 9116   uint32_t const_or_pre_comp_const_index[CRC32C_NUM_PRECOMPUTED_CONSTANTS];
 9117   Label L_wordByWord;
 9118   Label L_byteByByteProlog;
 9119   Label L_byteByByte;
 9120   Label L_exit;
 9121 
 9122   if (is_pclmulqdq_supported ) {
 9123     const_or_pre_comp_const_index[1] = *(uint32_t *)StubRoutines::_crc32c_table_addr;
 9124     const_or_pre_comp_const_index[0] = *((uint32_t *)StubRoutines::_crc32c_table_addr+1);
 9125 
 9126     const_or_pre_comp_const_index[3] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 2);
 9127     const_or_pre_comp_const_index[2] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 3);
 9128 
 9129     const_or_pre_comp_const_index[5] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 4);
 9130     const_or_pre_comp_const_index[4] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 5);
 9131     assert((CRC32C_NUM_PRECOMPUTED_CONSTANTS - 1 ) == 5, "Checking whether you declared all of the constants based on the number of \"chunks\"");
 9132   } else {
 9133     const_or_pre_comp_const_index[0] = 1;
 9134     const_or_pre_comp_const_index[1] = 0;
 9135 
 9136     const_or_pre_comp_const_index[2] = 3;
 9137     const_or_pre_comp_const_index[3] = 2;
 9138 
 9139     const_or_pre_comp_const_index[4] = 5;
 9140     const_or_pre_comp_const_index[5] = 4;
 9141    }
 9142   crc32c_proc_chunk(CRC32C_HIGH, const_or_pre_comp_const_index[0], const_or_pre_comp_const_index[1], is_pclmulqdq_supported,
 9143                     in2, in1, in_out,
 9144                     tmp1, tmp2, tmp3,
 9145                     w_xtmp1, w_xtmp2, w_xtmp3,
 9146                     tmp4, tmp5,
 9147                     tmp6);
 9148   crc32c_proc_chunk(CRC32C_MIDDLE, const_or_pre_comp_const_index[2], const_or_pre_comp_const_index[3], is_pclmulqdq_supported,
 9149                     in2, in1, in_out,
 9150                     tmp1, tmp2, tmp3,
 9151                     w_xtmp1, w_xtmp2, w_xtmp3,
 9152                     tmp4, tmp5,
 9153                     tmp6);
 9154   crc32c_proc_chunk(CRC32C_LOW, const_or_pre_comp_const_index[4], const_or_pre_comp_const_index[5], is_pclmulqdq_supported,
 9155                     in2, in1, in_out,
 9156                     tmp1, tmp2, tmp3,
 9157                     w_xtmp1, w_xtmp2, w_xtmp3,
 9158                     tmp4, tmp5,
 9159                     tmp6);
 9160   movl(tmp1, in2);
 9161   andl(tmp1, 0x00000007);
 9162   negl(tmp1);
 9163   addl(tmp1, in2);
 9164   addq(tmp1, in1);
 9165 
 9166   cmpq(in1, tmp1);
 9167   jccb(Assembler::greaterEqual, L_byteByByteProlog);
 9168   align(16);
 9169   BIND(L_wordByWord);
 9170     crc32(in_out, Address(in1, 0), 8);
 9171     addq(in1, 8);
 9172     cmpq(in1, tmp1);
 9173     jcc(Assembler::less, L_wordByWord);
 9174 
 9175   BIND(L_byteByByteProlog);
 9176   andl(in2, 0x00000007);
 9177   movl(tmp2, 1);
 9178 
 9179   cmpl(tmp2, in2);
 9180   jccb(Assembler::greater, L_exit);
 9181   BIND(L_byteByByte);
 9182     crc32(in_out, Address(in1, 0), 1);
 9183     incq(in1);
 9184     incl(tmp2);
 9185     cmpl(tmp2, in2);
 9186     jcc(Assembler::lessEqual, L_byteByByte);
 9187 
 9188   BIND(L_exit);
 9189 }
 9190 #else
 9191 void MacroAssembler::crc32c_ipl_alg2_alt2(Register in_out, Register in1, Register in2,
 9192                                           Register tmp1, Register  tmp2, Register tmp3,
 9193                                           Register tmp4, Register  tmp5, Register tmp6,
 9194                                           XMMRegister w_xtmp1, XMMRegister w_xtmp2, XMMRegister w_xtmp3,
 9195                                           bool is_pclmulqdq_supported) {
 9196   uint32_t const_or_pre_comp_const_index[CRC32C_NUM_PRECOMPUTED_CONSTANTS];
 9197   Label L_wordByWord;
 9198   Label L_byteByByteProlog;
 9199   Label L_byteByByte;
 9200   Label L_exit;
 9201 
 9202   if (is_pclmulqdq_supported) {
 9203     const_or_pre_comp_const_index[1] = *(uint32_t *)StubRoutines::_crc32c_table_addr;
 9204     const_or_pre_comp_const_index[0] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 1);
 9205 
 9206     const_or_pre_comp_const_index[3] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 2);
 9207     const_or_pre_comp_const_index[2] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 3);
 9208 
 9209     const_or_pre_comp_const_index[5] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 4);
 9210     const_or_pre_comp_const_index[4] = *((uint32_t *)StubRoutines::_crc32c_table_addr + 5);
 9211   } else {
 9212     const_or_pre_comp_const_index[0] = 1;
 9213     const_or_pre_comp_const_index[1] = 0;
 9214 
 9215     const_or_pre_comp_const_index[2] = 3;
 9216     const_or_pre_comp_const_index[3] = 2;
 9217 
 9218     const_or_pre_comp_const_index[4] = 5;
 9219     const_or_pre_comp_const_index[5] = 4;
 9220   }
 9221   crc32c_proc_chunk(CRC32C_HIGH, const_or_pre_comp_const_index[0], const_or_pre_comp_const_index[1], is_pclmulqdq_supported,
 9222                     in2, in1, in_out,
 9223                     tmp1, tmp2, tmp3,
 9224                     w_xtmp1, w_xtmp2, w_xtmp3,
 9225                     tmp4, tmp5,
 9226                     tmp6);
 9227   crc32c_proc_chunk(CRC32C_MIDDLE, const_or_pre_comp_const_index[2], const_or_pre_comp_const_index[3], is_pclmulqdq_supported,
 9228                     in2, in1, in_out,
 9229                     tmp1, tmp2, tmp3,
 9230                     w_xtmp1, w_xtmp2, w_xtmp3,
 9231                     tmp4, tmp5,
 9232                     tmp6);
 9233   crc32c_proc_chunk(CRC32C_LOW, const_or_pre_comp_const_index[4], const_or_pre_comp_const_index[5], is_pclmulqdq_supported,
 9234                     in2, in1, in_out,
 9235                     tmp1, tmp2, tmp3,
 9236                     w_xtmp1, w_xtmp2, w_xtmp3,
 9237                     tmp4, tmp5,
 9238                     tmp6);
 9239   movl(tmp1, in2);
 9240   andl(tmp1, 0x00000007);
 9241   negl(tmp1);
 9242   addl(tmp1, in2);
 9243   addl(tmp1, in1);
 9244 
 9245   BIND(L_wordByWord);
 9246   cmpl(in1, tmp1);
 9247   jcc(Assembler::greaterEqual, L_byteByByteProlog);
 9248     crc32(in_out, Address(in1,0), 4);
 9249     addl(in1, 4);
 9250     jmp(L_wordByWord);
 9251 
 9252   BIND(L_byteByByteProlog);
 9253   andl(in2, 0x00000007);
 9254   movl(tmp2, 1);
 9255 
 9256   BIND(L_byteByByte);
 9257   cmpl(tmp2, in2);
 9258   jccb(Assembler::greater, L_exit);
 9259     movb(tmp1, Address(in1, 0));
 9260     crc32(in_out, tmp1, 1);
 9261     incl(in1);
 9262     incl(tmp2);
 9263     jmp(L_byteByByte);
 9264 
 9265   BIND(L_exit);
 9266 }
 9267 #endif // LP64
 9268 #undef BIND
 9269 #undef BLOCK_COMMENT
 9270 
 9271 // Compress char[] array to byte[].
 9272 // Intrinsic for java.lang.StringUTF16.compress(char[] src, int srcOff, byte[] dst, int dstOff, int len)
 9273 // Return the array length if every element in array can be encoded,
 9274 // otherwise, the index of first non-latin1 (> 0xff) character.
 9275 //   @IntrinsicCandidate
 9276 //   public static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
 9277 //     for (int i = 0; i < len; i++) {
 9278 //       char c = src[srcOff];
 9279 //       if (c > 0xff) {
 9280 //           return i;  // return index of non-latin1 char
 9281 //       }
 9282 //       dst[dstOff] = (byte)c;
 9283 //       srcOff++;
 9284 //       dstOff++;
 9285 //     }
 9286 //     return len;
 9287 //   }
 9288 void MacroAssembler::char_array_compress(Register src, Register dst, Register len,
 9289   XMMRegister tmp1Reg, XMMRegister tmp2Reg,
 9290   XMMRegister tmp3Reg, XMMRegister tmp4Reg,
 9291   Register tmp5, Register result, KRegister mask1, KRegister mask2) {
 9292   Label copy_chars_loop, done, reset_sp, copy_tail;
 9293 
 9294   // rsi: src
 9295   // rdi: dst
 9296   // rdx: len
 9297   // rcx: tmp5
 9298   // rax: result
 9299 
 9300   // rsi holds start addr of source char[] to be compressed
 9301   // rdi holds start addr of destination byte[]
 9302   // rdx holds length
 9303 
 9304   assert(len != result, "");
 9305 
 9306   // save length for return
 9307   movl(result, len);
 9308 
 9309   if ((AVX3Threshold == 0) && (UseAVX > 2) && // AVX512
 9310     VM_Version::supports_avx512vlbw() &&
 9311     VM_Version::supports_bmi2()) {
 9312 
 9313     Label copy_32_loop, copy_loop_tail, below_threshold, reset_for_copy_tail;
 9314 
 9315     // alignment
 9316     Label post_alignment;
 9317 
 9318     // if length of the string is less than 32, handle it the old fashioned way
 9319     testl(len, -32);
 9320     jcc(Assembler::zero, below_threshold);
 9321 
 9322     // First check whether a character is compressible ( <= 0xFF).
 9323     // Create mask to test for Unicode chars inside zmm vector
 9324     movl(tmp5, 0x00FF);
 9325     evpbroadcastw(tmp2Reg, tmp5, Assembler::AVX_512bit);
 9326 
 9327     testl(len, -64);
 9328     jccb(Assembler::zero, post_alignment);
 9329 
 9330     movl(tmp5, dst);
 9331     andl(tmp5, (32 - 1));
 9332     negl(tmp5);
 9333     andl(tmp5, (32 - 1));
 9334 
 9335     // bail out when there is nothing to be done
 9336     testl(tmp5, 0xFFFFFFFF);
 9337     jccb(Assembler::zero, post_alignment);
 9338 
 9339     // ~(~0 << len), where len is the # of remaining elements to process
 9340     movl(len, 0xFFFFFFFF);
 9341     shlxl(len, len, tmp5);
 9342     notl(len);
 9343     kmovdl(mask2, len);
 9344     movl(len, result);
 9345 
 9346     evmovdquw(tmp1Reg, mask2, Address(src, 0), /*merge*/ false, Assembler::AVX_512bit);
 9347     evpcmpw(mask1, mask2, tmp1Reg, tmp2Reg, Assembler::le, /*signed*/ false, Assembler::AVX_512bit);
 9348     ktestd(mask1, mask2);
 9349     jcc(Assembler::carryClear, copy_tail);
 9350 
 9351     evpmovwb(Address(dst, 0), mask2, tmp1Reg, Assembler::AVX_512bit);
 9352 
 9353     addptr(src, tmp5);
 9354     addptr(src, tmp5);
 9355     addptr(dst, tmp5);
 9356     subl(len, tmp5);
 9357 
 9358     bind(post_alignment);
 9359     // end of alignment
 9360 
 9361     movl(tmp5, len);
 9362     andl(tmp5, (32 - 1));    // tail count (in chars)
 9363     andl(len, ~(32 - 1));    // vector count (in chars)
 9364     jccb(Assembler::zero, copy_loop_tail);
 9365 
 9366     lea(src, Address(src, len, Address::times_2));
 9367     lea(dst, Address(dst, len, Address::times_1));
 9368     negptr(len);
 9369 
 9370     bind(copy_32_loop);
 9371     evmovdquw(tmp1Reg, Address(src, len, Address::times_2), Assembler::AVX_512bit);
 9372     evpcmpuw(mask1, tmp1Reg, tmp2Reg, Assembler::le, Assembler::AVX_512bit);
 9373     kortestdl(mask1, mask1);
 9374     jccb(Assembler::carryClear, reset_for_copy_tail);
 9375 
 9376     // All elements in current processed chunk are valid candidates for
 9377     // compression. Write a truncated byte elements to the memory.
 9378     evpmovwb(Address(dst, len, Address::times_1), tmp1Reg, Assembler::AVX_512bit);
 9379     addptr(len, 32);
 9380     jccb(Assembler::notZero, copy_32_loop);
 9381 
 9382     bind(copy_loop_tail);
 9383     // bail out when there is nothing to be done
 9384     testl(tmp5, 0xFFFFFFFF);
 9385     jcc(Assembler::zero, done);
 9386 
 9387     movl(len, tmp5);
 9388 
 9389     // ~(~0 << len), where len is the # of remaining elements to process
 9390     movl(tmp5, 0xFFFFFFFF);
 9391     shlxl(tmp5, tmp5, len);
 9392     notl(tmp5);
 9393 
 9394     kmovdl(mask2, tmp5);
 9395 
 9396     evmovdquw(tmp1Reg, mask2, Address(src, 0), /*merge*/ false, Assembler::AVX_512bit);
 9397     evpcmpw(mask1, mask2, tmp1Reg, tmp2Reg, Assembler::le, /*signed*/ false, Assembler::AVX_512bit);
 9398     ktestd(mask1, mask2);
 9399     jcc(Assembler::carryClear, copy_tail);
 9400 
 9401     evpmovwb(Address(dst, 0), mask2, tmp1Reg, Assembler::AVX_512bit);
 9402     jmp(done);
 9403 
 9404     bind(reset_for_copy_tail);
 9405     lea(src, Address(src, tmp5, Address::times_2));
 9406     lea(dst, Address(dst, tmp5, Address::times_1));
 9407     subptr(len, tmp5);
 9408     jmp(copy_chars_loop);
 9409 
 9410     bind(below_threshold);
 9411   }
 9412 
 9413   if (UseSSE42Intrinsics) {
 9414     Label copy_32_loop, copy_16, copy_tail_sse, reset_for_copy_tail;
 9415 
 9416     // vectored compression
 9417     testl(len, 0xfffffff8);
 9418     jcc(Assembler::zero, copy_tail);
 9419 
 9420     movl(tmp5, 0xff00ff00);   // create mask to test for Unicode chars in vectors
 9421     movdl(tmp1Reg, tmp5);
 9422     pshufd(tmp1Reg, tmp1Reg, 0);   // store Unicode mask in tmp1Reg
 9423 
 9424     andl(len, 0xfffffff0);
 9425     jccb(Assembler::zero, copy_16);
 9426 
 9427     // compress 16 chars per iter
 9428     pxor(tmp4Reg, tmp4Reg);
 9429 
 9430     lea(src, Address(src, len, Address::times_2));
 9431     lea(dst, Address(dst, len, Address::times_1));
 9432     negptr(len);
 9433 
 9434     bind(copy_32_loop);
 9435     movdqu(tmp2Reg, Address(src, len, Address::times_2));     // load 1st 8 characters
 9436     por(tmp4Reg, tmp2Reg);
 9437     movdqu(tmp3Reg, Address(src, len, Address::times_2, 16)); // load next 8 characters
 9438     por(tmp4Reg, tmp3Reg);
 9439     ptest(tmp4Reg, tmp1Reg);       // check for Unicode chars in next vector
 9440     jccb(Assembler::notZero, reset_for_copy_tail);
 9441     packuswb(tmp2Reg, tmp3Reg);    // only ASCII chars; compress each to 1 byte
 9442     movdqu(Address(dst, len, Address::times_1), tmp2Reg);
 9443     addptr(len, 16);
 9444     jccb(Assembler::notZero, copy_32_loop);
 9445 
 9446     // compress next vector of 8 chars (if any)
 9447     bind(copy_16);
 9448     // len = 0
 9449     testl(result, 0x00000008);     // check if there's a block of 8 chars to compress
 9450     jccb(Assembler::zero, copy_tail_sse);
 9451 
 9452     pxor(tmp3Reg, tmp3Reg);
 9453 
 9454     movdqu(tmp2Reg, Address(src, 0));
 9455     ptest(tmp2Reg, tmp1Reg);       // check for Unicode chars in vector
 9456     jccb(Assembler::notZero, reset_for_copy_tail);
 9457     packuswb(tmp2Reg, tmp3Reg);    // only LATIN1 chars; compress each to 1 byte
 9458     movq(Address(dst, 0), tmp2Reg);
 9459     addptr(src, 16);
 9460     addptr(dst, 8);
 9461     jmpb(copy_tail_sse);
 9462 
 9463     bind(reset_for_copy_tail);
 9464     movl(tmp5, result);
 9465     andl(tmp5, 0x0000000f);
 9466     lea(src, Address(src, tmp5, Address::times_2));
 9467     lea(dst, Address(dst, tmp5, Address::times_1));
 9468     subptr(len, tmp5);
 9469     jmpb(copy_chars_loop);
 9470 
 9471     bind(copy_tail_sse);
 9472     movl(len, result);
 9473     andl(len, 0x00000007);    // tail count (in chars)
 9474   }
 9475   // compress 1 char per iter
 9476   bind(copy_tail);
 9477   testl(len, len);
 9478   jccb(Assembler::zero, done);
 9479   lea(src, Address(src, len, Address::times_2));
 9480   lea(dst, Address(dst, len, Address::times_1));
 9481   negptr(len);
 9482 
 9483   bind(copy_chars_loop);
 9484   load_unsigned_short(tmp5, Address(src, len, Address::times_2));
 9485   testl(tmp5, 0xff00);      // check if Unicode char
 9486   jccb(Assembler::notZero, reset_sp);
 9487   movb(Address(dst, len, Address::times_1), tmp5);  // ASCII char; compress to 1 byte
 9488   increment(len);
 9489   jccb(Assembler::notZero, copy_chars_loop);
 9490 
 9491   // add len then return (len will be zero if compress succeeded, otherwise negative)
 9492   bind(reset_sp);
 9493   addl(result, len);
 9494 
 9495   bind(done);
 9496 }
 9497 
 9498 // Inflate byte[] array to char[].
 9499 //   ..\jdk\src\java.base\share\classes\java\lang\StringLatin1.java
 9500 //   @IntrinsicCandidate
 9501 //   private static void inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
 9502 //     for (int i = 0; i < len; i++) {
 9503 //       dst[dstOff++] = (char)(src[srcOff++] & 0xff);
 9504 //     }
 9505 //   }
 9506 void MacroAssembler::byte_array_inflate(Register src, Register dst, Register len,
 9507   XMMRegister tmp1, Register tmp2, KRegister mask) {
 9508   Label copy_chars_loop, done, below_threshold, avx3_threshold;
 9509   // rsi: src
 9510   // rdi: dst
 9511   // rdx: len
 9512   // rcx: tmp2
 9513 
 9514   // rsi holds start addr of source byte[] to be inflated
 9515   // rdi holds start addr of destination char[]
 9516   // rdx holds length
 9517   assert_different_registers(src, dst, len, tmp2);
 9518   movl(tmp2, len);
 9519   if ((UseAVX > 2) && // AVX512
 9520     VM_Version::supports_avx512vlbw() &&
 9521     VM_Version::supports_bmi2()) {
 9522 
 9523     Label copy_32_loop, copy_tail;
 9524     Register tmp3_aliased = len;
 9525 
 9526     // if length of the string is less than 16, handle it in an old fashioned way
 9527     testl(len, -16);
 9528     jcc(Assembler::zero, below_threshold);
 9529 
 9530     testl(len, -1 * AVX3Threshold);
 9531     jcc(Assembler::zero, avx3_threshold);
 9532 
 9533     // In order to use only one arithmetic operation for the main loop we use
 9534     // this pre-calculation
 9535     andl(tmp2, (32 - 1)); // tail count (in chars), 32 element wide loop
 9536     andl(len, -32);     // vector count
 9537     jccb(Assembler::zero, copy_tail);
 9538 
 9539     lea(src, Address(src, len, Address::times_1));
 9540     lea(dst, Address(dst, len, Address::times_2));
 9541     negptr(len);
 9542 
 9543 
 9544     // inflate 32 chars per iter
 9545     bind(copy_32_loop);
 9546     vpmovzxbw(tmp1, Address(src, len, Address::times_1), Assembler::AVX_512bit);
 9547     evmovdquw(Address(dst, len, Address::times_2), tmp1, Assembler::AVX_512bit);
 9548     addptr(len, 32);
 9549     jcc(Assembler::notZero, copy_32_loop);
 9550 
 9551     bind(copy_tail);
 9552     // bail out when there is nothing to be done
 9553     testl(tmp2, -1); // we don't destroy the contents of tmp2 here
 9554     jcc(Assembler::zero, done);
 9555 
 9556     // ~(~0 << length), where length is the # of remaining elements to process
 9557     movl(tmp3_aliased, -1);
 9558     shlxl(tmp3_aliased, tmp3_aliased, tmp2);
 9559     notl(tmp3_aliased);
 9560     kmovdl(mask, tmp3_aliased);
 9561     evpmovzxbw(tmp1, mask, Address(src, 0), Assembler::AVX_512bit);
 9562     evmovdquw(Address(dst, 0), mask, tmp1, /*merge*/ true, Assembler::AVX_512bit);
 9563 
 9564     jmp(done);
 9565     bind(avx3_threshold);
 9566   }
 9567   if (UseSSE42Intrinsics) {
 9568     Label copy_16_loop, copy_8_loop, copy_bytes, copy_new_tail, copy_tail;
 9569 
 9570     if (UseAVX > 1) {
 9571       andl(tmp2, (16 - 1));
 9572       andl(len, -16);
 9573       jccb(Assembler::zero, copy_new_tail);
 9574     } else {
 9575       andl(tmp2, 0x00000007);   // tail count (in chars)
 9576       andl(len, 0xfffffff8);    // vector count (in chars)
 9577       jccb(Assembler::zero, copy_tail);
 9578     }
 9579 
 9580     // vectored inflation
 9581     lea(src, Address(src, len, Address::times_1));
 9582     lea(dst, Address(dst, len, Address::times_2));
 9583     negptr(len);
 9584 
 9585     if (UseAVX > 1) {
 9586       bind(copy_16_loop);
 9587       vpmovzxbw(tmp1, Address(src, len, Address::times_1), Assembler::AVX_256bit);
 9588       vmovdqu(Address(dst, len, Address::times_2), tmp1);
 9589       addptr(len, 16);
 9590       jcc(Assembler::notZero, copy_16_loop);
 9591 
 9592       bind(below_threshold);
 9593       bind(copy_new_tail);
 9594       movl(len, tmp2);
 9595       andl(tmp2, 0x00000007);
 9596       andl(len, 0xFFFFFFF8);
 9597       jccb(Assembler::zero, copy_tail);
 9598 
 9599       pmovzxbw(tmp1, Address(src, 0));
 9600       movdqu(Address(dst, 0), tmp1);
 9601       addptr(src, 8);
 9602       addptr(dst, 2 * 8);
 9603 
 9604       jmp(copy_tail, true);
 9605     }
 9606 
 9607     // inflate 8 chars per iter
 9608     bind(copy_8_loop);
 9609     pmovzxbw(tmp1, Address(src, len, Address::times_1));  // unpack to 8 words
 9610     movdqu(Address(dst, len, Address::times_2), tmp1);
 9611     addptr(len, 8);
 9612     jcc(Assembler::notZero, copy_8_loop);
 9613 
 9614     bind(copy_tail);
 9615     movl(len, tmp2);
 9616 
 9617     cmpl(len, 4);
 9618     jccb(Assembler::less, copy_bytes);
 9619 
 9620     movdl(tmp1, Address(src, 0));  // load 4 byte chars
 9621     pmovzxbw(tmp1, tmp1);
 9622     movq(Address(dst, 0), tmp1);
 9623     subptr(len, 4);
 9624     addptr(src, 4);
 9625     addptr(dst, 8);
 9626 
 9627     bind(copy_bytes);
 9628   } else {
 9629     bind(below_threshold);
 9630   }
 9631 
 9632   testl(len, len);
 9633   jccb(Assembler::zero, done);
 9634   lea(src, Address(src, len, Address::times_1));
 9635   lea(dst, Address(dst, len, Address::times_2));
 9636   negptr(len);
 9637 
 9638   // inflate 1 char per iter
 9639   bind(copy_chars_loop);
 9640   load_unsigned_byte(tmp2, Address(src, len, Address::times_1));  // load byte char
 9641   movw(Address(dst, len, Address::times_2), tmp2);  // inflate byte char to word
 9642   increment(len);
 9643   jcc(Assembler::notZero, copy_chars_loop);
 9644 
 9645   bind(done);
 9646 }
 9647 
 9648 void MacroAssembler::evmovdqu(BasicType type, KRegister kmask, XMMRegister dst, XMMRegister src, bool merge, int vector_len) {
 9649   switch(type) {
 9650     case T_BYTE:
 9651     case T_BOOLEAN:
 9652       evmovdqub(dst, kmask, src, merge, vector_len);
 9653       break;
 9654     case T_CHAR:
 9655     case T_SHORT:
 9656       evmovdquw(dst, kmask, src, merge, vector_len);
 9657       break;
 9658     case T_INT:
 9659     case T_FLOAT:
 9660       evmovdqul(dst, kmask, src, merge, vector_len);
 9661       break;
 9662     case T_LONG:
 9663     case T_DOUBLE:
 9664       evmovdquq(dst, kmask, src, merge, vector_len);
 9665       break;
 9666     default:
 9667       fatal("Unexpected type argument %s", type2name(type));
 9668       break;
 9669   }
 9670 }
 9671 
 9672 
 9673 void MacroAssembler::evmovdqu(BasicType type, KRegister kmask, XMMRegister dst, Address src, bool merge, int vector_len) {
 9674   switch(type) {
 9675     case T_BYTE:
 9676     case T_BOOLEAN:
 9677       evmovdqub(dst, kmask, src, merge, vector_len);
 9678       break;
 9679     case T_CHAR:
 9680     case T_SHORT:
 9681       evmovdquw(dst, kmask, src, merge, vector_len);
 9682       break;
 9683     case T_INT:
 9684     case T_FLOAT:
 9685       evmovdqul(dst, kmask, src, merge, vector_len);
 9686       break;
 9687     case T_LONG:
 9688     case T_DOUBLE:
 9689       evmovdquq(dst, kmask, src, merge, vector_len);
 9690       break;
 9691     default:
 9692       fatal("Unexpected type argument %s", type2name(type));
 9693       break;
 9694   }
 9695 }
 9696 
 9697 void MacroAssembler::evmovdqu(BasicType type, KRegister kmask, Address dst, XMMRegister src, bool merge, int vector_len) {
 9698   switch(type) {
 9699     case T_BYTE:
 9700     case T_BOOLEAN:
 9701       evmovdqub(dst, kmask, src, merge, vector_len);
 9702       break;
 9703     case T_CHAR:
 9704     case T_SHORT:
 9705       evmovdquw(dst, kmask, src, merge, vector_len);
 9706       break;
 9707     case T_INT:
 9708     case T_FLOAT:
 9709       evmovdqul(dst, kmask, src, merge, vector_len);
 9710       break;
 9711     case T_LONG:
 9712     case T_DOUBLE:
 9713       evmovdquq(dst, kmask, src, merge, vector_len);
 9714       break;
 9715     default:
 9716       fatal("Unexpected type argument %s", type2name(type));
 9717       break;
 9718   }
 9719 }
 9720 
 9721 void MacroAssembler::knot(uint masklen, KRegister dst, KRegister src, KRegister ktmp, Register rtmp) {
 9722   switch(masklen) {
 9723     case 2:
 9724        knotbl(dst, src);
 9725        movl(rtmp, 3);
 9726        kmovbl(ktmp, rtmp);
 9727        kandbl(dst, ktmp, dst);
 9728        break;
 9729     case 4:
 9730        knotbl(dst, src);
 9731        movl(rtmp, 15);
 9732        kmovbl(ktmp, rtmp);
 9733        kandbl(dst, ktmp, dst);
 9734        break;
 9735     case 8:
 9736        knotbl(dst, src);
 9737        break;
 9738     case 16:
 9739        knotwl(dst, src);
 9740        break;
 9741     case 32:
 9742        knotdl(dst, src);
 9743        break;
 9744     case 64:
 9745        knotql(dst, src);
 9746        break;
 9747     default:
 9748       fatal("Unexpected vector length %d", masklen);
 9749       break;
 9750   }
 9751 }
 9752 
 9753 void MacroAssembler::kand(BasicType type, KRegister dst, KRegister src1, KRegister src2) {
 9754   switch(type) {
 9755     case T_BOOLEAN:
 9756     case T_BYTE:
 9757        kandbl(dst, src1, src2);
 9758        break;
 9759     case T_CHAR:
 9760     case T_SHORT:
 9761        kandwl(dst, src1, src2);
 9762        break;
 9763     case T_INT:
 9764     case T_FLOAT:
 9765        kanddl(dst, src1, src2);
 9766        break;
 9767     case T_LONG:
 9768     case T_DOUBLE:
 9769        kandql(dst, src1, src2);
 9770        break;
 9771     default:
 9772       fatal("Unexpected type argument %s", type2name(type));
 9773       break;
 9774   }
 9775 }
 9776 
 9777 void MacroAssembler::kor(BasicType type, KRegister dst, KRegister src1, KRegister src2) {
 9778   switch(type) {
 9779     case T_BOOLEAN:
 9780     case T_BYTE:
 9781        korbl(dst, src1, src2);
 9782        break;
 9783     case T_CHAR:
 9784     case T_SHORT:
 9785        korwl(dst, src1, src2);
 9786        break;
 9787     case T_INT:
 9788     case T_FLOAT:
 9789        kordl(dst, src1, src2);
 9790        break;
 9791     case T_LONG:
 9792     case T_DOUBLE:
 9793        korql(dst, src1, src2);
 9794        break;
 9795     default:
 9796       fatal("Unexpected type argument %s", type2name(type));
 9797       break;
 9798   }
 9799 }
 9800 
 9801 void MacroAssembler::kxor(BasicType type, KRegister dst, KRegister src1, KRegister src2) {
 9802   switch(type) {
 9803     case T_BOOLEAN:
 9804     case T_BYTE:
 9805        kxorbl(dst, src1, src2);
 9806        break;
 9807     case T_CHAR:
 9808     case T_SHORT:
 9809        kxorwl(dst, src1, src2);
 9810        break;
 9811     case T_INT:
 9812     case T_FLOAT:
 9813        kxordl(dst, src1, src2);
 9814        break;
 9815     case T_LONG:
 9816     case T_DOUBLE:
 9817        kxorql(dst, src1, src2);
 9818        break;
 9819     default:
 9820       fatal("Unexpected type argument %s", type2name(type));
 9821       break;
 9822   }
 9823 }
 9824 
 9825 void MacroAssembler::evperm(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9826   switch(type) {
 9827     case T_BOOLEAN:
 9828     case T_BYTE:
 9829       evpermb(dst, mask, nds, src, merge, vector_len); break;
 9830     case T_CHAR:
 9831     case T_SHORT:
 9832       evpermw(dst, mask, nds, src, merge, vector_len); break;
 9833     case T_INT:
 9834     case T_FLOAT:
 9835       evpermd(dst, mask, nds, src, merge, vector_len); break;
 9836     case T_LONG:
 9837     case T_DOUBLE:
 9838       evpermq(dst, mask, nds, src, merge, vector_len); break;
 9839     default:
 9840       fatal("Unexpected type argument %s", type2name(type)); break;
 9841   }
 9842 }
 9843 
 9844 void MacroAssembler::evperm(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9845   switch(type) {
 9846     case T_BOOLEAN:
 9847     case T_BYTE:
 9848       evpermb(dst, mask, nds, src, merge, vector_len); break;
 9849     case T_CHAR:
 9850     case T_SHORT:
 9851       evpermw(dst, mask, nds, src, merge, vector_len); break;
 9852     case T_INT:
 9853     case T_FLOAT:
 9854       evpermd(dst, mask, nds, src, merge, vector_len); break;
 9855     case T_LONG:
 9856     case T_DOUBLE:
 9857       evpermq(dst, mask, nds, src, merge, vector_len); break;
 9858     default:
 9859       fatal("Unexpected type argument %s", type2name(type)); break;
 9860   }
 9861 }
 9862 
 9863 void MacroAssembler::evpminu(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9864   switch(type) {
 9865     case T_BYTE:
 9866       evpminub(dst, mask, nds, src, merge, vector_len); break;
 9867     case T_SHORT:
 9868       evpminuw(dst, mask, nds, src, merge, vector_len); break;
 9869     case T_INT:
 9870       evpminud(dst, mask, nds, src, merge, vector_len); break;
 9871     case T_LONG:
 9872       evpminuq(dst, mask, nds, src, merge, vector_len); break;
 9873     default:
 9874       fatal("Unexpected type argument %s", type2name(type)); break;
 9875   }
 9876 }
 9877 
 9878 void MacroAssembler::evpmaxu(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9879   switch(type) {
 9880     case T_BYTE:
 9881       evpmaxub(dst, mask, nds, src, merge, vector_len); break;
 9882     case T_SHORT:
 9883       evpmaxuw(dst, mask, nds, src, merge, vector_len); break;
 9884     case T_INT:
 9885       evpmaxud(dst, mask, nds, src, merge, vector_len); break;
 9886     case T_LONG:
 9887       evpmaxuq(dst, mask, nds, src, merge, vector_len); break;
 9888     default:
 9889       fatal("Unexpected type argument %s", type2name(type)); break;
 9890   }
 9891 }
 9892 
 9893 void MacroAssembler::evpminu(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9894   switch(type) {
 9895     case T_BYTE:
 9896       evpminub(dst, mask, nds, src, merge, vector_len); break;
 9897     case T_SHORT:
 9898       evpminuw(dst, mask, nds, src, merge, vector_len); break;
 9899     case T_INT:
 9900       evpminud(dst, mask, nds, src, merge, vector_len); break;
 9901     case T_LONG:
 9902       evpminuq(dst, mask, nds, src, merge, vector_len); break;
 9903     default:
 9904       fatal("Unexpected type argument %s", type2name(type)); break;
 9905   }
 9906 }
 9907 
 9908 void MacroAssembler::evpmaxu(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9909   switch(type) {
 9910     case T_BYTE:
 9911       evpmaxub(dst, mask, nds, src, merge, vector_len); break;
 9912     case T_SHORT:
 9913       evpmaxuw(dst, mask, nds, src, merge, vector_len); break;
 9914     case T_INT:
 9915       evpmaxud(dst, mask, nds, src, merge, vector_len); break;
 9916     case T_LONG:
 9917       evpmaxuq(dst, mask, nds, src, merge, vector_len); break;
 9918     default:
 9919       fatal("Unexpected type argument %s", type2name(type)); break;
 9920   }
 9921 }
 9922 
 9923 void MacroAssembler::evpmins(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9924   switch(type) {
 9925     case T_BYTE:
 9926       evpminsb(dst, mask, nds, src, merge, vector_len); break;
 9927     case T_SHORT:
 9928       evpminsw(dst, mask, nds, src, merge, vector_len); break;
 9929     case T_INT:
 9930       evpminsd(dst, mask, nds, src, merge, vector_len); break;
 9931     case T_LONG:
 9932       evpminsq(dst, mask, nds, src, merge, vector_len); break;
 9933     default:
 9934       fatal("Unexpected type argument %s", type2name(type)); break;
 9935   }
 9936 }
 9937 
 9938 void MacroAssembler::evpmaxs(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9939   switch(type) {
 9940     case T_BYTE:
 9941       evpmaxsb(dst, mask, nds, src, merge, vector_len); break;
 9942     case T_SHORT:
 9943       evpmaxsw(dst, mask, nds, src, merge, vector_len); break;
 9944     case T_INT:
 9945       evpmaxsd(dst, mask, nds, src, merge, vector_len); break;
 9946     case T_LONG:
 9947       evpmaxsq(dst, mask, nds, src, merge, vector_len); break;
 9948     default:
 9949       fatal("Unexpected type argument %s", type2name(type)); break;
 9950   }
 9951 }
 9952 
 9953 void MacroAssembler::evpmins(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9954   switch(type) {
 9955     case T_BYTE:
 9956       evpminsb(dst, mask, nds, src, merge, vector_len); break;
 9957     case T_SHORT:
 9958       evpminsw(dst, mask, nds, src, merge, vector_len); break;
 9959     case T_INT:
 9960       evpminsd(dst, mask, nds, src, merge, vector_len); break;
 9961     case T_LONG:
 9962       evpminsq(dst, mask, nds, src, merge, vector_len); break;
 9963     default:
 9964       fatal("Unexpected type argument %s", type2name(type)); break;
 9965   }
 9966 }
 9967 
 9968 void MacroAssembler::evpmaxs(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9969   switch(type) {
 9970     case T_BYTE:
 9971       evpmaxsb(dst, mask, nds, src, merge, vector_len); break;
 9972     case T_SHORT:
 9973       evpmaxsw(dst, mask, nds, src, merge, vector_len); break;
 9974     case T_INT:
 9975       evpmaxsd(dst, mask, nds, src, merge, vector_len); break;
 9976     case T_LONG:
 9977       evpmaxsq(dst, mask, nds, src, merge, vector_len); break;
 9978     default:
 9979       fatal("Unexpected type argument %s", type2name(type)); break;
 9980   }
 9981 }
 9982 
 9983 void MacroAssembler::evxor(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
 9984   switch(type) {
 9985     case T_INT:
 9986       evpxord(dst, mask, nds, src, merge, vector_len); break;
 9987     case T_LONG:
 9988       evpxorq(dst, mask, nds, src, merge, vector_len); break;
 9989     default:
 9990       fatal("Unexpected type argument %s", type2name(type)); break;
 9991   }
 9992 }
 9993 
 9994 void MacroAssembler::evxor(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
 9995   switch(type) {
 9996     case T_INT:
 9997       evpxord(dst, mask, nds, src, merge, vector_len); break;
 9998     case T_LONG:
 9999       evpxorq(dst, mask, nds, src, merge, vector_len); break;
10000     default:
10001       fatal("Unexpected type argument %s", type2name(type)); break;
10002   }
10003 }
10004 
10005 void MacroAssembler::evor(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
10006   switch(type) {
10007     case T_INT:
10008       Assembler::evpord(dst, mask, nds, src, merge, vector_len); break;
10009     case T_LONG:
10010       evporq(dst, mask, nds, src, merge, vector_len); break;
10011     default:
10012       fatal("Unexpected type argument %s", type2name(type)); break;
10013   }
10014 }
10015 
10016 void MacroAssembler::evor(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
10017   switch(type) {
10018     case T_INT:
10019       Assembler::evpord(dst, mask, nds, src, merge, vector_len); break;
10020     case T_LONG:
10021       evporq(dst, mask, nds, src, merge, vector_len); break;
10022     default:
10023       fatal("Unexpected type argument %s", type2name(type)); break;
10024   }
10025 }
10026 
10027 void MacroAssembler::evand(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, XMMRegister src, bool merge, int vector_len) {
10028   switch(type) {
10029     case T_INT:
10030       evpandd(dst, mask, nds, src, merge, vector_len); break;
10031     case T_LONG:
10032       evpandq(dst, mask, nds, src, merge, vector_len); break;
10033     default:
10034       fatal("Unexpected type argument %s", type2name(type)); break;
10035   }
10036 }
10037 
10038 void MacroAssembler::evand(BasicType type, XMMRegister dst, KRegister mask, XMMRegister nds, Address src, bool merge, int vector_len) {
10039   switch(type) {
10040     case T_INT:
10041       evpandd(dst, mask, nds, src, merge, vector_len); break;
10042     case T_LONG:
10043       evpandq(dst, mask, nds, src, merge, vector_len); break;
10044     default:
10045       fatal("Unexpected type argument %s", type2name(type)); break;
10046   }
10047 }
10048 
10049 void MacroAssembler::kortest(uint masklen, KRegister src1, KRegister src2) {
10050   switch(masklen) {
10051     case 8:
10052        kortestbl(src1, src2);
10053        break;
10054     case 16:
10055        kortestwl(src1, src2);
10056        break;
10057     case 32:
10058        kortestdl(src1, src2);
10059        break;
10060     case 64:
10061        kortestql(src1, src2);
10062        break;
10063     default:
10064       fatal("Unexpected mask length %d", masklen);
10065       break;
10066   }
10067 }
10068 
10069 
10070 void MacroAssembler::ktest(uint masklen, KRegister src1, KRegister src2) {
10071   switch(masklen)  {
10072     case 8:
10073        ktestbl(src1, src2);
10074        break;
10075     case 16:
10076        ktestwl(src1, src2);
10077        break;
10078     case 32:
10079        ktestdl(src1, src2);
10080        break;
10081     case 64:
10082        ktestql(src1, src2);
10083        break;
10084     default:
10085       fatal("Unexpected mask length %d", masklen);
10086       break;
10087   }
10088 }
10089 
10090 void MacroAssembler::evrold(BasicType type, XMMRegister dst, KRegister mask, XMMRegister src, int shift, bool merge, int vlen_enc) {
10091   switch(type) {
10092     case T_INT:
10093       evprold(dst, mask, src, shift, merge, vlen_enc); break;
10094     case T_LONG:
10095       evprolq(dst, mask, src, shift, merge, vlen_enc); break;
10096     default:
10097       fatal("Unexpected type argument %s", type2name(type)); break;
10098       break;
10099   }
10100 }
10101 
10102 void MacroAssembler::evrord(BasicType type, XMMRegister dst, KRegister mask, XMMRegister src, int shift, bool merge, int vlen_enc) {
10103   switch(type) {
10104     case T_INT:
10105       evprord(dst, mask, src, shift, merge, vlen_enc); break;
10106     case T_LONG:
10107       evprorq(dst, mask, src, shift, merge, vlen_enc); break;
10108     default:
10109       fatal("Unexpected type argument %s", type2name(type)); break;
10110   }
10111 }
10112 
10113 void MacroAssembler::evrold(BasicType type, XMMRegister dst, KRegister mask, XMMRegister src1, XMMRegister src2, bool merge, int vlen_enc) {
10114   switch(type) {
10115     case T_INT:
10116       evprolvd(dst, mask, src1, src2, merge, vlen_enc); break;
10117     case T_LONG:
10118       evprolvq(dst, mask, src1, src2, merge, vlen_enc); break;
10119     default:
10120       fatal("Unexpected type argument %s", type2name(type)); break;
10121   }
10122 }
10123 
10124 void MacroAssembler::evrord(BasicType type, XMMRegister dst, KRegister mask, XMMRegister src1, XMMRegister src2, bool merge, int vlen_enc) {
10125   switch(type) {
10126     case T_INT:
10127       evprorvd(dst, mask, src1, src2, merge, vlen_enc); break;
10128     case T_LONG:
10129       evprorvq(dst, mask, src1, src2, merge, vlen_enc); break;
10130     default:
10131       fatal("Unexpected type argument %s", type2name(type)); break;
10132   }
10133 }
10134 
10135 void MacroAssembler::evpandq(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
10136   assert(rscratch != noreg || always_reachable(src), "missing");
10137 
10138   if (reachable(src)) {
10139     evpandq(dst, nds, as_Address(src), vector_len);
10140   } else {
10141     lea(rscratch, src);
10142     evpandq(dst, nds, Address(rscratch, 0), vector_len);
10143   }
10144 }
10145 
10146 void MacroAssembler::evpaddq(XMMRegister dst, KRegister mask, XMMRegister nds, AddressLiteral src, bool merge, int vector_len, Register rscratch) {
10147   assert(rscratch != noreg || always_reachable(src), "missing");
10148 
10149   if (reachable(src)) {
10150     Assembler::evpaddq(dst, mask, nds, as_Address(src), merge, vector_len);
10151   } else {
10152     lea(rscratch, src);
10153     Assembler::evpaddq(dst, mask, nds, Address(rscratch, 0), merge, vector_len);
10154   }
10155 }
10156 
10157 void MacroAssembler::evporq(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
10158   assert(rscratch != noreg || always_reachable(src), "missing");
10159 
10160   if (reachable(src)) {
10161     evporq(dst, nds, as_Address(src), vector_len);
10162   } else {
10163     lea(rscratch, src);
10164     evporq(dst, nds, Address(rscratch, 0), vector_len);
10165   }
10166 }
10167 
10168 void MacroAssembler::vpshufb(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
10169   assert(rscratch != noreg || always_reachable(src), "missing");
10170 
10171   if (reachable(src)) {
10172     vpshufb(dst, nds, as_Address(src), vector_len);
10173   } else {
10174     lea(rscratch, src);
10175     vpshufb(dst, nds, Address(rscratch, 0), vector_len);
10176   }
10177 }
10178 
10179 void MacroAssembler::vpor(XMMRegister dst, XMMRegister nds, AddressLiteral src, int vector_len, Register rscratch) {
10180   assert(rscratch != noreg || always_reachable(src), "missing");
10181 
10182   if (reachable(src)) {
10183     Assembler::vpor(dst, nds, as_Address(src), vector_len);
10184   } else {
10185     lea(rscratch, src);
10186     Assembler::vpor(dst, nds, Address(rscratch, 0), vector_len);
10187   }
10188 }
10189 
10190 void MacroAssembler::vpternlogq(XMMRegister dst, int imm8, XMMRegister src2, AddressLiteral src3, int vector_len, Register rscratch) {
10191   assert(rscratch != noreg || always_reachable(src3), "missing");
10192 
10193   if (reachable(src3)) {
10194     vpternlogq(dst, imm8, src2, as_Address(src3), vector_len);
10195   } else {
10196     lea(rscratch, src3);
10197     vpternlogq(dst, imm8, src2, Address(rscratch, 0), vector_len);
10198   }
10199 }
10200 
10201 #if COMPILER2_OR_JVMCI
10202 
10203 void MacroAssembler::fill_masked(BasicType bt, Address dst, XMMRegister xmm, KRegister mask,
10204                                  Register length, Register temp, int vec_enc) {
10205   // Computing mask for predicated vector store.
10206   movptr(temp, -1);
10207   bzhiq(temp, temp, length);
10208   kmov(mask, temp);
10209   evmovdqu(bt, mask, dst, xmm, true, vec_enc);
10210 }
10211 
10212 // Set memory operation for length "less than" 64 bytes.
10213 void MacroAssembler::fill64_masked(uint shift, Register dst, int disp,
10214                                        XMMRegister xmm, KRegister mask, Register length,
10215                                        Register temp, bool use64byteVector) {
10216   assert(MaxVectorSize >= 32, "vector length should be >= 32");
10217   const BasicType type[] = { T_BYTE, T_SHORT, T_INT, T_LONG};
10218   if (!use64byteVector) {
10219     fill32(dst, disp, xmm);
10220     subptr(length, 32 >> shift);
10221     fill32_masked(shift, dst, disp + 32, xmm, mask, length, temp);
10222   } else {
10223     assert(MaxVectorSize == 64, "vector length != 64");
10224     fill_masked(type[shift], Address(dst, disp), xmm, mask, length, temp, Assembler::AVX_512bit);
10225   }
10226 }
10227 
10228 
10229 void MacroAssembler::fill32_masked(uint shift, Register dst, int disp,
10230                                        XMMRegister xmm, KRegister mask, Register length,
10231                                        Register temp) {
10232   assert(MaxVectorSize >= 32, "vector length should be >= 32");
10233   const BasicType type[] = { T_BYTE, T_SHORT, T_INT, T_LONG};
10234   fill_masked(type[shift], Address(dst, disp), xmm, mask, length, temp, Assembler::AVX_256bit);
10235 }
10236 
10237 
10238 void MacroAssembler::fill32(Address dst, XMMRegister xmm) {
10239   assert(MaxVectorSize >= 32, "vector length should be >= 32");
10240   vmovdqu(dst, xmm);
10241 }
10242 
10243 void MacroAssembler::fill32(Register dst, int disp, XMMRegister xmm) {
10244   fill32(Address(dst, disp), xmm);
10245 }
10246 
10247 void MacroAssembler::fill64(Address dst, XMMRegister xmm, bool use64byteVector) {
10248   assert(MaxVectorSize >= 32, "vector length should be >= 32");
10249   if (!use64byteVector) {
10250     fill32(dst, xmm);
10251     fill32(dst.plus_disp(32), xmm);
10252   } else {
10253     evmovdquq(dst, xmm, Assembler::AVX_512bit);
10254   }
10255 }
10256 
10257 void MacroAssembler::fill64(Register dst, int disp, XMMRegister xmm, bool use64byteVector) {
10258   fill64(Address(dst, disp), xmm, use64byteVector);
10259 }
10260 
10261 #ifdef _LP64
10262 void MacroAssembler::generate_fill_avx3(BasicType type, Register to, Register value,
10263                                         Register count, Register rtmp, XMMRegister xtmp) {
10264   Label L_exit;
10265   Label L_fill_start;
10266   Label L_fill_64_bytes;
10267   Label L_fill_96_bytes;
10268   Label L_fill_128_bytes;
10269   Label L_fill_128_bytes_loop;
10270   Label L_fill_128_loop_header;
10271   Label L_fill_128_bytes_loop_header;
10272   Label L_fill_128_bytes_loop_pre_header;
10273   Label L_fill_zmm_sequence;
10274 
10275   int shift = -1;
10276   int avx3threshold = VM_Version::avx3_threshold();
10277   switch(type) {
10278     case T_BYTE:  shift = 0;
10279       break;
10280     case T_SHORT: shift = 1;
10281       break;
10282     case T_INT:   shift = 2;
10283       break;
10284     /* Uncomment when LONG fill stubs are supported.
10285     case T_LONG:  shift = 3;
10286       break;
10287     */
10288     default:
10289       fatal("Unhandled type: %s\n", type2name(type));
10290   }
10291 
10292   if ((avx3threshold != 0)  || (MaxVectorSize == 32)) {
10293 
10294     if (MaxVectorSize == 64) {
10295       cmpq(count, avx3threshold >> shift);
10296       jcc(Assembler::greater, L_fill_zmm_sequence);
10297     }
10298 
10299     evpbroadcast(type, xtmp, value, Assembler::AVX_256bit);
10300 
10301     bind(L_fill_start);
10302 
10303     cmpq(count, 32 >> shift);
10304     jccb(Assembler::greater, L_fill_64_bytes);
10305     fill32_masked(shift, to, 0, xtmp, k2, count, rtmp);
10306     jmp(L_exit);
10307 
10308     bind(L_fill_64_bytes);
10309     cmpq(count, 64 >> shift);
10310     jccb(Assembler::greater, L_fill_96_bytes);
10311     fill64_masked(shift, to, 0, xtmp, k2, count, rtmp);
10312     jmp(L_exit);
10313 
10314     bind(L_fill_96_bytes);
10315     cmpq(count, 96 >> shift);
10316     jccb(Assembler::greater, L_fill_128_bytes);
10317     fill64(to, 0, xtmp);
10318     subq(count, 64 >> shift);
10319     fill32_masked(shift, to, 64, xtmp, k2, count, rtmp);
10320     jmp(L_exit);
10321 
10322     bind(L_fill_128_bytes);
10323     cmpq(count, 128 >> shift);
10324     jccb(Assembler::greater, L_fill_128_bytes_loop_pre_header);
10325     fill64(to, 0, xtmp);
10326     fill32(to, 64, xtmp);
10327     subq(count, 96 >> shift);
10328     fill32_masked(shift, to, 96, xtmp, k2, count, rtmp);
10329     jmp(L_exit);
10330 
10331     bind(L_fill_128_bytes_loop_pre_header);
10332     {
10333       mov(rtmp, to);
10334       andq(rtmp, 31);
10335       jccb(Assembler::zero, L_fill_128_bytes_loop_header);
10336       negq(rtmp);
10337       addq(rtmp, 32);
10338       mov64(r8, -1L);
10339       bzhiq(r8, r8, rtmp);
10340       kmovql(k2, r8);
10341       evmovdqu(T_BYTE, k2, Address(to, 0), xtmp, true, Assembler::AVX_256bit);
10342       addq(to, rtmp);
10343       shrq(rtmp, shift);
10344       subq(count, rtmp);
10345     }
10346 
10347     cmpq(count, 128 >> shift);
10348     jcc(Assembler::less, L_fill_start);
10349 
10350     bind(L_fill_128_bytes_loop_header);
10351     subq(count, 128 >> shift);
10352 
10353     align32();
10354     bind(L_fill_128_bytes_loop);
10355       fill64(to, 0, xtmp);
10356       fill64(to, 64, xtmp);
10357       addq(to, 128);
10358       subq(count, 128 >> shift);
10359       jccb(Assembler::greaterEqual, L_fill_128_bytes_loop);
10360 
10361     addq(count, 128 >> shift);
10362     jcc(Assembler::zero, L_exit);
10363     jmp(L_fill_start);
10364   }
10365 
10366   if (MaxVectorSize == 64) {
10367     // Sequence using 64 byte ZMM register.
10368     Label L_fill_128_bytes_zmm;
10369     Label L_fill_192_bytes_zmm;
10370     Label L_fill_192_bytes_loop_zmm;
10371     Label L_fill_192_bytes_loop_header_zmm;
10372     Label L_fill_192_bytes_loop_pre_header_zmm;
10373     Label L_fill_start_zmm_sequence;
10374 
10375     bind(L_fill_zmm_sequence);
10376     evpbroadcast(type, xtmp, value, Assembler::AVX_512bit);
10377 
10378     bind(L_fill_start_zmm_sequence);
10379     cmpq(count, 64 >> shift);
10380     jccb(Assembler::greater, L_fill_128_bytes_zmm);
10381     fill64_masked(shift, to, 0, xtmp, k2, count, rtmp, true);
10382     jmp(L_exit);
10383 
10384     bind(L_fill_128_bytes_zmm);
10385     cmpq(count, 128 >> shift);
10386     jccb(Assembler::greater, L_fill_192_bytes_zmm);
10387     fill64(to, 0, xtmp, true);
10388     subq(count, 64 >> shift);
10389     fill64_masked(shift, to, 64, xtmp, k2, count, rtmp, true);
10390     jmp(L_exit);
10391 
10392     bind(L_fill_192_bytes_zmm);
10393     cmpq(count, 192 >> shift);
10394     jccb(Assembler::greater, L_fill_192_bytes_loop_pre_header_zmm);
10395     fill64(to, 0, xtmp, true);
10396     fill64(to, 64, xtmp, true);
10397     subq(count, 128 >> shift);
10398     fill64_masked(shift, to, 128, xtmp, k2, count, rtmp, true);
10399     jmp(L_exit);
10400 
10401     bind(L_fill_192_bytes_loop_pre_header_zmm);
10402     {
10403       movq(rtmp, to);
10404       andq(rtmp, 63);
10405       jccb(Assembler::zero, L_fill_192_bytes_loop_header_zmm);
10406       negq(rtmp);
10407       addq(rtmp, 64);
10408       mov64(r8, -1L);
10409       bzhiq(r8, r8, rtmp);
10410       kmovql(k2, r8);
10411       evmovdqu(T_BYTE, k2, Address(to, 0), xtmp, true, Assembler::AVX_512bit);
10412       addq(to, rtmp);
10413       shrq(rtmp, shift);
10414       subq(count, rtmp);
10415     }
10416 
10417     cmpq(count, 192 >> shift);
10418     jcc(Assembler::less, L_fill_start_zmm_sequence);
10419 
10420     bind(L_fill_192_bytes_loop_header_zmm);
10421     subq(count, 192 >> shift);
10422 
10423     align32();
10424     bind(L_fill_192_bytes_loop_zmm);
10425       fill64(to, 0, xtmp, true);
10426       fill64(to, 64, xtmp, true);
10427       fill64(to, 128, xtmp, true);
10428       addq(to, 192);
10429       subq(count, 192 >> shift);
10430       jccb(Assembler::greaterEqual, L_fill_192_bytes_loop_zmm);
10431 
10432     addq(count, 192 >> shift);
10433     jcc(Assembler::zero, L_exit);
10434     jmp(L_fill_start_zmm_sequence);
10435   }
10436   bind(L_exit);
10437 }
10438 #endif
10439 #endif //COMPILER2_OR_JVMCI
10440 
10441 
10442 #ifdef _LP64
10443 void MacroAssembler::convert_f2i(Register dst, XMMRegister src) {
10444   Label done;
10445   cvttss2sil(dst, src);
10446   // Conversion instructions do not match JLS for overflow, underflow and NaN -> fixup in stub
10447   cmpl(dst, 0x80000000); // float_sign_flip
10448   jccb(Assembler::notEqual, done);
10449   subptr(rsp, 8);
10450   movflt(Address(rsp, 0), src);
10451   call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::f2i_fixup())));
10452   pop(dst);
10453   bind(done);
10454 }
10455 
10456 void MacroAssembler::convert_d2i(Register dst, XMMRegister src) {
10457   Label done;
10458   cvttsd2sil(dst, src);
10459   // Conversion instructions do not match JLS for overflow, underflow and NaN -> fixup in stub
10460   cmpl(dst, 0x80000000); // float_sign_flip
10461   jccb(Assembler::notEqual, done);
10462   subptr(rsp, 8);
10463   movdbl(Address(rsp, 0), src);
10464   call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::d2i_fixup())));
10465   pop(dst);
10466   bind(done);
10467 }
10468 
10469 void MacroAssembler::convert_f2l(Register dst, XMMRegister src) {
10470   Label done;
10471   cvttss2siq(dst, src);
10472   cmp64(dst, ExternalAddress((address) StubRoutines::x86::double_sign_flip()));
10473   jccb(Assembler::notEqual, done);
10474   subptr(rsp, 8);
10475   movflt(Address(rsp, 0), src);
10476   call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::f2l_fixup())));
10477   pop(dst);
10478   bind(done);
10479 }
10480 
10481 void MacroAssembler::round_float(Register dst, XMMRegister src, Register rtmp, Register rcx) {
10482   // Following code is line by line assembly translation rounding algorithm.
10483   // Please refer to java.lang.Math.round(float) algorithm for details.
10484   const int32_t FloatConsts_EXP_BIT_MASK = 0x7F800000;
10485   const int32_t FloatConsts_SIGNIFICAND_WIDTH = 24;
10486   const int32_t FloatConsts_EXP_BIAS = 127;
10487   const int32_t FloatConsts_SIGNIF_BIT_MASK = 0x007FFFFF;
10488   const int32_t MINUS_32 = 0xFFFFFFE0;
10489   Label L_special_case, L_block1, L_exit;
10490   movl(rtmp, FloatConsts_EXP_BIT_MASK);
10491   movdl(dst, src);
10492   andl(dst, rtmp);
10493   sarl(dst, FloatConsts_SIGNIFICAND_WIDTH - 1);
10494   movl(rtmp, FloatConsts_SIGNIFICAND_WIDTH - 2 + FloatConsts_EXP_BIAS);
10495   subl(rtmp, dst);
10496   movl(rcx, rtmp);
10497   movl(dst, MINUS_32);
10498   testl(rtmp, dst);
10499   jccb(Assembler::notEqual, L_special_case);
10500   movdl(dst, src);
10501   andl(dst, FloatConsts_SIGNIF_BIT_MASK);
10502   orl(dst, FloatConsts_SIGNIF_BIT_MASK + 1);
10503   movdl(rtmp, src);
10504   testl(rtmp, rtmp);
10505   jccb(Assembler::greaterEqual, L_block1);
10506   negl(dst);
10507   bind(L_block1);
10508   sarl(dst);
10509   addl(dst, 0x1);
10510   sarl(dst, 0x1);
10511   jmp(L_exit);
10512   bind(L_special_case);
10513   convert_f2i(dst, src);
10514   bind(L_exit);
10515 }
10516 
10517 void MacroAssembler::round_double(Register dst, XMMRegister src, Register rtmp, Register rcx) {
10518   // Following code is line by line assembly translation rounding algorithm.
10519   // Please refer to java.lang.Math.round(double) algorithm for details.
10520   const int64_t DoubleConsts_EXP_BIT_MASK = 0x7FF0000000000000L;
10521   const int64_t DoubleConsts_SIGNIFICAND_WIDTH = 53;
10522   const int64_t DoubleConsts_EXP_BIAS = 1023;
10523   const int64_t DoubleConsts_SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL;
10524   const int64_t MINUS_64 = 0xFFFFFFFFFFFFFFC0L;
10525   Label L_special_case, L_block1, L_exit;
10526   mov64(rtmp, DoubleConsts_EXP_BIT_MASK);
10527   movq(dst, src);
10528   andq(dst, rtmp);
10529   sarq(dst, DoubleConsts_SIGNIFICAND_WIDTH - 1);
10530   mov64(rtmp, DoubleConsts_SIGNIFICAND_WIDTH - 2 + DoubleConsts_EXP_BIAS);
10531   subq(rtmp, dst);
10532   movq(rcx, rtmp);
10533   mov64(dst, MINUS_64);
10534   testq(rtmp, dst);
10535   jccb(Assembler::notEqual, L_special_case);
10536   movq(dst, src);
10537   mov64(rtmp, DoubleConsts_SIGNIF_BIT_MASK);
10538   andq(dst, rtmp);
10539   mov64(rtmp, DoubleConsts_SIGNIF_BIT_MASK + 1);
10540   orq(dst, rtmp);
10541   movq(rtmp, src);
10542   testq(rtmp, rtmp);
10543   jccb(Assembler::greaterEqual, L_block1);
10544   negq(dst);
10545   bind(L_block1);
10546   sarq(dst);
10547   addq(dst, 0x1);
10548   sarq(dst, 0x1);
10549   jmp(L_exit);
10550   bind(L_special_case);
10551   convert_d2l(dst, src);
10552   bind(L_exit);
10553 }
10554 
10555 void MacroAssembler::convert_d2l(Register dst, XMMRegister src) {
10556   Label done;
10557   cvttsd2siq(dst, src);
10558   cmp64(dst, ExternalAddress((address) StubRoutines::x86::double_sign_flip()));
10559   jccb(Assembler::notEqual, done);
10560   subptr(rsp, 8);
10561   movdbl(Address(rsp, 0), src);
10562   call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::d2l_fixup())));
10563   pop(dst);
10564   bind(done);
10565 }
10566 
10567 void MacroAssembler::cache_wb(Address line)
10568 {
10569   // 64 bit cpus always support clflush
10570   assert(VM_Version::supports_clflush(), "clflush should be available");
10571   bool optimized = VM_Version::supports_clflushopt();
10572   bool no_evict = VM_Version::supports_clwb();
10573 
10574   // prefer clwb (writeback without evict) otherwise
10575   // prefer clflushopt (potentially parallel writeback with evict)
10576   // otherwise fallback on clflush (serial writeback with evict)
10577 
10578   if (optimized) {
10579     if (no_evict) {
10580       clwb(line);
10581     } else {
10582       clflushopt(line);
10583     }
10584   } else {
10585     // no need for fence when using CLFLUSH
10586     clflush(line);
10587   }
10588 }
10589 
10590 void MacroAssembler::cache_wbsync(bool is_pre)
10591 {
10592   assert(VM_Version::supports_clflush(), "clflush should be available");
10593   bool optimized = VM_Version::supports_clflushopt();
10594   bool no_evict = VM_Version::supports_clwb();
10595 
10596   // pick the correct implementation
10597 
10598   if (!is_pre && (optimized || no_evict)) {
10599     // need an sfence for post flush when using clflushopt or clwb
10600     // otherwise no no need for any synchroniaztion
10601 
10602     sfence();
10603   }
10604 }
10605 
10606 #endif // _LP64
10607 
10608 Assembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) {
10609   switch (cond) {
10610     // Note some conditions are synonyms for others
10611     case Assembler::zero:         return Assembler::notZero;
10612     case Assembler::notZero:      return Assembler::zero;
10613     case Assembler::less:         return Assembler::greaterEqual;
10614     case Assembler::lessEqual:    return Assembler::greater;
10615     case Assembler::greater:      return Assembler::lessEqual;
10616     case Assembler::greaterEqual: return Assembler::less;
10617     case Assembler::below:        return Assembler::aboveEqual;
10618     case Assembler::belowEqual:   return Assembler::above;
10619     case Assembler::above:        return Assembler::belowEqual;
10620     case Assembler::aboveEqual:   return Assembler::below;
10621     case Assembler::overflow:     return Assembler::noOverflow;
10622     case Assembler::noOverflow:   return Assembler::overflow;
10623     case Assembler::negative:     return Assembler::positive;
10624     case Assembler::positive:     return Assembler::negative;
10625     case Assembler::parity:       return Assembler::noParity;
10626     case Assembler::noParity:     return Assembler::parity;
10627   }
10628   ShouldNotReachHere(); return Assembler::overflow;
10629 }
10630 
10631 // This is simply a call to Thread::current()
10632 void MacroAssembler::get_thread(Register thread) {
10633   if (thread != rax) {
10634     push(rax);
10635   }
10636   LP64_ONLY(push(rdi);)
10637   LP64_ONLY(push(rsi);)
10638   push(rdx);
10639   push(rcx);
10640 #ifdef _LP64
10641   push(r8);
10642   push(r9);
10643   push(r10);
10644   push(r11);
10645 #endif
10646 
10647   MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, Thread::current), 0);
10648 
10649 #ifdef _LP64
10650   pop(r11);
10651   pop(r10);
10652   pop(r9);
10653   pop(r8);
10654 #endif
10655   pop(rcx);
10656   pop(rdx);
10657   LP64_ONLY(pop(rsi);)
10658   LP64_ONLY(pop(rdi);)
10659   if (thread != rax) {
10660     mov(thread, rax);
10661     pop(rax);
10662   }
10663 }
10664 
10665 void MacroAssembler::check_stack_alignment(Register sp, const char* msg, unsigned bias, Register tmp) {
10666   Label L_stack_ok;
10667   if (bias == 0) {
10668     testptr(sp, 2 * wordSize - 1);
10669   } else {
10670     // lea(tmp, Address(rsp, bias);
10671     mov(tmp, sp);
10672     addptr(tmp, bias);
10673     testptr(tmp, 2 * wordSize - 1);
10674   }
10675   jcc(Assembler::equal, L_stack_ok);
10676   block_comment(msg);
10677   stop(msg);
10678   bind(L_stack_ok);
10679 }
10680 
10681 // Implements lightweight-locking.
10682 //
10683 // obj: the object to be locked
10684 // reg_rax: rax
10685 // thread: the thread which attempts to lock obj
10686 // tmp: a temporary register
10687 void MacroAssembler::lightweight_lock(Register basic_lock, Register obj, Register reg_rax, Register thread, Register tmp, Label& slow) {
10688   assert(reg_rax == rax, "");
10689   assert_different_registers(basic_lock, obj, reg_rax, thread, tmp);
10690 
10691   Label push;
10692   const Register top = tmp;
10693 
10694   // Preload the markWord. It is important that this is the first
10695   // instruction emitted as it is part of C1's null check semantics.
10696   movptr(reg_rax, Address(obj, oopDesc::mark_offset_in_bytes()));
10697 
10698   if (UseObjectMonitorTable) {
10699     // Clear cache in case fast locking succeeds.
10700     movptr(Address(basic_lock, BasicObjectLock::lock_offset() + in_ByteSize((BasicLock::object_monitor_cache_offset_in_bytes()))), 0);
10701   }
10702 
10703   // Load top.
10704   movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10705 
10706   // Check if the lock-stack is full.
10707   cmpl(top, LockStack::end_offset());
10708   jcc(Assembler::greaterEqual, slow);
10709 
10710   // Check for recursion.
10711   cmpptr(obj, Address(thread, top, Address::times_1, -oopSize));
10712   jcc(Assembler::equal, push);
10713 
10714   // Check header for monitor (0b10).
10715   testptr(reg_rax, markWord::monitor_value);
10716   jcc(Assembler::notZero, slow);
10717 
10718   // Try to lock. Transition lock bits 0b01 => 0b00
10719   movptr(tmp, reg_rax);
10720   andptr(tmp, ~(int32_t)markWord::unlocked_value);
10721   orptr(reg_rax, markWord::unlocked_value);
10722   lock(); cmpxchgptr(tmp, Address(obj, oopDesc::mark_offset_in_bytes()));
10723   jcc(Assembler::notEqual, slow);
10724 
10725   // Restore top, CAS clobbers register.
10726   movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10727 
10728   bind(push);
10729   // After successful lock, push object on lock-stack.
10730   movptr(Address(thread, top), obj);
10731   incrementl(top, oopSize);
10732   movl(Address(thread, JavaThread::lock_stack_top_offset()), top);
10733 }
10734 
10735 // Implements lightweight-unlocking.
10736 //
10737 // obj: the object to be unlocked
10738 // reg_rax: rax
10739 // thread: the thread
10740 // tmp: a temporary register
10741 void MacroAssembler::lightweight_unlock(Register obj, Register reg_rax, Register thread, Register tmp, Label& slow) {
10742   assert(reg_rax == rax, "");
10743   assert_different_registers(obj, reg_rax, thread, tmp);
10744 
10745   Label unlocked, push_and_slow;
10746   const Register top = tmp;
10747 
10748   // Check if obj is top of lock-stack.
10749   movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10750   cmpptr(obj, Address(thread, top, Address::times_1, -oopSize));
10751   jcc(Assembler::notEqual, slow);
10752 
10753   // Pop lock-stack.
10754   DEBUG_ONLY(movptr(Address(thread, top, Address::times_1, -oopSize), 0);)
10755   subl(Address(thread, JavaThread::lock_stack_top_offset()), oopSize);
10756 
10757   // Check if recursive.
10758   cmpptr(obj, Address(thread, top, Address::times_1, -2 * oopSize));
10759   jcc(Assembler::equal, unlocked);
10760 
10761   // Not recursive. Check header for monitor (0b10).
10762   movptr(reg_rax, Address(obj, oopDesc::mark_offset_in_bytes()));
10763   testptr(reg_rax, markWord::monitor_value);
10764   jcc(Assembler::notZero, push_and_slow);
10765 
10766 #ifdef ASSERT
10767   // Check header not unlocked (0b01).
10768   Label not_unlocked;
10769   testptr(reg_rax, markWord::unlocked_value);
10770   jcc(Assembler::zero, not_unlocked);
10771   stop("lightweight_unlock already unlocked");
10772   bind(not_unlocked);
10773 #endif
10774 
10775   // Try to unlock. Transition lock bits 0b00 => 0b01
10776   movptr(tmp, reg_rax);
10777   orptr(tmp, markWord::unlocked_value);
10778   lock(); cmpxchgptr(tmp, Address(obj, oopDesc::mark_offset_in_bytes()));
10779   jcc(Assembler::equal, unlocked);
10780 
10781   bind(push_and_slow);
10782   // Restore lock-stack and handle the unlock in runtime.
10783 #ifdef ASSERT
10784   movl(top, Address(thread, JavaThread::lock_stack_top_offset()));
10785   movptr(Address(thread, top), obj);
10786 #endif
10787   addl(Address(thread, JavaThread::lock_stack_top_offset()), oopSize);
10788   jmp(slow);
10789 
10790   bind(unlocked);
10791 }
10792 
10793 #ifdef _LP64
10794 // Saves legacy GPRs state on stack.
10795 void MacroAssembler::save_legacy_gprs() {
10796   subq(rsp, 16 * wordSize);
10797   movq(Address(rsp, 15 * wordSize), rax);
10798   movq(Address(rsp, 14 * wordSize), rcx);
10799   movq(Address(rsp, 13 * wordSize), rdx);
10800   movq(Address(rsp, 12 * wordSize), rbx);
10801   movq(Address(rsp, 10 * wordSize), rbp);
10802   movq(Address(rsp, 9 * wordSize), rsi);
10803   movq(Address(rsp, 8 * wordSize), rdi);
10804   movq(Address(rsp, 7 * wordSize), r8);
10805   movq(Address(rsp, 6 * wordSize), r9);
10806   movq(Address(rsp, 5 * wordSize), r10);
10807   movq(Address(rsp, 4 * wordSize), r11);
10808   movq(Address(rsp, 3 * wordSize), r12);
10809   movq(Address(rsp, 2 * wordSize), r13);
10810   movq(Address(rsp, wordSize), r14);
10811   movq(Address(rsp, 0), r15);
10812 }
10813 
10814 // Resotres back legacy GPRs state from stack.
10815 void MacroAssembler::restore_legacy_gprs() {
10816   movq(r15, Address(rsp, 0));
10817   movq(r14, Address(rsp, wordSize));
10818   movq(r13, Address(rsp, 2 * wordSize));
10819   movq(r12, Address(rsp, 3 * wordSize));
10820   movq(r11, Address(rsp, 4 * wordSize));
10821   movq(r10, Address(rsp, 5 * wordSize));
10822   movq(r9,  Address(rsp, 6 * wordSize));
10823   movq(r8,  Address(rsp, 7 * wordSize));
10824   movq(rdi, Address(rsp, 8 * wordSize));
10825   movq(rsi, Address(rsp, 9 * wordSize));
10826   movq(rbp, Address(rsp, 10 * wordSize));
10827   movq(rbx, Address(rsp, 12 * wordSize));
10828   movq(rdx, Address(rsp, 13 * wordSize));
10829   movq(rcx, Address(rsp, 14 * wordSize));
10830   movq(rax, Address(rsp, 15 * wordSize));
10831   addq(rsp, 16 * wordSize);
10832 }
10833 
10834 void MacroAssembler::setcc(Assembler::Condition comparison, Register dst) {
10835   if (VM_Version::supports_apx_f()) {
10836     esetzucc(comparison, dst);
10837   } else {
10838     setb(comparison, dst);
10839     movzbl(dst, dst);
10840   }
10841 }
10842 #endif