1 //
    2 // Copyright (c) 2003, 2021, 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 // AMD64 Architecture Description File
   26 
   27 //----------REGISTER DEFINITION BLOCK------------------------------------------
   28 // This information is used by the matcher and the register allocator to
   29 // describe individual registers and classes of registers within the target
   30 // archtecture.
   31 
   32 register %{
   33 //----------Architecture Description Register Definitions----------------------
   34 // General Registers
   35 // "reg_def"  name ( register save type, C convention save type,
   36 //                   ideal register type, encoding );
   37 // Register Save Types:
   38 //
   39 // NS  = No-Save:       The register allocator assumes that these registers
   40 //                      can be used without saving upon entry to the method, &
   41 //                      that they do not need to be saved at call sites.
   42 //
   43 // SOC = Save-On-Call:  The register allocator assumes that these registers
   44 //                      can be used without saving upon entry to the method,
   45 //                      but that they must be saved at call sites.
   46 //
   47 // SOE = Save-On-Entry: The register allocator assumes that these registers
   48 //                      must be saved before using them upon entry to the
   49 //                      method, but they do not need to be saved at call
   50 //                      sites.
   51 //
   52 // AS  = Always-Save:   The register allocator assumes that these registers
   53 //                      must be saved before using them upon entry to the
   54 //                      method, & that they must be saved at call sites.
   55 //
   56 // Ideal Register Type is used to determine how to save & restore a
   57 // register.  Op_RegI will get spilled with LoadI/StoreI, Op_RegP will get
   58 // spilled with LoadP/StoreP.  If the register supports both, use Op_RegI.
   59 //
   60 // The encoding number is the actual bit-pattern placed into the opcodes.
   61 
   62 // General Registers
   63 // R8-R15 must be encoded with REX.  (RSP, RBP, RSI, RDI need REX when
   64 // used as byte registers)
   65 
   66 // Previously set RBX, RSI, and RDI as save-on-entry for java code
   67 // Turn off SOE in java-code due to frequent use of uncommon-traps.
   68 // Now that allocator is better, turn on RSI and RDI as SOE registers.
   69 
   70 reg_def RAX  (SOC, SOC, Op_RegI,  0, rax->as_VMReg());
   71 reg_def RAX_H(SOC, SOC, Op_RegI,  0, rax->as_VMReg()->next());
   72 
   73 reg_def RCX  (SOC, SOC, Op_RegI,  1, rcx->as_VMReg());
   74 reg_def RCX_H(SOC, SOC, Op_RegI,  1, rcx->as_VMReg()->next());
   75 
   76 reg_def RDX  (SOC, SOC, Op_RegI,  2, rdx->as_VMReg());
   77 reg_def RDX_H(SOC, SOC, Op_RegI,  2, rdx->as_VMReg()->next());
   78 
   79 reg_def RBX  (SOC, SOE, Op_RegI,  3, rbx->as_VMReg());
   80 reg_def RBX_H(SOC, SOE, Op_RegI,  3, rbx->as_VMReg()->next());
   81 
   82 reg_def RSP  (NS,  NS,  Op_RegI,  4, rsp->as_VMReg());
   83 reg_def RSP_H(NS,  NS,  Op_RegI,  4, rsp->as_VMReg()->next());
   84 
   85 // now that adapter frames are gone RBP is always saved and restored by the prolog/epilog code
   86 reg_def RBP  (NS, SOE, Op_RegI,  5, rbp->as_VMReg());
   87 reg_def RBP_H(NS, SOE, Op_RegI,  5, rbp->as_VMReg()->next());
   88 
   89 #ifdef _WIN64
   90 
   91 reg_def RSI  (SOC, SOE, Op_RegI,  6, rsi->as_VMReg());
   92 reg_def RSI_H(SOC, SOE, Op_RegI,  6, rsi->as_VMReg()->next());
   93 
   94 reg_def RDI  (SOC, SOE, Op_RegI,  7, rdi->as_VMReg());
   95 reg_def RDI_H(SOC, SOE, Op_RegI,  7, rdi->as_VMReg()->next());
   96 
   97 #else
   98 
   99 reg_def RSI  (SOC, SOC, Op_RegI,  6, rsi->as_VMReg());
  100 reg_def RSI_H(SOC, SOC, Op_RegI,  6, rsi->as_VMReg()->next());
  101 
  102 reg_def RDI  (SOC, SOC, Op_RegI,  7, rdi->as_VMReg());
  103 reg_def RDI_H(SOC, SOC, Op_RegI,  7, rdi->as_VMReg()->next());
  104 
  105 #endif
  106 
  107 reg_def R8   (SOC, SOC, Op_RegI,  8, r8->as_VMReg());
  108 reg_def R8_H (SOC, SOC, Op_RegI,  8, r8->as_VMReg()->next());
  109 
  110 reg_def R9   (SOC, SOC, Op_RegI,  9, r9->as_VMReg());
  111 reg_def R9_H (SOC, SOC, Op_RegI,  9, r9->as_VMReg()->next());
  112 
  113 reg_def R10  (SOC, SOC, Op_RegI, 10, r10->as_VMReg());
  114 reg_def R10_H(SOC, SOC, Op_RegI, 10, r10->as_VMReg()->next());
  115 
  116 reg_def R11  (SOC, SOC, Op_RegI, 11, r11->as_VMReg());
  117 reg_def R11_H(SOC, SOC, Op_RegI, 11, r11->as_VMReg()->next());
  118 
  119 reg_def R12  (SOC, SOE, Op_RegI, 12, r12->as_VMReg());
  120 reg_def R12_H(SOC, SOE, Op_RegI, 12, r12->as_VMReg()->next());
  121 
  122 reg_def R13  (SOC, SOE, Op_RegI, 13, r13->as_VMReg());
  123 reg_def R13_H(SOC, SOE, Op_RegI, 13, r13->as_VMReg()->next());
  124 
  125 reg_def R14  (SOC, SOE, Op_RegI, 14, r14->as_VMReg());
  126 reg_def R14_H(SOC, SOE, Op_RegI, 14, r14->as_VMReg()->next());
  127 
  128 reg_def R15  (SOC, SOE, Op_RegI, 15, r15->as_VMReg());
  129 reg_def R15_H(SOC, SOE, Op_RegI, 15, r15->as_VMReg()->next());
  130 
  131 
  132 // Floating Point Registers
  133 
  134 // Specify priority of register selection within phases of register
  135 // allocation.  Highest priority is first.  A useful heuristic is to
  136 // give registers a low priority when they are required by machine
  137 // instructions, like EAX and EDX on I486, and choose no-save registers
  138 // before save-on-call, & save-on-call before save-on-entry.  Registers
  139 // which participate in fixed calling sequences should come last.
  140 // Registers which are used as pairs must fall on an even boundary.
  141 
  142 alloc_class chunk0(R10,         R10_H,
  143                    R11,         R11_H,
  144                    R8,          R8_H,
  145                    R9,          R9_H,
  146                    R12,         R12_H,
  147                    RCX,         RCX_H,
  148                    RBX,         RBX_H,
  149                    RDI,         RDI_H,
  150                    RDX,         RDX_H,
  151                    RSI,         RSI_H,
  152                    RAX,         RAX_H,
  153                    RBP,         RBP_H,
  154                    R13,         R13_H,
  155                    R14,         R14_H,
  156                    R15,         R15_H,
  157                    RSP,         RSP_H);
  158 
  159 
  160 //----------Architecture Description Register Classes--------------------------
  161 // Several register classes are automatically defined based upon information in
  162 // this architecture description.
  163 // 1) reg_class inline_cache_reg           ( /* as def'd in frame section */ )
  164 // 2) reg_class stack_slots( /* one chunk of stack-based "registers" */ )
  165 //
  166 
  167 // Empty register class.
  168 reg_class no_reg();
  169 
  170 // Class for all pointer/long registers
  171 reg_class all_reg(RAX, RAX_H,
  172                   RDX, RDX_H,
  173                   RBP, RBP_H,
  174                   RDI, RDI_H,
  175                   RSI, RSI_H,
  176                   RCX, RCX_H,
  177                   RBX, RBX_H,
  178                   RSP, RSP_H,
  179                   R8,  R8_H,
  180                   R9,  R9_H,
  181                   R10, R10_H,
  182                   R11, R11_H,
  183                   R12, R12_H,
  184                   R13, R13_H,
  185                   R14, R14_H,
  186                   R15, R15_H);
  187 
  188 // Class for all int registers
  189 reg_class all_int_reg(RAX
  190                       RDX,
  191                       RBP,
  192                       RDI,
  193                       RSI,
  194                       RCX,
  195                       RBX,
  196                       R8,
  197                       R9,
  198                       R10,
  199                       R11,
  200                       R12,
  201                       R13,
  202                       R14);
  203 
  204 // Class for all pointer registers
  205 reg_class any_reg %{
  206   return _ANY_REG_mask;
  207 %}
  208 
  209 // Class for all pointer registers (excluding RSP)
  210 reg_class ptr_reg %{
  211   return _PTR_REG_mask;
  212 %}
  213 
  214 // Class for all pointer registers (excluding RSP and RBP)
  215 reg_class ptr_reg_no_rbp %{
  216   return _PTR_REG_NO_RBP_mask;
  217 %}
  218 
  219 // Class for all pointer registers (excluding RAX and RSP)
  220 reg_class ptr_no_rax_reg %{
  221   return _PTR_NO_RAX_REG_mask;
  222 %}
  223 
  224 // Class for all pointer registers (excluding RAX, RBX, and RSP)
  225 reg_class ptr_no_rax_rbx_reg %{
  226   return _PTR_NO_RAX_RBX_REG_mask;
  227 %}
  228 
  229 // Class for all long registers (excluding RSP)
  230 reg_class long_reg %{
  231   return _LONG_REG_mask;
  232 %}
  233 
  234 // Class for all long registers (excluding RAX, RDX and RSP)
  235 reg_class long_no_rax_rdx_reg %{
  236   return _LONG_NO_RAX_RDX_REG_mask;
  237 %}
  238 
  239 // Class for all long registers (excluding RCX and RSP)
  240 reg_class long_no_rcx_reg %{
  241   return _LONG_NO_RCX_REG_mask;
  242 %}
  243 
  244 // Class for all int registers (excluding RSP)
  245 reg_class int_reg %{
  246   return _INT_REG_mask;
  247 %}
  248 
  249 // Class for all int registers (excluding RAX, RDX, and RSP)
  250 reg_class int_no_rax_rdx_reg %{
  251   return _INT_NO_RAX_RDX_REG_mask;
  252 %}
  253 
  254 // Class for all int registers (excluding RCX and RSP)
  255 reg_class int_no_rcx_reg %{
  256   return _INT_NO_RCX_REG_mask;
  257 %}
  258 
  259 // Singleton class for RAX pointer register
  260 reg_class ptr_rax_reg(RAX, RAX_H);
  261 
  262 // Singleton class for RBX pointer register
  263 reg_class ptr_rbx_reg(RBX, RBX_H);
  264 
  265 // Singleton class for RSI pointer register
  266 reg_class ptr_rsi_reg(RSI, RSI_H);
  267 
  268 // Singleton class for RBP pointer register
  269 reg_class ptr_rbp_reg(RBP, RBP_H);
  270 
  271 // Singleton class for RDI pointer register
  272 reg_class ptr_rdi_reg(RDI, RDI_H);
  273 
  274 // Singleton class for stack pointer
  275 reg_class ptr_rsp_reg(RSP, RSP_H);
  276 
  277 // Singleton class for TLS pointer
  278 reg_class ptr_r15_reg(R15, R15_H);
  279 
  280 // Singleton class for RAX long register
  281 reg_class long_rax_reg(RAX, RAX_H);
  282 
  283 // Singleton class for RCX long register
  284 reg_class long_rcx_reg(RCX, RCX_H);
  285 
  286 // Singleton class for RDX long register
  287 reg_class long_rdx_reg(RDX, RDX_H);
  288 
  289 // Singleton class for RAX int register
  290 reg_class int_rax_reg(RAX);
  291 
  292 // Singleton class for RBX int register
  293 reg_class int_rbx_reg(RBX);
  294 
  295 // Singleton class for RCX int register
  296 reg_class int_rcx_reg(RCX);
  297 
  298 // Singleton class for RCX int register
  299 reg_class int_rdx_reg(RDX);
  300 
  301 // Singleton class for RCX int register
  302 reg_class int_rdi_reg(RDI);
  303 
  304 // Singleton class for instruction pointer
  305 // reg_class ip_reg(RIP);
  306 
  307 %}
  308 
  309 //----------SOURCE BLOCK-------------------------------------------------------
  310 // This is a block of C++ code which provides values, functions, and
  311 // definitions necessary in the rest of the architecture description
  312 source_hpp %{
  313 
  314 extern RegMask _ANY_REG_mask;
  315 extern RegMask _PTR_REG_mask;
  316 extern RegMask _PTR_REG_NO_RBP_mask;
  317 extern RegMask _PTR_NO_RAX_REG_mask;
  318 extern RegMask _PTR_NO_RAX_RBX_REG_mask;
  319 extern RegMask _LONG_REG_mask;
  320 extern RegMask _LONG_NO_RAX_RDX_REG_mask;
  321 extern RegMask _LONG_NO_RCX_REG_mask;
  322 extern RegMask _INT_REG_mask;
  323 extern RegMask _INT_NO_RAX_RDX_REG_mask;
  324 extern RegMask _INT_NO_RCX_REG_mask;
  325 extern RegMask _FLOAT_REG_mask;
  326 
  327 extern RegMask _STACK_OR_PTR_REG_mask;
  328 extern RegMask _STACK_OR_LONG_REG_mask;
  329 extern RegMask _STACK_OR_INT_REG_mask;
  330 
  331 inline const RegMask& STACK_OR_PTR_REG_mask()  { return _STACK_OR_PTR_REG_mask;  }
  332 inline const RegMask& STACK_OR_LONG_REG_mask() { return _STACK_OR_LONG_REG_mask; }
  333 inline const RegMask& STACK_OR_INT_REG_mask()  { return _STACK_OR_INT_REG_mask;  }
  334 
  335 %}
  336 
  337 source %{
  338 #define   RELOC_IMM64    Assembler::imm_operand
  339 #define   RELOC_DISP32   Assembler::disp32_operand
  340 
  341 #define __ _masm.
  342 
  343 RegMask _ANY_REG_mask;
  344 RegMask _PTR_REG_mask;
  345 RegMask _PTR_REG_NO_RBP_mask;
  346 RegMask _PTR_NO_RAX_REG_mask;
  347 RegMask _PTR_NO_RAX_RBX_REG_mask;
  348 RegMask _LONG_REG_mask;
  349 RegMask _LONG_NO_RAX_RDX_REG_mask;
  350 RegMask _LONG_NO_RCX_REG_mask;
  351 RegMask _INT_REG_mask;
  352 RegMask _INT_NO_RAX_RDX_REG_mask;
  353 RegMask _INT_NO_RCX_REG_mask;
  354 RegMask _FLOAT_REG_mask;
  355 RegMask _STACK_OR_PTR_REG_mask;
  356 RegMask _STACK_OR_LONG_REG_mask;
  357 RegMask _STACK_OR_INT_REG_mask;
  358 
  359 static bool need_r12_heapbase() {
  360   return UseCompressedOops;
  361 }
  362 
  363 void reg_mask_init() {
  364   // _ALL_REG_mask is generated by adlc from the all_reg register class below.
  365   // We derive a number of subsets from it.
  366   _ANY_REG_mask = _ALL_REG_mask;
  367 
  368   if (PreserveFramePointer) {
  369     _ANY_REG_mask.Remove(OptoReg::as_OptoReg(rbp->as_VMReg()));
  370     _ANY_REG_mask.Remove(OptoReg::as_OptoReg(rbp->as_VMReg()->next()));
  371   }
  372   if (need_r12_heapbase()) {
  373     _ANY_REG_mask.Remove(OptoReg::as_OptoReg(r12->as_VMReg()));
  374     _ANY_REG_mask.Remove(OptoReg::as_OptoReg(r12->as_VMReg()->next()));
  375   }
  376 
  377   _PTR_REG_mask = _ANY_REG_mask;
  378   _PTR_REG_mask.Remove(OptoReg::as_OptoReg(rsp->as_VMReg()));
  379   _PTR_REG_mask.Remove(OptoReg::as_OptoReg(rsp->as_VMReg()->next()));
  380   _PTR_REG_mask.Remove(OptoReg::as_OptoReg(r15->as_VMReg()));
  381   _PTR_REG_mask.Remove(OptoReg::as_OptoReg(r15->as_VMReg()->next()));
  382 
  383   _STACK_OR_PTR_REG_mask = _PTR_REG_mask;
  384   _STACK_OR_PTR_REG_mask.OR(STACK_OR_STACK_SLOTS_mask());
  385 
  386   _PTR_REG_NO_RBP_mask = _PTR_REG_mask;
  387   _PTR_REG_NO_RBP_mask.Remove(OptoReg::as_OptoReg(rbp->as_VMReg()));
  388   _PTR_REG_NO_RBP_mask.Remove(OptoReg::as_OptoReg(rbp->as_VMReg()->next()));
  389 
  390   _PTR_NO_RAX_REG_mask = _PTR_REG_mask;
  391   _PTR_NO_RAX_REG_mask.Remove(OptoReg::as_OptoReg(rax->as_VMReg()));
  392   _PTR_NO_RAX_REG_mask.Remove(OptoReg::as_OptoReg(rax->as_VMReg()->next()));
  393 
  394   _PTR_NO_RAX_RBX_REG_mask = _PTR_NO_RAX_REG_mask;
  395   _PTR_NO_RAX_RBX_REG_mask.Remove(OptoReg::as_OptoReg(rbx->as_VMReg()));
  396   _PTR_NO_RAX_RBX_REG_mask.Remove(OptoReg::as_OptoReg(rbx->as_VMReg()->next()));
  397 
  398   _LONG_REG_mask = _PTR_REG_mask;
  399   _STACK_OR_LONG_REG_mask = _LONG_REG_mask;
  400   _STACK_OR_LONG_REG_mask.OR(STACK_OR_STACK_SLOTS_mask());
  401 
  402   _LONG_NO_RAX_RDX_REG_mask = _LONG_REG_mask;
  403   _LONG_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rax->as_VMReg()));
  404   _LONG_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rax->as_VMReg()->next()));
  405   _LONG_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rdx->as_VMReg()));
  406   _LONG_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rdx->as_VMReg()->next()));
  407 
  408   _LONG_NO_RCX_REG_mask = _LONG_REG_mask;
  409   _LONG_NO_RCX_REG_mask.Remove(OptoReg::as_OptoReg(rcx->as_VMReg()));
  410   _LONG_NO_RCX_REG_mask.Remove(OptoReg::as_OptoReg(rcx->as_VMReg()->next()));
  411 
  412   _INT_REG_mask = _ALL_INT_REG_mask;
  413   if (PreserveFramePointer) {
  414     _INT_REG_mask.Remove(OptoReg::as_OptoReg(rbp->as_VMReg()));
  415   }
  416   if (need_r12_heapbase()) {
  417     _INT_REG_mask.Remove(OptoReg::as_OptoReg(r12->as_VMReg()));
  418   }
  419 
  420   _STACK_OR_INT_REG_mask = _INT_REG_mask;
  421   _STACK_OR_INT_REG_mask.OR(STACK_OR_STACK_SLOTS_mask());
  422 
  423   _INT_NO_RAX_RDX_REG_mask = _INT_REG_mask;
  424   _INT_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rax->as_VMReg()));
  425   _INT_NO_RAX_RDX_REG_mask.Remove(OptoReg::as_OptoReg(rdx->as_VMReg()));
  426 
  427   _INT_NO_RCX_REG_mask = _INT_REG_mask;
  428   _INT_NO_RCX_REG_mask.Remove(OptoReg::as_OptoReg(rcx->as_VMReg()));
  429 
  430   // _FLOAT_REG_LEGACY_mask/_FLOAT_REG_EVEX_mask is generated by adlc
  431   // from the float_reg_legacy/float_reg_evex register class.
  432   _FLOAT_REG_mask = VM_Version::supports_evex() ? _FLOAT_REG_EVEX_mask : _FLOAT_REG_LEGACY_mask;
  433 
  434   if (Matcher::has_predicated_vectors()) {
  435     // Post-loop multi-versioning expects mask to be present in K1 register, till the time
  436     // its fixed, RA should not be allocting K1 register, this shall prevent any accidental
  437     // curruption of value held in K1 register.
  438     if (PostLoopMultiversioning) {
  439       const_cast<RegMask*>(&_VECTMASK_REG_mask)->Remove(OptoReg::as_OptoReg(k1->as_VMReg()));
  440       const_cast<RegMask*>(&_VECTMASK_REG_mask)->Remove(OptoReg::as_OptoReg(k1->as_VMReg()->next()));
  441     }
  442   }
  443 }
  444 
  445 static bool generate_vzeroupper(Compile* C) {
  446   return (VM_Version::supports_vzeroupper() && (C->max_vector_size() > 16 || C->clear_upper_avx() == true)) ? true: false;  // Generate vzeroupper
  447 }
  448 
  449 static int clear_avx_size() {
  450   return generate_vzeroupper(Compile::current()) ? 3: 0;  // vzeroupper
  451 }
  452 
  453 // !!!!! Special hack to get all types of calls to specify the byte offset
  454 //       from the start of the call to the point where the return address
  455 //       will point.
  456 int MachCallStaticJavaNode::ret_addr_offset()
  457 {
  458   int offset = 5; // 5 bytes from start of call to where return address points
  459   offset += clear_avx_size();
  460   return offset;
  461 }
  462 
  463 int MachCallDynamicJavaNode::ret_addr_offset()
  464 {
  465   int offset = 15; // 15 bytes from start of call to where return address points
  466   offset += clear_avx_size();
  467   return offset;
  468 }
  469 
  470 int MachCallRuntimeNode::ret_addr_offset() {
  471   int offset = 13; // movq r10,#addr; callq (r10)
  472   if (this->ideal_Opcode() != Op_CallLeafVector) {
  473     offset += clear_avx_size();
  474   }
  475   return offset;
  476 }
  477 
  478 int MachCallNativeNode::ret_addr_offset() {
  479   int offset = 13; // movq r10,#addr; callq (r10)
  480   offset += clear_avx_size();
  481   return offset;
  482 }
  483 //
  484 // Compute padding required for nodes which need alignment
  485 //
  486 
  487 // The address of the call instruction needs to be 4-byte aligned to
  488 // ensure that it does not span a cache line so that it can be patched.
  489 int CallStaticJavaDirectNode::compute_padding(int current_offset) const
  490 {
  491   current_offset += clear_avx_size(); // skip vzeroupper
  492   current_offset += 1; // skip call opcode byte
  493   return align_up(current_offset, alignment_required()) - current_offset;
  494 }
  495 
  496 // The address of the call instruction needs to be 4-byte aligned to
  497 // ensure that it does not span a cache line so that it can be patched.
  498 int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
  499 {
  500   current_offset += clear_avx_size(); // skip vzeroupper
  501   current_offset += 11; // skip movq instruction + call opcode byte
  502   return align_up(current_offset, alignment_required()) - current_offset;
  503 }
  504 
  505 // EMIT_RM()
  506 void emit_rm(CodeBuffer &cbuf, int f1, int f2, int f3) {
  507   unsigned char c = (unsigned char) ((f1 << 6) | (f2 << 3) | f3);
  508   cbuf.insts()->emit_int8(c);
  509 }
  510 
  511 // EMIT_CC()
  512 void emit_cc(CodeBuffer &cbuf, int f1, int f2) {
  513   unsigned char c = (unsigned char) (f1 | f2);
  514   cbuf.insts()->emit_int8(c);
  515 }
  516 
  517 // EMIT_OPCODE()
  518 void emit_opcode(CodeBuffer &cbuf, int code) {
  519   cbuf.insts()->emit_int8((unsigned char) code);
  520 }
  521 
  522 // EMIT_OPCODE() w/ relocation information
  523 void emit_opcode(CodeBuffer &cbuf,
  524                  int code, relocInfo::relocType reloc, int offset, int format)
  525 {
  526   cbuf.relocate(cbuf.insts_mark() + offset, reloc, format);
  527   emit_opcode(cbuf, code);
  528 }
  529 
  530 // EMIT_D8()
  531 void emit_d8(CodeBuffer &cbuf, int d8) {
  532   cbuf.insts()->emit_int8((unsigned char) d8);
  533 }
  534 
  535 // EMIT_D16()
  536 void emit_d16(CodeBuffer &cbuf, int d16) {
  537   cbuf.insts()->emit_int16(d16);
  538 }
  539 
  540 // EMIT_D32()
  541 void emit_d32(CodeBuffer &cbuf, int d32) {
  542   cbuf.insts()->emit_int32(d32);
  543 }
  544 
  545 // EMIT_D64()
  546 void emit_d64(CodeBuffer &cbuf, int64_t d64) {
  547   cbuf.insts()->emit_int64(d64);
  548 }
  549 
  550 // emit 32 bit value and construct relocation entry from relocInfo::relocType
  551 void emit_d32_reloc(CodeBuffer& cbuf,
  552                     int d32,
  553                     relocInfo::relocType reloc,
  554                     int format)
  555 {
  556   assert(reloc != relocInfo::external_word_type, "use 2-arg emit_d32_reloc");
  557   cbuf.relocate(cbuf.insts_mark(), reloc, format);
  558   cbuf.insts()->emit_int32(d32);
  559 }
  560 
  561 // emit 32 bit value and construct relocation entry from RelocationHolder
  562 void emit_d32_reloc(CodeBuffer& cbuf, int d32, RelocationHolder const& rspec, int format) {
  563 #ifdef ASSERT
  564   if (rspec.reloc()->type() == relocInfo::oop_type &&
  565       d32 != 0 && d32 != (intptr_t) Universe::non_oop_word()) {
  566     assert(Universe::heap()->is_in((address)(intptr_t)d32), "should be real oop");
  567     assert(oopDesc::is_oop(cast_to_oop((intptr_t)d32)), "cannot embed broken oops in code");
  568   }
  569 #endif
  570   cbuf.relocate(cbuf.insts_mark(), rspec, format);
  571   cbuf.insts()->emit_int32(d32);
  572 }
  573 
  574 void emit_d32_reloc(CodeBuffer& cbuf, address addr) {
  575   address next_ip = cbuf.insts_end() + 4;
  576   emit_d32_reloc(cbuf, (int) (addr - next_ip),
  577                  external_word_Relocation::spec(addr),
  578                  RELOC_DISP32);
  579 }
  580 
  581 
  582 // emit 64 bit value and construct relocation entry from relocInfo::relocType
  583 void emit_d64_reloc(CodeBuffer& cbuf, int64_t d64, relocInfo::relocType reloc, int format) {
  584   cbuf.relocate(cbuf.insts_mark(), reloc, format);
  585   cbuf.insts()->emit_int64(d64);
  586 }
  587 
  588 // emit 64 bit value and construct relocation entry from RelocationHolder
  589 void emit_d64_reloc(CodeBuffer& cbuf, int64_t d64, RelocationHolder const& rspec, int format) {
  590 #ifdef ASSERT
  591   if (rspec.reloc()->type() == relocInfo::oop_type &&
  592       d64 != 0 && d64 != (int64_t) Universe::non_oop_word()) {
  593     assert(Universe::heap()->is_in((address)d64), "should be real oop");
  594     assert(oopDesc::is_oop(cast_to_oop(d64)), "cannot embed broken oops in code");
  595   }
  596 #endif
  597   cbuf.relocate(cbuf.insts_mark(), rspec, format);
  598   cbuf.insts()->emit_int64(d64);
  599 }
  600 
  601 // Access stack slot for load or store
  602 void store_to_stackslot(CodeBuffer &cbuf, int opcode, int rm_field, int disp)
  603 {
  604   emit_opcode(cbuf, opcode);                  // (e.g., FILD   [RSP+src])
  605   if (-0x80 <= disp && disp < 0x80) {
  606     emit_rm(cbuf, 0x01, rm_field, RSP_enc);   // R/M byte
  607     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
  608     emit_d8(cbuf, disp);     // Displacement  // R/M byte
  609   } else {
  610     emit_rm(cbuf, 0x02, rm_field, RSP_enc);   // R/M byte
  611     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
  612     emit_d32(cbuf, disp);     // Displacement // R/M byte
  613   }
  614 }
  615 
  616    // rRegI ereg, memory mem) %{    // emit_reg_mem
  617 void encode_RegMem(CodeBuffer &cbuf,
  618                    int reg,
  619                    int base, int index, int scale, int disp, relocInfo::relocType disp_reloc)
  620 {
  621   assert(disp_reloc == relocInfo::none, "cannot have disp");
  622   int regenc = reg & 7;
  623   int baseenc = base & 7;
  624   int indexenc = index & 7;
  625 
  626   // There is no index & no scale, use form without SIB byte
  627   if (index == 0x4 && scale == 0 && base != RSP_enc && base != R12_enc) {
  628     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
  629     if (disp == 0 && base != RBP_enc && base != R13_enc) {
  630       emit_rm(cbuf, 0x0, regenc, baseenc); // *
  631     } else if (-0x80 <= disp && disp < 0x80 && disp_reloc == relocInfo::none) {
  632       // If 8-bit displacement, mode 0x1
  633       emit_rm(cbuf, 0x1, regenc, baseenc); // *
  634       emit_d8(cbuf, disp);
  635     } else {
  636       // If 32-bit displacement
  637       if (base == -1) { // Special flag for absolute address
  638         emit_rm(cbuf, 0x0, regenc, 0x5); // *
  639         if (disp_reloc != relocInfo::none) {
  640           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
  641         } else {
  642           emit_d32(cbuf, disp);
  643         }
  644       } else {
  645         // Normal base + offset
  646         emit_rm(cbuf, 0x2, regenc, baseenc); // *
  647         if (disp_reloc != relocInfo::none) {
  648           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
  649         } else {
  650           emit_d32(cbuf, disp);
  651         }
  652       }
  653     }
  654   } else {
  655     // Else, encode with the SIB byte
  656     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
  657     if (disp == 0 && base != RBP_enc && base != R13_enc) {
  658       // If no displacement
  659       emit_rm(cbuf, 0x0, regenc, 0x4); // *
  660       emit_rm(cbuf, scale, indexenc, baseenc);
  661     } else {
  662       if (-0x80 <= disp && disp < 0x80 && disp_reloc == relocInfo::none) {
  663         // If 8-bit displacement, mode 0x1
  664         emit_rm(cbuf, 0x1, regenc, 0x4); // *
  665         emit_rm(cbuf, scale, indexenc, baseenc);
  666         emit_d8(cbuf, disp);
  667       } else {
  668         // If 32-bit displacement
  669         if (base == 0x04 ) {
  670           emit_rm(cbuf, 0x2, regenc, 0x4);
  671           emit_rm(cbuf, scale, indexenc, 0x04); // XXX is this valid???
  672         } else {
  673           emit_rm(cbuf, 0x2, regenc, 0x4);
  674           emit_rm(cbuf, scale, indexenc, baseenc); // *
  675         }
  676         if (disp_reloc != relocInfo::none) {
  677           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
  678         } else {
  679           emit_d32(cbuf, disp);
  680         }
  681       }
  682     }
  683   }
  684 }
  685 
  686 // This could be in MacroAssembler but it's fairly C2 specific
  687 void emit_cmpfp_fixup(MacroAssembler& _masm) {
  688   Label exit;
  689   __ jccb(Assembler::noParity, exit);
  690   __ pushf();
  691   //
  692   // comiss/ucomiss instructions set ZF,PF,CF flags and
  693   // zero OF,AF,SF for NaN values.
  694   // Fixup flags by zeroing ZF,PF so that compare of NaN
  695   // values returns 'less than' result (CF is set).
  696   // Leave the rest of flags unchanged.
  697   //
  698   //    7 6 5 4 3 2 1 0
  699   //   |S|Z|r|A|r|P|r|C|  (r - reserved bit)
  700   //    0 0 1 0 1 0 1 1   (0x2B)
  701   //
  702   __ andq(Address(rsp, 0), 0xffffff2b);
  703   __ popf();
  704   __ bind(exit);
  705 }
  706 
  707 void emit_cmpfp3(MacroAssembler& _masm, Register dst) {
  708   Label done;
  709   __ movl(dst, -1);
  710   __ jcc(Assembler::parity, done);
  711   __ jcc(Assembler::below, done);
  712   __ setb(Assembler::notEqual, dst);
  713   __ movzbl(dst, dst);
  714   __ bind(done);
  715 }
  716 
  717 // Math.min()    # Math.max()
  718 // --------------------------
  719 // ucomis[s/d]   #
  720 // ja   -> b     # a
  721 // jp   -> NaN   # NaN
  722 // jb   -> a     # b
  723 // je            #
  724 // |-jz -> a | b # a & b
  725 // |    -> a     #
  726 void emit_fp_min_max(MacroAssembler& _masm, XMMRegister dst,
  727                      XMMRegister a, XMMRegister b,
  728                      XMMRegister xmmt, Register rt,
  729                      bool min, bool single) {
  730 
  731   Label nan, zero, below, above, done;
  732 
  733   if (single)
  734     __ ucomiss(a, b);
  735   else
  736     __ ucomisd(a, b);
  737 
  738   if (dst->encoding() != (min ? b : a)->encoding())
  739     __ jccb(Assembler::above, above); // CF=0 & ZF=0
  740   else
  741     __ jccb(Assembler::above, done);
  742 
  743   __ jccb(Assembler::parity, nan);  // PF=1
  744   __ jccb(Assembler::below, below); // CF=1
  745 
  746   // equal
  747   __ vpxor(xmmt, xmmt, xmmt, Assembler::AVX_128bit);
  748   if (single) {
  749     __ ucomiss(a, xmmt);
  750     __ jccb(Assembler::equal, zero);
  751 
  752     __ movflt(dst, a);
  753     __ jmp(done);
  754   }
  755   else {
  756     __ ucomisd(a, xmmt);
  757     __ jccb(Assembler::equal, zero);
  758 
  759     __ movdbl(dst, a);
  760     __ jmp(done);
  761   }
  762 
  763   __ bind(zero);
  764   if (min)
  765     __ vpor(dst, a, b, Assembler::AVX_128bit);
  766   else
  767     __ vpand(dst, a, b, Assembler::AVX_128bit);
  768 
  769   __ jmp(done);
  770 
  771   __ bind(above);
  772   if (single)
  773     __ movflt(dst, min ? b : a);
  774   else
  775     __ movdbl(dst, min ? b : a);
  776 
  777   __ jmp(done);
  778 
  779   __ bind(nan);
  780   if (single) {
  781     __ movl(rt, 0x7fc00000); // Float.NaN
  782     __ movdl(dst, rt);
  783   }
  784   else {
  785     __ mov64(rt, 0x7ff8000000000000L); // Double.NaN
  786     __ movdq(dst, rt);
  787   }
  788   __ jmp(done);
  789 
  790   __ bind(below);
  791   if (single)
  792     __ movflt(dst, min ? a : b);
  793   else
  794     __ movdbl(dst, min ? a : b);
  795 
  796   __ bind(done);
  797 }
  798 
  799 //=============================================================================
  800 const RegMask& MachConstantBaseNode::_out_RegMask = RegMask::Empty;
  801 
  802 int ConstantTable::calculate_table_base_offset() const {
  803   return 0;  // absolute addressing, no offset
  804 }
  805 
  806 bool MachConstantBaseNode::requires_postalloc_expand() const { return false; }
  807 void MachConstantBaseNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {
  808   ShouldNotReachHere();
  809 }
  810 
  811 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
  812   // Empty encoding
  813 }
  814 
  815 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
  816   return 0;
  817 }
  818 
  819 #ifndef PRODUCT
  820 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
  821   st->print("# MachConstantBaseNode (empty encoding)");
  822 }
  823 #endif
  824 
  825 
  826 //=============================================================================
  827 #ifndef PRODUCT
  828 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
  829   Compile* C = ra_->C;
  830 
  831   int framesize = C->output()->frame_size_in_bytes();
  832   int bangsize = C->output()->bang_size_in_bytes();
  833   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
  834   // Remove wordSize for return addr which is already pushed.
  835   framesize -= wordSize;
  836 
  837   if (C->output()->need_stack_bang(bangsize)) {
  838     framesize -= wordSize;
  839     st->print("# stack bang (%d bytes)", bangsize);
  840     st->print("\n\t");
  841     st->print("pushq   rbp\t# Save rbp");
  842     if (PreserveFramePointer) {
  843         st->print("\n\t");
  844         st->print("movq    rbp, rsp\t# Save the caller's SP into rbp");
  845     }
  846     if (framesize) {
  847       st->print("\n\t");
  848       st->print("subq    rsp, #%d\t# Create frame",framesize);
  849     }
  850   } else {
  851     st->print("subq    rsp, #%d\t# Create frame",framesize);
  852     st->print("\n\t");
  853     framesize -= wordSize;
  854     st->print("movq    [rsp + #%d], rbp\t# Save rbp",framesize);
  855     if (PreserveFramePointer) {
  856       st->print("\n\t");
  857       st->print("movq    rbp, rsp\t# Save the caller's SP into rbp");
  858       if (framesize > 0) {
  859         st->print("\n\t");
  860         st->print("addq    rbp, #%d", framesize);
  861       }
  862     }
  863   }
  864 
  865   if (VerifyStackAtCalls) {
  866     st->print("\n\t");
  867     framesize -= wordSize;
  868     st->print("movq    [rsp + #%d], 0xbadb100d\t# Majik cookie for stack depth check",framesize);
  869 #ifdef ASSERT
  870     st->print("\n\t");
  871     st->print("# stack alignment check");
  872 #endif
  873   }
  874   if (C->stub_function() != NULL && BarrierSet::barrier_set()->barrier_set_nmethod() != NULL) {
  875     st->print("\n\t");
  876     st->print("cmpl    [r15_thread + #disarmed_offset], #disarmed_value\t");
  877     st->print("\n\t");
  878     st->print("je      fast_entry\t");
  879     st->print("\n\t");
  880     st->print("call    #nmethod_entry_barrier_stub\t");
  881     st->print("\n\tfast_entry:");
  882   }
  883   st->cr();
  884 }
  885 #endif
  886 
  887 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  888   Compile* C = ra_->C;
  889   MacroAssembler _masm(&cbuf);
  890 
  891   int framesize = C->output()->frame_size_in_bytes();
  892   int bangsize = C->output()->bang_size_in_bytes();
  893 
  894   if (C->clinit_barrier_on_entry()) {
  895     assert(VM_Version::supports_fast_class_init_checks(), "sanity");
  896     assert(!C->method()->holder()->is_not_initialized(), "initialization should have been started");
  897 
  898     Label L_skip_barrier;
  899     Register klass = rscratch1;
  900 
  901     __ mov_metadata(klass, C->method()->holder()->constant_encoding());
  902     __ clinit_barrier(klass, r15_thread, &L_skip_barrier /*L_fast_path*/);
  903 
  904     __ jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); // slow path
  905 
  906     __ bind(L_skip_barrier);
  907   }
  908 
  909   __ verified_entry(framesize, C->output()->need_stack_bang(bangsize)?bangsize:0, false, C->stub_function() != NULL);
  910 
  911   C->output()->set_frame_complete(cbuf.insts_size());
  912 
  913   if (C->has_mach_constant_base_node()) {
  914     // NOTE: We set the table base offset here because users might be
  915     // emitted before MachConstantBaseNode.
  916     ConstantTable& constant_table = C->output()->constant_table();
  917     constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
  918   }
  919 }
  920 
  921 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
  922 {
  923   return MachNode::size(ra_); // too many variables; just compute it
  924                               // the hard way
  925 }
  926 
  927 int MachPrologNode::reloc() const
  928 {
  929   return 0; // a large enough number
  930 }
  931 
  932 //=============================================================================
  933 #ifndef PRODUCT
  934 void MachEpilogNode::format(PhaseRegAlloc* ra_, outputStream* st) const
  935 {
  936   Compile* C = ra_->C;
  937   if (generate_vzeroupper(C)) {
  938     st->print("vzeroupper");
  939     st->cr(); st->print("\t");
  940   }
  941 
  942   int framesize = C->output()->frame_size_in_bytes();
  943   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
  944   // Remove word for return adr already pushed
  945   // and RBP
  946   framesize -= 2*wordSize;
  947 
  948   if (framesize) {
  949     st->print_cr("addq    rsp, %d\t# Destroy frame", framesize);
  950     st->print("\t");
  951   }
  952 
  953   st->print_cr("popq    rbp");
  954   if (do_polling() && C->is_method_compilation()) {
  955     st->print("\t");
  956     st->print_cr("cmpq     rsp, poll_offset[r15_thread] \n\t"
  957                  "ja       #safepoint_stub\t"
  958                  "# Safepoint: poll for GC");
  959   }
  960 }
  961 #endif
  962 
  963 void MachEpilogNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
  964 {
  965   Compile* C = ra_->C;
  966   MacroAssembler _masm(&cbuf);
  967 
  968   if (generate_vzeroupper(C)) {
  969     // Clear upper bits of YMM registers when current compiled code uses
  970     // wide vectors to avoid AVX <-> SSE transition penalty during call.
  971     __ vzeroupper();
  972   }
  973 
  974   int framesize = C->output()->frame_size_in_bytes();
  975   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
  976   // Remove word for return adr already pushed
  977   // and RBP
  978   framesize -= 2*wordSize;
  979 
  980   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
  981 
  982   if (framesize) {
  983     emit_opcode(cbuf, Assembler::REX_W);
  984     if (framesize < 0x80) {
  985       emit_opcode(cbuf, 0x83); // addq rsp, #framesize
  986       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
  987       emit_d8(cbuf, framesize);
  988     } else {
  989       emit_opcode(cbuf, 0x81); // addq rsp, #framesize
  990       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
  991       emit_d32(cbuf, framesize);
  992     }
  993   }
  994 
  995   // popq rbp
  996   emit_opcode(cbuf, 0x58 | RBP_enc);
  997 
  998   if (StackReservedPages > 0 && C->has_reserved_stack_access()) {
  999     __ reserved_stack_check();
 1000   }
 1001 
 1002   if (do_polling() && C->is_method_compilation()) {
 1003     MacroAssembler _masm(&cbuf);
 1004     Label dummy_label;
 1005     Label* code_stub = &dummy_label;
 1006     if (!C->output()->in_scratch_emit_size()) {
 1007       code_stub = &C->output()->safepoint_poll_table()->add_safepoint(__ offset());
 1008     }
 1009     __ relocate(relocInfo::poll_return_type);
 1010     __ safepoint_poll(*code_stub, r15_thread, true /* at_return */, true /* in_nmethod */);
 1011   }
 1012 }
 1013 
 1014 uint MachEpilogNode::size(PhaseRegAlloc* ra_) const
 1015 {
 1016   return MachNode::size(ra_); // too many variables; just compute it
 1017                               // the hard way
 1018 }
 1019 
 1020 int MachEpilogNode::reloc() const
 1021 {
 1022   return 2; // a large enough number
 1023 }
 1024 
 1025 const Pipeline* MachEpilogNode::pipeline() const
 1026 {
 1027   return MachNode::pipeline_class();
 1028 }
 1029 
 1030 //=============================================================================
 1031 
 1032 enum RC {
 1033   rc_bad,
 1034   rc_int,
 1035   rc_kreg,
 1036   rc_float,
 1037   rc_stack
 1038 };
 1039 
 1040 static enum RC rc_class(OptoReg::Name reg)
 1041 {
 1042   if( !OptoReg::is_valid(reg)  ) return rc_bad;
 1043 
 1044   if (OptoReg::is_stack(reg)) return rc_stack;
 1045 
 1046   VMReg r = OptoReg::as_VMReg(reg);
 1047 
 1048   if (r->is_Register()) return rc_int;
 1049 
 1050   if (r->is_KRegister()) return rc_kreg;
 1051 
 1052   assert(r->is_XMMRegister(), "must be");
 1053   return rc_float;
 1054 }
 1055 
 1056 // Next two methods are shared by 32- and 64-bit VM. They are defined in x86.ad.
 1057 static void vec_mov_helper(CodeBuffer *cbuf, int src_lo, int dst_lo,
 1058                           int src_hi, int dst_hi, uint ireg, outputStream* st);
 1059 
 1060 void vec_spill_helper(CodeBuffer *cbuf, bool is_load,
 1061                      int stack_offset, int reg, uint ireg, outputStream* st);
 1062 
 1063 static void vec_stack_to_stack_helper(CodeBuffer *cbuf, int src_offset,
 1064                                       int dst_offset, uint ireg, outputStream* st) {
 1065   if (cbuf) {
 1066     MacroAssembler _masm(cbuf);
 1067     switch (ireg) {
 1068     case Op_VecS:
 1069       __ movq(Address(rsp, -8), rax);
 1070       __ movl(rax, Address(rsp, src_offset));
 1071       __ movl(Address(rsp, dst_offset), rax);
 1072       __ movq(rax, Address(rsp, -8));
 1073       break;
 1074     case Op_VecD:
 1075       __ pushq(Address(rsp, src_offset));
 1076       __ popq (Address(rsp, dst_offset));
 1077       break;
 1078     case Op_VecX:
 1079       __ pushq(Address(rsp, src_offset));
 1080       __ popq (Address(rsp, dst_offset));
 1081       __ pushq(Address(rsp, src_offset+8));
 1082       __ popq (Address(rsp, dst_offset+8));
 1083       break;
 1084     case Op_VecY:
 1085       __ vmovdqu(Address(rsp, -32), xmm0);
 1086       __ vmovdqu(xmm0, Address(rsp, src_offset));
 1087       __ vmovdqu(Address(rsp, dst_offset), xmm0);
 1088       __ vmovdqu(xmm0, Address(rsp, -32));
 1089       break;
 1090     case Op_VecZ:
 1091       __ evmovdquq(Address(rsp, -64), xmm0, 2);
 1092       __ evmovdquq(xmm0, Address(rsp, src_offset), 2);
 1093       __ evmovdquq(Address(rsp, dst_offset), xmm0, 2);
 1094       __ evmovdquq(xmm0, Address(rsp, -64), 2);
 1095       break;
 1096     default:
 1097       ShouldNotReachHere();
 1098     }
 1099 #ifndef PRODUCT
 1100   } else {
 1101     switch (ireg) {
 1102     case Op_VecS:
 1103       st->print("movq    [rsp - #8], rax\t# 32-bit mem-mem spill\n\t"
 1104                 "movl    rax, [rsp + #%d]\n\t"
 1105                 "movl    [rsp + #%d], rax\n\t"
 1106                 "movq    rax, [rsp - #8]",
 1107                 src_offset, dst_offset);
 1108       break;
 1109     case Op_VecD:
 1110       st->print("pushq   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
 1111                 "popq    [rsp + #%d]",
 1112                 src_offset, dst_offset);
 1113       break;
 1114      case Op_VecX:
 1115       st->print("pushq   [rsp + #%d]\t# 128-bit mem-mem spill\n\t"
 1116                 "popq    [rsp + #%d]\n\t"
 1117                 "pushq   [rsp + #%d]\n\t"
 1118                 "popq    [rsp + #%d]",
 1119                 src_offset, dst_offset, src_offset+8, dst_offset+8);
 1120       break;
 1121     case Op_VecY:
 1122       st->print("vmovdqu [rsp - #32], xmm0\t# 256-bit mem-mem spill\n\t"
 1123                 "vmovdqu xmm0, [rsp + #%d]\n\t"
 1124                 "vmovdqu [rsp + #%d], xmm0\n\t"
 1125                 "vmovdqu xmm0, [rsp - #32]",
 1126                 src_offset, dst_offset);
 1127       break;
 1128     case Op_VecZ:
 1129       st->print("vmovdqu [rsp - #64], xmm0\t# 512-bit mem-mem spill\n\t"
 1130                 "vmovdqu xmm0, [rsp + #%d]\n\t"
 1131                 "vmovdqu [rsp + #%d], xmm0\n\t"
 1132                 "vmovdqu xmm0, [rsp - #64]",
 1133                 src_offset, dst_offset);
 1134       break;
 1135     default:
 1136       ShouldNotReachHere();
 1137     }
 1138 #endif
 1139   }
 1140 }
 1141 
 1142 uint MachSpillCopyNode::implementation(CodeBuffer* cbuf,
 1143                                        PhaseRegAlloc* ra_,
 1144                                        bool do_size,
 1145                                        outputStream* st) const {
 1146   assert(cbuf != NULL || st  != NULL, "sanity");
 1147   // Get registers to move
 1148   OptoReg::Name src_second = ra_->get_reg_second(in(1));
 1149   OptoReg::Name src_first = ra_->get_reg_first(in(1));
 1150   OptoReg::Name dst_second = ra_->get_reg_second(this);
 1151   OptoReg::Name dst_first = ra_->get_reg_first(this);
 1152 
 1153   enum RC src_second_rc = rc_class(src_second);
 1154   enum RC src_first_rc = rc_class(src_first);
 1155   enum RC dst_second_rc = rc_class(dst_second);
 1156   enum RC dst_first_rc = rc_class(dst_first);
 1157 
 1158   assert(OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first),
 1159          "must move at least 1 register" );
 1160 
 1161   if (src_first == dst_first && src_second == dst_second) {
 1162     // Self copy, no move
 1163     return 0;
 1164   }
 1165   if (bottom_type()->isa_vect() != NULL && bottom_type()->isa_vectmask() == NULL) {
 1166     uint ireg = ideal_reg();
 1167     assert((src_first_rc != rc_int && dst_first_rc != rc_int), "sanity");
 1168     assert((ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY || ireg == Op_VecZ ), "sanity");
 1169     if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
 1170       // mem -> mem
 1171       int src_offset = ra_->reg2offset(src_first);
 1172       int dst_offset = ra_->reg2offset(dst_first);
 1173       vec_stack_to_stack_helper(cbuf, src_offset, dst_offset, ireg, st);
 1174     } else if (src_first_rc == rc_float && dst_first_rc == rc_float ) {
 1175       vec_mov_helper(cbuf, src_first, dst_first, src_second, dst_second, ireg, st);
 1176     } else if (src_first_rc == rc_float && dst_first_rc == rc_stack ) {
 1177       int stack_offset = ra_->reg2offset(dst_first);
 1178       vec_spill_helper(cbuf, false, stack_offset, src_first, ireg, st);
 1179     } else if (src_first_rc == rc_stack && dst_first_rc == rc_float ) {
 1180       int stack_offset = ra_->reg2offset(src_first);
 1181       vec_spill_helper(cbuf, true,  stack_offset, dst_first, ireg, st);
 1182     } else {
 1183       ShouldNotReachHere();
 1184     }
 1185     return 0;
 1186   }
 1187   if (src_first_rc == rc_stack) {
 1188     // mem ->
 1189     if (dst_first_rc == rc_stack) {
 1190       // mem -> mem
 1191       assert(src_second != dst_first, "overlap");
 1192       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1193           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1194         // 64-bit
 1195         int src_offset = ra_->reg2offset(src_first);
 1196         int dst_offset = ra_->reg2offset(dst_first);
 1197         if (cbuf) {
 1198           MacroAssembler _masm(cbuf);
 1199           __ pushq(Address(rsp, src_offset));
 1200           __ popq (Address(rsp, dst_offset));
 1201 #ifndef PRODUCT
 1202         } else {
 1203           st->print("pushq   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
 1204                     "popq    [rsp + #%d]",
 1205                      src_offset, dst_offset);
 1206 #endif
 1207         }
 1208       } else {
 1209         // 32-bit
 1210         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1211         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1212         // No pushl/popl, so:
 1213         int src_offset = ra_->reg2offset(src_first);
 1214         int dst_offset = ra_->reg2offset(dst_first);
 1215         if (cbuf) {
 1216           MacroAssembler _masm(cbuf);
 1217           __ movq(Address(rsp, -8), rax);
 1218           __ movl(rax, Address(rsp, src_offset));
 1219           __ movl(Address(rsp, dst_offset), rax);
 1220           __ movq(rax, Address(rsp, -8));
 1221 #ifndef PRODUCT
 1222         } else {
 1223           st->print("movq    [rsp - #8], rax\t# 32-bit mem-mem spill\n\t"
 1224                     "movl    rax, [rsp + #%d]\n\t"
 1225                     "movl    [rsp + #%d], rax\n\t"
 1226                     "movq    rax, [rsp - #8]",
 1227                      src_offset, dst_offset);
 1228 #endif
 1229         }
 1230       }
 1231       return 0;
 1232     } else if (dst_first_rc == rc_int) {
 1233       // mem -> gpr
 1234       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1235           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1236         // 64-bit
 1237         int offset = ra_->reg2offset(src_first);
 1238         if (cbuf) {
 1239           MacroAssembler _masm(cbuf);
 1240           __ movq(as_Register(Matcher::_regEncode[dst_first]), Address(rsp, offset));
 1241 #ifndef PRODUCT
 1242         } else {
 1243           st->print("movq    %s, [rsp + #%d]\t# spill",
 1244                      Matcher::regName[dst_first],
 1245                      offset);
 1246 #endif
 1247         }
 1248       } else {
 1249         // 32-bit
 1250         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1251         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1252         int offset = ra_->reg2offset(src_first);
 1253         if (cbuf) {
 1254           MacroAssembler _masm(cbuf);
 1255           __ movl(as_Register(Matcher::_regEncode[dst_first]), Address(rsp, offset));
 1256 #ifndef PRODUCT
 1257         } else {
 1258           st->print("movl    %s, [rsp + #%d]\t# spill",
 1259                      Matcher::regName[dst_first],
 1260                      offset);
 1261 #endif
 1262         }
 1263       }
 1264       return 0;
 1265     } else if (dst_first_rc == rc_float) {
 1266       // mem-> xmm
 1267       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1268           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1269         // 64-bit
 1270         int offset = ra_->reg2offset(src_first);
 1271         if (cbuf) {
 1272           MacroAssembler _masm(cbuf);
 1273           __ movdbl( as_XMMRegister(Matcher::_regEncode[dst_first]), Address(rsp, offset));
 1274 #ifndef PRODUCT
 1275         } else {
 1276           st->print("%s  %s, [rsp + #%d]\t# spill",
 1277                      UseXmmLoadAndClearUpper ? "movsd " : "movlpd",
 1278                      Matcher::regName[dst_first],
 1279                      offset);
 1280 #endif
 1281         }
 1282       } else {
 1283         // 32-bit
 1284         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1285         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1286         int offset = ra_->reg2offset(src_first);
 1287         if (cbuf) {
 1288           MacroAssembler _masm(cbuf);
 1289           __ movflt( as_XMMRegister(Matcher::_regEncode[dst_first]), Address(rsp, offset));
 1290 #ifndef PRODUCT
 1291         } else {
 1292           st->print("movss   %s, [rsp + #%d]\t# spill",
 1293                      Matcher::regName[dst_first],
 1294                      offset);
 1295 #endif
 1296         }
 1297       }
 1298       return 0;
 1299     } else if (dst_first_rc == rc_kreg) {
 1300       // mem -> kreg
 1301       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1302           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1303         // 64-bit
 1304         int offset = ra_->reg2offset(src_first);
 1305         if (cbuf) {
 1306           MacroAssembler _masm(cbuf);
 1307           __ kmov(as_KRegister(Matcher::_regEncode[dst_first]), Address(rsp, offset));
 1308 #ifndef PRODUCT
 1309         } else {
 1310           st->print("kmovq   %s, [rsp + #%d]\t# spill",
 1311                      Matcher::regName[dst_first],
 1312                      offset);
 1313 #endif
 1314         }
 1315       }
 1316       return 0;
 1317     }
 1318   } else if (src_first_rc == rc_int) {
 1319     // gpr ->
 1320     if (dst_first_rc == rc_stack) {
 1321       // gpr -> mem
 1322       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1323           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1324         // 64-bit
 1325         int offset = ra_->reg2offset(dst_first);
 1326         if (cbuf) {
 1327           MacroAssembler _masm(cbuf);
 1328           __ movq(Address(rsp, offset), as_Register(Matcher::_regEncode[src_first]));
 1329 #ifndef PRODUCT
 1330         } else {
 1331           st->print("movq    [rsp + #%d], %s\t# spill",
 1332                      offset,
 1333                      Matcher::regName[src_first]);
 1334 #endif
 1335         }
 1336       } else {
 1337         // 32-bit
 1338         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1339         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1340         int offset = ra_->reg2offset(dst_first);
 1341         if (cbuf) {
 1342           MacroAssembler _masm(cbuf);
 1343           __ movl(Address(rsp, offset), as_Register(Matcher::_regEncode[src_first]));
 1344 #ifndef PRODUCT
 1345         } else {
 1346           st->print("movl    [rsp + #%d], %s\t# spill",
 1347                      offset,
 1348                      Matcher::regName[src_first]);
 1349 #endif
 1350         }
 1351       }
 1352       return 0;
 1353     } else if (dst_first_rc == rc_int) {
 1354       // gpr -> gpr
 1355       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1356           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1357         // 64-bit
 1358         if (cbuf) {
 1359           MacroAssembler _masm(cbuf);
 1360           __ movq(as_Register(Matcher::_regEncode[dst_first]),
 1361                   as_Register(Matcher::_regEncode[src_first]));
 1362 #ifndef PRODUCT
 1363         } else {
 1364           st->print("movq    %s, %s\t# spill",
 1365                      Matcher::regName[dst_first],
 1366                      Matcher::regName[src_first]);
 1367 #endif
 1368         }
 1369         return 0;
 1370       } else {
 1371         // 32-bit
 1372         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1373         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1374         if (cbuf) {
 1375           MacroAssembler _masm(cbuf);
 1376           __ movl(as_Register(Matcher::_regEncode[dst_first]),
 1377                   as_Register(Matcher::_regEncode[src_first]));
 1378 #ifndef PRODUCT
 1379         } else {
 1380           st->print("movl    %s, %s\t# spill",
 1381                      Matcher::regName[dst_first],
 1382                      Matcher::regName[src_first]);
 1383 #endif
 1384         }
 1385         return 0;
 1386       }
 1387     } else if (dst_first_rc == rc_float) {
 1388       // gpr -> xmm
 1389       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1390           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1391         // 64-bit
 1392         if (cbuf) {
 1393           MacroAssembler _masm(cbuf);
 1394           __ movdq( as_XMMRegister(Matcher::_regEncode[dst_first]), as_Register(Matcher::_regEncode[src_first]));
 1395 #ifndef PRODUCT
 1396         } else {
 1397           st->print("movdq   %s, %s\t# spill",
 1398                      Matcher::regName[dst_first],
 1399                      Matcher::regName[src_first]);
 1400 #endif
 1401         }
 1402       } else {
 1403         // 32-bit
 1404         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1405         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1406         if (cbuf) {
 1407           MacroAssembler _masm(cbuf);
 1408           __ movdl( as_XMMRegister(Matcher::_regEncode[dst_first]), as_Register(Matcher::_regEncode[src_first]));
 1409 #ifndef PRODUCT
 1410         } else {
 1411           st->print("movdl   %s, %s\t# spill",
 1412                      Matcher::regName[dst_first],
 1413                      Matcher::regName[src_first]);
 1414 #endif
 1415         }
 1416       }
 1417       return 0;
 1418     } else if (dst_first_rc == rc_kreg) {
 1419       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1420           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1421         // 64-bit
 1422         if (cbuf) {
 1423           MacroAssembler _masm(cbuf);
 1424           __ kmov(as_KRegister(Matcher::_regEncode[dst_first]), as_Register(Matcher::_regEncode[src_first]));
 1425   #ifndef PRODUCT
 1426         } else {
 1427            st->print("kmovq   %s, %s\t# spill",
 1428                        Matcher::regName[dst_first],
 1429                        Matcher::regName[src_first]);
 1430   #endif
 1431         }
 1432       }
 1433       Unimplemented();
 1434       return 0;
 1435     }
 1436   } else if (src_first_rc == rc_float) {
 1437     // xmm ->
 1438     if (dst_first_rc == rc_stack) {
 1439       // xmm -> mem
 1440       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1441           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1442         // 64-bit
 1443         int offset = ra_->reg2offset(dst_first);
 1444         if (cbuf) {
 1445           MacroAssembler _masm(cbuf);
 1446           __ movdbl( Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[src_first]));
 1447 #ifndef PRODUCT
 1448         } else {
 1449           st->print("movsd   [rsp + #%d], %s\t# spill",
 1450                      offset,
 1451                      Matcher::regName[src_first]);
 1452 #endif
 1453         }
 1454       } else {
 1455         // 32-bit
 1456         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1457         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1458         int offset = ra_->reg2offset(dst_first);
 1459         if (cbuf) {
 1460           MacroAssembler _masm(cbuf);
 1461           __ movflt(Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[src_first]));
 1462 #ifndef PRODUCT
 1463         } else {
 1464           st->print("movss   [rsp + #%d], %s\t# spill",
 1465                      offset,
 1466                      Matcher::regName[src_first]);
 1467 #endif
 1468         }
 1469       }
 1470       return 0;
 1471     } else if (dst_first_rc == rc_int) {
 1472       // xmm -> gpr
 1473       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1474           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1475         // 64-bit
 1476         if (cbuf) {
 1477           MacroAssembler _masm(cbuf);
 1478           __ movdq( as_Register(Matcher::_regEncode[dst_first]), as_XMMRegister(Matcher::_regEncode[src_first]));
 1479 #ifndef PRODUCT
 1480         } else {
 1481           st->print("movdq   %s, %s\t# spill",
 1482                      Matcher::regName[dst_first],
 1483                      Matcher::regName[src_first]);
 1484 #endif
 1485         }
 1486       } else {
 1487         // 32-bit
 1488         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1489         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1490         if (cbuf) {
 1491           MacroAssembler _masm(cbuf);
 1492           __ movdl( as_Register(Matcher::_regEncode[dst_first]), as_XMMRegister(Matcher::_regEncode[src_first]));
 1493 #ifndef PRODUCT
 1494         } else {
 1495           st->print("movdl   %s, %s\t# spill",
 1496                      Matcher::regName[dst_first],
 1497                      Matcher::regName[src_first]);
 1498 #endif
 1499         }
 1500       }
 1501       return 0;
 1502     } else if (dst_first_rc == rc_float) {
 1503       // xmm -> xmm
 1504       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1505           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1506         // 64-bit
 1507         if (cbuf) {
 1508           MacroAssembler _masm(cbuf);
 1509           __ movdbl( as_XMMRegister(Matcher::_regEncode[dst_first]), as_XMMRegister(Matcher::_regEncode[src_first]));
 1510 #ifndef PRODUCT
 1511         } else {
 1512           st->print("%s  %s, %s\t# spill",
 1513                      UseXmmRegToRegMoveAll ? "movapd" : "movsd ",
 1514                      Matcher::regName[dst_first],
 1515                      Matcher::regName[src_first]);
 1516 #endif
 1517         }
 1518       } else {
 1519         // 32-bit
 1520         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
 1521         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
 1522         if (cbuf) {
 1523           MacroAssembler _masm(cbuf);
 1524           __ movflt( as_XMMRegister(Matcher::_regEncode[dst_first]), as_XMMRegister(Matcher::_regEncode[src_first]));
 1525 #ifndef PRODUCT
 1526         } else {
 1527           st->print("%s  %s, %s\t# spill",
 1528                      UseXmmRegToRegMoveAll ? "movaps" : "movss ",
 1529                      Matcher::regName[dst_first],
 1530                      Matcher::regName[src_first]);
 1531 #endif
 1532         }
 1533       }
 1534       return 0;
 1535     } else if (dst_first_rc == rc_kreg) {
 1536       assert(false, "Illegal spilling");
 1537       return 0;
 1538     }
 1539   } else if (src_first_rc == rc_kreg) {
 1540     if (dst_first_rc == rc_stack) {
 1541       // mem -> kreg
 1542       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1543           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1544         // 64-bit
 1545         int offset = ra_->reg2offset(dst_first);
 1546         if (cbuf) {
 1547           MacroAssembler _masm(cbuf);
 1548           __ kmov(Address(rsp, offset), as_KRegister(Matcher::_regEncode[src_first]));
 1549 #ifndef PRODUCT
 1550         } else {
 1551           st->print("kmovq   [rsp + #%d] , %s\t# spill",
 1552                      offset,
 1553                      Matcher::regName[src_first]);
 1554 #endif
 1555         }
 1556       }
 1557       return 0;
 1558     } else if (dst_first_rc == rc_int) {
 1559       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1560           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1561         // 64-bit
 1562         if (cbuf) {
 1563           MacroAssembler _masm(cbuf);
 1564           __ kmov(as_Register(Matcher::_regEncode[dst_first]), as_KRegister(Matcher::_regEncode[src_first]));
 1565 #ifndef PRODUCT
 1566         } else {
 1567          st->print("kmovq   %s, %s\t# spill",
 1568                      Matcher::regName[dst_first],
 1569                      Matcher::regName[src_first]);
 1570 #endif
 1571         }
 1572       }
 1573       Unimplemented();
 1574       return 0;
 1575     } else if (dst_first_rc == rc_kreg) {
 1576       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
 1577           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
 1578         // 64-bit
 1579         if (cbuf) {
 1580           MacroAssembler _masm(cbuf);
 1581           __ kmov(as_KRegister(Matcher::_regEncode[dst_first]), as_KRegister(Matcher::_regEncode[src_first]));
 1582 #ifndef PRODUCT
 1583         } else {
 1584          st->print("kmovq   %s, %s\t# spill",
 1585                      Matcher::regName[dst_first],
 1586                      Matcher::regName[src_first]);
 1587 #endif
 1588         }
 1589       }
 1590       return 0;
 1591     } else if (dst_first_rc == rc_float) {
 1592       assert(false, "Illegal spill");
 1593       return 0;
 1594     }
 1595   }
 1596 
 1597   assert(0," foo ");
 1598   Unimplemented();
 1599   return 0;
 1600 }
 1601 
 1602 #ifndef PRODUCT
 1603 void MachSpillCopyNode::format(PhaseRegAlloc *ra_, outputStream* st) const {
 1604   implementation(NULL, ra_, false, st);
 1605 }
 1606 #endif
 1607 
 1608 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 1609   implementation(&cbuf, ra_, false, NULL);
 1610 }
 1611 
 1612 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const {
 1613   return MachNode::size(ra_);
 1614 }
 1615 
 1616 //=============================================================================
 1617 #ifndef PRODUCT
 1618 void BoxLockNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 1619 {
 1620   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
 1621   int reg = ra_->get_reg_first(this);
 1622   st->print("leaq    %s, [rsp + #%d]\t# box lock",
 1623             Matcher::regName[reg], offset);
 1624 }
 1625 #endif
 1626 
 1627 void BoxLockNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
 1628 {
 1629   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
 1630   int reg = ra_->get_encode(this);
 1631   if (offset >= 0x80) {
 1632     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
 1633     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
 1634     emit_rm(cbuf, 0x2, reg & 7, 0x04);
 1635     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
 1636     emit_d32(cbuf, offset);
 1637   } else {
 1638     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
 1639     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
 1640     emit_rm(cbuf, 0x1, reg & 7, 0x04);
 1641     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
 1642     emit_d8(cbuf, offset);
 1643   }
 1644 }
 1645 
 1646 uint BoxLockNode::size(PhaseRegAlloc *ra_) const
 1647 {
 1648   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
 1649   return (offset < 0x80) ? 5 : 8; // REX
 1650 }
 1651 
 1652 //=============================================================================
 1653 #ifndef PRODUCT
 1654 void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 1655 {
 1656   if (UseCompressedClassPointers) {
 1657     st->print_cr("movl    rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
 1658     st->print_cr("\tdecode_klass_not_null rscratch1, rscratch1");
 1659     st->print_cr("\tcmpq    rax, rscratch1\t # Inline cache check");
 1660   } else {
 1661     st->print_cr("\tcmpq    rax, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t"
 1662                  "# Inline cache check");
 1663   }
 1664   st->print_cr("\tjne     SharedRuntime::_ic_miss_stub");
 1665   st->print_cr("\tnop\t# nops to align entry point");
 1666 }
 1667 #endif
 1668 
 1669 void MachUEPNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
 1670 {
 1671   MacroAssembler masm(&cbuf);
 1672   uint insts_size = cbuf.insts_size();
 1673   if (UseCompressedClassPointers) {
 1674     masm.load_klass(rscratch1, j_rarg0, rscratch2);
 1675     masm.cmpptr(rax, rscratch1);
 1676   } else {
 1677     masm.cmpptr(rax, Address(j_rarg0, oopDesc::klass_offset_in_bytes()));
 1678   }
 1679 
 1680   masm.jump_cc(Assembler::notEqual, RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
 1681 
 1682   /* WARNING these NOPs are critical so that verified entry point is properly
 1683      4 bytes aligned for patching by NativeJump::patch_verified_entry() */
 1684   int nops_cnt = 4 - ((cbuf.insts_size() - insts_size) & 0x3);
 1685   if (OptoBreakpoint) {
 1686     // Leave space for int3
 1687     nops_cnt -= 1;
 1688   }
 1689   nops_cnt &= 0x3; // Do not add nops if code is aligned.
 1690   if (nops_cnt > 0)
 1691     masm.nop(nops_cnt);
 1692 }
 1693 
 1694 uint MachUEPNode::size(PhaseRegAlloc* ra_) const
 1695 {
 1696   return MachNode::size(ra_); // too many variables; just compute it
 1697                               // the hard way
 1698 }
 1699 
 1700 
 1701 //=============================================================================
 1702 
 1703 const bool Matcher::supports_vector_calling_convention(void) {
 1704   if (EnableVectorSupport && UseVectorStubs) {
 1705     return true;
 1706   }
 1707   return false;
 1708 }
 1709 
 1710 OptoRegPair Matcher::vector_return_value(uint ideal_reg) {
 1711   assert(EnableVectorSupport && UseVectorStubs, "sanity");
 1712   int lo = XMM0_num;
 1713   int hi = XMM0b_num;
 1714   if (ideal_reg == Op_VecX) hi = XMM0d_num;
 1715   else if (ideal_reg == Op_VecY) hi = XMM0h_num;
 1716   else if (ideal_reg == Op_VecZ) hi = XMM0p_num;
 1717   return OptoRegPair(hi, lo);
 1718 }
 1719 
 1720 // Is this branch offset short enough that a short branch can be used?
 1721 //
 1722 // NOTE: If the platform does not provide any short branch variants, then
 1723 //       this method should return false for offset 0.
 1724 bool Matcher::is_short_branch_offset(int rule, int br_size, int offset) {
 1725   // The passed offset is relative to address of the branch.
 1726   // On 86 a branch displacement is calculated relative to address
 1727   // of a next instruction.
 1728   offset -= br_size;
 1729 
 1730   // the short version of jmpConUCF2 contains multiple branches,
 1731   // making the reach slightly less
 1732   if (rule == jmpConUCF2_rule)
 1733     return (-126 <= offset && offset <= 125);
 1734   return (-128 <= offset && offset <= 127);
 1735 }
 1736 
 1737 // Return whether or not this register is ever used as an argument.
 1738 // This function is used on startup to build the trampoline stubs in
 1739 // generateOptoStub.  Registers not mentioned will be killed by the VM
 1740 // call in the trampoline, and arguments in those registers not be
 1741 // available to the callee.
 1742 bool Matcher::can_be_java_arg(int reg)
 1743 {
 1744   return
 1745     reg ==  RDI_num || reg == RDI_H_num ||
 1746     reg ==  RSI_num || reg == RSI_H_num ||
 1747     reg ==  RDX_num || reg == RDX_H_num ||
 1748     reg ==  RCX_num || reg == RCX_H_num ||
 1749     reg ==   R8_num || reg ==  R8_H_num ||
 1750     reg ==   R9_num || reg ==  R9_H_num ||
 1751     reg ==  R12_num || reg == R12_H_num ||
 1752     reg == XMM0_num || reg == XMM0b_num ||
 1753     reg == XMM1_num || reg == XMM1b_num ||
 1754     reg == XMM2_num || reg == XMM2b_num ||
 1755     reg == XMM3_num || reg == XMM3b_num ||
 1756     reg == XMM4_num || reg == XMM4b_num ||
 1757     reg == XMM5_num || reg == XMM5b_num ||
 1758     reg == XMM6_num || reg == XMM6b_num ||
 1759     reg == XMM7_num || reg == XMM7b_num;
 1760 }
 1761 
 1762 bool Matcher::is_spillable_arg(int reg)
 1763 {
 1764   return can_be_java_arg(reg);
 1765 }
 1766 
 1767 uint Matcher::int_pressure_limit()
 1768 {
 1769   return (INTPRESSURE == -1) ? _INT_REG_mask.Size() : INTPRESSURE;
 1770 }
 1771 
 1772 uint Matcher::float_pressure_limit()
 1773 {
 1774   // After experiment around with different values, the following default threshold
 1775   // works best for LCM's register pressure scheduling on x64.
 1776   uint dec_count  = VM_Version::supports_evex() ? 4 : 2;
 1777   uint default_float_pressure_threshold = _FLOAT_REG_mask.Size() - dec_count;
 1778   return (FLOATPRESSURE == -1) ? default_float_pressure_threshold : FLOATPRESSURE;
 1779 }
 1780 
 1781 bool Matcher::use_asm_for_ldiv_by_con( jlong divisor ) {
 1782   // In 64 bit mode a code which use multiply when
 1783   // devisor is constant is faster than hardware
 1784   // DIV instruction (it uses MulHiL).
 1785   return false;
 1786 }
 1787 
 1788 // Register for DIVI projection of divmodI
 1789 RegMask Matcher::divI_proj_mask() {
 1790   return INT_RAX_REG_mask();
 1791 }
 1792 
 1793 // Register for MODI projection of divmodI
 1794 RegMask Matcher::modI_proj_mask() {
 1795   return INT_RDX_REG_mask();
 1796 }
 1797 
 1798 // Register for DIVL projection of divmodL
 1799 RegMask Matcher::divL_proj_mask() {
 1800   return LONG_RAX_REG_mask();
 1801 }
 1802 
 1803 // Register for MODL projection of divmodL
 1804 RegMask Matcher::modL_proj_mask() {
 1805   return LONG_RDX_REG_mask();
 1806 }
 1807 
 1808 // Register for saving SP into on method handle invokes. Not used on x86_64.
 1809 const RegMask Matcher::method_handle_invoke_SP_save_mask() {
 1810     return NO_REG_mask();
 1811 }
 1812 
 1813 %}
 1814 
 1815 //----------ENCODING BLOCK-----------------------------------------------------
 1816 // This block specifies the encoding classes used by the compiler to
 1817 // output byte streams.  Encoding classes are parameterized macros
 1818 // used by Machine Instruction Nodes in order to generate the bit
 1819 // encoding of the instruction.  Operands specify their base encoding
 1820 // interface with the interface keyword.  There are currently
 1821 // supported four interfaces, REG_INTER, CONST_INTER, MEMORY_INTER, &
 1822 // COND_INTER.  REG_INTER causes an operand to generate a function
 1823 // which returns its register number when queried.  CONST_INTER causes
 1824 // an operand to generate a function which returns the value of the
 1825 // constant when queried.  MEMORY_INTER causes an operand to generate
 1826 // four functions which return the Base Register, the Index Register,
 1827 // the Scale Value, and the Offset Value of the operand when queried.
 1828 // COND_INTER causes an operand to generate six functions which return
 1829 // the encoding code (ie - encoding bits for the instruction)
 1830 // associated with each basic boolean condition for a conditional
 1831 // instruction.
 1832 //
 1833 // Instructions specify two basic values for encoding.  Again, a
 1834 // function is available to check if the constant displacement is an
 1835 // oop. They use the ins_encode keyword to specify their encoding
 1836 // classes (which must be a sequence of enc_class names, and their
 1837 // parameters, specified in the encoding block), and they use the
 1838 // opcode keyword to specify, in order, their primary, secondary, and
 1839 // tertiary opcode.  Only the opcode sections which a particular
 1840 // instruction needs for encoding need to be specified.
 1841 encode %{
 1842   // Build emit functions for each basic byte or larger field in the
 1843   // intel encoding scheme (opcode, rm, sib, immediate), and call them
 1844   // from C++ code in the enc_class source block.  Emit functions will
 1845   // live in the main source block for now.  In future, we can
 1846   // generalize this by adding a syntax that specifies the sizes of
 1847   // fields in an order, so that the adlc can build the emit functions
 1848   // automagically
 1849 
 1850   // Emit primary opcode
 1851   enc_class OpcP
 1852   %{
 1853     emit_opcode(cbuf, $primary);
 1854   %}
 1855 
 1856   // Emit secondary opcode
 1857   enc_class OpcS
 1858   %{
 1859     emit_opcode(cbuf, $secondary);
 1860   %}
 1861 
 1862   // Emit tertiary opcode
 1863   enc_class OpcT
 1864   %{
 1865     emit_opcode(cbuf, $tertiary);
 1866   %}
 1867 
 1868   // Emit opcode directly
 1869   enc_class Opcode(immI d8)
 1870   %{
 1871     emit_opcode(cbuf, $d8$$constant);
 1872   %}
 1873 
 1874   // Emit size prefix
 1875   enc_class SizePrefix
 1876   %{
 1877     emit_opcode(cbuf, 0x66);
 1878   %}
 1879 
 1880   enc_class reg(rRegI reg)
 1881   %{
 1882     emit_rm(cbuf, 0x3, 0, $reg$$reg & 7);
 1883   %}
 1884 
 1885   enc_class reg_reg(rRegI dst, rRegI src)
 1886   %{
 1887     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
 1888   %}
 1889 
 1890   enc_class opc_reg_reg(immI opcode, rRegI dst, rRegI src)
 1891   %{
 1892     emit_opcode(cbuf, $opcode$$constant);
 1893     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
 1894   %}
 1895 
 1896   enc_class cdql_enc(no_rax_rdx_RegI div)
 1897   %{
 1898     // Full implementation of Java idiv and irem; checks for
 1899     // special case as described in JVM spec., p.243 & p.271.
 1900     //
 1901     //         normal case                           special case
 1902     //
 1903     // input : rax: dividend                         min_int
 1904     //         reg: divisor                          -1
 1905     //
 1906     // output: rax: quotient  (= rax idiv reg)       min_int
 1907     //         rdx: remainder (= rax irem reg)       0
 1908     //
 1909     //  Code sequnce:
 1910     //
 1911     //    0:   3d 00 00 00 80          cmp    $0x80000000,%eax
 1912     //    5:   75 07/08                jne    e <normal>
 1913     //    7:   33 d2                   xor    %edx,%edx
 1914     //  [div >= 8 -> offset + 1]
 1915     //  [REX_B]
 1916     //    9:   83 f9 ff                cmp    $0xffffffffffffffff,$div
 1917     //    c:   74 03/04                je     11 <done>
 1918     // 000000000000000e <normal>:
 1919     //    e:   99                      cltd
 1920     //  [div >= 8 -> offset + 1]
 1921     //  [REX_B]
 1922     //    f:   f7 f9                   idiv   $div
 1923     // 0000000000000011 <done>:
 1924     MacroAssembler _masm(&cbuf);
 1925     Label normal;
 1926     Label done;
 1927 
 1928     // cmp    $0x80000000,%eax
 1929     __ cmp(as_Register(RAX_enc), 0x80000000);
 1930 
 1931     // jne    e <normal>
 1932     __ jccb(Assembler::notEqual, normal);
 1933 
 1934     // xor    %edx,%edx
 1935     __ xorl(as_Register(RDX_enc), as_Register(RDX_enc));
 1936 
 1937     // cmp    $0xffffffffffffffff,%ecx
 1938     __ cmpl($div$$Register, -1);
 1939 
 1940     // je     11 <done>
 1941     __ jccb(Assembler::equal, done);
 1942 
 1943     // <normal>
 1944     // cltd
 1945     __ bind(normal);
 1946     __ cdql();
 1947 
 1948     // idivl
 1949     // <done>
 1950     __ idivl($div$$Register);
 1951     __ bind(done);
 1952   %}
 1953 
 1954   enc_class cdqq_enc(no_rax_rdx_RegL div)
 1955   %{
 1956     // Full implementation of Java ldiv and lrem; checks for
 1957     // special case as described in JVM spec., p.243 & p.271.
 1958     //
 1959     //         normal case                           special case
 1960     //
 1961     // input : rax: dividend                         min_long
 1962     //         reg: divisor                          -1
 1963     //
 1964     // output: rax: quotient  (= rax idiv reg)       min_long
 1965     //         rdx: remainder (= rax irem reg)       0
 1966     //
 1967     //  Code sequnce:
 1968     //
 1969     //    0:   48 ba 00 00 00 00 00    mov    $0x8000000000000000,%rdx
 1970     //    7:   00 00 80
 1971     //    a:   48 39 d0                cmp    %rdx,%rax
 1972     //    d:   75 08                   jne    17 <normal>
 1973     //    f:   33 d2                   xor    %edx,%edx
 1974     //   11:   48 83 f9 ff             cmp    $0xffffffffffffffff,$div
 1975     //   15:   74 05                   je     1c <done>
 1976     // 0000000000000017 <normal>:
 1977     //   17:   48 99                   cqto
 1978     //   19:   48 f7 f9                idiv   $div
 1979     // 000000000000001c <done>:
 1980     MacroAssembler _masm(&cbuf);
 1981     Label normal;
 1982     Label done;
 1983 
 1984     // mov    $0x8000000000000000,%rdx
 1985     __ mov64(as_Register(RDX_enc), 0x8000000000000000);
 1986 
 1987     // cmp    %rdx,%rax
 1988     __ cmpq(as_Register(RAX_enc), as_Register(RDX_enc));
 1989 
 1990     // jne    17 <normal>
 1991     __ jccb(Assembler::notEqual, normal);
 1992 
 1993     // xor    %edx,%edx
 1994     __ xorl(as_Register(RDX_enc), as_Register(RDX_enc));
 1995 
 1996     // cmp    $0xffffffffffffffff,$div
 1997     __ cmpq($div$$Register, -1);
 1998 
 1999     // je     1e <done>
 2000     __ jccb(Assembler::equal, done);
 2001 
 2002     // <normal>
 2003     // cqto
 2004     __ bind(normal);
 2005     __ cdqq();
 2006 
 2007     // idivq (note: must be emitted by the user of this rule)
 2008     // <done>
 2009     __ idivq($div$$Register);
 2010     __ bind(done);
 2011   %}
 2012 
 2013   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
 2014   enc_class OpcSE(immI imm)
 2015   %{
 2016     // Emit primary opcode and set sign-extend bit
 2017     // Check for 8-bit immediate, and set sign extend bit in opcode
 2018     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
 2019       emit_opcode(cbuf, $primary | 0x02);
 2020     } else {
 2021       // 32-bit immediate
 2022       emit_opcode(cbuf, $primary);
 2023     }
 2024   %}
 2025 
 2026   enc_class OpcSErm(rRegI dst, immI imm)
 2027   %{
 2028     // OpcSEr/m
 2029     int dstenc = $dst$$reg;
 2030     if (dstenc >= 8) {
 2031       emit_opcode(cbuf, Assembler::REX_B);
 2032       dstenc -= 8;
 2033     }
 2034     // Emit primary opcode and set sign-extend bit
 2035     // Check for 8-bit immediate, and set sign extend bit in opcode
 2036     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
 2037       emit_opcode(cbuf, $primary | 0x02);
 2038     } else {
 2039       // 32-bit immediate
 2040       emit_opcode(cbuf, $primary);
 2041     }
 2042     // Emit r/m byte with secondary opcode, after primary opcode.
 2043     emit_rm(cbuf, 0x3, $secondary, dstenc);
 2044   %}
 2045 
 2046   enc_class OpcSErm_wide(rRegL dst, immI imm)
 2047   %{
 2048     // OpcSEr/m
 2049     int dstenc = $dst$$reg;
 2050     if (dstenc < 8) {
 2051       emit_opcode(cbuf, Assembler::REX_W);
 2052     } else {
 2053       emit_opcode(cbuf, Assembler::REX_WB);
 2054       dstenc -= 8;
 2055     }
 2056     // Emit primary opcode and set sign-extend bit
 2057     // Check for 8-bit immediate, and set sign extend bit in opcode
 2058     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
 2059       emit_opcode(cbuf, $primary | 0x02);
 2060     } else {
 2061       // 32-bit immediate
 2062       emit_opcode(cbuf, $primary);
 2063     }
 2064     // Emit r/m byte with secondary opcode, after primary opcode.
 2065     emit_rm(cbuf, 0x3, $secondary, dstenc);
 2066   %}
 2067 
 2068   enc_class Con8or32(immI imm)
 2069   %{
 2070     // Check for 8-bit immediate, and set sign extend bit in opcode
 2071     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
 2072       $$$emit8$imm$$constant;
 2073     } else {
 2074       // 32-bit immediate
 2075       $$$emit32$imm$$constant;
 2076     }
 2077   %}
 2078 
 2079   enc_class opc2_reg(rRegI dst)
 2080   %{
 2081     // BSWAP
 2082     emit_cc(cbuf, $secondary, $dst$$reg);
 2083   %}
 2084 
 2085   enc_class opc3_reg(rRegI dst)
 2086   %{
 2087     // BSWAP
 2088     emit_cc(cbuf, $tertiary, $dst$$reg);
 2089   %}
 2090 
 2091   enc_class reg_opc(rRegI div)
 2092   %{
 2093     // INC, DEC, IDIV, IMOD, JMP indirect, ...
 2094     emit_rm(cbuf, 0x3, $secondary, $div$$reg & 7);
 2095   %}
 2096 
 2097   enc_class enc_cmov(cmpOp cop)
 2098   %{
 2099     // CMOV
 2100     $$$emit8$primary;
 2101     emit_cc(cbuf, $secondary, $cop$$cmpcode);
 2102   %}
 2103 
 2104   enc_class enc_PartialSubtypeCheck()
 2105   %{
 2106     Register Rrdi = as_Register(RDI_enc); // result register
 2107     Register Rrax = as_Register(RAX_enc); // super class
 2108     Register Rrcx = as_Register(RCX_enc); // killed
 2109     Register Rrsi = as_Register(RSI_enc); // sub class
 2110     Label miss;
 2111     const bool set_cond_codes = true;
 2112 
 2113     MacroAssembler _masm(&cbuf);
 2114     __ check_klass_subtype_slow_path(Rrsi, Rrax, Rrcx, Rrdi,
 2115                                      NULL, &miss,
 2116                                      /*set_cond_codes:*/ true);
 2117     if ($primary) {
 2118       __ xorptr(Rrdi, Rrdi);
 2119     }
 2120     __ bind(miss);
 2121   %}
 2122 
 2123   enc_class clear_avx %{
 2124     debug_only(int off0 = cbuf.insts_size());
 2125     if (generate_vzeroupper(Compile::current())) {
 2126       // Clear upper bits of YMM registers to avoid AVX <-> SSE transition penalty
 2127       // Clear upper bits of YMM registers when current compiled code uses
 2128       // wide vectors to avoid AVX <-> SSE transition penalty during call.
 2129       MacroAssembler _masm(&cbuf);
 2130       __ vzeroupper();
 2131     }
 2132     debug_only(int off1 = cbuf.insts_size());
 2133     assert(off1 - off0 == clear_avx_size(), "correct size prediction");
 2134   %}
 2135 
 2136   enc_class Java_To_Runtime(method meth) %{
 2137     // No relocation needed
 2138     MacroAssembler _masm(&cbuf);
 2139     __ mov64(r10, (int64_t) $meth$$method);
 2140     __ call(r10);
 2141   %}
 2142 
 2143   enc_class Java_To_Interpreter(method meth)
 2144   %{
 2145     // CALL Java_To_Interpreter
 2146     // This is the instruction starting address for relocation info.
 2147     cbuf.set_insts_mark();
 2148     $$$emit8$primary;
 2149     // CALL directly to the runtime
 2150     emit_d32_reloc(cbuf,
 2151                    (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
 2152                    runtime_call_Relocation::spec(),
 2153                    RELOC_DISP32);
 2154   %}
 2155 
 2156   enc_class Java_Static_Call(method meth)
 2157   %{
 2158     // JAVA STATIC CALL
 2159     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to
 2160     // determine who we intended to call.
 2161     cbuf.set_insts_mark();
 2162     $$$emit8$primary;
 2163 
 2164     if (!_method) {
 2165       emit_d32_reloc(cbuf, (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
 2166                      runtime_call_Relocation::spec(),
 2167                      RELOC_DISP32);
 2168     } else {
 2169       int method_index = resolved_method_index(cbuf);
 2170       RelocationHolder rspec = _optimized_virtual ? opt_virtual_call_Relocation::spec(method_index)
 2171                                                   : static_call_Relocation::spec(method_index);
 2172       emit_d32_reloc(cbuf, (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
 2173                      rspec, RELOC_DISP32);
 2174       // Emit stubs for static call.
 2175       address mark = cbuf.insts_mark();
 2176       address stub = CompiledStaticCall::emit_to_interp_stub(cbuf, mark);
 2177       if (stub == NULL) {
 2178         ciEnv::current()->record_failure("CodeCache is full");
 2179         return;
 2180       }
 2181     }
 2182   %}
 2183 
 2184   enc_class Java_Dynamic_Call(method meth) %{
 2185     MacroAssembler _masm(&cbuf);
 2186     __ ic_call((address)$meth$$method, resolved_method_index(cbuf));
 2187   %}
 2188 
 2189   enc_class Java_Compiled_Call(method meth)
 2190   %{
 2191     // JAVA COMPILED CALL
 2192     int disp = in_bytes(Method:: from_compiled_offset());
 2193 
 2194     // XXX XXX offset is 128 is 1.5 NON-PRODUCT !!!
 2195     // assert(-0x80 <= disp && disp < 0x80, "compiled_code_offset isn't small");
 2196 
 2197     // callq *disp(%rax)
 2198     cbuf.set_insts_mark();
 2199     $$$emit8$primary;
 2200     if (disp < 0x80) {
 2201       emit_rm(cbuf, 0x01, $secondary, RAX_enc); // R/M byte
 2202       emit_d8(cbuf, disp); // Displacement
 2203     } else {
 2204       emit_rm(cbuf, 0x02, $secondary, RAX_enc); // R/M byte
 2205       emit_d32(cbuf, disp); // Displacement
 2206     }
 2207   %}
 2208 
 2209   enc_class reg_opc_imm(rRegI dst, immI8 shift)
 2210   %{
 2211     // SAL, SAR, SHR
 2212     int dstenc = $dst$$reg;
 2213     if (dstenc >= 8) {
 2214       emit_opcode(cbuf, Assembler::REX_B);
 2215       dstenc -= 8;
 2216     }
 2217     $$$emit8$primary;
 2218     emit_rm(cbuf, 0x3, $secondary, dstenc);
 2219     $$$emit8$shift$$constant;
 2220   %}
 2221 
 2222   enc_class reg_opc_imm_wide(rRegL dst, immI8 shift)
 2223   %{
 2224     // SAL, SAR, SHR
 2225     int dstenc = $dst$$reg;
 2226     if (dstenc < 8) {
 2227       emit_opcode(cbuf, Assembler::REX_W);
 2228     } else {
 2229       emit_opcode(cbuf, Assembler::REX_WB);
 2230       dstenc -= 8;
 2231     }
 2232     $$$emit8$primary;
 2233     emit_rm(cbuf, 0x3, $secondary, dstenc);
 2234     $$$emit8$shift$$constant;
 2235   %}
 2236 
 2237   enc_class load_immI(rRegI dst, immI src)
 2238   %{
 2239     int dstenc = $dst$$reg;
 2240     if (dstenc >= 8) {
 2241       emit_opcode(cbuf, Assembler::REX_B);
 2242       dstenc -= 8;
 2243     }
 2244     emit_opcode(cbuf, 0xB8 | dstenc);
 2245     $$$emit32$src$$constant;
 2246   %}
 2247 
 2248   enc_class load_immL(rRegL dst, immL src)
 2249   %{
 2250     int dstenc = $dst$$reg;
 2251     if (dstenc < 8) {
 2252       emit_opcode(cbuf, Assembler::REX_W);
 2253     } else {
 2254       emit_opcode(cbuf, Assembler::REX_WB);
 2255       dstenc -= 8;
 2256     }
 2257     emit_opcode(cbuf, 0xB8 | dstenc);
 2258     emit_d64(cbuf, $src$$constant);
 2259   %}
 2260 
 2261   enc_class load_immUL32(rRegL dst, immUL32 src)
 2262   %{
 2263     // same as load_immI, but this time we care about zeroes in the high word
 2264     int dstenc = $dst$$reg;
 2265     if (dstenc >= 8) {
 2266       emit_opcode(cbuf, Assembler::REX_B);
 2267       dstenc -= 8;
 2268     }
 2269     emit_opcode(cbuf, 0xB8 | dstenc);
 2270     $$$emit32$src$$constant;
 2271   %}
 2272 
 2273   enc_class load_immL32(rRegL dst, immL32 src)
 2274   %{
 2275     int dstenc = $dst$$reg;
 2276     if (dstenc < 8) {
 2277       emit_opcode(cbuf, Assembler::REX_W);
 2278     } else {
 2279       emit_opcode(cbuf, Assembler::REX_WB);
 2280       dstenc -= 8;
 2281     }
 2282     emit_opcode(cbuf, 0xC7);
 2283     emit_rm(cbuf, 0x03, 0x00, dstenc);
 2284     $$$emit32$src$$constant;
 2285   %}
 2286 
 2287   enc_class load_immP31(rRegP dst, immP32 src)
 2288   %{
 2289     // same as load_immI, but this time we care about zeroes in the high word
 2290     int dstenc = $dst$$reg;
 2291     if (dstenc >= 8) {
 2292       emit_opcode(cbuf, Assembler::REX_B);
 2293       dstenc -= 8;
 2294     }
 2295     emit_opcode(cbuf, 0xB8 | dstenc);
 2296     $$$emit32$src$$constant;
 2297   %}
 2298 
 2299   enc_class load_immP(rRegP dst, immP src)
 2300   %{
 2301     int dstenc = $dst$$reg;
 2302     if (dstenc < 8) {
 2303       emit_opcode(cbuf, Assembler::REX_W);
 2304     } else {
 2305       emit_opcode(cbuf, Assembler::REX_WB);
 2306       dstenc -= 8;
 2307     }
 2308     emit_opcode(cbuf, 0xB8 | dstenc);
 2309     // This next line should be generated from ADLC
 2310     if ($src->constant_reloc() != relocInfo::none) {
 2311       emit_d64_reloc(cbuf, $src$$constant, $src->constant_reloc(), RELOC_IMM64);
 2312     } else {
 2313       emit_d64(cbuf, $src$$constant);
 2314     }
 2315   %}
 2316 
 2317   enc_class Con32(immI src)
 2318   %{
 2319     // Output immediate
 2320     $$$emit32$src$$constant;
 2321   %}
 2322 
 2323   enc_class Con32F_as_bits(immF src)
 2324   %{
 2325     // Output Float immediate bits
 2326     jfloat jf = $src$$constant;
 2327     jint jf_as_bits = jint_cast(jf);
 2328     emit_d32(cbuf, jf_as_bits);
 2329   %}
 2330 
 2331   enc_class Con16(immI src)
 2332   %{
 2333     // Output immediate
 2334     $$$emit16$src$$constant;
 2335   %}
 2336 
 2337   // How is this different from Con32??? XXX
 2338   enc_class Con_d32(immI src)
 2339   %{
 2340     emit_d32(cbuf,$src$$constant);
 2341   %}
 2342 
 2343   enc_class conmemref (rRegP t1) %{    // Con32(storeImmI)
 2344     // Output immediate memory reference
 2345     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
 2346     emit_d32(cbuf, 0x00);
 2347   %}
 2348 
 2349   enc_class lock_prefix()
 2350   %{
 2351     emit_opcode(cbuf, 0xF0); // lock
 2352   %}
 2353 
 2354   enc_class REX_mem(memory mem)
 2355   %{
 2356     if ($mem$$base >= 8) {
 2357       if ($mem$$index < 8) {
 2358         emit_opcode(cbuf, Assembler::REX_B);
 2359       } else {
 2360         emit_opcode(cbuf, Assembler::REX_XB);
 2361       }
 2362     } else {
 2363       if ($mem$$index >= 8) {
 2364         emit_opcode(cbuf, Assembler::REX_X);
 2365       }
 2366     }
 2367   %}
 2368 
 2369   enc_class REX_mem_wide(memory mem)
 2370   %{
 2371     if ($mem$$base >= 8) {
 2372       if ($mem$$index < 8) {
 2373         emit_opcode(cbuf, Assembler::REX_WB);
 2374       } else {
 2375         emit_opcode(cbuf, Assembler::REX_WXB);
 2376       }
 2377     } else {
 2378       if ($mem$$index < 8) {
 2379         emit_opcode(cbuf, Assembler::REX_W);
 2380       } else {
 2381         emit_opcode(cbuf, Assembler::REX_WX);
 2382       }
 2383     }
 2384   %}
 2385 
 2386   // for byte regs
 2387   enc_class REX_breg(rRegI reg)
 2388   %{
 2389     if ($reg$$reg >= 4) {
 2390       emit_opcode(cbuf, $reg$$reg < 8 ? Assembler::REX : Assembler::REX_B);
 2391     }
 2392   %}
 2393 
 2394   // for byte regs
 2395   enc_class REX_reg_breg(rRegI dst, rRegI src)
 2396   %{
 2397     if ($dst$$reg < 8) {
 2398       if ($src$$reg >= 4) {
 2399         emit_opcode(cbuf, $src$$reg < 8 ? Assembler::REX : Assembler::REX_B);
 2400       }
 2401     } else {
 2402       if ($src$$reg < 8) {
 2403         emit_opcode(cbuf, Assembler::REX_R);
 2404       } else {
 2405         emit_opcode(cbuf, Assembler::REX_RB);
 2406       }
 2407     }
 2408   %}
 2409 
 2410   // for byte regs
 2411   enc_class REX_breg_mem(rRegI reg, memory mem)
 2412   %{
 2413     if ($reg$$reg < 8) {
 2414       if ($mem$$base < 8) {
 2415         if ($mem$$index >= 8) {
 2416           emit_opcode(cbuf, Assembler::REX_X);
 2417         } else if ($reg$$reg >= 4) {
 2418           emit_opcode(cbuf, Assembler::REX);
 2419         }
 2420       } else {
 2421         if ($mem$$index < 8) {
 2422           emit_opcode(cbuf, Assembler::REX_B);
 2423         } else {
 2424           emit_opcode(cbuf, Assembler::REX_XB);
 2425         }
 2426       }
 2427     } else {
 2428       if ($mem$$base < 8) {
 2429         if ($mem$$index < 8) {
 2430           emit_opcode(cbuf, Assembler::REX_R);
 2431         } else {
 2432           emit_opcode(cbuf, Assembler::REX_RX);
 2433         }
 2434       } else {
 2435         if ($mem$$index < 8) {
 2436           emit_opcode(cbuf, Assembler::REX_RB);
 2437         } else {
 2438           emit_opcode(cbuf, Assembler::REX_RXB);
 2439         }
 2440       }
 2441     }
 2442   %}
 2443 
 2444   enc_class REX_reg(rRegI reg)
 2445   %{
 2446     if ($reg$$reg >= 8) {
 2447       emit_opcode(cbuf, Assembler::REX_B);
 2448     }
 2449   %}
 2450 
 2451   enc_class REX_reg_wide(rRegI reg)
 2452   %{
 2453     if ($reg$$reg < 8) {
 2454       emit_opcode(cbuf, Assembler::REX_W);
 2455     } else {
 2456       emit_opcode(cbuf, Assembler::REX_WB);
 2457     }
 2458   %}
 2459 
 2460   enc_class REX_reg_reg(rRegI dst, rRegI src)
 2461   %{
 2462     if ($dst$$reg < 8) {
 2463       if ($src$$reg >= 8) {
 2464         emit_opcode(cbuf, Assembler::REX_B);
 2465       }
 2466     } else {
 2467       if ($src$$reg < 8) {
 2468         emit_opcode(cbuf, Assembler::REX_R);
 2469       } else {
 2470         emit_opcode(cbuf, Assembler::REX_RB);
 2471       }
 2472     }
 2473   %}
 2474 
 2475   enc_class REX_reg_reg_wide(rRegI dst, rRegI src)
 2476   %{
 2477     if ($dst$$reg < 8) {
 2478       if ($src$$reg < 8) {
 2479         emit_opcode(cbuf, Assembler::REX_W);
 2480       } else {
 2481         emit_opcode(cbuf, Assembler::REX_WB);
 2482       }
 2483     } else {
 2484       if ($src$$reg < 8) {
 2485         emit_opcode(cbuf, Assembler::REX_WR);
 2486       } else {
 2487         emit_opcode(cbuf, Assembler::REX_WRB);
 2488       }
 2489     }
 2490   %}
 2491 
 2492   enc_class REX_reg_mem(rRegI reg, memory mem)
 2493   %{
 2494     if ($reg$$reg < 8) {
 2495       if ($mem$$base < 8) {
 2496         if ($mem$$index >= 8) {
 2497           emit_opcode(cbuf, Assembler::REX_X);
 2498         }
 2499       } else {
 2500         if ($mem$$index < 8) {
 2501           emit_opcode(cbuf, Assembler::REX_B);
 2502         } else {
 2503           emit_opcode(cbuf, Assembler::REX_XB);
 2504         }
 2505       }
 2506     } else {
 2507       if ($mem$$base < 8) {
 2508         if ($mem$$index < 8) {
 2509           emit_opcode(cbuf, Assembler::REX_R);
 2510         } else {
 2511           emit_opcode(cbuf, Assembler::REX_RX);
 2512         }
 2513       } else {
 2514         if ($mem$$index < 8) {
 2515           emit_opcode(cbuf, Assembler::REX_RB);
 2516         } else {
 2517           emit_opcode(cbuf, Assembler::REX_RXB);
 2518         }
 2519       }
 2520     }
 2521   %}
 2522 
 2523   enc_class REX_reg_mem_wide(rRegL reg, memory mem)
 2524   %{
 2525     if ($reg$$reg < 8) {
 2526       if ($mem$$base < 8) {
 2527         if ($mem$$index < 8) {
 2528           emit_opcode(cbuf, Assembler::REX_W);
 2529         } else {
 2530           emit_opcode(cbuf, Assembler::REX_WX);
 2531         }
 2532       } else {
 2533         if ($mem$$index < 8) {
 2534           emit_opcode(cbuf, Assembler::REX_WB);
 2535         } else {
 2536           emit_opcode(cbuf, Assembler::REX_WXB);
 2537         }
 2538       }
 2539     } else {
 2540       if ($mem$$base < 8) {
 2541         if ($mem$$index < 8) {
 2542           emit_opcode(cbuf, Assembler::REX_WR);
 2543         } else {
 2544           emit_opcode(cbuf, Assembler::REX_WRX);
 2545         }
 2546       } else {
 2547         if ($mem$$index < 8) {
 2548           emit_opcode(cbuf, Assembler::REX_WRB);
 2549         } else {
 2550           emit_opcode(cbuf, Assembler::REX_WRXB);
 2551         }
 2552       }
 2553     }
 2554   %}
 2555 
 2556   enc_class reg_mem(rRegI ereg, memory mem)
 2557   %{
 2558     // High registers handle in encode_RegMem
 2559     int reg = $ereg$$reg;
 2560     int base = $mem$$base;
 2561     int index = $mem$$index;
 2562     int scale = $mem$$scale;
 2563     int disp = $mem$$disp;
 2564     relocInfo::relocType disp_reloc = $mem->disp_reloc();
 2565 
 2566     encode_RegMem(cbuf, reg, base, index, scale, disp, disp_reloc);
 2567   %}
 2568 
 2569   enc_class RM_opc_mem(immI rm_opcode, memory mem)
 2570   %{
 2571     int rm_byte_opcode = $rm_opcode$$constant;
 2572 
 2573     // High registers handle in encode_RegMem
 2574     int base = $mem$$base;
 2575     int index = $mem$$index;
 2576     int scale = $mem$$scale;
 2577     int displace = $mem$$disp;
 2578 
 2579     relocInfo::relocType disp_reloc = $mem->disp_reloc();       // disp-as-oop when
 2580                                             // working with static
 2581                                             // globals
 2582     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace,
 2583                   disp_reloc);
 2584   %}
 2585 
 2586   enc_class reg_lea(rRegI dst, rRegI src0, immI src1)
 2587   %{
 2588     int reg_encoding = $dst$$reg;
 2589     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
 2590     int index        = 0x04;            // 0x04 indicates no index
 2591     int scale        = 0x00;            // 0x00 indicates no scale
 2592     int displace     = $src1$$constant; // 0x00 indicates no displacement
 2593     relocInfo::relocType disp_reloc = relocInfo::none;
 2594     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace,
 2595                   disp_reloc);
 2596   %}
 2597 
 2598   enc_class neg_reg(rRegI dst)
 2599   %{
 2600     int dstenc = $dst$$reg;
 2601     if (dstenc >= 8) {
 2602       emit_opcode(cbuf, Assembler::REX_B);
 2603       dstenc -= 8;
 2604     }
 2605     // NEG $dst
 2606     emit_opcode(cbuf, 0xF7);
 2607     emit_rm(cbuf, 0x3, 0x03, dstenc);
 2608   %}
 2609 
 2610   enc_class neg_reg_wide(rRegI dst)
 2611   %{
 2612     int dstenc = $dst$$reg;
 2613     if (dstenc < 8) {
 2614       emit_opcode(cbuf, Assembler::REX_W);
 2615     } else {
 2616       emit_opcode(cbuf, Assembler::REX_WB);
 2617       dstenc -= 8;
 2618     }
 2619     // NEG $dst
 2620     emit_opcode(cbuf, 0xF7);
 2621     emit_rm(cbuf, 0x3, 0x03, dstenc);
 2622   %}
 2623 
 2624   enc_class setLT_reg(rRegI dst)
 2625   %{
 2626     int dstenc = $dst$$reg;
 2627     if (dstenc >= 8) {
 2628       emit_opcode(cbuf, Assembler::REX_B);
 2629       dstenc -= 8;
 2630     } else if (dstenc >= 4) {
 2631       emit_opcode(cbuf, Assembler::REX);
 2632     }
 2633     // SETLT $dst
 2634     emit_opcode(cbuf, 0x0F);
 2635     emit_opcode(cbuf, 0x9C);
 2636     emit_rm(cbuf, 0x3, 0x0, dstenc);
 2637   %}
 2638 
 2639   enc_class setNZ_reg(rRegI dst)
 2640   %{
 2641     int dstenc = $dst$$reg;
 2642     if (dstenc >= 8) {
 2643       emit_opcode(cbuf, Assembler::REX_B);
 2644       dstenc -= 8;
 2645     } else if (dstenc >= 4) {
 2646       emit_opcode(cbuf, Assembler::REX);
 2647     }
 2648     // SETNZ $dst
 2649     emit_opcode(cbuf, 0x0F);
 2650     emit_opcode(cbuf, 0x95);
 2651     emit_rm(cbuf, 0x3, 0x0, dstenc);
 2652   %}
 2653 
 2654 
 2655   // Compare the lonogs and set -1, 0, or 1 into dst
 2656   enc_class cmpl3_flag(rRegL src1, rRegL src2, rRegI dst)
 2657   %{
 2658     int src1enc = $src1$$reg;
 2659     int src2enc = $src2$$reg;
 2660     int dstenc = $dst$$reg;
 2661 
 2662     // cmpq $src1, $src2
 2663     if (src1enc < 8) {
 2664       if (src2enc < 8) {
 2665         emit_opcode(cbuf, Assembler::REX_W);
 2666       } else {
 2667         emit_opcode(cbuf, Assembler::REX_WB);
 2668       }
 2669     } else {
 2670       if (src2enc < 8) {
 2671         emit_opcode(cbuf, Assembler::REX_WR);
 2672       } else {
 2673         emit_opcode(cbuf, Assembler::REX_WRB);
 2674       }
 2675     }
 2676     emit_opcode(cbuf, 0x3B);
 2677     emit_rm(cbuf, 0x3, src1enc & 7, src2enc & 7);
 2678 
 2679     // movl $dst, -1
 2680     if (dstenc >= 8) {
 2681       emit_opcode(cbuf, Assembler::REX_B);
 2682     }
 2683     emit_opcode(cbuf, 0xB8 | (dstenc & 7));
 2684     emit_d32(cbuf, -1);
 2685 
 2686     // jl,s done
 2687     emit_opcode(cbuf, 0x7C);
 2688     emit_d8(cbuf, dstenc < 4 ? 0x06 : 0x08);
 2689 
 2690     // setne $dst
 2691     if (dstenc >= 4) {
 2692       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_B);
 2693     }
 2694     emit_opcode(cbuf, 0x0F);
 2695     emit_opcode(cbuf, 0x95);
 2696     emit_opcode(cbuf, 0xC0 | (dstenc & 7));
 2697 
 2698     // movzbl $dst, $dst
 2699     if (dstenc >= 4) {
 2700       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_RB);
 2701     }
 2702     emit_opcode(cbuf, 0x0F);
 2703     emit_opcode(cbuf, 0xB6);
 2704     emit_rm(cbuf, 0x3, dstenc & 7, dstenc & 7);
 2705   %}
 2706 
 2707   enc_class Push_ResultXD(regD dst) %{
 2708     MacroAssembler _masm(&cbuf);
 2709     __ fstp_d(Address(rsp, 0));
 2710     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
 2711     __ addptr(rsp, 8);
 2712   %}
 2713 
 2714   enc_class Push_SrcXD(regD src) %{
 2715     MacroAssembler _masm(&cbuf);
 2716     __ subptr(rsp, 8);
 2717     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
 2718     __ fld_d(Address(rsp, 0));
 2719   %}
 2720 
 2721 
 2722   enc_class enc_rethrow()
 2723   %{
 2724     cbuf.set_insts_mark();
 2725     emit_opcode(cbuf, 0xE9); // jmp entry
 2726     emit_d32_reloc(cbuf,
 2727                    (int) (OptoRuntime::rethrow_stub() - cbuf.insts_end() - 4),
 2728                    runtime_call_Relocation::spec(),
 2729                    RELOC_DISP32);
 2730   %}
 2731 
 2732 %}
 2733 
 2734 
 2735 
 2736 //----------FRAME--------------------------------------------------------------
 2737 // Definition of frame structure and management information.
 2738 //
 2739 //  S T A C K   L A Y O U T    Allocators stack-slot number
 2740 //                             |   (to get allocators register number
 2741 //  G  Owned by    |        |  v    add OptoReg::stack0())
 2742 //  r   CALLER     |        |
 2743 //  o     |        +--------+      pad to even-align allocators stack-slot
 2744 //  w     V        |  pad0  |        numbers; owned by CALLER
 2745 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
 2746 //  h     ^        |   in   |  5
 2747 //        |        |  args  |  4   Holes in incoming args owned by SELF
 2748 //  |     |        |        |  3
 2749 //  |     |        +--------+
 2750 //  V     |        | old out|      Empty on Intel, window on Sparc
 2751 //        |    old |preserve|      Must be even aligned.
 2752 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
 2753 //        |        |   in   |  3   area for Intel ret address
 2754 //     Owned by    |preserve|      Empty on Sparc.
 2755 //       SELF      +--------+
 2756 //        |        |  pad2  |  2   pad to align old SP
 2757 //        |        +--------+  1
 2758 //        |        | locks  |  0
 2759 //        |        +--------+----> OptoReg::stack0(), even aligned
 2760 //        |        |  pad1  | 11   pad to align new SP
 2761 //        |        +--------+
 2762 //        |        |        | 10
 2763 //        |        | spills |  9   spills
 2764 //        V        |        |  8   (pad0 slot for callee)
 2765 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
 2766 //        ^        |  out   |  7
 2767 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
 2768 //     Owned by    +--------+
 2769 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
 2770 //        |    new |preserve|      Must be even-aligned.
 2771 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
 2772 //        |        |        |
 2773 //
 2774 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
 2775 //         known from SELF's arguments and the Java calling convention.
 2776 //         Region 6-7 is determined per call site.
 2777 // Note 2: If the calling convention leaves holes in the incoming argument
 2778 //         area, those holes are owned by SELF.  Holes in the outgoing area
 2779 //         are owned by the CALLEE.  Holes should not be nessecary in the
 2780 //         incoming area, as the Java calling convention is completely under
 2781 //         the control of the AD file.  Doubles can be sorted and packed to
 2782 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
 2783 //         varargs C calling conventions.
 2784 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
 2785 //         even aligned with pad0 as needed.
 2786 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
 2787 //         region 6-11 is even aligned; it may be padded out more so that
 2788 //         the region from SP to FP meets the minimum stack alignment.
 2789 // Note 4: For I2C adapters, the incoming FP may not meet the minimum stack
 2790 //         alignment.  Region 11, pad1, may be dynamically extended so that
 2791 //         SP meets the minimum alignment.
 2792 
 2793 frame
 2794 %{
 2795   // These three registers define part of the calling convention
 2796   // between compiled code and the interpreter.
 2797   inline_cache_reg(RAX);                // Inline Cache Register
 2798 
 2799   // Optional: name the operand used by cisc-spilling to access
 2800   // [stack_pointer + offset]
 2801   cisc_spilling_operand_name(indOffset32);
 2802 
 2803   // Number of stack slots consumed by locking an object
 2804   sync_stack_slots(2);
 2805 
 2806   // Compiled code's Frame Pointer
 2807   frame_pointer(RSP);
 2808 
 2809   // Interpreter stores its frame pointer in a register which is
 2810   // stored to the stack by I2CAdaptors.
 2811   // I2CAdaptors convert from interpreted java to compiled java.
 2812   interpreter_frame_pointer(RBP);
 2813 
 2814   // Stack alignment requirement
 2815   stack_alignment(StackAlignmentInBytes); // Alignment size in bytes (128-bit -> 16 bytes)
 2816 
 2817   // Number of outgoing stack slots killed above the out_preserve_stack_slots
 2818   // for calls to C.  Supports the var-args backing area for register parms.
 2819   varargs_C_out_slots_killed(frame::arg_reg_save_area_bytes/BytesPerInt);
 2820 
 2821   // The after-PROLOG location of the return address.  Location of
 2822   // return address specifies a type (REG or STACK) and a number
 2823   // representing the register number (i.e. - use a register name) or
 2824   // stack slot.
 2825   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
 2826   // Otherwise, it is above the locks and verification slot and alignment word
 2827   return_addr(STACK - 2 +
 2828               align_up((Compile::current()->in_preserve_stack_slots() +
 2829                         Compile::current()->fixed_slots()),
 2830                        stack_alignment_in_slots()));
 2831 
 2832   // Location of compiled Java return values.  Same as C for now.
 2833   return_value
 2834   %{
 2835     assert(ideal_reg >= Op_RegI && ideal_reg <= Op_RegL,
 2836            "only return normal values");
 2837 
 2838     static const int lo[Op_RegL + 1] = {
 2839       0,
 2840       0,
 2841       RAX_num,  // Op_RegN
 2842       RAX_num,  // Op_RegI
 2843       RAX_num,  // Op_RegP
 2844       XMM0_num, // Op_RegF
 2845       XMM0_num, // Op_RegD
 2846       RAX_num   // Op_RegL
 2847     };
 2848     static const int hi[Op_RegL + 1] = {
 2849       0,
 2850       0,
 2851       OptoReg::Bad, // Op_RegN
 2852       OptoReg::Bad, // Op_RegI
 2853       RAX_H_num,    // Op_RegP
 2854       OptoReg::Bad, // Op_RegF
 2855       XMM0b_num,    // Op_RegD
 2856       RAX_H_num     // Op_RegL
 2857     };
 2858     // Excluded flags and vector registers.
 2859     assert(ARRAY_SIZE(hi) == _last_machine_leaf - 8, "missing type");
 2860     return OptoRegPair(hi[ideal_reg], lo[ideal_reg]);
 2861   %}
 2862 %}
 2863 
 2864 //----------ATTRIBUTES---------------------------------------------------------
 2865 //----------Operand Attributes-------------------------------------------------
 2866 op_attrib op_cost(0);        // Required cost attribute
 2867 
 2868 //----------Instruction Attributes---------------------------------------------
 2869 ins_attrib ins_cost(100);       // Required cost attribute
 2870 ins_attrib ins_size(8);         // Required size attribute (in bits)
 2871 ins_attrib ins_short_branch(0); // Required flag: is this instruction
 2872                                 // a non-matching short branch variant
 2873                                 // of some long branch?
 2874 ins_attrib ins_alignment(1);    // Required alignment attribute (must
 2875                                 // be a power of 2) specifies the
 2876                                 // alignment that some part of the
 2877                                 // instruction (not necessarily the
 2878                                 // start) requires.  If > 1, a
 2879                                 // compute_padding() function must be
 2880                                 // provided for the instruction
 2881 
 2882 //----------OPERANDS-----------------------------------------------------------
 2883 // Operand definitions must precede instruction definitions for correct parsing
 2884 // in the ADLC because operands constitute user defined types which are used in
 2885 // instruction definitions.
 2886 
 2887 //----------Simple Operands----------------------------------------------------
 2888 // Immediate Operands
 2889 // Integer Immediate
 2890 operand immI()
 2891 %{
 2892   match(ConI);
 2893 
 2894   op_cost(10);
 2895   format %{ %}
 2896   interface(CONST_INTER);
 2897 %}
 2898 
 2899 // Constant for test vs zero
 2900 operand immI_0()
 2901 %{
 2902   predicate(n->get_int() == 0);
 2903   match(ConI);
 2904 
 2905   op_cost(0);
 2906   format %{ %}
 2907   interface(CONST_INTER);
 2908 %}
 2909 
 2910 // Constant for increment
 2911 operand immI_1()
 2912 %{
 2913   predicate(n->get_int() == 1);
 2914   match(ConI);
 2915 
 2916   op_cost(0);
 2917   format %{ %}
 2918   interface(CONST_INTER);
 2919 %}
 2920 
 2921 // Constant for decrement
 2922 operand immI_M1()
 2923 %{
 2924   predicate(n->get_int() == -1);
 2925   match(ConI);
 2926 
 2927   op_cost(0);
 2928   format %{ %}
 2929   interface(CONST_INTER);
 2930 %}
 2931 
 2932 operand immI_2()
 2933 %{
 2934   predicate(n->get_int() == 2);
 2935   match(ConI);
 2936 
 2937   op_cost(0);
 2938   format %{ %}
 2939   interface(CONST_INTER);
 2940 %}
 2941 
 2942 operand immI_4()
 2943 %{
 2944   predicate(n->get_int() == 4);
 2945   match(ConI);
 2946 
 2947   op_cost(0);
 2948   format %{ %}
 2949   interface(CONST_INTER);
 2950 %}
 2951 
 2952 operand immI_8()
 2953 %{
 2954   predicate(n->get_int() == 8);
 2955   match(ConI);
 2956 
 2957   op_cost(0);
 2958   format %{ %}
 2959   interface(CONST_INTER);
 2960 %}
 2961 
 2962 // Valid scale values for addressing modes
 2963 operand immI2()
 2964 %{
 2965   predicate(0 <= n->get_int() && (n->get_int() <= 3));
 2966   match(ConI);
 2967 
 2968   format %{ %}
 2969   interface(CONST_INTER);
 2970 %}
 2971 
 2972 operand immU7()
 2973 %{
 2974   predicate((0 <= n->get_int()) && (n->get_int() <= 0x7F));
 2975   match(ConI);
 2976 
 2977   op_cost(5);
 2978   format %{ %}
 2979   interface(CONST_INTER);
 2980 %}
 2981 
 2982 operand immI8()
 2983 %{
 2984   predicate((-0x80 <= n->get_int()) && (n->get_int() < 0x80));
 2985   match(ConI);
 2986 
 2987   op_cost(5);
 2988   format %{ %}
 2989   interface(CONST_INTER);
 2990 %}
 2991 
 2992 operand immU8()
 2993 %{
 2994   predicate((0 <= n->get_int()) && (n->get_int() <= 255));
 2995   match(ConI);
 2996 
 2997   op_cost(5);
 2998   format %{ %}
 2999   interface(CONST_INTER);
 3000 %}
 3001 
 3002 operand immI16()
 3003 %{
 3004   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
 3005   match(ConI);
 3006 
 3007   op_cost(10);
 3008   format %{ %}
 3009   interface(CONST_INTER);
 3010 %}
 3011 
 3012 // Int Immediate non-negative
 3013 operand immU31()
 3014 %{
 3015   predicate(n->get_int() >= 0);
 3016   match(ConI);
 3017 
 3018   op_cost(0);
 3019   format %{ %}
 3020   interface(CONST_INTER);
 3021 %}
 3022 
 3023 // Constant for long shifts
 3024 operand immI_32()
 3025 %{
 3026   predicate( n->get_int() == 32 );
 3027   match(ConI);
 3028 
 3029   op_cost(0);
 3030   format %{ %}
 3031   interface(CONST_INTER);
 3032 %}
 3033 
 3034 // Constant for long shifts
 3035 operand immI_64()
 3036 %{
 3037   predicate( n->get_int() == 64 );
 3038   match(ConI);
 3039 
 3040   op_cost(0);
 3041   format %{ %}
 3042   interface(CONST_INTER);
 3043 %}
 3044 
 3045 // Pointer Immediate
 3046 operand immP()
 3047 %{
 3048   match(ConP);
 3049 
 3050   op_cost(10);
 3051   format %{ %}
 3052   interface(CONST_INTER);
 3053 %}
 3054 
 3055 // NULL Pointer Immediate
 3056 operand immP0()
 3057 %{
 3058   predicate(n->get_ptr() == 0);
 3059   match(ConP);
 3060 
 3061   op_cost(5);
 3062   format %{ %}
 3063   interface(CONST_INTER);
 3064 %}
 3065 
 3066 // Pointer Immediate
 3067 operand immN() %{
 3068   match(ConN);
 3069 
 3070   op_cost(10);
 3071   format %{ %}
 3072   interface(CONST_INTER);
 3073 %}
 3074 
 3075 operand immNKlass() %{
 3076   match(ConNKlass);
 3077 
 3078   op_cost(10);
 3079   format %{ %}
 3080   interface(CONST_INTER);
 3081 %}
 3082 
 3083 // NULL Pointer Immediate
 3084 operand immN0() %{
 3085   predicate(n->get_narrowcon() == 0);
 3086   match(ConN);
 3087 
 3088   op_cost(5);
 3089   format %{ %}
 3090   interface(CONST_INTER);
 3091 %}
 3092 
 3093 operand immP31()
 3094 %{
 3095   predicate(n->as_Type()->type()->reloc() == relocInfo::none
 3096             && (n->get_ptr() >> 31) == 0);
 3097   match(ConP);
 3098 
 3099   op_cost(5);
 3100   format %{ %}
 3101   interface(CONST_INTER);
 3102 %}
 3103 
 3104 
 3105 // Long Immediate
 3106 operand immL()
 3107 %{
 3108   match(ConL);
 3109 
 3110   op_cost(20);
 3111   format %{ %}
 3112   interface(CONST_INTER);
 3113 %}
 3114 
 3115 // Long Immediate 8-bit
 3116 operand immL8()
 3117 %{
 3118   predicate(-0x80L <= n->get_long() && n->get_long() < 0x80L);
 3119   match(ConL);
 3120 
 3121   op_cost(5);
 3122   format %{ %}
 3123   interface(CONST_INTER);
 3124 %}
 3125 
 3126 // Long Immediate 32-bit unsigned
 3127 operand immUL32()
 3128 %{
 3129   predicate(n->get_long() == (unsigned int) (n->get_long()));
 3130   match(ConL);
 3131 
 3132   op_cost(10);
 3133   format %{ %}
 3134   interface(CONST_INTER);
 3135 %}
 3136 
 3137 // Long Immediate 32-bit signed
 3138 operand immL32()
 3139 %{
 3140   predicate(n->get_long() == (int) (n->get_long()));
 3141   match(ConL);
 3142 
 3143   op_cost(15);
 3144   format %{ %}
 3145   interface(CONST_INTER);
 3146 %}
 3147 
 3148 operand immL_Pow2()
 3149 %{
 3150   predicate(is_power_of_2((julong)n->get_long()));
 3151   match(ConL);
 3152 
 3153   op_cost(15);
 3154   format %{ %}
 3155   interface(CONST_INTER);
 3156 %}
 3157 
 3158 operand immL_NotPow2()
 3159 %{
 3160   predicate(is_power_of_2((julong)~n->get_long()));
 3161   match(ConL);
 3162 
 3163   op_cost(15);
 3164   format %{ %}
 3165   interface(CONST_INTER);
 3166 %}
 3167 
 3168 // Long Immediate zero
 3169 operand immL0()
 3170 %{
 3171   predicate(n->get_long() == 0L);
 3172   match(ConL);
 3173 
 3174   op_cost(10);
 3175   format %{ %}
 3176   interface(CONST_INTER);
 3177 %}
 3178 
 3179 // Constant for increment
 3180 operand immL1()
 3181 %{
 3182   predicate(n->get_long() == 1);
 3183   match(ConL);
 3184 
 3185   format %{ %}
 3186   interface(CONST_INTER);
 3187 %}
 3188 
 3189 // Constant for decrement
 3190 operand immL_M1()
 3191 %{
 3192   predicate(n->get_long() == -1);
 3193   match(ConL);
 3194 
 3195   format %{ %}
 3196   interface(CONST_INTER);
 3197 %}
 3198 
 3199 // Long Immediate: the value 10
 3200 operand immL10()
 3201 %{
 3202   predicate(n->get_long() == 10);
 3203   match(ConL);
 3204 
 3205   format %{ %}
 3206   interface(CONST_INTER);
 3207 %}
 3208 
 3209 // Long immediate from 0 to 127.
 3210 // Used for a shorter form of long mul by 10.
 3211 operand immL_127()
 3212 %{
 3213   predicate(0 <= n->get_long() && n->get_long() < 0x80);
 3214   match(ConL);
 3215 
 3216   op_cost(10);
 3217   format %{ %}
 3218   interface(CONST_INTER);
 3219 %}
 3220 
 3221 // Long Immediate: low 32-bit mask
 3222 operand immL_32bits()
 3223 %{
 3224   predicate(n->get_long() == 0xFFFFFFFFL);
 3225   match(ConL);
 3226   op_cost(20);
 3227 
 3228   format %{ %}
 3229   interface(CONST_INTER);
 3230 %}
 3231 
 3232 // Int Immediate: 2^n-1, postive
 3233 operand immI_Pow2M1()
 3234 %{
 3235   predicate((n->get_int() > 0)
 3236             && is_power_of_2(n->get_int() + 1));
 3237   match(ConI);
 3238 
 3239   op_cost(20);
 3240   format %{ %}
 3241   interface(CONST_INTER);
 3242 %}
 3243 
 3244 // Float Immediate zero
 3245 operand immF0()
 3246 %{
 3247   predicate(jint_cast(n->getf()) == 0);
 3248   match(ConF);
 3249 
 3250   op_cost(5);
 3251   format %{ %}
 3252   interface(CONST_INTER);
 3253 %}
 3254 
 3255 // Float Immediate
 3256 operand immF()
 3257 %{
 3258   match(ConF);
 3259 
 3260   op_cost(15);
 3261   format %{ %}
 3262   interface(CONST_INTER);
 3263 %}
 3264 
 3265 // Double Immediate zero
 3266 operand immD0()
 3267 %{
 3268   predicate(jlong_cast(n->getd()) == 0);
 3269   match(ConD);
 3270 
 3271   op_cost(5);
 3272   format %{ %}
 3273   interface(CONST_INTER);
 3274 %}
 3275 
 3276 // Double Immediate
 3277 operand immD()
 3278 %{
 3279   match(ConD);
 3280 
 3281   op_cost(15);
 3282   format %{ %}
 3283   interface(CONST_INTER);
 3284 %}
 3285 
 3286 // Immediates for special shifts (sign extend)
 3287 
 3288 // Constants for increment
 3289 operand immI_16()
 3290 %{
 3291   predicate(n->get_int() == 16);
 3292   match(ConI);
 3293 
 3294   format %{ %}
 3295   interface(CONST_INTER);
 3296 %}
 3297 
 3298 operand immI_24()
 3299 %{
 3300   predicate(n->get_int() == 24);
 3301   match(ConI);
 3302 
 3303   format %{ %}
 3304   interface(CONST_INTER);
 3305 %}
 3306 
 3307 // Constant for byte-wide masking
 3308 operand immI_255()
 3309 %{
 3310   predicate(n->get_int() == 255);
 3311   match(ConI);
 3312 
 3313   format %{ %}
 3314   interface(CONST_INTER);
 3315 %}
 3316 
 3317 // Constant for short-wide masking
 3318 operand immI_65535()
 3319 %{
 3320   predicate(n->get_int() == 65535);
 3321   match(ConI);
 3322 
 3323   format %{ %}
 3324   interface(CONST_INTER);
 3325 %}
 3326 
 3327 // Constant for byte-wide masking
 3328 operand immL_255()
 3329 %{
 3330   predicate(n->get_long() == 255);
 3331   match(ConL);
 3332 
 3333   format %{ %}
 3334   interface(CONST_INTER);
 3335 %}
 3336 
 3337 // Constant for short-wide masking
 3338 operand immL_65535()
 3339 %{
 3340   predicate(n->get_long() == 65535);
 3341   match(ConL);
 3342 
 3343   format %{ %}
 3344   interface(CONST_INTER);
 3345 %}
 3346 
 3347 operand kReg()
 3348 %{
 3349   constraint(ALLOC_IN_RC(vectmask_reg));
 3350   match(RegVectMask);
 3351   format %{%}
 3352   interface(REG_INTER);
 3353 %}
 3354 
 3355 operand kReg_K1()
 3356 %{
 3357   constraint(ALLOC_IN_RC(vectmask_reg_K1));
 3358   match(RegVectMask);
 3359   format %{%}
 3360   interface(REG_INTER);
 3361 %}
 3362 
 3363 operand kReg_K2()
 3364 %{
 3365   constraint(ALLOC_IN_RC(vectmask_reg_K2));
 3366   match(RegVectMask);
 3367   format %{%}
 3368   interface(REG_INTER);
 3369 %}
 3370 
 3371 // Special Registers
 3372 operand kReg_K3()
 3373 %{
 3374   constraint(ALLOC_IN_RC(vectmask_reg_K3));
 3375   match(RegVectMask);
 3376   format %{%}
 3377   interface(REG_INTER);
 3378 %}
 3379 
 3380 operand kReg_K4()
 3381 %{
 3382   constraint(ALLOC_IN_RC(vectmask_reg_K4));
 3383   match(RegVectMask);
 3384   format %{%}
 3385   interface(REG_INTER);
 3386 %}
 3387 
 3388 operand kReg_K5()
 3389 %{
 3390   constraint(ALLOC_IN_RC(vectmask_reg_K5));
 3391   match(RegVectMask);
 3392   format %{%}
 3393   interface(REG_INTER);
 3394 %}
 3395 
 3396 operand kReg_K6()
 3397 %{
 3398   constraint(ALLOC_IN_RC(vectmask_reg_K6));
 3399   match(RegVectMask);
 3400   format %{%}
 3401   interface(REG_INTER);
 3402 %}
 3403 
 3404 // Special Registers
 3405 operand kReg_K7()
 3406 %{
 3407   constraint(ALLOC_IN_RC(vectmask_reg_K7));
 3408   match(RegVectMask);
 3409   format %{%}
 3410   interface(REG_INTER);
 3411 %}
 3412 
 3413 // Register Operands
 3414 // Integer Register
 3415 operand rRegI()
 3416 %{
 3417   constraint(ALLOC_IN_RC(int_reg));
 3418   match(RegI);
 3419 
 3420   match(rax_RegI);
 3421   match(rbx_RegI);
 3422   match(rcx_RegI);
 3423   match(rdx_RegI);
 3424   match(rdi_RegI);
 3425 
 3426   format %{ %}
 3427   interface(REG_INTER);
 3428 %}
 3429 
 3430 // Special Registers
 3431 operand rax_RegI()
 3432 %{
 3433   constraint(ALLOC_IN_RC(int_rax_reg));
 3434   match(RegI);
 3435   match(rRegI);
 3436 
 3437   format %{ "RAX" %}
 3438   interface(REG_INTER);
 3439 %}
 3440 
 3441 // Special Registers
 3442 operand rbx_RegI()
 3443 %{
 3444   constraint(ALLOC_IN_RC(int_rbx_reg));
 3445   match(RegI);
 3446   match(rRegI);
 3447 
 3448   format %{ "RBX" %}
 3449   interface(REG_INTER);
 3450 %}
 3451 
 3452 operand rcx_RegI()
 3453 %{
 3454   constraint(ALLOC_IN_RC(int_rcx_reg));
 3455   match(RegI);
 3456   match(rRegI);
 3457 
 3458   format %{ "RCX" %}
 3459   interface(REG_INTER);
 3460 %}
 3461 
 3462 operand rdx_RegI()
 3463 %{
 3464   constraint(ALLOC_IN_RC(int_rdx_reg));
 3465   match(RegI);
 3466   match(rRegI);
 3467 
 3468   format %{ "RDX" %}
 3469   interface(REG_INTER);
 3470 %}
 3471 
 3472 operand rdi_RegI()
 3473 %{
 3474   constraint(ALLOC_IN_RC(int_rdi_reg));
 3475   match(RegI);
 3476   match(rRegI);
 3477 
 3478   format %{ "RDI" %}
 3479   interface(REG_INTER);
 3480 %}
 3481 
 3482 operand no_rax_rdx_RegI()
 3483 %{
 3484   constraint(ALLOC_IN_RC(int_no_rax_rdx_reg));
 3485   match(RegI);
 3486   match(rbx_RegI);
 3487   match(rcx_RegI);
 3488   match(rdi_RegI);
 3489 
 3490   format %{ %}
 3491   interface(REG_INTER);
 3492 %}
 3493 
 3494 // Pointer Register
 3495 operand any_RegP()
 3496 %{
 3497   constraint(ALLOC_IN_RC(any_reg));
 3498   match(RegP);
 3499   match(rax_RegP);
 3500   match(rbx_RegP);
 3501   match(rdi_RegP);
 3502   match(rsi_RegP);
 3503   match(rbp_RegP);
 3504   match(r15_RegP);
 3505   match(rRegP);
 3506 
 3507   format %{ %}
 3508   interface(REG_INTER);
 3509 %}
 3510 
 3511 operand rRegP()
 3512 %{
 3513   constraint(ALLOC_IN_RC(ptr_reg));
 3514   match(RegP);
 3515   match(rax_RegP);
 3516   match(rbx_RegP);
 3517   match(rdi_RegP);
 3518   match(rsi_RegP);
 3519   match(rbp_RegP);  // See Q&A below about
 3520   match(r15_RegP);  // r15_RegP and rbp_RegP.
 3521 
 3522   format %{ %}
 3523   interface(REG_INTER);
 3524 %}
 3525 
 3526 operand rRegN() %{
 3527   constraint(ALLOC_IN_RC(int_reg));
 3528   match(RegN);
 3529 
 3530   format %{ %}
 3531   interface(REG_INTER);
 3532 %}
 3533 
 3534 // Question: Why is r15_RegP (the read-only TLS register) a match for rRegP?
 3535 // Answer: Operand match rules govern the DFA as it processes instruction inputs.
 3536 // It's fine for an instruction input that expects rRegP to match a r15_RegP.
 3537 // The output of an instruction is controlled by the allocator, which respects
 3538 // register class masks, not match rules.  Unless an instruction mentions
 3539 // r15_RegP or any_RegP explicitly as its output, r15 will not be considered
 3540 // by the allocator as an input.
 3541 // The same logic applies to rbp_RegP being a match for rRegP: If PreserveFramePointer==true,
 3542 // the RBP is used as a proper frame pointer and is not included in ptr_reg. As a
 3543 // result, RBP is not included in the output of the instruction either.
 3544 
 3545 operand no_rax_RegP()
 3546 %{
 3547   constraint(ALLOC_IN_RC(ptr_no_rax_reg));
 3548   match(RegP);
 3549   match(rbx_RegP);
 3550   match(rsi_RegP);
 3551   match(rdi_RegP);
 3552 
 3553   format %{ %}
 3554   interface(REG_INTER);
 3555 %}
 3556 
 3557 // This operand is not allowed to use RBP even if
 3558 // RBP is not used to hold the frame pointer.
 3559 operand no_rbp_RegP()
 3560 %{
 3561   constraint(ALLOC_IN_RC(ptr_reg_no_rbp));
 3562   match(RegP);
 3563   match(rbx_RegP);
 3564   match(rsi_RegP);
 3565   match(rdi_RegP);
 3566 
 3567   format %{ %}
 3568   interface(REG_INTER);
 3569 %}
 3570 
 3571 operand no_rax_rbx_RegP()
 3572 %{
 3573   constraint(ALLOC_IN_RC(ptr_no_rax_rbx_reg));
 3574   match(RegP);
 3575   match(rsi_RegP);
 3576   match(rdi_RegP);
 3577 
 3578   format %{ %}
 3579   interface(REG_INTER);
 3580 %}
 3581 
 3582 // Special Registers
 3583 // Return a pointer value
 3584 operand rax_RegP()
 3585 %{
 3586   constraint(ALLOC_IN_RC(ptr_rax_reg));
 3587   match(RegP);
 3588   match(rRegP);
 3589 
 3590   format %{ %}
 3591   interface(REG_INTER);
 3592 %}
 3593 
 3594 // Special Registers
 3595 // Return a compressed pointer value
 3596 operand rax_RegN()
 3597 %{
 3598   constraint(ALLOC_IN_RC(int_rax_reg));
 3599   match(RegN);
 3600   match(rRegN);
 3601 
 3602   format %{ %}
 3603   interface(REG_INTER);
 3604 %}
 3605 
 3606 // Used in AtomicAdd
 3607 operand rbx_RegP()
 3608 %{
 3609   constraint(ALLOC_IN_RC(ptr_rbx_reg));
 3610   match(RegP);
 3611   match(rRegP);
 3612 
 3613   format %{ %}
 3614   interface(REG_INTER);
 3615 %}
 3616 
 3617 operand rsi_RegP()
 3618 %{
 3619   constraint(ALLOC_IN_RC(ptr_rsi_reg));
 3620   match(RegP);
 3621   match(rRegP);
 3622 
 3623   format %{ %}
 3624   interface(REG_INTER);
 3625 %}
 3626 
 3627 operand rbp_RegP()
 3628 %{
 3629   constraint(ALLOC_IN_RC(ptr_rbp_reg));
 3630   match(RegP);
 3631   match(rRegP);
 3632 
 3633   format %{ %}
 3634   interface(REG_INTER);
 3635 %}
 3636 
 3637 // Used in rep stosq
 3638 operand rdi_RegP()
 3639 %{
 3640   constraint(ALLOC_IN_RC(ptr_rdi_reg));
 3641   match(RegP);
 3642   match(rRegP);
 3643 
 3644   format %{ %}
 3645   interface(REG_INTER);
 3646 %}
 3647 
 3648 operand r15_RegP()
 3649 %{
 3650   constraint(ALLOC_IN_RC(ptr_r15_reg));
 3651   match(RegP);
 3652   match(rRegP);
 3653 
 3654   format %{ %}
 3655   interface(REG_INTER);
 3656 %}
 3657 
 3658 operand rRegL()
 3659 %{
 3660   constraint(ALLOC_IN_RC(long_reg));
 3661   match(RegL);
 3662   match(rax_RegL);
 3663   match(rdx_RegL);
 3664 
 3665   format %{ %}
 3666   interface(REG_INTER);
 3667 %}
 3668 
 3669 // Special Registers
 3670 operand no_rax_rdx_RegL()
 3671 %{
 3672   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
 3673   match(RegL);
 3674   match(rRegL);
 3675 
 3676   format %{ %}
 3677   interface(REG_INTER);
 3678 %}
 3679 
 3680 operand no_rax_RegL()
 3681 %{
 3682   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
 3683   match(RegL);
 3684   match(rRegL);
 3685   match(rdx_RegL);
 3686 
 3687   format %{ %}
 3688   interface(REG_INTER);
 3689 %}
 3690 
 3691 operand rax_RegL()
 3692 %{
 3693   constraint(ALLOC_IN_RC(long_rax_reg));
 3694   match(RegL);
 3695   match(rRegL);
 3696 
 3697   format %{ "RAX" %}
 3698   interface(REG_INTER);
 3699 %}
 3700 
 3701 operand rcx_RegL()
 3702 %{
 3703   constraint(ALLOC_IN_RC(long_rcx_reg));
 3704   match(RegL);
 3705   match(rRegL);
 3706 
 3707   format %{ %}
 3708   interface(REG_INTER);
 3709 %}
 3710 
 3711 operand rdx_RegL()
 3712 %{
 3713   constraint(ALLOC_IN_RC(long_rdx_reg));
 3714   match(RegL);
 3715   match(rRegL);
 3716 
 3717   format %{ %}
 3718   interface(REG_INTER);
 3719 %}
 3720 
 3721 // Flags register, used as output of compare instructions
 3722 operand rFlagsReg()
 3723 %{
 3724   constraint(ALLOC_IN_RC(int_flags));
 3725   match(RegFlags);
 3726 
 3727   format %{ "RFLAGS" %}
 3728   interface(REG_INTER);
 3729 %}
 3730 
 3731 // Flags register, used as output of FLOATING POINT compare instructions
 3732 operand rFlagsRegU()
 3733 %{
 3734   constraint(ALLOC_IN_RC(int_flags));
 3735   match(RegFlags);
 3736 
 3737   format %{ "RFLAGS_U" %}
 3738   interface(REG_INTER);
 3739 %}
 3740 
 3741 operand rFlagsRegUCF() %{
 3742   constraint(ALLOC_IN_RC(int_flags));
 3743   match(RegFlags);
 3744   predicate(false);
 3745 
 3746   format %{ "RFLAGS_U_CF" %}
 3747   interface(REG_INTER);
 3748 %}
 3749 
 3750 // Float register operands
 3751 operand regF() %{
 3752    constraint(ALLOC_IN_RC(float_reg));
 3753    match(RegF);
 3754 
 3755    format %{ %}
 3756    interface(REG_INTER);
 3757 %}
 3758 
 3759 // Float register operands
 3760 operand legRegF() %{
 3761    constraint(ALLOC_IN_RC(float_reg_legacy));
 3762    match(RegF);
 3763 
 3764    format %{ %}
 3765    interface(REG_INTER);
 3766 %}
 3767 
 3768 // Float register operands
 3769 operand vlRegF() %{
 3770    constraint(ALLOC_IN_RC(float_reg_vl));
 3771    match(RegF);
 3772 
 3773    format %{ %}
 3774    interface(REG_INTER);
 3775 %}
 3776 
 3777 // Double register operands
 3778 operand regD() %{
 3779    constraint(ALLOC_IN_RC(double_reg));
 3780    match(RegD);
 3781 
 3782    format %{ %}
 3783    interface(REG_INTER);
 3784 %}
 3785 
 3786 // Double register operands
 3787 operand legRegD() %{
 3788    constraint(ALLOC_IN_RC(double_reg_legacy));
 3789    match(RegD);
 3790 
 3791    format %{ %}
 3792    interface(REG_INTER);
 3793 %}
 3794 
 3795 // Double register operands
 3796 operand vlRegD() %{
 3797    constraint(ALLOC_IN_RC(double_reg_vl));
 3798    match(RegD);
 3799 
 3800    format %{ %}
 3801    interface(REG_INTER);
 3802 %}
 3803 
 3804 //----------Memory Operands----------------------------------------------------
 3805 // Direct Memory Operand
 3806 // operand direct(immP addr)
 3807 // %{
 3808 //   match(addr);
 3809 
 3810 //   format %{ "[$addr]" %}
 3811 //   interface(MEMORY_INTER) %{
 3812 //     base(0xFFFFFFFF);
 3813 //     index(0x4);
 3814 //     scale(0x0);
 3815 //     disp($addr);
 3816 //   %}
 3817 // %}
 3818 
 3819 // Indirect Memory Operand
 3820 operand indirect(any_RegP reg)
 3821 %{
 3822   constraint(ALLOC_IN_RC(ptr_reg));
 3823   match(reg);
 3824 
 3825   format %{ "[$reg]" %}
 3826   interface(MEMORY_INTER) %{
 3827     base($reg);
 3828     index(0x4);
 3829     scale(0x0);
 3830     disp(0x0);
 3831   %}
 3832 %}
 3833 
 3834 // Indirect Memory Plus Short Offset Operand
 3835 operand indOffset8(any_RegP reg, immL8 off)
 3836 %{
 3837   constraint(ALLOC_IN_RC(ptr_reg));
 3838   match(AddP reg off);
 3839 
 3840   format %{ "[$reg + $off (8-bit)]" %}
 3841   interface(MEMORY_INTER) %{
 3842     base($reg);
 3843     index(0x4);
 3844     scale(0x0);
 3845     disp($off);
 3846   %}
 3847 %}
 3848 
 3849 // Indirect Memory Plus Long Offset Operand
 3850 operand indOffset32(any_RegP reg, immL32 off)
 3851 %{
 3852   constraint(ALLOC_IN_RC(ptr_reg));
 3853   match(AddP reg off);
 3854 
 3855   format %{ "[$reg + $off (32-bit)]" %}
 3856   interface(MEMORY_INTER) %{
 3857     base($reg);
 3858     index(0x4);
 3859     scale(0x0);
 3860     disp($off);
 3861   %}
 3862 %}
 3863 
 3864 // Indirect Memory Plus Index Register Plus Offset Operand
 3865 operand indIndexOffset(any_RegP reg, rRegL lreg, immL32 off)
 3866 %{
 3867   constraint(ALLOC_IN_RC(ptr_reg));
 3868   match(AddP (AddP reg lreg) off);
 3869 
 3870   op_cost(10);
 3871   format %{"[$reg + $off + $lreg]" %}
 3872   interface(MEMORY_INTER) %{
 3873     base($reg);
 3874     index($lreg);
 3875     scale(0x0);
 3876     disp($off);
 3877   %}
 3878 %}
 3879 
 3880 // Indirect Memory Plus Index Register Plus Offset Operand
 3881 operand indIndex(any_RegP reg, rRegL lreg)
 3882 %{
 3883   constraint(ALLOC_IN_RC(ptr_reg));
 3884   match(AddP reg lreg);
 3885 
 3886   op_cost(10);
 3887   format %{"[$reg + $lreg]" %}
 3888   interface(MEMORY_INTER) %{
 3889     base($reg);
 3890     index($lreg);
 3891     scale(0x0);
 3892     disp(0x0);
 3893   %}
 3894 %}
 3895 
 3896 // Indirect Memory Times Scale Plus Index Register
 3897 operand indIndexScale(any_RegP reg, rRegL lreg, immI2 scale)
 3898 %{
 3899   constraint(ALLOC_IN_RC(ptr_reg));
 3900   match(AddP reg (LShiftL lreg scale));
 3901 
 3902   op_cost(10);
 3903   format %{"[$reg + $lreg << $scale]" %}
 3904   interface(MEMORY_INTER) %{
 3905     base($reg);
 3906     index($lreg);
 3907     scale($scale);
 3908     disp(0x0);
 3909   %}
 3910 %}
 3911 
 3912 operand indPosIndexScale(any_RegP reg, rRegI idx, immI2 scale)
 3913 %{
 3914   constraint(ALLOC_IN_RC(ptr_reg));
 3915   predicate(n->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
 3916   match(AddP reg (LShiftL (ConvI2L idx) scale));
 3917 
 3918   op_cost(10);
 3919   format %{"[$reg + pos $idx << $scale]" %}
 3920   interface(MEMORY_INTER) %{
 3921     base($reg);
 3922     index($idx);
 3923     scale($scale);
 3924     disp(0x0);
 3925   %}
 3926 %}
 3927 
 3928 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
 3929 operand indIndexScaleOffset(any_RegP reg, immL32 off, rRegL lreg, immI2 scale)
 3930 %{
 3931   constraint(ALLOC_IN_RC(ptr_reg));
 3932   match(AddP (AddP reg (LShiftL lreg scale)) off);
 3933 
 3934   op_cost(10);
 3935   format %{"[$reg + $off + $lreg << $scale]" %}
 3936   interface(MEMORY_INTER) %{
 3937     base($reg);
 3938     index($lreg);
 3939     scale($scale);
 3940     disp($off);
 3941   %}
 3942 %}
 3943 
 3944 // Indirect Memory Plus Positive Index Register Plus Offset Operand
 3945 operand indPosIndexOffset(any_RegP reg, immL32 off, rRegI idx)
 3946 %{
 3947   constraint(ALLOC_IN_RC(ptr_reg));
 3948   predicate(n->in(2)->in(3)->as_Type()->type()->is_long()->_lo >= 0);
 3949   match(AddP (AddP reg (ConvI2L idx)) off);
 3950 
 3951   op_cost(10);
 3952   format %{"[$reg + $off + $idx]" %}
 3953   interface(MEMORY_INTER) %{
 3954     base($reg);
 3955     index($idx);
 3956     scale(0x0);
 3957     disp($off);
 3958   %}
 3959 %}
 3960 
 3961 // Indirect Memory Times Scale Plus Positive Index Register Plus Offset Operand
 3962 operand indPosIndexScaleOffset(any_RegP reg, immL32 off, rRegI idx, immI2 scale)
 3963 %{
 3964   constraint(ALLOC_IN_RC(ptr_reg));
 3965   predicate(n->in(2)->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
 3966   match(AddP (AddP reg (LShiftL (ConvI2L idx) scale)) off);
 3967 
 3968   op_cost(10);
 3969   format %{"[$reg + $off + $idx << $scale]" %}
 3970   interface(MEMORY_INTER) %{
 3971     base($reg);
 3972     index($idx);
 3973     scale($scale);
 3974     disp($off);
 3975   %}
 3976 %}
 3977 
 3978 // Indirect Narrow Oop Plus Offset Operand
 3979 // Note: x86 architecture doesn't support "scale * index + offset" without a base
 3980 // we can't free r12 even with CompressedOops::base() == NULL.
 3981 operand indCompressedOopOffset(rRegN reg, immL32 off) %{
 3982   predicate(UseCompressedOops && (CompressedOops::shift() == Address::times_8));
 3983   constraint(ALLOC_IN_RC(ptr_reg));
 3984   match(AddP (DecodeN reg) off);
 3985 
 3986   op_cost(10);
 3987   format %{"[R12 + $reg << 3 + $off] (compressed oop addressing)" %}
 3988   interface(MEMORY_INTER) %{
 3989     base(0xc); // R12
 3990     index($reg);
 3991     scale(0x3);
 3992     disp($off);
 3993   %}
 3994 %}
 3995 
 3996 // Indirect Memory Operand
 3997 operand indirectNarrow(rRegN reg)
 3998 %{
 3999   predicate(CompressedOops::shift() == 0);
 4000   constraint(ALLOC_IN_RC(ptr_reg));
 4001   match(DecodeN reg);
 4002 
 4003   format %{ "[$reg]" %}
 4004   interface(MEMORY_INTER) %{
 4005     base($reg);
 4006     index(0x4);
 4007     scale(0x0);
 4008     disp(0x0);
 4009   %}
 4010 %}
 4011 
 4012 // Indirect Memory Plus Short Offset Operand
 4013 operand indOffset8Narrow(rRegN reg, immL8 off)
 4014 %{
 4015   predicate(CompressedOops::shift() == 0);
 4016   constraint(ALLOC_IN_RC(ptr_reg));
 4017   match(AddP (DecodeN reg) off);
 4018 
 4019   format %{ "[$reg + $off (8-bit)]" %}
 4020   interface(MEMORY_INTER) %{
 4021     base($reg);
 4022     index(0x4);
 4023     scale(0x0);
 4024     disp($off);
 4025   %}
 4026 %}
 4027 
 4028 // Indirect Memory Plus Long Offset Operand
 4029 operand indOffset32Narrow(rRegN reg, immL32 off)
 4030 %{
 4031   predicate(CompressedOops::shift() == 0);
 4032   constraint(ALLOC_IN_RC(ptr_reg));
 4033   match(AddP (DecodeN reg) off);
 4034 
 4035   format %{ "[$reg + $off (32-bit)]" %}
 4036   interface(MEMORY_INTER) %{
 4037     base($reg);
 4038     index(0x4);
 4039     scale(0x0);
 4040     disp($off);
 4041   %}
 4042 %}
 4043 
 4044 // Indirect Memory Plus Index Register Plus Offset Operand
 4045 operand indIndexOffsetNarrow(rRegN reg, rRegL lreg, immL32 off)
 4046 %{
 4047   predicate(CompressedOops::shift() == 0);
 4048   constraint(ALLOC_IN_RC(ptr_reg));
 4049   match(AddP (AddP (DecodeN reg) lreg) off);
 4050 
 4051   op_cost(10);
 4052   format %{"[$reg + $off + $lreg]" %}
 4053   interface(MEMORY_INTER) %{
 4054     base($reg);
 4055     index($lreg);
 4056     scale(0x0);
 4057     disp($off);
 4058   %}
 4059 %}
 4060 
 4061 // Indirect Memory Plus Index Register Plus Offset Operand
 4062 operand indIndexNarrow(rRegN reg, rRegL lreg)
 4063 %{
 4064   predicate(CompressedOops::shift() == 0);
 4065   constraint(ALLOC_IN_RC(ptr_reg));
 4066   match(AddP (DecodeN reg) lreg);
 4067 
 4068   op_cost(10);
 4069   format %{"[$reg + $lreg]" %}
 4070   interface(MEMORY_INTER) %{
 4071     base($reg);
 4072     index($lreg);
 4073     scale(0x0);
 4074     disp(0x0);
 4075   %}
 4076 %}
 4077 
 4078 // Indirect Memory Times Scale Plus Index Register
 4079 operand indIndexScaleNarrow(rRegN reg, rRegL lreg, immI2 scale)
 4080 %{
 4081   predicate(CompressedOops::shift() == 0);
 4082   constraint(ALLOC_IN_RC(ptr_reg));
 4083   match(AddP (DecodeN reg) (LShiftL lreg scale));
 4084 
 4085   op_cost(10);
 4086   format %{"[$reg + $lreg << $scale]" %}
 4087   interface(MEMORY_INTER) %{
 4088     base($reg);
 4089     index($lreg);
 4090     scale($scale);
 4091     disp(0x0);
 4092   %}
 4093 %}
 4094 
 4095 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
 4096 operand indIndexScaleOffsetNarrow(rRegN reg, immL32 off, rRegL lreg, immI2 scale)
 4097 %{
 4098   predicate(CompressedOops::shift() == 0);
 4099   constraint(ALLOC_IN_RC(ptr_reg));
 4100   match(AddP (AddP (DecodeN reg) (LShiftL lreg scale)) off);
 4101 
 4102   op_cost(10);
 4103   format %{"[$reg + $off + $lreg << $scale]" %}
 4104   interface(MEMORY_INTER) %{
 4105     base($reg);
 4106     index($lreg);
 4107     scale($scale);
 4108     disp($off);
 4109   %}
 4110 %}
 4111 
 4112 // Indirect Memory Times Plus Positive Index Register Plus Offset Operand
 4113 operand indPosIndexOffsetNarrow(rRegN reg, immL32 off, rRegI idx)
 4114 %{
 4115   constraint(ALLOC_IN_RC(ptr_reg));
 4116   predicate(CompressedOops::shift() == 0 && n->in(2)->in(3)->as_Type()->type()->is_long()->_lo >= 0);
 4117   match(AddP (AddP (DecodeN reg) (ConvI2L idx)) off);
 4118 
 4119   op_cost(10);
 4120   format %{"[$reg + $off + $idx]" %}
 4121   interface(MEMORY_INTER) %{
 4122     base($reg);
 4123     index($idx);
 4124     scale(0x0);
 4125     disp($off);
 4126   %}
 4127 %}
 4128 
 4129 // Indirect Memory Times Scale Plus Positive Index Register Plus Offset Operand
 4130 operand indPosIndexScaleOffsetNarrow(rRegN reg, immL32 off, rRegI idx, immI2 scale)
 4131 %{
 4132   constraint(ALLOC_IN_RC(ptr_reg));
 4133   predicate(CompressedOops::shift() == 0 && n->in(2)->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
 4134   match(AddP (AddP (DecodeN reg) (LShiftL (ConvI2L idx) scale)) off);
 4135 
 4136   op_cost(10);
 4137   format %{"[$reg + $off + $idx << $scale]" %}
 4138   interface(MEMORY_INTER) %{
 4139     base($reg);
 4140     index($idx);
 4141     scale($scale);
 4142     disp($off);
 4143   %}
 4144 %}
 4145 
 4146 //----------Special Memory Operands--------------------------------------------
 4147 // Stack Slot Operand - This operand is used for loading and storing temporary
 4148 //                      values on the stack where a match requires a value to
 4149 //                      flow through memory.
 4150 operand stackSlotP(sRegP reg)
 4151 %{
 4152   constraint(ALLOC_IN_RC(stack_slots));
 4153   // No match rule because this operand is only generated in matching
 4154 
 4155   format %{ "[$reg]" %}
 4156   interface(MEMORY_INTER) %{
 4157     base(0x4);   // RSP
 4158     index(0x4);  // No Index
 4159     scale(0x0);  // No Scale
 4160     disp($reg);  // Stack Offset
 4161   %}
 4162 %}
 4163 
 4164 operand stackSlotI(sRegI reg)
 4165 %{
 4166   constraint(ALLOC_IN_RC(stack_slots));
 4167   // No match rule because this operand is only generated in matching
 4168 
 4169   format %{ "[$reg]" %}
 4170   interface(MEMORY_INTER) %{
 4171     base(0x4);   // RSP
 4172     index(0x4);  // No Index
 4173     scale(0x0);  // No Scale
 4174     disp($reg);  // Stack Offset
 4175   %}
 4176 %}
 4177 
 4178 operand stackSlotF(sRegF reg)
 4179 %{
 4180   constraint(ALLOC_IN_RC(stack_slots));
 4181   // No match rule because this operand is only generated in matching
 4182 
 4183   format %{ "[$reg]" %}
 4184   interface(MEMORY_INTER) %{
 4185     base(0x4);   // RSP
 4186     index(0x4);  // No Index
 4187     scale(0x0);  // No Scale
 4188     disp($reg);  // Stack Offset
 4189   %}
 4190 %}
 4191 
 4192 operand stackSlotD(sRegD reg)
 4193 %{
 4194   constraint(ALLOC_IN_RC(stack_slots));
 4195   // No match rule because this operand is only generated in matching
 4196 
 4197   format %{ "[$reg]" %}
 4198   interface(MEMORY_INTER) %{
 4199     base(0x4);   // RSP
 4200     index(0x4);  // No Index
 4201     scale(0x0);  // No Scale
 4202     disp($reg);  // Stack Offset
 4203   %}
 4204 %}
 4205 operand stackSlotL(sRegL reg)
 4206 %{
 4207   constraint(ALLOC_IN_RC(stack_slots));
 4208   // No match rule because this operand is only generated in matching
 4209 
 4210   format %{ "[$reg]" %}
 4211   interface(MEMORY_INTER) %{
 4212     base(0x4);   // RSP
 4213     index(0x4);  // No Index
 4214     scale(0x0);  // No Scale
 4215     disp($reg);  // Stack Offset
 4216   %}
 4217 %}
 4218 
 4219 //----------Conditional Branch Operands----------------------------------------
 4220 // Comparison Op  - This is the operation of the comparison, and is limited to
 4221 //                  the following set of codes:
 4222 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
 4223 //
 4224 // Other attributes of the comparison, such as unsignedness, are specified
 4225 // by the comparison instruction that sets a condition code flags register.
 4226 // That result is represented by a flags operand whose subtype is appropriate
 4227 // to the unsignedness (etc.) of the comparison.
 4228 //
 4229 // Later, the instruction which matches both the Comparison Op (a Bool) and
 4230 // the flags (produced by the Cmp) specifies the coding of the comparison op
 4231 // by matching a specific subtype of Bool operand below, such as cmpOpU.
 4232 
 4233 // Comparision Code
 4234 operand cmpOp()
 4235 %{
 4236   match(Bool);
 4237 
 4238   format %{ "" %}
 4239   interface(COND_INTER) %{
 4240     equal(0x4, "e");
 4241     not_equal(0x5, "ne");
 4242     less(0xC, "l");
 4243     greater_equal(0xD, "ge");
 4244     less_equal(0xE, "le");
 4245     greater(0xF, "g");
 4246     overflow(0x0, "o");
 4247     no_overflow(0x1, "no");
 4248   %}
 4249 %}
 4250 
 4251 // Comparison Code, unsigned compare.  Used by FP also, with
 4252 // C2 (unordered) turned into GT or LT already.  The other bits
 4253 // C0 and C3 are turned into Carry & Zero flags.
 4254 operand cmpOpU()
 4255 %{
 4256   match(Bool);
 4257 
 4258   format %{ "" %}
 4259   interface(COND_INTER) %{
 4260     equal(0x4, "e");
 4261     not_equal(0x5, "ne");
 4262     less(0x2, "b");
 4263     greater_equal(0x3, "nb");
 4264     less_equal(0x6, "be");
 4265     greater(0x7, "nbe");
 4266     overflow(0x0, "o");
 4267     no_overflow(0x1, "no");
 4268   %}
 4269 %}
 4270 
 4271 
 4272 // Floating comparisons that don't require any fixup for the unordered case
 4273 operand cmpOpUCF() %{
 4274   match(Bool);
 4275   predicate(n->as_Bool()->_test._test == BoolTest::lt ||
 4276             n->as_Bool()->_test._test == BoolTest::ge ||
 4277             n->as_Bool()->_test._test == BoolTest::le ||
 4278             n->as_Bool()->_test._test == BoolTest::gt);
 4279   format %{ "" %}
 4280   interface(COND_INTER) %{
 4281     equal(0x4, "e");
 4282     not_equal(0x5, "ne");
 4283     less(0x2, "b");
 4284     greater_equal(0x3, "nb");
 4285     less_equal(0x6, "be");
 4286     greater(0x7, "nbe");
 4287     overflow(0x0, "o");
 4288     no_overflow(0x1, "no");
 4289   %}
 4290 %}
 4291 
 4292 
 4293 // Floating comparisons that can be fixed up with extra conditional jumps
 4294 operand cmpOpUCF2() %{
 4295   match(Bool);
 4296   predicate(n->as_Bool()->_test._test == BoolTest::ne ||
 4297             n->as_Bool()->_test._test == BoolTest::eq);
 4298   format %{ "" %}
 4299   interface(COND_INTER) %{
 4300     equal(0x4, "e");
 4301     not_equal(0x5, "ne");
 4302     less(0x2, "b");
 4303     greater_equal(0x3, "nb");
 4304     less_equal(0x6, "be");
 4305     greater(0x7, "nbe");
 4306     overflow(0x0, "o");
 4307     no_overflow(0x1, "no");
 4308   %}
 4309 %}
 4310 
 4311 //----------OPERAND CLASSES----------------------------------------------------
 4312 // Operand Classes are groups of operands that are used as to simplify
 4313 // instruction definitions by not requiring the AD writer to specify separate
 4314 // instructions for every form of operand when the instruction accepts
 4315 // multiple operand types with the same basic encoding and format.  The classic
 4316 // case of this is memory operands.
 4317 
 4318 opclass memory(indirect, indOffset8, indOffset32, indIndexOffset, indIndex,
 4319                indIndexScale, indPosIndexScale, indIndexScaleOffset, indPosIndexOffset, indPosIndexScaleOffset,
 4320                indCompressedOopOffset,
 4321                indirectNarrow, indOffset8Narrow, indOffset32Narrow,
 4322                indIndexOffsetNarrow, indIndexNarrow, indIndexScaleNarrow,
 4323                indIndexScaleOffsetNarrow, indPosIndexOffsetNarrow, indPosIndexScaleOffsetNarrow);
 4324 
 4325 //----------PIPELINE-----------------------------------------------------------
 4326 // Rules which define the behavior of the target architectures pipeline.
 4327 pipeline %{
 4328 
 4329 //----------ATTRIBUTES---------------------------------------------------------
 4330 attributes %{
 4331   variable_size_instructions;        // Fixed size instructions
 4332   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
 4333   instruction_unit_size = 1;         // An instruction is 1 bytes long
 4334   instruction_fetch_unit_size = 16;  // The processor fetches one line
 4335   instruction_fetch_units = 1;       // of 16 bytes
 4336 
 4337   // List of nop instructions
 4338   nops( MachNop );
 4339 %}
 4340 
 4341 //----------RESOURCES----------------------------------------------------------
 4342 // Resources are the functional units available to the machine
 4343 
 4344 // Generic P2/P3 pipeline
 4345 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
 4346 // 3 instructions decoded per cycle.
 4347 // 2 load/store ops per cycle, 1 branch, 1 FPU,
 4348 // 3 ALU op, only ALU0 handles mul instructions.
 4349 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
 4350            MS0, MS1, MS2, MEM = MS0 | MS1 | MS2,
 4351            BR, FPU,
 4352            ALU0, ALU1, ALU2, ALU = ALU0 | ALU1 | ALU2);
 4353 
 4354 //----------PIPELINE DESCRIPTION-----------------------------------------------
 4355 // Pipeline Description specifies the stages in the machine's pipeline
 4356 
 4357 // Generic P2/P3 pipeline
 4358 pipe_desc(S0, S1, S2, S3, S4, S5);
 4359 
 4360 //----------PIPELINE CLASSES---------------------------------------------------
 4361 // Pipeline Classes describe the stages in which input and output are
 4362 // referenced by the hardware pipeline.
 4363 
 4364 // Naming convention: ialu or fpu
 4365 // Then: _reg
 4366 // Then: _reg if there is a 2nd register
 4367 // Then: _long if it's a pair of instructions implementing a long
 4368 // Then: _fat if it requires the big decoder
 4369 //   Or: _mem if it requires the big decoder and a memory unit.
 4370 
 4371 // Integer ALU reg operation
 4372 pipe_class ialu_reg(rRegI dst)
 4373 %{
 4374     single_instruction;
 4375     dst    : S4(write);
 4376     dst    : S3(read);
 4377     DECODE : S0;        // any decoder
 4378     ALU    : S3;        // any alu
 4379 %}
 4380 
 4381 // Long ALU reg operation
 4382 pipe_class ialu_reg_long(rRegL dst)
 4383 %{
 4384     instruction_count(2);
 4385     dst    : S4(write);
 4386     dst    : S3(read);
 4387     DECODE : S0(2);     // any 2 decoders
 4388     ALU    : S3(2);     // both alus
 4389 %}
 4390 
 4391 // Integer ALU reg operation using big decoder
 4392 pipe_class ialu_reg_fat(rRegI dst)
 4393 %{
 4394     single_instruction;
 4395     dst    : S4(write);
 4396     dst    : S3(read);
 4397     D0     : S0;        // big decoder only
 4398     ALU    : S3;        // any alu
 4399 %}
 4400 
 4401 // Integer ALU reg-reg operation
 4402 pipe_class ialu_reg_reg(rRegI dst, rRegI src)
 4403 %{
 4404     single_instruction;
 4405     dst    : S4(write);
 4406     src    : S3(read);
 4407     DECODE : S0;        // any decoder
 4408     ALU    : S3;        // any alu
 4409 %}
 4410 
 4411 // Integer ALU reg-reg operation
 4412 pipe_class ialu_reg_reg_fat(rRegI dst, memory src)
 4413 %{
 4414     single_instruction;
 4415     dst    : S4(write);
 4416     src    : S3(read);
 4417     D0     : S0;        // big decoder only
 4418     ALU    : S3;        // any alu
 4419 %}
 4420 
 4421 // Integer ALU reg-mem operation
 4422 pipe_class ialu_reg_mem(rRegI dst, memory mem)
 4423 %{
 4424     single_instruction;
 4425     dst    : S5(write);
 4426     mem    : S3(read);
 4427     D0     : S0;        // big decoder only
 4428     ALU    : S4;        // any alu
 4429     MEM    : S3;        // any mem
 4430 %}
 4431 
 4432 // Integer mem operation (prefetch)
 4433 pipe_class ialu_mem(memory mem)
 4434 %{
 4435     single_instruction;
 4436     mem    : S3(read);
 4437     D0     : S0;        // big decoder only
 4438     MEM    : S3;        // any mem
 4439 %}
 4440 
 4441 // Integer Store to Memory
 4442 pipe_class ialu_mem_reg(memory mem, rRegI src)
 4443 %{
 4444     single_instruction;
 4445     mem    : S3(read);
 4446     src    : S5(read);
 4447     D0     : S0;        // big decoder only
 4448     ALU    : S4;        // any alu
 4449     MEM    : S3;
 4450 %}
 4451 
 4452 // // Long Store to Memory
 4453 // pipe_class ialu_mem_long_reg(memory mem, rRegL src)
 4454 // %{
 4455 //     instruction_count(2);
 4456 //     mem    : S3(read);
 4457 //     src    : S5(read);
 4458 //     D0     : S0(2);          // big decoder only; twice
 4459 //     ALU    : S4(2);     // any 2 alus
 4460 //     MEM    : S3(2);  // Both mems
 4461 // %}
 4462 
 4463 // Integer Store to Memory
 4464 pipe_class ialu_mem_imm(memory mem)
 4465 %{
 4466     single_instruction;
 4467     mem    : S3(read);
 4468     D0     : S0;        // big decoder only
 4469     ALU    : S4;        // any alu
 4470     MEM    : S3;
 4471 %}
 4472 
 4473 // Integer ALU0 reg-reg operation
 4474 pipe_class ialu_reg_reg_alu0(rRegI dst, rRegI src)
 4475 %{
 4476     single_instruction;
 4477     dst    : S4(write);
 4478     src    : S3(read);
 4479     D0     : S0;        // Big decoder only
 4480     ALU0   : S3;        // only alu0
 4481 %}
 4482 
 4483 // Integer ALU0 reg-mem operation
 4484 pipe_class ialu_reg_mem_alu0(rRegI dst, memory mem)
 4485 %{
 4486     single_instruction;
 4487     dst    : S5(write);
 4488     mem    : S3(read);
 4489     D0     : S0;        // big decoder only
 4490     ALU0   : S4;        // ALU0 only
 4491     MEM    : S3;        // any mem
 4492 %}
 4493 
 4494 // Integer ALU reg-reg operation
 4495 pipe_class ialu_cr_reg_reg(rFlagsReg cr, rRegI src1, rRegI src2)
 4496 %{
 4497     single_instruction;
 4498     cr     : S4(write);
 4499     src1   : S3(read);
 4500     src2   : S3(read);
 4501     DECODE : S0;        // any decoder
 4502     ALU    : S3;        // any alu
 4503 %}
 4504 
 4505 // Integer ALU reg-imm operation
 4506 pipe_class ialu_cr_reg_imm(rFlagsReg cr, rRegI src1)
 4507 %{
 4508     single_instruction;
 4509     cr     : S4(write);
 4510     src1   : S3(read);
 4511     DECODE : S0;        // any decoder
 4512     ALU    : S3;        // any alu
 4513 %}
 4514 
 4515 // Integer ALU reg-mem operation
 4516 pipe_class ialu_cr_reg_mem(rFlagsReg cr, rRegI src1, memory src2)
 4517 %{
 4518     single_instruction;
 4519     cr     : S4(write);
 4520     src1   : S3(read);
 4521     src2   : S3(read);
 4522     D0     : S0;        // big decoder only
 4523     ALU    : S4;        // any alu
 4524     MEM    : S3;
 4525 %}
 4526 
 4527 // Conditional move reg-reg
 4528 pipe_class pipe_cmplt( rRegI p, rRegI q, rRegI y)
 4529 %{
 4530     instruction_count(4);
 4531     y      : S4(read);
 4532     q      : S3(read);
 4533     p      : S3(read);
 4534     DECODE : S0(4);     // any decoder
 4535 %}
 4536 
 4537 // Conditional move reg-reg
 4538 pipe_class pipe_cmov_reg( rRegI dst, rRegI src, rFlagsReg cr)
 4539 %{
 4540     single_instruction;
 4541     dst    : S4(write);
 4542     src    : S3(read);
 4543     cr     : S3(read);
 4544     DECODE : S0;        // any decoder
 4545 %}
 4546 
 4547 // Conditional move reg-mem
 4548 pipe_class pipe_cmov_mem( rFlagsReg cr, rRegI dst, memory src)
 4549 %{
 4550     single_instruction;
 4551     dst    : S4(write);
 4552     src    : S3(read);
 4553     cr     : S3(read);
 4554     DECODE : S0;        // any decoder
 4555     MEM    : S3;
 4556 %}
 4557 
 4558 // Conditional move reg-reg long
 4559 pipe_class pipe_cmov_reg_long( rFlagsReg cr, rRegL dst, rRegL src)
 4560 %{
 4561     single_instruction;
 4562     dst    : S4(write);
 4563     src    : S3(read);
 4564     cr     : S3(read);
 4565     DECODE : S0(2);     // any 2 decoders
 4566 %}
 4567 
 4568 // XXX
 4569 // // Conditional move double reg-reg
 4570 // pipe_class pipe_cmovD_reg( rFlagsReg cr, regDPR1 dst, regD src)
 4571 // %{
 4572 //     single_instruction;
 4573 //     dst    : S4(write);
 4574 //     src    : S3(read);
 4575 //     cr     : S3(read);
 4576 //     DECODE : S0;     // any decoder
 4577 // %}
 4578 
 4579 // Float reg-reg operation
 4580 pipe_class fpu_reg(regD dst)
 4581 %{
 4582     instruction_count(2);
 4583     dst    : S3(read);
 4584     DECODE : S0(2);     // any 2 decoders
 4585     FPU    : S3;
 4586 %}
 4587 
 4588 // Float reg-reg operation
 4589 pipe_class fpu_reg_reg(regD dst, regD src)
 4590 %{
 4591     instruction_count(2);
 4592     dst    : S4(write);
 4593     src    : S3(read);
 4594     DECODE : S0(2);     // any 2 decoders
 4595     FPU    : S3;
 4596 %}
 4597 
 4598 // Float reg-reg operation
 4599 pipe_class fpu_reg_reg_reg(regD dst, regD src1, regD src2)
 4600 %{
 4601     instruction_count(3);
 4602     dst    : S4(write);
 4603     src1   : S3(read);
 4604     src2   : S3(read);
 4605     DECODE : S0(3);     // any 3 decoders
 4606     FPU    : S3(2);
 4607 %}
 4608 
 4609 // Float reg-reg operation
 4610 pipe_class fpu_reg_reg_reg_reg(regD dst, regD src1, regD src2, regD src3)
 4611 %{
 4612     instruction_count(4);
 4613     dst    : S4(write);
 4614     src1   : S3(read);
 4615     src2   : S3(read);
 4616     src3   : S3(read);
 4617     DECODE : S0(4);     // any 3 decoders
 4618     FPU    : S3(2);
 4619 %}
 4620 
 4621 // Float reg-reg operation
 4622 pipe_class fpu_reg_mem_reg_reg(regD dst, memory src1, regD src2, regD src3)
 4623 %{
 4624     instruction_count(4);
 4625     dst    : S4(write);
 4626     src1   : S3(read);
 4627     src2   : S3(read);
 4628     src3   : S3(read);
 4629     DECODE : S1(3);     // any 3 decoders
 4630     D0     : S0;        // Big decoder only
 4631     FPU    : S3(2);
 4632     MEM    : S3;
 4633 %}
 4634 
 4635 // Float reg-mem operation
 4636 pipe_class fpu_reg_mem(regD dst, memory mem)
 4637 %{
 4638     instruction_count(2);
 4639     dst    : S5(write);
 4640     mem    : S3(read);
 4641     D0     : S0;        // big decoder only
 4642     DECODE : S1;        // any decoder for FPU POP
 4643     FPU    : S4;
 4644     MEM    : S3;        // any mem
 4645 %}
 4646 
 4647 // Float reg-mem operation
 4648 pipe_class fpu_reg_reg_mem(regD dst, regD src1, memory mem)
 4649 %{
 4650     instruction_count(3);
 4651     dst    : S5(write);
 4652     src1   : S3(read);
 4653     mem    : S3(read);
 4654     D0     : S0;        // big decoder only
 4655     DECODE : S1(2);     // any decoder for FPU POP
 4656     FPU    : S4;
 4657     MEM    : S3;        // any mem
 4658 %}
 4659 
 4660 // Float mem-reg operation
 4661 pipe_class fpu_mem_reg(memory mem, regD src)
 4662 %{
 4663     instruction_count(2);
 4664     src    : S5(read);
 4665     mem    : S3(read);
 4666     DECODE : S0;        // any decoder for FPU PUSH
 4667     D0     : S1;        // big decoder only
 4668     FPU    : S4;
 4669     MEM    : S3;        // any mem
 4670 %}
 4671 
 4672 pipe_class fpu_mem_reg_reg(memory mem, regD src1, regD src2)
 4673 %{
 4674     instruction_count(3);
 4675     src1   : S3(read);
 4676     src2   : S3(read);
 4677     mem    : S3(read);
 4678     DECODE : S0(2);     // any decoder for FPU PUSH
 4679     D0     : S1;        // big decoder only
 4680     FPU    : S4;
 4681     MEM    : S3;        // any mem
 4682 %}
 4683 
 4684 pipe_class fpu_mem_reg_mem(memory mem, regD src1, memory src2)
 4685 %{
 4686     instruction_count(3);
 4687     src1   : S3(read);
 4688     src2   : S3(read);
 4689     mem    : S4(read);
 4690     DECODE : S0;        // any decoder for FPU PUSH
 4691     D0     : S0(2);     // big decoder only
 4692     FPU    : S4;
 4693     MEM    : S3(2);     // any mem
 4694 %}
 4695 
 4696 pipe_class fpu_mem_mem(memory dst, memory src1)
 4697 %{
 4698     instruction_count(2);
 4699     src1   : S3(read);
 4700     dst    : S4(read);
 4701     D0     : S0(2);     // big decoder only
 4702     MEM    : S3(2);     // any mem
 4703 %}
 4704 
 4705 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2)
 4706 %{
 4707     instruction_count(3);
 4708     src1   : S3(read);
 4709     src2   : S3(read);
 4710     dst    : S4(read);
 4711     D0     : S0(3);     // big decoder only
 4712     FPU    : S4;
 4713     MEM    : S3(3);     // any mem
 4714 %}
 4715 
 4716 pipe_class fpu_mem_reg_con(memory mem, regD src1)
 4717 %{
 4718     instruction_count(3);
 4719     src1   : S4(read);
 4720     mem    : S4(read);
 4721     DECODE : S0;        // any decoder for FPU PUSH
 4722     D0     : S0(2);     // big decoder only
 4723     FPU    : S4;
 4724     MEM    : S3(2);     // any mem
 4725 %}
 4726 
 4727 // Float load constant
 4728 pipe_class fpu_reg_con(regD dst)
 4729 %{
 4730     instruction_count(2);
 4731     dst    : S5(write);
 4732     D0     : S0;        // big decoder only for the load
 4733     DECODE : S1;        // any decoder for FPU POP
 4734     FPU    : S4;
 4735     MEM    : S3;        // any mem
 4736 %}
 4737 
 4738 // Float load constant
 4739 pipe_class fpu_reg_reg_con(regD dst, regD src)
 4740 %{
 4741     instruction_count(3);
 4742     dst    : S5(write);
 4743     src    : S3(read);
 4744     D0     : S0;        // big decoder only for the load
 4745     DECODE : S1(2);     // any decoder for FPU POP
 4746     FPU    : S4;
 4747     MEM    : S3;        // any mem
 4748 %}
 4749 
 4750 // UnConditional branch
 4751 pipe_class pipe_jmp(label labl)
 4752 %{
 4753     single_instruction;
 4754     BR   : S3;
 4755 %}
 4756 
 4757 // Conditional branch
 4758 pipe_class pipe_jcc(cmpOp cmp, rFlagsReg cr, label labl)
 4759 %{
 4760     single_instruction;
 4761     cr    : S1(read);
 4762     BR    : S3;
 4763 %}
 4764 
 4765 // Allocation idiom
 4766 pipe_class pipe_cmpxchg(rRegP dst, rRegP heap_ptr)
 4767 %{
 4768     instruction_count(1); force_serialization;
 4769     fixed_latency(6);
 4770     heap_ptr : S3(read);
 4771     DECODE   : S0(3);
 4772     D0       : S2;
 4773     MEM      : S3;
 4774     ALU      : S3(2);
 4775     dst      : S5(write);
 4776     BR       : S5;
 4777 %}
 4778 
 4779 // Generic big/slow expanded idiom
 4780 pipe_class pipe_slow()
 4781 %{
 4782     instruction_count(10); multiple_bundles; force_serialization;
 4783     fixed_latency(100);
 4784     D0  : S0(2);
 4785     MEM : S3(2);
 4786 %}
 4787 
 4788 // The real do-nothing guy
 4789 pipe_class empty()
 4790 %{
 4791     instruction_count(0);
 4792 %}
 4793 
 4794 // Define the class for the Nop node
 4795 define
 4796 %{
 4797    MachNop = empty;
 4798 %}
 4799 
 4800 %}
 4801 
 4802 //----------INSTRUCTIONS-------------------------------------------------------
 4803 //
 4804 // match      -- States which machine-independent subtree may be replaced
 4805 //               by this instruction.
 4806 // ins_cost   -- The estimated cost of this instruction is used by instruction
 4807 //               selection to identify a minimum cost tree of machine
 4808 //               instructions that matches a tree of machine-independent
 4809 //               instructions.
 4810 // format     -- A string providing the disassembly for this instruction.
 4811 //               The value of an instruction's operand may be inserted
 4812 //               by referring to it with a '$' prefix.
 4813 // opcode     -- Three instruction opcodes may be provided.  These are referred
 4814 //               to within an encode class as $primary, $secondary, and $tertiary
 4815 //               rrspectively.  The primary opcode is commonly used to
 4816 //               indicate the type of machine instruction, while secondary
 4817 //               and tertiary are often used for prefix options or addressing
 4818 //               modes.
 4819 // ins_encode -- A list of encode classes with parameters. The encode class
 4820 //               name must have been defined in an 'enc_class' specification
 4821 //               in the encode section of the architecture description.
 4822 
 4823 // Dummy reg-to-reg vector moves. Removed during post-selection cleanup.
 4824 // Load Float
 4825 instruct MoveF2VL(vlRegF dst, regF src) %{
 4826   match(Set dst src);
 4827   format %{ "movss $dst,$src\t! load float (4 bytes)" %}
 4828   ins_encode %{
 4829     ShouldNotReachHere();
 4830   %}
 4831   ins_pipe( fpu_reg_reg );
 4832 %}
 4833 
 4834 // Load Float
 4835 instruct MoveF2LEG(legRegF dst, regF src) %{
 4836   match(Set dst src);
 4837   format %{ "movss $dst,$src\t# if src != dst load float (4 bytes)" %}
 4838   ins_encode %{
 4839     ShouldNotReachHere();
 4840   %}
 4841   ins_pipe( fpu_reg_reg );
 4842 %}
 4843 
 4844 // Load Float
 4845 instruct MoveVL2F(regF dst, vlRegF src) %{
 4846   match(Set dst src);
 4847   format %{ "movss $dst,$src\t! load float (4 bytes)" %}
 4848   ins_encode %{
 4849     ShouldNotReachHere();
 4850   %}
 4851   ins_pipe( fpu_reg_reg );
 4852 %}
 4853 
 4854 // Load Float
 4855 instruct MoveLEG2F(regF dst, legRegF src) %{
 4856   match(Set dst src);
 4857   format %{ "movss $dst,$src\t# if src != dst load float (4 bytes)" %}
 4858   ins_encode %{
 4859     ShouldNotReachHere();
 4860   %}
 4861   ins_pipe( fpu_reg_reg );
 4862 %}
 4863 
 4864 // Load Double
 4865 instruct MoveD2VL(vlRegD dst, regD src) %{
 4866   match(Set dst src);
 4867   format %{ "movsd $dst,$src\t! load double (8 bytes)" %}
 4868   ins_encode %{
 4869     ShouldNotReachHere();
 4870   %}
 4871   ins_pipe( fpu_reg_reg );
 4872 %}
 4873 
 4874 // Load Double
 4875 instruct MoveD2LEG(legRegD dst, regD src) %{
 4876   match(Set dst src);
 4877   format %{ "movsd $dst,$src\t# if src != dst load double (8 bytes)" %}
 4878   ins_encode %{
 4879     ShouldNotReachHere();
 4880   %}
 4881   ins_pipe( fpu_reg_reg );
 4882 %}
 4883 
 4884 // Load Double
 4885 instruct MoveVL2D(regD dst, vlRegD src) %{
 4886   match(Set dst src);
 4887   format %{ "movsd $dst,$src\t! load double (8 bytes)" %}
 4888   ins_encode %{
 4889     ShouldNotReachHere();
 4890   %}
 4891   ins_pipe( fpu_reg_reg );
 4892 %}
 4893 
 4894 // Load Double
 4895 instruct MoveLEG2D(regD dst, legRegD src) %{
 4896   match(Set dst src);
 4897   format %{ "movsd $dst,$src\t# if src != dst load double (8 bytes)" %}
 4898   ins_encode %{
 4899     ShouldNotReachHere();
 4900   %}
 4901   ins_pipe( fpu_reg_reg );
 4902 %}
 4903 
 4904 //----------Load/Store/Move Instructions---------------------------------------
 4905 //----------Load Instructions--------------------------------------------------
 4906 
 4907 // Load Byte (8 bit signed)
 4908 instruct loadB(rRegI dst, memory mem)
 4909 %{
 4910   match(Set dst (LoadB mem));
 4911 
 4912   ins_cost(125);
 4913   format %{ "movsbl  $dst, $mem\t# byte" %}
 4914 
 4915   ins_encode %{
 4916     __ movsbl($dst$$Register, $mem$$Address);
 4917   %}
 4918 
 4919   ins_pipe(ialu_reg_mem);
 4920 %}
 4921 
 4922 // Load Byte (8 bit signed) into Long Register
 4923 instruct loadB2L(rRegL dst, memory mem)
 4924 %{
 4925   match(Set dst (ConvI2L (LoadB mem)));
 4926 
 4927   ins_cost(125);
 4928   format %{ "movsbq  $dst, $mem\t# byte -> long" %}
 4929 
 4930   ins_encode %{
 4931     __ movsbq($dst$$Register, $mem$$Address);
 4932   %}
 4933 
 4934   ins_pipe(ialu_reg_mem);
 4935 %}
 4936 
 4937 // Load Unsigned Byte (8 bit UNsigned)
 4938 instruct loadUB(rRegI dst, memory mem)
 4939 %{
 4940   match(Set dst (LoadUB mem));
 4941 
 4942   ins_cost(125);
 4943   format %{ "movzbl  $dst, $mem\t# ubyte" %}
 4944 
 4945   ins_encode %{
 4946     __ movzbl($dst$$Register, $mem$$Address);
 4947   %}
 4948 
 4949   ins_pipe(ialu_reg_mem);
 4950 %}
 4951 
 4952 // Load Unsigned Byte (8 bit UNsigned) into Long Register
 4953 instruct loadUB2L(rRegL dst, memory mem)
 4954 %{
 4955   match(Set dst (ConvI2L (LoadUB mem)));
 4956 
 4957   ins_cost(125);
 4958   format %{ "movzbq  $dst, $mem\t# ubyte -> long" %}
 4959 
 4960   ins_encode %{
 4961     __ movzbq($dst$$Register, $mem$$Address);
 4962   %}
 4963 
 4964   ins_pipe(ialu_reg_mem);
 4965 %}
 4966 
 4967 // Load Unsigned Byte (8 bit UNsigned) with 32-bit mask into Long Register
 4968 instruct loadUB2L_immI(rRegL dst, memory mem, immI mask, rFlagsReg cr) %{
 4969   match(Set dst (ConvI2L (AndI (LoadUB mem) mask)));
 4970   effect(KILL cr);
 4971 
 4972   format %{ "movzbq  $dst, $mem\t# ubyte & 32-bit mask -> long\n\t"
 4973             "andl    $dst, right_n_bits($mask, 8)" %}
 4974   ins_encode %{
 4975     Register Rdst = $dst$$Register;
 4976     __ movzbq(Rdst, $mem$$Address);
 4977     __ andl(Rdst, $mask$$constant & right_n_bits(8));
 4978   %}
 4979   ins_pipe(ialu_reg_mem);
 4980 %}
 4981 
 4982 // Load Short (16 bit signed)
 4983 instruct loadS(rRegI dst, memory mem)
 4984 %{
 4985   match(Set dst (LoadS mem));
 4986 
 4987   ins_cost(125);
 4988   format %{ "movswl $dst, $mem\t# short" %}
 4989 
 4990   ins_encode %{
 4991     __ movswl($dst$$Register, $mem$$Address);
 4992   %}
 4993 
 4994   ins_pipe(ialu_reg_mem);
 4995 %}
 4996 
 4997 // Load Short (16 bit signed) to Byte (8 bit signed)
 4998 instruct loadS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
 4999   match(Set dst (RShiftI (LShiftI (LoadS mem) twentyfour) twentyfour));
 5000 
 5001   ins_cost(125);
 5002   format %{ "movsbl $dst, $mem\t# short -> byte" %}
 5003   ins_encode %{
 5004     __ movsbl($dst$$Register, $mem$$Address);
 5005   %}
 5006   ins_pipe(ialu_reg_mem);
 5007 %}
 5008 
 5009 // Load Short (16 bit signed) into Long Register
 5010 instruct loadS2L(rRegL dst, memory mem)
 5011 %{
 5012   match(Set dst (ConvI2L (LoadS mem)));
 5013 
 5014   ins_cost(125);
 5015   format %{ "movswq $dst, $mem\t# short -> long" %}
 5016 
 5017   ins_encode %{
 5018     __ movswq($dst$$Register, $mem$$Address);
 5019   %}
 5020 
 5021   ins_pipe(ialu_reg_mem);
 5022 %}
 5023 
 5024 // Load Unsigned Short/Char (16 bit UNsigned)
 5025 instruct loadUS(rRegI dst, memory mem)
 5026 %{
 5027   match(Set dst (LoadUS mem));
 5028 
 5029   ins_cost(125);
 5030   format %{ "movzwl  $dst, $mem\t# ushort/char" %}
 5031 
 5032   ins_encode %{
 5033     __ movzwl($dst$$Register, $mem$$Address);
 5034   %}
 5035 
 5036   ins_pipe(ialu_reg_mem);
 5037 %}
 5038 
 5039 // Load Unsigned Short/Char (16 bit UNsigned) to Byte (8 bit signed)
 5040 instruct loadUS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
 5041   match(Set dst (RShiftI (LShiftI (LoadUS mem) twentyfour) twentyfour));
 5042 
 5043   ins_cost(125);
 5044   format %{ "movsbl $dst, $mem\t# ushort -> byte" %}
 5045   ins_encode %{
 5046     __ movsbl($dst$$Register, $mem$$Address);
 5047   %}
 5048   ins_pipe(ialu_reg_mem);
 5049 %}
 5050 
 5051 // Load Unsigned Short/Char (16 bit UNsigned) into Long Register
 5052 instruct loadUS2L(rRegL dst, memory mem)
 5053 %{
 5054   match(Set dst (ConvI2L (LoadUS mem)));
 5055 
 5056   ins_cost(125);
 5057   format %{ "movzwq  $dst, $mem\t# ushort/char -> long" %}
 5058 
 5059   ins_encode %{
 5060     __ movzwq($dst$$Register, $mem$$Address);
 5061   %}
 5062 
 5063   ins_pipe(ialu_reg_mem);
 5064 %}
 5065 
 5066 // Load Unsigned Short/Char (16 bit UNsigned) with mask 0xFF into Long Register
 5067 instruct loadUS2L_immI_255(rRegL dst, memory mem, immI_255 mask) %{
 5068   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
 5069 
 5070   format %{ "movzbq  $dst, $mem\t# ushort/char & 0xFF -> long" %}
 5071   ins_encode %{
 5072     __ movzbq($dst$$Register, $mem$$Address);
 5073   %}
 5074   ins_pipe(ialu_reg_mem);
 5075 %}
 5076 
 5077 // Load Unsigned Short/Char (16 bit UNsigned) with 32-bit mask into Long Register
 5078 instruct loadUS2L_immI(rRegL dst, memory mem, immI mask, rFlagsReg cr) %{
 5079   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
 5080   effect(KILL cr);
 5081 
 5082   format %{ "movzwq  $dst, $mem\t# ushort/char & 32-bit mask -> long\n\t"
 5083             "andl    $dst, right_n_bits($mask, 16)" %}
 5084   ins_encode %{
 5085     Register Rdst = $dst$$Register;
 5086     __ movzwq(Rdst, $mem$$Address);
 5087     __ andl(Rdst, $mask$$constant & right_n_bits(16));
 5088   %}
 5089   ins_pipe(ialu_reg_mem);
 5090 %}
 5091 
 5092 // Load Integer
 5093 instruct loadI(rRegI dst, memory mem)
 5094 %{
 5095   match(Set dst (LoadI mem));
 5096 
 5097   ins_cost(125);
 5098   format %{ "movl    $dst, $mem\t# int" %}
 5099 
 5100   ins_encode %{
 5101     __ movl($dst$$Register, $mem$$Address);
 5102   %}
 5103 
 5104   ins_pipe(ialu_reg_mem);
 5105 %}
 5106 
 5107 // Load Integer (32 bit signed) to Byte (8 bit signed)
 5108 instruct loadI2B(rRegI dst, memory mem, immI_24 twentyfour) %{
 5109   match(Set dst (RShiftI (LShiftI (LoadI mem) twentyfour) twentyfour));
 5110 
 5111   ins_cost(125);
 5112   format %{ "movsbl  $dst, $mem\t# int -> byte" %}
 5113   ins_encode %{
 5114     __ movsbl($dst$$Register, $mem$$Address);
 5115   %}
 5116   ins_pipe(ialu_reg_mem);
 5117 %}
 5118 
 5119 // Load Integer (32 bit signed) to Unsigned Byte (8 bit UNsigned)
 5120 instruct loadI2UB(rRegI dst, memory mem, immI_255 mask) %{
 5121   match(Set dst (AndI (LoadI mem) mask));
 5122 
 5123   ins_cost(125);
 5124   format %{ "movzbl  $dst, $mem\t# int -> ubyte" %}
 5125   ins_encode %{
 5126     __ movzbl($dst$$Register, $mem$$Address);
 5127   %}
 5128   ins_pipe(ialu_reg_mem);
 5129 %}
 5130 
 5131 // Load Integer (32 bit signed) to Short (16 bit signed)
 5132 instruct loadI2S(rRegI dst, memory mem, immI_16 sixteen) %{
 5133   match(Set dst (RShiftI (LShiftI (LoadI mem) sixteen) sixteen));
 5134 
 5135   ins_cost(125);
 5136   format %{ "movswl  $dst, $mem\t# int -> short" %}
 5137   ins_encode %{
 5138     __ movswl($dst$$Register, $mem$$Address);
 5139   %}
 5140   ins_pipe(ialu_reg_mem);
 5141 %}
 5142 
 5143 // Load Integer (32 bit signed) to Unsigned Short/Char (16 bit UNsigned)
 5144 instruct loadI2US(rRegI dst, memory mem, immI_65535 mask) %{
 5145   match(Set dst (AndI (LoadI mem) mask));
 5146 
 5147   ins_cost(125);
 5148   format %{ "movzwl  $dst, $mem\t# int -> ushort/char" %}
 5149   ins_encode %{
 5150     __ movzwl($dst$$Register, $mem$$Address);
 5151   %}
 5152   ins_pipe(ialu_reg_mem);
 5153 %}
 5154 
 5155 // Load Integer into Long Register
 5156 instruct loadI2L(rRegL dst, memory mem)
 5157 %{
 5158   match(Set dst (ConvI2L (LoadI mem)));
 5159 
 5160   ins_cost(125);
 5161   format %{ "movslq  $dst, $mem\t# int -> long" %}
 5162 
 5163   ins_encode %{
 5164     __ movslq($dst$$Register, $mem$$Address);
 5165   %}
 5166 
 5167   ins_pipe(ialu_reg_mem);
 5168 %}
 5169 
 5170 // Load Integer with mask 0xFF into Long Register
 5171 instruct loadI2L_immI_255(rRegL dst, memory mem, immI_255 mask) %{
 5172   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
 5173 
 5174   format %{ "movzbq  $dst, $mem\t# int & 0xFF -> long" %}
 5175   ins_encode %{
 5176     __ movzbq($dst$$Register, $mem$$Address);
 5177   %}
 5178   ins_pipe(ialu_reg_mem);
 5179 %}
 5180 
 5181 // Load Integer with mask 0xFFFF into Long Register
 5182 instruct loadI2L_immI_65535(rRegL dst, memory mem, immI_65535 mask) %{
 5183   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
 5184 
 5185   format %{ "movzwq  $dst, $mem\t# int & 0xFFFF -> long" %}
 5186   ins_encode %{
 5187     __ movzwq($dst$$Register, $mem$$Address);
 5188   %}
 5189   ins_pipe(ialu_reg_mem);
 5190 %}
 5191 
 5192 // Load Integer with a 31-bit mask into Long Register
 5193 instruct loadI2L_immU31(rRegL dst, memory mem, immU31 mask, rFlagsReg cr) %{
 5194   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
 5195   effect(KILL cr);
 5196 
 5197   format %{ "movl    $dst, $mem\t# int & 31-bit mask -> long\n\t"
 5198             "andl    $dst, $mask" %}
 5199   ins_encode %{
 5200     Register Rdst = $dst$$Register;
 5201     __ movl(Rdst, $mem$$Address);
 5202     __ andl(Rdst, $mask$$constant);
 5203   %}
 5204   ins_pipe(ialu_reg_mem);
 5205 %}
 5206 
 5207 // Load Unsigned Integer into Long Register
 5208 instruct loadUI2L(rRegL dst, memory mem, immL_32bits mask)
 5209 %{
 5210   match(Set dst (AndL (ConvI2L (LoadI mem)) mask));
 5211 
 5212   ins_cost(125);
 5213   format %{ "movl    $dst, $mem\t# uint -> long" %}
 5214 
 5215   ins_encode %{
 5216     __ movl($dst$$Register, $mem$$Address);
 5217   %}
 5218 
 5219   ins_pipe(ialu_reg_mem);
 5220 %}
 5221 
 5222 // Load Long
 5223 instruct loadL(rRegL dst, memory mem)
 5224 %{
 5225   match(Set dst (LoadL mem));
 5226 
 5227   ins_cost(125);
 5228   format %{ "movq    $dst, $mem\t# long" %}
 5229 
 5230   ins_encode %{
 5231     __ movq($dst$$Register, $mem$$Address);
 5232   %}
 5233 
 5234   ins_pipe(ialu_reg_mem); // XXX
 5235 %}
 5236 
 5237 // Load Range
 5238 instruct loadRange(rRegI dst, memory mem)
 5239 %{
 5240   match(Set dst (LoadRange mem));
 5241 
 5242   ins_cost(125); // XXX
 5243   format %{ "movl    $dst, $mem\t# range" %}
 5244   ins_encode %{
 5245     __ movl($dst$$Register, $mem$$Address);
 5246   %}
 5247   ins_pipe(ialu_reg_mem);
 5248 %}
 5249 
 5250 // Load Pointer
 5251 instruct loadP(rRegP dst, memory mem)
 5252 %{
 5253   match(Set dst (LoadP mem));
 5254   predicate(n->as_Load()->barrier_data() == 0);
 5255 
 5256   ins_cost(125); // XXX
 5257   format %{ "movq    $dst, $mem\t# ptr" %}
 5258   ins_encode %{
 5259     __ movq($dst$$Register, $mem$$Address);
 5260   %}
 5261   ins_pipe(ialu_reg_mem); // XXX
 5262 %}
 5263 
 5264 // Load Compressed Pointer
 5265 instruct loadN(rRegN dst, memory mem)
 5266 %{
 5267    match(Set dst (LoadN mem));
 5268 
 5269    ins_cost(125); // XXX
 5270    format %{ "movl    $dst, $mem\t# compressed ptr" %}
 5271    ins_encode %{
 5272      __ movl($dst$$Register, $mem$$Address);
 5273    %}
 5274    ins_pipe(ialu_reg_mem); // XXX
 5275 %}
 5276 
 5277 
 5278 // Load Klass Pointer
 5279 instruct loadKlass(rRegP dst, memory mem)
 5280 %{
 5281   match(Set dst (LoadKlass mem));
 5282 
 5283   ins_cost(125); // XXX
 5284   format %{ "movq    $dst, $mem\t# class" %}
 5285   ins_encode %{
 5286     __ movq($dst$$Register, $mem$$Address);
 5287   %}
 5288   ins_pipe(ialu_reg_mem); // XXX
 5289 %}
 5290 
 5291 // Load narrow Klass Pointer
 5292 instruct loadNKlass(rRegN dst, memory mem)
 5293 %{
 5294   match(Set dst (LoadNKlass mem));
 5295 
 5296   ins_cost(125); // XXX
 5297   format %{ "movl    $dst, $mem\t# compressed klass ptr" %}
 5298   ins_encode %{
 5299     __ movl($dst$$Register, $mem$$Address);
 5300   %}
 5301   ins_pipe(ialu_reg_mem); // XXX
 5302 %}
 5303 
 5304 // Load Float
 5305 instruct loadF(regF dst, memory mem)
 5306 %{
 5307   match(Set dst (LoadF mem));
 5308 
 5309   ins_cost(145); // XXX
 5310   format %{ "movss   $dst, $mem\t# float" %}
 5311   ins_encode %{
 5312     __ movflt($dst$$XMMRegister, $mem$$Address);
 5313   %}
 5314   ins_pipe(pipe_slow); // XXX
 5315 %}
 5316 
 5317 // Load Double
 5318 instruct loadD_partial(regD dst, memory mem)
 5319 %{
 5320   predicate(!UseXmmLoadAndClearUpper);
 5321   match(Set dst (LoadD mem));
 5322 
 5323   ins_cost(145); // XXX
 5324   format %{ "movlpd  $dst, $mem\t# double" %}
 5325   ins_encode %{
 5326     __ movdbl($dst$$XMMRegister, $mem$$Address);
 5327   %}
 5328   ins_pipe(pipe_slow); // XXX
 5329 %}
 5330 
 5331 instruct loadD(regD dst, memory mem)
 5332 %{
 5333   predicate(UseXmmLoadAndClearUpper);
 5334   match(Set dst (LoadD mem));
 5335 
 5336   ins_cost(145); // XXX
 5337   format %{ "movsd   $dst, $mem\t# double" %}
 5338   ins_encode %{
 5339     __ movdbl($dst$$XMMRegister, $mem$$Address);
 5340   %}
 5341   ins_pipe(pipe_slow); // XXX
 5342 %}
 5343 
 5344 
 5345 // Following pseudo code describes the algorithm for max[FD]:
 5346 // Min algorithm is on similar lines
 5347 //  btmp = (b < +0.0) ? a : b
 5348 //  atmp = (b < +0.0) ? b : a
 5349 //  Tmp  = Max_Float(atmp , btmp)
 5350 //  Res  = (atmp == NaN) ? atmp : Tmp
 5351 
 5352 // max = java.lang.Math.max(float a, float b)
 5353 instruct maxF_reg(legRegF dst, legRegF a, legRegF b, legRegF tmp, legRegF atmp, legRegF btmp) %{
 5354   predicate(UseAVX > 0 && !n->is_reduction());
 5355   match(Set dst (MaxF a b));
 5356   effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp);
 5357   format %{
 5358      "vblendvps        $btmp,$b,$a,$b           \n\t"
 5359      "vblendvps        $atmp,$a,$b,$b           \n\t"
 5360      "vmaxss           $tmp,$atmp,$btmp         \n\t"
 5361      "vcmpps.unordered $btmp,$atmp,$atmp        \n\t"
 5362      "vblendvps        $dst,$tmp,$atmp,$btmp    \n\t"
 5363   %}
 5364   ins_encode %{
 5365     int vector_len = Assembler::AVX_128bit;
 5366     __ vblendvps($btmp$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, vector_len);
 5367     __ vblendvps($atmp$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $b$$XMMRegister, vector_len);
 5368     __ vmaxss($tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister);
 5369     __ vcmpps($btmp$$XMMRegister, $atmp$$XMMRegister, $atmp$$XMMRegister, Assembler::_false, vector_len);
 5370     __ vblendvps($dst$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, vector_len);
 5371  %}
 5372   ins_pipe( pipe_slow );
 5373 %}
 5374 
 5375 instruct maxF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xmmt, rRegI tmp, rFlagsReg cr) %{
 5376   predicate(UseAVX > 0 && n->is_reduction());
 5377   match(Set dst (MaxF a b));
 5378   effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr);
 5379 
 5380   format %{ "$dst = max($a, $b)\t# intrinsic (float)" %}
 5381   ins_encode %{
 5382     emit_fp_min_max(_masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register,
 5383                     false /*min*/, true /*single*/);
 5384   %}
 5385   ins_pipe( pipe_slow );
 5386 %}
 5387 
 5388 // max = java.lang.Math.max(double a, double b)
 5389 instruct maxD_reg(legRegD dst, legRegD a, legRegD b, legRegD tmp, legRegD atmp, legRegD btmp) %{
 5390   predicate(UseAVX > 0 && !n->is_reduction());
 5391   match(Set dst (MaxD a b));
 5392   effect(USE a, USE b, TEMP atmp, TEMP btmp, TEMP tmp);
 5393   format %{
 5394      "vblendvpd        $btmp,$b,$a,$b            \n\t"
 5395      "vblendvpd        $atmp,$a,$b,$b            \n\t"
 5396      "vmaxsd           $tmp,$atmp,$btmp          \n\t"
 5397      "vcmppd.unordered $btmp,$atmp,$atmp         \n\t"
 5398      "vblendvpd        $dst,$tmp,$atmp,$btmp     \n\t"
 5399   %}
 5400   ins_encode %{
 5401     int vector_len = Assembler::AVX_128bit;
 5402     __ vblendvpd($btmp$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, vector_len);
 5403     __ vblendvpd($atmp$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $b$$XMMRegister, vector_len);
 5404     __ vmaxsd($tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister);
 5405     __ vcmppd($btmp$$XMMRegister, $atmp$$XMMRegister, $atmp$$XMMRegister, Assembler::_false, vector_len);
 5406     __ vblendvpd($dst$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, vector_len);
 5407   %}
 5408   ins_pipe( pipe_slow );
 5409 %}
 5410 
 5411 instruct maxD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xmmt, rRegL tmp, rFlagsReg cr) %{
 5412   predicate(UseAVX > 0 && n->is_reduction());
 5413   match(Set dst (MaxD a b));
 5414   effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr);
 5415 
 5416   format %{ "$dst = max($a, $b)\t# intrinsic (double)" %}
 5417   ins_encode %{
 5418     emit_fp_min_max(_masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register,
 5419                     false /*min*/, false /*single*/);
 5420   %}
 5421   ins_pipe( pipe_slow );
 5422 %}
 5423 
 5424 // min = java.lang.Math.min(float a, float b)
 5425 instruct minF_reg(legRegF dst, legRegF a, legRegF b, legRegF tmp, legRegF atmp, legRegF btmp) %{
 5426   predicate(UseAVX > 0 && !n->is_reduction());
 5427   match(Set dst (MinF a b));
 5428   effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp);
 5429   format %{
 5430      "vblendvps        $atmp,$a,$b,$a             \n\t"
 5431      "vblendvps        $btmp,$b,$a,$a             \n\t"
 5432      "vminss           $tmp,$atmp,$btmp           \n\t"
 5433      "vcmpps.unordered $btmp,$atmp,$atmp          \n\t"
 5434      "vblendvps        $dst,$tmp,$atmp,$btmp      \n\t"
 5435   %}
 5436   ins_encode %{
 5437     int vector_len = Assembler::AVX_128bit;
 5438     __ vblendvps($atmp$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, vector_len);
 5439     __ vblendvps($btmp$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, $a$$XMMRegister, vector_len);
 5440     __ vminss($tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister);
 5441     __ vcmpps($btmp$$XMMRegister, $atmp$$XMMRegister, $atmp$$XMMRegister, Assembler::_false, vector_len);
 5442     __ vblendvps($dst$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, vector_len);
 5443   %}
 5444   ins_pipe( pipe_slow );
 5445 %}
 5446 
 5447 instruct minF_reduction_reg(legRegF dst, legRegF a, legRegF b, legRegF xmmt, rRegI tmp, rFlagsReg cr) %{
 5448   predicate(UseAVX > 0 && n->is_reduction());
 5449   match(Set dst (MinF a b));
 5450   effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr);
 5451 
 5452   format %{ "$dst = min($a, $b)\t# intrinsic (float)" %}
 5453   ins_encode %{
 5454     emit_fp_min_max(_masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register,
 5455                     true /*min*/, true /*single*/);
 5456   %}
 5457   ins_pipe( pipe_slow );
 5458 %}
 5459 
 5460 // min = java.lang.Math.min(double a, double b)
 5461 instruct minD_reg(legRegD dst, legRegD a, legRegD b, legRegD tmp, legRegD atmp, legRegD btmp) %{
 5462   predicate(UseAVX > 0 && !n->is_reduction());
 5463   match(Set dst (MinD a b));
 5464   effect(USE a, USE b, TEMP tmp, TEMP atmp, TEMP btmp);
 5465   format %{
 5466      "vblendvpd        $atmp,$a,$b,$a           \n\t"
 5467      "vblendvpd        $btmp,$b,$a,$a           \n\t"
 5468      "vminsd           $tmp,$atmp,$btmp         \n\t"
 5469      "vcmppd.unordered $btmp,$atmp,$atmp        \n\t"
 5470      "vblendvpd        $dst,$tmp,$atmp,$btmp    \n\t"
 5471   %}
 5472   ins_encode %{
 5473     int vector_len = Assembler::AVX_128bit;
 5474     __ vblendvpd($atmp$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, vector_len);
 5475     __ vblendvpd($btmp$$XMMRegister, $b$$XMMRegister, $a$$XMMRegister, $a$$XMMRegister, vector_len);
 5476     __ vminsd($tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister);
 5477     __ vcmppd($btmp$$XMMRegister, $atmp$$XMMRegister, $atmp$$XMMRegister, Assembler::_false, vector_len);
 5478     __ vblendvpd($dst$$XMMRegister, $tmp$$XMMRegister, $atmp$$XMMRegister, $btmp$$XMMRegister, vector_len);
 5479   %}
 5480   ins_pipe( pipe_slow );
 5481 %}
 5482 
 5483 instruct minD_reduction_reg(legRegD dst, legRegD a, legRegD b, legRegD xmmt, rRegL tmp, rFlagsReg cr) %{
 5484   predicate(UseAVX > 0 && n->is_reduction());
 5485   match(Set dst (MinD a b));
 5486   effect(USE a, USE b, TEMP xmmt, TEMP tmp, KILL cr);
 5487 
 5488   format %{ "$dst = min($a, $b)\t# intrinsic (double)" %}
 5489   ins_encode %{
 5490     emit_fp_min_max(_masm, $dst$$XMMRegister, $a$$XMMRegister, $b$$XMMRegister, $xmmt$$XMMRegister, $tmp$$Register,
 5491                     true /*min*/, false /*single*/);
 5492   %}
 5493   ins_pipe( pipe_slow );
 5494 %}
 5495 
 5496 // Load Effective Address
 5497 instruct leaP8(rRegP dst, indOffset8 mem)
 5498 %{
 5499   match(Set dst mem);
 5500 
 5501   ins_cost(110); // XXX
 5502   format %{ "leaq    $dst, $mem\t# ptr 8" %}
 5503   ins_encode %{
 5504     __ leaq($dst$$Register, $mem$$Address);
 5505   %}
 5506   ins_pipe(ialu_reg_reg_fat);
 5507 %}
 5508 
 5509 instruct leaP32(rRegP dst, indOffset32 mem)
 5510 %{
 5511   match(Set dst mem);
 5512 
 5513   ins_cost(110);
 5514   format %{ "leaq    $dst, $mem\t# ptr 32" %}
 5515   ins_encode %{
 5516     __ leaq($dst$$Register, $mem$$Address);
 5517   %}
 5518   ins_pipe(ialu_reg_reg_fat);
 5519 %}
 5520 
 5521 instruct leaPIdxOff(rRegP dst, indIndexOffset mem)
 5522 %{
 5523   match(Set dst mem);
 5524 
 5525   ins_cost(110);
 5526   format %{ "leaq    $dst, $mem\t# ptr idxoff" %}
 5527   ins_encode %{
 5528     __ leaq($dst$$Register, $mem$$Address);
 5529   %}
 5530   ins_pipe(ialu_reg_reg_fat);
 5531 %}
 5532 
 5533 instruct leaPIdxScale(rRegP dst, indIndexScale mem)
 5534 %{
 5535   match(Set dst mem);
 5536 
 5537   ins_cost(110);
 5538   format %{ "leaq    $dst, $mem\t# ptr idxscale" %}
 5539   ins_encode %{
 5540     __ leaq($dst$$Register, $mem$$Address);
 5541   %}
 5542   ins_pipe(ialu_reg_reg_fat);
 5543 %}
 5544 
 5545 instruct leaPPosIdxScale(rRegP dst, indPosIndexScale mem)
 5546 %{
 5547   match(Set dst mem);
 5548 
 5549   ins_cost(110);
 5550   format %{ "leaq    $dst, $mem\t# ptr idxscale" %}
 5551   ins_encode %{
 5552     __ leaq($dst$$Register, $mem$$Address);
 5553   %}
 5554   ins_pipe(ialu_reg_reg_fat);
 5555 %}
 5556 
 5557 instruct leaPIdxScaleOff(rRegP dst, indIndexScaleOffset mem)
 5558 %{
 5559   match(Set dst mem);
 5560 
 5561   ins_cost(110);
 5562   format %{ "leaq    $dst, $mem\t# ptr idxscaleoff" %}
 5563   ins_encode %{
 5564     __ leaq($dst$$Register, $mem$$Address);
 5565   %}
 5566   ins_pipe(ialu_reg_reg_fat);
 5567 %}
 5568 
 5569 instruct leaPPosIdxOff(rRegP dst, indPosIndexOffset mem)
 5570 %{
 5571   match(Set dst mem);
 5572 
 5573   ins_cost(110);
 5574   format %{ "leaq    $dst, $mem\t# ptr posidxoff" %}
 5575   ins_encode %{
 5576     __ leaq($dst$$Register, $mem$$Address);
 5577   %}
 5578   ins_pipe(ialu_reg_reg_fat);
 5579 %}
 5580 
 5581 instruct leaPPosIdxScaleOff(rRegP dst, indPosIndexScaleOffset mem)
 5582 %{
 5583   match(Set dst mem);
 5584 
 5585   ins_cost(110);
 5586   format %{ "leaq    $dst, $mem\t# ptr posidxscaleoff" %}
 5587   ins_encode %{
 5588     __ leaq($dst$$Register, $mem$$Address);
 5589   %}
 5590   ins_pipe(ialu_reg_reg_fat);
 5591 %}
 5592 
 5593 // Load Effective Address which uses Narrow (32-bits) oop
 5594 instruct leaPCompressedOopOffset(rRegP dst, indCompressedOopOffset mem)
 5595 %{
 5596   predicate(UseCompressedOops && (CompressedOops::shift() != 0));
 5597   match(Set dst mem);
 5598 
 5599   ins_cost(110);
 5600   format %{ "leaq    $dst, $mem\t# ptr compressedoopoff32" %}
 5601   ins_encode %{
 5602     __ leaq($dst$$Register, $mem$$Address);
 5603   %}
 5604   ins_pipe(ialu_reg_reg_fat);
 5605 %}
 5606 
 5607 instruct leaP8Narrow(rRegP dst, indOffset8Narrow mem)
 5608 %{
 5609   predicate(CompressedOops::shift() == 0);
 5610   match(Set dst mem);
 5611 
 5612   ins_cost(110); // XXX
 5613   format %{ "leaq    $dst, $mem\t# ptr off8narrow" %}
 5614   ins_encode %{
 5615     __ leaq($dst$$Register, $mem$$Address);
 5616   %}
 5617   ins_pipe(ialu_reg_reg_fat);
 5618 %}
 5619 
 5620 instruct leaP32Narrow(rRegP dst, indOffset32Narrow mem)
 5621 %{
 5622   predicate(CompressedOops::shift() == 0);
 5623   match(Set dst mem);
 5624 
 5625   ins_cost(110);
 5626   format %{ "leaq    $dst, $mem\t# ptr off32narrow" %}
 5627   ins_encode %{
 5628     __ leaq($dst$$Register, $mem$$Address);
 5629   %}
 5630   ins_pipe(ialu_reg_reg_fat);
 5631 %}
 5632 
 5633 instruct leaPIdxOffNarrow(rRegP dst, indIndexOffsetNarrow mem)
 5634 %{
 5635   predicate(CompressedOops::shift() == 0);
 5636   match(Set dst mem);
 5637 
 5638   ins_cost(110);
 5639   format %{ "leaq    $dst, $mem\t# ptr idxoffnarrow" %}
 5640   ins_encode %{
 5641     __ leaq($dst$$Register, $mem$$Address);
 5642   %}
 5643   ins_pipe(ialu_reg_reg_fat);
 5644 %}
 5645 
 5646 instruct leaPIdxScaleNarrow(rRegP dst, indIndexScaleNarrow mem)
 5647 %{
 5648   predicate(CompressedOops::shift() == 0);
 5649   match(Set dst mem);
 5650 
 5651   ins_cost(110);
 5652   format %{ "leaq    $dst, $mem\t# ptr idxscalenarrow" %}
 5653   ins_encode %{
 5654     __ leaq($dst$$Register, $mem$$Address);
 5655   %}
 5656   ins_pipe(ialu_reg_reg_fat);
 5657 %}
 5658 
 5659 instruct leaPIdxScaleOffNarrow(rRegP dst, indIndexScaleOffsetNarrow mem)
 5660 %{
 5661   predicate(CompressedOops::shift() == 0);
 5662   match(Set dst mem);
 5663 
 5664   ins_cost(110);
 5665   format %{ "leaq    $dst, $mem\t# ptr idxscaleoffnarrow" %}
 5666   ins_encode %{
 5667     __ leaq($dst$$Register, $mem$$Address);
 5668   %}
 5669   ins_pipe(ialu_reg_reg_fat);
 5670 %}
 5671 
 5672 instruct leaPPosIdxOffNarrow(rRegP dst, indPosIndexOffsetNarrow mem)
 5673 %{
 5674   predicate(CompressedOops::shift() == 0);
 5675   match(Set dst mem);
 5676 
 5677   ins_cost(110);
 5678   format %{ "leaq    $dst, $mem\t# ptr posidxoffnarrow" %}
 5679   ins_encode %{
 5680     __ leaq($dst$$Register, $mem$$Address);
 5681   %}
 5682   ins_pipe(ialu_reg_reg_fat);
 5683 %}
 5684 
 5685 instruct leaPPosIdxScaleOffNarrow(rRegP dst, indPosIndexScaleOffsetNarrow mem)
 5686 %{
 5687   predicate(CompressedOops::shift() == 0);
 5688   match(Set dst mem);
 5689 
 5690   ins_cost(110);
 5691   format %{ "leaq    $dst, $mem\t# ptr posidxscaleoffnarrow" %}
 5692   ins_encode %{
 5693     __ leaq($dst$$Register, $mem$$Address);
 5694   %}
 5695   ins_pipe(ialu_reg_reg_fat);
 5696 %}
 5697 
 5698 instruct loadConI(rRegI dst, immI src)
 5699 %{
 5700   match(Set dst src);
 5701 
 5702   format %{ "movl    $dst, $src\t# int" %}
 5703   ins_encode %{
 5704     __ movl($dst$$Register, $src$$constant);
 5705   %}
 5706   ins_pipe(ialu_reg_fat); // XXX
 5707 %}
 5708 
 5709 instruct loadConI0(rRegI dst, immI_0 src, rFlagsReg cr)
 5710 %{
 5711   match(Set dst src);
 5712   effect(KILL cr);
 5713 
 5714   ins_cost(50);
 5715   format %{ "xorl    $dst, $dst\t# int" %}
 5716   ins_encode %{
 5717     __ xorl($dst$$Register, $dst$$Register);
 5718   %}
 5719   ins_pipe(ialu_reg);
 5720 %}
 5721 
 5722 instruct loadConL(rRegL dst, immL src)
 5723 %{
 5724   match(Set dst src);
 5725 
 5726   ins_cost(150);
 5727   format %{ "movq    $dst, $src\t# long" %}
 5728   ins_encode %{
 5729     __ mov64($dst$$Register, $src$$constant);
 5730   %}
 5731   ins_pipe(ialu_reg);
 5732 %}
 5733 
 5734 instruct loadConL0(rRegL dst, immL0 src, rFlagsReg cr)
 5735 %{
 5736   match(Set dst src);
 5737   effect(KILL cr);
 5738 
 5739   ins_cost(50);
 5740   format %{ "xorl    $dst, $dst\t# long" %}
 5741   ins_encode %{
 5742     __ xorl($dst$$Register, $dst$$Register);
 5743   %}
 5744   ins_pipe(ialu_reg); // XXX
 5745 %}
 5746 
 5747 instruct loadConUL32(rRegL dst, immUL32 src)
 5748 %{
 5749   match(Set dst src);
 5750 
 5751   ins_cost(60);
 5752   format %{ "movl    $dst, $src\t# long (unsigned 32-bit)" %}
 5753   ins_encode %{
 5754     __ movl($dst$$Register, $src$$constant);
 5755   %}
 5756   ins_pipe(ialu_reg);
 5757 %}
 5758 
 5759 instruct loadConL32(rRegL dst, immL32 src)
 5760 %{
 5761   match(Set dst src);
 5762 
 5763   ins_cost(70);
 5764   format %{ "movq    $dst, $src\t# long (32-bit)" %}
 5765   ins_encode %{
 5766     __ movq($dst$$Register, $src$$constant);
 5767   %}
 5768   ins_pipe(ialu_reg);
 5769 %}
 5770 
 5771 instruct loadConP(rRegP dst, immP con) %{
 5772   match(Set dst con);
 5773 
 5774   format %{ "movq    $dst, $con\t# ptr" %}
 5775   ins_encode %{
 5776     __ mov64($dst$$Register, $con$$constant, $con->constant_reloc(), RELOC_IMM64);
 5777   %}
 5778   ins_pipe(ialu_reg_fat); // XXX
 5779 %}
 5780 
 5781 instruct loadConP0(rRegP dst, immP0 src, rFlagsReg cr)
 5782 %{
 5783   match(Set dst src);
 5784   effect(KILL cr);
 5785 
 5786   ins_cost(50);
 5787   format %{ "xorl    $dst, $dst\t# ptr" %}
 5788   ins_encode %{
 5789     __ xorl($dst$$Register, $dst$$Register);
 5790   %}
 5791   ins_pipe(ialu_reg);
 5792 %}
 5793 
 5794 instruct loadConP31(rRegP dst, immP31 src, rFlagsReg cr)
 5795 %{
 5796   match(Set dst src);
 5797   effect(KILL cr);
 5798 
 5799   ins_cost(60);
 5800   format %{ "movl    $dst, $src\t# ptr (positive 32-bit)" %}
 5801   ins_encode %{
 5802     __ movl($dst$$Register, $src$$constant);
 5803   %}
 5804   ins_pipe(ialu_reg);
 5805 %}
 5806 
 5807 instruct loadConF(regF dst, immF con) %{
 5808   match(Set dst con);
 5809   ins_cost(125);
 5810   format %{ "movss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
 5811   ins_encode %{
 5812     __ movflt($dst$$XMMRegister, $constantaddress($con));
 5813   %}
 5814   ins_pipe(pipe_slow);
 5815 %}
 5816 
 5817 instruct loadConN0(rRegN dst, immN0 src, rFlagsReg cr) %{
 5818   match(Set dst src);
 5819   effect(KILL cr);
 5820   format %{ "xorq    $dst, $src\t# compressed NULL ptr" %}
 5821   ins_encode %{
 5822     __ xorq($dst$$Register, $dst$$Register);
 5823   %}
 5824   ins_pipe(ialu_reg);
 5825 %}
 5826 
 5827 instruct loadConN(rRegN dst, immN src) %{
 5828   match(Set dst src);
 5829 
 5830   ins_cost(125);
 5831   format %{ "movl    $dst, $src\t# compressed ptr" %}
 5832   ins_encode %{
 5833     address con = (address)$src$$constant;
 5834     if (con == NULL) {
 5835       ShouldNotReachHere();
 5836     } else {
 5837       __ set_narrow_oop($dst$$Register, (jobject)$src$$constant);
 5838     }
 5839   %}
 5840   ins_pipe(ialu_reg_fat); // XXX
 5841 %}
 5842 
 5843 instruct loadConNKlass(rRegN dst, immNKlass src) %{
 5844   match(Set dst src);
 5845 
 5846   ins_cost(125);
 5847   format %{ "movl    $dst, $src\t# compressed klass ptr" %}
 5848   ins_encode %{
 5849     address con = (address)$src$$constant;
 5850     if (con == NULL) {
 5851       ShouldNotReachHere();
 5852     } else {
 5853       __ set_narrow_klass($dst$$Register, (Klass*)$src$$constant);
 5854     }
 5855   %}
 5856   ins_pipe(ialu_reg_fat); // XXX
 5857 %}
 5858 
 5859 instruct loadConF0(regF dst, immF0 src)
 5860 %{
 5861   match(Set dst src);
 5862   ins_cost(100);
 5863 
 5864   format %{ "xorps   $dst, $dst\t# float 0.0" %}
 5865   ins_encode %{
 5866     __ xorps($dst$$XMMRegister, $dst$$XMMRegister);
 5867   %}
 5868   ins_pipe(pipe_slow);
 5869 %}
 5870 
 5871 // Use the same format since predicate() can not be used here.
 5872 instruct loadConD(regD dst, immD con) %{
 5873   match(Set dst con);
 5874   ins_cost(125);
 5875   format %{ "movsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
 5876   ins_encode %{
 5877     __ movdbl($dst$$XMMRegister, $constantaddress($con));
 5878   %}
 5879   ins_pipe(pipe_slow);
 5880 %}
 5881 
 5882 instruct loadConD0(regD dst, immD0 src)
 5883 %{
 5884   match(Set dst src);
 5885   ins_cost(100);
 5886 
 5887   format %{ "xorpd   $dst, $dst\t# double 0.0" %}
 5888   ins_encode %{
 5889     __ xorpd ($dst$$XMMRegister, $dst$$XMMRegister);
 5890   %}
 5891   ins_pipe(pipe_slow);
 5892 %}
 5893 
 5894 instruct loadSSI(rRegI dst, stackSlotI src)
 5895 %{
 5896   match(Set dst src);
 5897 
 5898   ins_cost(125);
 5899   format %{ "movl    $dst, $src\t# int stk" %}
 5900   opcode(0x8B);
 5901   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
 5902   ins_pipe(ialu_reg_mem);
 5903 %}
 5904 
 5905 instruct loadSSL(rRegL dst, stackSlotL src)
 5906 %{
 5907   match(Set dst src);
 5908 
 5909   ins_cost(125);
 5910   format %{ "movq    $dst, $src\t# long stk" %}
 5911   opcode(0x8B);
 5912   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
 5913   ins_pipe(ialu_reg_mem);
 5914 %}
 5915 
 5916 instruct loadSSP(rRegP dst, stackSlotP src)
 5917 %{
 5918   match(Set dst src);
 5919 
 5920   ins_cost(125);
 5921   format %{ "movq    $dst, $src\t# ptr stk" %}
 5922   opcode(0x8B);
 5923   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
 5924   ins_pipe(ialu_reg_mem);
 5925 %}
 5926 
 5927 instruct loadSSF(regF dst, stackSlotF src)
 5928 %{
 5929   match(Set dst src);
 5930 
 5931   ins_cost(125);
 5932   format %{ "movss   $dst, $src\t# float stk" %}
 5933   ins_encode %{
 5934     __ movflt($dst$$XMMRegister, Address(rsp, $src$$disp));
 5935   %}
 5936   ins_pipe(pipe_slow); // XXX
 5937 %}
 5938 
 5939 // Use the same format since predicate() can not be used here.
 5940 instruct loadSSD(regD dst, stackSlotD src)
 5941 %{
 5942   match(Set dst src);
 5943 
 5944   ins_cost(125);
 5945   format %{ "movsd   $dst, $src\t# double stk" %}
 5946   ins_encode  %{
 5947     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
 5948   %}
 5949   ins_pipe(pipe_slow); // XXX
 5950 %}
 5951 
 5952 // Prefetch instructions for allocation.
 5953 // Must be safe to execute with invalid address (cannot fault).
 5954 
 5955 instruct prefetchAlloc( memory mem ) %{
 5956   predicate(AllocatePrefetchInstr==3);
 5957   match(PrefetchAllocation mem);
 5958   ins_cost(125);
 5959 
 5960   format %{ "PREFETCHW $mem\t# Prefetch allocation into level 1 cache and mark modified" %}
 5961   ins_encode %{
 5962     __ prefetchw($mem$$Address);
 5963   %}
 5964   ins_pipe(ialu_mem);
 5965 %}
 5966 
 5967 instruct prefetchAllocNTA( memory mem ) %{
 5968   predicate(AllocatePrefetchInstr==0);
 5969   match(PrefetchAllocation mem);
 5970   ins_cost(125);
 5971 
 5972   format %{ "PREFETCHNTA $mem\t# Prefetch allocation to non-temporal cache for write" %}
 5973   ins_encode %{
 5974     __ prefetchnta($mem$$Address);
 5975   %}
 5976   ins_pipe(ialu_mem);
 5977 %}
 5978 
 5979 instruct prefetchAllocT0( memory mem ) %{
 5980   predicate(AllocatePrefetchInstr==1);
 5981   match(PrefetchAllocation mem);
 5982   ins_cost(125);
 5983 
 5984   format %{ "PREFETCHT0 $mem\t# Prefetch allocation to level 1 and 2 caches for write" %}
 5985   ins_encode %{
 5986     __ prefetcht0($mem$$Address);
 5987   %}
 5988   ins_pipe(ialu_mem);
 5989 %}
 5990 
 5991 instruct prefetchAllocT2( memory mem ) %{
 5992   predicate(AllocatePrefetchInstr==2);
 5993   match(PrefetchAllocation mem);
 5994   ins_cost(125);
 5995 
 5996   format %{ "PREFETCHT2 $mem\t# Prefetch allocation to level 2 cache for write" %}
 5997   ins_encode %{
 5998     __ prefetcht2($mem$$Address);
 5999   %}
 6000   ins_pipe(ialu_mem);
 6001 %}
 6002 
 6003 //----------Store Instructions-------------------------------------------------
 6004 
 6005 // Store Byte
 6006 instruct storeB(memory mem, rRegI src)
 6007 %{
 6008   match(Set mem (StoreB mem src));
 6009 
 6010   ins_cost(125); // XXX
 6011   format %{ "movb    $mem, $src\t# byte" %}
 6012   ins_encode %{
 6013     __ movb($mem$$Address, $src$$Register);
 6014   %}
 6015   ins_pipe(ialu_mem_reg);
 6016 %}
 6017 
 6018 // Store Char/Short
 6019 instruct storeC(memory mem, rRegI src)
 6020 %{
 6021   match(Set mem (StoreC mem src));
 6022 
 6023   ins_cost(125); // XXX
 6024   format %{ "movw    $mem, $src\t# char/short" %}
 6025   ins_encode %{
 6026     __ movw($mem$$Address, $src$$Register);
 6027   %}
 6028   ins_pipe(ialu_mem_reg);
 6029 %}
 6030 
 6031 // Store Integer
 6032 instruct storeI(memory mem, rRegI src)
 6033 %{
 6034   match(Set mem (StoreI mem src));
 6035 
 6036   ins_cost(125); // XXX
 6037   format %{ "movl    $mem, $src\t# int" %}
 6038   ins_encode %{
 6039     __ movl($mem$$Address, $src$$Register);
 6040   %}
 6041   ins_pipe(ialu_mem_reg);
 6042 %}
 6043 
 6044 // Store Long
 6045 instruct storeL(memory mem, rRegL src)
 6046 %{
 6047   match(Set mem (StoreL mem src));
 6048 
 6049   ins_cost(125); // XXX
 6050   format %{ "movq    $mem, $src\t# long" %}
 6051   ins_encode %{
 6052     __ movq($mem$$Address, $src$$Register);
 6053   %}
 6054   ins_pipe(ialu_mem_reg); // XXX
 6055 %}
 6056 
 6057 // Store Pointer
 6058 instruct storeP(memory mem, any_RegP src)
 6059 %{
 6060   match(Set mem (StoreP mem src));
 6061 
 6062   ins_cost(125); // XXX
 6063   format %{ "movq    $mem, $src\t# ptr" %}
 6064   ins_encode %{
 6065     __ movq($mem$$Address, $src$$Register);
 6066   %}
 6067   ins_pipe(ialu_mem_reg);
 6068 %}
 6069 
 6070 instruct storeImmP0(memory mem, immP0 zero)
 6071 %{
 6072   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6073   match(Set mem (StoreP mem zero));
 6074 
 6075   ins_cost(125); // XXX
 6076   format %{ "movq    $mem, R12\t# ptr (R12_heapbase==0)" %}
 6077   ins_encode %{
 6078     __ movq($mem$$Address, r12);
 6079   %}
 6080   ins_pipe(ialu_mem_reg);
 6081 %}
 6082 
 6083 // Store NULL Pointer, mark word, or other simple pointer constant.
 6084 instruct storeImmP(memory mem, immP31 src)
 6085 %{
 6086   match(Set mem (StoreP mem src));
 6087 
 6088   ins_cost(150); // XXX
 6089   format %{ "movq    $mem, $src\t# ptr" %}
 6090   ins_encode %{
 6091     __ movq($mem$$Address, $src$$constant);
 6092   %}
 6093   ins_pipe(ialu_mem_imm);
 6094 %}
 6095 
 6096 // Store Compressed Pointer
 6097 instruct storeN(memory mem, rRegN src)
 6098 %{
 6099   match(Set mem (StoreN mem src));
 6100 
 6101   ins_cost(125); // XXX
 6102   format %{ "movl    $mem, $src\t# compressed ptr" %}
 6103   ins_encode %{
 6104     __ movl($mem$$Address, $src$$Register);
 6105   %}
 6106   ins_pipe(ialu_mem_reg);
 6107 %}
 6108 
 6109 instruct storeNKlass(memory mem, rRegN src)
 6110 %{
 6111   match(Set mem (StoreNKlass mem src));
 6112 
 6113   ins_cost(125); // XXX
 6114   format %{ "movl    $mem, $src\t# compressed klass ptr" %}
 6115   ins_encode %{
 6116     __ movl($mem$$Address, $src$$Register);
 6117   %}
 6118   ins_pipe(ialu_mem_reg);
 6119 %}
 6120 
 6121 instruct storeImmN0(memory mem, immN0 zero)
 6122 %{
 6123   predicate(CompressedOops::base() == NULL);
 6124   match(Set mem (StoreN mem zero));
 6125 
 6126   ins_cost(125); // XXX
 6127   format %{ "movl    $mem, R12\t# compressed ptr (R12_heapbase==0)" %}
 6128   ins_encode %{
 6129     __ movl($mem$$Address, r12);
 6130   %}
 6131   ins_pipe(ialu_mem_reg);
 6132 %}
 6133 
 6134 instruct storeImmN(memory mem, immN src)
 6135 %{
 6136   match(Set mem (StoreN mem src));
 6137 
 6138   ins_cost(150); // XXX
 6139   format %{ "movl    $mem, $src\t# compressed ptr" %}
 6140   ins_encode %{
 6141     address con = (address)$src$$constant;
 6142     if (con == NULL) {
 6143       __ movl($mem$$Address, (int32_t)0);
 6144     } else {
 6145       __ set_narrow_oop($mem$$Address, (jobject)$src$$constant);
 6146     }
 6147   %}
 6148   ins_pipe(ialu_mem_imm);
 6149 %}
 6150 
 6151 instruct storeImmNKlass(memory mem, immNKlass src)
 6152 %{
 6153   match(Set mem (StoreNKlass mem src));
 6154 
 6155   ins_cost(150); // XXX
 6156   format %{ "movl    $mem, $src\t# compressed klass ptr" %}
 6157   ins_encode %{
 6158     __ set_narrow_klass($mem$$Address, (Klass*)$src$$constant);
 6159   %}
 6160   ins_pipe(ialu_mem_imm);
 6161 %}
 6162 
 6163 // Store Integer Immediate
 6164 instruct storeImmI0(memory mem, immI_0 zero)
 6165 %{
 6166   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6167   match(Set mem (StoreI mem zero));
 6168 
 6169   ins_cost(125); // XXX
 6170   format %{ "movl    $mem, R12\t# int (R12_heapbase==0)" %}
 6171   ins_encode %{
 6172     __ movl($mem$$Address, r12);
 6173   %}
 6174   ins_pipe(ialu_mem_reg);
 6175 %}
 6176 
 6177 instruct storeImmI(memory mem, immI src)
 6178 %{
 6179   match(Set mem (StoreI mem src));
 6180 
 6181   ins_cost(150);
 6182   format %{ "movl    $mem, $src\t# int" %}
 6183   ins_encode %{
 6184     __ movl($mem$$Address, $src$$constant);
 6185   %}
 6186   ins_pipe(ialu_mem_imm);
 6187 %}
 6188 
 6189 // Store Long Immediate
 6190 instruct storeImmL0(memory mem, immL0 zero)
 6191 %{
 6192   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6193   match(Set mem (StoreL mem zero));
 6194 
 6195   ins_cost(125); // XXX
 6196   format %{ "movq    $mem, R12\t# long (R12_heapbase==0)" %}
 6197   ins_encode %{
 6198     __ movq($mem$$Address, r12);
 6199   %}
 6200   ins_pipe(ialu_mem_reg);
 6201 %}
 6202 
 6203 instruct storeImmL(memory mem, immL32 src)
 6204 %{
 6205   match(Set mem (StoreL mem src));
 6206 
 6207   ins_cost(150);
 6208   format %{ "movq    $mem, $src\t# long" %}
 6209   ins_encode %{
 6210     __ movq($mem$$Address, $src$$constant);
 6211   %}
 6212   ins_pipe(ialu_mem_imm);
 6213 %}
 6214 
 6215 // Store Short/Char Immediate
 6216 instruct storeImmC0(memory mem, immI_0 zero)
 6217 %{
 6218   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6219   match(Set mem (StoreC mem zero));
 6220 
 6221   ins_cost(125); // XXX
 6222   format %{ "movw    $mem, R12\t# short/char (R12_heapbase==0)" %}
 6223   ins_encode %{
 6224     __ movw($mem$$Address, r12);
 6225   %}
 6226   ins_pipe(ialu_mem_reg);
 6227 %}
 6228 
 6229 instruct storeImmI16(memory mem, immI16 src)
 6230 %{
 6231   predicate(UseStoreImmI16);
 6232   match(Set mem (StoreC mem src));
 6233 
 6234   ins_cost(150);
 6235   format %{ "movw    $mem, $src\t# short/char" %}
 6236   ins_encode %{
 6237     __ movw($mem$$Address, $src$$constant);
 6238   %}
 6239   ins_pipe(ialu_mem_imm);
 6240 %}
 6241 
 6242 // Store Byte Immediate
 6243 instruct storeImmB0(memory mem, immI_0 zero)
 6244 %{
 6245   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6246   match(Set mem (StoreB mem zero));
 6247 
 6248   ins_cost(125); // XXX
 6249   format %{ "movb    $mem, R12\t# short/char (R12_heapbase==0)" %}
 6250   ins_encode %{
 6251     __ movb($mem$$Address, r12);
 6252   %}
 6253   ins_pipe(ialu_mem_reg);
 6254 %}
 6255 
 6256 instruct storeImmB(memory mem, immI8 src)
 6257 %{
 6258   match(Set mem (StoreB mem src));
 6259 
 6260   ins_cost(150); // XXX
 6261   format %{ "movb    $mem, $src\t# byte" %}
 6262   ins_encode %{
 6263     __ movb($mem$$Address, $src$$constant);
 6264   %}
 6265   ins_pipe(ialu_mem_imm);
 6266 %}
 6267 
 6268 // Store CMS card-mark Immediate
 6269 instruct storeImmCM0_reg(memory mem, immI_0 zero)
 6270 %{
 6271   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6272   match(Set mem (StoreCM mem zero));
 6273 
 6274   ins_cost(125); // XXX
 6275   format %{ "movb    $mem, R12\t# CMS card-mark byte 0 (R12_heapbase==0)" %}
 6276   ins_encode %{
 6277     __ movb($mem$$Address, r12);
 6278   %}
 6279   ins_pipe(ialu_mem_reg);
 6280 %}
 6281 
 6282 instruct storeImmCM0(memory mem, immI_0 src)
 6283 %{
 6284   match(Set mem (StoreCM mem src));
 6285 
 6286   ins_cost(150); // XXX
 6287   format %{ "movb    $mem, $src\t# CMS card-mark byte 0" %}
 6288   ins_encode %{
 6289     __ movb($mem$$Address, $src$$constant);
 6290   %}
 6291   ins_pipe(ialu_mem_imm);
 6292 %}
 6293 
 6294 // Store Float
 6295 instruct storeF(memory mem, regF src)
 6296 %{
 6297   match(Set mem (StoreF mem src));
 6298 
 6299   ins_cost(95); // XXX
 6300   format %{ "movss   $mem, $src\t# float" %}
 6301   ins_encode %{
 6302     __ movflt($mem$$Address, $src$$XMMRegister);
 6303   %}
 6304   ins_pipe(pipe_slow); // XXX
 6305 %}
 6306 
 6307 // Store immediate Float value (it is faster than store from XMM register)
 6308 instruct storeF0(memory mem, immF0 zero)
 6309 %{
 6310   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6311   match(Set mem (StoreF mem zero));
 6312 
 6313   ins_cost(25); // XXX
 6314   format %{ "movl    $mem, R12\t# float 0. (R12_heapbase==0)" %}
 6315   ins_encode %{
 6316     __ movl($mem$$Address, r12);
 6317   %}
 6318   ins_pipe(ialu_mem_reg);
 6319 %}
 6320 
 6321 instruct storeF_imm(memory mem, immF src)
 6322 %{
 6323   match(Set mem (StoreF mem src));
 6324 
 6325   ins_cost(50);
 6326   format %{ "movl    $mem, $src\t# float" %}
 6327   ins_encode %{
 6328     __ movl($mem$$Address, jint_cast($src$$constant));
 6329   %}
 6330   ins_pipe(ialu_mem_imm);
 6331 %}
 6332 
 6333 // Store Double
 6334 instruct storeD(memory mem, regD src)
 6335 %{
 6336   match(Set mem (StoreD mem src));
 6337 
 6338   ins_cost(95); // XXX
 6339   format %{ "movsd   $mem, $src\t# double" %}
 6340   ins_encode %{
 6341     __ movdbl($mem$$Address, $src$$XMMRegister);
 6342   %}
 6343   ins_pipe(pipe_slow); // XXX
 6344 %}
 6345 
 6346 // Store immediate double 0.0 (it is faster than store from XMM register)
 6347 instruct storeD0_imm(memory mem, immD0 src)
 6348 %{
 6349   predicate(!UseCompressedOops || (CompressedOops::base() != NULL));
 6350   match(Set mem (StoreD mem src));
 6351 
 6352   ins_cost(50);
 6353   format %{ "movq    $mem, $src\t# double 0." %}
 6354   ins_encode %{
 6355     __ movq($mem$$Address, $src$$constant);
 6356   %}
 6357   ins_pipe(ialu_mem_imm);
 6358 %}
 6359 
 6360 instruct storeD0(memory mem, immD0 zero)
 6361 %{
 6362   predicate(UseCompressedOops && (CompressedOops::base() == NULL));
 6363   match(Set mem (StoreD mem zero));
 6364 
 6365   ins_cost(25); // XXX
 6366   format %{ "movq    $mem, R12\t# double 0. (R12_heapbase==0)" %}
 6367   ins_encode %{
 6368     __ movq($mem$$Address, r12);
 6369   %}
 6370   ins_pipe(ialu_mem_reg);
 6371 %}
 6372 
 6373 instruct storeSSI(stackSlotI dst, rRegI src)
 6374 %{
 6375   match(Set dst src);
 6376 
 6377   ins_cost(100);
 6378   format %{ "movl    $dst, $src\t# int stk" %}
 6379   opcode(0x89);
 6380   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
 6381   ins_pipe( ialu_mem_reg );
 6382 %}
 6383 
 6384 instruct storeSSL(stackSlotL dst, rRegL src)
 6385 %{
 6386   match(Set dst src);
 6387 
 6388   ins_cost(100);
 6389   format %{ "movq    $dst, $src\t# long stk" %}
 6390   opcode(0x89);
 6391   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
 6392   ins_pipe(ialu_mem_reg);
 6393 %}
 6394 
 6395 instruct storeSSP(stackSlotP dst, rRegP src)
 6396 %{
 6397   match(Set dst src);
 6398 
 6399   ins_cost(100);
 6400   format %{ "movq    $dst, $src\t# ptr stk" %}
 6401   opcode(0x89);
 6402   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
 6403   ins_pipe(ialu_mem_reg);
 6404 %}
 6405 
 6406 instruct storeSSF(stackSlotF dst, regF src)
 6407 %{
 6408   match(Set dst src);
 6409 
 6410   ins_cost(95); // XXX
 6411   format %{ "movss   $dst, $src\t# float stk" %}
 6412   ins_encode %{
 6413     __ movflt(Address(rsp, $dst$$disp), $src$$XMMRegister);
 6414   %}
 6415   ins_pipe(pipe_slow); // XXX
 6416 %}
 6417 
 6418 instruct storeSSD(stackSlotD dst, regD src)
 6419 %{
 6420   match(Set dst src);
 6421 
 6422   ins_cost(95); // XXX
 6423   format %{ "movsd   $dst, $src\t# double stk" %}
 6424   ins_encode %{
 6425     __ movdbl(Address(rsp, $dst$$disp), $src$$XMMRegister);
 6426   %}
 6427   ins_pipe(pipe_slow); // XXX
 6428 %}
 6429 
 6430 instruct cacheWB(indirect addr)
 6431 %{
 6432   predicate(VM_Version::supports_data_cache_line_flush());
 6433   match(CacheWB addr);
 6434 
 6435   ins_cost(100);
 6436   format %{"cache wb $addr" %}
 6437   ins_encode %{
 6438     assert($addr->index_position() < 0, "should be");
 6439     assert($addr$$disp == 0, "should be");
 6440     __ cache_wb(Address($addr$$base$$Register, 0));
 6441   %}
 6442   ins_pipe(pipe_slow); // XXX
 6443 %}
 6444 
 6445 instruct cacheWBPreSync()
 6446 %{
 6447   predicate(VM_Version::supports_data_cache_line_flush());
 6448   match(CacheWBPreSync);
 6449 
 6450   ins_cost(100);
 6451   format %{"cache wb presync" %}
 6452   ins_encode %{
 6453     __ cache_wbsync(true);
 6454   %}
 6455   ins_pipe(pipe_slow); // XXX
 6456 %}
 6457 
 6458 instruct cacheWBPostSync()
 6459 %{
 6460   predicate(VM_Version::supports_data_cache_line_flush());
 6461   match(CacheWBPostSync);
 6462 
 6463   ins_cost(100);
 6464   format %{"cache wb postsync" %}
 6465   ins_encode %{
 6466     __ cache_wbsync(false);
 6467   %}
 6468   ins_pipe(pipe_slow); // XXX
 6469 %}
 6470 
 6471 //----------BSWAP Instructions-------------------------------------------------
 6472 instruct bytes_reverse_int(rRegI dst) %{
 6473   match(Set dst (ReverseBytesI dst));
 6474 
 6475   format %{ "bswapl  $dst" %}
 6476   ins_encode %{
 6477     __ bswapl($dst$$Register);
 6478   %}
 6479   ins_pipe( ialu_reg );
 6480 %}
 6481 
 6482 instruct bytes_reverse_long(rRegL dst) %{
 6483   match(Set dst (ReverseBytesL dst));
 6484 
 6485   format %{ "bswapq  $dst" %}
 6486   ins_encode %{
 6487     __ bswapq($dst$$Register);
 6488   %}
 6489   ins_pipe( ialu_reg);
 6490 %}
 6491 
 6492 instruct bytes_reverse_unsigned_short(rRegI dst, rFlagsReg cr) %{
 6493   match(Set dst (ReverseBytesUS dst));
 6494   effect(KILL cr);
 6495 
 6496   format %{ "bswapl  $dst\n\t"
 6497             "shrl    $dst,16\n\t" %}
 6498   ins_encode %{
 6499     __ bswapl($dst$$Register);
 6500     __ shrl($dst$$Register, 16);
 6501   %}
 6502   ins_pipe( ialu_reg );
 6503 %}
 6504 
 6505 instruct bytes_reverse_short(rRegI dst, rFlagsReg cr) %{
 6506   match(Set dst (ReverseBytesS dst));
 6507   effect(KILL cr);
 6508 
 6509   format %{ "bswapl  $dst\n\t"
 6510             "sar     $dst,16\n\t" %}
 6511   ins_encode %{
 6512     __ bswapl($dst$$Register);
 6513     __ sarl($dst$$Register, 16);
 6514   %}
 6515   ins_pipe( ialu_reg );
 6516 %}
 6517 
 6518 //---------- Zeros Count Instructions ------------------------------------------
 6519 
 6520 instruct countLeadingZerosI(rRegI dst, rRegI src, rFlagsReg cr) %{
 6521   predicate(UseCountLeadingZerosInstruction);
 6522   match(Set dst (CountLeadingZerosI src));
 6523   effect(KILL cr);
 6524 
 6525   format %{ "lzcntl  $dst, $src\t# count leading zeros (int)" %}
 6526   ins_encode %{
 6527     __ lzcntl($dst$$Register, $src$$Register);
 6528   %}
 6529   ins_pipe(ialu_reg);
 6530 %}
 6531 
 6532 instruct countLeadingZerosI_bsr(rRegI dst, rRegI src, rFlagsReg cr) %{
 6533   predicate(!UseCountLeadingZerosInstruction);
 6534   match(Set dst (CountLeadingZerosI src));
 6535   effect(KILL cr);
 6536 
 6537   format %{ "bsrl    $dst, $src\t# count leading zeros (int)\n\t"
 6538             "jnz     skip\n\t"
 6539             "movl    $dst, -1\n"
 6540       "skip:\n\t"
 6541             "negl    $dst\n\t"
 6542             "addl    $dst, 31" %}
 6543   ins_encode %{
 6544     Register Rdst = $dst$$Register;
 6545     Register Rsrc = $src$$Register;
 6546     Label skip;
 6547     __ bsrl(Rdst, Rsrc);
 6548     __ jccb(Assembler::notZero, skip);
 6549     __ movl(Rdst, -1);
 6550     __ bind(skip);
 6551     __ negl(Rdst);
 6552     __ addl(Rdst, BitsPerInt - 1);
 6553   %}
 6554   ins_pipe(ialu_reg);
 6555 %}
 6556 
 6557 instruct countLeadingZerosL(rRegI dst, rRegL src, rFlagsReg cr) %{
 6558   predicate(UseCountLeadingZerosInstruction);
 6559   match(Set dst (CountLeadingZerosL src));
 6560   effect(KILL cr);
 6561 
 6562   format %{ "lzcntq  $dst, $src\t# count leading zeros (long)" %}
 6563   ins_encode %{
 6564     __ lzcntq($dst$$Register, $src$$Register);
 6565   %}
 6566   ins_pipe(ialu_reg);
 6567 %}
 6568 
 6569 instruct countLeadingZerosL_bsr(rRegI dst, rRegL src, rFlagsReg cr) %{
 6570   predicate(!UseCountLeadingZerosInstruction);
 6571   match(Set dst (CountLeadingZerosL src));
 6572   effect(KILL cr);
 6573 
 6574   format %{ "bsrq    $dst, $src\t# count leading zeros (long)\n\t"
 6575             "jnz     skip\n\t"
 6576             "movl    $dst, -1\n"
 6577       "skip:\n\t"
 6578             "negl    $dst\n\t"
 6579             "addl    $dst, 63" %}
 6580   ins_encode %{
 6581     Register Rdst = $dst$$Register;
 6582     Register Rsrc = $src$$Register;
 6583     Label skip;
 6584     __ bsrq(Rdst, Rsrc);
 6585     __ jccb(Assembler::notZero, skip);
 6586     __ movl(Rdst, -1);
 6587     __ bind(skip);
 6588     __ negl(Rdst);
 6589     __ addl(Rdst, BitsPerLong - 1);
 6590   %}
 6591   ins_pipe(ialu_reg);
 6592 %}
 6593 
 6594 instruct countTrailingZerosI(rRegI dst, rRegI src, rFlagsReg cr) %{
 6595   predicate(UseCountTrailingZerosInstruction);
 6596   match(Set dst (CountTrailingZerosI src));
 6597   effect(KILL cr);
 6598 
 6599   format %{ "tzcntl    $dst, $src\t# count trailing zeros (int)" %}
 6600   ins_encode %{
 6601     __ tzcntl($dst$$Register, $src$$Register);
 6602   %}
 6603   ins_pipe(ialu_reg);
 6604 %}
 6605 
 6606 instruct countTrailingZerosI_bsf(rRegI dst, rRegI src, rFlagsReg cr) %{
 6607   predicate(!UseCountTrailingZerosInstruction);
 6608   match(Set dst (CountTrailingZerosI src));
 6609   effect(KILL cr);
 6610 
 6611   format %{ "bsfl    $dst, $src\t# count trailing zeros (int)\n\t"
 6612             "jnz     done\n\t"
 6613             "movl    $dst, 32\n"
 6614       "done:" %}
 6615   ins_encode %{
 6616     Register Rdst = $dst$$Register;
 6617     Label done;
 6618     __ bsfl(Rdst, $src$$Register);
 6619     __ jccb(Assembler::notZero, done);
 6620     __ movl(Rdst, BitsPerInt);
 6621     __ bind(done);
 6622   %}
 6623   ins_pipe(ialu_reg);
 6624 %}
 6625 
 6626 instruct countTrailingZerosL(rRegI dst, rRegL src, rFlagsReg cr) %{
 6627   predicate(UseCountTrailingZerosInstruction);
 6628   match(Set dst (CountTrailingZerosL src));
 6629   effect(KILL cr);
 6630 
 6631   format %{ "tzcntq    $dst, $src\t# count trailing zeros (long)" %}
 6632   ins_encode %{
 6633     __ tzcntq($dst$$Register, $src$$Register);
 6634   %}
 6635   ins_pipe(ialu_reg);
 6636 %}
 6637 
 6638 instruct countTrailingZerosL_bsf(rRegI dst, rRegL src, rFlagsReg cr) %{
 6639   predicate(!UseCountTrailingZerosInstruction);
 6640   match(Set dst (CountTrailingZerosL src));
 6641   effect(KILL cr);
 6642 
 6643   format %{ "bsfq    $dst, $src\t# count trailing zeros (long)\n\t"
 6644             "jnz     done\n\t"
 6645             "movl    $dst, 64\n"
 6646       "done:" %}
 6647   ins_encode %{
 6648     Register Rdst = $dst$$Register;
 6649     Label done;
 6650     __ bsfq(Rdst, $src$$Register);
 6651     __ jccb(Assembler::notZero, done);
 6652     __ movl(Rdst, BitsPerLong);
 6653     __ bind(done);
 6654   %}
 6655   ins_pipe(ialu_reg);
 6656 %}
 6657 
 6658 
 6659 //---------- Population Count Instructions -------------------------------------
 6660 
 6661 instruct popCountI(rRegI dst, rRegI src, rFlagsReg cr) %{
 6662   predicate(UsePopCountInstruction);
 6663   match(Set dst (PopCountI src));
 6664   effect(KILL cr);
 6665 
 6666   format %{ "popcnt  $dst, $src" %}
 6667   ins_encode %{
 6668     __ popcntl($dst$$Register, $src$$Register);
 6669   %}
 6670   ins_pipe(ialu_reg);
 6671 %}
 6672 
 6673 instruct popCountI_mem(rRegI dst, memory mem, rFlagsReg cr) %{
 6674   predicate(UsePopCountInstruction);
 6675   match(Set dst (PopCountI (LoadI mem)));
 6676   effect(KILL cr);
 6677 
 6678   format %{ "popcnt  $dst, $mem" %}
 6679   ins_encode %{
 6680     __ popcntl($dst$$Register, $mem$$Address);
 6681   %}
 6682   ins_pipe(ialu_reg);
 6683 %}
 6684 
 6685 // Note: Long.bitCount(long) returns an int.
 6686 instruct popCountL(rRegI dst, rRegL src, rFlagsReg cr) %{
 6687   predicate(UsePopCountInstruction);
 6688   match(Set dst (PopCountL src));
 6689   effect(KILL cr);
 6690 
 6691   format %{ "popcnt  $dst, $src" %}
 6692   ins_encode %{
 6693     __ popcntq($dst$$Register, $src$$Register);
 6694   %}
 6695   ins_pipe(ialu_reg);
 6696 %}
 6697 
 6698 // Note: Long.bitCount(long) returns an int.
 6699 instruct popCountL_mem(rRegI dst, memory mem, rFlagsReg cr) %{
 6700   predicate(UsePopCountInstruction);
 6701   match(Set dst (PopCountL (LoadL mem)));
 6702   effect(KILL cr);
 6703 
 6704   format %{ "popcnt  $dst, $mem" %}
 6705   ins_encode %{
 6706     __ popcntq($dst$$Register, $mem$$Address);
 6707   %}
 6708   ins_pipe(ialu_reg);
 6709 %}
 6710 
 6711 
 6712 //----------MemBar Instructions-----------------------------------------------
 6713 // Memory barrier flavors
 6714 
 6715 instruct membar_acquire()
 6716 %{
 6717   match(MemBarAcquire);
 6718   match(LoadFence);
 6719   ins_cost(0);
 6720 
 6721   size(0);
 6722   format %{ "MEMBAR-acquire ! (empty encoding)" %}
 6723   ins_encode();
 6724   ins_pipe(empty);
 6725 %}
 6726 
 6727 instruct membar_acquire_lock()
 6728 %{
 6729   match(MemBarAcquireLock);
 6730   ins_cost(0);
 6731 
 6732   size(0);
 6733   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
 6734   ins_encode();
 6735   ins_pipe(empty);
 6736 %}
 6737 
 6738 instruct membar_release()
 6739 %{
 6740   match(MemBarRelease);
 6741   match(StoreFence);
 6742   ins_cost(0);
 6743 
 6744   size(0);
 6745   format %{ "MEMBAR-release ! (empty encoding)" %}
 6746   ins_encode();
 6747   ins_pipe(empty);
 6748 %}
 6749 
 6750 instruct membar_release_lock()
 6751 %{
 6752   match(MemBarReleaseLock);
 6753   ins_cost(0);
 6754 
 6755   size(0);
 6756   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
 6757   ins_encode();
 6758   ins_pipe(empty);
 6759 %}
 6760 
 6761 instruct membar_volatile(rFlagsReg cr) %{
 6762   match(MemBarVolatile);
 6763   effect(KILL cr);
 6764   ins_cost(400);
 6765 
 6766   format %{
 6767     $$template
 6768     $$emit$$"lock addl [rsp + #0], 0\t! membar_volatile"
 6769   %}
 6770   ins_encode %{
 6771     __ membar(Assembler::StoreLoad);
 6772   %}
 6773   ins_pipe(pipe_slow);
 6774 %}
 6775 
 6776 instruct unnecessary_membar_volatile()
 6777 %{
 6778   match(MemBarVolatile);
 6779   predicate(Matcher::post_store_load_barrier(n));
 6780   ins_cost(0);
 6781 
 6782   size(0);
 6783   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
 6784   ins_encode();
 6785   ins_pipe(empty);
 6786 %}
 6787 
 6788 instruct membar_storestore() %{
 6789   match(MemBarStoreStore);
 6790   ins_cost(0);
 6791 
 6792   size(0);
 6793   format %{ "MEMBAR-storestore (empty encoding)" %}
 6794   ins_encode( );
 6795   ins_pipe(empty);
 6796 %}
 6797 
 6798 //----------Move Instructions--------------------------------------------------
 6799 
 6800 instruct castX2P(rRegP dst, rRegL src)
 6801 %{
 6802   match(Set dst (CastX2P src));
 6803 
 6804   format %{ "movq    $dst, $src\t# long->ptr" %}
 6805   ins_encode %{
 6806     if ($dst$$reg != $src$$reg) {
 6807       __ movptr($dst$$Register, $src$$Register);
 6808     }
 6809   %}
 6810   ins_pipe(ialu_reg_reg); // XXX
 6811 %}
 6812 
 6813 instruct castP2X(rRegL dst, rRegP src)
 6814 %{
 6815   match(Set dst (CastP2X src));
 6816 
 6817   format %{ "movq    $dst, $src\t# ptr -> long" %}
 6818   ins_encode %{
 6819     if ($dst$$reg != $src$$reg) {
 6820       __ movptr($dst$$Register, $src$$Register);
 6821     }
 6822   %}
 6823   ins_pipe(ialu_reg_reg); // XXX
 6824 %}
 6825 
 6826 // Convert oop into int for vectors alignment masking
 6827 instruct convP2I(rRegI dst, rRegP src)
 6828 %{
 6829   match(Set dst (ConvL2I (CastP2X src)));
 6830 
 6831   format %{ "movl    $dst, $src\t# ptr -> int" %}
 6832   ins_encode %{
 6833     __ movl($dst$$Register, $src$$Register);
 6834   %}
 6835   ins_pipe(ialu_reg_reg); // XXX
 6836 %}
 6837 
 6838 // Convert compressed oop into int for vectors alignment masking
 6839 // in case of 32bit oops (heap < 4Gb).
 6840 instruct convN2I(rRegI dst, rRegN src)
 6841 %{
 6842   predicate(CompressedOops::shift() == 0);
 6843   match(Set dst (ConvL2I (CastP2X (DecodeN src))));
 6844 
 6845   format %{ "movl    $dst, $src\t# compressed ptr -> int" %}
 6846   ins_encode %{
 6847     __ movl($dst$$Register, $src$$Register);
 6848   %}
 6849   ins_pipe(ialu_reg_reg); // XXX
 6850 %}
 6851 
 6852 // Convert oop pointer into compressed form
 6853 instruct encodeHeapOop(rRegN dst, rRegP src, rFlagsReg cr) %{
 6854   predicate(n->bottom_type()->make_ptr()->ptr() != TypePtr::NotNull);
 6855   match(Set dst (EncodeP src));
 6856   effect(KILL cr);
 6857   format %{ "encode_heap_oop $dst,$src" %}
 6858   ins_encode %{
 6859     Register s = $src$$Register;
 6860     Register d = $dst$$Register;
 6861     if (s != d) {
 6862       __ movq(d, s);
 6863     }
 6864     __ encode_heap_oop(d);
 6865   %}
 6866   ins_pipe(ialu_reg_long);
 6867 %}
 6868 
 6869 instruct encodeHeapOop_not_null(rRegN dst, rRegP src, rFlagsReg cr) %{
 6870   predicate(n->bottom_type()->make_ptr()->ptr() == TypePtr::NotNull);
 6871   match(Set dst (EncodeP src));
 6872   effect(KILL cr);
 6873   format %{ "encode_heap_oop_not_null $dst,$src" %}
 6874   ins_encode %{
 6875     __ encode_heap_oop_not_null($dst$$Register, $src$$Register);
 6876   %}
 6877   ins_pipe(ialu_reg_long);
 6878 %}
 6879 
 6880 instruct decodeHeapOop(rRegP dst, rRegN src, rFlagsReg cr) %{
 6881   predicate(n->bottom_type()->is_ptr()->ptr() != TypePtr::NotNull &&
 6882             n->bottom_type()->is_ptr()->ptr() != TypePtr::Constant);
 6883   match(Set dst (DecodeN src));
 6884   effect(KILL cr);
 6885   format %{ "decode_heap_oop $dst,$src" %}
 6886   ins_encode %{
 6887     Register s = $src$$Register;
 6888     Register d = $dst$$Register;
 6889     if (s != d) {
 6890       __ movq(d, s);
 6891     }
 6892     __ decode_heap_oop(d);
 6893   %}
 6894   ins_pipe(ialu_reg_long);
 6895 %}
 6896 
 6897 instruct decodeHeapOop_not_null(rRegP dst, rRegN src, rFlagsReg cr) %{
 6898   predicate(n->bottom_type()->is_ptr()->ptr() == TypePtr::NotNull ||
 6899             n->bottom_type()->is_ptr()->ptr() == TypePtr::Constant);
 6900   match(Set dst (DecodeN src));
 6901   effect(KILL cr);
 6902   format %{ "decode_heap_oop_not_null $dst,$src" %}
 6903   ins_encode %{
 6904     Register s = $src$$Register;
 6905     Register d = $dst$$Register;
 6906     if (s != d) {
 6907       __ decode_heap_oop_not_null(d, s);
 6908     } else {
 6909       __ decode_heap_oop_not_null(d);
 6910     }
 6911   %}
 6912   ins_pipe(ialu_reg_long);
 6913 %}
 6914 
 6915 instruct encodeKlass_not_null(rRegN dst, rRegP src, rFlagsReg cr) %{
 6916   match(Set dst (EncodePKlass src));
 6917   effect(TEMP dst, KILL cr);
 6918   format %{ "encode_and_move_klass_not_null $dst,$src" %}
 6919   ins_encode %{
 6920     __ encode_and_move_klass_not_null($dst$$Register, $src$$Register);
 6921   %}
 6922   ins_pipe(ialu_reg_long);
 6923 %}
 6924 
 6925 instruct decodeKlass_not_null(rRegP dst, rRegN src, rFlagsReg cr) %{
 6926   match(Set dst (DecodeNKlass src));
 6927   effect(TEMP dst, KILL cr);
 6928   format %{ "decode_and_move_klass_not_null $dst,$src" %}
 6929   ins_encode %{
 6930     __ decode_and_move_klass_not_null($dst$$Register, $src$$Register);
 6931   %}
 6932   ins_pipe(ialu_reg_long);
 6933 %}
 6934 
 6935 //----------Conditional Move---------------------------------------------------
 6936 // Jump
 6937 // dummy instruction for generating temp registers
 6938 instruct jumpXtnd_offset(rRegL switch_val, immI2 shift, rRegI dest) %{
 6939   match(Jump (LShiftL switch_val shift));
 6940   ins_cost(350);
 6941   predicate(false);
 6942   effect(TEMP dest);
 6943 
 6944   format %{ "leaq    $dest, [$constantaddress]\n\t"
 6945             "jmp     [$dest + $switch_val << $shift]\n\t" %}
 6946   ins_encode %{
 6947     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
 6948     // to do that and the compiler is using that register as one it can allocate.
 6949     // So we build it all by hand.
 6950     // Address index(noreg, switch_reg, (Address::ScaleFactor)$shift$$constant);
 6951     // ArrayAddress dispatch(table, index);
 6952     Address dispatch($dest$$Register, $switch_val$$Register, (Address::ScaleFactor) $shift$$constant);
 6953     __ lea($dest$$Register, $constantaddress);
 6954     __ jmp(dispatch);
 6955   %}
 6956   ins_pipe(pipe_jmp);
 6957 %}
 6958 
 6959 instruct jumpXtnd_addr(rRegL switch_val, immI2 shift, immL32 offset, rRegI dest) %{
 6960   match(Jump (AddL (LShiftL switch_val shift) offset));
 6961   ins_cost(350);
 6962   effect(TEMP dest);
 6963 
 6964   format %{ "leaq    $dest, [$constantaddress]\n\t"
 6965             "jmp     [$dest + $switch_val << $shift + $offset]\n\t" %}
 6966   ins_encode %{
 6967     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
 6968     // to do that and the compiler is using that register as one it can allocate.
 6969     // So we build it all by hand.
 6970     // Address index(noreg, switch_reg, (Address::ScaleFactor) $shift$$constant, (int) $offset$$constant);
 6971     // ArrayAddress dispatch(table, index);
 6972     Address dispatch($dest$$Register, $switch_val$$Register, (Address::ScaleFactor) $shift$$constant, (int) $offset$$constant);
 6973     __ lea($dest$$Register, $constantaddress);
 6974     __ jmp(dispatch);
 6975   %}
 6976   ins_pipe(pipe_jmp);
 6977 %}
 6978 
 6979 instruct jumpXtnd(rRegL switch_val, rRegI dest) %{
 6980   match(Jump switch_val);
 6981   ins_cost(350);
 6982   effect(TEMP dest);
 6983 
 6984   format %{ "leaq    $dest, [$constantaddress]\n\t"
 6985             "jmp     [$dest + $switch_val]\n\t" %}
 6986   ins_encode %{
 6987     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
 6988     // to do that and the compiler is using that register as one it can allocate.
 6989     // So we build it all by hand.
 6990     // Address index(noreg, switch_reg, Address::times_1);
 6991     // ArrayAddress dispatch(table, index);
 6992     Address dispatch($dest$$Register, $switch_val$$Register, Address::times_1);
 6993     __ lea($dest$$Register, $constantaddress);
 6994     __ jmp(dispatch);
 6995   %}
 6996   ins_pipe(pipe_jmp);
 6997 %}
 6998 
 6999 // Conditional move
 7000 instruct cmovI_reg(rRegI dst, rRegI src, rFlagsReg cr, cmpOp cop)
 7001 %{
 7002   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
 7003 
 7004   ins_cost(200); // XXX
 7005   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
 7006   ins_encode %{
 7007     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7008   %}
 7009   ins_pipe(pipe_cmov_reg);
 7010 %}
 7011 
 7012 instruct cmovI_regU(cmpOpU cop, rFlagsRegU cr, rRegI dst, rRegI src) %{
 7013   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
 7014 
 7015   ins_cost(200); // XXX
 7016   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
 7017   ins_encode %{
 7018     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7019   %}
 7020   ins_pipe(pipe_cmov_reg);
 7021 %}
 7022 
 7023 instruct cmovI_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegI dst, rRegI src) %{
 7024   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
 7025   ins_cost(200);
 7026   expand %{
 7027     cmovI_regU(cop, cr, dst, src);
 7028   %}
 7029 %}
 7030 
 7031 // Conditional move
 7032 instruct cmovI_mem(cmpOp cop, rFlagsReg cr, rRegI dst, memory src) %{
 7033   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
 7034 
 7035   ins_cost(250); // XXX
 7036   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
 7037   ins_encode %{
 7038     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Address);
 7039   %}
 7040   ins_pipe(pipe_cmov_mem);
 7041 %}
 7042 
 7043 // Conditional move
 7044 instruct cmovI_memU(cmpOpU cop, rFlagsRegU cr, rRegI dst, memory src)
 7045 %{
 7046   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
 7047 
 7048   ins_cost(250); // XXX
 7049   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
 7050   ins_encode %{
 7051     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Address);
 7052   %}
 7053   ins_pipe(pipe_cmov_mem);
 7054 %}
 7055 
 7056 instruct cmovI_memUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegI dst, memory src) %{
 7057   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
 7058   ins_cost(250);
 7059   expand %{
 7060     cmovI_memU(cop, cr, dst, src);
 7061   %}
 7062 %}
 7063 
 7064 // Conditional move
 7065 instruct cmovN_reg(rRegN dst, rRegN src, rFlagsReg cr, cmpOp cop)
 7066 %{
 7067   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
 7068 
 7069   ins_cost(200); // XXX
 7070   format %{ "cmovl$cop $dst, $src\t# signed, compressed ptr" %}
 7071   ins_encode %{
 7072     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7073   %}
 7074   ins_pipe(pipe_cmov_reg);
 7075 %}
 7076 
 7077 // Conditional move
 7078 instruct cmovN_regU(cmpOpU cop, rFlagsRegU cr, rRegN dst, rRegN src)
 7079 %{
 7080   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
 7081 
 7082   ins_cost(200); // XXX
 7083   format %{ "cmovl$cop $dst, $src\t# unsigned, compressed ptr" %}
 7084   ins_encode %{
 7085     __ cmovl((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7086   %}
 7087   ins_pipe(pipe_cmov_reg);
 7088 %}
 7089 
 7090 instruct cmovN_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegN dst, rRegN src) %{
 7091   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
 7092   ins_cost(200);
 7093   expand %{
 7094     cmovN_regU(cop, cr, dst, src);
 7095   %}
 7096 %}
 7097 
 7098 // Conditional move
 7099 instruct cmovP_reg(rRegP dst, rRegP src, rFlagsReg cr, cmpOp cop)
 7100 %{
 7101   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
 7102 
 7103   ins_cost(200); // XXX
 7104   format %{ "cmovq$cop $dst, $src\t# signed, ptr" %}
 7105   ins_encode %{
 7106     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7107   %}
 7108   ins_pipe(pipe_cmov_reg);  // XXX
 7109 %}
 7110 
 7111 // Conditional move
 7112 instruct cmovP_regU(cmpOpU cop, rFlagsRegU cr, rRegP dst, rRegP src)
 7113 %{
 7114   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
 7115 
 7116   ins_cost(200); // XXX
 7117   format %{ "cmovq$cop $dst, $src\t# unsigned, ptr" %}
 7118   ins_encode %{
 7119     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7120   %}
 7121   ins_pipe(pipe_cmov_reg); // XXX
 7122 %}
 7123 
 7124 instruct cmovP_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegP dst, rRegP src) %{
 7125   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
 7126   ins_cost(200);
 7127   expand %{
 7128     cmovP_regU(cop, cr, dst, src);
 7129   %}
 7130 %}
 7131 
 7132 // DISABLED: Requires the ADLC to emit a bottom_type call that
 7133 // correctly meets the two pointer arguments; one is an incoming
 7134 // register but the other is a memory operand.  ALSO appears to
 7135 // be buggy with implicit null checks.
 7136 //
 7137 //// Conditional move
 7138 //instruct cmovP_mem(cmpOp cop, rFlagsReg cr, rRegP dst, memory src)
 7139 //%{
 7140 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
 7141 //  ins_cost(250);
 7142 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
 7143 //  opcode(0x0F,0x40);
 7144 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
 7145 //  ins_pipe( pipe_cmov_mem );
 7146 //%}
 7147 //
 7148 //// Conditional move
 7149 //instruct cmovP_memU(cmpOpU cop, rFlagsRegU cr, rRegP dst, memory src)
 7150 //%{
 7151 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
 7152 //  ins_cost(250);
 7153 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
 7154 //  opcode(0x0F,0x40);
 7155 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
 7156 //  ins_pipe( pipe_cmov_mem );
 7157 //%}
 7158 
 7159 instruct cmovL_reg(cmpOp cop, rFlagsReg cr, rRegL dst, rRegL src)
 7160 %{
 7161   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
 7162 
 7163   ins_cost(200); // XXX
 7164   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
 7165   ins_encode %{
 7166     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7167   %}
 7168   ins_pipe(pipe_cmov_reg);  // XXX
 7169 %}
 7170 
 7171 instruct cmovL_mem(cmpOp cop, rFlagsReg cr, rRegL dst, memory src)
 7172 %{
 7173   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
 7174 
 7175   ins_cost(200); // XXX
 7176   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
 7177   ins_encode %{
 7178     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Address);
 7179   %}
 7180   ins_pipe(pipe_cmov_mem);  // XXX
 7181 %}
 7182 
 7183 instruct cmovL_regU(cmpOpU cop, rFlagsRegU cr, rRegL dst, rRegL src)
 7184 %{
 7185   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
 7186 
 7187   ins_cost(200); // XXX
 7188   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
 7189   ins_encode %{
 7190     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Register);
 7191   %}
 7192   ins_pipe(pipe_cmov_reg); // XXX
 7193 %}
 7194 
 7195 instruct cmovL_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegL dst, rRegL src) %{
 7196   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
 7197   ins_cost(200);
 7198   expand %{
 7199     cmovL_regU(cop, cr, dst, src);
 7200   %}
 7201 %}
 7202 
 7203 instruct cmovL_memU(cmpOpU cop, rFlagsRegU cr, rRegL dst, memory src)
 7204 %{
 7205   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
 7206 
 7207   ins_cost(200); // XXX
 7208   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
 7209   ins_encode %{
 7210     __ cmovq((Assembler::Condition)($cop$$cmpcode), $dst$$Register, $src$$Address);
 7211   %}
 7212   ins_pipe(pipe_cmov_mem); // XXX
 7213 %}
 7214 
 7215 instruct cmovL_memUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegL dst, memory src) %{
 7216   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
 7217   ins_cost(200);
 7218   expand %{
 7219     cmovL_memU(cop, cr, dst, src);
 7220   %}
 7221 %}
 7222 
 7223 instruct cmovF_reg(cmpOp cop, rFlagsReg cr, regF dst, regF src)
 7224 %{
 7225   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
 7226 
 7227   ins_cost(200); // XXX
 7228   format %{ "jn$cop    skip\t# signed cmove float\n\t"
 7229             "movss     $dst, $src\n"
 7230     "skip:" %}
 7231   ins_encode %{
 7232     Label Lskip;
 7233     // Invert sense of branch from sense of CMOV
 7234     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
 7235     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
 7236     __ bind(Lskip);
 7237   %}
 7238   ins_pipe(pipe_slow);
 7239 %}
 7240 
 7241 // instruct cmovF_mem(cmpOp cop, rFlagsReg cr, regF dst, memory src)
 7242 // %{
 7243 //   match(Set dst (CMoveF (Binary cop cr) (Binary dst (LoadL src))));
 7244 
 7245 //   ins_cost(200); // XXX
 7246 //   format %{ "jn$cop    skip\t# signed cmove float\n\t"
 7247 //             "movss     $dst, $src\n"
 7248 //     "skip:" %}
 7249 //   ins_encode(enc_cmovf_mem_branch(cop, dst, src));
 7250 //   ins_pipe(pipe_slow);
 7251 // %}
 7252 
 7253 instruct cmovF_regU(cmpOpU cop, rFlagsRegU cr, regF dst, regF src)
 7254 %{
 7255   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
 7256 
 7257   ins_cost(200); // XXX
 7258   format %{ "jn$cop    skip\t# unsigned cmove float\n\t"
 7259             "movss     $dst, $src\n"
 7260     "skip:" %}
 7261   ins_encode %{
 7262     Label Lskip;
 7263     // Invert sense of branch from sense of CMOV
 7264     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
 7265     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
 7266     __ bind(Lskip);
 7267   %}
 7268   ins_pipe(pipe_slow);
 7269 %}
 7270 
 7271 instruct cmovF_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, regF dst, regF src) %{
 7272   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
 7273   ins_cost(200);
 7274   expand %{
 7275     cmovF_regU(cop, cr, dst, src);
 7276   %}
 7277 %}
 7278 
 7279 instruct cmovD_reg(cmpOp cop, rFlagsReg cr, regD dst, regD src)
 7280 %{
 7281   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
 7282 
 7283   ins_cost(200); // XXX
 7284   format %{ "jn$cop    skip\t# signed cmove double\n\t"
 7285             "movsd     $dst, $src\n"
 7286     "skip:" %}
 7287   ins_encode %{
 7288     Label Lskip;
 7289     // Invert sense of branch from sense of CMOV
 7290     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
 7291     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
 7292     __ bind(Lskip);
 7293   %}
 7294   ins_pipe(pipe_slow);
 7295 %}
 7296 
 7297 instruct cmovD_regU(cmpOpU cop, rFlagsRegU cr, regD dst, regD src)
 7298 %{
 7299   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
 7300 
 7301   ins_cost(200); // XXX
 7302   format %{ "jn$cop    skip\t# unsigned cmove double\n\t"
 7303             "movsd     $dst, $src\n"
 7304     "skip:" %}
 7305   ins_encode %{
 7306     Label Lskip;
 7307     // Invert sense of branch from sense of CMOV
 7308     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
 7309     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
 7310     __ bind(Lskip);
 7311   %}
 7312   ins_pipe(pipe_slow);
 7313 %}
 7314 
 7315 instruct cmovD_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, regD dst, regD src) %{
 7316   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
 7317   ins_cost(200);
 7318   expand %{
 7319     cmovD_regU(cop, cr, dst, src);
 7320   %}
 7321 %}
 7322 
 7323 //----------Arithmetic Instructions--------------------------------------------
 7324 //----------Addition Instructions----------------------------------------------
 7325 
 7326 instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 7327 %{
 7328   match(Set dst (AddI dst src));
 7329   effect(KILL cr);
 7330 
 7331   format %{ "addl    $dst, $src\t# int" %}
 7332   ins_encode %{
 7333     __ addl($dst$$Register, $src$$Register);
 7334   %}
 7335   ins_pipe(ialu_reg_reg);
 7336 %}
 7337 
 7338 instruct addI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
 7339 %{
 7340   match(Set dst (AddI dst src));
 7341   effect(KILL cr);
 7342 
 7343   format %{ "addl    $dst, $src\t# int" %}
 7344   ins_encode %{
 7345     __ addl($dst$$Register, $src$$constant);
 7346   %}
 7347   ins_pipe( ialu_reg );
 7348 %}
 7349 
 7350 instruct addI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
 7351 %{
 7352   match(Set dst (AddI dst (LoadI src)));
 7353   effect(KILL cr);
 7354 
 7355   ins_cost(125); // XXX
 7356   format %{ "addl    $dst, $src\t# int" %}
 7357   ins_encode %{
 7358     __ addl($dst$$Register, $src$$Address);
 7359   %}
 7360   ins_pipe(ialu_reg_mem);
 7361 %}
 7362 
 7363 instruct addI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 7364 %{
 7365   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
 7366   effect(KILL cr);
 7367 
 7368   ins_cost(150); // XXX
 7369   format %{ "addl    $dst, $src\t# int" %}
 7370   ins_encode %{
 7371     __ addl($dst$$Address, $src$$Register);
 7372   %}
 7373   ins_pipe(ialu_mem_reg);
 7374 %}
 7375 
 7376 instruct addI_mem_imm(memory dst, immI src, rFlagsReg cr)
 7377 %{
 7378   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
 7379   effect(KILL cr);
 7380 
 7381   ins_cost(125); // XXX
 7382   format %{ "addl    $dst, $src\t# int" %}
 7383   ins_encode %{
 7384     __ addl($dst$$Address, $src$$constant);
 7385   %}
 7386   ins_pipe(ialu_mem_imm);
 7387 %}
 7388 
 7389 instruct incI_rReg(rRegI dst, immI_1 src, rFlagsReg cr)
 7390 %{
 7391   predicate(UseIncDec);
 7392   match(Set dst (AddI dst src));
 7393   effect(KILL cr);
 7394 
 7395   format %{ "incl    $dst\t# int" %}
 7396   ins_encode %{
 7397     __ incrementl($dst$$Register);
 7398   %}
 7399   ins_pipe(ialu_reg);
 7400 %}
 7401 
 7402 instruct incI_mem(memory dst, immI_1 src, rFlagsReg cr)
 7403 %{
 7404   predicate(UseIncDec);
 7405   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
 7406   effect(KILL cr);
 7407 
 7408   ins_cost(125); // XXX
 7409   format %{ "incl    $dst\t# int" %}
 7410   ins_encode %{
 7411     __ incrementl($dst$$Address);
 7412   %}
 7413   ins_pipe(ialu_mem_imm);
 7414 %}
 7415 
 7416 // XXX why does that use AddI
 7417 instruct decI_rReg(rRegI dst, immI_M1 src, rFlagsReg cr)
 7418 %{
 7419   predicate(UseIncDec);
 7420   match(Set dst (AddI dst src));
 7421   effect(KILL cr);
 7422 
 7423   format %{ "decl    $dst\t# int" %}
 7424   ins_encode %{
 7425     __ decrementl($dst$$Register);
 7426   %}
 7427   ins_pipe(ialu_reg);
 7428 %}
 7429 
 7430 // XXX why does that use AddI
 7431 instruct decI_mem(memory dst, immI_M1 src, rFlagsReg cr)
 7432 %{
 7433   predicate(UseIncDec);
 7434   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
 7435   effect(KILL cr);
 7436 
 7437   ins_cost(125); // XXX
 7438   format %{ "decl    $dst\t# int" %}
 7439   ins_encode %{
 7440     __ decrementl($dst$$Address);
 7441   %}
 7442   ins_pipe(ialu_mem_imm);
 7443 %}
 7444 
 7445 instruct leaI_rReg_immI(rRegI dst, rRegI src0, immI src1)
 7446 %{
 7447   match(Set dst (AddI src0 src1));
 7448 
 7449   ins_cost(110);
 7450   format %{ "addr32 leal $dst, [$src0 + $src1]\t# int" %}
 7451   ins_encode %{
 7452     __ leal($dst$$Register, Address($src0$$Register, $src1$$constant));
 7453   %}
 7454   ins_pipe(ialu_reg_reg);
 7455 %}
 7456 
 7457 instruct addL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
 7458 %{
 7459   match(Set dst (AddL dst src));
 7460   effect(KILL cr);
 7461 
 7462   format %{ "addq    $dst, $src\t# long" %}
 7463   ins_encode %{
 7464     __ addq($dst$$Register, $src$$Register);
 7465   %}
 7466   ins_pipe(ialu_reg_reg);
 7467 %}
 7468 
 7469 instruct addL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
 7470 %{
 7471   match(Set dst (AddL dst src));
 7472   effect(KILL cr);
 7473 
 7474   format %{ "addq    $dst, $src\t# long" %}
 7475   ins_encode %{
 7476     __ addq($dst$$Register, $src$$constant);
 7477   %}
 7478   ins_pipe( ialu_reg );
 7479 %}
 7480 
 7481 instruct addL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
 7482 %{
 7483   match(Set dst (AddL dst (LoadL src)));
 7484   effect(KILL cr);
 7485 
 7486   ins_cost(125); // XXX
 7487   format %{ "addq    $dst, $src\t# long" %}
 7488   ins_encode %{
 7489     __ addq($dst$$Register, $src$$Address);
 7490   %}
 7491   ins_pipe(ialu_reg_mem);
 7492 %}
 7493 
 7494 instruct addL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
 7495 %{
 7496   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
 7497   effect(KILL cr);
 7498 
 7499   ins_cost(150); // XXX
 7500   format %{ "addq    $dst, $src\t# long" %}
 7501   ins_encode %{
 7502     __ addq($dst$$Address, $src$$Register);
 7503   %}
 7504   ins_pipe(ialu_mem_reg);
 7505 %}
 7506 
 7507 instruct addL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
 7508 %{
 7509   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
 7510   effect(KILL cr);
 7511 
 7512   ins_cost(125); // XXX
 7513   format %{ "addq    $dst, $src\t# long" %}
 7514   ins_encode %{
 7515     __ addq($dst$$Address, $src$$constant);
 7516   %}
 7517   ins_pipe(ialu_mem_imm);
 7518 %}
 7519 
 7520 instruct incL_rReg(rRegI dst, immL1 src, rFlagsReg cr)
 7521 %{
 7522   predicate(UseIncDec);
 7523   match(Set dst (AddL dst src));
 7524   effect(KILL cr);
 7525 
 7526   format %{ "incq    $dst\t# long" %}
 7527   ins_encode %{
 7528     __ incrementq($dst$$Register);
 7529   %}
 7530   ins_pipe(ialu_reg);
 7531 %}
 7532 
 7533 instruct incL_mem(memory dst, immL1 src, rFlagsReg cr)
 7534 %{
 7535   predicate(UseIncDec);
 7536   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
 7537   effect(KILL cr);
 7538 
 7539   ins_cost(125); // XXX
 7540   format %{ "incq    $dst\t# long" %}
 7541   ins_encode %{
 7542     __ incrementq($dst$$Address);
 7543   %}
 7544   ins_pipe(ialu_mem_imm);
 7545 %}
 7546 
 7547 // XXX why does that use AddL
 7548 instruct decL_rReg(rRegL dst, immL_M1 src, rFlagsReg cr)
 7549 %{
 7550   predicate(UseIncDec);
 7551   match(Set dst (AddL dst src));
 7552   effect(KILL cr);
 7553 
 7554   format %{ "decq    $dst\t# long" %}
 7555   ins_encode %{
 7556     __ decrementq($dst$$Register);
 7557   %}
 7558   ins_pipe(ialu_reg);
 7559 %}
 7560 
 7561 // XXX why does that use AddL
 7562 instruct decL_mem(memory dst, immL_M1 src, rFlagsReg cr)
 7563 %{
 7564   predicate(UseIncDec);
 7565   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
 7566   effect(KILL cr);
 7567 
 7568   ins_cost(125); // XXX
 7569   format %{ "decq    $dst\t# long" %}
 7570   ins_encode %{
 7571     __ decrementq($dst$$Address);
 7572   %}
 7573   ins_pipe(ialu_mem_imm);
 7574 %}
 7575 
 7576 instruct leaL_rReg_immL(rRegL dst, rRegL src0, immL32 src1)
 7577 %{
 7578   match(Set dst (AddL src0 src1));
 7579 
 7580   ins_cost(110);
 7581   format %{ "leaq    $dst, [$src0 + $src1]\t# long" %}
 7582   ins_encode %{
 7583     __ leaq($dst$$Register, Address($src0$$Register, $src1$$constant));
 7584   %}
 7585   ins_pipe(ialu_reg_reg);
 7586 %}
 7587 
 7588 instruct addP_rReg(rRegP dst, rRegL src, rFlagsReg cr)
 7589 %{
 7590   match(Set dst (AddP dst src));
 7591   effect(KILL cr);
 7592 
 7593   format %{ "addq    $dst, $src\t# ptr" %}
 7594   ins_encode %{
 7595     __ addq($dst$$Register, $src$$Register);
 7596   %}
 7597   ins_pipe(ialu_reg_reg);
 7598 %}
 7599 
 7600 instruct addP_rReg_imm(rRegP dst, immL32 src, rFlagsReg cr)
 7601 %{
 7602   match(Set dst (AddP dst src));
 7603   effect(KILL cr);
 7604 
 7605   format %{ "addq    $dst, $src\t# ptr" %}
 7606   ins_encode %{
 7607     __ addq($dst$$Register, $src$$constant);
 7608   %}
 7609   ins_pipe( ialu_reg );
 7610 %}
 7611 
 7612 // XXX addP mem ops ????
 7613 
 7614 instruct leaP_rReg_imm(rRegP dst, rRegP src0, immL32 src1)
 7615 %{
 7616   match(Set dst (AddP src0 src1));
 7617 
 7618   ins_cost(110);
 7619   format %{ "leaq    $dst, [$src0 + $src1]\t# ptr" %}
 7620   ins_encode %{
 7621     __ leaq($dst$$Register, Address($src0$$Register, $src1$$constant));
 7622   %}
 7623   ins_pipe(ialu_reg_reg);
 7624 %}
 7625 
 7626 instruct checkCastPP(rRegP dst)
 7627 %{
 7628   match(Set dst (CheckCastPP dst));
 7629 
 7630   size(0);
 7631   format %{ "# checkcastPP of $dst" %}
 7632   ins_encode(/* empty encoding */);
 7633   ins_pipe(empty);
 7634 %}
 7635 
 7636 instruct castPP(rRegP dst)
 7637 %{
 7638   match(Set dst (CastPP dst));
 7639 
 7640   size(0);
 7641   format %{ "# castPP of $dst" %}
 7642   ins_encode(/* empty encoding */);
 7643   ins_pipe(empty);
 7644 %}
 7645 
 7646 instruct castII(rRegI dst)
 7647 %{
 7648   match(Set dst (CastII dst));
 7649 
 7650   size(0);
 7651   format %{ "# castII of $dst" %}
 7652   ins_encode(/* empty encoding */);
 7653   ins_cost(0);
 7654   ins_pipe(empty);
 7655 %}
 7656 
 7657 instruct castLL(rRegL dst)
 7658 %{
 7659   match(Set dst (CastLL dst));
 7660 
 7661   size(0);
 7662   format %{ "# castLL of $dst" %}
 7663   ins_encode(/* empty encoding */);
 7664   ins_cost(0);
 7665   ins_pipe(empty);
 7666 %}
 7667 
 7668 instruct castFF(regF dst)
 7669 %{
 7670   match(Set dst (CastFF dst));
 7671 
 7672   size(0);
 7673   format %{ "# castFF of $dst" %}
 7674   ins_encode(/* empty encoding */);
 7675   ins_cost(0);
 7676   ins_pipe(empty);
 7677 %}
 7678 
 7679 instruct castDD(regD dst)
 7680 %{
 7681   match(Set dst (CastDD dst));
 7682 
 7683   size(0);
 7684   format %{ "# castDD of $dst" %}
 7685   ins_encode(/* empty encoding */);
 7686   ins_cost(0);
 7687   ins_pipe(empty);
 7688 %}
 7689 
 7690 // LoadP-locked same as a regular LoadP when used with compare-swap
 7691 instruct loadPLocked(rRegP dst, memory mem)
 7692 %{
 7693   match(Set dst (LoadPLocked mem));
 7694 
 7695   ins_cost(125); // XXX
 7696   format %{ "movq    $dst, $mem\t# ptr locked" %}
 7697   ins_encode %{
 7698     __ movq($dst$$Register, $mem$$Address);
 7699   %}
 7700   ins_pipe(ialu_reg_mem); // XXX
 7701 %}
 7702 
 7703 // Conditional-store of the updated heap-top.
 7704 // Used during allocation of the shared heap.
 7705 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
 7706 
 7707 instruct storePConditional(memory heap_top_ptr,
 7708                            rax_RegP oldval, rRegP newval,
 7709                            rFlagsReg cr)
 7710 %{
 7711   predicate(n->as_LoadStore()->barrier_data() == 0);
 7712   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
 7713 
 7714   format %{ "cmpxchgq $heap_top_ptr, $newval\t# (ptr) "
 7715             "If rax == $heap_top_ptr then store $newval into $heap_top_ptr" %}
 7716   ins_encode %{
 7717     __ lock();
 7718     __ cmpxchgq($newval$$Register, $heap_top_ptr$$Address);
 7719   %}
 7720   ins_pipe(pipe_cmpxchg);
 7721 %}
 7722 
 7723 // Conditional-store of an int value.
 7724 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG.
 7725 instruct storeIConditional(memory mem, rax_RegI oldval, rRegI newval, rFlagsReg cr)
 7726 %{
 7727   match(Set cr (StoreIConditional mem (Binary oldval newval)));
 7728   effect(KILL oldval);
 7729 
 7730   format %{ "cmpxchgl $mem, $newval\t# If rax == $mem then store $newval into $mem" %}
 7731   opcode(0x0F, 0xB1);
 7732   ins_encode(lock_prefix,
 7733              REX_reg_mem(newval, mem),
 7734              OpcP, OpcS,
 7735              reg_mem(newval, mem));
 7736   ins_pipe(pipe_cmpxchg);
 7737 %}
 7738 
 7739 // Conditional-store of a long value.
 7740 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG.
 7741 instruct storeLConditional(memory mem, rax_RegL oldval, rRegL newval, rFlagsReg cr)
 7742 %{
 7743   match(Set cr (StoreLConditional mem (Binary oldval newval)));
 7744   effect(KILL oldval);
 7745 
 7746   format %{ "cmpxchgq $mem, $newval\t# If rax == $mem then store $newval into $mem" %}
 7747   ins_encode %{
 7748     __ lock();
 7749     __ cmpxchgq($newval$$Register, $mem$$Address);
 7750   %}
 7751   ins_pipe(pipe_cmpxchg);
 7752 %}
 7753 
 7754 
 7755 // XXX No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
 7756 instruct compareAndSwapP(rRegI res,
 7757                          memory mem_ptr,
 7758                          rax_RegP oldval, rRegP newval,
 7759                          rFlagsReg cr)
 7760 %{
 7761   predicate(VM_Version::supports_cx8() && n->as_LoadStore()->barrier_data() == 0);
 7762   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
 7763   match(Set res (WeakCompareAndSwapP mem_ptr (Binary oldval newval)));
 7764   effect(KILL cr, KILL oldval);
 7765 
 7766   format %{ "cmpxchgq $mem_ptr,$newval\t# "
 7767             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7768             "sete    $res\n\t"
 7769             "movzbl  $res, $res" %}
 7770   ins_encode %{
 7771     __ lock();
 7772     __ cmpxchgq($newval$$Register, $mem_ptr$$Address);
 7773     __ sete($res$$Register);
 7774     __ movzbl($res$$Register, $res$$Register);
 7775   %}
 7776   ins_pipe( pipe_cmpxchg );
 7777 %}
 7778 
 7779 instruct compareAndSwapL(rRegI res,
 7780                          memory mem_ptr,
 7781                          rax_RegL oldval, rRegL newval,
 7782                          rFlagsReg cr)
 7783 %{
 7784   predicate(VM_Version::supports_cx8());
 7785   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
 7786   match(Set res (WeakCompareAndSwapL mem_ptr (Binary oldval newval)));
 7787   effect(KILL cr, KILL oldval);
 7788 
 7789   format %{ "cmpxchgq $mem_ptr,$newval\t# "
 7790             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7791             "sete    $res\n\t"
 7792             "movzbl  $res, $res" %}
 7793   ins_encode %{
 7794     __ lock();
 7795     __ cmpxchgq($newval$$Register, $mem_ptr$$Address);
 7796     __ sete($res$$Register);
 7797     __ movzbl($res$$Register, $res$$Register);
 7798   %}
 7799   ins_pipe( pipe_cmpxchg );
 7800 %}
 7801 
 7802 instruct compareAndSwapI(rRegI res,
 7803                          memory mem_ptr,
 7804                          rax_RegI oldval, rRegI newval,
 7805                          rFlagsReg cr)
 7806 %{
 7807   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
 7808   match(Set res (WeakCompareAndSwapI mem_ptr (Binary oldval newval)));
 7809   effect(KILL cr, KILL oldval);
 7810 
 7811   format %{ "cmpxchgl $mem_ptr,$newval\t# "
 7812             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7813             "sete    $res\n\t"
 7814             "movzbl  $res, $res" %}
 7815   ins_encode %{
 7816     __ lock();
 7817     __ cmpxchgl($newval$$Register, $mem_ptr$$Address);
 7818     __ sete($res$$Register);
 7819     __ movzbl($res$$Register, $res$$Register);
 7820   %}
 7821   ins_pipe( pipe_cmpxchg );
 7822 %}
 7823 
 7824 instruct compareAndSwapB(rRegI res,
 7825                          memory mem_ptr,
 7826                          rax_RegI oldval, rRegI newval,
 7827                          rFlagsReg cr)
 7828 %{
 7829   match(Set res (CompareAndSwapB mem_ptr (Binary oldval newval)));
 7830   match(Set res (WeakCompareAndSwapB mem_ptr (Binary oldval newval)));
 7831   effect(KILL cr, KILL oldval);
 7832 
 7833   format %{ "cmpxchgb $mem_ptr,$newval\t# "
 7834             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7835             "sete    $res\n\t"
 7836             "movzbl  $res, $res" %}
 7837   ins_encode %{
 7838     __ lock();
 7839     __ cmpxchgb($newval$$Register, $mem_ptr$$Address);
 7840     __ sete($res$$Register);
 7841     __ movzbl($res$$Register, $res$$Register);
 7842   %}
 7843   ins_pipe( pipe_cmpxchg );
 7844 %}
 7845 
 7846 instruct compareAndSwapS(rRegI res,
 7847                          memory mem_ptr,
 7848                          rax_RegI oldval, rRegI newval,
 7849                          rFlagsReg cr)
 7850 %{
 7851   match(Set res (CompareAndSwapS mem_ptr (Binary oldval newval)));
 7852   match(Set res (WeakCompareAndSwapS mem_ptr (Binary oldval newval)));
 7853   effect(KILL cr, KILL oldval);
 7854 
 7855   format %{ "cmpxchgw $mem_ptr,$newval\t# "
 7856             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7857             "sete    $res\n\t"
 7858             "movzbl  $res, $res" %}
 7859   ins_encode %{
 7860     __ lock();
 7861     __ cmpxchgw($newval$$Register, $mem_ptr$$Address);
 7862     __ sete($res$$Register);
 7863     __ movzbl($res$$Register, $res$$Register);
 7864   %}
 7865   ins_pipe( pipe_cmpxchg );
 7866 %}
 7867 
 7868 instruct compareAndSwapN(rRegI res,
 7869                           memory mem_ptr,
 7870                           rax_RegN oldval, rRegN newval,
 7871                           rFlagsReg cr) %{
 7872   match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval)));
 7873   match(Set res (WeakCompareAndSwapN mem_ptr (Binary oldval newval)));
 7874   effect(KILL cr, KILL oldval);
 7875 
 7876   format %{ "cmpxchgl $mem_ptr,$newval\t# "
 7877             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
 7878             "sete    $res\n\t"
 7879             "movzbl  $res, $res" %}
 7880   ins_encode %{
 7881     __ lock();
 7882     __ cmpxchgl($newval$$Register, $mem_ptr$$Address);
 7883     __ sete($res$$Register);
 7884     __ movzbl($res$$Register, $res$$Register);
 7885   %}
 7886   ins_pipe( pipe_cmpxchg );
 7887 %}
 7888 
 7889 instruct compareAndExchangeB(
 7890                          memory mem_ptr,
 7891                          rax_RegI oldval, rRegI newval,
 7892                          rFlagsReg cr)
 7893 %{
 7894   match(Set oldval (CompareAndExchangeB mem_ptr (Binary oldval newval)));
 7895   effect(KILL cr);
 7896 
 7897   format %{ "cmpxchgb $mem_ptr,$newval\t# "
 7898             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"  %}
 7899   ins_encode %{
 7900     __ lock();
 7901     __ cmpxchgb($newval$$Register, $mem_ptr$$Address);
 7902   %}
 7903   ins_pipe( pipe_cmpxchg );
 7904 %}
 7905 
 7906 instruct compareAndExchangeS(
 7907                          memory mem_ptr,
 7908                          rax_RegI oldval, rRegI newval,
 7909                          rFlagsReg cr)
 7910 %{
 7911   match(Set oldval (CompareAndExchangeS mem_ptr (Binary oldval newval)));
 7912   effect(KILL cr);
 7913 
 7914   format %{ "cmpxchgw $mem_ptr,$newval\t# "
 7915             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"  %}
 7916   ins_encode %{
 7917     __ lock();
 7918     __ cmpxchgw($newval$$Register, $mem_ptr$$Address);
 7919   %}
 7920   ins_pipe( pipe_cmpxchg );
 7921 %}
 7922 
 7923 instruct compareAndExchangeI(
 7924                          memory mem_ptr,
 7925                          rax_RegI oldval, rRegI newval,
 7926                          rFlagsReg cr)
 7927 %{
 7928   match(Set oldval (CompareAndExchangeI mem_ptr (Binary oldval newval)));
 7929   effect(KILL cr);
 7930 
 7931   format %{ "cmpxchgl $mem_ptr,$newval\t# "
 7932             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"  %}
 7933   ins_encode %{
 7934     __ lock();
 7935     __ cmpxchgl($newval$$Register, $mem_ptr$$Address);
 7936   %}
 7937   ins_pipe( pipe_cmpxchg );
 7938 %}
 7939 
 7940 instruct compareAndExchangeL(
 7941                          memory mem_ptr,
 7942                          rax_RegL oldval, rRegL newval,
 7943                          rFlagsReg cr)
 7944 %{
 7945   predicate(VM_Version::supports_cx8());
 7946   match(Set oldval (CompareAndExchangeL mem_ptr (Binary oldval newval)));
 7947   effect(KILL cr);
 7948 
 7949   format %{ "cmpxchgq $mem_ptr,$newval\t# "
 7950             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"  %}
 7951   ins_encode %{
 7952     __ lock();
 7953     __ cmpxchgq($newval$$Register, $mem_ptr$$Address);
 7954   %}
 7955   ins_pipe( pipe_cmpxchg );
 7956 %}
 7957 
 7958 instruct compareAndExchangeN(
 7959                           memory mem_ptr,
 7960                           rax_RegN oldval, rRegN newval,
 7961                           rFlagsReg cr) %{
 7962   match(Set oldval (CompareAndExchangeN mem_ptr (Binary oldval newval)));
 7963   effect(KILL cr);
 7964 
 7965   format %{ "cmpxchgl $mem_ptr,$newval\t# "
 7966             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t" %}
 7967   ins_encode %{
 7968     __ lock();
 7969     __ cmpxchgl($newval$$Register, $mem_ptr$$Address);
 7970   %}
 7971   ins_pipe( pipe_cmpxchg );
 7972 %}
 7973 
 7974 instruct compareAndExchangeP(
 7975                          memory mem_ptr,
 7976                          rax_RegP oldval, rRegP newval,
 7977                          rFlagsReg cr)
 7978 %{
 7979   predicate(VM_Version::supports_cx8() && n->as_LoadStore()->barrier_data() == 0);
 7980   match(Set oldval (CompareAndExchangeP mem_ptr (Binary oldval newval)));
 7981   effect(KILL cr);
 7982 
 7983   format %{ "cmpxchgq $mem_ptr,$newval\t# "
 7984             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t" %}
 7985   ins_encode %{
 7986     __ lock();
 7987     __ cmpxchgq($newval$$Register, $mem_ptr$$Address);
 7988   %}
 7989   ins_pipe( pipe_cmpxchg );
 7990 %}
 7991 
 7992 instruct xaddB_no_res( memory mem, Universe dummy, immI add, rFlagsReg cr) %{
 7993   predicate(n->as_LoadStore()->result_not_used());
 7994   match(Set dummy (GetAndAddB mem add));
 7995   effect(KILL cr);
 7996   format %{ "ADDB  [$mem],$add" %}
 7997   ins_encode %{
 7998     __ lock();
 7999     __ addb($mem$$Address, $add$$constant);
 8000   %}
 8001   ins_pipe( pipe_cmpxchg );
 8002 %}
 8003 
 8004 instruct xaddB( memory mem, rRegI newval, rFlagsReg cr) %{
 8005   match(Set newval (GetAndAddB mem newval));
 8006   effect(KILL cr);
 8007   format %{ "XADDB  [$mem],$newval" %}
 8008   ins_encode %{
 8009     __ lock();
 8010     __ xaddb($mem$$Address, $newval$$Register);
 8011   %}
 8012   ins_pipe( pipe_cmpxchg );
 8013 %}
 8014 
 8015 instruct xaddS_no_res( memory mem, Universe dummy, immI add, rFlagsReg cr) %{
 8016   predicate(n->as_LoadStore()->result_not_used());
 8017   match(Set dummy (GetAndAddS mem add));
 8018   effect(KILL cr);
 8019   format %{ "ADDW  [$mem],$add" %}
 8020   ins_encode %{
 8021     __ lock();
 8022     __ addw($mem$$Address, $add$$constant);
 8023   %}
 8024   ins_pipe( pipe_cmpxchg );
 8025 %}
 8026 
 8027 instruct xaddS( memory mem, rRegI newval, rFlagsReg cr) %{
 8028   match(Set newval (GetAndAddS mem newval));
 8029   effect(KILL cr);
 8030   format %{ "XADDW  [$mem],$newval" %}
 8031   ins_encode %{
 8032     __ lock();
 8033     __ xaddw($mem$$Address, $newval$$Register);
 8034   %}
 8035   ins_pipe( pipe_cmpxchg );
 8036 %}
 8037 
 8038 instruct xaddI_no_res( memory mem, Universe dummy, immI add, rFlagsReg cr) %{
 8039   predicate(n->as_LoadStore()->result_not_used());
 8040   match(Set dummy (GetAndAddI mem add));
 8041   effect(KILL cr);
 8042   format %{ "ADDL  [$mem],$add" %}
 8043   ins_encode %{
 8044     __ lock();
 8045     __ addl($mem$$Address, $add$$constant);
 8046   %}
 8047   ins_pipe( pipe_cmpxchg );
 8048 %}
 8049 
 8050 instruct xaddI( memory mem, rRegI newval, rFlagsReg cr) %{
 8051   match(Set newval (GetAndAddI mem newval));
 8052   effect(KILL cr);
 8053   format %{ "XADDL  [$mem],$newval" %}
 8054   ins_encode %{
 8055     __ lock();
 8056     __ xaddl($mem$$Address, $newval$$Register);
 8057   %}
 8058   ins_pipe( pipe_cmpxchg );
 8059 %}
 8060 
 8061 instruct xaddL_no_res( memory mem, Universe dummy, immL32 add, rFlagsReg cr) %{
 8062   predicate(n->as_LoadStore()->result_not_used());
 8063   match(Set dummy (GetAndAddL mem add));
 8064   effect(KILL cr);
 8065   format %{ "ADDQ  [$mem],$add" %}
 8066   ins_encode %{
 8067     __ lock();
 8068     __ addq($mem$$Address, $add$$constant);
 8069   %}
 8070   ins_pipe( pipe_cmpxchg );
 8071 %}
 8072 
 8073 instruct xaddL( memory mem, rRegL newval, rFlagsReg cr) %{
 8074   match(Set newval (GetAndAddL mem newval));
 8075   effect(KILL cr);
 8076   format %{ "XADDQ  [$mem],$newval" %}
 8077   ins_encode %{
 8078     __ lock();
 8079     __ xaddq($mem$$Address, $newval$$Register);
 8080   %}
 8081   ins_pipe( pipe_cmpxchg );
 8082 %}
 8083 
 8084 instruct xchgB( memory mem, rRegI newval) %{
 8085   match(Set newval (GetAndSetB mem newval));
 8086   format %{ "XCHGB  $newval,[$mem]" %}
 8087   ins_encode %{
 8088     __ xchgb($newval$$Register, $mem$$Address);
 8089   %}
 8090   ins_pipe( pipe_cmpxchg );
 8091 %}
 8092 
 8093 instruct xchgS( memory mem, rRegI newval) %{
 8094   match(Set newval (GetAndSetS mem newval));
 8095   format %{ "XCHGW  $newval,[$mem]" %}
 8096   ins_encode %{
 8097     __ xchgw($newval$$Register, $mem$$Address);
 8098   %}
 8099   ins_pipe( pipe_cmpxchg );
 8100 %}
 8101 
 8102 instruct xchgI( memory mem, rRegI newval) %{
 8103   match(Set newval (GetAndSetI mem newval));
 8104   format %{ "XCHGL  $newval,[$mem]" %}
 8105   ins_encode %{
 8106     __ xchgl($newval$$Register, $mem$$Address);
 8107   %}
 8108   ins_pipe( pipe_cmpxchg );
 8109 %}
 8110 
 8111 instruct xchgL( memory mem, rRegL newval) %{
 8112   match(Set newval (GetAndSetL mem newval));
 8113   format %{ "XCHGL  $newval,[$mem]" %}
 8114   ins_encode %{
 8115     __ xchgq($newval$$Register, $mem$$Address);
 8116   %}
 8117   ins_pipe( pipe_cmpxchg );
 8118 %}
 8119 
 8120 instruct xchgP( memory mem, rRegP newval) %{
 8121   match(Set newval (GetAndSetP mem newval));
 8122   predicate(n->as_LoadStore()->barrier_data() == 0);
 8123   format %{ "XCHGQ  $newval,[$mem]" %}
 8124   ins_encode %{
 8125     __ xchgq($newval$$Register, $mem$$Address);
 8126   %}
 8127   ins_pipe( pipe_cmpxchg );
 8128 %}
 8129 
 8130 instruct xchgN( memory mem, rRegN newval) %{
 8131   match(Set newval (GetAndSetN mem newval));
 8132   format %{ "XCHGL  $newval,$mem]" %}
 8133   ins_encode %{
 8134     __ xchgl($newval$$Register, $mem$$Address);
 8135   %}
 8136   ins_pipe( pipe_cmpxchg );
 8137 %}
 8138 
 8139 //----------Abs Instructions-------------------------------------------
 8140 
 8141 // Integer Absolute Instructions
 8142 instruct absI_rReg(rRegI dst, rRegI src, rRegI tmp, rFlagsReg cr)
 8143 %{
 8144   match(Set dst (AbsI src));
 8145   effect(TEMP dst, TEMP tmp, KILL cr);
 8146   format %{ "movl $tmp, $src\n\t"
 8147             "sarl $tmp, 31\n\t"
 8148             "movl $dst, $src\n\t"
 8149             "xorl $dst, $tmp\n\t"
 8150             "subl $dst, $tmp\n"
 8151           %}
 8152   ins_encode %{
 8153     __ movl($tmp$$Register, $src$$Register);
 8154     __ sarl($tmp$$Register, 31);
 8155     __ movl($dst$$Register, $src$$Register);
 8156     __ xorl($dst$$Register, $tmp$$Register);
 8157     __ subl($dst$$Register, $tmp$$Register);
 8158   %}
 8159 
 8160   ins_pipe(ialu_reg_reg);
 8161 %}
 8162 
 8163 // Long Absolute Instructions
 8164 instruct absL_rReg(rRegL dst, rRegL src, rRegL tmp, rFlagsReg cr)
 8165 %{
 8166   match(Set dst (AbsL src));
 8167   effect(TEMP dst, TEMP tmp, KILL cr);
 8168   format %{ "movq $tmp, $src\n\t"
 8169             "sarq $tmp, 63\n\t"
 8170             "movq $dst, $src\n\t"
 8171             "xorq $dst, $tmp\n\t"
 8172             "subq $dst, $tmp\n"
 8173           %}
 8174   ins_encode %{
 8175     __ movq($tmp$$Register, $src$$Register);
 8176     __ sarq($tmp$$Register, 63);
 8177     __ movq($dst$$Register, $src$$Register);
 8178     __ xorq($dst$$Register, $tmp$$Register);
 8179     __ subq($dst$$Register, $tmp$$Register);
 8180   %}
 8181 
 8182   ins_pipe(ialu_reg_reg);
 8183 %}
 8184 
 8185 //----------Subtraction Instructions-------------------------------------------
 8186 
 8187 // Integer Subtraction Instructions
 8188 instruct subI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 8189 %{
 8190   match(Set dst (SubI dst src));
 8191   effect(KILL cr);
 8192 
 8193   format %{ "subl    $dst, $src\t# int" %}
 8194   ins_encode %{
 8195     __ subl($dst$$Register, $src$$Register);
 8196   %}
 8197   ins_pipe(ialu_reg_reg);
 8198 %}
 8199 
 8200 instruct subI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
 8201 %{
 8202   match(Set dst (SubI dst src));
 8203   effect(KILL cr);
 8204 
 8205   format %{ "subl    $dst, $src\t# int" %}
 8206   ins_encode %{
 8207     __ subl($dst$$Register, $src$$constant);
 8208   %}
 8209   ins_pipe(ialu_reg);
 8210 %}
 8211 
 8212 instruct subI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
 8213 %{
 8214   match(Set dst (SubI dst (LoadI src)));
 8215   effect(KILL cr);
 8216 
 8217   ins_cost(125);
 8218   format %{ "subl    $dst, $src\t# int" %}
 8219   ins_encode %{
 8220     __ subl($dst$$Register, $src$$Address);
 8221   %}
 8222   ins_pipe(ialu_reg_mem);
 8223 %}
 8224 
 8225 instruct subI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 8226 %{
 8227   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
 8228   effect(KILL cr);
 8229 
 8230   ins_cost(150);
 8231   format %{ "subl    $dst, $src\t# int" %}
 8232   ins_encode %{
 8233     __ subl($dst$$Address, $src$$Register);
 8234   %}
 8235   ins_pipe(ialu_mem_reg);
 8236 %}
 8237 
 8238 instruct subI_mem_imm(memory dst, immI src, rFlagsReg cr)
 8239 %{
 8240   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
 8241   effect(KILL cr);
 8242 
 8243   ins_cost(125); // XXX
 8244   format %{ "subl    $dst, $src\t# int" %}
 8245   ins_encode %{
 8246     __ subl($dst$$Address, $src$$constant);
 8247   %}
 8248   ins_pipe(ialu_mem_imm);
 8249 %}
 8250 
 8251 instruct subL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
 8252 %{
 8253   match(Set dst (SubL dst src));
 8254   effect(KILL cr);
 8255 
 8256   format %{ "subq    $dst, $src\t# long" %}
 8257   ins_encode %{
 8258     __ subq($dst$$Register, $src$$Register);
 8259   %}
 8260   ins_pipe(ialu_reg_reg);
 8261 %}
 8262 
 8263 instruct subL_rReg_imm(rRegI dst, immL32 src, rFlagsReg cr)
 8264 %{
 8265   match(Set dst (SubL dst src));
 8266   effect(KILL cr);
 8267 
 8268   format %{ "subq    $dst, $src\t# long" %}
 8269   ins_encode %{
 8270     __ subq($dst$$Register, $src$$constant);
 8271   %}
 8272   ins_pipe(ialu_reg);
 8273 %}
 8274 
 8275 instruct subL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
 8276 %{
 8277   match(Set dst (SubL dst (LoadL src)));
 8278   effect(KILL cr);
 8279 
 8280   ins_cost(125);
 8281   format %{ "subq    $dst, $src\t# long" %}
 8282   ins_encode %{
 8283     __ subq($dst$$Register, $src$$Address);
 8284   %}
 8285   ins_pipe(ialu_reg_mem);
 8286 %}
 8287 
 8288 instruct subL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
 8289 %{
 8290   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
 8291   effect(KILL cr);
 8292 
 8293   ins_cost(150);
 8294   format %{ "subq    $dst, $src\t# long" %}
 8295   ins_encode %{
 8296     __ subq($dst$$Address, $src$$Register);
 8297   %}
 8298   ins_pipe(ialu_mem_reg);
 8299 %}
 8300 
 8301 instruct subL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
 8302 %{
 8303   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
 8304   effect(KILL cr);
 8305 
 8306   ins_cost(125); // XXX
 8307   format %{ "subq    $dst, $src\t# long" %}
 8308   ins_encode %{
 8309     __ subq($dst$$Address, $src$$constant);
 8310   %}
 8311   ins_pipe(ialu_mem_imm);
 8312 %}
 8313 
 8314 // Subtract from a pointer
 8315 // XXX hmpf???
 8316 instruct subP_rReg(rRegP dst, rRegI src, immI_0 zero, rFlagsReg cr)
 8317 %{
 8318   match(Set dst (AddP dst (SubI zero src)));
 8319   effect(KILL cr);
 8320 
 8321   format %{ "subq    $dst, $src\t# ptr - int" %}
 8322   opcode(0x2B);
 8323   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
 8324   ins_pipe(ialu_reg_reg);
 8325 %}
 8326 
 8327 instruct negI_rReg(rRegI dst, immI_0 zero, rFlagsReg cr)
 8328 %{
 8329   match(Set dst (SubI zero dst));
 8330   effect(KILL cr);
 8331 
 8332   format %{ "negl    $dst\t# int" %}
 8333   ins_encode %{
 8334     __ negl($dst$$Register);
 8335   %}
 8336   ins_pipe(ialu_reg);
 8337 %}
 8338 
 8339 instruct negI_rReg_2(rRegI dst, rFlagsReg cr)
 8340 %{
 8341   match(Set dst (NegI dst));
 8342   effect(KILL cr);
 8343 
 8344   format %{ "negl    $dst\t# int" %}
 8345   ins_encode %{
 8346     __ negl($dst$$Register);
 8347   %}
 8348   ins_pipe(ialu_reg);
 8349 %}
 8350 
 8351 instruct negI_mem(memory dst, immI_0 zero, rFlagsReg cr)
 8352 %{
 8353   match(Set dst (StoreI dst (SubI zero (LoadI dst))));
 8354   effect(KILL cr);
 8355 
 8356   format %{ "negl    $dst\t# int" %}
 8357   ins_encode %{
 8358     __ negl($dst$$Address);
 8359   %}
 8360   ins_pipe(ialu_reg);
 8361 %}
 8362 
 8363 instruct negL_rReg(rRegL dst, immL0 zero, rFlagsReg cr)
 8364 %{
 8365   match(Set dst (SubL zero dst));
 8366   effect(KILL cr);
 8367 
 8368   format %{ "negq    $dst\t# long" %}
 8369   ins_encode %{
 8370     __ negq($dst$$Register);
 8371   %}
 8372   ins_pipe(ialu_reg);
 8373 %}
 8374 
 8375 instruct negL_rReg_2(rRegL dst, rFlagsReg cr)
 8376 %{
 8377   match(Set dst (NegL dst));
 8378   effect(KILL cr);
 8379 
 8380   format %{ "negq    $dst\t# int" %}
 8381   ins_encode %{
 8382     __ negq($dst$$Register);
 8383   %}
 8384   ins_pipe(ialu_reg);
 8385 %}
 8386 
 8387 instruct negL_mem(memory dst, immL0 zero, rFlagsReg cr)
 8388 %{
 8389   match(Set dst (StoreL dst (SubL zero (LoadL dst))));
 8390   effect(KILL cr);
 8391 
 8392   format %{ "negq    $dst\t# long" %}
 8393   ins_encode %{
 8394     __ negq($dst$$Address);
 8395   %}
 8396   ins_pipe(ialu_reg);
 8397 %}
 8398 
 8399 //----------Multiplication/Division Instructions-------------------------------
 8400 // Integer Multiplication Instructions
 8401 // Multiply Register
 8402 
 8403 instruct mulI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 8404 %{
 8405   match(Set dst (MulI dst src));
 8406   effect(KILL cr);
 8407 
 8408   ins_cost(300);
 8409   format %{ "imull   $dst, $src\t# int" %}
 8410   ins_encode %{
 8411     __ imull($dst$$Register, $src$$Register);
 8412   %}
 8413   ins_pipe(ialu_reg_reg_alu0);
 8414 %}
 8415 
 8416 instruct mulI_rReg_imm(rRegI dst, rRegI src, immI imm, rFlagsReg cr)
 8417 %{
 8418   match(Set dst (MulI src imm));
 8419   effect(KILL cr);
 8420 
 8421   ins_cost(300);
 8422   format %{ "imull   $dst, $src, $imm\t# int" %}
 8423   ins_encode %{
 8424     __ imull($dst$$Register, $src$$Register, $imm$$constant);
 8425   %}
 8426   ins_pipe(ialu_reg_reg_alu0);
 8427 %}
 8428 
 8429 instruct mulI_mem(rRegI dst, memory src, rFlagsReg cr)
 8430 %{
 8431   match(Set dst (MulI dst (LoadI src)));
 8432   effect(KILL cr);
 8433 
 8434   ins_cost(350);
 8435   format %{ "imull   $dst, $src\t# int" %}
 8436   ins_encode %{
 8437     __ imull($dst$$Register, $src$$Address);
 8438   %}
 8439   ins_pipe(ialu_reg_mem_alu0);
 8440 %}
 8441 
 8442 instruct mulI_mem_imm(rRegI dst, memory src, immI imm, rFlagsReg cr)
 8443 %{
 8444   match(Set dst (MulI (LoadI src) imm));
 8445   effect(KILL cr);
 8446 
 8447   ins_cost(300);
 8448   format %{ "imull   $dst, $src, $imm\t# int" %}
 8449   ins_encode %{
 8450     __ imull($dst$$Register, $src$$Address, $imm$$constant);
 8451   %}
 8452   ins_pipe(ialu_reg_mem_alu0);
 8453 %}
 8454 
 8455 instruct mulAddS2I_rReg(rRegI dst, rRegI src1, rRegI src2, rRegI src3, rFlagsReg cr)
 8456 %{
 8457   match(Set dst (MulAddS2I (Binary dst src1) (Binary src2 src3)));
 8458   effect(KILL cr, KILL src2);
 8459 
 8460   expand %{ mulI_rReg(dst, src1, cr);
 8461            mulI_rReg(src2, src3, cr);
 8462            addI_rReg(dst, src2, cr); %}
 8463 %}
 8464 
 8465 instruct mulL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
 8466 %{
 8467   match(Set dst (MulL dst src));
 8468   effect(KILL cr);
 8469 
 8470   ins_cost(300);
 8471   format %{ "imulq   $dst, $src\t# long" %}
 8472   ins_encode %{
 8473     __ imulq($dst$$Register, $src$$Register);
 8474   %}
 8475   ins_pipe(ialu_reg_reg_alu0);
 8476 %}
 8477 
 8478 instruct mulL_rReg_imm(rRegL dst, rRegL src, immL32 imm, rFlagsReg cr)
 8479 %{
 8480   match(Set dst (MulL src imm));
 8481   effect(KILL cr);
 8482 
 8483   ins_cost(300);
 8484   format %{ "imulq   $dst, $src, $imm\t# long" %}
 8485   ins_encode %{
 8486     __ imulq($dst$$Register, $src$$Register, $imm$$constant);
 8487   %}
 8488   ins_pipe(ialu_reg_reg_alu0);
 8489 %}
 8490 
 8491 instruct mulL_mem(rRegL dst, memory src, rFlagsReg cr)
 8492 %{
 8493   match(Set dst (MulL dst (LoadL src)));
 8494   effect(KILL cr);
 8495 
 8496   ins_cost(350);
 8497   format %{ "imulq   $dst, $src\t# long" %}
 8498   ins_encode %{
 8499     __ imulq($dst$$Register, $src$$Address);
 8500   %}
 8501   ins_pipe(ialu_reg_mem_alu0);
 8502 %}
 8503 
 8504 instruct mulL_mem_imm(rRegL dst, memory src, immL32 imm, rFlagsReg cr)
 8505 %{
 8506   match(Set dst (MulL (LoadL src) imm));
 8507   effect(KILL cr);
 8508 
 8509   ins_cost(300);
 8510   format %{ "imulq   $dst, $src, $imm\t# long" %}
 8511   ins_encode %{
 8512     __ imulq($dst$$Register, $src$$Address, $imm$$constant);
 8513   %}
 8514   ins_pipe(ialu_reg_mem_alu0);
 8515 %}
 8516 
 8517 instruct mulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
 8518 %{
 8519   match(Set dst (MulHiL src rax));
 8520   effect(USE_KILL rax, KILL cr);
 8521 
 8522   ins_cost(300);
 8523   format %{ "imulq   RDX:RAX, RAX, $src\t# mulhi" %}
 8524   ins_encode %{
 8525     __ imulq($src$$Register);
 8526   %}
 8527   ins_pipe(ialu_reg_reg_alu0);
 8528 %}
 8529 
 8530 instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
 8531                    rFlagsReg cr)
 8532 %{
 8533   match(Set rax (DivI rax div));
 8534   effect(KILL rdx, KILL cr);
 8535 
 8536   ins_cost(30*100+10*100); // XXX
 8537   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
 8538             "jne,s   normal\n\t"
 8539             "xorl    rdx, rdx\n\t"
 8540             "cmpl    $div, -1\n\t"
 8541             "je,s    done\n"
 8542     "normal: cdql\n\t"
 8543             "idivl   $div\n"
 8544     "done:"        %}
 8545   ins_encode(cdql_enc(div));
 8546   ins_pipe(ialu_reg_reg_alu0);
 8547 %}
 8548 
 8549 instruct divL_rReg(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
 8550                    rFlagsReg cr)
 8551 %{
 8552   match(Set rax (DivL rax div));
 8553   effect(KILL rdx, KILL cr);
 8554 
 8555   ins_cost(30*100+10*100); // XXX
 8556   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
 8557             "cmpq    rax, rdx\n\t"
 8558             "jne,s   normal\n\t"
 8559             "xorl    rdx, rdx\n\t"
 8560             "cmpq    $div, -1\n\t"
 8561             "je,s    done\n"
 8562     "normal: cdqq\n\t"
 8563             "idivq   $div\n"
 8564     "done:"        %}
 8565   ins_encode(cdqq_enc(div));
 8566   ins_pipe(ialu_reg_reg_alu0);
 8567 %}
 8568 
 8569 // Integer DIVMOD with Register, both quotient and mod results
 8570 instruct divModI_rReg_divmod(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
 8571                              rFlagsReg cr)
 8572 %{
 8573   match(DivModI rax div);
 8574   effect(KILL cr);
 8575 
 8576   ins_cost(30*100+10*100); // XXX
 8577   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
 8578             "jne,s   normal\n\t"
 8579             "xorl    rdx, rdx\n\t"
 8580             "cmpl    $div, -1\n\t"
 8581             "je,s    done\n"
 8582     "normal: cdql\n\t"
 8583             "idivl   $div\n"
 8584     "done:"        %}
 8585   ins_encode(cdql_enc(div));
 8586   ins_pipe(pipe_slow);
 8587 %}
 8588 
 8589 // Long DIVMOD with Register, both quotient and mod results
 8590 instruct divModL_rReg_divmod(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
 8591                              rFlagsReg cr)
 8592 %{
 8593   match(DivModL rax div);
 8594   effect(KILL cr);
 8595 
 8596   ins_cost(30*100+10*100); // XXX
 8597   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
 8598             "cmpq    rax, rdx\n\t"
 8599             "jne,s   normal\n\t"
 8600             "xorl    rdx, rdx\n\t"
 8601             "cmpq    $div, -1\n\t"
 8602             "je,s    done\n"
 8603     "normal: cdqq\n\t"
 8604             "idivq   $div\n"
 8605     "done:"        %}
 8606   ins_encode(cdqq_enc(div));
 8607   ins_pipe(pipe_slow);
 8608 %}
 8609 
 8610 //----------- DivL-By-Constant-Expansions--------------------------------------
 8611 // DivI cases are handled by the compiler
 8612 
 8613 // Magic constant, reciprocal of 10
 8614 instruct loadConL_0x6666666666666667(rRegL dst)
 8615 %{
 8616   effect(DEF dst);
 8617 
 8618   format %{ "movq    $dst, #0x666666666666667\t# Used in div-by-10" %}
 8619   ins_encode(load_immL(dst, 0x6666666666666667));
 8620   ins_pipe(ialu_reg);
 8621 %}
 8622 
 8623 instruct mul_hi(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
 8624 %{
 8625   effect(DEF dst, USE src, USE_KILL rax, KILL cr);
 8626 
 8627   format %{ "imulq   rdx:rax, rax, $src\t# Used in div-by-10" %}
 8628   ins_encode %{
 8629     __ imulq($src$$Register);
 8630   %}
 8631   ins_pipe(ialu_reg_reg_alu0);
 8632 %}
 8633 
 8634 instruct sarL_rReg_63(rRegL dst, rFlagsReg cr)
 8635 %{
 8636   effect(USE_DEF dst, KILL cr);
 8637 
 8638   format %{ "sarq    $dst, #63\t# Used in div-by-10" %}
 8639   ins_encode %{
 8640     __ sarq($dst$$Register, 63);
 8641   %}
 8642   ins_pipe(ialu_reg);
 8643 %}
 8644 
 8645 instruct sarL_rReg_2(rRegL dst, rFlagsReg cr)
 8646 %{
 8647   effect(USE_DEF dst, KILL cr);
 8648 
 8649   format %{ "sarq    $dst, #2\t# Used in div-by-10" %}
 8650   ins_encode %{
 8651     __ sarq($dst$$Register, 2);
 8652   %}
 8653   ins_pipe(ialu_reg);
 8654 %}
 8655 
 8656 instruct divL_10(rdx_RegL dst, no_rax_RegL src, immL10 div)
 8657 %{
 8658   match(Set dst (DivL src div));
 8659 
 8660   ins_cost((5+8)*100);
 8661   expand %{
 8662     rax_RegL rax;                     // Killed temp
 8663     rFlagsReg cr;                     // Killed
 8664     loadConL_0x6666666666666667(rax); // movq  rax, 0x6666666666666667
 8665     mul_hi(dst, src, rax, cr);        // mulq  rdx:rax <= rax * $src
 8666     sarL_rReg_63(src, cr);            // sarq  src, 63
 8667     sarL_rReg_2(dst, cr);             // sarq  rdx, 2
 8668     subL_rReg(dst, src, cr);          // subl  rdx, src
 8669   %}
 8670 %}
 8671 
 8672 //-----------------------------------------------------------------------------
 8673 
 8674 instruct modI_rReg(rdx_RegI rdx, rax_RegI rax, no_rax_rdx_RegI div,
 8675                    rFlagsReg cr)
 8676 %{
 8677   match(Set rdx (ModI rax div));
 8678   effect(KILL rax, KILL cr);
 8679 
 8680   ins_cost(300); // XXX
 8681   format %{ "cmpl    rax, 0x80000000\t# irem\n\t"
 8682             "jne,s   normal\n\t"
 8683             "xorl    rdx, rdx\n\t"
 8684             "cmpl    $div, -1\n\t"
 8685             "je,s    done\n"
 8686     "normal: cdql\n\t"
 8687             "idivl   $div\n"
 8688     "done:"        %}
 8689   ins_encode(cdql_enc(div));
 8690   ins_pipe(ialu_reg_reg_alu0);
 8691 %}
 8692 
 8693 instruct modL_rReg(rdx_RegL rdx, rax_RegL rax, no_rax_rdx_RegL div,
 8694                    rFlagsReg cr)
 8695 %{
 8696   match(Set rdx (ModL rax div));
 8697   effect(KILL rax, KILL cr);
 8698 
 8699   ins_cost(300); // XXX
 8700   format %{ "movq    rdx, 0x8000000000000000\t# lrem\n\t"
 8701             "cmpq    rax, rdx\n\t"
 8702             "jne,s   normal\n\t"
 8703             "xorl    rdx, rdx\n\t"
 8704             "cmpq    $div, -1\n\t"
 8705             "je,s    done\n"
 8706     "normal: cdqq\n\t"
 8707             "idivq   $div\n"
 8708     "done:"        %}
 8709   ins_encode(cdqq_enc(div));
 8710   ins_pipe(ialu_reg_reg_alu0);
 8711 %}
 8712 
 8713 // Integer Shift Instructions
 8714 // Shift Left by one
 8715 instruct salI_rReg_1(rRegI dst, immI_1 shift, rFlagsReg cr)
 8716 %{
 8717   match(Set dst (LShiftI dst shift));
 8718   effect(KILL cr);
 8719 
 8720   format %{ "sall    $dst, $shift" %}
 8721   ins_encode %{
 8722     __ sall($dst$$Register, $shift$$constant);
 8723   %}
 8724   ins_pipe(ialu_reg);
 8725 %}
 8726 
 8727 // Shift Left by one
 8728 instruct salI_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 8729 %{
 8730   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
 8731   effect(KILL cr);
 8732 
 8733   format %{ "sall    $dst, $shift\t" %}
 8734   ins_encode %{
 8735     __ sall($dst$$Address, $shift$$constant);
 8736   %}
 8737   ins_pipe(ialu_mem_imm);
 8738 %}
 8739 
 8740 // Shift Left by 8-bit immediate
 8741 instruct salI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
 8742 %{
 8743   match(Set dst (LShiftI dst shift));
 8744   effect(KILL cr);
 8745 
 8746   format %{ "sall    $dst, $shift" %}
 8747   ins_encode %{
 8748     __ sall($dst$$Register, $shift$$constant);
 8749   %}
 8750   ins_pipe(ialu_reg);
 8751 %}
 8752 
 8753 // Shift Left by 8-bit immediate
 8754 instruct salI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 8755 %{
 8756   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
 8757   effect(KILL cr);
 8758 
 8759   format %{ "sall    $dst, $shift" %}
 8760   ins_encode %{
 8761     __ sall($dst$$Address, $shift$$constant);
 8762   %}
 8763   ins_pipe(ialu_mem_imm);
 8764 %}
 8765 
 8766 // Shift Left by variable
 8767 instruct salI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
 8768 %{
 8769   match(Set dst (LShiftI dst shift));
 8770   effect(KILL cr);
 8771 
 8772   format %{ "sall    $dst, $shift" %}
 8773   ins_encode %{
 8774     __ sall($dst$$Register);
 8775   %}
 8776   ins_pipe(ialu_reg_reg);
 8777 %}
 8778 
 8779 // Shift Left by variable
 8780 instruct salI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 8781 %{
 8782   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
 8783   effect(KILL cr);
 8784 
 8785   format %{ "sall    $dst, $shift" %}
 8786   ins_encode %{
 8787     __ sall($dst$$Address);
 8788   %}
 8789   ins_pipe(ialu_mem_reg);
 8790 %}
 8791 
 8792 // Arithmetic shift right by one
 8793 instruct sarI_rReg_1(rRegI dst, immI_1 shift, rFlagsReg cr)
 8794 %{
 8795   match(Set dst (RShiftI dst shift));
 8796   effect(KILL cr);
 8797 
 8798   format %{ "sarl    $dst, $shift" %}
 8799   ins_encode %{
 8800     __ sarl($dst$$Register, $shift$$constant);
 8801   %}
 8802   ins_pipe(ialu_reg);
 8803 %}
 8804 
 8805 // Arithmetic shift right by one
 8806 instruct sarI_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 8807 %{
 8808   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
 8809   effect(KILL cr);
 8810 
 8811   format %{ "sarl    $dst, $shift" %}
 8812   ins_encode %{
 8813     __ sarl($dst$$Address, $shift$$constant);
 8814   %}
 8815   ins_pipe(ialu_mem_imm);
 8816 %}
 8817 
 8818 // Arithmetic Shift Right by 8-bit immediate
 8819 instruct sarI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
 8820 %{
 8821   match(Set dst (RShiftI dst shift));
 8822   effect(KILL cr);
 8823 
 8824   format %{ "sarl    $dst, $shift" %}
 8825   ins_encode %{
 8826     __ sarl($dst$$Register, $shift$$constant);
 8827   %}
 8828   ins_pipe(ialu_mem_imm);
 8829 %}
 8830 
 8831 // Arithmetic Shift Right by 8-bit immediate
 8832 instruct sarI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 8833 %{
 8834   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
 8835   effect(KILL cr);
 8836 
 8837   format %{ "sarl    $dst, $shift" %}
 8838   ins_encode %{
 8839     __ sarl($dst$$Address, $shift$$constant);
 8840   %}
 8841   ins_pipe(ialu_mem_imm);
 8842 %}
 8843 
 8844 // Arithmetic Shift Right by variable
 8845 instruct sarI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
 8846 %{
 8847   match(Set dst (RShiftI dst shift));
 8848   effect(KILL cr);
 8849   format %{ "sarl    $dst, $shift" %}
 8850   ins_encode %{
 8851     __ sarl($dst$$Register);
 8852   %}
 8853   ins_pipe(ialu_reg_reg);
 8854 %}
 8855 
 8856 // Arithmetic Shift Right by variable
 8857 instruct sarI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 8858 %{
 8859   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
 8860   effect(KILL cr);
 8861 
 8862   format %{ "sarl    $dst, $shift" %}
 8863   ins_encode %{
 8864     __ sarl($dst$$Address);
 8865   %}
 8866   ins_pipe(ialu_mem_reg);
 8867 %}
 8868 
 8869 // Logical shift right by one
 8870 instruct shrI_rReg_1(rRegI dst, immI_1 shift, rFlagsReg cr)
 8871 %{
 8872   match(Set dst (URShiftI dst shift));
 8873   effect(KILL cr);
 8874 
 8875   format %{ "shrl    $dst, $shift" %}
 8876   ins_encode %{
 8877     __ shrl($dst$$Register, $shift$$constant);
 8878   %}
 8879   ins_pipe(ialu_reg);
 8880 %}
 8881 
 8882 // Logical shift right by one
 8883 instruct shrI_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 8884 %{
 8885   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
 8886   effect(KILL cr);
 8887 
 8888   format %{ "shrl    $dst, $shift" %}
 8889   ins_encode %{
 8890     __ shrl($dst$$Address, $shift$$constant);
 8891   %}
 8892   ins_pipe(ialu_mem_imm);
 8893 %}
 8894 
 8895 // Logical Shift Right by 8-bit immediate
 8896 instruct shrI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
 8897 %{
 8898   match(Set dst (URShiftI dst shift));
 8899   effect(KILL cr);
 8900 
 8901   format %{ "shrl    $dst, $shift" %}
 8902   ins_encode %{
 8903     __ shrl($dst$$Register, $shift$$constant);
 8904   %}
 8905   ins_pipe(ialu_reg);
 8906 %}
 8907 
 8908 // Logical Shift Right by 8-bit immediate
 8909 instruct shrI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 8910 %{
 8911   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
 8912   effect(KILL cr);
 8913 
 8914   format %{ "shrl    $dst, $shift" %}
 8915   ins_encode %{
 8916     __ shrl($dst$$Address, $shift$$constant);
 8917   %}
 8918   ins_pipe(ialu_mem_imm);
 8919 %}
 8920 
 8921 // Logical Shift Right by variable
 8922 instruct shrI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
 8923 %{
 8924   match(Set dst (URShiftI dst shift));
 8925   effect(KILL cr);
 8926 
 8927   format %{ "shrl    $dst, $shift" %}
 8928   ins_encode %{
 8929     __ shrl($dst$$Register);
 8930   %}
 8931   ins_pipe(ialu_reg_reg);
 8932 %}
 8933 
 8934 // Logical Shift Right by variable
 8935 instruct shrI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 8936 %{
 8937   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
 8938   effect(KILL cr);
 8939 
 8940   format %{ "shrl    $dst, $shift" %}
 8941   ins_encode %{
 8942     __ shrl($dst$$Address);
 8943   %}
 8944   ins_pipe(ialu_mem_reg);
 8945 %}
 8946 
 8947 // Long Shift Instructions
 8948 // Shift Left by one
 8949 instruct salL_rReg_1(rRegL dst, immI_1 shift, rFlagsReg cr)
 8950 %{
 8951   match(Set dst (LShiftL dst shift));
 8952   effect(KILL cr);
 8953 
 8954   format %{ "salq    $dst, $shift" %}
 8955   ins_encode %{
 8956     __ salq($dst$$Register, $shift$$constant);
 8957   %}
 8958   ins_pipe(ialu_reg);
 8959 %}
 8960 
 8961 // Shift Left by one
 8962 instruct salL_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 8963 %{
 8964   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
 8965   effect(KILL cr);
 8966 
 8967   format %{ "salq    $dst, $shift" %}
 8968   ins_encode %{
 8969     __ salq($dst$$Address, $shift$$constant);
 8970   %}
 8971   ins_pipe(ialu_mem_imm);
 8972 %}
 8973 
 8974 // Shift Left by 8-bit immediate
 8975 instruct salL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
 8976 %{
 8977   match(Set dst (LShiftL dst shift));
 8978   effect(KILL cr);
 8979 
 8980   format %{ "salq    $dst, $shift" %}
 8981   ins_encode %{
 8982     __ salq($dst$$Register, $shift$$constant);
 8983   %}
 8984   ins_pipe(ialu_reg);
 8985 %}
 8986 
 8987 // Shift Left by 8-bit immediate
 8988 instruct salL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 8989 %{
 8990   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
 8991   effect(KILL cr);
 8992 
 8993   format %{ "salq    $dst, $shift" %}
 8994   ins_encode %{
 8995     __ salq($dst$$Address, $shift$$constant);
 8996   %}
 8997   ins_pipe(ialu_mem_imm);
 8998 %}
 8999 
 9000 // Shift Left by variable
 9001 instruct salL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
 9002 %{
 9003   match(Set dst (LShiftL dst shift));
 9004   effect(KILL cr);
 9005 
 9006   format %{ "salq    $dst, $shift" %}
 9007   ins_encode %{
 9008     __ salq($dst$$Register);
 9009   %}
 9010   ins_pipe(ialu_reg_reg);
 9011 %}
 9012 
 9013 // Shift Left by variable
 9014 instruct salL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 9015 %{
 9016   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
 9017   effect(KILL cr);
 9018 
 9019   format %{ "salq    $dst, $shift" %}
 9020   ins_encode %{
 9021     __ salq($dst$$Address);
 9022   %}
 9023   ins_pipe(ialu_mem_reg);
 9024 %}
 9025 
 9026 // Arithmetic shift right by one
 9027 instruct sarL_rReg_1(rRegL dst, immI_1 shift, rFlagsReg cr)
 9028 %{
 9029   match(Set dst (RShiftL dst shift));
 9030   effect(KILL cr);
 9031 
 9032   format %{ "sarq    $dst, $shift" %}
 9033   ins_encode %{
 9034     __ sarq($dst$$Register, $shift$$constant);
 9035   %}
 9036   ins_pipe(ialu_reg);
 9037 %}
 9038 
 9039 // Arithmetic shift right by one
 9040 instruct sarL_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 9041 %{
 9042   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
 9043   effect(KILL cr);
 9044 
 9045   format %{ "sarq    $dst, $shift" %}
 9046   ins_encode %{
 9047     __ sarq($dst$$Address, $shift$$constant);
 9048   %}
 9049   ins_pipe(ialu_mem_imm);
 9050 %}
 9051 
 9052 // Arithmetic Shift Right by 8-bit immediate
 9053 instruct sarL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
 9054 %{
 9055   match(Set dst (RShiftL dst shift));
 9056   effect(KILL cr);
 9057 
 9058   format %{ "sarq    $dst, $shift" %}
 9059   ins_encode %{
 9060     __ sarq($dst$$Register, (unsigned char)($shift$$constant & 0x3F));
 9061   %}
 9062   ins_pipe(ialu_mem_imm);
 9063 %}
 9064 
 9065 // Arithmetic Shift Right by 8-bit immediate
 9066 instruct sarL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 9067 %{
 9068   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
 9069   effect(KILL cr);
 9070 
 9071   format %{ "sarq    $dst, $shift" %}
 9072   ins_encode %{
 9073     __ sarq($dst$$Address, (unsigned char)($shift$$constant & 0x3F));
 9074   %}
 9075   ins_pipe(ialu_mem_imm);
 9076 %}
 9077 
 9078 // Arithmetic Shift Right by variable
 9079 instruct sarL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
 9080 %{
 9081   match(Set dst (RShiftL dst shift));
 9082   effect(KILL cr);
 9083 
 9084   format %{ "sarq    $dst, $shift" %}
 9085   ins_encode %{
 9086     __ sarq($dst$$Register);
 9087   %}
 9088   ins_pipe(ialu_reg_reg);
 9089 %}
 9090 
 9091 // Arithmetic Shift Right by variable
 9092 instruct sarL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 9093 %{
 9094   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
 9095   effect(KILL cr);
 9096 
 9097   format %{ "sarq    $dst, $shift" %}
 9098   ins_encode %{
 9099     __ sarq($dst$$Address);
 9100   %}
 9101   ins_pipe(ialu_mem_reg);
 9102 %}
 9103 
 9104 // Logical shift right by one
 9105 instruct shrL_rReg_1(rRegL dst, immI_1 shift, rFlagsReg cr)
 9106 %{
 9107   match(Set dst (URShiftL dst shift));
 9108   effect(KILL cr);
 9109 
 9110   format %{ "shrq    $dst, $shift" %}
 9111   ins_encode %{
 9112     __ shrq($dst$$Register, $shift$$constant);
 9113   %}
 9114   ins_pipe(ialu_reg);
 9115 %}
 9116 
 9117 // Logical shift right by one
 9118 instruct shrL_mem_1(memory dst, immI_1 shift, rFlagsReg cr)
 9119 %{
 9120   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
 9121   effect(KILL cr);
 9122 
 9123   format %{ "shrq    $dst, $shift" %}
 9124   ins_encode %{
 9125     __ shrq($dst$$Address, $shift$$constant);
 9126   %}
 9127   ins_pipe(ialu_mem_imm);
 9128 %}
 9129 
 9130 // Logical Shift Right by 8-bit immediate
 9131 instruct shrL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
 9132 %{
 9133   match(Set dst (URShiftL dst shift));
 9134   effect(KILL cr);
 9135 
 9136   format %{ "shrq    $dst, $shift" %}
 9137   ins_encode %{
 9138     __ shrq($dst$$Register, $shift$$constant);
 9139   %}
 9140   ins_pipe(ialu_reg);
 9141 %}
 9142 
 9143 // Logical Shift Right by 8-bit immediate
 9144 instruct shrL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
 9145 %{
 9146   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
 9147   effect(KILL cr);
 9148 
 9149   format %{ "shrq    $dst, $shift" %}
 9150   ins_encode %{
 9151     __ shrq($dst$$Address, $shift$$constant);
 9152   %}
 9153   ins_pipe(ialu_mem_imm);
 9154 %}
 9155 
 9156 // Logical Shift Right by variable
 9157 instruct shrL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
 9158 %{
 9159   match(Set dst (URShiftL dst shift));
 9160   effect(KILL cr);
 9161 
 9162   format %{ "shrq    $dst, $shift" %}
 9163   ins_encode %{
 9164     __ shrq($dst$$Register);
 9165   %}
 9166   ins_pipe(ialu_reg_reg);
 9167 %}
 9168 
 9169 // Logical Shift Right by variable
 9170 instruct shrL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
 9171 %{
 9172   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
 9173   effect(KILL cr);
 9174 
 9175   format %{ "shrq    $dst, $shift" %}
 9176   ins_encode %{
 9177     __ shrq($dst$$Address);
 9178   %}
 9179   ins_pipe(ialu_mem_reg);
 9180 %}
 9181 
 9182 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
 9183 // This idiom is used by the compiler for the i2b bytecode.
 9184 instruct i2b(rRegI dst, rRegI src, immI_24 twentyfour)
 9185 %{
 9186   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
 9187 
 9188   format %{ "movsbl  $dst, $src\t# i2b" %}
 9189   ins_encode %{
 9190     __ movsbl($dst$$Register, $src$$Register);
 9191   %}
 9192   ins_pipe(ialu_reg_reg);
 9193 %}
 9194 
 9195 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
 9196 // This idiom is used by the compiler the i2s bytecode.
 9197 instruct i2s(rRegI dst, rRegI src, immI_16 sixteen)
 9198 %{
 9199   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
 9200 
 9201   format %{ "movswl  $dst, $src\t# i2s" %}
 9202   ins_encode %{
 9203     __ movswl($dst$$Register, $src$$Register);
 9204   %}
 9205   ins_pipe(ialu_reg_reg);
 9206 %}
 9207 
 9208 // ROL/ROR instructions
 9209 
 9210 // Rotate left by constant.
 9211 instruct rolI_imm(rRegI dst, immI8 shift, rFlagsReg cr)
 9212 %{
 9213   predicate(n->bottom_type()->basic_type() == T_INT);
 9214   match(Set dst (RotateLeft dst shift));
 9215   effect(KILL cr);
 9216   format %{ "roll    $dst, $shift" %}
 9217   ins_encode %{
 9218     __ roll($dst$$Register, $shift$$constant);
 9219   %}
 9220   ins_pipe(ialu_reg);
 9221 %}
 9222 
 9223 // Rotate Left by variable
 9224 instruct rolI_rReg_Var(rRegI dst, rcx_RegI shift, rFlagsReg cr)
 9225 %{
 9226   predicate(n->bottom_type()->basic_type() == T_INT);
 9227   match(Set dst (RotateLeft dst shift));
 9228   effect(KILL cr);
 9229   format %{ "roll    $dst, $shift" %}
 9230   ins_encode %{
 9231     __ roll($dst$$Register);
 9232   %}
 9233   ins_pipe(ialu_reg_reg);
 9234 %}
 9235 
 9236 // Rotate Right by constant.
 9237 instruct rorI_immI8_legacy(rRegI dst, immI8 shift, rFlagsReg cr)
 9238 %{
 9239   predicate(!VM_Version::supports_bmi2() && n->bottom_type()->basic_type() == T_INT);
 9240   match(Set dst (RotateRight dst shift));
 9241   effect(KILL cr);
 9242   format %{ "rorl    $dst, $shift" %}
 9243   ins_encode %{
 9244     __ rorl($dst$$Register, $shift$$constant);
 9245   %}
 9246   ins_pipe(ialu_reg);
 9247 %}
 9248 
 9249 // Rotate Right by constant.
 9250 instruct rorI_immI8(rRegI dst, immI8 shift)
 9251 %{
 9252   predicate(VM_Version::supports_bmi2() && n->bottom_type()->basic_type() == T_INT);
 9253   match(Set dst (RotateRight dst shift));
 9254   format %{ "rorxd     $dst, $shift" %}
 9255   ins_encode %{
 9256     __ rorxd($dst$$Register, $dst$$Register, $shift$$constant);
 9257   %}
 9258   ins_pipe(ialu_reg_reg);
 9259 %}
 9260 
 9261 // Rotate Right by variable
 9262 instruct rorI_rReg_Var(rRegI dst, rcx_RegI shift, rFlagsReg cr)
 9263 %{
 9264   predicate(n->bottom_type()->basic_type() == T_INT);
 9265   match(Set dst (RotateRight dst shift));
 9266   effect(KILL cr);
 9267   format %{ "rorl    $dst, $shift" %}
 9268   ins_encode %{
 9269     __ rorl($dst$$Register);
 9270   %}
 9271   ins_pipe(ialu_reg_reg);
 9272 %}
 9273 
 9274 
 9275 // Rotate Left by constant.
 9276 instruct rolL_immI8(rRegL dst, immI8 shift, rFlagsReg cr)
 9277 %{
 9278   predicate(n->bottom_type()->basic_type() == T_LONG);
 9279   match(Set dst (RotateLeft dst shift));
 9280   effect(KILL cr);
 9281   format %{ "rolq    $dst, $shift" %}
 9282   ins_encode %{
 9283     __ rolq($dst$$Register, $shift$$constant);
 9284   %}
 9285   ins_pipe(ialu_reg);
 9286 %}
 9287 
 9288 // Rotate Left by variable
 9289 instruct rolL_rReg_Var(rRegL dst, rcx_RegI shift, rFlagsReg cr)
 9290 %{
 9291   predicate(n->bottom_type()->basic_type() == T_LONG);
 9292   match(Set dst (RotateLeft dst shift));
 9293   effect(KILL cr);
 9294   format %{ "rolq    $dst, $shift" %}
 9295   ins_encode %{
 9296     __ rolq($dst$$Register);
 9297   %}
 9298   ins_pipe(ialu_reg_reg);
 9299 %}
 9300 
 9301 
 9302 // Rotate Right by constant.
 9303 instruct rorL_immI8_legacy(rRegL dst, immI8 shift, rFlagsReg cr)
 9304 %{
 9305   predicate(!VM_Version::supports_bmi2() && n->bottom_type()->basic_type() == T_LONG);
 9306   match(Set dst (RotateRight dst shift));
 9307   effect(KILL cr);
 9308   format %{ "rorq    $dst, $shift" %}
 9309   ins_encode %{
 9310     __ rorq($dst$$Register, $shift$$constant);
 9311   %}
 9312   ins_pipe(ialu_reg);
 9313 %}
 9314 
 9315 
 9316 // Rotate Right by constant
 9317 instruct rorL_immI8(rRegL dst, immI8 shift)
 9318 %{
 9319   predicate(VM_Version::supports_bmi2() && n->bottom_type()->basic_type() == T_LONG);
 9320   match(Set dst (RotateRight dst shift));
 9321   format %{ "rorxq    $dst, $shift" %}
 9322   ins_encode %{
 9323     __ rorxq($dst$$Register, $dst$$Register, $shift$$constant);
 9324   %}
 9325   ins_pipe(ialu_reg_reg);
 9326 %}
 9327 
 9328 // Rotate Right by variable
 9329 instruct rorL_rReg_Var(rRegL dst, rcx_RegI shift, rFlagsReg cr)
 9330 %{
 9331   predicate(n->bottom_type()->basic_type() == T_LONG);
 9332   match(Set dst (RotateRight dst shift));
 9333   effect(KILL cr);
 9334   format %{ "rorq    $dst, $shift" %}
 9335   ins_encode %{
 9336     __ rorq($dst$$Register);
 9337   %}
 9338   ins_pipe(ialu_reg_reg);
 9339 %}
 9340 
 9341 
 9342 // Logical Instructions
 9343 
 9344 // Integer Logical Instructions
 9345 
 9346 // And Instructions
 9347 // And Register with Register
 9348 instruct andI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 9349 %{
 9350   match(Set dst (AndI dst src));
 9351   effect(KILL cr);
 9352 
 9353   format %{ "andl    $dst, $src\t# int" %}
 9354   ins_encode %{
 9355     __ andl($dst$$Register, $src$$Register);
 9356   %}
 9357   ins_pipe(ialu_reg_reg);
 9358 %}
 9359 
 9360 // And Register with Immediate 255
 9361 instruct andI_rReg_imm255(rRegI dst, immI_255 src)
 9362 %{
 9363   match(Set dst (AndI dst src));
 9364 
 9365   format %{ "movzbl  $dst, $dst\t# int & 0xFF" %}
 9366   ins_encode %{
 9367     __ movzbl($dst$$Register, $dst$$Register);
 9368   %}
 9369   ins_pipe(ialu_reg);
 9370 %}
 9371 
 9372 // And Register with Immediate 255 and promote to long
 9373 instruct andI2L_rReg_imm255(rRegL dst, rRegI src, immI_255 mask)
 9374 %{
 9375   match(Set dst (ConvI2L (AndI src mask)));
 9376 
 9377   format %{ "movzbl  $dst, $src\t# int & 0xFF -> long" %}
 9378   ins_encode %{
 9379     __ movzbl($dst$$Register, $src$$Register);
 9380   %}
 9381   ins_pipe(ialu_reg);
 9382 %}
 9383 
 9384 // And Register with Immediate 65535
 9385 instruct andI_rReg_imm65535(rRegI dst, immI_65535 src)
 9386 %{
 9387   match(Set dst (AndI dst src));
 9388 
 9389   format %{ "movzwl  $dst, $dst\t# int & 0xFFFF" %}
 9390   ins_encode %{
 9391     __ movzwl($dst$$Register, $dst$$Register);
 9392   %}
 9393   ins_pipe(ialu_reg);
 9394 %}
 9395 
 9396 // And Register with Immediate 65535 and promote to long
 9397 instruct andI2L_rReg_imm65535(rRegL dst, rRegI src, immI_65535 mask)
 9398 %{
 9399   match(Set dst (ConvI2L (AndI src mask)));
 9400 
 9401   format %{ "movzwl  $dst, $src\t# int & 0xFFFF -> long" %}
 9402   ins_encode %{
 9403     __ movzwl($dst$$Register, $src$$Register);
 9404   %}
 9405   ins_pipe(ialu_reg);
 9406 %}
 9407 
 9408 // Can skip int2long conversions after AND with small bitmask
 9409 instruct convI2LAndI_reg_immIbitmask(rRegL dst, rRegI src,  immI_Pow2M1 mask, rRegI tmp, rFlagsReg cr)
 9410 %{
 9411   predicate(VM_Version::supports_bmi2());
 9412   ins_cost(125);
 9413   effect(TEMP tmp, KILL cr);
 9414   match(Set dst (ConvI2L (AndI src mask)));
 9415   format %{ "bzhiq $dst, $src, $mask \t# using $tmp as TEMP, int &  immI_Pow2M1 -> long" %}
 9416   ins_encode %{
 9417     __ movl($tmp$$Register, exact_log2($mask$$constant + 1));
 9418     __ bzhiq($dst$$Register, $src$$Register, $tmp$$Register);
 9419   %}
 9420   ins_pipe(ialu_reg_reg);
 9421 %}
 9422 
 9423 // And Register with Immediate
 9424 instruct andI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
 9425 %{
 9426   match(Set dst (AndI dst src));
 9427   effect(KILL cr);
 9428 
 9429   format %{ "andl    $dst, $src\t# int" %}
 9430   ins_encode %{
 9431     __ andl($dst$$Register, $src$$constant);
 9432   %}
 9433   ins_pipe(ialu_reg);
 9434 %}
 9435 
 9436 // And Register with Memory
 9437 instruct andI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
 9438 %{
 9439   match(Set dst (AndI dst (LoadI src)));
 9440   effect(KILL cr);
 9441 
 9442   ins_cost(125);
 9443   format %{ "andl    $dst, $src\t# int" %}
 9444   ins_encode %{
 9445     __ andl($dst$$Register, $src$$Address);
 9446   %}
 9447   ins_pipe(ialu_reg_mem);
 9448 %}
 9449 
 9450 // And Memory with Register
 9451 instruct andB_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9452 %{
 9453   match(Set dst (StoreB dst (AndI (LoadB dst) src)));
 9454   effect(KILL cr);
 9455 
 9456   ins_cost(150);
 9457   format %{ "andb    $dst, $src\t# byte" %}
 9458   ins_encode %{
 9459     __ andb($dst$$Address, $src$$Register);
 9460   %}
 9461   ins_pipe(ialu_mem_reg);
 9462 %}
 9463 
 9464 instruct andI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9465 %{
 9466   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
 9467   effect(KILL cr);
 9468 
 9469   ins_cost(150);
 9470   format %{ "andl    $dst, $src\t# int" %}
 9471   ins_encode %{
 9472     __ andl($dst$$Address, $src$$Register);
 9473   %}
 9474   ins_pipe(ialu_mem_reg);
 9475 %}
 9476 
 9477 // And Memory with Immediate
 9478 instruct andI_mem_imm(memory dst, immI src, rFlagsReg cr)
 9479 %{
 9480   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
 9481   effect(KILL cr);
 9482 
 9483   ins_cost(125);
 9484   format %{ "andl    $dst, $src\t# int" %}
 9485   ins_encode %{
 9486     __ andl($dst$$Address, $src$$constant);
 9487   %}
 9488   ins_pipe(ialu_mem_imm);
 9489 %}
 9490 
 9491 // BMI1 instructions
 9492 instruct andnI_rReg_rReg_mem(rRegI dst, rRegI src1, memory src2, immI_M1 minus_1, rFlagsReg cr) %{
 9493   match(Set dst (AndI (XorI src1 minus_1) (LoadI src2)));
 9494   predicate(UseBMI1Instructions);
 9495   effect(KILL cr);
 9496 
 9497   ins_cost(125);
 9498   format %{ "andnl  $dst, $src1, $src2" %}
 9499 
 9500   ins_encode %{
 9501     __ andnl($dst$$Register, $src1$$Register, $src2$$Address);
 9502   %}
 9503   ins_pipe(ialu_reg_mem);
 9504 %}
 9505 
 9506 instruct andnI_rReg_rReg_rReg(rRegI dst, rRegI src1, rRegI src2, immI_M1 minus_1, rFlagsReg cr) %{
 9507   match(Set dst (AndI (XorI src1 minus_1) src2));
 9508   predicate(UseBMI1Instructions);
 9509   effect(KILL cr);
 9510 
 9511   format %{ "andnl  $dst, $src1, $src2" %}
 9512 
 9513   ins_encode %{
 9514     __ andnl($dst$$Register, $src1$$Register, $src2$$Register);
 9515   %}
 9516   ins_pipe(ialu_reg);
 9517 %}
 9518 
 9519 instruct blsiI_rReg_rReg(rRegI dst, rRegI src, immI_0 imm_zero, rFlagsReg cr) %{
 9520   match(Set dst (AndI (SubI imm_zero src) src));
 9521   predicate(UseBMI1Instructions);
 9522   effect(KILL cr);
 9523 
 9524   format %{ "blsil  $dst, $src" %}
 9525 
 9526   ins_encode %{
 9527     __ blsil($dst$$Register, $src$$Register);
 9528   %}
 9529   ins_pipe(ialu_reg);
 9530 %}
 9531 
 9532 instruct blsiI_rReg_mem(rRegI dst, memory src, immI_0 imm_zero, rFlagsReg cr) %{
 9533   match(Set dst (AndI (SubI imm_zero (LoadI src) ) (LoadI src) ));
 9534   predicate(UseBMI1Instructions);
 9535   effect(KILL cr);
 9536 
 9537   ins_cost(125);
 9538   format %{ "blsil  $dst, $src" %}
 9539 
 9540   ins_encode %{
 9541     __ blsil($dst$$Register, $src$$Address);
 9542   %}
 9543   ins_pipe(ialu_reg_mem);
 9544 %}
 9545 
 9546 instruct blsmskI_rReg_mem(rRegI dst, memory src, immI_M1 minus_1, rFlagsReg cr)
 9547 %{
 9548   match(Set dst (XorI (AddI (LoadI src) minus_1) (LoadI src) ) );
 9549   predicate(UseBMI1Instructions);
 9550   effect(KILL cr);
 9551 
 9552   ins_cost(125);
 9553   format %{ "blsmskl $dst, $src" %}
 9554 
 9555   ins_encode %{
 9556     __ blsmskl($dst$$Register, $src$$Address);
 9557   %}
 9558   ins_pipe(ialu_reg_mem);
 9559 %}
 9560 
 9561 instruct blsmskI_rReg_rReg(rRegI dst, rRegI src, immI_M1 minus_1, rFlagsReg cr)
 9562 %{
 9563   match(Set dst (XorI (AddI src minus_1) src));
 9564   predicate(UseBMI1Instructions);
 9565   effect(KILL cr);
 9566 
 9567   format %{ "blsmskl $dst, $src" %}
 9568 
 9569   ins_encode %{
 9570     __ blsmskl($dst$$Register, $src$$Register);
 9571   %}
 9572 
 9573   ins_pipe(ialu_reg);
 9574 %}
 9575 
 9576 instruct blsrI_rReg_rReg(rRegI dst, rRegI src, immI_M1 minus_1, rFlagsReg cr)
 9577 %{
 9578   match(Set dst (AndI (AddI src minus_1) src) );
 9579   predicate(UseBMI1Instructions);
 9580   effect(KILL cr);
 9581 
 9582   format %{ "blsrl  $dst, $src" %}
 9583 
 9584   ins_encode %{
 9585     __ blsrl($dst$$Register, $src$$Register);
 9586   %}
 9587 
 9588   ins_pipe(ialu_reg_mem);
 9589 %}
 9590 
 9591 instruct blsrI_rReg_mem(rRegI dst, memory src, immI_M1 minus_1, rFlagsReg cr)
 9592 %{
 9593   match(Set dst (AndI (AddI (LoadI src) minus_1) (LoadI src) ) );
 9594   predicate(UseBMI1Instructions);
 9595   effect(KILL cr);
 9596 
 9597   ins_cost(125);
 9598   format %{ "blsrl  $dst, $src" %}
 9599 
 9600   ins_encode %{
 9601     __ blsrl($dst$$Register, $src$$Address);
 9602   %}
 9603 
 9604   ins_pipe(ialu_reg);
 9605 %}
 9606 
 9607 // Or Instructions
 9608 // Or Register with Register
 9609 instruct orI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 9610 %{
 9611   match(Set dst (OrI dst src));
 9612   effect(KILL cr);
 9613 
 9614   format %{ "orl     $dst, $src\t# int" %}
 9615   ins_encode %{
 9616     __ orl($dst$$Register, $src$$Register);
 9617   %}
 9618   ins_pipe(ialu_reg_reg);
 9619 %}
 9620 
 9621 // Or Register with Immediate
 9622 instruct orI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
 9623 %{
 9624   match(Set dst (OrI dst src));
 9625   effect(KILL cr);
 9626 
 9627   format %{ "orl     $dst, $src\t# int" %}
 9628   ins_encode %{
 9629     __ orl($dst$$Register, $src$$constant);
 9630   %}
 9631   ins_pipe(ialu_reg);
 9632 %}
 9633 
 9634 // Or Register with Memory
 9635 instruct orI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
 9636 %{
 9637   match(Set dst (OrI dst (LoadI src)));
 9638   effect(KILL cr);
 9639 
 9640   ins_cost(125);
 9641   format %{ "orl     $dst, $src\t# int" %}
 9642   ins_encode %{
 9643     __ orl($dst$$Register, $src$$Address);
 9644   %}
 9645   ins_pipe(ialu_reg_mem);
 9646 %}
 9647 
 9648 // Or Memory with Register
 9649 instruct orB_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9650 %{
 9651   match(Set dst (StoreB dst (OrI (LoadB dst) src)));
 9652   effect(KILL cr);
 9653 
 9654   ins_cost(150);
 9655   format %{ "orb    $dst, $src\t# byte" %}
 9656   ins_encode %{
 9657     __ orb($dst$$Address, $src$$Register);
 9658   %}
 9659   ins_pipe(ialu_mem_reg);
 9660 %}
 9661 
 9662 instruct orI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9663 %{
 9664   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
 9665   effect(KILL cr);
 9666 
 9667   ins_cost(150);
 9668   format %{ "orl     $dst, $src\t# int" %}
 9669   ins_encode %{
 9670     __ orl($dst$$Address, $src$$Register);
 9671   %}
 9672   ins_pipe(ialu_mem_reg);
 9673 %}
 9674 
 9675 // Or Memory with Immediate
 9676 instruct orI_mem_imm(memory dst, immI src, rFlagsReg cr)
 9677 %{
 9678   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
 9679   effect(KILL cr);
 9680 
 9681   ins_cost(125);
 9682   format %{ "orl     $dst, $src\t# int" %}
 9683   ins_encode %{
 9684     __ orl($dst$$Address, $src$$constant);
 9685   %}
 9686   ins_pipe(ialu_mem_imm);
 9687 %}
 9688 
 9689 // Xor Instructions
 9690 // Xor Register with Register
 9691 instruct xorI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 9692 %{
 9693   match(Set dst (XorI dst src));
 9694   effect(KILL cr);
 9695 
 9696   format %{ "xorl    $dst, $src\t# int" %}
 9697   ins_encode %{
 9698     __ xorl($dst$$Register, $src$$Register);
 9699   %}
 9700   ins_pipe(ialu_reg_reg);
 9701 %}
 9702 
 9703 // Xor Register with Immediate -1
 9704 instruct xorI_rReg_im1(rRegI dst, immI_M1 imm) %{
 9705   match(Set dst (XorI dst imm));
 9706 
 9707   format %{ "not    $dst" %}
 9708   ins_encode %{
 9709      __ notl($dst$$Register);
 9710   %}
 9711   ins_pipe(ialu_reg);
 9712 %}
 9713 
 9714 // Xor Register with Immediate
 9715 instruct xorI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
 9716 %{
 9717   match(Set dst (XorI dst src));
 9718   effect(KILL cr);
 9719 
 9720   format %{ "xorl    $dst, $src\t# int" %}
 9721   ins_encode %{
 9722     __ xorl($dst$$Register, $src$$constant);
 9723   %}
 9724   ins_pipe(ialu_reg);
 9725 %}
 9726 
 9727 // Xor Register with Memory
 9728 instruct xorI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
 9729 %{
 9730   match(Set dst (XorI dst (LoadI src)));
 9731   effect(KILL cr);
 9732 
 9733   ins_cost(125);
 9734   format %{ "xorl    $dst, $src\t# int" %}
 9735   ins_encode %{
 9736     __ xorl($dst$$Register, $src$$Address);
 9737   %}
 9738   ins_pipe(ialu_reg_mem);
 9739 %}
 9740 
 9741 // Xor Memory with Register
 9742 instruct xorB_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9743 %{
 9744   match(Set dst (StoreB dst (XorI (LoadB dst) src)));
 9745   effect(KILL cr);
 9746 
 9747   ins_cost(150);
 9748   format %{ "xorb    $dst, $src\t# byte" %}
 9749   ins_encode %{
 9750     __ xorb($dst$$Address, $src$$Register);
 9751   %}
 9752   ins_pipe(ialu_mem_reg);
 9753 %}
 9754 
 9755 instruct xorI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
 9756 %{
 9757   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
 9758   effect(KILL cr);
 9759 
 9760   ins_cost(150);
 9761   format %{ "xorl    $dst, $src\t# int" %}
 9762   ins_encode %{
 9763     __ xorl($dst$$Address, $src$$Register);
 9764   %}
 9765   ins_pipe(ialu_mem_reg);
 9766 %}
 9767 
 9768 // Xor Memory with Immediate
 9769 instruct xorI_mem_imm(memory dst, immI src, rFlagsReg cr)
 9770 %{
 9771   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
 9772   effect(KILL cr);
 9773 
 9774   ins_cost(125);
 9775   format %{ "xorl    $dst, $src\t# int" %}
 9776   ins_encode %{
 9777     __ xorl($dst$$Address, $src$$constant);
 9778   %}
 9779   ins_pipe(ialu_mem_imm);
 9780 %}
 9781 
 9782 
 9783 // Long Logical Instructions
 9784 
 9785 // And Instructions
 9786 // And Register with Register
 9787 instruct andL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
 9788 %{
 9789   match(Set dst (AndL dst src));
 9790   effect(KILL cr);
 9791 
 9792   format %{ "andq    $dst, $src\t# long" %}
 9793   ins_encode %{
 9794     __ andq($dst$$Register, $src$$Register);
 9795   %}
 9796   ins_pipe(ialu_reg_reg);
 9797 %}
 9798 
 9799 // And Register with Immediate 255
 9800 instruct andL_rReg_imm255(rRegL dst, immL_255 src)
 9801 %{
 9802   match(Set dst (AndL dst src));
 9803 
 9804   format %{ "movzbq  $dst, $dst\t# long & 0xFF" %}
 9805   ins_encode %{
 9806     __ movzbq($dst$$Register, $dst$$Register);
 9807   %}
 9808   ins_pipe(ialu_reg);
 9809 %}
 9810 
 9811 // And Register with Immediate 65535
 9812 instruct andL_rReg_imm65535(rRegL dst, immL_65535 src)
 9813 %{
 9814   match(Set dst (AndL dst src));
 9815 
 9816   format %{ "movzwq  $dst, $dst\t# long & 0xFFFF" %}
 9817   ins_encode %{
 9818     __ movzwq($dst$$Register, $dst$$Register);
 9819   %}
 9820   ins_pipe(ialu_reg);
 9821 %}
 9822 
 9823 // And Register with Immediate
 9824 instruct andL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
 9825 %{
 9826   match(Set dst (AndL dst src));
 9827   effect(KILL cr);
 9828 
 9829   format %{ "andq    $dst, $src\t# long" %}
 9830   ins_encode %{
 9831     __ andq($dst$$Register, $src$$constant);
 9832   %}
 9833   ins_pipe(ialu_reg);
 9834 %}
 9835 
 9836 // And Register with Memory
 9837 instruct andL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
 9838 %{
 9839   match(Set dst (AndL dst (LoadL src)));
 9840   effect(KILL cr);
 9841 
 9842   ins_cost(125);
 9843   format %{ "andq    $dst, $src\t# long" %}
 9844   ins_encode %{
 9845     __ andq($dst$$Register, $src$$Address);
 9846   %}
 9847   ins_pipe(ialu_reg_mem);
 9848 %}
 9849 
 9850 // And Memory with Register
 9851 instruct andL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
 9852 %{
 9853   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
 9854   effect(KILL cr);
 9855 
 9856   ins_cost(150);
 9857   format %{ "andq    $dst, $src\t# long" %}
 9858   ins_encode %{
 9859     __ andq($dst$$Address, $src$$Register);
 9860   %}
 9861   ins_pipe(ialu_mem_reg);
 9862 %}
 9863 
 9864 // And Memory with Immediate
 9865 instruct andL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
 9866 %{
 9867   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
 9868   effect(KILL cr);
 9869 
 9870   ins_cost(125);
 9871   format %{ "andq    $dst, $src\t# long" %}
 9872   ins_encode %{
 9873     __ andq($dst$$Address, $src$$constant);
 9874   %}
 9875   ins_pipe(ialu_mem_imm);
 9876 %}
 9877 
 9878 instruct btrL_mem_imm(memory dst, immL_NotPow2 con, rFlagsReg cr)
 9879 %{
 9880   // con should be a pure 64-bit immediate given that not(con) is a power of 2
 9881   // because AND/OR works well enough for 8/32-bit values.
 9882   predicate(log2i_graceful(~n->in(3)->in(2)->get_long()) > 30);
 9883 
 9884   match(Set dst (StoreL dst (AndL (LoadL dst) con)));
 9885   effect(KILL cr);
 9886 
 9887   ins_cost(125);
 9888   format %{ "btrq    $dst, log2(not($con))\t# long" %}
 9889   ins_encode %{
 9890     __ btrq($dst$$Address, log2i_exact((julong)~$con$$constant));
 9891   %}
 9892   ins_pipe(ialu_mem_imm);
 9893 %}
 9894 
 9895 // BMI1 instructions
 9896 instruct andnL_rReg_rReg_mem(rRegL dst, rRegL src1, memory src2, immL_M1 minus_1, rFlagsReg cr) %{
 9897   match(Set dst (AndL (XorL src1 minus_1) (LoadL src2)));
 9898   predicate(UseBMI1Instructions);
 9899   effect(KILL cr);
 9900 
 9901   ins_cost(125);
 9902   format %{ "andnq  $dst, $src1, $src2" %}
 9903 
 9904   ins_encode %{
 9905     __ andnq($dst$$Register, $src1$$Register, $src2$$Address);
 9906   %}
 9907   ins_pipe(ialu_reg_mem);
 9908 %}
 9909 
 9910 instruct andnL_rReg_rReg_rReg(rRegL dst, rRegL src1, rRegL src2, immL_M1 minus_1, rFlagsReg cr) %{
 9911   match(Set dst (AndL (XorL src1 minus_1) src2));
 9912   predicate(UseBMI1Instructions);
 9913   effect(KILL cr);
 9914 
 9915   format %{ "andnq  $dst, $src1, $src2" %}
 9916 
 9917   ins_encode %{
 9918   __ andnq($dst$$Register, $src1$$Register, $src2$$Register);
 9919   %}
 9920   ins_pipe(ialu_reg_mem);
 9921 %}
 9922 
 9923 instruct blsiL_rReg_rReg(rRegL dst, rRegL src, immL0 imm_zero, rFlagsReg cr) %{
 9924   match(Set dst (AndL (SubL imm_zero src) src));
 9925   predicate(UseBMI1Instructions);
 9926   effect(KILL cr);
 9927 
 9928   format %{ "blsiq  $dst, $src" %}
 9929 
 9930   ins_encode %{
 9931     __ blsiq($dst$$Register, $src$$Register);
 9932   %}
 9933   ins_pipe(ialu_reg);
 9934 %}
 9935 
 9936 instruct blsiL_rReg_mem(rRegL dst, memory src, immL0 imm_zero, rFlagsReg cr) %{
 9937   match(Set dst (AndL (SubL imm_zero (LoadL src) ) (LoadL src) ));
 9938   predicate(UseBMI1Instructions);
 9939   effect(KILL cr);
 9940 
 9941   ins_cost(125);
 9942   format %{ "blsiq  $dst, $src" %}
 9943 
 9944   ins_encode %{
 9945     __ blsiq($dst$$Register, $src$$Address);
 9946   %}
 9947   ins_pipe(ialu_reg_mem);
 9948 %}
 9949 
 9950 instruct blsmskL_rReg_mem(rRegL dst, memory src, immL_M1 minus_1, rFlagsReg cr)
 9951 %{
 9952   match(Set dst (XorL (AddL (LoadL src) minus_1) (LoadL src) ) );
 9953   predicate(UseBMI1Instructions);
 9954   effect(KILL cr);
 9955 
 9956   ins_cost(125);
 9957   format %{ "blsmskq $dst, $src" %}
 9958 
 9959   ins_encode %{
 9960     __ blsmskq($dst$$Register, $src$$Address);
 9961   %}
 9962   ins_pipe(ialu_reg_mem);
 9963 %}
 9964 
 9965 instruct blsmskL_rReg_rReg(rRegL dst, rRegL src, immL_M1 minus_1, rFlagsReg cr)
 9966 %{
 9967   match(Set dst (XorL (AddL src minus_1) src));
 9968   predicate(UseBMI1Instructions);
 9969   effect(KILL cr);
 9970 
 9971   format %{ "blsmskq $dst, $src" %}
 9972 
 9973   ins_encode %{
 9974     __ blsmskq($dst$$Register, $src$$Register);
 9975   %}
 9976 
 9977   ins_pipe(ialu_reg);
 9978 %}
 9979 
 9980 instruct blsrL_rReg_rReg(rRegL dst, rRegL src, immL_M1 minus_1, rFlagsReg cr)
 9981 %{
 9982   match(Set dst (AndL (AddL src minus_1) src) );
 9983   predicate(UseBMI1Instructions);
 9984   effect(KILL cr);
 9985 
 9986   format %{ "blsrq  $dst, $src" %}
 9987 
 9988   ins_encode %{
 9989     __ blsrq($dst$$Register, $src$$Register);
 9990   %}
 9991 
 9992   ins_pipe(ialu_reg);
 9993 %}
 9994 
 9995 instruct blsrL_rReg_mem(rRegL dst, memory src, immL_M1 minus_1, rFlagsReg cr)
 9996 %{
 9997   match(Set dst (AndL (AddL (LoadL src) minus_1) (LoadL src)) );
 9998   predicate(UseBMI1Instructions);
 9999   effect(KILL cr);
10000 
10001   ins_cost(125);
10002   format %{ "blsrq  $dst, $src" %}
10003 
10004   ins_encode %{
10005     __ blsrq($dst$$Register, $src$$Address);
10006   %}
10007 
10008   ins_pipe(ialu_reg);
10009 %}
10010 
10011 // Or Instructions
10012 // Or Register with Register
10013 instruct orL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
10014 %{
10015   match(Set dst (OrL dst src));
10016   effect(KILL cr);
10017 
10018   format %{ "orq     $dst, $src\t# long" %}
10019   ins_encode %{
10020     __ orq($dst$$Register, $src$$Register);
10021   %}
10022   ins_pipe(ialu_reg_reg);
10023 %}
10024 
10025 // Use any_RegP to match R15 (TLS register) without spilling.
10026 instruct orL_rReg_castP2X(rRegL dst, any_RegP src, rFlagsReg cr) %{
10027   match(Set dst (OrL dst (CastP2X src)));
10028   effect(KILL cr);
10029 
10030   format %{ "orq     $dst, $src\t# long" %}
10031   ins_encode %{
10032     __ orq($dst$$Register, $src$$Register);
10033   %}
10034   ins_pipe(ialu_reg_reg);
10035 %}
10036 
10037 
10038 // Or Register with Immediate
10039 instruct orL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
10040 %{
10041   match(Set dst (OrL dst src));
10042   effect(KILL cr);
10043 
10044   format %{ "orq     $dst, $src\t# long" %}
10045   ins_encode %{
10046     __ orq($dst$$Register, $src$$constant);
10047   %}
10048   ins_pipe(ialu_reg);
10049 %}
10050 
10051 // Or Register with Memory
10052 instruct orL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
10053 %{
10054   match(Set dst (OrL dst (LoadL src)));
10055   effect(KILL cr);
10056 
10057   ins_cost(125);
10058   format %{ "orq     $dst, $src\t# long" %}
10059   ins_encode %{
10060     __ orq($dst$$Register, $src$$Address);
10061   %}
10062   ins_pipe(ialu_reg_mem);
10063 %}
10064 
10065 // Or Memory with Register
10066 instruct orL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
10067 %{
10068   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
10069   effect(KILL cr);
10070 
10071   ins_cost(150);
10072   format %{ "orq     $dst, $src\t# long" %}
10073   ins_encode %{
10074     __ orq($dst$$Address, $src$$Register);
10075   %}
10076   ins_pipe(ialu_mem_reg);
10077 %}
10078 
10079 // Or Memory with Immediate
10080 instruct orL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
10081 %{
10082   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
10083   effect(KILL cr);
10084 
10085   ins_cost(125);
10086   format %{ "orq     $dst, $src\t# long" %}
10087   ins_encode %{
10088     __ orq($dst$$Address, $src$$constant);
10089   %}
10090   ins_pipe(ialu_mem_imm);
10091 %}
10092 
10093 instruct btsL_mem_imm(memory dst, immL_Pow2 con, rFlagsReg cr)
10094 %{
10095   // con should be a pure 64-bit power of 2 immediate
10096   // because AND/OR works well enough for 8/32-bit values.
10097   predicate(log2i_graceful(n->in(3)->in(2)->get_long()) > 31);
10098 
10099   match(Set dst (StoreL dst (OrL (LoadL dst) con)));
10100   effect(KILL cr);
10101 
10102   ins_cost(125);
10103   format %{ "btsq    $dst, log2($con)\t# long" %}
10104   ins_encode %{
10105     __ btsq($dst$$Address, log2i_exact((julong)$con$$constant));
10106   %}
10107   ins_pipe(ialu_mem_imm);
10108 %}
10109 
10110 // Xor Instructions
10111 // Xor Register with Register
10112 instruct xorL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
10113 %{
10114   match(Set dst (XorL dst src));
10115   effect(KILL cr);
10116 
10117   format %{ "xorq    $dst, $src\t# long" %}
10118   ins_encode %{
10119     __ xorq($dst$$Register, $src$$Register);
10120   %}
10121   ins_pipe(ialu_reg_reg);
10122 %}
10123 
10124 // Xor Register with Immediate -1
10125 instruct xorL_rReg_im1(rRegL dst, immL_M1 imm) %{
10126   match(Set dst (XorL dst imm));
10127 
10128   format %{ "notq   $dst" %}
10129   ins_encode %{
10130      __ notq($dst$$Register);
10131   %}
10132   ins_pipe(ialu_reg);
10133 %}
10134 
10135 // Xor Register with Immediate
10136 instruct xorL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
10137 %{
10138   match(Set dst (XorL dst src));
10139   effect(KILL cr);
10140 
10141   format %{ "xorq    $dst, $src\t# long" %}
10142   ins_encode %{
10143     __ xorq($dst$$Register, $src$$constant);
10144   %}
10145   ins_pipe(ialu_reg);
10146 %}
10147 
10148 // Xor Register with Memory
10149 instruct xorL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
10150 %{
10151   match(Set dst (XorL dst (LoadL src)));
10152   effect(KILL cr);
10153 
10154   ins_cost(125);
10155   format %{ "xorq    $dst, $src\t# long" %}
10156   ins_encode %{
10157     __ xorq($dst$$Register, $src$$Address);
10158   %}
10159   ins_pipe(ialu_reg_mem);
10160 %}
10161 
10162 // Xor Memory with Register
10163 instruct xorL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
10164 %{
10165   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
10166   effect(KILL cr);
10167 
10168   ins_cost(150);
10169   format %{ "xorq    $dst, $src\t# long" %}
10170   ins_encode %{
10171     __ xorq($dst$$Address, $src$$Register);
10172   %}
10173   ins_pipe(ialu_mem_reg);
10174 %}
10175 
10176 // Xor Memory with Immediate
10177 instruct xorL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
10178 %{
10179   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
10180   effect(KILL cr);
10181 
10182   ins_cost(125);
10183   format %{ "xorq    $dst, $src\t# long" %}
10184   ins_encode %{
10185     __ xorq($dst$$Address, $src$$constant);
10186   %}
10187   ins_pipe(ialu_mem_imm);
10188 %}
10189 
10190 // Convert Int to Boolean
10191 instruct convI2B(rRegI dst, rRegI src, rFlagsReg cr)
10192 %{
10193   match(Set dst (Conv2B src));
10194   effect(KILL cr);
10195 
10196   format %{ "testl   $src, $src\t# ci2b\n\t"
10197             "setnz   $dst\n\t"
10198             "movzbl  $dst, $dst" %}
10199   ins_encode %{
10200     __ testl($src$$Register, $src$$Register);
10201     __ set_byte_if_not_zero($dst$$Register);
10202     __ movzbl($dst$$Register, $dst$$Register);
10203   %}
10204   ins_pipe(pipe_slow); // XXX
10205 %}
10206 
10207 // Convert Pointer to Boolean
10208 instruct convP2B(rRegI dst, rRegP src, rFlagsReg cr)
10209 %{
10210   match(Set dst (Conv2B src));
10211   effect(KILL cr);
10212 
10213   format %{ "testq   $src, $src\t# cp2b\n\t"
10214             "setnz   $dst\n\t"
10215             "movzbl  $dst, $dst" %}
10216   ins_encode %{
10217     __ testq($src$$Register, $src$$Register);
10218     __ set_byte_if_not_zero($dst$$Register);
10219     __ movzbl($dst$$Register, $dst$$Register);
10220   %}
10221   ins_pipe(pipe_slow); // XXX
10222 %}
10223 
10224 instruct cmpLTMask(rRegI dst, rRegI p, rRegI q, rFlagsReg cr)
10225 %{
10226   match(Set dst (CmpLTMask p q));
10227   effect(KILL cr);
10228 
10229   ins_cost(400);
10230   format %{ "cmpl    $p, $q\t# cmpLTMask\n\t"
10231             "setlt   $dst\n\t"
10232             "movzbl  $dst, $dst\n\t"
10233             "negl    $dst" %}
10234   ins_encode %{
10235     __ cmpl($p$$Register, $q$$Register);
10236     __ setl($dst$$Register);
10237     __ movzbl($dst$$Register, $dst$$Register);
10238     __ negl($dst$$Register);
10239   %}
10240   ins_pipe(pipe_slow);
10241 %}
10242 
10243 instruct cmpLTMask0(rRegI dst, immI_0 zero, rFlagsReg cr)
10244 %{
10245   match(Set dst (CmpLTMask dst zero));
10246   effect(KILL cr);
10247 
10248   ins_cost(100);
10249   format %{ "sarl    $dst, #31\t# cmpLTMask0" %}
10250   ins_encode %{
10251     __ sarl($dst$$Register, 31);
10252   %}
10253   ins_pipe(ialu_reg);
10254 %}
10255 
10256 /* Better to save a register than avoid a branch */
10257 instruct cadd_cmpLTMask(rRegI p, rRegI q, rRegI y, rFlagsReg cr)
10258 %{
10259   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
10260   effect(KILL cr);
10261   ins_cost(300);
10262   format %{ "subl    $p,$q\t# cadd_cmpLTMask\n\t"
10263             "jge     done\n\t"
10264             "addl    $p,$y\n"
10265             "done:   " %}
10266   ins_encode %{
10267     Register Rp = $p$$Register;
10268     Register Rq = $q$$Register;
10269     Register Ry = $y$$Register;
10270     Label done;
10271     __ subl(Rp, Rq);
10272     __ jccb(Assembler::greaterEqual, done);
10273     __ addl(Rp, Ry);
10274     __ bind(done);
10275   %}
10276   ins_pipe(pipe_cmplt);
10277 %}
10278 
10279 /* Better to save a register than avoid a branch */
10280 instruct and_cmpLTMask(rRegI p, rRegI q, rRegI y, rFlagsReg cr)
10281 %{
10282   match(Set y (AndI (CmpLTMask p q) y));
10283   effect(KILL cr);
10284 
10285   ins_cost(300);
10286 
10287   format %{ "cmpl    $p, $q\t# and_cmpLTMask\n\t"
10288             "jlt     done\n\t"
10289             "xorl    $y, $y\n"
10290             "done:   " %}
10291   ins_encode %{
10292     Register Rp = $p$$Register;
10293     Register Rq = $q$$Register;
10294     Register Ry = $y$$Register;
10295     Label done;
10296     __ cmpl(Rp, Rq);
10297     __ jccb(Assembler::less, done);
10298     __ xorl(Ry, Ry);
10299     __ bind(done);
10300   %}
10301   ins_pipe(pipe_cmplt);
10302 %}
10303 
10304 
10305 //---------- FP Instructions------------------------------------------------
10306 
10307 instruct cmpF_cc_reg(rFlagsRegU cr, regF src1, regF src2)
10308 %{
10309   match(Set cr (CmpF src1 src2));
10310 
10311   ins_cost(145);
10312   format %{ "ucomiss $src1, $src2\n\t"
10313             "jnp,s   exit\n\t"
10314             "pushfq\t# saw NaN, set CF\n\t"
10315             "andq    [rsp], #0xffffff2b\n\t"
10316             "popfq\n"
10317     "exit:" %}
10318   ins_encode %{
10319     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10320     emit_cmpfp_fixup(_masm);
10321   %}
10322   ins_pipe(pipe_slow);
10323 %}
10324 
10325 instruct cmpF_cc_reg_CF(rFlagsRegUCF cr, regF src1, regF src2) %{
10326   match(Set cr (CmpF src1 src2));
10327 
10328   ins_cost(100);
10329   format %{ "ucomiss $src1, $src2" %}
10330   ins_encode %{
10331     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10332   %}
10333   ins_pipe(pipe_slow);
10334 %}
10335 
10336 instruct cmpF_cc_mem(rFlagsRegU cr, regF src1, memory src2)
10337 %{
10338   match(Set cr (CmpF src1 (LoadF src2)));
10339 
10340   ins_cost(145);
10341   format %{ "ucomiss $src1, $src2\n\t"
10342             "jnp,s   exit\n\t"
10343             "pushfq\t# saw NaN, set CF\n\t"
10344             "andq    [rsp], #0xffffff2b\n\t"
10345             "popfq\n"
10346     "exit:" %}
10347   ins_encode %{
10348     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10349     emit_cmpfp_fixup(_masm);
10350   %}
10351   ins_pipe(pipe_slow);
10352 %}
10353 
10354 instruct cmpF_cc_memCF(rFlagsRegUCF cr, regF src1, memory src2) %{
10355   match(Set cr (CmpF src1 (LoadF src2)));
10356 
10357   ins_cost(100);
10358   format %{ "ucomiss $src1, $src2" %}
10359   ins_encode %{
10360     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10361   %}
10362   ins_pipe(pipe_slow);
10363 %}
10364 
10365 instruct cmpF_cc_imm(rFlagsRegU cr, regF src, immF con) %{
10366   match(Set cr (CmpF src con));
10367 
10368   ins_cost(145);
10369   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con\n\t"
10370             "jnp,s   exit\n\t"
10371             "pushfq\t# saw NaN, set CF\n\t"
10372             "andq    [rsp], #0xffffff2b\n\t"
10373             "popfq\n"
10374     "exit:" %}
10375   ins_encode %{
10376     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10377     emit_cmpfp_fixup(_masm);
10378   %}
10379   ins_pipe(pipe_slow);
10380 %}
10381 
10382 instruct cmpF_cc_immCF(rFlagsRegUCF cr, regF src, immF con) %{
10383   match(Set cr (CmpF src con));
10384   ins_cost(100);
10385   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con" %}
10386   ins_encode %{
10387     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10388   %}
10389   ins_pipe(pipe_slow);
10390 %}
10391 
10392 instruct cmpD_cc_reg(rFlagsRegU cr, regD src1, regD src2)
10393 %{
10394   match(Set cr (CmpD src1 src2));
10395 
10396   ins_cost(145);
10397   format %{ "ucomisd $src1, $src2\n\t"
10398             "jnp,s   exit\n\t"
10399             "pushfq\t# saw NaN, set CF\n\t"
10400             "andq    [rsp], #0xffffff2b\n\t"
10401             "popfq\n"
10402     "exit:" %}
10403   ins_encode %{
10404     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
10405     emit_cmpfp_fixup(_masm);
10406   %}
10407   ins_pipe(pipe_slow);
10408 %}
10409 
10410 instruct cmpD_cc_reg_CF(rFlagsRegUCF cr, regD src1, regD src2) %{
10411   match(Set cr (CmpD src1 src2));
10412 
10413   ins_cost(100);
10414   format %{ "ucomisd $src1, $src2 test" %}
10415   ins_encode %{
10416     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
10417   %}
10418   ins_pipe(pipe_slow);
10419 %}
10420 
10421 instruct cmpD_cc_mem(rFlagsRegU cr, regD src1, memory src2)
10422 %{
10423   match(Set cr (CmpD src1 (LoadD src2)));
10424 
10425   ins_cost(145);
10426   format %{ "ucomisd $src1, $src2\n\t"
10427             "jnp,s   exit\n\t"
10428             "pushfq\t# saw NaN, set CF\n\t"
10429             "andq    [rsp], #0xffffff2b\n\t"
10430             "popfq\n"
10431     "exit:" %}
10432   ins_encode %{
10433     __ ucomisd($src1$$XMMRegister, $src2$$Address);
10434     emit_cmpfp_fixup(_masm);
10435   %}
10436   ins_pipe(pipe_slow);
10437 %}
10438 
10439 instruct cmpD_cc_memCF(rFlagsRegUCF cr, regD src1, memory src2) %{
10440   match(Set cr (CmpD src1 (LoadD src2)));
10441 
10442   ins_cost(100);
10443   format %{ "ucomisd $src1, $src2" %}
10444   ins_encode %{
10445     __ ucomisd($src1$$XMMRegister, $src2$$Address);
10446   %}
10447   ins_pipe(pipe_slow);
10448 %}
10449 
10450 instruct cmpD_cc_imm(rFlagsRegU cr, regD src, immD con) %{
10451   match(Set cr (CmpD src con));
10452 
10453   ins_cost(145);
10454   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con\n\t"
10455             "jnp,s   exit\n\t"
10456             "pushfq\t# saw NaN, set CF\n\t"
10457             "andq    [rsp], #0xffffff2b\n\t"
10458             "popfq\n"
10459     "exit:" %}
10460   ins_encode %{
10461     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10462     emit_cmpfp_fixup(_masm);
10463   %}
10464   ins_pipe(pipe_slow);
10465 %}
10466 
10467 instruct cmpD_cc_immCF(rFlagsRegUCF cr, regD src, immD con) %{
10468   match(Set cr (CmpD src con));
10469   ins_cost(100);
10470   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con" %}
10471   ins_encode %{
10472     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10473   %}
10474   ins_pipe(pipe_slow);
10475 %}
10476 
10477 // Compare into -1,0,1
10478 instruct cmpF_reg(rRegI dst, regF src1, regF src2, rFlagsReg cr)
10479 %{
10480   match(Set dst (CmpF3 src1 src2));
10481   effect(KILL cr);
10482 
10483   ins_cost(275);
10484   format %{ "ucomiss $src1, $src2\n\t"
10485             "movl    $dst, #-1\n\t"
10486             "jp,s    done\n\t"
10487             "jb,s    done\n\t"
10488             "setne   $dst\n\t"
10489             "movzbl  $dst, $dst\n"
10490     "done:" %}
10491   ins_encode %{
10492     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10493     emit_cmpfp3(_masm, $dst$$Register);
10494   %}
10495   ins_pipe(pipe_slow);
10496 %}
10497 
10498 // Compare into -1,0,1
10499 instruct cmpF_mem(rRegI dst, regF src1, memory src2, rFlagsReg cr)
10500 %{
10501   match(Set dst (CmpF3 src1 (LoadF src2)));
10502   effect(KILL cr);
10503 
10504   ins_cost(275);
10505   format %{ "ucomiss $src1, $src2\n\t"
10506             "movl    $dst, #-1\n\t"
10507             "jp,s    done\n\t"
10508             "jb,s    done\n\t"
10509             "setne   $dst\n\t"
10510             "movzbl  $dst, $dst\n"
10511     "done:" %}
10512   ins_encode %{
10513     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10514     emit_cmpfp3(_masm, $dst$$Register);
10515   %}
10516   ins_pipe(pipe_slow);
10517 %}
10518 
10519 // Compare into -1,0,1
10520 instruct cmpF_imm(rRegI dst, regF src, immF con, rFlagsReg cr) %{
10521   match(Set dst (CmpF3 src con));
10522   effect(KILL cr);
10523 
10524   ins_cost(275);
10525   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con\n\t"
10526             "movl    $dst, #-1\n\t"
10527             "jp,s    done\n\t"
10528             "jb,s    done\n\t"
10529             "setne   $dst\n\t"
10530             "movzbl  $dst, $dst\n"
10531     "done:" %}
10532   ins_encode %{
10533     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10534     emit_cmpfp3(_masm, $dst$$Register);
10535   %}
10536   ins_pipe(pipe_slow);
10537 %}
10538 
10539 // Compare into -1,0,1
10540 instruct cmpD_reg(rRegI dst, regD src1, regD src2, rFlagsReg cr)
10541 %{
10542   match(Set dst (CmpD3 src1 src2));
10543   effect(KILL cr);
10544 
10545   ins_cost(275);
10546   format %{ "ucomisd $src1, $src2\n\t"
10547             "movl    $dst, #-1\n\t"
10548             "jp,s    done\n\t"
10549             "jb,s    done\n\t"
10550             "setne   $dst\n\t"
10551             "movzbl  $dst, $dst\n"
10552     "done:" %}
10553   ins_encode %{
10554     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
10555     emit_cmpfp3(_masm, $dst$$Register);
10556   %}
10557   ins_pipe(pipe_slow);
10558 %}
10559 
10560 // Compare into -1,0,1
10561 instruct cmpD_mem(rRegI dst, regD src1, memory src2, rFlagsReg cr)
10562 %{
10563   match(Set dst (CmpD3 src1 (LoadD src2)));
10564   effect(KILL cr);
10565 
10566   ins_cost(275);
10567   format %{ "ucomisd $src1, $src2\n\t"
10568             "movl    $dst, #-1\n\t"
10569             "jp,s    done\n\t"
10570             "jb,s    done\n\t"
10571             "setne   $dst\n\t"
10572             "movzbl  $dst, $dst\n"
10573     "done:" %}
10574   ins_encode %{
10575     __ ucomisd($src1$$XMMRegister, $src2$$Address);
10576     emit_cmpfp3(_masm, $dst$$Register);
10577   %}
10578   ins_pipe(pipe_slow);
10579 %}
10580 
10581 // Compare into -1,0,1
10582 instruct cmpD_imm(rRegI dst, regD src, immD con, rFlagsReg cr) %{
10583   match(Set dst (CmpD3 src con));
10584   effect(KILL cr);
10585 
10586   ins_cost(275);
10587   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con\n\t"
10588             "movl    $dst, #-1\n\t"
10589             "jp,s    done\n\t"
10590             "jb,s    done\n\t"
10591             "setne   $dst\n\t"
10592             "movzbl  $dst, $dst\n"
10593     "done:" %}
10594   ins_encode %{
10595     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10596     emit_cmpfp3(_masm, $dst$$Register);
10597   %}
10598   ins_pipe(pipe_slow);
10599 %}
10600 
10601 //----------Arithmetic Conversion Instructions---------------------------------
10602 
10603 instruct convF2D_reg_reg(regD dst, regF src)
10604 %{
10605   match(Set dst (ConvF2D src));
10606 
10607   format %{ "cvtss2sd $dst, $src" %}
10608   ins_encode %{
10609     __ cvtss2sd ($dst$$XMMRegister, $src$$XMMRegister);
10610   %}
10611   ins_pipe(pipe_slow); // XXX
10612 %}
10613 
10614 instruct convF2D_reg_mem(regD dst, memory src)
10615 %{
10616   match(Set dst (ConvF2D (LoadF src)));
10617 
10618   format %{ "cvtss2sd $dst, $src" %}
10619   ins_encode %{
10620     __ cvtss2sd ($dst$$XMMRegister, $src$$Address);
10621   %}
10622   ins_pipe(pipe_slow); // XXX
10623 %}
10624 
10625 instruct convD2F_reg_reg(regF dst, regD src)
10626 %{
10627   match(Set dst (ConvD2F src));
10628 
10629   format %{ "cvtsd2ss $dst, $src" %}
10630   ins_encode %{
10631     __ cvtsd2ss ($dst$$XMMRegister, $src$$XMMRegister);
10632   %}
10633   ins_pipe(pipe_slow); // XXX
10634 %}
10635 
10636 instruct convD2F_reg_mem(regF dst, memory src)
10637 %{
10638   match(Set dst (ConvD2F (LoadD src)));
10639 
10640   format %{ "cvtsd2ss $dst, $src" %}
10641   ins_encode %{
10642     __ cvtsd2ss ($dst$$XMMRegister, $src$$Address);
10643   %}
10644   ins_pipe(pipe_slow); // XXX
10645 %}
10646 
10647 // XXX do mem variants
10648 instruct convF2I_reg_reg(rRegI dst, regF src, rFlagsReg cr)
10649 %{
10650   match(Set dst (ConvF2I src));
10651   effect(KILL cr);
10652   format %{ "convert_f2i $dst,$src" %}
10653   ins_encode %{
10654     __ convert_f2i($dst$$Register, $src$$XMMRegister);
10655   %}
10656   ins_pipe(pipe_slow);
10657 %}
10658 
10659 instruct convF2L_reg_reg(rRegL dst, regF src, rFlagsReg cr)
10660 %{
10661   match(Set dst (ConvF2L src));
10662   effect(KILL cr);
10663   format %{ "convert_f2l $dst,$src"%}
10664   ins_encode %{
10665     __ convert_f2l($dst$$Register, $src$$XMMRegister);
10666   %}
10667   ins_pipe(pipe_slow);
10668 %}
10669 
10670 instruct convD2I_reg_reg(rRegI dst, regD src, rFlagsReg cr)
10671 %{
10672   match(Set dst (ConvD2I src));
10673   effect(KILL cr);
10674   format %{ "convert_d2i $dst,$src"%}
10675   ins_encode %{
10676     __ convert_d2i($dst$$Register, $src$$XMMRegister);
10677   %}
10678   ins_pipe(pipe_slow);
10679 %}
10680 
10681 instruct convD2L_reg_reg(rRegL dst, regD src, rFlagsReg cr)
10682 %{
10683   match(Set dst (ConvD2L src));
10684   effect(KILL cr);
10685   format %{ "convert_d2l $dst,$src"%}
10686   ins_encode %{
10687     __ convert_d2l($dst$$Register, $src$$XMMRegister);
10688   %}
10689   ins_pipe(pipe_slow);
10690 %}
10691 
10692 instruct convI2F_reg_reg(regF dst, rRegI src)
10693 %{
10694   predicate(!UseXmmI2F);
10695   match(Set dst (ConvI2F src));
10696 
10697   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
10698   ins_encode %{
10699     __ cvtsi2ssl ($dst$$XMMRegister, $src$$Register);
10700   %}
10701   ins_pipe(pipe_slow); // XXX
10702 %}
10703 
10704 instruct convI2F_reg_mem(regF dst, memory src)
10705 %{
10706   match(Set dst (ConvI2F (LoadI src)));
10707 
10708   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
10709   ins_encode %{
10710     __ cvtsi2ssl ($dst$$XMMRegister, $src$$Address);
10711   %}
10712   ins_pipe(pipe_slow); // XXX
10713 %}
10714 
10715 instruct convI2D_reg_reg(regD dst, rRegI src)
10716 %{
10717   predicate(!UseXmmI2D);
10718   match(Set dst (ConvI2D src));
10719 
10720   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
10721   ins_encode %{
10722     __ cvtsi2sdl ($dst$$XMMRegister, $src$$Register);
10723   %}
10724   ins_pipe(pipe_slow); // XXX
10725 %}
10726 
10727 instruct convI2D_reg_mem(regD dst, memory src)
10728 %{
10729   match(Set dst (ConvI2D (LoadI src)));
10730 
10731   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
10732   ins_encode %{
10733     __ cvtsi2sdl ($dst$$XMMRegister, $src$$Address);
10734   %}
10735   ins_pipe(pipe_slow); // XXX
10736 %}
10737 
10738 instruct convXI2F_reg(regF dst, rRegI src)
10739 %{
10740   predicate(UseXmmI2F);
10741   match(Set dst (ConvI2F src));
10742 
10743   format %{ "movdl $dst, $src\n\t"
10744             "cvtdq2psl $dst, $dst\t# i2f" %}
10745   ins_encode %{
10746     __ movdl($dst$$XMMRegister, $src$$Register);
10747     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
10748   %}
10749   ins_pipe(pipe_slow); // XXX
10750 %}
10751 
10752 instruct convXI2D_reg(regD dst, rRegI src)
10753 %{
10754   predicate(UseXmmI2D);
10755   match(Set dst (ConvI2D src));
10756 
10757   format %{ "movdl $dst, $src\n\t"
10758             "cvtdq2pdl $dst, $dst\t# i2d" %}
10759   ins_encode %{
10760     __ movdl($dst$$XMMRegister, $src$$Register);
10761     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
10762   %}
10763   ins_pipe(pipe_slow); // XXX
10764 %}
10765 
10766 instruct convL2F_reg_reg(regF dst, rRegL src)
10767 %{
10768   match(Set dst (ConvL2F src));
10769 
10770   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
10771   ins_encode %{
10772     __ cvtsi2ssq ($dst$$XMMRegister, $src$$Register);
10773   %}
10774   ins_pipe(pipe_slow); // XXX
10775 %}
10776 
10777 instruct convL2F_reg_mem(regF dst, memory src)
10778 %{
10779   match(Set dst (ConvL2F (LoadL src)));
10780 
10781   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
10782   ins_encode %{
10783     __ cvtsi2ssq ($dst$$XMMRegister, $src$$Address);
10784   %}
10785   ins_pipe(pipe_slow); // XXX
10786 %}
10787 
10788 instruct convL2D_reg_reg(regD dst, rRegL src)
10789 %{
10790   match(Set dst (ConvL2D src));
10791 
10792   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
10793   ins_encode %{
10794     __ cvtsi2sdq ($dst$$XMMRegister, $src$$Register);
10795   %}
10796   ins_pipe(pipe_slow); // XXX
10797 %}
10798 
10799 instruct convL2D_reg_mem(regD dst, memory src)
10800 %{
10801   match(Set dst (ConvL2D (LoadL src)));
10802 
10803   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
10804   ins_encode %{
10805     __ cvtsi2sdq ($dst$$XMMRegister, $src$$Address);
10806   %}
10807   ins_pipe(pipe_slow); // XXX
10808 %}
10809 
10810 instruct convI2L_reg_reg(rRegL dst, rRegI src)
10811 %{
10812   match(Set dst (ConvI2L src));
10813 
10814   ins_cost(125);
10815   format %{ "movslq  $dst, $src\t# i2l" %}
10816   ins_encode %{
10817     __ movslq($dst$$Register, $src$$Register);
10818   %}
10819   ins_pipe(ialu_reg_reg);
10820 %}
10821 
10822 // instruct convI2L_reg_reg_foo(rRegL dst, rRegI src)
10823 // %{
10824 //   match(Set dst (ConvI2L src));
10825 // //   predicate(_kids[0]->_leaf->as_Type()->type()->is_int()->_lo >= 0 &&
10826 // //             _kids[0]->_leaf->as_Type()->type()->is_int()->_hi >= 0);
10827 //   predicate(((const TypeNode*) n)->type()->is_long()->_hi ==
10828 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_hi &&
10829 //             ((const TypeNode*) n)->type()->is_long()->_lo ==
10830 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_lo);
10831 
10832 //   format %{ "movl    $dst, $src\t# unsigned i2l" %}
10833 //   ins_encode(enc_copy(dst, src));
10834 // //   opcode(0x63); // needs REX.W
10835 // //   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst,src));
10836 //   ins_pipe(ialu_reg_reg);
10837 // %}
10838 
10839 // Zero-extend convert int to long
10840 instruct convI2L_reg_reg_zex(rRegL dst, rRegI src, immL_32bits mask)
10841 %{
10842   match(Set dst (AndL (ConvI2L src) mask));
10843 
10844   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
10845   ins_encode %{
10846     if ($dst$$reg != $src$$reg) {
10847       __ movl($dst$$Register, $src$$Register);
10848     }
10849   %}
10850   ins_pipe(ialu_reg_reg);
10851 %}
10852 
10853 // Zero-extend convert int to long
10854 instruct convI2L_reg_mem_zex(rRegL dst, memory src, immL_32bits mask)
10855 %{
10856   match(Set dst (AndL (ConvI2L (LoadI src)) mask));
10857 
10858   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
10859   ins_encode %{
10860     __ movl($dst$$Register, $src$$Address);
10861   %}
10862   ins_pipe(ialu_reg_mem);
10863 %}
10864 
10865 instruct zerox_long_reg_reg(rRegL dst, rRegL src, immL_32bits mask)
10866 %{
10867   match(Set dst (AndL src mask));
10868 
10869   format %{ "movl    $dst, $src\t# zero-extend long" %}
10870   ins_encode %{
10871     __ movl($dst$$Register, $src$$Register);
10872   %}
10873   ins_pipe(ialu_reg_reg);
10874 %}
10875 
10876 instruct convL2I_reg_reg(rRegI dst, rRegL src)
10877 %{
10878   match(Set dst (ConvL2I src));
10879 
10880   format %{ "movl    $dst, $src\t# l2i" %}
10881   ins_encode %{
10882     __ movl($dst$$Register, $src$$Register);
10883   %}
10884   ins_pipe(ialu_reg_reg);
10885 %}
10886 
10887 
10888 instruct MoveF2I_stack_reg(rRegI dst, stackSlotF src) %{
10889   match(Set dst (MoveF2I src));
10890   effect(DEF dst, USE src);
10891 
10892   ins_cost(125);
10893   format %{ "movl    $dst, $src\t# MoveF2I_stack_reg" %}
10894   ins_encode %{
10895     __ movl($dst$$Register, Address(rsp, $src$$disp));
10896   %}
10897   ins_pipe(ialu_reg_mem);
10898 %}
10899 
10900 instruct MoveI2F_stack_reg(regF dst, stackSlotI src) %{
10901   match(Set dst (MoveI2F src));
10902   effect(DEF dst, USE src);
10903 
10904   ins_cost(125);
10905   format %{ "movss   $dst, $src\t# MoveI2F_stack_reg" %}
10906   ins_encode %{
10907     __ movflt($dst$$XMMRegister, Address(rsp, $src$$disp));
10908   %}
10909   ins_pipe(pipe_slow);
10910 %}
10911 
10912 instruct MoveD2L_stack_reg(rRegL dst, stackSlotD src) %{
10913   match(Set dst (MoveD2L src));
10914   effect(DEF dst, USE src);
10915 
10916   ins_cost(125);
10917   format %{ "movq    $dst, $src\t# MoveD2L_stack_reg" %}
10918   ins_encode %{
10919     __ movq($dst$$Register, Address(rsp, $src$$disp));
10920   %}
10921   ins_pipe(ialu_reg_mem);
10922 %}
10923 
10924 instruct MoveL2D_stack_reg_partial(regD dst, stackSlotL src) %{
10925   predicate(!UseXmmLoadAndClearUpper);
10926   match(Set dst (MoveL2D src));
10927   effect(DEF dst, USE src);
10928 
10929   ins_cost(125);
10930   format %{ "movlpd  $dst, $src\t# MoveL2D_stack_reg" %}
10931   ins_encode %{
10932     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
10933   %}
10934   ins_pipe(pipe_slow);
10935 %}
10936 
10937 instruct MoveL2D_stack_reg(regD dst, stackSlotL src) %{
10938   predicate(UseXmmLoadAndClearUpper);
10939   match(Set dst (MoveL2D src));
10940   effect(DEF dst, USE src);
10941 
10942   ins_cost(125);
10943   format %{ "movsd   $dst, $src\t# MoveL2D_stack_reg" %}
10944   ins_encode %{
10945     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
10946   %}
10947   ins_pipe(pipe_slow);
10948 %}
10949 
10950 
10951 instruct MoveF2I_reg_stack(stackSlotI dst, regF src) %{
10952   match(Set dst (MoveF2I src));
10953   effect(DEF dst, USE src);
10954 
10955   ins_cost(95); // XXX
10956   format %{ "movss   $dst, $src\t# MoveF2I_reg_stack" %}
10957   ins_encode %{
10958     __ movflt(Address(rsp, $dst$$disp), $src$$XMMRegister);
10959   %}
10960   ins_pipe(pipe_slow);
10961 %}
10962 
10963 instruct MoveI2F_reg_stack(stackSlotF dst, rRegI src) %{
10964   match(Set dst (MoveI2F src));
10965   effect(DEF dst, USE src);
10966 
10967   ins_cost(100);
10968   format %{ "movl    $dst, $src\t# MoveI2F_reg_stack" %}
10969   ins_encode %{
10970     __ movl(Address(rsp, $dst$$disp), $src$$Register);
10971   %}
10972   ins_pipe( ialu_mem_reg );
10973 %}
10974 
10975 instruct MoveD2L_reg_stack(stackSlotL dst, regD src) %{
10976   match(Set dst (MoveD2L src));
10977   effect(DEF dst, USE src);
10978 
10979   ins_cost(95); // XXX
10980   format %{ "movsd   $dst, $src\t# MoveL2D_reg_stack" %}
10981   ins_encode %{
10982     __ movdbl(Address(rsp, $dst$$disp), $src$$XMMRegister);
10983   %}
10984   ins_pipe(pipe_slow);
10985 %}
10986 
10987 instruct MoveL2D_reg_stack(stackSlotD dst, rRegL src) %{
10988   match(Set dst (MoveL2D src));
10989   effect(DEF dst, USE src);
10990 
10991   ins_cost(100);
10992   format %{ "movq    $dst, $src\t# MoveL2D_reg_stack" %}
10993   ins_encode %{
10994     __ movq(Address(rsp, $dst$$disp), $src$$Register);
10995   %}
10996   ins_pipe(ialu_mem_reg);
10997 %}
10998 
10999 instruct MoveF2I_reg_reg(rRegI dst, regF src) %{
11000   match(Set dst (MoveF2I src));
11001   effect(DEF dst, USE src);
11002   ins_cost(85);
11003   format %{ "movd    $dst,$src\t# MoveF2I" %}
11004   ins_encode %{
11005     __ movdl($dst$$Register, $src$$XMMRegister);
11006   %}
11007   ins_pipe( pipe_slow );
11008 %}
11009 
11010 instruct MoveD2L_reg_reg(rRegL dst, regD src) %{
11011   match(Set dst (MoveD2L src));
11012   effect(DEF dst, USE src);
11013   ins_cost(85);
11014   format %{ "movd    $dst,$src\t# MoveD2L" %}
11015   ins_encode %{
11016     __ movdq($dst$$Register, $src$$XMMRegister);
11017   %}
11018   ins_pipe( pipe_slow );
11019 %}
11020 
11021 instruct MoveI2F_reg_reg(regF dst, rRegI src) %{
11022   match(Set dst (MoveI2F src));
11023   effect(DEF dst, USE src);
11024   ins_cost(100);
11025   format %{ "movd    $dst,$src\t# MoveI2F" %}
11026   ins_encode %{
11027     __ movdl($dst$$XMMRegister, $src$$Register);
11028   %}
11029   ins_pipe( pipe_slow );
11030 %}
11031 
11032 instruct MoveL2D_reg_reg(regD dst, rRegL src) %{
11033   match(Set dst (MoveL2D src));
11034   effect(DEF dst, USE src);
11035   ins_cost(100);
11036   format %{ "movd    $dst,$src\t# MoveL2D" %}
11037   ins_encode %{
11038      __ movdq($dst$$XMMRegister, $src$$Register);
11039   %}
11040   ins_pipe( pipe_slow );
11041 %}
11042 
11043 // Fast clearing of an array
11044 // Small ClearArray non-AVX512.
11045 instruct rep_stos(rcx_RegL cnt, rdi_RegP base, regD tmp, rax_RegI zero,
11046                   Universe dummy, rFlagsReg cr)
11047 %{
11048   predicate(!((ClearArrayNode*)n)->is_large() && (UseAVX <= 2));
11049   match(Set dummy (ClearArray cnt base));
11050   effect(USE_KILL cnt, USE_KILL base, TEMP tmp, KILL zero, KILL cr);
11051 
11052   format %{ $$template
11053     $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11054     $$emit$$"cmp     InitArrayShortSize,rcx\n\t"
11055     $$emit$$"jg      LARGE\n\t"
11056     $$emit$$"dec     rcx\n\t"
11057     $$emit$$"js      DONE\t# Zero length\n\t"
11058     $$emit$$"mov     rax,(rdi,rcx,8)\t# LOOP\n\t"
11059     $$emit$$"dec     rcx\n\t"
11060     $$emit$$"jge     LOOP\n\t"
11061     $$emit$$"jmp     DONE\n\t"
11062     $$emit$$"# LARGE:\n\t"
11063     if (UseFastStosb) {
11064        $$emit$$"shlq    rcx,3\t# Convert doublewords to bytes\n\t"
11065        $$emit$$"rep     stosb\t# Store rax to *rdi++ while rcx--\n\t"
11066     } else if (UseXMMForObjInit) {
11067        $$emit$$"mov     rdi,rax\n\t"
11068        $$emit$$"vpxor   ymm0,ymm0,ymm0\n\t"
11069        $$emit$$"jmpq    L_zero_64_bytes\n\t"
11070        $$emit$$"# L_loop:\t# 64-byte LOOP\n\t"
11071        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11072        $$emit$$"vmovdqu ymm0,0x20(rax)\n\t"
11073        $$emit$$"add     0x40,rax\n\t"
11074        $$emit$$"# L_zero_64_bytes:\n\t"
11075        $$emit$$"sub     0x8,rcx\n\t"
11076        $$emit$$"jge     L_loop\n\t"
11077        $$emit$$"add     0x4,rcx\n\t"
11078        $$emit$$"jl      L_tail\n\t"
11079        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11080        $$emit$$"add     0x20,rax\n\t"
11081        $$emit$$"sub     0x4,rcx\n\t"
11082        $$emit$$"# L_tail:\t# Clearing tail bytes\n\t"
11083        $$emit$$"add     0x4,rcx\n\t"
11084        $$emit$$"jle     L_end\n\t"
11085        $$emit$$"dec     rcx\n\t"
11086        $$emit$$"# L_sloop:\t# 8-byte short loop\n\t"
11087        $$emit$$"vmovq   xmm0,(rax)\n\t"
11088        $$emit$$"add     0x8,rax\n\t"
11089        $$emit$$"dec     rcx\n\t"
11090        $$emit$$"jge     L_sloop\n\t"
11091        $$emit$$"# L_end:\n\t"
11092     } else {
11093        $$emit$$"rep     stosq\t# Store rax to *rdi++ while rcx--\n\t"
11094     }
11095     $$emit$$"# DONE"
11096   %}
11097   ins_encode %{
11098     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register,
11099                  $tmp$$XMMRegister, false, knoreg);
11100   %}
11101   ins_pipe(pipe_slow);
11102 %}
11103 
11104 // Small ClearArray AVX512 non-constant length.
11105 instruct rep_stos_evex(rcx_RegL cnt, rdi_RegP base, legRegD tmp, kReg ktmp, rax_RegI zero,
11106                        Universe dummy, rFlagsReg cr)
11107 %{
11108   predicate(!((ClearArrayNode*)n)->is_large() && (UseAVX > 2));
11109   match(Set dummy (ClearArray cnt base));
11110   ins_cost(125);
11111   effect(USE_KILL cnt, USE_KILL base, TEMP tmp, TEMP ktmp, KILL zero, KILL cr);
11112 
11113   format %{ $$template
11114     $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11115     $$emit$$"cmp     InitArrayShortSize,rcx\n\t"
11116     $$emit$$"jg      LARGE\n\t"
11117     $$emit$$"dec     rcx\n\t"
11118     $$emit$$"js      DONE\t# Zero length\n\t"
11119     $$emit$$"mov     rax,(rdi,rcx,8)\t# LOOP\n\t"
11120     $$emit$$"dec     rcx\n\t"
11121     $$emit$$"jge     LOOP\n\t"
11122     $$emit$$"jmp     DONE\n\t"
11123     $$emit$$"# LARGE:\n\t"
11124     if (UseFastStosb) {
11125        $$emit$$"shlq    rcx,3\t# Convert doublewords to bytes\n\t"
11126        $$emit$$"rep     stosb\t# Store rax to *rdi++ while rcx--\n\t"
11127     } else if (UseXMMForObjInit) {
11128        $$emit$$"mov     rdi,rax\n\t"
11129        $$emit$$"vpxor   ymm0,ymm0,ymm0\n\t"
11130        $$emit$$"jmpq    L_zero_64_bytes\n\t"
11131        $$emit$$"# L_loop:\t# 64-byte LOOP\n\t"
11132        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11133        $$emit$$"vmovdqu ymm0,0x20(rax)\n\t"
11134        $$emit$$"add     0x40,rax\n\t"
11135        $$emit$$"# L_zero_64_bytes:\n\t"
11136        $$emit$$"sub     0x8,rcx\n\t"
11137        $$emit$$"jge     L_loop\n\t"
11138        $$emit$$"add     0x4,rcx\n\t"
11139        $$emit$$"jl      L_tail\n\t"
11140        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11141        $$emit$$"add     0x20,rax\n\t"
11142        $$emit$$"sub     0x4,rcx\n\t"
11143        $$emit$$"# L_tail:\t# Clearing tail bytes\n\t"
11144        $$emit$$"add     0x4,rcx\n\t"
11145        $$emit$$"jle     L_end\n\t"
11146        $$emit$$"dec     rcx\n\t"
11147        $$emit$$"# L_sloop:\t# 8-byte short loop\n\t"
11148        $$emit$$"vmovq   xmm0,(rax)\n\t"
11149        $$emit$$"add     0x8,rax\n\t"
11150        $$emit$$"dec     rcx\n\t"
11151        $$emit$$"jge     L_sloop\n\t"
11152        $$emit$$"# L_end:\n\t"
11153     } else {
11154        $$emit$$"rep     stosq\t# Store rax to *rdi++ while rcx--\n\t"
11155     }
11156     $$emit$$"# DONE"
11157   %}
11158   ins_encode %{
11159     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register,
11160                  $tmp$$XMMRegister, false, $ktmp$$KRegister);
11161   %}
11162   ins_pipe(pipe_slow);
11163 %}
11164 
11165 // Large ClearArray non-AVX512.
11166 instruct rep_stos_large(rcx_RegL cnt, rdi_RegP base, regD tmp, rax_RegI zero,
11167                         Universe dummy, rFlagsReg cr)
11168 %{
11169   predicate((UseAVX <=2) && ((ClearArrayNode*)n)->is_large());
11170   match(Set dummy (ClearArray cnt base));
11171   effect(USE_KILL cnt, USE_KILL base, TEMP tmp, KILL zero, KILL cr);
11172 
11173   format %{ $$template
11174     if (UseFastStosb) {
11175        $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11176        $$emit$$"shlq    rcx,3\t# Convert doublewords to bytes\n\t"
11177        $$emit$$"rep     stosb\t# Store rax to *rdi++ while rcx--"
11178     } else if (UseXMMForObjInit) {
11179        $$emit$$"mov     rdi,rax\t# ClearArray:\n\t"
11180        $$emit$$"vpxor   ymm0,ymm0,ymm0\n\t"
11181        $$emit$$"jmpq    L_zero_64_bytes\n\t"
11182        $$emit$$"# L_loop:\t# 64-byte LOOP\n\t"
11183        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11184        $$emit$$"vmovdqu ymm0,0x20(rax)\n\t"
11185        $$emit$$"add     0x40,rax\n\t"
11186        $$emit$$"# L_zero_64_bytes:\n\t"
11187        $$emit$$"sub     0x8,rcx\n\t"
11188        $$emit$$"jge     L_loop\n\t"
11189        $$emit$$"add     0x4,rcx\n\t"
11190        $$emit$$"jl      L_tail\n\t"
11191        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11192        $$emit$$"add     0x20,rax\n\t"
11193        $$emit$$"sub     0x4,rcx\n\t"
11194        $$emit$$"# L_tail:\t# Clearing tail bytes\n\t"
11195        $$emit$$"add     0x4,rcx\n\t"
11196        $$emit$$"jle     L_end\n\t"
11197        $$emit$$"dec     rcx\n\t"
11198        $$emit$$"# L_sloop:\t# 8-byte short loop\n\t"
11199        $$emit$$"vmovq   xmm0,(rax)\n\t"
11200        $$emit$$"add     0x8,rax\n\t"
11201        $$emit$$"dec     rcx\n\t"
11202        $$emit$$"jge     L_sloop\n\t"
11203        $$emit$$"# L_end:\n\t"
11204     } else {
11205        $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11206        $$emit$$"rep     stosq\t# Store rax to *rdi++ while rcx--"
11207     }
11208   %}
11209   ins_encode %{
11210     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register,
11211                  $tmp$$XMMRegister, true, knoreg);
11212   %}
11213   ins_pipe(pipe_slow);
11214 %}
11215 
11216 // Large ClearArray AVX512.
11217 instruct rep_stos_large_evex(rcx_RegL cnt, rdi_RegP base, legRegD tmp, kReg ktmp, rax_RegI zero,
11218                              Universe dummy, rFlagsReg cr)
11219 %{
11220   predicate((UseAVX > 2) && ((ClearArrayNode*)n)->is_large());
11221   match(Set dummy (ClearArray cnt base));
11222   effect(USE_KILL cnt, USE_KILL base, TEMP tmp, TEMP ktmp, KILL zero, KILL cr);
11223 
11224   format %{ $$template
11225     if (UseFastStosb) {
11226        $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11227        $$emit$$"shlq    rcx,3\t# Convert doublewords to bytes\n\t"
11228        $$emit$$"rep     stosb\t# Store rax to *rdi++ while rcx--"
11229     } else if (UseXMMForObjInit) {
11230        $$emit$$"mov     rdi,rax\t# ClearArray:\n\t"
11231        $$emit$$"vpxor   ymm0,ymm0,ymm0\n\t"
11232        $$emit$$"jmpq    L_zero_64_bytes\n\t"
11233        $$emit$$"# L_loop:\t# 64-byte LOOP\n\t"
11234        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11235        $$emit$$"vmovdqu ymm0,0x20(rax)\n\t"
11236        $$emit$$"add     0x40,rax\n\t"
11237        $$emit$$"# L_zero_64_bytes:\n\t"
11238        $$emit$$"sub     0x8,rcx\n\t"
11239        $$emit$$"jge     L_loop\n\t"
11240        $$emit$$"add     0x4,rcx\n\t"
11241        $$emit$$"jl      L_tail\n\t"
11242        $$emit$$"vmovdqu ymm0,(rax)\n\t"
11243        $$emit$$"add     0x20,rax\n\t"
11244        $$emit$$"sub     0x4,rcx\n\t"
11245        $$emit$$"# L_tail:\t# Clearing tail bytes\n\t"
11246        $$emit$$"add     0x4,rcx\n\t"
11247        $$emit$$"jle     L_end\n\t"
11248        $$emit$$"dec     rcx\n\t"
11249        $$emit$$"# L_sloop:\t# 8-byte short loop\n\t"
11250        $$emit$$"vmovq   xmm0,(rax)\n\t"
11251        $$emit$$"add     0x8,rax\n\t"
11252        $$emit$$"dec     rcx\n\t"
11253        $$emit$$"jge     L_sloop\n\t"
11254        $$emit$$"# L_end:\n\t"
11255     } else {
11256        $$emit$$"xorq    rax, rax\t# ClearArray:\n\t"
11257        $$emit$$"rep     stosq\t# Store rax to *rdi++ while rcx--"
11258     }
11259   %}
11260   ins_encode %{
11261     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register,
11262                  $tmp$$XMMRegister, true, $ktmp$$KRegister);
11263   %}
11264   ins_pipe(pipe_slow);
11265 %}
11266 
11267 // Small ClearArray AVX512 constant length.
11268 instruct rep_stos_im(immL cnt, rRegP base, regD tmp, rRegI zero, kReg ktmp, Universe dummy, rFlagsReg cr)
11269 %{
11270   predicate(!((ClearArrayNode*)n)->is_large() &&
11271               ((UseAVX > 2) && VM_Version::supports_avx512vlbw()));
11272   match(Set dummy (ClearArray cnt base));
11273   ins_cost(100);
11274   effect(TEMP tmp, TEMP zero, TEMP ktmp, KILL cr);
11275   format %{ "clear_mem_imm $base , $cnt  \n\t" %}
11276   ins_encode %{
11277    __ clear_mem($base$$Register, $cnt$$constant, $zero$$Register, $tmp$$XMMRegister, $ktmp$$KRegister);
11278   %}
11279   ins_pipe(pipe_slow);
11280 %}
11281 
11282 instruct string_compareL(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11283                          rax_RegI result, legRegD tmp1, rFlagsReg cr)
11284 %{
11285   predicate(!VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::LL);
11286   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11287   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11288 
11289   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11290   ins_encode %{
11291     __ string_compare($str1$$Register, $str2$$Register,
11292                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11293                       $tmp1$$XMMRegister, StrIntrinsicNode::LL, knoreg);
11294   %}
11295   ins_pipe( pipe_slow );
11296 %}
11297 
11298 instruct string_compareL_evex(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11299                               rax_RegI result, legRegD tmp1, kReg ktmp, rFlagsReg cr)
11300 %{
11301   predicate(VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::LL);
11302   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11303   effect(TEMP tmp1, TEMP ktmp, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11304 
11305   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11306   ins_encode %{
11307     __ string_compare($str1$$Register, $str2$$Register,
11308                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11309                       $tmp1$$XMMRegister, StrIntrinsicNode::LL, $ktmp$$KRegister);
11310   %}
11311   ins_pipe( pipe_slow );
11312 %}
11313 
11314 instruct string_compareU(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11315                          rax_RegI result, legRegD tmp1, rFlagsReg cr)
11316 %{
11317   predicate(!VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::UU);
11318   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11319   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11320 
11321   format %{ "String Compare char[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11322   ins_encode %{
11323     __ string_compare($str1$$Register, $str2$$Register,
11324                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11325                       $tmp1$$XMMRegister, StrIntrinsicNode::UU, knoreg);
11326   %}
11327   ins_pipe( pipe_slow );
11328 %}
11329 
11330 instruct string_compareU_evex(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11331                               rax_RegI result, legRegD tmp1, kReg ktmp, rFlagsReg cr)
11332 %{
11333   predicate(VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::UU);
11334   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11335   effect(TEMP tmp1, TEMP ktmp, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11336 
11337   format %{ "String Compare char[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11338   ins_encode %{
11339     __ string_compare($str1$$Register, $str2$$Register,
11340                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11341                       $tmp1$$XMMRegister, StrIntrinsicNode::UU, $ktmp$$KRegister);
11342   %}
11343   ins_pipe( pipe_slow );
11344 %}
11345 
11346 instruct string_compareLU(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11347                           rax_RegI result, legRegD tmp1, rFlagsReg cr)
11348 %{
11349   predicate(!VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::LU);
11350   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11351   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11352 
11353   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11354   ins_encode %{
11355     __ string_compare($str1$$Register, $str2$$Register,
11356                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11357                       $tmp1$$XMMRegister, StrIntrinsicNode::LU, knoreg);
11358   %}
11359   ins_pipe( pipe_slow );
11360 %}
11361 
11362 instruct string_compareLU_evex(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11363                                rax_RegI result, legRegD tmp1, kReg ktmp, rFlagsReg cr)
11364 %{
11365   predicate(VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::LU);
11366   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11367   effect(TEMP tmp1, TEMP ktmp, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11368 
11369   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11370   ins_encode %{
11371     __ string_compare($str1$$Register, $str2$$Register,
11372                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11373                       $tmp1$$XMMRegister, StrIntrinsicNode::LU, $ktmp$$KRegister);
11374   %}
11375   ins_pipe( pipe_slow );
11376 %}
11377 
11378 instruct string_compareUL(rsi_RegP str1, rdx_RegI cnt1, rdi_RegP str2, rcx_RegI cnt2,
11379                           rax_RegI result, legRegD tmp1, rFlagsReg cr)
11380 %{
11381   predicate(!VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::UL);
11382   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11383   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11384 
11385   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11386   ins_encode %{
11387     __ string_compare($str2$$Register, $str1$$Register,
11388                       $cnt2$$Register, $cnt1$$Register, $result$$Register,
11389                       $tmp1$$XMMRegister, StrIntrinsicNode::UL, knoreg);
11390   %}
11391   ins_pipe( pipe_slow );
11392 %}
11393 
11394 instruct string_compareUL_evex(rsi_RegP str1, rdx_RegI cnt1, rdi_RegP str2, rcx_RegI cnt2,
11395                                rax_RegI result, legRegD tmp1, kReg ktmp, rFlagsReg cr)
11396 %{
11397   predicate(VM_Version::supports_avx512vlbw() && ((StrCompNode*)n)->encoding() == StrIntrinsicNode::UL);
11398   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11399   effect(TEMP tmp1, TEMP ktmp, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11400 
11401   format %{ "String Compare byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11402   ins_encode %{
11403     __ string_compare($str2$$Register, $str1$$Register,
11404                       $cnt2$$Register, $cnt1$$Register, $result$$Register,
11405                       $tmp1$$XMMRegister, StrIntrinsicNode::UL, $ktmp$$KRegister);
11406   %}
11407   ins_pipe( pipe_slow );
11408 %}
11409 
11410 // fast search of substring with known size.
11411 instruct string_indexof_conL(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, immI int_cnt2,
11412                              rbx_RegI result, legRegD tmp_vec, rax_RegI cnt2, rcx_RegI tmp, rFlagsReg cr)
11413 %{
11414   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LL));
11415   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
11416   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
11417 
11418   format %{ "String IndexOf byte[] $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $tmp_vec, $cnt1, $cnt2, $tmp" %}
11419   ins_encode %{
11420     int icnt2 = (int)$int_cnt2$$constant;
11421     if (icnt2 >= 16) {
11422       // IndexOf for constant substrings with size >= 16 elements
11423       // which don't need to be loaded through stack.
11424       __ string_indexofC8($str1$$Register, $str2$$Register,
11425                           $cnt1$$Register, $cnt2$$Register,
11426                           icnt2, $result$$Register,
11427                           $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::LL);
11428     } else {
11429       // Small strings are loaded through stack if they cross page boundary.
11430       __ string_indexof($str1$$Register, $str2$$Register,
11431                         $cnt1$$Register, $cnt2$$Register,
11432                         icnt2, $result$$Register,
11433                         $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::LL);
11434     }
11435   %}
11436   ins_pipe( pipe_slow );
11437 %}
11438 
11439 // fast search of substring with known size.
11440 instruct string_indexof_conU(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, immI int_cnt2,
11441                              rbx_RegI result, legRegD tmp_vec, rax_RegI cnt2, rcx_RegI tmp, rFlagsReg cr)
11442 %{
11443   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UU));
11444   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
11445   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
11446 
11447   format %{ "String IndexOf char[] $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $tmp_vec, $cnt1, $cnt2, $tmp" %}
11448   ins_encode %{
11449     int icnt2 = (int)$int_cnt2$$constant;
11450     if (icnt2 >= 8) {
11451       // IndexOf for constant substrings with size >= 8 elements
11452       // which don't need to be loaded through stack.
11453       __ string_indexofC8($str1$$Register, $str2$$Register,
11454                           $cnt1$$Register, $cnt2$$Register,
11455                           icnt2, $result$$Register,
11456                           $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UU);
11457     } else {
11458       // Small strings are loaded through stack if they cross page boundary.
11459       __ string_indexof($str1$$Register, $str2$$Register,
11460                         $cnt1$$Register, $cnt2$$Register,
11461                         icnt2, $result$$Register,
11462                         $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UU);
11463     }
11464   %}
11465   ins_pipe( pipe_slow );
11466 %}
11467 
11468 // fast search of substring with known size.
11469 instruct string_indexof_conUL(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, immI int_cnt2,
11470                               rbx_RegI result, legRegD tmp_vec, rax_RegI cnt2, rcx_RegI tmp, rFlagsReg cr)
11471 %{
11472   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UL));
11473   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
11474   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
11475 
11476   format %{ "String IndexOf char[] $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $tmp_vec, $cnt1, $cnt2, $tmp" %}
11477   ins_encode %{
11478     int icnt2 = (int)$int_cnt2$$constant;
11479     if (icnt2 >= 8) {
11480       // IndexOf for constant substrings with size >= 8 elements
11481       // which don't need to be loaded through stack.
11482       __ string_indexofC8($str1$$Register, $str2$$Register,
11483                           $cnt1$$Register, $cnt2$$Register,
11484                           icnt2, $result$$Register,
11485                           $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UL);
11486     } else {
11487       // Small strings are loaded through stack if they cross page boundary.
11488       __ string_indexof($str1$$Register, $str2$$Register,
11489                         $cnt1$$Register, $cnt2$$Register,
11490                         icnt2, $result$$Register,
11491                         $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UL);
11492     }
11493   %}
11494   ins_pipe( pipe_slow );
11495 %}
11496 
11497 instruct string_indexofL(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2,
11498                          rbx_RegI result, legRegD tmp_vec, rcx_RegI tmp, rFlagsReg cr)
11499 %{
11500   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::LL));
11501   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
11502   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
11503 
11504   format %{ "String IndexOf byte[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
11505   ins_encode %{
11506     __ string_indexof($str1$$Register, $str2$$Register,
11507                       $cnt1$$Register, $cnt2$$Register,
11508                       (-1), $result$$Register,
11509                       $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::LL);
11510   %}
11511   ins_pipe( pipe_slow );
11512 %}
11513 
11514 instruct string_indexofU(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2,
11515                          rbx_RegI result, legRegD tmp_vec, rcx_RegI tmp, rFlagsReg cr)
11516 %{
11517   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UU));
11518   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
11519   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
11520 
11521   format %{ "String IndexOf char[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
11522   ins_encode %{
11523     __ string_indexof($str1$$Register, $str2$$Register,
11524                       $cnt1$$Register, $cnt2$$Register,
11525                       (-1), $result$$Register,
11526                       $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UU);
11527   %}
11528   ins_pipe( pipe_slow );
11529 %}
11530 
11531 instruct string_indexofUL(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2,
11532                           rbx_RegI result, legRegD tmp_vec, rcx_RegI tmp, rFlagsReg cr)
11533 %{
11534   predicate(UseSSE42Intrinsics && (((StrIndexOfNode*)n)->encoding() == StrIntrinsicNode::UL));
11535   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
11536   effect(TEMP tmp_vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
11537 
11538   format %{ "String IndexOf char[] $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
11539   ins_encode %{
11540     __ string_indexof($str1$$Register, $str2$$Register,
11541                       $cnt1$$Register, $cnt2$$Register,
11542                       (-1), $result$$Register,
11543                       $tmp_vec$$XMMRegister, $tmp$$Register, StrIntrinsicNode::UL);
11544   %}
11545   ins_pipe( pipe_slow );
11546 %}
11547 
11548 instruct string_indexof_char(rdi_RegP str1, rdx_RegI cnt1, rax_RegI ch,
11549                               rbx_RegI result, legRegD tmp_vec1, legRegD tmp_vec2, legRegD tmp_vec3, rcx_RegI tmp, rFlagsReg cr)
11550 %{
11551   predicate(UseSSE42Intrinsics && (((StrIndexOfCharNode*)n)->encoding() == StrIntrinsicNode::U));
11552   match(Set result (StrIndexOfChar (Binary str1 cnt1) ch));
11553   effect(TEMP tmp_vec1, TEMP tmp_vec2, TEMP tmp_vec3, USE_KILL str1, USE_KILL cnt1, USE_KILL ch, TEMP tmp, KILL cr);
11554   format %{ "StringUTF16 IndexOf char[] $str1,$cnt1,$ch -> $result   // KILL all" %}
11555   ins_encode %{
11556     __ string_indexof_char($str1$$Register, $cnt1$$Register, $ch$$Register, $result$$Register,
11557                            $tmp_vec1$$XMMRegister, $tmp_vec2$$XMMRegister, $tmp_vec3$$XMMRegister, $tmp$$Register);
11558   %}
11559   ins_pipe( pipe_slow );
11560 %}
11561 
11562 instruct stringL_indexof_char(rdi_RegP str1, rdx_RegI cnt1, rax_RegI ch,
11563                               rbx_RegI result, legRegD tmp_vec1, legRegD tmp_vec2, legRegD tmp_vec3, rcx_RegI tmp, rFlagsReg cr)
11564 %{
11565   predicate(UseSSE42Intrinsics && (((StrIndexOfCharNode*)n)->encoding() == StrIntrinsicNode::L));
11566   match(Set result (StrIndexOfChar (Binary str1 cnt1) ch));
11567   effect(TEMP tmp_vec1, TEMP tmp_vec2, TEMP tmp_vec3, USE_KILL str1, USE_KILL cnt1, USE_KILL ch, TEMP tmp, KILL cr);
11568   format %{ "StringLatin1 IndexOf char[] $str1,$cnt1,$ch -> $result   // KILL all" %}
11569   ins_encode %{
11570     __ stringL_indexof_char($str1$$Register, $cnt1$$Register, $ch$$Register, $result$$Register,
11571                            $tmp_vec1$$XMMRegister, $tmp_vec2$$XMMRegister, $tmp_vec3$$XMMRegister, $tmp$$Register);
11572   %}
11573   ins_pipe( pipe_slow );
11574 %}
11575 
11576 // fast string equals
11577 instruct string_equals(rdi_RegP str1, rsi_RegP str2, rcx_RegI cnt, rax_RegI result,
11578                        legRegD tmp1, legRegD tmp2, rbx_RegI tmp3, rFlagsReg cr)
11579 %{
11580   predicate(!VM_Version::supports_avx512vlbw());
11581   match(Set result (StrEquals (Binary str1 str2) cnt));
11582   effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
11583 
11584   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
11585   ins_encode %{
11586     __ arrays_equals(false, $str1$$Register, $str2$$Register,
11587                      $cnt$$Register, $result$$Register, $tmp3$$Register,
11588                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, false /* char */, knoreg);
11589   %}
11590   ins_pipe( pipe_slow );
11591 %}
11592 
11593 instruct string_equals_evex(rdi_RegP str1, rsi_RegP str2, rcx_RegI cnt, rax_RegI result,
11594                            legRegD tmp1, legRegD tmp2, kReg ktmp, rbx_RegI tmp3, rFlagsReg cr)
11595 %{
11596   predicate(VM_Version::supports_avx512vlbw());
11597   match(Set result (StrEquals (Binary str1 str2) cnt));
11598   effect(TEMP tmp1, TEMP tmp2, TEMP ktmp, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
11599 
11600   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
11601   ins_encode %{
11602     __ arrays_equals(false, $str1$$Register, $str2$$Register,
11603                      $cnt$$Register, $result$$Register, $tmp3$$Register,
11604                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, false /* char */, $ktmp$$KRegister);
11605   %}
11606   ins_pipe( pipe_slow );
11607 %}
11608 
11609 // fast array equals
11610 instruct array_equalsB(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
11611                        legRegD tmp1, legRegD tmp2, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
11612 %{
11613   predicate(!VM_Version::supports_avx512vlbw() && ((AryEqNode*)n)->encoding() == StrIntrinsicNode::LL);
11614   match(Set result (AryEq ary1 ary2));
11615   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11616 
11617   format %{ "Array Equals byte[] $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11618   ins_encode %{
11619     __ arrays_equals(true, $ary1$$Register, $ary2$$Register,
11620                      $tmp3$$Register, $result$$Register, $tmp4$$Register,
11621                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, false /* char */, knoreg);
11622   %}
11623   ins_pipe( pipe_slow );
11624 %}
11625 
11626 instruct array_equalsB_evex(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
11627                             legRegD tmp1, legRegD tmp2, kReg ktmp, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
11628 %{
11629   predicate(VM_Version::supports_avx512vlbw() && ((AryEqNode*)n)->encoding() == StrIntrinsicNode::LL);
11630   match(Set result (AryEq ary1 ary2));
11631   effect(TEMP tmp1, TEMP tmp2, TEMP ktmp, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11632 
11633   format %{ "Array Equals byte[] $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11634   ins_encode %{
11635     __ arrays_equals(true, $ary1$$Register, $ary2$$Register,
11636                      $tmp3$$Register, $result$$Register, $tmp4$$Register,
11637                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, false /* char */, $ktmp$$KRegister);
11638   %}
11639   ins_pipe( pipe_slow );
11640 %}
11641 
11642 instruct array_equalsC(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
11643                        legRegD tmp1, legRegD tmp2, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
11644 %{
11645   predicate(!VM_Version::supports_avx512vlbw() && ((AryEqNode*)n)->encoding() == StrIntrinsicNode::UU);
11646   match(Set result (AryEq ary1 ary2));
11647   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11648 
11649   format %{ "Array Equals char[] $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11650   ins_encode %{
11651     __ arrays_equals(true, $ary1$$Register, $ary2$$Register,
11652                      $tmp3$$Register, $result$$Register, $tmp4$$Register,
11653                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, true /* char */, knoreg);
11654   %}
11655   ins_pipe( pipe_slow );
11656 %}
11657 
11658 instruct array_equalsC_evex(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
11659                             legRegD tmp1, legRegD tmp2, kReg ktmp, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
11660 %{
11661   predicate(VM_Version::supports_avx512vlbw() && ((AryEqNode*)n)->encoding() == StrIntrinsicNode::UU);
11662   match(Set result (AryEq ary1 ary2));
11663   effect(TEMP tmp1, TEMP tmp2, TEMP ktmp, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11664 
11665   format %{ "Array Equals char[] $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11666   ins_encode %{
11667     __ arrays_equals(true, $ary1$$Register, $ary2$$Register,
11668                      $tmp3$$Register, $result$$Register, $tmp4$$Register,
11669                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, true /* char */, $ktmp$$KRegister);
11670   %}
11671   ins_pipe( pipe_slow );
11672 %}
11673 
11674 instruct has_negatives(rsi_RegP ary1, rcx_RegI len, rax_RegI result,
11675                        legRegD tmp1, legRegD tmp2, rbx_RegI tmp3, rFlagsReg cr,)
11676 %{
11677   predicate(!VM_Version::supports_avx512vlbw() || !VM_Version::supports_bmi2());
11678   match(Set result (HasNegatives ary1 len));
11679   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL len, KILL tmp3, KILL cr);
11680 
11681   format %{ "has negatives byte[] $ary1,$len -> $result   // KILL $tmp1, $tmp2, $tmp3" %}
11682   ins_encode %{
11683     __ has_negatives($ary1$$Register, $len$$Register,
11684                      $result$$Register, $tmp3$$Register,
11685                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, knoreg, knoreg);
11686   %}
11687   ins_pipe( pipe_slow );
11688 %}
11689 
11690 instruct has_negatives_evex(rsi_RegP ary1, rcx_RegI len, rax_RegI result,
11691                             legRegD tmp1, legRegD tmp2, kReg ktmp1, kReg ktmp2, rbx_RegI tmp3, rFlagsReg cr,)
11692 %{
11693   predicate(VM_Version::supports_avx512vlbw() && VM_Version::supports_bmi2());
11694   match(Set result (HasNegatives ary1 len));
11695   effect(TEMP tmp1, TEMP tmp2, TEMP ktmp1, TEMP ktmp2, USE_KILL ary1, USE_KILL len, KILL tmp3, KILL cr);
11696 
11697   format %{ "has negatives byte[] $ary1,$len -> $result   // KILL $tmp1, $tmp2, $tmp3" %}
11698   ins_encode %{
11699     __ has_negatives($ary1$$Register, $len$$Register,
11700                      $result$$Register, $tmp3$$Register,
11701                      $tmp1$$XMMRegister, $tmp2$$XMMRegister, $ktmp1$$KRegister, $ktmp2$$KRegister);
11702   %}
11703   ins_pipe( pipe_slow );
11704 %}
11705 
11706 // fast char[] to byte[] compression
11707 instruct string_compress(rsi_RegP src, rdi_RegP dst, rdx_RegI len, legRegD tmp1, legRegD tmp2, legRegD tmp3,
11708                          legRegD tmp4, rcx_RegI tmp5, rax_RegI result, rFlagsReg cr) %{
11709   predicate(!VM_Version::supports_avx512vlbw() || !VM_Version::supports_bmi2());
11710   match(Set result (StrCompressedCopy src (Binary dst len)));
11711   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, USE_KILL src, USE_KILL dst,
11712          USE_KILL len, KILL tmp5, KILL cr);
11713 
11714   format %{ "String Compress $src,$dst -> $result    // KILL RAX, RCX, RDX" %}
11715   ins_encode %{
11716     __ char_array_compress($src$$Register, $dst$$Register, $len$$Register,
11717                            $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
11718                            $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register,
11719                            knoreg, knoreg);
11720   %}
11721   ins_pipe( pipe_slow );
11722 %}
11723 
11724 instruct string_compress_evex(rsi_RegP src, rdi_RegP dst, rdx_RegI len, legRegD tmp1, legRegD tmp2, legRegD tmp3,
11725                               legRegD tmp4, kReg ktmp1, kReg ktmp2, rcx_RegI tmp5, rax_RegI result, rFlagsReg cr) %{
11726   predicate(VM_Version::supports_avx512vlbw() && VM_Version::supports_bmi2());
11727   match(Set result (StrCompressedCopy src (Binary dst len)));
11728   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, TEMP ktmp1, TEMP ktmp2, USE_KILL src, USE_KILL dst,
11729          USE_KILL len, KILL tmp5, KILL cr);
11730 
11731   format %{ "String Compress $src,$dst -> $result    // KILL RAX, RCX, RDX" %}
11732   ins_encode %{
11733     __ char_array_compress($src$$Register, $dst$$Register, $len$$Register,
11734                            $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
11735                            $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register,
11736                            $ktmp1$$KRegister, $ktmp2$$KRegister);
11737   %}
11738   ins_pipe( pipe_slow );
11739 %}
11740 // fast byte[] to char[] inflation
11741 instruct string_inflate(Universe dummy, rsi_RegP src, rdi_RegP dst, rdx_RegI len,
11742                         legRegD tmp1, rcx_RegI tmp2, rFlagsReg cr) %{
11743   predicate(!VM_Version::supports_avx512vlbw() || !VM_Version::supports_bmi2());
11744   match(Set dummy (StrInflatedCopy src (Binary dst len)));
11745   effect(TEMP tmp1, TEMP tmp2, USE_KILL src, USE_KILL dst, USE_KILL len, KILL cr);
11746 
11747   format %{ "String Inflate $src,$dst    // KILL $tmp1, $tmp2" %}
11748   ins_encode %{
11749     __ byte_array_inflate($src$$Register, $dst$$Register, $len$$Register,
11750                           $tmp1$$XMMRegister, $tmp2$$Register, knoreg);
11751   %}
11752   ins_pipe( pipe_slow );
11753 %}
11754 
11755 instruct string_inflate_evex(Universe dummy, rsi_RegP src, rdi_RegP dst, rdx_RegI len,
11756                              legRegD tmp1, kReg ktmp, rcx_RegI tmp2, rFlagsReg cr) %{
11757   predicate(VM_Version::supports_avx512vlbw() && VM_Version::supports_bmi2());
11758   match(Set dummy (StrInflatedCopy src (Binary dst len)));
11759   effect(TEMP tmp1, TEMP tmp2, TEMP ktmp, USE_KILL src, USE_KILL dst, USE_KILL len, KILL cr);
11760 
11761   format %{ "String Inflate $src,$dst    // KILL $tmp1, $tmp2" %}
11762   ins_encode %{
11763     __ byte_array_inflate($src$$Register, $dst$$Register, $len$$Register,
11764                           $tmp1$$XMMRegister, $tmp2$$Register, $ktmp$$KRegister);
11765   %}
11766   ins_pipe( pipe_slow );
11767 %}
11768 
11769 // encode char[] to byte[] in ISO_8859_1
11770 instruct encode_iso_array(rsi_RegP src, rdi_RegP dst, rdx_RegI len,
11771                           legRegD tmp1, legRegD tmp2, legRegD tmp3, legRegD tmp4,
11772                           rcx_RegI tmp5, rax_RegI result, rFlagsReg cr) %{
11773   predicate(!((EncodeISOArrayNode*)n)->is_ascii());
11774   match(Set result (EncodeISOArray src (Binary dst len)));
11775   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, USE_KILL src, USE_KILL dst, USE_KILL len, KILL tmp5, KILL cr);
11776 
11777   format %{ "Encode iso array $src,$dst,$len -> $result    // KILL RCX, RDX, $tmp1, $tmp2, $tmp3, $tmp4, RSI, RDI " %}
11778   ins_encode %{
11779     __ encode_iso_array($src$$Register, $dst$$Register, $len$$Register,
11780                         $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
11781                         $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register, false);
11782   %}
11783   ins_pipe( pipe_slow );
11784 %}
11785 
11786 // encode char[] to byte[] in ASCII
11787 instruct encode_ascii_array(rsi_RegP src, rdi_RegP dst, rdx_RegI len,
11788                             legRegD tmp1, legRegD tmp2, legRegD tmp3, legRegD tmp4,
11789                             rcx_RegI tmp5, rax_RegI result, rFlagsReg cr) %{
11790   predicate(((EncodeISOArrayNode*)n)->is_ascii());
11791   match(Set result (EncodeISOArray src (Binary dst len)));
11792   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, USE_KILL src, USE_KILL dst, USE_KILL len, KILL tmp5, KILL cr);
11793 
11794   format %{ "Encode ascii array $src,$dst,$len -> $result    // KILL RCX, RDX, $tmp1, $tmp2, $tmp3, $tmp4, RSI, RDI " %}
11795   ins_encode %{
11796     __ encode_iso_array($src$$Register, $dst$$Register, $len$$Register,
11797                         $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
11798                         $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register, true);
11799   %}
11800   ins_pipe( pipe_slow );
11801 %}
11802 
11803 //----------Overflow Math Instructions-----------------------------------------
11804 
11805 instruct overflowAddI_rReg(rFlagsReg cr, rax_RegI op1, rRegI op2)
11806 %{
11807   match(Set cr (OverflowAddI op1 op2));
11808   effect(DEF cr, USE_KILL op1, USE op2);
11809 
11810   format %{ "addl    $op1, $op2\t# overflow check int" %}
11811 
11812   ins_encode %{
11813     __ addl($op1$$Register, $op2$$Register);
11814   %}
11815   ins_pipe(ialu_reg_reg);
11816 %}
11817 
11818 instruct overflowAddI_rReg_imm(rFlagsReg cr, rax_RegI op1, immI op2)
11819 %{
11820   match(Set cr (OverflowAddI op1 op2));
11821   effect(DEF cr, USE_KILL op1, USE op2);
11822 
11823   format %{ "addl    $op1, $op2\t# overflow check int" %}
11824 
11825   ins_encode %{
11826     __ addl($op1$$Register, $op2$$constant);
11827   %}
11828   ins_pipe(ialu_reg_reg);
11829 %}
11830 
11831 instruct overflowAddL_rReg(rFlagsReg cr, rax_RegL op1, rRegL op2)
11832 %{
11833   match(Set cr (OverflowAddL op1 op2));
11834   effect(DEF cr, USE_KILL op1, USE op2);
11835 
11836   format %{ "addq    $op1, $op2\t# overflow check long" %}
11837   ins_encode %{
11838     __ addq($op1$$Register, $op2$$Register);
11839   %}
11840   ins_pipe(ialu_reg_reg);
11841 %}
11842 
11843 instruct overflowAddL_rReg_imm(rFlagsReg cr, rax_RegL op1, immL32 op2)
11844 %{
11845   match(Set cr (OverflowAddL op1 op2));
11846   effect(DEF cr, USE_KILL op1, USE op2);
11847 
11848   format %{ "addq    $op1, $op2\t# overflow check long" %}
11849   ins_encode %{
11850     __ addq($op1$$Register, $op2$$constant);
11851   %}
11852   ins_pipe(ialu_reg_reg);
11853 %}
11854 
11855 instruct overflowSubI_rReg(rFlagsReg cr, rRegI op1, rRegI op2)
11856 %{
11857   match(Set cr (OverflowSubI op1 op2));
11858 
11859   format %{ "cmpl    $op1, $op2\t# overflow check int" %}
11860   ins_encode %{
11861     __ cmpl($op1$$Register, $op2$$Register);
11862   %}
11863   ins_pipe(ialu_reg_reg);
11864 %}
11865 
11866 instruct overflowSubI_rReg_imm(rFlagsReg cr, rRegI op1, immI op2)
11867 %{
11868   match(Set cr (OverflowSubI op1 op2));
11869 
11870   format %{ "cmpl    $op1, $op2\t# overflow check int" %}
11871   ins_encode %{
11872     __ cmpl($op1$$Register, $op2$$constant);
11873   %}
11874   ins_pipe(ialu_reg_reg);
11875 %}
11876 
11877 instruct overflowSubL_rReg(rFlagsReg cr, rRegL op1, rRegL op2)
11878 %{
11879   match(Set cr (OverflowSubL op1 op2));
11880 
11881   format %{ "cmpq    $op1, $op2\t# overflow check long" %}
11882   ins_encode %{
11883     __ cmpq($op1$$Register, $op2$$Register);
11884   %}
11885   ins_pipe(ialu_reg_reg);
11886 %}
11887 
11888 instruct overflowSubL_rReg_imm(rFlagsReg cr, rRegL op1, immL32 op2)
11889 %{
11890   match(Set cr (OverflowSubL op1 op2));
11891 
11892   format %{ "cmpq    $op1, $op2\t# overflow check long" %}
11893   ins_encode %{
11894     __ cmpq($op1$$Register, $op2$$constant);
11895   %}
11896   ins_pipe(ialu_reg_reg);
11897 %}
11898 
11899 instruct overflowNegI_rReg(rFlagsReg cr, immI_0 zero, rax_RegI op2)
11900 %{
11901   match(Set cr (OverflowSubI zero op2));
11902   effect(DEF cr, USE_KILL op2);
11903 
11904   format %{ "negl    $op2\t# overflow check int" %}
11905   ins_encode %{
11906     __ negl($op2$$Register);
11907   %}
11908   ins_pipe(ialu_reg_reg);
11909 %}
11910 
11911 instruct overflowNegL_rReg(rFlagsReg cr, immL0 zero, rax_RegL op2)
11912 %{
11913   match(Set cr (OverflowSubL zero op2));
11914   effect(DEF cr, USE_KILL op2);
11915 
11916   format %{ "negq    $op2\t# overflow check long" %}
11917   ins_encode %{
11918     __ negq($op2$$Register);
11919   %}
11920   ins_pipe(ialu_reg_reg);
11921 %}
11922 
11923 instruct overflowMulI_rReg(rFlagsReg cr, rax_RegI op1, rRegI op2)
11924 %{
11925   match(Set cr (OverflowMulI op1 op2));
11926   effect(DEF cr, USE_KILL op1, USE op2);
11927 
11928   format %{ "imull    $op1, $op2\t# overflow check int" %}
11929   ins_encode %{
11930     __ imull($op1$$Register, $op2$$Register);
11931   %}
11932   ins_pipe(ialu_reg_reg_alu0);
11933 %}
11934 
11935 instruct overflowMulI_rReg_imm(rFlagsReg cr, rRegI op1, immI op2, rRegI tmp)
11936 %{
11937   match(Set cr (OverflowMulI op1 op2));
11938   effect(DEF cr, TEMP tmp, USE op1, USE op2);
11939 
11940   format %{ "imull    $tmp, $op1, $op2\t# overflow check int" %}
11941   ins_encode %{
11942     __ imull($tmp$$Register, $op1$$Register, $op2$$constant);
11943   %}
11944   ins_pipe(ialu_reg_reg_alu0);
11945 %}
11946 
11947 instruct overflowMulL_rReg(rFlagsReg cr, rax_RegL op1, rRegL op2)
11948 %{
11949   match(Set cr (OverflowMulL op1 op2));
11950   effect(DEF cr, USE_KILL op1, USE op2);
11951 
11952   format %{ "imulq    $op1, $op2\t# overflow check long" %}
11953   ins_encode %{
11954     __ imulq($op1$$Register, $op2$$Register);
11955   %}
11956   ins_pipe(ialu_reg_reg_alu0);
11957 %}
11958 
11959 instruct overflowMulL_rReg_imm(rFlagsReg cr, rRegL op1, immL32 op2, rRegL tmp)
11960 %{
11961   match(Set cr (OverflowMulL op1 op2));
11962   effect(DEF cr, TEMP tmp, USE op1, USE op2);
11963 
11964   format %{ "imulq    $tmp, $op1, $op2\t# overflow check long" %}
11965   ins_encode %{
11966     __ imulq($tmp$$Register, $op1$$Register, $op2$$constant);
11967   %}
11968   ins_pipe(ialu_reg_reg_alu0);
11969 %}
11970 
11971 
11972 //----------Control Flow Instructions------------------------------------------
11973 // Signed compare Instructions
11974 
11975 // XXX more variants!!
11976 instruct compI_rReg(rFlagsReg cr, rRegI op1, rRegI op2)
11977 %{
11978   match(Set cr (CmpI op1 op2));
11979   effect(DEF cr, USE op1, USE op2);
11980 
11981   format %{ "cmpl    $op1, $op2" %}
11982   ins_encode %{
11983     __ cmpl($op1$$Register, $op2$$Register);
11984   %}
11985   ins_pipe(ialu_cr_reg_reg);
11986 %}
11987 
11988 instruct compI_rReg_imm(rFlagsReg cr, rRegI op1, immI op2)
11989 %{
11990   match(Set cr (CmpI op1 op2));
11991 
11992   format %{ "cmpl    $op1, $op2" %}
11993   ins_encode %{
11994     __ cmpl($op1$$Register, $op2$$constant);
11995   %}
11996   ins_pipe(ialu_cr_reg_imm);
11997 %}
11998 
11999 instruct compI_rReg_mem(rFlagsReg cr, rRegI op1, memory op2)
12000 %{
12001   match(Set cr (CmpI op1 (LoadI op2)));
12002 
12003   ins_cost(500); // XXX
12004   format %{ "cmpl    $op1, $op2" %}
12005   ins_encode %{
12006     __ cmpl($op1$$Register, $op2$$Address);
12007   %}
12008   ins_pipe(ialu_cr_reg_mem);
12009 %}
12010 
12011 instruct testI_reg(rFlagsReg cr, rRegI src, immI_0 zero)
12012 %{
12013   match(Set cr (CmpI src zero));
12014 
12015   format %{ "testl   $src, $src" %}
12016   ins_encode %{
12017     __ testl($src$$Register, $src$$Register);
12018   %}
12019   ins_pipe(ialu_cr_reg_imm);
12020 %}
12021 
12022 instruct testI_reg_imm(rFlagsReg cr, rRegI src, immI con, immI_0 zero)
12023 %{
12024   match(Set cr (CmpI (AndI src con) zero));
12025 
12026   format %{ "testl   $src, $con" %}
12027   ins_encode %{
12028     __ testl($src$$Register, $con$$constant);
12029   %}
12030   ins_pipe(ialu_cr_reg_imm);
12031 %}
12032 
12033 instruct testI_reg_mem(rFlagsReg cr, rRegI src, memory mem, immI_0 zero)
12034 %{
12035   match(Set cr (CmpI (AndI src (LoadI mem)) zero));
12036 
12037   format %{ "testl   $src, $mem" %}
12038   ins_encode %{
12039     __ testl($src$$Register, $mem$$Address);
12040   %}
12041   ins_pipe(ialu_cr_reg_mem);
12042 %}
12043 
12044 // Unsigned compare Instructions; really, same as signed except they
12045 // produce an rFlagsRegU instead of rFlagsReg.
12046 instruct compU_rReg(rFlagsRegU cr, rRegI op1, rRegI op2)
12047 %{
12048   match(Set cr (CmpU op1 op2));
12049 
12050   format %{ "cmpl    $op1, $op2\t# unsigned" %}
12051   ins_encode %{
12052     __ cmpl($op1$$Register, $op2$$Register);
12053   %}
12054   ins_pipe(ialu_cr_reg_reg);
12055 %}
12056 
12057 instruct compU_rReg_imm(rFlagsRegU cr, rRegI op1, immI op2)
12058 %{
12059   match(Set cr (CmpU op1 op2));
12060 
12061   format %{ "cmpl    $op1, $op2\t# unsigned" %}
12062   ins_encode %{
12063     __ cmpl($op1$$Register, $op2$$constant);
12064   %}
12065   ins_pipe(ialu_cr_reg_imm);
12066 %}
12067 
12068 instruct compU_rReg_mem(rFlagsRegU cr, rRegI op1, memory op2)
12069 %{
12070   match(Set cr (CmpU op1 (LoadI op2)));
12071 
12072   ins_cost(500); // XXX
12073   format %{ "cmpl    $op1, $op2\t# unsigned" %}
12074   ins_encode %{
12075     __ cmpl($op1$$Register, $op2$$Address);
12076   %}
12077   ins_pipe(ialu_cr_reg_mem);
12078 %}
12079 
12080 // // // Cisc-spilled version of cmpU_rReg
12081 // //instruct compU_mem_rReg(rFlagsRegU cr, memory op1, rRegI op2)
12082 // //%{
12083 // //  match(Set cr (CmpU (LoadI op1) op2));
12084 // //
12085 // //  format %{ "CMPu   $op1,$op2" %}
12086 // //  ins_cost(500);
12087 // //  opcode(0x39);  /* Opcode 39 /r */
12088 // //  ins_encode( OpcP, reg_mem( op1, op2) );
12089 // //%}
12090 
12091 instruct testU_reg(rFlagsRegU cr, rRegI src, immI_0 zero)
12092 %{
12093   match(Set cr (CmpU src zero));
12094 
12095   format %{ "testl   $src, $src\t# unsigned" %}
12096   ins_encode %{
12097     __ testl($src$$Register, $src$$Register);
12098   %}
12099   ins_pipe(ialu_cr_reg_imm);
12100 %}
12101 
12102 instruct compP_rReg(rFlagsRegU cr, rRegP op1, rRegP op2)
12103 %{
12104   match(Set cr (CmpP op1 op2));
12105 
12106   format %{ "cmpq    $op1, $op2\t# ptr" %}
12107   ins_encode %{
12108     __ cmpq($op1$$Register, $op2$$Register);
12109   %}
12110   ins_pipe(ialu_cr_reg_reg);
12111 %}
12112 
12113 instruct compP_rReg_mem(rFlagsRegU cr, rRegP op1, memory op2)
12114 %{
12115   match(Set cr (CmpP op1 (LoadP op2)));
12116   predicate(n->in(2)->as_Load()->barrier_data() == 0);
12117 
12118   ins_cost(500); // XXX
12119   format %{ "cmpq    $op1, $op2\t# ptr" %}
12120   ins_encode %{
12121     __ cmpq($op1$$Register, $op2$$Address);
12122   %}
12123   ins_pipe(ialu_cr_reg_mem);
12124 %}
12125 
12126 // // // Cisc-spilled version of cmpP_rReg
12127 // //instruct compP_mem_rReg(rFlagsRegU cr, memory op1, rRegP op2)
12128 // //%{
12129 // //  match(Set cr (CmpP (LoadP op1) op2));
12130 // //
12131 // //  format %{ "CMPu   $op1,$op2" %}
12132 // //  ins_cost(500);
12133 // //  opcode(0x39);  /* Opcode 39 /r */
12134 // //  ins_encode( OpcP, reg_mem( op1, op2) );
12135 // //%}
12136 
12137 // XXX this is generalized by compP_rReg_mem???
12138 // Compare raw pointer (used in out-of-heap check).
12139 // Only works because non-oop pointers must be raw pointers
12140 // and raw pointers have no anti-dependencies.
12141 instruct compP_mem_rReg(rFlagsRegU cr, rRegP op1, memory op2)
12142 %{
12143   predicate(n->in(2)->in(2)->bottom_type()->reloc() == relocInfo::none &&
12144             n->in(2)->as_Load()->barrier_data() == 0);
12145   match(Set cr (CmpP op1 (LoadP op2)));
12146 
12147   format %{ "cmpq    $op1, $op2\t# raw ptr" %}
12148   ins_encode %{
12149     __ cmpq($op1$$Register, $op2$$Address);
12150   %}
12151   ins_pipe(ialu_cr_reg_mem);
12152 %}
12153 
12154 // This will generate a signed flags result. This should be OK since
12155 // any compare to a zero should be eq/neq.
12156 instruct testP_reg(rFlagsReg cr, rRegP src, immP0 zero)
12157 %{
12158   match(Set cr (CmpP src zero));
12159 
12160   format %{ "testq   $src, $src\t# ptr" %}
12161   ins_encode %{
12162     __ testq($src$$Register, $src$$Register);
12163   %}
12164   ins_pipe(ialu_cr_reg_imm);
12165 %}
12166 
12167 // This will generate a signed flags result. This should be OK since
12168 // any compare to a zero should be eq/neq.
12169 instruct testP_mem(rFlagsReg cr, memory op, immP0 zero)
12170 %{
12171   predicate((!UseCompressedOops || (CompressedOops::base() != NULL)) &&
12172             n->in(1)->as_Load()->barrier_data() == 0);
12173   match(Set cr (CmpP (LoadP op) zero));
12174 
12175   ins_cost(500); // XXX
12176   format %{ "testq   $op, 0xffffffffffffffff\t# ptr" %}
12177   ins_encode %{
12178     __ testq($op$$Address, 0xFFFFFFFF);
12179   %}
12180   ins_pipe(ialu_cr_reg_imm);
12181 %}
12182 
12183 instruct testP_mem_reg0(rFlagsReg cr, memory mem, immP0 zero)
12184 %{
12185   predicate(UseCompressedOops && (CompressedOops::base() == NULL) &&
12186             n->in(1)->as_Load()->barrier_data() == 0);
12187   match(Set cr (CmpP (LoadP mem) zero));
12188 
12189   format %{ "cmpq    R12, $mem\t# ptr (R12_heapbase==0)" %}
12190   ins_encode %{
12191     __ cmpq(r12, $mem$$Address);
12192   %}
12193   ins_pipe(ialu_cr_reg_mem);
12194 %}
12195 
12196 instruct compN_rReg(rFlagsRegU cr, rRegN op1, rRegN op2)
12197 %{
12198   match(Set cr (CmpN op1 op2));
12199 
12200   format %{ "cmpl    $op1, $op2\t# compressed ptr" %}
12201   ins_encode %{ __ cmpl($op1$$Register, $op2$$Register); %}
12202   ins_pipe(ialu_cr_reg_reg);
12203 %}
12204 
12205 instruct compN_rReg_mem(rFlagsRegU cr, rRegN src, memory mem)
12206 %{
12207   match(Set cr (CmpN src (LoadN mem)));
12208 
12209   format %{ "cmpl    $src, $mem\t# compressed ptr" %}
12210   ins_encode %{
12211     __ cmpl($src$$Register, $mem$$Address);
12212   %}
12213   ins_pipe(ialu_cr_reg_mem);
12214 %}
12215 
12216 instruct compN_rReg_imm(rFlagsRegU cr, rRegN op1, immN op2) %{
12217   match(Set cr (CmpN op1 op2));
12218 
12219   format %{ "cmpl    $op1, $op2\t# compressed ptr" %}
12220   ins_encode %{
12221     __ cmp_narrow_oop($op1$$Register, (jobject)$op2$$constant);
12222   %}
12223   ins_pipe(ialu_cr_reg_imm);
12224 %}
12225 
12226 instruct compN_mem_imm(rFlagsRegU cr, memory mem, immN src)
12227 %{
12228   match(Set cr (CmpN src (LoadN mem)));
12229 
12230   format %{ "cmpl    $mem, $src\t# compressed ptr" %}
12231   ins_encode %{
12232     __ cmp_narrow_oop($mem$$Address, (jobject)$src$$constant);
12233   %}
12234   ins_pipe(ialu_cr_reg_mem);
12235 %}
12236 
12237 instruct compN_rReg_imm_klass(rFlagsRegU cr, rRegN op1, immNKlass op2) %{
12238   match(Set cr (CmpN op1 op2));
12239 
12240   format %{ "cmpl    $op1, $op2\t# compressed klass ptr" %}
12241   ins_encode %{
12242     __ cmp_narrow_klass($op1$$Register, (Klass*)$op2$$constant);
12243   %}
12244   ins_pipe(ialu_cr_reg_imm);
12245 %}
12246 
12247 instruct compN_mem_imm_klass(rFlagsRegU cr, memory mem, immNKlass src)
12248 %{
12249   match(Set cr (CmpN src (LoadNKlass mem)));
12250 
12251   format %{ "cmpl    $mem, $src\t# compressed klass ptr" %}
12252   ins_encode %{
12253     __ cmp_narrow_klass($mem$$Address, (Klass*)$src$$constant);
12254   %}
12255   ins_pipe(ialu_cr_reg_mem);
12256 %}
12257 
12258 instruct testN_reg(rFlagsReg cr, rRegN src, immN0 zero) %{
12259   match(Set cr (CmpN src zero));
12260 
12261   format %{ "testl   $src, $src\t# compressed ptr" %}
12262   ins_encode %{ __ testl($src$$Register, $src$$Register); %}
12263   ins_pipe(ialu_cr_reg_imm);
12264 %}
12265 
12266 instruct testN_mem(rFlagsReg cr, memory mem, immN0 zero)
12267 %{
12268   predicate(CompressedOops::base() != NULL);
12269   match(Set cr (CmpN (LoadN mem) zero));
12270 
12271   ins_cost(500); // XXX
12272   format %{ "testl   $mem, 0xffffffff\t# compressed ptr" %}
12273   ins_encode %{
12274     __ cmpl($mem$$Address, (int)0xFFFFFFFF);
12275   %}
12276   ins_pipe(ialu_cr_reg_mem);
12277 %}
12278 
12279 instruct testN_mem_reg0(rFlagsReg cr, memory mem, immN0 zero)
12280 %{
12281   predicate(CompressedOops::base() == NULL);
12282   match(Set cr (CmpN (LoadN mem) zero));
12283 
12284   format %{ "cmpl    R12, $mem\t# compressed ptr (R12_heapbase==0)" %}
12285   ins_encode %{
12286     __ cmpl(r12, $mem$$Address);
12287   %}
12288   ins_pipe(ialu_cr_reg_mem);
12289 %}
12290 
12291 // Yanked all unsigned pointer compare operations.
12292 // Pointer compares are done with CmpP which is already unsigned.
12293 
12294 instruct compL_rReg(rFlagsReg cr, rRegL op1, rRegL op2)
12295 %{
12296   match(Set cr (CmpL op1 op2));
12297 
12298   format %{ "cmpq    $op1, $op2" %}
12299   ins_encode %{
12300     __ cmpq($op1$$Register, $op2$$Register);
12301   %}
12302   ins_pipe(ialu_cr_reg_reg);
12303 %}
12304 
12305 instruct compL_rReg_imm(rFlagsReg cr, rRegL op1, immL32 op2)
12306 %{
12307   match(Set cr (CmpL op1 op2));
12308 
12309   format %{ "cmpq    $op1, $op2" %}
12310   ins_encode %{
12311     __ cmpq($op1$$Register, $op2$$constant);
12312   %}
12313   ins_pipe(ialu_cr_reg_imm);
12314 %}
12315 
12316 instruct compL_rReg_mem(rFlagsReg cr, rRegL op1, memory op2)
12317 %{
12318   match(Set cr (CmpL op1 (LoadL op2)));
12319 
12320   format %{ "cmpq    $op1, $op2" %}
12321   ins_encode %{
12322     __ cmpq($op1$$Register, $op2$$Address);
12323   %}
12324   ins_pipe(ialu_cr_reg_mem);
12325 %}
12326 
12327 instruct testL_reg(rFlagsReg cr, rRegL src, immL0 zero)
12328 %{
12329   match(Set cr (CmpL src zero));
12330 
12331   format %{ "testq   $src, $src" %}
12332   ins_encode %{
12333     __ testq($src$$Register, $src$$Register);
12334   %}
12335   ins_pipe(ialu_cr_reg_imm);
12336 %}
12337 
12338 instruct testL_reg_imm(rFlagsReg cr, rRegL src, immL32 con, immL0 zero)
12339 %{
12340   match(Set cr (CmpL (AndL src con) zero));
12341 
12342   format %{ "testq   $src, $con\t# long" %}
12343   ins_encode %{
12344     __ testq($src$$Register, $con$$constant);
12345   %}
12346   ins_pipe(ialu_cr_reg_imm);
12347 %}
12348 
12349 instruct testL_reg_mem(rFlagsReg cr, rRegL src, memory mem, immL0 zero)
12350 %{
12351   match(Set cr (CmpL (AndL src (LoadL mem)) zero));
12352 
12353   format %{ "testq   $src, $mem" %}
12354   ins_encode %{
12355     __ testq($src$$Register, $mem$$Address);
12356   %}
12357   ins_pipe(ialu_cr_reg_mem);
12358 %}
12359 
12360 instruct testL_reg_mem2(rFlagsReg cr, rRegP src, memory mem, immL0 zero)
12361 %{
12362   match(Set cr (CmpL (AndL (CastP2X src) (LoadL mem)) zero));
12363 
12364   format %{ "testq   $src, $mem" %}
12365   ins_encode %{
12366     __ testq($src$$Register, $mem$$Address);
12367   %}
12368   ins_pipe(ialu_cr_reg_mem);
12369 %}
12370 
12371 // Manifest a CmpL result in an integer register.  Very painful.
12372 // This is the test to avoid.
12373 instruct cmpL3_reg_reg(rRegI dst, rRegL src1, rRegL src2, rFlagsReg flags)
12374 %{
12375   match(Set dst (CmpL3 src1 src2));
12376   effect(KILL flags);
12377 
12378   ins_cost(275); // XXX
12379   format %{ "cmpq    $src1, $src2\t# CmpL3\n\t"
12380             "movl    $dst, -1\n\t"
12381             "jl,s    done\n\t"
12382             "setne   $dst\n\t"
12383             "movzbl  $dst, $dst\n\t"
12384     "done:" %}
12385   ins_encode %{
12386     Label done;
12387     __ cmpq($src1$$Register, $src2$$Register);
12388     __ movl($dst$$Register, -1);
12389     __ jccb(Assembler::less, done);
12390     __ setne($dst$$Register);
12391     __ movzbl($dst$$Register, $dst$$Register);
12392     __ bind(done);
12393   %}
12394   ins_pipe(pipe_slow);
12395 %}
12396 
12397 // Unsigned long compare Instructions; really, same as signed long except they
12398 // produce an rFlagsRegU instead of rFlagsReg.
12399 instruct compUL_rReg(rFlagsRegU cr, rRegL op1, rRegL op2)
12400 %{
12401   match(Set cr (CmpUL op1 op2));
12402 
12403   format %{ "cmpq    $op1, $op2\t# unsigned" %}
12404   ins_encode %{
12405     __ cmpq($op1$$Register, $op2$$Register);
12406   %}
12407   ins_pipe(ialu_cr_reg_reg);
12408 %}
12409 
12410 instruct compUL_rReg_imm(rFlagsRegU cr, rRegL op1, immL32 op2)
12411 %{
12412   match(Set cr (CmpUL op1 op2));
12413 
12414   format %{ "cmpq    $op1, $op2\t# unsigned" %}
12415   ins_encode %{
12416     __ cmpq($op1$$Register, $op2$$constant);
12417   %}
12418   ins_pipe(ialu_cr_reg_imm);
12419 %}
12420 
12421 instruct compUL_rReg_mem(rFlagsRegU cr, rRegL op1, memory op2)
12422 %{
12423   match(Set cr (CmpUL op1 (LoadL op2)));
12424 
12425   format %{ "cmpq    $op1, $op2\t# unsigned" %}
12426   ins_encode %{
12427     __ cmpq($op1$$Register, $op2$$Address);
12428   %}
12429   ins_pipe(ialu_cr_reg_mem);
12430 %}
12431 
12432 instruct testUL_reg(rFlagsRegU cr, rRegL src, immL0 zero)
12433 %{
12434   match(Set cr (CmpUL src zero));
12435 
12436   format %{ "testq   $src, $src\t# unsigned" %}
12437   ins_encode %{
12438     __ testq($src$$Register, $src$$Register);
12439   %}
12440   ins_pipe(ialu_cr_reg_imm);
12441 %}
12442 
12443 instruct compB_mem_imm(rFlagsReg cr, memory mem, immI8 imm)
12444 %{
12445   match(Set cr (CmpI (LoadB mem) imm));
12446 
12447   ins_cost(125);
12448   format %{ "cmpb    $mem, $imm" %}
12449   ins_encode %{ __ cmpb($mem$$Address, $imm$$constant); %}
12450   ins_pipe(ialu_cr_reg_mem);
12451 %}
12452 
12453 instruct testUB_mem_imm(rFlagsReg cr, memory mem, immU7 imm, immI_0 zero)
12454 %{
12455   match(Set cr (CmpI (AndI (LoadUB mem) imm) zero));
12456 
12457   ins_cost(125);
12458   format %{ "testb   $mem, $imm\t# ubyte" %}
12459   ins_encode %{ __ testb($mem$$Address, $imm$$constant); %}
12460   ins_pipe(ialu_cr_reg_mem);
12461 %}
12462 
12463 instruct testB_mem_imm(rFlagsReg cr, memory mem, immI8 imm, immI_0 zero)
12464 %{
12465   match(Set cr (CmpI (AndI (LoadB mem) imm) zero));
12466 
12467   ins_cost(125);
12468   format %{ "testb   $mem, $imm\t# byte" %}
12469   ins_encode %{ __ testb($mem$$Address, $imm$$constant); %}
12470   ins_pipe(ialu_cr_reg_mem);
12471 %}
12472 
12473 //----------Max and Min--------------------------------------------------------
12474 // Min Instructions
12475 
12476 instruct cmovI_reg_g(rRegI dst, rRegI src, rFlagsReg cr)
12477 %{
12478   effect(USE_DEF dst, USE src, USE cr);
12479 
12480   format %{ "cmovlgt $dst, $src\t# min" %}
12481   ins_encode %{
12482     __ cmovl(Assembler::greater, $dst$$Register, $src$$Register);
12483   %}
12484   ins_pipe(pipe_cmov_reg);
12485 %}
12486 
12487 
12488 instruct minI_rReg(rRegI dst, rRegI src)
12489 %{
12490   match(Set dst (MinI dst src));
12491 
12492   ins_cost(200);
12493   expand %{
12494     rFlagsReg cr;
12495     compI_rReg(cr, dst, src);
12496     cmovI_reg_g(dst, src, cr);
12497   %}
12498 %}
12499 
12500 instruct cmovI_reg_l(rRegI dst, rRegI src, rFlagsReg cr)
12501 %{
12502   effect(USE_DEF dst, USE src, USE cr);
12503 
12504   format %{ "cmovllt $dst, $src\t# max" %}
12505   ins_encode %{
12506     __ cmovl(Assembler::less, $dst$$Register, $src$$Register);
12507   %}
12508   ins_pipe(pipe_cmov_reg);
12509 %}
12510 
12511 
12512 instruct maxI_rReg(rRegI dst, rRegI src)
12513 %{
12514   match(Set dst (MaxI dst src));
12515 
12516   ins_cost(200);
12517   expand %{
12518     rFlagsReg cr;
12519     compI_rReg(cr, dst, src);
12520     cmovI_reg_l(dst, src, cr);
12521   %}
12522 %}
12523 
12524 // ============================================================================
12525 // Branch Instructions
12526 
12527 // Jump Direct - Label defines a relative address from JMP+1
12528 instruct jmpDir(label labl)
12529 %{
12530   match(Goto);
12531   effect(USE labl);
12532 
12533   ins_cost(300);
12534   format %{ "jmp     $labl" %}
12535   size(5);
12536   ins_encode %{
12537     Label* L = $labl$$label;
12538     __ jmp(*L, false); // Always long jump
12539   %}
12540   ins_pipe(pipe_jmp);
12541 %}
12542 
12543 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12544 instruct jmpCon(cmpOp cop, rFlagsReg cr, label labl)
12545 %{
12546   match(If cop cr);
12547   effect(USE labl);
12548 
12549   ins_cost(300);
12550   format %{ "j$cop     $labl" %}
12551   size(6);
12552   ins_encode %{
12553     Label* L = $labl$$label;
12554     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12555   %}
12556   ins_pipe(pipe_jcc);
12557 %}
12558 
12559 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12560 instruct jmpLoopEnd(cmpOp cop, rFlagsReg cr, label labl)
12561 %{
12562   predicate(!n->has_vector_mask_set());
12563   match(CountedLoopEnd cop cr);
12564   effect(USE labl);
12565 
12566   ins_cost(300);
12567   format %{ "j$cop     $labl\t# loop end" %}
12568   size(6);
12569   ins_encode %{
12570     Label* L = $labl$$label;
12571     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12572   %}
12573   ins_pipe(pipe_jcc);
12574 %}
12575 
12576 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12577 instruct jmpLoopEndU(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12578   predicate(!n->has_vector_mask_set());
12579   match(CountedLoopEnd cop cmp);
12580   effect(USE labl);
12581 
12582   ins_cost(300);
12583   format %{ "j$cop,u   $labl\t# loop end" %}
12584   size(6);
12585   ins_encode %{
12586     Label* L = $labl$$label;
12587     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12588   %}
12589   ins_pipe(pipe_jcc);
12590 %}
12591 
12592 instruct jmpLoopEndUCF(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12593   predicate(!n->has_vector_mask_set());
12594   match(CountedLoopEnd cop cmp);
12595   effect(USE labl);
12596 
12597   ins_cost(200);
12598   format %{ "j$cop,u   $labl\t# loop end" %}
12599   size(6);
12600   ins_encode %{
12601     Label* L = $labl$$label;
12602     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12603   %}
12604   ins_pipe(pipe_jcc);
12605 %}
12606 
12607 // mask version
12608 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12609 // Bounded mask operand used in following patten is needed for
12610 // post-loop multiversioning.
12611 instruct jmpLoopEnd_and_restoreMask(cmpOp cop, kReg_K1 ktmp, rFlagsReg cr, label labl)
12612 %{
12613   predicate(PostLoopMultiversioning && n->has_vector_mask_set());
12614   match(CountedLoopEnd cop cr);
12615   effect(USE labl, TEMP ktmp);
12616 
12617   ins_cost(400);
12618   format %{ "j$cop     $labl\t# loop end\n\t"
12619             "restorevectmask \t# vector mask restore for loops" %}
12620   size(10);
12621   ins_encode %{
12622     Label* L = $labl$$label;
12623     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12624     __ restorevectmask($ktmp$$KRegister);
12625   %}
12626   ins_pipe(pipe_jcc);
12627 %}
12628 
12629 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12630 // Bounded mask operand used in following patten is needed for
12631 // post-loop multiversioning.
12632 instruct jmpLoopEndU_and_restoreMask(cmpOpU cop, kReg_K1 ktmp, rFlagsRegU cmp, label labl) %{
12633   predicate(PostLoopMultiversioning && n->has_vector_mask_set());
12634   match(CountedLoopEnd cop cmp);
12635   effect(USE labl, TEMP ktmp);
12636 
12637   ins_cost(400);
12638   format %{ "j$cop,u   $labl\t# loop end\n\t"
12639             "restorevectmask \t# vector mask restore for loops" %}
12640   size(10);
12641   ins_encode %{
12642     Label* L = $labl$$label;
12643     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12644     __ restorevectmask($ktmp$$KRegister);
12645   %}
12646   ins_pipe(pipe_jcc);
12647 %}
12648 
12649 // Bounded mask operand used in following patten is needed for
12650 // post-loop multiversioning.
12651 instruct jmpLoopEndUCF_and_restoreMask(cmpOpUCF cop, kReg_K1 ktmp, rFlagsRegUCF cmp, label labl) %{
12652   predicate(PostLoopMultiversioning && n->has_vector_mask_set());
12653   match(CountedLoopEnd cop cmp);
12654   effect(USE labl, TEMP ktmp);
12655 
12656   ins_cost(300);
12657   format %{ "j$cop,u   $labl\t# loop end\n\t"
12658             "restorevectmask \t# vector mask restore for loops" %}
12659   size(10);
12660   ins_encode %{
12661     Label* L = $labl$$label;
12662     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12663     __ restorevectmask($ktmp$$KRegister);
12664   %}
12665   ins_pipe(pipe_jcc);
12666 %}
12667 
12668 // Jump Direct Conditional - using unsigned comparison
12669 instruct jmpConU(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12670   match(If cop cmp);
12671   effect(USE labl);
12672 
12673   ins_cost(300);
12674   format %{ "j$cop,u   $labl" %}
12675   size(6);
12676   ins_encode %{
12677     Label* L = $labl$$label;
12678     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12679   %}
12680   ins_pipe(pipe_jcc);
12681 %}
12682 
12683 instruct jmpConUCF(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12684   match(If cop cmp);
12685   effect(USE labl);
12686 
12687   ins_cost(200);
12688   format %{ "j$cop,u   $labl" %}
12689   size(6);
12690   ins_encode %{
12691     Label* L = $labl$$label;
12692     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12693   %}
12694   ins_pipe(pipe_jcc);
12695 %}
12696 
12697 instruct jmpConUCF2(cmpOpUCF2 cop, rFlagsRegUCF cmp, label labl) %{
12698   match(If cop cmp);
12699   effect(USE labl);
12700 
12701   ins_cost(200);
12702   format %{ $$template
12703     if ($cop$$cmpcode == Assembler::notEqual) {
12704       $$emit$$"jp,u    $labl\n\t"
12705       $$emit$$"j$cop,u   $labl"
12706     } else {
12707       $$emit$$"jp,u    done\n\t"
12708       $$emit$$"j$cop,u   $labl\n\t"
12709       $$emit$$"done:"
12710     }
12711   %}
12712   ins_encode %{
12713     Label* l = $labl$$label;
12714     if ($cop$$cmpcode == Assembler::notEqual) {
12715       __ jcc(Assembler::parity, *l, false);
12716       __ jcc(Assembler::notEqual, *l, false);
12717     } else if ($cop$$cmpcode == Assembler::equal) {
12718       Label done;
12719       __ jccb(Assembler::parity, done);
12720       __ jcc(Assembler::equal, *l, false);
12721       __ bind(done);
12722     } else {
12723        ShouldNotReachHere();
12724     }
12725   %}
12726   ins_pipe(pipe_jcc);
12727 %}
12728 
12729 // ============================================================================
12730 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary
12731 // superklass array for an instance of the superklass.  Set a hidden
12732 // internal cache on a hit (cache is checked with exposed code in
12733 // gen_subtype_check()).  Return NZ for a miss or zero for a hit.  The
12734 // encoding ALSO sets flags.
12735 
12736 instruct partialSubtypeCheck(rdi_RegP result,
12737                              rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
12738                              rFlagsReg cr)
12739 %{
12740   match(Set result (PartialSubtypeCheck sub super));
12741   effect(KILL rcx, KILL cr);
12742 
12743   ins_cost(1100);  // slightly larger than the next version
12744   format %{ "movq    rdi, [$sub + in_bytes(Klass::secondary_supers_offset())]\n\t"
12745             "movl    rcx, [rdi + Array<Klass*>::length_offset_in_bytes()]\t# length to scan\n\t"
12746             "addq    rdi, Array<Klass*>::base_offset_in_bytes()\t# Skip to start of data; set NZ in case count is zero\n\t"
12747             "repne   scasq\t# Scan *rdi++ for a match with rax while rcx--\n\t"
12748             "jne,s   miss\t\t# Missed: rdi not-zero\n\t"
12749             "movq    [$sub + in_bytes(Klass::secondary_super_cache_offset())], $super\t# Hit: update cache\n\t"
12750             "xorq    $result, $result\t\t Hit: rdi zero\n\t"
12751     "miss:\t" %}
12752 
12753   opcode(0x1); // Force a XOR of RDI
12754   ins_encode(enc_PartialSubtypeCheck());
12755   ins_pipe(pipe_slow);
12756 %}
12757 
12758 instruct partialSubtypeCheck_vs_Zero(rFlagsReg cr,
12759                                      rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
12760                                      immP0 zero,
12761                                      rdi_RegP result)
12762 %{
12763   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
12764   effect(KILL rcx, KILL result);
12765 
12766   ins_cost(1000);
12767   format %{ "movq    rdi, [$sub + in_bytes(Klass::secondary_supers_offset())]\n\t"
12768             "movl    rcx, [rdi + Array<Klass*>::length_offset_in_bytes()]\t# length to scan\n\t"
12769             "addq    rdi, Array<Klass*>::base_offset_in_bytes()\t# Skip to start of data; set NZ in case count is zero\n\t"
12770             "repne   scasq\t# Scan *rdi++ for a match with rax while cx-- != 0\n\t"
12771             "jne,s   miss\t\t# Missed: flags nz\n\t"
12772             "movq    [$sub + in_bytes(Klass::secondary_super_cache_offset())], $super\t# Hit: update cache\n\t"
12773     "miss:\t" %}
12774 
12775   opcode(0x0); // No need to XOR RDI
12776   ins_encode(enc_PartialSubtypeCheck());
12777   ins_pipe(pipe_slow);
12778 %}
12779 
12780 // ============================================================================
12781 // Branch Instructions -- short offset versions
12782 //
12783 // These instructions are used to replace jumps of a long offset (the default
12784 // match) with jumps of a shorter offset.  These instructions are all tagged
12785 // with the ins_short_branch attribute, which causes the ADLC to suppress the
12786 // match rules in general matching.  Instead, the ADLC generates a conversion
12787 // method in the MachNode which can be used to do in-place replacement of the
12788 // long variant with the shorter variant.  The compiler will determine if a
12789 // branch can be taken by the is_short_branch_offset() predicate in the machine
12790 // specific code section of the file.
12791 
12792 // Jump Direct - Label defines a relative address from JMP+1
12793 instruct jmpDir_short(label labl) %{
12794   match(Goto);
12795   effect(USE labl);
12796 
12797   ins_cost(300);
12798   format %{ "jmp,s   $labl" %}
12799   size(2);
12800   ins_encode %{
12801     Label* L = $labl$$label;
12802     __ jmpb(*L);
12803   %}
12804   ins_pipe(pipe_jmp);
12805   ins_short_branch(1);
12806 %}
12807 
12808 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12809 instruct jmpCon_short(cmpOp cop, rFlagsReg cr, label labl) %{
12810   match(If cop cr);
12811   effect(USE labl);
12812 
12813   ins_cost(300);
12814   format %{ "j$cop,s   $labl" %}
12815   size(2);
12816   ins_encode %{
12817     Label* L = $labl$$label;
12818     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12819   %}
12820   ins_pipe(pipe_jcc);
12821   ins_short_branch(1);
12822 %}
12823 
12824 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12825 instruct jmpLoopEnd_short(cmpOp cop, rFlagsReg cr, label labl) %{
12826   match(CountedLoopEnd cop cr);
12827   effect(USE labl);
12828 
12829   ins_cost(300);
12830   format %{ "j$cop,s   $labl\t# loop end" %}
12831   size(2);
12832   ins_encode %{
12833     Label* L = $labl$$label;
12834     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12835   %}
12836   ins_pipe(pipe_jcc);
12837   ins_short_branch(1);
12838 %}
12839 
12840 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12841 instruct jmpLoopEndU_short(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12842   match(CountedLoopEnd cop cmp);
12843   effect(USE labl);
12844 
12845   ins_cost(300);
12846   format %{ "j$cop,us  $labl\t# loop end" %}
12847   size(2);
12848   ins_encode %{
12849     Label* L = $labl$$label;
12850     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12851   %}
12852   ins_pipe(pipe_jcc);
12853   ins_short_branch(1);
12854 %}
12855 
12856 instruct jmpLoopEndUCF_short(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12857   match(CountedLoopEnd cop cmp);
12858   effect(USE labl);
12859 
12860   ins_cost(300);
12861   format %{ "j$cop,us  $labl\t# loop end" %}
12862   size(2);
12863   ins_encode %{
12864     Label* L = $labl$$label;
12865     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12866   %}
12867   ins_pipe(pipe_jcc);
12868   ins_short_branch(1);
12869 %}
12870 
12871 // Jump Direct Conditional - using unsigned comparison
12872 instruct jmpConU_short(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12873   match(If cop cmp);
12874   effect(USE labl);
12875 
12876   ins_cost(300);
12877   format %{ "j$cop,us  $labl" %}
12878   size(2);
12879   ins_encode %{
12880     Label* L = $labl$$label;
12881     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12882   %}
12883   ins_pipe(pipe_jcc);
12884   ins_short_branch(1);
12885 %}
12886 
12887 instruct jmpConUCF_short(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12888   match(If cop cmp);
12889   effect(USE labl);
12890 
12891   ins_cost(300);
12892   format %{ "j$cop,us  $labl" %}
12893   size(2);
12894   ins_encode %{
12895     Label* L = $labl$$label;
12896     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12897   %}
12898   ins_pipe(pipe_jcc);
12899   ins_short_branch(1);
12900 %}
12901 
12902 instruct jmpConUCF2_short(cmpOpUCF2 cop, rFlagsRegUCF cmp, label labl) %{
12903   match(If cop cmp);
12904   effect(USE labl);
12905 
12906   ins_cost(300);
12907   format %{ $$template
12908     if ($cop$$cmpcode == Assembler::notEqual) {
12909       $$emit$$"jp,u,s  $labl\n\t"
12910       $$emit$$"j$cop,u,s  $labl"
12911     } else {
12912       $$emit$$"jp,u,s  done\n\t"
12913       $$emit$$"j$cop,u,s  $labl\n\t"
12914       $$emit$$"done:"
12915     }
12916   %}
12917   size(4);
12918   ins_encode %{
12919     Label* l = $labl$$label;
12920     if ($cop$$cmpcode == Assembler::notEqual) {
12921       __ jccb(Assembler::parity, *l);
12922       __ jccb(Assembler::notEqual, *l);
12923     } else if ($cop$$cmpcode == Assembler::equal) {
12924       Label done;
12925       __ jccb(Assembler::parity, done);
12926       __ jccb(Assembler::equal, *l);
12927       __ bind(done);
12928     } else {
12929        ShouldNotReachHere();
12930     }
12931   %}
12932   ins_pipe(pipe_jcc);
12933   ins_short_branch(1);
12934 %}
12935 
12936 // ============================================================================
12937 // inlined locking and unlocking
12938 
12939 instruct cmpFastLockRTM(rFlagsReg cr, rRegP object, rbx_RegP box, rax_RegI tmp, rdx_RegI scr, rRegI cx1, rRegI cx2) %{
12940   predicate(Compile::current()->use_rtm());
12941   match(Set cr (FastLock object box));
12942   effect(TEMP tmp, TEMP scr, TEMP cx1, TEMP cx2, USE_KILL box);
12943   ins_cost(300);
12944   format %{ "fastlock $object,$box\t! kills $box,$tmp,$scr,$cx1,$cx2" %}
12945   ins_encode %{
12946     __ fast_lock($object$$Register, $box$$Register, $tmp$$Register,
12947                  $scr$$Register, $cx1$$Register, $cx2$$Register,
12948                  _rtm_counters, _stack_rtm_counters,
12949                  ((Method*)(ra_->C->method()->constant_encoding()))->method_data(),
12950                  true, ra_->C->profile_rtm());
12951   %}
12952   ins_pipe(pipe_slow);
12953 %}
12954 
12955 instruct cmpFastLock(rFlagsReg cr, rRegP object, rbx_RegP box, rax_RegI tmp, rRegP scr, rRegP cx1) %{
12956   predicate(!Compile::current()->use_rtm());
12957   match(Set cr (FastLock object box));
12958   effect(TEMP tmp, TEMP scr, TEMP cx1, USE_KILL box);
12959   ins_cost(300);
12960   format %{ "fastlock $object,$box\t! kills $box,$tmp,$scr" %}
12961   ins_encode %{
12962     __ fast_lock($object$$Register, $box$$Register, $tmp$$Register,
12963                  $scr$$Register, $cx1$$Register, noreg, NULL, NULL, NULL, false, false);
12964   %}
12965   ins_pipe(pipe_slow);
12966 %}
12967 
12968 instruct cmpFastUnlock(rFlagsReg cr, rRegP object, rax_RegP box, rRegP tmp) %{
12969   match(Set cr (FastUnlock object box));
12970   effect(TEMP tmp, USE_KILL box);
12971   ins_cost(300);
12972   format %{ "fastunlock $object,$box\t! kills $box,$tmp" %}
12973   ins_encode %{
12974     __ fast_unlock($object$$Register, $box$$Register, $tmp$$Register, ra_->C->use_rtm());
12975   %}
12976   ins_pipe(pipe_slow);
12977 %}
12978 
12979 
12980 // ============================================================================
12981 // Safepoint Instructions
12982 instruct safePoint_poll_tls(rFlagsReg cr, rRegP poll)
12983 %{
12984   match(SafePoint poll);
12985   effect(KILL cr, USE poll);
12986 
12987   format %{ "testl   rax, [$poll]\t"
12988             "# Safepoint: poll for GC" %}
12989   ins_cost(125);
12990   size(4); /* setting an explicit size will cause debug builds to assert if size is incorrect */
12991   ins_encode %{
12992     __ relocate(relocInfo::poll_type);
12993     address pre_pc = __ pc();
12994     __ testl(rax, Address($poll$$Register, 0));
12995     assert(nativeInstruction_at(pre_pc)->is_safepoint_poll(), "must emit test %%eax [reg]");
12996   %}
12997   ins_pipe(ialu_reg_mem);
12998 %}
12999 
13000 // ============================================================================
13001 // Procedure Call/Return Instructions
13002 // Call Java Static Instruction
13003 // Note: If this code changes, the corresponding ret_addr_offset() and
13004 //       compute_padding() functions will have to be adjusted.
13005 instruct CallStaticJavaDirect(method meth) %{
13006   match(CallStaticJava);
13007   effect(USE meth);
13008 
13009   ins_cost(300);
13010   format %{ "call,static " %}
13011   opcode(0xE8); /* E8 cd */
13012   ins_encode(clear_avx, Java_Static_Call(meth), call_epilog);
13013   ins_pipe(pipe_slow);
13014   ins_alignment(4);
13015 %}
13016 
13017 // Call Java Dynamic Instruction
13018 // Note: If this code changes, the corresponding ret_addr_offset() and
13019 //       compute_padding() functions will have to be adjusted.
13020 instruct CallDynamicJavaDirect(method meth)
13021 %{
13022   match(CallDynamicJava);
13023   effect(USE meth);
13024 
13025   ins_cost(300);
13026   format %{ "movq    rax, #Universe::non_oop_word()\n\t"
13027             "call,dynamic " %}
13028   ins_encode(clear_avx, Java_Dynamic_Call(meth), call_epilog);
13029   ins_pipe(pipe_slow);
13030   ins_alignment(4);
13031 %}
13032 
13033 // Call Runtime Instruction
13034 instruct CallRuntimeDirect(method meth)
13035 %{
13036   match(CallRuntime);
13037   effect(USE meth);
13038 
13039   ins_cost(300);
13040   format %{ "call,runtime " %}
13041   ins_encode(clear_avx, Java_To_Runtime(meth));
13042   ins_pipe(pipe_slow);
13043 %}
13044 
13045 // Call runtime without safepoint
13046 instruct CallLeafDirect(method meth)
13047 %{
13048   match(CallLeaf);
13049   effect(USE meth);
13050 
13051   ins_cost(300);
13052   format %{ "call_leaf,runtime " %}
13053   ins_encode(clear_avx, Java_To_Runtime(meth));
13054   ins_pipe(pipe_slow);
13055 %}
13056 
13057 // Call runtime without safepoint and with vector arguments
13058 instruct CallLeafDirectVector(method meth)
13059 %{
13060   match(CallLeafVector);
13061   effect(USE meth);
13062 
13063   ins_cost(300);
13064   format %{ "call_leaf,vector " %}
13065   ins_encode(Java_To_Runtime(meth));
13066   ins_pipe(pipe_slow);
13067 %}
13068 
13069 //
13070 instruct CallNativeDirect(method meth)
13071 %{
13072   match(CallNative);
13073   effect(USE meth);
13074 
13075   ins_cost(300);
13076   format %{ "call_native " %}
13077   ins_encode(clear_avx, Java_To_Runtime(meth));
13078   ins_pipe(pipe_slow);
13079 %}
13080 
13081 // Call runtime without safepoint
13082 instruct CallLeafNoFPDirect(method meth)
13083 %{
13084   match(CallLeafNoFP);
13085   effect(USE meth);
13086 
13087   ins_cost(300);
13088   format %{ "call_leaf_nofp,runtime " %}
13089   ins_encode(clear_avx, Java_To_Runtime(meth));
13090   ins_pipe(pipe_slow);
13091 %}
13092 
13093 // Return Instruction
13094 // Remove the return address & jump to it.
13095 // Notice: We always emit a nop after a ret to make sure there is room
13096 // for safepoint patching
13097 instruct Ret()
13098 %{
13099   match(Return);
13100 
13101   format %{ "ret" %}
13102   ins_encode %{
13103     __ ret(0);
13104   %}
13105   ins_pipe(pipe_jmp);
13106 %}
13107 
13108 // Tail Call; Jump from runtime stub to Java code.
13109 // Also known as an 'interprocedural jump'.
13110 // Target of jump will eventually return to caller.
13111 // TailJump below removes the return address.
13112 instruct TailCalljmpInd(no_rbp_RegP jump_target, rbx_RegP method_ptr)
13113 %{
13114   match(TailCall jump_target method_ptr);
13115 
13116   ins_cost(300);
13117   format %{ "jmp     $jump_target\t# rbx holds method" %}
13118   ins_encode %{
13119     __ jmp($jump_target$$Register);
13120   %}
13121   ins_pipe(pipe_jmp);
13122 %}
13123 
13124 // Tail Jump; remove the return address; jump to target.
13125 // TailCall above leaves the return address around.
13126 instruct tailjmpInd(no_rbp_RegP jump_target, rax_RegP ex_oop)
13127 %{
13128   match(TailJump jump_target ex_oop);
13129 
13130   ins_cost(300);
13131   format %{ "popq    rdx\t# pop return address\n\t"
13132             "jmp     $jump_target" %}
13133   ins_encode %{
13134     __ popq(as_Register(RDX_enc));
13135     __ jmp($jump_target$$Register);
13136   %}
13137   ins_pipe(pipe_jmp);
13138 %}
13139 
13140 // Create exception oop: created by stack-crawling runtime code.
13141 // Created exception is now available to this handler, and is setup
13142 // just prior to jumping to this handler.  No code emitted.
13143 instruct CreateException(rax_RegP ex_oop)
13144 %{
13145   match(Set ex_oop (CreateEx));
13146 
13147   size(0);
13148   // use the following format syntax
13149   format %{ "# exception oop is in rax; no code emitted" %}
13150   ins_encode();
13151   ins_pipe(empty);
13152 %}
13153 
13154 // Rethrow exception:
13155 // The exception oop will come in the first argument position.
13156 // Then JUMP (not call) to the rethrow stub code.
13157 instruct RethrowException()
13158 %{
13159   match(Rethrow);
13160 
13161   // use the following format syntax
13162   format %{ "jmp     rethrow_stub" %}
13163   ins_encode(enc_rethrow);
13164   ins_pipe(pipe_jmp);
13165 %}
13166 
13167 // ============================================================================
13168 // This name is KNOWN by the ADLC and cannot be changed.
13169 // The ADLC forces a 'TypeRawPtr::BOTTOM' output type
13170 // for this guy.
13171 instruct tlsLoadP(r15_RegP dst) %{
13172   match(Set dst (ThreadLocal));
13173   effect(DEF dst);
13174 
13175   size(0);
13176   format %{ "# TLS is in R15" %}
13177   ins_encode( /*empty encoding*/ );
13178   ins_pipe(ialu_reg_reg);
13179 %}
13180 
13181 
13182 //----------PEEPHOLE RULES-----------------------------------------------------
13183 // These must follow all instruction definitions as they use the names
13184 // defined in the instructions definitions.
13185 //
13186 // peepmatch ( root_instr_name [preceding_instruction]* );
13187 //
13188 // peepconstraint %{
13189 // (instruction_number.operand_name relational_op instruction_number.operand_name
13190 //  [, ...] );
13191 // // instruction numbers are zero-based using left to right order in peepmatch
13192 //
13193 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
13194 // // provide an instruction_number.operand_name for each operand that appears
13195 // // in the replacement instruction's match rule
13196 //
13197 // ---------VM FLAGS---------------------------------------------------------
13198 //
13199 // All peephole optimizations can be turned off using -XX:-OptoPeephole
13200 //
13201 // Each peephole rule is given an identifying number starting with zero and
13202 // increasing by one in the order seen by the parser.  An individual peephole
13203 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
13204 // on the command-line.
13205 //
13206 // ---------CURRENT LIMITATIONS----------------------------------------------
13207 //
13208 // Only match adjacent instructions in same basic block
13209 // Only equality constraints
13210 // Only constraints between operands, not (0.dest_reg == RAX_enc)
13211 // Only one replacement instruction
13212 //
13213 // ---------EXAMPLE----------------------------------------------------------
13214 //
13215 // // pertinent parts of existing instructions in architecture description
13216 // instruct movI(rRegI dst, rRegI src)
13217 // %{
13218 //   match(Set dst (CopyI src));
13219 // %}
13220 //
13221 // instruct incI_rReg(rRegI dst, immI_1 src, rFlagsReg cr)
13222 // %{
13223 //   match(Set dst (AddI dst src));
13224 //   effect(KILL cr);
13225 // %}
13226 //
13227 // // Change (inc mov) to lea
13228 // peephole %{
13229 //   // increment preceeded by register-register move
13230 //   peepmatch ( incI_rReg movI );
13231 //   // require that the destination register of the increment
13232 //   // match the destination register of the move
13233 //   peepconstraint ( 0.dst == 1.dst );
13234 //   // construct a replacement instruction that sets
13235 //   // the destination to ( move's source register + one )
13236 //   peepreplace ( leaI_rReg_immI( 0.dst 1.src 0.src ) );
13237 // %}
13238 //
13239 
13240 // Implementation no longer uses movX instructions since
13241 // machine-independent system no longer uses CopyX nodes.
13242 //
13243 // peephole
13244 // %{
13245 //   peepmatch (incI_rReg movI);
13246 //   peepconstraint (0.dst == 1.dst);
13247 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
13248 // %}
13249 
13250 // peephole
13251 // %{
13252 //   peepmatch (decI_rReg movI);
13253 //   peepconstraint (0.dst == 1.dst);
13254 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
13255 // %}
13256 
13257 // peephole
13258 // %{
13259 //   peepmatch (addI_rReg_imm movI);
13260 //   peepconstraint (0.dst == 1.dst);
13261 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
13262 // %}
13263 
13264 // peephole
13265 // %{
13266 //   peepmatch (incL_rReg movL);
13267 //   peepconstraint (0.dst == 1.dst);
13268 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
13269 // %}
13270 
13271 // peephole
13272 // %{
13273 //   peepmatch (decL_rReg movL);
13274 //   peepconstraint (0.dst == 1.dst);
13275 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
13276 // %}
13277 
13278 // peephole
13279 // %{
13280 //   peepmatch (addL_rReg_imm movL);
13281 //   peepconstraint (0.dst == 1.dst);
13282 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
13283 // %}
13284 
13285 // peephole
13286 // %{
13287 //   peepmatch (addP_rReg_imm movP);
13288 //   peepconstraint (0.dst == 1.dst);
13289 //   peepreplace (leaP_rReg_imm(0.dst 1.src 0.src));
13290 // %}
13291 
13292 // // Change load of spilled value to only a spill
13293 // instruct storeI(memory mem, rRegI src)
13294 // %{
13295 //   match(Set mem (StoreI mem src));
13296 // %}
13297 //
13298 // instruct loadI(rRegI dst, memory mem)
13299 // %{
13300 //   match(Set dst (LoadI mem));
13301 // %}
13302 //
13303 
13304 peephole
13305 %{
13306   peepmatch (loadI storeI);
13307   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
13308   peepreplace (storeI(1.mem 1.mem 1.src));
13309 %}
13310 
13311 peephole
13312 %{
13313   peepmatch (loadL storeL);
13314   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
13315   peepreplace (storeL(1.mem 1.mem 1.src));
13316 %}
13317 
13318 //----------SMARTSPILL RULES---------------------------------------------------
13319 // These must follow all instruction definitions as they use the names
13320 // defined in the instructions definitions.