1 //
   2 // Copyright (c) 1997, 2013, 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 // X86 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 // Previously set EBX, ESI, and EDI as save-on-entry for java code
  64 // Turn off SOE in java-code due to frequent use of uncommon-traps.
  65 // Now that allocator is better, turn on ESI and EDI as SOE registers.
  66 
  67 reg_def EBX(SOC, SOE, Op_RegI, 3, rbx->as_VMReg());
  68 reg_def ECX(SOC, SOC, Op_RegI, 1, rcx->as_VMReg());
  69 reg_def ESI(SOC, SOE, Op_RegI, 6, rsi->as_VMReg());
  70 reg_def EDI(SOC, SOE, Op_RegI, 7, rdi->as_VMReg());
  71 // now that adapter frames are gone EBP is always saved and restored by the prolog/epilog code
  72 reg_def EBP(NS, SOE, Op_RegI, 5, rbp->as_VMReg());
  73 reg_def EDX(SOC, SOC, Op_RegI, 2, rdx->as_VMReg());
  74 reg_def EAX(SOC, SOC, Op_RegI, 0, rax->as_VMReg());
  75 reg_def ESP( NS,  NS, Op_RegI, 4, rsp->as_VMReg());
  76 
  77 // Float registers.  We treat TOS/FPR0 special.  It is invisible to the
  78 // allocator, and only shows up in the encodings.
  79 reg_def FPR0L( SOC, SOC, Op_RegF, 0, VMRegImpl::Bad());
  80 reg_def FPR0H( SOC, SOC, Op_RegF, 0, VMRegImpl::Bad());
  81 // Ok so here's the trick FPR1 is really st(0) except in the midst
  82 // of emission of assembly for a machnode. During the emission the fpu stack
  83 // is pushed making FPR1 == st(1) temporarily. However at any safepoint
  84 // the stack will not have this element so FPR1 == st(0) from the
  85 // oopMap viewpoint. This same weirdness with numbering causes
  86 // instruction encoding to have to play games with the register
  87 // encode to correct for this 0/1 issue. See MachSpillCopyNode::implementation
  88 // where it does flt->flt moves to see an example
  89 //
  90 reg_def FPR1L( SOC, SOC, Op_RegF, 1, as_FloatRegister(0)->as_VMReg());
  91 reg_def FPR1H( SOC, SOC, Op_RegF, 1, as_FloatRegister(0)->as_VMReg()->next());
  92 reg_def FPR2L( SOC, SOC, Op_RegF, 2, as_FloatRegister(1)->as_VMReg());
  93 reg_def FPR2H( SOC, SOC, Op_RegF, 2, as_FloatRegister(1)->as_VMReg()->next());
  94 reg_def FPR3L( SOC, SOC, Op_RegF, 3, as_FloatRegister(2)->as_VMReg());
  95 reg_def FPR3H( SOC, SOC, Op_RegF, 3, as_FloatRegister(2)->as_VMReg()->next());
  96 reg_def FPR4L( SOC, SOC, Op_RegF, 4, as_FloatRegister(3)->as_VMReg());
  97 reg_def FPR4H( SOC, SOC, Op_RegF, 4, as_FloatRegister(3)->as_VMReg()->next());
  98 reg_def FPR5L( SOC, SOC, Op_RegF, 5, as_FloatRegister(4)->as_VMReg());
  99 reg_def FPR5H( SOC, SOC, Op_RegF, 5, as_FloatRegister(4)->as_VMReg()->next());
 100 reg_def FPR6L( SOC, SOC, Op_RegF, 6, as_FloatRegister(5)->as_VMReg());
 101 reg_def FPR6H( SOC, SOC, Op_RegF, 6, as_FloatRegister(5)->as_VMReg()->next());
 102 reg_def FPR7L( SOC, SOC, Op_RegF, 7, as_FloatRegister(6)->as_VMReg());
 103 reg_def FPR7H( SOC, SOC, Op_RegF, 7, as_FloatRegister(6)->as_VMReg()->next());
 104 
 105 // Specify priority of register selection within phases of register
 106 // allocation.  Highest priority is first.  A useful heuristic is to
 107 // give registers a low priority when they are required by machine
 108 // instructions, like EAX and EDX.  Registers which are used as
 109 // pairs must fall on an even boundary (witness the FPR#L's in this list).
 110 // For the Intel integer registers, the equivalent Long pairs are
 111 // EDX:EAX, EBX:ECX, and EDI:EBP.
 112 alloc_class chunk0( ECX,   EBX,   EBP,   EDI,   EAX,   EDX,   ESI, ESP,
 113                     FPR0L, FPR0H, FPR1L, FPR1H, FPR2L, FPR2H,
 114                     FPR3L, FPR3H, FPR4L, FPR4H, FPR5L, FPR5H,
 115                     FPR6L, FPR6H, FPR7L, FPR7H );
 116 
 117 
 118 //----------Architecture Description Register Classes--------------------------
 119 // Several register classes are automatically defined based upon information in
 120 // this architecture description.
 121 // 1) reg_class inline_cache_reg           ( /* as def'd in frame section */ )
 122 // 2) reg_class compiler_method_oop_reg    ( /* as def'd in frame section */ )
 123 // 2) reg_class interpreter_method_oop_reg ( /* as def'd in frame section */ )
 124 // 3) reg_class stack_slots( /* one chunk of stack-based "registers" */ )
 125 //
 126 // Class for all registers
 127 reg_class any_reg(EAX, EDX, EBP, EDI, ESI, ECX, EBX, ESP);
 128 // Class for general registers
 129 reg_class int_reg(EAX, EDX, EBP, EDI, ESI, ECX, EBX);
 130 // Class for general registers which may be used for implicit null checks on win95
 131 // Also safe for use by tailjump. We don't want to allocate in rbp,
 132 reg_class int_reg_no_rbp(EAX, EDX, EDI, ESI, ECX, EBX);
 133 // Class of "X" registers
 134 reg_class int_x_reg(EBX, ECX, EDX, EAX);
 135 // Class of registers that can appear in an address with no offset.
 136 // EBP and ESP require an extra instruction byte for zero offset.
 137 // Used in fast-unlock
 138 reg_class p_reg(EDX, EDI, ESI, EBX);
 139 // Class for general registers not including ECX
 140 reg_class ncx_reg(EAX, EDX, EBP, EDI, ESI, EBX);
 141 // Class for general registers not including EAX
 142 reg_class nax_reg(EDX, EDI, ESI, ECX, EBX);
 143 // Class for general registers not including EAX or EBX.
 144 reg_class nabx_reg(EDX, EDI, ESI, ECX, EBP);
 145 // Class of EAX (for multiply and divide operations)
 146 reg_class eax_reg(EAX);
 147 // Class of EBX (for atomic add)
 148 reg_class ebx_reg(EBX);
 149 // Class of ECX (for shift and JCXZ operations and cmpLTMask)
 150 reg_class ecx_reg(ECX);
 151 // Class of EDX (for multiply and divide operations)
 152 reg_class edx_reg(EDX);
 153 // Class of EDI (for synchronization)
 154 reg_class edi_reg(EDI);
 155 // Class of ESI (for synchronization)
 156 reg_class esi_reg(ESI);
 157 // Singleton class for interpreter's stack pointer
 158 reg_class ebp_reg(EBP);
 159 // Singleton class for stack pointer
 160 reg_class sp_reg(ESP);
 161 // Singleton class for instruction pointer
 162 // reg_class ip_reg(EIP);
 163 // Class of integer register pairs
 164 reg_class long_reg( EAX,EDX, ECX,EBX, EBP,EDI );
 165 // Class of integer register pairs that aligns with calling convention
 166 reg_class eadx_reg( EAX,EDX );
 167 reg_class ebcx_reg( ECX,EBX );
 168 // Not AX or DX, used in divides
 169 reg_class nadx_reg( EBX,ECX,ESI,EDI,EBP );
 170 
 171 // Floating point registers.  Notice FPR0 is not a choice.
 172 // FPR0 is not ever allocated; we use clever encodings to fake
 173 // a 2-address instructions out of Intels FP stack.
 174 reg_class fp_flt_reg( FPR1L,FPR2L,FPR3L,FPR4L,FPR5L,FPR6L,FPR7L );
 175 
 176 reg_class fp_dbl_reg( FPR1L,FPR1H, FPR2L,FPR2H, FPR3L,FPR3H,
 177                       FPR4L,FPR4H, FPR5L,FPR5H, FPR6L,FPR6H,
 178                       FPR7L,FPR7H );
 179 
 180 reg_class fp_flt_reg0( FPR1L );
 181 reg_class fp_dbl_reg0( FPR1L,FPR1H );
 182 reg_class fp_dbl_reg1( FPR2L,FPR2H );
 183 reg_class fp_dbl_notreg0( FPR2L,FPR2H, FPR3L,FPR3H, FPR4L,FPR4H,
 184                           FPR5L,FPR5H, FPR6L,FPR6H, FPR7L,FPR7H );
 185 
 186 %}
 187 
 188 
 189 //----------SOURCE BLOCK-------------------------------------------------------
 190 // This is a block of C++ code which provides values, functions, and
 191 // definitions necessary in the rest of the architecture description
 192 source_hpp %{
 193 // Must be visible to the DFA in dfa_x86_32.cpp
 194 extern bool is_operand_hi32_zero(Node* n);
 195 %}
 196 
 197 source %{
 198 #define   RELOC_IMM32    Assembler::imm_operand
 199 #define   RELOC_DISP32   Assembler::disp32_operand
 200 
 201 #define __ _masm.
 202 
 203 // How to find the high register of a Long pair, given the low register
 204 #define   HIGH_FROM_LOW(x) ((x)+2)
 205 
 206 // These masks are used to provide 128-bit aligned bitmasks to the XMM
 207 // instructions, to allow sign-masking or sign-bit flipping.  They allow
 208 // fast versions of NegF/NegD and AbsF/AbsD.
 209 
 210 // Note: 'double' and 'long long' have 32-bits alignment on x86.
 211 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) {
 212   // Use the expression (adr)&(~0xF) to provide 128-bits aligned address
 213   // of 128-bits operands for SSE instructions.
 214   jlong *operand = (jlong*)(((uintptr_t)adr)&((uintptr_t)(~0xF)));
 215   // Store the value to a 128-bits operand.
 216   operand[0] = lo;
 217   operand[1] = hi;
 218   return operand;
 219 }
 220 
 221 // Buffer for 128-bits masks used by SSE instructions.
 222 static jlong fp_signmask_pool[(4+1)*2]; // 4*128bits(data) + 128bits(alignment)
 223 
 224 // Static initialization during VM startup.
 225 static jlong *float_signmask_pool  = double_quadword(&fp_signmask_pool[1*2], CONST64(0x7FFFFFFF7FFFFFFF), CONST64(0x7FFFFFFF7FFFFFFF));
 226 static jlong *double_signmask_pool = double_quadword(&fp_signmask_pool[2*2], CONST64(0x7FFFFFFFFFFFFFFF), CONST64(0x7FFFFFFFFFFFFFFF));
 227 static jlong *float_signflip_pool  = double_quadword(&fp_signmask_pool[3*2], CONST64(0x8000000080000000), CONST64(0x8000000080000000));
 228 static jlong *double_signflip_pool = double_quadword(&fp_signmask_pool[4*2], CONST64(0x8000000000000000), CONST64(0x8000000000000000));
 229 
 230 // Offset hacking within calls.
 231 static int pre_call_resets_size() {
 232   int size = 0;
 233   Compile* C = Compile::current();
 234   if (C->in_24_bit_fp_mode()) {
 235     size += 6; // fldcw
 236   }
 237   if (C->max_vector_size() > 16) {
 238     size += 3; // vzeroupper
 239   }
 240   return size;
 241 }
 242 
 243 static int preserve_SP_size() {
 244   return 2;  // op, rm(reg/reg)
 245 }
 246 
 247 // !!!!! Special hack to get all type of calls to specify the byte offset
 248 //       from the start of the call to the point where the return address
 249 //       will point.
 250 int MachCallStaticJavaNode::ret_addr_offset() {
 251   int offset = 5 + pre_call_resets_size();  // 5 bytes from start of call to where return address points
 252   if (_method_handle_invoke)
 253     offset += preserve_SP_size();
 254   return offset;
 255 }
 256 
 257 int MachCallDynamicJavaNode::ret_addr_offset() {
 258   return 10 + pre_call_resets_size();  // 10 bytes from start of call to where return address points
 259 }
 260 
 261 static int sizeof_FFree_Float_Stack_All = -1;
 262 
 263 int MachCallRuntimeNode::ret_addr_offset() {
 264   assert(sizeof_FFree_Float_Stack_All != -1, "must have been emitted already");
 265   return sizeof_FFree_Float_Stack_All + 5 + pre_call_resets_size();
 266 }
 267 
 268 // Indicate if the safepoint node needs the polling page as an input.
 269 // Since x86 does have absolute addressing, it doesn't.
 270 bool SafePointNode::needs_polling_address_input() {
 271   return false;
 272 }
 273 
 274 //
 275 // Compute padding required for nodes which need alignment
 276 //
 277 
 278 // The address of the call instruction needs to be 4-byte aligned to
 279 // ensure that it does not span a cache line so that it can be patched.
 280 int CallStaticJavaDirectNode::compute_padding(int current_offset) const {
 281   current_offset += pre_call_resets_size();  // skip fldcw, if any
 282   current_offset += 1;      // skip call opcode byte
 283   return round_to(current_offset, alignment_required()) - current_offset;
 284 }
 285 
 286 // The address of the call instruction needs to be 4-byte aligned to
 287 // ensure that it does not span a cache line so that it can be patched.
 288 int CallStaticJavaHandleNode::compute_padding(int current_offset) const {
 289   current_offset += pre_call_resets_size();  // skip fldcw, if any
 290   current_offset += preserve_SP_size();   // skip mov rbp, rsp
 291   current_offset += 1;      // skip call opcode byte
 292   return round_to(current_offset, alignment_required()) - current_offset;
 293 }
 294 
 295 // The address of the call instruction needs to be 4-byte aligned to
 296 // ensure that it does not span a cache line so that it can be patched.
 297 int CallDynamicJavaDirectNode::compute_padding(int current_offset) const {
 298   current_offset += pre_call_resets_size();  // skip fldcw, if any
 299   current_offset += 5;      // skip MOV instruction
 300   current_offset += 1;      // skip call opcode byte
 301   return round_to(current_offset, alignment_required()) - current_offset;
 302 }
 303 
 304 // EMIT_RM()
 305 void emit_rm(CodeBuffer &cbuf, int f1, int f2, int f3) {
 306   unsigned char c = (unsigned char)((f1 << 6) | (f2 << 3) | f3);
 307   cbuf.insts()->emit_int8(c);
 308 }
 309 
 310 // EMIT_CC()
 311 void emit_cc(CodeBuffer &cbuf, int f1, int f2) {
 312   unsigned char c = (unsigned char)( f1 | f2 );
 313   cbuf.insts()->emit_int8(c);
 314 }
 315 
 316 // EMIT_OPCODE()
 317 void emit_opcode(CodeBuffer &cbuf, int code) {
 318   cbuf.insts()->emit_int8((unsigned char) code);
 319 }
 320 
 321 // EMIT_OPCODE() w/ relocation information
 322 void emit_opcode(CodeBuffer &cbuf, int code, relocInfo::relocType reloc, int offset = 0) {
 323   cbuf.relocate(cbuf.insts_mark() + offset, reloc);
 324   emit_opcode(cbuf, code);
 325 }
 326 
 327 // EMIT_D8()
 328 void emit_d8(CodeBuffer &cbuf, int d8) {
 329   cbuf.insts()->emit_int8((unsigned char) d8);
 330 }
 331 
 332 // EMIT_D16()
 333 void emit_d16(CodeBuffer &cbuf, int d16) {
 334   cbuf.insts()->emit_int16(d16);
 335 }
 336 
 337 // EMIT_D32()
 338 void emit_d32(CodeBuffer &cbuf, int d32) {
 339   cbuf.insts()->emit_int32(d32);
 340 }
 341 
 342 // emit 32 bit value and construct relocation entry from relocInfo::relocType
 343 void emit_d32_reloc(CodeBuffer &cbuf, int d32, relocInfo::relocType reloc,
 344         int format) {
 345   cbuf.relocate(cbuf.insts_mark(), reloc, format);
 346   cbuf.insts()->emit_int32(d32);
 347 }
 348 
 349 // emit 32 bit value and construct relocation entry from RelocationHolder
 350 void emit_d32_reloc(CodeBuffer &cbuf, int d32, RelocationHolder const& rspec,
 351         int format) {
 352 #ifdef ASSERT
 353   if (rspec.reloc()->type() == relocInfo::oop_type && d32 != 0 && d32 != (int)Universe::non_oop_word()) {
 354     assert(cast_to_oop(d32)->is_oop() && (ScavengeRootsInCode || !cast_to_oop(d32)->is_scavengable()), "cannot embed scavengable oops in code");
 355   }
 356 #endif
 357   cbuf.relocate(cbuf.insts_mark(), rspec, format);
 358   cbuf.insts()->emit_int32(d32);
 359 }
 360 
 361 // Access stack slot for load or store
 362 void store_to_stackslot(CodeBuffer &cbuf, int opcode, int rm_field, int disp) {
 363   emit_opcode( cbuf, opcode );               // (e.g., FILD   [ESP+src])
 364   if( -128 <= disp && disp <= 127 ) {
 365     emit_rm( cbuf, 0x01, rm_field, ESP_enc );  // R/M byte
 366     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);    // SIB byte
 367     emit_d8 (cbuf, disp);     // Displacement  // R/M byte
 368   } else {
 369     emit_rm( cbuf, 0x02, rm_field, ESP_enc );  // R/M byte
 370     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);    // SIB byte
 371     emit_d32(cbuf, disp);     // Displacement  // R/M byte
 372   }
 373 }
 374 
 375    // rRegI ereg, memory mem) %{    // emit_reg_mem
 376 void encode_RegMem( CodeBuffer &cbuf, int reg_encoding, int base, int index, int scale, int displace, relocInfo::relocType disp_reloc ) {
 377   // There is no index & no scale, use form without SIB byte
 378   if ((index == 0x4) &&
 379       (scale == 0) && (base != ESP_enc)) {
 380     // If no displacement, mode is 0x0; unless base is [EBP]
 381     if ( (displace == 0) && (base != EBP_enc) ) {
 382       emit_rm(cbuf, 0x0, reg_encoding, base);
 383     }
 384     else {                    // If 8-bit displacement, mode 0x1
 385       if ((displace >= -128) && (displace <= 127)
 386           && (disp_reloc == relocInfo::none) ) {
 387         emit_rm(cbuf, 0x1, reg_encoding, base);
 388         emit_d8(cbuf, displace);
 389       }
 390       else {                  // If 32-bit displacement
 391         if (base == -1) { // Special flag for absolute address
 392           emit_rm(cbuf, 0x0, reg_encoding, 0x5);
 393           // (manual lies; no SIB needed here)
 394           if ( disp_reloc != relocInfo::none ) {
 395             emit_d32_reloc(cbuf, displace, disp_reloc, 1);
 396           } else {
 397             emit_d32      (cbuf, displace);
 398           }
 399         }
 400         else {                // Normal base + offset
 401           emit_rm(cbuf, 0x2, reg_encoding, base);
 402           if ( disp_reloc != relocInfo::none ) {
 403             emit_d32_reloc(cbuf, displace, disp_reloc, 1);
 404           } else {
 405             emit_d32      (cbuf, displace);
 406           }
 407         }
 408       }
 409     }
 410   }
 411   else {                      // Else, encode with the SIB byte
 412     // If no displacement, mode is 0x0; unless base is [EBP]
 413     if (displace == 0 && (base != EBP_enc)) {  // If no displacement
 414       emit_rm(cbuf, 0x0, reg_encoding, 0x4);
 415       emit_rm(cbuf, scale, index, base);
 416     }
 417     else {                    // If 8-bit displacement, mode 0x1
 418       if ((displace >= -128) && (displace <= 127)
 419           && (disp_reloc == relocInfo::none) ) {
 420         emit_rm(cbuf, 0x1, reg_encoding, 0x4);
 421         emit_rm(cbuf, scale, index, base);
 422         emit_d8(cbuf, displace);
 423       }
 424       else {                  // If 32-bit displacement
 425         if (base == 0x04 ) {
 426           emit_rm(cbuf, 0x2, reg_encoding, 0x4);
 427           emit_rm(cbuf, scale, index, 0x04);
 428         } else {
 429           emit_rm(cbuf, 0x2, reg_encoding, 0x4);
 430           emit_rm(cbuf, scale, index, base);
 431         }
 432         if ( disp_reloc != relocInfo::none ) {
 433           emit_d32_reloc(cbuf, displace, disp_reloc, 1);
 434         } else {
 435           emit_d32      (cbuf, displace);
 436         }
 437       }
 438     }
 439   }
 440 }
 441 
 442 
 443 void encode_Copy( CodeBuffer &cbuf, int dst_encoding, int src_encoding ) {
 444   if( dst_encoding == src_encoding ) {
 445     // reg-reg copy, use an empty encoding
 446   } else {
 447     emit_opcode( cbuf, 0x8B );
 448     emit_rm(cbuf, 0x3, dst_encoding, src_encoding );
 449   }
 450 }
 451 
 452 void emit_cmpfp_fixup(MacroAssembler& _masm) {
 453   Label exit;
 454   __ jccb(Assembler::noParity, exit);
 455   __ pushf();
 456   //
 457   // comiss/ucomiss instructions set ZF,PF,CF flags and
 458   // zero OF,AF,SF for NaN values.
 459   // Fixup flags by zeroing ZF,PF so that compare of NaN
 460   // values returns 'less than' result (CF is set).
 461   // Leave the rest of flags unchanged.
 462   //
 463   //    7 6 5 4 3 2 1 0
 464   //   |S|Z|r|A|r|P|r|C|  (r - reserved bit)
 465   //    0 0 1 0 1 0 1 1   (0x2B)
 466   //
 467   __ andl(Address(rsp, 0), 0xffffff2b);
 468   __ popf();
 469   __ bind(exit);
 470 }
 471 
 472 void emit_cmpfp3(MacroAssembler& _masm, Register dst) {
 473   Label done;
 474   __ movl(dst, -1);
 475   __ jcc(Assembler::parity, done);
 476   __ jcc(Assembler::below, done);
 477   __ setb(Assembler::notEqual, dst);
 478   __ movzbl(dst, dst);
 479   __ bind(done);
 480 }
 481 
 482 
 483 //=============================================================================
 484 const RegMask& MachConstantBaseNode::_out_RegMask = RegMask::Empty;
 485 
 486 int Compile::ConstantTable::calculate_table_base_offset() const {
 487   return 0;  // absolute addressing, no offset
 488 }
 489 
 490 bool MachConstantBaseNode::requires_postalloc_expand() const { return false; }
 491 void MachConstantBaseNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {
 492   ShouldNotReachHere();
 493 }
 494 
 495 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
 496   // Empty encoding
 497 }
 498 
 499 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
 500   return 0;
 501 }
 502 
 503 #ifndef PRODUCT
 504 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 505   st->print("# MachConstantBaseNode (empty encoding)");
 506 }
 507 #endif
 508 
 509 
 510 //=============================================================================
 511 #ifndef PRODUCT
 512 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 513   Compile* C = ra_->C;
 514 
 515   int framesize = C->frame_slots() << LogBytesPerInt;
 516   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 517   // Remove wordSize for return addr which is already pushed.
 518   framesize -= wordSize;
 519 
 520   if (C->need_stack_bang(framesize)) {
 521     framesize -= wordSize;
 522     st->print("# stack bang");
 523     st->print("\n\t");
 524     st->print("PUSH   EBP\t# Save EBP");
 525     if (framesize) {
 526       st->print("\n\t");
 527       st->print("SUB    ESP, #%d\t# Create frame",framesize);
 528     }
 529   } else {
 530     st->print("SUB    ESP, #%d\t# Create frame",framesize);
 531     st->print("\n\t");
 532     framesize -= wordSize;
 533     st->print("MOV    [ESP + #%d], EBP\t# Save EBP",framesize);
 534   }
 535 
 536   if (VerifyStackAtCalls) {
 537     st->print("\n\t");
 538     framesize -= wordSize;
 539     st->print("MOV    [ESP + #%d], 0xBADB100D\t# Majik cookie for stack depth check",framesize);
 540   }
 541 
 542   if( C->in_24_bit_fp_mode() ) {
 543     st->print("\n\t");
 544     st->print("FLDCW  \t# load 24 bit fpu control word");
 545   }
 546   if (UseSSE >= 2 && VerifyFPU) {
 547     st->print("\n\t");
 548     st->print("# verify FPU stack (must be clean on entry)");
 549   }
 550 
 551 #ifdef ASSERT
 552   if (VerifyStackAtCalls) {
 553     st->print("\n\t");
 554     st->print("# stack alignment check");
 555   }
 556 #endif
 557   st->cr();
 558 }
 559 #endif
 560 
 561 
 562 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 563   Compile* C = ra_->C;
 564   MacroAssembler _masm(&cbuf);
 565 
 566   int framesize = C->frame_slots() << LogBytesPerInt;
 567 
 568   __ verified_entry(framesize, C->need_stack_bang(framesize), C->in_24_bit_fp_mode());
 569 
 570   C->set_frame_complete(cbuf.insts_size());
 571 
 572   if (C->has_mach_constant_base_node()) {
 573     // NOTE: We set the table base offset here because users might be
 574     // emitted before MachConstantBaseNode.
 575     Compile::ConstantTable& constant_table = C->constant_table();
 576     constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
 577   }
 578 }
 579 
 580 uint MachPrologNode::size(PhaseRegAlloc *ra_) const {
 581   return MachNode::size(ra_); // too many variables; just compute it the hard way
 582 }
 583 
 584 int MachPrologNode::reloc() const {
 585   return 0; // a large enough number
 586 }
 587 
 588 //=============================================================================
 589 #ifndef PRODUCT
 590 void MachEpilogNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
 591   Compile *C = ra_->C;
 592   int framesize = C->frame_slots() << LogBytesPerInt;
 593   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 594   // Remove two words for return addr and rbp,
 595   framesize -= 2*wordSize;
 596 
 597   if (C->max_vector_size() > 16) {
 598     st->print("VZEROUPPER");
 599     st->cr(); st->print("\t");
 600   }
 601   if (C->in_24_bit_fp_mode()) {
 602     st->print("FLDCW  standard control word");
 603     st->cr(); st->print("\t");
 604   }
 605   if (framesize) {
 606     st->print("ADD    ESP,%d\t# Destroy frame",framesize);
 607     st->cr(); st->print("\t");
 608   }
 609   st->print_cr("POPL   EBP"); st->print("\t");
 610   if (do_polling() && C->is_method_compilation()) {
 611     st->print("TEST   PollPage,EAX\t! Poll Safepoint");
 612     st->cr(); st->print("\t");
 613   }
 614 }
 615 #endif
 616 
 617 void MachEpilogNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
 618   Compile *C = ra_->C;
 619 
 620   if (C->max_vector_size() > 16) {
 621     // Clear upper bits of YMM registers when current compiled code uses
 622     // wide vectors to avoid AVX <-> SSE transition penalty during call.
 623     MacroAssembler masm(&cbuf);
 624     masm.vzeroupper();
 625   }
 626   // If method set FPU control word, restore to standard control word
 627   if (C->in_24_bit_fp_mode()) {
 628     MacroAssembler masm(&cbuf);
 629     masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
 630   }
 631 
 632   int framesize = C->frame_slots() << LogBytesPerInt;
 633   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 634   // Remove two words for return addr and rbp,
 635   framesize -= 2*wordSize;
 636 
 637   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
 638 
 639   if (framesize >= 128) {
 640     emit_opcode(cbuf, 0x81); // add  SP, #framesize
 641     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
 642     emit_d32(cbuf, framesize);
 643   } else if (framesize) {
 644     emit_opcode(cbuf, 0x83); // add  SP, #framesize
 645     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
 646     emit_d8(cbuf, framesize);
 647   }
 648 
 649   emit_opcode(cbuf, 0x58 | EBP_enc);
 650 
 651   if (do_polling() && C->is_method_compilation()) {
 652     cbuf.relocate(cbuf.insts_end(), relocInfo::poll_return_type, 0);
 653     emit_opcode(cbuf,0x85);
 654     emit_rm(cbuf, 0x0, EAX_enc, 0x5); // EAX
 655     emit_d32(cbuf, (intptr_t)os::get_polling_page());
 656   }
 657 }
 658 
 659 uint MachEpilogNode::size(PhaseRegAlloc *ra_) const {
 660   Compile *C = ra_->C;
 661   // If method set FPU control word, restore to standard control word
 662   int size = C->in_24_bit_fp_mode() ? 6 : 0;
 663   if (C->max_vector_size() > 16) size += 3; // vzeroupper
 664   if (do_polling() && C->is_method_compilation()) size += 6;
 665 
 666   int framesize = C->frame_slots() << LogBytesPerInt;
 667   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 668   // Remove two words for return addr and rbp,
 669   framesize -= 2*wordSize;
 670 
 671   size++; // popl rbp,
 672 
 673   if (framesize >= 128) {
 674     size += 6;
 675   } else {
 676     size += framesize ? 3 : 0;
 677   }
 678   return size;
 679 }
 680 
 681 int MachEpilogNode::reloc() const {
 682   return 0; // a large enough number
 683 }
 684 
 685 const Pipeline * MachEpilogNode::pipeline() const {
 686   return MachNode::pipeline_class();
 687 }
 688 
 689 int MachEpilogNode::safepoint_offset() const { return 0; }
 690 
 691 //=============================================================================
 692 
 693 enum RC { rc_bad, rc_int, rc_float, rc_xmm, rc_stack };
 694 static enum RC rc_class( OptoReg::Name reg ) {
 695 
 696   if( !OptoReg::is_valid(reg)  ) return rc_bad;
 697   if (OptoReg::is_stack(reg)) return rc_stack;
 698 
 699   VMReg r = OptoReg::as_VMReg(reg);
 700   if (r->is_Register()) return rc_int;
 701   if (r->is_FloatRegister()) {
 702     assert(UseSSE < 2, "shouldn't be used in SSE2+ mode");
 703     return rc_float;
 704   }
 705   assert(r->is_XMMRegister(), "must be");
 706   return rc_xmm;
 707 }
 708 
 709 static int impl_helper( CodeBuffer *cbuf, bool do_size, bool is_load, int offset, int reg,
 710                         int opcode, const char *op_str, int size, outputStream* st ) {
 711   if( cbuf ) {
 712     emit_opcode  (*cbuf, opcode );
 713     encode_RegMem(*cbuf, Matcher::_regEncode[reg], ESP_enc, 0x4, 0, offset, relocInfo::none);
 714 #ifndef PRODUCT
 715   } else if( !do_size ) {
 716     if( size != 0 ) st->print("\n\t");
 717     if( opcode == 0x8B || opcode == 0x89 ) { // MOV
 718       if( is_load ) st->print("%s   %s,[ESP + #%d]",op_str,Matcher::regName[reg],offset);
 719       else          st->print("%s   [ESP + #%d],%s",op_str,offset,Matcher::regName[reg]);
 720     } else { // FLD, FST, PUSH, POP
 721       st->print("%s [ESP + #%d]",op_str,offset);
 722     }
 723 #endif
 724   }
 725   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
 726   return size+3+offset_size;
 727 }
 728 
 729 // Helper for XMM registers.  Extra opcode bits, limited syntax.
 730 static int impl_x_helper( CodeBuffer *cbuf, bool do_size, bool is_load,
 731                          int offset, int reg_lo, int reg_hi, int size, outputStream* st ) {
 732   if (cbuf) {
 733     MacroAssembler _masm(cbuf);
 734     if (reg_lo+1 == reg_hi) { // double move?
 735       if (is_load) {
 736         __ movdbl(as_XMMRegister(Matcher::_regEncode[reg_lo]), Address(rsp, offset));
 737       } else {
 738         __ movdbl(Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[reg_lo]));
 739       }
 740     } else {
 741       if (is_load) {
 742         __ movflt(as_XMMRegister(Matcher::_regEncode[reg_lo]), Address(rsp, offset));
 743       } else {
 744         __ movflt(Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[reg_lo]));
 745       }
 746     }
 747 #ifndef PRODUCT
 748   } else if (!do_size) {
 749     if (size != 0) st->print("\n\t");
 750     if (reg_lo+1 == reg_hi) { // double move?
 751       if (is_load) st->print("%s %s,[ESP + #%d]",
 752                               UseXmmLoadAndClearUpper ? "MOVSD " : "MOVLPD",
 753                               Matcher::regName[reg_lo], offset);
 754       else         st->print("MOVSD  [ESP + #%d],%s",
 755                               offset, Matcher::regName[reg_lo]);
 756     } else {
 757       if (is_load) st->print("MOVSS  %s,[ESP + #%d]",
 758                               Matcher::regName[reg_lo], offset);
 759       else         st->print("MOVSS  [ESP + #%d],%s",
 760                               offset, Matcher::regName[reg_lo]);
 761     }
 762 #endif
 763   }
 764   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
 765   // VEX_2bytes prefix is used if UseAVX > 0, so it takes the same 2 bytes as SIMD prefix.
 766   return size+5+offset_size;
 767 }
 768 
 769 
 770 static int impl_movx_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
 771                             int src_hi, int dst_hi, int size, outputStream* st ) {
 772   if (cbuf) {
 773     MacroAssembler _masm(cbuf);
 774     if (src_lo+1 == src_hi && dst_lo+1 == dst_hi) { // double move?
 775       __ movdbl(as_XMMRegister(Matcher::_regEncode[dst_lo]),
 776                 as_XMMRegister(Matcher::_regEncode[src_lo]));
 777     } else {
 778       __ movflt(as_XMMRegister(Matcher::_regEncode[dst_lo]),
 779                 as_XMMRegister(Matcher::_regEncode[src_lo]));
 780     }
 781 #ifndef PRODUCT
 782   } else if (!do_size) {
 783     if (size != 0) st->print("\n\t");
 784     if (UseXmmRegToRegMoveAll) {//Use movaps,movapd to move between xmm registers
 785       if (src_lo+1 == src_hi && dst_lo+1 == dst_hi) { // double move?
 786         st->print("MOVAPD %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
 787       } else {
 788         st->print("MOVAPS %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
 789       }
 790     } else {
 791       if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double move?
 792         st->print("MOVSD  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
 793       } else {
 794         st->print("MOVSS  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
 795       }
 796     }
 797 #endif
 798   }
 799   // VEX_2bytes prefix is used if UseAVX > 0, and it takes the same 2 bytes as SIMD prefix.
 800   // Only MOVAPS SSE prefix uses 1 byte.
 801   int sz = 4;
 802   if (!(src_lo+1 == src_hi && dst_lo+1 == dst_hi) &&
 803       UseXmmRegToRegMoveAll && (UseAVX == 0)) sz = 3;
 804   return size + sz;
 805 }
 806 
 807 static int impl_movgpr2x_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
 808                             int src_hi, int dst_hi, int size, outputStream* st ) {
 809   // 32-bit
 810   if (cbuf) {
 811     MacroAssembler _masm(cbuf);
 812     __ movdl(as_XMMRegister(Matcher::_regEncode[dst_lo]),
 813              as_Register(Matcher::_regEncode[src_lo]));
 814 #ifndef PRODUCT
 815   } else if (!do_size) {
 816     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
 817 #endif
 818   }
 819   return 4;
 820 }
 821 
 822 
 823 static int impl_movx2gpr_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
 824                                  int src_hi, int dst_hi, int size, outputStream* st ) {
 825   // 32-bit
 826   if (cbuf) {
 827     MacroAssembler _masm(cbuf);
 828     __ movdl(as_Register(Matcher::_regEncode[dst_lo]),
 829              as_XMMRegister(Matcher::_regEncode[src_lo]));
 830 #ifndef PRODUCT
 831   } else if (!do_size) {
 832     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
 833 #endif
 834   }
 835   return 4;
 836 }
 837 
 838 static int impl_mov_helper( CodeBuffer *cbuf, bool do_size, int src, int dst, int size, outputStream* st ) {
 839   if( cbuf ) {
 840     emit_opcode(*cbuf, 0x8B );
 841     emit_rm    (*cbuf, 0x3, Matcher::_regEncode[dst], Matcher::_regEncode[src] );
 842 #ifndef PRODUCT
 843   } else if( !do_size ) {
 844     if( size != 0 ) st->print("\n\t");
 845     st->print("MOV    %s,%s",Matcher::regName[dst],Matcher::regName[src]);
 846 #endif
 847   }
 848   return size+2;
 849 }
 850 
 851 static int impl_fp_store_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int src_hi, int dst_lo, int dst_hi,
 852                                  int offset, int size, outputStream* st ) {
 853   if( src_lo != FPR1L_num ) {      // Move value to top of FP stack, if not already there
 854     if( cbuf ) {
 855       emit_opcode( *cbuf, 0xD9 );  // FLD (i.e., push it)
 856       emit_d8( *cbuf, 0xC0-1+Matcher::_regEncode[src_lo] );
 857 #ifndef PRODUCT
 858     } else if( !do_size ) {
 859       if( size != 0 ) st->print("\n\t");
 860       st->print("FLD    %s",Matcher::regName[src_lo]);
 861 #endif
 862     }
 863     size += 2;
 864   }
 865 
 866   int st_op = (src_lo != FPR1L_num) ? EBX_num /*store & pop*/ : EDX_num /*store no pop*/;
 867   const char *op_str;
 868   int op;
 869   if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double store?
 870     op_str = (src_lo != FPR1L_num) ? "FSTP_D" : "FST_D ";
 871     op = 0xDD;
 872   } else {                   // 32-bit store
 873     op_str = (src_lo != FPR1L_num) ? "FSTP_S" : "FST_S ";
 874     op = 0xD9;
 875     assert( !OptoReg::is_valid(src_hi) && !OptoReg::is_valid(dst_hi), "no non-adjacent float-stores" );
 876   }
 877 
 878   return impl_helper(cbuf,do_size,false,offset,st_op,op,op_str,size, st);
 879 }
 880 
 881 // Next two methods are shared by 32- and 64-bit VM. They are defined in x86.ad.
 882 static int vec_mov_helper(CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
 883                           int src_hi, int dst_hi, uint ireg, outputStream* st);
 884 
 885 static int vec_spill_helper(CodeBuffer *cbuf, bool do_size, bool is_load,
 886                             int stack_offset, int reg, uint ireg, outputStream* st);
 887 
 888 static int vec_stack_to_stack_helper(CodeBuffer *cbuf, bool do_size, int src_offset,
 889                                      int dst_offset, uint ireg, outputStream* st) {
 890   int calc_size = 0;
 891   int src_offset_size = (src_offset == 0) ? 0 : ((src_offset < 0x80) ? 1 : 4);
 892   int dst_offset_size = (dst_offset == 0) ? 0 : ((dst_offset < 0x80) ? 1 : 4);
 893   switch (ireg) {
 894   case Op_VecS:
 895     calc_size = 3+src_offset_size + 3+dst_offset_size;
 896     break;
 897   case Op_VecD:
 898     calc_size = 3+src_offset_size + 3+dst_offset_size;
 899     src_offset += 4;
 900     dst_offset += 4;
 901     src_offset_size = (src_offset == 0) ? 0 : ((src_offset < 0x80) ? 1 : 4);
 902     dst_offset_size = (dst_offset == 0) ? 0 : ((dst_offset < 0x80) ? 1 : 4);
 903     calc_size += 3+src_offset_size + 3+dst_offset_size;
 904     break;
 905   case Op_VecX:
 906     calc_size = 6 + 6 + 5+src_offset_size + 5+dst_offset_size;
 907     break;
 908   case Op_VecY:
 909     calc_size = 6 + 6 + 5+src_offset_size + 5+dst_offset_size;
 910     break;
 911   default:
 912     ShouldNotReachHere();
 913   }
 914   if (cbuf) {
 915     MacroAssembler _masm(cbuf);
 916     int offset = __ offset();
 917     switch (ireg) {
 918     case Op_VecS:
 919       __ pushl(Address(rsp, src_offset));
 920       __ popl (Address(rsp, dst_offset));
 921       break;
 922     case Op_VecD:
 923       __ pushl(Address(rsp, src_offset));
 924       __ popl (Address(rsp, dst_offset));
 925       __ pushl(Address(rsp, src_offset+4));
 926       __ popl (Address(rsp, dst_offset+4));
 927       break;
 928     case Op_VecX:
 929       __ movdqu(Address(rsp, -16), xmm0);
 930       __ movdqu(xmm0, Address(rsp, src_offset));
 931       __ movdqu(Address(rsp, dst_offset), xmm0);
 932       __ movdqu(xmm0, Address(rsp, -16));
 933       break;
 934     case Op_VecY:
 935       __ vmovdqu(Address(rsp, -32), xmm0);
 936       __ vmovdqu(xmm0, Address(rsp, src_offset));
 937       __ vmovdqu(Address(rsp, dst_offset), xmm0);
 938       __ vmovdqu(xmm0, Address(rsp, -32));
 939       break;
 940     default:
 941       ShouldNotReachHere();
 942     }
 943     int size = __ offset() - offset;
 944     assert(size == calc_size, "incorrect size calculattion");
 945     return size;
 946 #ifndef PRODUCT
 947   } else if (!do_size) {
 948     switch (ireg) {
 949     case Op_VecS:
 950       st->print("pushl   [rsp + #%d]\t# 32-bit mem-mem spill\n\t"
 951                 "popl    [rsp + #%d]",
 952                 src_offset, dst_offset);
 953       break;
 954     case Op_VecD:
 955       st->print("pushl   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
 956                 "popq    [rsp + #%d]\n\t"
 957                 "pushl   [rsp + #%d]\n\t"
 958                 "popq    [rsp + #%d]",
 959                 src_offset, dst_offset, src_offset+4, dst_offset+4);
 960       break;
 961      case Op_VecX:
 962       st->print("movdqu  [rsp - #16], xmm0\t# 128-bit mem-mem spill\n\t"
 963                 "movdqu  xmm0, [rsp + #%d]\n\t"
 964                 "movdqu  [rsp + #%d], xmm0\n\t"
 965                 "movdqu  xmm0, [rsp - #16]",
 966                 src_offset, dst_offset);
 967       break;
 968     case Op_VecY:
 969       st->print("vmovdqu [rsp - #32], xmm0\t# 256-bit mem-mem spill\n\t"
 970                 "vmovdqu xmm0, [rsp + #%d]\n\t"
 971                 "vmovdqu [rsp + #%d], xmm0\n\t"
 972                 "vmovdqu xmm0, [rsp - #32]",
 973                 src_offset, dst_offset);
 974       break;
 975     default:
 976       ShouldNotReachHere();
 977     }
 978 #endif
 979   }
 980   return calc_size;
 981 }
 982 
 983 uint MachSpillCopyNode::implementation( CodeBuffer *cbuf, PhaseRegAlloc *ra_, bool do_size, outputStream* st ) const {
 984   // Get registers to move
 985   OptoReg::Name src_second = ra_->get_reg_second(in(1));
 986   OptoReg::Name src_first = ra_->get_reg_first(in(1));
 987   OptoReg::Name dst_second = ra_->get_reg_second(this );
 988   OptoReg::Name dst_first = ra_->get_reg_first(this );
 989 
 990   enum RC src_second_rc = rc_class(src_second);
 991   enum RC src_first_rc = rc_class(src_first);
 992   enum RC dst_second_rc = rc_class(dst_second);
 993   enum RC dst_first_rc = rc_class(dst_first);
 994 
 995   assert( OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first), "must move at least 1 register" );
 996 
 997   // Generate spill code!
 998   int size = 0;
 999 
1000   if( src_first == dst_first && src_second == dst_second )
1001     return size;            // Self copy, no move
1002 
1003   if (bottom_type()->isa_vect() != NULL) {
1004     uint ireg = ideal_reg();
1005     assert((src_first_rc != rc_int && dst_first_rc != rc_int), "sanity");
1006     assert((src_first_rc != rc_float && dst_first_rc != rc_float), "sanity");
1007     assert((ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY), "sanity");
1008     if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
1009       // mem -> mem
1010       int src_offset = ra_->reg2offset(src_first);
1011       int dst_offset = ra_->reg2offset(dst_first);
1012       return vec_stack_to_stack_helper(cbuf, do_size, src_offset, dst_offset, ireg, st);
1013     } else if (src_first_rc == rc_xmm && dst_first_rc == rc_xmm ) {
1014       return vec_mov_helper(cbuf, do_size, src_first, dst_first, src_second, dst_second, ireg, st);
1015     } else if (src_first_rc == rc_xmm && dst_first_rc == rc_stack ) {
1016       int stack_offset = ra_->reg2offset(dst_first);
1017       return vec_spill_helper(cbuf, do_size, false, stack_offset, src_first, ireg, st);
1018     } else if (src_first_rc == rc_stack && dst_first_rc == rc_xmm ) {
1019       int stack_offset = ra_->reg2offset(src_first);
1020       return vec_spill_helper(cbuf, do_size, true,  stack_offset, dst_first, ireg, st);
1021     } else {
1022       ShouldNotReachHere();
1023     }
1024   }
1025 
1026   // --------------------------------------
1027   // Check for mem-mem move.  push/pop to move.
1028   if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
1029     if( src_second == dst_first ) { // overlapping stack copy ranges
1030       assert( src_second_rc == rc_stack && dst_second_rc == rc_stack, "we only expect a stk-stk copy here" );
1031       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
1032       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
1033       src_second_rc = dst_second_rc = rc_bad;  // flag as already moved the second bits
1034     }
1035     // move low bits
1036     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),ESI_num,0xFF,"PUSH  ",size, st);
1037     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),EAX_num,0x8F,"POP   ",size, st);
1038     if( src_second_rc == rc_stack && dst_second_rc == rc_stack ) { // mov second bits
1039       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
1040       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
1041     }
1042     return size;
1043   }
1044 
1045   // --------------------------------------
1046   // Check for integer reg-reg copy
1047   if( src_first_rc == rc_int && dst_first_rc == rc_int )
1048     size = impl_mov_helper(cbuf,do_size,src_first,dst_first,size, st);
1049 
1050   // Check for integer store
1051   if( src_first_rc == rc_int && dst_first_rc == rc_stack )
1052     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first,0x89,"MOV ",size, st);
1053 
1054   // Check for integer load
1055   if( dst_first_rc == rc_int && src_first_rc == rc_stack )
1056     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first,0x8B,"MOV ",size, st);
1057 
1058   // Check for integer reg-xmm reg copy
1059   if( src_first_rc == rc_int && dst_first_rc == rc_xmm ) {
1060     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
1061             "no 64 bit integer-float reg moves" );
1062     return impl_movgpr2x_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
1063   }
1064   // --------------------------------------
1065   // Check for float reg-reg copy
1066   if( src_first_rc == rc_float && dst_first_rc == rc_float ) {
1067     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
1068             (src_first+1 == src_second && dst_first+1 == dst_second), "no non-adjacent float-moves" );
1069     if( cbuf ) {
1070 
1071       // Note the mucking with the register encode to compensate for the 0/1
1072       // indexing issue mentioned in a comment in the reg_def sections
1073       // for FPR registers many lines above here.
1074 
1075       if( src_first != FPR1L_num ) {
1076         emit_opcode  (*cbuf, 0xD9 );           // FLD    ST(i)
1077         emit_d8      (*cbuf, 0xC0+Matcher::_regEncode[src_first]-1 );
1078         emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
1079         emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
1080      } else {
1081         emit_opcode  (*cbuf, 0xDD );           // FST    ST(i)
1082         emit_d8      (*cbuf, 0xD0+Matcher::_regEncode[dst_first]-1 );
1083      }
1084 #ifndef PRODUCT
1085     } else if( !do_size ) {
1086       if( size != 0 ) st->print("\n\t");
1087       if( src_first != FPR1L_num ) st->print("FLD    %s\n\tFSTP   %s",Matcher::regName[src_first],Matcher::regName[dst_first]);
1088       else                      st->print(             "FST    %s",                            Matcher::regName[dst_first]);
1089 #endif
1090     }
1091     return size + ((src_first != FPR1L_num) ? 2+2 : 2);
1092   }
1093 
1094   // Check for float store
1095   if( src_first_rc == rc_float && dst_first_rc == rc_stack ) {
1096     return impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,ra_->reg2offset(dst_first),size, st);
1097   }
1098 
1099   // Check for float load
1100   if( dst_first_rc == rc_float && src_first_rc == rc_stack ) {
1101     int offset = ra_->reg2offset(src_first);
1102     const char *op_str;
1103     int op;
1104     if( src_first+1 == src_second && dst_first+1 == dst_second ) { // double load?
1105       op_str = "FLD_D";
1106       op = 0xDD;
1107     } else {                   // 32-bit load
1108       op_str = "FLD_S";
1109       op = 0xD9;
1110       assert( src_second_rc == rc_bad && dst_second_rc == rc_bad, "no non-adjacent float-loads" );
1111     }
1112     if( cbuf ) {
1113       emit_opcode  (*cbuf, op );
1114       encode_RegMem(*cbuf, 0x0, ESP_enc, 0x4, 0, offset, relocInfo::none);
1115       emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
1116       emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
1117 #ifndef PRODUCT
1118     } else if( !do_size ) {
1119       if( size != 0 ) st->print("\n\t");
1120       st->print("%s  ST,[ESP + #%d]\n\tFSTP   %s",op_str, offset,Matcher::regName[dst_first]);
1121 #endif
1122     }
1123     int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
1124     return size + 3+offset_size+2;
1125   }
1126 
1127   // Check for xmm reg-reg copy
1128   if( src_first_rc == rc_xmm && dst_first_rc == rc_xmm ) {
1129     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
1130             (src_first+1 == src_second && dst_first+1 == dst_second),
1131             "no non-adjacent float-moves" );
1132     return impl_movx_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
1133   }
1134 
1135   // Check for xmm reg-integer reg copy
1136   if( src_first_rc == rc_xmm && dst_first_rc == rc_int ) {
1137     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
1138             "no 64 bit float-integer reg moves" );
1139     return impl_movx2gpr_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
1140   }
1141 
1142   // Check for xmm store
1143   if( src_first_rc == rc_xmm && dst_first_rc == rc_stack ) {
1144     return impl_x_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first, src_second, size, st);
1145   }
1146 
1147   // Check for float xmm load
1148   if( dst_first_rc == rc_xmm && src_first_rc == rc_stack ) {
1149     return impl_x_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first, dst_second, size, st);
1150   }
1151 
1152   // Copy from float reg to xmm reg
1153   if( dst_first_rc == rc_xmm && src_first_rc == rc_float ) {
1154     // copy to the top of stack from floating point reg
1155     // and use LEA to preserve flags
1156     if( cbuf ) {
1157       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP-8]
1158       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
1159       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
1160       emit_d8(*cbuf,0xF8);
1161 #ifndef PRODUCT
1162     } else if( !do_size ) {
1163       if( size != 0 ) st->print("\n\t");
1164       st->print("LEA    ESP,[ESP-8]");
1165 #endif
1166     }
1167     size += 4;
1168 
1169     size = impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,0,size, st);
1170 
1171     // Copy from the temp memory to the xmm reg.
1172     size = impl_x_helper(cbuf,do_size,true ,0,dst_first, dst_second, size, st);
1173 
1174     if( cbuf ) {
1175       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP+8]
1176       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
1177       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
1178       emit_d8(*cbuf,0x08);
1179 #ifndef PRODUCT
1180     } else if( !do_size ) {
1181       if( size != 0 ) st->print("\n\t");
1182       st->print("LEA    ESP,[ESP+8]");
1183 #endif
1184     }
1185     size += 4;
1186     return size;
1187   }
1188 
1189   assert( size > 0, "missed a case" );
1190 
1191   // --------------------------------------------------------------------
1192   // Check for second bits still needing moving.
1193   if( src_second == dst_second )
1194     return size;               // Self copy; no move
1195   assert( src_second_rc != rc_bad && dst_second_rc != rc_bad, "src_second & dst_second cannot be Bad" );
1196 
1197   // Check for second word int-int move
1198   if( src_second_rc == rc_int && dst_second_rc == rc_int )
1199     return impl_mov_helper(cbuf,do_size,src_second,dst_second,size, st);
1200 
1201   // Check for second word integer store
1202   if( src_second_rc == rc_int && dst_second_rc == rc_stack )
1203     return impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),src_second,0x89,"MOV ",size, st);
1204 
1205   // Check for second word integer load
1206   if( dst_second_rc == rc_int && src_second_rc == rc_stack )
1207     return impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),dst_second,0x8B,"MOV ",size, st);
1208 
1209 
1210   Unimplemented();
1211 }
1212 
1213 #ifndef PRODUCT
1214 void MachSpillCopyNode::format(PhaseRegAlloc *ra_, outputStream* st) const {
1215   implementation( NULL, ra_, false, st );
1216 }
1217 #endif
1218 
1219 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
1220   implementation( &cbuf, ra_, false, NULL );
1221 }
1222 
1223 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const {
1224   return implementation( NULL, ra_, true, NULL );
1225 }
1226 
1227 
1228 //=============================================================================
1229 #ifndef PRODUCT
1230 void BoxLockNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
1231   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1232   int reg = ra_->get_reg_first(this);
1233   st->print("LEA    %s,[ESP + #%d]",Matcher::regName[reg],offset);
1234 }
1235 #endif
1236 
1237 void BoxLockNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
1238   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1239   int reg = ra_->get_encode(this);
1240   if( offset >= 128 ) {
1241     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
1242     emit_rm(cbuf, 0x2, reg, 0x04);
1243     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
1244     emit_d32(cbuf, offset);
1245   }
1246   else {
1247     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
1248     emit_rm(cbuf, 0x1, reg, 0x04);
1249     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
1250     emit_d8(cbuf, offset);
1251   }
1252 }
1253 
1254 uint BoxLockNode::size(PhaseRegAlloc *ra_) const {
1255   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1256   if( offset >= 128 ) {
1257     return 7;
1258   }
1259   else {
1260     return 4;
1261   }
1262 }
1263 
1264 //=============================================================================
1265 #ifndef PRODUCT
1266 void MachUEPNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
1267   st->print_cr(  "CMP    EAX,[ECX+4]\t# Inline cache check");
1268   st->print_cr("\tJNE    SharedRuntime::handle_ic_miss_stub");
1269   st->print_cr("\tNOP");
1270   st->print_cr("\tNOP");
1271   if( !OptoBreakpoint )
1272     st->print_cr("\tNOP");
1273 }
1274 #endif
1275 
1276 void MachUEPNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
1277   MacroAssembler masm(&cbuf);
1278 #ifdef ASSERT
1279   uint insts_size = cbuf.insts_size();
1280 #endif
1281   masm.cmpptr(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
1282   masm.jump_cc(Assembler::notEqual,
1283                RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1284   /* WARNING these NOPs are critical so that verified entry point is properly
1285      aligned for patching by NativeJump::patch_verified_entry() */
1286   int nops_cnt = 2;
1287   if( !OptoBreakpoint ) // Leave space for int3
1288      nops_cnt += 1;
1289   masm.nop(nops_cnt);
1290 
1291   assert(cbuf.insts_size() - insts_size == size(ra_), "checking code size of inline cache node");
1292 }
1293 
1294 uint MachUEPNode::size(PhaseRegAlloc *ra_) const {
1295   return OptoBreakpoint ? 11 : 12;
1296 }
1297 
1298 
1299 //=============================================================================
1300 uint size_exception_handler() {
1301   // NativeCall instruction size is the same as NativeJump.
1302   // exception handler starts out as jump and can be patched to
1303   // a call be deoptimization.  (4932387)
1304   // Note that this value is also credited (in output.cpp) to
1305   // the size of the code section.
1306   return NativeJump::instruction_size;
1307 }
1308 
1309 // Emit exception handler code.  Stuff framesize into a register
1310 // and call a VM stub routine.
1311 int emit_exception_handler(CodeBuffer& cbuf) {
1312 
1313   // Note that the code buffer's insts_mark is always relative to insts.
1314   // That's why we must use the macroassembler to generate a handler.
1315   MacroAssembler _masm(&cbuf);
1316   address base =
1317   __ start_a_stub(size_exception_handler());
1318   if (base == NULL)  return 0;  // CodeBuffer::expand failed
1319   int offset = __ offset();
1320   __ jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
1321   assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
1322   __ end_a_stub();
1323   return offset;
1324 }
1325 
1326 uint size_deopt_handler() {
1327   // NativeCall instruction size is the same as NativeJump.
1328   // exception handler starts out as jump and can be patched to
1329   // a call be deoptimization.  (4932387)
1330   // Note that this value is also credited (in output.cpp) to
1331   // the size of the code section.
1332   return 5 + NativeJump::instruction_size; // pushl(); jmp;
1333 }
1334 
1335 // Emit deopt handler code.
1336 int emit_deopt_handler(CodeBuffer& cbuf) {
1337 
1338   // Note that the code buffer's insts_mark is always relative to insts.
1339   // That's why we must use the macroassembler to generate a handler.
1340   MacroAssembler _masm(&cbuf);
1341   address base =
1342   __ start_a_stub(size_exception_handler());
1343   if (base == NULL)  return 0;  // CodeBuffer::expand failed
1344   int offset = __ offset();
1345   InternalAddress here(__ pc());
1346   __ pushptr(here.addr());
1347 
1348   __ jump(RuntimeAddress(SharedRuntime::deopt_blob()->unpack()));
1349   assert(__ offset() - offset <= (int) size_deopt_handler(), "overflow");
1350   __ end_a_stub();
1351   return offset;
1352 }
1353 
1354 int Matcher::regnum_to_fpu_offset(int regnum) {
1355   return regnum - 32; // The FP registers are in the second chunk
1356 }
1357 
1358 // This is UltraSparc specific, true just means we have fast l2f conversion
1359 const bool Matcher::convL2FSupported(void) {
1360   return true;
1361 }
1362 
1363 // Is this branch offset short enough that a short branch can be used?
1364 //
1365 // NOTE: If the platform does not provide any short branch variants, then
1366 //       this method should return false for offset 0.
1367 bool Matcher::is_short_branch_offset(int rule, int br_size, int offset) {
1368   // The passed offset is relative to address of the branch.
1369   // On 86 a branch displacement is calculated relative to address
1370   // of a next instruction.
1371   offset -= br_size;
1372 
1373   // the short version of jmpConUCF2 contains multiple branches,
1374   // making the reach slightly less
1375   if (rule == jmpConUCF2_rule)
1376     return (-126 <= offset && offset <= 125);
1377   return (-128 <= offset && offset <= 127);
1378 }
1379 
1380 const bool Matcher::isSimpleConstant64(jlong value) {
1381   // Will one (StoreL ConL) be cheaper than two (StoreI ConI)?.
1382   return false;
1383 }
1384 
1385 // The ecx parameter to rep stos for the ClearArray node is in dwords.
1386 const bool Matcher::init_array_count_is_in_bytes = false;
1387 
1388 // Threshold size for cleararray.
1389 const int Matcher::init_array_short_size = 8 * BytesPerLong;
1390 
1391 // Needs 2 CMOV's for longs.
1392 const int Matcher::long_cmove_cost() { return 1; }
1393 
1394 // No CMOVF/CMOVD with SSE/SSE2
1395 const int Matcher::float_cmove_cost() { return (UseSSE>=1) ? ConditionalMoveLimit : 0; }
1396 
1397 // Does the CPU require late expand (see block.cpp for description of late expand)?
1398 const bool Matcher::require_postalloc_expand = false;
1399 
1400 // Should the Matcher clone shifts on addressing modes, expecting them to
1401 // be subsumed into complex addressing expressions or compute them into
1402 // registers?  True for Intel but false for most RISCs
1403 const bool Matcher::clone_shift_expressions = true;
1404 
1405 // Do we need to mask the count passed to shift instructions or does
1406 // the cpu only look at the lower 5/6 bits anyway?
1407 const bool Matcher::need_masked_shift_count = false;
1408 
1409 bool Matcher::narrow_oop_use_complex_address() {
1410   ShouldNotCallThis();
1411   return true;
1412 }
1413 
1414 bool Matcher::narrow_klass_use_complex_address() {
1415   ShouldNotCallThis();
1416   return true;
1417 }
1418 
1419 
1420 // Is it better to copy float constants, or load them directly from memory?
1421 // Intel can load a float constant from a direct address, requiring no
1422 // extra registers.  Most RISCs will have to materialize an address into a
1423 // register first, so they would do better to copy the constant from stack.
1424 const bool Matcher::rematerialize_float_constants = true;
1425 
1426 // If CPU can load and store mis-aligned doubles directly then no fixup is
1427 // needed.  Else we split the double into 2 integer pieces and move it
1428 // piece-by-piece.  Only happens when passing doubles into C code as the
1429 // Java calling convention forces doubles to be aligned.
1430 const bool Matcher::misaligned_doubles_ok = true;
1431 
1432 
1433 void Matcher::pd_implicit_null_fixup(MachNode *node, uint idx) {
1434   // Get the memory operand from the node
1435   uint numopnds = node->num_opnds();        // Virtual call for number of operands
1436   uint skipped  = node->oper_input_base();  // Sum of leaves skipped so far
1437   assert( idx >= skipped, "idx too low in pd_implicit_null_fixup" );
1438   uint opcnt     = 1;                 // First operand
1439   uint num_edges = node->_opnds[1]->num_edges(); // leaves for first operand
1440   while( idx >= skipped+num_edges ) {
1441     skipped += num_edges;
1442     opcnt++;                          // Bump operand count
1443     assert( opcnt < numopnds, "Accessing non-existent operand" );
1444     num_edges = node->_opnds[opcnt]->num_edges(); // leaves for next operand
1445   }
1446 
1447   MachOper *memory = node->_opnds[opcnt];
1448   MachOper *new_memory = NULL;
1449   switch (memory->opcode()) {
1450   case DIRECT:
1451   case INDOFFSET32X:
1452     // No transformation necessary.
1453     return;
1454   case INDIRECT:
1455     new_memory = new (C) indirect_win95_safeOper( );
1456     break;
1457   case INDOFFSET8:
1458     new_memory = new (C) indOffset8_win95_safeOper(memory->disp(NULL, NULL, 0));
1459     break;
1460   case INDOFFSET32:
1461     new_memory = new (C) indOffset32_win95_safeOper(memory->disp(NULL, NULL, 0));
1462     break;
1463   case INDINDEXOFFSET:
1464     new_memory = new (C) indIndexOffset_win95_safeOper(memory->disp(NULL, NULL, 0));
1465     break;
1466   case INDINDEXSCALE:
1467     new_memory = new (C) indIndexScale_win95_safeOper(memory->scale());
1468     break;
1469   case INDINDEXSCALEOFFSET:
1470     new_memory = new (C) indIndexScaleOffset_win95_safeOper(memory->scale(), memory->disp(NULL, NULL, 0));
1471     break;
1472   case LOAD_LONG_INDIRECT:
1473   case LOAD_LONG_INDOFFSET32:
1474     // Does not use EBP as address register, use { EDX, EBX, EDI, ESI}
1475     return;
1476   default:
1477     assert(false, "unexpected memory operand in pd_implicit_null_fixup()");
1478     return;
1479   }
1480   node->_opnds[opcnt] = new_memory;
1481 }
1482 
1483 // Advertise here if the CPU requires explicit rounding operations
1484 // to implement the UseStrictFP mode.
1485 const bool Matcher::strict_fp_requires_explicit_rounding = true;
1486 
1487 // Are floats conerted to double when stored to stack during deoptimization?
1488 // On x32 it is stored with convertion only when FPU is used for floats.
1489 bool Matcher::float_in_double() { return (UseSSE == 0); }
1490 
1491 // Do ints take an entire long register or just half?
1492 const bool Matcher::int_in_long = false;
1493 
1494 // Return whether or not this register is ever used as an argument.  This
1495 // function is used on startup to build the trampoline stubs in generateOptoStub.
1496 // Registers not mentioned will be killed by the VM call in the trampoline, and
1497 // arguments in those registers not be available to the callee.
1498 bool Matcher::can_be_java_arg( int reg ) {
1499   if(  reg == ECX_num   || reg == EDX_num   ) return true;
1500   if( (reg == XMM0_num  || reg == XMM1_num ) && UseSSE>=1 ) return true;
1501   if( (reg == XMM0b_num || reg == XMM1b_num) && UseSSE>=2 ) return true;
1502   return false;
1503 }
1504 
1505 bool Matcher::is_spillable_arg( int reg ) {
1506   return can_be_java_arg(reg);
1507 }
1508 
1509 bool Matcher::use_asm_for_ldiv_by_con( jlong divisor ) {
1510   // Use hardware integer DIV instruction when
1511   // it is faster than a code which use multiply.
1512   // Only when constant divisor fits into 32 bit
1513   // (min_jint is excluded to get only correct
1514   // positive 32 bit values from negative).
1515   return VM_Version::has_fast_idiv() &&
1516          (divisor == (int)divisor && divisor != min_jint);
1517 }
1518 
1519 // Register for DIVI projection of divmodI
1520 RegMask Matcher::divI_proj_mask() {
1521   return EAX_REG_mask();
1522 }
1523 
1524 // Register for MODI projection of divmodI
1525 RegMask Matcher::modI_proj_mask() {
1526   return EDX_REG_mask();
1527 }
1528 
1529 // Register for DIVL projection of divmodL
1530 RegMask Matcher::divL_proj_mask() {
1531   ShouldNotReachHere();
1532   return RegMask();
1533 }
1534 
1535 // Register for MODL projection of divmodL
1536 RegMask Matcher::modL_proj_mask() {
1537   ShouldNotReachHere();
1538   return RegMask();
1539 }
1540 
1541 const RegMask Matcher::method_handle_invoke_SP_save_mask() {
1542   return EBP_REG_mask();
1543 }
1544 
1545 // Returns true if the high 32 bits of the value is known to be zero.
1546 bool is_operand_hi32_zero(Node* n) {
1547   int opc = n->Opcode();
1548   if (opc == Op_AndL) {
1549     Node* o2 = n->in(2);
1550     if (o2->is_Con() && (o2->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
1551       return true;
1552     }
1553   }
1554   if (opc == Op_ConL && (n->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
1555     return true;
1556   }
1557   return false;
1558 }
1559 
1560 %}
1561 
1562 //----------ENCODING BLOCK-----------------------------------------------------
1563 // This block specifies the encoding classes used by the compiler to output
1564 // byte streams.  Encoding classes generate functions which are called by
1565 // Machine Instruction Nodes in order to generate the bit encoding of the
1566 // instruction.  Operands specify their base encoding interface with the
1567 // interface keyword.  There are currently supported four interfaces,
1568 // REG_INTER, CONST_INTER, MEMORY_INTER, & COND_INTER.  REG_INTER causes an
1569 // operand to generate a function which returns its register number when
1570 // queried.   CONST_INTER causes an operand to generate a function which
1571 // returns the value of the constant when queried.  MEMORY_INTER causes an
1572 // operand to generate four functions which return the Base Register, the
1573 // Index Register, the Scale Value, and the Offset Value of the operand when
1574 // queried.  COND_INTER causes an operand to generate six functions which
1575 // return the encoding code (ie - encoding bits for the instruction)
1576 // associated with each basic boolean condition for a conditional instruction.
1577 // Instructions specify two basic values for encoding.  They use the
1578 // ins_encode keyword to specify their encoding class (which must be one of
1579 // the class names specified in the encoding block), and they use the
1580 // opcode keyword to specify, in order, their primary, secondary, and
1581 // tertiary opcode.  Only the opcode sections which a particular instruction
1582 // needs for encoding need to be specified.
1583 encode %{
1584   // Build emit functions for each basic byte or larger field in the intel
1585   // encoding scheme (opcode, rm, sib, immediate), and call them from C++
1586   // code in the enc_class source block.  Emit functions will live in the
1587   // main source block for now.  In future, we can generalize this by
1588   // adding a syntax that specifies the sizes of fields in an order,
1589   // so that the adlc can build the emit functions automagically
1590 
1591   // Emit primary opcode
1592   enc_class OpcP %{
1593     emit_opcode(cbuf, $primary);
1594   %}
1595 
1596   // Emit secondary opcode
1597   enc_class OpcS %{
1598     emit_opcode(cbuf, $secondary);
1599   %}
1600 
1601   // Emit opcode directly
1602   enc_class Opcode(immI d8) %{
1603     emit_opcode(cbuf, $d8$$constant);
1604   %}
1605 
1606   enc_class SizePrefix %{
1607     emit_opcode(cbuf,0x66);
1608   %}
1609 
1610   enc_class RegReg (rRegI dst, rRegI src) %{    // RegReg(Many)
1611     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
1612   %}
1613 
1614   enc_class OpcRegReg (immI opcode, rRegI dst, rRegI src) %{    // OpcRegReg(Many)
1615     emit_opcode(cbuf,$opcode$$constant);
1616     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
1617   %}
1618 
1619   enc_class mov_r32_imm0( rRegI dst ) %{
1620     emit_opcode( cbuf, 0xB8 + $dst$$reg ); // 0xB8+ rd   -- MOV r32  ,imm32
1621     emit_d32   ( cbuf, 0x0  );             //                         imm32==0x0
1622   %}
1623 
1624   enc_class cdq_enc %{
1625     // Full implementation of Java idiv and irem; checks for
1626     // special case as described in JVM spec., p.243 & p.271.
1627     //
1628     //         normal case                           special case
1629     //
1630     // input : rax,: dividend                         min_int
1631     //         reg: divisor                          -1
1632     //
1633     // output: rax,: quotient  (= rax, idiv reg)       min_int
1634     //         rdx: remainder (= rax, irem reg)       0
1635     //
1636     //  Code sequnce:
1637     //
1638     //  81 F8 00 00 00 80    cmp         rax,80000000h
1639     //  0F 85 0B 00 00 00    jne         normal_case
1640     //  33 D2                xor         rdx,edx
1641     //  83 F9 FF             cmp         rcx,0FFh
1642     //  0F 84 03 00 00 00    je          done
1643     //                  normal_case:
1644     //  99                   cdq
1645     //  F7 F9                idiv        rax,ecx
1646     //                  done:
1647     //
1648     emit_opcode(cbuf,0x81); emit_d8(cbuf,0xF8);
1649     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);
1650     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x80);                     // cmp rax,80000000h
1651     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x85);
1652     emit_opcode(cbuf,0x0B); emit_d8(cbuf,0x00);
1653     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // jne normal_case
1654     emit_opcode(cbuf,0x33); emit_d8(cbuf,0xD2);                     // xor rdx,edx
1655     emit_opcode(cbuf,0x83); emit_d8(cbuf,0xF9); emit_d8(cbuf,0xFF); // cmp rcx,0FFh
1656     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x84);
1657     emit_opcode(cbuf,0x03); emit_d8(cbuf,0x00);
1658     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // je done
1659     // normal_case:
1660     emit_opcode(cbuf,0x99);                                         // cdq
1661     // idiv (note: must be emitted by the user of this rule)
1662     // normal:
1663   %}
1664 
1665   // Dense encoding for older common ops
1666   enc_class Opc_plus(immI opcode, rRegI reg) %{
1667     emit_opcode(cbuf, $opcode$$constant + $reg$$reg);
1668   %}
1669 
1670 
1671   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
1672   enc_class OpcSE (immI imm) %{ // Emit primary opcode and set sign-extend bit
1673     // Check for 8-bit immediate, and set sign extend bit in opcode
1674     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
1675       emit_opcode(cbuf, $primary | 0x02);
1676     }
1677     else {                          // If 32-bit immediate
1678       emit_opcode(cbuf, $primary);
1679     }
1680   %}
1681 
1682   enc_class OpcSErm (rRegI dst, immI imm) %{    // OpcSEr/m
1683     // Emit primary opcode and set sign-extend bit
1684     // Check for 8-bit immediate, and set sign extend bit in opcode
1685     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
1686       emit_opcode(cbuf, $primary | 0x02);    }
1687     else {                          // If 32-bit immediate
1688       emit_opcode(cbuf, $primary);
1689     }
1690     // Emit r/m byte with secondary opcode, after primary opcode.
1691     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
1692   %}
1693 
1694   enc_class Con8or32 (immI imm) %{    // Con8or32(storeImmI), 8 or 32 bits
1695     // Check for 8-bit immediate, and set sign extend bit in opcode
1696     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
1697       $$$emit8$imm$$constant;
1698     }
1699     else {                          // If 32-bit immediate
1700       // Output immediate
1701       $$$emit32$imm$$constant;
1702     }
1703   %}
1704 
1705   enc_class Long_OpcSErm_Lo(eRegL dst, immL imm) %{
1706     // Emit primary opcode and set sign-extend bit
1707     // Check for 8-bit immediate, and set sign extend bit in opcode
1708     int con = (int)$imm$$constant; // Throw away top bits
1709     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
1710     // Emit r/m byte with secondary opcode, after primary opcode.
1711     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
1712     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
1713     else                               emit_d32(cbuf,con);
1714   %}
1715 
1716   enc_class Long_OpcSErm_Hi(eRegL dst, immL imm) %{
1717     // Emit primary opcode and set sign-extend bit
1718     // Check for 8-bit immediate, and set sign extend bit in opcode
1719     int con = (int)($imm$$constant >> 32); // Throw away bottom bits
1720     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
1721     // Emit r/m byte with tertiary opcode, after primary opcode.
1722     emit_rm(cbuf, 0x3, $tertiary, HIGH_FROM_LOW($dst$$reg));
1723     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
1724     else                               emit_d32(cbuf,con);
1725   %}
1726 
1727   enc_class OpcSReg (rRegI dst) %{    // BSWAP
1728     emit_cc(cbuf, $secondary, $dst$$reg );
1729   %}
1730 
1731   enc_class bswap_long_bytes(eRegL dst) %{ // BSWAP
1732     int destlo = $dst$$reg;
1733     int desthi = HIGH_FROM_LOW(destlo);
1734     // bswap lo
1735     emit_opcode(cbuf, 0x0F);
1736     emit_cc(cbuf, 0xC8, destlo);
1737     // bswap hi
1738     emit_opcode(cbuf, 0x0F);
1739     emit_cc(cbuf, 0xC8, desthi);
1740     // xchg lo and hi
1741     emit_opcode(cbuf, 0x87);
1742     emit_rm(cbuf, 0x3, destlo, desthi);
1743   %}
1744 
1745   enc_class RegOpc (rRegI div) %{    // IDIV, IMOD, JMP indirect, ...
1746     emit_rm(cbuf, 0x3, $secondary, $div$$reg );
1747   %}
1748 
1749   enc_class enc_cmov(cmpOp cop ) %{ // CMOV
1750     $$$emit8$primary;
1751     emit_cc(cbuf, $secondary, $cop$$cmpcode);
1752   %}
1753 
1754   enc_class enc_cmov_dpr(cmpOp cop, regDPR src ) %{ // CMOV
1755     int op = 0xDA00 + $cop$$cmpcode + ($src$$reg-1);
1756     emit_d8(cbuf, op >> 8 );
1757     emit_d8(cbuf, op & 255);
1758   %}
1759 
1760   // emulate a CMOV with a conditional branch around a MOV
1761   enc_class enc_cmov_branch( cmpOp cop, immI brOffs ) %{ // CMOV
1762     // Invert sense of branch from sense of CMOV
1763     emit_cc( cbuf, 0x70, ($cop$$cmpcode^1) );
1764     emit_d8( cbuf, $brOffs$$constant );
1765   %}
1766 
1767   enc_class enc_PartialSubtypeCheck( ) %{
1768     Register Redi = as_Register(EDI_enc); // result register
1769     Register Reax = as_Register(EAX_enc); // super class
1770     Register Recx = as_Register(ECX_enc); // killed
1771     Register Resi = as_Register(ESI_enc); // sub class
1772     Label miss;
1773 
1774     MacroAssembler _masm(&cbuf);
1775     __ check_klass_subtype_slow_path(Resi, Reax, Recx, Redi,
1776                                      NULL, &miss,
1777                                      /*set_cond_codes:*/ true);
1778     if ($primary) {
1779       __ xorptr(Redi, Redi);
1780     }
1781     __ bind(miss);
1782   %}
1783 
1784   enc_class FFree_Float_Stack_All %{    // Free_Float_Stack_All
1785     MacroAssembler masm(&cbuf);
1786     int start = masm.offset();
1787     if (UseSSE >= 2) {
1788       if (VerifyFPU) {
1789         masm.verify_FPU(0, "must be empty in SSE2+ mode");
1790       }
1791     } else {
1792       // External c_calling_convention expects the FPU stack to be 'clean'.
1793       // Compiled code leaves it dirty.  Do cleanup now.
1794       masm.empty_FPU_stack();
1795     }
1796     if (sizeof_FFree_Float_Stack_All == -1) {
1797       sizeof_FFree_Float_Stack_All = masm.offset() - start;
1798     } else {
1799       assert(masm.offset() - start == sizeof_FFree_Float_Stack_All, "wrong size");
1800     }
1801   %}
1802 
1803   enc_class Verify_FPU_For_Leaf %{
1804     if( VerifyFPU ) {
1805       MacroAssembler masm(&cbuf);
1806       masm.verify_FPU( -3, "Returning from Runtime Leaf call");
1807     }
1808   %}
1809 
1810   enc_class Java_To_Runtime (method meth) %{    // CALL Java_To_Runtime, Java_To_Runtime_Leaf
1811     // This is the instruction starting address for relocation info.
1812     cbuf.set_insts_mark();
1813     $$$emit8$primary;
1814     // CALL directly to the runtime
1815     emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
1816                 runtime_call_Relocation::spec(), RELOC_IMM32 );
1817 
1818     if (UseSSE >= 2) {
1819       MacroAssembler _masm(&cbuf);
1820       BasicType rt = tf()->return_type();
1821 
1822       if ((rt == T_FLOAT || rt == T_DOUBLE) && !return_value_is_used()) {
1823         // A C runtime call where the return value is unused.  In SSE2+
1824         // mode the result needs to be removed from the FPU stack.  It's
1825         // likely that this function call could be removed by the
1826         // optimizer if the C function is a pure function.
1827         __ ffree(0);
1828       } else if (rt == T_FLOAT) {
1829         __ lea(rsp, Address(rsp, -4));
1830         __ fstp_s(Address(rsp, 0));
1831         __ movflt(xmm0, Address(rsp, 0));
1832         __ lea(rsp, Address(rsp,  4));
1833       } else if (rt == T_DOUBLE) {
1834         __ lea(rsp, Address(rsp, -8));
1835         __ fstp_d(Address(rsp, 0));
1836         __ movdbl(xmm0, Address(rsp, 0));
1837         __ lea(rsp, Address(rsp,  8));
1838       }
1839     }
1840   %}
1841 
1842 
1843   enc_class pre_call_resets %{
1844     // If method sets FPU control word restore it here
1845     debug_only(int off0 = cbuf.insts_size());
1846     if (ra_->C->in_24_bit_fp_mode()) {
1847       MacroAssembler _masm(&cbuf);
1848       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
1849     }
1850     if (ra_->C->max_vector_size() > 16) {
1851       // Clear upper bits of YMM registers when current compiled code uses
1852       // wide vectors to avoid AVX <-> SSE transition penalty during call.
1853       MacroAssembler _masm(&cbuf);
1854       __ vzeroupper();
1855     }
1856     debug_only(int off1 = cbuf.insts_size());
1857     assert(off1 - off0 == pre_call_resets_size(), "correct size prediction");
1858   %}
1859 
1860   enc_class post_call_FPU %{
1861     // If method sets FPU control word do it here also
1862     if (Compile::current()->in_24_bit_fp_mode()) {
1863       MacroAssembler masm(&cbuf);
1864       masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
1865     }
1866   %}
1867 
1868   enc_class Java_Static_Call (method meth) %{    // JAVA STATIC CALL
1869     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
1870     // who we intended to call.
1871     cbuf.set_insts_mark();
1872     $$$emit8$primary;
1873     if (!_method) {
1874       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
1875                      runtime_call_Relocation::spec(), RELOC_IMM32 );
1876     } else if (_optimized_virtual) {
1877       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
1878                      opt_virtual_call_Relocation::spec(), RELOC_IMM32 );
1879     } else {
1880       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
1881                      static_call_Relocation::spec(), RELOC_IMM32 );
1882     }
1883     if (_method) {  // Emit stub for static call.
1884       CompiledStaticCall::emit_to_interp_stub(cbuf);
1885     }
1886   %}
1887 
1888   enc_class Java_Dynamic_Call (method meth) %{    // JAVA DYNAMIC CALL
1889     MacroAssembler _masm(&cbuf);
1890     __ ic_call((address)$meth$$method);
1891   %}
1892 
1893   enc_class Java_Compiled_Call (method meth) %{    // JAVA COMPILED CALL
1894     int disp = in_bytes(Method::from_compiled_offset());
1895     assert( -128 <= disp && disp <= 127, "compiled_code_offset isn't small");
1896 
1897     // CALL *[EAX+in_bytes(Method::from_compiled_code_entry_point_offset())]
1898     cbuf.set_insts_mark();
1899     $$$emit8$primary;
1900     emit_rm(cbuf, 0x01, $secondary, EAX_enc );  // R/M byte
1901     emit_d8(cbuf, disp);             // Displacement
1902 
1903   %}
1904 
1905 //   Following encoding is no longer used, but may be restored if calling
1906 //   convention changes significantly.
1907 //   Became: Xor_Reg(EBP), Java_To_Runtime( labl )
1908 //
1909 //   enc_class Java_Interpreter_Call (label labl) %{    // JAVA INTERPRETER CALL
1910 //     // int ic_reg     = Matcher::inline_cache_reg();
1911 //     // int ic_encode  = Matcher::_regEncode[ic_reg];
1912 //     // int imo_reg    = Matcher::interpreter_method_oop_reg();
1913 //     // int imo_encode = Matcher::_regEncode[imo_reg];
1914 //
1915 //     // // Interpreter expects method_oop in EBX, currently a callee-saved register,
1916 //     // // so we load it immediately before the call
1917 //     // emit_opcode(cbuf, 0x8B);                     // MOV    imo_reg,ic_reg  # method_oop
1918 //     // emit_rm(cbuf, 0x03, imo_encode, ic_encode ); // R/M byte
1919 //
1920 //     // xor rbp,ebp
1921 //     emit_opcode(cbuf, 0x33);
1922 //     emit_rm(cbuf, 0x3, EBP_enc, EBP_enc);
1923 //
1924 //     // CALL to interpreter.
1925 //     cbuf.set_insts_mark();
1926 //     $$$emit8$primary;
1927 //     emit_d32_reloc(cbuf, ($labl$$label - (int)(cbuf.insts_end()) - 4),
1928 //                 runtime_call_Relocation::spec(), RELOC_IMM32 );
1929 //   %}
1930 
1931   enc_class RegOpcImm (rRegI dst, immI8 shift) %{    // SHL, SAR, SHR
1932     $$$emit8$primary;
1933     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
1934     $$$emit8$shift$$constant;
1935   %}
1936 
1937   enc_class LdImmI (rRegI dst, immI src) %{    // Load Immediate
1938     // Load immediate does not have a zero or sign extended version
1939     // for 8-bit immediates
1940     emit_opcode(cbuf, 0xB8 + $dst$$reg);
1941     $$$emit32$src$$constant;
1942   %}
1943 
1944   enc_class LdImmP (rRegI dst, immI src) %{    // Load Immediate
1945     // Load immediate does not have a zero or sign extended version
1946     // for 8-bit immediates
1947     emit_opcode(cbuf, $primary + $dst$$reg);
1948     $$$emit32$src$$constant;
1949   %}
1950 
1951   enc_class LdImmL_Lo( eRegL dst, immL src) %{    // Load Immediate
1952     // Load immediate does not have a zero or sign extended version
1953     // for 8-bit immediates
1954     int dst_enc = $dst$$reg;
1955     int src_con = $src$$constant & 0x0FFFFFFFFL;
1956     if (src_con == 0) {
1957       // xor dst, dst
1958       emit_opcode(cbuf, 0x33);
1959       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
1960     } else {
1961       emit_opcode(cbuf, $primary + dst_enc);
1962       emit_d32(cbuf, src_con);
1963     }
1964   %}
1965 
1966   enc_class LdImmL_Hi( eRegL dst, immL src) %{    // Load Immediate
1967     // Load immediate does not have a zero or sign extended version
1968     // for 8-bit immediates
1969     int dst_enc = $dst$$reg + 2;
1970     int src_con = ((julong)($src$$constant)) >> 32;
1971     if (src_con == 0) {
1972       // xor dst, dst
1973       emit_opcode(cbuf, 0x33);
1974       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
1975     } else {
1976       emit_opcode(cbuf, $primary + dst_enc);
1977       emit_d32(cbuf, src_con);
1978     }
1979   %}
1980 
1981 
1982   // Encode a reg-reg copy.  If it is useless, then empty encoding.
1983   enc_class enc_Copy( rRegI dst, rRegI src ) %{
1984     encode_Copy( cbuf, $dst$$reg, $src$$reg );
1985   %}
1986 
1987   enc_class enc_CopyL_Lo( rRegI dst, eRegL src ) %{
1988     encode_Copy( cbuf, $dst$$reg, $src$$reg );
1989   %}
1990 
1991   enc_class RegReg (rRegI dst, rRegI src) %{    // RegReg(Many)
1992     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
1993   %}
1994 
1995   enc_class RegReg_Lo(eRegL dst, eRegL src) %{    // RegReg(Many)
1996     $$$emit8$primary;
1997     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
1998   %}
1999 
2000   enc_class RegReg_Hi(eRegL dst, eRegL src) %{    // RegReg(Many)
2001     $$$emit8$secondary;
2002     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
2003   %}
2004 
2005   enc_class RegReg_Lo2(eRegL dst, eRegL src) %{    // RegReg(Many)
2006     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
2007   %}
2008 
2009   enc_class RegReg_Hi2(eRegL dst, eRegL src) %{    // RegReg(Many)
2010     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
2011   %}
2012 
2013   enc_class RegReg_HiLo( eRegL src, rRegI dst ) %{
2014     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($src$$reg));
2015   %}
2016 
2017   enc_class Con32 (immI src) %{    // Con32(storeImmI)
2018     // Output immediate
2019     $$$emit32$src$$constant;
2020   %}
2021 
2022   enc_class Con32FPR_as_bits(immFPR src) %{        // storeF_imm
2023     // Output Float immediate bits
2024     jfloat jf = $src$$constant;
2025     int    jf_as_bits = jint_cast( jf );
2026     emit_d32(cbuf, jf_as_bits);
2027   %}
2028 
2029   enc_class Con32F_as_bits(immF src) %{      // storeX_imm
2030     // Output Float immediate bits
2031     jfloat jf = $src$$constant;
2032     int    jf_as_bits = jint_cast( jf );
2033     emit_d32(cbuf, jf_as_bits);
2034   %}
2035 
2036   enc_class Con16 (immI src) %{    // Con16(storeImmI)
2037     // Output immediate
2038     $$$emit16$src$$constant;
2039   %}
2040 
2041   enc_class Con_d32(immI src) %{
2042     emit_d32(cbuf,$src$$constant);
2043   %}
2044 
2045   enc_class conmemref (eRegP t1) %{    // Con32(storeImmI)
2046     // Output immediate memory reference
2047     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
2048     emit_d32(cbuf, 0x00);
2049   %}
2050 
2051   enc_class lock_prefix( ) %{
2052     if( os::is_MP() )
2053       emit_opcode(cbuf,0xF0);         // [Lock]
2054   %}
2055 
2056   // Cmp-xchg long value.
2057   // Note: we need to swap rbx, and rcx before and after the
2058   //       cmpxchg8 instruction because the instruction uses
2059   //       rcx as the high order word of the new value to store but
2060   //       our register encoding uses rbx,.
2061   enc_class enc_cmpxchg8(eSIRegP mem_ptr) %{
2062 
2063     // XCHG  rbx,ecx
2064     emit_opcode(cbuf,0x87);
2065     emit_opcode(cbuf,0xD9);
2066     // [Lock]
2067     if( os::is_MP() )
2068       emit_opcode(cbuf,0xF0);
2069     // CMPXCHG8 [Eptr]
2070     emit_opcode(cbuf,0x0F);
2071     emit_opcode(cbuf,0xC7);
2072     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
2073     // XCHG  rbx,ecx
2074     emit_opcode(cbuf,0x87);
2075     emit_opcode(cbuf,0xD9);
2076   %}
2077 
2078   enc_class enc_cmpxchg(eSIRegP mem_ptr) %{
2079     // [Lock]
2080     if( os::is_MP() )
2081       emit_opcode(cbuf,0xF0);
2082 
2083     // CMPXCHG [Eptr]
2084     emit_opcode(cbuf,0x0F);
2085     emit_opcode(cbuf,0xB1);
2086     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
2087   %}
2088 
2089   enc_class enc_flags_ne_to_boolean( iRegI res ) %{
2090     int res_encoding = $res$$reg;
2091 
2092     // MOV  res,0
2093     emit_opcode( cbuf, 0xB8 + res_encoding);
2094     emit_d32( cbuf, 0 );
2095     // JNE,s  fail
2096     emit_opcode(cbuf,0x75);
2097     emit_d8(cbuf, 5 );
2098     // MOV  res,1
2099     emit_opcode( cbuf, 0xB8 + res_encoding);
2100     emit_d32( cbuf, 1 );
2101     // fail:
2102   %}
2103 
2104   enc_class set_instruction_start( ) %{
2105     cbuf.set_insts_mark();            // Mark start of opcode for reloc info in mem operand
2106   %}
2107 
2108   enc_class RegMem (rRegI ereg, memory mem) %{    // emit_reg_mem
2109     int reg_encoding = $ereg$$reg;
2110     int base  = $mem$$base;
2111     int index = $mem$$index;
2112     int scale = $mem$$scale;
2113     int displace = $mem$$disp;
2114     relocInfo::relocType disp_reloc = $mem->disp_reloc();
2115     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
2116   %}
2117 
2118   enc_class RegMem_Hi(eRegL ereg, memory mem) %{    // emit_reg_mem
2119     int reg_encoding = HIGH_FROM_LOW($ereg$$reg);  // Hi register of pair, computed from lo
2120     int base  = $mem$$base;
2121     int index = $mem$$index;
2122     int scale = $mem$$scale;
2123     int displace = $mem$$disp + 4;      // Offset is 4 further in memory
2124     assert( $mem->disp_reloc() == relocInfo::none, "Cannot add 4 to oop" );
2125     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, relocInfo::none);
2126   %}
2127 
2128   enc_class move_long_small_shift( eRegL dst, immI_1_31 cnt ) %{
2129     int r1, r2;
2130     if( $tertiary == 0xA4 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
2131     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
2132     emit_opcode(cbuf,0x0F);
2133     emit_opcode(cbuf,$tertiary);
2134     emit_rm(cbuf, 0x3, r1, r2);
2135     emit_d8(cbuf,$cnt$$constant);
2136     emit_d8(cbuf,$primary);
2137     emit_rm(cbuf, 0x3, $secondary, r1);
2138     emit_d8(cbuf,$cnt$$constant);
2139   %}
2140 
2141   enc_class move_long_big_shift_sign( eRegL dst, immI_32_63 cnt ) %{
2142     emit_opcode( cbuf, 0x8B ); // Move
2143     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
2144     if( $cnt$$constant > 32 ) { // Shift, if not by zero
2145       emit_d8(cbuf,$primary);
2146       emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
2147       emit_d8(cbuf,$cnt$$constant-32);
2148     }
2149     emit_d8(cbuf,$primary);
2150     emit_rm(cbuf, 0x3, $secondary, HIGH_FROM_LOW($dst$$reg));
2151     emit_d8(cbuf,31);
2152   %}
2153 
2154   enc_class move_long_big_shift_clr( eRegL dst, immI_32_63 cnt ) %{
2155     int r1, r2;
2156     if( $secondary == 0x5 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
2157     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
2158 
2159     emit_opcode( cbuf, 0x8B ); // Move r1,r2
2160     emit_rm(cbuf, 0x3, r1, r2);
2161     if( $cnt$$constant > 32 ) { // Shift, if not by zero
2162       emit_opcode(cbuf,$primary);
2163       emit_rm(cbuf, 0x3, $secondary, r1);
2164       emit_d8(cbuf,$cnt$$constant-32);
2165     }
2166     emit_opcode(cbuf,0x33);  // XOR r2,r2
2167     emit_rm(cbuf, 0x3, r2, r2);
2168   %}
2169 
2170   // Clone of RegMem but accepts an extra parameter to access each
2171   // half of a double in memory; it never needs relocation info.
2172   enc_class Mov_MemD_half_to_Reg (immI opcode, memory mem, immI disp_for_half, rRegI rm_reg) %{
2173     emit_opcode(cbuf,$opcode$$constant);
2174     int reg_encoding = $rm_reg$$reg;
2175     int base     = $mem$$base;
2176     int index    = $mem$$index;
2177     int scale    = $mem$$scale;
2178     int displace = $mem$$disp + $disp_for_half$$constant;
2179     relocInfo::relocType disp_reloc = relocInfo::none;
2180     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
2181   %}
2182 
2183   // !!!!! Special Custom Code used by MemMove, and stack access instructions !!!!!
2184   //
2185   // Clone of RegMem except the RM-byte's reg/opcode field is an ADLC-time constant
2186   // and it never needs relocation information.
2187   // Frequently used to move data between FPU's Stack Top and memory.
2188   enc_class RMopc_Mem_no_oop (immI rm_opcode, memory mem) %{
2189     int rm_byte_opcode = $rm_opcode$$constant;
2190     int base     = $mem$$base;
2191     int index    = $mem$$index;
2192     int scale    = $mem$$scale;
2193     int displace = $mem$$disp;
2194     assert( $mem->disp_reloc() == relocInfo::none, "No oops here because no reloc info allowed" );
2195     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, relocInfo::none);
2196   %}
2197 
2198   enc_class RMopc_Mem (immI rm_opcode, memory mem) %{
2199     int rm_byte_opcode = $rm_opcode$$constant;
2200     int base     = $mem$$base;
2201     int index    = $mem$$index;
2202     int scale    = $mem$$scale;
2203     int displace = $mem$$disp;
2204     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
2205     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
2206   %}
2207 
2208   enc_class RegLea (rRegI dst, rRegI src0, immI src1 ) %{    // emit_reg_lea
2209     int reg_encoding = $dst$$reg;
2210     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
2211     int index        = 0x04;            // 0x04 indicates no index
2212     int scale        = 0x00;            // 0x00 indicates no scale
2213     int displace     = $src1$$constant; // 0x00 indicates no displacement
2214     relocInfo::relocType disp_reloc = relocInfo::none;
2215     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
2216   %}
2217 
2218   enc_class min_enc (rRegI dst, rRegI src) %{    // MIN
2219     // Compare dst,src
2220     emit_opcode(cbuf,0x3B);
2221     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
2222     // jmp dst < src around move
2223     emit_opcode(cbuf,0x7C);
2224     emit_d8(cbuf,2);
2225     // move dst,src
2226     emit_opcode(cbuf,0x8B);
2227     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
2228   %}
2229 
2230   enc_class max_enc (rRegI dst, rRegI src) %{    // MAX
2231     // Compare dst,src
2232     emit_opcode(cbuf,0x3B);
2233     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
2234     // jmp dst > src around move
2235     emit_opcode(cbuf,0x7F);
2236     emit_d8(cbuf,2);
2237     // move dst,src
2238     emit_opcode(cbuf,0x8B);
2239     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
2240   %}
2241 
2242   enc_class enc_FPR_store(memory mem, regDPR src) %{
2243     // If src is FPR1, we can just FST to store it.
2244     // Else we need to FLD it to FPR1, then FSTP to store/pop it.
2245     int reg_encoding = 0x2; // Just store
2246     int base  = $mem$$base;
2247     int index = $mem$$index;
2248     int scale = $mem$$scale;
2249     int displace = $mem$$disp;
2250     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
2251     if( $src$$reg != FPR1L_enc ) {
2252       reg_encoding = 0x3;  // Store & pop
2253       emit_opcode( cbuf, 0xD9 ); // FLD (i.e., push it)
2254       emit_d8( cbuf, 0xC0-1+$src$$reg );
2255     }
2256     cbuf.set_insts_mark();       // Mark start of opcode for reloc info in mem operand
2257     emit_opcode(cbuf,$primary);
2258     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
2259   %}
2260 
2261   enc_class neg_reg(rRegI dst) %{
2262     // NEG $dst
2263     emit_opcode(cbuf,0xF7);
2264     emit_rm(cbuf, 0x3, 0x03, $dst$$reg );
2265   %}
2266 
2267   enc_class setLT_reg(eCXRegI dst) %{
2268     // SETLT $dst
2269     emit_opcode(cbuf,0x0F);
2270     emit_opcode(cbuf,0x9C);
2271     emit_rm( cbuf, 0x3, 0x4, $dst$$reg );
2272   %}
2273 
2274   enc_class enc_cmpLTP(ncxRegI p, ncxRegI q, ncxRegI y, eCXRegI tmp) %{    // cadd_cmpLT
2275     int tmpReg = $tmp$$reg;
2276 
2277     // SUB $p,$q
2278     emit_opcode(cbuf,0x2B);
2279     emit_rm(cbuf, 0x3, $p$$reg, $q$$reg);
2280     // SBB $tmp,$tmp
2281     emit_opcode(cbuf,0x1B);
2282     emit_rm(cbuf, 0x3, tmpReg, tmpReg);
2283     // AND $tmp,$y
2284     emit_opcode(cbuf,0x23);
2285     emit_rm(cbuf, 0x3, tmpReg, $y$$reg);
2286     // ADD $p,$tmp
2287     emit_opcode(cbuf,0x03);
2288     emit_rm(cbuf, 0x3, $p$$reg, tmpReg);
2289   %}
2290 
2291   enc_class shift_left_long( eRegL dst, eCXRegI shift ) %{
2292     // TEST shift,32
2293     emit_opcode(cbuf,0xF7);
2294     emit_rm(cbuf, 0x3, 0, ECX_enc);
2295     emit_d32(cbuf,0x20);
2296     // JEQ,s small
2297     emit_opcode(cbuf, 0x74);
2298     emit_d8(cbuf, 0x04);
2299     // MOV    $dst.hi,$dst.lo
2300     emit_opcode( cbuf, 0x8B );
2301     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
2302     // CLR    $dst.lo
2303     emit_opcode(cbuf, 0x33);
2304     emit_rm(cbuf, 0x3, $dst$$reg, $dst$$reg);
2305 // small:
2306     // SHLD   $dst.hi,$dst.lo,$shift
2307     emit_opcode(cbuf,0x0F);
2308     emit_opcode(cbuf,0xA5);
2309     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
2310     // SHL    $dst.lo,$shift"
2311     emit_opcode(cbuf,0xD3);
2312     emit_rm(cbuf, 0x3, 0x4, $dst$$reg );
2313   %}
2314 
2315   enc_class shift_right_long( eRegL dst, eCXRegI shift ) %{
2316     // TEST shift,32
2317     emit_opcode(cbuf,0xF7);
2318     emit_rm(cbuf, 0x3, 0, ECX_enc);
2319     emit_d32(cbuf,0x20);
2320     // JEQ,s small
2321     emit_opcode(cbuf, 0x74);
2322     emit_d8(cbuf, 0x04);
2323     // MOV    $dst.lo,$dst.hi
2324     emit_opcode( cbuf, 0x8B );
2325     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
2326     // CLR    $dst.hi
2327     emit_opcode(cbuf, 0x33);
2328     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($dst$$reg));
2329 // small:
2330     // SHRD   $dst.lo,$dst.hi,$shift
2331     emit_opcode(cbuf,0x0F);
2332     emit_opcode(cbuf,0xAD);
2333     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
2334     // SHR    $dst.hi,$shift"
2335     emit_opcode(cbuf,0xD3);
2336     emit_rm(cbuf, 0x3, 0x5, HIGH_FROM_LOW($dst$$reg) );
2337   %}
2338 
2339   enc_class shift_right_arith_long( eRegL dst, eCXRegI shift ) %{
2340     // TEST shift,32
2341     emit_opcode(cbuf,0xF7);
2342     emit_rm(cbuf, 0x3, 0, ECX_enc);
2343     emit_d32(cbuf,0x20);
2344     // JEQ,s small
2345     emit_opcode(cbuf, 0x74);
2346     emit_d8(cbuf, 0x05);
2347     // MOV    $dst.lo,$dst.hi
2348     emit_opcode( cbuf, 0x8B );
2349     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
2350     // SAR    $dst.hi,31
2351     emit_opcode(cbuf, 0xC1);
2352     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW($dst$$reg) );
2353     emit_d8(cbuf, 0x1F );
2354 // small:
2355     // SHRD   $dst.lo,$dst.hi,$shift
2356     emit_opcode(cbuf,0x0F);
2357     emit_opcode(cbuf,0xAD);
2358     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
2359     // SAR    $dst.hi,$shift"
2360     emit_opcode(cbuf,0xD3);
2361     emit_rm(cbuf, 0x3, 0x7, HIGH_FROM_LOW($dst$$reg) );
2362   %}
2363 
2364 
2365   // ----------------- Encodings for floating point unit -----------------
2366   // May leave result in FPU-TOS or FPU reg depending on opcodes
2367   enc_class OpcReg_FPR(regFPR src) %{    // FMUL, FDIV
2368     $$$emit8$primary;
2369     emit_rm(cbuf, 0x3, $secondary, $src$$reg );
2370   %}
2371 
2372   // Pop argument in FPR0 with FSTP ST(0)
2373   enc_class PopFPU() %{
2374     emit_opcode( cbuf, 0xDD );
2375     emit_d8( cbuf, 0xD8 );
2376   %}
2377 
2378   // !!!!! equivalent to Pop_Reg_F
2379   enc_class Pop_Reg_DPR( regDPR dst ) %{
2380     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
2381     emit_d8( cbuf, 0xD8+$dst$$reg );
2382   %}
2383 
2384   enc_class Push_Reg_DPR( regDPR dst ) %{
2385     emit_opcode( cbuf, 0xD9 );
2386     emit_d8( cbuf, 0xC0-1+$dst$$reg );   // FLD ST(i-1)
2387   %}
2388 
2389   enc_class strictfp_bias1( regDPR dst ) %{
2390     emit_opcode( cbuf, 0xDB );           // FLD m80real
2391     emit_opcode( cbuf, 0x2D );
2392     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias1() );
2393     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
2394     emit_opcode( cbuf, 0xC8+$dst$$reg );
2395   %}
2396 
2397   enc_class strictfp_bias2( regDPR dst ) %{
2398     emit_opcode( cbuf, 0xDB );           // FLD m80real
2399     emit_opcode( cbuf, 0x2D );
2400     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias2() );
2401     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
2402     emit_opcode( cbuf, 0xC8+$dst$$reg );
2403   %}
2404 
2405   // Special case for moving an integer register to a stack slot.
2406   enc_class OpcPRegSS( stackSlotI dst, rRegI src ) %{ // RegSS
2407     store_to_stackslot( cbuf, $primary, $src$$reg, $dst$$disp );
2408   %}
2409 
2410   // Special case for moving a register to a stack slot.
2411   enc_class RegSS( stackSlotI dst, rRegI src ) %{ // RegSS
2412     // Opcode already emitted
2413     emit_rm( cbuf, 0x02, $src$$reg, ESP_enc );   // R/M byte
2414     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);          // SIB byte
2415     emit_d32(cbuf, $dst$$disp);   // Displacement
2416   %}
2417 
2418   // Push the integer in stackSlot 'src' onto FP-stack
2419   enc_class Push_Mem_I( memory src ) %{    // FILD   [ESP+src]
2420     store_to_stackslot( cbuf, $primary, $secondary, $src$$disp );
2421   %}
2422 
2423   // Push FPU's TOS float to a stack-slot, and pop FPU-stack
2424   enc_class Pop_Mem_FPR( stackSlotF dst ) %{ // FSTP_S [ESP+dst]
2425     store_to_stackslot( cbuf, 0xD9, 0x03, $dst$$disp );
2426   %}
2427 
2428   // Same as Pop_Mem_F except for opcode
2429   // Push FPU's TOS double to a stack-slot, and pop FPU-stack
2430   enc_class Pop_Mem_DPR( stackSlotD dst ) %{ // FSTP_D [ESP+dst]
2431     store_to_stackslot( cbuf, 0xDD, 0x03, $dst$$disp );
2432   %}
2433 
2434   enc_class Pop_Reg_FPR( regFPR dst ) %{
2435     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
2436     emit_d8( cbuf, 0xD8+$dst$$reg );
2437   %}
2438 
2439   enc_class Push_Reg_FPR( regFPR dst ) %{
2440     emit_opcode( cbuf, 0xD9 );           // FLD    ST(i-1)
2441     emit_d8( cbuf, 0xC0-1+$dst$$reg );
2442   %}
2443 
2444   // Push FPU's float to a stack-slot, and pop FPU-stack
2445   enc_class Pop_Mem_Reg_FPR( stackSlotF dst, regFPR src ) %{
2446     int pop = 0x02;
2447     if ($src$$reg != FPR1L_enc) {
2448       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
2449       emit_d8( cbuf, 0xC0-1+$src$$reg );
2450       pop = 0x03;
2451     }
2452     store_to_stackslot( cbuf, 0xD9, pop, $dst$$disp ); // FST<P>_S  [ESP+dst]
2453   %}
2454 
2455   // Push FPU's double to a stack-slot, and pop FPU-stack
2456   enc_class Pop_Mem_Reg_DPR( stackSlotD dst, regDPR src ) %{
2457     int pop = 0x02;
2458     if ($src$$reg != FPR1L_enc) {
2459       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
2460       emit_d8( cbuf, 0xC0-1+$src$$reg );
2461       pop = 0x03;
2462     }
2463     store_to_stackslot( cbuf, 0xDD, pop, $dst$$disp ); // FST<P>_D  [ESP+dst]
2464   %}
2465 
2466   // Push FPU's double to a FPU-stack-slot, and pop FPU-stack
2467   enc_class Pop_Reg_Reg_DPR( regDPR dst, regFPR src ) %{
2468     int pop = 0xD0 - 1; // -1 since we skip FLD
2469     if ($src$$reg != FPR1L_enc) {
2470       emit_opcode( cbuf, 0xD9 );         // FLD    ST(src-1)
2471       emit_d8( cbuf, 0xC0-1+$src$$reg );
2472       pop = 0xD8;
2473     }
2474     emit_opcode( cbuf, 0xDD );
2475     emit_d8( cbuf, pop+$dst$$reg );      // FST<P> ST(i)
2476   %}
2477 
2478 
2479   enc_class Push_Reg_Mod_DPR( regDPR dst, regDPR src) %{
2480     // load dst in FPR0
2481     emit_opcode( cbuf, 0xD9 );
2482     emit_d8( cbuf, 0xC0-1+$dst$$reg );
2483     if ($src$$reg != FPR1L_enc) {
2484       // fincstp
2485       emit_opcode (cbuf, 0xD9);
2486       emit_opcode (cbuf, 0xF7);
2487       // swap src with FPR1:
2488       // FXCH FPR1 with src
2489       emit_opcode(cbuf, 0xD9);
2490       emit_d8(cbuf, 0xC8-1+$src$$reg );
2491       // fdecstp
2492       emit_opcode (cbuf, 0xD9);
2493       emit_opcode (cbuf, 0xF6);
2494     }
2495   %}
2496 
2497   enc_class Push_ModD_encoding(regD src0, regD src1) %{
2498     MacroAssembler _masm(&cbuf);
2499     __ subptr(rsp, 8);
2500     __ movdbl(Address(rsp, 0), $src1$$XMMRegister);
2501     __ fld_d(Address(rsp, 0));
2502     __ movdbl(Address(rsp, 0), $src0$$XMMRegister);
2503     __ fld_d(Address(rsp, 0));
2504   %}
2505 
2506   enc_class Push_ModF_encoding(regF src0, regF src1) %{
2507     MacroAssembler _masm(&cbuf);
2508     __ subptr(rsp, 4);
2509     __ movflt(Address(rsp, 0), $src1$$XMMRegister);
2510     __ fld_s(Address(rsp, 0));
2511     __ movflt(Address(rsp, 0), $src0$$XMMRegister);
2512     __ fld_s(Address(rsp, 0));
2513   %}
2514 
2515   enc_class Push_ResultD(regD dst) %{
2516     MacroAssembler _masm(&cbuf);
2517     __ fstp_d(Address(rsp, 0));
2518     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
2519     __ addptr(rsp, 8);
2520   %}
2521 
2522   enc_class Push_ResultF(regF dst, immI d8) %{
2523     MacroAssembler _masm(&cbuf);
2524     __ fstp_s(Address(rsp, 0));
2525     __ movflt($dst$$XMMRegister, Address(rsp, 0));
2526     __ addptr(rsp, $d8$$constant);
2527   %}
2528 
2529   enc_class Push_SrcD(regD src) %{
2530     MacroAssembler _masm(&cbuf);
2531     __ subptr(rsp, 8);
2532     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
2533     __ fld_d(Address(rsp, 0));
2534   %}
2535 
2536   enc_class push_stack_temp_qword() %{
2537     MacroAssembler _masm(&cbuf);
2538     __ subptr(rsp, 8);
2539   %}
2540 
2541   enc_class pop_stack_temp_qword() %{
2542     MacroAssembler _masm(&cbuf);
2543     __ addptr(rsp, 8);
2544   %}
2545 
2546   enc_class push_xmm_to_fpr1(regD src) %{
2547     MacroAssembler _masm(&cbuf);
2548     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
2549     __ fld_d(Address(rsp, 0));
2550   %}
2551 
2552   enc_class Push_Result_Mod_DPR( regDPR src) %{
2553     if ($src$$reg != FPR1L_enc) {
2554       // fincstp
2555       emit_opcode (cbuf, 0xD9);
2556       emit_opcode (cbuf, 0xF7);
2557       // FXCH FPR1 with src
2558       emit_opcode(cbuf, 0xD9);
2559       emit_d8(cbuf, 0xC8-1+$src$$reg );
2560       // fdecstp
2561       emit_opcode (cbuf, 0xD9);
2562       emit_opcode (cbuf, 0xF6);
2563     }
2564     // // following asm replaced with Pop_Reg_F or Pop_Mem_F
2565     // // FSTP   FPR$dst$$reg
2566     // emit_opcode( cbuf, 0xDD );
2567     // emit_d8( cbuf, 0xD8+$dst$$reg );
2568   %}
2569 
2570   enc_class fnstsw_sahf_skip_parity() %{
2571     // fnstsw ax
2572     emit_opcode( cbuf, 0xDF );
2573     emit_opcode( cbuf, 0xE0 );
2574     // sahf
2575     emit_opcode( cbuf, 0x9E );
2576     // jnp  ::skip
2577     emit_opcode( cbuf, 0x7B );
2578     emit_opcode( cbuf, 0x05 );
2579   %}
2580 
2581   enc_class emitModDPR() %{
2582     // fprem must be iterative
2583     // :: loop
2584     // fprem
2585     emit_opcode( cbuf, 0xD9 );
2586     emit_opcode( cbuf, 0xF8 );
2587     // wait
2588     emit_opcode( cbuf, 0x9b );
2589     // fnstsw ax
2590     emit_opcode( cbuf, 0xDF );
2591     emit_opcode( cbuf, 0xE0 );
2592     // sahf
2593     emit_opcode( cbuf, 0x9E );
2594     // jp  ::loop
2595     emit_opcode( cbuf, 0x0F );
2596     emit_opcode( cbuf, 0x8A );
2597     emit_opcode( cbuf, 0xF4 );
2598     emit_opcode( cbuf, 0xFF );
2599     emit_opcode( cbuf, 0xFF );
2600     emit_opcode( cbuf, 0xFF );
2601   %}
2602 
2603   enc_class fpu_flags() %{
2604     // fnstsw_ax
2605     emit_opcode( cbuf, 0xDF);
2606     emit_opcode( cbuf, 0xE0);
2607     // test ax,0x0400
2608     emit_opcode( cbuf, 0x66 );   // operand-size prefix for 16-bit immediate
2609     emit_opcode( cbuf, 0xA9 );
2610     emit_d16   ( cbuf, 0x0400 );
2611     // // // This sequence works, but stalls for 12-16 cycles on PPro
2612     // // test rax,0x0400
2613     // emit_opcode( cbuf, 0xA9 );
2614     // emit_d32   ( cbuf, 0x00000400 );
2615     //
2616     // jz exit (no unordered comparison)
2617     emit_opcode( cbuf, 0x74 );
2618     emit_d8    ( cbuf, 0x02 );
2619     // mov ah,1 - treat as LT case (set carry flag)
2620     emit_opcode( cbuf, 0xB4 );
2621     emit_d8    ( cbuf, 0x01 );
2622     // sahf
2623     emit_opcode( cbuf, 0x9E);
2624   %}
2625 
2626   enc_class cmpF_P6_fixup() %{
2627     // Fixup the integer flags in case comparison involved a NaN
2628     //
2629     // JNP exit (no unordered comparison, P-flag is set by NaN)
2630     emit_opcode( cbuf, 0x7B );
2631     emit_d8    ( cbuf, 0x03 );
2632     // MOV AH,1 - treat as LT case (set carry flag)
2633     emit_opcode( cbuf, 0xB4 );
2634     emit_d8    ( cbuf, 0x01 );
2635     // SAHF
2636     emit_opcode( cbuf, 0x9E);
2637     // NOP     // target for branch to avoid branch to branch
2638     emit_opcode( cbuf, 0x90);
2639   %}
2640 
2641 //     fnstsw_ax();
2642 //     sahf();
2643 //     movl(dst, nan_result);
2644 //     jcc(Assembler::parity, exit);
2645 //     movl(dst, less_result);
2646 //     jcc(Assembler::below, exit);
2647 //     movl(dst, equal_result);
2648 //     jcc(Assembler::equal, exit);
2649 //     movl(dst, greater_result);
2650 
2651 // less_result     =  1;
2652 // greater_result  = -1;
2653 // equal_result    = 0;
2654 // nan_result      = -1;
2655 
2656   enc_class CmpF_Result(rRegI dst) %{
2657     // fnstsw_ax();
2658     emit_opcode( cbuf, 0xDF);
2659     emit_opcode( cbuf, 0xE0);
2660     // sahf
2661     emit_opcode( cbuf, 0x9E);
2662     // movl(dst, nan_result);
2663     emit_opcode( cbuf, 0xB8 + $dst$$reg);
2664     emit_d32( cbuf, -1 );
2665     // jcc(Assembler::parity, exit);
2666     emit_opcode( cbuf, 0x7A );
2667     emit_d8    ( cbuf, 0x13 );
2668     // movl(dst, less_result);
2669     emit_opcode( cbuf, 0xB8 + $dst$$reg);
2670     emit_d32( cbuf, -1 );
2671     // jcc(Assembler::below, exit);
2672     emit_opcode( cbuf, 0x72 );
2673     emit_d8    ( cbuf, 0x0C );
2674     // movl(dst, equal_result);
2675     emit_opcode( cbuf, 0xB8 + $dst$$reg);
2676     emit_d32( cbuf, 0 );
2677     // jcc(Assembler::equal, exit);
2678     emit_opcode( cbuf, 0x74 );
2679     emit_d8    ( cbuf, 0x05 );
2680     // movl(dst, greater_result);
2681     emit_opcode( cbuf, 0xB8 + $dst$$reg);
2682     emit_d32( cbuf, 1 );
2683   %}
2684 
2685 
2686   // Compare the longs and set flags
2687   // BROKEN!  Do Not use as-is
2688   enc_class cmpl_test( eRegL src1, eRegL src2 ) %{
2689     // CMP    $src1.hi,$src2.hi
2690     emit_opcode( cbuf, 0x3B );
2691     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
2692     // JNE,s  done
2693     emit_opcode(cbuf,0x75);
2694     emit_d8(cbuf, 2 );
2695     // CMP    $src1.lo,$src2.lo
2696     emit_opcode( cbuf, 0x3B );
2697     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
2698 // done:
2699   %}
2700 
2701   enc_class convert_int_long( regL dst, rRegI src ) %{
2702     // mov $dst.lo,$src
2703     int dst_encoding = $dst$$reg;
2704     int src_encoding = $src$$reg;
2705     encode_Copy( cbuf, dst_encoding  , src_encoding );
2706     // mov $dst.hi,$src
2707     encode_Copy( cbuf, HIGH_FROM_LOW(dst_encoding), src_encoding );
2708     // sar $dst.hi,31
2709     emit_opcode( cbuf, 0xC1 );
2710     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW(dst_encoding) );
2711     emit_d8(cbuf, 0x1F );
2712   %}
2713 
2714   enc_class convert_long_double( eRegL src ) %{
2715     // push $src.hi
2716     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
2717     // push $src.lo
2718     emit_opcode(cbuf, 0x50+$src$$reg  );
2719     // fild 64-bits at [SP]
2720     emit_opcode(cbuf,0xdf);
2721     emit_d8(cbuf, 0x6C);
2722     emit_d8(cbuf, 0x24);
2723     emit_d8(cbuf, 0x00);
2724     // pop stack
2725     emit_opcode(cbuf, 0x83); // add  SP, #8
2726     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
2727     emit_d8(cbuf, 0x8);
2728   %}
2729 
2730   enc_class multiply_con_and_shift_high( eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr ) %{
2731     // IMUL   EDX:EAX,$src1
2732     emit_opcode( cbuf, 0xF7 );
2733     emit_rm( cbuf, 0x3, 0x5, $src1$$reg );
2734     // SAR    EDX,$cnt-32
2735     int shift_count = ((int)$cnt$$constant) - 32;
2736     if (shift_count > 0) {
2737       emit_opcode(cbuf, 0xC1);
2738       emit_rm(cbuf, 0x3, 7, $dst$$reg );
2739       emit_d8(cbuf, shift_count);
2740     }
2741   %}
2742 
2743   // this version doesn't have add sp, 8
2744   enc_class convert_long_double2( eRegL src ) %{
2745     // push $src.hi
2746     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
2747     // push $src.lo
2748     emit_opcode(cbuf, 0x50+$src$$reg  );
2749     // fild 64-bits at [SP]
2750     emit_opcode(cbuf,0xdf);
2751     emit_d8(cbuf, 0x6C);
2752     emit_d8(cbuf, 0x24);
2753     emit_d8(cbuf, 0x00);
2754   %}
2755 
2756   enc_class long_int_multiply( eADXRegL dst, nadxRegI src) %{
2757     // Basic idea: long = (long)int * (long)int
2758     // IMUL EDX:EAX, src
2759     emit_opcode( cbuf, 0xF7 );
2760     emit_rm( cbuf, 0x3, 0x5, $src$$reg);
2761   %}
2762 
2763   enc_class long_uint_multiply( eADXRegL dst, nadxRegI src) %{
2764     // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
2765     // MUL EDX:EAX, src
2766     emit_opcode( cbuf, 0xF7 );
2767     emit_rm( cbuf, 0x3, 0x4, $src$$reg);
2768   %}
2769 
2770   enc_class long_multiply( eADXRegL dst, eRegL src, rRegI tmp ) %{
2771     // Basic idea: lo(result) = lo(x_lo * y_lo)
2772     //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
2773     // MOV    $tmp,$src.lo
2774     encode_Copy( cbuf, $tmp$$reg, $src$$reg );
2775     // IMUL   $tmp,EDX
2776     emit_opcode( cbuf, 0x0F );
2777     emit_opcode( cbuf, 0xAF );
2778     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
2779     // MOV    EDX,$src.hi
2780     encode_Copy( cbuf, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg) );
2781     // IMUL   EDX,EAX
2782     emit_opcode( cbuf, 0x0F );
2783     emit_opcode( cbuf, 0xAF );
2784     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
2785     // ADD    $tmp,EDX
2786     emit_opcode( cbuf, 0x03 );
2787     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
2788     // MUL   EDX:EAX,$src.lo
2789     emit_opcode( cbuf, 0xF7 );
2790     emit_rm( cbuf, 0x3, 0x4, $src$$reg );
2791     // ADD    EDX,ESI
2792     emit_opcode( cbuf, 0x03 );
2793     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $tmp$$reg );
2794   %}
2795 
2796   enc_class long_multiply_con( eADXRegL dst, immL_127 src, rRegI tmp ) %{
2797     // Basic idea: lo(result) = lo(src * y_lo)
2798     //             hi(result) = hi(src * y_lo) + lo(src * y_hi)
2799     // IMUL   $tmp,EDX,$src
2800     emit_opcode( cbuf, 0x6B );
2801     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
2802     emit_d8( cbuf, (int)$src$$constant );
2803     // MOV    EDX,$src
2804     emit_opcode(cbuf, 0xB8 + EDX_enc);
2805     emit_d32( cbuf, (int)$src$$constant );
2806     // MUL   EDX:EAX,EDX
2807     emit_opcode( cbuf, 0xF7 );
2808     emit_rm( cbuf, 0x3, 0x4, EDX_enc );
2809     // ADD    EDX,ESI
2810     emit_opcode( cbuf, 0x03 );
2811     emit_rm( cbuf, 0x3, EDX_enc, $tmp$$reg );
2812   %}
2813 
2814   enc_class long_div( eRegL src1, eRegL src2 ) %{
2815     // PUSH src1.hi
2816     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
2817     // PUSH src1.lo
2818     emit_opcode(cbuf,               0x50+$src1$$reg  );
2819     // PUSH src2.hi
2820     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
2821     // PUSH src2.lo
2822     emit_opcode(cbuf,               0x50+$src2$$reg  );
2823     // CALL directly to the runtime
2824     cbuf.set_insts_mark();
2825     emit_opcode(cbuf,0xE8);       // Call into runtime
2826     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::ldiv) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
2827     // Restore stack
2828     emit_opcode(cbuf, 0x83); // add  SP, #framesize
2829     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
2830     emit_d8(cbuf, 4*4);
2831   %}
2832 
2833   enc_class long_mod( eRegL src1, eRegL src2 ) %{
2834     // PUSH src1.hi
2835     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
2836     // PUSH src1.lo
2837     emit_opcode(cbuf,               0x50+$src1$$reg  );
2838     // PUSH src2.hi
2839     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
2840     // PUSH src2.lo
2841     emit_opcode(cbuf,               0x50+$src2$$reg  );
2842     // CALL directly to the runtime
2843     cbuf.set_insts_mark();
2844     emit_opcode(cbuf,0xE8);       // Call into runtime
2845     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::lrem ) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
2846     // Restore stack
2847     emit_opcode(cbuf, 0x83); // add  SP, #framesize
2848     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
2849     emit_d8(cbuf, 4*4);
2850   %}
2851 
2852   enc_class long_cmp_flags0( eRegL src, rRegI tmp ) %{
2853     // MOV   $tmp,$src.lo
2854     emit_opcode(cbuf, 0x8B);
2855     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg);
2856     // OR    $tmp,$src.hi
2857     emit_opcode(cbuf, 0x0B);
2858     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg));
2859   %}
2860 
2861   enc_class long_cmp_flags1( eRegL src1, eRegL src2 ) %{
2862     // CMP    $src1.lo,$src2.lo
2863     emit_opcode( cbuf, 0x3B );
2864     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
2865     // JNE,s  skip
2866     emit_cc(cbuf, 0x70, 0x5);
2867     emit_d8(cbuf,2);
2868     // CMP    $src1.hi,$src2.hi
2869     emit_opcode( cbuf, 0x3B );
2870     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
2871   %}
2872 
2873   enc_class long_cmp_flags2( eRegL src1, eRegL src2, rRegI tmp ) %{
2874     // CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits
2875     emit_opcode( cbuf, 0x3B );
2876     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
2877     // MOV    $tmp,$src1.hi
2878     emit_opcode( cbuf, 0x8B );
2879     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src1$$reg) );
2880     // SBB   $tmp,$src2.hi\t! Compute flags for long compare
2881     emit_opcode( cbuf, 0x1B );
2882     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src2$$reg) );
2883   %}
2884 
2885   enc_class long_cmp_flags3( eRegL src, rRegI tmp ) %{
2886     // XOR    $tmp,$tmp
2887     emit_opcode(cbuf,0x33);  // XOR
2888     emit_rm(cbuf,0x3, $tmp$$reg, $tmp$$reg);
2889     // CMP    $tmp,$src.lo
2890     emit_opcode( cbuf, 0x3B );
2891     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg );
2892     // SBB    $tmp,$src.hi
2893     emit_opcode( cbuf, 0x1B );
2894     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg) );
2895   %}
2896 
2897  // Sniff, sniff... smells like Gnu Superoptimizer
2898   enc_class neg_long( eRegL dst ) %{
2899     emit_opcode(cbuf,0xF7);    // NEG hi
2900     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
2901     emit_opcode(cbuf,0xF7);    // NEG lo
2902     emit_rm    (cbuf,0x3, 0x3,               $dst$$reg );
2903     emit_opcode(cbuf,0x83);    // SBB hi,0
2904     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
2905     emit_d8    (cbuf,0 );
2906   %}
2907 
2908 
2909   // Because the transitions from emitted code to the runtime
2910   // monitorenter/exit helper stubs are so slow it's critical that
2911   // we inline both the stack-locking fast-path and the inflated fast path.
2912   //
2913   // See also: cmpFastLock and cmpFastUnlock.
2914   //
2915   // What follows is a specialized inline transliteration of the code
2916   // in slow_enter() and slow_exit().  If we're concerned about I$ bloat
2917   // another option would be to emit TrySlowEnter and TrySlowExit methods
2918   // at startup-time.  These methods would accept arguments as
2919   // (rax,=Obj, rbx=Self, rcx=box, rdx=Scratch) and return success-failure
2920   // indications in the icc.ZFlag.  Fast_Lock and Fast_Unlock would simply
2921   // marshal the arguments and emit calls to TrySlowEnter and TrySlowExit.
2922   // In practice, however, the # of lock sites is bounded and is usually small.
2923   // Besides the call overhead, TrySlowEnter and TrySlowExit might suffer
2924   // if the processor uses simple bimodal branch predictors keyed by EIP
2925   // Since the helper routines would be called from multiple synchronization
2926   // sites.
2927   //
2928   // An even better approach would be write "MonitorEnter()" and "MonitorExit()"
2929   // in java - using j.u.c and unsafe - and just bind the lock and unlock sites
2930   // to those specialized methods.  That'd give us a mostly platform-independent
2931   // implementation that the JITs could optimize and inline at their pleasure.
2932   // Done correctly, the only time we'd need to cross to native could would be
2933   // to park() or unpark() threads.  We'd also need a few more unsafe operators
2934   // to (a) prevent compiler-JIT reordering of non-volatile accesses, and
2935   // (b) explicit barriers or fence operations.
2936   //
2937   // TODO:
2938   //
2939   // *  Arrange for C2 to pass "Self" into Fast_Lock and Fast_Unlock in one of the registers (scr).
2940   //    This avoids manifesting the Self pointer in the Fast_Lock and Fast_Unlock terminals.
2941   //    Given TLAB allocation, Self is usually manifested in a register, so passing it into
2942   //    the lock operators would typically be faster than reifying Self.
2943   //
2944   // *  Ideally I'd define the primitives as:
2945   //       fast_lock   (nax Obj, nax box, EAX tmp, nax scr) where box, tmp and scr are KILLED.
2946   //       fast_unlock (nax Obj, EAX box, nax tmp) where box and tmp are KILLED
2947   //    Unfortunately ADLC bugs prevent us from expressing the ideal form.
2948   //    Instead, we're stuck with a rather awkward and brittle register assignments below.
2949   //    Furthermore the register assignments are overconstrained, possibly resulting in
2950   //    sub-optimal code near the synchronization site.
2951   //
2952   // *  Eliminate the sp-proximity tests and just use "== Self" tests instead.
2953   //    Alternately, use a better sp-proximity test.
2954   //
2955   // *  Currently ObjectMonitor._Owner can hold either an sp value or a (THREAD *) value.
2956   //    Either one is sufficient to uniquely identify a thread.
2957   //    TODO: eliminate use of sp in _owner and use get_thread(tr) instead.
2958   //
2959   // *  Intrinsify notify() and notifyAll() for the common cases where the
2960   //    object is locked by the calling thread but the waitlist is empty.
2961   //    avoid the expensive JNI call to JVM_Notify() and JVM_NotifyAll().
2962   //
2963   // *  use jccb and jmpb instead of jcc and jmp to improve code density.
2964   //    But beware of excessive branch density on AMD Opterons.
2965   //
2966   // *  Both Fast_Lock and Fast_Unlock set the ICC.ZF to indicate success
2967   //    or failure of the fast-path.  If the fast-path fails then we pass
2968   //    control to the slow-path, typically in C.  In Fast_Lock and
2969   //    Fast_Unlock we often branch to DONE_LABEL, just to find that C2
2970   //    will emit a conditional branch immediately after the node.
2971   //    So we have branches to branches and lots of ICC.ZF games.
2972   //    Instead, it might be better to have C2 pass a "FailureLabel"
2973   //    into Fast_Lock and Fast_Unlock.  In the case of success, control
2974   //    will drop through the node.  ICC.ZF is undefined at exit.
2975   //    In the case of failure, the node will branch directly to the
2976   //    FailureLabel
2977 
2978 
2979   // obj: object to lock
2980   // box: on-stack box address (displaced header location) - KILLED
2981   // rax,: tmp -- KILLED
2982   // scr: tmp -- KILLED
2983   enc_class Fast_Lock( eRegP obj, eRegP box, eAXRegI tmp, eRegP scr ) %{
2984 
2985     Register objReg = as_Register($obj$$reg);
2986     Register boxReg = as_Register($box$$reg);
2987     Register tmpReg = as_Register($tmp$$reg);
2988     Register scrReg = as_Register($scr$$reg);
2989 
2990     // Ensure the register assignents are disjoint
2991     guarantee (objReg != boxReg, "") ;
2992     guarantee (objReg != tmpReg, "") ;
2993     guarantee (objReg != scrReg, "") ;
2994     guarantee (boxReg != tmpReg, "") ;
2995     guarantee (boxReg != scrReg, "") ;
2996     guarantee (tmpReg == as_Register(EAX_enc), "") ;
2997 
2998     MacroAssembler masm(&cbuf);
2999 
3000     if (_counters != NULL) {
3001       masm.atomic_incl(ExternalAddress((address) _counters->total_entry_count_addr()));
3002     }
3003     if (EmitSync & 1) {
3004         // set box->dhw = unused_mark (3)
3005         // Force all sync thru slow-path: slow_enter() and slow_exit() 
3006         masm.movptr (Address(boxReg, 0), int32_t(markOopDesc::unused_mark())) ;             
3007         masm.cmpptr (rsp, (int32_t)0) ;                        
3008     } else 
3009     if (EmitSync & 2) { 
3010         Label DONE_LABEL ;           
3011         if (UseBiasedLocking) {
3012            // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument.
3013            masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
3014         }
3015 
3016         masm.movptr(tmpReg, Address(objReg, 0)) ;          // fetch markword 
3017         masm.orptr (tmpReg, 0x1);
3018         masm.movptr(Address(boxReg, 0), tmpReg);           // Anticipate successful CAS 
3019         if (os::is_MP()) { masm.lock();  }
3020         masm.cmpxchgptr(boxReg, Address(objReg, 0));          // Updates tmpReg
3021         masm.jcc(Assembler::equal, DONE_LABEL);
3022         // Recursive locking
3023         masm.subptr(tmpReg, rsp);
3024         masm.andptr(tmpReg, (int32_t) 0xFFFFF003 );
3025         masm.movptr(Address(boxReg, 0), tmpReg);
3026         masm.bind(DONE_LABEL) ; 
3027     } else {  
3028       // Possible cases that we'll encounter in fast_lock 
3029       // ------------------------------------------------
3030       // * Inflated
3031       //    -- unlocked
3032       //    -- Locked
3033       //       = by self
3034       //       = by other
3035       // * biased
3036       //    -- by Self
3037       //    -- by other
3038       // * neutral
3039       // * stack-locked
3040       //    -- by self
3041       //       = sp-proximity test hits
3042       //       = sp-proximity test generates false-negative
3043       //    -- by other
3044       //
3045 
3046       Label IsInflated, DONE_LABEL, PopDone ;
3047 
3048       // TODO: optimize away redundant LDs of obj->mark and improve the markword triage
3049       // order to reduce the number of conditional branches in the most common cases.
3050       // Beware -- there's a subtle invariant that fetch of the markword
3051       // at [FETCH], below, will never observe a biased encoding (*101b).
3052       // If this invariant is not held we risk exclusion (safety) failure.
3053       if (UseBiasedLocking && !UseOptoBiasInlining) {
3054         masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
3055       }
3056 
3057       masm.movptr(tmpReg, Address(objReg, 0)) ;         // [FETCH]
3058       masm.testptr(tmpReg, 0x02) ;                      // Inflated v (Stack-locked or neutral)
3059       masm.jccb  (Assembler::notZero, IsInflated) ;
3060 
3061       // Attempt stack-locking ...
3062       masm.orptr (tmpReg, 0x1);
3063       masm.movptr(Address(boxReg, 0), tmpReg);          // Anticipate successful CAS
3064       if (os::is_MP()) { masm.lock();  }
3065       masm.cmpxchgptr(boxReg, Address(objReg, 0));           // Updates tmpReg
3066       if (_counters != NULL) {
3067         masm.cond_inc32(Assembler::equal,
3068                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
3069       }
3070       masm.jccb (Assembler::equal, DONE_LABEL);
3071 
3072       // Recursive locking
3073       masm.subptr(tmpReg, rsp);
3074       masm.andptr(tmpReg, 0xFFFFF003 );
3075       masm.movptr(Address(boxReg, 0), tmpReg);
3076       if (_counters != NULL) {
3077         masm.cond_inc32(Assembler::equal,
3078                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
3079       }
3080       masm.jmp  (DONE_LABEL) ;
3081 
3082       masm.bind (IsInflated) ;
3083 
3084       // The object is inflated.
3085       //
3086       // TODO-FIXME: eliminate the ugly use of manifest constants:
3087       //   Use markOopDesc::monitor_value instead of "2".
3088       //   use markOop::unused_mark() instead of "3".
3089       // The tmpReg value is an objectMonitor reference ORed with
3090       // markOopDesc::monitor_value (2).   We can either convert tmpReg to an
3091       // objectmonitor pointer by masking off the "2" bit or we can just
3092       // use tmpReg as an objectmonitor pointer but bias the objectmonitor
3093       // field offsets with "-2" to compensate for and annul the low-order tag bit.
3094       //
3095       // I use the latter as it avoids AGI stalls.
3096       // As such, we write "mov r, [tmpReg+OFFSETOF(Owner)-2]"
3097       // instead of "mov r, [tmpReg+OFFSETOF(Owner)]".
3098       //
3099       #define OFFSET_SKEWED(f) ((ObjectMonitor::f ## _offset_in_bytes())-2)
3100 
3101       // boxReg refers to the on-stack BasicLock in the current frame.
3102       // We'd like to write:
3103       //   set box->_displaced_header = markOop::unused_mark().  Any non-0 value suffices.
3104       // This is convenient but results a ST-before-CAS penalty.  The following CAS suffers
3105       // additional latency as we have another ST in the store buffer that must drain.
3106 
3107       if (EmitSync & 8192) { 
3108          masm.movptr(Address(boxReg, 0), 3) ;            // results in ST-before-CAS penalty
3109          masm.get_thread (scrReg) ; 
3110          masm.movptr(boxReg, tmpReg);                    // consider: LEA box, [tmp-2] 
3111          masm.movptr(tmpReg, NULL_WORD);                 // consider: xor vs mov
3112          if (os::is_MP()) { masm.lock(); } 
3113          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
3114       } else 
3115       if ((EmitSync & 128) == 0) {                      // avoid ST-before-CAS
3116          masm.movptr(scrReg, boxReg) ; 
3117          masm.movptr(boxReg, tmpReg);                   // consider: LEA box, [tmp-2] 
3118 
3119          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
3120          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
3121             // prefetchw [eax + Offset(_owner)-2]
3122             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
3123          }
3124 
3125          if ((EmitSync & 64) == 0) {
3126            // Optimistic form: consider XORL tmpReg,tmpReg
3127            masm.movptr(tmpReg, NULL_WORD) ; 
3128          } else { 
3129            // Can suffer RTS->RTO upgrades on shared or cold $ lines
3130            // Test-And-CAS instead of CAS
3131            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
3132            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
3133            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
3134          }
3135 
3136          // Appears unlocked - try to swing _owner from null to non-null.
3137          // Ideally, I'd manifest "Self" with get_thread and then attempt
3138          // to CAS the register containing Self into m->Owner.
3139          // But we don't have enough registers, so instead we can either try to CAS
3140          // rsp or the address of the box (in scr) into &m->owner.  If the CAS succeeds
3141          // we later store "Self" into m->Owner.  Transiently storing a stack address
3142          // (rsp or the address of the box) into  m->owner is harmless.
3143          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
3144          if (os::is_MP()) { masm.lock();  }
3145          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
3146          masm.movptr(Address(scrReg, 0), 3) ;          // box->_displaced_header = 3
3147          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
3148          masm.get_thread (scrReg) ;                    // beware: clobbers ICCs
3149          masm.movptr(Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2), scrReg) ; 
3150          masm.xorptr(boxReg, boxReg) ;                 // set icc.ZFlag = 1 to indicate success
3151                        
3152          // If the CAS fails we can either retry or pass control to the slow-path.  
3153          // We use the latter tactic.  
3154          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
3155          // If the CAS was successful ...
3156          //   Self has acquired the lock
3157          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
3158          // Intentional fall-through into DONE_LABEL ...
3159       } else {
3160          masm.movptr(Address(boxReg, 0), 3) ;       // results in ST-before-CAS penalty
3161          masm.movptr(boxReg, tmpReg) ; 
3162 
3163          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
3164          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
3165             // prefetchw [eax + Offset(_owner)-2]
3166             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
3167          }
3168 
3169          if ((EmitSync & 64) == 0) {
3170            // Optimistic form
3171            masm.xorptr  (tmpReg, tmpReg) ; 
3172          } else { 
3173            // Can suffer RTS->RTO upgrades on shared or cold $ lines
3174            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
3175            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
3176            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
3177          }
3178 
3179          // Appears unlocked - try to swing _owner from null to non-null.
3180          // Use either "Self" (in scr) or rsp as thread identity in _owner.
3181          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
3182          masm.get_thread (scrReg) ;
3183          if (os::is_MP()) { masm.lock(); }
3184          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
3185 
3186          // If the CAS fails we can either retry or pass control to the slow-path.
3187          // We use the latter tactic.
3188          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
3189          // If the CAS was successful ...
3190          //   Self has acquired the lock
3191          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
3192          // Intentional fall-through into DONE_LABEL ...
3193       }
3194 
3195       // DONE_LABEL is a hot target - we'd really like to place it at the
3196       // start of cache line by padding with NOPs.
3197       // See the AMD and Intel software optimization manuals for the
3198       // most efficient "long" NOP encodings.
3199       // Unfortunately none of our alignment mechanisms suffice.
3200       masm.bind(DONE_LABEL);
3201 
3202       // Avoid branch-to-branch on AMD processors
3203       // This appears to be superstition.
3204       if (EmitSync & 32) masm.nop() ;
3205 
3206 
3207       // At DONE_LABEL the icc ZFlag is set as follows ...
3208       // Fast_Unlock uses the same protocol.
3209       // ZFlag == 1 -> Success
3210       // ZFlag == 0 -> Failure - force control through the slow-path
3211     }
3212   %}
3213 
3214   // obj: object to unlock
3215   // box: box address (displaced header location), killed.  Must be EAX.
3216   // rbx,: killed tmp; cannot be obj nor box.
3217   //
3218   // Some commentary on balanced locking:
3219   //
3220   // Fast_Lock and Fast_Unlock are emitted only for provably balanced lock sites.
3221   // Methods that don't have provably balanced locking are forced to run in the
3222   // interpreter - such methods won't be compiled to use fast_lock and fast_unlock.
3223   // The interpreter provides two properties:
3224   // I1:  At return-time the interpreter automatically and quietly unlocks any
3225   //      objects acquired the current activation (frame).  Recall that the
3226   //      interpreter maintains an on-stack list of locks currently held by
3227   //      a frame.
3228   // I2:  If a method attempts to unlock an object that is not held by the
3229   //      the frame the interpreter throws IMSX.
3230   //
3231   // Lets say A(), which has provably balanced locking, acquires O and then calls B().
3232   // B() doesn't have provably balanced locking so it runs in the interpreter.
3233   // Control returns to A() and A() unlocks O.  By I1 and I2, above, we know that O
3234   // is still locked by A().
3235   //
3236   // The only other source of unbalanced locking would be JNI.  The "Java Native Interface:
3237   // Programmer's Guide and Specification" claims that an object locked by jni_monitorenter
3238   // should not be unlocked by "normal" java-level locking and vice-versa.  The specification
3239   // doesn't specify what will occur if a program engages in such mixed-mode locking, however.
3240 
3241   enc_class Fast_Unlock( nabxRegP obj, eAXRegP box, eRegP tmp) %{
3242 
3243     Register objReg = as_Register($obj$$reg);
3244     Register boxReg = as_Register($box$$reg);
3245     Register tmpReg = as_Register($tmp$$reg);
3246 
3247     guarantee (objReg != boxReg, "") ;
3248     guarantee (objReg != tmpReg, "") ;
3249     guarantee (boxReg != tmpReg, "") ;
3250     guarantee (boxReg == as_Register(EAX_enc), "") ;
3251     MacroAssembler masm(&cbuf);
3252 
3253     if (EmitSync & 4) {
3254       // Disable - inhibit all inlining.  Force control through the slow-path
3255       masm.cmpptr (rsp, 0) ; 
3256     } else 
3257     if (EmitSync & 8) {
3258       Label DONE_LABEL ;
3259       if (UseBiasedLocking) {
3260          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
3261       }
3262       // classic stack-locking code ...
3263       masm.movptr(tmpReg, Address(boxReg, 0)) ;
3264       masm.testptr(tmpReg, tmpReg) ;
3265       masm.jcc   (Assembler::zero, DONE_LABEL) ;
3266       if (os::is_MP()) { masm.lock(); }
3267       masm.cmpxchgptr(tmpReg, Address(objReg, 0));          // Uses EAX which is box
3268       masm.bind(DONE_LABEL);
3269     } else {
3270       Label DONE_LABEL, Stacked, CheckSucc, Inflated ;
3271 
3272       // Critically, the biased locking test must have precedence over
3273       // and appear before the (box->dhw == 0) recursive stack-lock test.
3274       if (UseBiasedLocking && !UseOptoBiasInlining) {
3275          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
3276       }
3277       
3278       masm.cmpptr(Address(boxReg, 0), 0) ;            // Examine the displaced header
3279       masm.movptr(tmpReg, Address(objReg, 0)) ;       // Examine the object's markword
3280       masm.jccb  (Assembler::zero, DONE_LABEL) ;      // 0 indicates recursive stack-lock
3281 
3282       masm.testptr(tmpReg, 0x02) ;                     // Inflated? 
3283       masm.jccb  (Assembler::zero, Stacked) ;
3284 
3285       masm.bind  (Inflated) ;
3286       // It's inflated.
3287       // Despite our balanced locking property we still check that m->_owner == Self
3288       // as java routines or native JNI code called by this thread might
3289       // have released the lock.
3290       // Refer to the comments in synchronizer.cpp for how we might encode extra
3291       // state in _succ so we can avoid fetching EntryList|cxq.
3292       //
3293       // I'd like to add more cases in fast_lock() and fast_unlock() --
3294       // such as recursive enter and exit -- but we have to be wary of
3295       // I$ bloat, T$ effects and BP$ effects.
3296       //
3297       // If there's no contention try a 1-0 exit.  That is, exit without
3298       // a costly MEMBAR or CAS.  See synchronizer.cpp for details on how
3299       // we detect and recover from the race that the 1-0 exit admits.
3300       //
3301       // Conceptually Fast_Unlock() must execute a STST|LDST "release" barrier
3302       // before it STs null into _owner, releasing the lock.  Updates
3303       // to data protected by the critical section must be visible before
3304       // we drop the lock (and thus before any other thread could acquire
3305       // the lock and observe the fields protected by the lock).
3306       // IA32's memory-model is SPO, so STs are ordered with respect to
3307       // each other and there's no need for an explicit barrier (fence).
3308       // See also http://gee.cs.oswego.edu/dl/jmm/cookbook.html.
3309 
3310       masm.get_thread (boxReg) ;
3311       if ((EmitSync & 4096) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
3312         // prefetchw [ebx + Offset(_owner)-2]
3313         masm.prefetchw(Address(rbx, ObjectMonitor::owner_offset_in_bytes()-2));
3314       }
3315 
3316       // Note that we could employ various encoding schemes to reduce
3317       // the number of loads below (currently 4) to just 2 or 3.
3318       // Refer to the comments in synchronizer.cpp.
3319       // In practice the chain of fetches doesn't seem to impact performance, however.
3320       if ((EmitSync & 65536) == 0 && (EmitSync & 256)) {
3321          // Attempt to reduce branch density - AMD's branch predictor.
3322          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
3323          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
3324          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
3325          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
3326          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
3327          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
3328          masm.jmpb  (DONE_LABEL) ; 
3329       } else { 
3330          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
3331          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
3332          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
3333          masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
3334          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
3335          masm.jccb  (Assembler::notZero, CheckSucc) ; 
3336          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
3337          masm.jmpb  (DONE_LABEL) ; 
3338       }
3339 
3340       // The Following code fragment (EmitSync & 65536) improves the performance of
3341       // contended applications and contended synchronization microbenchmarks.
3342       // Unfortunately the emission of the code - even though not executed - causes regressions
3343       // in scimark and jetstream, evidently because of $ effects.  Replacing the code
3344       // with an equal number of never-executed NOPs results in the same regression.
3345       // We leave it off by default.
3346 
3347       if ((EmitSync & 65536) != 0) {
3348          Label LSuccess, LGoSlowPath ;
3349 
3350          masm.bind  (CheckSucc) ;
3351 
3352          // Optional pre-test ... it's safe to elide this
3353          if ((EmitSync & 16) == 0) { 
3354             masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
3355             masm.jccb  (Assembler::zero, LGoSlowPath) ; 
3356          }
3357 
3358          // We have a classic Dekker-style idiom:
3359          //    ST m->_owner = 0 ; MEMBAR; LD m->_succ
3360          // There are a number of ways to implement the barrier:
3361          // (1) lock:andl &m->_owner, 0
3362          //     is fast, but mask doesn't currently support the "ANDL M,IMM32" form.
3363          //     LOCK: ANDL [ebx+Offset(_Owner)-2], 0
3364          //     Encodes as 81 31 OFF32 IMM32 or 83 63 OFF8 IMM8
3365          // (2) If supported, an explicit MFENCE is appealing.
3366          //     In older IA32 processors MFENCE is slower than lock:add or xchg
3367          //     particularly if the write-buffer is full as might be the case if
3368          //     if stores closely precede the fence or fence-equivalent instruction.
3369          //     In more modern implementations MFENCE appears faster, however.
3370          // (3) In lieu of an explicit fence, use lock:addl to the top-of-stack
3371          //     The $lines underlying the top-of-stack should be in M-state.
3372          //     The locked add instruction is serializing, of course.
3373          // (4) Use xchg, which is serializing
3374          //     mov boxReg, 0; xchgl boxReg, [tmpReg + Offset(_owner)-2] also works
3375          // (5) ST m->_owner = 0 and then execute lock:orl &m->_succ, 0.
3376          //     The integer condition codes will tell us if succ was 0.
3377          //     Since _succ and _owner should reside in the same $line and
3378          //     we just stored into _owner, it's likely that the $line
3379          //     remains in M-state for the lock:orl.
3380          //
3381          // We currently use (3), although it's likely that switching to (2)
3382          // is correct for the future.
3383             
3384          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
3385          if (os::is_MP()) { 
3386             if (VM_Version::supports_sse2() && 1 == FenceInstruction) { 
3387               masm.mfence();
3388             } else { 
3389               masm.lock () ; masm.addptr(Address(rsp, 0), 0) ; 
3390             }
3391          }
3392          // Ratify _succ remains non-null
3393          masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
3394          masm.jccb  (Assembler::notZero, LSuccess) ; 
3395 
3396          masm.xorptr(boxReg, boxReg) ;                  // box is really EAX
3397          if (os::is_MP()) { masm.lock(); }
3398          masm.cmpxchgptr(rsp, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2));
3399          masm.jccb  (Assembler::notEqual, LSuccess) ;
3400          // Since we're low on registers we installed rsp as a placeholding in _owner.
3401          // Now install Self over rsp.  This is safe as we're transitioning from
3402          // non-null to non=null
3403          masm.get_thread (boxReg) ;
3404          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), boxReg) ;
3405          // Intentional fall-through into LGoSlowPath ...
3406 
3407          masm.bind  (LGoSlowPath) ; 
3408          masm.orptr(boxReg, 1) ;                      // set ICC.ZF=0 to indicate failure
3409          masm.jmpb  (DONE_LABEL) ; 
3410 
3411          masm.bind  (LSuccess) ; 
3412          masm.xorptr(boxReg, boxReg) ;                 // set ICC.ZF=1 to indicate success
3413          masm.jmpb  (DONE_LABEL) ; 
3414       }
3415 
3416       masm.bind (Stacked) ;
3417       // It's not inflated and it's not recursively stack-locked and it's not biased.
3418       // It must be stack-locked.
3419       // Try to reset the header to displaced header.
3420       // The "box" value on the stack is stable, so we can reload
3421       // and be assured we observe the same value as above.
3422       masm.movptr(tmpReg, Address(boxReg, 0)) ;
3423       if (os::is_MP()) {   masm.lock();    }
3424       masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses EAX which is box
3425       // Intention fall-thru into DONE_LABEL
3426 
3427 
3428       // DONE_LABEL is a hot target - we'd really like to place it at the
3429       // start of cache line by padding with NOPs.
3430       // See the AMD and Intel software optimization manuals for the
3431       // most efficient "long" NOP encodings.
3432       // Unfortunately none of our alignment mechanisms suffice.
3433       if ((EmitSync & 65536) == 0) {
3434          masm.bind (CheckSucc) ;
3435       }
3436       masm.bind(DONE_LABEL);
3437 
3438       // Avoid branch to branch on AMD processors
3439       if (EmitSync & 32768) { masm.nop() ; }
3440     }
3441   %}
3442 
3443 
3444   enc_class enc_pop_rdx() %{
3445     emit_opcode(cbuf,0x5A);
3446   %}
3447 
3448   enc_class enc_rethrow() %{
3449     cbuf.set_insts_mark();
3450     emit_opcode(cbuf, 0xE9);        // jmp    entry
3451     emit_d32_reloc(cbuf, (int)OptoRuntime::rethrow_stub() - ((int)cbuf.insts_end())-4,
3452                    runtime_call_Relocation::spec(), RELOC_IMM32 );
3453   %}
3454 
3455 
3456   // Convert a double to an int.  Java semantics require we do complex
3457   // manglelations in the corner cases.  So we set the rounding mode to
3458   // 'zero', store the darned double down as an int, and reset the
3459   // rounding mode to 'nearest'.  The hardware throws an exception which
3460   // patches up the correct value directly to the stack.
3461   enc_class DPR2I_encoding( regDPR src ) %{
3462     // Flip to round-to-zero mode.  We attempted to allow invalid-op
3463     // exceptions here, so that a NAN or other corner-case value will
3464     // thrown an exception (but normal values get converted at full speed).
3465     // However, I2C adapters and other float-stack manglers leave pending
3466     // invalid-op exceptions hanging.  We would have to clear them before
3467     // enabling them and that is more expensive than just testing for the
3468     // invalid value Intel stores down in the corner cases.
3469     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
3470     emit_opcode(cbuf,0x2D);
3471     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
3472     // Allocate a word
3473     emit_opcode(cbuf,0x83);            // SUB ESP,4
3474     emit_opcode(cbuf,0xEC);
3475     emit_d8(cbuf,0x04);
3476     // Encoding assumes a double has been pushed into FPR0.
3477     // Store down the double as an int, popping the FPU stack
3478     emit_opcode(cbuf,0xDB);            // FISTP [ESP]
3479     emit_opcode(cbuf,0x1C);
3480     emit_d8(cbuf,0x24);
3481     // Restore the rounding mode; mask the exception
3482     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
3483     emit_opcode(cbuf,0x2D);
3484     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
3485         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
3486         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
3487 
3488     // Load the converted int; adjust CPU stack
3489     emit_opcode(cbuf,0x58);       // POP EAX
3490     emit_opcode(cbuf,0x3D);       // CMP EAX,imm
3491     emit_d32   (cbuf,0x80000000); //         0x80000000
3492     emit_opcode(cbuf,0x75);       // JNE around_slow_call
3493     emit_d8    (cbuf,0x07);       // Size of slow_call
3494     // Push src onto stack slow-path
3495     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
3496     emit_d8    (cbuf,0xC0-1+$src$$reg );
3497     // CALL directly to the runtime
3498     cbuf.set_insts_mark();
3499     emit_opcode(cbuf,0xE8);       // Call into runtime
3500     emit_d32_reloc(cbuf, (StubRoutines::d2i_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
3501     // Carry on here...
3502   %}
3503 
3504   enc_class DPR2L_encoding( regDPR src ) %{
3505     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
3506     emit_opcode(cbuf,0x2D);
3507     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
3508     // Allocate a word
3509     emit_opcode(cbuf,0x83);            // SUB ESP,8
3510     emit_opcode(cbuf,0xEC);
3511     emit_d8(cbuf,0x08);
3512     // Encoding assumes a double has been pushed into FPR0.
3513     // Store down the double as a long, popping the FPU stack
3514     emit_opcode(cbuf,0xDF);            // FISTP [ESP]
3515     emit_opcode(cbuf,0x3C);
3516     emit_d8(cbuf,0x24);
3517     // Restore the rounding mode; mask the exception
3518     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
3519     emit_opcode(cbuf,0x2D);
3520     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
3521         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
3522         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
3523 
3524     // Load the converted int; adjust CPU stack
3525     emit_opcode(cbuf,0x58);       // POP EAX
3526     emit_opcode(cbuf,0x5A);       // POP EDX
3527     emit_opcode(cbuf,0x81);       // CMP EDX,imm
3528     emit_d8    (cbuf,0xFA);       // rdx
3529     emit_d32   (cbuf,0x80000000); //         0x80000000
3530     emit_opcode(cbuf,0x75);       // JNE around_slow_call
3531     emit_d8    (cbuf,0x07+4);     // Size of slow_call
3532     emit_opcode(cbuf,0x85);       // TEST EAX,EAX
3533     emit_opcode(cbuf,0xC0);       // 2/rax,/rax,
3534     emit_opcode(cbuf,0x75);       // JNE around_slow_call
3535     emit_d8    (cbuf,0x07);       // Size of slow_call
3536     // Push src onto stack slow-path
3537     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
3538     emit_d8    (cbuf,0xC0-1+$src$$reg );
3539     // CALL directly to the runtime
3540     cbuf.set_insts_mark();
3541     emit_opcode(cbuf,0xE8);       // Call into runtime
3542     emit_d32_reloc(cbuf, (StubRoutines::d2l_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
3543     // Carry on here...
3544   %}
3545 
3546   enc_class FMul_ST_reg( eRegFPR src1 ) %{
3547     // Operand was loaded from memory into fp ST (stack top)
3548     // FMUL   ST,$src  /* D8 C8+i */
3549     emit_opcode(cbuf, 0xD8);
3550     emit_opcode(cbuf, 0xC8 + $src1$$reg);
3551   %}
3552 
3553   enc_class FAdd_ST_reg( eRegFPR src2 ) %{
3554     // FADDP  ST,src2  /* D8 C0+i */
3555     emit_opcode(cbuf, 0xD8);
3556     emit_opcode(cbuf, 0xC0 + $src2$$reg);
3557     //could use FADDP  src2,fpST  /* DE C0+i */
3558   %}
3559 
3560   enc_class FAddP_reg_ST( eRegFPR src2 ) %{
3561     // FADDP  src2,ST  /* DE C0+i */
3562     emit_opcode(cbuf, 0xDE);
3563     emit_opcode(cbuf, 0xC0 + $src2$$reg);
3564   %}
3565 
3566   enc_class subFPR_divFPR_encode( eRegFPR src1, eRegFPR src2) %{
3567     // Operand has been loaded into fp ST (stack top)
3568       // FSUB   ST,$src1
3569       emit_opcode(cbuf, 0xD8);
3570       emit_opcode(cbuf, 0xE0 + $src1$$reg);
3571 
3572       // FDIV
3573       emit_opcode(cbuf, 0xD8);
3574       emit_opcode(cbuf, 0xF0 + $src2$$reg);
3575   %}
3576 
3577   enc_class MulFAddF (eRegFPR src1, eRegFPR src2) %{
3578     // Operand was loaded from memory into fp ST (stack top)
3579     // FADD   ST,$src  /* D8 C0+i */
3580     emit_opcode(cbuf, 0xD8);
3581     emit_opcode(cbuf, 0xC0 + $src1$$reg);
3582 
3583     // FMUL  ST,src2  /* D8 C*+i */
3584     emit_opcode(cbuf, 0xD8);
3585     emit_opcode(cbuf, 0xC8 + $src2$$reg);
3586   %}
3587 
3588 
3589   enc_class MulFAddFreverse (eRegFPR src1, eRegFPR src2) %{
3590     // Operand was loaded from memory into fp ST (stack top)
3591     // FADD   ST,$src  /* D8 C0+i */
3592     emit_opcode(cbuf, 0xD8);
3593     emit_opcode(cbuf, 0xC0 + $src1$$reg);
3594 
3595     // FMULP  src2,ST  /* DE C8+i */
3596     emit_opcode(cbuf, 0xDE);
3597     emit_opcode(cbuf, 0xC8 + $src2$$reg);
3598   %}
3599 
3600   // Atomically load the volatile long
3601   enc_class enc_loadL_volatile( memory mem, stackSlotL dst ) %{
3602     emit_opcode(cbuf,0xDF);
3603     int rm_byte_opcode = 0x05;
3604     int base     = $mem$$base;
3605     int index    = $mem$$index;
3606     int scale    = $mem$$scale;
3607     int displace = $mem$$disp;
3608     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
3609     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
3610     store_to_stackslot( cbuf, 0x0DF, 0x07, $dst$$disp );
3611   %}
3612 
3613   // Volatile Store Long.  Must be atomic, so move it into
3614   // the FP TOS and then do a 64-bit FIST.  Has to probe the
3615   // target address before the store (for null-ptr checks)
3616   // so the memory operand is used twice in the encoding.
3617   enc_class enc_storeL_volatile( memory mem, stackSlotL src ) %{
3618     store_to_stackslot( cbuf, 0x0DF, 0x05, $src$$disp );
3619     cbuf.set_insts_mark();            // Mark start of FIST in case $mem has an oop
3620     emit_opcode(cbuf,0xDF);
3621     int rm_byte_opcode = 0x07;
3622     int base     = $mem$$base;
3623     int index    = $mem$$index;
3624     int scale    = $mem$$scale;
3625     int displace = $mem$$disp;
3626     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
3627     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
3628   %}
3629 
3630   // Safepoint Poll.  This polls the safepoint page, and causes an
3631   // exception if it is not readable. Unfortunately, it kills the condition code
3632   // in the process
3633   // We current use TESTL [spp],EDI
3634   // A better choice might be TESTB [spp + pagesize() - CacheLineSize()],0
3635 
3636   enc_class Safepoint_Poll() %{
3637     cbuf.relocate(cbuf.insts_mark(), relocInfo::poll_type, 0);
3638     emit_opcode(cbuf,0x85);
3639     emit_rm (cbuf, 0x0, 0x7, 0x5);
3640     emit_d32(cbuf, (intptr_t)os::get_polling_page());
3641   %}
3642 %}
3643 
3644 
3645 //----------FRAME--------------------------------------------------------------
3646 // Definition of frame structure and management information.
3647 //
3648 //  S T A C K   L A Y O U T    Allocators stack-slot number
3649 //                             |   (to get allocators register number
3650 //  G  Owned by    |        |  v    add OptoReg::stack0())
3651 //  r   CALLER     |        |
3652 //  o     |        +--------+      pad to even-align allocators stack-slot
3653 //  w     V        |  pad0  |        numbers; owned by CALLER
3654 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
3655 //  h     ^        |   in   |  5
3656 //        |        |  args  |  4   Holes in incoming args owned by SELF
3657 //  |     |        |        |  3
3658 //  |     |        +--------+
3659 //  V     |        | old out|      Empty on Intel, window on Sparc
3660 //        |    old |preserve|      Must be even aligned.
3661 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
3662 //        |        |   in   |  3   area for Intel ret address
3663 //     Owned by    |preserve|      Empty on Sparc.
3664 //       SELF      +--------+
3665 //        |        |  pad2  |  2   pad to align old SP
3666 //        |        +--------+  1
3667 //        |        | locks  |  0
3668 //        |        +--------+----> OptoReg::stack0(), even aligned
3669 //        |        |  pad1  | 11   pad to align new SP
3670 //        |        +--------+
3671 //        |        |        | 10
3672 //        |        | spills |  9   spills
3673 //        V        |        |  8   (pad0 slot for callee)
3674 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
3675 //        ^        |  out   |  7
3676 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
3677 //     Owned by    +--------+
3678 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
3679 //        |    new |preserve|      Must be even-aligned.
3680 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
3681 //        |        |        |
3682 //
3683 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
3684 //         known from SELF's arguments and the Java calling convention.
3685 //         Region 6-7 is determined per call site.
3686 // Note 2: If the calling convention leaves holes in the incoming argument
3687 //         area, those holes are owned by SELF.  Holes in the outgoing area
3688 //         are owned by the CALLEE.  Holes should not be nessecary in the
3689 //         incoming area, as the Java calling convention is completely under
3690 //         the control of the AD file.  Doubles can be sorted and packed to
3691 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
3692 //         varargs C calling conventions.
3693 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
3694 //         even aligned with pad0 as needed.
3695 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
3696 //         region 6-11 is even aligned; it may be padded out more so that
3697 //         the region from SP to FP meets the minimum stack alignment.
3698 
3699 frame %{
3700   // What direction does stack grow in (assumed to be same for C & Java)
3701   stack_direction(TOWARDS_LOW);
3702 
3703   // These three registers define part of the calling convention
3704   // between compiled code and the interpreter.
3705   inline_cache_reg(EAX);                // Inline Cache Register
3706   interpreter_method_oop_reg(EBX);      // Method Oop Register when calling interpreter
3707 
3708   // Optional: name the operand used by cisc-spilling to access [stack_pointer + offset]
3709   cisc_spilling_operand_name(indOffset32);
3710 
3711   // Number of stack slots consumed by locking an object
3712   sync_stack_slots(1);
3713 
3714   // Compiled code's Frame Pointer
3715   frame_pointer(ESP);
3716   // Interpreter stores its frame pointer in a register which is
3717   // stored to the stack by I2CAdaptors.
3718   // I2CAdaptors convert from interpreted java to compiled java.
3719   interpreter_frame_pointer(EBP);
3720 
3721   // Stack alignment requirement
3722   // Alignment size in bytes (128-bit -> 16 bytes)
3723   stack_alignment(StackAlignmentInBytes);
3724 
3725   // Number of stack slots between incoming argument block and the start of
3726   // a new frame.  The PROLOG must add this many slots to the stack.  The
3727   // EPILOG must remove this many slots.  Intel needs one slot for
3728   // return address and one for rbp, (must save rbp)
3729   in_preserve_stack_slots(2+VerifyStackAtCalls);
3730 
3731   // Number of outgoing stack slots killed above the out_preserve_stack_slots
3732   // for calls to C.  Supports the var-args backing area for register parms.
3733   varargs_C_out_slots_killed(0);
3734 
3735   // The after-PROLOG location of the return address.  Location of
3736   // return address specifies a type (REG or STACK) and a number
3737   // representing the register number (i.e. - use a register name) or
3738   // stack slot.
3739   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
3740   // Otherwise, it is above the locks and verification slot and alignment word
3741   return_addr(STACK - 1 +
3742               round_to((Compile::current()->in_preserve_stack_slots() +
3743                         Compile::current()->fixed_slots()),
3744                        stack_alignment_in_slots()));
3745 
3746   // Body of function which returns an integer array locating
3747   // arguments either in registers or in stack slots.  Passed an array
3748   // of ideal registers called "sig" and a "length" count.  Stack-slot
3749   // offsets are based on outgoing arguments, i.e. a CALLER setting up
3750   // arguments for a CALLEE.  Incoming stack arguments are
3751   // automatically biased by the preserve_stack_slots field above.
3752   calling_convention %{
3753     // No difference between ingoing/outgoing just pass false
3754     SharedRuntime::java_calling_convention(sig_bt, regs, length, false);
3755   %}
3756 
3757 
3758   // Body of function which returns an integer array locating
3759   // arguments either in registers or in stack slots.  Passed an array
3760   // of ideal registers called "sig" and a "length" count.  Stack-slot
3761   // offsets are based on outgoing arguments, i.e. a CALLER setting up
3762   // arguments for a CALLEE.  Incoming stack arguments are
3763   // automatically biased by the preserve_stack_slots field above.
3764   c_calling_convention %{
3765     // This is obviously always outgoing
3766     (void) SharedRuntime::c_calling_convention(sig_bt, regs, /*regs2=*/NULL, length);
3767   %}
3768 
3769   // Location of C & interpreter return values
3770   c_return_value %{
3771     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
3772     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
3773     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
3774 
3775     // in SSE2+ mode we want to keep the FPU stack clean so pretend
3776     // that C functions return float and double results in XMM0.
3777     if( ideal_reg == Op_RegD && UseSSE>=2 )
3778       return OptoRegPair(XMM0b_num,XMM0_num);
3779     if( ideal_reg == Op_RegF && UseSSE>=2 )
3780       return OptoRegPair(OptoReg::Bad,XMM0_num);
3781 
3782     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
3783   %}
3784 
3785   // Location of return values
3786   return_value %{
3787     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
3788     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
3789     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
3790     if( ideal_reg == Op_RegD && UseSSE>=2 )
3791       return OptoRegPair(XMM0b_num,XMM0_num);
3792     if( ideal_reg == Op_RegF && UseSSE>=1 )
3793       return OptoRegPair(OptoReg::Bad,XMM0_num);
3794     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
3795   %}
3796 
3797 %}
3798 
3799 //----------ATTRIBUTES---------------------------------------------------------
3800 //----------Operand Attributes-------------------------------------------------
3801 op_attrib op_cost(0);        // Required cost attribute
3802 
3803 //----------Instruction Attributes---------------------------------------------
3804 ins_attrib ins_cost(100);       // Required cost attribute
3805 ins_attrib ins_size(8);         // Required size attribute (in bits)
3806 ins_attrib ins_short_branch(0); // Required flag: is this instruction a
3807                                 // non-matching short branch variant of some
3808                                                             // long branch?
3809 ins_attrib ins_alignment(1);    // Required alignment attribute (must be a power of 2)
3810                                 // specifies the alignment that some part of the instruction (not
3811                                 // necessarily the start) requires.  If > 1, a compute_padding()
3812                                 // function must be provided for the instruction
3813 
3814 //----------OPERANDS-----------------------------------------------------------
3815 // Operand definitions must precede instruction definitions for correct parsing
3816 // in the ADLC because operands constitute user defined types which are used in
3817 // instruction definitions.
3818 
3819 //----------Simple Operands----------------------------------------------------
3820 // Immediate Operands
3821 // Integer Immediate
3822 operand immI() %{
3823   match(ConI);
3824 
3825   op_cost(10);
3826   format %{ %}
3827   interface(CONST_INTER);
3828 %}
3829 
3830 // Constant for test vs zero
3831 operand immI0() %{
3832   predicate(n->get_int() == 0);
3833   match(ConI);
3834 
3835   op_cost(0);
3836   format %{ %}
3837   interface(CONST_INTER);
3838 %}
3839 
3840 // Constant for increment
3841 operand immI1() %{
3842   predicate(n->get_int() == 1);
3843   match(ConI);
3844 
3845   op_cost(0);
3846   format %{ %}
3847   interface(CONST_INTER);
3848 %}
3849 
3850 // Constant for decrement
3851 operand immI_M1() %{
3852   predicate(n->get_int() == -1);
3853   match(ConI);
3854 
3855   op_cost(0);
3856   format %{ %}
3857   interface(CONST_INTER);
3858 %}
3859 
3860 // Valid scale values for addressing modes
3861 operand immI2() %{
3862   predicate(0 <= n->get_int() && (n->get_int() <= 3));
3863   match(ConI);
3864 
3865   format %{ %}
3866   interface(CONST_INTER);
3867 %}
3868 
3869 operand immI8() %{
3870   predicate((-128 <= n->get_int()) && (n->get_int() <= 127));
3871   match(ConI);
3872 
3873   op_cost(5);
3874   format %{ %}
3875   interface(CONST_INTER);
3876 %}
3877 
3878 operand immI16() %{
3879   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
3880   match(ConI);
3881 
3882   op_cost(10);
3883   format %{ %}
3884   interface(CONST_INTER);
3885 %}
3886 
3887 // Int Immediate non-negative
3888 operand immU31()
3889 %{
3890   predicate(n->get_int() >= 0);
3891   match(ConI);
3892 
3893   op_cost(0);
3894   format %{ %}
3895   interface(CONST_INTER);
3896 %}
3897 
3898 // Constant for long shifts
3899 operand immI_32() %{
3900   predicate( n->get_int() == 32 );
3901   match(ConI);
3902 
3903   op_cost(0);
3904   format %{ %}
3905   interface(CONST_INTER);
3906 %}
3907 
3908 operand immI_1_31() %{
3909   predicate( n->get_int() >= 1 && n->get_int() <= 31 );
3910   match(ConI);
3911 
3912   op_cost(0);
3913   format %{ %}
3914   interface(CONST_INTER);
3915 %}
3916 
3917 operand immI_32_63() %{
3918   predicate( n->get_int() >= 32 && n->get_int() <= 63 );
3919   match(ConI);
3920   op_cost(0);
3921 
3922   format %{ %}
3923   interface(CONST_INTER);
3924 %}
3925 
3926 operand immI_1() %{
3927   predicate( n->get_int() == 1 );
3928   match(ConI);
3929 
3930   op_cost(0);
3931   format %{ %}
3932   interface(CONST_INTER);
3933 %}
3934 
3935 operand immI_2() %{
3936   predicate( n->get_int() == 2 );
3937   match(ConI);
3938 
3939   op_cost(0);
3940   format %{ %}
3941   interface(CONST_INTER);
3942 %}
3943 
3944 operand immI_3() %{
3945   predicate( n->get_int() == 3 );
3946   match(ConI);
3947 
3948   op_cost(0);
3949   format %{ %}
3950   interface(CONST_INTER);
3951 %}
3952 
3953 // Pointer Immediate
3954 operand immP() %{
3955   match(ConP);
3956 
3957   op_cost(10);
3958   format %{ %}
3959   interface(CONST_INTER);
3960 %}
3961 
3962 // NULL Pointer Immediate
3963 operand immP0() %{
3964   predicate( n->get_ptr() == 0 );
3965   match(ConP);
3966   op_cost(0);
3967 
3968   format %{ %}
3969   interface(CONST_INTER);
3970 %}
3971 
3972 // Long Immediate
3973 operand immL() %{
3974   match(ConL);
3975 
3976   op_cost(20);
3977   format %{ %}
3978   interface(CONST_INTER);
3979 %}
3980 
3981 // Long Immediate zero
3982 operand immL0() %{
3983   predicate( n->get_long() == 0L );
3984   match(ConL);
3985   op_cost(0);
3986 
3987   format %{ %}
3988   interface(CONST_INTER);
3989 %}
3990 
3991 // Long Immediate zero
3992 operand immL_M1() %{
3993   predicate( n->get_long() == -1L );
3994   match(ConL);
3995   op_cost(0);
3996 
3997   format %{ %}
3998   interface(CONST_INTER);
3999 %}
4000 
4001 // Long immediate from 0 to 127.
4002 // Used for a shorter form of long mul by 10.
4003 operand immL_127() %{
4004   predicate((0 <= n->get_long()) && (n->get_long() <= 127));
4005   match(ConL);
4006   op_cost(0);
4007 
4008   format %{ %}
4009   interface(CONST_INTER);
4010 %}
4011 
4012 // Long Immediate: low 32-bit mask
4013 operand immL_32bits() %{
4014   predicate(n->get_long() == 0xFFFFFFFFL);
4015   match(ConL);
4016   op_cost(0);
4017 
4018   format %{ %}
4019   interface(CONST_INTER);
4020 %}
4021 
4022 // Long Immediate: low 32-bit mask
4023 operand immL32() %{
4024   predicate(n->get_long() == (int)(n->get_long()));
4025   match(ConL);
4026   op_cost(20);
4027 
4028   format %{ %}
4029   interface(CONST_INTER);
4030 %}
4031 
4032 //Double Immediate zero
4033 operand immDPR0() %{
4034   // Do additional (and counter-intuitive) test against NaN to work around VC++
4035   // bug that generates code such that NaNs compare equal to 0.0
4036   predicate( UseSSE<=1 && n->getd() == 0.0 && !g_isnan(n->getd()) );
4037   match(ConD);
4038 
4039   op_cost(5);
4040   format %{ %}
4041   interface(CONST_INTER);
4042 %}
4043 
4044 // Double Immediate one
4045 operand immDPR1() %{
4046   predicate( UseSSE<=1 && n->getd() == 1.0 );
4047   match(ConD);
4048 
4049   op_cost(5);
4050   format %{ %}
4051   interface(CONST_INTER);
4052 %}
4053 
4054 // Double Immediate
4055 operand immDPR() %{
4056   predicate(UseSSE<=1);
4057   match(ConD);
4058 
4059   op_cost(5);
4060   format %{ %}
4061   interface(CONST_INTER);
4062 %}
4063 
4064 operand immD() %{
4065   predicate(UseSSE>=2);
4066   match(ConD);
4067 
4068   op_cost(5);
4069   format %{ %}
4070   interface(CONST_INTER);
4071 %}
4072 
4073 // Double Immediate zero
4074 operand immD0() %{
4075   // Do additional (and counter-intuitive) test against NaN to work around VC++
4076   // bug that generates code such that NaNs compare equal to 0.0 AND do not
4077   // compare equal to -0.0.
4078   predicate( UseSSE>=2 && jlong_cast(n->getd()) == 0 );
4079   match(ConD);
4080 
4081   format %{ %}
4082   interface(CONST_INTER);
4083 %}
4084 
4085 // Float Immediate zero
4086 operand immFPR0() %{
4087   predicate(UseSSE == 0 && n->getf() == 0.0F);
4088   match(ConF);
4089 
4090   op_cost(5);
4091   format %{ %}
4092   interface(CONST_INTER);
4093 %}
4094 
4095 // Float Immediate one
4096 operand immFPR1() %{
4097   predicate(UseSSE == 0 && n->getf() == 1.0F);
4098   match(ConF);
4099 
4100   op_cost(5);
4101   format %{ %}
4102   interface(CONST_INTER);
4103 %}
4104 
4105 // Float Immediate
4106 operand immFPR() %{
4107   predicate( UseSSE == 0 );
4108   match(ConF);
4109 
4110   op_cost(5);
4111   format %{ %}
4112   interface(CONST_INTER);
4113 %}
4114 
4115 // Float Immediate
4116 operand immF() %{
4117   predicate(UseSSE >= 1);
4118   match(ConF);
4119 
4120   op_cost(5);
4121   format %{ %}
4122   interface(CONST_INTER);
4123 %}
4124 
4125 // Float Immediate zero.  Zero and not -0.0
4126 operand immF0() %{
4127   predicate( UseSSE >= 1 && jint_cast(n->getf()) == 0 );
4128   match(ConF);
4129 
4130   op_cost(5);
4131   format %{ %}
4132   interface(CONST_INTER);
4133 %}
4134 
4135 // Immediates for special shifts (sign extend)
4136 
4137 // Constants for increment
4138 operand immI_16() %{
4139   predicate( n->get_int() == 16 );
4140   match(ConI);
4141 
4142   format %{ %}
4143   interface(CONST_INTER);
4144 %}
4145 
4146 operand immI_24() %{
4147   predicate( n->get_int() == 24 );
4148   match(ConI);
4149 
4150   format %{ %}
4151   interface(CONST_INTER);
4152 %}
4153 
4154 // Constant for byte-wide masking
4155 operand immI_255() %{
4156   predicate( n->get_int() == 255 );
4157   match(ConI);
4158 
4159   format %{ %}
4160   interface(CONST_INTER);
4161 %}
4162 
4163 // Constant for short-wide masking
4164 operand immI_65535() %{
4165   predicate(n->get_int() == 65535);
4166   match(ConI);
4167 
4168   format %{ %}
4169   interface(CONST_INTER);
4170 %}
4171 
4172 // Register Operands
4173 // Integer Register
4174 operand rRegI() %{
4175   constraint(ALLOC_IN_RC(int_reg));
4176   match(RegI);
4177   match(xRegI);
4178   match(eAXRegI);
4179   match(eBXRegI);
4180   match(eCXRegI);
4181   match(eDXRegI);
4182   match(eDIRegI);
4183   match(eSIRegI);
4184 
4185   format %{ %}
4186   interface(REG_INTER);
4187 %}
4188 
4189 // Subset of Integer Register
4190 operand xRegI(rRegI reg) %{
4191   constraint(ALLOC_IN_RC(int_x_reg));
4192   match(reg);
4193   match(eAXRegI);
4194   match(eBXRegI);
4195   match(eCXRegI);
4196   match(eDXRegI);
4197 
4198   format %{ %}
4199   interface(REG_INTER);
4200 %}
4201 
4202 // Special Registers
4203 operand eAXRegI(xRegI reg) %{
4204   constraint(ALLOC_IN_RC(eax_reg));
4205   match(reg);
4206   match(rRegI);
4207 
4208   format %{ "EAX" %}
4209   interface(REG_INTER);
4210 %}
4211 
4212 // Special Registers
4213 operand eBXRegI(xRegI reg) %{
4214   constraint(ALLOC_IN_RC(ebx_reg));
4215   match(reg);
4216   match(rRegI);
4217 
4218   format %{ "EBX" %}
4219   interface(REG_INTER);
4220 %}
4221 
4222 operand eCXRegI(xRegI reg) %{
4223   constraint(ALLOC_IN_RC(ecx_reg));
4224   match(reg);
4225   match(rRegI);
4226 
4227   format %{ "ECX" %}
4228   interface(REG_INTER);
4229 %}
4230 
4231 operand eDXRegI(xRegI reg) %{
4232   constraint(ALLOC_IN_RC(edx_reg));
4233   match(reg);
4234   match(rRegI);
4235 
4236   format %{ "EDX" %}
4237   interface(REG_INTER);
4238 %}
4239 
4240 operand eDIRegI(xRegI reg) %{
4241   constraint(ALLOC_IN_RC(edi_reg));
4242   match(reg);
4243   match(rRegI);
4244 
4245   format %{ "EDI" %}
4246   interface(REG_INTER);
4247 %}
4248 
4249 operand naxRegI() %{
4250   constraint(ALLOC_IN_RC(nax_reg));
4251   match(RegI);
4252   match(eCXRegI);
4253   match(eDXRegI);
4254   match(eSIRegI);
4255   match(eDIRegI);
4256 
4257   format %{ %}
4258   interface(REG_INTER);
4259 %}
4260 
4261 operand nadxRegI() %{
4262   constraint(ALLOC_IN_RC(nadx_reg));
4263   match(RegI);
4264   match(eBXRegI);
4265   match(eCXRegI);
4266   match(eSIRegI);
4267   match(eDIRegI);
4268 
4269   format %{ %}
4270   interface(REG_INTER);
4271 %}
4272 
4273 operand ncxRegI() %{
4274   constraint(ALLOC_IN_RC(ncx_reg));
4275   match(RegI);
4276   match(eAXRegI);
4277   match(eDXRegI);
4278   match(eSIRegI);
4279   match(eDIRegI);
4280 
4281   format %{ %}
4282   interface(REG_INTER);
4283 %}
4284 
4285 // // This operand was used by cmpFastUnlock, but conflicted with 'object' reg
4286 // //
4287 operand eSIRegI(xRegI reg) %{
4288    constraint(ALLOC_IN_RC(esi_reg));
4289    match(reg);
4290    match(rRegI);
4291 
4292    format %{ "ESI" %}
4293    interface(REG_INTER);
4294 %}
4295 
4296 // Pointer Register
4297 operand anyRegP() %{
4298   constraint(ALLOC_IN_RC(any_reg));
4299   match(RegP);
4300   match(eAXRegP);
4301   match(eBXRegP);
4302   match(eCXRegP);
4303   match(eDIRegP);
4304   match(eRegP);
4305 
4306   format %{ %}
4307   interface(REG_INTER);
4308 %}
4309 
4310 operand eRegP() %{
4311   constraint(ALLOC_IN_RC(int_reg));
4312   match(RegP);
4313   match(eAXRegP);
4314   match(eBXRegP);
4315   match(eCXRegP);
4316   match(eDIRegP);
4317 
4318   format %{ %}
4319   interface(REG_INTER);
4320 %}
4321 
4322 // On windows95, EBP is not safe to use for implicit null tests.
4323 operand eRegP_no_EBP() %{
4324   constraint(ALLOC_IN_RC(int_reg_no_rbp));
4325   match(RegP);
4326   match(eAXRegP);
4327   match(eBXRegP);
4328   match(eCXRegP);
4329   match(eDIRegP);
4330 
4331   op_cost(100);
4332   format %{ %}
4333   interface(REG_INTER);
4334 %}
4335 
4336 operand naxRegP() %{
4337   constraint(ALLOC_IN_RC(nax_reg));
4338   match(RegP);
4339   match(eBXRegP);
4340   match(eDXRegP);
4341   match(eCXRegP);
4342   match(eSIRegP);
4343   match(eDIRegP);
4344 
4345   format %{ %}
4346   interface(REG_INTER);
4347 %}
4348 
4349 operand nabxRegP() %{
4350   constraint(ALLOC_IN_RC(nabx_reg));
4351   match(RegP);
4352   match(eCXRegP);
4353   match(eDXRegP);
4354   match(eSIRegP);
4355   match(eDIRegP);
4356 
4357   format %{ %}
4358   interface(REG_INTER);
4359 %}
4360 
4361 operand pRegP() %{
4362   constraint(ALLOC_IN_RC(p_reg));
4363   match(RegP);
4364   match(eBXRegP);
4365   match(eDXRegP);
4366   match(eSIRegP);
4367   match(eDIRegP);
4368 
4369   format %{ %}
4370   interface(REG_INTER);
4371 %}
4372 
4373 // Special Registers
4374 // Return a pointer value
4375 operand eAXRegP(eRegP reg) %{
4376   constraint(ALLOC_IN_RC(eax_reg));
4377   match(reg);
4378   format %{ "EAX" %}
4379   interface(REG_INTER);
4380 %}
4381 
4382 // Used in AtomicAdd
4383 operand eBXRegP(eRegP reg) %{
4384   constraint(ALLOC_IN_RC(ebx_reg));
4385   match(reg);
4386   format %{ "EBX" %}
4387   interface(REG_INTER);
4388 %}
4389 
4390 // Tail-call (interprocedural jump) to interpreter
4391 operand eCXRegP(eRegP reg) %{
4392   constraint(ALLOC_IN_RC(ecx_reg));
4393   match(reg);
4394   format %{ "ECX" %}
4395   interface(REG_INTER);
4396 %}
4397 
4398 operand eSIRegP(eRegP reg) %{
4399   constraint(ALLOC_IN_RC(esi_reg));
4400   match(reg);
4401   format %{ "ESI" %}
4402   interface(REG_INTER);
4403 %}
4404 
4405 // Used in rep stosw
4406 operand eDIRegP(eRegP reg) %{
4407   constraint(ALLOC_IN_RC(edi_reg));
4408   match(reg);
4409   format %{ "EDI" %}
4410   interface(REG_INTER);
4411 %}
4412 
4413 operand eBPRegP() %{
4414   constraint(ALLOC_IN_RC(ebp_reg));
4415   match(RegP);
4416   format %{ "EBP" %}
4417   interface(REG_INTER);
4418 %}
4419 
4420 operand eRegL() %{
4421   constraint(ALLOC_IN_RC(long_reg));
4422   match(RegL);
4423   match(eADXRegL);
4424 
4425   format %{ %}
4426   interface(REG_INTER);
4427 %}
4428 
4429 operand eADXRegL( eRegL reg ) %{
4430   constraint(ALLOC_IN_RC(eadx_reg));
4431   match(reg);
4432 
4433   format %{ "EDX:EAX" %}
4434   interface(REG_INTER);
4435 %}
4436 
4437 operand eBCXRegL( eRegL reg ) %{
4438   constraint(ALLOC_IN_RC(ebcx_reg));
4439   match(reg);
4440 
4441   format %{ "EBX:ECX" %}
4442   interface(REG_INTER);
4443 %}
4444 
4445 // Special case for integer high multiply
4446 operand eADXRegL_low_only() %{
4447   constraint(ALLOC_IN_RC(eadx_reg));
4448   match(RegL);
4449 
4450   format %{ "EAX" %}
4451   interface(REG_INTER);
4452 %}
4453 
4454 // Flags register, used as output of compare instructions
4455 operand eFlagsReg() %{
4456   constraint(ALLOC_IN_RC(int_flags));
4457   match(RegFlags);
4458 
4459   format %{ "EFLAGS" %}
4460   interface(REG_INTER);
4461 %}
4462 
4463 // Flags register, used as output of FLOATING POINT compare instructions
4464 operand eFlagsRegU() %{
4465   constraint(ALLOC_IN_RC(int_flags));
4466   match(RegFlags);
4467 
4468   format %{ "EFLAGS_U" %}
4469   interface(REG_INTER);
4470 %}
4471 
4472 operand eFlagsRegUCF() %{
4473   constraint(ALLOC_IN_RC(int_flags));
4474   match(RegFlags);
4475   predicate(false);
4476 
4477   format %{ "EFLAGS_U_CF" %}
4478   interface(REG_INTER);
4479 %}
4480 
4481 // Condition Code Register used by long compare
4482 operand flagsReg_long_LTGE() %{
4483   constraint(ALLOC_IN_RC(int_flags));
4484   match(RegFlags);
4485   format %{ "FLAGS_LTGE" %}
4486   interface(REG_INTER);
4487 %}
4488 operand flagsReg_long_EQNE() %{
4489   constraint(ALLOC_IN_RC(int_flags));
4490   match(RegFlags);
4491   format %{ "FLAGS_EQNE" %}
4492   interface(REG_INTER);
4493 %}
4494 operand flagsReg_long_LEGT() %{
4495   constraint(ALLOC_IN_RC(int_flags));
4496   match(RegFlags);
4497   format %{ "FLAGS_LEGT" %}
4498   interface(REG_INTER);
4499 %}
4500 
4501 // Float register operands
4502 operand regDPR() %{
4503   predicate( UseSSE < 2 );
4504   constraint(ALLOC_IN_RC(fp_dbl_reg));
4505   match(RegD);
4506   match(regDPR1);
4507   match(regDPR2);
4508   format %{ %}
4509   interface(REG_INTER);
4510 %}
4511 
4512 operand regDPR1(regDPR reg) %{
4513   predicate( UseSSE < 2 );
4514   constraint(ALLOC_IN_RC(fp_dbl_reg0));
4515   match(reg);
4516   format %{ "FPR1" %}
4517   interface(REG_INTER);
4518 %}
4519 
4520 operand regDPR2(regDPR reg) %{
4521   predicate( UseSSE < 2 );
4522   constraint(ALLOC_IN_RC(fp_dbl_reg1));
4523   match(reg);
4524   format %{ "FPR2" %}
4525   interface(REG_INTER);
4526 %}
4527 
4528 operand regnotDPR1(regDPR reg) %{
4529   predicate( UseSSE < 2 );
4530   constraint(ALLOC_IN_RC(fp_dbl_notreg0));
4531   match(reg);
4532   format %{ %}
4533   interface(REG_INTER);
4534 %}
4535 
4536 // Float register operands
4537 operand regFPR() %{
4538   predicate( UseSSE < 2 );
4539   constraint(ALLOC_IN_RC(fp_flt_reg));
4540   match(RegF);
4541   match(regFPR1);
4542   format %{ %}
4543   interface(REG_INTER);
4544 %}
4545 
4546 // Float register operands
4547 operand regFPR1(regFPR reg) %{
4548   predicate( UseSSE < 2 );
4549   constraint(ALLOC_IN_RC(fp_flt_reg0));
4550   match(reg);
4551   format %{ "FPR1" %}
4552   interface(REG_INTER);
4553 %}
4554 
4555 // XMM Float register operands
4556 operand regF() %{
4557   predicate( UseSSE>=1 );
4558   constraint(ALLOC_IN_RC(float_reg));
4559   match(RegF);
4560   format %{ %}
4561   interface(REG_INTER);
4562 %}
4563 
4564 // XMM Double register operands
4565 operand regD() %{
4566   predicate( UseSSE>=2 );
4567   constraint(ALLOC_IN_RC(double_reg));
4568   match(RegD);
4569   format %{ %}
4570   interface(REG_INTER);
4571 %}
4572 
4573 
4574 //----------Memory Operands----------------------------------------------------
4575 // Direct Memory Operand
4576 operand direct(immP addr) %{
4577   match(addr);
4578 
4579   format %{ "[$addr]" %}
4580   interface(MEMORY_INTER) %{
4581     base(0xFFFFFFFF);
4582     index(0x4);
4583     scale(0x0);
4584     disp($addr);
4585   %}
4586 %}
4587 
4588 // Indirect Memory Operand
4589 operand indirect(eRegP reg) %{
4590   constraint(ALLOC_IN_RC(int_reg));
4591   match(reg);
4592 
4593   format %{ "[$reg]" %}
4594   interface(MEMORY_INTER) %{
4595     base($reg);
4596     index(0x4);
4597     scale(0x0);
4598     disp(0x0);
4599   %}
4600 %}
4601 
4602 // Indirect Memory Plus Short Offset Operand
4603 operand indOffset8(eRegP reg, immI8 off) %{
4604   match(AddP reg off);
4605 
4606   format %{ "[$reg + $off]" %}
4607   interface(MEMORY_INTER) %{
4608     base($reg);
4609     index(0x4);
4610     scale(0x0);
4611     disp($off);
4612   %}
4613 %}
4614 
4615 // Indirect Memory Plus Long Offset Operand
4616 operand indOffset32(eRegP reg, immI off) %{
4617   match(AddP reg off);
4618 
4619   format %{ "[$reg + $off]" %}
4620   interface(MEMORY_INTER) %{
4621     base($reg);
4622     index(0x4);
4623     scale(0x0);
4624     disp($off);
4625   %}
4626 %}
4627 
4628 // Indirect Memory Plus Long Offset Operand
4629 operand indOffset32X(rRegI reg, immP off) %{
4630   match(AddP off reg);
4631 
4632   format %{ "[$reg + $off]" %}
4633   interface(MEMORY_INTER) %{
4634     base($reg);
4635     index(0x4);
4636     scale(0x0);
4637     disp($off);
4638   %}
4639 %}
4640 
4641 // Indirect Memory Plus Index Register Plus Offset Operand
4642 operand indIndexOffset(eRegP reg, rRegI ireg, immI off) %{
4643   match(AddP (AddP reg ireg) off);
4644 
4645   op_cost(10);
4646   format %{"[$reg + $off + $ireg]" %}
4647   interface(MEMORY_INTER) %{
4648     base($reg);
4649     index($ireg);
4650     scale(0x0);
4651     disp($off);
4652   %}
4653 %}
4654 
4655 // Indirect Memory Plus Index Register Plus Offset Operand
4656 operand indIndex(eRegP reg, rRegI ireg) %{
4657   match(AddP reg ireg);
4658 
4659   op_cost(10);
4660   format %{"[$reg + $ireg]" %}
4661   interface(MEMORY_INTER) %{
4662     base($reg);
4663     index($ireg);
4664     scale(0x0);
4665     disp(0x0);
4666   %}
4667 %}
4668 
4669 // // -------------------------------------------------------------------------
4670 // // 486 architecture doesn't support "scale * index + offset" with out a base
4671 // // -------------------------------------------------------------------------
4672 // // Scaled Memory Operands
4673 // // Indirect Memory Times Scale Plus Offset Operand
4674 // operand indScaleOffset(immP off, rRegI ireg, immI2 scale) %{
4675 //   match(AddP off (LShiftI ireg scale));
4676 //
4677 //   op_cost(10);
4678 //   format %{"[$off + $ireg << $scale]" %}
4679 //   interface(MEMORY_INTER) %{
4680 //     base(0x4);
4681 //     index($ireg);
4682 //     scale($scale);
4683 //     disp($off);
4684 //   %}
4685 // %}
4686 
4687 // Indirect Memory Times Scale Plus Index Register
4688 operand indIndexScale(eRegP reg, rRegI ireg, immI2 scale) %{
4689   match(AddP reg (LShiftI ireg scale));
4690 
4691   op_cost(10);
4692   format %{"[$reg + $ireg << $scale]" %}
4693   interface(MEMORY_INTER) %{
4694     base($reg);
4695     index($ireg);
4696     scale($scale);
4697     disp(0x0);
4698   %}
4699 %}
4700 
4701 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
4702 operand indIndexScaleOffset(eRegP reg, immI off, rRegI ireg, immI2 scale) %{
4703   match(AddP (AddP reg (LShiftI ireg scale)) off);
4704 
4705   op_cost(10);
4706   format %{"[$reg + $off + $ireg << $scale]" %}
4707   interface(MEMORY_INTER) %{
4708     base($reg);
4709     index($ireg);
4710     scale($scale);
4711     disp($off);
4712   %}
4713 %}
4714 
4715 //----------Load Long Memory Operands------------------------------------------
4716 // The load-long idiom will use it's address expression again after loading
4717 // the first word of the long.  If the load-long destination overlaps with
4718 // registers used in the addressing expression, the 2nd half will be loaded
4719 // from a clobbered address.  Fix this by requiring that load-long use
4720 // address registers that do not overlap with the load-long target.
4721 
4722 // load-long support
4723 operand load_long_RegP() %{
4724   constraint(ALLOC_IN_RC(esi_reg));
4725   match(RegP);
4726   match(eSIRegP);
4727   op_cost(100);
4728   format %{  %}
4729   interface(REG_INTER);
4730 %}
4731 
4732 // Indirect Memory Operand Long
4733 operand load_long_indirect(load_long_RegP reg) %{
4734   constraint(ALLOC_IN_RC(esi_reg));
4735   match(reg);
4736 
4737   format %{ "[$reg]" %}
4738   interface(MEMORY_INTER) %{
4739     base($reg);
4740     index(0x4);
4741     scale(0x0);
4742     disp(0x0);
4743   %}
4744 %}
4745 
4746 // Indirect Memory Plus Long Offset Operand
4747 operand load_long_indOffset32(load_long_RegP reg, immI off) %{
4748   match(AddP reg off);
4749 
4750   format %{ "[$reg + $off]" %}
4751   interface(MEMORY_INTER) %{
4752     base($reg);
4753     index(0x4);
4754     scale(0x0);
4755     disp($off);
4756   %}
4757 %}
4758 
4759 opclass load_long_memory(load_long_indirect, load_long_indOffset32);
4760 
4761 
4762 //----------Special Memory Operands--------------------------------------------
4763 // Stack Slot Operand - This operand is used for loading and storing temporary
4764 //                      values on the stack where a match requires a value to
4765 //                      flow through memory.
4766 operand stackSlotP(sRegP reg) %{
4767   constraint(ALLOC_IN_RC(stack_slots));
4768   // No match rule because this operand is only generated in matching
4769   format %{ "[$reg]" %}
4770   interface(MEMORY_INTER) %{
4771     base(0x4);   // ESP
4772     index(0x4);  // No Index
4773     scale(0x0);  // No Scale
4774     disp($reg);  // Stack Offset
4775   %}
4776 %}
4777 
4778 operand stackSlotI(sRegI reg) %{
4779   constraint(ALLOC_IN_RC(stack_slots));
4780   // No match rule because this operand is only generated in matching
4781   format %{ "[$reg]" %}
4782   interface(MEMORY_INTER) %{
4783     base(0x4);   // ESP
4784     index(0x4);  // No Index
4785     scale(0x0);  // No Scale
4786     disp($reg);  // Stack Offset
4787   %}
4788 %}
4789 
4790 operand stackSlotF(sRegF reg) %{
4791   constraint(ALLOC_IN_RC(stack_slots));
4792   // No match rule because this operand is only generated in matching
4793   format %{ "[$reg]" %}
4794   interface(MEMORY_INTER) %{
4795     base(0x4);   // ESP
4796     index(0x4);  // No Index
4797     scale(0x0);  // No Scale
4798     disp($reg);  // Stack Offset
4799   %}
4800 %}
4801 
4802 operand stackSlotD(sRegD reg) %{
4803   constraint(ALLOC_IN_RC(stack_slots));
4804   // No match rule because this operand is only generated in matching
4805   format %{ "[$reg]" %}
4806   interface(MEMORY_INTER) %{
4807     base(0x4);   // ESP
4808     index(0x4);  // No Index
4809     scale(0x0);  // No Scale
4810     disp($reg);  // Stack Offset
4811   %}
4812 %}
4813 
4814 operand stackSlotL(sRegL reg) %{
4815   constraint(ALLOC_IN_RC(stack_slots));
4816   // No match rule because this operand is only generated in matching
4817   format %{ "[$reg]" %}
4818   interface(MEMORY_INTER) %{
4819     base(0x4);   // ESP
4820     index(0x4);  // No Index
4821     scale(0x0);  // No Scale
4822     disp($reg);  // Stack Offset
4823   %}
4824 %}
4825 
4826 //----------Memory Operands - Win95 Implicit Null Variants----------------
4827 // Indirect Memory Operand
4828 operand indirect_win95_safe(eRegP_no_EBP reg)
4829 %{
4830   constraint(ALLOC_IN_RC(int_reg));
4831   match(reg);
4832 
4833   op_cost(100);
4834   format %{ "[$reg]" %}
4835   interface(MEMORY_INTER) %{
4836     base($reg);
4837     index(0x4);
4838     scale(0x0);
4839     disp(0x0);
4840   %}
4841 %}
4842 
4843 // Indirect Memory Plus Short Offset Operand
4844 operand indOffset8_win95_safe(eRegP_no_EBP reg, immI8 off)
4845 %{
4846   match(AddP reg off);
4847 
4848   op_cost(100);
4849   format %{ "[$reg + $off]" %}
4850   interface(MEMORY_INTER) %{
4851     base($reg);
4852     index(0x4);
4853     scale(0x0);
4854     disp($off);
4855   %}
4856 %}
4857 
4858 // Indirect Memory Plus Long Offset Operand
4859 operand indOffset32_win95_safe(eRegP_no_EBP reg, immI off)
4860 %{
4861   match(AddP reg off);
4862 
4863   op_cost(100);
4864   format %{ "[$reg + $off]" %}
4865   interface(MEMORY_INTER) %{
4866     base($reg);
4867     index(0x4);
4868     scale(0x0);
4869     disp($off);
4870   %}
4871 %}
4872 
4873 // Indirect Memory Plus Index Register Plus Offset Operand
4874 operand indIndexOffset_win95_safe(eRegP_no_EBP reg, rRegI ireg, immI off)
4875 %{
4876   match(AddP (AddP reg ireg) off);
4877 
4878   op_cost(100);
4879   format %{"[$reg + $off + $ireg]" %}
4880   interface(MEMORY_INTER) %{
4881     base($reg);
4882     index($ireg);
4883     scale(0x0);
4884     disp($off);
4885   %}
4886 %}
4887 
4888 // Indirect Memory Times Scale Plus Index Register
4889 operand indIndexScale_win95_safe(eRegP_no_EBP reg, rRegI ireg, immI2 scale)
4890 %{
4891   match(AddP reg (LShiftI ireg scale));
4892 
4893   op_cost(100);
4894   format %{"[$reg + $ireg << $scale]" %}
4895   interface(MEMORY_INTER) %{
4896     base($reg);
4897     index($ireg);
4898     scale($scale);
4899     disp(0x0);
4900   %}
4901 %}
4902 
4903 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
4904 operand indIndexScaleOffset_win95_safe(eRegP_no_EBP reg, immI off, rRegI ireg, immI2 scale)
4905 %{
4906   match(AddP (AddP reg (LShiftI ireg scale)) off);
4907 
4908   op_cost(100);
4909   format %{"[$reg + $off + $ireg << $scale]" %}
4910   interface(MEMORY_INTER) %{
4911     base($reg);
4912     index($ireg);
4913     scale($scale);
4914     disp($off);
4915   %}
4916 %}
4917 
4918 //----------Conditional Branch Operands----------------------------------------
4919 // Comparison Op  - This is the operation of the comparison, and is limited to
4920 //                  the following set of codes:
4921 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
4922 //
4923 // Other attributes of the comparison, such as unsignedness, are specified
4924 // by the comparison instruction that sets a condition code flags register.
4925 // That result is represented by a flags operand whose subtype is appropriate
4926 // to the unsignedness (etc.) of the comparison.
4927 //
4928 // Later, the instruction which matches both the Comparison Op (a Bool) and
4929 // the flags (produced by the Cmp) specifies the coding of the comparison op
4930 // by matching a specific subtype of Bool operand below, such as cmpOpU.
4931 
4932 // Comparision Code
4933 operand cmpOp() %{
4934   match(Bool);
4935 
4936   format %{ "" %}
4937   interface(COND_INTER) %{
4938     equal(0x4, "e");
4939     not_equal(0x5, "ne");
4940     less(0xC, "l");
4941     greater_equal(0xD, "ge");
4942     less_equal(0xE, "le");
4943     greater(0xF, "g");
4944     overflow(0x0, "o");
4945     no_overflow(0x1, "no");
4946   %}
4947 %}
4948 
4949 // Comparison Code, unsigned compare.  Used by FP also, with
4950 // C2 (unordered) turned into GT or LT already.  The other bits
4951 // C0 and C3 are turned into Carry & Zero flags.
4952 operand cmpOpU() %{
4953   match(Bool);
4954 
4955   format %{ "" %}
4956   interface(COND_INTER) %{
4957     equal(0x4, "e");
4958     not_equal(0x5, "ne");
4959     less(0x2, "b");
4960     greater_equal(0x3, "nb");
4961     less_equal(0x6, "be");
4962     greater(0x7, "nbe");
4963     overflow(0x0, "o");
4964     no_overflow(0x1, "no");
4965   %}
4966 %}
4967 
4968 // Floating comparisons that don't require any fixup for the unordered case
4969 operand cmpOpUCF() %{
4970   match(Bool);
4971   predicate(n->as_Bool()->_test._test == BoolTest::lt ||
4972             n->as_Bool()->_test._test == BoolTest::ge ||
4973             n->as_Bool()->_test._test == BoolTest::le ||
4974             n->as_Bool()->_test._test == BoolTest::gt);
4975   format %{ "" %}
4976   interface(COND_INTER) %{
4977     equal(0x4, "e");
4978     not_equal(0x5, "ne");
4979     less(0x2, "b");
4980     greater_equal(0x3, "nb");
4981     less_equal(0x6, "be");
4982     greater(0x7, "nbe");
4983     overflow(0x0, "o");
4984     no_overflow(0x1, "no");
4985   %}
4986 %}
4987 
4988 
4989 // Floating comparisons that can be fixed up with extra conditional jumps
4990 operand cmpOpUCF2() %{
4991   match(Bool);
4992   predicate(n->as_Bool()->_test._test == BoolTest::ne ||
4993             n->as_Bool()->_test._test == BoolTest::eq);
4994   format %{ "" %}
4995   interface(COND_INTER) %{
4996     equal(0x4, "e");
4997     not_equal(0x5, "ne");
4998     less(0x2, "b");
4999     greater_equal(0x3, "nb");
5000     less_equal(0x6, "be");
5001     greater(0x7, "nbe");
5002     overflow(0x0, "o");
5003     no_overflow(0x1, "no");
5004   %}
5005 %}
5006 
5007 // Comparison Code for FP conditional move
5008 operand cmpOp_fcmov() %{
5009   match(Bool);
5010 
5011   predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
5012             n->as_Bool()->_test._test != BoolTest::no_overflow);
5013   format %{ "" %}
5014   interface(COND_INTER) %{
5015     equal        (0x0C8);
5016     not_equal    (0x1C8);
5017     less         (0x0C0);
5018     greater_equal(0x1C0);
5019     less_equal   (0x0D0);
5020     greater      (0x1D0);
5021     overflow(0x0, "o"); // not really supported by the instruction
5022     no_overflow(0x1, "no"); // not really supported by the instruction
5023   %}
5024 %}
5025 
5026 // Comparision Code used in long compares
5027 operand cmpOp_commute() %{
5028   match(Bool);
5029 
5030   format %{ "" %}
5031   interface(COND_INTER) %{
5032     equal(0x4, "e");
5033     not_equal(0x5, "ne");
5034     less(0xF, "g");
5035     greater_equal(0xE, "le");
5036     less_equal(0xD, "ge");
5037     greater(0xC, "l");
5038     overflow(0x0, "o");
5039     no_overflow(0x1, "no");
5040   %}
5041 %}
5042 
5043 //----------OPERAND CLASSES----------------------------------------------------
5044 // Operand Classes are groups of operands that are used as to simplify
5045 // instruction definitions by not requiring the AD writer to specify separate
5046 // instructions for every form of operand when the instruction accepts
5047 // multiple operand types with the same basic encoding and format.  The classic
5048 // case of this is memory operands.
5049 
5050 opclass memory(direct, indirect, indOffset8, indOffset32, indOffset32X, indIndexOffset,
5051                indIndex, indIndexScale, indIndexScaleOffset);
5052 
5053 // Long memory operations are encoded in 2 instructions and a +4 offset.
5054 // This means some kind of offset is always required and you cannot use
5055 // an oop as the offset (done when working on static globals).
5056 opclass long_memory(direct, indirect, indOffset8, indOffset32, indIndexOffset,
5057                     indIndex, indIndexScale, indIndexScaleOffset);
5058 
5059 
5060 //----------PIPELINE-----------------------------------------------------------
5061 // Rules which define the behavior of the target architectures pipeline.
5062 pipeline %{
5063 
5064 //----------ATTRIBUTES---------------------------------------------------------
5065 attributes %{
5066   variable_size_instructions;        // Fixed size instructions
5067   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
5068   instruction_unit_size = 1;         // An instruction is 1 bytes long
5069   instruction_fetch_unit_size = 16;  // The processor fetches one line
5070   instruction_fetch_units = 1;       // of 16 bytes
5071 
5072   // List of nop instructions
5073   nops( MachNop );
5074 %}
5075 
5076 //----------RESOURCES----------------------------------------------------------
5077 // Resources are the functional units available to the machine
5078 
5079 // Generic P2/P3 pipeline
5080 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
5081 // 3 instructions decoded per cycle.
5082 // 2 load/store ops per cycle, 1 branch, 1 FPU,
5083 // 2 ALU op, only ALU0 handles mul/div instructions.
5084 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
5085            MS0, MS1, MEM = MS0 | MS1,
5086            BR, FPU,
5087            ALU0, ALU1, ALU = ALU0 | ALU1 );
5088 
5089 //----------PIPELINE DESCRIPTION-----------------------------------------------
5090 // Pipeline Description specifies the stages in the machine's pipeline
5091 
5092 // Generic P2/P3 pipeline
5093 pipe_desc(S0, S1, S2, S3, S4, S5);
5094 
5095 //----------PIPELINE CLASSES---------------------------------------------------
5096 // Pipeline Classes describe the stages in which input and output are
5097 // referenced by the hardware pipeline.
5098 
5099 // Naming convention: ialu or fpu
5100 // Then: _reg
5101 // Then: _reg if there is a 2nd register
5102 // Then: _long if it's a pair of instructions implementing a long
5103 // Then: _fat if it requires the big decoder
5104 //   Or: _mem if it requires the big decoder and a memory unit.
5105 
5106 // Integer ALU reg operation
5107 pipe_class ialu_reg(rRegI dst) %{
5108     single_instruction;
5109     dst    : S4(write);
5110     dst    : S3(read);
5111     DECODE : S0;        // any decoder
5112     ALU    : S3;        // any alu
5113 %}
5114 
5115 // Long ALU reg operation
5116 pipe_class ialu_reg_long(eRegL dst) %{
5117     instruction_count(2);
5118     dst    : S4(write);
5119     dst    : S3(read);
5120     DECODE : S0(2);     // any 2 decoders
5121     ALU    : S3(2);     // both alus
5122 %}
5123 
5124 // Integer ALU reg operation using big decoder
5125 pipe_class ialu_reg_fat(rRegI dst) %{
5126     single_instruction;
5127     dst    : S4(write);
5128     dst    : S3(read);
5129     D0     : S0;        // big decoder only
5130     ALU    : S3;        // any alu
5131 %}
5132 
5133 // Long ALU reg operation using big decoder
5134 pipe_class ialu_reg_long_fat(eRegL dst) %{
5135     instruction_count(2);
5136     dst    : S4(write);
5137     dst    : S3(read);
5138     D0     : S0(2);     // big decoder only; twice
5139     ALU    : S3(2);     // any 2 alus
5140 %}
5141 
5142 // Integer ALU reg-reg operation
5143 pipe_class ialu_reg_reg(rRegI dst, rRegI src) %{
5144     single_instruction;
5145     dst    : S4(write);
5146     src    : S3(read);
5147     DECODE : S0;        // any decoder
5148     ALU    : S3;        // any alu
5149 %}
5150 
5151 // Long ALU reg-reg operation
5152 pipe_class ialu_reg_reg_long(eRegL dst, eRegL src) %{
5153     instruction_count(2);
5154     dst    : S4(write);
5155     src    : S3(read);
5156     DECODE : S0(2);     // any 2 decoders
5157     ALU    : S3(2);     // both alus
5158 %}
5159 
5160 // Integer ALU reg-reg operation
5161 pipe_class ialu_reg_reg_fat(rRegI dst, memory src) %{
5162     single_instruction;
5163     dst    : S4(write);
5164     src    : S3(read);
5165     D0     : S0;        // big decoder only
5166     ALU    : S3;        // any alu
5167 %}
5168 
5169 // Long ALU reg-reg operation
5170 pipe_class ialu_reg_reg_long_fat(eRegL dst, eRegL src) %{
5171     instruction_count(2);
5172     dst    : S4(write);
5173     src    : S3(read);
5174     D0     : S0(2);     // big decoder only; twice
5175     ALU    : S3(2);     // both alus
5176 %}
5177 
5178 // Integer ALU reg-mem operation
5179 pipe_class ialu_reg_mem(rRegI dst, memory mem) %{
5180     single_instruction;
5181     dst    : S5(write);
5182     mem    : S3(read);
5183     D0     : S0;        // big decoder only
5184     ALU    : S4;        // any alu
5185     MEM    : S3;        // any mem
5186 %}
5187 
5188 // Long ALU reg-mem operation
5189 pipe_class ialu_reg_long_mem(eRegL dst, load_long_memory mem) %{
5190     instruction_count(2);
5191     dst    : S5(write);
5192     mem    : S3(read);
5193     D0     : S0(2);     // big decoder only; twice
5194     ALU    : S4(2);     // any 2 alus
5195     MEM    : S3(2);     // both mems
5196 %}
5197 
5198 // Integer mem operation (prefetch)
5199 pipe_class ialu_mem(memory mem)
5200 %{
5201     single_instruction;
5202     mem    : S3(read);
5203     D0     : S0;        // big decoder only
5204     MEM    : S3;        // any mem
5205 %}
5206 
5207 // Integer Store to Memory
5208 pipe_class ialu_mem_reg(memory mem, rRegI src) %{
5209     single_instruction;
5210     mem    : S3(read);
5211     src    : S5(read);
5212     D0     : S0;        // big decoder only
5213     ALU    : S4;        // any alu
5214     MEM    : S3;
5215 %}
5216 
5217 // Long Store to Memory
5218 pipe_class ialu_mem_long_reg(memory mem, eRegL src) %{
5219     instruction_count(2);
5220     mem    : S3(read);
5221     src    : S5(read);
5222     D0     : S0(2);     // big decoder only; twice
5223     ALU    : S4(2);     // any 2 alus
5224     MEM    : S3(2);     // Both mems
5225 %}
5226 
5227 // Integer Store to Memory
5228 pipe_class ialu_mem_imm(memory mem) %{
5229     single_instruction;
5230     mem    : S3(read);
5231     D0     : S0;        // big decoder only
5232     ALU    : S4;        // any alu
5233     MEM    : S3;
5234 %}
5235 
5236 // Integer ALU0 reg-reg operation
5237 pipe_class ialu_reg_reg_alu0(rRegI dst, rRegI src) %{
5238     single_instruction;
5239     dst    : S4(write);
5240     src    : S3(read);
5241     D0     : S0;        // Big decoder only
5242     ALU0   : S3;        // only alu0
5243 %}
5244 
5245 // Integer ALU0 reg-mem operation
5246 pipe_class ialu_reg_mem_alu0(rRegI dst, memory mem) %{
5247     single_instruction;
5248     dst    : S5(write);
5249     mem    : S3(read);
5250     D0     : S0;        // big decoder only
5251     ALU0   : S4;        // ALU0 only
5252     MEM    : S3;        // any mem
5253 %}
5254 
5255 // Integer ALU reg-reg operation
5256 pipe_class ialu_cr_reg_reg(eFlagsReg cr, rRegI src1, rRegI src2) %{
5257     single_instruction;
5258     cr     : S4(write);
5259     src1   : S3(read);
5260     src2   : S3(read);
5261     DECODE : S0;        // any decoder
5262     ALU    : S3;        // any alu
5263 %}
5264 
5265 // Integer ALU reg-imm operation
5266 pipe_class ialu_cr_reg_imm(eFlagsReg cr, rRegI src1) %{
5267     single_instruction;
5268     cr     : S4(write);
5269     src1   : S3(read);
5270     DECODE : S0;        // any decoder
5271     ALU    : S3;        // any alu
5272 %}
5273 
5274 // Integer ALU reg-mem operation
5275 pipe_class ialu_cr_reg_mem(eFlagsReg cr, rRegI src1, memory src2) %{
5276     single_instruction;
5277     cr     : S4(write);
5278     src1   : S3(read);
5279     src2   : S3(read);
5280     D0     : S0;        // big decoder only
5281     ALU    : S4;        // any alu
5282     MEM    : S3;
5283 %}
5284 
5285 // Conditional move reg-reg
5286 pipe_class pipe_cmplt( rRegI p, rRegI q, rRegI y ) %{
5287     instruction_count(4);
5288     y      : S4(read);
5289     q      : S3(read);
5290     p      : S3(read);
5291     DECODE : S0(4);     // any decoder
5292 %}
5293 
5294 // Conditional move reg-reg
5295 pipe_class pipe_cmov_reg( rRegI dst, rRegI src, eFlagsReg cr ) %{
5296     single_instruction;
5297     dst    : S4(write);
5298     src    : S3(read);
5299     cr     : S3(read);
5300     DECODE : S0;        // any decoder
5301 %}
5302 
5303 // Conditional move reg-mem
5304 pipe_class pipe_cmov_mem( eFlagsReg cr, rRegI dst, memory src) %{
5305     single_instruction;
5306     dst    : S4(write);
5307     src    : S3(read);
5308     cr     : S3(read);
5309     DECODE : S0;        // any decoder
5310     MEM    : S3;
5311 %}
5312 
5313 // Conditional move reg-reg long
5314 pipe_class pipe_cmov_reg_long( eFlagsReg cr, eRegL dst, eRegL src) %{
5315     single_instruction;
5316     dst    : S4(write);
5317     src    : S3(read);
5318     cr     : S3(read);
5319     DECODE : S0(2);     // any 2 decoders
5320 %}
5321 
5322 // Conditional move double reg-reg
5323 pipe_class pipe_cmovDPR_reg( eFlagsReg cr, regDPR1 dst, regDPR src) %{
5324     single_instruction;
5325     dst    : S4(write);
5326     src    : S3(read);
5327     cr     : S3(read);
5328     DECODE : S0;        // any decoder
5329 %}
5330 
5331 // Float reg-reg operation
5332 pipe_class fpu_reg(regDPR dst) %{
5333     instruction_count(2);
5334     dst    : S3(read);
5335     DECODE : S0(2);     // any 2 decoders
5336     FPU    : S3;
5337 %}
5338 
5339 // Float reg-reg operation
5340 pipe_class fpu_reg_reg(regDPR dst, regDPR src) %{
5341     instruction_count(2);
5342     dst    : S4(write);
5343     src    : S3(read);
5344     DECODE : S0(2);     // any 2 decoders
5345     FPU    : S3;
5346 %}
5347 
5348 // Float reg-reg operation
5349 pipe_class fpu_reg_reg_reg(regDPR dst, regDPR src1, regDPR src2) %{
5350     instruction_count(3);
5351     dst    : S4(write);
5352     src1   : S3(read);
5353     src2   : S3(read);
5354     DECODE : S0(3);     // any 3 decoders
5355     FPU    : S3(2);
5356 %}
5357 
5358 // Float reg-reg operation
5359 pipe_class fpu_reg_reg_reg_reg(regDPR dst, regDPR src1, regDPR src2, regDPR src3) %{
5360     instruction_count(4);
5361     dst    : S4(write);
5362     src1   : S3(read);
5363     src2   : S3(read);
5364     src3   : S3(read);
5365     DECODE : S0(4);     // any 3 decoders
5366     FPU    : S3(2);
5367 %}
5368 
5369 // Float reg-reg operation
5370 pipe_class fpu_reg_mem_reg_reg(regDPR dst, memory src1, regDPR src2, regDPR src3) %{
5371     instruction_count(4);
5372     dst    : S4(write);
5373     src1   : S3(read);
5374     src2   : S3(read);
5375     src3   : S3(read);
5376     DECODE : S1(3);     // any 3 decoders
5377     D0     : S0;        // Big decoder only
5378     FPU    : S3(2);
5379     MEM    : S3;
5380 %}
5381 
5382 // Float reg-mem operation
5383 pipe_class fpu_reg_mem(regDPR dst, memory mem) %{
5384     instruction_count(2);
5385     dst    : S5(write);
5386     mem    : S3(read);
5387     D0     : S0;        // big decoder only
5388     DECODE : S1;        // any decoder for FPU POP
5389     FPU    : S4;
5390     MEM    : S3;        // any mem
5391 %}
5392 
5393 // Float reg-mem operation
5394 pipe_class fpu_reg_reg_mem(regDPR dst, regDPR src1, memory mem) %{
5395     instruction_count(3);
5396     dst    : S5(write);
5397     src1   : S3(read);
5398     mem    : S3(read);
5399     D0     : S0;        // big decoder only
5400     DECODE : S1(2);     // any decoder for FPU POP
5401     FPU    : S4;
5402     MEM    : S3;        // any mem
5403 %}
5404 
5405 // Float mem-reg operation
5406 pipe_class fpu_mem_reg(memory mem, regDPR src) %{
5407     instruction_count(2);
5408     src    : S5(read);
5409     mem    : S3(read);
5410     DECODE : S0;        // any decoder for FPU PUSH
5411     D0     : S1;        // big decoder only
5412     FPU    : S4;
5413     MEM    : S3;        // any mem
5414 %}
5415 
5416 pipe_class fpu_mem_reg_reg(memory mem, regDPR src1, regDPR src2) %{
5417     instruction_count(3);
5418     src1   : S3(read);
5419     src2   : S3(read);
5420     mem    : S3(read);
5421     DECODE : S0(2);     // any decoder for FPU PUSH
5422     D0     : S1;        // big decoder only
5423     FPU    : S4;
5424     MEM    : S3;        // any mem
5425 %}
5426 
5427 pipe_class fpu_mem_reg_mem(memory mem, regDPR src1, memory src2) %{
5428     instruction_count(3);
5429     src1   : S3(read);
5430     src2   : S3(read);
5431     mem    : S4(read);
5432     DECODE : S0;        // any decoder for FPU PUSH
5433     D0     : S0(2);     // big decoder only
5434     FPU    : S4;
5435     MEM    : S3(2);     // any mem
5436 %}
5437 
5438 pipe_class fpu_mem_mem(memory dst, memory src1) %{
5439     instruction_count(2);
5440     src1   : S3(read);
5441     dst    : S4(read);
5442     D0     : S0(2);     // big decoder only
5443     MEM    : S3(2);     // any mem
5444 %}
5445 
5446 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2) %{
5447     instruction_count(3);
5448     src1   : S3(read);
5449     src2   : S3(read);
5450     dst    : S4(read);
5451     D0     : S0(3);     // big decoder only
5452     FPU    : S4;
5453     MEM    : S3(3);     // any mem
5454 %}
5455 
5456 pipe_class fpu_mem_reg_con(memory mem, regDPR src1) %{
5457     instruction_count(3);
5458     src1   : S4(read);
5459     mem    : S4(read);
5460     DECODE : S0;        // any decoder for FPU PUSH
5461     D0     : S0(2);     // big decoder only
5462     FPU    : S4;
5463     MEM    : S3(2);     // any mem
5464 %}
5465 
5466 // Float load constant
5467 pipe_class fpu_reg_con(regDPR dst) %{
5468     instruction_count(2);
5469     dst    : S5(write);
5470     D0     : S0;        // big decoder only for the load
5471     DECODE : S1;        // any decoder for FPU POP
5472     FPU    : S4;
5473     MEM    : S3;        // any mem
5474 %}
5475 
5476 // Float load constant
5477 pipe_class fpu_reg_reg_con(regDPR dst, regDPR src) %{
5478     instruction_count(3);
5479     dst    : S5(write);
5480     src    : S3(read);
5481     D0     : S0;        // big decoder only for the load
5482     DECODE : S1(2);     // any decoder for FPU POP
5483     FPU    : S4;
5484     MEM    : S3;        // any mem
5485 %}
5486 
5487 // UnConditional branch
5488 pipe_class pipe_jmp( label labl ) %{
5489     single_instruction;
5490     BR   : S3;
5491 %}
5492 
5493 // Conditional branch
5494 pipe_class pipe_jcc( cmpOp cmp, eFlagsReg cr, label labl ) %{
5495     single_instruction;
5496     cr    : S1(read);
5497     BR    : S3;
5498 %}
5499 
5500 // Allocation idiom
5501 pipe_class pipe_cmpxchg( eRegP dst, eRegP heap_ptr ) %{
5502     instruction_count(1); force_serialization;
5503     fixed_latency(6);
5504     heap_ptr : S3(read);
5505     DECODE   : S0(3);
5506     D0       : S2;
5507     MEM      : S3;
5508     ALU      : S3(2);
5509     dst      : S5(write);
5510     BR       : S5;
5511 %}
5512 
5513 // Generic big/slow expanded idiom
5514 pipe_class pipe_slow(  ) %{
5515     instruction_count(10); multiple_bundles; force_serialization;
5516     fixed_latency(100);
5517     D0  : S0(2);
5518     MEM : S3(2);
5519 %}
5520 
5521 // The real do-nothing guy
5522 pipe_class empty( ) %{
5523     instruction_count(0);
5524 %}
5525 
5526 // Define the class for the Nop node
5527 define %{
5528    MachNop = empty;
5529 %}
5530 
5531 %}
5532 
5533 //----------INSTRUCTIONS-------------------------------------------------------
5534 //
5535 // match      -- States which machine-independent subtree may be replaced
5536 //               by this instruction.
5537 // ins_cost   -- The estimated cost of this instruction is used by instruction
5538 //               selection to identify a minimum cost tree of machine
5539 //               instructions that matches a tree of machine-independent
5540 //               instructions.
5541 // format     -- A string providing the disassembly for this instruction.
5542 //               The value of an instruction's operand may be inserted
5543 //               by referring to it with a '$' prefix.
5544 // opcode     -- Three instruction opcodes may be provided.  These are referred
5545 //               to within an encode class as $primary, $secondary, and $tertiary
5546 //               respectively.  The primary opcode is commonly used to
5547 //               indicate the type of machine instruction, while secondary
5548 //               and tertiary are often used for prefix options or addressing
5549 //               modes.
5550 // ins_encode -- A list of encode classes with parameters. The encode class
5551 //               name must have been defined in an 'enc_class' specification
5552 //               in the encode section of the architecture description.
5553 
5554 //----------BSWAP-Instruction--------------------------------------------------
5555 instruct bytes_reverse_int(rRegI dst) %{
5556   match(Set dst (ReverseBytesI dst));
5557 
5558   format %{ "BSWAP  $dst" %}
5559   opcode(0x0F, 0xC8);
5560   ins_encode( OpcP, OpcSReg(dst) );
5561   ins_pipe( ialu_reg );
5562 %}
5563 
5564 instruct bytes_reverse_long(eRegL dst) %{
5565   match(Set dst (ReverseBytesL dst));
5566 
5567   format %{ "BSWAP  $dst.lo\n\t"
5568             "BSWAP  $dst.hi\n\t"
5569             "XCHG   $dst.lo $dst.hi" %}
5570 
5571   ins_cost(125);
5572   ins_encode( bswap_long_bytes(dst) );
5573   ins_pipe( ialu_reg_reg);
5574 %}
5575 
5576 instruct bytes_reverse_unsigned_short(rRegI dst, eFlagsReg cr) %{
5577   match(Set dst (ReverseBytesUS dst));
5578   effect(KILL cr);
5579 
5580   format %{ "BSWAP  $dst\n\t" 
5581             "SHR    $dst,16\n\t" %}
5582   ins_encode %{
5583     __ bswapl($dst$$Register);
5584     __ shrl($dst$$Register, 16); 
5585   %}
5586   ins_pipe( ialu_reg );
5587 %}
5588 
5589 instruct bytes_reverse_short(rRegI dst, eFlagsReg cr) %{
5590   match(Set dst (ReverseBytesS dst));
5591   effect(KILL cr);
5592 
5593   format %{ "BSWAP  $dst\n\t" 
5594             "SAR    $dst,16\n\t" %}
5595   ins_encode %{
5596     __ bswapl($dst$$Register);
5597     __ sarl($dst$$Register, 16); 
5598   %}
5599   ins_pipe( ialu_reg );
5600 %}
5601 
5602 
5603 //---------- Zeros Count Instructions ------------------------------------------
5604 
5605 instruct countLeadingZerosI(rRegI dst, rRegI src, eFlagsReg cr) %{
5606   predicate(UseCountLeadingZerosInstruction);
5607   match(Set dst (CountLeadingZerosI src));
5608   effect(KILL cr);
5609 
5610   format %{ "LZCNT  $dst, $src\t# count leading zeros (int)" %}
5611   ins_encode %{
5612     __ lzcntl($dst$$Register, $src$$Register);
5613   %}
5614   ins_pipe(ialu_reg);
5615 %}
5616 
5617 instruct countLeadingZerosI_bsr(rRegI dst, rRegI src, eFlagsReg cr) %{
5618   predicate(!UseCountLeadingZerosInstruction);
5619   match(Set dst (CountLeadingZerosI src));
5620   effect(KILL cr);
5621 
5622   format %{ "BSR    $dst, $src\t# count leading zeros (int)\n\t"
5623             "JNZ    skip\n\t"
5624             "MOV    $dst, -1\n"
5625       "skip:\n\t"
5626             "NEG    $dst\n\t"
5627             "ADD    $dst, 31" %}
5628   ins_encode %{
5629     Register Rdst = $dst$$Register;
5630     Register Rsrc = $src$$Register;
5631     Label skip;
5632     __ bsrl(Rdst, Rsrc);
5633     __ jccb(Assembler::notZero, skip);
5634     __ movl(Rdst, -1);
5635     __ bind(skip);
5636     __ negl(Rdst);
5637     __ addl(Rdst, BitsPerInt - 1);
5638   %}
5639   ins_pipe(ialu_reg);
5640 %}
5641 
5642 instruct countLeadingZerosL(rRegI dst, eRegL src, eFlagsReg cr) %{
5643   predicate(UseCountLeadingZerosInstruction);
5644   match(Set dst (CountLeadingZerosL src));
5645   effect(TEMP dst, KILL cr);
5646 
5647   format %{ "LZCNT  $dst, $src.hi\t# count leading zeros (long)\n\t"
5648             "JNC    done\n\t"
5649             "LZCNT  $dst, $src.lo\n\t"
5650             "ADD    $dst, 32\n"
5651       "done:" %}
5652   ins_encode %{
5653     Register Rdst = $dst$$Register;
5654     Register Rsrc = $src$$Register;
5655     Label done;
5656     __ lzcntl(Rdst, HIGH_FROM_LOW(Rsrc));
5657     __ jccb(Assembler::carryClear, done);
5658     __ lzcntl(Rdst, Rsrc);
5659     __ addl(Rdst, BitsPerInt);
5660     __ bind(done);
5661   %}
5662   ins_pipe(ialu_reg);
5663 %}
5664 
5665 instruct countLeadingZerosL_bsr(rRegI dst, eRegL src, eFlagsReg cr) %{
5666   predicate(!UseCountLeadingZerosInstruction);
5667   match(Set dst (CountLeadingZerosL src));
5668   effect(TEMP dst, KILL cr);
5669 
5670   format %{ "BSR    $dst, $src.hi\t# count leading zeros (long)\n\t"
5671             "JZ     msw_is_zero\n\t"
5672             "ADD    $dst, 32\n\t"
5673             "JMP    not_zero\n"
5674       "msw_is_zero:\n\t"
5675             "BSR    $dst, $src.lo\n\t"
5676             "JNZ    not_zero\n\t"
5677             "MOV    $dst, -1\n"
5678       "not_zero:\n\t"
5679             "NEG    $dst\n\t"
5680             "ADD    $dst, 63\n" %}
5681  ins_encode %{
5682     Register Rdst = $dst$$Register;
5683     Register Rsrc = $src$$Register;
5684     Label msw_is_zero;
5685     Label not_zero;
5686     __ bsrl(Rdst, HIGH_FROM_LOW(Rsrc));
5687     __ jccb(Assembler::zero, msw_is_zero);
5688     __ addl(Rdst, BitsPerInt);
5689     __ jmpb(not_zero);
5690     __ bind(msw_is_zero);
5691     __ bsrl(Rdst, Rsrc);
5692     __ jccb(Assembler::notZero, not_zero);
5693     __ movl(Rdst, -1);
5694     __ bind(not_zero);
5695     __ negl(Rdst);
5696     __ addl(Rdst, BitsPerLong - 1);
5697   %}
5698   ins_pipe(ialu_reg);
5699 %}
5700 
5701 instruct countTrailingZerosI(rRegI dst, rRegI src, eFlagsReg cr) %{
5702   match(Set dst (CountTrailingZerosI src));
5703   effect(KILL cr);
5704 
5705   format %{ "BSF    $dst, $src\t# count trailing zeros (int)\n\t"
5706             "JNZ    done\n\t"
5707             "MOV    $dst, 32\n"
5708       "done:" %}
5709   ins_encode %{
5710     Register Rdst = $dst$$Register;
5711     Label done;
5712     __ bsfl(Rdst, $src$$Register);
5713     __ jccb(Assembler::notZero, done);
5714     __ movl(Rdst, BitsPerInt);
5715     __ bind(done);
5716   %}
5717   ins_pipe(ialu_reg);
5718 %}
5719 
5720 instruct countTrailingZerosL(rRegI dst, eRegL src, eFlagsReg cr) %{
5721   match(Set dst (CountTrailingZerosL src));
5722   effect(TEMP dst, KILL cr);
5723 
5724   format %{ "BSF    $dst, $src.lo\t# count trailing zeros (long)\n\t"
5725             "JNZ    done\n\t"
5726             "BSF    $dst, $src.hi\n\t"
5727             "JNZ    msw_not_zero\n\t"
5728             "MOV    $dst, 32\n"
5729       "msw_not_zero:\n\t"
5730             "ADD    $dst, 32\n"
5731       "done:" %}
5732   ins_encode %{
5733     Register Rdst = $dst$$Register;
5734     Register Rsrc = $src$$Register;
5735     Label msw_not_zero;
5736     Label done;
5737     __ bsfl(Rdst, Rsrc);
5738     __ jccb(Assembler::notZero, done);
5739     __ bsfl(Rdst, HIGH_FROM_LOW(Rsrc));
5740     __ jccb(Assembler::notZero, msw_not_zero);
5741     __ movl(Rdst, BitsPerInt);
5742     __ bind(msw_not_zero);
5743     __ addl(Rdst, BitsPerInt);
5744     __ bind(done);
5745   %}
5746   ins_pipe(ialu_reg);
5747 %}
5748 
5749 
5750 //---------- Population Count Instructions -------------------------------------
5751 
5752 instruct popCountI(rRegI dst, rRegI src, eFlagsReg cr) %{
5753   predicate(UsePopCountInstruction);
5754   match(Set dst (PopCountI src));
5755   effect(KILL cr);
5756 
5757   format %{ "POPCNT $dst, $src" %}
5758   ins_encode %{
5759     __ popcntl($dst$$Register, $src$$Register);
5760   %}
5761   ins_pipe(ialu_reg);
5762 %}
5763 
5764 instruct popCountI_mem(rRegI dst, memory mem, eFlagsReg cr) %{
5765   predicate(UsePopCountInstruction);
5766   match(Set dst (PopCountI (LoadI mem)));
5767   effect(KILL cr);
5768 
5769   format %{ "POPCNT $dst, $mem" %}
5770   ins_encode %{
5771     __ popcntl($dst$$Register, $mem$$Address);
5772   %}
5773   ins_pipe(ialu_reg);
5774 %}
5775 
5776 // Note: Long.bitCount(long) returns an int.
5777 instruct popCountL(rRegI dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
5778   predicate(UsePopCountInstruction);
5779   match(Set dst (PopCountL src));
5780   effect(KILL cr, TEMP tmp, TEMP dst);
5781 
5782   format %{ "POPCNT $dst, $src.lo\n\t"
5783             "POPCNT $tmp, $src.hi\n\t"
5784             "ADD    $dst, $tmp" %}
5785   ins_encode %{
5786     __ popcntl($dst$$Register, $src$$Register);
5787     __ popcntl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
5788     __ addl($dst$$Register, $tmp$$Register);
5789   %}
5790   ins_pipe(ialu_reg);
5791 %}
5792 
5793 // Note: Long.bitCount(long) returns an int.
5794 instruct popCountL_mem(rRegI dst, memory mem, rRegI tmp, eFlagsReg cr) %{
5795   predicate(UsePopCountInstruction);
5796   match(Set dst (PopCountL (LoadL mem)));
5797   effect(KILL cr, TEMP tmp, TEMP dst);
5798 
5799   format %{ "POPCNT $dst, $mem\n\t"
5800             "POPCNT $tmp, $mem+4\n\t"
5801             "ADD    $dst, $tmp" %}
5802   ins_encode %{
5803     //__ popcntl($dst$$Register, $mem$$Address$$first);
5804     //__ popcntl($tmp$$Register, $mem$$Address$$second);
5805     __ popcntl($dst$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, relocInfo::none));
5806     __ popcntl($tmp$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, relocInfo::none));
5807     __ addl($dst$$Register, $tmp$$Register);
5808   %}
5809   ins_pipe(ialu_reg);
5810 %}
5811 
5812 
5813 //----------Load/Store/Move Instructions---------------------------------------
5814 //----------Load Instructions--------------------------------------------------
5815 // Load Byte (8bit signed)
5816 instruct loadB(xRegI dst, memory mem) %{
5817   match(Set dst (LoadB mem));
5818 
5819   ins_cost(125);
5820   format %{ "MOVSX8 $dst,$mem\t# byte" %}
5821 
5822   ins_encode %{
5823     __ movsbl($dst$$Register, $mem$$Address);
5824   %}
5825 
5826   ins_pipe(ialu_reg_mem);
5827 %}
5828 
5829 // Load Byte (8bit signed) into Long Register
5830 instruct loadB2L(eRegL dst, memory mem, eFlagsReg cr) %{
5831   match(Set dst (ConvI2L (LoadB mem)));
5832   effect(KILL cr);
5833 
5834   ins_cost(375);
5835   format %{ "MOVSX8 $dst.lo,$mem\t# byte -> long\n\t"
5836             "MOV    $dst.hi,$dst.lo\n\t"
5837             "SAR    $dst.hi,7" %}
5838 
5839   ins_encode %{
5840     __ movsbl($dst$$Register, $mem$$Address);
5841     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
5842     __ sarl(HIGH_FROM_LOW($dst$$Register), 7); // 24+1 MSB are already signed extended.
5843   %}
5844 
5845   ins_pipe(ialu_reg_mem);
5846 %}
5847 
5848 // Load Unsigned Byte (8bit UNsigned)
5849 instruct loadUB(xRegI dst, memory mem) %{
5850   match(Set dst (LoadUB mem));
5851 
5852   ins_cost(125);
5853   format %{ "MOVZX8 $dst,$mem\t# ubyte -> int" %}
5854 
5855   ins_encode %{
5856     __ movzbl($dst$$Register, $mem$$Address);
5857   %}
5858 
5859   ins_pipe(ialu_reg_mem);
5860 %}
5861 
5862 // Load Unsigned Byte (8 bit UNsigned) into Long Register
5863 instruct loadUB2L(eRegL dst, memory mem, eFlagsReg cr) %{
5864   match(Set dst (ConvI2L (LoadUB mem)));
5865   effect(KILL cr);
5866 
5867   ins_cost(250);
5868   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte -> long\n\t"
5869             "XOR    $dst.hi,$dst.hi" %}
5870 
5871   ins_encode %{
5872     Register Rdst = $dst$$Register;
5873     __ movzbl(Rdst, $mem$$Address);
5874     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
5875   %}
5876 
5877   ins_pipe(ialu_reg_mem);
5878 %}
5879 
5880 // Load Unsigned Byte (8 bit UNsigned) with mask into Long Register
5881 instruct loadUB2L_immI8(eRegL dst, memory mem, immI8 mask, eFlagsReg cr) %{
5882   match(Set dst (ConvI2L (AndI (LoadUB mem) mask)));
5883   effect(KILL cr);
5884 
5885   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte & 8-bit mask -> long\n\t"
5886             "XOR    $dst.hi,$dst.hi\n\t"
5887             "AND    $dst.lo,$mask" %}
5888   ins_encode %{
5889     Register Rdst = $dst$$Register;
5890     __ movzbl(Rdst, $mem$$Address);
5891     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
5892     __ andl(Rdst, $mask$$constant);
5893   %}
5894   ins_pipe(ialu_reg_mem);
5895 %}
5896 
5897 // Load Short (16bit signed)
5898 instruct loadS(rRegI dst, memory mem) %{
5899   match(Set dst (LoadS mem));
5900 
5901   ins_cost(125);
5902   format %{ "MOVSX  $dst,$mem\t# short" %}
5903 
5904   ins_encode %{
5905     __ movswl($dst$$Register, $mem$$Address);
5906   %}
5907 
5908   ins_pipe(ialu_reg_mem);
5909 %}
5910 
5911 // Load Short (16 bit signed) to Byte (8 bit signed)
5912 instruct loadS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
5913   match(Set dst (RShiftI (LShiftI (LoadS mem) twentyfour) twentyfour));
5914 
5915   ins_cost(125);
5916   format %{ "MOVSX  $dst, $mem\t# short -> byte" %}
5917   ins_encode %{
5918     __ movsbl($dst$$Register, $mem$$Address);
5919   %}
5920   ins_pipe(ialu_reg_mem);
5921 %}
5922 
5923 // Load Short (16bit signed) into Long Register
5924 instruct loadS2L(eRegL dst, memory mem, eFlagsReg cr) %{
5925   match(Set dst (ConvI2L (LoadS mem)));
5926   effect(KILL cr);
5927 
5928   ins_cost(375);
5929   format %{ "MOVSX  $dst.lo,$mem\t# short -> long\n\t"
5930             "MOV    $dst.hi,$dst.lo\n\t"
5931             "SAR    $dst.hi,15" %}
5932 
5933   ins_encode %{
5934     __ movswl($dst$$Register, $mem$$Address);
5935     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
5936     __ sarl(HIGH_FROM_LOW($dst$$Register), 15); // 16+1 MSB are already signed extended.
5937   %}
5938 
5939   ins_pipe(ialu_reg_mem);
5940 %}
5941 
5942 // Load Unsigned Short/Char (16bit unsigned)
5943 instruct loadUS(rRegI dst, memory mem) %{
5944   match(Set dst (LoadUS mem));
5945 
5946   ins_cost(125);
5947   format %{ "MOVZX  $dst,$mem\t# ushort/char -> int" %}
5948 
5949   ins_encode %{
5950     __ movzwl($dst$$Register, $mem$$Address);
5951   %}
5952 
5953   ins_pipe(ialu_reg_mem);
5954 %}
5955 
5956 // Load Unsigned Short/Char (16 bit UNsigned) to Byte (8 bit signed)
5957 instruct loadUS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
5958   match(Set dst (RShiftI (LShiftI (LoadUS mem) twentyfour) twentyfour));
5959 
5960   ins_cost(125);
5961   format %{ "MOVSX  $dst, $mem\t# ushort -> byte" %}
5962   ins_encode %{
5963     __ movsbl($dst$$Register, $mem$$Address);
5964   %}
5965   ins_pipe(ialu_reg_mem);
5966 %}
5967 
5968 // Load Unsigned Short/Char (16 bit UNsigned) into Long Register
5969 instruct loadUS2L(eRegL dst, memory mem, eFlagsReg cr) %{
5970   match(Set dst (ConvI2L (LoadUS mem)));
5971   effect(KILL cr);
5972 
5973   ins_cost(250);
5974   format %{ "MOVZX  $dst.lo,$mem\t# ushort/char -> long\n\t"
5975             "XOR    $dst.hi,$dst.hi" %}
5976 
5977   ins_encode %{
5978     __ movzwl($dst$$Register, $mem$$Address);
5979     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
5980   %}
5981 
5982   ins_pipe(ialu_reg_mem);
5983 %}
5984 
5985 // Load Unsigned Short/Char (16 bit UNsigned) with mask 0xFF into Long Register
5986 instruct loadUS2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
5987   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
5988   effect(KILL cr);
5989 
5990   format %{ "MOVZX8 $dst.lo,$mem\t# ushort/char & 0xFF -> long\n\t"
5991             "XOR    $dst.hi,$dst.hi" %}
5992   ins_encode %{
5993     Register Rdst = $dst$$Register;
5994     __ movzbl(Rdst, $mem$$Address);
5995     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
5996   %}
5997   ins_pipe(ialu_reg_mem);
5998 %}
5999 
6000 // Load Unsigned Short/Char (16 bit UNsigned) with a 16-bit mask into Long Register
6001 instruct loadUS2L_immI16(eRegL dst, memory mem, immI16 mask, eFlagsReg cr) %{
6002   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
6003   effect(KILL cr);
6004 
6005   format %{ "MOVZX  $dst.lo, $mem\t# ushort/char & 16-bit mask -> long\n\t"
6006             "XOR    $dst.hi,$dst.hi\n\t"
6007             "AND    $dst.lo,$mask" %}
6008   ins_encode %{
6009     Register Rdst = $dst$$Register;
6010     __ movzwl(Rdst, $mem$$Address);
6011     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
6012     __ andl(Rdst, $mask$$constant);
6013   %}
6014   ins_pipe(ialu_reg_mem);
6015 %}
6016 
6017 // Load Integer
6018 instruct loadI(rRegI dst, memory mem) %{
6019   match(Set dst (LoadI mem));
6020 
6021   ins_cost(125);
6022   format %{ "MOV    $dst,$mem\t# int" %}
6023 
6024   ins_encode %{
6025     __ movl($dst$$Register, $mem$$Address);
6026   %}
6027 
6028   ins_pipe(ialu_reg_mem);
6029 %}
6030 
6031 // Load Integer (32 bit signed) to Byte (8 bit signed)
6032 instruct loadI2B(rRegI dst, memory mem, immI_24 twentyfour) %{
6033   match(Set dst (RShiftI (LShiftI (LoadI mem) twentyfour) twentyfour));
6034 
6035   ins_cost(125);
6036   format %{ "MOVSX  $dst, $mem\t# int -> byte" %}
6037   ins_encode %{
6038     __ movsbl($dst$$Register, $mem$$Address);
6039   %}
6040   ins_pipe(ialu_reg_mem);
6041 %}
6042 
6043 // Load Integer (32 bit signed) to Unsigned Byte (8 bit UNsigned)
6044 instruct loadI2UB(rRegI dst, memory mem, immI_255 mask) %{
6045   match(Set dst (AndI (LoadI mem) mask));
6046 
6047   ins_cost(125);
6048   format %{ "MOVZX  $dst, $mem\t# int -> ubyte" %}
6049   ins_encode %{
6050     __ movzbl($dst$$Register, $mem$$Address);
6051   %}
6052   ins_pipe(ialu_reg_mem);
6053 %}
6054 
6055 // Load Integer (32 bit signed) to Short (16 bit signed)
6056 instruct loadI2S(rRegI dst, memory mem, immI_16 sixteen) %{
6057   match(Set dst (RShiftI (LShiftI (LoadI mem) sixteen) sixteen));
6058 
6059   ins_cost(125);
6060   format %{ "MOVSX  $dst, $mem\t# int -> short" %}
6061   ins_encode %{
6062     __ movswl($dst$$Register, $mem$$Address);
6063   %}
6064   ins_pipe(ialu_reg_mem);
6065 %}
6066 
6067 // Load Integer (32 bit signed) to Unsigned Short/Char (16 bit UNsigned)
6068 instruct loadI2US(rRegI dst, memory mem, immI_65535 mask) %{
6069   match(Set dst (AndI (LoadI mem) mask));
6070 
6071   ins_cost(125);
6072   format %{ "MOVZX  $dst, $mem\t# int -> ushort/char" %}
6073   ins_encode %{
6074     __ movzwl($dst$$Register, $mem$$Address);
6075   %}
6076   ins_pipe(ialu_reg_mem);
6077 %}
6078 
6079 // Load Integer into Long Register
6080 instruct loadI2L(eRegL dst, memory mem, eFlagsReg cr) %{
6081   match(Set dst (ConvI2L (LoadI mem)));
6082   effect(KILL cr);
6083 
6084   ins_cost(375);
6085   format %{ "MOV    $dst.lo,$mem\t# int -> long\n\t"
6086             "MOV    $dst.hi,$dst.lo\n\t"
6087             "SAR    $dst.hi,31" %}
6088 
6089   ins_encode %{
6090     __ movl($dst$$Register, $mem$$Address);
6091     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
6092     __ sarl(HIGH_FROM_LOW($dst$$Register), 31);
6093   %}
6094 
6095   ins_pipe(ialu_reg_mem);
6096 %}
6097 
6098 // Load Integer with mask 0xFF into Long Register
6099 instruct loadI2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
6100   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6101   effect(KILL cr);
6102 
6103   format %{ "MOVZX8 $dst.lo,$mem\t# int & 0xFF -> long\n\t"
6104             "XOR    $dst.hi,$dst.hi" %}
6105   ins_encode %{
6106     Register Rdst = $dst$$Register;
6107     __ movzbl(Rdst, $mem$$Address);
6108     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
6109   %}
6110   ins_pipe(ialu_reg_mem);
6111 %}
6112 
6113 // Load Integer with mask 0xFFFF into Long Register
6114 instruct loadI2L_immI_65535(eRegL dst, memory mem, immI_65535 mask, eFlagsReg cr) %{
6115   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6116   effect(KILL cr);
6117 
6118   format %{ "MOVZX  $dst.lo,$mem\t# int & 0xFFFF -> long\n\t"
6119             "XOR    $dst.hi,$dst.hi" %}
6120   ins_encode %{
6121     Register Rdst = $dst$$Register;
6122     __ movzwl(Rdst, $mem$$Address);
6123     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
6124   %}
6125   ins_pipe(ialu_reg_mem);
6126 %}
6127 
6128 // Load Integer with 31-bit mask into Long Register
6129 instruct loadI2L_immU31(eRegL dst, memory mem, immU31 mask, eFlagsReg cr) %{
6130   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6131   effect(KILL cr);
6132 
6133   format %{ "MOV    $dst.lo,$mem\t# int & 31-bit mask -> long\n\t"
6134             "XOR    $dst.hi,$dst.hi\n\t"
6135             "AND    $dst.lo,$mask" %}
6136   ins_encode %{
6137     Register Rdst = $dst$$Register;
6138     __ movl(Rdst, $mem$$Address);
6139     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
6140     __ andl(Rdst, $mask$$constant);
6141   %}
6142   ins_pipe(ialu_reg_mem);
6143 %}
6144 
6145 // Load Unsigned Integer into Long Register
6146 instruct loadUI2L(eRegL dst, memory mem, immL_32bits mask, eFlagsReg cr) %{
6147   match(Set dst (AndL (ConvI2L (LoadI mem)) mask));
6148   effect(KILL cr);
6149 
6150   ins_cost(250);
6151   format %{ "MOV    $dst.lo,$mem\t# uint -> long\n\t"
6152             "XOR    $dst.hi,$dst.hi" %}
6153 
6154   ins_encode %{
6155     __ movl($dst$$Register, $mem$$Address);
6156     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
6157   %}
6158 
6159   ins_pipe(ialu_reg_mem);
6160 %}
6161 
6162 // Load Long.  Cannot clobber address while loading, so restrict address
6163 // register to ESI
6164 instruct loadL(eRegL dst, load_long_memory mem) %{
6165   predicate(!((LoadLNode*)n)->require_atomic_access());
6166   match(Set dst (LoadL mem));
6167 
6168   ins_cost(250);
6169   format %{ "MOV    $dst.lo,$mem\t# long\n\t"
6170             "MOV    $dst.hi,$mem+4" %}
6171 
6172   ins_encode %{
6173     Address Amemlo = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, relocInfo::none);
6174     Address Amemhi = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, relocInfo::none);
6175     __ movl($dst$$Register, Amemlo);
6176     __ movl(HIGH_FROM_LOW($dst$$Register), Amemhi);
6177   %}
6178 
6179   ins_pipe(ialu_reg_long_mem);
6180 %}
6181 
6182 // Volatile Load Long.  Must be atomic, so do 64-bit FILD
6183 // then store it down to the stack and reload on the int
6184 // side.
6185 instruct loadL_volatile(stackSlotL dst, memory mem) %{
6186   predicate(UseSSE<=1 && ((LoadLNode*)n)->require_atomic_access());
6187   match(Set dst (LoadL mem));
6188 
6189   ins_cost(200);
6190   format %{ "FILD   $mem\t# Atomic volatile long load\n\t"
6191             "FISTp  $dst" %}
6192   ins_encode(enc_loadL_volatile(mem,dst));
6193   ins_pipe( fpu_reg_mem );
6194 %}
6195 
6196 instruct loadLX_volatile(stackSlotL dst, memory mem, regD tmp) %{
6197   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
6198   match(Set dst (LoadL mem));
6199   effect(TEMP tmp);
6200   ins_cost(180);
6201   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
6202             "MOVSD  $dst,$tmp" %}
6203   ins_encode %{
6204     __ movdbl($tmp$$XMMRegister, $mem$$Address);
6205     __ movdbl(Address(rsp, $dst$$disp), $tmp$$XMMRegister);
6206   %}
6207   ins_pipe( pipe_slow );
6208 %}
6209 
6210 instruct loadLX_reg_volatile(eRegL dst, memory mem, regD tmp) %{
6211   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
6212   match(Set dst (LoadL mem));
6213   effect(TEMP tmp);
6214   ins_cost(160);
6215   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
6216             "MOVD   $dst.lo,$tmp\n\t"
6217             "PSRLQ  $tmp,32\n\t"
6218             "MOVD   $dst.hi,$tmp" %}
6219   ins_encode %{
6220     __ movdbl($tmp$$XMMRegister, $mem$$Address);
6221     __ movdl($dst$$Register, $tmp$$XMMRegister);
6222     __ psrlq($tmp$$XMMRegister, 32);
6223     __ movdl(HIGH_FROM_LOW($dst$$Register), $tmp$$XMMRegister);
6224   %}
6225   ins_pipe( pipe_slow );
6226 %}
6227 
6228 // Load Range
6229 instruct loadRange(rRegI dst, memory mem) %{
6230   match(Set dst (LoadRange mem));
6231 
6232   ins_cost(125);
6233   format %{ "MOV    $dst,$mem" %}
6234   opcode(0x8B);
6235   ins_encode( OpcP, RegMem(dst,mem));
6236   ins_pipe( ialu_reg_mem );
6237 %}
6238 
6239 
6240 // Load Pointer
6241 instruct loadP(eRegP dst, memory mem) %{
6242   match(Set dst (LoadP mem));
6243 
6244   ins_cost(125);
6245   format %{ "MOV    $dst,$mem" %}
6246   opcode(0x8B);
6247   ins_encode( OpcP, RegMem(dst,mem));
6248   ins_pipe( ialu_reg_mem );
6249 %}
6250 
6251 // Load Klass Pointer
6252 instruct loadKlass(eRegP dst, memory mem) %{
6253   match(Set dst (LoadKlass mem));
6254 
6255   ins_cost(125);
6256   format %{ "MOV    $dst,$mem" %}
6257   opcode(0x8B);
6258   ins_encode( OpcP, RegMem(dst,mem));
6259   ins_pipe( ialu_reg_mem );
6260 %}
6261 
6262 // Load Double
6263 instruct loadDPR(regDPR dst, memory mem) %{
6264   predicate(UseSSE<=1);
6265   match(Set dst (LoadD mem));
6266 
6267   ins_cost(150);
6268   format %{ "FLD_D  ST,$mem\n\t"
6269             "FSTP   $dst" %}
6270   opcode(0xDD);               /* DD /0 */
6271   ins_encode( OpcP, RMopc_Mem(0x00,mem),
6272               Pop_Reg_DPR(dst) );
6273   ins_pipe( fpu_reg_mem );
6274 %}
6275 
6276 // Load Double to XMM
6277 instruct loadD(regD dst, memory mem) %{
6278   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
6279   match(Set dst (LoadD mem));
6280   ins_cost(145);
6281   format %{ "MOVSD  $dst,$mem" %}
6282   ins_encode %{
6283     __ movdbl ($dst$$XMMRegister, $mem$$Address);
6284   %}
6285   ins_pipe( pipe_slow );
6286 %}
6287 
6288 instruct loadD_partial(regD dst, memory mem) %{
6289   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
6290   match(Set dst (LoadD mem));
6291   ins_cost(145);
6292   format %{ "MOVLPD $dst,$mem" %}
6293   ins_encode %{
6294     __ movdbl ($dst$$XMMRegister, $mem$$Address);
6295   %}
6296   ins_pipe( pipe_slow );
6297 %}
6298 
6299 // Load to XMM register (single-precision floating point)
6300 // MOVSS instruction
6301 instruct loadF(regF dst, memory mem) %{
6302   predicate(UseSSE>=1);
6303   match(Set dst (LoadF mem));
6304   ins_cost(145);
6305   format %{ "MOVSS  $dst,$mem" %}
6306   ins_encode %{
6307     __ movflt ($dst$$XMMRegister, $mem$$Address);
6308   %}
6309   ins_pipe( pipe_slow );
6310 %}
6311 
6312 // Load Float
6313 instruct loadFPR(regFPR dst, memory mem) %{
6314   predicate(UseSSE==0);
6315   match(Set dst (LoadF mem));
6316 
6317   ins_cost(150);
6318   format %{ "FLD_S  ST,$mem\n\t"
6319             "FSTP   $dst" %}
6320   opcode(0xD9);               /* D9 /0 */
6321   ins_encode( OpcP, RMopc_Mem(0x00,mem),
6322               Pop_Reg_FPR(dst) );
6323   ins_pipe( fpu_reg_mem );
6324 %}
6325 
6326 // Load Effective Address
6327 instruct leaP8(eRegP dst, indOffset8 mem) %{
6328   match(Set dst mem);
6329 
6330   ins_cost(110);
6331   format %{ "LEA    $dst,$mem" %}
6332   opcode(0x8D);
6333   ins_encode( OpcP, RegMem(dst,mem));
6334   ins_pipe( ialu_reg_reg_fat );
6335 %}
6336 
6337 instruct leaP32(eRegP dst, indOffset32 mem) %{
6338   match(Set dst mem);
6339 
6340   ins_cost(110);
6341   format %{ "LEA    $dst,$mem" %}
6342   opcode(0x8D);
6343   ins_encode( OpcP, RegMem(dst,mem));
6344   ins_pipe( ialu_reg_reg_fat );
6345 %}
6346 
6347 instruct leaPIdxOff(eRegP dst, indIndexOffset mem) %{
6348   match(Set dst mem);
6349 
6350   ins_cost(110);
6351   format %{ "LEA    $dst,$mem" %}
6352   opcode(0x8D);
6353   ins_encode( OpcP, RegMem(dst,mem));
6354   ins_pipe( ialu_reg_reg_fat );
6355 %}
6356 
6357 instruct leaPIdxScale(eRegP dst, indIndexScale mem) %{
6358   match(Set dst mem);
6359 
6360   ins_cost(110);
6361   format %{ "LEA    $dst,$mem" %}
6362   opcode(0x8D);
6363   ins_encode( OpcP, RegMem(dst,mem));
6364   ins_pipe( ialu_reg_reg_fat );
6365 %}
6366 
6367 instruct leaPIdxScaleOff(eRegP dst, indIndexScaleOffset mem) %{
6368   match(Set dst mem);
6369 
6370   ins_cost(110);
6371   format %{ "LEA    $dst,$mem" %}
6372   opcode(0x8D);
6373   ins_encode( OpcP, RegMem(dst,mem));
6374   ins_pipe( ialu_reg_reg_fat );
6375 %}
6376 
6377 // Load Constant
6378 instruct loadConI(rRegI dst, immI src) %{
6379   match(Set dst src);
6380 
6381   format %{ "MOV    $dst,$src" %}
6382   ins_encode( LdImmI(dst, src) );
6383   ins_pipe( ialu_reg_fat );
6384 %}
6385 
6386 // Load Constant zero
6387 instruct loadConI0(rRegI dst, immI0 src, eFlagsReg cr) %{
6388   match(Set dst src);
6389   effect(KILL cr);
6390 
6391   ins_cost(50);
6392   format %{ "XOR    $dst,$dst" %}
6393   opcode(0x33);  /* + rd */
6394   ins_encode( OpcP, RegReg( dst, dst ) );
6395   ins_pipe( ialu_reg );
6396 %}
6397 
6398 instruct loadConP(eRegP dst, immP src) %{
6399   match(Set dst src);
6400 
6401   format %{ "MOV    $dst,$src" %}
6402   opcode(0xB8);  /* + rd */
6403   ins_encode( LdImmP(dst, src) );
6404   ins_pipe( ialu_reg_fat );
6405 %}
6406 
6407 instruct loadConL(eRegL dst, immL src, eFlagsReg cr) %{
6408   match(Set dst src);
6409   effect(KILL cr);
6410   ins_cost(200);
6411   format %{ "MOV    $dst.lo,$src.lo\n\t"
6412             "MOV    $dst.hi,$src.hi" %}
6413   opcode(0xB8);
6414   ins_encode( LdImmL_Lo(dst, src), LdImmL_Hi(dst, src) );
6415   ins_pipe( ialu_reg_long_fat );
6416 %}
6417 
6418 instruct loadConL0(eRegL dst, immL0 src, eFlagsReg cr) %{
6419   match(Set dst src);
6420   effect(KILL cr);
6421   ins_cost(150);
6422   format %{ "XOR    $dst.lo,$dst.lo\n\t"
6423             "XOR    $dst.hi,$dst.hi" %}
6424   opcode(0x33,0x33);
6425   ins_encode( RegReg_Lo(dst,dst), RegReg_Hi(dst, dst) );
6426   ins_pipe( ialu_reg_long );
6427 %}
6428 
6429 // The instruction usage is guarded by predicate in operand immFPR().
6430 instruct loadConFPR(regFPR dst, immFPR con) %{
6431   match(Set dst con);
6432   ins_cost(125);
6433   format %{ "FLD_S  ST,[$constantaddress]\t# load from constant table: float=$con\n\t"
6434             "FSTP   $dst" %}
6435   ins_encode %{
6436     __ fld_s($constantaddress($con));
6437     __ fstp_d($dst$$reg);
6438   %}
6439   ins_pipe(fpu_reg_con);
6440 %}
6441 
6442 // The instruction usage is guarded by predicate in operand immFPR0().
6443 instruct loadConFPR0(regFPR dst, immFPR0 con) %{
6444   match(Set dst con);
6445   ins_cost(125);
6446   format %{ "FLDZ   ST\n\t"
6447             "FSTP   $dst" %}
6448   ins_encode %{
6449     __ fldz();
6450     __ fstp_d($dst$$reg);
6451   %}
6452   ins_pipe(fpu_reg_con);
6453 %}
6454 
6455 // The instruction usage is guarded by predicate in operand immFPR1().
6456 instruct loadConFPR1(regFPR dst, immFPR1 con) %{
6457   match(Set dst con);
6458   ins_cost(125);
6459   format %{ "FLD1   ST\n\t"
6460             "FSTP   $dst" %}
6461   ins_encode %{
6462     __ fld1();
6463     __ fstp_d($dst$$reg);
6464   %}
6465   ins_pipe(fpu_reg_con);
6466 %}
6467 
6468 // The instruction usage is guarded by predicate in operand immF().
6469 instruct loadConF(regF dst, immF con) %{
6470   match(Set dst con);
6471   ins_cost(125);
6472   format %{ "MOVSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
6473   ins_encode %{
6474     __ movflt($dst$$XMMRegister, $constantaddress($con));
6475   %}
6476   ins_pipe(pipe_slow);
6477 %}
6478 
6479 // The instruction usage is guarded by predicate in operand immF0().
6480 instruct loadConF0(regF dst, immF0 src) %{
6481   match(Set dst src);
6482   ins_cost(100);
6483   format %{ "XORPS  $dst,$dst\t# float 0.0" %}
6484   ins_encode %{
6485     __ xorps($dst$$XMMRegister, $dst$$XMMRegister);
6486   %}
6487   ins_pipe(pipe_slow);
6488 %}
6489 
6490 // The instruction usage is guarded by predicate in operand immDPR().
6491 instruct loadConDPR(regDPR dst, immDPR con) %{
6492   match(Set dst con);
6493   ins_cost(125);
6494 
6495   format %{ "FLD_D  ST,[$constantaddress]\t# load from constant table: double=$con\n\t"
6496             "FSTP   $dst" %}
6497   ins_encode %{
6498     __ fld_d($constantaddress($con));
6499     __ fstp_d($dst$$reg);
6500   %}
6501   ins_pipe(fpu_reg_con);
6502 %}
6503 
6504 // The instruction usage is guarded by predicate in operand immDPR0().
6505 instruct loadConDPR0(regDPR dst, immDPR0 con) %{
6506   match(Set dst con);
6507   ins_cost(125);
6508 
6509   format %{ "FLDZ   ST\n\t"
6510             "FSTP   $dst" %}
6511   ins_encode %{
6512     __ fldz();
6513     __ fstp_d($dst$$reg);
6514   %}
6515   ins_pipe(fpu_reg_con);
6516 %}
6517 
6518 // The instruction usage is guarded by predicate in operand immDPR1().
6519 instruct loadConDPR1(regDPR dst, immDPR1 con) %{
6520   match(Set dst con);
6521   ins_cost(125);
6522 
6523   format %{ "FLD1   ST\n\t"
6524             "FSTP   $dst" %}
6525   ins_encode %{
6526     __ fld1();
6527     __ fstp_d($dst$$reg);
6528   %}
6529   ins_pipe(fpu_reg_con);
6530 %}
6531 
6532 // The instruction usage is guarded by predicate in operand immD().
6533 instruct loadConD(regD dst, immD con) %{
6534   match(Set dst con);
6535   ins_cost(125);
6536   format %{ "MOVSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
6537   ins_encode %{
6538     __ movdbl($dst$$XMMRegister, $constantaddress($con));
6539   %}
6540   ins_pipe(pipe_slow);
6541 %}
6542 
6543 // The instruction usage is guarded by predicate in operand immD0().
6544 instruct loadConD0(regD dst, immD0 src) %{
6545   match(Set dst src);
6546   ins_cost(100);
6547   format %{ "XORPD  $dst,$dst\t# double 0.0" %}
6548   ins_encode %{
6549     __ xorpd ($dst$$XMMRegister, $dst$$XMMRegister);
6550   %}
6551   ins_pipe( pipe_slow );
6552 %}
6553 
6554 // Load Stack Slot
6555 instruct loadSSI(rRegI dst, stackSlotI src) %{
6556   match(Set dst src);
6557   ins_cost(125);
6558 
6559   format %{ "MOV    $dst,$src" %}
6560   opcode(0x8B);
6561   ins_encode( OpcP, RegMem(dst,src));
6562   ins_pipe( ialu_reg_mem );
6563 %}
6564 
6565 instruct loadSSL(eRegL dst, stackSlotL src) %{
6566   match(Set dst src);
6567 
6568   ins_cost(200);
6569   format %{ "MOV    $dst,$src.lo\n\t"
6570             "MOV    $dst+4,$src.hi" %}
6571   opcode(0x8B, 0x8B);
6572   ins_encode( OpcP, RegMem( dst, src ), OpcS, RegMem_Hi( dst, src ) );
6573   ins_pipe( ialu_mem_long_reg );
6574 %}
6575 
6576 // Load Stack Slot
6577 instruct loadSSP(eRegP dst, stackSlotP src) %{
6578   match(Set dst src);
6579   ins_cost(125);
6580 
6581   format %{ "MOV    $dst,$src" %}
6582   opcode(0x8B);
6583   ins_encode( OpcP, RegMem(dst,src));
6584   ins_pipe( ialu_reg_mem );
6585 %}
6586 
6587 // Load Stack Slot
6588 instruct loadSSF(regFPR dst, stackSlotF src) %{
6589   match(Set dst src);
6590   ins_cost(125);
6591 
6592   format %{ "FLD_S  $src\n\t"
6593             "FSTP   $dst" %}
6594   opcode(0xD9);               /* D9 /0, FLD m32real */
6595   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
6596               Pop_Reg_FPR(dst) );
6597   ins_pipe( fpu_reg_mem );
6598 %}
6599 
6600 // Load Stack Slot
6601 instruct loadSSD(regDPR dst, stackSlotD src) %{
6602   match(Set dst src);
6603   ins_cost(125);
6604 
6605   format %{ "FLD_D  $src\n\t"
6606             "FSTP   $dst" %}
6607   opcode(0xDD);               /* DD /0, FLD m64real */
6608   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
6609               Pop_Reg_DPR(dst) );
6610   ins_pipe( fpu_reg_mem );
6611 %}
6612 
6613 // Prefetch instructions.
6614 // Must be safe to execute with invalid address (cannot fault).
6615 
6616 instruct prefetchr0( memory mem ) %{
6617   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
6618   match(PrefetchRead mem);
6619   ins_cost(0);
6620   size(0);
6621   format %{ "PREFETCHR (non-SSE is empty encoding)" %}
6622   ins_encode();
6623   ins_pipe(empty);
6624 %}
6625 
6626 instruct prefetchr( memory mem ) %{
6627   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch() || ReadPrefetchInstr==3);
6628   match(PrefetchRead mem);
6629   ins_cost(100);
6630 
6631   format %{ "PREFETCHR $mem\t! Prefetch into level 1 cache for read" %}
6632   ins_encode %{
6633     __ prefetchr($mem$$Address);
6634   %}
6635   ins_pipe(ialu_mem);
6636 %}
6637 
6638 instruct prefetchrNTA( memory mem ) %{
6639   predicate(UseSSE>=1 && ReadPrefetchInstr==0);
6640   match(PrefetchRead mem);
6641   ins_cost(100);
6642 
6643   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for read" %}
6644   ins_encode %{
6645     __ prefetchnta($mem$$Address);
6646   %}
6647   ins_pipe(ialu_mem);
6648 %}
6649 
6650 instruct prefetchrT0( memory mem ) %{
6651   predicate(UseSSE>=1 && ReadPrefetchInstr==1);
6652   match(PrefetchRead mem);
6653   ins_cost(100);
6654 
6655   format %{ "PREFETCHT0 $mem\t! Prefetch into L1 and L2 caches for read" %}
6656   ins_encode %{
6657     __ prefetcht0($mem$$Address);
6658   %}
6659   ins_pipe(ialu_mem);
6660 %}
6661 
6662 instruct prefetchrT2( memory mem ) %{
6663   predicate(UseSSE>=1 && ReadPrefetchInstr==2);
6664   match(PrefetchRead mem);
6665   ins_cost(100);
6666 
6667   format %{ "PREFETCHT2 $mem\t! Prefetch into L2 cache for read" %}
6668   ins_encode %{
6669     __ prefetcht2($mem$$Address);
6670   %}
6671   ins_pipe(ialu_mem);
6672 %}
6673 
6674 instruct prefetchw0( memory mem ) %{
6675   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
6676   match(PrefetchWrite mem);
6677   ins_cost(0);
6678   size(0);
6679   format %{ "Prefetch (non-SSE is empty encoding)" %}
6680   ins_encode();
6681   ins_pipe(empty);
6682 %}
6683 
6684 instruct prefetchw( memory mem ) %{
6685   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch());
6686   match( PrefetchWrite mem );
6687   ins_cost(100);
6688 
6689   format %{ "PREFETCHW $mem\t! Prefetch into L1 cache and mark modified" %}
6690   ins_encode %{
6691     __ prefetchw($mem$$Address);
6692   %}
6693   ins_pipe(ialu_mem);
6694 %}
6695 
6696 instruct prefetchwNTA( memory mem ) %{
6697   predicate(UseSSE>=1);
6698   match(PrefetchWrite mem);
6699   ins_cost(100);
6700 
6701   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for write" %}
6702   ins_encode %{
6703     __ prefetchnta($mem$$Address);
6704   %}
6705   ins_pipe(ialu_mem);
6706 %}
6707 
6708 // Prefetch instructions for allocation.
6709 
6710 instruct prefetchAlloc0( memory mem ) %{
6711   predicate(UseSSE==0 && AllocatePrefetchInstr!=3);
6712   match(PrefetchAllocation mem);
6713   ins_cost(0);
6714   size(0);
6715   format %{ "Prefetch allocation (non-SSE is empty encoding)" %}
6716   ins_encode();
6717   ins_pipe(empty);
6718 %}
6719 
6720 instruct prefetchAlloc( memory mem ) %{
6721   predicate(AllocatePrefetchInstr==3);
6722   match( PrefetchAllocation mem );
6723   ins_cost(100);
6724 
6725   format %{ "PREFETCHW $mem\t! Prefetch allocation into L1 cache and mark modified" %}
6726   ins_encode %{
6727     __ prefetchw($mem$$Address);
6728   %}
6729   ins_pipe(ialu_mem);
6730 %}
6731 
6732 instruct prefetchAllocNTA( memory mem ) %{
6733   predicate(UseSSE>=1 && AllocatePrefetchInstr==0);
6734   match(PrefetchAllocation mem);
6735   ins_cost(100);
6736 
6737   format %{ "PREFETCHNTA $mem\t! Prefetch allocation into non-temporal cache for write" %}
6738   ins_encode %{
6739     __ prefetchnta($mem$$Address);
6740   %}
6741   ins_pipe(ialu_mem);
6742 %}
6743 
6744 instruct prefetchAllocT0( memory mem ) %{
6745   predicate(UseSSE>=1 && AllocatePrefetchInstr==1);
6746   match(PrefetchAllocation mem);
6747   ins_cost(100);
6748 
6749   format %{ "PREFETCHT0 $mem\t! Prefetch allocation into L1 and L2 caches for write" %}
6750   ins_encode %{
6751     __ prefetcht0($mem$$Address);
6752   %}
6753   ins_pipe(ialu_mem);
6754 %}
6755 
6756 instruct prefetchAllocT2( memory mem ) %{
6757   predicate(UseSSE>=1 && AllocatePrefetchInstr==2);
6758   match(PrefetchAllocation mem);
6759   ins_cost(100);
6760 
6761   format %{ "PREFETCHT2 $mem\t! Prefetch allocation into L2 cache for write" %}
6762   ins_encode %{
6763     __ prefetcht2($mem$$Address);
6764   %}
6765   ins_pipe(ialu_mem);
6766 %}
6767 
6768 //----------Store Instructions-------------------------------------------------
6769 
6770 // Store Byte
6771 instruct storeB(memory mem, xRegI src) %{
6772   match(Set mem (StoreB mem src));
6773 
6774   ins_cost(125);
6775   format %{ "MOV8   $mem,$src" %}
6776   opcode(0x88);
6777   ins_encode( OpcP, RegMem( src, mem ) );
6778   ins_pipe( ialu_mem_reg );
6779 %}
6780 
6781 // Store Char/Short
6782 instruct storeC(memory mem, rRegI src) %{
6783   match(Set mem (StoreC mem src));
6784 
6785   ins_cost(125);
6786   format %{ "MOV16  $mem,$src" %}
6787   opcode(0x89, 0x66);
6788   ins_encode( OpcS, OpcP, RegMem( src, mem ) );
6789   ins_pipe( ialu_mem_reg );
6790 %}
6791 
6792 // Store Integer
6793 instruct storeI(memory mem, rRegI src) %{
6794   match(Set mem (StoreI mem src));
6795 
6796   ins_cost(125);
6797   format %{ "MOV    $mem,$src" %}
6798   opcode(0x89);
6799   ins_encode( OpcP, RegMem( src, mem ) );
6800   ins_pipe( ialu_mem_reg );
6801 %}
6802 
6803 // Store Long
6804 instruct storeL(long_memory mem, eRegL src) %{
6805   predicate(!((StoreLNode*)n)->require_atomic_access());
6806   match(Set mem (StoreL mem src));
6807 
6808   ins_cost(200);
6809   format %{ "MOV    $mem,$src.lo\n\t"
6810             "MOV    $mem+4,$src.hi" %}
6811   opcode(0x89, 0x89);
6812   ins_encode( OpcP, RegMem( src, mem ), OpcS, RegMem_Hi( src, mem ) );
6813   ins_pipe( ialu_mem_long_reg );
6814 %}
6815 
6816 // Store Long to Integer
6817 instruct storeL2I(memory mem, eRegL src) %{
6818   match(Set mem (StoreI mem (ConvL2I src)));
6819 
6820   format %{ "MOV    $mem,$src.lo\t# long -> int" %}
6821   ins_encode %{
6822     __ movl($mem$$Address, $src$$Register);
6823   %}
6824   ins_pipe(ialu_mem_reg);
6825 %}
6826 
6827 // Volatile Store Long.  Must be atomic, so move it into
6828 // the FP TOS and then do a 64-bit FIST.  Has to probe the
6829 // target address before the store (for null-ptr checks)
6830 // so the memory operand is used twice in the encoding.
6831 instruct storeL_volatile(memory mem, stackSlotL src, eFlagsReg cr ) %{
6832   predicate(UseSSE<=1 && ((StoreLNode*)n)->require_atomic_access());
6833   match(Set mem (StoreL mem src));
6834   effect( KILL cr );
6835   ins_cost(400);
6836   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
6837             "FILD   $src\n\t"
6838             "FISTp  $mem\t # 64-bit atomic volatile long store" %}
6839   opcode(0x3B);
6840   ins_encode( OpcP, RegMem( EAX, mem ), enc_storeL_volatile(mem,src));
6841   ins_pipe( fpu_reg_mem );
6842 %}
6843 
6844 instruct storeLX_volatile(memory mem, stackSlotL src, regD tmp, eFlagsReg cr) %{
6845   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
6846   match(Set mem (StoreL mem src));
6847   effect( TEMP tmp, KILL cr );
6848   ins_cost(380);
6849   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
6850             "MOVSD  $tmp,$src\n\t"
6851             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
6852   ins_encode %{
6853     __ cmpl(rax, $mem$$Address);
6854     __ movdbl($tmp$$XMMRegister, Address(rsp, $src$$disp));
6855     __ movdbl($mem$$Address, $tmp$$XMMRegister);
6856   %}
6857   ins_pipe( pipe_slow );
6858 %}
6859 
6860 instruct storeLX_reg_volatile(memory mem, eRegL src, regD tmp2, regD tmp, eFlagsReg cr) %{
6861   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
6862   match(Set mem (StoreL mem src));
6863   effect( TEMP tmp2 , TEMP tmp, KILL cr );
6864   ins_cost(360);
6865   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
6866             "MOVD   $tmp,$src.lo\n\t"
6867             "MOVD   $tmp2,$src.hi\n\t"
6868             "PUNPCKLDQ $tmp,$tmp2\n\t"
6869             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
6870   ins_encode %{
6871     __ cmpl(rax, $mem$$Address);
6872     __ movdl($tmp$$XMMRegister, $src$$Register);
6873     __ movdl($tmp2$$XMMRegister, HIGH_FROM_LOW($src$$Register));
6874     __ punpckldq($tmp$$XMMRegister, $tmp2$$XMMRegister);
6875     __ movdbl($mem$$Address, $tmp$$XMMRegister);
6876   %}
6877   ins_pipe( pipe_slow );
6878 %}
6879 
6880 // Store Pointer; for storing unknown oops and raw pointers
6881 instruct storeP(memory mem, anyRegP src) %{
6882   match(Set mem (StoreP mem src));
6883 
6884   ins_cost(125);
6885   format %{ "MOV    $mem,$src" %}
6886   opcode(0x89);
6887   ins_encode( OpcP, RegMem( src, mem ) );
6888   ins_pipe( ialu_mem_reg );
6889 %}
6890 
6891 // Store Integer Immediate
6892 instruct storeImmI(memory mem, immI src) %{
6893   match(Set mem (StoreI mem src));
6894 
6895   ins_cost(150);
6896   format %{ "MOV    $mem,$src" %}
6897   opcode(0xC7);               /* C7 /0 */
6898   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
6899   ins_pipe( ialu_mem_imm );
6900 %}
6901 
6902 // Store Short/Char Immediate
6903 instruct storeImmI16(memory mem, immI16 src) %{
6904   predicate(UseStoreImmI16);
6905   match(Set mem (StoreC mem src));
6906 
6907   ins_cost(150);
6908   format %{ "MOV16  $mem,$src" %}
6909   opcode(0xC7);     /* C7 /0 Same as 32 store immediate with prefix */
6910   ins_encode( SizePrefix, OpcP, RMopc_Mem(0x00,mem),  Con16( src ));
6911   ins_pipe( ialu_mem_imm );
6912 %}
6913 
6914 // Store Pointer Immediate; null pointers or constant oops that do not
6915 // need card-mark barriers.
6916 instruct storeImmP(memory mem, immP src) %{
6917   match(Set mem (StoreP mem src));
6918 
6919   ins_cost(150);
6920   format %{ "MOV    $mem,$src" %}
6921   opcode(0xC7);               /* C7 /0 */
6922   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
6923   ins_pipe( ialu_mem_imm );
6924 %}
6925 
6926 // Store Byte Immediate
6927 instruct storeImmB(memory mem, immI8 src) %{
6928   match(Set mem (StoreB mem src));
6929 
6930   ins_cost(150);
6931   format %{ "MOV8   $mem,$src" %}
6932   opcode(0xC6);               /* C6 /0 */
6933   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
6934   ins_pipe( ialu_mem_imm );
6935 %}
6936 
6937 // Store CMS card-mark Immediate
6938 instruct storeImmCM(memory mem, immI8 src) %{
6939   match(Set mem (StoreCM mem src));
6940 
6941   ins_cost(150);
6942   format %{ "MOV8   $mem,$src\t! CMS card-mark imm0" %}
6943   opcode(0xC6);               /* C6 /0 */
6944   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
6945   ins_pipe( ialu_mem_imm );
6946 %}
6947 
6948 // Store Double
6949 instruct storeDPR( memory mem, regDPR1 src) %{
6950   predicate(UseSSE<=1);
6951   match(Set mem (StoreD mem src));
6952 
6953   ins_cost(100);
6954   format %{ "FST_D  $mem,$src" %}
6955   opcode(0xDD);       /* DD /2 */
6956   ins_encode( enc_FPR_store(mem,src) );
6957   ins_pipe( fpu_mem_reg );
6958 %}
6959 
6960 // Store double does rounding on x86
6961 instruct storeDPR_rounded( memory mem, regDPR1 src) %{
6962   predicate(UseSSE<=1);
6963   match(Set mem (StoreD mem (RoundDouble src)));
6964 
6965   ins_cost(100);
6966   format %{ "FST_D  $mem,$src\t# round" %}
6967   opcode(0xDD);       /* DD /2 */
6968   ins_encode( enc_FPR_store(mem,src) );
6969   ins_pipe( fpu_mem_reg );
6970 %}
6971 
6972 // Store XMM register to memory (double-precision floating points)
6973 // MOVSD instruction
6974 instruct storeD(memory mem, regD src) %{
6975   predicate(UseSSE>=2);
6976   match(Set mem (StoreD mem src));
6977   ins_cost(95);
6978   format %{ "MOVSD  $mem,$src" %}
6979   ins_encode %{
6980     __ movdbl($mem$$Address, $src$$XMMRegister);
6981   %}
6982   ins_pipe( pipe_slow );
6983 %}
6984 
6985 // Store XMM register to memory (single-precision floating point)
6986 // MOVSS instruction
6987 instruct storeF(memory mem, regF src) %{
6988   predicate(UseSSE>=1);
6989   match(Set mem (StoreF mem src));
6990   ins_cost(95);
6991   format %{ "MOVSS  $mem,$src" %}
6992   ins_encode %{
6993     __ movflt($mem$$Address, $src$$XMMRegister);
6994   %}
6995   ins_pipe( pipe_slow );
6996 %}
6997 
6998 // Store Float
6999 instruct storeFPR( memory mem, regFPR1 src) %{
7000   predicate(UseSSE==0);
7001   match(Set mem (StoreF mem src));
7002 
7003   ins_cost(100);
7004   format %{ "FST_S  $mem,$src" %}
7005   opcode(0xD9);       /* D9 /2 */
7006   ins_encode( enc_FPR_store(mem,src) );
7007   ins_pipe( fpu_mem_reg );
7008 %}
7009 
7010 // Store Float does rounding on x86
7011 instruct storeFPR_rounded( memory mem, regFPR1 src) %{
7012   predicate(UseSSE==0);
7013   match(Set mem (StoreF mem (RoundFloat src)));
7014 
7015   ins_cost(100);
7016   format %{ "FST_S  $mem,$src\t# round" %}
7017   opcode(0xD9);       /* D9 /2 */
7018   ins_encode( enc_FPR_store(mem,src) );
7019   ins_pipe( fpu_mem_reg );
7020 %}
7021 
7022 // Store Float does rounding on x86
7023 instruct storeFPR_Drounded( memory mem, regDPR1 src) %{
7024   predicate(UseSSE<=1);
7025   match(Set mem (StoreF mem (ConvD2F src)));
7026 
7027   ins_cost(100);
7028   format %{ "FST_S  $mem,$src\t# D-round" %}
7029   opcode(0xD9);       /* D9 /2 */
7030   ins_encode( enc_FPR_store(mem,src) );
7031   ins_pipe( fpu_mem_reg );
7032 %}
7033 
7034 // Store immediate Float value (it is faster than store from FPU register)
7035 // The instruction usage is guarded by predicate in operand immFPR().
7036 instruct storeFPR_imm( memory mem, immFPR src) %{
7037   match(Set mem (StoreF mem src));
7038 
7039   ins_cost(50);
7040   format %{ "MOV    $mem,$src\t# store float" %}
7041   opcode(0xC7);               /* C7 /0 */
7042   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32FPR_as_bits( src ));
7043   ins_pipe( ialu_mem_imm );
7044 %}
7045 
7046 // Store immediate Float value (it is faster than store from XMM register)
7047 // The instruction usage is guarded by predicate in operand immF().
7048 instruct storeF_imm( memory mem, immF src) %{
7049   match(Set mem (StoreF mem src));
7050 
7051   ins_cost(50);
7052   format %{ "MOV    $mem,$src\t# store float" %}
7053   opcode(0xC7);               /* C7 /0 */
7054   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32F_as_bits( src ));
7055   ins_pipe( ialu_mem_imm );
7056 %}
7057 
7058 // Store Integer to stack slot
7059 instruct storeSSI(stackSlotI dst, rRegI src) %{
7060   match(Set dst src);
7061 
7062   ins_cost(100);
7063   format %{ "MOV    $dst,$src" %}
7064   opcode(0x89);
7065   ins_encode( OpcPRegSS( dst, src ) );
7066   ins_pipe( ialu_mem_reg );
7067 %}
7068 
7069 // Store Integer to stack slot
7070 instruct storeSSP(stackSlotP dst, eRegP src) %{
7071   match(Set dst src);
7072 
7073   ins_cost(100);
7074   format %{ "MOV    $dst,$src" %}
7075   opcode(0x89);
7076   ins_encode( OpcPRegSS( dst, src ) );
7077   ins_pipe( ialu_mem_reg );
7078 %}
7079 
7080 // Store Long to stack slot
7081 instruct storeSSL(stackSlotL dst, eRegL src) %{
7082   match(Set dst src);
7083 
7084   ins_cost(200);
7085   format %{ "MOV    $dst,$src.lo\n\t"
7086             "MOV    $dst+4,$src.hi" %}
7087   opcode(0x89, 0x89);
7088   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
7089   ins_pipe( ialu_mem_long_reg );
7090 %}
7091 
7092 //----------MemBar Instructions-----------------------------------------------
7093 // Memory barrier flavors
7094 
7095 instruct membar_acquire() %{
7096   match(MemBarAcquire);
7097   match(LoadFence);
7098   ins_cost(400);
7099 
7100   size(0);
7101   format %{ "MEMBAR-acquire ! (empty encoding)" %}
7102   ins_encode();
7103   ins_pipe(empty);
7104 %}
7105 
7106 instruct membar_acquire_lock() %{
7107   match(MemBarAcquireLock);
7108   ins_cost(0);
7109 
7110   size(0);
7111   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
7112   ins_encode( );
7113   ins_pipe(empty);
7114 %}
7115 
7116 instruct membar_release() %{
7117   match(MemBarRelease);
7118   match(StoreFence);
7119   ins_cost(400);
7120 
7121   size(0);
7122   format %{ "MEMBAR-release ! (empty encoding)" %}
7123   ins_encode( );
7124   ins_pipe(empty);
7125 %}
7126 
7127 instruct membar_release_lock() %{
7128   match(MemBarReleaseLock);
7129   ins_cost(0);
7130 
7131   size(0);
7132   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
7133   ins_encode( );
7134   ins_pipe(empty);
7135 %}
7136 
7137 instruct membar_volatile(eFlagsReg cr) %{
7138   match(MemBarVolatile);
7139   effect(KILL cr);
7140   ins_cost(400);
7141 
7142   format %{ 
7143     $$template
7144     if (os::is_MP()) {
7145       $$emit$$"LOCK ADDL [ESP + #0], 0\t! membar_volatile"
7146     } else {
7147       $$emit$$"MEMBAR-volatile ! (empty encoding)"
7148     }
7149   %}
7150   ins_encode %{
7151     __ membar(Assembler::StoreLoad);
7152   %}
7153   ins_pipe(pipe_slow);
7154 %}
7155 
7156 instruct unnecessary_membar_volatile() %{
7157   match(MemBarVolatile);
7158   predicate(Matcher::post_store_load_barrier(n));
7159   ins_cost(0);
7160 
7161   size(0);
7162   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
7163   ins_encode( );
7164   ins_pipe(empty);
7165 %}
7166 
7167 instruct membar_storestore() %{
7168   match(MemBarStoreStore);
7169   ins_cost(0);
7170 
7171   size(0);
7172   format %{ "MEMBAR-storestore (empty encoding)" %}
7173   ins_encode( );
7174   ins_pipe(empty);
7175 %}
7176 
7177 //----------Move Instructions--------------------------------------------------
7178 instruct castX2P(eAXRegP dst, eAXRegI src) %{
7179   match(Set dst (CastX2P src));
7180   format %{ "# X2P  $dst, $src" %}
7181   ins_encode( /*empty encoding*/ );
7182   ins_cost(0);
7183   ins_pipe(empty);
7184 %}
7185 
7186 instruct castP2X(rRegI dst, eRegP src ) %{
7187   match(Set dst (CastP2X src));
7188   ins_cost(50);
7189   format %{ "MOV    $dst, $src\t# CastP2X" %}
7190   ins_encode( enc_Copy( dst, src) );
7191   ins_pipe( ialu_reg_reg );
7192 %}
7193 
7194 //----------Conditional Move---------------------------------------------------
7195 // Conditional move
7196 instruct jmovI_reg(cmpOp cop, eFlagsReg cr, rRegI dst, rRegI src) %{
7197   predicate(!VM_Version::supports_cmov() );
7198   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7199   ins_cost(200);
7200   format %{ "J$cop,us skip\t# signed cmove\n\t"
7201             "MOV    $dst,$src\n"
7202       "skip:" %}
7203   ins_encode %{
7204     Label Lskip;
7205     // Invert sense of branch from sense of CMOV
7206     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
7207     __ movl($dst$$Register, $src$$Register);
7208     __ bind(Lskip);
7209   %}
7210   ins_pipe( pipe_cmov_reg );
7211 %}
7212 
7213 instruct jmovI_regU(cmpOpU cop, eFlagsRegU cr, rRegI dst, rRegI src) %{
7214   predicate(!VM_Version::supports_cmov() );
7215   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7216   ins_cost(200);
7217   format %{ "J$cop,us skip\t# unsigned cmove\n\t"
7218             "MOV    $dst,$src\n"
7219       "skip:" %}
7220   ins_encode %{
7221     Label Lskip;
7222     // Invert sense of branch from sense of CMOV
7223     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
7224     __ movl($dst$$Register, $src$$Register);
7225     __ bind(Lskip);
7226   %}
7227   ins_pipe( pipe_cmov_reg );
7228 %}
7229 
7230 instruct cmovI_reg(rRegI dst, rRegI src, eFlagsReg cr, cmpOp cop ) %{
7231   predicate(VM_Version::supports_cmov() );
7232   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7233   ins_cost(200);
7234   format %{ "CMOV$cop $dst,$src" %}
7235   opcode(0x0F,0x40);
7236   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
7237   ins_pipe( pipe_cmov_reg );
7238 %}
7239 
7240 instruct cmovI_regU( cmpOpU cop, eFlagsRegU cr, rRegI dst, rRegI src ) %{
7241   predicate(VM_Version::supports_cmov() );
7242   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7243   ins_cost(200);
7244   format %{ "CMOV$cop $dst,$src" %}
7245   opcode(0x0F,0x40);
7246   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
7247   ins_pipe( pipe_cmov_reg );
7248 %}
7249 
7250 instruct cmovI_regUCF( cmpOpUCF cop, eFlagsRegUCF cr, rRegI dst, rRegI src ) %{
7251   predicate(VM_Version::supports_cmov() );
7252   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7253   ins_cost(200);
7254   expand %{
7255     cmovI_regU(cop, cr, dst, src);
7256   %}
7257 %}
7258 
7259 // Conditional move
7260 instruct cmovI_mem(cmpOp cop, eFlagsReg cr, rRegI dst, memory src) %{
7261   predicate(VM_Version::supports_cmov() );
7262   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7263   ins_cost(250);
7264   format %{ "CMOV$cop $dst,$src" %}
7265   opcode(0x0F,0x40);
7266   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
7267   ins_pipe( pipe_cmov_mem );
7268 %}
7269 
7270 // Conditional move
7271 instruct cmovI_memU(cmpOpU cop, eFlagsRegU cr, rRegI dst, memory src) %{
7272   predicate(VM_Version::supports_cmov() );
7273   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7274   ins_cost(250);
7275   format %{ "CMOV$cop $dst,$src" %}
7276   opcode(0x0F,0x40);
7277   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
7278   ins_pipe( pipe_cmov_mem );
7279 %}
7280 
7281 instruct cmovI_memUCF(cmpOpUCF cop, eFlagsRegUCF cr, rRegI dst, memory src) %{
7282   predicate(VM_Version::supports_cmov() );
7283   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7284   ins_cost(250);
7285   expand %{
7286     cmovI_memU(cop, cr, dst, src);
7287   %}
7288 %}
7289 
7290 // Conditional move
7291 instruct cmovP_reg(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
7292   predicate(VM_Version::supports_cmov() );
7293   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7294   ins_cost(200);
7295   format %{ "CMOV$cop $dst,$src\t# ptr" %}
7296   opcode(0x0F,0x40);
7297   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
7298   ins_pipe( pipe_cmov_reg );
7299 %}
7300 
7301 // Conditional move (non-P6 version)
7302 // Note:  a CMoveP is generated for  stubs and native wrappers
7303 //        regardless of whether we are on a P6, so we
7304 //        emulate a cmov here
7305 instruct cmovP_reg_nonP6(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
7306   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7307   ins_cost(300);
7308   format %{ "Jn$cop   skip\n\t"
7309           "MOV    $dst,$src\t# pointer\n"
7310       "skip:" %}
7311   opcode(0x8b);
7312   ins_encode( enc_cmov_branch(cop, 0x2), OpcP, RegReg(dst, src));
7313   ins_pipe( pipe_cmov_reg );
7314 %}
7315 
7316 // Conditional move
7317 instruct cmovP_regU(cmpOpU cop, eFlagsRegU cr, eRegP dst, eRegP src ) %{
7318   predicate(VM_Version::supports_cmov() );
7319   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7320   ins_cost(200);
7321   format %{ "CMOV$cop $dst,$src\t# ptr" %}
7322   opcode(0x0F,0x40);
7323   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
7324   ins_pipe( pipe_cmov_reg );
7325 %}
7326 
7327 instruct cmovP_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegP dst, eRegP src ) %{
7328   predicate(VM_Version::supports_cmov() );
7329   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7330   ins_cost(200);
7331   expand %{
7332     cmovP_regU(cop, cr, dst, src);
7333   %}
7334 %}
7335 
7336 // DISABLED: Requires the ADLC to emit a bottom_type call that
7337 // correctly meets the two pointer arguments; one is an incoming
7338 // register but the other is a memory operand.  ALSO appears to
7339 // be buggy with implicit null checks.
7340 //
7341 //// Conditional move
7342 //instruct cmovP_mem(cmpOp cop, eFlagsReg cr, eRegP dst, memory src) %{
7343 //  predicate(VM_Version::supports_cmov() );
7344 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
7345 //  ins_cost(250);
7346 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
7347 //  opcode(0x0F,0x40);
7348 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
7349 //  ins_pipe( pipe_cmov_mem );
7350 //%}
7351 //
7352 //// Conditional move
7353 //instruct cmovP_memU(cmpOpU cop, eFlagsRegU cr, eRegP dst, memory src) %{
7354 //  predicate(VM_Version::supports_cmov() );
7355 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
7356 //  ins_cost(250);
7357 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
7358 //  opcode(0x0F,0x40);
7359 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
7360 //  ins_pipe( pipe_cmov_mem );
7361 //%}
7362 
7363 // Conditional move
7364 instruct fcmovDPR_regU(cmpOp_fcmov cop, eFlagsRegU cr, regDPR1 dst, regDPR src) %{
7365   predicate(UseSSE<=1);
7366   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7367   ins_cost(200);
7368   format %{ "FCMOV$cop $dst,$src\t# double" %}
7369   opcode(0xDA);
7370   ins_encode( enc_cmov_dpr(cop,src) );
7371   ins_pipe( pipe_cmovDPR_reg );
7372 %}
7373 
7374 // Conditional move
7375 instruct fcmovFPR_regU(cmpOp_fcmov cop, eFlagsRegU cr, regFPR1 dst, regFPR src) %{
7376   predicate(UseSSE==0);
7377   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7378   ins_cost(200);
7379   format %{ "FCMOV$cop $dst,$src\t# float" %}
7380   opcode(0xDA);
7381   ins_encode( enc_cmov_dpr(cop,src) );
7382   ins_pipe( pipe_cmovDPR_reg );
7383 %}
7384 
7385 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
7386 instruct fcmovDPR_regS(cmpOp cop, eFlagsReg cr, regDPR dst, regDPR src) %{
7387   predicate(UseSSE<=1);
7388   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7389   ins_cost(200);
7390   format %{ "Jn$cop   skip\n\t"
7391             "MOV    $dst,$src\t# double\n"
7392       "skip:" %}
7393   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
7394   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_DPR(src), OpcP, RegOpc(dst) );
7395   ins_pipe( pipe_cmovDPR_reg );
7396 %}
7397 
7398 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
7399 instruct fcmovFPR_regS(cmpOp cop, eFlagsReg cr, regFPR dst, regFPR src) %{
7400   predicate(UseSSE==0);
7401   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7402   ins_cost(200);
7403   format %{ "Jn$cop    skip\n\t"
7404             "MOV    $dst,$src\t# float\n"
7405       "skip:" %}
7406   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
7407   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_FPR(src), OpcP, RegOpc(dst) );
7408   ins_pipe( pipe_cmovDPR_reg );
7409 %}
7410 
7411 // No CMOVE with SSE/SSE2
7412 instruct fcmovF_regS(cmpOp cop, eFlagsReg cr, regF dst, regF src) %{
7413   predicate (UseSSE>=1);
7414   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7415   ins_cost(200);
7416   format %{ "Jn$cop   skip\n\t"
7417             "MOVSS  $dst,$src\t# float\n"
7418       "skip:" %}
7419   ins_encode %{
7420     Label skip;
7421     // Invert sense of branch from sense of CMOV
7422     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
7423     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
7424     __ bind(skip);
7425   %}
7426   ins_pipe( pipe_slow );
7427 %}
7428 
7429 // No CMOVE with SSE/SSE2
7430 instruct fcmovD_regS(cmpOp cop, eFlagsReg cr, regD dst, regD src) %{
7431   predicate (UseSSE>=2);
7432   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7433   ins_cost(200);
7434   format %{ "Jn$cop   skip\n\t"
7435             "MOVSD  $dst,$src\t# float\n"
7436       "skip:" %}
7437   ins_encode %{
7438     Label skip;
7439     // Invert sense of branch from sense of CMOV
7440     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
7441     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
7442     __ bind(skip);
7443   %}
7444   ins_pipe( pipe_slow );
7445 %}
7446 
7447 // unsigned version
7448 instruct fcmovF_regU(cmpOpU cop, eFlagsRegU cr, regF dst, regF src) %{
7449   predicate (UseSSE>=1);
7450   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7451   ins_cost(200);
7452   format %{ "Jn$cop   skip\n\t"
7453             "MOVSS  $dst,$src\t# float\n"
7454       "skip:" %}
7455   ins_encode %{
7456     Label skip;
7457     // Invert sense of branch from sense of CMOV
7458     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
7459     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
7460     __ bind(skip);
7461   %}
7462   ins_pipe( pipe_slow );
7463 %}
7464 
7465 instruct fcmovF_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regF dst, regF src) %{
7466   predicate (UseSSE>=1);
7467   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7468   ins_cost(200);
7469   expand %{
7470     fcmovF_regU(cop, cr, dst, src);
7471   %}
7472 %}
7473 
7474 // unsigned version
7475 instruct fcmovD_regU(cmpOpU cop, eFlagsRegU cr, regD dst, regD src) %{
7476   predicate (UseSSE>=2);
7477   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7478   ins_cost(200);
7479   format %{ "Jn$cop   skip\n\t"
7480             "MOVSD  $dst,$src\t# float\n"
7481       "skip:" %}
7482   ins_encode %{
7483     Label skip;
7484     // Invert sense of branch from sense of CMOV
7485     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
7486     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
7487     __ bind(skip);
7488   %}
7489   ins_pipe( pipe_slow );
7490 %}
7491 
7492 instruct fcmovD_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regD dst, regD src) %{
7493   predicate (UseSSE>=2);
7494   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7495   ins_cost(200);
7496   expand %{
7497     fcmovD_regU(cop, cr, dst, src);
7498   %}
7499 %}
7500 
7501 instruct cmovL_reg(cmpOp cop, eFlagsReg cr, eRegL dst, eRegL src) %{
7502   predicate(VM_Version::supports_cmov() );
7503   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7504   ins_cost(200);
7505   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
7506             "CMOV$cop $dst.hi,$src.hi" %}
7507   opcode(0x0F,0x40);
7508   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
7509   ins_pipe( pipe_cmov_reg_long );
7510 %}
7511 
7512 instruct cmovL_regU(cmpOpU cop, eFlagsRegU cr, eRegL dst, eRegL src) %{
7513   predicate(VM_Version::supports_cmov() );
7514   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7515   ins_cost(200);
7516   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
7517             "CMOV$cop $dst.hi,$src.hi" %}
7518   opcode(0x0F,0x40);
7519   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
7520   ins_pipe( pipe_cmov_reg_long );
7521 %}
7522 
7523 instruct cmovL_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegL dst, eRegL src) %{
7524   predicate(VM_Version::supports_cmov() );
7525   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7526   ins_cost(200);
7527   expand %{
7528     cmovL_regU(cop, cr, dst, src);
7529   %}
7530 %}
7531 
7532 //----------Arithmetic Instructions--------------------------------------------
7533 //----------Addition Instructions----------------------------------------------
7534 
7535 // Integer Addition Instructions
7536 instruct addI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
7537   match(Set dst (AddI dst src));
7538   effect(KILL cr);
7539 
7540   size(2);
7541   format %{ "ADD    $dst,$src" %}
7542   opcode(0x03);
7543   ins_encode( OpcP, RegReg( dst, src) );
7544   ins_pipe( ialu_reg_reg );
7545 %}
7546 
7547 instruct addI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
7548   match(Set dst (AddI dst src));
7549   effect(KILL cr);
7550 
7551   format %{ "ADD    $dst,$src" %}
7552   opcode(0x81, 0x00); /* /0 id */
7553   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
7554   ins_pipe( ialu_reg );
7555 %}
7556 
7557 instruct incI_eReg(rRegI dst, immI1 src, eFlagsReg cr) %{
7558   predicate(UseIncDec);
7559   match(Set dst (AddI dst src));
7560   effect(KILL cr);
7561 
7562   size(1);
7563   format %{ "INC    $dst" %}
7564   opcode(0x40); /*  */
7565   ins_encode( Opc_plus( primary, dst ) );
7566   ins_pipe( ialu_reg );
7567 %}
7568 
7569 instruct leaI_eReg_immI(rRegI dst, rRegI src0, immI src1) %{
7570   match(Set dst (AddI src0 src1));
7571   ins_cost(110);
7572 
7573   format %{ "LEA    $dst,[$src0 + $src1]" %}
7574   opcode(0x8D); /* 0x8D /r */
7575   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
7576   ins_pipe( ialu_reg_reg );
7577 %}
7578 
7579 instruct leaP_eReg_immI(eRegP dst, eRegP src0, immI src1) %{
7580   match(Set dst (AddP src0 src1));
7581   ins_cost(110);
7582 
7583   format %{ "LEA    $dst,[$src0 + $src1]\t# ptr" %}
7584   opcode(0x8D); /* 0x8D /r */
7585   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
7586   ins_pipe( ialu_reg_reg );
7587 %}
7588 
7589 instruct decI_eReg(rRegI dst, immI_M1 src, eFlagsReg cr) %{
7590   predicate(UseIncDec);
7591   match(Set dst (AddI dst src));
7592   effect(KILL cr);
7593 
7594   size(1);
7595   format %{ "DEC    $dst" %}
7596   opcode(0x48); /*  */
7597   ins_encode( Opc_plus( primary, dst ) );
7598   ins_pipe( ialu_reg );
7599 %}
7600 
7601 instruct addP_eReg(eRegP dst, rRegI src, eFlagsReg cr) %{
7602   match(Set dst (AddP dst src));
7603   effect(KILL cr);
7604 
7605   size(2);
7606   format %{ "ADD    $dst,$src" %}
7607   opcode(0x03);
7608   ins_encode( OpcP, RegReg( dst, src) );
7609   ins_pipe( ialu_reg_reg );
7610 %}
7611 
7612 instruct addP_eReg_imm(eRegP dst, immI src, eFlagsReg cr) %{
7613   match(Set dst (AddP dst src));
7614   effect(KILL cr);
7615 
7616   format %{ "ADD    $dst,$src" %}
7617   opcode(0x81,0x00); /* Opcode 81 /0 id */
7618   // ins_encode( RegImm( dst, src) );
7619   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
7620   ins_pipe( ialu_reg );
7621 %}
7622 
7623 instruct addI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
7624   match(Set dst (AddI dst (LoadI src)));
7625   effect(KILL cr);
7626 
7627   ins_cost(125);
7628   format %{ "ADD    $dst,$src" %}
7629   opcode(0x03);
7630   ins_encode( OpcP, RegMem( dst, src) );
7631   ins_pipe( ialu_reg_mem );
7632 %}
7633 
7634 instruct addI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
7635   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7636   effect(KILL cr);
7637 
7638   ins_cost(150);
7639   format %{ "ADD    $dst,$src" %}
7640   opcode(0x01);  /* Opcode 01 /r */
7641   ins_encode( OpcP, RegMem( src, dst ) );
7642   ins_pipe( ialu_mem_reg );
7643 %}
7644 
7645 // Add Memory with Immediate
7646 instruct addI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
7647   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7648   effect(KILL cr);
7649 
7650   ins_cost(125);
7651   format %{ "ADD    $dst,$src" %}
7652   opcode(0x81);               /* Opcode 81 /0 id */
7653   ins_encode( OpcSE( src ), RMopc_Mem(0x00,dst), Con8or32( src ) );
7654   ins_pipe( ialu_mem_imm );
7655 %}
7656 
7657 instruct incI_mem(memory dst, immI1 src, eFlagsReg cr) %{
7658   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7659   effect(KILL cr);
7660 
7661   ins_cost(125);
7662   format %{ "INC    $dst" %}
7663   opcode(0xFF);               /* Opcode FF /0 */
7664   ins_encode( OpcP, RMopc_Mem(0x00,dst));
7665   ins_pipe( ialu_mem_imm );
7666 %}
7667 
7668 instruct decI_mem(memory dst, immI_M1 src, eFlagsReg cr) %{
7669   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7670   effect(KILL cr);
7671 
7672   ins_cost(125);
7673   format %{ "DEC    $dst" %}
7674   opcode(0xFF);               /* Opcode FF /1 */
7675   ins_encode( OpcP, RMopc_Mem(0x01,dst));
7676   ins_pipe( ialu_mem_imm );
7677 %}
7678 
7679 
7680 instruct checkCastPP( eRegP dst ) %{
7681   match(Set dst (CheckCastPP dst));
7682 
7683   size(0);
7684   format %{ "#checkcastPP of $dst" %}
7685   ins_encode( /*empty encoding*/ );
7686   ins_pipe( empty );
7687 %}
7688 
7689 instruct castPP( eRegP dst ) %{
7690   match(Set dst (CastPP dst));
7691   format %{ "#castPP of $dst" %}
7692   ins_encode( /*empty encoding*/ );
7693   ins_pipe( empty );
7694 %}
7695 
7696 instruct castII( rRegI dst ) %{
7697   match(Set dst (CastII dst));
7698   format %{ "#castII of $dst" %}
7699   ins_encode( /*empty encoding*/ );
7700   ins_cost(0);
7701   ins_pipe( empty );
7702 %}
7703 
7704 
7705 // Load-locked - same as a regular pointer load when used with compare-swap
7706 instruct loadPLocked(eRegP dst, memory mem) %{
7707   match(Set dst (LoadPLocked mem));
7708 
7709   ins_cost(125);
7710   format %{ "MOV    $dst,$mem\t# Load ptr. locked" %}
7711   opcode(0x8B);
7712   ins_encode( OpcP, RegMem(dst,mem));
7713   ins_pipe( ialu_reg_mem );
7714 %}
7715 
7716 // Conditional-store of the updated heap-top.
7717 // Used during allocation of the shared heap.
7718 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
7719 instruct storePConditional( memory heap_top_ptr, eAXRegP oldval, eRegP newval, eFlagsReg cr ) %{
7720   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
7721   // EAX is killed if there is contention, but then it's also unused.
7722   // In the common case of no contention, EAX holds the new oop address.
7723   format %{ "CMPXCHG $heap_top_ptr,$newval\t# If EAX==$heap_top_ptr Then store $newval into $heap_top_ptr" %}
7724   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval,heap_top_ptr) );
7725   ins_pipe( pipe_cmpxchg );
7726 %}
7727 
7728 // Conditional-store of an int value.
7729 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG on Intel.
7730 instruct storeIConditional( memory mem, eAXRegI oldval, rRegI newval, eFlagsReg cr ) %{
7731   match(Set cr (StoreIConditional mem (Binary oldval newval)));
7732   effect(KILL oldval);
7733   format %{ "CMPXCHG $mem,$newval\t# If EAX==$mem Then store $newval into $mem" %}
7734   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval, mem) );
7735   ins_pipe( pipe_cmpxchg );
7736 %}
7737 
7738 // Conditional-store of a long value.
7739 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG8 on Intel.
7740 instruct storeLConditional( memory mem, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
7741   match(Set cr (StoreLConditional mem (Binary oldval newval)));
7742   effect(KILL oldval);
7743   format %{ "XCHG   EBX,ECX\t# correct order for CMPXCHG8 instruction\n\t"
7744             "CMPXCHG8 $mem,ECX:EBX\t# If EDX:EAX==$mem Then store ECX:EBX into $mem\n\t"
7745             "XCHG   EBX,ECX"
7746   %}
7747   ins_encode %{
7748     // Note: we need to swap rbx, and rcx before and after the
7749     //       cmpxchg8 instruction because the instruction uses
7750     //       rcx as the high order word of the new value to store but
7751     //       our register encoding uses rbx.
7752     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
7753     if( os::is_MP() )
7754       __ lock();
7755     __ cmpxchg8($mem$$Address);
7756     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
7757   %}
7758   ins_pipe( pipe_cmpxchg );
7759 %}
7760 
7761 // No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
7762 
7763 instruct compareAndSwapL( rRegI res, eSIRegP mem_ptr, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
7764   predicate(VM_Version::supports_cx8());
7765   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
7766   effect(KILL cr, KILL oldval);
7767   format %{ "CMPXCHG8 [$mem_ptr],$newval\t# If EDX:EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
7768             "MOV    $res,0\n\t"
7769             "JNE,s  fail\n\t"
7770             "MOV    $res,1\n"
7771           "fail:" %}
7772   ins_encode( enc_cmpxchg8(mem_ptr),
7773               enc_flags_ne_to_boolean(res) );
7774   ins_pipe( pipe_cmpxchg );
7775 %}
7776 
7777 instruct compareAndSwapP( rRegI res,  pRegP mem_ptr, eAXRegP oldval, eCXRegP newval, eFlagsReg cr) %{
7778   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
7779   effect(KILL cr, KILL oldval);
7780   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
7781             "MOV    $res,0\n\t"
7782             "JNE,s  fail\n\t"
7783             "MOV    $res,1\n"
7784           "fail:" %}
7785   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
7786   ins_pipe( pipe_cmpxchg );
7787 %}
7788 
7789 instruct compareAndSwapI( rRegI res, pRegP mem_ptr, eAXRegI oldval, eCXRegI newval, eFlagsReg cr) %{
7790   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
7791   effect(KILL cr, KILL oldval);
7792   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
7793             "MOV    $res,0\n\t"
7794             "JNE,s  fail\n\t"
7795             "MOV    $res,1\n"
7796           "fail:" %}
7797   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
7798   ins_pipe( pipe_cmpxchg );
7799 %}
7800 
7801 instruct xaddI_no_res( memory mem, Universe dummy, immI add, eFlagsReg cr) %{
7802   predicate(n->as_LoadStore()->result_not_used());
7803   match(Set dummy (GetAndAddI mem add));
7804   effect(KILL cr);
7805   format %{ "ADDL  [$mem],$add" %}
7806   ins_encode %{
7807     if (os::is_MP()) { __ lock(); }
7808     __ addl($mem$$Address, $add$$constant);
7809   %}
7810   ins_pipe( pipe_cmpxchg );
7811 %}
7812 
7813 instruct xaddI( memory mem, rRegI newval, eFlagsReg cr) %{
7814   match(Set newval (GetAndAddI mem newval));
7815   effect(KILL cr);
7816   format %{ "XADDL  [$mem],$newval" %}
7817   ins_encode %{
7818     if (os::is_MP()) { __ lock(); }
7819     __ xaddl($mem$$Address, $newval$$Register);
7820   %}
7821   ins_pipe( pipe_cmpxchg );
7822 %}
7823 
7824 instruct xchgI( memory mem, rRegI newval) %{
7825   match(Set newval (GetAndSetI mem newval));
7826   format %{ "XCHGL  $newval,[$mem]" %}
7827   ins_encode %{
7828     __ xchgl($newval$$Register, $mem$$Address);
7829   %}
7830   ins_pipe( pipe_cmpxchg );
7831 %}
7832 
7833 instruct xchgP( memory mem, pRegP newval) %{
7834   match(Set newval (GetAndSetP mem newval));
7835   format %{ "XCHGL  $newval,[$mem]" %}
7836   ins_encode %{
7837     __ xchgl($newval$$Register, $mem$$Address);
7838   %}
7839   ins_pipe( pipe_cmpxchg );
7840 %}
7841 
7842 //----------Subtraction Instructions-------------------------------------------
7843 
7844 // Integer Subtraction Instructions
7845 instruct subI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
7846   match(Set dst (SubI dst src));
7847   effect(KILL cr);
7848 
7849   size(2);
7850   format %{ "SUB    $dst,$src" %}
7851   opcode(0x2B);
7852   ins_encode( OpcP, RegReg( dst, src) );
7853   ins_pipe( ialu_reg_reg );
7854 %}
7855 
7856 instruct subI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
7857   match(Set dst (SubI dst src));
7858   effect(KILL cr);
7859 
7860   format %{ "SUB    $dst,$src" %}
7861   opcode(0x81,0x05);  /* Opcode 81 /5 */
7862   // ins_encode( RegImm( dst, src) );
7863   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
7864   ins_pipe( ialu_reg );
7865 %}
7866 
7867 instruct subI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
7868   match(Set dst (SubI dst (LoadI src)));
7869   effect(KILL cr);
7870 
7871   ins_cost(125);
7872   format %{ "SUB    $dst,$src" %}
7873   opcode(0x2B);
7874   ins_encode( OpcP, RegMem( dst, src) );
7875   ins_pipe( ialu_reg_mem );
7876 %}
7877 
7878 instruct subI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
7879   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
7880   effect(KILL cr);
7881 
7882   ins_cost(150);
7883   format %{ "SUB    $dst,$src" %}
7884   opcode(0x29);  /* Opcode 29 /r */
7885   ins_encode( OpcP, RegMem( src, dst ) );
7886   ins_pipe( ialu_mem_reg );
7887 %}
7888 
7889 // Subtract from a pointer
7890 instruct subP_eReg(eRegP dst, rRegI src, immI0 zero, eFlagsReg cr) %{
7891   match(Set dst (AddP dst (SubI zero src)));
7892   effect(KILL cr);
7893 
7894   size(2);
7895   format %{ "SUB    $dst,$src" %}
7896   opcode(0x2B);
7897   ins_encode( OpcP, RegReg( dst, src) );
7898   ins_pipe( ialu_reg_reg );
7899 %}
7900 
7901 instruct negI_eReg(rRegI dst, immI0 zero, eFlagsReg cr) %{
7902   match(Set dst (SubI zero dst));
7903   effect(KILL cr);
7904 
7905   size(2);
7906   format %{ "NEG    $dst" %}
7907   opcode(0xF7,0x03);  // Opcode F7 /3
7908   ins_encode( OpcP, RegOpc( dst ) );
7909   ins_pipe( ialu_reg );
7910 %}
7911 
7912 //----------Multiplication/Division Instructions-------------------------------
7913 // Integer Multiplication Instructions
7914 // Multiply Register
7915 instruct mulI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
7916   match(Set dst (MulI dst src));
7917   effect(KILL cr);
7918 
7919   size(3);
7920   ins_cost(300);
7921   format %{ "IMUL   $dst,$src" %}
7922   opcode(0xAF, 0x0F);
7923   ins_encode( OpcS, OpcP, RegReg( dst, src) );
7924   ins_pipe( ialu_reg_reg_alu0 );
7925 %}
7926 
7927 // Multiply 32-bit Immediate
7928 instruct mulI_eReg_imm(rRegI dst, rRegI src, immI imm, eFlagsReg cr) %{
7929   match(Set dst (MulI src imm));
7930   effect(KILL cr);
7931 
7932   ins_cost(300);
7933   format %{ "IMUL   $dst,$src,$imm" %}
7934   opcode(0x69);  /* 69 /r id */
7935   ins_encode( OpcSE(imm), RegReg( dst, src ), Con8or32( imm ) );
7936   ins_pipe( ialu_reg_reg_alu0 );
7937 %}
7938 
7939 instruct loadConL_low_only(eADXRegL_low_only dst, immL32 src, eFlagsReg cr) %{
7940   match(Set dst src);
7941   effect(KILL cr);
7942 
7943   // Note that this is artificially increased to make it more expensive than loadConL
7944   ins_cost(250);
7945   format %{ "MOV    EAX,$src\t// low word only" %}
7946   opcode(0xB8);
7947   ins_encode( LdImmL_Lo(dst, src) );
7948   ins_pipe( ialu_reg_fat );
7949 %}
7950 
7951 // Multiply by 32-bit Immediate, taking the shifted high order results
7952 //  (special case for shift by 32)
7953 instruct mulI_imm_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32 cnt, eFlagsReg cr) %{
7954   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
7955   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
7956              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
7957              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
7958   effect(USE src1, KILL cr);
7959 
7960   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
7961   ins_cost(0*100 + 1*400 - 150);
7962   format %{ "IMUL   EDX:EAX,$src1" %}
7963   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
7964   ins_pipe( pipe_slow );
7965 %}
7966 
7967 // Multiply by 32-bit Immediate, taking the shifted high order results
7968 instruct mulI_imm_RShift_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr) %{
7969   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
7970   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
7971              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
7972              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
7973   effect(USE src1, KILL cr);
7974 
7975   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
7976   ins_cost(1*100 + 1*400 - 150);
7977   format %{ "IMUL   EDX:EAX,$src1\n\t"
7978             "SAR    EDX,$cnt-32" %}
7979   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
7980   ins_pipe( pipe_slow );
7981 %}
7982 
7983 // Multiply Memory 32-bit Immediate
7984 instruct mulI_mem_imm(rRegI dst, memory src, immI imm, eFlagsReg cr) %{
7985   match(Set dst (MulI (LoadI src) imm));
7986   effect(KILL cr);
7987 
7988   ins_cost(300);
7989   format %{ "IMUL   $dst,$src,$imm" %}
7990   opcode(0x69);  /* 69 /r id */
7991   ins_encode( OpcSE(imm), RegMem( dst, src ), Con8or32( imm ) );
7992   ins_pipe( ialu_reg_mem_alu0 );
7993 %}
7994 
7995 // Multiply Memory
7996 instruct mulI(rRegI dst, memory src, eFlagsReg cr) %{
7997   match(Set dst (MulI dst (LoadI src)));
7998   effect(KILL cr);
7999 
8000   ins_cost(350);
8001   format %{ "IMUL   $dst,$src" %}
8002   opcode(0xAF, 0x0F);
8003   ins_encode( OpcS, OpcP, RegMem( dst, src) );
8004   ins_pipe( ialu_reg_mem_alu0 );
8005 %}
8006 
8007 // Multiply Register Int to Long
8008 instruct mulI2L(eADXRegL dst, eAXRegI src, nadxRegI src1, eFlagsReg flags) %{
8009   // Basic Idea: long = (long)int * (long)int
8010   match(Set dst (MulL (ConvI2L src) (ConvI2L src1)));
8011   effect(DEF dst, USE src, USE src1, KILL flags);
8012 
8013   ins_cost(300);
8014   format %{ "IMUL   $dst,$src1" %}
8015 
8016   ins_encode( long_int_multiply( dst, src1 ) );
8017   ins_pipe( ialu_reg_reg_alu0 );
8018 %}
8019 
8020 instruct mulIS_eReg(eADXRegL dst, immL_32bits mask, eFlagsReg flags, eAXRegI src, nadxRegI src1) %{
8021   // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
8022   match(Set dst (MulL (AndL (ConvI2L src) mask) (AndL (ConvI2L src1) mask)));
8023   effect(KILL flags);
8024 
8025   ins_cost(300);
8026   format %{ "MUL    $dst,$src1" %}
8027 
8028   ins_encode( long_uint_multiply(dst, src1) );
8029   ins_pipe( ialu_reg_reg_alu0 );
8030 %}
8031 
8032 // Multiply Register Long
8033 instruct mulL_eReg(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
8034   match(Set dst (MulL dst src));
8035   effect(KILL cr, TEMP tmp);
8036   ins_cost(4*100+3*400);
8037 // Basic idea: lo(result) = lo(x_lo * y_lo)
8038 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
8039   format %{ "MOV    $tmp,$src.lo\n\t"
8040             "IMUL   $tmp,EDX\n\t"
8041             "MOV    EDX,$src.hi\n\t"
8042             "IMUL   EDX,EAX\n\t"
8043             "ADD    $tmp,EDX\n\t"
8044             "MUL    EDX:EAX,$src.lo\n\t"
8045             "ADD    EDX,$tmp" %}
8046   ins_encode( long_multiply( dst, src, tmp ) );
8047   ins_pipe( pipe_slow );
8048 %}
8049 
8050 // Multiply Register Long where the left operand's high 32 bits are zero
8051 instruct mulL_eReg_lhi0(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
8052   predicate(is_operand_hi32_zero(n->in(1)));
8053   match(Set dst (MulL dst src));
8054   effect(KILL cr, TEMP tmp);
8055   ins_cost(2*100+2*400);
8056 // Basic idea: lo(result) = lo(x_lo * y_lo)
8057 //             hi(result) = hi(x_lo * y_lo) + lo(x_lo * y_hi) where lo(x_hi * y_lo) = 0 because x_hi = 0
8058   format %{ "MOV    $tmp,$src.hi\n\t"
8059             "IMUL   $tmp,EAX\n\t"
8060             "MUL    EDX:EAX,$src.lo\n\t"
8061             "ADD    EDX,$tmp" %}
8062   ins_encode %{
8063     __ movl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
8064     __ imull($tmp$$Register, rax);
8065     __ mull($src$$Register);
8066     __ addl(rdx, $tmp$$Register);
8067   %}
8068   ins_pipe( pipe_slow );
8069 %}
8070 
8071 // Multiply Register Long where the right operand's high 32 bits are zero
8072 instruct mulL_eReg_rhi0(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
8073   predicate(is_operand_hi32_zero(n->in(2)));
8074   match(Set dst (MulL dst src));
8075   effect(KILL cr, TEMP tmp);
8076   ins_cost(2*100+2*400);
8077 // Basic idea: lo(result) = lo(x_lo * y_lo)
8078 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) where lo(x_lo * y_hi) = 0 because y_hi = 0
8079   format %{ "MOV    $tmp,$src.lo\n\t"
8080             "IMUL   $tmp,EDX\n\t"
8081             "MUL    EDX:EAX,$src.lo\n\t"
8082             "ADD    EDX,$tmp" %}
8083   ins_encode %{
8084     __ movl($tmp$$Register, $src$$Register);
8085     __ imull($tmp$$Register, rdx);
8086     __ mull($src$$Register);
8087     __ addl(rdx, $tmp$$Register);
8088   %}
8089   ins_pipe( pipe_slow );
8090 %}
8091 
8092 // Multiply Register Long where the left and the right operands' high 32 bits are zero
8093 instruct mulL_eReg_hi0(eADXRegL dst, eRegL src, eFlagsReg cr) %{
8094   predicate(is_operand_hi32_zero(n->in(1)) && is_operand_hi32_zero(n->in(2)));
8095   match(Set dst (MulL dst src));
8096   effect(KILL cr);
8097   ins_cost(1*400);
8098 // Basic idea: lo(result) = lo(x_lo * y_lo)
8099 //             hi(result) = hi(x_lo * y_lo) where lo(x_hi * y_lo) = 0 and lo(x_lo * y_hi) = 0 because x_hi = 0 and y_hi = 0
8100   format %{ "MUL    EDX:EAX,$src.lo\n\t" %}
8101   ins_encode %{
8102     __ mull($src$$Register);
8103   %}
8104   ins_pipe( pipe_slow );
8105 %}
8106 
8107 // Multiply Register Long by small constant
8108 instruct mulL_eReg_con(eADXRegL dst, immL_127 src, rRegI tmp, eFlagsReg cr) %{
8109   match(Set dst (MulL dst src));
8110   effect(KILL cr, TEMP tmp);
8111   ins_cost(2*100+2*400);
8112   size(12);
8113 // Basic idea: lo(result) = lo(src * EAX)
8114 //             hi(result) = hi(src * EAX) + lo(src * EDX)
8115   format %{ "IMUL   $tmp,EDX,$src\n\t"
8116             "MOV    EDX,$src\n\t"
8117             "MUL    EDX\t# EDX*EAX -> EDX:EAX\n\t"
8118             "ADD    EDX,$tmp" %}
8119   ins_encode( long_multiply_con( dst, src, tmp ) );
8120   ins_pipe( pipe_slow );
8121 %}
8122 
8123 // Integer DIV with Register
8124 instruct divI_eReg(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
8125   match(Set rax (DivI rax div));
8126   effect(KILL rdx, KILL cr);
8127   size(26);
8128   ins_cost(30*100+10*100);
8129   format %{ "CMP    EAX,0x80000000\n\t"
8130             "JNE,s  normal\n\t"
8131             "XOR    EDX,EDX\n\t"
8132             "CMP    ECX,-1\n\t"
8133             "JE,s   done\n"
8134     "normal: CDQ\n\t"
8135             "IDIV   $div\n\t"
8136     "done:"        %}
8137   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8138   ins_encode( cdq_enc, OpcP, RegOpc(div) );
8139   ins_pipe( ialu_reg_reg_alu0 );
8140 %}
8141 
8142 // Divide Register Long
8143 instruct divL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
8144   match(Set dst (DivL src1 src2));
8145   effect( KILL cr, KILL cx, KILL bx );
8146   ins_cost(10000);
8147   format %{ "PUSH   $src1.hi\n\t"
8148             "PUSH   $src1.lo\n\t"
8149             "PUSH   $src2.hi\n\t"
8150             "PUSH   $src2.lo\n\t"
8151             "CALL   SharedRuntime::ldiv\n\t"
8152             "ADD    ESP,16" %}
8153   ins_encode( long_div(src1,src2) );
8154   ins_pipe( pipe_slow );
8155 %}
8156 
8157 // Integer DIVMOD with Register, both quotient and mod results
8158 instruct divModI_eReg_divmod(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
8159   match(DivModI rax div);
8160   effect(KILL cr);
8161   size(26);
8162   ins_cost(30*100+10*100);
8163   format %{ "CMP    EAX,0x80000000\n\t"
8164             "JNE,s  normal\n\t"
8165             "XOR    EDX,EDX\n\t"
8166             "CMP    ECX,-1\n\t"
8167             "JE,s   done\n"
8168     "normal: CDQ\n\t"
8169             "IDIV   $div\n\t"
8170     "done:"        %}
8171   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8172   ins_encode( cdq_enc, OpcP, RegOpc(div) );
8173   ins_pipe( pipe_slow );
8174 %}
8175 
8176 // Integer MOD with Register
8177 instruct modI_eReg(eDXRegI rdx, eAXRegI rax, eCXRegI div, eFlagsReg cr) %{
8178   match(Set rdx (ModI rax div));
8179   effect(KILL rax, KILL cr);
8180 
8181   size(26);
8182   ins_cost(300);
8183   format %{ "CDQ\n\t"
8184             "IDIV   $div" %}
8185   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8186   ins_encode( cdq_enc, OpcP, RegOpc(div) );
8187   ins_pipe( ialu_reg_reg_alu0 );
8188 %}
8189 
8190 // Remainder Register Long
8191 instruct modL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
8192   match(Set dst (ModL src1 src2));
8193   effect( KILL cr, KILL cx, KILL bx );
8194   ins_cost(10000);
8195   format %{ "PUSH   $src1.hi\n\t"
8196             "PUSH   $src1.lo\n\t"
8197             "PUSH   $src2.hi\n\t"
8198             "PUSH   $src2.lo\n\t"
8199             "CALL   SharedRuntime::lrem\n\t"
8200             "ADD    ESP,16" %}
8201   ins_encode( long_mod(src1,src2) );
8202   ins_pipe( pipe_slow );
8203 %}
8204 
8205 // Divide Register Long (no special case since divisor != -1)
8206 instruct divL_eReg_imm32( eADXRegL dst, immL32 imm, rRegI tmp, rRegI tmp2, eFlagsReg cr ) %{
8207   match(Set dst (DivL dst imm));
8208   effect( TEMP tmp, TEMP tmp2, KILL cr );
8209   ins_cost(1000);
8210   format %{ "MOV    $tmp,abs($imm) # ldiv EDX:EAX,$imm\n\t"
8211             "XOR    $tmp2,$tmp2\n\t"
8212             "CMP    $tmp,EDX\n\t"
8213             "JA,s   fast\n\t"
8214             "MOV    $tmp2,EAX\n\t"
8215             "MOV    EAX,EDX\n\t"
8216             "MOV    EDX,0\n\t"
8217             "JLE,s  pos\n\t"
8218             "LNEG   EAX : $tmp2\n\t"
8219             "DIV    $tmp # unsigned division\n\t"
8220             "XCHG   EAX,$tmp2\n\t"
8221             "DIV    $tmp\n\t"
8222             "LNEG   $tmp2 : EAX\n\t"
8223             "JMP,s  done\n"
8224     "pos:\n\t"
8225             "DIV    $tmp\n\t"
8226             "XCHG   EAX,$tmp2\n"
8227     "fast:\n\t"
8228             "DIV    $tmp\n"
8229     "done:\n\t"
8230             "MOV    EDX,$tmp2\n\t"
8231             "NEG    EDX:EAX # if $imm < 0" %}
8232   ins_encode %{
8233     int con = (int)$imm$$constant;
8234     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
8235     int pcon = (con > 0) ? con : -con;
8236     Label Lfast, Lpos, Ldone;
8237 
8238     __ movl($tmp$$Register, pcon);
8239     __ xorl($tmp2$$Register,$tmp2$$Register);
8240     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
8241     __ jccb(Assembler::above, Lfast); // result fits into 32 bit
8242 
8243     __ movl($tmp2$$Register, $dst$$Register); // save
8244     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
8245     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
8246     __ jccb(Assembler::lessEqual, Lpos); // result is positive
8247 
8248     // Negative dividend.
8249     // convert value to positive to use unsigned division
8250     __ lneg($dst$$Register, $tmp2$$Register);
8251     __ divl($tmp$$Register);
8252     __ xchgl($dst$$Register, $tmp2$$Register);
8253     __ divl($tmp$$Register);
8254     // revert result back to negative
8255     __ lneg($tmp2$$Register, $dst$$Register);
8256     __ jmpb(Ldone);
8257 
8258     __ bind(Lpos);
8259     __ divl($tmp$$Register); // Use unsigned division
8260     __ xchgl($dst$$Register, $tmp2$$Register);
8261     // Fallthrow for final divide, tmp2 has 32 bit hi result
8262 
8263     __ bind(Lfast);
8264     // fast path: src is positive
8265     __ divl($tmp$$Register); // Use unsigned division
8266 
8267     __ bind(Ldone);
8268     __ movl(HIGH_FROM_LOW($dst$$Register),$tmp2$$Register);
8269     if (con < 0) {
8270       __ lneg(HIGH_FROM_LOW($dst$$Register), $dst$$Register);
8271     }
8272   %}
8273   ins_pipe( pipe_slow );
8274 %}
8275 
8276 // Remainder Register Long (remainder fit into 32 bits)
8277 instruct modL_eReg_imm32( eADXRegL dst, immL32 imm, rRegI tmp, rRegI tmp2, eFlagsReg cr ) %{
8278   match(Set dst (ModL dst imm));
8279   effect( TEMP tmp, TEMP tmp2, KILL cr );
8280   ins_cost(1000);
8281   format %{ "MOV    $tmp,abs($imm) # lrem EDX:EAX,$imm\n\t"
8282             "CMP    $tmp,EDX\n\t"
8283             "JA,s   fast\n\t"
8284             "MOV    $tmp2,EAX\n\t"
8285             "MOV    EAX,EDX\n\t"
8286             "MOV    EDX,0\n\t"
8287             "JLE,s  pos\n\t"
8288             "LNEG   EAX : $tmp2\n\t"
8289             "DIV    $tmp # unsigned division\n\t"
8290             "MOV    EAX,$tmp2\n\t"
8291             "DIV    $tmp\n\t"
8292             "NEG    EDX\n\t"
8293             "JMP,s  done\n"
8294     "pos:\n\t"
8295             "DIV    $tmp\n\t"
8296             "MOV    EAX,$tmp2\n"
8297     "fast:\n\t"
8298             "DIV    $tmp\n"
8299     "done:\n\t"
8300             "MOV    EAX,EDX\n\t"
8301             "SAR    EDX,31\n\t" %}
8302   ins_encode %{
8303     int con = (int)$imm$$constant;
8304     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
8305     int pcon = (con > 0) ? con : -con;
8306     Label  Lfast, Lpos, Ldone;
8307 
8308     __ movl($tmp$$Register, pcon);
8309     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
8310     __ jccb(Assembler::above, Lfast); // src is positive and result fits into 32 bit
8311 
8312     __ movl($tmp2$$Register, $dst$$Register); // save
8313     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
8314     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
8315     __ jccb(Assembler::lessEqual, Lpos); // result is positive
8316 
8317     // Negative dividend.
8318     // convert value to positive to use unsigned division
8319     __ lneg($dst$$Register, $tmp2$$Register);
8320     __ divl($tmp$$Register);
8321     __ movl($dst$$Register, $tmp2$$Register);
8322     __ divl($tmp$$Register);
8323     // revert remainder back to negative
8324     __ negl(HIGH_FROM_LOW($dst$$Register));
8325     __ jmpb(Ldone);
8326 
8327     __ bind(Lpos);
8328     __ divl($tmp$$Register);
8329     __ movl($dst$$Register, $tmp2$$Register);
8330 
8331     __ bind(Lfast);
8332     // fast path: src is positive
8333     __ divl($tmp$$Register);
8334 
8335     __ bind(Ldone);
8336     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
8337     __ sarl(HIGH_FROM_LOW($dst$$Register), 31); // result sign
8338 
8339   %}
8340   ins_pipe( pipe_slow );
8341 %}
8342 
8343 // Integer Shift Instructions
8344 // Shift Left by one
8345 instruct shlI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
8346   match(Set dst (LShiftI dst shift));
8347   effect(KILL cr);
8348 
8349   size(2);
8350   format %{ "SHL    $dst,$shift" %}
8351   opcode(0xD1, 0x4);  /* D1 /4 */
8352   ins_encode( OpcP, RegOpc( dst ) );
8353   ins_pipe( ialu_reg );
8354 %}
8355 
8356 // Shift Left by 8-bit immediate
8357 instruct salI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
8358   match(Set dst (LShiftI dst shift));
8359   effect(KILL cr);
8360 
8361   size(3);
8362   format %{ "SHL    $dst,$shift" %}
8363   opcode(0xC1, 0x4);  /* C1 /4 ib */
8364   ins_encode( RegOpcImm( dst, shift) );
8365   ins_pipe( ialu_reg );
8366 %}
8367 
8368 // Shift Left by variable
8369 instruct salI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
8370   match(Set dst (LShiftI dst shift));
8371   effect(KILL cr);
8372 
8373   size(2);
8374   format %{ "SHL    $dst,$shift" %}
8375   opcode(0xD3, 0x4);  /* D3 /4 */
8376   ins_encode( OpcP, RegOpc( dst ) );
8377   ins_pipe( ialu_reg_reg );
8378 %}
8379 
8380 // Arithmetic shift right by one
8381 instruct sarI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
8382   match(Set dst (RShiftI dst shift));
8383   effect(KILL cr);
8384 
8385   size(2);
8386   format %{ "SAR    $dst,$shift" %}
8387   opcode(0xD1, 0x7);  /* D1 /7 */
8388   ins_encode( OpcP, RegOpc( dst ) );
8389   ins_pipe( ialu_reg );
8390 %}
8391 
8392 // Arithmetic shift right by one
8393 instruct sarI_mem_1(memory dst, immI1 shift, eFlagsReg cr) %{
8394   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
8395   effect(KILL cr);
8396   format %{ "SAR    $dst,$shift" %}
8397   opcode(0xD1, 0x7);  /* D1 /7 */
8398   ins_encode( OpcP, RMopc_Mem(secondary,dst) );
8399   ins_pipe( ialu_mem_imm );
8400 %}
8401 
8402 // Arithmetic Shift Right by 8-bit immediate
8403 instruct sarI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
8404   match(Set dst (RShiftI dst shift));
8405   effect(KILL cr);
8406 
8407   size(3);
8408   format %{ "SAR    $dst,$shift" %}
8409   opcode(0xC1, 0x7);  /* C1 /7 ib */
8410   ins_encode( RegOpcImm( dst, shift ) );
8411   ins_pipe( ialu_mem_imm );
8412 %}
8413 
8414 // Arithmetic Shift Right by 8-bit immediate
8415 instruct sarI_mem_imm(memory dst, immI8 shift, eFlagsReg cr) %{
8416   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
8417   effect(KILL cr);
8418 
8419   format %{ "SAR    $dst,$shift" %}
8420   opcode(0xC1, 0x7);  /* C1 /7 ib */
8421   ins_encode( OpcP, RMopc_Mem(secondary, dst ), Con8or32( shift ) );
8422   ins_pipe( ialu_mem_imm );
8423 %}
8424 
8425 // Arithmetic Shift Right by variable
8426 instruct sarI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
8427   match(Set dst (RShiftI dst shift));
8428   effect(KILL cr);
8429 
8430   size(2);
8431   format %{ "SAR    $dst,$shift" %}
8432   opcode(0xD3, 0x7);  /* D3 /7 */
8433   ins_encode( OpcP, RegOpc( dst ) );
8434   ins_pipe( ialu_reg_reg );
8435 %}
8436 
8437 // Logical shift right by one
8438 instruct shrI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
8439   match(Set dst (URShiftI dst shift));
8440   effect(KILL cr);
8441 
8442   size(2);
8443   format %{ "SHR    $dst,$shift" %}
8444   opcode(0xD1, 0x5);  /* D1 /5 */
8445   ins_encode( OpcP, RegOpc( dst ) );
8446   ins_pipe( ialu_reg );
8447 %}
8448 
8449 // Logical Shift Right by 8-bit immediate
8450 instruct shrI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
8451   match(Set dst (URShiftI dst shift));
8452   effect(KILL cr);
8453 
8454   size(3);
8455   format %{ "SHR    $dst,$shift" %}
8456   opcode(0xC1, 0x5);  /* C1 /5 ib */
8457   ins_encode( RegOpcImm( dst, shift) );
8458   ins_pipe( ialu_reg );
8459 %}
8460 
8461 
8462 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
8463 // This idiom is used by the compiler for the i2b bytecode.
8464 instruct i2b(rRegI dst, xRegI src, immI_24 twentyfour) %{
8465   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
8466 
8467   size(3);
8468   format %{ "MOVSX  $dst,$src :8" %}
8469   ins_encode %{
8470     __ movsbl($dst$$Register, $src$$Register);
8471   %}
8472   ins_pipe(ialu_reg_reg);
8473 %}
8474 
8475 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
8476 // This idiom is used by the compiler the i2s bytecode.
8477 instruct i2s(rRegI dst, xRegI src, immI_16 sixteen) %{
8478   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
8479 
8480   size(3);
8481   format %{ "MOVSX  $dst,$src :16" %}
8482   ins_encode %{
8483     __ movswl($dst$$Register, $src$$Register);
8484   %}
8485   ins_pipe(ialu_reg_reg);
8486 %}
8487 
8488 
8489 // Logical Shift Right by variable
8490 instruct shrI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
8491   match(Set dst (URShiftI dst shift));
8492   effect(KILL cr);
8493 
8494   size(2);
8495   format %{ "SHR    $dst,$shift" %}
8496   opcode(0xD3, 0x5);  /* D3 /5 */
8497   ins_encode( OpcP, RegOpc( dst ) );
8498   ins_pipe( ialu_reg_reg );
8499 %}
8500 
8501 
8502 //----------Logical Instructions-----------------------------------------------
8503 //----------Integer Logical Instructions---------------------------------------
8504 // And Instructions
8505 // And Register with Register
8506 instruct andI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
8507   match(Set dst (AndI dst src));
8508   effect(KILL cr);
8509 
8510   size(2);
8511   format %{ "AND    $dst,$src" %}
8512   opcode(0x23);
8513   ins_encode( OpcP, RegReg( dst, src) );
8514   ins_pipe( ialu_reg_reg );
8515 %}
8516 
8517 // And Register with Immediate
8518 instruct andI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
8519   match(Set dst (AndI dst src));
8520   effect(KILL cr);
8521 
8522   format %{ "AND    $dst,$src" %}
8523   opcode(0x81,0x04);  /* Opcode 81 /4 */
8524   // ins_encode( RegImm( dst, src) );
8525   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
8526   ins_pipe( ialu_reg );
8527 %}
8528 
8529 // And Register with Memory
8530 instruct andI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
8531   match(Set dst (AndI dst (LoadI src)));
8532   effect(KILL cr);
8533 
8534   ins_cost(125);
8535   format %{ "AND    $dst,$src" %}
8536   opcode(0x23);
8537   ins_encode( OpcP, RegMem( dst, src) );
8538   ins_pipe( ialu_reg_mem );
8539 %}
8540 
8541 // And Memory with Register
8542 instruct andI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
8543   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
8544   effect(KILL cr);
8545 
8546   ins_cost(150);
8547   format %{ "AND    $dst,$src" %}
8548   opcode(0x21);  /* Opcode 21 /r */
8549   ins_encode( OpcP, RegMem( src, dst ) );
8550   ins_pipe( ialu_mem_reg );
8551 %}
8552 
8553 // And Memory with Immediate
8554 instruct andI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
8555   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
8556   effect(KILL cr);
8557 
8558   ins_cost(125);
8559   format %{ "AND    $dst,$src" %}
8560   opcode(0x81, 0x4);  /* Opcode 81 /4 id */
8561   // ins_encode( MemImm( dst, src) );
8562   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
8563   ins_pipe( ialu_mem_imm );
8564 %}
8565 
8566 // Or Instructions
8567 // Or Register with Register
8568 instruct orI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
8569   match(Set dst (OrI dst src));
8570   effect(KILL cr);
8571 
8572   size(2);
8573   format %{ "OR     $dst,$src" %}
8574   opcode(0x0B);
8575   ins_encode( OpcP, RegReg( dst, src) );
8576   ins_pipe( ialu_reg_reg );
8577 %}
8578 
8579 instruct orI_eReg_castP2X(rRegI dst, eRegP src, eFlagsReg cr) %{
8580   match(Set dst (OrI dst (CastP2X src)));
8581   effect(KILL cr);
8582 
8583   size(2);
8584   format %{ "OR     $dst,$src" %}
8585   opcode(0x0B);
8586   ins_encode( OpcP, RegReg( dst, src) );
8587   ins_pipe( ialu_reg_reg );
8588 %}
8589 
8590 
8591 // Or Register with Immediate
8592 instruct orI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
8593   match(Set dst (OrI dst src));
8594   effect(KILL cr);
8595 
8596   format %{ "OR     $dst,$src" %}
8597   opcode(0x81,0x01);  /* Opcode 81 /1 id */
8598   // ins_encode( RegImm( dst, src) );
8599   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
8600   ins_pipe( ialu_reg );
8601 %}
8602 
8603 // Or Register with Memory
8604 instruct orI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
8605   match(Set dst (OrI dst (LoadI src)));
8606   effect(KILL cr);
8607 
8608   ins_cost(125);
8609   format %{ "OR     $dst,$src" %}
8610   opcode(0x0B);
8611   ins_encode( OpcP, RegMem( dst, src) );
8612   ins_pipe( ialu_reg_mem );
8613 %}
8614 
8615 // Or Memory with Register
8616 instruct orI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
8617   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
8618   effect(KILL cr);
8619 
8620   ins_cost(150);
8621   format %{ "OR     $dst,$src" %}
8622   opcode(0x09);  /* Opcode 09 /r */
8623   ins_encode( OpcP, RegMem( src, dst ) );
8624   ins_pipe( ialu_mem_reg );
8625 %}
8626 
8627 // Or Memory with Immediate
8628 instruct orI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
8629   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
8630   effect(KILL cr);
8631 
8632   ins_cost(125);
8633   format %{ "OR     $dst,$src" %}
8634   opcode(0x81,0x1);  /* Opcode 81 /1 id */
8635   // ins_encode( MemImm( dst, src) );
8636   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
8637   ins_pipe( ialu_mem_imm );
8638 %}
8639 
8640 // ROL/ROR
8641 // ROL expand
8642 instruct rolI_eReg_imm1(rRegI dst, immI1 shift, eFlagsReg cr) %{
8643   effect(USE_DEF dst, USE shift, KILL cr);
8644 
8645   format %{ "ROL    $dst, $shift" %}
8646   opcode(0xD1, 0x0); /* Opcode D1 /0 */
8647   ins_encode( OpcP, RegOpc( dst ));
8648   ins_pipe( ialu_reg );
8649 %}
8650 
8651 instruct rolI_eReg_imm8(rRegI dst, immI8 shift, eFlagsReg cr) %{
8652   effect(USE_DEF dst, USE shift, KILL cr);
8653 
8654   format %{ "ROL    $dst, $shift" %}
8655   opcode(0xC1, 0x0); /*Opcode /C1  /0  */
8656   ins_encode( RegOpcImm(dst, shift) );
8657   ins_pipe(ialu_reg);
8658 %}
8659 
8660 instruct rolI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr) %{
8661   effect(USE_DEF dst, USE shift, KILL cr);
8662 
8663   format %{ "ROL    $dst, $shift" %}
8664   opcode(0xD3, 0x0);    /* Opcode D3 /0 */
8665   ins_encode(OpcP, RegOpc(dst));
8666   ins_pipe( ialu_reg_reg );
8667 %}
8668 // end of ROL expand
8669 
8670 // ROL 32bit by one once
8671 instruct rolI_eReg_i1(rRegI dst, immI1 lshift, immI_M1 rshift, eFlagsReg cr) %{
8672   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
8673 
8674   expand %{
8675     rolI_eReg_imm1(dst, lshift, cr);
8676   %}
8677 %}
8678 
8679 // ROL 32bit var by imm8 once
8680 instruct rolI_eReg_i8(rRegI dst, immI8 lshift, immI8 rshift, eFlagsReg cr) %{
8681   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
8682   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
8683 
8684   expand %{
8685     rolI_eReg_imm8(dst, lshift, cr);
8686   %}
8687 %}
8688 
8689 // ROL 32bit var by var once
8690 instruct rolI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
8691   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI zero shift))));
8692 
8693   expand %{
8694     rolI_eReg_CL(dst, shift, cr);
8695   %}
8696 %}
8697 
8698 // ROL 32bit var by var once
8699 instruct rolI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
8700   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI c32 shift))));
8701 
8702   expand %{
8703     rolI_eReg_CL(dst, shift, cr);
8704   %}
8705 %}
8706 
8707 // ROR expand
8708 instruct rorI_eReg_imm1(rRegI dst, immI1 shift, eFlagsReg cr) %{
8709   effect(USE_DEF dst, USE shift, KILL cr);
8710 
8711   format %{ "ROR    $dst, $shift" %}
8712   opcode(0xD1,0x1);  /* Opcode D1 /1 */
8713   ins_encode( OpcP, RegOpc( dst ) );
8714   ins_pipe( ialu_reg );
8715 %}
8716 
8717 instruct rorI_eReg_imm8(rRegI dst, immI8 shift, eFlagsReg cr) %{
8718   effect (USE_DEF dst, USE shift, KILL cr);
8719 
8720   format %{ "ROR    $dst, $shift" %}
8721   opcode(0xC1, 0x1); /* Opcode /C1 /1 ib */
8722   ins_encode( RegOpcImm(dst, shift) );
8723   ins_pipe( ialu_reg );
8724 %}
8725 
8726 instruct rorI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr)%{
8727   effect(USE_DEF dst, USE shift, KILL cr);
8728 
8729   format %{ "ROR    $dst, $shift" %}
8730   opcode(0xD3, 0x1);    /* Opcode D3 /1 */
8731   ins_encode(OpcP, RegOpc(dst));
8732   ins_pipe( ialu_reg_reg );
8733 %}
8734 // end of ROR expand
8735 
8736 // ROR right once
8737 instruct rorI_eReg_i1(rRegI dst, immI1 rshift, immI_M1 lshift, eFlagsReg cr) %{
8738   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
8739 
8740   expand %{
8741     rorI_eReg_imm1(dst, rshift, cr);
8742   %}
8743 %}
8744 
8745 // ROR 32bit by immI8 once
8746 instruct rorI_eReg_i8(rRegI dst, immI8 rshift, immI8 lshift, eFlagsReg cr) %{
8747   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
8748   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
8749 
8750   expand %{
8751     rorI_eReg_imm8(dst, rshift, cr);
8752   %}
8753 %}
8754 
8755 // ROR 32bit var by var once
8756 instruct rorI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
8757   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI zero shift))));
8758 
8759   expand %{
8760     rorI_eReg_CL(dst, shift, cr);
8761   %}
8762 %}
8763 
8764 // ROR 32bit var by var once
8765 instruct rorI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
8766   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI c32 shift))));
8767 
8768   expand %{
8769     rorI_eReg_CL(dst, shift, cr);
8770   %}
8771 %}
8772 
8773 // Xor Instructions
8774 // Xor Register with Register
8775 instruct xorI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
8776   match(Set dst (XorI dst src));
8777   effect(KILL cr);
8778 
8779   size(2);
8780   format %{ "XOR    $dst,$src" %}
8781   opcode(0x33);
8782   ins_encode( OpcP, RegReg( dst, src) );
8783   ins_pipe( ialu_reg_reg );
8784 %}
8785 
8786 // Xor Register with Immediate -1
8787 instruct xorI_eReg_im1(rRegI dst, immI_M1 imm) %{
8788   match(Set dst (XorI dst imm));  
8789 
8790   size(2);
8791   format %{ "NOT    $dst" %}  
8792   ins_encode %{
8793      __ notl($dst$$Register);
8794   %}
8795   ins_pipe( ialu_reg );
8796 %}
8797 
8798 // Xor Register with Immediate
8799 instruct xorI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
8800   match(Set dst (XorI dst src));
8801   effect(KILL cr);
8802 
8803   format %{ "XOR    $dst,$src" %}
8804   opcode(0x81,0x06);  /* Opcode 81 /6 id */
8805   // ins_encode( RegImm( dst, src) );
8806   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
8807   ins_pipe( ialu_reg );
8808 %}
8809 
8810 // Xor Register with Memory
8811 instruct xorI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
8812   match(Set dst (XorI dst (LoadI src)));
8813   effect(KILL cr);
8814 
8815   ins_cost(125);
8816   format %{ "XOR    $dst,$src" %}
8817   opcode(0x33);
8818   ins_encode( OpcP, RegMem(dst, src) );
8819   ins_pipe( ialu_reg_mem );
8820 %}
8821 
8822 // Xor Memory with Register
8823 instruct xorI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
8824   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
8825   effect(KILL cr);
8826 
8827   ins_cost(150);
8828   format %{ "XOR    $dst,$src" %}
8829   opcode(0x31);  /* Opcode 31 /r */
8830   ins_encode( OpcP, RegMem( src, dst ) );
8831   ins_pipe( ialu_mem_reg );
8832 %}
8833 
8834 // Xor Memory with Immediate
8835 instruct xorI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
8836   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
8837   effect(KILL cr);
8838 
8839   ins_cost(125);
8840   format %{ "XOR    $dst,$src" %}
8841   opcode(0x81,0x6);  /* Opcode 81 /6 id */
8842   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
8843   ins_pipe( ialu_mem_imm );
8844 %}
8845 
8846 //----------Convert Int to Boolean---------------------------------------------
8847 
8848 instruct movI_nocopy(rRegI dst, rRegI src) %{
8849   effect( DEF dst, USE src );
8850   format %{ "MOV    $dst,$src" %}
8851   ins_encode( enc_Copy( dst, src) );
8852   ins_pipe( ialu_reg_reg );
8853 %}
8854 
8855 instruct ci2b( rRegI dst, rRegI src, eFlagsReg cr ) %{
8856   effect( USE_DEF dst, USE src, KILL cr );
8857 
8858   size(4);
8859   format %{ "NEG    $dst\n\t"
8860             "ADC    $dst,$src" %}
8861   ins_encode( neg_reg(dst),
8862               OpcRegReg(0x13,dst,src) );
8863   ins_pipe( ialu_reg_reg_long );
8864 %}
8865 
8866 instruct convI2B( rRegI dst, rRegI src, eFlagsReg cr ) %{
8867   match(Set dst (Conv2B src));
8868 
8869   expand %{
8870     movI_nocopy(dst,src);
8871     ci2b(dst,src,cr);
8872   %}
8873 %}
8874 
8875 instruct movP_nocopy(rRegI dst, eRegP src) %{
8876   effect( DEF dst, USE src );
8877   format %{ "MOV    $dst,$src" %}
8878   ins_encode( enc_Copy( dst, src) );
8879   ins_pipe( ialu_reg_reg );
8880 %}
8881 
8882 instruct cp2b( rRegI dst, eRegP src, eFlagsReg cr ) %{
8883   effect( USE_DEF dst, USE src, KILL cr );
8884   format %{ "NEG    $dst\n\t"
8885             "ADC    $dst,$src" %}
8886   ins_encode( neg_reg(dst),
8887               OpcRegReg(0x13,dst,src) );
8888   ins_pipe( ialu_reg_reg_long );
8889 %}
8890 
8891 instruct convP2B( rRegI dst, eRegP src, eFlagsReg cr ) %{
8892   match(Set dst (Conv2B src));
8893 
8894   expand %{
8895     movP_nocopy(dst,src);
8896     cp2b(dst,src,cr);
8897   %}
8898 %}
8899 
8900 instruct cmpLTMask(eCXRegI dst, ncxRegI p, ncxRegI q, eFlagsReg cr) %{
8901   match(Set dst (CmpLTMask p q));
8902   effect(KILL cr);
8903   ins_cost(400);
8904 
8905   // SETlt can only use low byte of EAX,EBX, ECX, or EDX as destination
8906   format %{ "XOR    $dst,$dst\n\t"
8907             "CMP    $p,$q\n\t"
8908             "SETlt  $dst\n\t"
8909             "NEG    $dst" %}
8910   ins_encode %{
8911     Register Rp = $p$$Register;
8912     Register Rq = $q$$Register;
8913     Register Rd = $dst$$Register;
8914     Label done;
8915     __ xorl(Rd, Rd);
8916     __ cmpl(Rp, Rq);
8917     __ setb(Assembler::less, Rd);
8918     __ negl(Rd);
8919   %}
8920 
8921   ins_pipe(pipe_slow);
8922 %}
8923 
8924 instruct cmpLTMask0(rRegI dst, immI0 zero, eFlagsReg cr) %{
8925   match(Set dst (CmpLTMask dst zero));
8926   effect(DEF dst, KILL cr);
8927   ins_cost(100);
8928 
8929   format %{ "SAR    $dst,31\t# cmpLTMask0" %}
8930   ins_encode %{
8931   __ sarl($dst$$Register, 31);
8932   %}
8933   ins_pipe(ialu_reg);
8934 %}
8935 
8936 /* better to save a register than avoid a branch */
8937 instruct cadd_cmpLTMask(rRegI p, rRegI q, rRegI y, eFlagsReg cr) %{
8938   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
8939   effect(KILL cr);
8940   ins_cost(400);
8941   format %{ "SUB    $p,$q\t# cadd_cmpLTMask\n\t"
8942             "JGE    done\n\t"
8943             "ADD    $p,$y\n"
8944             "done:  " %}
8945   ins_encode %{
8946     Register Rp = $p$$Register;
8947     Register Rq = $q$$Register;
8948     Register Ry = $y$$Register;
8949     Label done;
8950     __ subl(Rp, Rq);
8951     __ jccb(Assembler::greaterEqual, done);
8952     __ addl(Rp, Ry);
8953     __ bind(done);
8954   %}
8955 
8956   ins_pipe(pipe_cmplt);
8957 %}
8958 
8959 /* better to save a register than avoid a branch */
8960 instruct and_cmpLTMask(rRegI p, rRegI q, rRegI y, eFlagsReg cr) %{
8961   match(Set y (AndI (CmpLTMask p q) y));
8962   effect(KILL cr);
8963 
8964   ins_cost(300);
8965 
8966   format %{ "CMPL     $p, $q\t# and_cmpLTMask\n\t"
8967             "JLT      done\n\t"
8968             "XORL     $y, $y\n"
8969             "done:  " %}
8970   ins_encode %{
8971     Register Rp = $p$$Register;
8972     Register Rq = $q$$Register;
8973     Register Ry = $y$$Register;
8974     Label done;
8975     __ cmpl(Rp, Rq);
8976     __ jccb(Assembler::less, done);
8977     __ xorl(Ry, Ry);
8978     __ bind(done);
8979   %}
8980 
8981   ins_pipe(pipe_cmplt);
8982 %}
8983 
8984 /* If I enable this, I encourage spilling in the inner loop of compress.
8985 instruct cadd_cmpLTMask_mem(ncxRegI p, ncxRegI q, memory y, eCXRegI tmp, eFlagsReg cr) %{
8986   match(Set p (AddI (AndI (CmpLTMask p q) (LoadI y)) (SubI p q)));
8987 */
8988 //----------Overflow Math Instructions-----------------------------------------
8989 
8990 instruct overflowAddI_eReg(eFlagsReg cr, eAXRegI op1, rRegI op2)
8991 %{
8992   match(Set cr (OverflowAddI op1 op2));
8993   effect(DEF cr, USE_KILL op1, USE op2);
8994 
8995   format %{ "ADD    $op1, $op2\t# overflow check int" %}
8996 
8997   ins_encode %{
8998     __ addl($op1$$Register, $op2$$Register);
8999   %}
9000   ins_pipe(ialu_reg_reg);
9001 %}
9002 
9003 instruct overflowAddI_rReg_imm(eFlagsReg cr, eAXRegI op1, immI op2)
9004 %{
9005   match(Set cr (OverflowAddI op1 op2));
9006   effect(DEF cr, USE_KILL op1, USE op2);
9007 
9008   format %{ "ADD    $op1, $op2\t# overflow check int" %}
9009 
9010   ins_encode %{
9011     __ addl($op1$$Register, $op2$$constant);
9012   %}
9013   ins_pipe(ialu_reg_reg);
9014 %}
9015 
9016 instruct overflowSubI_rReg(eFlagsReg cr, eAXRegI op1, rRegI op2)
9017 %{
9018   match(Set cr (OverflowSubI op1 op2));
9019 
9020   format %{ "CMP    $op1, $op2\t# overflow check int" %}
9021   ins_encode %{
9022     __ cmpl($op1$$Register, $op2$$Register);
9023   %}
9024   ins_pipe(ialu_reg_reg);
9025 %}
9026 
9027 instruct overflowSubI_rReg_imm(eFlagsReg cr, eAXRegI op1, immI op2)
9028 %{
9029   match(Set cr (OverflowSubI op1 op2));
9030 
9031   format %{ "CMP    $op1, $op2\t# overflow check int" %}
9032   ins_encode %{
9033     __ cmpl($op1$$Register, $op2$$constant);
9034   %}
9035   ins_pipe(ialu_reg_reg);
9036 %}
9037 
9038 instruct overflowNegI_rReg(eFlagsReg cr, immI0 zero, eAXRegI op2)
9039 %{
9040   match(Set cr (OverflowSubI zero op2));
9041   effect(DEF cr, USE_KILL op2);
9042 
9043   format %{ "NEG    $op2\t# overflow check int" %}
9044   ins_encode %{
9045     __ negl($op2$$Register);
9046   %}
9047   ins_pipe(ialu_reg_reg);
9048 %}
9049 
9050 instruct overflowMulI_rReg(eFlagsReg cr, eAXRegI op1, rRegI op2)
9051 %{
9052   match(Set cr (OverflowMulI op1 op2));
9053   effect(DEF cr, USE_KILL op1, USE op2);
9054 
9055   format %{ "IMUL    $op1, $op2\t# overflow check int" %}
9056   ins_encode %{
9057     __ imull($op1$$Register, $op2$$Register);
9058   %}
9059   ins_pipe(ialu_reg_reg_alu0);
9060 %}
9061 
9062 instruct overflowMulI_rReg_imm(eFlagsReg cr, rRegI op1, immI op2, rRegI tmp)
9063 %{
9064   match(Set cr (OverflowMulI op1 op2));
9065   effect(DEF cr, TEMP tmp, USE op1, USE op2);
9066 
9067   format %{ "IMUL    $tmp, $op1, $op2\t# overflow check int" %}
9068   ins_encode %{
9069     __ imull($tmp$$Register, $op1$$Register, $op2$$constant);
9070   %}
9071   ins_pipe(ialu_reg_reg_alu0);
9072 %}
9073 
9074 //----------Long Instructions------------------------------------------------
9075 // Add Long Register with Register
9076 instruct addL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
9077   match(Set dst (AddL dst src));
9078   effect(KILL cr);
9079   ins_cost(200);
9080   format %{ "ADD    $dst.lo,$src.lo\n\t"
9081             "ADC    $dst.hi,$src.hi" %}
9082   opcode(0x03, 0x13);
9083   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
9084   ins_pipe( ialu_reg_reg_long );
9085 %}
9086 
9087 // Add Long Register with Immediate
9088 instruct addL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
9089   match(Set dst (AddL dst src));
9090   effect(KILL cr);
9091   format %{ "ADD    $dst.lo,$src.lo\n\t"
9092             "ADC    $dst.hi,$src.hi" %}
9093   opcode(0x81,0x00,0x02);  /* Opcode 81 /0, 81 /2 */
9094   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
9095   ins_pipe( ialu_reg_long );
9096 %}
9097 
9098 // Add Long Register with Memory
9099 instruct addL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
9100   match(Set dst (AddL dst (LoadL mem)));
9101   effect(KILL cr);
9102   ins_cost(125);
9103   format %{ "ADD    $dst.lo,$mem\n\t"
9104             "ADC    $dst.hi,$mem+4" %}
9105   opcode(0x03, 0x13);
9106   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
9107   ins_pipe( ialu_reg_long_mem );
9108 %}
9109 
9110 // Subtract Long Register with Register.
9111 instruct subL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
9112   match(Set dst (SubL dst src));
9113   effect(KILL cr);
9114   ins_cost(200);
9115   format %{ "SUB    $dst.lo,$src.lo\n\t"
9116             "SBB    $dst.hi,$src.hi" %}
9117   opcode(0x2B, 0x1B);
9118   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
9119   ins_pipe( ialu_reg_reg_long );
9120 %}
9121 
9122 // Subtract Long Register with Immediate
9123 instruct subL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
9124   match(Set dst (SubL dst src));
9125   effect(KILL cr);
9126   format %{ "SUB    $dst.lo,$src.lo\n\t"
9127             "SBB    $dst.hi,$src.hi" %}
9128   opcode(0x81,0x05,0x03);  /* Opcode 81 /5, 81 /3 */
9129   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
9130   ins_pipe( ialu_reg_long );
9131 %}
9132 
9133 // Subtract Long Register with Memory
9134 instruct subL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
9135   match(Set dst (SubL dst (LoadL mem)));
9136   effect(KILL cr);
9137   ins_cost(125);
9138   format %{ "SUB    $dst.lo,$mem\n\t"
9139             "SBB    $dst.hi,$mem+4" %}
9140   opcode(0x2B, 0x1B);
9141   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
9142   ins_pipe( ialu_reg_long_mem );
9143 %}
9144 
9145 instruct negL_eReg(eRegL dst, immL0 zero, eFlagsReg cr) %{
9146   match(Set dst (SubL zero dst));
9147   effect(KILL cr);
9148   ins_cost(300);
9149   format %{ "NEG    $dst.hi\n\tNEG    $dst.lo\n\tSBB    $dst.hi,0" %}
9150   ins_encode( neg_long(dst) );
9151   ins_pipe( ialu_reg_reg_long );
9152 %}
9153 
9154 // And Long Register with Register
9155 instruct andL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
9156   match(Set dst (AndL dst src));
9157   effect(KILL cr);
9158   format %{ "AND    $dst.lo,$src.lo\n\t"
9159             "AND    $dst.hi,$src.hi" %}
9160   opcode(0x23,0x23);
9161   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
9162   ins_pipe( ialu_reg_reg_long );
9163 %}
9164 
9165 // And Long Register with Immediate
9166 instruct andL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
9167   match(Set dst (AndL dst src));
9168   effect(KILL cr);
9169   format %{ "AND    $dst.lo,$src.lo\n\t"
9170             "AND    $dst.hi,$src.hi" %}
9171   opcode(0x81,0x04,0x04);  /* Opcode 81 /4, 81 /4 */
9172   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
9173   ins_pipe( ialu_reg_long );
9174 %}
9175 
9176 // And Long Register with Memory
9177 instruct andL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
9178   match(Set dst (AndL dst (LoadL mem)));
9179   effect(KILL cr);
9180   ins_cost(125);
9181   format %{ "AND    $dst.lo,$mem\n\t"
9182             "AND    $dst.hi,$mem+4" %}
9183   opcode(0x23, 0x23);
9184   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
9185   ins_pipe( ialu_reg_long_mem );
9186 %}
9187 
9188 // Or Long Register with Register
9189 instruct orl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
9190   match(Set dst (OrL dst src));
9191   effect(KILL cr);
9192   format %{ "OR     $dst.lo,$src.lo\n\t"
9193             "OR     $dst.hi,$src.hi" %}
9194   opcode(0x0B,0x0B);
9195   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
9196   ins_pipe( ialu_reg_reg_long );
9197 %}
9198 
9199 // Or Long Register with Immediate
9200 instruct orl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
9201   match(Set dst (OrL dst src));
9202   effect(KILL cr);
9203   format %{ "OR     $dst.lo,$src.lo\n\t"
9204             "OR     $dst.hi,$src.hi" %}
9205   opcode(0x81,0x01,0x01);  /* Opcode 81 /1, 81 /1 */
9206   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
9207   ins_pipe( ialu_reg_long );
9208 %}
9209 
9210 // Or Long Register with Memory
9211 instruct orl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
9212   match(Set dst (OrL dst (LoadL mem)));
9213   effect(KILL cr);
9214   ins_cost(125);
9215   format %{ "OR     $dst.lo,$mem\n\t"
9216             "OR     $dst.hi,$mem+4" %}
9217   opcode(0x0B,0x0B);
9218   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
9219   ins_pipe( ialu_reg_long_mem );
9220 %}
9221 
9222 // Xor Long Register with Register
9223 instruct xorl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
9224   match(Set dst (XorL dst src));
9225   effect(KILL cr);
9226   format %{ "XOR    $dst.lo,$src.lo\n\t"
9227             "XOR    $dst.hi,$src.hi" %}
9228   opcode(0x33,0x33);
9229   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
9230   ins_pipe( ialu_reg_reg_long );
9231 %}
9232 
9233 // Xor Long Register with Immediate -1
9234 instruct xorl_eReg_im1(eRegL dst, immL_M1 imm) %{
9235   match(Set dst (XorL dst imm));  
9236   format %{ "NOT    $dst.lo\n\t"
9237             "NOT    $dst.hi" %}
9238   ins_encode %{
9239      __ notl($dst$$Register);
9240      __ notl(HIGH_FROM_LOW($dst$$Register));
9241   %}
9242   ins_pipe( ialu_reg_long );
9243 %}
9244 
9245 // Xor Long Register with Immediate
9246 instruct xorl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
9247   match(Set dst (XorL dst src));
9248   effect(KILL cr);
9249   format %{ "XOR    $dst.lo,$src.lo\n\t"
9250             "XOR    $dst.hi,$src.hi" %}
9251   opcode(0x81,0x06,0x06);  /* Opcode 81 /6, 81 /6 */
9252   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
9253   ins_pipe( ialu_reg_long );
9254 %}
9255 
9256 // Xor Long Register with Memory
9257 instruct xorl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
9258   match(Set dst (XorL dst (LoadL mem)));
9259   effect(KILL cr);
9260   ins_cost(125);
9261   format %{ "XOR    $dst.lo,$mem\n\t"
9262             "XOR    $dst.hi,$mem+4" %}
9263   opcode(0x33,0x33);
9264   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
9265   ins_pipe( ialu_reg_long_mem );
9266 %}
9267 
9268 // Shift Left Long by 1
9269 instruct shlL_eReg_1(eRegL dst, immI_1 cnt, eFlagsReg cr) %{
9270   predicate(UseNewLongLShift);
9271   match(Set dst (LShiftL dst cnt));
9272   effect(KILL cr);
9273   ins_cost(100);
9274   format %{ "ADD    $dst.lo,$dst.lo\n\t"
9275             "ADC    $dst.hi,$dst.hi" %}
9276   ins_encode %{
9277     __ addl($dst$$Register,$dst$$Register);
9278     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9279   %}
9280   ins_pipe( ialu_reg_long );
9281 %}
9282 
9283 // Shift Left Long by 2
9284 instruct shlL_eReg_2(eRegL dst, immI_2 cnt, eFlagsReg cr) %{
9285   predicate(UseNewLongLShift);
9286   match(Set dst (LShiftL dst cnt));
9287   effect(KILL cr);
9288   ins_cost(100);
9289   format %{ "ADD    $dst.lo,$dst.lo\n\t"
9290             "ADC    $dst.hi,$dst.hi\n\t" 
9291             "ADD    $dst.lo,$dst.lo\n\t"
9292             "ADC    $dst.hi,$dst.hi" %}
9293   ins_encode %{
9294     __ addl($dst$$Register,$dst$$Register);
9295     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9296     __ addl($dst$$Register,$dst$$Register);
9297     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9298   %}
9299   ins_pipe( ialu_reg_long );
9300 %}
9301 
9302 // Shift Left Long by 3
9303 instruct shlL_eReg_3(eRegL dst, immI_3 cnt, eFlagsReg cr) %{
9304   predicate(UseNewLongLShift);
9305   match(Set dst (LShiftL dst cnt));
9306   effect(KILL cr);
9307   ins_cost(100);
9308   format %{ "ADD    $dst.lo,$dst.lo\n\t"
9309             "ADC    $dst.hi,$dst.hi\n\t" 
9310             "ADD    $dst.lo,$dst.lo\n\t"
9311             "ADC    $dst.hi,$dst.hi\n\t" 
9312             "ADD    $dst.lo,$dst.lo\n\t"
9313             "ADC    $dst.hi,$dst.hi" %}
9314   ins_encode %{
9315     __ addl($dst$$Register,$dst$$Register);
9316     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9317     __ addl($dst$$Register,$dst$$Register);
9318     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9319     __ addl($dst$$Register,$dst$$Register);
9320     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
9321   %}
9322   ins_pipe( ialu_reg_long );
9323 %}
9324 
9325 // Shift Left Long by 1-31
9326 instruct shlL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
9327   match(Set dst (LShiftL dst cnt));
9328   effect(KILL cr);
9329   ins_cost(200);
9330   format %{ "SHLD   $dst.hi,$dst.lo,$cnt\n\t"
9331             "SHL    $dst.lo,$cnt" %}
9332   opcode(0xC1, 0x4, 0xA4);  /* 0F/A4, then C1 /4 ib */
9333   ins_encode( move_long_small_shift(dst,cnt) );
9334   ins_pipe( ialu_reg_long );
9335 %}
9336 
9337 // Shift Left Long by 32-63
9338 instruct shlL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
9339   match(Set dst (LShiftL dst cnt));
9340   effect(KILL cr);
9341   ins_cost(300);
9342   format %{ "MOV    $dst.hi,$dst.lo\n"
9343           "\tSHL    $dst.hi,$cnt-32\n"
9344           "\tXOR    $dst.lo,$dst.lo" %}
9345   opcode(0xC1, 0x4);  /* C1 /4 ib */
9346   ins_encode( move_long_big_shift_clr(dst,cnt) );
9347   ins_pipe( ialu_reg_long );
9348 %}
9349 
9350 // Shift Left Long by variable
9351 instruct salL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
9352   match(Set dst (LShiftL dst shift));
9353   effect(KILL cr);
9354   ins_cost(500+200);
9355   size(17);
9356   format %{ "TEST   $shift,32\n\t"
9357             "JEQ,s  small\n\t"
9358             "MOV    $dst.hi,$dst.lo\n\t"
9359             "XOR    $dst.lo,$dst.lo\n"
9360     "small:\tSHLD   $dst.hi,$dst.lo,$shift\n\t"
9361             "SHL    $dst.lo,$shift" %}
9362   ins_encode( shift_left_long( dst, shift ) );
9363   ins_pipe( pipe_slow );
9364 %}
9365 
9366 // Shift Right Long by 1-31
9367 instruct shrL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
9368   match(Set dst (URShiftL dst cnt));
9369   effect(KILL cr);
9370   ins_cost(200);
9371   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
9372             "SHR    $dst.hi,$cnt" %}
9373   opcode(0xC1, 0x5, 0xAC);  /* 0F/AC, then C1 /5 ib */
9374   ins_encode( move_long_small_shift(dst,cnt) );
9375   ins_pipe( ialu_reg_long );
9376 %}
9377 
9378 // Shift Right Long by 32-63
9379 instruct shrL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
9380   match(Set dst (URShiftL dst cnt));
9381   effect(KILL cr);
9382   ins_cost(300);
9383   format %{ "MOV    $dst.lo,$dst.hi\n"
9384           "\tSHR    $dst.lo,$cnt-32\n"
9385           "\tXOR    $dst.hi,$dst.hi" %}
9386   opcode(0xC1, 0x5);  /* C1 /5 ib */
9387   ins_encode( move_long_big_shift_clr(dst,cnt) );
9388   ins_pipe( ialu_reg_long );
9389 %}
9390 
9391 // Shift Right Long by variable
9392 instruct shrL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
9393   match(Set dst (URShiftL dst shift));
9394   effect(KILL cr);
9395   ins_cost(600);
9396   size(17);
9397   format %{ "TEST   $shift,32\n\t"
9398             "JEQ,s  small\n\t"
9399             "MOV    $dst.lo,$dst.hi\n\t"
9400             "XOR    $dst.hi,$dst.hi\n"
9401     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
9402             "SHR    $dst.hi,$shift" %}
9403   ins_encode( shift_right_long( dst, shift ) );
9404   ins_pipe( pipe_slow );
9405 %}
9406 
9407 // Shift Right Long by 1-31
9408 instruct sarL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
9409   match(Set dst (RShiftL dst cnt));
9410   effect(KILL cr);
9411   ins_cost(200);
9412   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
9413             "SAR    $dst.hi,$cnt" %}
9414   opcode(0xC1, 0x7, 0xAC);  /* 0F/AC, then C1 /7 ib */
9415   ins_encode( move_long_small_shift(dst,cnt) );
9416   ins_pipe( ialu_reg_long );
9417 %}
9418 
9419 // Shift Right Long by 32-63
9420 instruct sarL_eReg_32_63( eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
9421   match(Set dst (RShiftL dst cnt));
9422   effect(KILL cr);
9423   ins_cost(300);
9424   format %{ "MOV    $dst.lo,$dst.hi\n"
9425           "\tSAR    $dst.lo,$cnt-32\n"
9426           "\tSAR    $dst.hi,31" %}
9427   opcode(0xC1, 0x7);  /* C1 /7 ib */
9428   ins_encode( move_long_big_shift_sign(dst,cnt) );
9429   ins_pipe( ialu_reg_long );
9430 %}
9431 
9432 // Shift Right arithmetic Long by variable
9433 instruct sarL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
9434   match(Set dst (RShiftL dst shift));
9435   effect(KILL cr);
9436   ins_cost(600);
9437   size(18);
9438   format %{ "TEST   $shift,32\n\t"
9439             "JEQ,s  small\n\t"
9440             "MOV    $dst.lo,$dst.hi\n\t"
9441             "SAR    $dst.hi,31\n"
9442     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
9443             "SAR    $dst.hi,$shift" %}
9444   ins_encode( shift_right_arith_long( dst, shift ) );
9445   ins_pipe( pipe_slow );
9446 %}
9447 
9448 
9449 //----------Double Instructions------------------------------------------------
9450 // Double Math
9451 
9452 // Compare & branch
9453 
9454 // P6 version of float compare, sets condition codes in EFLAGS
9455 instruct cmpDPR_cc_P6(eFlagsRegU cr, regDPR src1, regDPR src2, eAXRegI rax) %{
9456   predicate(VM_Version::supports_cmov() && UseSSE <=1);
9457   match(Set cr (CmpD src1 src2));
9458   effect(KILL rax);
9459   ins_cost(150);
9460   format %{ "FLD    $src1\n\t"
9461             "FUCOMIP ST,$src2  // P6 instruction\n\t"
9462             "JNP    exit\n\t"
9463             "MOV    ah,1       // saw a NaN, set CF\n\t"
9464             "SAHF\n"
9465      "exit:\tNOP               // avoid branch to branch" %}
9466   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
9467   ins_encode( Push_Reg_DPR(src1),
9468               OpcP, RegOpc(src2),
9469               cmpF_P6_fixup );
9470   ins_pipe( pipe_slow );
9471 %}
9472 
9473 instruct cmpDPR_cc_P6CF(eFlagsRegUCF cr, regDPR src1, regDPR src2) %{
9474   predicate(VM_Version::supports_cmov() && UseSSE <=1);
9475   match(Set cr (CmpD src1 src2));
9476   ins_cost(150);
9477   format %{ "FLD    $src1\n\t"
9478             "FUCOMIP ST,$src2  // P6 instruction" %}
9479   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
9480   ins_encode( Push_Reg_DPR(src1),
9481               OpcP, RegOpc(src2));
9482   ins_pipe( pipe_slow );
9483 %}
9484 
9485 // Compare & branch
9486 instruct cmpDPR_cc(eFlagsRegU cr, regDPR src1, regDPR src2, eAXRegI rax) %{
9487   predicate(UseSSE<=1);
9488   match(Set cr (CmpD src1 src2));
9489   effect(KILL rax);
9490   ins_cost(200);
9491   format %{ "FLD    $src1\n\t"
9492             "FCOMp  $src2\n\t"
9493             "FNSTSW AX\n\t"
9494             "TEST   AX,0x400\n\t"
9495             "JZ,s   flags\n\t"
9496             "MOV    AH,1\t# unordered treat as LT\n"
9497     "flags:\tSAHF" %}
9498   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
9499   ins_encode( Push_Reg_DPR(src1),
9500               OpcP, RegOpc(src2),
9501               fpu_flags);
9502   ins_pipe( pipe_slow );
9503 %}
9504 
9505 // Compare vs zero into -1,0,1
9506 instruct cmpDPR_0(rRegI dst, regDPR src1, immDPR0 zero, eAXRegI rax, eFlagsReg cr) %{
9507   predicate(UseSSE<=1);
9508   match(Set dst (CmpD3 src1 zero));
9509   effect(KILL cr, KILL rax);
9510   ins_cost(280);
9511   format %{ "FTSTD  $dst,$src1" %}
9512   opcode(0xE4, 0xD9);
9513   ins_encode( Push_Reg_DPR(src1),
9514               OpcS, OpcP, PopFPU,
9515               CmpF_Result(dst));
9516   ins_pipe( pipe_slow );
9517 %}
9518 
9519 // Compare into -1,0,1
9520 instruct cmpDPR_reg(rRegI dst, regDPR src1, regDPR src2, eAXRegI rax, eFlagsReg cr) %{
9521   predicate(UseSSE<=1);
9522   match(Set dst (CmpD3 src1 src2));
9523   effect(KILL cr, KILL rax);
9524   ins_cost(300);
9525   format %{ "FCMPD  $dst,$src1,$src2" %}
9526   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
9527   ins_encode( Push_Reg_DPR(src1),
9528               OpcP, RegOpc(src2),
9529               CmpF_Result(dst));
9530   ins_pipe( pipe_slow );
9531 %}
9532 
9533 // float compare and set condition codes in EFLAGS by XMM regs
9534 instruct cmpD_cc(eFlagsRegU cr, regD src1, regD src2) %{
9535   predicate(UseSSE>=2);
9536   match(Set cr (CmpD src1 src2));
9537   ins_cost(145);
9538   format %{ "UCOMISD $src1,$src2\n\t"
9539             "JNP,s   exit\n\t"
9540             "PUSHF\t# saw NaN, set CF\n\t"
9541             "AND     [rsp], #0xffffff2b\n\t"
9542             "POPF\n"
9543     "exit:" %}
9544   ins_encode %{
9545     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
9546     emit_cmpfp_fixup(_masm);
9547   %}
9548   ins_pipe( pipe_slow );
9549 %}
9550 
9551 instruct cmpD_ccCF(eFlagsRegUCF cr, regD src1, regD src2) %{
9552   predicate(UseSSE>=2);
9553   match(Set cr (CmpD src1 src2));
9554   ins_cost(100);
9555   format %{ "UCOMISD $src1,$src2" %}
9556   ins_encode %{
9557     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
9558   %}
9559   ins_pipe( pipe_slow );
9560 %}
9561 
9562 // float compare and set condition codes in EFLAGS by XMM regs
9563 instruct cmpD_ccmem(eFlagsRegU cr, regD src1, memory src2) %{
9564   predicate(UseSSE>=2);
9565   match(Set cr (CmpD src1 (LoadD src2)));
9566   ins_cost(145);
9567   format %{ "UCOMISD $src1,$src2\n\t"
9568             "JNP,s   exit\n\t"
9569             "PUSHF\t# saw NaN, set CF\n\t"
9570             "AND     [rsp], #0xffffff2b\n\t"
9571             "POPF\n"
9572     "exit:" %}
9573   ins_encode %{
9574     __ ucomisd($src1$$XMMRegister, $src2$$Address);
9575     emit_cmpfp_fixup(_masm);
9576   %}
9577   ins_pipe( pipe_slow );
9578 %}
9579 
9580 instruct cmpD_ccmemCF(eFlagsRegUCF cr, regD src1, memory src2) %{
9581   predicate(UseSSE>=2);
9582   match(Set cr (CmpD src1 (LoadD src2)));
9583   ins_cost(100);
9584   format %{ "UCOMISD $src1,$src2" %}
9585   ins_encode %{
9586     __ ucomisd($src1$$XMMRegister, $src2$$Address);
9587   %}
9588   ins_pipe( pipe_slow );
9589 %}
9590 
9591 // Compare into -1,0,1 in XMM
9592 instruct cmpD_reg(xRegI dst, regD src1, regD src2, eFlagsReg cr) %{
9593   predicate(UseSSE>=2);
9594   match(Set dst (CmpD3 src1 src2));
9595   effect(KILL cr);
9596   ins_cost(255);
9597   format %{ "UCOMISD $src1, $src2\n\t"
9598             "MOV     $dst, #-1\n\t"
9599             "JP,s    done\n\t"
9600             "JB,s    done\n\t"
9601             "SETNE   $dst\n\t"
9602             "MOVZB   $dst, $dst\n"
9603     "done:" %}
9604   ins_encode %{
9605     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
9606     emit_cmpfp3(_masm, $dst$$Register);
9607   %}
9608   ins_pipe( pipe_slow );
9609 %}
9610 
9611 // Compare into -1,0,1 in XMM and memory
9612 instruct cmpD_regmem(xRegI dst, regD src1, memory src2, eFlagsReg cr) %{
9613   predicate(UseSSE>=2);
9614   match(Set dst (CmpD3 src1 (LoadD src2)));
9615   effect(KILL cr);
9616   ins_cost(275);
9617   format %{ "UCOMISD $src1, $src2\n\t"
9618             "MOV     $dst, #-1\n\t"
9619             "JP,s    done\n\t"
9620             "JB,s    done\n\t"
9621             "SETNE   $dst\n\t"
9622             "MOVZB   $dst, $dst\n"
9623     "done:" %}
9624   ins_encode %{
9625     __ ucomisd($src1$$XMMRegister, $src2$$Address);
9626     emit_cmpfp3(_masm, $dst$$Register);
9627   %}
9628   ins_pipe( pipe_slow );
9629 %}
9630 
9631 
9632 instruct subDPR_reg(regDPR dst, regDPR src) %{
9633   predicate (UseSSE <=1);
9634   match(Set dst (SubD dst src));
9635 
9636   format %{ "FLD    $src\n\t"
9637             "DSUBp  $dst,ST" %}
9638   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
9639   ins_cost(150);
9640   ins_encode( Push_Reg_DPR(src),
9641               OpcP, RegOpc(dst) );
9642   ins_pipe( fpu_reg_reg );
9643 %}
9644 
9645 instruct subDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
9646   predicate (UseSSE <=1);
9647   match(Set dst (RoundDouble (SubD src1 src2)));
9648   ins_cost(250);
9649 
9650   format %{ "FLD    $src2\n\t"
9651             "DSUB   ST,$src1\n\t"
9652             "FSTP_D $dst\t# D-round" %}
9653   opcode(0xD8, 0x5);
9654   ins_encode( Push_Reg_DPR(src2),
9655               OpcP, RegOpc(src1), Pop_Mem_DPR(dst) );
9656   ins_pipe( fpu_mem_reg_reg );
9657 %}
9658 
9659 
9660 instruct subDPR_reg_mem(regDPR dst, memory src) %{
9661   predicate (UseSSE <=1);
9662   match(Set dst (SubD dst (LoadD src)));
9663   ins_cost(150);
9664 
9665   format %{ "FLD    $src\n\t"
9666             "DSUBp  $dst,ST" %}
9667   opcode(0xDE, 0x5, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
9668   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
9669               OpcP, RegOpc(dst) );
9670   ins_pipe( fpu_reg_mem );
9671 %}
9672 
9673 instruct absDPR_reg(regDPR1 dst, regDPR1 src) %{
9674   predicate (UseSSE<=1);
9675   match(Set dst (AbsD src));
9676   ins_cost(100);
9677   format %{ "FABS" %}
9678   opcode(0xE1, 0xD9);
9679   ins_encode( OpcS, OpcP );
9680   ins_pipe( fpu_reg_reg );
9681 %}
9682 
9683 instruct negDPR_reg(regDPR1 dst, regDPR1 src) %{
9684   predicate(UseSSE<=1);
9685   match(Set dst (NegD src));
9686   ins_cost(100);
9687   format %{ "FCHS" %}
9688   opcode(0xE0, 0xD9);
9689   ins_encode( OpcS, OpcP );
9690   ins_pipe( fpu_reg_reg );
9691 %}
9692 
9693 instruct addDPR_reg(regDPR dst, regDPR src) %{
9694   predicate(UseSSE<=1);
9695   match(Set dst (AddD dst src));
9696   format %{ "FLD    $src\n\t"
9697             "DADD   $dst,ST" %}
9698   size(4);
9699   ins_cost(150);
9700   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
9701   ins_encode( Push_Reg_DPR(src),
9702               OpcP, RegOpc(dst) );
9703   ins_pipe( fpu_reg_reg );
9704 %}
9705 
9706 
9707 instruct addDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
9708   predicate(UseSSE<=1);
9709   match(Set dst (RoundDouble (AddD src1 src2)));
9710   ins_cost(250);
9711 
9712   format %{ "FLD    $src2\n\t"
9713             "DADD   ST,$src1\n\t"
9714             "FSTP_D $dst\t# D-round" %}
9715   opcode(0xD8, 0x0); /* D8 C0+i or D8 /0*/
9716   ins_encode( Push_Reg_DPR(src2),
9717               OpcP, RegOpc(src1), Pop_Mem_DPR(dst) );
9718   ins_pipe( fpu_mem_reg_reg );
9719 %}
9720 
9721 
9722 instruct addDPR_reg_mem(regDPR dst, memory src) %{
9723   predicate(UseSSE<=1);
9724   match(Set dst (AddD dst (LoadD src)));
9725   ins_cost(150);
9726 
9727   format %{ "FLD    $src\n\t"
9728             "DADDp  $dst,ST" %}
9729   opcode(0xDE, 0x0, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
9730   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
9731               OpcP, RegOpc(dst) );
9732   ins_pipe( fpu_reg_mem );
9733 %}
9734 
9735 // add-to-memory
9736 instruct addDPR_mem_reg(memory dst, regDPR src) %{
9737   predicate(UseSSE<=1);
9738   match(Set dst (StoreD dst (RoundDouble (AddD (LoadD dst) src))));
9739   ins_cost(150);
9740 
9741   format %{ "FLD_D  $dst\n\t"
9742             "DADD   ST,$src\n\t"
9743             "FST_D  $dst" %}
9744   opcode(0xDD, 0x0);
9745   ins_encode( Opcode(0xDD), RMopc_Mem(0x00,dst),
9746               Opcode(0xD8), RegOpc(src),
9747               set_instruction_start,
9748               Opcode(0xDD), RMopc_Mem(0x03,dst) );
9749   ins_pipe( fpu_reg_mem );
9750 %}
9751 
9752 instruct addDPR_reg_imm1(regDPR dst, immDPR1 con) %{
9753   predicate(UseSSE<=1);
9754   match(Set dst (AddD dst con));
9755   ins_cost(125);
9756   format %{ "FLD1\n\t"
9757             "DADDp  $dst,ST" %}
9758   ins_encode %{
9759     __ fld1();
9760     __ faddp($dst$$reg);
9761   %}
9762   ins_pipe(fpu_reg);
9763 %}
9764 
9765 instruct addDPR_reg_imm(regDPR dst, immDPR con) %{
9766   predicate(UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
9767   match(Set dst (AddD dst con));
9768   ins_cost(200);
9769   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
9770             "DADDp  $dst,ST" %}
9771   ins_encode %{
9772     __ fld_d($constantaddress($con));
9773     __ faddp($dst$$reg);
9774   %}
9775   ins_pipe(fpu_reg_mem);
9776 %}
9777 
9778 instruct addDPR_reg_imm_round(stackSlotD dst, regDPR src, immDPR con) %{
9779   predicate(UseSSE<=1 && _kids[0]->_kids[1]->_leaf->getd() != 0.0 && _kids[0]->_kids[1]->_leaf->getd() != 1.0 );
9780   match(Set dst (RoundDouble (AddD src con)));
9781   ins_cost(200);
9782   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
9783             "DADD   ST,$src\n\t"
9784             "FSTP_D $dst\t# D-round" %}
9785   ins_encode %{
9786     __ fld_d($constantaddress($con));
9787     __ fadd($src$$reg);
9788     __ fstp_d(Address(rsp, $dst$$disp));
9789   %}
9790   ins_pipe(fpu_mem_reg_con);
9791 %}
9792 
9793 instruct mulDPR_reg(regDPR dst, regDPR src) %{
9794   predicate(UseSSE<=1);
9795   match(Set dst (MulD dst src));
9796   format %{ "FLD    $src\n\t"
9797             "DMULp  $dst,ST" %}
9798   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
9799   ins_cost(150);
9800   ins_encode( Push_Reg_DPR(src),
9801               OpcP, RegOpc(dst) );
9802   ins_pipe( fpu_reg_reg );
9803 %}
9804 
9805 // Strict FP instruction biases argument before multiply then
9806 // biases result to avoid double rounding of subnormals.
9807 //
9808 // scale arg1 by multiplying arg1 by 2^(-15360)
9809 // load arg2
9810 // multiply scaled arg1 by arg2
9811 // rescale product by 2^(15360)
9812 //
9813 instruct strictfp_mulDPR_reg(regDPR1 dst, regnotDPR1 src) %{
9814   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
9815   match(Set dst (MulD dst src));
9816   ins_cost(1);   // Select this instruction for all strict FP double multiplies
9817 
9818   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
9819             "DMULp  $dst,ST\n\t"
9820             "FLD    $src\n\t"
9821             "DMULp  $dst,ST\n\t"
9822             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
9823             "DMULp  $dst,ST\n\t" %}
9824   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
9825   ins_encode( strictfp_bias1(dst),
9826               Push_Reg_DPR(src),
9827               OpcP, RegOpc(dst),
9828               strictfp_bias2(dst) );
9829   ins_pipe( fpu_reg_reg );
9830 %}
9831 
9832 instruct mulDPR_reg_imm(regDPR dst, immDPR con) %{
9833   predicate( UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
9834   match(Set dst (MulD dst con));
9835   ins_cost(200);
9836   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
9837             "DMULp  $dst,ST" %}
9838   ins_encode %{
9839     __ fld_d($constantaddress($con));
9840     __ fmulp($dst$$reg);
9841   %}
9842   ins_pipe(fpu_reg_mem);
9843 %}
9844 
9845 
9846 instruct mulDPR_reg_mem(regDPR dst, memory src) %{
9847   predicate( UseSSE<=1 );
9848   match(Set dst (MulD dst (LoadD src)));
9849   ins_cost(200);
9850   format %{ "FLD_D  $src\n\t"
9851             "DMULp  $dst,ST" %}
9852   opcode(0xDE, 0x1, 0xDD); /* DE C8+i or DE /1*/  /* LoadD  DD /0 */
9853   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
9854               OpcP, RegOpc(dst) );
9855   ins_pipe( fpu_reg_mem );
9856 %}
9857 
9858 //
9859 // Cisc-alternate to reg-reg multiply
9860 instruct mulDPR_reg_mem_cisc(regDPR dst, regDPR src, memory mem) %{
9861   predicate( UseSSE<=1 );
9862   match(Set dst (MulD src (LoadD mem)));
9863   ins_cost(250);
9864   format %{ "FLD_D  $mem\n\t"
9865             "DMUL   ST,$src\n\t"
9866             "FSTP_D $dst" %}
9867   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadD D9 /0 */
9868   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem),
9869               OpcReg_FPR(src),
9870               Pop_Reg_DPR(dst) );
9871   ins_pipe( fpu_reg_reg_mem );
9872 %}
9873 
9874 
9875 // MACRO3 -- addDPR a mulDPR
9876 // This instruction is a '2-address' instruction in that the result goes
9877 // back to src2.  This eliminates a move from the macro; possibly the
9878 // register allocator will have to add it back (and maybe not).
9879 instruct addDPR_mulDPR_reg(regDPR src2, regDPR src1, regDPR src0) %{
9880   predicate( UseSSE<=1 );
9881   match(Set src2 (AddD (MulD src0 src1) src2));
9882   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
9883             "DMUL   ST,$src1\n\t"
9884             "DADDp  $src2,ST" %}
9885   ins_cost(250);
9886   opcode(0xDD); /* LoadD DD /0 */
9887   ins_encode( Push_Reg_FPR(src0),
9888               FMul_ST_reg(src1),
9889               FAddP_reg_ST(src2) );
9890   ins_pipe( fpu_reg_reg_reg );
9891 %}
9892 
9893 
9894 // MACRO3 -- subDPR a mulDPR
9895 instruct subDPR_mulDPR_reg(regDPR src2, regDPR src1, regDPR src0) %{
9896   predicate( UseSSE<=1 );
9897   match(Set src2 (SubD (MulD src0 src1) src2));
9898   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
9899             "DMUL   ST,$src1\n\t"
9900             "DSUBRp $src2,ST" %}
9901   ins_cost(250);
9902   ins_encode( Push_Reg_FPR(src0),
9903               FMul_ST_reg(src1),
9904               Opcode(0xDE), Opc_plus(0xE0,src2));
9905   ins_pipe( fpu_reg_reg_reg );
9906 %}
9907 
9908 
9909 instruct divDPR_reg(regDPR dst, regDPR src) %{
9910   predicate( UseSSE<=1 );
9911   match(Set dst (DivD dst src));
9912 
9913   format %{ "FLD    $src\n\t"
9914             "FDIVp  $dst,ST" %}
9915   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
9916   ins_cost(150);
9917   ins_encode( Push_Reg_DPR(src),
9918               OpcP, RegOpc(dst) );
9919   ins_pipe( fpu_reg_reg );
9920 %}
9921 
9922 // Strict FP instruction biases argument before division then
9923 // biases result, to avoid double rounding of subnormals.
9924 //
9925 // scale dividend by multiplying dividend by 2^(-15360)
9926 // load divisor
9927 // divide scaled dividend by divisor
9928 // rescale quotient by 2^(15360)
9929 //
9930 instruct strictfp_divDPR_reg(regDPR1 dst, regnotDPR1 src) %{
9931   predicate (UseSSE<=1);
9932   match(Set dst (DivD dst src));
9933   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
9934   ins_cost(01);
9935 
9936   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
9937             "DMULp  $dst,ST\n\t"
9938             "FLD    $src\n\t"
9939             "FDIVp  $dst,ST\n\t"
9940             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
9941             "DMULp  $dst,ST\n\t" %}
9942   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
9943   ins_encode( strictfp_bias1(dst),
9944               Push_Reg_DPR(src),
9945               OpcP, RegOpc(dst),
9946               strictfp_bias2(dst) );
9947   ins_pipe( fpu_reg_reg );
9948 %}
9949 
9950 instruct divDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
9951   predicate( UseSSE<=1 && !(Compile::current()->has_method() && Compile::current()->method()->is_strict()) );
9952   match(Set dst (RoundDouble (DivD src1 src2)));
9953 
9954   format %{ "FLD    $src1\n\t"
9955             "FDIV   ST,$src2\n\t"
9956             "FSTP_D $dst\t# D-round" %}
9957   opcode(0xD8, 0x6); /* D8 F0+i or D8 /6 */
9958   ins_encode( Push_Reg_DPR(src1),
9959               OpcP, RegOpc(src2), Pop_Mem_DPR(dst) );
9960   ins_pipe( fpu_mem_reg_reg );
9961 %}
9962 
9963 
9964 instruct modDPR_reg(regDPR dst, regDPR src, eAXRegI rax, eFlagsReg cr) %{
9965   predicate(UseSSE<=1);
9966   match(Set dst (ModD dst src));
9967   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
9968 
9969   format %{ "DMOD   $dst,$src" %}
9970   ins_cost(250);
9971   ins_encode(Push_Reg_Mod_DPR(dst, src),
9972               emitModDPR(),
9973               Push_Result_Mod_DPR(src),
9974               Pop_Reg_DPR(dst));
9975   ins_pipe( pipe_slow );
9976 %}
9977 
9978 instruct modD_reg(regD dst, regD src0, regD src1, eAXRegI rax, eFlagsReg cr) %{
9979   predicate(UseSSE>=2);
9980   match(Set dst (ModD src0 src1));
9981   effect(KILL rax, KILL cr);
9982 
9983   format %{ "SUB    ESP,8\t # DMOD\n"
9984           "\tMOVSD  [ESP+0],$src1\n"
9985           "\tFLD_D  [ESP+0]\n"
9986           "\tMOVSD  [ESP+0],$src0\n"
9987           "\tFLD_D  [ESP+0]\n"
9988      "loop:\tFPREM\n"
9989           "\tFWAIT\n"
9990           "\tFNSTSW AX\n"
9991           "\tSAHF\n"
9992           "\tJP     loop\n"
9993           "\tFSTP_D [ESP+0]\n"
9994           "\tMOVSD  $dst,[ESP+0]\n"
9995           "\tADD    ESP,8\n"
9996           "\tFSTP   ST0\t # Restore FPU Stack"
9997     %}
9998   ins_cost(250);
9999   ins_encode( Push_ModD_encoding(src0, src1), emitModDPR(), Push_ResultD(dst), PopFPU);
10000   ins_pipe( pipe_slow );
10001 %}
10002 
10003 instruct sinDPR_reg(regDPR1 dst, regDPR1 src) %{
10004   predicate (UseSSE<=1);
10005   match(Set dst (SinD src));
10006   ins_cost(1800);
10007   format %{ "DSIN   $dst" %}
10008   opcode(0xD9, 0xFE);
10009   ins_encode( OpcP, OpcS );
10010   ins_pipe( pipe_slow );
10011 %}
10012 
10013 instruct sinD_reg(regD dst, eFlagsReg cr) %{
10014   predicate (UseSSE>=2);
10015   match(Set dst (SinD dst));
10016   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
10017   ins_cost(1800);
10018   format %{ "DSIN   $dst" %}
10019   opcode(0xD9, 0xFE);
10020   ins_encode( Push_SrcD(dst), OpcP, OpcS, Push_ResultD(dst) );
10021   ins_pipe( pipe_slow );
10022 %}
10023 
10024 instruct cosDPR_reg(regDPR1 dst, regDPR1 src) %{
10025   predicate (UseSSE<=1);
10026   match(Set dst (CosD src));
10027   ins_cost(1800);
10028   format %{ "DCOS   $dst" %}
10029   opcode(0xD9, 0xFF);
10030   ins_encode( OpcP, OpcS );
10031   ins_pipe( pipe_slow );
10032 %}
10033 
10034 instruct cosD_reg(regD dst, eFlagsReg cr) %{
10035   predicate (UseSSE>=2);
10036   match(Set dst (CosD dst));
10037   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
10038   ins_cost(1800);
10039   format %{ "DCOS   $dst" %}
10040   opcode(0xD9, 0xFF);
10041   ins_encode( Push_SrcD(dst), OpcP, OpcS, Push_ResultD(dst) );
10042   ins_pipe( pipe_slow );
10043 %}
10044 
10045 instruct tanDPR_reg(regDPR1 dst, regDPR1 src) %{
10046   predicate (UseSSE<=1);
10047   match(Set dst(TanD src));
10048   format %{ "DTAN   $dst" %}
10049   ins_encode( Opcode(0xD9), Opcode(0xF2),    // fptan
10050               Opcode(0xDD), Opcode(0xD8));   // fstp st
10051   ins_pipe( pipe_slow );
10052 %}
10053 
10054 instruct tanD_reg(regD dst, eFlagsReg cr) %{
10055   predicate (UseSSE>=2);
10056   match(Set dst(TanD dst));
10057   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
10058   format %{ "DTAN   $dst" %}
10059   ins_encode( Push_SrcD(dst),
10060               Opcode(0xD9), Opcode(0xF2),    // fptan
10061               Opcode(0xDD), Opcode(0xD8),   // fstp st
10062               Push_ResultD(dst) );
10063   ins_pipe( pipe_slow );
10064 %}
10065 
10066 instruct atanDPR_reg(regDPR dst, regDPR src) %{
10067   predicate (UseSSE<=1);
10068   match(Set dst(AtanD dst src));
10069   format %{ "DATA   $dst,$src" %}
10070   opcode(0xD9, 0xF3);
10071   ins_encode( Push_Reg_DPR(src),
10072               OpcP, OpcS, RegOpc(dst) );
10073   ins_pipe( pipe_slow );
10074 %}
10075 
10076 instruct atanD_reg(regD dst, regD src, eFlagsReg cr) %{
10077   predicate (UseSSE>=2);
10078   match(Set dst(AtanD dst src));
10079   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
10080   format %{ "DATA   $dst,$src" %}
10081   opcode(0xD9, 0xF3);
10082   ins_encode( Push_SrcD(src),
10083               OpcP, OpcS, Push_ResultD(dst) );
10084   ins_pipe( pipe_slow );
10085 %}
10086 
10087 instruct sqrtDPR_reg(regDPR dst, regDPR src) %{
10088   predicate (UseSSE<=1);
10089   match(Set dst (SqrtD src));
10090   format %{ "DSQRT  $dst,$src" %}
10091   opcode(0xFA, 0xD9);
10092   ins_encode( Push_Reg_DPR(src),
10093               OpcS, OpcP, Pop_Reg_DPR(dst) );
10094   ins_pipe( pipe_slow );
10095 %}
10096 
10097 instruct powDPR_reg(regDPR X, regDPR1 Y, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
10098   predicate (UseSSE<=1);
10099   match(Set Y (PowD X Y));  // Raise X to the Yth power
10100   effect(KILL rax, KILL rdx, KILL rcx, KILL cr);
10101   format %{ "fast_pow $X $Y -> $Y  // KILL $rax, $rcx, $rdx" %}
10102   ins_encode %{
10103     __ subptr(rsp, 8);
10104     __ fld_s($X$$reg - 1);
10105     __ fast_pow();
10106     __ addptr(rsp, 8);
10107   %}
10108   ins_pipe( pipe_slow );
10109 %}
10110 
10111 instruct powD_reg(regD dst, regD src0, regD src1, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
10112   predicate (UseSSE>=2);
10113   match(Set dst (PowD src0 src1));  // Raise src0 to the src1'th power
10114   effect(KILL rax, KILL rdx, KILL rcx, KILL cr);
10115   format %{ "fast_pow $src0 $src1 -> $dst  // KILL $rax, $rcx, $rdx" %}
10116   ins_encode %{
10117     __ subptr(rsp, 8);
10118     __ movdbl(Address(rsp, 0), $src1$$XMMRegister);
10119     __ fld_d(Address(rsp, 0));
10120     __ movdbl(Address(rsp, 0), $src0$$XMMRegister);
10121     __ fld_d(Address(rsp, 0));
10122     __ fast_pow();
10123     __ fstp_d(Address(rsp, 0));
10124     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
10125     __ addptr(rsp, 8);
10126   %}
10127   ins_pipe( pipe_slow );
10128 %}
10129 
10130 
10131 instruct expDPR_reg(regDPR1 dpr1, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
10132   predicate (UseSSE<=1);
10133   match(Set dpr1 (ExpD dpr1));
10134   effect(KILL rax, KILL rcx, KILL rdx, KILL cr);
10135   format %{ "fast_exp $dpr1 -> $dpr1  // KILL $rax, $rcx, $rdx" %}
10136   ins_encode %{
10137     __ fast_exp();
10138   %}
10139   ins_pipe( pipe_slow );
10140 %}
10141 
10142 instruct expD_reg(regD dst, regD src, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
10143   predicate (UseSSE>=2);
10144   match(Set dst (ExpD src));
10145   effect(KILL rax, KILL rcx, KILL rdx, KILL cr);
10146   format %{ "fast_exp $dst -> $src  // KILL $rax, $rcx, $rdx" %}
10147   ins_encode %{
10148     __ subptr(rsp, 8);
10149     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
10150     __ fld_d(Address(rsp, 0));
10151     __ fast_exp();
10152     __ fstp_d(Address(rsp, 0));
10153     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
10154     __ addptr(rsp, 8);
10155   %}
10156   ins_pipe( pipe_slow );
10157 %}
10158 
10159 instruct log10DPR_reg(regDPR1 dst, regDPR1 src) %{
10160   predicate (UseSSE<=1);
10161   // The source Double operand on FPU stack
10162   match(Set dst (Log10D src));
10163   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
10164   // fxch         ; swap ST(0) with ST(1)
10165   // fyl2x        ; compute log_10(2) * log_2(x)
10166   format %{ "FLDLG2 \t\t\t#Log10\n\t"
10167             "FXCH   \n\t"
10168             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
10169          %}
10170   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
10171               Opcode(0xD9), Opcode(0xC9),   // fxch
10172               Opcode(0xD9), Opcode(0xF1));  // fyl2x
10173 
10174   ins_pipe( pipe_slow );
10175 %}
10176 
10177 instruct log10D_reg(regD dst, regD src, eFlagsReg cr) %{
10178   predicate (UseSSE>=2);
10179   effect(KILL cr);
10180   match(Set dst (Log10D src));
10181   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
10182   // fyl2x        ; compute log_10(2) * log_2(x)
10183   format %{ "FLDLG2 \t\t\t#Log10\n\t"
10184             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
10185          %}
10186   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
10187               Push_SrcD(src),
10188               Opcode(0xD9), Opcode(0xF1),   // fyl2x
10189               Push_ResultD(dst));
10190 
10191   ins_pipe( pipe_slow );
10192 %}
10193 
10194 instruct logDPR_reg(regDPR1 dst, regDPR1 src) %{
10195   predicate (UseSSE<=1);
10196   // The source Double operand on FPU stack
10197   match(Set dst (LogD src));
10198   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
10199   // fxch         ; swap ST(0) with ST(1)
10200   // fyl2x        ; compute log_e(2) * log_2(x)
10201   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
10202             "FXCH   \n\t"
10203             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
10204          %}
10205   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
10206               Opcode(0xD9), Opcode(0xC9),   // fxch
10207               Opcode(0xD9), Opcode(0xF1));  // fyl2x
10208 
10209   ins_pipe( pipe_slow );
10210 %}
10211 
10212 instruct logD_reg(regD dst, regD src, eFlagsReg cr) %{
10213   predicate (UseSSE>=2);
10214   effect(KILL cr);
10215   // The source and result Double operands in XMM registers
10216   match(Set dst (LogD src));
10217   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
10218   // fyl2x        ; compute log_e(2) * log_2(x)
10219   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
10220             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
10221          %}
10222   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
10223               Push_SrcD(src),
10224               Opcode(0xD9), Opcode(0xF1),   // fyl2x
10225               Push_ResultD(dst));
10226   ins_pipe( pipe_slow );
10227 %}
10228 
10229 //-------------Float Instructions-------------------------------
10230 // Float Math
10231 
10232 // Code for float compare:
10233 //     fcompp();
10234 //     fwait(); fnstsw_ax();
10235 //     sahf();
10236 //     movl(dst, unordered_result);
10237 //     jcc(Assembler::parity, exit);
10238 //     movl(dst, less_result);
10239 //     jcc(Assembler::below, exit);
10240 //     movl(dst, equal_result);
10241 //     jcc(Assembler::equal, exit);
10242 //     movl(dst, greater_result);
10243 //   exit:
10244 
10245 // P6 version of float compare, sets condition codes in EFLAGS
10246 instruct cmpFPR_cc_P6(eFlagsRegU cr, regFPR src1, regFPR src2, eAXRegI rax) %{
10247   predicate(VM_Version::supports_cmov() && UseSSE == 0);
10248   match(Set cr (CmpF src1 src2));
10249   effect(KILL rax);
10250   ins_cost(150);
10251   format %{ "FLD    $src1\n\t"
10252             "FUCOMIP ST,$src2  // P6 instruction\n\t"
10253             "JNP    exit\n\t"
10254             "MOV    ah,1       // saw a NaN, set CF (treat as LT)\n\t"
10255             "SAHF\n"
10256      "exit:\tNOP               // avoid branch to branch" %}
10257   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
10258   ins_encode( Push_Reg_DPR(src1),
10259               OpcP, RegOpc(src2),
10260               cmpF_P6_fixup );
10261   ins_pipe( pipe_slow );
10262 %}
10263 
10264 instruct cmpFPR_cc_P6CF(eFlagsRegUCF cr, regFPR src1, regFPR src2) %{
10265   predicate(VM_Version::supports_cmov() && UseSSE == 0);
10266   match(Set cr (CmpF src1 src2));
10267   ins_cost(100);
10268   format %{ "FLD    $src1\n\t"
10269             "FUCOMIP ST,$src2  // P6 instruction" %}
10270   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
10271   ins_encode( Push_Reg_DPR(src1),
10272               OpcP, RegOpc(src2));
10273   ins_pipe( pipe_slow );
10274 %}
10275 
10276 
10277 // Compare & branch
10278 instruct cmpFPR_cc(eFlagsRegU cr, regFPR src1, regFPR src2, eAXRegI rax) %{
10279   predicate(UseSSE == 0);
10280   match(Set cr (CmpF src1 src2));
10281   effect(KILL rax);
10282   ins_cost(200);
10283   format %{ "FLD    $src1\n\t"
10284             "FCOMp  $src2\n\t"
10285             "FNSTSW AX\n\t"
10286             "TEST   AX,0x400\n\t"
10287             "JZ,s   flags\n\t"
10288             "MOV    AH,1\t# unordered treat as LT\n"
10289     "flags:\tSAHF" %}
10290   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
10291   ins_encode( Push_Reg_DPR(src1),
10292               OpcP, RegOpc(src2),
10293               fpu_flags);
10294   ins_pipe( pipe_slow );
10295 %}
10296 
10297 // Compare vs zero into -1,0,1
10298 instruct cmpFPR_0(rRegI dst, regFPR src1, immFPR0 zero, eAXRegI rax, eFlagsReg cr) %{
10299   predicate(UseSSE == 0);
10300   match(Set dst (CmpF3 src1 zero));
10301   effect(KILL cr, KILL rax);
10302   ins_cost(280);
10303   format %{ "FTSTF  $dst,$src1" %}
10304   opcode(0xE4, 0xD9);
10305   ins_encode( Push_Reg_DPR(src1),
10306               OpcS, OpcP, PopFPU,
10307               CmpF_Result(dst));
10308   ins_pipe( pipe_slow );
10309 %}
10310 
10311 // Compare into -1,0,1
10312 instruct cmpFPR_reg(rRegI dst, regFPR src1, regFPR src2, eAXRegI rax, eFlagsReg cr) %{
10313   predicate(UseSSE == 0);
10314   match(Set dst (CmpF3 src1 src2));
10315   effect(KILL cr, KILL rax);
10316   ins_cost(300);
10317   format %{ "FCMPF  $dst,$src1,$src2" %}
10318   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
10319   ins_encode( Push_Reg_DPR(src1),
10320               OpcP, RegOpc(src2),
10321               CmpF_Result(dst));
10322   ins_pipe( pipe_slow );
10323 %}
10324 
10325 // float compare and set condition codes in EFLAGS by XMM regs
10326 instruct cmpF_cc(eFlagsRegU cr, regF src1, regF src2) %{
10327   predicate(UseSSE>=1);
10328   match(Set cr (CmpF src1 src2));
10329   ins_cost(145);
10330   format %{ "UCOMISS $src1,$src2\n\t"
10331             "JNP,s   exit\n\t"
10332             "PUSHF\t# saw NaN, set CF\n\t"
10333             "AND     [rsp], #0xffffff2b\n\t"
10334             "POPF\n"
10335     "exit:" %}
10336   ins_encode %{
10337     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10338     emit_cmpfp_fixup(_masm);
10339   %}
10340   ins_pipe( pipe_slow );
10341 %}
10342 
10343 instruct cmpF_ccCF(eFlagsRegUCF cr, regF src1, regF src2) %{
10344   predicate(UseSSE>=1);
10345   match(Set cr (CmpF src1 src2));
10346   ins_cost(100);
10347   format %{ "UCOMISS $src1,$src2" %}
10348   ins_encode %{
10349     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10350   %}
10351   ins_pipe( pipe_slow );
10352 %}
10353 
10354 // float compare and set condition codes in EFLAGS by XMM regs
10355 instruct cmpF_ccmem(eFlagsRegU cr, regF src1, memory src2) %{
10356   predicate(UseSSE>=1);
10357   match(Set cr (CmpF src1 (LoadF src2)));
10358   ins_cost(165);
10359   format %{ "UCOMISS $src1,$src2\n\t"
10360             "JNP,s   exit\n\t"
10361             "PUSHF\t# saw NaN, set CF\n\t"
10362             "AND     [rsp], #0xffffff2b\n\t"
10363             "POPF\n"
10364     "exit:" %}
10365   ins_encode %{
10366     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10367     emit_cmpfp_fixup(_masm);
10368   %}
10369   ins_pipe( pipe_slow );
10370 %}
10371 
10372 instruct cmpF_ccmemCF(eFlagsRegUCF cr, regF src1, memory src2) %{
10373   predicate(UseSSE>=1);
10374   match(Set cr (CmpF src1 (LoadF src2)));
10375   ins_cost(100);
10376   format %{ "UCOMISS $src1,$src2" %}
10377   ins_encode %{
10378     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10379   %}
10380   ins_pipe( pipe_slow );
10381 %}
10382 
10383 // Compare into -1,0,1 in XMM
10384 instruct cmpF_reg(xRegI dst, regF src1, regF src2, eFlagsReg cr) %{
10385   predicate(UseSSE>=1);
10386   match(Set dst (CmpF3 src1 src2));
10387   effect(KILL cr);
10388   ins_cost(255);
10389   format %{ "UCOMISS $src1, $src2\n\t"
10390             "MOV     $dst, #-1\n\t"
10391             "JP,s    done\n\t"
10392             "JB,s    done\n\t"
10393             "SETNE   $dst\n\t"
10394             "MOVZB   $dst, $dst\n"
10395     "done:" %}
10396   ins_encode %{
10397     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10398     emit_cmpfp3(_masm, $dst$$Register);
10399   %}
10400   ins_pipe( pipe_slow );
10401 %}
10402 
10403 // Compare into -1,0,1 in XMM and memory
10404 instruct cmpF_regmem(xRegI dst, regF src1, memory src2, eFlagsReg cr) %{
10405   predicate(UseSSE>=1);
10406   match(Set dst (CmpF3 src1 (LoadF src2)));
10407   effect(KILL cr);
10408   ins_cost(275);
10409   format %{ "UCOMISS $src1, $src2\n\t"
10410             "MOV     $dst, #-1\n\t"
10411             "JP,s    done\n\t"
10412             "JB,s    done\n\t"
10413             "SETNE   $dst\n\t"
10414             "MOVZB   $dst, $dst\n"
10415     "done:" %}
10416   ins_encode %{
10417     __ ucomiss($src1$$XMMRegister, $src2$$Address);
10418     emit_cmpfp3(_masm, $dst$$Register);
10419   %}
10420   ins_pipe( pipe_slow );
10421 %}
10422 
10423 // Spill to obtain 24-bit precision
10424 instruct subFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
10425   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10426   match(Set dst (SubF src1 src2));
10427 
10428   format %{ "FSUB   $dst,$src1 - $src2" %}
10429   opcode(0xD8, 0x4); /* D8 E0+i or D8 /4 mod==0x3 ;; result in TOS */
10430   ins_encode( Push_Reg_FPR(src1),
10431               OpcReg_FPR(src2),
10432               Pop_Mem_FPR(dst) );
10433   ins_pipe( fpu_mem_reg_reg );
10434 %}
10435 //
10436 // This instruction does not round to 24-bits
10437 instruct subFPR_reg(regFPR dst, regFPR src) %{
10438   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10439   match(Set dst (SubF dst src));
10440 
10441   format %{ "FSUB   $dst,$src" %}
10442   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
10443   ins_encode( Push_Reg_FPR(src),
10444               OpcP, RegOpc(dst) );
10445   ins_pipe( fpu_reg_reg );
10446 %}
10447 
10448 // Spill to obtain 24-bit precision
10449 instruct addFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
10450   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10451   match(Set dst (AddF src1 src2));
10452 
10453   format %{ "FADD   $dst,$src1,$src2" %}
10454   opcode(0xD8, 0x0); /* D8 C0+i */
10455   ins_encode( Push_Reg_FPR(src2),
10456               OpcReg_FPR(src1),
10457               Pop_Mem_FPR(dst) );
10458   ins_pipe( fpu_mem_reg_reg );
10459 %}
10460 //
10461 // This instruction does not round to 24-bits
10462 instruct addFPR_reg(regFPR dst, regFPR src) %{
10463   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10464   match(Set dst (AddF dst src));
10465 
10466   format %{ "FLD    $src\n\t"
10467             "FADDp  $dst,ST" %}
10468   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
10469   ins_encode( Push_Reg_FPR(src),
10470               OpcP, RegOpc(dst) );
10471   ins_pipe( fpu_reg_reg );
10472 %}
10473 
10474 instruct absFPR_reg(regFPR1 dst, regFPR1 src) %{
10475   predicate(UseSSE==0);
10476   match(Set dst (AbsF src));
10477   ins_cost(100);
10478   format %{ "FABS" %}
10479   opcode(0xE1, 0xD9);
10480   ins_encode( OpcS, OpcP );
10481   ins_pipe( fpu_reg_reg );
10482 %}
10483 
10484 instruct negFPR_reg(regFPR1 dst, regFPR1 src) %{
10485   predicate(UseSSE==0);
10486   match(Set dst (NegF src));
10487   ins_cost(100);
10488   format %{ "FCHS" %}
10489   opcode(0xE0, 0xD9);
10490   ins_encode( OpcS, OpcP );
10491   ins_pipe( fpu_reg_reg );
10492 %}
10493 
10494 // Cisc-alternate to addFPR_reg
10495 // Spill to obtain 24-bit precision
10496 instruct addFPR24_reg_mem(stackSlotF dst, regFPR src1, memory src2) %{
10497   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10498   match(Set dst (AddF src1 (LoadF src2)));
10499 
10500   format %{ "FLD    $src2\n\t"
10501             "FADD   ST,$src1\n\t"
10502             "FSTP_S $dst" %}
10503   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
10504   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10505               OpcReg_FPR(src1),
10506               Pop_Mem_FPR(dst) );
10507   ins_pipe( fpu_mem_reg_mem );
10508 %}
10509 //
10510 // Cisc-alternate to addFPR_reg
10511 // This instruction does not round to 24-bits
10512 instruct addFPR_reg_mem(regFPR dst, memory src) %{
10513   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10514   match(Set dst (AddF dst (LoadF src)));
10515 
10516   format %{ "FADD   $dst,$src" %}
10517   opcode(0xDE, 0x0, 0xD9); /* DE C0+i or DE /0*/  /* LoadF  D9 /0 */
10518   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
10519               OpcP, RegOpc(dst) );
10520   ins_pipe( fpu_reg_mem );
10521 %}
10522 
10523 // // Following two instructions for _222_mpegaudio
10524 // Spill to obtain 24-bit precision
10525 instruct addFPR24_mem_reg(stackSlotF dst, regFPR src2, memory src1 ) %{
10526   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10527   match(Set dst (AddF src1 src2));
10528 
10529   format %{ "FADD   $dst,$src1,$src2" %}
10530   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
10531   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src1),
10532               OpcReg_FPR(src2),
10533               Pop_Mem_FPR(dst) );
10534   ins_pipe( fpu_mem_reg_mem );
10535 %}
10536 
10537 // Cisc-spill variant
10538 // Spill to obtain 24-bit precision
10539 instruct addFPR24_mem_cisc(stackSlotF dst, memory src1, memory src2) %{
10540   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10541   match(Set dst (AddF src1 (LoadF src2)));
10542 
10543   format %{ "FADD   $dst,$src1,$src2 cisc" %}
10544   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
10545   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10546               set_instruction_start,
10547               OpcP, RMopc_Mem(secondary,src1),
10548               Pop_Mem_FPR(dst) );
10549   ins_pipe( fpu_mem_mem_mem );
10550 %}
10551 
10552 // Spill to obtain 24-bit precision
10553 instruct addFPR24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
10554   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10555   match(Set dst (AddF src1 src2));
10556 
10557   format %{ "FADD   $dst,$src1,$src2" %}
10558   opcode(0xD8, 0x0, 0xD9); /* D8 /0 */  /* LoadF  D9 /0 */
10559   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10560               set_instruction_start,
10561               OpcP, RMopc_Mem(secondary,src1),
10562               Pop_Mem_FPR(dst) );
10563   ins_pipe( fpu_mem_mem_mem );
10564 %}
10565 
10566 
10567 // Spill to obtain 24-bit precision
10568 instruct addFPR24_reg_imm(stackSlotF dst, regFPR src, immFPR con) %{
10569   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10570   match(Set dst (AddF src con));
10571   format %{ "FLD    $src\n\t"
10572             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
10573             "FSTP_S $dst"  %}
10574   ins_encode %{
10575     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
10576     __ fadd_s($constantaddress($con));
10577     __ fstp_s(Address(rsp, $dst$$disp));
10578   %}
10579   ins_pipe(fpu_mem_reg_con);
10580 %}
10581 //
10582 // This instruction does not round to 24-bits
10583 instruct addFPR_reg_imm(regFPR dst, regFPR src, immFPR con) %{
10584   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10585   match(Set dst (AddF src con));
10586   format %{ "FLD    $src\n\t"
10587             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
10588             "FSTP   $dst"  %}
10589   ins_encode %{
10590     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
10591     __ fadd_s($constantaddress($con));
10592     __ fstp_d($dst$$reg);
10593   %}
10594   ins_pipe(fpu_reg_reg_con);
10595 %}
10596 
10597 // Spill to obtain 24-bit precision
10598 instruct mulFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
10599   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10600   match(Set dst (MulF src1 src2));
10601 
10602   format %{ "FLD    $src1\n\t"
10603             "FMUL   $src2\n\t"
10604             "FSTP_S $dst"  %}
10605   opcode(0xD8, 0x1); /* D8 C8+i or D8 /1 ;; result in TOS */
10606   ins_encode( Push_Reg_FPR(src1),
10607               OpcReg_FPR(src2),
10608               Pop_Mem_FPR(dst) );
10609   ins_pipe( fpu_mem_reg_reg );
10610 %}
10611 //
10612 // This instruction does not round to 24-bits
10613 instruct mulFPR_reg(regFPR dst, regFPR src1, regFPR src2) %{
10614   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10615   match(Set dst (MulF src1 src2));
10616 
10617   format %{ "FLD    $src1\n\t"
10618             "FMUL   $src2\n\t"
10619             "FSTP_S $dst"  %}
10620   opcode(0xD8, 0x1); /* D8 C8+i */
10621   ins_encode( Push_Reg_FPR(src2),
10622               OpcReg_FPR(src1),
10623               Pop_Reg_FPR(dst) );
10624   ins_pipe( fpu_reg_reg_reg );
10625 %}
10626 
10627 
10628 // Spill to obtain 24-bit precision
10629 // Cisc-alternate to reg-reg multiply
10630 instruct mulFPR24_reg_mem(stackSlotF dst, regFPR src1, memory src2) %{
10631   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10632   match(Set dst (MulF src1 (LoadF src2)));
10633 
10634   format %{ "FLD_S  $src2\n\t"
10635             "FMUL   $src1\n\t"
10636             "FSTP_S $dst"  %}
10637   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or DE /1*/  /* LoadF D9 /0 */
10638   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10639               OpcReg_FPR(src1),
10640               Pop_Mem_FPR(dst) );
10641   ins_pipe( fpu_mem_reg_mem );
10642 %}
10643 //
10644 // This instruction does not round to 24-bits
10645 // Cisc-alternate to reg-reg multiply
10646 instruct mulFPR_reg_mem(regFPR dst, regFPR src1, memory src2) %{
10647   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10648   match(Set dst (MulF src1 (LoadF src2)));
10649 
10650   format %{ "FMUL   $dst,$src1,$src2" %}
10651   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadF D9 /0 */
10652   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10653               OpcReg_FPR(src1),
10654               Pop_Reg_FPR(dst) );
10655   ins_pipe( fpu_reg_reg_mem );
10656 %}
10657 
10658 // Spill to obtain 24-bit precision
10659 instruct mulFPR24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
10660   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10661   match(Set dst (MulF src1 src2));
10662 
10663   format %{ "FMUL   $dst,$src1,$src2" %}
10664   opcode(0xD8, 0x1, 0xD9); /* D8 /1 */  /* LoadF D9 /0 */
10665   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
10666               set_instruction_start,
10667               OpcP, RMopc_Mem(secondary,src1),
10668               Pop_Mem_FPR(dst) );
10669   ins_pipe( fpu_mem_mem_mem );
10670 %}
10671 
10672 // Spill to obtain 24-bit precision
10673 instruct mulFPR24_reg_imm(stackSlotF dst, regFPR src, immFPR con) %{
10674   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10675   match(Set dst (MulF src con));
10676 
10677   format %{ "FLD    $src\n\t"
10678             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
10679             "FSTP_S $dst"  %}
10680   ins_encode %{
10681     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
10682     __ fmul_s($constantaddress($con));
10683     __ fstp_s(Address(rsp, $dst$$disp));
10684   %}
10685   ins_pipe(fpu_mem_reg_con);
10686 %}
10687 //
10688 // This instruction does not round to 24-bits
10689 instruct mulFPR_reg_imm(regFPR dst, regFPR src, immFPR con) %{
10690   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10691   match(Set dst (MulF src con));
10692 
10693   format %{ "FLD    $src\n\t"
10694             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
10695             "FSTP   $dst"  %}
10696   ins_encode %{
10697     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
10698     __ fmul_s($constantaddress($con));
10699     __ fstp_d($dst$$reg);
10700   %}
10701   ins_pipe(fpu_reg_reg_con);
10702 %}
10703 
10704 
10705 //
10706 // MACRO1 -- subsume unshared load into mulFPR
10707 // This instruction does not round to 24-bits
10708 instruct mulFPR_reg_load1(regFPR dst, regFPR src, memory mem1 ) %{
10709   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10710   match(Set dst (MulF (LoadF mem1) src));
10711 
10712   format %{ "FLD    $mem1    ===MACRO1===\n\t"
10713             "FMUL   ST,$src\n\t"
10714             "FSTP   $dst" %}
10715   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or D8 /1 */  /* LoadF D9 /0 */
10716   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem1),
10717               OpcReg_FPR(src),
10718               Pop_Reg_FPR(dst) );
10719   ins_pipe( fpu_reg_reg_mem );
10720 %}
10721 //
10722 // MACRO2 -- addFPR a mulFPR which subsumed an unshared load
10723 // This instruction does not round to 24-bits
10724 instruct addFPR_mulFPR_reg_load1(regFPR dst, memory mem1, regFPR src1, regFPR src2) %{
10725   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10726   match(Set dst (AddF (MulF (LoadF mem1) src1) src2));
10727   ins_cost(95);
10728 
10729   format %{ "FLD    $mem1     ===MACRO2===\n\t"
10730             "FMUL   ST,$src1  subsume mulFPR left load\n\t"
10731             "FADD   ST,$src2\n\t"
10732             "FSTP   $dst" %}
10733   opcode(0xD9); /* LoadF D9 /0 */
10734   ins_encode( OpcP, RMopc_Mem(0x00,mem1),
10735               FMul_ST_reg(src1),
10736               FAdd_ST_reg(src2),
10737               Pop_Reg_FPR(dst) );
10738   ins_pipe( fpu_reg_mem_reg_reg );
10739 %}
10740 
10741 // MACRO3 -- addFPR a mulFPR
10742 // This instruction does not round to 24-bits.  It is a '2-address'
10743 // instruction in that the result goes back to src2.  This eliminates
10744 // a move from the macro; possibly the register allocator will have
10745 // to add it back (and maybe not).
10746 instruct addFPR_mulFPR_reg(regFPR src2, regFPR src1, regFPR src0) %{
10747   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10748   match(Set src2 (AddF (MulF src0 src1) src2));
10749 
10750   format %{ "FLD    $src0     ===MACRO3===\n\t"
10751             "FMUL   ST,$src1\n\t"
10752             "FADDP  $src2,ST" %}
10753   opcode(0xD9); /* LoadF D9 /0 */
10754   ins_encode( Push_Reg_FPR(src0),
10755               FMul_ST_reg(src1),
10756               FAddP_reg_ST(src2) );
10757   ins_pipe( fpu_reg_reg_reg );
10758 %}
10759 
10760 // MACRO4 -- divFPR subFPR
10761 // This instruction does not round to 24-bits
10762 instruct subFPR_divFPR_reg(regFPR dst, regFPR src1, regFPR src2, regFPR src3) %{
10763   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10764   match(Set dst (DivF (SubF src2 src1) src3));
10765 
10766   format %{ "FLD    $src2   ===MACRO4===\n\t"
10767             "FSUB   ST,$src1\n\t"
10768             "FDIV   ST,$src3\n\t"
10769             "FSTP  $dst" %}
10770   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
10771   ins_encode( Push_Reg_FPR(src2),
10772               subFPR_divFPR_encode(src1,src3),
10773               Pop_Reg_FPR(dst) );
10774   ins_pipe( fpu_reg_reg_reg_reg );
10775 %}
10776 
10777 // Spill to obtain 24-bit precision
10778 instruct divFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
10779   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
10780   match(Set dst (DivF src1 src2));
10781 
10782   format %{ "FDIV   $dst,$src1,$src2" %}
10783   opcode(0xD8, 0x6); /* D8 F0+i or DE /6*/
10784   ins_encode( Push_Reg_FPR(src1),
10785               OpcReg_FPR(src2),
10786               Pop_Mem_FPR(dst) );
10787   ins_pipe( fpu_mem_reg_reg );
10788 %}
10789 //
10790 // This instruction does not round to 24-bits
10791 instruct divFPR_reg(regFPR dst, regFPR src) %{
10792   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
10793   match(Set dst (DivF dst src));
10794 
10795   format %{ "FDIV   $dst,$src" %}
10796   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
10797   ins_encode( Push_Reg_FPR(src),
10798               OpcP, RegOpc(dst) );
10799   ins_pipe( fpu_reg_reg );
10800 %}
10801 
10802 
10803 // Spill to obtain 24-bit precision
10804 instruct modFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2, eAXRegI rax, eFlagsReg cr) %{
10805   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
10806   match(Set dst (ModF src1 src2));
10807   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
10808 
10809   format %{ "FMOD   $dst,$src1,$src2" %}
10810   ins_encode( Push_Reg_Mod_DPR(src1, src2),
10811               emitModDPR(),
10812               Push_Result_Mod_DPR(src2),
10813               Pop_Mem_FPR(dst));
10814   ins_pipe( pipe_slow );
10815 %}
10816 //
10817 // This instruction does not round to 24-bits
10818 instruct modFPR_reg(regFPR dst, regFPR src, eAXRegI rax, eFlagsReg cr) %{
10819   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
10820   match(Set dst (ModF dst src));
10821   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
10822 
10823   format %{ "FMOD   $dst,$src" %}
10824   ins_encode(Push_Reg_Mod_DPR(dst, src),
10825               emitModDPR(),
10826               Push_Result_Mod_DPR(src),
10827               Pop_Reg_FPR(dst));
10828   ins_pipe( pipe_slow );
10829 %}
10830 
10831 instruct modF_reg(regF dst, regF src0, regF src1, eAXRegI rax, eFlagsReg cr) %{
10832   predicate(UseSSE>=1);
10833   match(Set dst (ModF src0 src1));
10834   effect(KILL rax, KILL cr);
10835   format %{ "SUB    ESP,4\t # FMOD\n"
10836           "\tMOVSS  [ESP+0],$src1\n"
10837           "\tFLD_S  [ESP+0]\n"
10838           "\tMOVSS  [ESP+0],$src0\n"
10839           "\tFLD_S  [ESP+0]\n"
10840      "loop:\tFPREM\n"
10841           "\tFWAIT\n"
10842           "\tFNSTSW AX\n"
10843           "\tSAHF\n"
10844           "\tJP     loop\n"
10845           "\tFSTP_S [ESP+0]\n"
10846           "\tMOVSS  $dst,[ESP+0]\n"
10847           "\tADD    ESP,4\n"
10848           "\tFSTP   ST0\t # Restore FPU Stack"
10849     %}
10850   ins_cost(250);
10851   ins_encode( Push_ModF_encoding(src0, src1), emitModDPR(), Push_ResultF(dst,0x4), PopFPU);
10852   ins_pipe( pipe_slow );
10853 %}
10854 
10855 
10856 //----------Arithmetic Conversion Instructions---------------------------------
10857 // The conversions operations are all Alpha sorted.  Please keep it that way!
10858 
10859 instruct roundFloat_mem_reg(stackSlotF dst, regFPR src) %{
10860   predicate(UseSSE==0);
10861   match(Set dst (RoundFloat src));
10862   ins_cost(125);
10863   format %{ "FST_S  $dst,$src\t# F-round" %}
10864   ins_encode( Pop_Mem_Reg_FPR(dst, src) );
10865   ins_pipe( fpu_mem_reg );
10866 %}
10867 
10868 instruct roundDouble_mem_reg(stackSlotD dst, regDPR src) %{
10869   predicate(UseSSE<=1);
10870   match(Set dst (RoundDouble src));
10871   ins_cost(125);
10872   format %{ "FST_D  $dst,$src\t# D-round" %}
10873   ins_encode( Pop_Mem_Reg_DPR(dst, src) );
10874   ins_pipe( fpu_mem_reg );
10875 %}
10876 
10877 // Force rounding to 24-bit precision and 6-bit exponent
10878 instruct convDPR2FPR_reg(stackSlotF dst, regDPR src) %{
10879   predicate(UseSSE==0);
10880   match(Set dst (ConvD2F src));
10881   format %{ "FST_S  $dst,$src\t# F-round" %}
10882   expand %{
10883     roundFloat_mem_reg(dst,src);
10884   %}
10885 %}
10886 
10887 // Force rounding to 24-bit precision and 6-bit exponent
10888 instruct convDPR2F_reg(regF dst, regDPR src, eFlagsReg cr) %{
10889   predicate(UseSSE==1);
10890   match(Set dst (ConvD2F src));
10891   effect( KILL cr );
10892   format %{ "SUB    ESP,4\n\t"
10893             "FST_S  [ESP],$src\t# F-round\n\t"
10894             "MOVSS  $dst,[ESP]\n\t"
10895             "ADD ESP,4" %}
10896   ins_encode %{
10897     __ subptr(rsp, 4);
10898     if ($src$$reg != FPR1L_enc) {
10899       __ fld_s($src$$reg-1);
10900       __ fstp_s(Address(rsp, 0));
10901     } else {
10902       __ fst_s(Address(rsp, 0));
10903     }
10904     __ movflt($dst$$XMMRegister, Address(rsp, 0));
10905     __ addptr(rsp, 4);
10906   %}
10907   ins_pipe( pipe_slow );
10908 %}
10909 
10910 // Force rounding double precision to single precision
10911 instruct convD2F_reg(regF dst, regD src) %{
10912   predicate(UseSSE>=2);
10913   match(Set dst (ConvD2F src));
10914   format %{ "CVTSD2SS $dst,$src\t# F-round" %}
10915   ins_encode %{
10916     __ cvtsd2ss ($dst$$XMMRegister, $src$$XMMRegister);
10917   %}
10918   ins_pipe( pipe_slow );
10919 %}
10920 
10921 instruct convFPR2DPR_reg_reg(regDPR dst, regFPR src) %{
10922   predicate(UseSSE==0);
10923   match(Set dst (ConvF2D src));
10924   format %{ "FST_S  $dst,$src\t# D-round" %}
10925   ins_encode( Pop_Reg_Reg_DPR(dst, src));
10926   ins_pipe( fpu_reg_reg );
10927 %}
10928 
10929 instruct convFPR2D_reg(stackSlotD dst, regFPR src) %{
10930   predicate(UseSSE==1);
10931   match(Set dst (ConvF2D src));
10932   format %{ "FST_D  $dst,$src\t# D-round" %}
10933   expand %{
10934     roundDouble_mem_reg(dst,src);
10935   %}
10936 %}
10937 
10938 instruct convF2DPR_reg(regDPR dst, regF src, eFlagsReg cr) %{
10939   predicate(UseSSE==1);
10940   match(Set dst (ConvF2D src));
10941   effect( KILL cr );
10942   format %{ "SUB    ESP,4\n\t"
10943             "MOVSS  [ESP] $src\n\t"
10944             "FLD_S  [ESP]\n\t"
10945             "ADD    ESP,4\n\t"
10946             "FSTP   $dst\t# D-round" %}
10947   ins_encode %{
10948     __ subptr(rsp, 4);
10949     __ movflt(Address(rsp, 0), $src$$XMMRegister);
10950     __ fld_s(Address(rsp, 0));
10951     __ addptr(rsp, 4);
10952     __ fstp_d($dst$$reg);
10953   %}
10954   ins_pipe( pipe_slow );
10955 %}
10956 
10957 instruct convF2D_reg(regD dst, regF src) %{
10958   predicate(UseSSE>=2);
10959   match(Set dst (ConvF2D src));
10960   format %{ "CVTSS2SD $dst,$src\t# D-round" %}
10961   ins_encode %{
10962     __ cvtss2sd ($dst$$XMMRegister, $src$$XMMRegister);
10963   %}
10964   ins_pipe( pipe_slow );
10965 %}
10966 
10967 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
10968 instruct convDPR2I_reg_reg( eAXRegI dst, eDXRegI tmp, regDPR src, eFlagsReg cr ) %{
10969   predicate(UseSSE<=1);
10970   match(Set dst (ConvD2I src));
10971   effect( KILL tmp, KILL cr );
10972   format %{ "FLD    $src\t# Convert double to int \n\t"
10973             "FLDCW  trunc mode\n\t"
10974             "SUB    ESP,4\n\t"
10975             "FISTp  [ESP + #0]\n\t"
10976             "FLDCW  std/24-bit mode\n\t"
10977             "POP    EAX\n\t"
10978             "CMP    EAX,0x80000000\n\t"
10979             "JNE,s  fast\n\t"
10980             "FLD_D  $src\n\t"
10981             "CALL   d2i_wrapper\n"
10982       "fast:" %}
10983   ins_encode( Push_Reg_DPR(src), DPR2I_encoding(src) );
10984   ins_pipe( pipe_slow );
10985 %}
10986 
10987 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
10988 instruct convD2I_reg_reg( eAXRegI dst, eDXRegI tmp, regD src, eFlagsReg cr ) %{
10989   predicate(UseSSE>=2);
10990   match(Set dst (ConvD2I src));
10991   effect( KILL tmp, KILL cr );
10992   format %{ "CVTTSD2SI $dst, $src\n\t"
10993             "CMP    $dst,0x80000000\n\t"
10994             "JNE,s  fast\n\t"
10995             "SUB    ESP, 8\n\t"
10996             "MOVSD  [ESP], $src\n\t"
10997             "FLD_D  [ESP]\n\t"
10998             "ADD    ESP, 8\n\t"
10999             "CALL   d2i_wrapper\n"
11000       "fast:" %}
11001   ins_encode %{
11002     Label fast;
11003     __ cvttsd2sil($dst$$Register, $src$$XMMRegister);
11004     __ cmpl($dst$$Register, 0x80000000);
11005     __ jccb(Assembler::notEqual, fast);
11006     __ subptr(rsp, 8);
11007     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
11008     __ fld_d(Address(rsp, 0));
11009     __ addptr(rsp, 8);
11010     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2i_wrapper())));
11011     __ bind(fast);
11012   %}
11013   ins_pipe( pipe_slow );
11014 %}
11015 
11016 instruct convDPR2L_reg_reg( eADXRegL dst, regDPR src, eFlagsReg cr ) %{
11017   predicate(UseSSE<=1);
11018   match(Set dst (ConvD2L src));
11019   effect( KILL cr );
11020   format %{ "FLD    $src\t# Convert double to long\n\t"
11021             "FLDCW  trunc mode\n\t"
11022             "SUB    ESP,8\n\t"
11023             "FISTp  [ESP + #0]\n\t"
11024             "FLDCW  std/24-bit mode\n\t"
11025             "POP    EAX\n\t"
11026             "POP    EDX\n\t"
11027             "CMP    EDX,0x80000000\n\t"
11028             "JNE,s  fast\n\t"
11029             "TEST   EAX,EAX\n\t"
11030             "JNE,s  fast\n\t"
11031             "FLD    $src\n\t"
11032             "CALL   d2l_wrapper\n"
11033       "fast:" %}
11034   ins_encode( Push_Reg_DPR(src),  DPR2L_encoding(src) );
11035   ins_pipe( pipe_slow );
11036 %}
11037 
11038 // XMM lacks a float/double->long conversion, so use the old FPU stack.
11039 instruct convD2L_reg_reg( eADXRegL dst, regD src, eFlagsReg cr ) %{
11040   predicate (UseSSE>=2);
11041   match(Set dst (ConvD2L src));
11042   effect( KILL cr );
11043   format %{ "SUB    ESP,8\t# Convert double to long\n\t"
11044             "MOVSD  [ESP],$src\n\t"
11045             "FLD_D  [ESP]\n\t"
11046             "FLDCW  trunc mode\n\t"
11047             "FISTp  [ESP + #0]\n\t"
11048             "FLDCW  std/24-bit mode\n\t"
11049             "POP    EAX\n\t"
11050             "POP    EDX\n\t"
11051             "CMP    EDX,0x80000000\n\t"
11052             "JNE,s  fast\n\t"
11053             "TEST   EAX,EAX\n\t"
11054             "JNE,s  fast\n\t"
11055             "SUB    ESP,8\n\t"
11056             "MOVSD  [ESP],$src\n\t"
11057             "FLD_D  [ESP]\n\t"
11058             "ADD    ESP,8\n\t"
11059             "CALL   d2l_wrapper\n"
11060       "fast:" %}
11061   ins_encode %{
11062     Label fast;
11063     __ subptr(rsp, 8);
11064     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
11065     __ fld_d(Address(rsp, 0));
11066     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_trunc()));
11067     __ fistp_d(Address(rsp, 0));
11068     // Restore the rounding mode, mask the exception
11069     if (Compile::current()->in_24_bit_fp_mode()) {
11070       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
11071     } else {
11072       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
11073     }
11074     // Load the converted long, adjust CPU stack
11075     __ pop(rax);
11076     __ pop(rdx);
11077     __ cmpl(rdx, 0x80000000);
11078     __ jccb(Assembler::notEqual, fast);
11079     __ testl(rax, rax);
11080     __ jccb(Assembler::notEqual, fast);
11081     __ subptr(rsp, 8);
11082     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
11083     __ fld_d(Address(rsp, 0));
11084     __ addptr(rsp, 8);
11085     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2l_wrapper())));
11086     __ bind(fast);
11087   %}
11088   ins_pipe( pipe_slow );
11089 %}
11090 
11091 // Convert a double to an int.  Java semantics require we do complex
11092 // manglations in the corner cases.  So we set the rounding mode to
11093 // 'zero', store the darned double down as an int, and reset the
11094 // rounding mode to 'nearest'.  The hardware stores a flag value down
11095 // if we would overflow or converted a NAN; we check for this and
11096 // and go the slow path if needed.
11097 instruct convFPR2I_reg_reg(eAXRegI dst, eDXRegI tmp, regFPR src, eFlagsReg cr ) %{
11098   predicate(UseSSE==0);
11099   match(Set dst (ConvF2I src));
11100   effect( KILL tmp, KILL cr );
11101   format %{ "FLD    $src\t# Convert float to int \n\t"
11102             "FLDCW  trunc mode\n\t"
11103             "SUB    ESP,4\n\t"
11104             "FISTp  [ESP + #0]\n\t"
11105             "FLDCW  std/24-bit mode\n\t"
11106             "POP    EAX\n\t"
11107             "CMP    EAX,0x80000000\n\t"
11108             "JNE,s  fast\n\t"
11109             "FLD    $src\n\t"
11110             "CALL   d2i_wrapper\n"
11111       "fast:" %}
11112   // DPR2I_encoding works for FPR2I
11113   ins_encode( Push_Reg_FPR(src), DPR2I_encoding(src) );
11114   ins_pipe( pipe_slow );
11115 %}
11116 
11117 // Convert a float in xmm to an int reg.
11118 instruct convF2I_reg(eAXRegI dst, eDXRegI tmp, regF src, eFlagsReg cr ) %{
11119   predicate(UseSSE>=1);
11120   match(Set dst (ConvF2I src));
11121   effect( KILL tmp, KILL cr );
11122   format %{ "CVTTSS2SI $dst, $src\n\t"
11123             "CMP    $dst,0x80000000\n\t"
11124             "JNE,s  fast\n\t"
11125             "SUB    ESP, 4\n\t"
11126             "MOVSS  [ESP], $src\n\t"
11127             "FLD    [ESP]\n\t"
11128             "ADD    ESP, 4\n\t"
11129             "CALL   d2i_wrapper\n"
11130       "fast:" %}
11131   ins_encode %{
11132     Label fast;
11133     __ cvttss2sil($dst$$Register, $src$$XMMRegister);
11134     __ cmpl($dst$$Register, 0x80000000);
11135     __ jccb(Assembler::notEqual, fast);
11136     __ subptr(rsp, 4);
11137     __ movflt(Address(rsp, 0), $src$$XMMRegister);
11138     __ fld_s(Address(rsp, 0));
11139     __ addptr(rsp, 4);
11140     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2i_wrapper())));
11141     __ bind(fast);
11142   %}
11143   ins_pipe( pipe_slow );
11144 %}
11145 
11146 instruct convFPR2L_reg_reg( eADXRegL dst, regFPR src, eFlagsReg cr ) %{
11147   predicate(UseSSE==0);
11148   match(Set dst (ConvF2L src));
11149   effect( KILL cr );
11150   format %{ "FLD    $src\t# Convert float to long\n\t"
11151             "FLDCW  trunc mode\n\t"
11152             "SUB    ESP,8\n\t"
11153             "FISTp  [ESP + #0]\n\t"
11154             "FLDCW  std/24-bit mode\n\t"
11155             "POP    EAX\n\t"
11156             "POP    EDX\n\t"
11157             "CMP    EDX,0x80000000\n\t"
11158             "JNE,s  fast\n\t"
11159             "TEST   EAX,EAX\n\t"
11160             "JNE,s  fast\n\t"
11161             "FLD    $src\n\t"
11162             "CALL   d2l_wrapper\n"
11163       "fast:" %}
11164   // DPR2L_encoding works for FPR2L
11165   ins_encode( Push_Reg_FPR(src), DPR2L_encoding(src) );
11166   ins_pipe( pipe_slow );
11167 %}
11168 
11169 // XMM lacks a float/double->long conversion, so use the old FPU stack.
11170 instruct convF2L_reg_reg( eADXRegL dst, regF src, eFlagsReg cr ) %{
11171   predicate (UseSSE>=1);
11172   match(Set dst (ConvF2L src));
11173   effect( KILL cr );
11174   format %{ "SUB    ESP,8\t# Convert float to long\n\t"
11175             "MOVSS  [ESP],$src\n\t"
11176             "FLD_S  [ESP]\n\t"
11177             "FLDCW  trunc mode\n\t"
11178             "FISTp  [ESP + #0]\n\t"
11179             "FLDCW  std/24-bit mode\n\t"
11180             "POP    EAX\n\t"
11181             "POP    EDX\n\t"
11182             "CMP    EDX,0x80000000\n\t"
11183             "JNE,s  fast\n\t"
11184             "TEST   EAX,EAX\n\t"
11185             "JNE,s  fast\n\t"
11186             "SUB    ESP,4\t# Convert float to long\n\t"
11187             "MOVSS  [ESP],$src\n\t"
11188             "FLD_S  [ESP]\n\t"
11189             "ADD    ESP,4\n\t"
11190             "CALL   d2l_wrapper\n"
11191       "fast:" %}
11192   ins_encode %{
11193     Label fast;
11194     __ subptr(rsp, 8);
11195     __ movflt(Address(rsp, 0), $src$$XMMRegister);
11196     __ fld_s(Address(rsp, 0));
11197     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_trunc()));
11198     __ fistp_d(Address(rsp, 0));
11199     // Restore the rounding mode, mask the exception
11200     if (Compile::current()->in_24_bit_fp_mode()) {
11201       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
11202     } else {
11203       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
11204     }
11205     // Load the converted long, adjust CPU stack
11206     __ pop(rax);
11207     __ pop(rdx);
11208     __ cmpl(rdx, 0x80000000);
11209     __ jccb(Assembler::notEqual, fast);
11210     __ testl(rax, rax);
11211     __ jccb(Assembler::notEqual, fast);
11212     __ subptr(rsp, 4);
11213     __ movflt(Address(rsp, 0), $src$$XMMRegister);
11214     __ fld_s(Address(rsp, 0));
11215     __ addptr(rsp, 4);
11216     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2l_wrapper())));
11217     __ bind(fast);
11218   %}
11219   ins_pipe( pipe_slow );
11220 %}
11221 
11222 instruct convI2DPR_reg(regDPR dst, stackSlotI src) %{
11223   predicate( UseSSE<=1 );
11224   match(Set dst (ConvI2D src));
11225   format %{ "FILD   $src\n\t"
11226             "FSTP   $dst" %}
11227   opcode(0xDB, 0x0);  /* DB /0 */
11228   ins_encode(Push_Mem_I(src), Pop_Reg_DPR(dst));
11229   ins_pipe( fpu_reg_mem );
11230 %}
11231 
11232 instruct convI2D_reg(regD dst, rRegI src) %{
11233   predicate( UseSSE>=2 && !UseXmmI2D );
11234   match(Set dst (ConvI2D src));
11235   format %{ "CVTSI2SD $dst,$src" %}
11236   ins_encode %{
11237     __ cvtsi2sdl ($dst$$XMMRegister, $src$$Register);
11238   %}
11239   ins_pipe( pipe_slow );
11240 %}
11241 
11242 instruct convI2D_mem(regD dst, memory mem) %{
11243   predicate( UseSSE>=2 );
11244   match(Set dst (ConvI2D (LoadI mem)));
11245   format %{ "CVTSI2SD $dst,$mem" %}
11246   ins_encode %{
11247     __ cvtsi2sdl ($dst$$XMMRegister, $mem$$Address);
11248   %}
11249   ins_pipe( pipe_slow );
11250 %}
11251 
11252 instruct convXI2D_reg(regD dst, rRegI src)
11253 %{
11254   predicate( UseSSE>=2 && UseXmmI2D );
11255   match(Set dst (ConvI2D src));
11256 
11257   format %{ "MOVD  $dst,$src\n\t"
11258             "CVTDQ2PD $dst,$dst\t# i2d" %}
11259   ins_encode %{
11260     __ movdl($dst$$XMMRegister, $src$$Register);
11261     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
11262   %}
11263   ins_pipe(pipe_slow); // XXX
11264 %}
11265 
11266 instruct convI2DPR_mem(regDPR dst, memory mem) %{
11267   predicate( UseSSE<=1 && !Compile::current()->select_24_bit_instr());
11268   match(Set dst (ConvI2D (LoadI mem)));
11269   format %{ "FILD   $mem\n\t"
11270             "FSTP   $dst" %}
11271   opcode(0xDB);      /* DB /0 */
11272   ins_encode( OpcP, RMopc_Mem(0x00,mem),
11273               Pop_Reg_DPR(dst));
11274   ins_pipe( fpu_reg_mem );
11275 %}
11276 
11277 // Convert a byte to a float; no rounding step needed.
11278 instruct conv24I2FPR_reg(regFPR dst, stackSlotI src) %{
11279   predicate( UseSSE==0 && n->in(1)->Opcode() == Op_AndI && n->in(1)->in(2)->is_Con() && n->in(1)->in(2)->get_int() == 255 );
11280   match(Set dst (ConvI2F src));
11281   format %{ "FILD   $src\n\t"
11282             "FSTP   $dst" %}
11283 
11284   opcode(0xDB, 0x0);  /* DB /0 */
11285   ins_encode(Push_Mem_I(src), Pop_Reg_FPR(dst));
11286   ins_pipe( fpu_reg_mem );
11287 %}
11288 
11289 // In 24-bit mode, force exponent rounding by storing back out
11290 instruct convI2FPR_SSF(stackSlotF dst, stackSlotI src) %{
11291   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
11292   match(Set dst (ConvI2F src));
11293   ins_cost(200);
11294   format %{ "FILD   $src\n\t"
11295             "FSTP_S $dst" %}
11296   opcode(0xDB, 0x0);  /* DB /0 */
11297   ins_encode( Push_Mem_I(src),
11298               Pop_Mem_FPR(dst));
11299   ins_pipe( fpu_mem_mem );
11300 %}
11301 
11302 // In 24-bit mode, force exponent rounding by storing back out
11303 instruct convI2FPR_SSF_mem(stackSlotF dst, memory mem) %{
11304   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
11305   match(Set dst (ConvI2F (LoadI mem)));
11306   ins_cost(200);
11307   format %{ "FILD   $mem\n\t"
11308             "FSTP_S $dst" %}
11309   opcode(0xDB);  /* DB /0 */
11310   ins_encode( OpcP, RMopc_Mem(0x00,mem),
11311               Pop_Mem_FPR(dst));
11312   ins_pipe( fpu_mem_mem );
11313 %}
11314 
11315 // This instruction does not round to 24-bits
11316 instruct convI2FPR_reg(regFPR dst, stackSlotI src) %{
11317   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
11318   match(Set dst (ConvI2F src));
11319   format %{ "FILD   $src\n\t"
11320             "FSTP   $dst" %}
11321   opcode(0xDB, 0x0);  /* DB /0 */
11322   ins_encode( Push_Mem_I(src),
11323               Pop_Reg_FPR(dst));
11324   ins_pipe( fpu_reg_mem );
11325 %}
11326 
11327 // This instruction does not round to 24-bits
11328 instruct convI2FPR_mem(regFPR dst, memory mem) %{
11329   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
11330   match(Set dst (ConvI2F (LoadI mem)));
11331   format %{ "FILD   $mem\n\t"
11332             "FSTP   $dst" %}
11333   opcode(0xDB);      /* DB /0 */
11334   ins_encode( OpcP, RMopc_Mem(0x00,mem),
11335               Pop_Reg_FPR(dst));
11336   ins_pipe( fpu_reg_mem );
11337 %}
11338 
11339 // Convert an int to a float in xmm; no rounding step needed.
11340 instruct convI2F_reg(regF dst, rRegI src) %{
11341   predicate( UseSSE==1 || UseSSE>=2 && !UseXmmI2F );
11342   match(Set dst (ConvI2F src));
11343   format %{ "CVTSI2SS $dst, $src" %}
11344   ins_encode %{
11345     __ cvtsi2ssl ($dst$$XMMRegister, $src$$Register);
11346   %}
11347   ins_pipe( pipe_slow );
11348 %}
11349 
11350  instruct convXI2F_reg(regF dst, rRegI src)
11351 %{
11352   predicate( UseSSE>=2 && UseXmmI2F );
11353   match(Set dst (ConvI2F src));
11354 
11355   format %{ "MOVD  $dst,$src\n\t"
11356             "CVTDQ2PS $dst,$dst\t# i2f" %}
11357   ins_encode %{
11358     __ movdl($dst$$XMMRegister, $src$$Register);
11359     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
11360   %}
11361   ins_pipe(pipe_slow); // XXX
11362 %}
11363 
11364 instruct convI2L_reg( eRegL dst, rRegI src, eFlagsReg cr) %{
11365   match(Set dst (ConvI2L src));
11366   effect(KILL cr);
11367   ins_cost(375);
11368   format %{ "MOV    $dst.lo,$src\n\t"
11369             "MOV    $dst.hi,$src\n\t"
11370             "SAR    $dst.hi,31" %}
11371   ins_encode(convert_int_long(dst,src));
11372   ins_pipe( ialu_reg_reg_long );
11373 %}
11374 
11375 // Zero-extend convert int to long
11376 instruct convI2L_reg_zex(eRegL dst, rRegI src, immL_32bits mask, eFlagsReg flags ) %{
11377   match(Set dst (AndL (ConvI2L src) mask) );
11378   effect( KILL flags );
11379   ins_cost(250);
11380   format %{ "MOV    $dst.lo,$src\n\t"
11381             "XOR    $dst.hi,$dst.hi" %}
11382   opcode(0x33); // XOR
11383   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
11384   ins_pipe( ialu_reg_reg_long );
11385 %}
11386 
11387 // Zero-extend long
11388 instruct zerox_long(eRegL dst, eRegL src, immL_32bits mask, eFlagsReg flags ) %{
11389   match(Set dst (AndL src mask) );
11390   effect( KILL flags );
11391   ins_cost(250);
11392   format %{ "MOV    $dst.lo,$src.lo\n\t"
11393             "XOR    $dst.hi,$dst.hi\n\t" %}
11394   opcode(0x33); // XOR
11395   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
11396   ins_pipe( ialu_reg_reg_long );
11397 %}
11398 
11399 instruct convL2DPR_reg( stackSlotD dst, eRegL src, eFlagsReg cr) %{
11400   predicate (UseSSE<=1);
11401   match(Set dst (ConvL2D src));
11402   effect( KILL cr );
11403   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
11404             "PUSH   $src.lo\n\t"
11405             "FILD   ST,[ESP + #0]\n\t"
11406             "ADD    ESP,8\n\t"
11407             "FSTP_D $dst\t# D-round" %}
11408   opcode(0xDF, 0x5);  /* DF /5 */
11409   ins_encode(convert_long_double(src), Pop_Mem_DPR(dst));
11410   ins_pipe( pipe_slow );
11411 %}
11412 
11413 instruct convL2D_reg( regD dst, eRegL src, eFlagsReg cr) %{
11414   predicate (UseSSE>=2);
11415   match(Set dst (ConvL2D src));
11416   effect( KILL cr );
11417   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
11418             "PUSH   $src.lo\n\t"
11419             "FILD_D [ESP]\n\t"
11420             "FSTP_D [ESP]\n\t"
11421             "MOVSD  $dst,[ESP]\n\t"
11422             "ADD    ESP,8" %}
11423   opcode(0xDF, 0x5);  /* DF /5 */
11424   ins_encode(convert_long_double2(src), Push_ResultD(dst));
11425   ins_pipe( pipe_slow );
11426 %}
11427 
11428 instruct convL2F_reg( regF dst, eRegL src, eFlagsReg cr) %{
11429   predicate (UseSSE>=1);
11430   match(Set dst (ConvL2F src));
11431   effect( KILL cr );
11432   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
11433             "PUSH   $src.lo\n\t"
11434             "FILD_D [ESP]\n\t"
11435             "FSTP_S [ESP]\n\t"
11436             "MOVSS  $dst,[ESP]\n\t"
11437             "ADD    ESP,8" %}
11438   opcode(0xDF, 0x5);  /* DF /5 */
11439   ins_encode(convert_long_double2(src), Push_ResultF(dst,0x8));
11440   ins_pipe( pipe_slow );
11441 %}
11442 
11443 instruct convL2FPR_reg( stackSlotF dst, eRegL src, eFlagsReg cr) %{
11444   match(Set dst (ConvL2F src));
11445   effect( KILL cr );
11446   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
11447             "PUSH   $src.lo\n\t"
11448             "FILD   ST,[ESP + #0]\n\t"
11449             "ADD    ESP,8\n\t"
11450             "FSTP_S $dst\t# F-round" %}
11451   opcode(0xDF, 0x5);  /* DF /5 */
11452   ins_encode(convert_long_double(src), Pop_Mem_FPR(dst));
11453   ins_pipe( pipe_slow );
11454 %}
11455 
11456 instruct convL2I_reg( rRegI dst, eRegL src ) %{
11457   match(Set dst (ConvL2I src));
11458   effect( DEF dst, USE src );
11459   format %{ "MOV    $dst,$src.lo" %}
11460   ins_encode(enc_CopyL_Lo(dst,src));
11461   ins_pipe( ialu_reg_reg );
11462 %}
11463 
11464 
11465 instruct MoveF2I_stack_reg(rRegI dst, stackSlotF src) %{
11466   match(Set dst (MoveF2I src));
11467   effect( DEF dst, USE src );
11468   ins_cost(100);
11469   format %{ "MOV    $dst,$src\t# MoveF2I_stack_reg" %}
11470   ins_encode %{
11471     __ movl($dst$$Register, Address(rsp, $src$$disp));
11472   %}
11473   ins_pipe( ialu_reg_mem );
11474 %}
11475 
11476 instruct MoveFPR2I_reg_stack(stackSlotI dst, regFPR src) %{
11477   predicate(UseSSE==0);
11478   match(Set dst (MoveF2I src));
11479   effect( DEF dst, USE src );
11480 
11481   ins_cost(125);
11482   format %{ "FST_S  $dst,$src\t# MoveF2I_reg_stack" %}
11483   ins_encode( Pop_Mem_Reg_FPR(dst, src) );
11484   ins_pipe( fpu_mem_reg );
11485 %}
11486 
11487 instruct MoveF2I_reg_stack_sse(stackSlotI dst, regF src) %{
11488   predicate(UseSSE>=1);
11489   match(Set dst (MoveF2I src));
11490   effect( DEF dst, USE src );
11491 
11492   ins_cost(95);
11493   format %{ "MOVSS  $dst,$src\t# MoveF2I_reg_stack_sse" %}
11494   ins_encode %{
11495     __ movflt(Address(rsp, $dst$$disp), $src$$XMMRegister);
11496   %}
11497   ins_pipe( pipe_slow );
11498 %}
11499 
11500 instruct MoveF2I_reg_reg_sse(rRegI dst, regF src) %{
11501   predicate(UseSSE>=2);
11502   match(Set dst (MoveF2I src));
11503   effect( DEF dst, USE src );
11504   ins_cost(85);
11505   format %{ "MOVD   $dst,$src\t# MoveF2I_reg_reg_sse" %}
11506   ins_encode %{
11507     __ movdl($dst$$Register, $src$$XMMRegister);
11508   %}
11509   ins_pipe( pipe_slow );
11510 %}
11511 
11512 instruct MoveI2F_reg_stack(stackSlotF dst, rRegI src) %{
11513   match(Set dst (MoveI2F src));
11514   effect( DEF dst, USE src );
11515 
11516   ins_cost(100);
11517   format %{ "MOV    $dst,$src\t# MoveI2F_reg_stack" %}
11518   ins_encode %{
11519     __ movl(Address(rsp, $dst$$disp), $src$$Register);
11520   %}
11521   ins_pipe( ialu_mem_reg );
11522 %}
11523 
11524 
11525 instruct MoveI2FPR_stack_reg(regFPR dst, stackSlotI src) %{
11526   predicate(UseSSE==0);
11527   match(Set dst (MoveI2F src));
11528   effect(DEF dst, USE src);
11529 
11530   ins_cost(125);
11531   format %{ "FLD_S  $src\n\t"
11532             "FSTP   $dst\t# MoveI2F_stack_reg" %}
11533   opcode(0xD9);               /* D9 /0, FLD m32real */
11534   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
11535               Pop_Reg_FPR(dst) );
11536   ins_pipe( fpu_reg_mem );
11537 %}
11538 
11539 instruct MoveI2F_stack_reg_sse(regF dst, stackSlotI src) %{
11540   predicate(UseSSE>=1);
11541   match(Set dst (MoveI2F src));
11542   effect( DEF dst, USE src );
11543 
11544   ins_cost(95);
11545   format %{ "MOVSS  $dst,$src\t# MoveI2F_stack_reg_sse" %}
11546   ins_encode %{
11547     __ movflt($dst$$XMMRegister, Address(rsp, $src$$disp));
11548   %}
11549   ins_pipe( pipe_slow );
11550 %}
11551 
11552 instruct MoveI2F_reg_reg_sse(regF dst, rRegI src) %{
11553   predicate(UseSSE>=2);
11554   match(Set dst (MoveI2F src));
11555   effect( DEF dst, USE src );
11556 
11557   ins_cost(85);
11558   format %{ "MOVD   $dst,$src\t# MoveI2F_reg_reg_sse" %}
11559   ins_encode %{
11560     __ movdl($dst$$XMMRegister, $src$$Register);
11561   %}
11562   ins_pipe( pipe_slow );
11563 %}
11564 
11565 instruct MoveD2L_stack_reg(eRegL dst, stackSlotD src) %{
11566   match(Set dst (MoveD2L src));
11567   effect(DEF dst, USE src);
11568 
11569   ins_cost(250);
11570   format %{ "MOV    $dst.lo,$src\n\t"
11571             "MOV    $dst.hi,$src+4\t# MoveD2L_stack_reg" %}
11572   opcode(0x8B, 0x8B);
11573   ins_encode( OpcP, RegMem(dst,src), OpcS, RegMem_Hi(dst,src));
11574   ins_pipe( ialu_mem_long_reg );
11575 %}
11576 
11577 instruct MoveDPR2L_reg_stack(stackSlotL dst, regDPR src) %{
11578   predicate(UseSSE<=1);
11579   match(Set dst (MoveD2L src));
11580   effect(DEF dst, USE src);
11581 
11582   ins_cost(125);
11583   format %{ "FST_D  $dst,$src\t# MoveD2L_reg_stack" %}
11584   ins_encode( Pop_Mem_Reg_DPR(dst, src) );
11585   ins_pipe( fpu_mem_reg );
11586 %}
11587 
11588 instruct MoveD2L_reg_stack_sse(stackSlotL dst, regD src) %{
11589   predicate(UseSSE>=2);
11590   match(Set dst (MoveD2L src));
11591   effect(DEF dst, USE src);
11592   ins_cost(95);
11593   format %{ "MOVSD  $dst,$src\t# MoveD2L_reg_stack_sse" %}
11594   ins_encode %{
11595     __ movdbl(Address(rsp, $dst$$disp), $src$$XMMRegister);
11596   %}
11597   ins_pipe( pipe_slow );
11598 %}
11599 
11600 instruct MoveD2L_reg_reg_sse(eRegL dst, regD src, regD tmp) %{
11601   predicate(UseSSE>=2);
11602   match(Set dst (MoveD2L src));
11603   effect(DEF dst, USE src, TEMP tmp);
11604   ins_cost(85);
11605   format %{ "MOVD   $dst.lo,$src\n\t"
11606             "PSHUFLW $tmp,$src,0x4E\n\t"
11607             "MOVD   $dst.hi,$tmp\t# MoveD2L_reg_reg_sse" %}
11608   ins_encode %{
11609     __ movdl($dst$$Register, $src$$XMMRegister);
11610     __ pshuflw($tmp$$XMMRegister, $src$$XMMRegister, 0x4e);
11611     __ movdl(HIGH_FROM_LOW($dst$$Register), $tmp$$XMMRegister);
11612   %}
11613   ins_pipe( pipe_slow );
11614 %}
11615 
11616 instruct MoveL2D_reg_stack(stackSlotD dst, eRegL src) %{
11617   match(Set dst (MoveL2D src));
11618   effect(DEF dst, USE src);
11619 
11620   ins_cost(200);
11621   format %{ "MOV    $dst,$src.lo\n\t"
11622             "MOV    $dst+4,$src.hi\t# MoveL2D_reg_stack" %}
11623   opcode(0x89, 0x89);
11624   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
11625   ins_pipe( ialu_mem_long_reg );
11626 %}
11627 
11628 
11629 instruct MoveL2DPR_stack_reg(regDPR dst, stackSlotL src) %{
11630   predicate(UseSSE<=1);
11631   match(Set dst (MoveL2D src));
11632   effect(DEF dst, USE src);
11633   ins_cost(125);
11634 
11635   format %{ "FLD_D  $src\n\t"
11636             "FSTP   $dst\t# MoveL2D_stack_reg" %}
11637   opcode(0xDD);               /* DD /0, FLD m64real */
11638   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
11639               Pop_Reg_DPR(dst) );
11640   ins_pipe( fpu_reg_mem );
11641 %}
11642 
11643 
11644 instruct MoveL2D_stack_reg_sse(regD dst, stackSlotL src) %{
11645   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
11646   match(Set dst (MoveL2D src));
11647   effect(DEF dst, USE src);
11648 
11649   ins_cost(95);
11650   format %{ "MOVSD  $dst,$src\t# MoveL2D_stack_reg_sse" %}
11651   ins_encode %{
11652     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
11653   %}
11654   ins_pipe( pipe_slow );
11655 %}
11656 
11657 instruct MoveL2D_stack_reg_sse_partial(regD dst, stackSlotL src) %{
11658   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
11659   match(Set dst (MoveL2D src));
11660   effect(DEF dst, USE src);
11661 
11662   ins_cost(95);
11663   format %{ "MOVLPD $dst,$src\t# MoveL2D_stack_reg_sse" %}
11664   ins_encode %{
11665     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
11666   %}
11667   ins_pipe( pipe_slow );
11668 %}
11669 
11670 instruct MoveL2D_reg_reg_sse(regD dst, eRegL src, regD tmp) %{
11671   predicate(UseSSE>=2);
11672   match(Set dst (MoveL2D src));
11673   effect(TEMP dst, USE src, TEMP tmp);
11674   ins_cost(85);
11675   format %{ "MOVD   $dst,$src.lo\n\t"
11676             "MOVD   $tmp,$src.hi\n\t"
11677             "PUNPCKLDQ $dst,$tmp\t# MoveL2D_reg_reg_sse" %}
11678   ins_encode %{
11679     __ movdl($dst$$XMMRegister, $src$$Register);
11680     __ movdl($tmp$$XMMRegister, HIGH_FROM_LOW($src$$Register));
11681     __ punpckldq($dst$$XMMRegister, $tmp$$XMMRegister);
11682   %}
11683   ins_pipe( pipe_slow );
11684 %}
11685 
11686 
11687 // =======================================================================
11688 // fast clearing of an array
11689 instruct rep_stos(eCXRegI cnt, eDIRegP base, eAXRegI zero, Universe dummy, eFlagsReg cr) %{
11690   predicate(!UseFastStosb);
11691   match(Set dummy (ClearArray cnt base));
11692   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
11693   format %{ "XOR    EAX,EAX\t# ClearArray:\n\t"
11694             "SHL    ECX,1\t# Convert doublewords to words\n\t"
11695             "REP STOS\t# store EAX into [EDI++] while ECX--" %}
11696   ins_encode %{ 
11697     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register);
11698   %}
11699   ins_pipe( pipe_slow );
11700 %}
11701 
11702 instruct rep_fast_stosb(eCXRegI cnt, eDIRegP base, eAXRegI zero, Universe dummy, eFlagsReg cr) %{
11703   predicate(UseFastStosb);
11704   match(Set dummy (ClearArray cnt base));
11705   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
11706   format %{ "XOR    EAX,EAX\t# ClearArray:\n\t"
11707             "SHL    ECX,3\t# Convert doublewords to bytes\n\t"
11708             "REP STOSB\t# store EAX into [EDI++] while ECX--" %}
11709   ins_encode %{ 
11710     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register);
11711   %}
11712   ins_pipe( pipe_slow );
11713 %}
11714 
11715 instruct string_compare(eDIRegP str1, eCXRegI cnt1, eSIRegP str2, eDXRegI cnt2,
11716                         eAXRegI result, regD tmp1, eFlagsReg cr) %{
11717   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11718   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11719 
11720   format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11721   ins_encode %{
11722     __ string_compare($str1$$Register, $str2$$Register,
11723                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11724                       $tmp1$$XMMRegister);
11725   %}
11726   ins_pipe( pipe_slow );
11727 %}
11728 
11729 // fast string equals
11730 instruct string_equals(eDIRegP str1, eSIRegP str2, eCXRegI cnt, eAXRegI result,
11731                        regD tmp1, regD tmp2, eBXRegI tmp3, eFlagsReg cr) %{
11732   match(Set result (StrEquals (Binary str1 str2) cnt));
11733   effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
11734 
11735   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
11736   ins_encode %{
11737     __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
11738                           $cnt$$Register, $result$$Register, $tmp3$$Register,
11739                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
11740   %}
11741   ins_pipe( pipe_slow );
11742 %}
11743 
11744 // fast search of substring with known size.
11745 instruct string_indexof_con(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, immI int_cnt2,
11746                             eBXRegI result, regD vec, eAXRegI cnt2, eCXRegI tmp, eFlagsReg cr) %{
11747   predicate(UseSSE42Intrinsics);
11748   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
11749   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
11750 
11751   format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $vec, $cnt1, $cnt2, $tmp" %}
11752   ins_encode %{
11753     int icnt2 = (int)$int_cnt2$$constant;
11754     if (icnt2 >= 8) {
11755       // IndexOf for constant substrings with size >= 8 elements
11756       // which don't need to be loaded through stack.
11757       __ string_indexofC8($str1$$Register, $str2$$Register,
11758                           $cnt1$$Register, $cnt2$$Register,
11759                           icnt2, $result$$Register,
11760                           $vec$$XMMRegister, $tmp$$Register);
11761     } else {
11762       // Small strings are loaded through stack if they cross page boundary.
11763       __ string_indexof($str1$$Register, $str2$$Register,
11764                         $cnt1$$Register, $cnt2$$Register,
11765                         icnt2, $result$$Register,
11766                         $vec$$XMMRegister, $tmp$$Register);
11767     }
11768   %}
11769   ins_pipe( pipe_slow );
11770 %}
11771 
11772 instruct string_indexof(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, eAXRegI cnt2,
11773                         eBXRegI result, regD vec, eCXRegI tmp, eFlagsReg cr) %{
11774   predicate(UseSSE42Intrinsics);
11775   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
11776   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
11777 
11778   format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
11779   ins_encode %{
11780     __ string_indexof($str1$$Register, $str2$$Register,
11781                       $cnt1$$Register, $cnt2$$Register,
11782                       (-1), $result$$Register,
11783                       $vec$$XMMRegister, $tmp$$Register);
11784   %}
11785   ins_pipe( pipe_slow );
11786 %}
11787 
11788 // fast array equals
11789 instruct array_equals(eDIRegP ary1, eSIRegP ary2, eAXRegI result,
11790                       regD tmp1, regD tmp2, eCXRegI tmp3, eBXRegI tmp4, eFlagsReg cr)
11791 %{
11792   match(Set result (AryEq ary1 ary2));
11793   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11794   //ins_cost(300);
11795 
11796   format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11797   ins_encode %{
11798     __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
11799                           $tmp3$$Register, $result$$Register, $tmp4$$Register,
11800                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
11801   %}
11802   ins_pipe( pipe_slow );
11803 %}
11804 
11805 // encode char[] to byte[] in ISO_8859_1
11806 instruct encode_iso_array(eSIRegP src, eDIRegP dst, eDXRegI len,
11807                           regD tmp1, regD tmp2, regD tmp3, regD tmp4,
11808                           eCXRegI tmp5, eAXRegI result, eFlagsReg cr) %{
11809   match(Set result (EncodeISOArray src (Binary dst len)));
11810   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, USE_KILL src, USE_KILL dst, USE_KILL len, KILL tmp5, KILL cr);
11811 
11812   format %{ "Encode array $src,$dst,$len -> $result    // KILL ECX, EDX, $tmp1, $tmp2, $tmp3, $tmp4, ESI, EDI " %}
11813   ins_encode %{
11814     __ encode_iso_array($src$$Register, $dst$$Register, $len$$Register,
11815                         $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
11816                         $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register);
11817   %}
11818   ins_pipe( pipe_slow );
11819 %}
11820 
11821 
11822 //----------Control Flow Instructions------------------------------------------
11823 // Signed compare Instructions
11824 instruct compI_eReg(eFlagsReg cr, rRegI op1, rRegI op2) %{
11825   match(Set cr (CmpI op1 op2));
11826   effect( DEF cr, USE op1, USE op2 );
11827   format %{ "CMP    $op1,$op2" %}
11828   opcode(0x3B);  /* Opcode 3B /r */
11829   ins_encode( OpcP, RegReg( op1, op2) );
11830   ins_pipe( ialu_cr_reg_reg );
11831 %}
11832 
11833 instruct compI_eReg_imm(eFlagsReg cr, rRegI op1, immI op2) %{
11834   match(Set cr (CmpI op1 op2));
11835   effect( DEF cr, USE op1 );
11836   format %{ "CMP    $op1,$op2" %}
11837   opcode(0x81,0x07);  /* Opcode 81 /7 */
11838   // ins_encode( RegImm( op1, op2) );  /* Was CmpImm */
11839   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
11840   ins_pipe( ialu_cr_reg_imm );
11841 %}
11842 
11843 // Cisc-spilled version of cmpI_eReg
11844 instruct compI_eReg_mem(eFlagsReg cr, rRegI op1, memory op2) %{
11845   match(Set cr (CmpI op1 (LoadI op2)));
11846 
11847   format %{ "CMP    $op1,$op2" %}
11848   ins_cost(500);
11849   opcode(0x3B);  /* Opcode 3B /r */
11850   ins_encode( OpcP, RegMem( op1, op2) );
11851   ins_pipe( ialu_cr_reg_mem );
11852 %}
11853 
11854 instruct testI_reg( eFlagsReg cr, rRegI src, immI0 zero ) %{
11855   match(Set cr (CmpI src zero));
11856   effect( DEF cr, USE src );
11857 
11858   format %{ "TEST   $src,$src" %}
11859   opcode(0x85);
11860   ins_encode( OpcP, RegReg( src, src ) );
11861   ins_pipe( ialu_cr_reg_imm );
11862 %}
11863 
11864 instruct testI_reg_imm( eFlagsReg cr, rRegI src, immI con, immI0 zero ) %{
11865   match(Set cr (CmpI (AndI src con) zero));
11866 
11867   format %{ "TEST   $src,$con" %}
11868   opcode(0xF7,0x00);
11869   ins_encode( OpcP, RegOpc(src), Con32(con) );
11870   ins_pipe( ialu_cr_reg_imm );
11871 %}
11872 
11873 instruct testI_reg_mem( eFlagsReg cr, rRegI src, memory mem, immI0 zero ) %{
11874   match(Set cr (CmpI (AndI src mem) zero));
11875 
11876   format %{ "TEST   $src,$mem" %}
11877   opcode(0x85);
11878   ins_encode( OpcP, RegMem( src, mem ) );
11879   ins_pipe( ialu_cr_reg_mem );
11880 %}
11881 
11882 // Unsigned compare Instructions; really, same as signed except they
11883 // produce an eFlagsRegU instead of eFlagsReg.
11884 instruct compU_eReg(eFlagsRegU cr, rRegI op1, rRegI op2) %{
11885   match(Set cr (CmpU op1 op2));
11886 
11887   format %{ "CMPu   $op1,$op2" %}
11888   opcode(0x3B);  /* Opcode 3B /r */
11889   ins_encode( OpcP, RegReg( op1, op2) );
11890   ins_pipe( ialu_cr_reg_reg );
11891 %}
11892 
11893 instruct compU_eReg_imm(eFlagsRegU cr, rRegI op1, immI op2) %{
11894   match(Set cr (CmpU op1 op2));
11895 
11896   format %{ "CMPu   $op1,$op2" %}
11897   opcode(0x81,0x07);  /* Opcode 81 /7 */
11898   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
11899   ins_pipe( ialu_cr_reg_imm );
11900 %}
11901 
11902 // // Cisc-spilled version of cmpU_eReg
11903 instruct compU_eReg_mem(eFlagsRegU cr, rRegI op1, memory op2) %{
11904   match(Set cr (CmpU op1 (LoadI op2)));
11905 
11906   format %{ "CMPu   $op1,$op2" %}
11907   ins_cost(500);
11908   opcode(0x3B);  /* Opcode 3B /r */
11909   ins_encode( OpcP, RegMem( op1, op2) );
11910   ins_pipe( ialu_cr_reg_mem );
11911 %}
11912 
11913 // // Cisc-spilled version of cmpU_eReg
11914 //instruct compU_mem_eReg(eFlagsRegU cr, memory op1, rRegI op2) %{
11915 //  match(Set cr (CmpU (LoadI op1) op2));
11916 //
11917 //  format %{ "CMPu   $op1,$op2" %}
11918 //  ins_cost(500);
11919 //  opcode(0x39);  /* Opcode 39 /r */
11920 //  ins_encode( OpcP, RegMem( op1, op2) );
11921 //%}
11922 
11923 instruct testU_reg( eFlagsRegU cr, rRegI src, immI0 zero ) %{
11924   match(Set cr (CmpU src zero));
11925 
11926   format %{ "TESTu  $src,$src" %}
11927   opcode(0x85);
11928   ins_encode( OpcP, RegReg( src, src ) );
11929   ins_pipe( ialu_cr_reg_imm );
11930 %}
11931 
11932 // Unsigned pointer compare Instructions
11933 instruct compP_eReg(eFlagsRegU cr, eRegP op1, eRegP op2) %{
11934   match(Set cr (CmpP op1 op2));
11935 
11936   format %{ "CMPu   $op1,$op2" %}
11937   opcode(0x3B);  /* Opcode 3B /r */
11938   ins_encode( OpcP, RegReg( op1, op2) );
11939   ins_pipe( ialu_cr_reg_reg );
11940 %}
11941 
11942 instruct compP_eReg_imm(eFlagsRegU cr, eRegP op1, immP op2) %{
11943   match(Set cr (CmpP op1 op2));
11944 
11945   format %{ "CMPu   $op1,$op2" %}
11946   opcode(0x81,0x07);  /* Opcode 81 /7 */
11947   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
11948   ins_pipe( ialu_cr_reg_imm );
11949 %}
11950 
11951 // // Cisc-spilled version of cmpP_eReg
11952 instruct compP_eReg_mem(eFlagsRegU cr, eRegP op1, memory op2) %{
11953   match(Set cr (CmpP op1 (LoadP op2)));
11954 
11955   format %{ "CMPu   $op1,$op2" %}
11956   ins_cost(500);
11957   opcode(0x3B);  /* Opcode 3B /r */
11958   ins_encode( OpcP, RegMem( op1, op2) );
11959   ins_pipe( ialu_cr_reg_mem );
11960 %}
11961 
11962 // // Cisc-spilled version of cmpP_eReg
11963 //instruct compP_mem_eReg(eFlagsRegU cr, memory op1, eRegP op2) %{
11964 //  match(Set cr (CmpP (LoadP op1) op2));
11965 //
11966 //  format %{ "CMPu   $op1,$op2" %}
11967 //  ins_cost(500);
11968 //  opcode(0x39);  /* Opcode 39 /r */
11969 //  ins_encode( OpcP, RegMem( op1, op2) );
11970 //%}
11971 
11972 // Compare raw pointer (used in out-of-heap check).
11973 // Only works because non-oop pointers must be raw pointers
11974 // and raw pointers have no anti-dependencies.
11975 instruct compP_mem_eReg( eFlagsRegU cr, eRegP op1, memory op2 ) %{
11976   predicate( n->in(2)->in(2)->bottom_type()->reloc() == relocInfo::none );
11977   match(Set cr (CmpP op1 (LoadP op2)));
11978 
11979   format %{ "CMPu   $op1,$op2" %}
11980   opcode(0x3B);  /* Opcode 3B /r */
11981   ins_encode( OpcP, RegMem( op1, op2) );
11982   ins_pipe( ialu_cr_reg_mem );
11983 %}
11984 
11985 //
11986 // This will generate a signed flags result. This should be ok
11987 // since any compare to a zero should be eq/neq.
11988 instruct testP_reg( eFlagsReg cr, eRegP src, immP0 zero ) %{
11989   match(Set cr (CmpP src zero));
11990 
11991   format %{ "TEST   $src,$src" %}
11992   opcode(0x85);
11993   ins_encode( OpcP, RegReg( src, src ) );
11994   ins_pipe( ialu_cr_reg_imm );
11995 %}
11996 
11997 // Cisc-spilled version of testP_reg
11998 // This will generate a signed flags result. This should be ok
11999 // since any compare to a zero should be eq/neq.
12000 instruct testP_Reg_mem( eFlagsReg cr, memory op, immI0 zero ) %{
12001   match(Set cr (CmpP (LoadP op) zero));
12002 
12003   format %{ "TEST   $op,0xFFFFFFFF" %}
12004   ins_cost(500);
12005   opcode(0xF7);               /* Opcode F7 /0 */
12006   ins_encode( OpcP, RMopc_Mem(0x00,op), Con_d32(0xFFFFFFFF) );
12007   ins_pipe( ialu_cr_reg_imm );
12008 %}
12009 
12010 // Yanked all unsigned pointer compare operations.
12011 // Pointer compares are done with CmpP which is already unsigned.
12012 
12013 //----------Max and Min--------------------------------------------------------
12014 // Min Instructions
12015 ////
12016 //   *** Min and Max using the conditional move are slower than the
12017 //   *** branch version on a Pentium III.
12018 // // Conditional move for min
12019 //instruct cmovI_reg_lt( rRegI op2, rRegI op1, eFlagsReg cr ) %{
12020 //  effect( USE_DEF op2, USE op1, USE cr );
12021 //  format %{ "CMOVlt $op2,$op1\t! min" %}
12022 //  opcode(0x4C,0x0F);
12023 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
12024 //  ins_pipe( pipe_cmov_reg );
12025 //%}
12026 //
12027 //// Min Register with Register (P6 version)
12028 //instruct minI_eReg_p6( rRegI op1, rRegI op2 ) %{
12029 //  predicate(VM_Version::supports_cmov() );
12030 //  match(Set op2 (MinI op1 op2));
12031 //  ins_cost(200);
12032 //  expand %{
12033 //    eFlagsReg cr;
12034 //    compI_eReg(cr,op1,op2);
12035 //    cmovI_reg_lt(op2,op1,cr);
12036 //  %}
12037 //%}
12038 
12039 // Min Register with Register (generic version)
12040 instruct minI_eReg(rRegI dst, rRegI src, eFlagsReg flags) %{
12041   match(Set dst (MinI dst src));
12042   effect(KILL flags);
12043   ins_cost(300);
12044 
12045   format %{ "MIN    $dst,$src" %}
12046   opcode(0xCC);
12047   ins_encode( min_enc(dst,src) );
12048   ins_pipe( pipe_slow );
12049 %}
12050 
12051 // Max Register with Register
12052 //   *** Min and Max using the conditional move are slower than the
12053 //   *** branch version on a Pentium III.
12054 // // Conditional move for max
12055 //instruct cmovI_reg_gt( rRegI op2, rRegI op1, eFlagsReg cr ) %{
12056 //  effect( USE_DEF op2, USE op1, USE cr );
12057 //  format %{ "CMOVgt $op2,$op1\t! max" %}
12058 //  opcode(0x4F,0x0F);
12059 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
12060 //  ins_pipe( pipe_cmov_reg );
12061 //%}
12062 //
12063 // // Max Register with Register (P6 version)
12064 //instruct maxI_eReg_p6( rRegI op1, rRegI op2 ) %{
12065 //  predicate(VM_Version::supports_cmov() );
12066 //  match(Set op2 (MaxI op1 op2));
12067 //  ins_cost(200);
12068 //  expand %{
12069 //    eFlagsReg cr;
12070 //    compI_eReg(cr,op1,op2);
12071 //    cmovI_reg_gt(op2,op1,cr);
12072 //  %}
12073 //%}
12074 
12075 // Max Register with Register (generic version)
12076 instruct maxI_eReg(rRegI dst, rRegI src, eFlagsReg flags) %{
12077   match(Set dst (MaxI dst src));
12078   effect(KILL flags);
12079   ins_cost(300);
12080 
12081   format %{ "MAX    $dst,$src" %}
12082   opcode(0xCC);
12083   ins_encode( max_enc(dst,src) );
12084   ins_pipe( pipe_slow );
12085 %}
12086 
12087 // ============================================================================
12088 // Counted Loop limit node which represents exact final iterator value.
12089 // Note: the resulting value should fit into integer range since
12090 // counted loops have limit check on overflow.
12091 instruct loopLimit_eReg(eAXRegI limit, nadxRegI init, immI stride, eDXRegI limit_hi, nadxRegI tmp, eFlagsReg flags) %{
12092   match(Set limit (LoopLimit (Binary init limit) stride));
12093   effect(TEMP limit_hi, TEMP tmp, KILL flags);
12094   ins_cost(300);
12095 
12096   format %{ "loopLimit $init,$limit,$stride  # $limit = $init + $stride *( $limit - $init + $stride -1)/ $stride, kills $limit_hi" %}
12097   ins_encode %{
12098     int strd = (int)$stride$$constant;
12099     assert(strd != 1 && strd != -1, "sanity");
12100     int m1 = (strd > 0) ? 1 : -1;
12101     // Convert limit to long (EAX:EDX)
12102     __ cdql();
12103     // Convert init to long (init:tmp)
12104     __ movl($tmp$$Register, $init$$Register);
12105     __ sarl($tmp$$Register, 31);
12106     // $limit - $init
12107     __ subl($limit$$Register, $init$$Register);
12108     __ sbbl($limit_hi$$Register, $tmp$$Register);
12109     // + ($stride - 1)
12110     if (strd > 0) {
12111       __ addl($limit$$Register, (strd - 1));
12112       __ adcl($limit_hi$$Register, 0);
12113       __ movl($tmp$$Register, strd);
12114     } else {
12115       __ addl($limit$$Register, (strd + 1));
12116       __ adcl($limit_hi$$Register, -1);
12117       __ lneg($limit_hi$$Register, $limit$$Register);
12118       __ movl($tmp$$Register, -strd);
12119     }
12120     // signed devision: (EAX:EDX) / pos_stride
12121     __ idivl($tmp$$Register);
12122     if (strd < 0) {
12123       // restore sign
12124       __ negl($tmp$$Register);
12125     }
12126     // (EAX) * stride
12127     __ mull($tmp$$Register);
12128     // + init (ignore upper bits)
12129     __ addl($limit$$Register, $init$$Register);
12130   %}
12131   ins_pipe( pipe_slow );
12132 %}
12133 
12134 // ============================================================================
12135 // Branch Instructions
12136 // Jump Table
12137 instruct jumpXtnd(rRegI switch_val) %{
12138   match(Jump switch_val);
12139   ins_cost(350);
12140   format %{  "JMP    [$constantaddress](,$switch_val,1)\n\t" %}
12141   ins_encode %{
12142     // Jump to Address(table_base + switch_reg)
12143     Address index(noreg, $switch_val$$Register, Address::times_1);
12144     __ jump(ArrayAddress($constantaddress, index));
12145   %}
12146   ins_pipe(pipe_jmp);
12147 %}
12148 
12149 // Jump Direct - Label defines a relative address from JMP+1
12150 instruct jmpDir(label labl) %{
12151   match(Goto);
12152   effect(USE labl);
12153 
12154   ins_cost(300);
12155   format %{ "JMP    $labl" %}
12156   size(5);
12157   ins_encode %{
12158     Label* L = $labl$$label;
12159     __ jmp(*L, false); // Always long jump
12160   %}
12161   ins_pipe( pipe_jmp );
12162 %}
12163 
12164 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12165 instruct jmpCon(cmpOp cop, eFlagsReg cr, label labl) %{
12166   match(If cop cr);
12167   effect(USE labl);
12168 
12169   ins_cost(300);
12170   format %{ "J$cop    $labl" %}
12171   size(6);
12172   ins_encode %{
12173     Label* L = $labl$$label;
12174     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12175   %}
12176   ins_pipe( pipe_jcc );
12177 %}
12178 
12179 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12180 instruct jmpLoopEnd(cmpOp cop, eFlagsReg cr, label labl) %{
12181   match(CountedLoopEnd cop cr);
12182   effect(USE labl);
12183 
12184   ins_cost(300);
12185   format %{ "J$cop    $labl\t# Loop end" %}
12186   size(6);
12187   ins_encode %{
12188     Label* L = $labl$$label;
12189     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12190   %}
12191   ins_pipe( pipe_jcc );
12192 %}
12193 
12194 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12195 instruct jmpLoopEndU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
12196   match(CountedLoopEnd cop cmp);
12197   effect(USE labl);
12198 
12199   ins_cost(300);
12200   format %{ "J$cop,u  $labl\t# Loop end" %}
12201   size(6);
12202   ins_encode %{
12203     Label* L = $labl$$label;
12204     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12205   %}
12206   ins_pipe( pipe_jcc );
12207 %}
12208 
12209 instruct jmpLoopEndUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
12210   match(CountedLoopEnd cop cmp);
12211   effect(USE labl);
12212 
12213   ins_cost(200);
12214   format %{ "J$cop,u  $labl\t# Loop end" %}
12215   size(6);
12216   ins_encode %{
12217     Label* L = $labl$$label;
12218     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12219   %}
12220   ins_pipe( pipe_jcc );
12221 %}
12222 
12223 // Jump Direct Conditional - using unsigned comparison
12224 instruct jmpConU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
12225   match(If cop cmp);
12226   effect(USE labl);
12227 
12228   ins_cost(300);
12229   format %{ "J$cop,u  $labl" %}
12230   size(6);
12231   ins_encode %{
12232     Label* L = $labl$$label;
12233     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12234   %}
12235   ins_pipe(pipe_jcc);
12236 %}
12237 
12238 instruct jmpConUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
12239   match(If cop cmp);
12240   effect(USE labl);
12241 
12242   ins_cost(200);
12243   format %{ "J$cop,u  $labl" %}
12244   size(6);
12245   ins_encode %{
12246     Label* L = $labl$$label;
12247     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
12248   %}
12249   ins_pipe(pipe_jcc);
12250 %}
12251 
12252 instruct jmpConUCF2(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
12253   match(If cop cmp);
12254   effect(USE labl);
12255 
12256   ins_cost(200);
12257   format %{ $$template
12258     if ($cop$$cmpcode == Assembler::notEqual) {
12259       $$emit$$"JP,u   $labl\n\t"
12260       $$emit$$"J$cop,u   $labl"
12261     } else {
12262       $$emit$$"JP,u   done\n\t"
12263       $$emit$$"J$cop,u   $labl\n\t"
12264       $$emit$$"done:"
12265     }
12266   %}
12267   ins_encode %{
12268     Label* l = $labl$$label;
12269     if ($cop$$cmpcode == Assembler::notEqual) {
12270       __ jcc(Assembler::parity, *l, false);
12271       __ jcc(Assembler::notEqual, *l, false);
12272     } else if ($cop$$cmpcode == Assembler::equal) {
12273       Label done;
12274       __ jccb(Assembler::parity, done);
12275       __ jcc(Assembler::equal, *l, false);
12276       __ bind(done);
12277     } else {
12278        ShouldNotReachHere();
12279     }
12280   %}
12281   ins_pipe(pipe_jcc);
12282 %}
12283 
12284 // ============================================================================
12285 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary superklass
12286 // array for an instance of the superklass.  Set a hidden internal cache on a
12287 // hit (cache is checked with exposed code in gen_subtype_check()).  Return
12288 // NZ for a miss or zero for a hit.  The encoding ALSO sets flags.
12289 instruct partialSubtypeCheck( eDIRegP result, eSIRegP sub, eAXRegP super, eCXRegI rcx, eFlagsReg cr ) %{
12290   match(Set result (PartialSubtypeCheck sub super));
12291   effect( KILL rcx, KILL cr );
12292 
12293   ins_cost(1100);  // slightly larger than the next version
12294   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
12295             "MOV    ECX,[EDI+ArrayKlass::length]\t# length to scan\n\t"
12296             "ADD    EDI,ArrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
12297             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
12298             "JNE,s  miss\t\t# Missed: EDI not-zero\n\t"
12299             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache\n\t"
12300             "XOR    $result,$result\t\t Hit: EDI zero\n\t"
12301      "miss:\t" %}
12302 
12303   opcode(0x1); // Force a XOR of EDI
12304   ins_encode( enc_PartialSubtypeCheck() );
12305   ins_pipe( pipe_slow );
12306 %}
12307 
12308 instruct partialSubtypeCheck_vs_Zero( eFlagsReg cr, eSIRegP sub, eAXRegP super, eCXRegI rcx, eDIRegP result, immP0 zero ) %{
12309   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
12310   effect( KILL rcx, KILL result );
12311 
12312   ins_cost(1000);
12313   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
12314             "MOV    ECX,[EDI+ArrayKlass::length]\t# length to scan\n\t"
12315             "ADD    EDI,ArrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
12316             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
12317             "JNE,s  miss\t\t# Missed: flags NZ\n\t"
12318             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache, flags Z\n\t"
12319      "miss:\t" %}
12320 
12321   opcode(0x0);  // No need to XOR EDI
12322   ins_encode( enc_PartialSubtypeCheck() );
12323   ins_pipe( pipe_slow );
12324 %}
12325 
12326 // ============================================================================
12327 // Branch Instructions -- short offset versions
12328 //
12329 // These instructions are used to replace jumps of a long offset (the default
12330 // match) with jumps of a shorter offset.  These instructions are all tagged
12331 // with the ins_short_branch attribute, which causes the ADLC to suppress the
12332 // match rules in general matching.  Instead, the ADLC generates a conversion
12333 // method in the MachNode which can be used to do in-place replacement of the
12334 // long variant with the shorter variant.  The compiler will determine if a
12335 // branch can be taken by the is_short_branch_offset() predicate in the machine
12336 // specific code section of the file.
12337 
12338 // Jump Direct - Label defines a relative address from JMP+1
12339 instruct jmpDir_short(label labl) %{
12340   match(Goto);
12341   effect(USE labl);
12342 
12343   ins_cost(300);
12344   format %{ "JMP,s  $labl" %}
12345   size(2);
12346   ins_encode %{
12347     Label* L = $labl$$label;
12348     __ jmpb(*L);
12349   %}
12350   ins_pipe( pipe_jmp );
12351   ins_short_branch(1);
12352 %}
12353 
12354 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12355 instruct jmpCon_short(cmpOp cop, eFlagsReg cr, label labl) %{
12356   match(If cop cr);
12357   effect(USE labl);
12358 
12359   ins_cost(300);
12360   format %{ "J$cop,s  $labl" %}
12361   size(2);
12362   ins_encode %{
12363     Label* L = $labl$$label;
12364     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12365   %}
12366   ins_pipe( pipe_jcc );
12367   ins_short_branch(1);
12368 %}
12369 
12370 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12371 instruct jmpLoopEnd_short(cmpOp cop, eFlagsReg cr, label labl) %{
12372   match(CountedLoopEnd cop cr);
12373   effect(USE labl);
12374 
12375   ins_cost(300);
12376   format %{ "J$cop,s  $labl\t# Loop end" %}
12377   size(2);
12378   ins_encode %{
12379     Label* L = $labl$$label;
12380     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12381   %}
12382   ins_pipe( pipe_jcc );
12383   ins_short_branch(1);
12384 %}
12385 
12386 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12387 instruct jmpLoopEndU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
12388   match(CountedLoopEnd cop cmp);
12389   effect(USE labl);
12390 
12391   ins_cost(300);
12392   format %{ "J$cop,us $labl\t# Loop end" %}
12393   size(2);
12394   ins_encode %{
12395     Label* L = $labl$$label;
12396     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12397   %}
12398   ins_pipe( pipe_jcc );
12399   ins_short_branch(1);
12400 %}
12401 
12402 instruct jmpLoopEndUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
12403   match(CountedLoopEnd cop cmp);
12404   effect(USE labl);
12405 
12406   ins_cost(300);
12407   format %{ "J$cop,us $labl\t# Loop end" %}
12408   size(2);
12409   ins_encode %{
12410     Label* L = $labl$$label;
12411     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12412   %}
12413   ins_pipe( pipe_jcc );
12414   ins_short_branch(1);
12415 %}
12416 
12417 // Jump Direct Conditional - using unsigned comparison
12418 instruct jmpConU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
12419   match(If cop cmp);
12420   effect(USE labl);
12421 
12422   ins_cost(300);
12423   format %{ "J$cop,us $labl" %}
12424   size(2);
12425   ins_encode %{
12426     Label* L = $labl$$label;
12427     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12428   %}
12429   ins_pipe( pipe_jcc );
12430   ins_short_branch(1);
12431 %}
12432 
12433 instruct jmpConUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
12434   match(If cop cmp);
12435   effect(USE labl);
12436 
12437   ins_cost(300);
12438   format %{ "J$cop,us $labl" %}
12439   size(2);
12440   ins_encode %{
12441     Label* L = $labl$$label;
12442     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
12443   %}
12444   ins_pipe( pipe_jcc );
12445   ins_short_branch(1);
12446 %}
12447 
12448 instruct jmpConUCF2_short(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
12449   match(If cop cmp);
12450   effect(USE labl);
12451 
12452   ins_cost(300);
12453   format %{ $$template
12454     if ($cop$$cmpcode == Assembler::notEqual) {
12455       $$emit$$"JP,u,s   $labl\n\t"
12456       $$emit$$"J$cop,u,s   $labl"
12457     } else {
12458       $$emit$$"JP,u,s   done\n\t"
12459       $$emit$$"J$cop,u,s  $labl\n\t"
12460       $$emit$$"done:"
12461     }
12462   %}
12463   size(4);
12464   ins_encode %{
12465     Label* l = $labl$$label;
12466     if ($cop$$cmpcode == Assembler::notEqual) {
12467       __ jccb(Assembler::parity, *l);
12468       __ jccb(Assembler::notEqual, *l);
12469     } else if ($cop$$cmpcode == Assembler::equal) {
12470       Label done;
12471       __ jccb(Assembler::parity, done);
12472       __ jccb(Assembler::equal, *l);
12473       __ bind(done);
12474     } else {
12475        ShouldNotReachHere();
12476     }
12477   %}
12478   ins_pipe(pipe_jcc);
12479   ins_short_branch(1);
12480 %}
12481 
12482 // ============================================================================
12483 // Long Compare
12484 //
12485 // Currently we hold longs in 2 registers.  Comparing such values efficiently
12486 // is tricky.  The flavor of compare used depends on whether we are testing
12487 // for LT, LE, or EQ.  For a simple LT test we can check just the sign bit.
12488 // The GE test is the negated LT test.  The LE test can be had by commuting
12489 // the operands (yielding a GE test) and then negating; negate again for the
12490 // GT test.  The EQ test is done by ORcc'ing the high and low halves, and the
12491 // NE test is negated from that.
12492 
12493 // Due to a shortcoming in the ADLC, it mixes up expressions like:
12494 // (foo (CmpI (CmpL X Y) 0)) and (bar (CmpI (CmpL X 0L) 0)).  Note the
12495 // difference between 'Y' and '0L'.  The tree-matches for the CmpI sections
12496 // are collapsed internally in the ADLC's dfa-gen code.  The match for
12497 // (CmpI (CmpL X Y) 0) is silently replaced with (CmpI (CmpL X 0L) 0) and the
12498 // foo match ends up with the wrong leaf.  One fix is to not match both
12499 // reg-reg and reg-zero forms of long-compare.  This is unfortunate because
12500 // both forms beat the trinary form of long-compare and both are very useful
12501 // on Intel which has so few registers.
12502 
12503 // Manifest a CmpL result in an integer register.  Very painful.
12504 // This is the test to avoid.
12505 instruct cmpL3_reg_reg(eSIRegI dst, eRegL src1, eRegL src2, eFlagsReg flags ) %{
12506   match(Set dst (CmpL3 src1 src2));
12507   effect( KILL flags );
12508   ins_cost(1000);
12509   format %{ "XOR    $dst,$dst\n\t"
12510             "CMP    $src1.hi,$src2.hi\n\t"
12511             "JLT,s  m_one\n\t"
12512             "JGT,s  p_one\n\t"
12513             "CMP    $src1.lo,$src2.lo\n\t"
12514             "JB,s   m_one\n\t"
12515             "JEQ,s  done\n"
12516     "p_one:\tINC    $dst\n\t"
12517             "JMP,s  done\n"
12518     "m_one:\tDEC    $dst\n"
12519      "done:" %}
12520   ins_encode %{
12521     Label p_one, m_one, done;
12522     __ xorptr($dst$$Register, $dst$$Register);
12523     __ cmpl(HIGH_FROM_LOW($src1$$Register), HIGH_FROM_LOW($src2$$Register));
12524     __ jccb(Assembler::less,    m_one);
12525     __ jccb(Assembler::greater, p_one);
12526     __ cmpl($src1$$Register, $src2$$Register);
12527     __ jccb(Assembler::below,   m_one);
12528     __ jccb(Assembler::equal,   done);
12529     __ bind(p_one);
12530     __ incrementl($dst$$Register);
12531     __ jmpb(done);
12532     __ bind(m_one);
12533     __ decrementl($dst$$Register);
12534     __ bind(done);
12535   %}
12536   ins_pipe( pipe_slow );
12537 %}
12538 
12539 //======
12540 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
12541 // compares.  Can be used for LE or GT compares by reversing arguments.
12542 // NOT GOOD FOR EQ/NE tests.
12543 instruct cmpL_zero_flags_LTGE( flagsReg_long_LTGE flags, eRegL src, immL0 zero ) %{
12544   match( Set flags (CmpL src zero ));
12545   ins_cost(100);
12546   format %{ "TEST   $src.hi,$src.hi" %}
12547   opcode(0x85);
12548   ins_encode( OpcP, RegReg_Hi2( src, src ) );
12549   ins_pipe( ialu_cr_reg_reg );
12550 %}
12551 
12552 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
12553 // compares.  Can be used for LE or GT compares by reversing arguments.
12554 // NOT GOOD FOR EQ/NE tests.
12555 instruct cmpL_reg_flags_LTGE( flagsReg_long_LTGE flags, eRegL src1, eRegL src2, rRegI tmp ) %{
12556   match( Set flags (CmpL src1 src2 ));
12557   effect( TEMP tmp );
12558   ins_cost(300);
12559   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
12560             "MOV    $tmp,$src1.hi\n\t"
12561             "SBB    $tmp,$src2.hi\t! Compute flags for long compare" %}
12562   ins_encode( long_cmp_flags2( src1, src2, tmp ) );
12563   ins_pipe( ialu_cr_reg_reg );
12564 %}
12565 
12566 // Long compares reg < zero/req OR reg >= zero/req.
12567 // Just a wrapper for a normal branch, plus the predicate test.
12568 instruct cmpL_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, label labl) %{
12569   match(If cmp flags);
12570   effect(USE labl);
12571   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
12572   expand %{
12573     jmpCon(cmp,flags,labl);    // JLT or JGE...
12574   %}
12575 %}
12576 
12577 // Compare 2 longs and CMOVE longs.
12578 instruct cmovLL_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, eRegL src) %{
12579   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
12580   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge ));
12581   ins_cost(400);
12582   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12583             "CMOV$cmp $dst.hi,$src.hi" %}
12584   opcode(0x0F,0x40);
12585   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
12586   ins_pipe( pipe_cmov_reg_long );
12587 %}
12588 
12589 instruct cmovLL_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, load_long_memory src) %{
12590   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
12591   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge ));
12592   ins_cost(500);
12593   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12594             "CMOV$cmp $dst.hi,$src.hi" %}
12595   opcode(0x0F,0x40);
12596   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
12597   ins_pipe( pipe_cmov_reg_long );
12598 %}
12599 
12600 // Compare 2 longs and CMOVE ints.
12601 instruct cmovII_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, rRegI dst, rRegI src) %{
12602   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge ));
12603   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
12604   ins_cost(200);
12605   format %{ "CMOV$cmp $dst,$src" %}
12606   opcode(0x0F,0x40);
12607   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12608   ins_pipe( pipe_cmov_reg );
12609 %}
12610 
12611 instruct cmovII_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, rRegI dst, memory src) %{
12612   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge ));
12613   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
12614   ins_cost(250);
12615   format %{ "CMOV$cmp $dst,$src" %}
12616   opcode(0x0F,0x40);
12617   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
12618   ins_pipe( pipe_cmov_mem );
12619 %}
12620 
12621 // Compare 2 longs and CMOVE ints.
12622 instruct cmovPP_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegP dst, eRegP src) %{
12623   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge ));
12624   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
12625   ins_cost(200);
12626   format %{ "CMOV$cmp $dst,$src" %}
12627   opcode(0x0F,0x40);
12628   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12629   ins_pipe( pipe_cmov_reg );
12630 %}
12631 
12632 // Compare 2 longs and CMOVE doubles
12633 instruct cmovDDPR_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regDPR dst, regDPR src) %{
12634   predicate( UseSSE<=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
12635   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12636   ins_cost(200);
12637   expand %{
12638     fcmovDPR_regS(cmp,flags,dst,src);
12639   %}
12640 %}
12641 
12642 // Compare 2 longs and CMOVE doubles
12643 instruct cmovDD_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regD dst, regD src) %{
12644   predicate( UseSSE>=2 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
12645   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12646   ins_cost(200);
12647   expand %{
12648     fcmovD_regS(cmp,flags,dst,src);
12649   %}
12650 %}
12651 
12652 instruct cmovFFPR_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regFPR dst, regFPR src) %{
12653   predicate( UseSSE==0 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
12654   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12655   ins_cost(200);
12656   expand %{
12657     fcmovFPR_regS(cmp,flags,dst,src);
12658   %}
12659 %}
12660 
12661 instruct cmovFF_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regF dst, regF src) %{
12662   predicate( UseSSE>=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
12663   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12664   ins_cost(200);
12665   expand %{
12666     fcmovF_regS(cmp,flags,dst,src);
12667   %}
12668 %}
12669 
12670 //======
12671 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
12672 instruct cmpL_zero_flags_EQNE( flagsReg_long_EQNE flags, eRegL src, immL0 zero, rRegI tmp ) %{
12673   match( Set flags (CmpL src zero ));
12674   effect(TEMP tmp);
12675   ins_cost(200);
12676   format %{ "MOV    $tmp,$src.lo\n\t"
12677             "OR     $tmp,$src.hi\t! Long is EQ/NE 0?" %}
12678   ins_encode( long_cmp_flags0( src, tmp ) );
12679   ins_pipe( ialu_reg_reg_long );
12680 %}
12681 
12682 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
12683 instruct cmpL_reg_flags_EQNE( flagsReg_long_EQNE flags, eRegL src1, eRegL src2 ) %{
12684   match( Set flags (CmpL src1 src2 ));
12685   ins_cost(200+300);
12686   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
12687             "JNE,s  skip\n\t"
12688             "CMP    $src1.hi,$src2.hi\n\t"
12689      "skip:\t" %}
12690   ins_encode( long_cmp_flags1( src1, src2 ) );
12691   ins_pipe( ialu_cr_reg_reg );
12692 %}
12693 
12694 // Long compare reg == zero/reg OR reg != zero/reg
12695 // Just a wrapper for a normal branch, plus the predicate test.
12696 instruct cmpL_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, label labl) %{
12697   match(If cmp flags);
12698   effect(USE labl);
12699   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
12700   expand %{
12701     jmpCon(cmp,flags,labl);    // JEQ or JNE...
12702   %}
12703 %}
12704 
12705 // Compare 2 longs and CMOVE longs.
12706 instruct cmovLL_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, eRegL src) %{
12707   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
12708   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne ));
12709   ins_cost(400);
12710   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12711             "CMOV$cmp $dst.hi,$src.hi" %}
12712   opcode(0x0F,0x40);
12713   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
12714   ins_pipe( pipe_cmov_reg_long );
12715 %}
12716 
12717 instruct cmovLL_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, load_long_memory src) %{
12718   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
12719   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne ));
12720   ins_cost(500);
12721   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12722             "CMOV$cmp $dst.hi,$src.hi" %}
12723   opcode(0x0F,0x40);
12724   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
12725   ins_pipe( pipe_cmov_reg_long );
12726 %}
12727 
12728 // Compare 2 longs and CMOVE ints.
12729 instruct cmovII_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, rRegI dst, rRegI src) %{
12730   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne ));
12731   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
12732   ins_cost(200);
12733   format %{ "CMOV$cmp $dst,$src" %}
12734   opcode(0x0F,0x40);
12735   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12736   ins_pipe( pipe_cmov_reg );
12737 %}
12738 
12739 instruct cmovII_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, rRegI dst, memory src) %{
12740   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne ));
12741   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
12742   ins_cost(250);
12743   format %{ "CMOV$cmp $dst,$src" %}
12744   opcode(0x0F,0x40);
12745   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
12746   ins_pipe( pipe_cmov_mem );
12747 %}
12748 
12749 // Compare 2 longs and CMOVE ints.
12750 instruct cmovPP_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegP dst, eRegP src) %{
12751   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne ));
12752   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
12753   ins_cost(200);
12754   format %{ "CMOV$cmp $dst,$src" %}
12755   opcode(0x0F,0x40);
12756   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12757   ins_pipe( pipe_cmov_reg );
12758 %}
12759 
12760 // Compare 2 longs and CMOVE doubles
12761 instruct cmovDDPR_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regDPR dst, regDPR src) %{
12762   predicate( UseSSE<=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
12763   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12764   ins_cost(200);
12765   expand %{
12766     fcmovDPR_regS(cmp,flags,dst,src);
12767   %}
12768 %}
12769 
12770 // Compare 2 longs and CMOVE doubles
12771 instruct cmovDD_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regD dst, regD src) %{
12772   predicate( UseSSE>=2 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
12773   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12774   ins_cost(200);
12775   expand %{
12776     fcmovD_regS(cmp,flags,dst,src);
12777   %}
12778 %}
12779 
12780 instruct cmovFFPR_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regFPR dst, regFPR src) %{
12781   predicate( UseSSE==0 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
12782   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12783   ins_cost(200);
12784   expand %{
12785     fcmovFPR_regS(cmp,flags,dst,src);
12786   %}
12787 %}
12788 
12789 instruct cmovFF_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regF dst, regF src) %{
12790   predicate( UseSSE>=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
12791   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12792   ins_cost(200);
12793   expand %{
12794     fcmovF_regS(cmp,flags,dst,src);
12795   %}
12796 %}
12797 
12798 //======
12799 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
12800 // Same as cmpL_reg_flags_LEGT except must negate src
12801 instruct cmpL_zero_flags_LEGT( flagsReg_long_LEGT flags, eRegL src, immL0 zero, rRegI tmp ) %{
12802   match( Set flags (CmpL src zero ));
12803   effect( TEMP tmp );
12804   ins_cost(300);
12805   format %{ "XOR    $tmp,$tmp\t# Long compare for -$src < 0, use commuted test\n\t"
12806             "CMP    $tmp,$src.lo\n\t"
12807             "SBB    $tmp,$src.hi\n\t" %}
12808   ins_encode( long_cmp_flags3(src, tmp) );
12809   ins_pipe( ialu_reg_reg_long );
12810 %}
12811 
12812 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
12813 // Same as cmpL_reg_flags_LTGE except operands swapped.  Swapping operands
12814 // requires a commuted test to get the same result.
12815 instruct cmpL_reg_flags_LEGT( flagsReg_long_LEGT flags, eRegL src1, eRegL src2, rRegI tmp ) %{
12816   match( Set flags (CmpL src1 src2 ));
12817   effect( TEMP tmp );
12818   ins_cost(300);
12819   format %{ "CMP    $src2.lo,$src1.lo\t! Long compare, swapped operands, use with commuted test\n\t"
12820             "MOV    $tmp,$src2.hi\n\t"
12821             "SBB    $tmp,$src1.hi\t! Compute flags for long compare" %}
12822   ins_encode( long_cmp_flags2( src2, src1, tmp ) );
12823   ins_pipe( ialu_cr_reg_reg );
12824 %}
12825 
12826 // Long compares reg < zero/req OR reg >= zero/req.
12827 // Just a wrapper for a normal branch, plus the predicate test
12828 instruct cmpL_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, label labl) %{
12829   match(If cmp flags);
12830   effect(USE labl);
12831   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le );
12832   ins_cost(300);
12833   expand %{
12834     jmpCon(cmp,flags,labl);    // JGT or JLE...
12835   %}
12836 %}
12837 
12838 // Compare 2 longs and CMOVE longs.
12839 instruct cmovLL_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, eRegL src) %{
12840   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
12841   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt ));
12842   ins_cost(400);
12843   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12844             "CMOV$cmp $dst.hi,$src.hi" %}
12845   opcode(0x0F,0x40);
12846   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
12847   ins_pipe( pipe_cmov_reg_long );
12848 %}
12849 
12850 instruct cmovLL_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, load_long_memory src) %{
12851   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
12852   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt ));
12853   ins_cost(500);
12854   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
12855             "CMOV$cmp $dst.hi,$src.hi+4" %}
12856   opcode(0x0F,0x40);
12857   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
12858   ins_pipe( pipe_cmov_reg_long );
12859 %}
12860 
12861 // Compare 2 longs and CMOVE ints.
12862 instruct cmovII_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, rRegI dst, rRegI src) %{
12863   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt ));
12864   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
12865   ins_cost(200);
12866   format %{ "CMOV$cmp $dst,$src" %}
12867   opcode(0x0F,0x40);
12868   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12869   ins_pipe( pipe_cmov_reg );
12870 %}
12871 
12872 instruct cmovII_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, rRegI dst, memory src) %{
12873   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt ));
12874   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
12875   ins_cost(250);
12876   format %{ "CMOV$cmp $dst,$src" %}
12877   opcode(0x0F,0x40);
12878   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
12879   ins_pipe( pipe_cmov_mem );
12880 %}
12881 
12882 // Compare 2 longs and CMOVE ptrs.
12883 instruct cmovPP_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegP dst, eRegP src) %{
12884   predicate(VM_Version::supports_cmov() && ( _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt ));
12885   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
12886   ins_cost(200);
12887   format %{ "CMOV$cmp $dst,$src" %}
12888   opcode(0x0F,0x40);
12889   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
12890   ins_pipe( pipe_cmov_reg );
12891 %}
12892 
12893 // Compare 2 longs and CMOVE doubles
12894 instruct cmovDDPR_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regDPR dst, regDPR src) %{
12895   predicate( UseSSE<=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt );
12896   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12897   ins_cost(200);
12898   expand %{
12899     fcmovDPR_regS(cmp,flags,dst,src);
12900   %}
12901 %}
12902 
12903 // Compare 2 longs and CMOVE doubles
12904 instruct cmovDD_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regD dst, regD src) %{
12905   predicate( UseSSE>=2 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt );
12906   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
12907   ins_cost(200);
12908   expand %{
12909     fcmovD_regS(cmp,flags,dst,src);
12910   %}
12911 %}
12912 
12913 instruct cmovFFPR_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regFPR dst, regFPR src) %{
12914   predicate( UseSSE==0 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt );
12915   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12916   ins_cost(200);
12917   expand %{
12918     fcmovFPR_regS(cmp,flags,dst,src);
12919   %}
12920 %}
12921 
12922 
12923 instruct cmovFF_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regF dst, regF src) %{
12924   predicate( UseSSE>=1 && _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le || _kids[0]->_kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt );
12925   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
12926   ins_cost(200);
12927   expand %{
12928     fcmovF_regS(cmp,flags,dst,src);
12929   %}
12930 %}
12931 
12932 
12933 // ============================================================================
12934 // Procedure Call/Return Instructions
12935 // Call Java Static Instruction
12936 // Note: If this code changes, the corresponding ret_addr_offset() and
12937 //       compute_padding() functions will have to be adjusted.
12938 instruct CallStaticJavaDirect(method meth) %{
12939   match(CallStaticJava);
12940   predicate(! ((CallStaticJavaNode*)n)->is_method_handle_invoke());
12941   effect(USE meth);
12942 
12943   ins_cost(300);
12944   format %{ "CALL,static " %}
12945   opcode(0xE8); /* E8 cd */
12946   ins_encode( pre_call_resets,
12947               Java_Static_Call( meth ),
12948               call_epilog,
12949               post_call_FPU );
12950   ins_pipe( pipe_slow );
12951   ins_alignment(4);
12952 %}
12953 
12954 // Call Java Static Instruction (method handle version)
12955 // Note: If this code changes, the corresponding ret_addr_offset() and
12956 //       compute_padding() functions will have to be adjusted.
12957 instruct CallStaticJavaHandle(method meth, eBPRegP ebp_mh_SP_save) %{
12958   match(CallStaticJava);
12959   predicate(((CallStaticJavaNode*)n)->is_method_handle_invoke());
12960   effect(USE meth);
12961   // EBP is saved by all callees (for interpreter stack correction).
12962   // We use it here for a similar purpose, in {preserve,restore}_SP.
12963 
12964   ins_cost(300);
12965   format %{ "CALL,static/MethodHandle " %}
12966   opcode(0xE8); /* E8 cd */
12967   ins_encode( pre_call_resets,
12968               preserve_SP,
12969               Java_Static_Call( meth ),
12970               restore_SP,
12971               call_epilog,
12972               post_call_FPU );
12973   ins_pipe( pipe_slow );
12974   ins_alignment(4);
12975 %}
12976 
12977 // Call Java Dynamic Instruction
12978 // Note: If this code changes, the corresponding ret_addr_offset() and
12979 //       compute_padding() functions will have to be adjusted.
12980 instruct CallDynamicJavaDirect(method meth) %{
12981   match(CallDynamicJava);
12982   effect(USE meth);
12983 
12984   ins_cost(300);
12985   format %{ "MOV    EAX,(oop)-1\n\t"
12986             "CALL,dynamic" %}
12987   opcode(0xE8); /* E8 cd */
12988   ins_encode( pre_call_resets,
12989               Java_Dynamic_Call( meth ),
12990               call_epilog,
12991               post_call_FPU );
12992   ins_pipe( pipe_slow );
12993   ins_alignment(4);
12994 %}
12995 
12996 // Call Runtime Instruction
12997 instruct CallRuntimeDirect(method meth) %{
12998   match(CallRuntime );
12999   effect(USE meth);
13000 
13001   ins_cost(300);
13002   format %{ "CALL,runtime " %}
13003   opcode(0xE8); /* E8 cd */
13004   // Use FFREEs to clear entries in float stack
13005   ins_encode( pre_call_resets,
13006               FFree_Float_Stack_All,
13007               Java_To_Runtime( meth ),
13008               post_call_FPU );
13009   ins_pipe( pipe_slow );
13010 %}
13011 
13012 // Call runtime without safepoint
13013 instruct CallLeafDirect(method meth) %{
13014   match(CallLeaf);
13015   effect(USE meth);
13016 
13017   ins_cost(300);
13018   format %{ "CALL_LEAF,runtime " %}
13019   opcode(0xE8); /* E8 cd */
13020   ins_encode( pre_call_resets,
13021               FFree_Float_Stack_All,
13022               Java_To_Runtime( meth ),
13023               Verify_FPU_For_Leaf, post_call_FPU );
13024   ins_pipe( pipe_slow );
13025 %}
13026 
13027 instruct CallLeafNoFPDirect(method meth) %{
13028   match(CallLeafNoFP);
13029   effect(USE meth);
13030 
13031   ins_cost(300);
13032   format %{ "CALL_LEAF_NOFP,runtime " %}
13033   opcode(0xE8); /* E8 cd */
13034   ins_encode(Java_To_Runtime(meth));
13035   ins_pipe( pipe_slow );
13036 %}
13037 
13038 
13039 // Return Instruction
13040 // Remove the return address & jump to it.
13041 instruct Ret() %{
13042   match(Return);
13043   format %{ "RET" %}
13044   opcode(0xC3);
13045   ins_encode(OpcP);
13046   ins_pipe( pipe_jmp );
13047 %}
13048 
13049 // Tail Call; Jump from runtime stub to Java code.
13050 // Also known as an 'interprocedural jump'.
13051 // Target of jump will eventually return to caller.
13052 // TailJump below removes the return address.
13053 instruct TailCalljmpInd(eRegP_no_EBP jump_target, eBXRegP method_oop) %{
13054   match(TailCall jump_target method_oop );
13055   ins_cost(300);
13056   format %{ "JMP    $jump_target \t# EBX holds method oop" %}
13057   opcode(0xFF, 0x4);  /* Opcode FF /4 */
13058   ins_encode( OpcP, RegOpc(jump_target) );
13059   ins_pipe( pipe_jmp );
13060 %}
13061 
13062 
13063 // Tail Jump; remove the return address; jump to target.
13064 // TailCall above leaves the return address around.
13065 instruct tailjmpInd(eRegP_no_EBP jump_target, eAXRegP ex_oop) %{
13066   match( TailJump jump_target ex_oop );
13067   ins_cost(300);
13068   format %{ "POP    EDX\t# pop return address into dummy\n\t"
13069             "JMP    $jump_target " %}
13070   opcode(0xFF, 0x4);  /* Opcode FF /4 */
13071   ins_encode( enc_pop_rdx,
13072               OpcP, RegOpc(jump_target) );
13073   ins_pipe( pipe_jmp );
13074 %}
13075 
13076 // Create exception oop: created by stack-crawling runtime code.
13077 // Created exception is now available to this handler, and is setup
13078 // just prior to jumping to this handler.  No code emitted.
13079 instruct CreateException( eAXRegP ex_oop )
13080 %{
13081   match(Set ex_oop (CreateEx));
13082 
13083   size(0);
13084   // use the following format syntax
13085   format %{ "# exception oop is in EAX; no code emitted" %}
13086   ins_encode();
13087   ins_pipe( empty );
13088 %}
13089 
13090 
13091 // Rethrow exception:
13092 // The exception oop will come in the first argument position.
13093 // Then JUMP (not call) to the rethrow stub code.
13094 instruct RethrowException()
13095 %{
13096   match(Rethrow);
13097 
13098   // use the following format syntax
13099   format %{ "JMP    rethrow_stub" %}
13100   ins_encode(enc_rethrow);
13101   ins_pipe( pipe_jmp );
13102 %}
13103 
13104 // inlined locking and unlocking
13105 
13106 
13107 instruct cmpFastLock( eFlagsReg cr, eRegP object, eBXRegP box, eAXRegI tmp, eRegP scr) %{
13108   match( Set cr (FastLock object box) );
13109   effect( TEMP tmp, TEMP scr, USE_KILL box );
13110   ins_cost(300);
13111   format %{ "FASTLOCK $object,$box\t! kills $box,$tmp,$scr" %}
13112   ins_encode( Fast_Lock(object,box,tmp,scr) );
13113   ins_pipe( pipe_slow );
13114 %}
13115 
13116 instruct cmpFastUnlock( eFlagsReg cr, eRegP object, eAXRegP box, eRegP tmp ) %{
13117   match( Set cr (FastUnlock object box) );
13118   effect( TEMP tmp, USE_KILL box );
13119   ins_cost(300);
13120   format %{ "FASTUNLOCK $object,$box\t! kills $box,$tmp" %}
13121   ins_encode( Fast_Unlock(object,box,tmp) );
13122   ins_pipe( pipe_slow );
13123 %}
13124 
13125 
13126 
13127 // ============================================================================
13128 // Safepoint Instruction
13129 instruct safePoint_poll(eFlagsReg cr) %{
13130   match(SafePoint);
13131   effect(KILL cr);
13132 
13133   // TODO-FIXME: we currently poll at offset 0 of the safepoint polling page.
13134   // On SPARC that might be acceptable as we can generate the address with
13135   // just a sethi, saving an or.  By polling at offset 0 we can end up
13136   // putting additional pressure on the index-0 in the D$.  Because of
13137   // alignment (just like the situation at hand) the lower indices tend
13138   // to see more traffic.  It'd be better to change the polling address
13139   // to offset 0 of the last $line in the polling page.
13140 
13141   format %{ "TSTL   #polladdr,EAX\t! Safepoint: poll for GC" %}
13142   ins_cost(125);
13143   size(6) ;
13144   ins_encode( Safepoint_Poll() );
13145   ins_pipe( ialu_reg_mem );
13146 %}
13147 
13148 
13149 // ============================================================================
13150 // This name is KNOWN by the ADLC and cannot be changed.
13151 // The ADLC forces a 'TypeRawPtr::BOTTOM' output type
13152 // for this guy.
13153 instruct tlsLoadP(eRegP dst, eFlagsReg cr) %{
13154   match(Set dst (ThreadLocal));
13155   effect(DEF dst, KILL cr);
13156 
13157   format %{ "MOV    $dst, Thread::current()" %}
13158   ins_encode %{
13159     Register dstReg = as_Register($dst$$reg);
13160     __ get_thread(dstReg);
13161   %}
13162   ins_pipe( ialu_reg_fat );
13163 %}
13164 
13165 
13166 
13167 //----------PEEPHOLE RULES-----------------------------------------------------
13168 // These must follow all instruction definitions as they use the names
13169 // defined in the instructions definitions.
13170 //
13171 // peepmatch ( root_instr_name [preceding_instruction]* );
13172 //
13173 // peepconstraint %{
13174 // (instruction_number.operand_name relational_op instruction_number.operand_name
13175 //  [, ...] );
13176 // // instruction numbers are zero-based using left to right order in peepmatch
13177 //
13178 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
13179 // // provide an instruction_number.operand_name for each operand that appears
13180 // // in the replacement instruction's match rule
13181 //
13182 // ---------VM FLAGS---------------------------------------------------------
13183 //
13184 // All peephole optimizations can be turned off using -XX:-OptoPeephole
13185 //
13186 // Each peephole rule is given an identifying number starting with zero and
13187 // increasing by one in the order seen by the parser.  An individual peephole
13188 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
13189 // on the command-line.
13190 //
13191 // ---------CURRENT LIMITATIONS----------------------------------------------
13192 //
13193 // Only match adjacent instructions in same basic block
13194 // Only equality constraints
13195 // Only constraints between operands, not (0.dest_reg == EAX_enc)
13196 // Only one replacement instruction
13197 //
13198 // ---------EXAMPLE----------------------------------------------------------
13199 //
13200 // // pertinent parts of existing instructions in architecture description
13201 // instruct movI(rRegI dst, rRegI src) %{
13202 //   match(Set dst (CopyI src));
13203 // %}
13204 //
13205 // instruct incI_eReg(rRegI dst, immI1 src, eFlagsReg cr) %{
13206 //   match(Set dst (AddI dst src));
13207 //   effect(KILL cr);
13208 // %}
13209 //
13210 // // Change (inc mov) to lea
13211 // peephole %{
13212 //   // increment preceeded by register-register move
13213 //   peepmatch ( incI_eReg movI );
13214 //   // require that the destination register of the increment
13215 //   // match the destination register of the move
13216 //   peepconstraint ( 0.dst == 1.dst );
13217 //   // construct a replacement instruction that sets
13218 //   // the destination to ( move's source register + one )
13219 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
13220 // %}
13221 //
13222 // Implementation no longer uses movX instructions since
13223 // machine-independent system no longer uses CopyX nodes.
13224 //
13225 // peephole %{
13226 //   peepmatch ( incI_eReg movI );
13227 //   peepconstraint ( 0.dst == 1.dst );
13228 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
13229 // %}
13230 //
13231 // peephole %{
13232 //   peepmatch ( decI_eReg movI );
13233 //   peepconstraint ( 0.dst == 1.dst );
13234 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
13235 // %}
13236 //
13237 // peephole %{
13238 //   peepmatch ( addI_eReg_imm movI );
13239 //   peepconstraint ( 0.dst == 1.dst );
13240 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
13241 // %}
13242 //
13243 // peephole %{
13244 //   peepmatch ( addP_eReg_imm movP );
13245 //   peepconstraint ( 0.dst == 1.dst );
13246 //   peepreplace ( leaP_eReg_immI( 0.dst 1.src 0.src ) );
13247 // %}
13248 
13249 // // Change load of spilled value to only a spill
13250 // instruct storeI(memory mem, rRegI src) %{
13251 //   match(Set mem (StoreI mem src));
13252 // %}
13253 //
13254 // instruct loadI(rRegI dst, memory mem) %{
13255 //   match(Set dst (LoadI mem));
13256 // %}
13257 //
13258 peephole %{
13259   peepmatch ( loadI storeI );
13260   peepconstraint ( 1.src == 0.dst, 1.mem == 0.mem );
13261   peepreplace ( storeI( 1.mem 1.mem 1.src ) );
13262 %}
13263 
13264 //----------SMARTSPILL RULES---------------------------------------------------
13265 // These must follow all instruction definitions as they use the names
13266 // defined in the instructions definitions.