src/cpu/x86/vm/x86_32.ad

Fri, 12 Apr 2013 19:14:47 -0700

author
drchase
date
Fri, 12 Apr 2013 19:14:47 -0700
changeset 4944
886d1fd67dc3
parent 4873
e961c11b85fe
child 5001
e10e43e58e92
permissions
-rw-r--r--

6443505: Ideal() function for CmpLTMask
Summary: Repair wrong code generation, added new matching rule
Reviewed-by: kvn, twisti

     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 //
    25 // X86 Architecture Description File
    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.
    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.
    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.
    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());
    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());
   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 );
   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 );
   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 );
   176 reg_class fp_dbl_reg( FPR1L,FPR1H, FPR2L,FPR2H, FPR3L,FPR3H,
   177                       FPR4L,FPR4H, FPR5L,FPR5H, FPR6L,FPR6H,
   178                       FPR7L,FPR7H );
   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 );
   186 %}
   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 %}
   197 source %{
   198 #define   RELOC_IMM32    Assembler::imm_operand
   199 #define   RELOC_DISP32   Assembler::disp32_operand
   201 #define __ _masm.
   203 // How to find the high register of a Long pair, given the low register
   204 #define   HIGH_FROM_LOW(x) ((x)+2)
   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.
   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 }
   221 // Buffer for 128-bits masks used by SSE instructions.
   222 static jlong fp_signmask_pool[(4+1)*2]; // 4*128bits(data) + 128bits(alignment)
   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));
   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 }
   243 static int preserve_SP_size() {
   244   return 2;  // op, rm(reg/reg)
   245 }
   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 }
   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 }
   261 static int sizeof_FFree_Float_Stack_All = -1;
   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 }
   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 }
   274 //
   275 // Compute padding required for nodes which need alignment
   276 //
   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 }
   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 }
   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 }
   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 }
   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 }
   316 // EMIT_OPCODE()
   317 void emit_opcode(CodeBuffer &cbuf, int code) {
   318   cbuf.insts()->emit_int8((unsigned char) code);
   319 }
   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 }
   327 // EMIT_D8()
   328 void emit_d8(CodeBuffer &cbuf, int d8) {
   329   cbuf.insts()->emit_int8((unsigned char) d8);
   330 }
   332 // EMIT_D16()
   333 void emit_d16(CodeBuffer &cbuf, int d16) {
   334   cbuf.insts()->emit_int16(d16);
   335 }
   337 // EMIT_D32()
   338 void emit_d32(CodeBuffer &cbuf, int d32) {
   339   cbuf.insts()->emit_int32(d32);
   340 }
   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 }
   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(oop(d32)->is_oop() && (ScavengeRootsInCode || !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 }
   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 }
   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 }
   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 }
   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 }
   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 }
   483 //=============================================================================
   484 const RegMask& MachConstantBaseNode::_out_RegMask = RegMask::Empty;
   486 int Compile::ConstantTable::calculate_table_base_offset() const {
   487   return 0;  // absolute addressing, no offset
   488 }
   490 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
   491   // Empty encoding
   492 }
   494 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
   495   return 0;
   496 }
   498 #ifndef PRODUCT
   499 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
   500   st->print("# MachConstantBaseNode (empty encoding)");
   501 }
   502 #endif
   505 //=============================================================================
   506 #ifndef PRODUCT
   507 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
   508   Compile* C = ra_->C;
   510   int framesize = C->frame_slots() << LogBytesPerInt;
   511   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   512   // Remove wordSize for return addr which is already pushed.
   513   framesize -= wordSize;
   515   if (C->need_stack_bang(framesize)) {
   516     framesize -= wordSize;
   517     st->print("# stack bang");
   518     st->print("\n\t");
   519     st->print("PUSH   EBP\t# Save EBP");
   520     if (framesize) {
   521       st->print("\n\t");
   522       st->print("SUB    ESP, #%d\t# Create frame",framesize);
   523     }
   524   } else {
   525     st->print("SUB    ESP, #%d\t# Create frame",framesize);
   526     st->print("\n\t");
   527     framesize -= wordSize;
   528     st->print("MOV    [ESP + #%d], EBP\t# Save EBP",framesize);
   529   }
   531   if (VerifyStackAtCalls) {
   532     st->print("\n\t");
   533     framesize -= wordSize;
   534     st->print("MOV    [ESP + #%d], 0xBADB100D\t# Majik cookie for stack depth check",framesize);
   535   }
   537   if( C->in_24_bit_fp_mode() ) {
   538     st->print("\n\t");
   539     st->print("FLDCW  \t# load 24 bit fpu control word");
   540   }
   541   if (UseSSE >= 2 && VerifyFPU) {
   542     st->print("\n\t");
   543     st->print("# verify FPU stack (must be clean on entry)");
   544   }
   546 #ifdef ASSERT
   547   if (VerifyStackAtCalls) {
   548     st->print("\n\t");
   549     st->print("# stack alignment check");
   550   }
   551 #endif
   552   st->cr();
   553 }
   554 #endif
   557 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
   558   Compile* C = ra_->C;
   559   MacroAssembler _masm(&cbuf);
   561   int framesize = C->frame_slots() << LogBytesPerInt;
   563   __ verified_entry(framesize, C->need_stack_bang(framesize), C->in_24_bit_fp_mode());
   565   C->set_frame_complete(cbuf.insts_size());
   567   if (C->has_mach_constant_base_node()) {
   568     // NOTE: We set the table base offset here because users might be
   569     // emitted before MachConstantBaseNode.
   570     Compile::ConstantTable& constant_table = C->constant_table();
   571     constant_table.set_table_base_offset(constant_table.calculate_table_base_offset());
   572   }
   573 }
   575 uint MachPrologNode::size(PhaseRegAlloc *ra_) const {
   576   return MachNode::size(ra_); // too many variables; just compute it the hard way
   577 }
   579 int MachPrologNode::reloc() const {
   580   return 0; // a large enough number
   581 }
   583 //=============================================================================
   584 #ifndef PRODUCT
   585 void MachEpilogNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
   586   Compile *C = ra_->C;
   587   int framesize = C->frame_slots() << LogBytesPerInt;
   588   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   589   // Remove two words for return addr and rbp,
   590   framesize -= 2*wordSize;
   592   if (C->max_vector_size() > 16) {
   593     st->print("VZEROUPPER");
   594     st->cr(); st->print("\t");
   595   }
   596   if (C->in_24_bit_fp_mode()) {
   597     st->print("FLDCW  standard control word");
   598     st->cr(); st->print("\t");
   599   }
   600   if (framesize) {
   601     st->print("ADD    ESP,%d\t# Destroy frame",framesize);
   602     st->cr(); st->print("\t");
   603   }
   604   st->print_cr("POPL   EBP"); st->print("\t");
   605   if (do_polling() && C->is_method_compilation()) {
   606     st->print("TEST   PollPage,EAX\t! Poll Safepoint");
   607     st->cr(); st->print("\t");
   608   }
   609 }
   610 #endif
   612 void MachEpilogNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
   613   Compile *C = ra_->C;
   615   if (C->max_vector_size() > 16) {
   616     // Clear upper bits of YMM registers when current compiled code uses
   617     // wide vectors to avoid AVX <-> SSE transition penalty during call.
   618     MacroAssembler masm(&cbuf);
   619     masm.vzeroupper();
   620   }
   621   // If method set FPU control word, restore to standard control word
   622   if (C->in_24_bit_fp_mode()) {
   623     MacroAssembler masm(&cbuf);
   624     masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
   625   }
   627   int framesize = C->frame_slots() << LogBytesPerInt;
   628   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   629   // Remove two words for return addr and rbp,
   630   framesize -= 2*wordSize;
   632   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
   634   if (framesize >= 128) {
   635     emit_opcode(cbuf, 0x81); // add  SP, #framesize
   636     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
   637     emit_d32(cbuf, framesize);
   638   } else if (framesize) {
   639     emit_opcode(cbuf, 0x83); // add  SP, #framesize
   640     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
   641     emit_d8(cbuf, framesize);
   642   }
   644   emit_opcode(cbuf, 0x58 | EBP_enc);
   646   if (do_polling() && C->is_method_compilation()) {
   647     cbuf.relocate(cbuf.insts_end(), relocInfo::poll_return_type, 0);
   648     emit_opcode(cbuf,0x85);
   649     emit_rm(cbuf, 0x0, EAX_enc, 0x5); // EAX
   650     emit_d32(cbuf, (intptr_t)os::get_polling_page());
   651   }
   652 }
   654 uint MachEpilogNode::size(PhaseRegAlloc *ra_) const {
   655   Compile *C = ra_->C;
   656   // If method set FPU control word, restore to standard control word
   657   int size = C->in_24_bit_fp_mode() ? 6 : 0;
   658   if (C->max_vector_size() > 16) size += 3; // vzeroupper
   659   if (do_polling() && C->is_method_compilation()) size += 6;
   661   int framesize = C->frame_slots() << LogBytesPerInt;
   662   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   663   // Remove two words for return addr and rbp,
   664   framesize -= 2*wordSize;
   666   size++; // popl rbp,
   668   if (framesize >= 128) {
   669     size += 6;
   670   } else {
   671     size += framesize ? 3 : 0;
   672   }
   673   return size;
   674 }
   676 int MachEpilogNode::reloc() const {
   677   return 0; // a large enough number
   678 }
   680 const Pipeline * MachEpilogNode::pipeline() const {
   681   return MachNode::pipeline_class();
   682 }
   684 int MachEpilogNode::safepoint_offset() const { return 0; }
   686 //=============================================================================
   688 enum RC { rc_bad, rc_int, rc_float, rc_xmm, rc_stack };
   689 static enum RC rc_class( OptoReg::Name reg ) {
   691   if( !OptoReg::is_valid(reg)  ) return rc_bad;
   692   if (OptoReg::is_stack(reg)) return rc_stack;
   694   VMReg r = OptoReg::as_VMReg(reg);
   695   if (r->is_Register()) return rc_int;
   696   if (r->is_FloatRegister()) {
   697     assert(UseSSE < 2, "shouldn't be used in SSE2+ mode");
   698     return rc_float;
   699   }
   700   assert(r->is_XMMRegister(), "must be");
   701   return rc_xmm;
   702 }
   704 static int impl_helper( CodeBuffer *cbuf, bool do_size, bool is_load, int offset, int reg,
   705                         int opcode, const char *op_str, int size, outputStream* st ) {
   706   if( cbuf ) {
   707     emit_opcode  (*cbuf, opcode );
   708     encode_RegMem(*cbuf, Matcher::_regEncode[reg], ESP_enc, 0x4, 0, offset, relocInfo::none);
   709 #ifndef PRODUCT
   710   } else if( !do_size ) {
   711     if( size != 0 ) st->print("\n\t");
   712     if( opcode == 0x8B || opcode == 0x89 ) { // MOV
   713       if( is_load ) st->print("%s   %s,[ESP + #%d]",op_str,Matcher::regName[reg],offset);
   714       else          st->print("%s   [ESP + #%d],%s",op_str,offset,Matcher::regName[reg]);
   715     } else { // FLD, FST, PUSH, POP
   716       st->print("%s [ESP + #%d]",op_str,offset);
   717     }
   718 #endif
   719   }
   720   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
   721   return size+3+offset_size;
   722 }
   724 // Helper for XMM registers.  Extra opcode bits, limited syntax.
   725 static int impl_x_helper( CodeBuffer *cbuf, bool do_size, bool is_load,
   726                          int offset, int reg_lo, int reg_hi, int size, outputStream* st ) {
   727   if (cbuf) {
   728     MacroAssembler _masm(cbuf);
   729     if (reg_lo+1 == reg_hi) { // double move?
   730       if (is_load) {
   731         __ movdbl(as_XMMRegister(Matcher::_regEncode[reg_lo]), Address(rsp, offset));
   732       } else {
   733         __ movdbl(Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[reg_lo]));
   734       }
   735     } else {
   736       if (is_load) {
   737         __ movflt(as_XMMRegister(Matcher::_regEncode[reg_lo]), Address(rsp, offset));
   738       } else {
   739         __ movflt(Address(rsp, offset), as_XMMRegister(Matcher::_regEncode[reg_lo]));
   740       }
   741     }
   742 #ifndef PRODUCT
   743   } else if (!do_size) {
   744     if (size != 0) st->print("\n\t");
   745     if (reg_lo+1 == reg_hi) { // double move?
   746       if (is_load) st->print("%s %s,[ESP + #%d]",
   747                               UseXmmLoadAndClearUpper ? "MOVSD " : "MOVLPD",
   748                               Matcher::regName[reg_lo], offset);
   749       else         st->print("MOVSD  [ESP + #%d],%s",
   750                               offset, Matcher::regName[reg_lo]);
   751     } else {
   752       if (is_load) st->print("MOVSS  %s,[ESP + #%d]",
   753                               Matcher::regName[reg_lo], offset);
   754       else         st->print("MOVSS  [ESP + #%d],%s",
   755                               offset, Matcher::regName[reg_lo]);
   756     }
   757 #endif
   758   }
   759   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
   760   // VEX_2bytes prefix is used if UseAVX > 0, so it takes the same 2 bytes as SIMD prefix.
   761   return size+5+offset_size;
   762 }
   765 static int impl_movx_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   766                             int src_hi, int dst_hi, int size, outputStream* st ) {
   767   if (cbuf) {
   768     MacroAssembler _masm(cbuf);
   769     if (src_lo+1 == src_hi && dst_lo+1 == dst_hi) { // double move?
   770       __ movdbl(as_XMMRegister(Matcher::_regEncode[dst_lo]),
   771                 as_XMMRegister(Matcher::_regEncode[src_lo]));
   772     } else {
   773       __ movflt(as_XMMRegister(Matcher::_regEncode[dst_lo]),
   774                 as_XMMRegister(Matcher::_regEncode[src_lo]));
   775     }
   776 #ifndef PRODUCT
   777   } else if (!do_size) {
   778     if (size != 0) st->print("\n\t");
   779     if (UseXmmRegToRegMoveAll) {//Use movaps,movapd to move between xmm registers
   780       if (src_lo+1 == src_hi && dst_lo+1 == dst_hi) { // double move?
   781         st->print("MOVAPD %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   782       } else {
   783         st->print("MOVAPS %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   784       }
   785     } else {
   786       if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double move?
   787         st->print("MOVSD  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   788       } else {
   789         st->print("MOVSS  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   790       }
   791     }
   792 #endif
   793   }
   794   // VEX_2bytes prefix is used if UseAVX > 0, and it takes the same 2 bytes as SIMD prefix.
   795   // Only MOVAPS SSE prefix uses 1 byte.
   796   int sz = 4;
   797   if (!(src_lo+1 == src_hi && dst_lo+1 == dst_hi) &&
   798       UseXmmRegToRegMoveAll && (UseAVX == 0)) sz = 3;
   799   return size + sz;
   800 }
   802 static int impl_movgpr2x_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   803                             int src_hi, int dst_hi, int size, outputStream* st ) {
   804   // 32-bit
   805   if (cbuf) {
   806     MacroAssembler _masm(cbuf);
   807     __ movdl(as_XMMRegister(Matcher::_regEncode[dst_lo]),
   808              as_Register(Matcher::_regEncode[src_lo]));
   809 #ifndef PRODUCT
   810   } else if (!do_size) {
   811     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
   812 #endif
   813   }
   814   return 4;
   815 }
   818 static int impl_movx2gpr_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   819                                  int src_hi, int dst_hi, int size, outputStream* st ) {
   820   // 32-bit
   821   if (cbuf) {
   822     MacroAssembler _masm(cbuf);
   823     __ movdl(as_Register(Matcher::_regEncode[dst_lo]),
   824              as_XMMRegister(Matcher::_regEncode[src_lo]));
   825 #ifndef PRODUCT
   826   } else if (!do_size) {
   827     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
   828 #endif
   829   }
   830   return 4;
   831 }
   833 static int impl_mov_helper( CodeBuffer *cbuf, bool do_size, int src, int dst, int size, outputStream* st ) {
   834   if( cbuf ) {
   835     emit_opcode(*cbuf, 0x8B );
   836     emit_rm    (*cbuf, 0x3, Matcher::_regEncode[dst], Matcher::_regEncode[src] );
   837 #ifndef PRODUCT
   838   } else if( !do_size ) {
   839     if( size != 0 ) st->print("\n\t");
   840     st->print("MOV    %s,%s",Matcher::regName[dst],Matcher::regName[src]);
   841 #endif
   842   }
   843   return size+2;
   844 }
   846 static int impl_fp_store_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int src_hi, int dst_lo, int dst_hi,
   847                                  int offset, int size, outputStream* st ) {
   848   if( src_lo != FPR1L_num ) {      // Move value to top of FP stack, if not already there
   849     if( cbuf ) {
   850       emit_opcode( *cbuf, 0xD9 );  // FLD (i.e., push it)
   851       emit_d8( *cbuf, 0xC0-1+Matcher::_regEncode[src_lo] );
   852 #ifndef PRODUCT
   853     } else if( !do_size ) {
   854       if( size != 0 ) st->print("\n\t");
   855       st->print("FLD    %s",Matcher::regName[src_lo]);
   856 #endif
   857     }
   858     size += 2;
   859   }
   861   int st_op = (src_lo != FPR1L_num) ? EBX_num /*store & pop*/ : EDX_num /*store no pop*/;
   862   const char *op_str;
   863   int op;
   864   if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double store?
   865     op_str = (src_lo != FPR1L_num) ? "FSTP_D" : "FST_D ";
   866     op = 0xDD;
   867   } else {                   // 32-bit store
   868     op_str = (src_lo != FPR1L_num) ? "FSTP_S" : "FST_S ";
   869     op = 0xD9;
   870     assert( !OptoReg::is_valid(src_hi) && !OptoReg::is_valid(dst_hi), "no non-adjacent float-stores" );
   871   }
   873   return impl_helper(cbuf,do_size,false,offset,st_op,op,op_str,size, st);
   874 }
   876 // Next two methods are shared by 32- and 64-bit VM. They are defined in x86.ad.
   877 static int vec_mov_helper(CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   878                           int src_hi, int dst_hi, uint ireg, outputStream* st);
   880 static int vec_spill_helper(CodeBuffer *cbuf, bool do_size, bool is_load,
   881                             int stack_offset, int reg, uint ireg, outputStream* st);
   883 static int vec_stack_to_stack_helper(CodeBuffer *cbuf, bool do_size, int src_offset,
   884                                      int dst_offset, uint ireg, outputStream* st) {
   885   int calc_size = 0;
   886   int src_offset_size = (src_offset == 0) ? 0 : ((src_offset < 0x80) ? 1 : 4);
   887   int dst_offset_size = (dst_offset == 0) ? 0 : ((dst_offset < 0x80) ? 1 : 4);
   888   switch (ireg) {
   889   case Op_VecS:
   890     calc_size = 3+src_offset_size + 3+dst_offset_size;
   891     break;
   892   case Op_VecD:
   893     calc_size = 3+src_offset_size + 3+dst_offset_size;
   894     src_offset += 4;
   895     dst_offset += 4;
   896     src_offset_size = (src_offset == 0) ? 0 : ((src_offset < 0x80) ? 1 : 4);
   897     dst_offset_size = (dst_offset == 0) ? 0 : ((dst_offset < 0x80) ? 1 : 4);
   898     calc_size += 3+src_offset_size + 3+dst_offset_size;
   899     break;
   900   case Op_VecX:
   901     calc_size = 6 + 6 + 5+src_offset_size + 5+dst_offset_size;
   902     break;
   903   case Op_VecY:
   904     calc_size = 6 + 6 + 5+src_offset_size + 5+dst_offset_size;
   905     break;
   906   default:
   907     ShouldNotReachHere();
   908   }
   909   if (cbuf) {
   910     MacroAssembler _masm(cbuf);
   911     int offset = __ offset();
   912     switch (ireg) {
   913     case Op_VecS:
   914       __ pushl(Address(rsp, src_offset));
   915       __ popl (Address(rsp, dst_offset));
   916       break;
   917     case Op_VecD:
   918       __ pushl(Address(rsp, src_offset));
   919       __ popl (Address(rsp, dst_offset));
   920       __ pushl(Address(rsp, src_offset+4));
   921       __ popl (Address(rsp, dst_offset+4));
   922       break;
   923     case Op_VecX:
   924       __ movdqu(Address(rsp, -16), xmm0);
   925       __ movdqu(xmm0, Address(rsp, src_offset));
   926       __ movdqu(Address(rsp, dst_offset), xmm0);
   927       __ movdqu(xmm0, Address(rsp, -16));
   928       break;
   929     case Op_VecY:
   930       __ vmovdqu(Address(rsp, -32), xmm0);
   931       __ vmovdqu(xmm0, Address(rsp, src_offset));
   932       __ vmovdqu(Address(rsp, dst_offset), xmm0);
   933       __ vmovdqu(xmm0, Address(rsp, -32));
   934       break;
   935     default:
   936       ShouldNotReachHere();
   937     }
   938     int size = __ offset() - offset;
   939     assert(size == calc_size, "incorrect size calculattion");
   940     return size;
   941 #ifndef PRODUCT
   942   } else if (!do_size) {
   943     switch (ireg) {
   944     case Op_VecS:
   945       st->print("pushl   [rsp + #%d]\t# 32-bit mem-mem spill\n\t"
   946                 "popl    [rsp + #%d]",
   947                 src_offset, dst_offset);
   948       break;
   949     case Op_VecD:
   950       st->print("pushl   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
   951                 "popq    [rsp + #%d]\n\t"
   952                 "pushl   [rsp + #%d]\n\t"
   953                 "popq    [rsp + #%d]",
   954                 src_offset, dst_offset, src_offset+4, dst_offset+4);
   955       break;
   956      case Op_VecX:
   957       st->print("movdqu  [rsp - #16], xmm0\t# 128-bit mem-mem spill\n\t"
   958                 "movdqu  xmm0, [rsp + #%d]\n\t"
   959                 "movdqu  [rsp + #%d], xmm0\n\t"
   960                 "movdqu  xmm0, [rsp - #16]",
   961                 src_offset, dst_offset);
   962       break;
   963     case Op_VecY:
   964       st->print("vmovdqu [rsp - #32], xmm0\t# 256-bit mem-mem spill\n\t"
   965                 "vmovdqu xmm0, [rsp + #%d]\n\t"
   966                 "vmovdqu [rsp + #%d], xmm0\n\t"
   967                 "vmovdqu xmm0, [rsp - #32]",
   968                 src_offset, dst_offset);
   969       break;
   970     default:
   971       ShouldNotReachHere();
   972     }
   973 #endif
   974   }
   975   return calc_size;
   976 }
   978 uint MachSpillCopyNode::implementation( CodeBuffer *cbuf, PhaseRegAlloc *ra_, bool do_size, outputStream* st ) const {
   979   // Get registers to move
   980   OptoReg::Name src_second = ra_->get_reg_second(in(1));
   981   OptoReg::Name src_first = ra_->get_reg_first(in(1));
   982   OptoReg::Name dst_second = ra_->get_reg_second(this );
   983   OptoReg::Name dst_first = ra_->get_reg_first(this );
   985   enum RC src_second_rc = rc_class(src_second);
   986   enum RC src_first_rc = rc_class(src_first);
   987   enum RC dst_second_rc = rc_class(dst_second);
   988   enum RC dst_first_rc = rc_class(dst_first);
   990   assert( OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first), "must move at least 1 register" );
   992   // Generate spill code!
   993   int size = 0;
   995   if( src_first == dst_first && src_second == dst_second )
   996     return size;            // Self copy, no move
   998   if (bottom_type()->isa_vect() != NULL) {
   999     uint ireg = ideal_reg();
  1000     assert((src_first_rc != rc_int && dst_first_rc != rc_int), "sanity");
  1001     assert((src_first_rc != rc_float && dst_first_rc != rc_float), "sanity");
  1002     assert((ireg == Op_VecS || ireg == Op_VecD || ireg == Op_VecX || ireg == Op_VecY), "sanity");
  1003     if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
  1004       // mem -> mem
  1005       int src_offset = ra_->reg2offset(src_first);
  1006       int dst_offset = ra_->reg2offset(dst_first);
  1007       return vec_stack_to_stack_helper(cbuf, do_size, src_offset, dst_offset, ireg, st);
  1008     } else if (src_first_rc == rc_xmm && dst_first_rc == rc_xmm ) {
  1009       return vec_mov_helper(cbuf, do_size, src_first, dst_first, src_second, dst_second, ireg, st);
  1010     } else if (src_first_rc == rc_xmm && dst_first_rc == rc_stack ) {
  1011       int stack_offset = ra_->reg2offset(dst_first);
  1012       return vec_spill_helper(cbuf, do_size, false, stack_offset, src_first, ireg, st);
  1013     } else if (src_first_rc == rc_stack && dst_first_rc == rc_xmm ) {
  1014       int stack_offset = ra_->reg2offset(src_first);
  1015       return vec_spill_helper(cbuf, do_size, true,  stack_offset, dst_first, ireg, st);
  1016     } else {
  1017       ShouldNotReachHere();
  1021   // --------------------------------------
  1022   // Check for mem-mem move.  push/pop to move.
  1023   if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
  1024     if( src_second == dst_first ) { // overlapping stack copy ranges
  1025       assert( src_second_rc == rc_stack && dst_second_rc == rc_stack, "we only expect a stk-stk copy here" );
  1026       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
  1027       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
  1028       src_second_rc = dst_second_rc = rc_bad;  // flag as already moved the second bits
  1030     // move low bits
  1031     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),ESI_num,0xFF,"PUSH  ",size, st);
  1032     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),EAX_num,0x8F,"POP   ",size, st);
  1033     if( src_second_rc == rc_stack && dst_second_rc == rc_stack ) { // mov second bits
  1034       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
  1035       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
  1037     return size;
  1040   // --------------------------------------
  1041   // Check for integer reg-reg copy
  1042   if( src_first_rc == rc_int && dst_first_rc == rc_int )
  1043     size = impl_mov_helper(cbuf,do_size,src_first,dst_first,size, st);
  1045   // Check for integer store
  1046   if( src_first_rc == rc_int && dst_first_rc == rc_stack )
  1047     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first,0x89,"MOV ",size, st);
  1049   // Check for integer load
  1050   if( dst_first_rc == rc_int && src_first_rc == rc_stack )
  1051     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first,0x8B,"MOV ",size, st);
  1053   // Check for integer reg-xmm reg copy
  1054   if( src_first_rc == rc_int && dst_first_rc == rc_xmm ) {
  1055     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
  1056             "no 64 bit integer-float reg moves" );
  1057     return impl_movgpr2x_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
  1059   // --------------------------------------
  1060   // Check for float reg-reg copy
  1061   if( src_first_rc == rc_float && dst_first_rc == rc_float ) {
  1062     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
  1063             (src_first+1 == src_second && dst_first+1 == dst_second), "no non-adjacent float-moves" );
  1064     if( cbuf ) {
  1066       // Note the mucking with the register encode to compensate for the 0/1
  1067       // indexing issue mentioned in a comment in the reg_def sections
  1068       // for FPR registers many lines above here.
  1070       if( src_first != FPR1L_num ) {
  1071         emit_opcode  (*cbuf, 0xD9 );           // FLD    ST(i)
  1072         emit_d8      (*cbuf, 0xC0+Matcher::_regEncode[src_first]-1 );
  1073         emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
  1074         emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
  1075      } else {
  1076         emit_opcode  (*cbuf, 0xDD );           // FST    ST(i)
  1077         emit_d8      (*cbuf, 0xD0+Matcher::_regEncode[dst_first]-1 );
  1079 #ifndef PRODUCT
  1080     } else if( !do_size ) {
  1081       if( size != 0 ) st->print("\n\t");
  1082       if( src_first != FPR1L_num ) st->print("FLD    %s\n\tFSTP   %s",Matcher::regName[src_first],Matcher::regName[dst_first]);
  1083       else                      st->print(             "FST    %s",                            Matcher::regName[dst_first]);
  1084 #endif
  1086     return size + ((src_first != FPR1L_num) ? 2+2 : 2);
  1089   // Check for float store
  1090   if( src_first_rc == rc_float && dst_first_rc == rc_stack ) {
  1091     return impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,ra_->reg2offset(dst_first),size, st);
  1094   // Check for float load
  1095   if( dst_first_rc == rc_float && src_first_rc == rc_stack ) {
  1096     int offset = ra_->reg2offset(src_first);
  1097     const char *op_str;
  1098     int op;
  1099     if( src_first+1 == src_second && dst_first+1 == dst_second ) { // double load?
  1100       op_str = "FLD_D";
  1101       op = 0xDD;
  1102     } else {                   // 32-bit load
  1103       op_str = "FLD_S";
  1104       op = 0xD9;
  1105       assert( src_second_rc == rc_bad && dst_second_rc == rc_bad, "no non-adjacent float-loads" );
  1107     if( cbuf ) {
  1108       emit_opcode  (*cbuf, op );
  1109       encode_RegMem(*cbuf, 0x0, ESP_enc, 0x4, 0, offset, relocInfo::none);
  1110       emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
  1111       emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
  1112 #ifndef PRODUCT
  1113     } else if( !do_size ) {
  1114       if( size != 0 ) st->print("\n\t");
  1115       st->print("%s  ST,[ESP + #%d]\n\tFSTP   %s",op_str, offset,Matcher::regName[dst_first]);
  1116 #endif
  1118     int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
  1119     return size + 3+offset_size+2;
  1122   // Check for xmm reg-reg copy
  1123   if( src_first_rc == rc_xmm && dst_first_rc == rc_xmm ) {
  1124     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
  1125             (src_first+1 == src_second && dst_first+1 == dst_second),
  1126             "no non-adjacent float-moves" );
  1127     return impl_movx_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
  1130   // Check for xmm reg-integer reg copy
  1131   if( src_first_rc == rc_xmm && dst_first_rc == rc_int ) {
  1132     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
  1133             "no 64 bit float-integer reg moves" );
  1134     return impl_movx2gpr_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
  1137   // Check for xmm store
  1138   if( src_first_rc == rc_xmm && dst_first_rc == rc_stack ) {
  1139     return impl_x_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first, src_second, size, st);
  1142   // Check for float xmm load
  1143   if( dst_first_rc == rc_xmm && src_first_rc == rc_stack ) {
  1144     return impl_x_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first, dst_second, size, st);
  1147   // Copy from float reg to xmm reg
  1148   if( dst_first_rc == rc_xmm && src_first_rc == rc_float ) {
  1149     // copy to the top of stack from floating point reg
  1150     // and use LEA to preserve flags
  1151     if( cbuf ) {
  1152       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP-8]
  1153       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
  1154       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
  1155       emit_d8(*cbuf,0xF8);
  1156 #ifndef PRODUCT
  1157     } else if( !do_size ) {
  1158       if( size != 0 ) st->print("\n\t");
  1159       st->print("LEA    ESP,[ESP-8]");
  1160 #endif
  1162     size += 4;
  1164     size = impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,0,size, st);
  1166     // Copy from the temp memory to the xmm reg.
  1167     size = impl_x_helper(cbuf,do_size,true ,0,dst_first, dst_second, size, st);
  1169     if( cbuf ) {
  1170       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP+8]
  1171       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
  1172       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
  1173       emit_d8(*cbuf,0x08);
  1174 #ifndef PRODUCT
  1175     } else if( !do_size ) {
  1176       if( size != 0 ) st->print("\n\t");
  1177       st->print("LEA    ESP,[ESP+8]");
  1178 #endif
  1180     size += 4;
  1181     return size;
  1184   assert( size > 0, "missed a case" );
  1186   // --------------------------------------------------------------------
  1187   // Check for second bits still needing moving.
  1188   if( src_second == dst_second )
  1189     return size;               // Self copy; no move
  1190   assert( src_second_rc != rc_bad && dst_second_rc != rc_bad, "src_second & dst_second cannot be Bad" );
  1192   // Check for second word int-int move
  1193   if( src_second_rc == rc_int && dst_second_rc == rc_int )
  1194     return impl_mov_helper(cbuf,do_size,src_second,dst_second,size, st);
  1196   // Check for second word integer store
  1197   if( src_second_rc == rc_int && dst_second_rc == rc_stack )
  1198     return impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),src_second,0x89,"MOV ",size, st);
  1200   // Check for second word integer load
  1201   if( dst_second_rc == rc_int && src_second_rc == rc_stack )
  1202     return impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),dst_second,0x8B,"MOV ",size, st);
  1205   Unimplemented();
  1208 #ifndef PRODUCT
  1209 void MachSpillCopyNode::format(PhaseRegAlloc *ra_, outputStream* st) const {
  1210   implementation( NULL, ra_, false, st );
  1212 #endif
  1214 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1215   implementation( &cbuf, ra_, false, NULL );
  1218 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const {
  1219   return implementation( NULL, ra_, true, NULL );
  1223 //=============================================================================
  1224 #ifndef PRODUCT
  1225 void BoxLockNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
  1226   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1227   int reg = ra_->get_reg_first(this);
  1228   st->print("LEA    %s,[ESP + #%d]",Matcher::regName[reg],offset);
  1230 #endif
  1232 void BoxLockNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1233   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1234   int reg = ra_->get_encode(this);
  1235   if( offset >= 128 ) {
  1236     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
  1237     emit_rm(cbuf, 0x2, reg, 0x04);
  1238     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
  1239     emit_d32(cbuf, offset);
  1241   else {
  1242     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
  1243     emit_rm(cbuf, 0x1, reg, 0x04);
  1244     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
  1245     emit_d8(cbuf, offset);
  1249 uint BoxLockNode::size(PhaseRegAlloc *ra_) const {
  1250   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1251   if( offset >= 128 ) {
  1252     return 7;
  1254   else {
  1255     return 4;
  1259 //=============================================================================
  1261 // emit call stub, compiled java to interpreter
  1262 void emit_java_to_interp(CodeBuffer &cbuf ) {
  1263   // Stub is fixed up when the corresponding call is converted from calling
  1264   // compiled code to calling interpreted code.
  1265   // mov rbx,0
  1266   // jmp -1
  1268   address mark = cbuf.insts_mark();  // get mark within main instrs section
  1270   // Note that the code buffer's insts_mark is always relative to insts.
  1271   // That's why we must use the macroassembler to generate a stub.
  1272   MacroAssembler _masm(&cbuf);
  1274   address base =
  1275   __ start_a_stub(Compile::MAX_stubs_size);
  1276   if (base == NULL)  return;  // CodeBuffer::expand failed
  1277   // static stub relocation stores the instruction address of the call
  1278   __ relocate(static_stub_Relocation::spec(mark), RELOC_IMM32);
  1279   // static stub relocation also tags the Method* in the code-stream.
  1280   __ mov_metadata(rbx, (Metadata*)NULL);  // method is zapped till fixup time
  1281   // This is recognized as unresolved by relocs/nativeInst/ic code
  1282   __ jump(RuntimeAddress(__ pc()));
  1284   __ end_a_stub();
  1285   // Update current stubs pointer and restore insts_end.
  1287 // size of call stub, compiled java to interpretor
  1288 uint size_java_to_interp() {
  1289   return 10;  // movl; jmp
  1291 // relocation entries for call stub, compiled java to interpretor
  1292 uint reloc_java_to_interp() {
  1293   return 4;  // 3 in emit_java_to_interp + 1 in Java_Static_Call
  1296 //=============================================================================
  1297 #ifndef PRODUCT
  1298 void MachUEPNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
  1299   st->print_cr(  "CMP    EAX,[ECX+4]\t# Inline cache check");
  1300   st->print_cr("\tJNE    SharedRuntime::handle_ic_miss_stub");
  1301   st->print_cr("\tNOP");
  1302   st->print_cr("\tNOP");
  1303   if( !OptoBreakpoint )
  1304     st->print_cr("\tNOP");
  1306 #endif
  1308 void MachUEPNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1309   MacroAssembler masm(&cbuf);
  1310 #ifdef ASSERT
  1311   uint insts_size = cbuf.insts_size();
  1312 #endif
  1313   masm.cmpptr(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
  1314   masm.jump_cc(Assembler::notEqual,
  1315                RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
  1316   /* WARNING these NOPs are critical so that verified entry point is properly
  1317      aligned for patching by NativeJump::patch_verified_entry() */
  1318   int nops_cnt = 2;
  1319   if( !OptoBreakpoint ) // Leave space for int3
  1320      nops_cnt += 1;
  1321   masm.nop(nops_cnt);
  1323   assert(cbuf.insts_size() - insts_size == size(ra_), "checking code size of inline cache node");
  1326 uint MachUEPNode::size(PhaseRegAlloc *ra_) const {
  1327   return OptoBreakpoint ? 11 : 12;
  1331 //=============================================================================
  1332 uint size_exception_handler() {
  1333   // NativeCall instruction size is the same as NativeJump.
  1334   // exception handler starts out as jump and can be patched to
  1335   // a call be deoptimization.  (4932387)
  1336   // Note that this value is also credited (in output.cpp) to
  1337   // the size of the code section.
  1338   return NativeJump::instruction_size;
  1341 // Emit exception handler code.  Stuff framesize into a register
  1342 // and call a VM stub routine.
  1343 int emit_exception_handler(CodeBuffer& cbuf) {
  1345   // Note that the code buffer's insts_mark is always relative to insts.
  1346   // That's why we must use the macroassembler to generate a handler.
  1347   MacroAssembler _masm(&cbuf);
  1348   address base =
  1349   __ start_a_stub(size_exception_handler());
  1350   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1351   int offset = __ offset();
  1352   __ jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
  1353   assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
  1354   __ end_a_stub();
  1355   return offset;
  1358 uint size_deopt_handler() {
  1359   // NativeCall instruction size is the same as NativeJump.
  1360   // exception handler starts out as jump and can be patched to
  1361   // a call be deoptimization.  (4932387)
  1362   // Note that this value is also credited (in output.cpp) to
  1363   // the size of the code section.
  1364   return 5 + NativeJump::instruction_size; // pushl(); jmp;
  1367 // Emit deopt handler code.
  1368 int emit_deopt_handler(CodeBuffer& cbuf) {
  1370   // Note that the code buffer's insts_mark is always relative to insts.
  1371   // That's why we must use the macroassembler to generate a handler.
  1372   MacroAssembler _masm(&cbuf);
  1373   address base =
  1374   __ start_a_stub(size_exception_handler());
  1375   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1376   int offset = __ offset();
  1377   InternalAddress here(__ pc());
  1378   __ pushptr(here.addr());
  1380   __ jump(RuntimeAddress(SharedRuntime::deopt_blob()->unpack()));
  1381   assert(__ offset() - offset <= (int) size_deopt_handler(), "overflow");
  1382   __ end_a_stub();
  1383   return offset;
  1386 int Matcher::regnum_to_fpu_offset(int regnum) {
  1387   return regnum - 32; // The FP registers are in the second chunk
  1390 // This is UltraSparc specific, true just means we have fast l2f conversion
  1391 const bool Matcher::convL2FSupported(void) {
  1392   return true;
  1395 // Is this branch offset short enough that a short branch can be used?
  1396 //
  1397 // NOTE: If the platform does not provide any short branch variants, then
  1398 //       this method should return false for offset 0.
  1399 bool Matcher::is_short_branch_offset(int rule, int br_size, int offset) {
  1400   // The passed offset is relative to address of the branch.
  1401   // On 86 a branch displacement is calculated relative to address
  1402   // of a next instruction.
  1403   offset -= br_size;
  1405   // the short version of jmpConUCF2 contains multiple branches,
  1406   // making the reach slightly less
  1407   if (rule == jmpConUCF2_rule)
  1408     return (-126 <= offset && offset <= 125);
  1409   return (-128 <= offset && offset <= 127);
  1412 const bool Matcher::isSimpleConstant64(jlong value) {
  1413   // Will one (StoreL ConL) be cheaper than two (StoreI ConI)?.
  1414   return false;
  1417 // The ecx parameter to rep stos for the ClearArray node is in dwords.
  1418 const bool Matcher::init_array_count_is_in_bytes = false;
  1420 // Threshold size for cleararray.
  1421 const int Matcher::init_array_short_size = 8 * BytesPerLong;
  1423 // Needs 2 CMOV's for longs.
  1424 const int Matcher::long_cmove_cost() { return 1; }
  1426 // No CMOVF/CMOVD with SSE/SSE2
  1427 const int Matcher::float_cmove_cost() { return (UseSSE>=1) ? ConditionalMoveLimit : 0; }
  1429 // Should the Matcher clone shifts on addressing modes, expecting them to
  1430 // be subsumed into complex addressing expressions or compute them into
  1431 // registers?  True for Intel but false for most RISCs
  1432 const bool Matcher::clone_shift_expressions = true;
  1434 // Do we need to mask the count passed to shift instructions or does
  1435 // the cpu only look at the lower 5/6 bits anyway?
  1436 const bool Matcher::need_masked_shift_count = false;
  1438 bool Matcher::narrow_oop_use_complex_address() {
  1439   ShouldNotCallThis();
  1440   return true;
  1443 bool Matcher::narrow_klass_use_complex_address() {
  1444   ShouldNotCallThis();
  1445   return true;
  1449 // Is it better to copy float constants, or load them directly from memory?
  1450 // Intel can load a float constant from a direct address, requiring no
  1451 // extra registers.  Most RISCs will have to materialize an address into a
  1452 // register first, so they would do better to copy the constant from stack.
  1453 const bool Matcher::rematerialize_float_constants = true;
  1455 // If CPU can load and store mis-aligned doubles directly then no fixup is
  1456 // needed.  Else we split the double into 2 integer pieces and move it
  1457 // piece-by-piece.  Only happens when passing doubles into C code as the
  1458 // Java calling convention forces doubles to be aligned.
  1459 const bool Matcher::misaligned_doubles_ok = true;
  1462 void Matcher::pd_implicit_null_fixup(MachNode *node, uint idx) {
  1463   // Get the memory operand from the node
  1464   uint numopnds = node->num_opnds();        // Virtual call for number of operands
  1465   uint skipped  = node->oper_input_base();  // Sum of leaves skipped so far
  1466   assert( idx >= skipped, "idx too low in pd_implicit_null_fixup" );
  1467   uint opcnt     = 1;                 // First operand
  1468   uint num_edges = node->_opnds[1]->num_edges(); // leaves for first operand
  1469   while( idx >= skipped+num_edges ) {
  1470     skipped += num_edges;
  1471     opcnt++;                          // Bump operand count
  1472     assert( opcnt < numopnds, "Accessing non-existent operand" );
  1473     num_edges = node->_opnds[opcnt]->num_edges(); // leaves for next operand
  1476   MachOper *memory = node->_opnds[opcnt];
  1477   MachOper *new_memory = NULL;
  1478   switch (memory->opcode()) {
  1479   case DIRECT:
  1480   case INDOFFSET32X:
  1481     // No transformation necessary.
  1482     return;
  1483   case INDIRECT:
  1484     new_memory = new (C) indirect_win95_safeOper( );
  1485     break;
  1486   case INDOFFSET8:
  1487     new_memory = new (C) indOffset8_win95_safeOper(memory->disp(NULL, NULL, 0));
  1488     break;
  1489   case INDOFFSET32:
  1490     new_memory = new (C) indOffset32_win95_safeOper(memory->disp(NULL, NULL, 0));
  1491     break;
  1492   case INDINDEXOFFSET:
  1493     new_memory = new (C) indIndexOffset_win95_safeOper(memory->disp(NULL, NULL, 0));
  1494     break;
  1495   case INDINDEXSCALE:
  1496     new_memory = new (C) indIndexScale_win95_safeOper(memory->scale());
  1497     break;
  1498   case INDINDEXSCALEOFFSET:
  1499     new_memory = new (C) indIndexScaleOffset_win95_safeOper(memory->scale(), memory->disp(NULL, NULL, 0));
  1500     break;
  1501   case LOAD_LONG_INDIRECT:
  1502   case LOAD_LONG_INDOFFSET32:
  1503     // Does not use EBP as address register, use { EDX, EBX, EDI, ESI}
  1504     return;
  1505   default:
  1506     assert(false, "unexpected memory operand in pd_implicit_null_fixup()");
  1507     return;
  1509   node->_opnds[opcnt] = new_memory;
  1512 // Advertise here if the CPU requires explicit rounding operations
  1513 // to implement the UseStrictFP mode.
  1514 const bool Matcher::strict_fp_requires_explicit_rounding = true;
  1516 // Are floats conerted to double when stored to stack during deoptimization?
  1517 // On x32 it is stored with convertion only when FPU is used for floats.
  1518 bool Matcher::float_in_double() { return (UseSSE == 0); }
  1520 // Do ints take an entire long register or just half?
  1521 const bool Matcher::int_in_long = false;
  1523 // Return whether or not this register is ever used as an argument.  This
  1524 // function is used on startup to build the trampoline stubs in generateOptoStub.
  1525 // Registers not mentioned will be killed by the VM call in the trampoline, and
  1526 // arguments in those registers not be available to the callee.
  1527 bool Matcher::can_be_java_arg( int reg ) {
  1528   if(  reg == ECX_num   || reg == EDX_num   ) return true;
  1529   if( (reg == XMM0_num  || reg == XMM1_num ) && UseSSE>=1 ) return true;
  1530   if( (reg == XMM0b_num || reg == XMM1b_num) && UseSSE>=2 ) return true;
  1531   return false;
  1534 bool Matcher::is_spillable_arg( int reg ) {
  1535   return can_be_java_arg(reg);
  1538 bool Matcher::use_asm_for_ldiv_by_con( jlong divisor ) {
  1539   // Use hardware integer DIV instruction when
  1540   // it is faster than a code which use multiply.
  1541   // Only when constant divisor fits into 32 bit
  1542   // (min_jint is excluded to get only correct
  1543   // positive 32 bit values from negative).
  1544   return VM_Version::has_fast_idiv() &&
  1545          (divisor == (int)divisor && divisor != min_jint);
  1548 // Register for DIVI projection of divmodI
  1549 RegMask Matcher::divI_proj_mask() {
  1550   return EAX_REG_mask();
  1553 // Register for MODI projection of divmodI
  1554 RegMask Matcher::modI_proj_mask() {
  1555   return EDX_REG_mask();
  1558 // Register for DIVL projection of divmodL
  1559 RegMask Matcher::divL_proj_mask() {
  1560   ShouldNotReachHere();
  1561   return RegMask();
  1564 // Register for MODL projection of divmodL
  1565 RegMask Matcher::modL_proj_mask() {
  1566   ShouldNotReachHere();
  1567   return RegMask();
  1570 const RegMask Matcher::method_handle_invoke_SP_save_mask() {
  1571   return EBP_REG_mask();
  1574 // Returns true if the high 32 bits of the value is known to be zero.
  1575 bool is_operand_hi32_zero(Node* n) {
  1576   int opc = n->Opcode();
  1577   if (opc == Op_AndL) {
  1578     Node* o2 = n->in(2);
  1579     if (o2->is_Con() && (o2->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
  1580       return true;
  1583   if (opc == Op_ConL && (n->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
  1584     return true;
  1586   return false;
  1589 %}
  1591 //----------ENCODING BLOCK-----------------------------------------------------
  1592 // This block specifies the encoding classes used by the compiler to output
  1593 // byte streams.  Encoding classes generate functions which are called by
  1594 // Machine Instruction Nodes in order to generate the bit encoding of the
  1595 // instruction.  Operands specify their base encoding interface with the
  1596 // interface keyword.  There are currently supported four interfaces,
  1597 // REG_INTER, CONST_INTER, MEMORY_INTER, & COND_INTER.  REG_INTER causes an
  1598 // operand to generate a function which returns its register number when
  1599 // queried.   CONST_INTER causes an operand to generate a function which
  1600 // returns the value of the constant when queried.  MEMORY_INTER causes an
  1601 // operand to generate four functions which return the Base Register, the
  1602 // Index Register, the Scale Value, and the Offset Value of the operand when
  1603 // queried.  COND_INTER causes an operand to generate six functions which
  1604 // return the encoding code (ie - encoding bits for the instruction)
  1605 // associated with each basic boolean condition for a conditional instruction.
  1606 // Instructions specify two basic values for encoding.  They use the
  1607 // ins_encode keyword to specify their encoding class (which must be one of
  1608 // the class names specified in the encoding block), and they use the
  1609 // opcode keyword to specify, in order, their primary, secondary, and
  1610 // tertiary opcode.  Only the opcode sections which a particular instruction
  1611 // needs for encoding need to be specified.
  1612 encode %{
  1613   // Build emit functions for each basic byte or larger field in the intel
  1614   // encoding scheme (opcode, rm, sib, immediate), and call them from C++
  1615   // code in the enc_class source block.  Emit functions will live in the
  1616   // main source block for now.  In future, we can generalize this by
  1617   // adding a syntax that specifies the sizes of fields in an order,
  1618   // so that the adlc can build the emit functions automagically
  1620   // Emit primary opcode
  1621   enc_class OpcP %{
  1622     emit_opcode(cbuf, $primary);
  1623   %}
  1625   // Emit secondary opcode
  1626   enc_class OpcS %{
  1627     emit_opcode(cbuf, $secondary);
  1628   %}
  1630   // Emit opcode directly
  1631   enc_class Opcode(immI d8) %{
  1632     emit_opcode(cbuf, $d8$$constant);
  1633   %}
  1635   enc_class SizePrefix %{
  1636     emit_opcode(cbuf,0x66);
  1637   %}
  1639   enc_class RegReg (rRegI dst, rRegI src) %{    // RegReg(Many)
  1640     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  1641   %}
  1643   enc_class OpcRegReg (immI opcode, rRegI dst, rRegI src) %{    // OpcRegReg(Many)
  1644     emit_opcode(cbuf,$opcode$$constant);
  1645     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  1646   %}
  1648   enc_class mov_r32_imm0( rRegI dst ) %{
  1649     emit_opcode( cbuf, 0xB8 + $dst$$reg ); // 0xB8+ rd   -- MOV r32  ,imm32
  1650     emit_d32   ( cbuf, 0x0  );             //                         imm32==0x0
  1651   %}
  1653   enc_class cdq_enc %{
  1654     // Full implementation of Java idiv and irem; checks for
  1655     // special case as described in JVM spec., p.243 & p.271.
  1656     //
  1657     //         normal case                           special case
  1658     //
  1659     // input : rax,: dividend                         min_int
  1660     //         reg: divisor                          -1
  1661     //
  1662     // output: rax,: quotient  (= rax, idiv reg)       min_int
  1663     //         rdx: remainder (= rax, irem reg)       0
  1664     //
  1665     //  Code sequnce:
  1666     //
  1667     //  81 F8 00 00 00 80    cmp         rax,80000000h
  1668     //  0F 85 0B 00 00 00    jne         normal_case
  1669     //  33 D2                xor         rdx,edx
  1670     //  83 F9 FF             cmp         rcx,0FFh
  1671     //  0F 84 03 00 00 00    je          done
  1672     //                  normal_case:
  1673     //  99                   cdq
  1674     //  F7 F9                idiv        rax,ecx
  1675     //                  done:
  1676     //
  1677     emit_opcode(cbuf,0x81); emit_d8(cbuf,0xF8);
  1678     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);
  1679     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x80);                     // cmp rax,80000000h
  1680     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x85);
  1681     emit_opcode(cbuf,0x0B); emit_d8(cbuf,0x00);
  1682     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // jne normal_case
  1683     emit_opcode(cbuf,0x33); emit_d8(cbuf,0xD2);                     // xor rdx,edx
  1684     emit_opcode(cbuf,0x83); emit_d8(cbuf,0xF9); emit_d8(cbuf,0xFF); // cmp rcx,0FFh
  1685     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x84);
  1686     emit_opcode(cbuf,0x03); emit_d8(cbuf,0x00);
  1687     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // je done
  1688     // normal_case:
  1689     emit_opcode(cbuf,0x99);                                         // cdq
  1690     // idiv (note: must be emitted by the user of this rule)
  1691     // normal:
  1692   %}
  1694   // Dense encoding for older common ops
  1695   enc_class Opc_plus(immI opcode, rRegI reg) %{
  1696     emit_opcode(cbuf, $opcode$$constant + $reg$$reg);
  1697   %}
  1700   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
  1701   enc_class OpcSE (immI imm) %{ // Emit primary opcode and set sign-extend bit
  1702     // Check for 8-bit immediate, and set sign extend bit in opcode
  1703     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1704       emit_opcode(cbuf, $primary | 0x02);
  1706     else {                          // If 32-bit immediate
  1707       emit_opcode(cbuf, $primary);
  1709   %}
  1711   enc_class OpcSErm (rRegI dst, immI imm) %{    // OpcSEr/m
  1712     // Emit primary opcode and set sign-extend bit
  1713     // Check for 8-bit immediate, and set sign extend bit in opcode
  1714     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1715       emit_opcode(cbuf, $primary | 0x02);    }
  1716     else {                          // If 32-bit immediate
  1717       emit_opcode(cbuf, $primary);
  1719     // Emit r/m byte with secondary opcode, after primary opcode.
  1720     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1721   %}
  1723   enc_class Con8or32 (immI imm) %{    // Con8or32(storeImmI), 8 or 32 bits
  1724     // Check for 8-bit immediate, and set sign extend bit in opcode
  1725     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1726       $$$emit8$imm$$constant;
  1728     else {                          // If 32-bit immediate
  1729       // Output immediate
  1730       $$$emit32$imm$$constant;
  1732   %}
  1734   enc_class Long_OpcSErm_Lo(eRegL dst, immL imm) %{
  1735     // Emit primary opcode and set sign-extend bit
  1736     // Check for 8-bit immediate, and set sign extend bit in opcode
  1737     int con = (int)$imm$$constant; // Throw away top bits
  1738     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
  1739     // Emit r/m byte with secondary opcode, after primary opcode.
  1740     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1741     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
  1742     else                               emit_d32(cbuf,con);
  1743   %}
  1745   enc_class Long_OpcSErm_Hi(eRegL dst, immL imm) %{
  1746     // Emit primary opcode and set sign-extend bit
  1747     // Check for 8-bit immediate, and set sign extend bit in opcode
  1748     int con = (int)($imm$$constant >> 32); // Throw away bottom bits
  1749     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
  1750     // Emit r/m byte with tertiary opcode, after primary opcode.
  1751     emit_rm(cbuf, 0x3, $tertiary, HIGH_FROM_LOW($dst$$reg));
  1752     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
  1753     else                               emit_d32(cbuf,con);
  1754   %}
  1756   enc_class OpcSReg (rRegI dst) %{    // BSWAP
  1757     emit_cc(cbuf, $secondary, $dst$$reg );
  1758   %}
  1760   enc_class bswap_long_bytes(eRegL dst) %{ // BSWAP
  1761     int destlo = $dst$$reg;
  1762     int desthi = HIGH_FROM_LOW(destlo);
  1763     // bswap lo
  1764     emit_opcode(cbuf, 0x0F);
  1765     emit_cc(cbuf, 0xC8, destlo);
  1766     // bswap hi
  1767     emit_opcode(cbuf, 0x0F);
  1768     emit_cc(cbuf, 0xC8, desthi);
  1769     // xchg lo and hi
  1770     emit_opcode(cbuf, 0x87);
  1771     emit_rm(cbuf, 0x3, destlo, desthi);
  1772   %}
  1774   enc_class RegOpc (rRegI div) %{    // IDIV, IMOD, JMP indirect, ...
  1775     emit_rm(cbuf, 0x3, $secondary, $div$$reg );
  1776   %}
  1778   enc_class enc_cmov(cmpOp cop ) %{ // CMOV
  1779     $$$emit8$primary;
  1780     emit_cc(cbuf, $secondary, $cop$$cmpcode);
  1781   %}
  1783   enc_class enc_cmov_dpr(cmpOp cop, regDPR src ) %{ // CMOV
  1784     int op = 0xDA00 + $cop$$cmpcode + ($src$$reg-1);
  1785     emit_d8(cbuf, op >> 8 );
  1786     emit_d8(cbuf, op & 255);
  1787   %}
  1789   // emulate a CMOV with a conditional branch around a MOV
  1790   enc_class enc_cmov_branch( cmpOp cop, immI brOffs ) %{ // CMOV
  1791     // Invert sense of branch from sense of CMOV
  1792     emit_cc( cbuf, 0x70, ($cop$$cmpcode^1) );
  1793     emit_d8( cbuf, $brOffs$$constant );
  1794   %}
  1796   enc_class enc_PartialSubtypeCheck( ) %{
  1797     Register Redi = as_Register(EDI_enc); // result register
  1798     Register Reax = as_Register(EAX_enc); // super class
  1799     Register Recx = as_Register(ECX_enc); // killed
  1800     Register Resi = as_Register(ESI_enc); // sub class
  1801     Label miss;
  1803     MacroAssembler _masm(&cbuf);
  1804     __ check_klass_subtype_slow_path(Resi, Reax, Recx, Redi,
  1805                                      NULL, &miss,
  1806                                      /*set_cond_codes:*/ true);
  1807     if ($primary) {
  1808       __ xorptr(Redi, Redi);
  1810     __ bind(miss);
  1811   %}
  1813   enc_class FFree_Float_Stack_All %{    // Free_Float_Stack_All
  1814     MacroAssembler masm(&cbuf);
  1815     int start = masm.offset();
  1816     if (UseSSE >= 2) {
  1817       if (VerifyFPU) {
  1818         masm.verify_FPU(0, "must be empty in SSE2+ mode");
  1820     } else {
  1821       // External c_calling_convention expects the FPU stack to be 'clean'.
  1822       // Compiled code leaves it dirty.  Do cleanup now.
  1823       masm.empty_FPU_stack();
  1825     if (sizeof_FFree_Float_Stack_All == -1) {
  1826       sizeof_FFree_Float_Stack_All = masm.offset() - start;
  1827     } else {
  1828       assert(masm.offset() - start == sizeof_FFree_Float_Stack_All, "wrong size");
  1830   %}
  1832   enc_class Verify_FPU_For_Leaf %{
  1833     if( VerifyFPU ) {
  1834       MacroAssembler masm(&cbuf);
  1835       masm.verify_FPU( -3, "Returning from Runtime Leaf call");
  1837   %}
  1839   enc_class Java_To_Runtime (method meth) %{    // CALL Java_To_Runtime, Java_To_Runtime_Leaf
  1840     // This is the instruction starting address for relocation info.
  1841     cbuf.set_insts_mark();
  1842     $$$emit8$primary;
  1843     // CALL directly to the runtime
  1844     emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1845                 runtime_call_Relocation::spec(), RELOC_IMM32 );
  1847     if (UseSSE >= 2) {
  1848       MacroAssembler _masm(&cbuf);
  1849       BasicType rt = tf()->return_type();
  1851       if ((rt == T_FLOAT || rt == T_DOUBLE) && !return_value_is_used()) {
  1852         // A C runtime call where the return value is unused.  In SSE2+
  1853         // mode the result needs to be removed from the FPU stack.  It's
  1854         // likely that this function call could be removed by the
  1855         // optimizer if the C function is a pure function.
  1856         __ ffree(0);
  1857       } else if (rt == T_FLOAT) {
  1858         __ lea(rsp, Address(rsp, -4));
  1859         __ fstp_s(Address(rsp, 0));
  1860         __ movflt(xmm0, Address(rsp, 0));
  1861         __ lea(rsp, Address(rsp,  4));
  1862       } else if (rt == T_DOUBLE) {
  1863         __ lea(rsp, Address(rsp, -8));
  1864         __ fstp_d(Address(rsp, 0));
  1865         __ movdbl(xmm0, Address(rsp, 0));
  1866         __ lea(rsp, Address(rsp,  8));
  1869   %}
  1872   enc_class pre_call_resets %{
  1873     // If method sets FPU control word restore it here
  1874     debug_only(int off0 = cbuf.insts_size());
  1875     if (ra_->C->in_24_bit_fp_mode()) {
  1876       MacroAssembler _masm(&cbuf);
  1877       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
  1879     if (ra_->C->max_vector_size() > 16) {
  1880       // Clear upper bits of YMM registers when current compiled code uses
  1881       // wide vectors to avoid AVX <-> SSE transition penalty during call.
  1882       MacroAssembler _masm(&cbuf);
  1883       __ vzeroupper();
  1885     debug_only(int off1 = cbuf.insts_size());
  1886     assert(off1 - off0 == pre_call_resets_size(), "correct size prediction");
  1887   %}
  1889   enc_class post_call_FPU %{
  1890     // If method sets FPU control word do it here also
  1891     if (Compile::current()->in_24_bit_fp_mode()) {
  1892       MacroAssembler masm(&cbuf);
  1893       masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
  1895   %}
  1897   enc_class Java_Static_Call (method meth) %{    // JAVA STATIC CALL
  1898     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
  1899     // who we intended to call.
  1900     cbuf.set_insts_mark();
  1901     $$$emit8$primary;
  1902     if (!_method) {
  1903       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1904                      runtime_call_Relocation::spec(), RELOC_IMM32 );
  1905     } else if (_optimized_virtual) {
  1906       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1907                      opt_virtual_call_Relocation::spec(), RELOC_IMM32 );
  1908     } else {
  1909       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1910                      static_call_Relocation::spec(), RELOC_IMM32 );
  1912     if (_method) {  // Emit stub for static call
  1913       emit_java_to_interp(cbuf);
  1915   %}
  1917   enc_class Java_Dynamic_Call (method meth) %{    // JAVA DYNAMIC CALL
  1918     MacroAssembler _masm(&cbuf);
  1919     __ ic_call((address)$meth$$method);
  1920   %}
  1922   enc_class Java_Compiled_Call (method meth) %{    // JAVA COMPILED CALL
  1923     int disp = in_bytes(Method::from_compiled_offset());
  1924     assert( -128 <= disp && disp <= 127, "compiled_code_offset isn't small");
  1926     // CALL *[EAX+in_bytes(Method::from_compiled_code_entry_point_offset())]
  1927     cbuf.set_insts_mark();
  1928     $$$emit8$primary;
  1929     emit_rm(cbuf, 0x01, $secondary, EAX_enc );  // R/M byte
  1930     emit_d8(cbuf, disp);             // Displacement
  1932   %}
  1934 //   Following encoding is no longer used, but may be restored if calling
  1935 //   convention changes significantly.
  1936 //   Became: Xor_Reg(EBP), Java_To_Runtime( labl )
  1937 //
  1938 //   enc_class Java_Interpreter_Call (label labl) %{    // JAVA INTERPRETER CALL
  1939 //     // int ic_reg     = Matcher::inline_cache_reg();
  1940 //     // int ic_encode  = Matcher::_regEncode[ic_reg];
  1941 //     // int imo_reg    = Matcher::interpreter_method_oop_reg();
  1942 //     // int imo_encode = Matcher::_regEncode[imo_reg];
  1943 //
  1944 //     // // Interpreter expects method_oop in EBX, currently a callee-saved register,
  1945 //     // // so we load it immediately before the call
  1946 //     // emit_opcode(cbuf, 0x8B);                     // MOV    imo_reg,ic_reg  # method_oop
  1947 //     // emit_rm(cbuf, 0x03, imo_encode, ic_encode ); // R/M byte
  1948 //
  1949 //     // xor rbp,ebp
  1950 //     emit_opcode(cbuf, 0x33);
  1951 //     emit_rm(cbuf, 0x3, EBP_enc, EBP_enc);
  1952 //
  1953 //     // CALL to interpreter.
  1954 //     cbuf.set_insts_mark();
  1955 //     $$$emit8$primary;
  1956 //     emit_d32_reloc(cbuf, ($labl$$label - (int)(cbuf.insts_end()) - 4),
  1957 //                 runtime_call_Relocation::spec(), RELOC_IMM32 );
  1958 //   %}
  1960   enc_class RegOpcImm (rRegI dst, immI8 shift) %{    // SHL, SAR, SHR
  1961     $$$emit8$primary;
  1962     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1963     $$$emit8$shift$$constant;
  1964   %}
  1966   enc_class LdImmI (rRegI dst, immI src) %{    // Load Immediate
  1967     // Load immediate does not have a zero or sign extended version
  1968     // for 8-bit immediates
  1969     emit_opcode(cbuf, 0xB8 + $dst$$reg);
  1970     $$$emit32$src$$constant;
  1971   %}
  1973   enc_class LdImmP (rRegI dst, immI src) %{    // Load Immediate
  1974     // Load immediate does not have a zero or sign extended version
  1975     // for 8-bit immediates
  1976     emit_opcode(cbuf, $primary + $dst$$reg);
  1977     $$$emit32$src$$constant;
  1978   %}
  1980   enc_class LdImmL_Lo( eRegL dst, immL src) %{    // Load Immediate
  1981     // Load immediate does not have a zero or sign extended version
  1982     // for 8-bit immediates
  1983     int dst_enc = $dst$$reg;
  1984     int src_con = $src$$constant & 0x0FFFFFFFFL;
  1985     if (src_con == 0) {
  1986       // xor dst, dst
  1987       emit_opcode(cbuf, 0x33);
  1988       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
  1989     } else {
  1990       emit_opcode(cbuf, $primary + dst_enc);
  1991       emit_d32(cbuf, src_con);
  1993   %}
  1995   enc_class LdImmL_Hi( eRegL dst, immL src) %{    // Load Immediate
  1996     // Load immediate does not have a zero or sign extended version
  1997     // for 8-bit immediates
  1998     int dst_enc = $dst$$reg + 2;
  1999     int src_con = ((julong)($src$$constant)) >> 32;
  2000     if (src_con == 0) {
  2001       // xor dst, dst
  2002       emit_opcode(cbuf, 0x33);
  2003       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
  2004     } else {
  2005       emit_opcode(cbuf, $primary + dst_enc);
  2006       emit_d32(cbuf, src_con);
  2008   %}
  2011   // Encode a reg-reg copy.  If it is useless, then empty encoding.
  2012   enc_class enc_Copy( rRegI dst, rRegI src ) %{
  2013     encode_Copy( cbuf, $dst$$reg, $src$$reg );
  2014   %}
  2016   enc_class enc_CopyL_Lo( rRegI dst, eRegL src ) %{
  2017     encode_Copy( cbuf, $dst$$reg, $src$$reg );
  2018   %}
  2020   enc_class RegReg (rRegI dst, rRegI src) %{    // RegReg(Many)
  2021     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2022   %}
  2024   enc_class RegReg_Lo(eRegL dst, eRegL src) %{    // RegReg(Many)
  2025     $$$emit8$primary;
  2026     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2027   %}
  2029   enc_class RegReg_Hi(eRegL dst, eRegL src) %{    // RegReg(Many)
  2030     $$$emit8$secondary;
  2031     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
  2032   %}
  2034   enc_class RegReg_Lo2(eRegL dst, eRegL src) %{    // RegReg(Many)
  2035     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2036   %}
  2038   enc_class RegReg_Hi2(eRegL dst, eRegL src) %{    // RegReg(Many)
  2039     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
  2040   %}
  2042   enc_class RegReg_HiLo( eRegL src, rRegI dst ) %{
  2043     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($src$$reg));
  2044   %}
  2046   enc_class Con32 (immI src) %{    // Con32(storeImmI)
  2047     // Output immediate
  2048     $$$emit32$src$$constant;
  2049   %}
  2051   enc_class Con32FPR_as_bits(immFPR src) %{        // storeF_imm
  2052     // Output Float immediate bits
  2053     jfloat jf = $src$$constant;
  2054     int    jf_as_bits = jint_cast( jf );
  2055     emit_d32(cbuf, jf_as_bits);
  2056   %}
  2058   enc_class Con32F_as_bits(immF src) %{      // storeX_imm
  2059     // Output Float immediate bits
  2060     jfloat jf = $src$$constant;
  2061     int    jf_as_bits = jint_cast( jf );
  2062     emit_d32(cbuf, jf_as_bits);
  2063   %}
  2065   enc_class Con16 (immI src) %{    // Con16(storeImmI)
  2066     // Output immediate
  2067     $$$emit16$src$$constant;
  2068   %}
  2070   enc_class Con_d32(immI src) %{
  2071     emit_d32(cbuf,$src$$constant);
  2072   %}
  2074   enc_class conmemref (eRegP t1) %{    // Con32(storeImmI)
  2075     // Output immediate memory reference
  2076     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
  2077     emit_d32(cbuf, 0x00);
  2078   %}
  2080   enc_class lock_prefix( ) %{
  2081     if( os::is_MP() )
  2082       emit_opcode(cbuf,0xF0);         // [Lock]
  2083   %}
  2085   // Cmp-xchg long value.
  2086   // Note: we need to swap rbx, and rcx before and after the
  2087   //       cmpxchg8 instruction because the instruction uses
  2088   //       rcx as the high order word of the new value to store but
  2089   //       our register encoding uses rbx,.
  2090   enc_class enc_cmpxchg8(eSIRegP mem_ptr) %{
  2092     // XCHG  rbx,ecx
  2093     emit_opcode(cbuf,0x87);
  2094     emit_opcode(cbuf,0xD9);
  2095     // [Lock]
  2096     if( os::is_MP() )
  2097       emit_opcode(cbuf,0xF0);
  2098     // CMPXCHG8 [Eptr]
  2099     emit_opcode(cbuf,0x0F);
  2100     emit_opcode(cbuf,0xC7);
  2101     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
  2102     // XCHG  rbx,ecx
  2103     emit_opcode(cbuf,0x87);
  2104     emit_opcode(cbuf,0xD9);
  2105   %}
  2107   enc_class enc_cmpxchg(eSIRegP mem_ptr) %{
  2108     // [Lock]
  2109     if( os::is_MP() )
  2110       emit_opcode(cbuf,0xF0);
  2112     // CMPXCHG [Eptr]
  2113     emit_opcode(cbuf,0x0F);
  2114     emit_opcode(cbuf,0xB1);
  2115     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
  2116   %}
  2118   enc_class enc_flags_ne_to_boolean( iRegI res ) %{
  2119     int res_encoding = $res$$reg;
  2121     // MOV  res,0
  2122     emit_opcode( cbuf, 0xB8 + res_encoding);
  2123     emit_d32( cbuf, 0 );
  2124     // JNE,s  fail
  2125     emit_opcode(cbuf,0x75);
  2126     emit_d8(cbuf, 5 );
  2127     // MOV  res,1
  2128     emit_opcode( cbuf, 0xB8 + res_encoding);
  2129     emit_d32( cbuf, 1 );
  2130     // fail:
  2131   %}
  2133   enc_class set_instruction_start( ) %{
  2134     cbuf.set_insts_mark();            // Mark start of opcode for reloc info in mem operand
  2135   %}
  2137   enc_class RegMem (rRegI ereg, memory mem) %{    // emit_reg_mem
  2138     int reg_encoding = $ereg$$reg;
  2139     int base  = $mem$$base;
  2140     int index = $mem$$index;
  2141     int scale = $mem$$scale;
  2142     int displace = $mem$$disp;
  2143     relocInfo::relocType disp_reloc = $mem->disp_reloc();
  2144     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
  2145   %}
  2147   enc_class RegMem_Hi(eRegL ereg, memory mem) %{    // emit_reg_mem
  2148     int reg_encoding = HIGH_FROM_LOW($ereg$$reg);  // Hi register of pair, computed from lo
  2149     int base  = $mem$$base;
  2150     int index = $mem$$index;
  2151     int scale = $mem$$scale;
  2152     int displace = $mem$$disp + 4;      // Offset is 4 further in memory
  2153     assert( $mem->disp_reloc() == relocInfo::none, "Cannot add 4 to oop" );
  2154     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, relocInfo::none);
  2155   %}
  2157   enc_class move_long_small_shift( eRegL dst, immI_1_31 cnt ) %{
  2158     int r1, r2;
  2159     if( $tertiary == 0xA4 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
  2160     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
  2161     emit_opcode(cbuf,0x0F);
  2162     emit_opcode(cbuf,$tertiary);
  2163     emit_rm(cbuf, 0x3, r1, r2);
  2164     emit_d8(cbuf,$cnt$$constant);
  2165     emit_d8(cbuf,$primary);
  2166     emit_rm(cbuf, 0x3, $secondary, r1);
  2167     emit_d8(cbuf,$cnt$$constant);
  2168   %}
  2170   enc_class move_long_big_shift_sign( eRegL dst, immI_32_63 cnt ) %{
  2171     emit_opcode( cbuf, 0x8B ); // Move
  2172     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
  2173     if( $cnt$$constant > 32 ) { // Shift, if not by zero
  2174       emit_d8(cbuf,$primary);
  2175       emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  2176       emit_d8(cbuf,$cnt$$constant-32);
  2178     emit_d8(cbuf,$primary);
  2179     emit_rm(cbuf, 0x3, $secondary, HIGH_FROM_LOW($dst$$reg));
  2180     emit_d8(cbuf,31);
  2181   %}
  2183   enc_class move_long_big_shift_clr( eRegL dst, immI_32_63 cnt ) %{
  2184     int r1, r2;
  2185     if( $secondary == 0x5 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
  2186     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
  2188     emit_opcode( cbuf, 0x8B ); // Move r1,r2
  2189     emit_rm(cbuf, 0x3, r1, r2);
  2190     if( $cnt$$constant > 32 ) { // Shift, if not by zero
  2191       emit_opcode(cbuf,$primary);
  2192       emit_rm(cbuf, 0x3, $secondary, r1);
  2193       emit_d8(cbuf,$cnt$$constant-32);
  2195     emit_opcode(cbuf,0x33);  // XOR r2,r2
  2196     emit_rm(cbuf, 0x3, r2, r2);
  2197   %}
  2199   // Clone of RegMem but accepts an extra parameter to access each
  2200   // half of a double in memory; it never needs relocation info.
  2201   enc_class Mov_MemD_half_to_Reg (immI opcode, memory mem, immI disp_for_half, rRegI rm_reg) %{
  2202     emit_opcode(cbuf,$opcode$$constant);
  2203     int reg_encoding = $rm_reg$$reg;
  2204     int base     = $mem$$base;
  2205     int index    = $mem$$index;
  2206     int scale    = $mem$$scale;
  2207     int displace = $mem$$disp + $disp_for_half$$constant;
  2208     relocInfo::relocType disp_reloc = relocInfo::none;
  2209     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
  2210   %}
  2212   // !!!!! Special Custom Code used by MemMove, and stack access instructions !!!!!
  2213   //
  2214   // Clone of RegMem except the RM-byte's reg/opcode field is an ADLC-time constant
  2215   // and it never needs relocation information.
  2216   // Frequently used to move data between FPU's Stack Top and memory.
  2217   enc_class RMopc_Mem_no_oop (immI rm_opcode, memory mem) %{
  2218     int rm_byte_opcode = $rm_opcode$$constant;
  2219     int base     = $mem$$base;
  2220     int index    = $mem$$index;
  2221     int scale    = $mem$$scale;
  2222     int displace = $mem$$disp;
  2223     assert( $mem->disp_reloc() == relocInfo::none, "No oops here because no reloc info allowed" );
  2224     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, relocInfo::none);
  2225   %}
  2227   enc_class RMopc_Mem (immI rm_opcode, memory mem) %{
  2228     int rm_byte_opcode = $rm_opcode$$constant;
  2229     int base     = $mem$$base;
  2230     int index    = $mem$$index;
  2231     int scale    = $mem$$scale;
  2232     int displace = $mem$$disp;
  2233     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
  2234     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
  2235   %}
  2237   enc_class RegLea (rRegI dst, rRegI src0, immI src1 ) %{    // emit_reg_lea
  2238     int reg_encoding = $dst$$reg;
  2239     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
  2240     int index        = 0x04;            // 0x04 indicates no index
  2241     int scale        = 0x00;            // 0x00 indicates no scale
  2242     int displace     = $src1$$constant; // 0x00 indicates no displacement
  2243     relocInfo::relocType disp_reloc = relocInfo::none;
  2244     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
  2245   %}
  2247   enc_class min_enc (rRegI dst, rRegI src) %{    // MIN
  2248     // Compare dst,src
  2249     emit_opcode(cbuf,0x3B);
  2250     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2251     // jmp dst < src around move
  2252     emit_opcode(cbuf,0x7C);
  2253     emit_d8(cbuf,2);
  2254     // move dst,src
  2255     emit_opcode(cbuf,0x8B);
  2256     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2257   %}
  2259   enc_class max_enc (rRegI dst, rRegI src) %{    // MAX
  2260     // Compare dst,src
  2261     emit_opcode(cbuf,0x3B);
  2262     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2263     // jmp dst > src around move
  2264     emit_opcode(cbuf,0x7F);
  2265     emit_d8(cbuf,2);
  2266     // move dst,src
  2267     emit_opcode(cbuf,0x8B);
  2268     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2269   %}
  2271   enc_class enc_FPR_store(memory mem, regDPR src) %{
  2272     // If src is FPR1, we can just FST to store it.
  2273     // Else we need to FLD it to FPR1, then FSTP to store/pop it.
  2274     int reg_encoding = 0x2; // Just store
  2275     int base  = $mem$$base;
  2276     int index = $mem$$index;
  2277     int scale = $mem$$scale;
  2278     int displace = $mem$$disp;
  2279     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
  2280     if( $src$$reg != FPR1L_enc ) {
  2281       reg_encoding = 0x3;  // Store & pop
  2282       emit_opcode( cbuf, 0xD9 ); // FLD (i.e., push it)
  2283       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2285     cbuf.set_insts_mark();       // Mark start of opcode for reloc info in mem operand
  2286     emit_opcode(cbuf,$primary);
  2287     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_reloc);
  2288   %}
  2290   enc_class neg_reg(rRegI dst) %{
  2291     // NEG $dst
  2292     emit_opcode(cbuf,0xF7);
  2293     emit_rm(cbuf, 0x3, 0x03, $dst$$reg );
  2294   %}
  2296   enc_class setLT_reg(eCXRegI dst) %{
  2297     // SETLT $dst
  2298     emit_opcode(cbuf,0x0F);
  2299     emit_opcode(cbuf,0x9C);
  2300     emit_rm( cbuf, 0x3, 0x4, $dst$$reg );
  2301   %}
  2303   enc_class enc_cmpLTP(ncxRegI p, ncxRegI q, ncxRegI y, eCXRegI tmp) %{    // cadd_cmpLT
  2304     int tmpReg = $tmp$$reg;
  2306     // SUB $p,$q
  2307     emit_opcode(cbuf,0x2B);
  2308     emit_rm(cbuf, 0x3, $p$$reg, $q$$reg);
  2309     // SBB $tmp,$tmp
  2310     emit_opcode(cbuf,0x1B);
  2311     emit_rm(cbuf, 0x3, tmpReg, tmpReg);
  2312     // AND $tmp,$y
  2313     emit_opcode(cbuf,0x23);
  2314     emit_rm(cbuf, 0x3, tmpReg, $y$$reg);
  2315     // ADD $p,$tmp
  2316     emit_opcode(cbuf,0x03);
  2317     emit_rm(cbuf, 0x3, $p$$reg, tmpReg);
  2318   %}
  2320   enc_class shift_left_long( eRegL dst, eCXRegI shift ) %{
  2321     // TEST shift,32
  2322     emit_opcode(cbuf,0xF7);
  2323     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2324     emit_d32(cbuf,0x20);
  2325     // JEQ,s small
  2326     emit_opcode(cbuf, 0x74);
  2327     emit_d8(cbuf, 0x04);
  2328     // MOV    $dst.hi,$dst.lo
  2329     emit_opcode( cbuf, 0x8B );
  2330     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
  2331     // CLR    $dst.lo
  2332     emit_opcode(cbuf, 0x33);
  2333     emit_rm(cbuf, 0x3, $dst$$reg, $dst$$reg);
  2334 // small:
  2335     // SHLD   $dst.hi,$dst.lo,$shift
  2336     emit_opcode(cbuf,0x0F);
  2337     emit_opcode(cbuf,0xA5);
  2338     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
  2339     // SHL    $dst.lo,$shift"
  2340     emit_opcode(cbuf,0xD3);
  2341     emit_rm(cbuf, 0x3, 0x4, $dst$$reg );
  2342   %}
  2344   enc_class shift_right_long( eRegL dst, eCXRegI shift ) %{
  2345     // TEST shift,32
  2346     emit_opcode(cbuf,0xF7);
  2347     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2348     emit_d32(cbuf,0x20);
  2349     // JEQ,s small
  2350     emit_opcode(cbuf, 0x74);
  2351     emit_d8(cbuf, 0x04);
  2352     // MOV    $dst.lo,$dst.hi
  2353     emit_opcode( cbuf, 0x8B );
  2354     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
  2355     // CLR    $dst.hi
  2356     emit_opcode(cbuf, 0x33);
  2357     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($dst$$reg));
  2358 // small:
  2359     // SHRD   $dst.lo,$dst.hi,$shift
  2360     emit_opcode(cbuf,0x0F);
  2361     emit_opcode(cbuf,0xAD);
  2362     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
  2363     // SHR    $dst.hi,$shift"
  2364     emit_opcode(cbuf,0xD3);
  2365     emit_rm(cbuf, 0x3, 0x5, HIGH_FROM_LOW($dst$$reg) );
  2366   %}
  2368   enc_class shift_right_arith_long( eRegL dst, eCXRegI shift ) %{
  2369     // TEST shift,32
  2370     emit_opcode(cbuf,0xF7);
  2371     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2372     emit_d32(cbuf,0x20);
  2373     // JEQ,s small
  2374     emit_opcode(cbuf, 0x74);
  2375     emit_d8(cbuf, 0x05);
  2376     // MOV    $dst.lo,$dst.hi
  2377     emit_opcode( cbuf, 0x8B );
  2378     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
  2379     // SAR    $dst.hi,31
  2380     emit_opcode(cbuf, 0xC1);
  2381     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW($dst$$reg) );
  2382     emit_d8(cbuf, 0x1F );
  2383 // small:
  2384     // SHRD   $dst.lo,$dst.hi,$shift
  2385     emit_opcode(cbuf,0x0F);
  2386     emit_opcode(cbuf,0xAD);
  2387     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
  2388     // SAR    $dst.hi,$shift"
  2389     emit_opcode(cbuf,0xD3);
  2390     emit_rm(cbuf, 0x3, 0x7, HIGH_FROM_LOW($dst$$reg) );
  2391   %}
  2394   // ----------------- Encodings for floating point unit -----------------
  2395   // May leave result in FPU-TOS or FPU reg depending on opcodes
  2396   enc_class OpcReg_FPR(regFPR src) %{    // FMUL, FDIV
  2397     $$$emit8$primary;
  2398     emit_rm(cbuf, 0x3, $secondary, $src$$reg );
  2399   %}
  2401   // Pop argument in FPR0 with FSTP ST(0)
  2402   enc_class PopFPU() %{
  2403     emit_opcode( cbuf, 0xDD );
  2404     emit_d8( cbuf, 0xD8 );
  2405   %}
  2407   // !!!!! equivalent to Pop_Reg_F
  2408   enc_class Pop_Reg_DPR( regDPR dst ) %{
  2409     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
  2410     emit_d8( cbuf, 0xD8+$dst$$reg );
  2411   %}
  2413   enc_class Push_Reg_DPR( regDPR dst ) %{
  2414     emit_opcode( cbuf, 0xD9 );
  2415     emit_d8( cbuf, 0xC0-1+$dst$$reg );   // FLD ST(i-1)
  2416   %}
  2418   enc_class strictfp_bias1( regDPR dst ) %{
  2419     emit_opcode( cbuf, 0xDB );           // FLD m80real
  2420     emit_opcode( cbuf, 0x2D );
  2421     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias1() );
  2422     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
  2423     emit_opcode( cbuf, 0xC8+$dst$$reg );
  2424   %}
  2426   enc_class strictfp_bias2( regDPR dst ) %{
  2427     emit_opcode( cbuf, 0xDB );           // FLD m80real
  2428     emit_opcode( cbuf, 0x2D );
  2429     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias2() );
  2430     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
  2431     emit_opcode( cbuf, 0xC8+$dst$$reg );
  2432   %}
  2434   // Special case for moving an integer register to a stack slot.
  2435   enc_class OpcPRegSS( stackSlotI dst, rRegI src ) %{ // RegSS
  2436     store_to_stackslot( cbuf, $primary, $src$$reg, $dst$$disp );
  2437   %}
  2439   // Special case for moving a register to a stack slot.
  2440   enc_class RegSS( stackSlotI dst, rRegI src ) %{ // RegSS
  2441     // Opcode already emitted
  2442     emit_rm( cbuf, 0x02, $src$$reg, ESP_enc );   // R/M byte
  2443     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);          // SIB byte
  2444     emit_d32(cbuf, $dst$$disp);   // Displacement
  2445   %}
  2447   // Push the integer in stackSlot 'src' onto FP-stack
  2448   enc_class Push_Mem_I( memory src ) %{    // FILD   [ESP+src]
  2449     store_to_stackslot( cbuf, $primary, $secondary, $src$$disp );
  2450   %}
  2452   // Push FPU's TOS float to a stack-slot, and pop FPU-stack
  2453   enc_class Pop_Mem_FPR( stackSlotF dst ) %{ // FSTP_S [ESP+dst]
  2454     store_to_stackslot( cbuf, 0xD9, 0x03, $dst$$disp );
  2455   %}
  2457   // Same as Pop_Mem_F except for opcode
  2458   // Push FPU's TOS double to a stack-slot, and pop FPU-stack
  2459   enc_class Pop_Mem_DPR( stackSlotD dst ) %{ // FSTP_D [ESP+dst]
  2460     store_to_stackslot( cbuf, 0xDD, 0x03, $dst$$disp );
  2461   %}
  2463   enc_class Pop_Reg_FPR( regFPR dst ) %{
  2464     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
  2465     emit_d8( cbuf, 0xD8+$dst$$reg );
  2466   %}
  2468   enc_class Push_Reg_FPR( regFPR dst ) %{
  2469     emit_opcode( cbuf, 0xD9 );           // FLD    ST(i-1)
  2470     emit_d8( cbuf, 0xC0-1+$dst$$reg );
  2471   %}
  2473   // Push FPU's float to a stack-slot, and pop FPU-stack
  2474   enc_class Pop_Mem_Reg_FPR( stackSlotF dst, regFPR src ) %{
  2475     int pop = 0x02;
  2476     if ($src$$reg != FPR1L_enc) {
  2477       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
  2478       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2479       pop = 0x03;
  2481     store_to_stackslot( cbuf, 0xD9, pop, $dst$$disp ); // FST<P>_S  [ESP+dst]
  2482   %}
  2484   // Push FPU's double to a stack-slot, and pop FPU-stack
  2485   enc_class Pop_Mem_Reg_DPR( stackSlotD dst, regDPR src ) %{
  2486     int pop = 0x02;
  2487     if ($src$$reg != FPR1L_enc) {
  2488       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
  2489       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2490       pop = 0x03;
  2492     store_to_stackslot( cbuf, 0xDD, pop, $dst$$disp ); // FST<P>_D  [ESP+dst]
  2493   %}
  2495   // Push FPU's double to a FPU-stack-slot, and pop FPU-stack
  2496   enc_class Pop_Reg_Reg_DPR( regDPR dst, regFPR src ) %{
  2497     int pop = 0xD0 - 1; // -1 since we skip FLD
  2498     if ($src$$reg != FPR1L_enc) {
  2499       emit_opcode( cbuf, 0xD9 );         // FLD    ST(src-1)
  2500       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2501       pop = 0xD8;
  2503     emit_opcode( cbuf, 0xDD );
  2504     emit_d8( cbuf, pop+$dst$$reg );      // FST<P> ST(i)
  2505   %}
  2508   enc_class Push_Reg_Mod_DPR( regDPR dst, regDPR src) %{
  2509     // load dst in FPR0
  2510     emit_opcode( cbuf, 0xD9 );
  2511     emit_d8( cbuf, 0xC0-1+$dst$$reg );
  2512     if ($src$$reg != FPR1L_enc) {
  2513       // fincstp
  2514       emit_opcode (cbuf, 0xD9);
  2515       emit_opcode (cbuf, 0xF7);
  2516       // swap src with FPR1:
  2517       // FXCH FPR1 with src
  2518       emit_opcode(cbuf, 0xD9);
  2519       emit_d8(cbuf, 0xC8-1+$src$$reg );
  2520       // fdecstp
  2521       emit_opcode (cbuf, 0xD9);
  2522       emit_opcode (cbuf, 0xF6);
  2524   %}
  2526   enc_class Push_ModD_encoding(regD src0, regD src1) %{
  2527     MacroAssembler _masm(&cbuf);
  2528     __ subptr(rsp, 8);
  2529     __ movdbl(Address(rsp, 0), $src1$$XMMRegister);
  2530     __ fld_d(Address(rsp, 0));
  2531     __ movdbl(Address(rsp, 0), $src0$$XMMRegister);
  2532     __ fld_d(Address(rsp, 0));
  2533   %}
  2535   enc_class Push_ModF_encoding(regF src0, regF src1) %{
  2536     MacroAssembler _masm(&cbuf);
  2537     __ subptr(rsp, 4);
  2538     __ movflt(Address(rsp, 0), $src1$$XMMRegister);
  2539     __ fld_s(Address(rsp, 0));
  2540     __ movflt(Address(rsp, 0), $src0$$XMMRegister);
  2541     __ fld_s(Address(rsp, 0));
  2542   %}
  2544   enc_class Push_ResultD(regD dst) %{
  2545     MacroAssembler _masm(&cbuf);
  2546     __ fstp_d(Address(rsp, 0));
  2547     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
  2548     __ addptr(rsp, 8);
  2549   %}
  2551   enc_class Push_ResultF(regF dst, immI d8) %{
  2552     MacroAssembler _masm(&cbuf);
  2553     __ fstp_s(Address(rsp, 0));
  2554     __ movflt($dst$$XMMRegister, Address(rsp, 0));
  2555     __ addptr(rsp, $d8$$constant);
  2556   %}
  2558   enc_class Push_SrcD(regD src) %{
  2559     MacroAssembler _masm(&cbuf);
  2560     __ subptr(rsp, 8);
  2561     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
  2562     __ fld_d(Address(rsp, 0));
  2563   %}
  2565   enc_class push_stack_temp_qword() %{
  2566     MacroAssembler _masm(&cbuf);
  2567     __ subptr(rsp, 8);
  2568   %}
  2570   enc_class pop_stack_temp_qword() %{
  2571     MacroAssembler _masm(&cbuf);
  2572     __ addptr(rsp, 8);
  2573   %}
  2575   enc_class push_xmm_to_fpr1(regD src) %{
  2576     MacroAssembler _masm(&cbuf);
  2577     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
  2578     __ fld_d(Address(rsp, 0));
  2579   %}
  2581   enc_class Push_Result_Mod_DPR( regDPR src) %{
  2582     if ($src$$reg != FPR1L_enc) {
  2583       // fincstp
  2584       emit_opcode (cbuf, 0xD9);
  2585       emit_opcode (cbuf, 0xF7);
  2586       // FXCH FPR1 with src
  2587       emit_opcode(cbuf, 0xD9);
  2588       emit_d8(cbuf, 0xC8-1+$src$$reg );
  2589       // fdecstp
  2590       emit_opcode (cbuf, 0xD9);
  2591       emit_opcode (cbuf, 0xF6);
  2593     // // following asm replaced with Pop_Reg_F or Pop_Mem_F
  2594     // // FSTP   FPR$dst$$reg
  2595     // emit_opcode( cbuf, 0xDD );
  2596     // emit_d8( cbuf, 0xD8+$dst$$reg );
  2597   %}
  2599   enc_class fnstsw_sahf_skip_parity() %{
  2600     // fnstsw ax
  2601     emit_opcode( cbuf, 0xDF );
  2602     emit_opcode( cbuf, 0xE0 );
  2603     // sahf
  2604     emit_opcode( cbuf, 0x9E );
  2605     // jnp  ::skip
  2606     emit_opcode( cbuf, 0x7B );
  2607     emit_opcode( cbuf, 0x05 );
  2608   %}
  2610   enc_class emitModDPR() %{
  2611     // fprem must be iterative
  2612     // :: loop
  2613     // fprem
  2614     emit_opcode( cbuf, 0xD9 );
  2615     emit_opcode( cbuf, 0xF8 );
  2616     // wait
  2617     emit_opcode( cbuf, 0x9b );
  2618     // fnstsw ax
  2619     emit_opcode( cbuf, 0xDF );
  2620     emit_opcode( cbuf, 0xE0 );
  2621     // sahf
  2622     emit_opcode( cbuf, 0x9E );
  2623     // jp  ::loop
  2624     emit_opcode( cbuf, 0x0F );
  2625     emit_opcode( cbuf, 0x8A );
  2626     emit_opcode( cbuf, 0xF4 );
  2627     emit_opcode( cbuf, 0xFF );
  2628     emit_opcode( cbuf, 0xFF );
  2629     emit_opcode( cbuf, 0xFF );
  2630   %}
  2632   enc_class fpu_flags() %{
  2633     // fnstsw_ax
  2634     emit_opcode( cbuf, 0xDF);
  2635     emit_opcode( cbuf, 0xE0);
  2636     // test ax,0x0400
  2637     emit_opcode( cbuf, 0x66 );   // operand-size prefix for 16-bit immediate
  2638     emit_opcode( cbuf, 0xA9 );
  2639     emit_d16   ( cbuf, 0x0400 );
  2640     // // // This sequence works, but stalls for 12-16 cycles on PPro
  2641     // // test rax,0x0400
  2642     // emit_opcode( cbuf, 0xA9 );
  2643     // emit_d32   ( cbuf, 0x00000400 );
  2644     //
  2645     // jz exit (no unordered comparison)
  2646     emit_opcode( cbuf, 0x74 );
  2647     emit_d8    ( cbuf, 0x02 );
  2648     // mov ah,1 - treat as LT case (set carry flag)
  2649     emit_opcode( cbuf, 0xB4 );
  2650     emit_d8    ( cbuf, 0x01 );
  2651     // sahf
  2652     emit_opcode( cbuf, 0x9E);
  2653   %}
  2655   enc_class cmpF_P6_fixup() %{
  2656     // Fixup the integer flags in case comparison involved a NaN
  2657     //
  2658     // JNP exit (no unordered comparison, P-flag is set by NaN)
  2659     emit_opcode( cbuf, 0x7B );
  2660     emit_d8    ( cbuf, 0x03 );
  2661     // MOV AH,1 - treat as LT case (set carry flag)
  2662     emit_opcode( cbuf, 0xB4 );
  2663     emit_d8    ( cbuf, 0x01 );
  2664     // SAHF
  2665     emit_opcode( cbuf, 0x9E);
  2666     // NOP     // target for branch to avoid branch to branch
  2667     emit_opcode( cbuf, 0x90);
  2668   %}
  2670 //     fnstsw_ax();
  2671 //     sahf();
  2672 //     movl(dst, nan_result);
  2673 //     jcc(Assembler::parity, exit);
  2674 //     movl(dst, less_result);
  2675 //     jcc(Assembler::below, exit);
  2676 //     movl(dst, equal_result);
  2677 //     jcc(Assembler::equal, exit);
  2678 //     movl(dst, greater_result);
  2680 // less_result     =  1;
  2681 // greater_result  = -1;
  2682 // equal_result    = 0;
  2683 // nan_result      = -1;
  2685   enc_class CmpF_Result(rRegI dst) %{
  2686     // fnstsw_ax();
  2687     emit_opcode( cbuf, 0xDF);
  2688     emit_opcode( cbuf, 0xE0);
  2689     // sahf
  2690     emit_opcode( cbuf, 0x9E);
  2691     // movl(dst, nan_result);
  2692     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2693     emit_d32( cbuf, -1 );
  2694     // jcc(Assembler::parity, exit);
  2695     emit_opcode( cbuf, 0x7A );
  2696     emit_d8    ( cbuf, 0x13 );
  2697     // movl(dst, less_result);
  2698     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2699     emit_d32( cbuf, -1 );
  2700     // jcc(Assembler::below, exit);
  2701     emit_opcode( cbuf, 0x72 );
  2702     emit_d8    ( cbuf, 0x0C );
  2703     // movl(dst, equal_result);
  2704     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2705     emit_d32( cbuf, 0 );
  2706     // jcc(Assembler::equal, exit);
  2707     emit_opcode( cbuf, 0x74 );
  2708     emit_d8    ( cbuf, 0x05 );
  2709     // movl(dst, greater_result);
  2710     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2711     emit_d32( cbuf, 1 );
  2712   %}
  2715   // Compare the longs and set flags
  2716   // BROKEN!  Do Not use as-is
  2717   enc_class cmpl_test( eRegL src1, eRegL src2 ) %{
  2718     // CMP    $src1.hi,$src2.hi
  2719     emit_opcode( cbuf, 0x3B );
  2720     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
  2721     // JNE,s  done
  2722     emit_opcode(cbuf,0x75);
  2723     emit_d8(cbuf, 2 );
  2724     // CMP    $src1.lo,$src2.lo
  2725     emit_opcode( cbuf, 0x3B );
  2726     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  2727 // done:
  2728   %}
  2730   enc_class convert_int_long( regL dst, rRegI src ) %{
  2731     // mov $dst.lo,$src
  2732     int dst_encoding = $dst$$reg;
  2733     int src_encoding = $src$$reg;
  2734     encode_Copy( cbuf, dst_encoding  , src_encoding );
  2735     // mov $dst.hi,$src
  2736     encode_Copy( cbuf, HIGH_FROM_LOW(dst_encoding), src_encoding );
  2737     // sar $dst.hi,31
  2738     emit_opcode( cbuf, 0xC1 );
  2739     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW(dst_encoding) );
  2740     emit_d8(cbuf, 0x1F );
  2741   %}
  2743   enc_class convert_long_double( eRegL src ) %{
  2744     // push $src.hi
  2745     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
  2746     // push $src.lo
  2747     emit_opcode(cbuf, 0x50+$src$$reg  );
  2748     // fild 64-bits at [SP]
  2749     emit_opcode(cbuf,0xdf);
  2750     emit_d8(cbuf, 0x6C);
  2751     emit_d8(cbuf, 0x24);
  2752     emit_d8(cbuf, 0x00);
  2753     // pop stack
  2754     emit_opcode(cbuf, 0x83); // add  SP, #8
  2755     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  2756     emit_d8(cbuf, 0x8);
  2757   %}
  2759   enc_class multiply_con_and_shift_high( eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr ) %{
  2760     // IMUL   EDX:EAX,$src1
  2761     emit_opcode( cbuf, 0xF7 );
  2762     emit_rm( cbuf, 0x3, 0x5, $src1$$reg );
  2763     // SAR    EDX,$cnt-32
  2764     int shift_count = ((int)$cnt$$constant) - 32;
  2765     if (shift_count > 0) {
  2766       emit_opcode(cbuf, 0xC1);
  2767       emit_rm(cbuf, 0x3, 7, $dst$$reg );
  2768       emit_d8(cbuf, shift_count);
  2770   %}
  2772   // this version doesn't have add sp, 8
  2773   enc_class convert_long_double2( eRegL src ) %{
  2774     // push $src.hi
  2775     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
  2776     // push $src.lo
  2777     emit_opcode(cbuf, 0x50+$src$$reg  );
  2778     // fild 64-bits at [SP]
  2779     emit_opcode(cbuf,0xdf);
  2780     emit_d8(cbuf, 0x6C);
  2781     emit_d8(cbuf, 0x24);
  2782     emit_d8(cbuf, 0x00);
  2783   %}
  2785   enc_class long_int_multiply( eADXRegL dst, nadxRegI src) %{
  2786     // Basic idea: long = (long)int * (long)int
  2787     // IMUL EDX:EAX, src
  2788     emit_opcode( cbuf, 0xF7 );
  2789     emit_rm( cbuf, 0x3, 0x5, $src$$reg);
  2790   %}
  2792   enc_class long_uint_multiply( eADXRegL dst, nadxRegI src) %{
  2793     // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
  2794     // MUL EDX:EAX, src
  2795     emit_opcode( cbuf, 0xF7 );
  2796     emit_rm( cbuf, 0x3, 0x4, $src$$reg);
  2797   %}
  2799   enc_class long_multiply( eADXRegL dst, eRegL src, rRegI tmp ) %{
  2800     // Basic idea: lo(result) = lo(x_lo * y_lo)
  2801     //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
  2802     // MOV    $tmp,$src.lo
  2803     encode_Copy( cbuf, $tmp$$reg, $src$$reg );
  2804     // IMUL   $tmp,EDX
  2805     emit_opcode( cbuf, 0x0F );
  2806     emit_opcode( cbuf, 0xAF );
  2807     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  2808     // MOV    EDX,$src.hi
  2809     encode_Copy( cbuf, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg) );
  2810     // IMUL   EDX,EAX
  2811     emit_opcode( cbuf, 0x0F );
  2812     emit_opcode( cbuf, 0xAF );
  2813     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
  2814     // ADD    $tmp,EDX
  2815     emit_opcode( cbuf, 0x03 );
  2816     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  2817     // MUL   EDX:EAX,$src.lo
  2818     emit_opcode( cbuf, 0xF7 );
  2819     emit_rm( cbuf, 0x3, 0x4, $src$$reg );
  2820     // ADD    EDX,ESI
  2821     emit_opcode( cbuf, 0x03 );
  2822     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $tmp$$reg );
  2823   %}
  2825   enc_class long_multiply_con( eADXRegL dst, immL_127 src, rRegI tmp ) %{
  2826     // Basic idea: lo(result) = lo(src * y_lo)
  2827     //             hi(result) = hi(src * y_lo) + lo(src * y_hi)
  2828     // IMUL   $tmp,EDX,$src
  2829     emit_opcode( cbuf, 0x6B );
  2830     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  2831     emit_d8( cbuf, (int)$src$$constant );
  2832     // MOV    EDX,$src
  2833     emit_opcode(cbuf, 0xB8 + EDX_enc);
  2834     emit_d32( cbuf, (int)$src$$constant );
  2835     // MUL   EDX:EAX,EDX
  2836     emit_opcode( cbuf, 0xF7 );
  2837     emit_rm( cbuf, 0x3, 0x4, EDX_enc );
  2838     // ADD    EDX,ESI
  2839     emit_opcode( cbuf, 0x03 );
  2840     emit_rm( cbuf, 0x3, EDX_enc, $tmp$$reg );
  2841   %}
  2843   enc_class long_div( eRegL src1, eRegL src2 ) %{
  2844     // PUSH src1.hi
  2845     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
  2846     // PUSH src1.lo
  2847     emit_opcode(cbuf,               0x50+$src1$$reg  );
  2848     // PUSH src2.hi
  2849     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
  2850     // PUSH src2.lo
  2851     emit_opcode(cbuf,               0x50+$src2$$reg  );
  2852     // CALL directly to the runtime
  2853     cbuf.set_insts_mark();
  2854     emit_opcode(cbuf,0xE8);       // Call into runtime
  2855     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::ldiv) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  2856     // Restore stack
  2857     emit_opcode(cbuf, 0x83); // add  SP, #framesize
  2858     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  2859     emit_d8(cbuf, 4*4);
  2860   %}
  2862   enc_class long_mod( eRegL src1, eRegL src2 ) %{
  2863     // PUSH src1.hi
  2864     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
  2865     // PUSH src1.lo
  2866     emit_opcode(cbuf,               0x50+$src1$$reg  );
  2867     // PUSH src2.hi
  2868     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
  2869     // PUSH src2.lo
  2870     emit_opcode(cbuf,               0x50+$src2$$reg  );
  2871     // CALL directly to the runtime
  2872     cbuf.set_insts_mark();
  2873     emit_opcode(cbuf,0xE8);       // Call into runtime
  2874     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::lrem ) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  2875     // Restore stack
  2876     emit_opcode(cbuf, 0x83); // add  SP, #framesize
  2877     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  2878     emit_d8(cbuf, 4*4);
  2879   %}
  2881   enc_class long_cmp_flags0( eRegL src, rRegI tmp ) %{
  2882     // MOV   $tmp,$src.lo
  2883     emit_opcode(cbuf, 0x8B);
  2884     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg);
  2885     // OR    $tmp,$src.hi
  2886     emit_opcode(cbuf, 0x0B);
  2887     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg));
  2888   %}
  2890   enc_class long_cmp_flags1( eRegL src1, eRegL src2 ) %{
  2891     // CMP    $src1.lo,$src2.lo
  2892     emit_opcode( cbuf, 0x3B );
  2893     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  2894     // JNE,s  skip
  2895     emit_cc(cbuf, 0x70, 0x5);
  2896     emit_d8(cbuf,2);
  2897     // CMP    $src1.hi,$src2.hi
  2898     emit_opcode( cbuf, 0x3B );
  2899     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
  2900   %}
  2902   enc_class long_cmp_flags2( eRegL src1, eRegL src2, rRegI tmp ) %{
  2903     // CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits
  2904     emit_opcode( cbuf, 0x3B );
  2905     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  2906     // MOV    $tmp,$src1.hi
  2907     emit_opcode( cbuf, 0x8B );
  2908     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src1$$reg) );
  2909     // SBB   $tmp,$src2.hi\t! Compute flags for long compare
  2910     emit_opcode( cbuf, 0x1B );
  2911     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src2$$reg) );
  2912   %}
  2914   enc_class long_cmp_flags3( eRegL src, rRegI tmp ) %{
  2915     // XOR    $tmp,$tmp
  2916     emit_opcode(cbuf,0x33);  // XOR
  2917     emit_rm(cbuf,0x3, $tmp$$reg, $tmp$$reg);
  2918     // CMP    $tmp,$src.lo
  2919     emit_opcode( cbuf, 0x3B );
  2920     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg );
  2921     // SBB    $tmp,$src.hi
  2922     emit_opcode( cbuf, 0x1B );
  2923     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg) );
  2924   %}
  2926  // Sniff, sniff... smells like Gnu Superoptimizer
  2927   enc_class neg_long( eRegL dst ) %{
  2928     emit_opcode(cbuf,0xF7);    // NEG hi
  2929     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
  2930     emit_opcode(cbuf,0xF7);    // NEG lo
  2931     emit_rm    (cbuf,0x3, 0x3,               $dst$$reg );
  2932     emit_opcode(cbuf,0x83);    // SBB hi,0
  2933     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
  2934     emit_d8    (cbuf,0 );
  2935   %}
  2938   // Because the transitions from emitted code to the runtime
  2939   // monitorenter/exit helper stubs are so slow it's critical that
  2940   // we inline both the stack-locking fast-path and the inflated fast path.
  2941   //
  2942   // See also: cmpFastLock and cmpFastUnlock.
  2943   //
  2944   // What follows is a specialized inline transliteration of the code
  2945   // in slow_enter() and slow_exit().  If we're concerned about I$ bloat
  2946   // another option would be to emit TrySlowEnter and TrySlowExit methods
  2947   // at startup-time.  These methods would accept arguments as
  2948   // (rax,=Obj, rbx=Self, rcx=box, rdx=Scratch) and return success-failure
  2949   // indications in the icc.ZFlag.  Fast_Lock and Fast_Unlock would simply
  2950   // marshal the arguments and emit calls to TrySlowEnter and TrySlowExit.
  2951   // In practice, however, the # of lock sites is bounded and is usually small.
  2952   // Besides the call overhead, TrySlowEnter and TrySlowExit might suffer
  2953   // if the processor uses simple bimodal branch predictors keyed by EIP
  2954   // Since the helper routines would be called from multiple synchronization
  2955   // sites.
  2956   //
  2957   // An even better approach would be write "MonitorEnter()" and "MonitorExit()"
  2958   // in java - using j.u.c and unsafe - and just bind the lock and unlock sites
  2959   // to those specialized methods.  That'd give us a mostly platform-independent
  2960   // implementation that the JITs could optimize and inline at their pleasure.
  2961   // Done correctly, the only time we'd need to cross to native could would be
  2962   // to park() or unpark() threads.  We'd also need a few more unsafe operators
  2963   // to (a) prevent compiler-JIT reordering of non-volatile accesses, and
  2964   // (b) explicit barriers or fence operations.
  2965   //
  2966   // TODO:
  2967   //
  2968   // *  Arrange for C2 to pass "Self" into Fast_Lock and Fast_Unlock in one of the registers (scr).
  2969   //    This avoids manifesting the Self pointer in the Fast_Lock and Fast_Unlock terminals.
  2970   //    Given TLAB allocation, Self is usually manifested in a register, so passing it into
  2971   //    the lock operators would typically be faster than reifying Self.
  2972   //
  2973   // *  Ideally I'd define the primitives as:
  2974   //       fast_lock   (nax Obj, nax box, EAX tmp, nax scr) where box, tmp and scr are KILLED.
  2975   //       fast_unlock (nax Obj, EAX box, nax tmp) where box and tmp are KILLED
  2976   //    Unfortunately ADLC bugs prevent us from expressing the ideal form.
  2977   //    Instead, we're stuck with a rather awkward and brittle register assignments below.
  2978   //    Furthermore the register assignments are overconstrained, possibly resulting in
  2979   //    sub-optimal code near the synchronization site.
  2980   //
  2981   // *  Eliminate the sp-proximity tests and just use "== Self" tests instead.
  2982   //    Alternately, use a better sp-proximity test.
  2983   //
  2984   // *  Currently ObjectMonitor._Owner can hold either an sp value or a (THREAD *) value.
  2985   //    Either one is sufficient to uniquely identify a thread.
  2986   //    TODO: eliminate use of sp in _owner and use get_thread(tr) instead.
  2987   //
  2988   // *  Intrinsify notify() and notifyAll() for the common cases where the
  2989   //    object is locked by the calling thread but the waitlist is empty.
  2990   //    avoid the expensive JNI call to JVM_Notify() and JVM_NotifyAll().
  2991   //
  2992   // *  use jccb and jmpb instead of jcc and jmp to improve code density.
  2993   //    But beware of excessive branch density on AMD Opterons.
  2994   //
  2995   // *  Both Fast_Lock and Fast_Unlock set the ICC.ZF to indicate success
  2996   //    or failure of the fast-path.  If the fast-path fails then we pass
  2997   //    control to the slow-path, typically in C.  In Fast_Lock and
  2998   //    Fast_Unlock we often branch to DONE_LABEL, just to find that C2
  2999   //    will emit a conditional branch immediately after the node.
  3000   //    So we have branches to branches and lots of ICC.ZF games.
  3001   //    Instead, it might be better to have C2 pass a "FailureLabel"
  3002   //    into Fast_Lock and Fast_Unlock.  In the case of success, control
  3003   //    will drop through the node.  ICC.ZF is undefined at exit.
  3004   //    In the case of failure, the node will branch directly to the
  3005   //    FailureLabel
  3008   // obj: object to lock
  3009   // box: on-stack box address (displaced header location) - KILLED
  3010   // rax,: tmp -- KILLED
  3011   // scr: tmp -- KILLED
  3012   enc_class Fast_Lock( eRegP obj, eRegP box, eAXRegI tmp, eRegP scr ) %{
  3014     Register objReg = as_Register($obj$$reg);
  3015     Register boxReg = as_Register($box$$reg);
  3016     Register tmpReg = as_Register($tmp$$reg);
  3017     Register scrReg = as_Register($scr$$reg);
  3019     // Ensure the register assignents are disjoint
  3020     guarantee (objReg != boxReg, "") ;
  3021     guarantee (objReg != tmpReg, "") ;
  3022     guarantee (objReg != scrReg, "") ;
  3023     guarantee (boxReg != tmpReg, "") ;
  3024     guarantee (boxReg != scrReg, "") ;
  3025     guarantee (tmpReg == as_Register(EAX_enc), "") ;
  3027     MacroAssembler masm(&cbuf);
  3029     if (_counters != NULL) {
  3030       masm.atomic_incl(ExternalAddress((address) _counters->total_entry_count_addr()));
  3032     if (EmitSync & 1) {
  3033         // set box->dhw = unused_mark (3)
  3034         // Force all sync thru slow-path: slow_enter() and slow_exit() 
  3035         masm.movptr (Address(boxReg, 0), int32_t(markOopDesc::unused_mark())) ;             
  3036         masm.cmpptr (rsp, (int32_t)0) ;                        
  3037     } else 
  3038     if (EmitSync & 2) { 
  3039         Label DONE_LABEL ;           
  3040         if (UseBiasedLocking) {
  3041            // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument.
  3042            masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
  3045         masm.movptr(tmpReg, Address(objReg, 0)) ;          // fetch markword 
  3046         masm.orptr (tmpReg, 0x1);
  3047         masm.movptr(Address(boxReg, 0), tmpReg);           // Anticipate successful CAS 
  3048         if (os::is_MP()) { masm.lock();  }
  3049         masm.cmpxchgptr(boxReg, Address(objReg, 0));          // Updates tmpReg
  3050         masm.jcc(Assembler::equal, DONE_LABEL);
  3051         // Recursive locking
  3052         masm.subptr(tmpReg, rsp);
  3053         masm.andptr(tmpReg, (int32_t) 0xFFFFF003 );
  3054         masm.movptr(Address(boxReg, 0), tmpReg);
  3055         masm.bind(DONE_LABEL) ; 
  3056     } else {  
  3057       // Possible cases that we'll encounter in fast_lock 
  3058       // ------------------------------------------------
  3059       // * Inflated
  3060       //    -- unlocked
  3061       //    -- Locked
  3062       //       = by self
  3063       //       = by other
  3064       // * biased
  3065       //    -- by Self
  3066       //    -- by other
  3067       // * neutral
  3068       // * stack-locked
  3069       //    -- by self
  3070       //       = sp-proximity test hits
  3071       //       = sp-proximity test generates false-negative
  3072       //    -- by other
  3073       //
  3075       Label IsInflated, DONE_LABEL, PopDone ;
  3077       // TODO: optimize away redundant LDs of obj->mark and improve the markword triage
  3078       // order to reduce the number of conditional branches in the most common cases.
  3079       // Beware -- there's a subtle invariant that fetch of the markword
  3080       // at [FETCH], below, will never observe a biased encoding (*101b).
  3081       // If this invariant is not held we risk exclusion (safety) failure.
  3082       if (UseBiasedLocking && !UseOptoBiasInlining) {
  3083         masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
  3086       masm.movptr(tmpReg, Address(objReg, 0)) ;         // [FETCH]
  3087       masm.testptr(tmpReg, 0x02) ;                      // Inflated v (Stack-locked or neutral)
  3088       masm.jccb  (Assembler::notZero, IsInflated) ;
  3090       // Attempt stack-locking ...
  3091       masm.orptr (tmpReg, 0x1);
  3092       masm.movptr(Address(boxReg, 0), tmpReg);          // Anticipate successful CAS
  3093       if (os::is_MP()) { masm.lock();  }
  3094       masm.cmpxchgptr(boxReg, Address(objReg, 0));           // Updates tmpReg
  3095       if (_counters != NULL) {
  3096         masm.cond_inc32(Assembler::equal,
  3097                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
  3099       masm.jccb (Assembler::equal, DONE_LABEL);
  3101       // Recursive locking
  3102       masm.subptr(tmpReg, rsp);
  3103       masm.andptr(tmpReg, 0xFFFFF003 );
  3104       masm.movptr(Address(boxReg, 0), tmpReg);
  3105       if (_counters != NULL) {
  3106         masm.cond_inc32(Assembler::equal,
  3107                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
  3109       masm.jmp  (DONE_LABEL) ;
  3111       masm.bind (IsInflated) ;
  3113       // The object is inflated.
  3114       //
  3115       // TODO-FIXME: eliminate the ugly use of manifest constants:
  3116       //   Use markOopDesc::monitor_value instead of "2".
  3117       //   use markOop::unused_mark() instead of "3".
  3118       // The tmpReg value is an objectMonitor reference ORed with
  3119       // markOopDesc::monitor_value (2).   We can either convert tmpReg to an
  3120       // objectmonitor pointer by masking off the "2" bit or we can just
  3121       // use tmpReg as an objectmonitor pointer but bias the objectmonitor
  3122       // field offsets with "-2" to compensate for and annul the low-order tag bit.
  3123       //
  3124       // I use the latter as it avoids AGI stalls.
  3125       // As such, we write "mov r, [tmpReg+OFFSETOF(Owner)-2]"
  3126       // instead of "mov r, [tmpReg+OFFSETOF(Owner)]".
  3127       //
  3128       #define OFFSET_SKEWED(f) ((ObjectMonitor::f ## _offset_in_bytes())-2)
  3130       // boxReg refers to the on-stack BasicLock in the current frame.
  3131       // We'd like to write:
  3132       //   set box->_displaced_header = markOop::unused_mark().  Any non-0 value suffices.
  3133       // This is convenient but results a ST-before-CAS penalty.  The following CAS suffers
  3134       // additional latency as we have another ST in the store buffer that must drain.
  3136       if (EmitSync & 8192) { 
  3137          masm.movptr(Address(boxReg, 0), 3) ;            // results in ST-before-CAS penalty
  3138          masm.get_thread (scrReg) ; 
  3139          masm.movptr(boxReg, tmpReg);                    // consider: LEA box, [tmp-2] 
  3140          masm.movptr(tmpReg, NULL_WORD);                 // consider: xor vs mov
  3141          if (os::is_MP()) { masm.lock(); } 
  3142          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
  3143       } else 
  3144       if ((EmitSync & 128) == 0) {                      // avoid ST-before-CAS
  3145          masm.movptr(scrReg, boxReg) ; 
  3146          masm.movptr(boxReg, tmpReg);                   // consider: LEA box, [tmp-2] 
  3148          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
  3149          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3150             // prefetchw [eax + Offset(_owner)-2]
  3151             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
  3154          if ((EmitSync & 64) == 0) {
  3155            // Optimistic form: consider XORL tmpReg,tmpReg
  3156            masm.movptr(tmpReg, NULL_WORD) ; 
  3157          } else { 
  3158            // Can suffer RTS->RTO upgrades on shared or cold $ lines
  3159            // Test-And-CAS instead of CAS
  3160            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
  3161            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
  3162            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
  3165          // Appears unlocked - try to swing _owner from null to non-null.
  3166          // Ideally, I'd manifest "Self" with get_thread and then attempt
  3167          // to CAS the register containing Self into m->Owner.
  3168          // But we don't have enough registers, so instead we can either try to CAS
  3169          // rsp or the address of the box (in scr) into &m->owner.  If the CAS succeeds
  3170          // we later store "Self" into m->Owner.  Transiently storing a stack address
  3171          // (rsp or the address of the box) into  m->owner is harmless.
  3172          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
  3173          if (os::is_MP()) { masm.lock();  }
  3174          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
  3175          masm.movptr(Address(scrReg, 0), 3) ;          // box->_displaced_header = 3
  3176          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3177          masm.get_thread (scrReg) ;                    // beware: clobbers ICCs
  3178          masm.movptr(Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2), scrReg) ; 
  3179          masm.xorptr(boxReg, boxReg) ;                 // set icc.ZFlag = 1 to indicate success
  3181          // If the CAS fails we can either retry or pass control to the slow-path.  
  3182          // We use the latter tactic.  
  3183          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
  3184          // If the CAS was successful ...
  3185          //   Self has acquired the lock
  3186          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
  3187          // Intentional fall-through into DONE_LABEL ...
  3188       } else {
  3189          masm.movptr(Address(boxReg, 0), 3) ;       // results in ST-before-CAS penalty
  3190          masm.movptr(boxReg, tmpReg) ; 
  3192          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
  3193          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3194             // prefetchw [eax + Offset(_owner)-2]
  3195             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
  3198          if ((EmitSync & 64) == 0) {
  3199            // Optimistic form
  3200            masm.xorptr  (tmpReg, tmpReg) ; 
  3201          } else { 
  3202            // Can suffer RTS->RTO upgrades on shared or cold $ lines
  3203            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
  3204            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
  3205            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
  3208          // Appears unlocked - try to swing _owner from null to non-null.
  3209          // Use either "Self" (in scr) or rsp as thread identity in _owner.
  3210          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
  3211          masm.get_thread (scrReg) ;
  3212          if (os::is_MP()) { masm.lock(); }
  3213          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
  3215          // If the CAS fails we can either retry or pass control to the slow-path.
  3216          // We use the latter tactic.
  3217          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
  3218          // If the CAS was successful ...
  3219          //   Self has acquired the lock
  3220          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
  3221          // Intentional fall-through into DONE_LABEL ...
  3224       // DONE_LABEL is a hot target - we'd really like to place it at the
  3225       // start of cache line by padding with NOPs.
  3226       // See the AMD and Intel software optimization manuals for the
  3227       // most efficient "long" NOP encodings.
  3228       // Unfortunately none of our alignment mechanisms suffice.
  3229       masm.bind(DONE_LABEL);
  3231       // Avoid branch-to-branch on AMD processors
  3232       // This appears to be superstition.
  3233       if (EmitSync & 32) masm.nop() ;
  3236       // At DONE_LABEL the icc ZFlag is set as follows ...
  3237       // Fast_Unlock uses the same protocol.
  3238       // ZFlag == 1 -> Success
  3239       // ZFlag == 0 -> Failure - force control through the slow-path
  3241   %}
  3243   // obj: object to unlock
  3244   // box: box address (displaced header location), killed.  Must be EAX.
  3245   // rbx,: killed tmp; cannot be obj nor box.
  3246   //
  3247   // Some commentary on balanced locking:
  3248   //
  3249   // Fast_Lock and Fast_Unlock are emitted only for provably balanced lock sites.
  3250   // Methods that don't have provably balanced locking are forced to run in the
  3251   // interpreter - such methods won't be compiled to use fast_lock and fast_unlock.
  3252   // The interpreter provides two properties:
  3253   // I1:  At return-time the interpreter automatically and quietly unlocks any
  3254   //      objects acquired the current activation (frame).  Recall that the
  3255   //      interpreter maintains an on-stack list of locks currently held by
  3256   //      a frame.
  3257   // I2:  If a method attempts to unlock an object that is not held by the
  3258   //      the frame the interpreter throws IMSX.
  3259   //
  3260   // Lets say A(), which has provably balanced locking, acquires O and then calls B().
  3261   // B() doesn't have provably balanced locking so it runs in the interpreter.
  3262   // Control returns to A() and A() unlocks O.  By I1 and I2, above, we know that O
  3263   // is still locked by A().
  3264   //
  3265   // The only other source of unbalanced locking would be JNI.  The "Java Native Interface:
  3266   // Programmer's Guide and Specification" claims that an object locked by jni_monitorenter
  3267   // should not be unlocked by "normal" java-level locking and vice-versa.  The specification
  3268   // doesn't specify what will occur if a program engages in such mixed-mode locking, however.
  3270   enc_class Fast_Unlock( nabxRegP obj, eAXRegP box, eRegP tmp) %{
  3272     Register objReg = as_Register($obj$$reg);
  3273     Register boxReg = as_Register($box$$reg);
  3274     Register tmpReg = as_Register($tmp$$reg);
  3276     guarantee (objReg != boxReg, "") ;
  3277     guarantee (objReg != tmpReg, "") ;
  3278     guarantee (boxReg != tmpReg, "") ;
  3279     guarantee (boxReg == as_Register(EAX_enc), "") ;
  3280     MacroAssembler masm(&cbuf);
  3282     if (EmitSync & 4) {
  3283       // Disable - inhibit all inlining.  Force control through the slow-path
  3284       masm.cmpptr (rsp, 0) ; 
  3285     } else 
  3286     if (EmitSync & 8) {
  3287       Label DONE_LABEL ;
  3288       if (UseBiasedLocking) {
  3289          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3291       // classic stack-locking code ...
  3292       masm.movptr(tmpReg, Address(boxReg, 0)) ;
  3293       masm.testptr(tmpReg, tmpReg) ;
  3294       masm.jcc   (Assembler::zero, DONE_LABEL) ;
  3295       if (os::is_MP()) { masm.lock(); }
  3296       masm.cmpxchgptr(tmpReg, Address(objReg, 0));          // Uses EAX which is box
  3297       masm.bind(DONE_LABEL);
  3298     } else {
  3299       Label DONE_LABEL, Stacked, CheckSucc, Inflated ;
  3301       // Critically, the biased locking test must have precedence over
  3302       // and appear before the (box->dhw == 0) recursive stack-lock test.
  3303       if (UseBiasedLocking && !UseOptoBiasInlining) {
  3304          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3307       masm.cmpptr(Address(boxReg, 0), 0) ;            // Examine the displaced header
  3308       masm.movptr(tmpReg, Address(objReg, 0)) ;       // Examine the object's markword
  3309       masm.jccb  (Assembler::zero, DONE_LABEL) ;      // 0 indicates recursive stack-lock
  3311       masm.testptr(tmpReg, 0x02) ;                     // Inflated? 
  3312       masm.jccb  (Assembler::zero, Stacked) ;
  3314       masm.bind  (Inflated) ;
  3315       // It's inflated.
  3316       // Despite our balanced locking property we still check that m->_owner == Self
  3317       // as java routines or native JNI code called by this thread might
  3318       // have released the lock.
  3319       // Refer to the comments in synchronizer.cpp for how we might encode extra
  3320       // state in _succ so we can avoid fetching EntryList|cxq.
  3321       //
  3322       // I'd like to add more cases in fast_lock() and fast_unlock() --
  3323       // such as recursive enter and exit -- but we have to be wary of
  3324       // I$ bloat, T$ effects and BP$ effects.
  3325       //
  3326       // If there's no contention try a 1-0 exit.  That is, exit without
  3327       // a costly MEMBAR or CAS.  See synchronizer.cpp for details on how
  3328       // we detect and recover from the race that the 1-0 exit admits.
  3329       //
  3330       // Conceptually Fast_Unlock() must execute a STST|LDST "release" barrier
  3331       // before it STs null into _owner, releasing the lock.  Updates
  3332       // to data protected by the critical section must be visible before
  3333       // we drop the lock (and thus before any other thread could acquire
  3334       // the lock and observe the fields protected by the lock).
  3335       // IA32's memory-model is SPO, so STs are ordered with respect to
  3336       // each other and there's no need for an explicit barrier (fence).
  3337       // See also http://gee.cs.oswego.edu/dl/jmm/cookbook.html.
  3339       masm.get_thread (boxReg) ;
  3340       if ((EmitSync & 4096) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3341         // prefetchw [ebx + Offset(_owner)-2]
  3342         masm.prefetchw(Address(rbx, ObjectMonitor::owner_offset_in_bytes()-2));
  3345       // Note that we could employ various encoding schemes to reduce
  3346       // the number of loads below (currently 4) to just 2 or 3.
  3347       // Refer to the comments in synchronizer.cpp.
  3348       // In practice the chain of fetches doesn't seem to impact performance, however.
  3349       if ((EmitSync & 65536) == 0 && (EmitSync & 256)) {
  3350          // Attempt to reduce branch density - AMD's branch predictor.
  3351          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
  3352          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
  3353          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
  3354          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
  3355          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3356          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3357          masm.jmpb  (DONE_LABEL) ; 
  3358       } else { 
  3359          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
  3360          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
  3361          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3362          masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
  3363          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
  3364          masm.jccb  (Assembler::notZero, CheckSucc) ; 
  3365          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3366          masm.jmpb  (DONE_LABEL) ; 
  3369       // The Following code fragment (EmitSync & 65536) improves the performance of
  3370       // contended applications and contended synchronization microbenchmarks.
  3371       // Unfortunately the emission of the code - even though not executed - causes regressions
  3372       // in scimark and jetstream, evidently because of $ effects.  Replacing the code
  3373       // with an equal number of never-executed NOPs results in the same regression.
  3374       // We leave it off by default.
  3376       if ((EmitSync & 65536) != 0) {
  3377          Label LSuccess, LGoSlowPath ;
  3379          masm.bind  (CheckSucc) ;
  3381          // Optional pre-test ... it's safe to elide this
  3382          if ((EmitSync & 16) == 0) { 
  3383             masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
  3384             masm.jccb  (Assembler::zero, LGoSlowPath) ; 
  3387          // We have a classic Dekker-style idiom:
  3388          //    ST m->_owner = 0 ; MEMBAR; LD m->_succ
  3389          // There are a number of ways to implement the barrier:
  3390          // (1) lock:andl &m->_owner, 0
  3391          //     is fast, but mask doesn't currently support the "ANDL M,IMM32" form.
  3392          //     LOCK: ANDL [ebx+Offset(_Owner)-2], 0
  3393          //     Encodes as 81 31 OFF32 IMM32 or 83 63 OFF8 IMM8
  3394          // (2) If supported, an explicit MFENCE is appealing.
  3395          //     In older IA32 processors MFENCE is slower than lock:add or xchg
  3396          //     particularly if the write-buffer is full as might be the case if
  3397          //     if stores closely precede the fence or fence-equivalent instruction.
  3398          //     In more modern implementations MFENCE appears faster, however.
  3399          // (3) In lieu of an explicit fence, use lock:addl to the top-of-stack
  3400          //     The $lines underlying the top-of-stack should be in M-state.
  3401          //     The locked add instruction is serializing, of course.
  3402          // (4) Use xchg, which is serializing
  3403          //     mov boxReg, 0; xchgl boxReg, [tmpReg + Offset(_owner)-2] also works
  3404          // (5) ST m->_owner = 0 and then execute lock:orl &m->_succ, 0.
  3405          //     The integer condition codes will tell us if succ was 0.
  3406          //     Since _succ and _owner should reside in the same $line and
  3407          //     we just stored into _owner, it's likely that the $line
  3408          //     remains in M-state for the lock:orl.
  3409          //
  3410          // We currently use (3), although it's likely that switching to (2)
  3411          // is correct for the future.
  3413          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3414          if (os::is_MP()) { 
  3415             if (VM_Version::supports_sse2() && 1 == FenceInstruction) { 
  3416               masm.mfence();
  3417             } else { 
  3418               masm.lock () ; masm.addptr(Address(rsp, 0), 0) ; 
  3421          // Ratify _succ remains non-null
  3422          masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
  3423          masm.jccb  (Assembler::notZero, LSuccess) ; 
  3425          masm.xorptr(boxReg, boxReg) ;                  // box is really EAX
  3426          if (os::is_MP()) { masm.lock(); }
  3427          masm.cmpxchgptr(rsp, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2));
  3428          masm.jccb  (Assembler::notEqual, LSuccess) ;
  3429          // Since we're low on registers we installed rsp as a placeholding in _owner.
  3430          // Now install Self over rsp.  This is safe as we're transitioning from
  3431          // non-null to non=null
  3432          masm.get_thread (boxReg) ;
  3433          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), boxReg) ;
  3434          // Intentional fall-through into LGoSlowPath ...
  3436          masm.bind  (LGoSlowPath) ; 
  3437          masm.orptr(boxReg, 1) ;                      // set ICC.ZF=0 to indicate failure
  3438          masm.jmpb  (DONE_LABEL) ; 
  3440          masm.bind  (LSuccess) ; 
  3441          masm.xorptr(boxReg, boxReg) ;                 // set ICC.ZF=1 to indicate success
  3442          masm.jmpb  (DONE_LABEL) ; 
  3445       masm.bind (Stacked) ;
  3446       // It's not inflated and it's not recursively stack-locked and it's not biased.
  3447       // It must be stack-locked.
  3448       // Try to reset the header to displaced header.
  3449       // The "box" value on the stack is stable, so we can reload
  3450       // and be assured we observe the same value as above.
  3451       masm.movptr(tmpReg, Address(boxReg, 0)) ;
  3452       if (os::is_MP()) {   masm.lock();    }
  3453       masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses EAX which is box
  3454       // Intention fall-thru into DONE_LABEL
  3457       // DONE_LABEL is a hot target - we'd really like to place it at the
  3458       // start of cache line by padding with NOPs.
  3459       // See the AMD and Intel software optimization manuals for the
  3460       // most efficient "long" NOP encodings.
  3461       // Unfortunately none of our alignment mechanisms suffice.
  3462       if ((EmitSync & 65536) == 0) {
  3463          masm.bind (CheckSucc) ;
  3465       masm.bind(DONE_LABEL);
  3467       // Avoid branch to branch on AMD processors
  3468       if (EmitSync & 32768) { masm.nop() ; }
  3470   %}
  3473   enc_class enc_pop_rdx() %{
  3474     emit_opcode(cbuf,0x5A);
  3475   %}
  3477   enc_class enc_rethrow() %{
  3478     cbuf.set_insts_mark();
  3479     emit_opcode(cbuf, 0xE9);        // jmp    entry
  3480     emit_d32_reloc(cbuf, (int)OptoRuntime::rethrow_stub() - ((int)cbuf.insts_end())-4,
  3481                    runtime_call_Relocation::spec(), RELOC_IMM32 );
  3482   %}
  3485   // Convert a double to an int.  Java semantics require we do complex
  3486   // manglelations in the corner cases.  So we set the rounding mode to
  3487   // 'zero', store the darned double down as an int, and reset the
  3488   // rounding mode to 'nearest'.  The hardware throws an exception which
  3489   // patches up the correct value directly to the stack.
  3490   enc_class DPR2I_encoding( regDPR src ) %{
  3491     // Flip to round-to-zero mode.  We attempted to allow invalid-op
  3492     // exceptions here, so that a NAN or other corner-case value will
  3493     // thrown an exception (but normal values get converted at full speed).
  3494     // However, I2C adapters and other float-stack manglers leave pending
  3495     // invalid-op exceptions hanging.  We would have to clear them before
  3496     // enabling them and that is more expensive than just testing for the
  3497     // invalid value Intel stores down in the corner cases.
  3498     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
  3499     emit_opcode(cbuf,0x2D);
  3500     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3501     // Allocate a word
  3502     emit_opcode(cbuf,0x83);            // SUB ESP,4
  3503     emit_opcode(cbuf,0xEC);
  3504     emit_d8(cbuf,0x04);
  3505     // Encoding assumes a double has been pushed into FPR0.
  3506     // Store down the double as an int, popping the FPU stack
  3507     emit_opcode(cbuf,0xDB);            // FISTP [ESP]
  3508     emit_opcode(cbuf,0x1C);
  3509     emit_d8(cbuf,0x24);
  3510     // Restore the rounding mode; mask the exception
  3511     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
  3512     emit_opcode(cbuf,0x2D);
  3513     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3514         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3515         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3517     // Load the converted int; adjust CPU stack
  3518     emit_opcode(cbuf,0x58);       // POP EAX
  3519     emit_opcode(cbuf,0x3D);       // CMP EAX,imm
  3520     emit_d32   (cbuf,0x80000000); //         0x80000000
  3521     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3522     emit_d8    (cbuf,0x07);       // Size of slow_call
  3523     // Push src onto stack slow-path
  3524     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
  3525     emit_d8    (cbuf,0xC0-1+$src$$reg );
  3526     // CALL directly to the runtime
  3527     cbuf.set_insts_mark();
  3528     emit_opcode(cbuf,0xE8);       // Call into runtime
  3529     emit_d32_reloc(cbuf, (StubRoutines::d2i_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3530     // Carry on here...
  3531   %}
  3533   enc_class DPR2L_encoding( regDPR src ) %{
  3534     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
  3535     emit_opcode(cbuf,0x2D);
  3536     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3537     // Allocate a word
  3538     emit_opcode(cbuf,0x83);            // SUB ESP,8
  3539     emit_opcode(cbuf,0xEC);
  3540     emit_d8(cbuf,0x08);
  3541     // Encoding assumes a double has been pushed into FPR0.
  3542     // Store down the double as a long, popping the FPU stack
  3543     emit_opcode(cbuf,0xDF);            // FISTP [ESP]
  3544     emit_opcode(cbuf,0x3C);
  3545     emit_d8(cbuf,0x24);
  3546     // Restore the rounding mode; mask the exception
  3547     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
  3548     emit_opcode(cbuf,0x2D);
  3549     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3550         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3551         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3553     // Load the converted int; adjust CPU stack
  3554     emit_opcode(cbuf,0x58);       // POP EAX
  3555     emit_opcode(cbuf,0x5A);       // POP EDX
  3556     emit_opcode(cbuf,0x81);       // CMP EDX,imm
  3557     emit_d8    (cbuf,0xFA);       // rdx
  3558     emit_d32   (cbuf,0x80000000); //         0x80000000
  3559     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3560     emit_d8    (cbuf,0x07+4);     // Size of slow_call
  3561     emit_opcode(cbuf,0x85);       // TEST EAX,EAX
  3562     emit_opcode(cbuf,0xC0);       // 2/rax,/rax,
  3563     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3564     emit_d8    (cbuf,0x07);       // Size of slow_call
  3565     // Push src onto stack slow-path
  3566     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
  3567     emit_d8    (cbuf,0xC0-1+$src$$reg );
  3568     // CALL directly to the runtime
  3569     cbuf.set_insts_mark();
  3570     emit_opcode(cbuf,0xE8);       // Call into runtime
  3571     emit_d32_reloc(cbuf, (StubRoutines::d2l_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3572     // Carry on here...
  3573   %}
  3575   enc_class FMul_ST_reg( eRegFPR src1 ) %{
  3576     // Operand was loaded from memory into fp ST (stack top)
  3577     // FMUL   ST,$src  /* D8 C8+i */
  3578     emit_opcode(cbuf, 0xD8);
  3579     emit_opcode(cbuf, 0xC8 + $src1$$reg);
  3580   %}
  3582   enc_class FAdd_ST_reg( eRegFPR src2 ) %{
  3583     // FADDP  ST,src2  /* D8 C0+i */
  3584     emit_opcode(cbuf, 0xD8);
  3585     emit_opcode(cbuf, 0xC0 + $src2$$reg);
  3586     //could use FADDP  src2,fpST  /* DE C0+i */
  3587   %}
  3589   enc_class FAddP_reg_ST( eRegFPR src2 ) %{
  3590     // FADDP  src2,ST  /* DE C0+i */
  3591     emit_opcode(cbuf, 0xDE);
  3592     emit_opcode(cbuf, 0xC0 + $src2$$reg);
  3593   %}
  3595   enc_class subFPR_divFPR_encode( eRegFPR src1, eRegFPR src2) %{
  3596     // Operand has been loaded into fp ST (stack top)
  3597       // FSUB   ST,$src1
  3598       emit_opcode(cbuf, 0xD8);
  3599       emit_opcode(cbuf, 0xE0 + $src1$$reg);
  3601       // FDIV
  3602       emit_opcode(cbuf, 0xD8);
  3603       emit_opcode(cbuf, 0xF0 + $src2$$reg);
  3604   %}
  3606   enc_class MulFAddF (eRegFPR src1, eRegFPR src2) %{
  3607     // Operand was loaded from memory into fp ST (stack top)
  3608     // FADD   ST,$src  /* D8 C0+i */
  3609     emit_opcode(cbuf, 0xD8);
  3610     emit_opcode(cbuf, 0xC0 + $src1$$reg);
  3612     // FMUL  ST,src2  /* D8 C*+i */
  3613     emit_opcode(cbuf, 0xD8);
  3614     emit_opcode(cbuf, 0xC8 + $src2$$reg);
  3615   %}
  3618   enc_class MulFAddFreverse (eRegFPR src1, eRegFPR src2) %{
  3619     // Operand was loaded from memory into fp ST (stack top)
  3620     // FADD   ST,$src  /* D8 C0+i */
  3621     emit_opcode(cbuf, 0xD8);
  3622     emit_opcode(cbuf, 0xC0 + $src1$$reg);
  3624     // FMULP  src2,ST  /* DE C8+i */
  3625     emit_opcode(cbuf, 0xDE);
  3626     emit_opcode(cbuf, 0xC8 + $src2$$reg);
  3627   %}
  3629   // Atomically load the volatile long
  3630   enc_class enc_loadL_volatile( memory mem, stackSlotL dst ) %{
  3631     emit_opcode(cbuf,0xDF);
  3632     int rm_byte_opcode = 0x05;
  3633     int base     = $mem$$base;
  3634     int index    = $mem$$index;
  3635     int scale    = $mem$$scale;
  3636     int displace = $mem$$disp;
  3637     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
  3638     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
  3639     store_to_stackslot( cbuf, 0x0DF, 0x07, $dst$$disp );
  3640   %}
  3642   // Volatile Store Long.  Must be atomic, so move it into
  3643   // the FP TOS and then do a 64-bit FIST.  Has to probe the
  3644   // target address before the store (for null-ptr checks)
  3645   // so the memory operand is used twice in the encoding.
  3646   enc_class enc_storeL_volatile( memory mem, stackSlotL src ) %{
  3647     store_to_stackslot( cbuf, 0x0DF, 0x05, $src$$disp );
  3648     cbuf.set_insts_mark();            // Mark start of FIST in case $mem has an oop
  3649     emit_opcode(cbuf,0xDF);
  3650     int rm_byte_opcode = 0x07;
  3651     int base     = $mem$$base;
  3652     int index    = $mem$$index;
  3653     int scale    = $mem$$scale;
  3654     int displace = $mem$$disp;
  3655     relocInfo::relocType disp_reloc = $mem->disp_reloc(); // disp-as-oop when working with static globals
  3656     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_reloc);
  3657   %}
  3659   // Safepoint Poll.  This polls the safepoint page, and causes an
  3660   // exception if it is not readable. Unfortunately, it kills the condition code
  3661   // in the process
  3662   // We current use TESTL [spp],EDI
  3663   // A better choice might be TESTB [spp + pagesize() - CacheLineSize()],0
  3665   enc_class Safepoint_Poll() %{
  3666     cbuf.relocate(cbuf.insts_mark(), relocInfo::poll_type, 0);
  3667     emit_opcode(cbuf,0x85);
  3668     emit_rm (cbuf, 0x0, 0x7, 0x5);
  3669     emit_d32(cbuf, (intptr_t)os::get_polling_page());
  3670   %}
  3671 %}
  3674 //----------FRAME--------------------------------------------------------------
  3675 // Definition of frame structure and management information.
  3676 //
  3677 //  S T A C K   L A Y O U T    Allocators stack-slot number
  3678 //                             |   (to get allocators register number
  3679 //  G  Owned by    |        |  v    add OptoReg::stack0())
  3680 //  r   CALLER     |        |
  3681 //  o     |        +--------+      pad to even-align allocators stack-slot
  3682 //  w     V        |  pad0  |        numbers; owned by CALLER
  3683 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
  3684 //  h     ^        |   in   |  5
  3685 //        |        |  args  |  4   Holes in incoming args owned by SELF
  3686 //  |     |        |        |  3
  3687 //  |     |        +--------+
  3688 //  V     |        | old out|      Empty on Intel, window on Sparc
  3689 //        |    old |preserve|      Must be even aligned.
  3690 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
  3691 //        |        |   in   |  3   area for Intel ret address
  3692 //     Owned by    |preserve|      Empty on Sparc.
  3693 //       SELF      +--------+
  3694 //        |        |  pad2  |  2   pad to align old SP
  3695 //        |        +--------+  1
  3696 //        |        | locks  |  0
  3697 //        |        +--------+----> OptoReg::stack0(), even aligned
  3698 //        |        |  pad1  | 11   pad to align new SP
  3699 //        |        +--------+
  3700 //        |        |        | 10
  3701 //        |        | spills |  9   spills
  3702 //        V        |        |  8   (pad0 slot for callee)
  3703 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
  3704 //        ^        |  out   |  7
  3705 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
  3706 //     Owned by    +--------+
  3707 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
  3708 //        |    new |preserve|      Must be even-aligned.
  3709 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
  3710 //        |        |        |
  3711 //
  3712 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
  3713 //         known from SELF's arguments and the Java calling convention.
  3714 //         Region 6-7 is determined per call site.
  3715 // Note 2: If the calling convention leaves holes in the incoming argument
  3716 //         area, those holes are owned by SELF.  Holes in the outgoing area
  3717 //         are owned by the CALLEE.  Holes should not be nessecary in the
  3718 //         incoming area, as the Java calling convention is completely under
  3719 //         the control of the AD file.  Doubles can be sorted and packed to
  3720 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
  3721 //         varargs C calling conventions.
  3722 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
  3723 //         even aligned with pad0 as needed.
  3724 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
  3725 //         region 6-11 is even aligned; it may be padded out more so that
  3726 //         the region from SP to FP meets the minimum stack alignment.
  3728 frame %{
  3729   // What direction does stack grow in (assumed to be same for C & Java)
  3730   stack_direction(TOWARDS_LOW);
  3732   // These three registers define part of the calling convention
  3733   // between compiled code and the interpreter.
  3734   inline_cache_reg(EAX);                // Inline Cache Register
  3735   interpreter_method_oop_reg(EBX);      // Method Oop Register when calling interpreter
  3737   // Optional: name the operand used by cisc-spilling to access [stack_pointer + offset]
  3738   cisc_spilling_operand_name(indOffset32);
  3740   // Number of stack slots consumed by locking an object
  3741   sync_stack_slots(1);
  3743   // Compiled code's Frame Pointer
  3744   frame_pointer(ESP);
  3745   // Interpreter stores its frame pointer in a register which is
  3746   // stored to the stack by I2CAdaptors.
  3747   // I2CAdaptors convert from interpreted java to compiled java.
  3748   interpreter_frame_pointer(EBP);
  3750   // Stack alignment requirement
  3751   // Alignment size in bytes (128-bit -> 16 bytes)
  3752   stack_alignment(StackAlignmentInBytes);
  3754   // Number of stack slots between incoming argument block and the start of
  3755   // a new frame.  The PROLOG must add this many slots to the stack.  The
  3756   // EPILOG must remove this many slots.  Intel needs one slot for
  3757   // return address and one for rbp, (must save rbp)
  3758   in_preserve_stack_slots(2+VerifyStackAtCalls);
  3760   // Number of outgoing stack slots killed above the out_preserve_stack_slots
  3761   // for calls to C.  Supports the var-args backing area for register parms.
  3762   varargs_C_out_slots_killed(0);
  3764   // The after-PROLOG location of the return address.  Location of
  3765   // return address specifies a type (REG or STACK) and a number
  3766   // representing the register number (i.e. - use a register name) or
  3767   // stack slot.
  3768   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
  3769   // Otherwise, it is above the locks and verification slot and alignment word
  3770   return_addr(STACK - 1 +
  3771               round_to((Compile::current()->in_preserve_stack_slots() +
  3772                         Compile::current()->fixed_slots()),
  3773                        stack_alignment_in_slots()));
  3775   // Body of function which returns an integer array locating
  3776   // arguments either in registers or in stack slots.  Passed an array
  3777   // of ideal registers called "sig" and a "length" count.  Stack-slot
  3778   // offsets are based on outgoing arguments, i.e. a CALLER setting up
  3779   // arguments for a CALLEE.  Incoming stack arguments are
  3780   // automatically biased by the preserve_stack_slots field above.
  3781   calling_convention %{
  3782     // No difference between ingoing/outgoing just pass false
  3783     SharedRuntime::java_calling_convention(sig_bt, regs, length, false);
  3784   %}
  3787   // Body of function which returns an integer array locating
  3788   // arguments either in registers or in stack slots.  Passed an array
  3789   // of ideal registers called "sig" and a "length" count.  Stack-slot
  3790   // offsets are based on outgoing arguments, i.e. a CALLER setting up
  3791   // arguments for a CALLEE.  Incoming stack arguments are
  3792   // automatically biased by the preserve_stack_slots field above.
  3793   c_calling_convention %{
  3794     // This is obviously always outgoing
  3795     (void) SharedRuntime::c_calling_convention(sig_bt, regs, length);
  3796   %}
  3798   // Location of C & interpreter return values
  3799   c_return_value %{
  3800     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
  3801     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
  3802     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
  3804     // in SSE2+ mode we want to keep the FPU stack clean so pretend
  3805     // that C functions return float and double results in XMM0.
  3806     if( ideal_reg == Op_RegD && UseSSE>=2 )
  3807       return OptoRegPair(XMM0b_num,XMM0_num);
  3808     if( ideal_reg == Op_RegF && UseSSE>=2 )
  3809       return OptoRegPair(OptoReg::Bad,XMM0_num);
  3811     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
  3812   %}
  3814   // Location of return values
  3815   return_value %{
  3816     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
  3817     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
  3818     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
  3819     if( ideal_reg == Op_RegD && UseSSE>=2 )
  3820       return OptoRegPair(XMM0b_num,XMM0_num);
  3821     if( ideal_reg == Op_RegF && UseSSE>=1 )
  3822       return OptoRegPair(OptoReg::Bad,XMM0_num);
  3823     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
  3824   %}
  3826 %}
  3828 //----------ATTRIBUTES---------------------------------------------------------
  3829 //----------Operand Attributes-------------------------------------------------
  3830 op_attrib op_cost(0);        // Required cost attribute
  3832 //----------Instruction Attributes---------------------------------------------
  3833 ins_attrib ins_cost(100);       // Required cost attribute
  3834 ins_attrib ins_size(8);         // Required size attribute (in bits)
  3835 ins_attrib ins_short_branch(0); // Required flag: is this instruction a
  3836                                 // non-matching short branch variant of some
  3837                                                             // long branch?
  3838 ins_attrib ins_alignment(1);    // Required alignment attribute (must be a power of 2)
  3839                                 // specifies the alignment that some part of the instruction (not
  3840                                 // necessarily the start) requires.  If > 1, a compute_padding()
  3841                                 // function must be provided for the instruction
  3843 //----------OPERANDS-----------------------------------------------------------
  3844 // Operand definitions must precede instruction definitions for correct parsing
  3845 // in the ADLC because operands constitute user defined types which are used in
  3846 // instruction definitions.
  3848 //----------Simple Operands----------------------------------------------------
  3849 // Immediate Operands
  3850 // Integer Immediate
  3851 operand immI() %{
  3852   match(ConI);
  3854   op_cost(10);
  3855   format %{ %}
  3856   interface(CONST_INTER);
  3857 %}
  3859 // Constant for test vs zero
  3860 operand immI0() %{
  3861   predicate(n->get_int() == 0);
  3862   match(ConI);
  3864   op_cost(0);
  3865   format %{ %}
  3866   interface(CONST_INTER);
  3867 %}
  3869 // Constant for increment
  3870 operand immI1() %{
  3871   predicate(n->get_int() == 1);
  3872   match(ConI);
  3874   op_cost(0);
  3875   format %{ %}
  3876   interface(CONST_INTER);
  3877 %}
  3879 // Constant for decrement
  3880 operand immI_M1() %{
  3881   predicate(n->get_int() == -1);
  3882   match(ConI);
  3884   op_cost(0);
  3885   format %{ %}
  3886   interface(CONST_INTER);
  3887 %}
  3889 // Valid scale values for addressing modes
  3890 operand immI2() %{
  3891   predicate(0 <= n->get_int() && (n->get_int() <= 3));
  3892   match(ConI);
  3894   format %{ %}
  3895   interface(CONST_INTER);
  3896 %}
  3898 operand immI8() %{
  3899   predicate((-128 <= n->get_int()) && (n->get_int() <= 127));
  3900   match(ConI);
  3902   op_cost(5);
  3903   format %{ %}
  3904   interface(CONST_INTER);
  3905 %}
  3907 operand immI16() %{
  3908   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
  3909   match(ConI);
  3911   op_cost(10);
  3912   format %{ %}
  3913   interface(CONST_INTER);
  3914 %}
  3916 // Constant for long shifts
  3917 operand immI_32() %{
  3918   predicate( n->get_int() == 32 );
  3919   match(ConI);
  3921   op_cost(0);
  3922   format %{ %}
  3923   interface(CONST_INTER);
  3924 %}
  3926 operand immI_1_31() %{
  3927   predicate( n->get_int() >= 1 && n->get_int() <= 31 );
  3928   match(ConI);
  3930   op_cost(0);
  3931   format %{ %}
  3932   interface(CONST_INTER);
  3933 %}
  3935 operand immI_32_63() %{
  3936   predicate( n->get_int() >= 32 && n->get_int() <= 63 );
  3937   match(ConI);
  3938   op_cost(0);
  3940   format %{ %}
  3941   interface(CONST_INTER);
  3942 %}
  3944 operand immI_1() %{
  3945   predicate( n->get_int() == 1 );
  3946   match(ConI);
  3948   op_cost(0);
  3949   format %{ %}
  3950   interface(CONST_INTER);
  3951 %}
  3953 operand immI_2() %{
  3954   predicate( n->get_int() == 2 );
  3955   match(ConI);
  3957   op_cost(0);
  3958   format %{ %}
  3959   interface(CONST_INTER);
  3960 %}
  3962 operand immI_3() %{
  3963   predicate( n->get_int() == 3 );
  3964   match(ConI);
  3966   op_cost(0);
  3967   format %{ %}
  3968   interface(CONST_INTER);
  3969 %}
  3971 // Pointer Immediate
  3972 operand immP() %{
  3973   match(ConP);
  3975   op_cost(10);
  3976   format %{ %}
  3977   interface(CONST_INTER);
  3978 %}
  3980 // NULL Pointer Immediate
  3981 operand immP0() %{
  3982   predicate( n->get_ptr() == 0 );
  3983   match(ConP);
  3984   op_cost(0);
  3986   format %{ %}
  3987   interface(CONST_INTER);
  3988 %}
  3990 // Long Immediate
  3991 operand immL() %{
  3992   match(ConL);
  3994   op_cost(20);
  3995   format %{ %}
  3996   interface(CONST_INTER);
  3997 %}
  3999 // Long Immediate zero
  4000 operand immL0() %{
  4001   predicate( n->get_long() == 0L );
  4002   match(ConL);
  4003   op_cost(0);
  4005   format %{ %}
  4006   interface(CONST_INTER);
  4007 %}
  4009 // Long Immediate zero
  4010 operand immL_M1() %{
  4011   predicate( n->get_long() == -1L );
  4012   match(ConL);
  4013   op_cost(0);
  4015   format %{ %}
  4016   interface(CONST_INTER);
  4017 %}
  4019 // Long immediate from 0 to 127.
  4020 // Used for a shorter form of long mul by 10.
  4021 operand immL_127() %{
  4022   predicate((0 <= n->get_long()) && (n->get_long() <= 127));
  4023   match(ConL);
  4024   op_cost(0);
  4026   format %{ %}
  4027   interface(CONST_INTER);
  4028 %}
  4030 // Long Immediate: low 32-bit mask
  4031 operand immL_32bits() %{
  4032   predicate(n->get_long() == 0xFFFFFFFFL);
  4033   match(ConL);
  4034   op_cost(0);
  4036   format %{ %}
  4037   interface(CONST_INTER);
  4038 %}
  4040 // Long Immediate: low 32-bit mask
  4041 operand immL32() %{
  4042   predicate(n->get_long() == (int)(n->get_long()));
  4043   match(ConL);
  4044   op_cost(20);
  4046   format %{ %}
  4047   interface(CONST_INTER);
  4048 %}
  4050 //Double Immediate zero
  4051 operand immDPR0() %{
  4052   // Do additional (and counter-intuitive) test against NaN to work around VC++
  4053   // bug that generates code such that NaNs compare equal to 0.0
  4054   predicate( UseSSE<=1 && n->getd() == 0.0 && !g_isnan(n->getd()) );
  4055   match(ConD);
  4057   op_cost(5);
  4058   format %{ %}
  4059   interface(CONST_INTER);
  4060 %}
  4062 // Double Immediate one
  4063 operand immDPR1() %{
  4064   predicate( UseSSE<=1 && n->getd() == 1.0 );
  4065   match(ConD);
  4067   op_cost(5);
  4068   format %{ %}
  4069   interface(CONST_INTER);
  4070 %}
  4072 // Double Immediate
  4073 operand immDPR() %{
  4074   predicate(UseSSE<=1);
  4075   match(ConD);
  4077   op_cost(5);
  4078   format %{ %}
  4079   interface(CONST_INTER);
  4080 %}
  4082 operand immD() %{
  4083   predicate(UseSSE>=2);
  4084   match(ConD);
  4086   op_cost(5);
  4087   format %{ %}
  4088   interface(CONST_INTER);
  4089 %}
  4091 // Double Immediate zero
  4092 operand immD0() %{
  4093   // Do additional (and counter-intuitive) test against NaN to work around VC++
  4094   // bug that generates code such that NaNs compare equal to 0.0 AND do not
  4095   // compare equal to -0.0.
  4096   predicate( UseSSE>=2 && jlong_cast(n->getd()) == 0 );
  4097   match(ConD);
  4099   format %{ %}
  4100   interface(CONST_INTER);
  4101 %}
  4103 // Float Immediate zero
  4104 operand immFPR0() %{
  4105   predicate(UseSSE == 0 && n->getf() == 0.0F);
  4106   match(ConF);
  4108   op_cost(5);
  4109   format %{ %}
  4110   interface(CONST_INTER);
  4111 %}
  4113 // Float Immediate one
  4114 operand immFPR1() %{
  4115   predicate(UseSSE == 0 && n->getf() == 1.0F);
  4116   match(ConF);
  4118   op_cost(5);
  4119   format %{ %}
  4120   interface(CONST_INTER);
  4121 %}
  4123 // Float Immediate
  4124 operand immFPR() %{
  4125   predicate( UseSSE == 0 );
  4126   match(ConF);
  4128   op_cost(5);
  4129   format %{ %}
  4130   interface(CONST_INTER);
  4131 %}
  4133 // Float Immediate
  4134 operand immF() %{
  4135   predicate(UseSSE >= 1);
  4136   match(ConF);
  4138   op_cost(5);
  4139   format %{ %}
  4140   interface(CONST_INTER);
  4141 %}
  4143 // Float Immediate zero.  Zero and not -0.0
  4144 operand immF0() %{
  4145   predicate( UseSSE >= 1 && jint_cast(n->getf()) == 0 );
  4146   match(ConF);
  4148   op_cost(5);
  4149   format %{ %}
  4150   interface(CONST_INTER);
  4151 %}
  4153 // Immediates for special shifts (sign extend)
  4155 // Constants for increment
  4156 operand immI_16() %{
  4157   predicate( n->get_int() == 16 );
  4158   match(ConI);
  4160   format %{ %}
  4161   interface(CONST_INTER);
  4162 %}
  4164 operand immI_24() %{
  4165   predicate( n->get_int() == 24 );
  4166   match(ConI);
  4168   format %{ %}
  4169   interface(CONST_INTER);
  4170 %}
  4172 // Constant for byte-wide masking
  4173 operand immI_255() %{
  4174   predicate( n->get_int() == 255 );
  4175   match(ConI);
  4177   format %{ %}
  4178   interface(CONST_INTER);
  4179 %}
  4181 // Constant for short-wide masking
  4182 operand immI_65535() %{
  4183   predicate(n->get_int() == 65535);
  4184   match(ConI);
  4186   format %{ %}
  4187   interface(CONST_INTER);
  4188 %}
  4190 // Register Operands
  4191 // Integer Register
  4192 operand rRegI() %{
  4193   constraint(ALLOC_IN_RC(int_reg));
  4194   match(RegI);
  4195   match(xRegI);
  4196   match(eAXRegI);
  4197   match(eBXRegI);
  4198   match(eCXRegI);
  4199   match(eDXRegI);
  4200   match(eDIRegI);
  4201   match(eSIRegI);
  4203   format %{ %}
  4204   interface(REG_INTER);
  4205 %}
  4207 // Subset of Integer Register
  4208 operand xRegI(rRegI reg) %{
  4209   constraint(ALLOC_IN_RC(int_x_reg));
  4210   match(reg);
  4211   match(eAXRegI);
  4212   match(eBXRegI);
  4213   match(eCXRegI);
  4214   match(eDXRegI);
  4216   format %{ %}
  4217   interface(REG_INTER);
  4218 %}
  4220 // Special Registers
  4221 operand eAXRegI(xRegI reg) %{
  4222   constraint(ALLOC_IN_RC(eax_reg));
  4223   match(reg);
  4224   match(rRegI);
  4226   format %{ "EAX" %}
  4227   interface(REG_INTER);
  4228 %}
  4230 // Special Registers
  4231 operand eBXRegI(xRegI reg) %{
  4232   constraint(ALLOC_IN_RC(ebx_reg));
  4233   match(reg);
  4234   match(rRegI);
  4236   format %{ "EBX" %}
  4237   interface(REG_INTER);
  4238 %}
  4240 operand eCXRegI(xRegI reg) %{
  4241   constraint(ALLOC_IN_RC(ecx_reg));
  4242   match(reg);
  4243   match(rRegI);
  4245   format %{ "ECX" %}
  4246   interface(REG_INTER);
  4247 %}
  4249 operand eDXRegI(xRegI reg) %{
  4250   constraint(ALLOC_IN_RC(edx_reg));
  4251   match(reg);
  4252   match(rRegI);
  4254   format %{ "EDX" %}
  4255   interface(REG_INTER);
  4256 %}
  4258 operand eDIRegI(xRegI reg) %{
  4259   constraint(ALLOC_IN_RC(edi_reg));
  4260   match(reg);
  4261   match(rRegI);
  4263   format %{ "EDI" %}
  4264   interface(REG_INTER);
  4265 %}
  4267 operand naxRegI() %{
  4268   constraint(ALLOC_IN_RC(nax_reg));
  4269   match(RegI);
  4270   match(eCXRegI);
  4271   match(eDXRegI);
  4272   match(eSIRegI);
  4273   match(eDIRegI);
  4275   format %{ %}
  4276   interface(REG_INTER);
  4277 %}
  4279 operand nadxRegI() %{
  4280   constraint(ALLOC_IN_RC(nadx_reg));
  4281   match(RegI);
  4282   match(eBXRegI);
  4283   match(eCXRegI);
  4284   match(eSIRegI);
  4285   match(eDIRegI);
  4287   format %{ %}
  4288   interface(REG_INTER);
  4289 %}
  4291 operand ncxRegI() %{
  4292   constraint(ALLOC_IN_RC(ncx_reg));
  4293   match(RegI);
  4294   match(eAXRegI);
  4295   match(eDXRegI);
  4296   match(eSIRegI);
  4297   match(eDIRegI);
  4299   format %{ %}
  4300   interface(REG_INTER);
  4301 %}
  4303 // // This operand was used by cmpFastUnlock, but conflicted with 'object' reg
  4304 // //
  4305 operand eSIRegI(xRegI reg) %{
  4306    constraint(ALLOC_IN_RC(esi_reg));
  4307    match(reg);
  4308    match(rRegI);
  4310    format %{ "ESI" %}
  4311    interface(REG_INTER);
  4312 %}
  4314 // Pointer Register
  4315 operand anyRegP() %{
  4316   constraint(ALLOC_IN_RC(any_reg));
  4317   match(RegP);
  4318   match(eAXRegP);
  4319   match(eBXRegP);
  4320   match(eCXRegP);
  4321   match(eDIRegP);
  4322   match(eRegP);
  4324   format %{ %}
  4325   interface(REG_INTER);
  4326 %}
  4328 operand eRegP() %{
  4329   constraint(ALLOC_IN_RC(int_reg));
  4330   match(RegP);
  4331   match(eAXRegP);
  4332   match(eBXRegP);
  4333   match(eCXRegP);
  4334   match(eDIRegP);
  4336   format %{ %}
  4337   interface(REG_INTER);
  4338 %}
  4340 // On windows95, EBP is not safe to use for implicit null tests.
  4341 operand eRegP_no_EBP() %{
  4342   constraint(ALLOC_IN_RC(int_reg_no_rbp));
  4343   match(RegP);
  4344   match(eAXRegP);
  4345   match(eBXRegP);
  4346   match(eCXRegP);
  4347   match(eDIRegP);
  4349   op_cost(100);
  4350   format %{ %}
  4351   interface(REG_INTER);
  4352 %}
  4354 operand naxRegP() %{
  4355   constraint(ALLOC_IN_RC(nax_reg));
  4356   match(RegP);
  4357   match(eBXRegP);
  4358   match(eDXRegP);
  4359   match(eCXRegP);
  4360   match(eSIRegP);
  4361   match(eDIRegP);
  4363   format %{ %}
  4364   interface(REG_INTER);
  4365 %}
  4367 operand nabxRegP() %{
  4368   constraint(ALLOC_IN_RC(nabx_reg));
  4369   match(RegP);
  4370   match(eCXRegP);
  4371   match(eDXRegP);
  4372   match(eSIRegP);
  4373   match(eDIRegP);
  4375   format %{ %}
  4376   interface(REG_INTER);
  4377 %}
  4379 operand pRegP() %{
  4380   constraint(ALLOC_IN_RC(p_reg));
  4381   match(RegP);
  4382   match(eBXRegP);
  4383   match(eDXRegP);
  4384   match(eSIRegP);
  4385   match(eDIRegP);
  4387   format %{ %}
  4388   interface(REG_INTER);
  4389 %}
  4391 // Special Registers
  4392 // Return a pointer value
  4393 operand eAXRegP(eRegP reg) %{
  4394   constraint(ALLOC_IN_RC(eax_reg));
  4395   match(reg);
  4396   format %{ "EAX" %}
  4397   interface(REG_INTER);
  4398 %}
  4400 // Used in AtomicAdd
  4401 operand eBXRegP(eRegP reg) %{
  4402   constraint(ALLOC_IN_RC(ebx_reg));
  4403   match(reg);
  4404   format %{ "EBX" %}
  4405   interface(REG_INTER);
  4406 %}
  4408 // Tail-call (interprocedural jump) to interpreter
  4409 operand eCXRegP(eRegP reg) %{
  4410   constraint(ALLOC_IN_RC(ecx_reg));
  4411   match(reg);
  4412   format %{ "ECX" %}
  4413   interface(REG_INTER);
  4414 %}
  4416 operand eSIRegP(eRegP reg) %{
  4417   constraint(ALLOC_IN_RC(esi_reg));
  4418   match(reg);
  4419   format %{ "ESI" %}
  4420   interface(REG_INTER);
  4421 %}
  4423 // Used in rep stosw
  4424 operand eDIRegP(eRegP reg) %{
  4425   constraint(ALLOC_IN_RC(edi_reg));
  4426   match(reg);
  4427   format %{ "EDI" %}
  4428   interface(REG_INTER);
  4429 %}
  4431 operand eBPRegP() %{
  4432   constraint(ALLOC_IN_RC(ebp_reg));
  4433   match(RegP);
  4434   format %{ "EBP" %}
  4435   interface(REG_INTER);
  4436 %}
  4438 operand eRegL() %{
  4439   constraint(ALLOC_IN_RC(long_reg));
  4440   match(RegL);
  4441   match(eADXRegL);
  4443   format %{ %}
  4444   interface(REG_INTER);
  4445 %}
  4447 operand eADXRegL( eRegL reg ) %{
  4448   constraint(ALLOC_IN_RC(eadx_reg));
  4449   match(reg);
  4451   format %{ "EDX:EAX" %}
  4452   interface(REG_INTER);
  4453 %}
  4455 operand eBCXRegL( eRegL reg ) %{
  4456   constraint(ALLOC_IN_RC(ebcx_reg));
  4457   match(reg);
  4459   format %{ "EBX:ECX" %}
  4460   interface(REG_INTER);
  4461 %}
  4463 // Special case for integer high multiply
  4464 operand eADXRegL_low_only() %{
  4465   constraint(ALLOC_IN_RC(eadx_reg));
  4466   match(RegL);
  4468   format %{ "EAX" %}
  4469   interface(REG_INTER);
  4470 %}
  4472 // Flags register, used as output of compare instructions
  4473 operand eFlagsReg() %{
  4474   constraint(ALLOC_IN_RC(int_flags));
  4475   match(RegFlags);
  4477   format %{ "EFLAGS" %}
  4478   interface(REG_INTER);
  4479 %}
  4481 // Flags register, used as output of FLOATING POINT compare instructions
  4482 operand eFlagsRegU() %{
  4483   constraint(ALLOC_IN_RC(int_flags));
  4484   match(RegFlags);
  4486   format %{ "EFLAGS_U" %}
  4487   interface(REG_INTER);
  4488 %}
  4490 operand eFlagsRegUCF() %{
  4491   constraint(ALLOC_IN_RC(int_flags));
  4492   match(RegFlags);
  4493   predicate(false);
  4495   format %{ "EFLAGS_U_CF" %}
  4496   interface(REG_INTER);
  4497 %}
  4499 // Condition Code Register used by long compare
  4500 operand flagsReg_long_LTGE() %{
  4501   constraint(ALLOC_IN_RC(int_flags));
  4502   match(RegFlags);
  4503   format %{ "FLAGS_LTGE" %}
  4504   interface(REG_INTER);
  4505 %}
  4506 operand flagsReg_long_EQNE() %{
  4507   constraint(ALLOC_IN_RC(int_flags));
  4508   match(RegFlags);
  4509   format %{ "FLAGS_EQNE" %}
  4510   interface(REG_INTER);
  4511 %}
  4512 operand flagsReg_long_LEGT() %{
  4513   constraint(ALLOC_IN_RC(int_flags));
  4514   match(RegFlags);
  4515   format %{ "FLAGS_LEGT" %}
  4516   interface(REG_INTER);
  4517 %}
  4519 // Float register operands
  4520 operand regDPR() %{
  4521   predicate( UseSSE < 2 );
  4522   constraint(ALLOC_IN_RC(fp_dbl_reg));
  4523   match(RegD);
  4524   match(regDPR1);
  4525   match(regDPR2);
  4526   format %{ %}
  4527   interface(REG_INTER);
  4528 %}
  4530 operand regDPR1(regDPR reg) %{
  4531   predicate( UseSSE < 2 );
  4532   constraint(ALLOC_IN_RC(fp_dbl_reg0));
  4533   match(reg);
  4534   format %{ "FPR1" %}
  4535   interface(REG_INTER);
  4536 %}
  4538 operand regDPR2(regDPR reg) %{
  4539   predicate( UseSSE < 2 );
  4540   constraint(ALLOC_IN_RC(fp_dbl_reg1));
  4541   match(reg);
  4542   format %{ "FPR2" %}
  4543   interface(REG_INTER);
  4544 %}
  4546 operand regnotDPR1(regDPR reg) %{
  4547   predicate( UseSSE < 2 );
  4548   constraint(ALLOC_IN_RC(fp_dbl_notreg0));
  4549   match(reg);
  4550   format %{ %}
  4551   interface(REG_INTER);
  4552 %}
  4554 // Float register operands
  4555 operand regFPR() %{
  4556   predicate( UseSSE < 2 );
  4557   constraint(ALLOC_IN_RC(fp_flt_reg));
  4558   match(RegF);
  4559   match(regFPR1);
  4560   format %{ %}
  4561   interface(REG_INTER);
  4562 %}
  4564 // Float register operands
  4565 operand regFPR1(regFPR reg) %{
  4566   predicate( UseSSE < 2 );
  4567   constraint(ALLOC_IN_RC(fp_flt_reg0));
  4568   match(reg);
  4569   format %{ "FPR1" %}
  4570   interface(REG_INTER);
  4571 %}
  4573 // XMM Float register operands
  4574 operand regF() %{
  4575   predicate( UseSSE>=1 );
  4576   constraint(ALLOC_IN_RC(float_reg));
  4577   match(RegF);
  4578   format %{ %}
  4579   interface(REG_INTER);
  4580 %}
  4582 // XMM Double register operands
  4583 operand regD() %{
  4584   predicate( UseSSE>=2 );
  4585   constraint(ALLOC_IN_RC(double_reg));
  4586   match(RegD);
  4587   format %{ %}
  4588   interface(REG_INTER);
  4589 %}
  4592 //----------Memory Operands----------------------------------------------------
  4593 // Direct Memory Operand
  4594 operand direct(immP addr) %{
  4595   match(addr);
  4597   format %{ "[$addr]" %}
  4598   interface(MEMORY_INTER) %{
  4599     base(0xFFFFFFFF);
  4600     index(0x4);
  4601     scale(0x0);
  4602     disp($addr);
  4603   %}
  4604 %}
  4606 // Indirect Memory Operand
  4607 operand indirect(eRegP reg) %{
  4608   constraint(ALLOC_IN_RC(int_reg));
  4609   match(reg);
  4611   format %{ "[$reg]" %}
  4612   interface(MEMORY_INTER) %{
  4613     base($reg);
  4614     index(0x4);
  4615     scale(0x0);
  4616     disp(0x0);
  4617   %}
  4618 %}
  4620 // Indirect Memory Plus Short Offset Operand
  4621 operand indOffset8(eRegP reg, immI8 off) %{
  4622   match(AddP reg off);
  4624   format %{ "[$reg + $off]" %}
  4625   interface(MEMORY_INTER) %{
  4626     base($reg);
  4627     index(0x4);
  4628     scale(0x0);
  4629     disp($off);
  4630   %}
  4631 %}
  4633 // Indirect Memory Plus Long Offset Operand
  4634 operand indOffset32(eRegP reg, immI off) %{
  4635   match(AddP reg off);
  4637   format %{ "[$reg + $off]" %}
  4638   interface(MEMORY_INTER) %{
  4639     base($reg);
  4640     index(0x4);
  4641     scale(0x0);
  4642     disp($off);
  4643   %}
  4644 %}
  4646 // Indirect Memory Plus Long Offset Operand
  4647 operand indOffset32X(rRegI reg, immP off) %{
  4648   match(AddP off reg);
  4650   format %{ "[$reg + $off]" %}
  4651   interface(MEMORY_INTER) %{
  4652     base($reg);
  4653     index(0x4);
  4654     scale(0x0);
  4655     disp($off);
  4656   %}
  4657 %}
  4659 // Indirect Memory Plus Index Register Plus Offset Operand
  4660 operand indIndexOffset(eRegP reg, rRegI ireg, immI off) %{
  4661   match(AddP (AddP reg ireg) off);
  4663   op_cost(10);
  4664   format %{"[$reg + $off + $ireg]" %}
  4665   interface(MEMORY_INTER) %{
  4666     base($reg);
  4667     index($ireg);
  4668     scale(0x0);
  4669     disp($off);
  4670   %}
  4671 %}
  4673 // Indirect Memory Plus Index Register Plus Offset Operand
  4674 operand indIndex(eRegP reg, rRegI ireg) %{
  4675   match(AddP reg ireg);
  4677   op_cost(10);
  4678   format %{"[$reg + $ireg]" %}
  4679   interface(MEMORY_INTER) %{
  4680     base($reg);
  4681     index($ireg);
  4682     scale(0x0);
  4683     disp(0x0);
  4684   %}
  4685 %}
  4687 // // -------------------------------------------------------------------------
  4688 // // 486 architecture doesn't support "scale * index + offset" with out a base
  4689 // // -------------------------------------------------------------------------
  4690 // // Scaled Memory Operands
  4691 // // Indirect Memory Times Scale Plus Offset Operand
  4692 // operand indScaleOffset(immP off, rRegI ireg, immI2 scale) %{
  4693 //   match(AddP off (LShiftI ireg scale));
  4694 //
  4695 //   op_cost(10);
  4696 //   format %{"[$off + $ireg << $scale]" %}
  4697 //   interface(MEMORY_INTER) %{
  4698 //     base(0x4);
  4699 //     index($ireg);
  4700 //     scale($scale);
  4701 //     disp($off);
  4702 //   %}
  4703 // %}
  4705 // Indirect Memory Times Scale Plus Index Register
  4706 operand indIndexScale(eRegP reg, rRegI ireg, immI2 scale) %{
  4707   match(AddP reg (LShiftI ireg scale));
  4709   op_cost(10);
  4710   format %{"[$reg + $ireg << $scale]" %}
  4711   interface(MEMORY_INTER) %{
  4712     base($reg);
  4713     index($ireg);
  4714     scale($scale);
  4715     disp(0x0);
  4716   %}
  4717 %}
  4719 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
  4720 operand indIndexScaleOffset(eRegP reg, immI off, rRegI ireg, immI2 scale) %{
  4721   match(AddP (AddP reg (LShiftI ireg scale)) off);
  4723   op_cost(10);
  4724   format %{"[$reg + $off + $ireg << $scale]" %}
  4725   interface(MEMORY_INTER) %{
  4726     base($reg);
  4727     index($ireg);
  4728     scale($scale);
  4729     disp($off);
  4730   %}
  4731 %}
  4733 //----------Load Long Memory Operands------------------------------------------
  4734 // The load-long idiom will use it's address expression again after loading
  4735 // the first word of the long.  If the load-long destination overlaps with
  4736 // registers used in the addressing expression, the 2nd half will be loaded
  4737 // from a clobbered address.  Fix this by requiring that load-long use
  4738 // address registers that do not overlap with the load-long target.
  4740 // load-long support
  4741 operand load_long_RegP() %{
  4742   constraint(ALLOC_IN_RC(esi_reg));
  4743   match(RegP);
  4744   match(eSIRegP);
  4745   op_cost(100);
  4746   format %{  %}
  4747   interface(REG_INTER);
  4748 %}
  4750 // Indirect Memory Operand Long
  4751 operand load_long_indirect(load_long_RegP reg) %{
  4752   constraint(ALLOC_IN_RC(esi_reg));
  4753   match(reg);
  4755   format %{ "[$reg]" %}
  4756   interface(MEMORY_INTER) %{
  4757     base($reg);
  4758     index(0x4);
  4759     scale(0x0);
  4760     disp(0x0);
  4761   %}
  4762 %}
  4764 // Indirect Memory Plus Long Offset Operand
  4765 operand load_long_indOffset32(load_long_RegP reg, immI off) %{
  4766   match(AddP reg off);
  4768   format %{ "[$reg + $off]" %}
  4769   interface(MEMORY_INTER) %{
  4770     base($reg);
  4771     index(0x4);
  4772     scale(0x0);
  4773     disp($off);
  4774   %}
  4775 %}
  4777 opclass load_long_memory(load_long_indirect, load_long_indOffset32);
  4780 //----------Special Memory Operands--------------------------------------------
  4781 // Stack Slot Operand - This operand is used for loading and storing temporary
  4782 //                      values on the stack where a match requires a value to
  4783 //                      flow through memory.
  4784 operand stackSlotP(sRegP reg) %{
  4785   constraint(ALLOC_IN_RC(stack_slots));
  4786   // No match rule because this operand is only generated in matching
  4787   format %{ "[$reg]" %}
  4788   interface(MEMORY_INTER) %{
  4789     base(0x4);   // ESP
  4790     index(0x4);  // No Index
  4791     scale(0x0);  // No Scale
  4792     disp($reg);  // Stack Offset
  4793   %}
  4794 %}
  4796 operand stackSlotI(sRegI reg) %{
  4797   constraint(ALLOC_IN_RC(stack_slots));
  4798   // No match rule because this operand is only generated in matching
  4799   format %{ "[$reg]" %}
  4800   interface(MEMORY_INTER) %{
  4801     base(0x4);   // ESP
  4802     index(0x4);  // No Index
  4803     scale(0x0);  // No Scale
  4804     disp($reg);  // Stack Offset
  4805   %}
  4806 %}
  4808 operand stackSlotF(sRegF reg) %{
  4809   constraint(ALLOC_IN_RC(stack_slots));
  4810   // No match rule because this operand is only generated in matching
  4811   format %{ "[$reg]" %}
  4812   interface(MEMORY_INTER) %{
  4813     base(0x4);   // ESP
  4814     index(0x4);  // No Index
  4815     scale(0x0);  // No Scale
  4816     disp($reg);  // Stack Offset
  4817   %}
  4818 %}
  4820 operand stackSlotD(sRegD reg) %{
  4821   constraint(ALLOC_IN_RC(stack_slots));
  4822   // No match rule because this operand is only generated in matching
  4823   format %{ "[$reg]" %}
  4824   interface(MEMORY_INTER) %{
  4825     base(0x4);   // ESP
  4826     index(0x4);  // No Index
  4827     scale(0x0);  // No Scale
  4828     disp($reg);  // Stack Offset
  4829   %}
  4830 %}
  4832 operand stackSlotL(sRegL reg) %{
  4833   constraint(ALLOC_IN_RC(stack_slots));
  4834   // No match rule because this operand is only generated in matching
  4835   format %{ "[$reg]" %}
  4836   interface(MEMORY_INTER) %{
  4837     base(0x4);   // ESP
  4838     index(0x4);  // No Index
  4839     scale(0x0);  // No Scale
  4840     disp($reg);  // Stack Offset
  4841   %}
  4842 %}
  4844 //----------Memory Operands - Win95 Implicit Null Variants----------------
  4845 // Indirect Memory Operand
  4846 operand indirect_win95_safe(eRegP_no_EBP reg)
  4847 %{
  4848   constraint(ALLOC_IN_RC(int_reg));
  4849   match(reg);
  4851   op_cost(100);
  4852   format %{ "[$reg]" %}
  4853   interface(MEMORY_INTER) %{
  4854     base($reg);
  4855     index(0x4);
  4856     scale(0x0);
  4857     disp(0x0);
  4858   %}
  4859 %}
  4861 // Indirect Memory Plus Short Offset Operand
  4862 operand indOffset8_win95_safe(eRegP_no_EBP reg, immI8 off)
  4863 %{
  4864   match(AddP reg off);
  4866   op_cost(100);
  4867   format %{ "[$reg + $off]" %}
  4868   interface(MEMORY_INTER) %{
  4869     base($reg);
  4870     index(0x4);
  4871     scale(0x0);
  4872     disp($off);
  4873   %}
  4874 %}
  4876 // Indirect Memory Plus Long Offset Operand
  4877 operand indOffset32_win95_safe(eRegP_no_EBP reg, immI off)
  4878 %{
  4879   match(AddP reg off);
  4881   op_cost(100);
  4882   format %{ "[$reg + $off]" %}
  4883   interface(MEMORY_INTER) %{
  4884     base($reg);
  4885     index(0x4);
  4886     scale(0x0);
  4887     disp($off);
  4888   %}
  4889 %}
  4891 // Indirect Memory Plus Index Register Plus Offset Operand
  4892 operand indIndexOffset_win95_safe(eRegP_no_EBP reg, rRegI ireg, immI off)
  4893 %{
  4894   match(AddP (AddP reg ireg) off);
  4896   op_cost(100);
  4897   format %{"[$reg + $off + $ireg]" %}
  4898   interface(MEMORY_INTER) %{
  4899     base($reg);
  4900     index($ireg);
  4901     scale(0x0);
  4902     disp($off);
  4903   %}
  4904 %}
  4906 // Indirect Memory Times Scale Plus Index Register
  4907 operand indIndexScale_win95_safe(eRegP_no_EBP reg, rRegI ireg, immI2 scale)
  4908 %{
  4909   match(AddP reg (LShiftI ireg scale));
  4911   op_cost(100);
  4912   format %{"[$reg + $ireg << $scale]" %}
  4913   interface(MEMORY_INTER) %{
  4914     base($reg);
  4915     index($ireg);
  4916     scale($scale);
  4917     disp(0x0);
  4918   %}
  4919 %}
  4921 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
  4922 operand indIndexScaleOffset_win95_safe(eRegP_no_EBP reg, immI off, rRegI ireg, immI2 scale)
  4923 %{
  4924   match(AddP (AddP reg (LShiftI ireg scale)) off);
  4926   op_cost(100);
  4927   format %{"[$reg + $off + $ireg << $scale]" %}
  4928   interface(MEMORY_INTER) %{
  4929     base($reg);
  4930     index($ireg);
  4931     scale($scale);
  4932     disp($off);
  4933   %}
  4934 %}
  4936 //----------Conditional Branch Operands----------------------------------------
  4937 // Comparison Op  - This is the operation of the comparison, and is limited to
  4938 //                  the following set of codes:
  4939 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
  4940 //
  4941 // Other attributes of the comparison, such as unsignedness, are specified
  4942 // by the comparison instruction that sets a condition code flags register.
  4943 // That result is represented by a flags operand whose subtype is appropriate
  4944 // to the unsignedness (etc.) of the comparison.
  4945 //
  4946 // Later, the instruction which matches both the Comparison Op (a Bool) and
  4947 // the flags (produced by the Cmp) specifies the coding of the comparison op
  4948 // by matching a specific subtype of Bool operand below, such as cmpOpU.
  4950 // Comparision Code
  4951 operand cmpOp() %{
  4952   match(Bool);
  4954   format %{ "" %}
  4955   interface(COND_INTER) %{
  4956     equal(0x4, "e");
  4957     not_equal(0x5, "ne");
  4958     less(0xC, "l");
  4959     greater_equal(0xD, "ge");
  4960     less_equal(0xE, "le");
  4961     greater(0xF, "g");
  4962   %}
  4963 %}
  4965 // Comparison Code, unsigned compare.  Used by FP also, with
  4966 // C2 (unordered) turned into GT or LT already.  The other bits
  4967 // C0 and C3 are turned into Carry & Zero flags.
  4968 operand cmpOpU() %{
  4969   match(Bool);
  4971   format %{ "" %}
  4972   interface(COND_INTER) %{
  4973     equal(0x4, "e");
  4974     not_equal(0x5, "ne");
  4975     less(0x2, "b");
  4976     greater_equal(0x3, "nb");
  4977     less_equal(0x6, "be");
  4978     greater(0x7, "nbe");
  4979   %}
  4980 %}
  4982 // Floating comparisons that don't require any fixup for the unordered case
  4983 operand cmpOpUCF() %{
  4984   match(Bool);
  4985   predicate(n->as_Bool()->_test._test == BoolTest::lt ||
  4986             n->as_Bool()->_test._test == BoolTest::ge ||
  4987             n->as_Bool()->_test._test == BoolTest::le ||
  4988             n->as_Bool()->_test._test == BoolTest::gt);
  4989   format %{ "" %}
  4990   interface(COND_INTER) %{
  4991     equal(0x4, "e");
  4992     not_equal(0x5, "ne");
  4993     less(0x2, "b");
  4994     greater_equal(0x3, "nb");
  4995     less_equal(0x6, "be");
  4996     greater(0x7, "nbe");
  4997   %}
  4998 %}
  5001 // Floating comparisons that can be fixed up with extra conditional jumps
  5002 operand cmpOpUCF2() %{
  5003   match(Bool);
  5004   predicate(n->as_Bool()->_test._test == BoolTest::ne ||
  5005             n->as_Bool()->_test._test == BoolTest::eq);
  5006   format %{ "" %}
  5007   interface(COND_INTER) %{
  5008     equal(0x4, "e");
  5009     not_equal(0x5, "ne");
  5010     less(0x2, "b");
  5011     greater_equal(0x3, "nb");
  5012     less_equal(0x6, "be");
  5013     greater(0x7, "nbe");
  5014   %}
  5015 %}
  5017 // Comparison Code for FP conditional move
  5018 operand cmpOp_fcmov() %{
  5019   match(Bool);
  5021   format %{ "" %}
  5022   interface(COND_INTER) %{
  5023     equal        (0x0C8);
  5024     not_equal    (0x1C8);
  5025     less         (0x0C0);
  5026     greater_equal(0x1C0);
  5027     less_equal   (0x0D0);
  5028     greater      (0x1D0);
  5029   %}
  5030 %}
  5032 // Comparision Code used in long compares
  5033 operand cmpOp_commute() %{
  5034   match(Bool);
  5036   format %{ "" %}
  5037   interface(COND_INTER) %{
  5038     equal(0x4, "e");
  5039     not_equal(0x5, "ne");
  5040     less(0xF, "g");
  5041     greater_equal(0xE, "le");
  5042     less_equal(0xD, "ge");
  5043     greater(0xC, "l");
  5044   %}
  5045 %}
  5047 //----------OPERAND CLASSES----------------------------------------------------
  5048 // Operand Classes are groups of operands that are used as to simplify
  5049 // instruction definitions by not requiring the AD writer to specify separate
  5050 // instructions for every form of operand when the instruction accepts
  5051 // multiple operand types with the same basic encoding and format.  The classic
  5052 // case of this is memory operands.
  5054 opclass memory(direct, indirect, indOffset8, indOffset32, indOffset32X, indIndexOffset,
  5055                indIndex, indIndexScale, indIndexScaleOffset);
  5057 // Long memory operations are encoded in 2 instructions and a +4 offset.
  5058 // This means some kind of offset is always required and you cannot use
  5059 // an oop as the offset (done when working on static globals).
  5060 opclass long_memory(direct, indirect, indOffset8, indOffset32, indIndexOffset,
  5061                     indIndex, indIndexScale, indIndexScaleOffset);
  5064 //----------PIPELINE-----------------------------------------------------------
  5065 // Rules which define the behavior of the target architectures pipeline.
  5066 pipeline %{
  5068 //----------ATTRIBUTES---------------------------------------------------------
  5069 attributes %{
  5070   variable_size_instructions;        // Fixed size instructions
  5071   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
  5072   instruction_unit_size = 1;         // An instruction is 1 bytes long
  5073   instruction_fetch_unit_size = 16;  // The processor fetches one line
  5074   instruction_fetch_units = 1;       // of 16 bytes
  5076   // List of nop instructions
  5077   nops( MachNop );
  5078 %}
  5080 //----------RESOURCES----------------------------------------------------------
  5081 // Resources are the functional units available to the machine
  5083 // Generic P2/P3 pipeline
  5084 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
  5085 // 3 instructions decoded per cycle.
  5086 // 2 load/store ops per cycle, 1 branch, 1 FPU,
  5087 // 2 ALU op, only ALU0 handles mul/div instructions.
  5088 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
  5089            MS0, MS1, MEM = MS0 | MS1,
  5090            BR, FPU,
  5091            ALU0, ALU1, ALU = ALU0 | ALU1 );
  5093 //----------PIPELINE DESCRIPTION-----------------------------------------------
  5094 // Pipeline Description specifies the stages in the machine's pipeline
  5096 // Generic P2/P3 pipeline
  5097 pipe_desc(S0, S1, S2, S3, S4, S5);
  5099 //----------PIPELINE CLASSES---------------------------------------------------
  5100 // Pipeline Classes describe the stages in which input and output are
  5101 // referenced by the hardware pipeline.
  5103 // Naming convention: ialu or fpu
  5104 // Then: _reg
  5105 // Then: _reg if there is a 2nd register
  5106 // Then: _long if it's a pair of instructions implementing a long
  5107 // Then: _fat if it requires the big decoder
  5108 //   Or: _mem if it requires the big decoder and a memory unit.
  5110 // Integer ALU reg operation
  5111 pipe_class ialu_reg(rRegI dst) %{
  5112     single_instruction;
  5113     dst    : S4(write);
  5114     dst    : S3(read);
  5115     DECODE : S0;        // any decoder
  5116     ALU    : S3;        // any alu
  5117 %}
  5119 // Long ALU reg operation
  5120 pipe_class ialu_reg_long(eRegL dst) %{
  5121     instruction_count(2);
  5122     dst    : S4(write);
  5123     dst    : S3(read);
  5124     DECODE : S0(2);     // any 2 decoders
  5125     ALU    : S3(2);     // both alus
  5126 %}
  5128 // Integer ALU reg operation using big decoder
  5129 pipe_class ialu_reg_fat(rRegI dst) %{
  5130     single_instruction;
  5131     dst    : S4(write);
  5132     dst    : S3(read);
  5133     D0     : S0;        // big decoder only
  5134     ALU    : S3;        // any alu
  5135 %}
  5137 // Long ALU reg operation using big decoder
  5138 pipe_class ialu_reg_long_fat(eRegL dst) %{
  5139     instruction_count(2);
  5140     dst    : S4(write);
  5141     dst    : S3(read);
  5142     D0     : S0(2);     // big decoder only; twice
  5143     ALU    : S3(2);     // any 2 alus
  5144 %}
  5146 // Integer ALU reg-reg operation
  5147 pipe_class ialu_reg_reg(rRegI dst, rRegI src) %{
  5148     single_instruction;
  5149     dst    : S4(write);
  5150     src    : S3(read);
  5151     DECODE : S0;        // any decoder
  5152     ALU    : S3;        // any alu
  5153 %}
  5155 // Long ALU reg-reg operation
  5156 pipe_class ialu_reg_reg_long(eRegL dst, eRegL src) %{
  5157     instruction_count(2);
  5158     dst    : S4(write);
  5159     src    : S3(read);
  5160     DECODE : S0(2);     // any 2 decoders
  5161     ALU    : S3(2);     // both alus
  5162 %}
  5164 // Integer ALU reg-reg operation
  5165 pipe_class ialu_reg_reg_fat(rRegI dst, memory src) %{
  5166     single_instruction;
  5167     dst    : S4(write);
  5168     src    : S3(read);
  5169     D0     : S0;        // big decoder only
  5170     ALU    : S3;        // any alu
  5171 %}
  5173 // Long ALU reg-reg operation
  5174 pipe_class ialu_reg_reg_long_fat(eRegL dst, eRegL src) %{
  5175     instruction_count(2);
  5176     dst    : S4(write);
  5177     src    : S3(read);
  5178     D0     : S0(2);     // big decoder only; twice
  5179     ALU    : S3(2);     // both alus
  5180 %}
  5182 // Integer ALU reg-mem operation
  5183 pipe_class ialu_reg_mem(rRegI dst, memory mem) %{
  5184     single_instruction;
  5185     dst    : S5(write);
  5186     mem    : S3(read);
  5187     D0     : S0;        // big decoder only
  5188     ALU    : S4;        // any alu
  5189     MEM    : S3;        // any mem
  5190 %}
  5192 // Long ALU reg-mem operation
  5193 pipe_class ialu_reg_long_mem(eRegL dst, load_long_memory mem) %{
  5194     instruction_count(2);
  5195     dst    : S5(write);
  5196     mem    : S3(read);
  5197     D0     : S0(2);     // big decoder only; twice
  5198     ALU    : S4(2);     // any 2 alus
  5199     MEM    : S3(2);     // both mems
  5200 %}
  5202 // Integer mem operation (prefetch)
  5203 pipe_class ialu_mem(memory mem)
  5204 %{
  5205     single_instruction;
  5206     mem    : S3(read);
  5207     D0     : S0;        // big decoder only
  5208     MEM    : S3;        // any mem
  5209 %}
  5211 // Integer Store to Memory
  5212 pipe_class ialu_mem_reg(memory mem, rRegI src) %{
  5213     single_instruction;
  5214     mem    : S3(read);
  5215     src    : S5(read);
  5216     D0     : S0;        // big decoder only
  5217     ALU    : S4;        // any alu
  5218     MEM    : S3;
  5219 %}
  5221 // Long Store to Memory
  5222 pipe_class ialu_mem_long_reg(memory mem, eRegL src) %{
  5223     instruction_count(2);
  5224     mem    : S3(read);
  5225     src    : S5(read);
  5226     D0     : S0(2);     // big decoder only; twice
  5227     ALU    : S4(2);     // any 2 alus
  5228     MEM    : S3(2);     // Both mems
  5229 %}
  5231 // Integer Store to Memory
  5232 pipe_class ialu_mem_imm(memory mem) %{
  5233     single_instruction;
  5234     mem    : S3(read);
  5235     D0     : S0;        // big decoder only
  5236     ALU    : S4;        // any alu
  5237     MEM    : S3;
  5238 %}
  5240 // Integer ALU0 reg-reg operation
  5241 pipe_class ialu_reg_reg_alu0(rRegI dst, rRegI src) %{
  5242     single_instruction;
  5243     dst    : S4(write);
  5244     src    : S3(read);
  5245     D0     : S0;        // Big decoder only
  5246     ALU0   : S3;        // only alu0
  5247 %}
  5249 // Integer ALU0 reg-mem operation
  5250 pipe_class ialu_reg_mem_alu0(rRegI dst, memory mem) %{
  5251     single_instruction;
  5252     dst    : S5(write);
  5253     mem    : S3(read);
  5254     D0     : S0;        // big decoder only
  5255     ALU0   : S4;        // ALU0 only
  5256     MEM    : S3;        // any mem
  5257 %}
  5259 // Integer ALU reg-reg operation
  5260 pipe_class ialu_cr_reg_reg(eFlagsReg cr, rRegI src1, rRegI src2) %{
  5261     single_instruction;
  5262     cr     : S4(write);
  5263     src1   : S3(read);
  5264     src2   : S3(read);
  5265     DECODE : S0;        // any decoder
  5266     ALU    : S3;        // any alu
  5267 %}
  5269 // Integer ALU reg-imm operation
  5270 pipe_class ialu_cr_reg_imm(eFlagsReg cr, rRegI src1) %{
  5271     single_instruction;
  5272     cr     : S4(write);
  5273     src1   : S3(read);
  5274     DECODE : S0;        // any decoder
  5275     ALU    : S3;        // any alu
  5276 %}
  5278 // Integer ALU reg-mem operation
  5279 pipe_class ialu_cr_reg_mem(eFlagsReg cr, rRegI src1, memory src2) %{
  5280     single_instruction;
  5281     cr     : S4(write);
  5282     src1   : S3(read);
  5283     src2   : S3(read);
  5284     D0     : S0;        // big decoder only
  5285     ALU    : S4;        // any alu
  5286     MEM    : S3;
  5287 %}
  5289 // Conditional move reg-reg
  5290 pipe_class pipe_cmplt( rRegI p, rRegI q, rRegI y ) %{
  5291     instruction_count(4);
  5292     y      : S4(read);
  5293     q      : S3(read);
  5294     p      : S3(read);
  5295     DECODE : S0(4);     // any decoder
  5296 %}
  5298 // Conditional move reg-reg
  5299 pipe_class pipe_cmov_reg( rRegI dst, rRegI src, eFlagsReg cr ) %{
  5300     single_instruction;
  5301     dst    : S4(write);
  5302     src    : S3(read);
  5303     cr     : S3(read);
  5304     DECODE : S0;        // any decoder
  5305 %}
  5307 // Conditional move reg-mem
  5308 pipe_class pipe_cmov_mem( eFlagsReg cr, rRegI dst, memory src) %{
  5309     single_instruction;
  5310     dst    : S4(write);
  5311     src    : S3(read);
  5312     cr     : S3(read);
  5313     DECODE : S0;        // any decoder
  5314     MEM    : S3;
  5315 %}
  5317 // Conditional move reg-reg long
  5318 pipe_class pipe_cmov_reg_long( eFlagsReg cr, eRegL dst, eRegL src) %{
  5319     single_instruction;
  5320     dst    : S4(write);
  5321     src    : S3(read);
  5322     cr     : S3(read);
  5323     DECODE : S0(2);     // any 2 decoders
  5324 %}
  5326 // Conditional move double reg-reg
  5327 pipe_class pipe_cmovDPR_reg( eFlagsReg cr, regDPR1 dst, regDPR src) %{
  5328     single_instruction;
  5329     dst    : S4(write);
  5330     src    : S3(read);
  5331     cr     : S3(read);
  5332     DECODE : S0;        // any decoder
  5333 %}
  5335 // Float reg-reg operation
  5336 pipe_class fpu_reg(regDPR dst) %{
  5337     instruction_count(2);
  5338     dst    : S3(read);
  5339     DECODE : S0(2);     // any 2 decoders
  5340     FPU    : S3;
  5341 %}
  5343 // Float reg-reg operation
  5344 pipe_class fpu_reg_reg(regDPR dst, regDPR src) %{
  5345     instruction_count(2);
  5346     dst    : S4(write);
  5347     src    : S3(read);
  5348     DECODE : S0(2);     // any 2 decoders
  5349     FPU    : S3;
  5350 %}
  5352 // Float reg-reg operation
  5353 pipe_class fpu_reg_reg_reg(regDPR dst, regDPR src1, regDPR src2) %{
  5354     instruction_count(3);
  5355     dst    : S4(write);
  5356     src1   : S3(read);
  5357     src2   : S3(read);
  5358     DECODE : S0(3);     // any 3 decoders
  5359     FPU    : S3(2);
  5360 %}
  5362 // Float reg-reg operation
  5363 pipe_class fpu_reg_reg_reg_reg(regDPR dst, regDPR src1, regDPR src2, regDPR src3) %{
  5364     instruction_count(4);
  5365     dst    : S4(write);
  5366     src1   : S3(read);
  5367     src2   : S3(read);
  5368     src3   : S3(read);
  5369     DECODE : S0(4);     // any 3 decoders
  5370     FPU    : S3(2);
  5371 %}
  5373 // Float reg-reg operation
  5374 pipe_class fpu_reg_mem_reg_reg(regDPR dst, memory src1, regDPR src2, regDPR src3) %{
  5375     instruction_count(4);
  5376     dst    : S4(write);
  5377     src1   : S3(read);
  5378     src2   : S3(read);
  5379     src3   : S3(read);
  5380     DECODE : S1(3);     // any 3 decoders
  5381     D0     : S0;        // Big decoder only
  5382     FPU    : S3(2);
  5383     MEM    : S3;
  5384 %}
  5386 // Float reg-mem operation
  5387 pipe_class fpu_reg_mem(regDPR dst, memory mem) %{
  5388     instruction_count(2);
  5389     dst    : S5(write);
  5390     mem    : S3(read);
  5391     D0     : S0;        // big decoder only
  5392     DECODE : S1;        // any decoder for FPU POP
  5393     FPU    : S4;
  5394     MEM    : S3;        // any mem
  5395 %}
  5397 // Float reg-mem operation
  5398 pipe_class fpu_reg_reg_mem(regDPR dst, regDPR src1, memory mem) %{
  5399     instruction_count(3);
  5400     dst    : S5(write);
  5401     src1   : S3(read);
  5402     mem    : S3(read);
  5403     D0     : S0;        // big decoder only
  5404     DECODE : S1(2);     // any decoder for FPU POP
  5405     FPU    : S4;
  5406     MEM    : S3;        // any mem
  5407 %}
  5409 // Float mem-reg operation
  5410 pipe_class fpu_mem_reg(memory mem, regDPR src) %{
  5411     instruction_count(2);
  5412     src    : S5(read);
  5413     mem    : S3(read);
  5414     DECODE : S0;        // any decoder for FPU PUSH
  5415     D0     : S1;        // big decoder only
  5416     FPU    : S4;
  5417     MEM    : S3;        // any mem
  5418 %}
  5420 pipe_class fpu_mem_reg_reg(memory mem, regDPR src1, regDPR src2) %{
  5421     instruction_count(3);
  5422     src1   : S3(read);
  5423     src2   : S3(read);
  5424     mem    : S3(read);
  5425     DECODE : S0(2);     // any decoder for FPU PUSH
  5426     D0     : S1;        // big decoder only
  5427     FPU    : S4;
  5428     MEM    : S3;        // any mem
  5429 %}
  5431 pipe_class fpu_mem_reg_mem(memory mem, regDPR src1, memory src2) %{
  5432     instruction_count(3);
  5433     src1   : S3(read);
  5434     src2   : S3(read);
  5435     mem    : S4(read);
  5436     DECODE : S0;        // any decoder for FPU PUSH
  5437     D0     : S0(2);     // big decoder only
  5438     FPU    : S4;
  5439     MEM    : S3(2);     // any mem
  5440 %}
  5442 pipe_class fpu_mem_mem(memory dst, memory src1) %{
  5443     instruction_count(2);
  5444     src1   : S3(read);
  5445     dst    : S4(read);
  5446     D0     : S0(2);     // big decoder only
  5447     MEM    : S3(2);     // any mem
  5448 %}
  5450 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2) %{
  5451     instruction_count(3);
  5452     src1   : S3(read);
  5453     src2   : S3(read);
  5454     dst    : S4(read);
  5455     D0     : S0(3);     // big decoder only
  5456     FPU    : S4;
  5457     MEM    : S3(3);     // any mem
  5458 %}
  5460 pipe_class fpu_mem_reg_con(memory mem, regDPR src1) %{
  5461     instruction_count(3);
  5462     src1   : S4(read);
  5463     mem    : S4(read);
  5464     DECODE : S0;        // any decoder for FPU PUSH
  5465     D0     : S0(2);     // big decoder only
  5466     FPU    : S4;
  5467     MEM    : S3(2);     // any mem
  5468 %}
  5470 // Float load constant
  5471 pipe_class fpu_reg_con(regDPR dst) %{
  5472     instruction_count(2);
  5473     dst    : S5(write);
  5474     D0     : S0;        // big decoder only for the load
  5475     DECODE : S1;        // any decoder for FPU POP
  5476     FPU    : S4;
  5477     MEM    : S3;        // any mem
  5478 %}
  5480 // Float load constant
  5481 pipe_class fpu_reg_reg_con(regDPR dst, regDPR src) %{
  5482     instruction_count(3);
  5483     dst    : S5(write);
  5484     src    : S3(read);
  5485     D0     : S0;        // big decoder only for the load
  5486     DECODE : S1(2);     // any decoder for FPU POP
  5487     FPU    : S4;
  5488     MEM    : S3;        // any mem
  5489 %}
  5491 // UnConditional branch
  5492 pipe_class pipe_jmp( label labl ) %{
  5493     single_instruction;
  5494     BR   : S3;
  5495 %}
  5497 // Conditional branch
  5498 pipe_class pipe_jcc( cmpOp cmp, eFlagsReg cr, label labl ) %{
  5499     single_instruction;
  5500     cr    : S1(read);
  5501     BR    : S3;
  5502 %}
  5504 // Allocation idiom
  5505 pipe_class pipe_cmpxchg( eRegP dst, eRegP heap_ptr ) %{
  5506     instruction_count(1); force_serialization;
  5507     fixed_latency(6);
  5508     heap_ptr : S3(read);
  5509     DECODE   : S0(3);
  5510     D0       : S2;
  5511     MEM      : S3;
  5512     ALU      : S3(2);
  5513     dst      : S5(write);
  5514     BR       : S5;
  5515 %}
  5517 // Generic big/slow expanded idiom
  5518 pipe_class pipe_slow(  ) %{
  5519     instruction_count(10); multiple_bundles; force_serialization;
  5520     fixed_latency(100);
  5521     D0  : S0(2);
  5522     MEM : S3(2);
  5523 %}
  5525 // The real do-nothing guy
  5526 pipe_class empty( ) %{
  5527     instruction_count(0);
  5528 %}
  5530 // Define the class for the Nop node
  5531 define %{
  5532    MachNop = empty;
  5533 %}
  5535 %}
  5537 //----------INSTRUCTIONS-------------------------------------------------------
  5538 //
  5539 // match      -- States which machine-independent subtree may be replaced
  5540 //               by this instruction.
  5541 // ins_cost   -- The estimated cost of this instruction is used by instruction
  5542 //               selection to identify a minimum cost tree of machine
  5543 //               instructions that matches a tree of machine-independent
  5544 //               instructions.
  5545 // format     -- A string providing the disassembly for this instruction.
  5546 //               The value of an instruction's operand may be inserted
  5547 //               by referring to it with a '$' prefix.
  5548 // opcode     -- Three instruction opcodes may be provided.  These are referred
  5549 //               to within an encode class as $primary, $secondary, and $tertiary
  5550 //               respectively.  The primary opcode is commonly used to
  5551 //               indicate the type of machine instruction, while secondary
  5552 //               and tertiary are often used for prefix options or addressing
  5553 //               modes.
  5554 // ins_encode -- A list of encode classes with parameters. The encode class
  5555 //               name must have been defined in an 'enc_class' specification
  5556 //               in the encode section of the architecture description.
  5558 //----------BSWAP-Instruction--------------------------------------------------
  5559 instruct bytes_reverse_int(rRegI dst) %{
  5560   match(Set dst (ReverseBytesI dst));
  5562   format %{ "BSWAP  $dst" %}
  5563   opcode(0x0F, 0xC8);
  5564   ins_encode( OpcP, OpcSReg(dst) );
  5565   ins_pipe( ialu_reg );
  5566 %}
  5568 instruct bytes_reverse_long(eRegL dst) %{
  5569   match(Set dst (ReverseBytesL dst));
  5571   format %{ "BSWAP  $dst.lo\n\t"
  5572             "BSWAP  $dst.hi\n\t"
  5573             "XCHG   $dst.lo $dst.hi" %}
  5575   ins_cost(125);
  5576   ins_encode( bswap_long_bytes(dst) );
  5577   ins_pipe( ialu_reg_reg);
  5578 %}
  5580 instruct bytes_reverse_unsigned_short(rRegI dst, eFlagsReg cr) %{
  5581   match(Set dst (ReverseBytesUS dst));
  5582   effect(KILL cr);
  5584   format %{ "BSWAP  $dst\n\t" 
  5585             "SHR    $dst,16\n\t" %}
  5586   ins_encode %{
  5587     __ bswapl($dst$$Register);
  5588     __ shrl($dst$$Register, 16); 
  5589   %}
  5590   ins_pipe( ialu_reg );
  5591 %}
  5593 instruct bytes_reverse_short(rRegI dst, eFlagsReg cr) %{
  5594   match(Set dst (ReverseBytesS dst));
  5595   effect(KILL cr);
  5597   format %{ "BSWAP  $dst\n\t" 
  5598             "SAR    $dst,16\n\t" %}
  5599   ins_encode %{
  5600     __ bswapl($dst$$Register);
  5601     __ sarl($dst$$Register, 16); 
  5602   %}
  5603   ins_pipe( ialu_reg );
  5604 %}
  5607 //---------- Zeros Count Instructions ------------------------------------------
  5609 instruct countLeadingZerosI(rRegI dst, rRegI src, eFlagsReg cr) %{
  5610   predicate(UseCountLeadingZerosInstruction);
  5611   match(Set dst (CountLeadingZerosI src));
  5612   effect(KILL cr);
  5614   format %{ "LZCNT  $dst, $src\t# count leading zeros (int)" %}
  5615   ins_encode %{
  5616     __ lzcntl($dst$$Register, $src$$Register);
  5617   %}
  5618   ins_pipe(ialu_reg);
  5619 %}
  5621 instruct countLeadingZerosI_bsr(rRegI dst, rRegI src, eFlagsReg cr) %{
  5622   predicate(!UseCountLeadingZerosInstruction);
  5623   match(Set dst (CountLeadingZerosI src));
  5624   effect(KILL cr);
  5626   format %{ "BSR    $dst, $src\t# count leading zeros (int)\n\t"
  5627             "JNZ    skip\n\t"
  5628             "MOV    $dst, -1\n"
  5629       "skip:\n\t"
  5630             "NEG    $dst\n\t"
  5631             "ADD    $dst, 31" %}
  5632   ins_encode %{
  5633     Register Rdst = $dst$$Register;
  5634     Register Rsrc = $src$$Register;
  5635     Label skip;
  5636     __ bsrl(Rdst, Rsrc);
  5637     __ jccb(Assembler::notZero, skip);
  5638     __ movl(Rdst, -1);
  5639     __ bind(skip);
  5640     __ negl(Rdst);
  5641     __ addl(Rdst, BitsPerInt - 1);
  5642   %}
  5643   ins_pipe(ialu_reg);
  5644 %}
  5646 instruct countLeadingZerosL(rRegI dst, eRegL src, eFlagsReg cr) %{
  5647   predicate(UseCountLeadingZerosInstruction);
  5648   match(Set dst (CountLeadingZerosL src));
  5649   effect(TEMP dst, KILL cr);
  5651   format %{ "LZCNT  $dst, $src.hi\t# count leading zeros (long)\n\t"
  5652             "JNC    done\n\t"
  5653             "LZCNT  $dst, $src.lo\n\t"
  5654             "ADD    $dst, 32\n"
  5655       "done:" %}
  5656   ins_encode %{
  5657     Register Rdst = $dst$$Register;
  5658     Register Rsrc = $src$$Register;
  5659     Label done;
  5660     __ lzcntl(Rdst, HIGH_FROM_LOW(Rsrc));
  5661     __ jccb(Assembler::carryClear, done);
  5662     __ lzcntl(Rdst, Rsrc);
  5663     __ addl(Rdst, BitsPerInt);
  5664     __ bind(done);
  5665   %}
  5666   ins_pipe(ialu_reg);
  5667 %}
  5669 instruct countLeadingZerosL_bsr(rRegI dst, eRegL src, eFlagsReg cr) %{
  5670   predicate(!UseCountLeadingZerosInstruction);
  5671   match(Set dst (CountLeadingZerosL src));
  5672   effect(TEMP dst, KILL cr);
  5674   format %{ "BSR    $dst, $src.hi\t# count leading zeros (long)\n\t"
  5675             "JZ     msw_is_zero\n\t"
  5676             "ADD    $dst, 32\n\t"
  5677             "JMP    not_zero\n"
  5678       "msw_is_zero:\n\t"
  5679             "BSR    $dst, $src.lo\n\t"
  5680             "JNZ    not_zero\n\t"
  5681             "MOV    $dst, -1\n"
  5682       "not_zero:\n\t"
  5683             "NEG    $dst\n\t"
  5684             "ADD    $dst, 63\n" %}
  5685  ins_encode %{
  5686     Register Rdst = $dst$$Register;
  5687     Register Rsrc = $src$$Register;
  5688     Label msw_is_zero;
  5689     Label not_zero;
  5690     __ bsrl(Rdst, HIGH_FROM_LOW(Rsrc));
  5691     __ jccb(Assembler::zero, msw_is_zero);
  5692     __ addl(Rdst, BitsPerInt);
  5693     __ jmpb(not_zero);
  5694     __ bind(msw_is_zero);
  5695     __ bsrl(Rdst, Rsrc);
  5696     __ jccb(Assembler::notZero, not_zero);
  5697     __ movl(Rdst, -1);
  5698     __ bind(not_zero);
  5699     __ negl(Rdst);
  5700     __ addl(Rdst, BitsPerLong - 1);
  5701   %}
  5702   ins_pipe(ialu_reg);
  5703 %}
  5705 instruct countTrailingZerosI(rRegI dst, rRegI src, eFlagsReg cr) %{
  5706   match(Set dst (CountTrailingZerosI src));
  5707   effect(KILL cr);
  5709   format %{ "BSF    $dst, $src\t# count trailing zeros (int)\n\t"
  5710             "JNZ    done\n\t"
  5711             "MOV    $dst, 32\n"
  5712       "done:" %}
  5713   ins_encode %{
  5714     Register Rdst = $dst$$Register;
  5715     Label done;
  5716     __ bsfl(Rdst, $src$$Register);
  5717     __ jccb(Assembler::notZero, done);
  5718     __ movl(Rdst, BitsPerInt);
  5719     __ bind(done);
  5720   %}
  5721   ins_pipe(ialu_reg);
  5722 %}
  5724 instruct countTrailingZerosL(rRegI dst, eRegL src, eFlagsReg cr) %{
  5725   match(Set dst (CountTrailingZerosL src));
  5726   effect(TEMP dst, KILL cr);
  5728   format %{ "BSF    $dst, $src.lo\t# count trailing zeros (long)\n\t"
  5729             "JNZ    done\n\t"
  5730             "BSF    $dst, $src.hi\n\t"
  5731             "JNZ    msw_not_zero\n\t"
  5732             "MOV    $dst, 32\n"
  5733       "msw_not_zero:\n\t"
  5734             "ADD    $dst, 32\n"
  5735       "done:" %}
  5736   ins_encode %{
  5737     Register Rdst = $dst$$Register;
  5738     Register Rsrc = $src$$Register;
  5739     Label msw_not_zero;
  5740     Label done;
  5741     __ bsfl(Rdst, Rsrc);
  5742     __ jccb(Assembler::notZero, done);
  5743     __ bsfl(Rdst, HIGH_FROM_LOW(Rsrc));
  5744     __ jccb(Assembler::notZero, msw_not_zero);
  5745     __ movl(Rdst, BitsPerInt);
  5746     __ bind(msw_not_zero);
  5747     __ addl(Rdst, BitsPerInt);
  5748     __ bind(done);
  5749   %}
  5750   ins_pipe(ialu_reg);
  5751 %}
  5754 //---------- Population Count Instructions -------------------------------------
  5756 instruct popCountI(rRegI dst, rRegI src, eFlagsReg cr) %{
  5757   predicate(UsePopCountInstruction);
  5758   match(Set dst (PopCountI src));
  5759   effect(KILL cr);
  5761   format %{ "POPCNT $dst, $src" %}
  5762   ins_encode %{
  5763     __ popcntl($dst$$Register, $src$$Register);
  5764   %}
  5765   ins_pipe(ialu_reg);
  5766 %}
  5768 instruct popCountI_mem(rRegI dst, memory mem, eFlagsReg cr) %{
  5769   predicate(UsePopCountInstruction);
  5770   match(Set dst (PopCountI (LoadI mem)));
  5771   effect(KILL cr);
  5773   format %{ "POPCNT $dst, $mem" %}
  5774   ins_encode %{
  5775     __ popcntl($dst$$Register, $mem$$Address);
  5776   %}
  5777   ins_pipe(ialu_reg);
  5778 %}
  5780 // Note: Long.bitCount(long) returns an int.
  5781 instruct popCountL(rRegI dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
  5782   predicate(UsePopCountInstruction);
  5783   match(Set dst (PopCountL src));
  5784   effect(KILL cr, TEMP tmp, TEMP dst);
  5786   format %{ "POPCNT $dst, $src.lo\n\t"
  5787             "POPCNT $tmp, $src.hi\n\t"
  5788             "ADD    $dst, $tmp" %}
  5789   ins_encode %{
  5790     __ popcntl($dst$$Register, $src$$Register);
  5791     __ popcntl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
  5792     __ addl($dst$$Register, $tmp$$Register);
  5793   %}
  5794   ins_pipe(ialu_reg);
  5795 %}
  5797 // Note: Long.bitCount(long) returns an int.
  5798 instruct popCountL_mem(rRegI dst, memory mem, rRegI tmp, eFlagsReg cr) %{
  5799   predicate(UsePopCountInstruction);
  5800   match(Set dst (PopCountL (LoadL mem)));
  5801   effect(KILL cr, TEMP tmp, TEMP dst);
  5803   format %{ "POPCNT $dst, $mem\n\t"
  5804             "POPCNT $tmp, $mem+4\n\t"
  5805             "ADD    $dst, $tmp" %}
  5806   ins_encode %{
  5807     //__ popcntl($dst$$Register, $mem$$Address$$first);
  5808     //__ popcntl($tmp$$Register, $mem$$Address$$second);
  5809     __ popcntl($dst$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, relocInfo::none));
  5810     __ popcntl($tmp$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, relocInfo::none));
  5811     __ addl($dst$$Register, $tmp$$Register);
  5812   %}
  5813   ins_pipe(ialu_reg);
  5814 %}
  5817 //----------Load/Store/Move Instructions---------------------------------------
  5818 //----------Load Instructions--------------------------------------------------
  5819 // Load Byte (8bit signed)
  5820 instruct loadB(xRegI dst, memory mem) %{
  5821   match(Set dst (LoadB mem));
  5823   ins_cost(125);
  5824   format %{ "MOVSX8 $dst,$mem\t# byte" %}
  5826   ins_encode %{
  5827     __ movsbl($dst$$Register, $mem$$Address);
  5828   %}
  5830   ins_pipe(ialu_reg_mem);
  5831 %}
  5833 // Load Byte (8bit signed) into Long Register
  5834 instruct loadB2L(eRegL dst, memory mem, eFlagsReg cr) %{
  5835   match(Set dst (ConvI2L (LoadB mem)));
  5836   effect(KILL cr);
  5838   ins_cost(375);
  5839   format %{ "MOVSX8 $dst.lo,$mem\t# byte -> long\n\t"
  5840             "MOV    $dst.hi,$dst.lo\n\t"
  5841             "SAR    $dst.hi,7" %}
  5843   ins_encode %{
  5844     __ movsbl($dst$$Register, $mem$$Address);
  5845     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  5846     __ sarl(HIGH_FROM_LOW($dst$$Register), 7); // 24+1 MSB are already signed extended.
  5847   %}
  5849   ins_pipe(ialu_reg_mem);
  5850 %}
  5852 // Load Unsigned Byte (8bit UNsigned)
  5853 instruct loadUB(xRegI dst, memory mem) %{
  5854   match(Set dst (LoadUB mem));
  5856   ins_cost(125);
  5857   format %{ "MOVZX8 $dst,$mem\t# ubyte -> int" %}
  5859   ins_encode %{
  5860     __ movzbl($dst$$Register, $mem$$Address);
  5861   %}
  5863   ins_pipe(ialu_reg_mem);
  5864 %}
  5866 // Load Unsigned Byte (8 bit UNsigned) into Long Register
  5867 instruct loadUB2L(eRegL dst, memory mem, eFlagsReg cr) %{
  5868   match(Set dst (ConvI2L (LoadUB mem)));
  5869   effect(KILL cr);
  5871   ins_cost(250);
  5872   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte -> long\n\t"
  5873             "XOR    $dst.hi,$dst.hi" %}
  5875   ins_encode %{
  5876     Register Rdst = $dst$$Register;
  5877     __ movzbl(Rdst, $mem$$Address);
  5878     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  5879   %}
  5881   ins_pipe(ialu_reg_mem);
  5882 %}
  5884 // Load Unsigned Byte (8 bit UNsigned) with mask into Long Register
  5885 instruct loadUB2L_immI8(eRegL dst, memory mem, immI8 mask, eFlagsReg cr) %{
  5886   match(Set dst (ConvI2L (AndI (LoadUB mem) mask)));
  5887   effect(KILL cr);
  5889   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte & 8-bit mask -> long\n\t"
  5890             "XOR    $dst.hi,$dst.hi\n\t"
  5891             "AND    $dst.lo,$mask" %}
  5892   ins_encode %{
  5893     Register Rdst = $dst$$Register;
  5894     __ movzbl(Rdst, $mem$$Address);
  5895     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  5896     __ andl(Rdst, $mask$$constant);
  5897   %}
  5898   ins_pipe(ialu_reg_mem);
  5899 %}
  5901 // Load Short (16bit signed)
  5902 instruct loadS(rRegI dst, memory mem) %{
  5903   match(Set dst (LoadS mem));
  5905   ins_cost(125);
  5906   format %{ "MOVSX  $dst,$mem\t# short" %}
  5908   ins_encode %{
  5909     __ movswl($dst$$Register, $mem$$Address);
  5910   %}
  5912   ins_pipe(ialu_reg_mem);
  5913 %}
  5915 // Load Short (16 bit signed) to Byte (8 bit signed)
  5916 instruct loadS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
  5917   match(Set dst (RShiftI (LShiftI (LoadS mem) twentyfour) twentyfour));
  5919   ins_cost(125);
  5920   format %{ "MOVSX  $dst, $mem\t# short -> byte" %}
  5921   ins_encode %{
  5922     __ movsbl($dst$$Register, $mem$$Address);
  5923   %}
  5924   ins_pipe(ialu_reg_mem);
  5925 %}
  5927 // Load Short (16bit signed) into Long Register
  5928 instruct loadS2L(eRegL dst, memory mem, eFlagsReg cr) %{
  5929   match(Set dst (ConvI2L (LoadS mem)));
  5930   effect(KILL cr);
  5932   ins_cost(375);
  5933   format %{ "MOVSX  $dst.lo,$mem\t# short -> long\n\t"
  5934             "MOV    $dst.hi,$dst.lo\n\t"
  5935             "SAR    $dst.hi,15" %}
  5937   ins_encode %{
  5938     __ movswl($dst$$Register, $mem$$Address);
  5939     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  5940     __ sarl(HIGH_FROM_LOW($dst$$Register), 15); // 16+1 MSB are already signed extended.
  5941   %}
  5943   ins_pipe(ialu_reg_mem);
  5944 %}
  5946 // Load Unsigned Short/Char (16bit unsigned)
  5947 instruct loadUS(rRegI dst, memory mem) %{
  5948   match(Set dst (LoadUS mem));
  5950   ins_cost(125);
  5951   format %{ "MOVZX  $dst,$mem\t# ushort/char -> int" %}
  5953   ins_encode %{
  5954     __ movzwl($dst$$Register, $mem$$Address);
  5955   %}
  5957   ins_pipe(ialu_reg_mem);
  5958 %}
  5960 // Load Unsigned Short/Char (16 bit UNsigned) to Byte (8 bit signed)
  5961 instruct loadUS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
  5962   match(Set dst (RShiftI (LShiftI (LoadUS mem) twentyfour) twentyfour));
  5964   ins_cost(125);
  5965   format %{ "MOVSX  $dst, $mem\t# ushort -> byte" %}
  5966   ins_encode %{
  5967     __ movsbl($dst$$Register, $mem$$Address);
  5968   %}
  5969   ins_pipe(ialu_reg_mem);
  5970 %}
  5972 // Load Unsigned Short/Char (16 bit UNsigned) into Long Register
  5973 instruct loadUS2L(eRegL dst, memory mem, eFlagsReg cr) %{
  5974   match(Set dst (ConvI2L (LoadUS mem)));
  5975   effect(KILL cr);
  5977   ins_cost(250);
  5978   format %{ "MOVZX  $dst.lo,$mem\t# ushort/char -> long\n\t"
  5979             "XOR    $dst.hi,$dst.hi" %}
  5981   ins_encode %{
  5982     __ movzwl($dst$$Register, $mem$$Address);
  5983     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
  5984   %}
  5986   ins_pipe(ialu_reg_mem);
  5987 %}
  5989 // Load Unsigned Short/Char (16 bit UNsigned) with mask 0xFF into Long Register
  5990 instruct loadUS2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
  5991   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
  5992   effect(KILL cr);
  5994   format %{ "MOVZX8 $dst.lo,$mem\t# ushort/char & 0xFF -> long\n\t"
  5995             "XOR    $dst.hi,$dst.hi" %}
  5996   ins_encode %{
  5997     Register Rdst = $dst$$Register;
  5998     __ movzbl(Rdst, $mem$$Address);
  5999     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6000   %}
  6001   ins_pipe(ialu_reg_mem);
  6002 %}
  6004 // Load Unsigned Short/Char (16 bit UNsigned) with a 16-bit mask into Long Register
  6005 instruct loadUS2L_immI16(eRegL dst, memory mem, immI16 mask, eFlagsReg cr) %{
  6006   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
  6007   effect(KILL cr);
  6009   format %{ "MOVZX  $dst.lo, $mem\t# ushort/char & 16-bit mask -> long\n\t"
  6010             "XOR    $dst.hi,$dst.hi\n\t"
  6011             "AND    $dst.lo,$mask" %}
  6012   ins_encode %{
  6013     Register Rdst = $dst$$Register;
  6014     __ movzwl(Rdst, $mem$$Address);
  6015     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6016     __ andl(Rdst, $mask$$constant);
  6017   %}
  6018   ins_pipe(ialu_reg_mem);
  6019 %}
  6021 // Load Integer
  6022 instruct loadI(rRegI dst, memory mem) %{
  6023   match(Set dst (LoadI mem));
  6025   ins_cost(125);
  6026   format %{ "MOV    $dst,$mem\t# int" %}
  6028   ins_encode %{
  6029     __ movl($dst$$Register, $mem$$Address);
  6030   %}
  6032   ins_pipe(ialu_reg_mem);
  6033 %}
  6035 // Load Integer (32 bit signed) to Byte (8 bit signed)
  6036 instruct loadI2B(rRegI dst, memory mem, immI_24 twentyfour) %{
  6037   match(Set dst (RShiftI (LShiftI (LoadI mem) twentyfour) twentyfour));
  6039   ins_cost(125);
  6040   format %{ "MOVSX  $dst, $mem\t# int -> byte" %}
  6041   ins_encode %{
  6042     __ movsbl($dst$$Register, $mem$$Address);
  6043   %}
  6044   ins_pipe(ialu_reg_mem);
  6045 %}
  6047 // Load Integer (32 bit signed) to Unsigned Byte (8 bit UNsigned)
  6048 instruct loadI2UB(rRegI dst, memory mem, immI_255 mask) %{
  6049   match(Set dst (AndI (LoadI mem) mask));
  6051   ins_cost(125);
  6052   format %{ "MOVZX  $dst, $mem\t# int -> ubyte" %}
  6053   ins_encode %{
  6054     __ movzbl($dst$$Register, $mem$$Address);
  6055   %}
  6056   ins_pipe(ialu_reg_mem);
  6057 %}
  6059 // Load Integer (32 bit signed) to Short (16 bit signed)
  6060 instruct loadI2S(rRegI dst, memory mem, immI_16 sixteen) %{
  6061   match(Set dst (RShiftI (LShiftI (LoadI mem) sixteen) sixteen));
  6063   ins_cost(125);
  6064   format %{ "MOVSX  $dst, $mem\t# int -> short" %}
  6065   ins_encode %{
  6066     __ movswl($dst$$Register, $mem$$Address);
  6067   %}
  6068   ins_pipe(ialu_reg_mem);
  6069 %}
  6071 // Load Integer (32 bit signed) to Unsigned Short/Char (16 bit UNsigned)
  6072 instruct loadI2US(rRegI dst, memory mem, immI_65535 mask) %{
  6073   match(Set dst (AndI (LoadI mem) mask));
  6075   ins_cost(125);
  6076   format %{ "MOVZX  $dst, $mem\t# int -> ushort/char" %}
  6077   ins_encode %{
  6078     __ movzwl($dst$$Register, $mem$$Address);
  6079   %}
  6080   ins_pipe(ialu_reg_mem);
  6081 %}
  6083 // Load Integer into Long Register
  6084 instruct loadI2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6085   match(Set dst (ConvI2L (LoadI mem)));
  6086   effect(KILL cr);
  6088   ins_cost(375);
  6089   format %{ "MOV    $dst.lo,$mem\t# int -> long\n\t"
  6090             "MOV    $dst.hi,$dst.lo\n\t"
  6091             "SAR    $dst.hi,31" %}
  6093   ins_encode %{
  6094     __ movl($dst$$Register, $mem$$Address);
  6095     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  6096     __ sarl(HIGH_FROM_LOW($dst$$Register), 31);
  6097   %}
  6099   ins_pipe(ialu_reg_mem);
  6100 %}
  6102 // Load Integer with mask 0xFF into Long Register
  6103 instruct loadI2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
  6104   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6105   effect(KILL cr);
  6107   format %{ "MOVZX8 $dst.lo,$mem\t# int & 0xFF -> long\n\t"
  6108             "XOR    $dst.hi,$dst.hi" %}
  6109   ins_encode %{
  6110     Register Rdst = $dst$$Register;
  6111     __ movzbl(Rdst, $mem$$Address);
  6112     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6113   %}
  6114   ins_pipe(ialu_reg_mem);
  6115 %}
  6117 // Load Integer with mask 0xFFFF into Long Register
  6118 instruct loadI2L_immI_65535(eRegL dst, memory mem, immI_65535 mask, eFlagsReg cr) %{
  6119   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6120   effect(KILL cr);
  6122   format %{ "MOVZX  $dst.lo,$mem\t# int & 0xFFFF -> long\n\t"
  6123             "XOR    $dst.hi,$dst.hi" %}
  6124   ins_encode %{
  6125     Register Rdst = $dst$$Register;
  6126     __ movzwl(Rdst, $mem$$Address);
  6127     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6128   %}
  6129   ins_pipe(ialu_reg_mem);
  6130 %}
  6132 // Load Integer with 32-bit mask into Long Register
  6133 instruct loadI2L_immI(eRegL dst, memory mem, immI mask, eFlagsReg cr) %{
  6134   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6135   effect(KILL cr);
  6137   format %{ "MOV    $dst.lo,$mem\t# int & 32-bit mask -> long\n\t"
  6138             "XOR    $dst.hi,$dst.hi\n\t"
  6139             "AND    $dst.lo,$mask" %}
  6140   ins_encode %{
  6141     Register Rdst = $dst$$Register;
  6142     __ movl(Rdst, $mem$$Address);
  6143     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6144     __ andl(Rdst, $mask$$constant);
  6145   %}
  6146   ins_pipe(ialu_reg_mem);
  6147 %}
  6149 // Load Unsigned Integer into Long Register
  6150 instruct loadUI2L(eRegL dst, memory mem, immL_32bits mask, eFlagsReg cr) %{
  6151   match(Set dst (AndL (ConvI2L (LoadI mem)) mask));
  6152   effect(KILL cr);
  6154   ins_cost(250);
  6155   format %{ "MOV    $dst.lo,$mem\t# uint -> long\n\t"
  6156             "XOR    $dst.hi,$dst.hi" %}
  6158   ins_encode %{
  6159     __ movl($dst$$Register, $mem$$Address);
  6160     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
  6161   %}
  6163   ins_pipe(ialu_reg_mem);
  6164 %}
  6166 // Load Long.  Cannot clobber address while loading, so restrict address
  6167 // register to ESI
  6168 instruct loadL(eRegL dst, load_long_memory mem) %{
  6169   predicate(!((LoadLNode*)n)->require_atomic_access());
  6170   match(Set dst (LoadL mem));
  6172   ins_cost(250);
  6173   format %{ "MOV    $dst.lo,$mem\t# long\n\t"
  6174             "MOV    $dst.hi,$mem+4" %}
  6176   ins_encode %{
  6177     Address Amemlo = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, relocInfo::none);
  6178     Address Amemhi = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, relocInfo::none);
  6179     __ movl($dst$$Register, Amemlo);
  6180     __ movl(HIGH_FROM_LOW($dst$$Register), Amemhi);
  6181   %}
  6183   ins_pipe(ialu_reg_long_mem);
  6184 %}
  6186 // Volatile Load Long.  Must be atomic, so do 64-bit FILD
  6187 // then store it down to the stack and reload on the int
  6188 // side.
  6189 instruct loadL_volatile(stackSlotL dst, memory mem) %{
  6190   predicate(UseSSE<=1 && ((LoadLNode*)n)->require_atomic_access());
  6191   match(Set dst (LoadL mem));
  6193   ins_cost(200);
  6194   format %{ "FILD   $mem\t# Atomic volatile long load\n\t"
  6195             "FISTp  $dst" %}
  6196   ins_encode(enc_loadL_volatile(mem,dst));
  6197   ins_pipe( fpu_reg_mem );
  6198 %}
  6200 instruct loadLX_volatile(stackSlotL dst, memory mem, regD tmp) %{
  6201   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
  6202   match(Set dst (LoadL mem));
  6203   effect(TEMP tmp);
  6204   ins_cost(180);
  6205   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  6206             "MOVSD  $dst,$tmp" %}
  6207   ins_encode %{
  6208     __ movdbl($tmp$$XMMRegister, $mem$$Address);
  6209     __ movdbl(Address(rsp, $dst$$disp), $tmp$$XMMRegister);
  6210   %}
  6211   ins_pipe( pipe_slow );
  6212 %}
  6214 instruct loadLX_reg_volatile(eRegL dst, memory mem, regD tmp) %{
  6215   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
  6216   match(Set dst (LoadL mem));
  6217   effect(TEMP tmp);
  6218   ins_cost(160);
  6219   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  6220             "MOVD   $dst.lo,$tmp\n\t"
  6221             "PSRLQ  $tmp,32\n\t"
  6222             "MOVD   $dst.hi,$tmp" %}
  6223   ins_encode %{
  6224     __ movdbl($tmp$$XMMRegister, $mem$$Address);
  6225     __ movdl($dst$$Register, $tmp$$XMMRegister);
  6226     __ psrlq($tmp$$XMMRegister, 32);
  6227     __ movdl(HIGH_FROM_LOW($dst$$Register), $tmp$$XMMRegister);
  6228   %}
  6229   ins_pipe( pipe_slow );
  6230 %}
  6232 // Load Range
  6233 instruct loadRange(rRegI dst, memory mem) %{
  6234   match(Set dst (LoadRange mem));
  6236   ins_cost(125);
  6237   format %{ "MOV    $dst,$mem" %}
  6238   opcode(0x8B);
  6239   ins_encode( OpcP, RegMem(dst,mem));
  6240   ins_pipe( ialu_reg_mem );
  6241 %}
  6244 // Load Pointer
  6245 instruct loadP(eRegP dst, memory mem) %{
  6246   match(Set dst (LoadP mem));
  6248   ins_cost(125);
  6249   format %{ "MOV    $dst,$mem" %}
  6250   opcode(0x8B);
  6251   ins_encode( OpcP, RegMem(dst,mem));
  6252   ins_pipe( ialu_reg_mem );
  6253 %}
  6255 // Load Klass Pointer
  6256 instruct loadKlass(eRegP dst, memory mem) %{
  6257   match(Set dst (LoadKlass mem));
  6259   ins_cost(125);
  6260   format %{ "MOV    $dst,$mem" %}
  6261   opcode(0x8B);
  6262   ins_encode( OpcP, RegMem(dst,mem));
  6263   ins_pipe( ialu_reg_mem );
  6264 %}
  6266 // Load Double
  6267 instruct loadDPR(regDPR dst, memory mem) %{
  6268   predicate(UseSSE<=1);
  6269   match(Set dst (LoadD mem));
  6271   ins_cost(150);
  6272   format %{ "FLD_D  ST,$mem\n\t"
  6273             "FSTP   $dst" %}
  6274   opcode(0xDD);               /* DD /0 */
  6275   ins_encode( OpcP, RMopc_Mem(0x00,mem),
  6276               Pop_Reg_DPR(dst) );
  6277   ins_pipe( fpu_reg_mem );
  6278 %}
  6280 // Load Double to XMM
  6281 instruct loadD(regD dst, memory mem) %{
  6282   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
  6283   match(Set dst (LoadD mem));
  6284   ins_cost(145);
  6285   format %{ "MOVSD  $dst,$mem" %}
  6286   ins_encode %{
  6287     __ movdbl ($dst$$XMMRegister, $mem$$Address);
  6288   %}
  6289   ins_pipe( pipe_slow );
  6290 %}
  6292 instruct loadD_partial(regD dst, memory mem) %{
  6293   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
  6294   match(Set dst (LoadD mem));
  6295   ins_cost(145);
  6296   format %{ "MOVLPD $dst,$mem" %}
  6297   ins_encode %{
  6298     __ movdbl ($dst$$XMMRegister, $mem$$Address);
  6299   %}
  6300   ins_pipe( pipe_slow );
  6301 %}
  6303 // Load to XMM register (single-precision floating point)
  6304 // MOVSS instruction
  6305 instruct loadF(regF dst, memory mem) %{
  6306   predicate(UseSSE>=1);
  6307   match(Set dst (LoadF mem));
  6308   ins_cost(145);
  6309   format %{ "MOVSS  $dst,$mem" %}
  6310   ins_encode %{
  6311     __ movflt ($dst$$XMMRegister, $mem$$Address);
  6312   %}
  6313   ins_pipe( pipe_slow );
  6314 %}
  6316 // Load Float
  6317 instruct loadFPR(regFPR dst, memory mem) %{
  6318   predicate(UseSSE==0);
  6319   match(Set dst (LoadF mem));
  6321   ins_cost(150);
  6322   format %{ "FLD_S  ST,$mem\n\t"
  6323             "FSTP   $dst" %}
  6324   opcode(0xD9);               /* D9 /0 */
  6325   ins_encode( OpcP, RMopc_Mem(0x00,mem),
  6326               Pop_Reg_FPR(dst) );
  6327   ins_pipe( fpu_reg_mem );
  6328 %}
  6330 // Load Effective Address
  6331 instruct leaP8(eRegP dst, indOffset8 mem) %{
  6332   match(Set dst mem);
  6334   ins_cost(110);
  6335   format %{ "LEA    $dst,$mem" %}
  6336   opcode(0x8D);
  6337   ins_encode( OpcP, RegMem(dst,mem));
  6338   ins_pipe( ialu_reg_reg_fat );
  6339 %}
  6341 instruct leaP32(eRegP dst, indOffset32 mem) %{
  6342   match(Set dst mem);
  6344   ins_cost(110);
  6345   format %{ "LEA    $dst,$mem" %}
  6346   opcode(0x8D);
  6347   ins_encode( OpcP, RegMem(dst,mem));
  6348   ins_pipe( ialu_reg_reg_fat );
  6349 %}
  6351 instruct leaPIdxOff(eRegP dst, indIndexOffset mem) %{
  6352   match(Set dst mem);
  6354   ins_cost(110);
  6355   format %{ "LEA    $dst,$mem" %}
  6356   opcode(0x8D);
  6357   ins_encode( OpcP, RegMem(dst,mem));
  6358   ins_pipe( ialu_reg_reg_fat );
  6359 %}
  6361 instruct leaPIdxScale(eRegP dst, indIndexScale mem) %{
  6362   match(Set dst mem);
  6364   ins_cost(110);
  6365   format %{ "LEA    $dst,$mem" %}
  6366   opcode(0x8D);
  6367   ins_encode( OpcP, RegMem(dst,mem));
  6368   ins_pipe( ialu_reg_reg_fat );
  6369 %}
  6371 instruct leaPIdxScaleOff(eRegP dst, indIndexScaleOffset mem) %{
  6372   match(Set dst mem);
  6374   ins_cost(110);
  6375   format %{ "LEA    $dst,$mem" %}
  6376   opcode(0x8D);
  6377   ins_encode( OpcP, RegMem(dst,mem));
  6378   ins_pipe( ialu_reg_reg_fat );
  6379 %}
  6381 // Load Constant
  6382 instruct loadConI(rRegI dst, immI src) %{
  6383   match(Set dst src);
  6385   format %{ "MOV    $dst,$src" %}
  6386   ins_encode( LdImmI(dst, src) );
  6387   ins_pipe( ialu_reg_fat );
  6388 %}
  6390 // Load Constant zero
  6391 instruct loadConI0(rRegI dst, immI0 src, eFlagsReg cr) %{
  6392   match(Set dst src);
  6393   effect(KILL cr);
  6395   ins_cost(50);
  6396   format %{ "XOR    $dst,$dst" %}
  6397   opcode(0x33);  /* + rd */
  6398   ins_encode( OpcP, RegReg( dst, dst ) );
  6399   ins_pipe( ialu_reg );
  6400 %}
  6402 instruct loadConP(eRegP dst, immP src) %{
  6403   match(Set dst src);
  6405   format %{ "MOV    $dst,$src" %}
  6406   opcode(0xB8);  /* + rd */
  6407   ins_encode( LdImmP(dst, src) );
  6408   ins_pipe( ialu_reg_fat );
  6409 %}
  6411 instruct loadConL(eRegL dst, immL src, eFlagsReg cr) %{
  6412   match(Set dst src);
  6413   effect(KILL cr);
  6414   ins_cost(200);
  6415   format %{ "MOV    $dst.lo,$src.lo\n\t"
  6416             "MOV    $dst.hi,$src.hi" %}
  6417   opcode(0xB8);
  6418   ins_encode( LdImmL_Lo(dst, src), LdImmL_Hi(dst, src) );
  6419   ins_pipe( ialu_reg_long_fat );
  6420 %}
  6422 instruct loadConL0(eRegL dst, immL0 src, eFlagsReg cr) %{
  6423   match(Set dst src);
  6424   effect(KILL cr);
  6425   ins_cost(150);
  6426   format %{ "XOR    $dst.lo,$dst.lo\n\t"
  6427             "XOR    $dst.hi,$dst.hi" %}
  6428   opcode(0x33,0x33);
  6429   ins_encode( RegReg_Lo(dst,dst), RegReg_Hi(dst, dst) );
  6430   ins_pipe( ialu_reg_long );
  6431 %}
  6433 // The instruction usage is guarded by predicate in operand immFPR().
  6434 instruct loadConFPR(regFPR dst, immFPR con) %{
  6435   match(Set dst con);
  6436   ins_cost(125);
  6437   format %{ "FLD_S  ST,[$constantaddress]\t# load from constant table: float=$con\n\t"
  6438             "FSTP   $dst" %}
  6439   ins_encode %{
  6440     __ fld_s($constantaddress($con));
  6441     __ fstp_d($dst$$reg);
  6442   %}
  6443   ins_pipe(fpu_reg_con);
  6444 %}
  6446 // The instruction usage is guarded by predicate in operand immFPR0().
  6447 instruct loadConFPR0(regFPR dst, immFPR0 con) %{
  6448   match(Set dst con);
  6449   ins_cost(125);
  6450   format %{ "FLDZ   ST\n\t"
  6451             "FSTP   $dst" %}
  6452   ins_encode %{
  6453     __ fldz();
  6454     __ fstp_d($dst$$reg);
  6455   %}
  6456   ins_pipe(fpu_reg_con);
  6457 %}
  6459 // The instruction usage is guarded by predicate in operand immFPR1().
  6460 instruct loadConFPR1(regFPR dst, immFPR1 con) %{
  6461   match(Set dst con);
  6462   ins_cost(125);
  6463   format %{ "FLD1   ST\n\t"
  6464             "FSTP   $dst" %}
  6465   ins_encode %{
  6466     __ fld1();
  6467     __ fstp_d($dst$$reg);
  6468   %}
  6469   ins_pipe(fpu_reg_con);
  6470 %}
  6472 // The instruction usage is guarded by predicate in operand immF().
  6473 instruct loadConF(regF dst, immF con) %{
  6474   match(Set dst con);
  6475   ins_cost(125);
  6476   format %{ "MOVSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
  6477   ins_encode %{
  6478     __ movflt($dst$$XMMRegister, $constantaddress($con));
  6479   %}
  6480   ins_pipe(pipe_slow);
  6481 %}
  6483 // The instruction usage is guarded by predicate in operand immF0().
  6484 instruct loadConF0(regF dst, immF0 src) %{
  6485   match(Set dst src);
  6486   ins_cost(100);
  6487   format %{ "XORPS  $dst,$dst\t# float 0.0" %}
  6488   ins_encode %{
  6489     __ xorps($dst$$XMMRegister, $dst$$XMMRegister);
  6490   %}
  6491   ins_pipe(pipe_slow);
  6492 %}
  6494 // The instruction usage is guarded by predicate in operand immDPR().
  6495 instruct loadConDPR(regDPR dst, immDPR con) %{
  6496   match(Set dst con);
  6497   ins_cost(125);
  6499   format %{ "FLD_D  ST,[$constantaddress]\t# load from constant table: double=$con\n\t"
  6500             "FSTP   $dst" %}
  6501   ins_encode %{
  6502     __ fld_d($constantaddress($con));
  6503     __ fstp_d($dst$$reg);
  6504   %}
  6505   ins_pipe(fpu_reg_con);
  6506 %}
  6508 // The instruction usage is guarded by predicate in operand immDPR0().
  6509 instruct loadConDPR0(regDPR dst, immDPR0 con) %{
  6510   match(Set dst con);
  6511   ins_cost(125);
  6513   format %{ "FLDZ   ST\n\t"
  6514             "FSTP   $dst" %}
  6515   ins_encode %{
  6516     __ fldz();
  6517     __ fstp_d($dst$$reg);
  6518   %}
  6519   ins_pipe(fpu_reg_con);
  6520 %}
  6522 // The instruction usage is guarded by predicate in operand immDPR1().
  6523 instruct loadConDPR1(regDPR dst, immDPR1 con) %{
  6524   match(Set dst con);
  6525   ins_cost(125);
  6527   format %{ "FLD1   ST\n\t"
  6528             "FSTP   $dst" %}
  6529   ins_encode %{
  6530     __ fld1();
  6531     __ fstp_d($dst$$reg);
  6532   %}
  6533   ins_pipe(fpu_reg_con);
  6534 %}
  6536 // The instruction usage is guarded by predicate in operand immD().
  6537 instruct loadConD(regD dst, immD con) %{
  6538   match(Set dst con);
  6539   ins_cost(125);
  6540   format %{ "MOVSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
  6541   ins_encode %{
  6542     __ movdbl($dst$$XMMRegister, $constantaddress($con));
  6543   %}
  6544   ins_pipe(pipe_slow);
  6545 %}
  6547 // The instruction usage is guarded by predicate in operand immD0().
  6548 instruct loadConD0(regD dst, immD0 src) %{
  6549   match(Set dst src);
  6550   ins_cost(100);
  6551   format %{ "XORPD  $dst,$dst\t# double 0.0" %}
  6552   ins_encode %{
  6553     __ xorpd ($dst$$XMMRegister, $dst$$XMMRegister);
  6554   %}
  6555   ins_pipe( pipe_slow );
  6556 %}
  6558 // Load Stack Slot
  6559 instruct loadSSI(rRegI dst, stackSlotI src) %{
  6560   match(Set dst src);
  6561   ins_cost(125);
  6563   format %{ "MOV    $dst,$src" %}
  6564   opcode(0x8B);
  6565   ins_encode( OpcP, RegMem(dst,src));
  6566   ins_pipe( ialu_reg_mem );
  6567 %}
  6569 instruct loadSSL(eRegL dst, stackSlotL src) %{
  6570   match(Set dst src);
  6572   ins_cost(200);
  6573   format %{ "MOV    $dst,$src.lo\n\t"
  6574             "MOV    $dst+4,$src.hi" %}
  6575   opcode(0x8B, 0x8B);
  6576   ins_encode( OpcP, RegMem( dst, src ), OpcS, RegMem_Hi( dst, src ) );
  6577   ins_pipe( ialu_mem_long_reg );
  6578 %}
  6580 // Load Stack Slot
  6581 instruct loadSSP(eRegP dst, stackSlotP src) %{
  6582   match(Set dst src);
  6583   ins_cost(125);
  6585   format %{ "MOV    $dst,$src" %}
  6586   opcode(0x8B);
  6587   ins_encode( OpcP, RegMem(dst,src));
  6588   ins_pipe( ialu_reg_mem );
  6589 %}
  6591 // Load Stack Slot
  6592 instruct loadSSF(regFPR dst, stackSlotF src) %{
  6593   match(Set dst src);
  6594   ins_cost(125);
  6596   format %{ "FLD_S  $src\n\t"
  6597             "FSTP   $dst" %}
  6598   opcode(0xD9);               /* D9 /0, FLD m32real */
  6599   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
  6600               Pop_Reg_FPR(dst) );
  6601   ins_pipe( fpu_reg_mem );
  6602 %}
  6604 // Load Stack Slot
  6605 instruct loadSSD(regDPR dst, stackSlotD src) %{
  6606   match(Set dst src);
  6607   ins_cost(125);
  6609   format %{ "FLD_D  $src\n\t"
  6610             "FSTP   $dst" %}
  6611   opcode(0xDD);               /* DD /0, FLD m64real */
  6612   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
  6613               Pop_Reg_DPR(dst) );
  6614   ins_pipe( fpu_reg_mem );
  6615 %}
  6617 // Prefetch instructions.
  6618 // Must be safe to execute with invalid address (cannot fault).
  6620 instruct prefetchr0( memory mem ) %{
  6621   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
  6622   match(PrefetchRead mem);
  6623   ins_cost(0);
  6624   size(0);
  6625   format %{ "PREFETCHR (non-SSE is empty encoding)" %}
  6626   ins_encode();
  6627   ins_pipe(empty);
  6628 %}
  6630 instruct prefetchr( memory mem ) %{
  6631   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch() || ReadPrefetchInstr==3);
  6632   match(PrefetchRead mem);
  6633   ins_cost(100);
  6635   format %{ "PREFETCHR $mem\t! Prefetch into level 1 cache for read" %}
  6636   ins_encode %{
  6637     __ prefetchr($mem$$Address);
  6638   %}
  6639   ins_pipe(ialu_mem);
  6640 %}
  6642 instruct prefetchrNTA( memory mem ) %{
  6643   predicate(UseSSE>=1 && ReadPrefetchInstr==0);
  6644   match(PrefetchRead mem);
  6645   ins_cost(100);
  6647   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for read" %}
  6648   ins_encode %{
  6649     __ prefetchnta($mem$$Address);
  6650   %}
  6651   ins_pipe(ialu_mem);
  6652 %}
  6654 instruct prefetchrT0( memory mem ) %{
  6655   predicate(UseSSE>=1 && ReadPrefetchInstr==1);
  6656   match(PrefetchRead mem);
  6657   ins_cost(100);
  6659   format %{ "PREFETCHT0 $mem\t! Prefetch into L1 and L2 caches for read" %}
  6660   ins_encode %{
  6661     __ prefetcht0($mem$$Address);
  6662   %}
  6663   ins_pipe(ialu_mem);
  6664 %}
  6666 instruct prefetchrT2( memory mem ) %{
  6667   predicate(UseSSE>=1 && ReadPrefetchInstr==2);
  6668   match(PrefetchRead mem);
  6669   ins_cost(100);
  6671   format %{ "PREFETCHT2 $mem\t! Prefetch into L2 cache for read" %}
  6672   ins_encode %{
  6673     __ prefetcht2($mem$$Address);
  6674   %}
  6675   ins_pipe(ialu_mem);
  6676 %}
  6678 instruct prefetchw0( memory mem ) %{
  6679   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
  6680   match(PrefetchWrite mem);
  6681   ins_cost(0);
  6682   size(0);
  6683   format %{ "Prefetch (non-SSE is empty encoding)" %}
  6684   ins_encode();
  6685   ins_pipe(empty);
  6686 %}
  6688 instruct prefetchw( memory mem ) %{
  6689   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch());
  6690   match( PrefetchWrite mem );
  6691   ins_cost(100);
  6693   format %{ "PREFETCHW $mem\t! Prefetch into L1 cache and mark modified" %}
  6694   ins_encode %{
  6695     __ prefetchw($mem$$Address);
  6696   %}
  6697   ins_pipe(ialu_mem);
  6698 %}
  6700 instruct prefetchwNTA( memory mem ) %{
  6701   predicate(UseSSE>=1);
  6702   match(PrefetchWrite mem);
  6703   ins_cost(100);
  6705   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for write" %}
  6706   ins_encode %{
  6707     __ prefetchnta($mem$$Address);
  6708   %}
  6709   ins_pipe(ialu_mem);
  6710 %}
  6712 // Prefetch instructions for allocation.
  6714 instruct prefetchAlloc0( memory mem ) %{
  6715   predicate(UseSSE==0 && AllocatePrefetchInstr!=3);
  6716   match(PrefetchAllocation mem);
  6717   ins_cost(0);
  6718   size(0);
  6719   format %{ "Prefetch allocation (non-SSE is empty encoding)" %}
  6720   ins_encode();
  6721   ins_pipe(empty);
  6722 %}
  6724 instruct prefetchAlloc( memory mem ) %{
  6725   predicate(AllocatePrefetchInstr==3);
  6726   match( PrefetchAllocation mem );
  6727   ins_cost(100);
  6729   format %{ "PREFETCHW $mem\t! Prefetch allocation into L1 cache and mark modified" %}
  6730   ins_encode %{
  6731     __ prefetchw($mem$$Address);
  6732   %}
  6733   ins_pipe(ialu_mem);
  6734 %}
  6736 instruct prefetchAllocNTA( memory mem ) %{
  6737   predicate(UseSSE>=1 && AllocatePrefetchInstr==0);
  6738   match(PrefetchAllocation mem);
  6739   ins_cost(100);
  6741   format %{ "PREFETCHNTA $mem\t! Prefetch allocation into non-temporal cache for write" %}
  6742   ins_encode %{
  6743     __ prefetchnta($mem$$Address);
  6744   %}
  6745   ins_pipe(ialu_mem);
  6746 %}
  6748 instruct prefetchAllocT0( memory mem ) %{
  6749   predicate(UseSSE>=1 && AllocatePrefetchInstr==1);
  6750   match(PrefetchAllocation mem);
  6751   ins_cost(100);
  6753   format %{ "PREFETCHT0 $mem\t! Prefetch allocation into L1 and L2 caches for write" %}
  6754   ins_encode %{
  6755     __ prefetcht0($mem$$Address);
  6756   %}
  6757   ins_pipe(ialu_mem);
  6758 %}
  6760 instruct prefetchAllocT2( memory mem ) %{
  6761   predicate(UseSSE>=1 && AllocatePrefetchInstr==2);
  6762   match(PrefetchAllocation mem);
  6763   ins_cost(100);
  6765   format %{ "PREFETCHT2 $mem\t! Prefetch allocation into L2 cache for write" %}
  6766   ins_encode %{
  6767     __ prefetcht2($mem$$Address);
  6768   %}
  6769   ins_pipe(ialu_mem);
  6770 %}
  6772 //----------Store Instructions-------------------------------------------------
  6774 // Store Byte
  6775 instruct storeB(memory mem, xRegI src) %{
  6776   match(Set mem (StoreB mem src));
  6778   ins_cost(125);
  6779   format %{ "MOV8   $mem,$src" %}
  6780   opcode(0x88);
  6781   ins_encode( OpcP, RegMem( src, mem ) );
  6782   ins_pipe( ialu_mem_reg );
  6783 %}
  6785 // Store Char/Short
  6786 instruct storeC(memory mem, rRegI src) %{
  6787   match(Set mem (StoreC mem src));
  6789   ins_cost(125);
  6790   format %{ "MOV16  $mem,$src" %}
  6791   opcode(0x89, 0x66);
  6792   ins_encode( OpcS, OpcP, RegMem( src, mem ) );
  6793   ins_pipe( ialu_mem_reg );
  6794 %}
  6796 // Store Integer
  6797 instruct storeI(memory mem, rRegI src) %{
  6798   match(Set mem (StoreI mem src));
  6800   ins_cost(125);
  6801   format %{ "MOV    $mem,$src" %}
  6802   opcode(0x89);
  6803   ins_encode( OpcP, RegMem( src, mem ) );
  6804   ins_pipe( ialu_mem_reg );
  6805 %}
  6807 // Store Long
  6808 instruct storeL(long_memory mem, eRegL src) %{
  6809   predicate(!((StoreLNode*)n)->require_atomic_access());
  6810   match(Set mem (StoreL mem src));
  6812   ins_cost(200);
  6813   format %{ "MOV    $mem,$src.lo\n\t"
  6814             "MOV    $mem+4,$src.hi" %}
  6815   opcode(0x89, 0x89);
  6816   ins_encode( OpcP, RegMem( src, mem ), OpcS, RegMem_Hi( src, mem ) );
  6817   ins_pipe( ialu_mem_long_reg );
  6818 %}
  6820 // Store Long to Integer
  6821 instruct storeL2I(memory mem, eRegL src) %{
  6822   match(Set mem (StoreI mem (ConvL2I src)));
  6824   format %{ "MOV    $mem,$src.lo\t# long -> int" %}
  6825   ins_encode %{
  6826     __ movl($mem$$Address, $src$$Register);
  6827   %}
  6828   ins_pipe(ialu_mem_reg);
  6829 %}
  6831 // Volatile Store Long.  Must be atomic, so move it into
  6832 // the FP TOS and then do a 64-bit FIST.  Has to probe the
  6833 // target address before the store (for null-ptr checks)
  6834 // so the memory operand is used twice in the encoding.
  6835 instruct storeL_volatile(memory mem, stackSlotL src, eFlagsReg cr ) %{
  6836   predicate(UseSSE<=1 && ((StoreLNode*)n)->require_atomic_access());
  6837   match(Set mem (StoreL mem src));
  6838   effect( KILL cr );
  6839   ins_cost(400);
  6840   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  6841             "FILD   $src\n\t"
  6842             "FISTp  $mem\t # 64-bit atomic volatile long store" %}
  6843   opcode(0x3B);
  6844   ins_encode( OpcP, RegMem( EAX, mem ), enc_storeL_volatile(mem,src));
  6845   ins_pipe( fpu_reg_mem );
  6846 %}
  6848 instruct storeLX_volatile(memory mem, stackSlotL src, regD tmp, eFlagsReg cr) %{
  6849   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
  6850   match(Set mem (StoreL mem src));
  6851   effect( TEMP tmp, KILL cr );
  6852   ins_cost(380);
  6853   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  6854             "MOVSD  $tmp,$src\n\t"
  6855             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
  6856   ins_encode %{
  6857     __ cmpl(rax, $mem$$Address);
  6858     __ movdbl($tmp$$XMMRegister, Address(rsp, $src$$disp));
  6859     __ movdbl($mem$$Address, $tmp$$XMMRegister);
  6860   %}
  6861   ins_pipe( pipe_slow );
  6862 %}
  6864 instruct storeLX_reg_volatile(memory mem, eRegL src, regD tmp2, regD tmp, eFlagsReg cr) %{
  6865   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
  6866   match(Set mem (StoreL mem src));
  6867   effect( TEMP tmp2 , TEMP tmp, KILL cr );
  6868   ins_cost(360);
  6869   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  6870             "MOVD   $tmp,$src.lo\n\t"
  6871             "MOVD   $tmp2,$src.hi\n\t"
  6872             "PUNPCKLDQ $tmp,$tmp2\n\t"
  6873             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
  6874   ins_encode %{
  6875     __ cmpl(rax, $mem$$Address);
  6876     __ movdl($tmp$$XMMRegister, $src$$Register);
  6877     __ movdl($tmp2$$XMMRegister, HIGH_FROM_LOW($src$$Register));
  6878     __ punpckldq($tmp$$XMMRegister, $tmp2$$XMMRegister);
  6879     __ movdbl($mem$$Address, $tmp$$XMMRegister);
  6880   %}
  6881   ins_pipe( pipe_slow );
  6882 %}
  6884 // Store Pointer; for storing unknown oops and raw pointers
  6885 instruct storeP(memory mem, anyRegP src) %{
  6886   match(Set mem (StoreP mem src));
  6888   ins_cost(125);
  6889   format %{ "MOV    $mem,$src" %}
  6890   opcode(0x89);
  6891   ins_encode( OpcP, RegMem( src, mem ) );
  6892   ins_pipe( ialu_mem_reg );
  6893 %}
  6895 // Store Integer Immediate
  6896 instruct storeImmI(memory mem, immI src) %{
  6897   match(Set mem (StoreI mem src));
  6899   ins_cost(150);
  6900   format %{ "MOV    $mem,$src" %}
  6901   opcode(0xC7);               /* C7 /0 */
  6902   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
  6903   ins_pipe( ialu_mem_imm );
  6904 %}
  6906 // Store Short/Char Immediate
  6907 instruct storeImmI16(memory mem, immI16 src) %{
  6908   predicate(UseStoreImmI16);
  6909   match(Set mem (StoreC mem src));
  6911   ins_cost(150);
  6912   format %{ "MOV16  $mem,$src" %}
  6913   opcode(0xC7);     /* C7 /0 Same as 32 store immediate with prefix */
  6914   ins_encode( SizePrefix, OpcP, RMopc_Mem(0x00,mem),  Con16( src ));
  6915   ins_pipe( ialu_mem_imm );
  6916 %}
  6918 // Store Pointer Immediate; null pointers or constant oops that do not
  6919 // need card-mark barriers.
  6920 instruct storeImmP(memory mem, immP src) %{
  6921   match(Set mem (StoreP mem src));
  6923   ins_cost(150);
  6924   format %{ "MOV    $mem,$src" %}
  6925   opcode(0xC7);               /* C7 /0 */
  6926   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
  6927   ins_pipe( ialu_mem_imm );
  6928 %}
  6930 // Store Byte Immediate
  6931 instruct storeImmB(memory mem, immI8 src) %{
  6932   match(Set mem (StoreB mem src));
  6934   ins_cost(150);
  6935   format %{ "MOV8   $mem,$src" %}
  6936   opcode(0xC6);               /* C6 /0 */
  6937   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
  6938   ins_pipe( ialu_mem_imm );
  6939 %}
  6941 // Store CMS card-mark Immediate
  6942 instruct storeImmCM(memory mem, immI8 src) %{
  6943   match(Set mem (StoreCM mem src));
  6945   ins_cost(150);
  6946   format %{ "MOV8   $mem,$src\t! CMS card-mark imm0" %}
  6947   opcode(0xC6);               /* C6 /0 */
  6948   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
  6949   ins_pipe( ialu_mem_imm );
  6950 %}
  6952 // Store Double
  6953 instruct storeDPR( memory mem, regDPR1 src) %{
  6954   predicate(UseSSE<=1);
  6955   match(Set mem (StoreD mem src));
  6957   ins_cost(100);
  6958   format %{ "FST_D  $mem,$src" %}
  6959   opcode(0xDD);       /* DD /2 */
  6960   ins_encode( enc_FPR_store(mem,src) );
  6961   ins_pipe( fpu_mem_reg );
  6962 %}
  6964 // Store double does rounding on x86
  6965 instruct storeDPR_rounded( memory mem, regDPR1 src) %{
  6966   predicate(UseSSE<=1);
  6967   match(Set mem (StoreD mem (RoundDouble src)));
  6969   ins_cost(100);
  6970   format %{ "FST_D  $mem,$src\t# round" %}
  6971   opcode(0xDD);       /* DD /2 */
  6972   ins_encode( enc_FPR_store(mem,src) );
  6973   ins_pipe( fpu_mem_reg );
  6974 %}
  6976 // Store XMM register to memory (double-precision floating points)
  6977 // MOVSD instruction
  6978 instruct storeD(memory mem, regD src) %{
  6979   predicate(UseSSE>=2);
  6980   match(Set mem (StoreD mem src));
  6981   ins_cost(95);
  6982   format %{ "MOVSD  $mem,$src" %}
  6983   ins_encode %{
  6984     __ movdbl($mem$$Address, $src$$XMMRegister);
  6985   %}
  6986   ins_pipe( pipe_slow );
  6987 %}
  6989 // Store XMM register to memory (single-precision floating point)
  6990 // MOVSS instruction
  6991 instruct storeF(memory mem, regF src) %{
  6992   predicate(UseSSE>=1);
  6993   match(Set mem (StoreF mem src));
  6994   ins_cost(95);
  6995   format %{ "MOVSS  $mem,$src" %}
  6996   ins_encode %{
  6997     __ movflt($mem$$Address, $src$$XMMRegister);
  6998   %}
  6999   ins_pipe( pipe_slow );
  7000 %}
  7002 // Store Float
  7003 instruct storeFPR( memory mem, regFPR1 src) %{
  7004   predicate(UseSSE==0);
  7005   match(Set mem (StoreF mem src));
  7007   ins_cost(100);
  7008   format %{ "FST_S  $mem,$src" %}
  7009   opcode(0xD9);       /* D9 /2 */
  7010   ins_encode( enc_FPR_store(mem,src) );
  7011   ins_pipe( fpu_mem_reg );
  7012 %}
  7014 // Store Float does rounding on x86
  7015 instruct storeFPR_rounded( memory mem, regFPR1 src) %{
  7016   predicate(UseSSE==0);
  7017   match(Set mem (StoreF mem (RoundFloat src)));
  7019   ins_cost(100);
  7020   format %{ "FST_S  $mem,$src\t# round" %}
  7021   opcode(0xD9);       /* D9 /2 */
  7022   ins_encode( enc_FPR_store(mem,src) );
  7023   ins_pipe( fpu_mem_reg );
  7024 %}
  7026 // Store Float does rounding on x86
  7027 instruct storeFPR_Drounded( memory mem, regDPR1 src) %{
  7028   predicate(UseSSE<=1);
  7029   match(Set mem (StoreF mem (ConvD2F src)));
  7031   ins_cost(100);
  7032   format %{ "FST_S  $mem,$src\t# D-round" %}
  7033   opcode(0xD9);       /* D9 /2 */
  7034   ins_encode( enc_FPR_store(mem,src) );
  7035   ins_pipe( fpu_mem_reg );
  7036 %}
  7038 // Store immediate Float value (it is faster than store from FPU register)
  7039 // The instruction usage is guarded by predicate in operand immFPR().
  7040 instruct storeFPR_imm( memory mem, immFPR src) %{
  7041   match(Set mem (StoreF mem src));
  7043   ins_cost(50);
  7044   format %{ "MOV    $mem,$src\t# store float" %}
  7045   opcode(0xC7);               /* C7 /0 */
  7046   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32FPR_as_bits( src ));
  7047   ins_pipe( ialu_mem_imm );
  7048 %}
  7050 // Store immediate Float value (it is faster than store from XMM register)
  7051 // The instruction usage is guarded by predicate in operand immF().
  7052 instruct storeF_imm( memory mem, immF src) %{
  7053   match(Set mem (StoreF mem src));
  7055   ins_cost(50);
  7056   format %{ "MOV    $mem,$src\t# store float" %}
  7057   opcode(0xC7);               /* C7 /0 */
  7058   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32F_as_bits( src ));
  7059   ins_pipe( ialu_mem_imm );
  7060 %}
  7062 // Store Integer to stack slot
  7063 instruct storeSSI(stackSlotI dst, rRegI src) %{
  7064   match(Set dst src);
  7066   ins_cost(100);
  7067   format %{ "MOV    $dst,$src" %}
  7068   opcode(0x89);
  7069   ins_encode( OpcPRegSS( dst, src ) );
  7070   ins_pipe( ialu_mem_reg );
  7071 %}
  7073 // Store Integer to stack slot
  7074 instruct storeSSP(stackSlotP dst, eRegP src) %{
  7075   match(Set dst src);
  7077   ins_cost(100);
  7078   format %{ "MOV    $dst,$src" %}
  7079   opcode(0x89);
  7080   ins_encode( OpcPRegSS( dst, src ) );
  7081   ins_pipe( ialu_mem_reg );
  7082 %}
  7084 // Store Long to stack slot
  7085 instruct storeSSL(stackSlotL dst, eRegL src) %{
  7086   match(Set dst src);
  7088   ins_cost(200);
  7089   format %{ "MOV    $dst,$src.lo\n\t"
  7090             "MOV    $dst+4,$src.hi" %}
  7091   opcode(0x89, 0x89);
  7092   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
  7093   ins_pipe( ialu_mem_long_reg );
  7094 %}
  7096 //----------MemBar Instructions-----------------------------------------------
  7097 // Memory barrier flavors
  7099 instruct membar_acquire() %{
  7100   match(MemBarAcquire);
  7101   ins_cost(400);
  7103   size(0);
  7104   format %{ "MEMBAR-acquire ! (empty encoding)" %}
  7105   ins_encode();
  7106   ins_pipe(empty);
  7107 %}
  7109 instruct membar_acquire_lock() %{
  7110   match(MemBarAcquireLock);
  7111   ins_cost(0);
  7113   size(0);
  7114   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
  7115   ins_encode( );
  7116   ins_pipe(empty);
  7117 %}
  7119 instruct membar_release() %{
  7120   match(MemBarRelease);
  7121   ins_cost(400);
  7123   size(0);
  7124   format %{ "MEMBAR-release ! (empty encoding)" %}
  7125   ins_encode( );
  7126   ins_pipe(empty);
  7127 %}
  7129 instruct membar_release_lock() %{
  7130   match(MemBarReleaseLock);
  7131   ins_cost(0);
  7133   size(0);
  7134   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
  7135   ins_encode( );
  7136   ins_pipe(empty);
  7137 %}
  7139 instruct membar_volatile(eFlagsReg cr) %{
  7140   match(MemBarVolatile);
  7141   effect(KILL cr);
  7142   ins_cost(400);
  7144   format %{ 
  7145     $$template
  7146     if (os::is_MP()) {
  7147       $$emit$$"LOCK ADDL [ESP + #0], 0\t! membar_volatile"
  7148     } else {
  7149       $$emit$$"MEMBAR-volatile ! (empty encoding)"
  7151   %}
  7152   ins_encode %{
  7153     __ membar(Assembler::StoreLoad);
  7154   %}
  7155   ins_pipe(pipe_slow);
  7156 %}
  7158 instruct unnecessary_membar_volatile() %{
  7159   match(MemBarVolatile);
  7160   predicate(Matcher::post_store_load_barrier(n));
  7161   ins_cost(0);
  7163   size(0);
  7164   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
  7165   ins_encode( );
  7166   ins_pipe(empty);
  7167 %}
  7169 instruct membar_storestore() %{
  7170   match(MemBarStoreStore);
  7171   ins_cost(0);
  7173   size(0);
  7174   format %{ "MEMBAR-storestore (empty encoding)" %}
  7175   ins_encode( );
  7176   ins_pipe(empty);
  7177 %}
  7179 //----------Move Instructions--------------------------------------------------
  7180 instruct castX2P(eAXRegP dst, eAXRegI src) %{
  7181   match(Set dst (CastX2P src));
  7182   format %{ "# X2P  $dst, $src" %}
  7183   ins_encode( /*empty encoding*/ );
  7184   ins_cost(0);
  7185   ins_pipe(empty);
  7186 %}
  7188 instruct castP2X(rRegI dst, eRegP src ) %{
  7189   match(Set dst (CastP2X src));
  7190   ins_cost(50);
  7191   format %{ "MOV    $dst, $src\t# CastP2X" %}
  7192   ins_encode( enc_Copy( dst, src) );
  7193   ins_pipe( ialu_reg_reg );
  7194 %}
  7196 //----------Conditional Move---------------------------------------------------
  7197 // Conditional move
  7198 instruct jmovI_reg(cmpOp cop, eFlagsReg cr, rRegI dst, rRegI src) %{
  7199   predicate(!VM_Version::supports_cmov() );
  7200   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7201   ins_cost(200);
  7202   format %{ "J$cop,us skip\t# signed cmove\n\t"
  7203             "MOV    $dst,$src\n"
  7204       "skip:" %}
  7205   ins_encode %{
  7206     Label Lskip;
  7207     // Invert sense of branch from sense of CMOV
  7208     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
  7209     __ movl($dst$$Register, $src$$Register);
  7210     __ bind(Lskip);
  7211   %}
  7212   ins_pipe( pipe_cmov_reg );
  7213 %}
  7215 instruct jmovI_regU(cmpOpU cop, eFlagsRegU cr, rRegI dst, rRegI src) %{
  7216   predicate(!VM_Version::supports_cmov() );
  7217   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7218   ins_cost(200);
  7219   format %{ "J$cop,us skip\t# unsigned cmove\n\t"
  7220             "MOV    $dst,$src\n"
  7221       "skip:" %}
  7222   ins_encode %{
  7223     Label Lskip;
  7224     // Invert sense of branch from sense of CMOV
  7225     __ jccb((Assembler::Condition)($cop$$cmpcode^1), Lskip);
  7226     __ movl($dst$$Register, $src$$Register);
  7227     __ bind(Lskip);
  7228   %}
  7229   ins_pipe( pipe_cmov_reg );
  7230 %}
  7232 instruct cmovI_reg(rRegI dst, rRegI src, eFlagsReg cr, cmpOp cop ) %{
  7233   predicate(VM_Version::supports_cmov() );
  7234   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7235   ins_cost(200);
  7236   format %{ "CMOV$cop $dst,$src" %}
  7237   opcode(0x0F,0x40);
  7238   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7239   ins_pipe( pipe_cmov_reg );
  7240 %}
  7242 instruct cmovI_regU( cmpOpU cop, eFlagsRegU cr, rRegI dst, rRegI src ) %{
  7243   predicate(VM_Version::supports_cmov() );
  7244   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7245   ins_cost(200);
  7246   format %{ "CMOV$cop $dst,$src" %}
  7247   opcode(0x0F,0x40);
  7248   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7249   ins_pipe( pipe_cmov_reg );
  7250 %}
  7252 instruct cmovI_regUCF( cmpOpUCF cop, eFlagsRegUCF cr, rRegI dst, rRegI src ) %{
  7253   predicate(VM_Version::supports_cmov() );
  7254   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7255   ins_cost(200);
  7256   expand %{
  7257     cmovI_regU(cop, cr, dst, src);
  7258   %}
  7259 %}
  7261 // Conditional move
  7262 instruct cmovI_mem(cmpOp cop, eFlagsReg cr, rRegI dst, memory src) %{
  7263   predicate(VM_Version::supports_cmov() );
  7264   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7265   ins_cost(250);
  7266   format %{ "CMOV$cop $dst,$src" %}
  7267   opcode(0x0F,0x40);
  7268   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7269   ins_pipe( pipe_cmov_mem );
  7270 %}
  7272 // Conditional move
  7273 instruct cmovI_memU(cmpOpU cop, eFlagsRegU cr, rRegI dst, memory src) %{
  7274   predicate(VM_Version::supports_cmov() );
  7275   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7276   ins_cost(250);
  7277   format %{ "CMOV$cop $dst,$src" %}
  7278   opcode(0x0F,0x40);
  7279   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7280   ins_pipe( pipe_cmov_mem );
  7281 %}
  7283 instruct cmovI_memUCF(cmpOpUCF cop, eFlagsRegUCF cr, rRegI dst, memory src) %{
  7284   predicate(VM_Version::supports_cmov() );
  7285   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7286   ins_cost(250);
  7287   expand %{
  7288     cmovI_memU(cop, cr, dst, src);
  7289   %}
  7290 %}
  7292 // Conditional move
  7293 instruct cmovP_reg(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
  7294   predicate(VM_Version::supports_cmov() );
  7295   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7296   ins_cost(200);
  7297   format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7298   opcode(0x0F,0x40);
  7299   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7300   ins_pipe( pipe_cmov_reg );
  7301 %}
  7303 // Conditional move (non-P6 version)
  7304 // Note:  a CMoveP is generated for  stubs and native wrappers
  7305 //        regardless of whether we are on a P6, so we
  7306 //        emulate a cmov here
  7307 instruct cmovP_reg_nonP6(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
  7308   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7309   ins_cost(300);
  7310   format %{ "Jn$cop   skip\n\t"
  7311           "MOV    $dst,$src\t# pointer\n"
  7312       "skip:" %}
  7313   opcode(0x8b);
  7314   ins_encode( enc_cmov_branch(cop, 0x2), OpcP, RegReg(dst, src));
  7315   ins_pipe( pipe_cmov_reg );
  7316 %}
  7318 // Conditional move
  7319 instruct cmovP_regU(cmpOpU cop, eFlagsRegU cr, eRegP dst, eRegP src ) %{
  7320   predicate(VM_Version::supports_cmov() );
  7321   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7322   ins_cost(200);
  7323   format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7324   opcode(0x0F,0x40);
  7325   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7326   ins_pipe( pipe_cmov_reg );
  7327 %}
  7329 instruct cmovP_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegP dst, eRegP src ) %{
  7330   predicate(VM_Version::supports_cmov() );
  7331   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7332   ins_cost(200);
  7333   expand %{
  7334     cmovP_regU(cop, cr, dst, src);
  7335   %}
  7336 %}
  7338 // DISABLED: Requires the ADLC to emit a bottom_type call that
  7339 // correctly meets the two pointer arguments; one is an incoming
  7340 // register but the other is a memory operand.  ALSO appears to
  7341 // be buggy with implicit null checks.
  7342 //
  7343 //// Conditional move
  7344 //instruct cmovP_mem(cmpOp cop, eFlagsReg cr, eRegP dst, memory src) %{
  7345 //  predicate(VM_Version::supports_cmov() );
  7346 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  7347 //  ins_cost(250);
  7348 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7349 //  opcode(0x0F,0x40);
  7350 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7351 //  ins_pipe( pipe_cmov_mem );
  7352 //%}
  7353 //
  7354 //// Conditional move
  7355 //instruct cmovP_memU(cmpOpU cop, eFlagsRegU cr, eRegP dst, memory src) %{
  7356 //  predicate(VM_Version::supports_cmov() );
  7357 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  7358 //  ins_cost(250);
  7359 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7360 //  opcode(0x0F,0x40);
  7361 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7362 //  ins_pipe( pipe_cmov_mem );
  7363 //%}
  7365 // Conditional move
  7366 instruct fcmovDPR_regU(cmpOp_fcmov cop, eFlagsRegU cr, regDPR1 dst, regDPR src) %{
  7367   predicate(UseSSE<=1);
  7368   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7369   ins_cost(200);
  7370   format %{ "FCMOV$cop $dst,$src\t# double" %}
  7371   opcode(0xDA);
  7372   ins_encode( enc_cmov_dpr(cop,src) );
  7373   ins_pipe( pipe_cmovDPR_reg );
  7374 %}
  7376 // Conditional move
  7377 instruct fcmovFPR_regU(cmpOp_fcmov cop, eFlagsRegU cr, regFPR1 dst, regFPR src) %{
  7378   predicate(UseSSE==0);
  7379   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7380   ins_cost(200);
  7381   format %{ "FCMOV$cop $dst,$src\t# float" %}
  7382   opcode(0xDA);
  7383   ins_encode( enc_cmov_dpr(cop,src) );
  7384   ins_pipe( pipe_cmovDPR_reg );
  7385 %}
  7387 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
  7388 instruct fcmovDPR_regS(cmpOp cop, eFlagsReg cr, regDPR dst, regDPR src) %{
  7389   predicate(UseSSE<=1);
  7390   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7391   ins_cost(200);
  7392   format %{ "Jn$cop   skip\n\t"
  7393             "MOV    $dst,$src\t# double\n"
  7394       "skip:" %}
  7395   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
  7396   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_DPR(src), OpcP, RegOpc(dst) );
  7397   ins_pipe( pipe_cmovDPR_reg );
  7398 %}
  7400 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
  7401 instruct fcmovFPR_regS(cmpOp cop, eFlagsReg cr, regFPR dst, regFPR src) %{
  7402   predicate(UseSSE==0);
  7403   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7404   ins_cost(200);
  7405   format %{ "Jn$cop    skip\n\t"
  7406             "MOV    $dst,$src\t# float\n"
  7407       "skip:" %}
  7408   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
  7409   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_FPR(src), OpcP, RegOpc(dst) );
  7410   ins_pipe( pipe_cmovDPR_reg );
  7411 %}
  7413 // No CMOVE with SSE/SSE2
  7414 instruct fcmovF_regS(cmpOp cop, eFlagsReg cr, regF dst, regF src) %{
  7415   predicate (UseSSE>=1);
  7416   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7417   ins_cost(200);
  7418   format %{ "Jn$cop   skip\n\t"
  7419             "MOVSS  $dst,$src\t# float\n"
  7420       "skip:" %}
  7421   ins_encode %{
  7422     Label skip;
  7423     // Invert sense of branch from sense of CMOV
  7424     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  7425     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
  7426     __ bind(skip);
  7427   %}
  7428   ins_pipe( pipe_slow );
  7429 %}
  7431 // No CMOVE with SSE/SSE2
  7432 instruct fcmovD_regS(cmpOp cop, eFlagsReg cr, regD dst, regD src) %{
  7433   predicate (UseSSE>=2);
  7434   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7435   ins_cost(200);
  7436   format %{ "Jn$cop   skip\n\t"
  7437             "MOVSD  $dst,$src\t# float\n"
  7438       "skip:" %}
  7439   ins_encode %{
  7440     Label skip;
  7441     // Invert sense of branch from sense of CMOV
  7442     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  7443     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
  7444     __ bind(skip);
  7445   %}
  7446   ins_pipe( pipe_slow );
  7447 %}
  7449 // unsigned version
  7450 instruct fcmovF_regU(cmpOpU cop, eFlagsRegU cr, regF dst, regF src) %{
  7451   predicate (UseSSE>=1);
  7452   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7453   ins_cost(200);
  7454   format %{ "Jn$cop   skip\n\t"
  7455             "MOVSS  $dst,$src\t# float\n"
  7456       "skip:" %}
  7457   ins_encode %{
  7458     Label skip;
  7459     // Invert sense of branch from sense of CMOV
  7460     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  7461     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
  7462     __ bind(skip);
  7463   %}
  7464   ins_pipe( pipe_slow );
  7465 %}
  7467 instruct fcmovF_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regF dst, regF src) %{
  7468   predicate (UseSSE>=1);
  7469   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7470   ins_cost(200);
  7471   expand %{
  7472     fcmovF_regU(cop, cr, dst, src);
  7473   %}
  7474 %}
  7476 // unsigned version
  7477 instruct fcmovD_regU(cmpOpU cop, eFlagsRegU cr, regD dst, regD src) %{
  7478   predicate (UseSSE>=2);
  7479   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7480   ins_cost(200);
  7481   format %{ "Jn$cop   skip\n\t"
  7482             "MOVSD  $dst,$src\t# float\n"
  7483       "skip:" %}
  7484   ins_encode %{
  7485     Label skip;
  7486     // Invert sense of branch from sense of CMOV
  7487     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  7488     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
  7489     __ bind(skip);
  7490   %}
  7491   ins_pipe( pipe_slow );
  7492 %}
  7494 instruct fcmovD_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regD dst, regD src) %{
  7495   predicate (UseSSE>=2);
  7496   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7497   ins_cost(200);
  7498   expand %{
  7499     fcmovD_regU(cop, cr, dst, src);
  7500   %}
  7501 %}
  7503 instruct cmovL_reg(cmpOp cop, eFlagsReg cr, eRegL dst, eRegL src) %{
  7504   predicate(VM_Version::supports_cmov() );
  7505   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  7506   ins_cost(200);
  7507   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
  7508             "CMOV$cop $dst.hi,$src.hi" %}
  7509   opcode(0x0F,0x40);
  7510   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
  7511   ins_pipe( pipe_cmov_reg_long );
  7512 %}
  7514 instruct cmovL_regU(cmpOpU cop, eFlagsRegU cr, eRegL dst, eRegL src) %{
  7515   predicate(VM_Version::supports_cmov() );
  7516   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  7517   ins_cost(200);
  7518   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
  7519             "CMOV$cop $dst.hi,$src.hi" %}
  7520   opcode(0x0F,0x40);
  7521   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
  7522   ins_pipe( pipe_cmov_reg_long );
  7523 %}
  7525 instruct cmovL_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegL dst, eRegL src) %{
  7526   predicate(VM_Version::supports_cmov() );
  7527   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  7528   ins_cost(200);
  7529   expand %{
  7530     cmovL_regU(cop, cr, dst, src);
  7531   %}
  7532 %}
  7534 //----------Arithmetic Instructions--------------------------------------------
  7535 //----------Addition Instructions----------------------------------------------
  7536 // Integer Addition Instructions
  7537 instruct addI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
  7538   match(Set dst (AddI dst src));
  7539   effect(KILL cr);
  7541   size(2);
  7542   format %{ "ADD    $dst,$src" %}
  7543   opcode(0x03);
  7544   ins_encode( OpcP, RegReg( dst, src) );
  7545   ins_pipe( ialu_reg_reg );
  7546 %}
  7548 instruct addI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
  7549   match(Set dst (AddI dst src));
  7550   effect(KILL cr);
  7552   format %{ "ADD    $dst,$src" %}
  7553   opcode(0x81, 0x00); /* /0 id */
  7554   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  7555   ins_pipe( ialu_reg );
  7556 %}
  7558 instruct incI_eReg(rRegI dst, immI1 src, eFlagsReg cr) %{
  7559   predicate(UseIncDec);
  7560   match(Set dst (AddI dst src));
  7561   effect(KILL cr);
  7563   size(1);
  7564   format %{ "INC    $dst" %}
  7565   opcode(0x40); /*  */
  7566   ins_encode( Opc_plus( primary, dst ) );
  7567   ins_pipe( ialu_reg );
  7568 %}
  7570 instruct leaI_eReg_immI(rRegI dst, rRegI src0, immI src1) %{
  7571   match(Set dst (AddI src0 src1));
  7572   ins_cost(110);
  7574   format %{ "LEA    $dst,[$src0 + $src1]" %}
  7575   opcode(0x8D); /* 0x8D /r */
  7576   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
  7577   ins_pipe( ialu_reg_reg );
  7578 %}
  7580 instruct leaP_eReg_immI(eRegP dst, eRegP src0, immI src1) %{
  7581   match(Set dst (AddP src0 src1));
  7582   ins_cost(110);
  7584   format %{ "LEA    $dst,[$src0 + $src1]\t# ptr" %}
  7585   opcode(0x8D); /* 0x8D /r */
  7586   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
  7587   ins_pipe( ialu_reg_reg );
  7588 %}
  7590 instruct decI_eReg(rRegI dst, immI_M1 src, eFlagsReg cr) %{
  7591   predicate(UseIncDec);
  7592   match(Set dst (AddI dst src));
  7593   effect(KILL cr);
  7595   size(1);
  7596   format %{ "DEC    $dst" %}
  7597   opcode(0x48); /*  */
  7598   ins_encode( Opc_plus( primary, dst ) );
  7599   ins_pipe( ialu_reg );
  7600 %}
  7602 instruct addP_eReg(eRegP dst, rRegI src, eFlagsReg cr) %{
  7603   match(Set dst (AddP dst src));
  7604   effect(KILL cr);
  7606   size(2);
  7607   format %{ "ADD    $dst,$src" %}
  7608   opcode(0x03);
  7609   ins_encode( OpcP, RegReg( dst, src) );
  7610   ins_pipe( ialu_reg_reg );
  7611 %}
  7613 instruct addP_eReg_imm(eRegP dst, immI src, eFlagsReg cr) %{
  7614   match(Set dst (AddP dst src));
  7615   effect(KILL cr);
  7617   format %{ "ADD    $dst,$src" %}
  7618   opcode(0x81,0x00); /* Opcode 81 /0 id */
  7619   // ins_encode( RegImm( dst, src) );
  7620   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  7621   ins_pipe( ialu_reg );
  7622 %}
  7624 instruct addI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
  7625   match(Set dst (AddI dst (LoadI src)));
  7626   effect(KILL cr);
  7628   ins_cost(125);
  7629   format %{ "ADD    $dst,$src" %}
  7630   opcode(0x03);
  7631   ins_encode( OpcP, RegMem( dst, src) );
  7632   ins_pipe( ialu_reg_mem );
  7633 %}
  7635 instruct addI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
  7636   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7637   effect(KILL cr);
  7639   ins_cost(150);
  7640   format %{ "ADD    $dst,$src" %}
  7641   opcode(0x01);  /* Opcode 01 /r */
  7642   ins_encode( OpcP, RegMem( src, dst ) );
  7643   ins_pipe( ialu_mem_reg );
  7644 %}
  7646 // Add Memory with Immediate
  7647 instruct addI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  7648   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7649   effect(KILL cr);
  7651   ins_cost(125);
  7652   format %{ "ADD    $dst,$src" %}
  7653   opcode(0x81);               /* Opcode 81 /0 id */
  7654   ins_encode( OpcSE( src ), RMopc_Mem(0x00,dst), Con8or32( src ) );
  7655   ins_pipe( ialu_mem_imm );
  7656 %}
  7658 instruct incI_mem(memory dst, immI1 src, eFlagsReg cr) %{
  7659   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7660   effect(KILL cr);
  7662   ins_cost(125);
  7663   format %{ "INC    $dst" %}
  7664   opcode(0xFF);               /* Opcode FF /0 */
  7665   ins_encode( OpcP, RMopc_Mem(0x00,dst));
  7666   ins_pipe( ialu_mem_imm );
  7667 %}
  7669 instruct decI_mem(memory dst, immI_M1 src, eFlagsReg cr) %{
  7670   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7671   effect(KILL cr);
  7673   ins_cost(125);
  7674   format %{ "DEC    $dst" %}
  7675   opcode(0xFF);               /* Opcode FF /1 */
  7676   ins_encode( OpcP, RMopc_Mem(0x01,dst));
  7677   ins_pipe( ialu_mem_imm );
  7678 %}
  7681 instruct checkCastPP( eRegP dst ) %{
  7682   match(Set dst (CheckCastPP dst));
  7684   size(0);
  7685   format %{ "#checkcastPP of $dst" %}
  7686   ins_encode( /*empty encoding*/ );
  7687   ins_pipe( empty );
  7688 %}
  7690 instruct castPP( eRegP dst ) %{
  7691   match(Set dst (CastPP dst));
  7692   format %{ "#castPP of $dst" %}
  7693   ins_encode( /*empty encoding*/ );
  7694   ins_pipe( empty );
  7695 %}
  7697 instruct castII( rRegI dst ) %{
  7698   match(Set dst (CastII dst));
  7699   format %{ "#castII of $dst" %}
  7700   ins_encode( /*empty encoding*/ );
  7701   ins_cost(0);
  7702   ins_pipe( empty );
  7703 %}
  7706 // Load-locked - same as a regular pointer load when used with compare-swap
  7707 instruct loadPLocked(eRegP dst, memory mem) %{
  7708   match(Set dst (LoadPLocked mem));
  7710   ins_cost(125);
  7711   format %{ "MOV    $dst,$mem\t# Load ptr. locked" %}
  7712   opcode(0x8B);
  7713   ins_encode( OpcP, RegMem(dst,mem));
  7714   ins_pipe( ialu_reg_mem );
  7715 %}
  7717 // Conditional-store of the updated heap-top.
  7718 // Used during allocation of the shared heap.
  7719 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
  7720 instruct storePConditional( memory heap_top_ptr, eAXRegP oldval, eRegP newval, eFlagsReg cr ) %{
  7721   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
  7722   // EAX is killed if there is contention, but then it's also unused.
  7723   // In the common case of no contention, EAX holds the new oop address.
  7724   format %{ "CMPXCHG $heap_top_ptr,$newval\t# If EAX==$heap_top_ptr Then store $newval into $heap_top_ptr" %}
  7725   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval,heap_top_ptr) );
  7726   ins_pipe( pipe_cmpxchg );
  7727 %}
  7729 // Conditional-store of an int value.
  7730 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG on Intel.
  7731 instruct storeIConditional( memory mem, eAXRegI oldval, rRegI newval, eFlagsReg cr ) %{
  7732   match(Set cr (StoreIConditional mem (Binary oldval newval)));
  7733   effect(KILL oldval);
  7734   format %{ "CMPXCHG $mem,$newval\t# If EAX==$mem Then store $newval into $mem" %}
  7735   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval, mem) );
  7736   ins_pipe( pipe_cmpxchg );
  7737 %}
  7739 // Conditional-store of a long value.
  7740 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG8 on Intel.
  7741 instruct storeLConditional( memory mem, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
  7742   match(Set cr (StoreLConditional mem (Binary oldval newval)));
  7743   effect(KILL oldval);
  7744   format %{ "XCHG   EBX,ECX\t# correct order for CMPXCHG8 instruction\n\t"
  7745             "CMPXCHG8 $mem,ECX:EBX\t# If EDX:EAX==$mem Then store ECX:EBX into $mem\n\t"
  7746             "XCHG   EBX,ECX"
  7747   %}
  7748   ins_encode %{
  7749     // Note: we need to swap rbx, and rcx before and after the
  7750     //       cmpxchg8 instruction because the instruction uses
  7751     //       rcx as the high order word of the new value to store but
  7752     //       our register encoding uses rbx.
  7753     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
  7754     if( os::is_MP() )
  7755       __ lock();
  7756     __ cmpxchg8($mem$$Address);
  7757     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
  7758   %}
  7759   ins_pipe( pipe_cmpxchg );
  7760 %}
  7762 // No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
  7764 instruct compareAndSwapL( rRegI res, eSIRegP mem_ptr, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
  7765   predicate(VM_Version::supports_cx8());
  7766   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
  7767   effect(KILL cr, KILL oldval);
  7768   format %{ "CMPXCHG8 [$mem_ptr],$newval\t# If EDX:EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  7769             "MOV    $res,0\n\t"
  7770             "JNE,s  fail\n\t"
  7771             "MOV    $res,1\n"
  7772           "fail:" %}
  7773   ins_encode( enc_cmpxchg8(mem_ptr),
  7774               enc_flags_ne_to_boolean(res) );
  7775   ins_pipe( pipe_cmpxchg );
  7776 %}
  7778 instruct compareAndSwapP( rRegI res,  pRegP mem_ptr, eAXRegP oldval, eCXRegP newval, eFlagsReg cr) %{
  7779   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
  7780   effect(KILL cr, KILL oldval);
  7781   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  7782             "MOV    $res,0\n\t"
  7783             "JNE,s  fail\n\t"
  7784             "MOV    $res,1\n"
  7785           "fail:" %}
  7786   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
  7787   ins_pipe( pipe_cmpxchg );
  7788 %}
  7790 instruct compareAndSwapI( rRegI res, pRegP mem_ptr, eAXRegI oldval, eCXRegI newval, eFlagsReg cr) %{
  7791   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
  7792   effect(KILL cr, KILL oldval);
  7793   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  7794             "MOV    $res,0\n\t"
  7795             "JNE,s  fail\n\t"
  7796             "MOV    $res,1\n"
  7797           "fail:" %}
  7798   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
  7799   ins_pipe( pipe_cmpxchg );
  7800 %}
  7802 instruct xaddI_no_res( memory mem, Universe dummy, immI add, eFlagsReg cr) %{
  7803   predicate(n->as_LoadStore()->result_not_used());
  7804   match(Set dummy (GetAndAddI mem add));
  7805   effect(KILL cr);
  7806   format %{ "ADDL  [$mem],$add" %}
  7807   ins_encode %{
  7808     if (os::is_MP()) { __ lock(); }
  7809     __ addl($mem$$Address, $add$$constant);
  7810   %}
  7811   ins_pipe( pipe_cmpxchg );
  7812 %}
  7814 instruct xaddI( memory mem, rRegI newval, eFlagsReg cr) %{
  7815   match(Set newval (GetAndAddI mem newval));
  7816   effect(KILL cr);
  7817   format %{ "XADDL  [$mem],$newval" %}
  7818   ins_encode %{
  7819     if (os::is_MP()) { __ lock(); }
  7820     __ xaddl($mem$$Address, $newval$$Register);
  7821   %}
  7822   ins_pipe( pipe_cmpxchg );
  7823 %}
  7825 instruct xchgI( memory mem, rRegI newval) %{
  7826   match(Set newval (GetAndSetI mem newval));
  7827   format %{ "XCHGL  $newval,[$mem]" %}
  7828   ins_encode %{
  7829     __ xchgl($newval$$Register, $mem$$Address);
  7830   %}
  7831   ins_pipe( pipe_cmpxchg );
  7832 %}
  7834 instruct xchgP( memory mem, pRegP newval) %{
  7835   match(Set newval (GetAndSetP mem newval));
  7836   format %{ "XCHGL  $newval,[$mem]" %}
  7837   ins_encode %{
  7838     __ xchgl($newval$$Register, $mem$$Address);
  7839   %}
  7840   ins_pipe( pipe_cmpxchg );
  7841 %}
  7843 //----------Subtraction Instructions-------------------------------------------
  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);
  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 %}
  7856 instruct subI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
  7857   match(Set dst (SubI dst src));
  7858   effect(KILL cr);
  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 %}
  7867 instruct subI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
  7868   match(Set dst (SubI dst (LoadI src)));
  7869   effect(KILL cr);
  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 %}
  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);
  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 %}
  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);
  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 %}
  7901 instruct negI_eReg(rRegI dst, immI0 zero, eFlagsReg cr) %{
  7902   match(Set dst (SubI zero dst));
  7903   effect(KILL cr);
  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 %}
  7913 //----------Multiplication/Division Instructions-------------------------------
  7914 // Integer Multiplication Instructions
  7915 // Multiply Register
  7916 instruct mulI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
  7917   match(Set dst (MulI dst src));
  7918   effect(KILL cr);
  7920   size(3);
  7921   ins_cost(300);
  7922   format %{ "IMUL   $dst,$src" %}
  7923   opcode(0xAF, 0x0F);
  7924   ins_encode( OpcS, OpcP, RegReg( dst, src) );
  7925   ins_pipe( ialu_reg_reg_alu0 );
  7926 %}
  7928 // Multiply 32-bit Immediate
  7929 instruct mulI_eReg_imm(rRegI dst, rRegI src, immI imm, eFlagsReg cr) %{
  7930   match(Set dst (MulI src imm));
  7931   effect(KILL cr);
  7933   ins_cost(300);
  7934   format %{ "IMUL   $dst,$src,$imm" %}
  7935   opcode(0x69);  /* 69 /r id */
  7936   ins_encode( OpcSE(imm), RegReg( dst, src ), Con8or32( imm ) );
  7937   ins_pipe( ialu_reg_reg_alu0 );
  7938 %}
  7940 instruct loadConL_low_only(eADXRegL_low_only dst, immL32 src, eFlagsReg cr) %{
  7941   match(Set dst src);
  7942   effect(KILL cr);
  7944   // Note that this is artificially increased to make it more expensive than loadConL
  7945   ins_cost(250);
  7946   format %{ "MOV    EAX,$src\t// low word only" %}
  7947   opcode(0xB8);
  7948   ins_encode( LdImmL_Lo(dst, src) );
  7949   ins_pipe( ialu_reg_fat );
  7950 %}
  7952 // Multiply by 32-bit Immediate, taking the shifted high order results
  7953 //  (special case for shift by 32)
  7954 instruct mulI_imm_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32 cnt, eFlagsReg cr) %{
  7955   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
  7956   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
  7957              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
  7958              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
  7959   effect(USE src1, KILL cr);
  7961   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
  7962   ins_cost(0*100 + 1*400 - 150);
  7963   format %{ "IMUL   EDX:EAX,$src1" %}
  7964   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
  7965   ins_pipe( pipe_slow );
  7966 %}
  7968 // Multiply by 32-bit Immediate, taking the shifted high order results
  7969 instruct mulI_imm_RShift_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr) %{
  7970   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
  7971   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
  7972              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
  7973              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
  7974   effect(USE src1, KILL cr);
  7976   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
  7977   ins_cost(1*100 + 1*400 - 150);
  7978   format %{ "IMUL   EDX:EAX,$src1\n\t"
  7979             "SAR    EDX,$cnt-32" %}
  7980   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
  7981   ins_pipe( pipe_slow );
  7982 %}
  7984 // Multiply Memory 32-bit Immediate
  7985 instruct mulI_mem_imm(rRegI dst, memory src, immI imm, eFlagsReg cr) %{
  7986   match(Set dst (MulI (LoadI src) imm));
  7987   effect(KILL cr);
  7989   ins_cost(300);
  7990   format %{ "IMUL   $dst,$src,$imm" %}
  7991   opcode(0x69);  /* 69 /r id */
  7992   ins_encode( OpcSE(imm), RegMem( dst, src ), Con8or32( imm ) );
  7993   ins_pipe( ialu_reg_mem_alu0 );
  7994 %}
  7996 // Multiply Memory
  7997 instruct mulI(rRegI dst, memory src, eFlagsReg cr) %{
  7998   match(Set dst (MulI dst (LoadI src)));
  7999   effect(KILL cr);
  8001   ins_cost(350);
  8002   format %{ "IMUL   $dst,$src" %}
  8003   opcode(0xAF, 0x0F);
  8004   ins_encode( OpcS, OpcP, RegMem( dst, src) );
  8005   ins_pipe( ialu_reg_mem_alu0 );
  8006 %}
  8008 // Multiply Register Int to Long
  8009 instruct mulI2L(eADXRegL dst, eAXRegI src, nadxRegI src1, eFlagsReg flags) %{
  8010   // Basic Idea: long = (long)int * (long)int
  8011   match(Set dst (MulL (ConvI2L src) (ConvI2L src1)));
  8012   effect(DEF dst, USE src, USE src1, KILL flags);
  8014   ins_cost(300);
  8015   format %{ "IMUL   $dst,$src1" %}
  8017   ins_encode( long_int_multiply( dst, src1 ) );
  8018   ins_pipe( ialu_reg_reg_alu0 );
  8019 %}
  8021 instruct mulIS_eReg(eADXRegL dst, immL_32bits mask, eFlagsReg flags, eAXRegI src, nadxRegI src1) %{
  8022   // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
  8023   match(Set dst (MulL (AndL (ConvI2L src) mask) (AndL (ConvI2L src1) mask)));
  8024   effect(KILL flags);
  8026   ins_cost(300);
  8027   format %{ "MUL    $dst,$src1" %}
  8029   ins_encode( long_uint_multiply(dst, src1) );
  8030   ins_pipe( ialu_reg_reg_alu0 );
  8031 %}
  8033 // Multiply Register Long
  8034 instruct mulL_eReg(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
  8035   match(Set dst (MulL dst src));
  8036   effect(KILL cr, TEMP tmp);
  8037   ins_cost(4*100+3*400);
  8038 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8039 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
  8040   format %{ "MOV    $tmp,$src.lo\n\t"
  8041             "IMUL   $tmp,EDX\n\t"
  8042             "MOV    EDX,$src.hi\n\t"
  8043             "IMUL   EDX,EAX\n\t"
  8044             "ADD    $tmp,EDX\n\t"
  8045             "MUL    EDX:EAX,$src.lo\n\t"
  8046             "ADD    EDX,$tmp" %}
  8047   ins_encode( long_multiply( dst, src, tmp ) );
  8048   ins_pipe( pipe_slow );
  8049 %}
  8051 // Multiply Register Long where the left operand's high 32 bits are zero
  8052 instruct mulL_eReg_lhi0(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
  8053   predicate(is_operand_hi32_zero(n->in(1)));
  8054   match(Set dst (MulL dst src));
  8055   effect(KILL cr, TEMP tmp);
  8056   ins_cost(2*100+2*400);
  8057 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8058 //             hi(result) = hi(x_lo * y_lo) + lo(x_lo * y_hi) where lo(x_hi * y_lo) = 0 because x_hi = 0
  8059   format %{ "MOV    $tmp,$src.hi\n\t"
  8060             "IMUL   $tmp,EAX\n\t"
  8061             "MUL    EDX:EAX,$src.lo\n\t"
  8062             "ADD    EDX,$tmp" %}
  8063   ins_encode %{
  8064     __ movl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
  8065     __ imull($tmp$$Register, rax);
  8066     __ mull($src$$Register);
  8067     __ addl(rdx, $tmp$$Register);
  8068   %}
  8069   ins_pipe( pipe_slow );
  8070 %}
  8072 // Multiply Register Long where the right operand's high 32 bits are zero
  8073 instruct mulL_eReg_rhi0(eADXRegL dst, eRegL src, rRegI tmp, eFlagsReg cr) %{
  8074   predicate(is_operand_hi32_zero(n->in(2)));
  8075   match(Set dst (MulL dst src));
  8076   effect(KILL cr, TEMP tmp);
  8077   ins_cost(2*100+2*400);
  8078 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8079 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) where lo(x_lo * y_hi) = 0 because y_hi = 0
  8080   format %{ "MOV    $tmp,$src.lo\n\t"
  8081             "IMUL   $tmp,EDX\n\t"
  8082             "MUL    EDX:EAX,$src.lo\n\t"
  8083             "ADD    EDX,$tmp" %}
  8084   ins_encode %{
  8085     __ movl($tmp$$Register, $src$$Register);
  8086     __ imull($tmp$$Register, rdx);
  8087     __ mull($src$$Register);
  8088     __ addl(rdx, $tmp$$Register);
  8089   %}
  8090   ins_pipe( pipe_slow );
  8091 %}
  8093 // Multiply Register Long where the left and the right operands' high 32 bits are zero
  8094 instruct mulL_eReg_hi0(eADXRegL dst, eRegL src, eFlagsReg cr) %{
  8095   predicate(is_operand_hi32_zero(n->in(1)) && is_operand_hi32_zero(n->in(2)));
  8096   match(Set dst (MulL dst src));
  8097   effect(KILL cr);
  8098   ins_cost(1*400);
  8099 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8100 //             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
  8101   format %{ "MUL    EDX:EAX,$src.lo\n\t" %}
  8102   ins_encode %{
  8103     __ mull($src$$Register);
  8104   %}
  8105   ins_pipe( pipe_slow );
  8106 %}
  8108 // Multiply Register Long by small constant
  8109 instruct mulL_eReg_con(eADXRegL dst, immL_127 src, rRegI tmp, eFlagsReg cr) %{
  8110   match(Set dst (MulL dst src));
  8111   effect(KILL cr, TEMP tmp);
  8112   ins_cost(2*100+2*400);
  8113   size(12);
  8114 // Basic idea: lo(result) = lo(src * EAX)
  8115 //             hi(result) = hi(src * EAX) + lo(src * EDX)
  8116   format %{ "IMUL   $tmp,EDX,$src\n\t"
  8117             "MOV    EDX,$src\n\t"
  8118             "MUL    EDX\t# EDX*EAX -> EDX:EAX\n\t"
  8119             "ADD    EDX,$tmp" %}
  8120   ins_encode( long_multiply_con( dst, src, tmp ) );
  8121   ins_pipe( pipe_slow );
  8122 %}
  8124 // Integer DIV with Register
  8125 instruct divI_eReg(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
  8126   match(Set rax (DivI rax div));
  8127   effect(KILL rdx, KILL cr);
  8128   size(26);
  8129   ins_cost(30*100+10*100);
  8130   format %{ "CMP    EAX,0x80000000\n\t"
  8131             "JNE,s  normal\n\t"
  8132             "XOR    EDX,EDX\n\t"
  8133             "CMP    ECX,-1\n\t"
  8134             "JE,s   done\n"
  8135     "normal: CDQ\n\t"
  8136             "IDIV   $div\n\t"
  8137     "done:"        %}
  8138   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8139   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8140   ins_pipe( ialu_reg_reg_alu0 );
  8141 %}
  8143 // Divide Register Long
  8144 instruct divL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
  8145   match(Set dst (DivL src1 src2));
  8146   effect( KILL cr, KILL cx, KILL bx );
  8147   ins_cost(10000);
  8148   format %{ "PUSH   $src1.hi\n\t"
  8149             "PUSH   $src1.lo\n\t"
  8150             "PUSH   $src2.hi\n\t"
  8151             "PUSH   $src2.lo\n\t"
  8152             "CALL   SharedRuntime::ldiv\n\t"
  8153             "ADD    ESP,16" %}
  8154   ins_encode( long_div(src1,src2) );
  8155   ins_pipe( pipe_slow );
  8156 %}
  8158 // Integer DIVMOD with Register, both quotient and mod results
  8159 instruct divModI_eReg_divmod(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
  8160   match(DivModI rax div);
  8161   effect(KILL cr);
  8162   size(26);
  8163   ins_cost(30*100+10*100);
  8164   format %{ "CMP    EAX,0x80000000\n\t"
  8165             "JNE,s  normal\n\t"
  8166             "XOR    EDX,EDX\n\t"
  8167             "CMP    ECX,-1\n\t"
  8168             "JE,s   done\n"
  8169     "normal: CDQ\n\t"
  8170             "IDIV   $div\n\t"
  8171     "done:"        %}
  8172   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8173   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8174   ins_pipe( pipe_slow );
  8175 %}
  8177 // Integer MOD with Register
  8178 instruct modI_eReg(eDXRegI rdx, eAXRegI rax, eCXRegI div, eFlagsReg cr) %{
  8179   match(Set rdx (ModI rax div));
  8180   effect(KILL rax, KILL cr);
  8182   size(26);
  8183   ins_cost(300);
  8184   format %{ "CDQ\n\t"
  8185             "IDIV   $div" %}
  8186   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8187   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8188   ins_pipe( ialu_reg_reg_alu0 );
  8189 %}
  8191 // Remainder Register Long
  8192 instruct modL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
  8193   match(Set dst (ModL src1 src2));
  8194   effect( KILL cr, KILL cx, KILL bx );
  8195   ins_cost(10000);
  8196   format %{ "PUSH   $src1.hi\n\t"
  8197             "PUSH   $src1.lo\n\t"
  8198             "PUSH   $src2.hi\n\t"
  8199             "PUSH   $src2.lo\n\t"
  8200             "CALL   SharedRuntime::lrem\n\t"
  8201             "ADD    ESP,16" %}
  8202   ins_encode( long_mod(src1,src2) );
  8203   ins_pipe( pipe_slow );
  8204 %}
  8206 // Divide Register Long (no special case since divisor != -1)
  8207 instruct divL_eReg_imm32( eADXRegL dst, immL32 imm, rRegI tmp, rRegI tmp2, eFlagsReg cr ) %{
  8208   match(Set dst (DivL dst imm));
  8209   effect( TEMP tmp, TEMP tmp2, KILL cr );
  8210   ins_cost(1000);
  8211   format %{ "MOV    $tmp,abs($imm) # ldiv EDX:EAX,$imm\n\t"
  8212             "XOR    $tmp2,$tmp2\n\t"
  8213             "CMP    $tmp,EDX\n\t"
  8214             "JA,s   fast\n\t"
  8215             "MOV    $tmp2,EAX\n\t"
  8216             "MOV    EAX,EDX\n\t"
  8217             "MOV    EDX,0\n\t"
  8218             "JLE,s  pos\n\t"
  8219             "LNEG   EAX : $tmp2\n\t"
  8220             "DIV    $tmp # unsigned division\n\t"
  8221             "XCHG   EAX,$tmp2\n\t"
  8222             "DIV    $tmp\n\t"
  8223             "LNEG   $tmp2 : EAX\n\t"
  8224             "JMP,s  done\n"
  8225     "pos:\n\t"
  8226             "DIV    $tmp\n\t"
  8227             "XCHG   EAX,$tmp2\n"
  8228     "fast:\n\t"
  8229             "DIV    $tmp\n"
  8230     "done:\n\t"
  8231             "MOV    EDX,$tmp2\n\t"
  8232             "NEG    EDX:EAX # if $imm < 0" %}
  8233   ins_encode %{
  8234     int con = (int)$imm$$constant;
  8235     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
  8236     int pcon = (con > 0) ? con : -con;
  8237     Label Lfast, Lpos, Ldone;
  8239     __ movl($tmp$$Register, pcon);
  8240     __ xorl($tmp2$$Register,$tmp2$$Register);
  8241     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
  8242     __ jccb(Assembler::above, Lfast); // result fits into 32 bit
  8244     __ movl($tmp2$$Register, $dst$$Register); // save
  8245     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8246     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
  8247     __ jccb(Assembler::lessEqual, Lpos); // result is positive
  8249     // Negative dividend.
  8250     // convert value to positive to use unsigned division
  8251     __ lneg($dst$$Register, $tmp2$$Register);
  8252     __ divl($tmp$$Register);
  8253     __ xchgl($dst$$Register, $tmp2$$Register);
  8254     __ divl($tmp$$Register);
  8255     // revert result back to negative
  8256     __ lneg($tmp2$$Register, $dst$$Register);
  8257     __ jmpb(Ldone);
  8259     __ bind(Lpos);
  8260     __ divl($tmp$$Register); // Use unsigned division
  8261     __ xchgl($dst$$Register, $tmp2$$Register);
  8262     // Fallthrow for final divide, tmp2 has 32 bit hi result
  8264     __ bind(Lfast);
  8265     // fast path: src is positive
  8266     __ divl($tmp$$Register); // Use unsigned division
  8268     __ bind(Ldone);
  8269     __ movl(HIGH_FROM_LOW($dst$$Register),$tmp2$$Register);
  8270     if (con < 0) {
  8271       __ lneg(HIGH_FROM_LOW($dst$$Register), $dst$$Register);
  8273   %}
  8274   ins_pipe( pipe_slow );
  8275 %}
  8277 // Remainder Register Long (remainder fit into 32 bits)
  8278 instruct modL_eReg_imm32( eADXRegL dst, immL32 imm, rRegI tmp, rRegI tmp2, eFlagsReg cr ) %{
  8279   match(Set dst (ModL dst imm));
  8280   effect( TEMP tmp, TEMP tmp2, KILL cr );
  8281   ins_cost(1000);
  8282   format %{ "MOV    $tmp,abs($imm) # lrem EDX:EAX,$imm\n\t"
  8283             "CMP    $tmp,EDX\n\t"
  8284             "JA,s   fast\n\t"
  8285             "MOV    $tmp2,EAX\n\t"
  8286             "MOV    EAX,EDX\n\t"
  8287             "MOV    EDX,0\n\t"
  8288             "JLE,s  pos\n\t"
  8289             "LNEG   EAX : $tmp2\n\t"
  8290             "DIV    $tmp # unsigned division\n\t"
  8291             "MOV    EAX,$tmp2\n\t"
  8292             "DIV    $tmp\n\t"
  8293             "NEG    EDX\n\t"
  8294             "JMP,s  done\n"
  8295     "pos:\n\t"
  8296             "DIV    $tmp\n\t"
  8297             "MOV    EAX,$tmp2\n"
  8298     "fast:\n\t"
  8299             "DIV    $tmp\n"
  8300     "done:\n\t"
  8301             "MOV    EAX,EDX\n\t"
  8302             "SAR    EDX,31\n\t" %}
  8303   ins_encode %{
  8304     int con = (int)$imm$$constant;
  8305     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
  8306     int pcon = (con > 0) ? con : -con;
  8307     Label  Lfast, Lpos, Ldone;
  8309     __ movl($tmp$$Register, pcon);
  8310     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
  8311     __ jccb(Assembler::above, Lfast); // src is positive and result fits into 32 bit
  8313     __ movl($tmp2$$Register, $dst$$Register); // save
  8314     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8315     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
  8316     __ jccb(Assembler::lessEqual, Lpos); // result is positive
  8318     // Negative dividend.
  8319     // convert value to positive to use unsigned division
  8320     __ lneg($dst$$Register, $tmp2$$Register);
  8321     __ divl($tmp$$Register);
  8322     __ movl($dst$$Register, $tmp2$$Register);
  8323     __ divl($tmp$$Register);
  8324     // revert remainder back to negative
  8325     __ negl(HIGH_FROM_LOW($dst$$Register));
  8326     __ jmpb(Ldone);
  8328     __ bind(Lpos);
  8329     __ divl($tmp$$Register);
  8330     __ movl($dst$$Register, $tmp2$$Register);
  8332     __ bind(Lfast);
  8333     // fast path: src is positive
  8334     __ divl($tmp$$Register);
  8336     __ bind(Ldone);
  8337     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8338     __ sarl(HIGH_FROM_LOW($dst$$Register), 31); // result sign
  8340   %}
  8341   ins_pipe( pipe_slow );
  8342 %}
  8344 // Integer Shift Instructions
  8345 // Shift Left by one
  8346 instruct shlI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
  8347   match(Set dst (LShiftI dst shift));
  8348   effect(KILL cr);
  8350   size(2);
  8351   format %{ "SHL    $dst,$shift" %}
  8352   opcode(0xD1, 0x4);  /* D1 /4 */
  8353   ins_encode( OpcP, RegOpc( dst ) );
  8354   ins_pipe( ialu_reg );
  8355 %}
  8357 // Shift Left by 8-bit immediate
  8358 instruct salI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
  8359   match(Set dst (LShiftI dst shift));
  8360   effect(KILL cr);
  8362   size(3);
  8363   format %{ "SHL    $dst,$shift" %}
  8364   opcode(0xC1, 0x4);  /* C1 /4 ib */
  8365   ins_encode( RegOpcImm( dst, shift) );
  8366   ins_pipe( ialu_reg );
  8367 %}
  8369 // Shift Left by variable
  8370 instruct salI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
  8371   match(Set dst (LShiftI dst shift));
  8372   effect(KILL cr);
  8374   size(2);
  8375   format %{ "SHL    $dst,$shift" %}
  8376   opcode(0xD3, 0x4);  /* D3 /4 */
  8377   ins_encode( OpcP, RegOpc( dst ) );
  8378   ins_pipe( ialu_reg_reg );
  8379 %}
  8381 // Arithmetic shift right by one
  8382 instruct sarI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
  8383   match(Set dst (RShiftI dst shift));
  8384   effect(KILL cr);
  8386   size(2);
  8387   format %{ "SAR    $dst,$shift" %}
  8388   opcode(0xD1, 0x7);  /* D1 /7 */
  8389   ins_encode( OpcP, RegOpc( dst ) );
  8390   ins_pipe( ialu_reg );
  8391 %}
  8393 // Arithmetic shift right by one
  8394 instruct sarI_mem_1(memory dst, immI1 shift, eFlagsReg cr) %{
  8395   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  8396   effect(KILL cr);
  8397   format %{ "SAR    $dst,$shift" %}
  8398   opcode(0xD1, 0x7);  /* D1 /7 */
  8399   ins_encode( OpcP, RMopc_Mem(secondary,dst) );
  8400   ins_pipe( ialu_mem_imm );
  8401 %}
  8403 // Arithmetic Shift Right by 8-bit immediate
  8404 instruct sarI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
  8405   match(Set dst (RShiftI dst shift));
  8406   effect(KILL cr);
  8408   size(3);
  8409   format %{ "SAR    $dst,$shift" %}
  8410   opcode(0xC1, 0x7);  /* C1 /7 ib */
  8411   ins_encode( RegOpcImm( dst, shift ) );
  8412   ins_pipe( ialu_mem_imm );
  8413 %}
  8415 // Arithmetic Shift Right by 8-bit immediate
  8416 instruct sarI_mem_imm(memory dst, immI8 shift, eFlagsReg cr) %{
  8417   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  8418   effect(KILL cr);
  8420   format %{ "SAR    $dst,$shift" %}
  8421   opcode(0xC1, 0x7);  /* C1 /7 ib */
  8422   ins_encode( OpcP, RMopc_Mem(secondary, dst ), Con8or32( shift ) );
  8423   ins_pipe( ialu_mem_imm );
  8424 %}
  8426 // Arithmetic Shift Right by variable
  8427 instruct sarI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
  8428   match(Set dst (RShiftI dst shift));
  8429   effect(KILL cr);
  8431   size(2);
  8432   format %{ "SAR    $dst,$shift" %}
  8433   opcode(0xD3, 0x7);  /* D3 /7 */
  8434   ins_encode( OpcP, RegOpc( dst ) );
  8435   ins_pipe( ialu_reg_reg );
  8436 %}
  8438 // Logical shift right by one
  8439 instruct shrI_eReg_1(rRegI dst, immI1 shift, eFlagsReg cr) %{
  8440   match(Set dst (URShiftI dst shift));
  8441   effect(KILL cr);
  8443   size(2);
  8444   format %{ "SHR    $dst,$shift" %}
  8445   opcode(0xD1, 0x5);  /* D1 /5 */
  8446   ins_encode( OpcP, RegOpc( dst ) );
  8447   ins_pipe( ialu_reg );
  8448 %}
  8450 // Logical Shift Right by 8-bit immediate
  8451 instruct shrI_eReg_imm(rRegI dst, immI8 shift, eFlagsReg cr) %{
  8452   match(Set dst (URShiftI dst shift));
  8453   effect(KILL cr);
  8455   size(3);
  8456   format %{ "SHR    $dst,$shift" %}
  8457   opcode(0xC1, 0x5);  /* C1 /5 ib */
  8458   ins_encode( RegOpcImm( dst, shift) );
  8459   ins_pipe( ialu_reg );
  8460 %}
  8463 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
  8464 // This idiom is used by the compiler for the i2b bytecode.
  8465 instruct i2b(rRegI dst, xRegI src, immI_24 twentyfour) %{
  8466   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
  8468   size(3);
  8469   format %{ "MOVSX  $dst,$src :8" %}
  8470   ins_encode %{
  8471     __ movsbl($dst$$Register, $src$$Register);
  8472   %}
  8473   ins_pipe(ialu_reg_reg);
  8474 %}
  8476 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
  8477 // This idiom is used by the compiler the i2s bytecode.
  8478 instruct i2s(rRegI dst, xRegI src, immI_16 sixteen) %{
  8479   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
  8481   size(3);
  8482   format %{ "MOVSX  $dst,$src :16" %}
  8483   ins_encode %{
  8484     __ movswl($dst$$Register, $src$$Register);
  8485   %}
  8486   ins_pipe(ialu_reg_reg);
  8487 %}
  8490 // Logical Shift Right by variable
  8491 instruct shrI_eReg_CL(rRegI dst, eCXRegI shift, eFlagsReg cr) %{
  8492   match(Set dst (URShiftI dst shift));
  8493   effect(KILL cr);
  8495   size(2);
  8496   format %{ "SHR    $dst,$shift" %}
  8497   opcode(0xD3, 0x5);  /* D3 /5 */
  8498   ins_encode( OpcP, RegOpc( dst ) );
  8499   ins_pipe( ialu_reg_reg );
  8500 %}
  8503 //----------Logical Instructions-----------------------------------------------
  8504 //----------Integer Logical Instructions---------------------------------------
  8505 // And Instructions
  8506 // And Register with Register
  8507 instruct andI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
  8508   match(Set dst (AndI dst src));
  8509   effect(KILL cr);
  8511   size(2);
  8512   format %{ "AND    $dst,$src" %}
  8513   opcode(0x23);
  8514   ins_encode( OpcP, RegReg( dst, src) );
  8515   ins_pipe( ialu_reg_reg );
  8516 %}
  8518 // And Register with Immediate
  8519 instruct andI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
  8520   match(Set dst (AndI dst src));
  8521   effect(KILL cr);
  8523   format %{ "AND    $dst,$src" %}
  8524   opcode(0x81,0x04);  /* Opcode 81 /4 */
  8525   // ins_encode( RegImm( dst, src) );
  8526   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8527   ins_pipe( ialu_reg );
  8528 %}
  8530 // And Register with Memory
  8531 instruct andI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
  8532   match(Set dst (AndI dst (LoadI src)));
  8533   effect(KILL cr);
  8535   ins_cost(125);
  8536   format %{ "AND    $dst,$src" %}
  8537   opcode(0x23);
  8538   ins_encode( OpcP, RegMem( dst, src) );
  8539   ins_pipe( ialu_reg_mem );
  8540 %}
  8542 // And Memory with Register
  8543 instruct andI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
  8544   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  8545   effect(KILL cr);
  8547   ins_cost(150);
  8548   format %{ "AND    $dst,$src" %}
  8549   opcode(0x21);  /* Opcode 21 /r */
  8550   ins_encode( OpcP, RegMem( src, dst ) );
  8551   ins_pipe( ialu_mem_reg );
  8552 %}
  8554 // And Memory with Immediate
  8555 instruct andI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  8556   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  8557   effect(KILL cr);
  8559   ins_cost(125);
  8560   format %{ "AND    $dst,$src" %}
  8561   opcode(0x81, 0x4);  /* Opcode 81 /4 id */
  8562   // ins_encode( MemImm( dst, src) );
  8563   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  8564   ins_pipe( ialu_mem_imm );
  8565 %}
  8567 // Or Instructions
  8568 // Or Register with Register
  8569 instruct orI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
  8570   match(Set dst (OrI dst src));
  8571   effect(KILL cr);
  8573   size(2);
  8574   format %{ "OR     $dst,$src" %}
  8575   opcode(0x0B);
  8576   ins_encode( OpcP, RegReg( dst, src) );
  8577   ins_pipe( ialu_reg_reg );
  8578 %}
  8580 instruct orI_eReg_castP2X(rRegI dst, eRegP src, eFlagsReg cr) %{
  8581   match(Set dst (OrI dst (CastP2X src)));
  8582   effect(KILL cr);
  8584   size(2);
  8585   format %{ "OR     $dst,$src" %}
  8586   opcode(0x0B);
  8587   ins_encode( OpcP, RegReg( dst, src) );
  8588   ins_pipe( ialu_reg_reg );
  8589 %}
  8592 // Or Register with Immediate
  8593 instruct orI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
  8594   match(Set dst (OrI dst src));
  8595   effect(KILL cr);
  8597   format %{ "OR     $dst,$src" %}
  8598   opcode(0x81,0x01);  /* Opcode 81 /1 id */
  8599   // ins_encode( RegImm( dst, src) );
  8600   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8601   ins_pipe( ialu_reg );
  8602 %}
  8604 // Or Register with Memory
  8605 instruct orI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
  8606   match(Set dst (OrI dst (LoadI src)));
  8607   effect(KILL cr);
  8609   ins_cost(125);
  8610   format %{ "OR     $dst,$src" %}
  8611   opcode(0x0B);
  8612   ins_encode( OpcP, RegMem( dst, src) );
  8613   ins_pipe( ialu_reg_mem );
  8614 %}
  8616 // Or Memory with Register
  8617 instruct orI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
  8618   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  8619   effect(KILL cr);
  8621   ins_cost(150);
  8622   format %{ "OR     $dst,$src" %}
  8623   opcode(0x09);  /* Opcode 09 /r */
  8624   ins_encode( OpcP, RegMem( src, dst ) );
  8625   ins_pipe( ialu_mem_reg );
  8626 %}
  8628 // Or Memory with Immediate
  8629 instruct orI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  8630   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  8631   effect(KILL cr);
  8633   ins_cost(125);
  8634   format %{ "OR     $dst,$src" %}
  8635   opcode(0x81,0x1);  /* Opcode 81 /1 id */
  8636   // ins_encode( MemImm( dst, src) );
  8637   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  8638   ins_pipe( ialu_mem_imm );
  8639 %}
  8641 // ROL/ROR
  8642 // ROL expand
  8643 instruct rolI_eReg_imm1(rRegI dst, immI1 shift, eFlagsReg cr) %{
  8644   effect(USE_DEF dst, USE shift, KILL cr);
  8646   format %{ "ROL    $dst, $shift" %}
  8647   opcode(0xD1, 0x0); /* Opcode D1 /0 */
  8648   ins_encode( OpcP, RegOpc( dst ));
  8649   ins_pipe( ialu_reg );
  8650 %}
  8652 instruct rolI_eReg_imm8(rRegI dst, immI8 shift, eFlagsReg cr) %{
  8653   effect(USE_DEF dst, USE shift, KILL cr);
  8655   format %{ "ROL    $dst, $shift" %}
  8656   opcode(0xC1, 0x0); /*Opcode /C1  /0  */
  8657   ins_encode( RegOpcImm(dst, shift) );
  8658   ins_pipe(ialu_reg);
  8659 %}
  8661 instruct rolI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr) %{
  8662   effect(USE_DEF dst, USE shift, KILL cr);
  8664   format %{ "ROL    $dst, $shift" %}
  8665   opcode(0xD3, 0x0);    /* Opcode D3 /0 */
  8666   ins_encode(OpcP, RegOpc(dst));
  8667   ins_pipe( ialu_reg_reg );
  8668 %}
  8669 // end of ROL expand
  8671 // ROL 32bit by one once
  8672 instruct rolI_eReg_i1(rRegI dst, immI1 lshift, immI_M1 rshift, eFlagsReg cr) %{
  8673   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  8675   expand %{
  8676     rolI_eReg_imm1(dst, lshift, cr);
  8677   %}
  8678 %}
  8680 // ROL 32bit var by imm8 once
  8681 instruct rolI_eReg_i8(rRegI dst, immI8 lshift, immI8 rshift, eFlagsReg cr) %{
  8682   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  8683   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  8685   expand %{
  8686     rolI_eReg_imm8(dst, lshift, cr);
  8687   %}
  8688 %}
  8690 // ROL 32bit var by var once
  8691 instruct rolI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
  8692   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI zero shift))));
  8694   expand %{
  8695     rolI_eReg_CL(dst, shift, cr);
  8696   %}
  8697 %}
  8699 // ROL 32bit var by var once
  8700 instruct rolI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
  8701   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI c32 shift))));
  8703   expand %{
  8704     rolI_eReg_CL(dst, shift, cr);
  8705   %}
  8706 %}
  8708 // ROR expand
  8709 instruct rorI_eReg_imm1(rRegI dst, immI1 shift, eFlagsReg cr) %{
  8710   effect(USE_DEF dst, USE shift, KILL cr);
  8712   format %{ "ROR    $dst, $shift" %}
  8713   opcode(0xD1,0x1);  /* Opcode D1 /1 */
  8714   ins_encode( OpcP, RegOpc( dst ) );
  8715   ins_pipe( ialu_reg );
  8716 %}
  8718 instruct rorI_eReg_imm8(rRegI dst, immI8 shift, eFlagsReg cr) %{
  8719   effect (USE_DEF dst, USE shift, KILL cr);
  8721   format %{ "ROR    $dst, $shift" %}
  8722   opcode(0xC1, 0x1); /* Opcode /C1 /1 ib */
  8723   ins_encode( RegOpcImm(dst, shift) );
  8724   ins_pipe( ialu_reg );
  8725 %}
  8727 instruct rorI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr)%{
  8728   effect(USE_DEF dst, USE shift, KILL cr);
  8730   format %{ "ROR    $dst, $shift" %}
  8731   opcode(0xD3, 0x1);    /* Opcode D3 /1 */
  8732   ins_encode(OpcP, RegOpc(dst));
  8733   ins_pipe( ialu_reg_reg );
  8734 %}
  8735 // end of ROR expand
  8737 // ROR right once
  8738 instruct rorI_eReg_i1(rRegI dst, immI1 rshift, immI_M1 lshift, eFlagsReg cr) %{
  8739   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  8741   expand %{
  8742     rorI_eReg_imm1(dst, rshift, cr);
  8743   %}
  8744 %}
  8746 // ROR 32bit by immI8 once
  8747 instruct rorI_eReg_i8(rRegI dst, immI8 rshift, immI8 lshift, eFlagsReg cr) %{
  8748   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  8749   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  8751   expand %{
  8752     rorI_eReg_imm8(dst, rshift, cr);
  8753   %}
  8754 %}
  8756 // ROR 32bit var by var once
  8757 instruct rorI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
  8758   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI zero shift))));
  8760   expand %{
  8761     rorI_eReg_CL(dst, shift, cr);
  8762   %}
  8763 %}
  8765 // ROR 32bit var by var once
  8766 instruct rorI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
  8767   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI c32 shift))));
  8769   expand %{
  8770     rorI_eReg_CL(dst, shift, cr);
  8771   %}
  8772 %}
  8774 // Xor Instructions
  8775 // Xor Register with Register
  8776 instruct xorI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
  8777   match(Set dst (XorI dst src));
  8778   effect(KILL cr);
  8780   size(2);
  8781   format %{ "XOR    $dst,$src" %}
  8782   opcode(0x33);
  8783   ins_encode( OpcP, RegReg( dst, src) );
  8784   ins_pipe( ialu_reg_reg );
  8785 %}
  8787 // Xor Register with Immediate -1
  8788 instruct xorI_eReg_im1(rRegI dst, immI_M1 imm) %{
  8789   match(Set dst (XorI dst imm));  
  8791   size(2);
  8792   format %{ "NOT    $dst" %}  
  8793   ins_encode %{
  8794      __ notl($dst$$Register);
  8795   %}
  8796   ins_pipe( ialu_reg );
  8797 %}
  8799 // Xor Register with Immediate
  8800 instruct xorI_eReg_imm(rRegI dst, immI src, eFlagsReg cr) %{
  8801   match(Set dst (XorI dst src));
  8802   effect(KILL cr);
  8804   format %{ "XOR    $dst,$src" %}
  8805   opcode(0x81,0x06);  /* Opcode 81 /6 id */
  8806   // ins_encode( RegImm( dst, src) );
  8807   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8808   ins_pipe( ialu_reg );
  8809 %}
  8811 // Xor Register with Memory
  8812 instruct xorI_eReg_mem(rRegI dst, memory src, eFlagsReg cr) %{
  8813   match(Set dst (XorI dst (LoadI src)));
  8814   effect(KILL cr);
  8816   ins_cost(125);
  8817   format %{ "XOR    $dst,$src" %}
  8818   opcode(0x33);
  8819   ins_encode( OpcP, RegMem(dst, src) );
  8820   ins_pipe( ialu_reg_mem );
  8821 %}
  8823 // Xor Memory with Register
  8824 instruct xorI_mem_eReg(memory dst, rRegI src, eFlagsReg cr) %{
  8825   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  8826   effect(KILL cr);
  8828   ins_cost(150);
  8829   format %{ "XOR    $dst,$src" %}
  8830   opcode(0x31);  /* Opcode 31 /r */
  8831   ins_encode( OpcP, RegMem( src, dst ) );
  8832   ins_pipe( ialu_mem_reg );
  8833 %}
  8835 // Xor Memory with Immediate
  8836 instruct xorI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  8837   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  8838   effect(KILL cr);
  8840   ins_cost(125);
  8841   format %{ "XOR    $dst,$src" %}
  8842   opcode(0x81,0x6);  /* Opcode 81 /6 id */
  8843   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  8844   ins_pipe( ialu_mem_imm );
  8845 %}
  8847 //----------Convert Int to Boolean---------------------------------------------
  8849 instruct movI_nocopy(rRegI dst, rRegI src) %{
  8850   effect( DEF dst, USE src );
  8851   format %{ "MOV    $dst,$src" %}
  8852   ins_encode( enc_Copy( dst, src) );
  8853   ins_pipe( ialu_reg_reg );
  8854 %}
  8856 instruct ci2b( rRegI dst, rRegI src, eFlagsReg cr ) %{
  8857   effect( USE_DEF dst, USE src, KILL cr );
  8859   size(4);
  8860   format %{ "NEG    $dst\n\t"
  8861             "ADC    $dst,$src" %}
  8862   ins_encode( neg_reg(dst),
  8863               OpcRegReg(0x13,dst,src) );
  8864   ins_pipe( ialu_reg_reg_long );
  8865 %}
  8867 instruct convI2B( rRegI dst, rRegI src, eFlagsReg cr ) %{
  8868   match(Set dst (Conv2B src));
  8870   expand %{
  8871     movI_nocopy(dst,src);
  8872     ci2b(dst,src,cr);
  8873   %}
  8874 %}
  8876 instruct movP_nocopy(rRegI dst, eRegP src) %{
  8877   effect( DEF dst, USE src );
  8878   format %{ "MOV    $dst,$src" %}
  8879   ins_encode( enc_Copy( dst, src) );
  8880   ins_pipe( ialu_reg_reg );
  8881 %}
  8883 instruct cp2b( rRegI dst, eRegP src, eFlagsReg cr ) %{
  8884   effect( USE_DEF dst, USE src, KILL cr );
  8885   format %{ "NEG    $dst\n\t"
  8886             "ADC    $dst,$src" %}
  8887   ins_encode( neg_reg(dst),
  8888               OpcRegReg(0x13,dst,src) );
  8889   ins_pipe( ialu_reg_reg_long );
  8890 %}
  8892 instruct convP2B( rRegI dst, eRegP src, eFlagsReg cr ) %{
  8893   match(Set dst (Conv2B src));
  8895   expand %{
  8896     movP_nocopy(dst,src);
  8897     cp2b(dst,src,cr);
  8898   %}
  8899 %}
  8901 instruct cmpLTMask(eCXRegI dst, ncxRegI p, ncxRegI q, eFlagsReg cr) %{
  8902   match(Set dst (CmpLTMask p q));
  8903   effect(KILL cr);
  8904   ins_cost(400);
  8906   // SETlt can only use low byte of EAX,EBX, ECX, or EDX as destination
  8907   format %{ "XOR    $dst,$dst\n\t"
  8908             "CMP    $p,$q\n\t"
  8909             "SETlt  $dst\n\t"
  8910             "NEG    $dst" %}
  8911   ins_encode %{
  8912     Register Rp = $p$$Register;
  8913     Register Rq = $q$$Register;
  8914     Register Rd = $dst$$Register;
  8915     Label done;
  8916     __ xorl(Rd, Rd);
  8917     __ cmpl(Rp, Rq);
  8918     __ setb(Assembler::less, Rd);
  8919     __ negl(Rd);
  8920   %}
  8922   ins_pipe(pipe_slow);
  8923 %}
  8925 instruct cmpLTMask0(rRegI dst, immI0 zero, eFlagsReg cr) %{
  8926   match(Set dst (CmpLTMask dst zero));
  8927   effect(DEF dst, KILL cr);
  8928   ins_cost(100);
  8930   format %{ "SAR    $dst,31\t# cmpLTMask0" %}
  8931   ins_encode %{
  8932   __ sarl($dst$$Register, 31);
  8933   %}
  8934   ins_pipe(ialu_reg);
  8935 %}
  8937 /* better to save a register than avoid a branch */
  8938 instruct cadd_cmpLTMask(rRegI p, rRegI q, rRegI y, eFlagsReg cr) %{
  8939   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
  8940   effect(KILL cr);
  8941   ins_cost(400);
  8942   format %{ "SUB    $p,$q\t# cadd_cmpLTMask\n\t"
  8943             "JGE    done\n\t"
  8944             "ADD    $p,$y\n"
  8945             "done:  " %}
  8946   ins_encode %{
  8947     Register Rp = $p$$Register;
  8948     Register Rq = $q$$Register;
  8949     Register Ry = $y$$Register;
  8950     Label done;
  8951     __ subl(Rp, Rq);
  8952     __ jccb(Assembler::greaterEqual, done);
  8953     __ addl(Rp, Ry);
  8954     __ bind(done);
  8955   %}
  8957   ins_pipe(pipe_cmplt);
  8958 %}
  8960 /* better to save a register than avoid a branch */
  8961 instruct and_cmpLTMask(rRegI p, rRegI q, rRegI y, eFlagsReg cr) %{
  8962   match(Set y (AndI (CmpLTMask p q) y));
  8963   effect(KILL cr);
  8965   ins_cost(300);
  8967   format %{ "CMPL     $p, $q\t# and_cmpLTMask\n\t"
  8968             "JLT      done\n\t"
  8969             "XORL     $y, $y\n"
  8970             "done:  " %}
  8971   ins_encode %{
  8972     Register Rp = $p$$Register;
  8973     Register Rq = $q$$Register;
  8974     Register Ry = $y$$Register;
  8975     Label done;
  8976     __ cmpl(Rp, Rq);
  8977     __ jccb(Assembler::less, done);
  8978     __ xorl(Ry, Ry);
  8979     __ bind(done);
  8980   %}
  8982   ins_pipe(pipe_cmplt);
  8983 %}
  8985 /* If I enable this, I encourage spilling in the inner loop of compress.
  8986 instruct cadd_cmpLTMask_mem(ncxRegI p, ncxRegI q, memory y, eCXRegI tmp, eFlagsReg cr) %{
  8987   match(Set p (AddI (AndI (CmpLTMask p q) (LoadI y)) (SubI p q)));
  8988 */
  8990 //----------Long Instructions------------------------------------------------
  8991 // Add Long Register with Register
  8992 instruct addL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  8993   match(Set dst (AddL dst src));
  8994   effect(KILL cr);
  8995   ins_cost(200);
  8996   format %{ "ADD    $dst.lo,$src.lo\n\t"
  8997             "ADC    $dst.hi,$src.hi" %}
  8998   opcode(0x03, 0x13);
  8999   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
  9000   ins_pipe( ialu_reg_reg_long );
  9001 %}
  9003 // Add Long Register with Immediate
  9004 instruct addL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9005   match(Set dst (AddL dst src));
  9006   effect(KILL cr);
  9007   format %{ "ADD    $dst.lo,$src.lo\n\t"
  9008             "ADC    $dst.hi,$src.hi" %}
  9009   opcode(0x81,0x00,0x02);  /* Opcode 81 /0, 81 /2 */
  9010   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9011   ins_pipe( ialu_reg_long );
  9012 %}
  9014 // Add Long Register with Memory
  9015 instruct addL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9016   match(Set dst (AddL dst (LoadL mem)));
  9017   effect(KILL cr);
  9018   ins_cost(125);
  9019   format %{ "ADD    $dst.lo,$mem\n\t"
  9020             "ADC    $dst.hi,$mem+4" %}
  9021   opcode(0x03, 0x13);
  9022   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9023   ins_pipe( ialu_reg_long_mem );
  9024 %}
  9026 // Subtract Long Register with Register.
  9027 instruct subL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9028   match(Set dst (SubL dst src));
  9029   effect(KILL cr);
  9030   ins_cost(200);
  9031   format %{ "SUB    $dst.lo,$src.lo\n\t"
  9032             "SBB    $dst.hi,$src.hi" %}
  9033   opcode(0x2B, 0x1B);
  9034   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
  9035   ins_pipe( ialu_reg_reg_long );
  9036 %}
  9038 // Subtract Long Register with Immediate
  9039 instruct subL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9040   match(Set dst (SubL dst src));
  9041   effect(KILL cr);
  9042   format %{ "SUB    $dst.lo,$src.lo\n\t"
  9043             "SBB    $dst.hi,$src.hi" %}
  9044   opcode(0x81,0x05,0x03);  /* Opcode 81 /5, 81 /3 */
  9045   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9046   ins_pipe( ialu_reg_long );
  9047 %}
  9049 // Subtract Long Register with Memory
  9050 instruct subL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9051   match(Set dst (SubL dst (LoadL mem)));
  9052   effect(KILL cr);
  9053   ins_cost(125);
  9054   format %{ "SUB    $dst.lo,$mem\n\t"
  9055             "SBB    $dst.hi,$mem+4" %}
  9056   opcode(0x2B, 0x1B);
  9057   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9058   ins_pipe( ialu_reg_long_mem );
  9059 %}
  9061 instruct negL_eReg(eRegL dst, immL0 zero, eFlagsReg cr) %{
  9062   match(Set dst (SubL zero dst));
  9063   effect(KILL cr);
  9064   ins_cost(300);
  9065   format %{ "NEG    $dst.hi\n\tNEG    $dst.lo\n\tSBB    $dst.hi,0" %}
  9066   ins_encode( neg_long(dst) );
  9067   ins_pipe( ialu_reg_reg_long );
  9068 %}
  9070 // And Long Register with Register
  9071 instruct andL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9072   match(Set dst (AndL dst src));
  9073   effect(KILL cr);
  9074   format %{ "AND    $dst.lo,$src.lo\n\t"
  9075             "AND    $dst.hi,$src.hi" %}
  9076   opcode(0x23,0x23);
  9077   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9078   ins_pipe( ialu_reg_reg_long );
  9079 %}
  9081 // And Long Register with Immediate
  9082 instruct andL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9083   match(Set dst (AndL dst src));
  9084   effect(KILL cr);
  9085   format %{ "AND    $dst.lo,$src.lo\n\t"
  9086             "AND    $dst.hi,$src.hi" %}
  9087   opcode(0x81,0x04,0x04);  /* Opcode 81 /4, 81 /4 */
  9088   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9089   ins_pipe( ialu_reg_long );
  9090 %}
  9092 // And Long Register with Memory
  9093 instruct andL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9094   match(Set dst (AndL dst (LoadL mem)));
  9095   effect(KILL cr);
  9096   ins_cost(125);
  9097   format %{ "AND    $dst.lo,$mem\n\t"
  9098             "AND    $dst.hi,$mem+4" %}
  9099   opcode(0x23, 0x23);
  9100   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9101   ins_pipe( ialu_reg_long_mem );
  9102 %}
  9104 // Or Long Register with Register
  9105 instruct orl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9106   match(Set dst (OrL dst src));
  9107   effect(KILL cr);
  9108   format %{ "OR     $dst.lo,$src.lo\n\t"
  9109             "OR     $dst.hi,$src.hi" %}
  9110   opcode(0x0B,0x0B);
  9111   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9112   ins_pipe( ialu_reg_reg_long );
  9113 %}
  9115 // Or Long Register with Immediate
  9116 instruct orl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9117   match(Set dst (OrL dst src));
  9118   effect(KILL cr);
  9119   format %{ "OR     $dst.lo,$src.lo\n\t"
  9120             "OR     $dst.hi,$src.hi" %}
  9121   opcode(0x81,0x01,0x01);  /* Opcode 81 /1, 81 /1 */
  9122   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9123   ins_pipe( ialu_reg_long );
  9124 %}
  9126 // Or Long Register with Memory
  9127 instruct orl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9128   match(Set dst (OrL dst (LoadL mem)));
  9129   effect(KILL cr);
  9130   ins_cost(125);
  9131   format %{ "OR     $dst.lo,$mem\n\t"
  9132             "OR     $dst.hi,$mem+4" %}
  9133   opcode(0x0B,0x0B);
  9134   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9135   ins_pipe( ialu_reg_long_mem );
  9136 %}
  9138 // Xor Long Register with Register
  9139 instruct xorl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9140   match(Set dst (XorL dst src));
  9141   effect(KILL cr);
  9142   format %{ "XOR    $dst.lo,$src.lo\n\t"
  9143             "XOR    $dst.hi,$src.hi" %}
  9144   opcode(0x33,0x33);
  9145   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9146   ins_pipe( ialu_reg_reg_long );
  9147 %}
  9149 // Xor Long Register with Immediate -1
  9150 instruct xorl_eReg_im1(eRegL dst, immL_M1 imm) %{
  9151   match(Set dst (XorL dst imm));  
  9152   format %{ "NOT    $dst.lo\n\t"
  9153             "NOT    $dst.hi" %}
  9154   ins_encode %{
  9155      __ notl($dst$$Register);
  9156      __ notl(HIGH_FROM_LOW($dst$$Register));
  9157   %}
  9158   ins_pipe( ialu_reg_long );
  9159 %}
  9161 // Xor Long Register with Immediate
  9162 instruct xorl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9163   match(Set dst (XorL dst src));
  9164   effect(KILL cr);
  9165   format %{ "XOR    $dst.lo,$src.lo\n\t"
  9166             "XOR    $dst.hi,$src.hi" %}
  9167   opcode(0x81,0x06,0x06);  /* Opcode 81 /6, 81 /6 */
  9168   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9169   ins_pipe( ialu_reg_long );
  9170 %}
  9172 // Xor Long Register with Memory
  9173 instruct xorl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9174   match(Set dst (XorL dst (LoadL mem)));
  9175   effect(KILL cr);
  9176   ins_cost(125);
  9177   format %{ "XOR    $dst.lo,$mem\n\t"
  9178             "XOR    $dst.hi,$mem+4" %}
  9179   opcode(0x33,0x33);
  9180   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9181   ins_pipe( ialu_reg_long_mem );
  9182 %}
  9184 // Shift Left Long by 1
  9185 instruct shlL_eReg_1(eRegL dst, immI_1 cnt, eFlagsReg cr) %{
  9186   predicate(UseNewLongLShift);
  9187   match(Set dst (LShiftL dst cnt));
  9188   effect(KILL cr);
  9189   ins_cost(100);
  9190   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9191             "ADC    $dst.hi,$dst.hi" %}
  9192   ins_encode %{
  9193     __ addl($dst$$Register,$dst$$Register);
  9194     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9195   %}
  9196   ins_pipe( ialu_reg_long );
  9197 %}
  9199 // Shift Left Long by 2
  9200 instruct shlL_eReg_2(eRegL dst, immI_2 cnt, eFlagsReg cr) %{
  9201   predicate(UseNewLongLShift);
  9202   match(Set dst (LShiftL dst cnt));
  9203   effect(KILL cr);
  9204   ins_cost(100);
  9205   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9206             "ADC    $dst.hi,$dst.hi\n\t" 
  9207             "ADD    $dst.lo,$dst.lo\n\t"
  9208             "ADC    $dst.hi,$dst.hi" %}
  9209   ins_encode %{
  9210     __ addl($dst$$Register,$dst$$Register);
  9211     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9212     __ addl($dst$$Register,$dst$$Register);
  9213     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9214   %}
  9215   ins_pipe( ialu_reg_long );
  9216 %}
  9218 // Shift Left Long by 3
  9219 instruct shlL_eReg_3(eRegL dst, immI_3 cnt, eFlagsReg cr) %{
  9220   predicate(UseNewLongLShift);
  9221   match(Set dst (LShiftL dst cnt));
  9222   effect(KILL cr);
  9223   ins_cost(100);
  9224   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9225             "ADC    $dst.hi,$dst.hi\n\t" 
  9226             "ADD    $dst.lo,$dst.lo\n\t"
  9227             "ADC    $dst.hi,$dst.hi\n\t" 
  9228             "ADD    $dst.lo,$dst.lo\n\t"
  9229             "ADC    $dst.hi,$dst.hi" %}
  9230   ins_encode %{
  9231     __ addl($dst$$Register,$dst$$Register);
  9232     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9233     __ addl($dst$$Register,$dst$$Register);
  9234     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9235     __ addl($dst$$Register,$dst$$Register);
  9236     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9237   %}
  9238   ins_pipe( ialu_reg_long );
  9239 %}
  9241 // Shift Left Long by 1-31
  9242 instruct shlL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9243   match(Set dst (LShiftL dst cnt));
  9244   effect(KILL cr);
  9245   ins_cost(200);
  9246   format %{ "SHLD   $dst.hi,$dst.lo,$cnt\n\t"
  9247             "SHL    $dst.lo,$cnt" %}
  9248   opcode(0xC1, 0x4, 0xA4);  /* 0F/A4, then C1 /4 ib */
  9249   ins_encode( move_long_small_shift(dst,cnt) );
  9250   ins_pipe( ialu_reg_long );
  9251 %}
  9253 // Shift Left Long by 32-63
  9254 instruct shlL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9255   match(Set dst (LShiftL dst cnt));
  9256   effect(KILL cr);
  9257   ins_cost(300);
  9258   format %{ "MOV    $dst.hi,$dst.lo\n"
  9259           "\tSHL    $dst.hi,$cnt-32\n"
  9260           "\tXOR    $dst.lo,$dst.lo" %}
  9261   opcode(0xC1, 0x4);  /* C1 /4 ib */
  9262   ins_encode( move_long_big_shift_clr(dst,cnt) );
  9263   ins_pipe( ialu_reg_long );
  9264 %}
  9266 // Shift Left Long by variable
  9267 instruct salL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9268   match(Set dst (LShiftL dst shift));
  9269   effect(KILL cr);
  9270   ins_cost(500+200);
  9271   size(17);
  9272   format %{ "TEST   $shift,32\n\t"
  9273             "JEQ,s  small\n\t"
  9274             "MOV    $dst.hi,$dst.lo\n\t"
  9275             "XOR    $dst.lo,$dst.lo\n"
  9276     "small:\tSHLD   $dst.hi,$dst.lo,$shift\n\t"
  9277             "SHL    $dst.lo,$shift" %}
  9278   ins_encode( shift_left_long( dst, shift ) );
  9279   ins_pipe( pipe_slow );
  9280 %}
  9282 // Shift Right Long by 1-31
  9283 instruct shrL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9284   match(Set dst (URShiftL dst cnt));
  9285   effect(KILL cr);
  9286   ins_cost(200);
  9287   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
  9288             "SHR    $dst.hi,$cnt" %}
  9289   opcode(0xC1, 0x5, 0xAC);  /* 0F/AC, then C1 /5 ib */
  9290   ins_encode( move_long_small_shift(dst,cnt) );
  9291   ins_pipe( ialu_reg_long );
  9292 %}
  9294 // Shift Right Long by 32-63
  9295 instruct shrL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9296   match(Set dst (URShiftL dst cnt));
  9297   effect(KILL cr);
  9298   ins_cost(300);
  9299   format %{ "MOV    $dst.lo,$dst.hi\n"
  9300           "\tSHR    $dst.lo,$cnt-32\n"
  9301           "\tXOR    $dst.hi,$dst.hi" %}
  9302   opcode(0xC1, 0x5);  /* C1 /5 ib */
  9303   ins_encode( move_long_big_shift_clr(dst,cnt) );
  9304   ins_pipe( ialu_reg_long );
  9305 %}
  9307 // Shift Right Long by variable
  9308 instruct shrL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9309   match(Set dst (URShiftL dst shift));
  9310   effect(KILL cr);
  9311   ins_cost(600);
  9312   size(17);
  9313   format %{ "TEST   $shift,32\n\t"
  9314             "JEQ,s  small\n\t"
  9315             "MOV    $dst.lo,$dst.hi\n\t"
  9316             "XOR    $dst.hi,$dst.hi\n"
  9317     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
  9318             "SHR    $dst.hi,$shift" %}
  9319   ins_encode( shift_right_long( dst, shift ) );
  9320   ins_pipe( pipe_slow );
  9321 %}
  9323 // Shift Right Long by 1-31
  9324 instruct sarL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9325   match(Set dst (RShiftL dst cnt));
  9326   effect(KILL cr);
  9327   ins_cost(200);
  9328   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
  9329             "SAR    $dst.hi,$cnt" %}
  9330   opcode(0xC1, 0x7, 0xAC);  /* 0F/AC, then C1 /7 ib */
  9331   ins_encode( move_long_small_shift(dst,cnt) );
  9332   ins_pipe( ialu_reg_long );
  9333 %}
  9335 // Shift Right Long by 32-63
  9336 instruct sarL_eReg_32_63( eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9337   match(Set dst (RShiftL dst cnt));
  9338   effect(KILL cr);
  9339   ins_cost(300);
  9340   format %{ "MOV    $dst.lo,$dst.hi\n"
  9341           "\tSAR    $dst.lo,$cnt-32\n"
  9342           "\tSAR    $dst.hi,31" %}
  9343   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9344   ins_encode( move_long_big_shift_sign(dst,cnt) );
  9345   ins_pipe( ialu_reg_long );
  9346 %}
  9348 // Shift Right arithmetic Long by variable
  9349 instruct sarL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9350   match(Set dst (RShiftL dst shift));
  9351   effect(KILL cr);
  9352   ins_cost(600);
  9353   size(18);
  9354   format %{ "TEST   $shift,32\n\t"
  9355             "JEQ,s  small\n\t"
  9356             "MOV    $dst.lo,$dst.hi\n\t"
  9357             "SAR    $dst.hi,31\n"
  9358     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
  9359             "SAR    $dst.hi,$shift" %}
  9360   ins_encode( shift_right_arith_long( dst, shift ) );
  9361   ins_pipe( pipe_slow );
  9362 %}
  9365 //----------Double Instructions------------------------------------------------
  9366 // Double Math
  9368 // Compare & branch
  9370 // P6 version of float compare, sets condition codes in EFLAGS
  9371 instruct cmpDPR_cc_P6(eFlagsRegU cr, regDPR src1, regDPR src2, eAXRegI rax) %{
  9372   predicate(VM_Version::supports_cmov() && UseSSE <=1);
  9373   match(Set cr (CmpD src1 src2));
  9374   effect(KILL rax);
  9375   ins_cost(150);
  9376   format %{ "FLD    $src1\n\t"
  9377             "FUCOMIP ST,$src2  // P6 instruction\n\t"
  9378             "JNP    exit\n\t"
  9379             "MOV    ah,1       // saw a NaN, set CF\n\t"
  9380             "SAHF\n"
  9381      "exit:\tNOP               // avoid branch to branch" %}
  9382   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
  9383   ins_encode( Push_Reg_DPR(src1),
  9384               OpcP, RegOpc(src2),
  9385               cmpF_P6_fixup );
  9386   ins_pipe( pipe_slow );
  9387 %}
  9389 instruct cmpDPR_cc_P6CF(eFlagsRegUCF cr, regDPR src1, regDPR src2) %{
  9390   predicate(VM_Version::supports_cmov() && UseSSE <=1);
  9391   match(Set cr (CmpD src1 src2));
  9392   ins_cost(150);
  9393   format %{ "FLD    $src1\n\t"
  9394             "FUCOMIP ST,$src2  // P6 instruction" %}
  9395   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
  9396   ins_encode( Push_Reg_DPR(src1),
  9397               OpcP, RegOpc(src2));
  9398   ins_pipe( pipe_slow );
  9399 %}
  9401 // Compare & branch
  9402 instruct cmpDPR_cc(eFlagsRegU cr, regDPR src1, regDPR src2, eAXRegI rax) %{
  9403   predicate(UseSSE<=1);
  9404   match(Set cr (CmpD src1 src2));
  9405   effect(KILL rax);
  9406   ins_cost(200);
  9407   format %{ "FLD    $src1\n\t"
  9408             "FCOMp  $src2\n\t"
  9409             "FNSTSW AX\n\t"
  9410             "TEST   AX,0x400\n\t"
  9411             "JZ,s   flags\n\t"
  9412             "MOV    AH,1\t# unordered treat as LT\n"
  9413     "flags:\tSAHF" %}
  9414   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
  9415   ins_encode( Push_Reg_DPR(src1),
  9416               OpcP, RegOpc(src2),
  9417               fpu_flags);
  9418   ins_pipe( pipe_slow );
  9419 %}
  9421 // Compare vs zero into -1,0,1
  9422 instruct cmpDPR_0(rRegI dst, regDPR src1, immDPR0 zero, eAXRegI rax, eFlagsReg cr) %{
  9423   predicate(UseSSE<=1);
  9424   match(Set dst (CmpD3 src1 zero));
  9425   effect(KILL cr, KILL rax);
  9426   ins_cost(280);
  9427   format %{ "FTSTD  $dst,$src1" %}
  9428   opcode(0xE4, 0xD9);
  9429   ins_encode( Push_Reg_DPR(src1),
  9430               OpcS, OpcP, PopFPU,
  9431               CmpF_Result(dst));
  9432   ins_pipe( pipe_slow );
  9433 %}
  9435 // Compare into -1,0,1
  9436 instruct cmpDPR_reg(rRegI dst, regDPR src1, regDPR src2, eAXRegI rax, eFlagsReg cr) %{
  9437   predicate(UseSSE<=1);
  9438   match(Set dst (CmpD3 src1 src2));
  9439   effect(KILL cr, KILL rax);
  9440   ins_cost(300);
  9441   format %{ "FCMPD  $dst,$src1,$src2" %}
  9442   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
  9443   ins_encode( Push_Reg_DPR(src1),
  9444               OpcP, RegOpc(src2),
  9445               CmpF_Result(dst));
  9446   ins_pipe( pipe_slow );
  9447 %}
  9449 // float compare and set condition codes in EFLAGS by XMM regs
  9450 instruct cmpD_cc(eFlagsRegU cr, regD src1, regD src2) %{
  9451   predicate(UseSSE>=2);
  9452   match(Set cr (CmpD src1 src2));
  9453   ins_cost(145);
  9454   format %{ "UCOMISD $src1,$src2\n\t"
  9455             "JNP,s   exit\n\t"
  9456             "PUSHF\t# saw NaN, set CF\n\t"
  9457             "AND     [rsp], #0xffffff2b\n\t"
  9458             "POPF\n"
  9459     "exit:" %}
  9460   ins_encode %{
  9461     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
  9462     emit_cmpfp_fixup(_masm);
  9463   %}
  9464   ins_pipe( pipe_slow );
  9465 %}
  9467 instruct cmpD_ccCF(eFlagsRegUCF cr, regD src1, regD src2) %{
  9468   predicate(UseSSE>=2);
  9469   match(Set cr (CmpD src1 src2));
  9470   ins_cost(100);
  9471   format %{ "UCOMISD $src1,$src2" %}
  9472   ins_encode %{
  9473     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
  9474   %}
  9475   ins_pipe( pipe_slow );
  9476 %}
  9478 // float compare and set condition codes in EFLAGS by XMM regs
  9479 instruct cmpD_ccmem(eFlagsRegU cr, regD src1, memory src2) %{
  9480   predicate(UseSSE>=2);
  9481   match(Set cr (CmpD src1 (LoadD src2)));
  9482   ins_cost(145);
  9483   format %{ "UCOMISD $src1,$src2\n\t"
  9484             "JNP,s   exit\n\t"
  9485             "PUSHF\t# saw NaN, set CF\n\t"
  9486             "AND     [rsp], #0xffffff2b\n\t"
  9487             "POPF\n"
  9488     "exit:" %}
  9489   ins_encode %{
  9490     __ ucomisd($src1$$XMMRegister, $src2$$Address);
  9491     emit_cmpfp_fixup(_masm);
  9492   %}
  9493   ins_pipe( pipe_slow );
  9494 %}
  9496 instruct cmpD_ccmemCF(eFlagsRegUCF cr, regD src1, memory src2) %{
  9497   predicate(UseSSE>=2);
  9498   match(Set cr (CmpD src1 (LoadD src2)));
  9499   ins_cost(100);
  9500   format %{ "UCOMISD $src1,$src2" %}
  9501   ins_encode %{
  9502     __ ucomisd($src1$$XMMRegister, $src2$$Address);
  9503   %}
  9504   ins_pipe( pipe_slow );
  9505 %}
  9507 // Compare into -1,0,1 in XMM
  9508 instruct cmpD_reg(xRegI dst, regD src1, regD src2, eFlagsReg cr) %{
  9509   predicate(UseSSE>=2);
  9510   match(Set dst (CmpD3 src1 src2));
  9511   effect(KILL cr);
  9512   ins_cost(255);
  9513   format %{ "UCOMISD $src1, $src2\n\t"
  9514             "MOV     $dst, #-1\n\t"
  9515             "JP,s    done\n\t"
  9516             "JB,s    done\n\t"
  9517             "SETNE   $dst\n\t"
  9518             "MOVZB   $dst, $dst\n"
  9519     "done:" %}
  9520   ins_encode %{
  9521     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
  9522     emit_cmpfp3(_masm, $dst$$Register);
  9523   %}
  9524   ins_pipe( pipe_slow );
  9525 %}
  9527 // Compare into -1,0,1 in XMM and memory
  9528 instruct cmpD_regmem(xRegI dst, regD src1, memory src2, eFlagsReg cr) %{
  9529   predicate(UseSSE>=2);
  9530   match(Set dst (CmpD3 src1 (LoadD src2)));
  9531   effect(KILL cr);
  9532   ins_cost(275);
  9533   format %{ "UCOMISD $src1, $src2\n\t"
  9534             "MOV     $dst, #-1\n\t"
  9535             "JP,s    done\n\t"
  9536             "JB,s    done\n\t"
  9537             "SETNE   $dst\n\t"
  9538             "MOVZB   $dst, $dst\n"
  9539     "done:" %}
  9540   ins_encode %{
  9541     __ ucomisd($src1$$XMMRegister, $src2$$Address);
  9542     emit_cmpfp3(_masm, $dst$$Register);
  9543   %}
  9544   ins_pipe( pipe_slow );
  9545 %}
  9548 instruct subDPR_reg(regDPR dst, regDPR src) %{
  9549   predicate (UseSSE <=1);
  9550   match(Set dst (SubD dst src));
  9552   format %{ "FLD    $src\n\t"
  9553             "DSUBp  $dst,ST" %}
  9554   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
  9555   ins_cost(150);
  9556   ins_encode( Push_Reg_DPR(src),
  9557               OpcP, RegOpc(dst) );
  9558   ins_pipe( fpu_reg_reg );
  9559 %}
  9561 instruct subDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
  9562   predicate (UseSSE <=1);
  9563   match(Set dst (RoundDouble (SubD src1 src2)));
  9564   ins_cost(250);
  9566   format %{ "FLD    $src2\n\t"
  9567             "DSUB   ST,$src1\n\t"
  9568             "FSTP_D $dst\t# D-round" %}
  9569   opcode(0xD8, 0x5);
  9570   ins_encode( Push_Reg_DPR(src2),
  9571               OpcP, RegOpc(src1), Pop_Mem_DPR(dst) );
  9572   ins_pipe( fpu_mem_reg_reg );
  9573 %}
  9576 instruct subDPR_reg_mem(regDPR dst, memory src) %{
  9577   predicate (UseSSE <=1);
  9578   match(Set dst (SubD dst (LoadD src)));
  9579   ins_cost(150);
  9581   format %{ "FLD    $src\n\t"
  9582             "DSUBp  $dst,ST" %}
  9583   opcode(0xDE, 0x5, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
  9584   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
  9585               OpcP, RegOpc(dst) );
  9586   ins_pipe( fpu_reg_mem );
  9587 %}
  9589 instruct absDPR_reg(regDPR1 dst, regDPR1 src) %{
  9590   predicate (UseSSE<=1);
  9591   match(Set dst (AbsD src));
  9592   ins_cost(100);
  9593   format %{ "FABS" %}
  9594   opcode(0xE1, 0xD9);
  9595   ins_encode( OpcS, OpcP );
  9596   ins_pipe( fpu_reg_reg );
  9597 %}
  9599 instruct negDPR_reg(regDPR1 dst, regDPR1 src) %{
  9600   predicate(UseSSE<=1);
  9601   match(Set dst (NegD src));
  9602   ins_cost(100);
  9603   format %{ "FCHS" %}
  9604   opcode(0xE0, 0xD9);
  9605   ins_encode( OpcS, OpcP );
  9606   ins_pipe( fpu_reg_reg );
  9607 %}
  9609 instruct addDPR_reg(regDPR dst, regDPR src) %{
  9610   predicate(UseSSE<=1);
  9611   match(Set dst (AddD dst src));
  9612   format %{ "FLD    $src\n\t"
  9613             "DADD   $dst,ST" %}
  9614   size(4);
  9615   ins_cost(150);
  9616   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
  9617   ins_encode( Push_Reg_DPR(src),
  9618               OpcP, RegOpc(dst) );
  9619   ins_pipe( fpu_reg_reg );
  9620 %}
  9623 instruct addDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
  9624   predicate(UseSSE<=1);
  9625   match(Set dst (RoundDouble (AddD src1 src2)));
  9626   ins_cost(250);
  9628   format %{ "FLD    $src2\n\t"
  9629             "DADD   ST,$src1\n\t"
  9630             "FSTP_D $dst\t# D-round" %}
  9631   opcode(0xD8, 0x0); /* D8 C0+i or D8 /0*/
  9632   ins_encode( Push_Reg_DPR(src2),
  9633               OpcP, RegOpc(src1), Pop_Mem_DPR(dst) );
  9634   ins_pipe( fpu_mem_reg_reg );
  9635 %}
  9638 instruct addDPR_reg_mem(regDPR dst, memory src) %{
  9639   predicate(UseSSE<=1);
  9640   match(Set dst (AddD dst (LoadD src)));
  9641   ins_cost(150);
  9643   format %{ "FLD    $src\n\t"
  9644             "DADDp  $dst,ST" %}
  9645   opcode(0xDE, 0x0, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
  9646   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
  9647               OpcP, RegOpc(dst) );
  9648   ins_pipe( fpu_reg_mem );
  9649 %}
  9651 // add-to-memory
  9652 instruct addDPR_mem_reg(memory dst, regDPR src) %{
  9653   predicate(UseSSE<=1);
  9654   match(Set dst (StoreD dst (RoundDouble (AddD (LoadD dst) src))));
  9655   ins_cost(150);
  9657   format %{ "FLD_D  $dst\n\t"
  9658             "DADD   ST,$src\n\t"
  9659             "FST_D  $dst" %}
  9660   opcode(0xDD, 0x0);
  9661   ins_encode( Opcode(0xDD), RMopc_Mem(0x00,dst),
  9662               Opcode(0xD8), RegOpc(src),
  9663               set_instruction_start,
  9664               Opcode(0xDD), RMopc_Mem(0x03,dst) );
  9665   ins_pipe( fpu_reg_mem );
  9666 %}
  9668 instruct addDPR_reg_imm1(regDPR dst, immDPR1 con) %{
  9669   predicate(UseSSE<=1);
  9670   match(Set dst (AddD dst con));
  9671   ins_cost(125);
  9672   format %{ "FLD1\n\t"
  9673             "DADDp  $dst,ST" %}
  9674   ins_encode %{
  9675     __ fld1();
  9676     __ faddp($dst$$reg);
  9677   %}
  9678   ins_pipe(fpu_reg);
  9679 %}
  9681 instruct addDPR_reg_imm(regDPR dst, immDPR con) %{
  9682   predicate(UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
  9683   match(Set dst (AddD dst con));
  9684   ins_cost(200);
  9685   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
  9686             "DADDp  $dst,ST" %}
  9687   ins_encode %{
  9688     __ fld_d($constantaddress($con));
  9689     __ faddp($dst$$reg);
  9690   %}
  9691   ins_pipe(fpu_reg_mem);
  9692 %}
  9694 instruct addDPR_reg_imm_round(stackSlotD dst, regDPR src, immDPR con) %{
  9695   predicate(UseSSE<=1 && _kids[0]->_kids[1]->_leaf->getd() != 0.0 && _kids[0]->_kids[1]->_leaf->getd() != 1.0 );
  9696   match(Set dst (RoundDouble (AddD src con)));
  9697   ins_cost(200);
  9698   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
  9699             "DADD   ST,$src\n\t"
  9700             "FSTP_D $dst\t# D-round" %}
  9701   ins_encode %{
  9702     __ fld_d($constantaddress($con));
  9703     __ fadd($src$$reg);
  9704     __ fstp_d(Address(rsp, $dst$$disp));
  9705   %}
  9706   ins_pipe(fpu_mem_reg_con);
  9707 %}
  9709 instruct mulDPR_reg(regDPR dst, regDPR src) %{
  9710   predicate(UseSSE<=1);
  9711   match(Set dst (MulD dst src));
  9712   format %{ "FLD    $src\n\t"
  9713             "DMULp  $dst,ST" %}
  9714   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
  9715   ins_cost(150);
  9716   ins_encode( Push_Reg_DPR(src),
  9717               OpcP, RegOpc(dst) );
  9718   ins_pipe( fpu_reg_reg );
  9719 %}
  9721 // Strict FP instruction biases argument before multiply then
  9722 // biases result to avoid double rounding of subnormals.
  9723 //
  9724 // scale arg1 by multiplying arg1 by 2^(-15360)
  9725 // load arg2
  9726 // multiply scaled arg1 by arg2
  9727 // rescale product by 2^(15360)
  9728 //
  9729 instruct strictfp_mulDPR_reg(regDPR1 dst, regnotDPR1 src) %{
  9730   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
  9731   match(Set dst (MulD dst src));
  9732   ins_cost(1);   // Select this instruction for all strict FP double multiplies
  9734   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
  9735             "DMULp  $dst,ST\n\t"
  9736             "FLD    $src\n\t"
  9737             "DMULp  $dst,ST\n\t"
  9738             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
  9739             "DMULp  $dst,ST\n\t" %}
  9740   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
  9741   ins_encode( strictfp_bias1(dst),
  9742               Push_Reg_DPR(src),
  9743               OpcP, RegOpc(dst),
  9744               strictfp_bias2(dst) );
  9745   ins_pipe( fpu_reg_reg );
  9746 %}
  9748 instruct mulDPR_reg_imm(regDPR dst, immDPR con) %{
  9749   predicate( UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
  9750   match(Set dst (MulD dst con));
  9751   ins_cost(200);
  9752   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
  9753             "DMULp  $dst,ST" %}
  9754   ins_encode %{
  9755     __ fld_d($constantaddress($con));
  9756     __ fmulp($dst$$reg);
  9757   %}
  9758   ins_pipe(fpu_reg_mem);
  9759 %}
  9762 instruct mulDPR_reg_mem(regDPR dst, memory src) %{
  9763   predicate( UseSSE<=1 );
  9764   match(Set dst (MulD dst (LoadD src)));
  9765   ins_cost(200);
  9766   format %{ "FLD_D  $src\n\t"
  9767             "DMULp  $dst,ST" %}
  9768   opcode(0xDE, 0x1, 0xDD); /* DE C8+i or DE /1*/  /* LoadD  DD /0 */
  9769   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
  9770               OpcP, RegOpc(dst) );
  9771   ins_pipe( fpu_reg_mem );
  9772 %}
  9774 //
  9775 // Cisc-alternate to reg-reg multiply
  9776 instruct mulDPR_reg_mem_cisc(regDPR dst, regDPR src, memory mem) %{
  9777   predicate( UseSSE<=1 );
  9778   match(Set dst (MulD src (LoadD mem)));
  9779   ins_cost(250);
  9780   format %{ "FLD_D  $mem\n\t"
  9781             "DMUL   ST,$src\n\t"
  9782             "FSTP_D $dst" %}
  9783   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadD D9 /0 */
  9784   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem),
  9785               OpcReg_FPR(src),
  9786               Pop_Reg_DPR(dst) );
  9787   ins_pipe( fpu_reg_reg_mem );
  9788 %}
  9791 // MACRO3 -- addDPR a mulDPR
  9792 // This instruction is a '2-address' instruction in that the result goes
  9793 // back to src2.  This eliminates a move from the macro; possibly the
  9794 // register allocator will have to add it back (and maybe not).
  9795 instruct addDPR_mulDPR_reg(regDPR src2, regDPR src1, regDPR src0) %{
  9796   predicate( UseSSE<=1 );
  9797   match(Set src2 (AddD (MulD src0 src1) src2));
  9798   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
  9799             "DMUL   ST,$src1\n\t"
  9800             "DADDp  $src2,ST" %}
  9801   ins_cost(250);
  9802   opcode(0xDD); /* LoadD DD /0 */
  9803   ins_encode( Push_Reg_FPR(src0),
  9804               FMul_ST_reg(src1),
  9805               FAddP_reg_ST(src2) );
  9806   ins_pipe( fpu_reg_reg_reg );
  9807 %}
  9810 // MACRO3 -- subDPR a mulDPR
  9811 instruct subDPR_mulDPR_reg(regDPR src2, regDPR src1, regDPR src0) %{
  9812   predicate( UseSSE<=1 );
  9813   match(Set src2 (SubD (MulD src0 src1) src2));
  9814   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
  9815             "DMUL   ST,$src1\n\t"
  9816             "DSUBRp $src2,ST" %}
  9817   ins_cost(250);
  9818   ins_encode( Push_Reg_FPR(src0),
  9819               FMul_ST_reg(src1),
  9820               Opcode(0xDE), Opc_plus(0xE0,src2));
  9821   ins_pipe( fpu_reg_reg_reg );
  9822 %}
  9825 instruct divDPR_reg(regDPR dst, regDPR src) %{
  9826   predicate( UseSSE<=1 );
  9827   match(Set dst (DivD dst src));
  9829   format %{ "FLD    $src\n\t"
  9830             "FDIVp  $dst,ST" %}
  9831   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
  9832   ins_cost(150);
  9833   ins_encode( Push_Reg_DPR(src),
  9834               OpcP, RegOpc(dst) );
  9835   ins_pipe( fpu_reg_reg );
  9836 %}
  9838 // Strict FP instruction biases argument before division then
  9839 // biases result, to avoid double rounding of subnormals.
  9840 //
  9841 // scale dividend by multiplying dividend by 2^(-15360)
  9842 // load divisor
  9843 // divide scaled dividend by divisor
  9844 // rescale quotient by 2^(15360)
  9845 //
  9846 instruct strictfp_divDPR_reg(regDPR1 dst, regnotDPR1 src) %{
  9847   predicate (UseSSE<=1);
  9848   match(Set dst (DivD dst src));
  9849   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
  9850   ins_cost(01);
  9852   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
  9853             "DMULp  $dst,ST\n\t"
  9854             "FLD    $src\n\t"
  9855             "FDIVp  $dst,ST\n\t"
  9856             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
  9857             "DMULp  $dst,ST\n\t" %}
  9858   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
  9859   ins_encode( strictfp_bias1(dst),
  9860               Push_Reg_DPR(src),
  9861               OpcP, RegOpc(dst),
  9862               strictfp_bias2(dst) );
  9863   ins_pipe( fpu_reg_reg );
  9864 %}
  9866 instruct divDPR_reg_round(stackSlotD dst, regDPR src1, regDPR src2) %{
  9867   predicate( UseSSE<=1 && !(Compile::current()->has_method() && Compile::current()->method()->is_strict()) );
  9868   match(Set dst (RoundDouble (DivD src1 src2)));
  9870   format %{ "FLD    $src1\n\t"
  9871             "FDIV   ST,$src2\n\t"
  9872             "FSTP_D $dst\t# D-round" %}
  9873   opcode(0xD8, 0x6); /* D8 F0+i or D8 /6 */
  9874   ins_encode( Push_Reg_DPR(src1),
  9875               OpcP, RegOpc(src2), Pop_Mem_DPR(dst) );
  9876   ins_pipe( fpu_mem_reg_reg );
  9877 %}
  9880 instruct modDPR_reg(regDPR dst, regDPR src, eAXRegI rax, eFlagsReg cr) %{
  9881   predicate(UseSSE<=1);
  9882   match(Set dst (ModD dst src));
  9883   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
  9885   format %{ "DMOD   $dst,$src" %}
  9886   ins_cost(250);
  9887   ins_encode(Push_Reg_Mod_DPR(dst, src),
  9888               emitModDPR(),
  9889               Push_Result_Mod_DPR(src),
  9890               Pop_Reg_DPR(dst));
  9891   ins_pipe( pipe_slow );
  9892 %}
  9894 instruct modD_reg(regD dst, regD src0, regD src1, eAXRegI rax, eFlagsReg cr) %{
  9895   predicate(UseSSE>=2);
  9896   match(Set dst (ModD src0 src1));
  9897   effect(KILL rax, KILL cr);
  9899   format %{ "SUB    ESP,8\t # DMOD\n"
  9900           "\tMOVSD  [ESP+0],$src1\n"
  9901           "\tFLD_D  [ESP+0]\n"
  9902           "\tMOVSD  [ESP+0],$src0\n"
  9903           "\tFLD_D  [ESP+0]\n"
  9904      "loop:\tFPREM\n"
  9905           "\tFWAIT\n"
  9906           "\tFNSTSW AX\n"
  9907           "\tSAHF\n"
  9908           "\tJP     loop\n"
  9909           "\tFSTP_D [ESP+0]\n"
  9910           "\tMOVSD  $dst,[ESP+0]\n"
  9911           "\tADD    ESP,8\n"
  9912           "\tFSTP   ST0\t # Restore FPU Stack"
  9913     %}
  9914   ins_cost(250);
  9915   ins_encode( Push_ModD_encoding(src0, src1), emitModDPR(), Push_ResultD(dst), PopFPU);
  9916   ins_pipe( pipe_slow );
  9917 %}
  9919 instruct sinDPR_reg(regDPR1 dst, regDPR1 src) %{
  9920   predicate (UseSSE<=1);
  9921   match(Set dst (SinD src));
  9922   ins_cost(1800);
  9923   format %{ "DSIN   $dst" %}
  9924   opcode(0xD9, 0xFE);
  9925   ins_encode( OpcP, OpcS );
  9926   ins_pipe( pipe_slow );
  9927 %}
  9929 instruct sinD_reg(regD dst, eFlagsReg cr) %{
  9930   predicate (UseSSE>=2);
  9931   match(Set dst (SinD dst));
  9932   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
  9933   ins_cost(1800);
  9934   format %{ "DSIN   $dst" %}
  9935   opcode(0xD9, 0xFE);
  9936   ins_encode( Push_SrcD(dst), OpcP, OpcS, Push_ResultD(dst) );
  9937   ins_pipe( pipe_slow );
  9938 %}
  9940 instruct cosDPR_reg(regDPR1 dst, regDPR1 src) %{
  9941   predicate (UseSSE<=1);
  9942   match(Set dst (CosD src));
  9943   ins_cost(1800);
  9944   format %{ "DCOS   $dst" %}
  9945   opcode(0xD9, 0xFF);
  9946   ins_encode( OpcP, OpcS );
  9947   ins_pipe( pipe_slow );
  9948 %}
  9950 instruct cosD_reg(regD dst, eFlagsReg cr) %{
  9951   predicate (UseSSE>=2);
  9952   match(Set dst (CosD dst));
  9953   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
  9954   ins_cost(1800);
  9955   format %{ "DCOS   $dst" %}
  9956   opcode(0xD9, 0xFF);
  9957   ins_encode( Push_SrcD(dst), OpcP, OpcS, Push_ResultD(dst) );
  9958   ins_pipe( pipe_slow );
  9959 %}
  9961 instruct tanDPR_reg(regDPR1 dst, regDPR1 src) %{
  9962   predicate (UseSSE<=1);
  9963   match(Set dst(TanD src));
  9964   format %{ "DTAN   $dst" %}
  9965   ins_encode( Opcode(0xD9), Opcode(0xF2),    // fptan
  9966               Opcode(0xDD), Opcode(0xD8));   // fstp st
  9967   ins_pipe( pipe_slow );
  9968 %}
  9970 instruct tanD_reg(regD dst, eFlagsReg cr) %{
  9971   predicate (UseSSE>=2);
  9972   match(Set dst(TanD dst));
  9973   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
  9974   format %{ "DTAN   $dst" %}
  9975   ins_encode( Push_SrcD(dst),
  9976               Opcode(0xD9), Opcode(0xF2),    // fptan
  9977               Opcode(0xDD), Opcode(0xD8),   // fstp st
  9978               Push_ResultD(dst) );
  9979   ins_pipe( pipe_slow );
  9980 %}
  9982 instruct atanDPR_reg(regDPR dst, regDPR src) %{
  9983   predicate (UseSSE<=1);
  9984   match(Set dst(AtanD dst src));
  9985   format %{ "DATA   $dst,$src" %}
  9986   opcode(0xD9, 0xF3);
  9987   ins_encode( Push_Reg_DPR(src),
  9988               OpcP, OpcS, RegOpc(dst) );
  9989   ins_pipe( pipe_slow );
  9990 %}
  9992 instruct atanD_reg(regD dst, regD src, eFlagsReg cr) %{
  9993   predicate (UseSSE>=2);
  9994   match(Set dst(AtanD dst src));
  9995   effect(KILL cr); // Push_{Src|Result}D() uses "{SUB|ADD} ESP,8"
  9996   format %{ "DATA   $dst,$src" %}
  9997   opcode(0xD9, 0xF3);
  9998   ins_encode( Push_SrcD(src),
  9999               OpcP, OpcS, Push_ResultD(dst) );
 10000   ins_pipe( pipe_slow );
 10001 %}
 10003 instruct sqrtDPR_reg(regDPR dst, regDPR src) %{
 10004   predicate (UseSSE<=1);
 10005   match(Set dst (SqrtD src));
 10006   format %{ "DSQRT  $dst,$src" %}
 10007   opcode(0xFA, 0xD9);
 10008   ins_encode( Push_Reg_DPR(src),
 10009               OpcS, OpcP, Pop_Reg_DPR(dst) );
 10010   ins_pipe( pipe_slow );
 10011 %}
 10013 instruct powDPR_reg(regDPR X, regDPR1 Y, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
 10014   predicate (UseSSE<=1);
 10015   match(Set Y (PowD X Y));  // Raise X to the Yth power
 10016   effect(KILL rax, KILL rdx, KILL rcx, KILL cr);
 10017   format %{ "fast_pow $X $Y -> $Y  // KILL $rax, $rcx, $rdx" %}
 10018   ins_encode %{
 10019     __ subptr(rsp, 8);
 10020     __ fld_s($X$$reg - 1);
 10021     __ fast_pow();
 10022     __ addptr(rsp, 8);
 10023   %}
 10024   ins_pipe( pipe_slow );
 10025 %}
 10027 instruct powD_reg(regD dst, regD src0, regD src1, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
 10028   predicate (UseSSE>=2);
 10029   match(Set dst (PowD src0 src1));  // Raise src0 to the src1'th power
 10030   effect(KILL rax, KILL rdx, KILL rcx, KILL cr);
 10031   format %{ "fast_pow $src0 $src1 -> $dst  // KILL $rax, $rcx, $rdx" %}
 10032   ins_encode %{
 10033     __ subptr(rsp, 8);
 10034     __ movdbl(Address(rsp, 0), $src1$$XMMRegister);
 10035     __ fld_d(Address(rsp, 0));
 10036     __ movdbl(Address(rsp, 0), $src0$$XMMRegister);
 10037     __ fld_d(Address(rsp, 0));
 10038     __ fast_pow();
 10039     __ fstp_d(Address(rsp, 0));
 10040     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
 10041     __ addptr(rsp, 8);
 10042   %}
 10043   ins_pipe( pipe_slow );
 10044 %}
 10047 instruct expDPR_reg(regDPR1 dpr1, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
 10048   predicate (UseSSE<=1);
 10049   match(Set dpr1 (ExpD dpr1));
 10050   effect(KILL rax, KILL rcx, KILL rdx, KILL cr);
 10051   format %{ "fast_exp $dpr1 -> $dpr1  // KILL $rax, $rcx, $rdx" %}
 10052   ins_encode %{
 10053     __ fast_exp();
 10054   %}
 10055   ins_pipe( pipe_slow );
 10056 %}
 10058 instruct expD_reg(regD dst, regD src, eAXRegI rax, eDXRegI rdx, eCXRegI rcx, eFlagsReg cr) %{
 10059   predicate (UseSSE>=2);
 10060   match(Set dst (ExpD src));
 10061   effect(KILL rax, KILL rcx, KILL rdx, KILL cr);
 10062   format %{ "fast_exp $dst -> $src  // KILL $rax, $rcx, $rdx" %}
 10063   ins_encode %{
 10064     __ subptr(rsp, 8);
 10065     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
 10066     __ fld_d(Address(rsp, 0));
 10067     __ fast_exp();
 10068     __ fstp_d(Address(rsp, 0));
 10069     __ movdbl($dst$$XMMRegister, Address(rsp, 0));
 10070     __ addptr(rsp, 8);
 10071   %}
 10072   ins_pipe( pipe_slow );
 10073 %}
 10075 instruct log10DPR_reg(regDPR1 dst, regDPR1 src) %{
 10076   predicate (UseSSE<=1);
 10077   // The source Double operand on FPU stack
 10078   match(Set dst (Log10D src));
 10079   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
 10080   // fxch         ; swap ST(0) with ST(1)
 10081   // fyl2x        ; compute log_10(2) * log_2(x)
 10082   format %{ "FLDLG2 \t\t\t#Log10\n\t"
 10083             "FXCH   \n\t"
 10084             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
 10085          %}
 10086   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
 10087               Opcode(0xD9), Opcode(0xC9),   // fxch
 10088               Opcode(0xD9), Opcode(0xF1));  // fyl2x
 10090   ins_pipe( pipe_slow );
 10091 %}
 10093 instruct log10D_reg(regD dst, regD src, eFlagsReg cr) %{
 10094   predicate (UseSSE>=2);
 10095   effect(KILL cr);
 10096   match(Set dst (Log10D src));
 10097   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
 10098   // fyl2x        ; compute log_10(2) * log_2(x)
 10099   format %{ "FLDLG2 \t\t\t#Log10\n\t"
 10100             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
 10101          %}
 10102   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
 10103               Push_SrcD(src),
 10104               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10105               Push_ResultD(dst));
 10107   ins_pipe( pipe_slow );
 10108 %}
 10110 instruct logDPR_reg(regDPR1 dst, regDPR1 src) %{
 10111   predicate (UseSSE<=1);
 10112   // The source Double operand on FPU stack
 10113   match(Set dst (LogD src));
 10114   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
 10115   // fxch         ; swap ST(0) with ST(1)
 10116   // fyl2x        ; compute log_e(2) * log_2(x)
 10117   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
 10118             "FXCH   \n\t"
 10119             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
 10120          %}
 10121   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
 10122               Opcode(0xD9), Opcode(0xC9),   // fxch
 10123               Opcode(0xD9), Opcode(0xF1));  // fyl2x
 10125   ins_pipe( pipe_slow );
 10126 %}
 10128 instruct logD_reg(regD dst, regD src, eFlagsReg cr) %{
 10129   predicate (UseSSE>=2);
 10130   effect(KILL cr);
 10131   // The source and result Double operands in XMM registers
 10132   match(Set dst (LogD src));
 10133   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
 10134   // fyl2x        ; compute log_e(2) * log_2(x)
 10135   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
 10136             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
 10137          %}
 10138   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
 10139               Push_SrcD(src),
 10140               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10141               Push_ResultD(dst));
 10142   ins_pipe( pipe_slow );
 10143 %}
 10145 //-------------Float Instructions-------------------------------
 10146 // Float Math
 10148 // Code for float compare:
 10149 //     fcompp();
 10150 //     fwait(); fnstsw_ax();
 10151 //     sahf();
 10152 //     movl(dst, unordered_result);
 10153 //     jcc(Assembler::parity, exit);
 10154 //     movl(dst, less_result);
 10155 //     jcc(Assembler::below, exit);
 10156 //     movl(dst, equal_result);
 10157 //     jcc(Assembler::equal, exit);
 10158 //     movl(dst, greater_result);
 10159 //   exit:
 10161 // P6 version of float compare, sets condition codes in EFLAGS
 10162 instruct cmpFPR_cc_P6(eFlagsRegU cr, regFPR src1, regFPR src2, eAXRegI rax) %{
 10163   predicate(VM_Version::supports_cmov() && UseSSE == 0);
 10164   match(Set cr (CmpF src1 src2));
 10165   effect(KILL rax);
 10166   ins_cost(150);
 10167   format %{ "FLD    $src1\n\t"
 10168             "FUCOMIP ST,$src2  // P6 instruction\n\t"
 10169             "JNP    exit\n\t"
 10170             "MOV    ah,1       // saw a NaN, set CF (treat as LT)\n\t"
 10171             "SAHF\n"
 10172      "exit:\tNOP               // avoid branch to branch" %}
 10173   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
 10174   ins_encode( Push_Reg_DPR(src1),
 10175               OpcP, RegOpc(src2),
 10176               cmpF_P6_fixup );
 10177   ins_pipe( pipe_slow );
 10178 %}
 10180 instruct cmpFPR_cc_P6CF(eFlagsRegUCF cr, regFPR src1, regFPR src2) %{
 10181   predicate(VM_Version::supports_cmov() && UseSSE == 0);
 10182   match(Set cr (CmpF src1 src2));
 10183   ins_cost(100);
 10184   format %{ "FLD    $src1\n\t"
 10185             "FUCOMIP ST,$src2  // P6 instruction" %}
 10186   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
 10187   ins_encode( Push_Reg_DPR(src1),
 10188               OpcP, RegOpc(src2));
 10189   ins_pipe( pipe_slow );
 10190 %}
 10193 // Compare & branch
 10194 instruct cmpFPR_cc(eFlagsRegU cr, regFPR src1, regFPR src2, eAXRegI rax) %{
 10195   predicate(UseSSE == 0);
 10196   match(Set cr (CmpF src1 src2));
 10197   effect(KILL rax);
 10198   ins_cost(200);
 10199   format %{ "FLD    $src1\n\t"
 10200             "FCOMp  $src2\n\t"
 10201             "FNSTSW AX\n\t"
 10202             "TEST   AX,0x400\n\t"
 10203             "JZ,s   flags\n\t"
 10204             "MOV    AH,1\t# unordered treat as LT\n"
 10205     "flags:\tSAHF" %}
 10206   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 10207   ins_encode( Push_Reg_DPR(src1),
 10208               OpcP, RegOpc(src2),
 10209               fpu_flags);
 10210   ins_pipe( pipe_slow );
 10211 %}
 10213 // Compare vs zero into -1,0,1
 10214 instruct cmpFPR_0(rRegI dst, regFPR src1, immFPR0 zero, eAXRegI rax, eFlagsReg cr) %{
 10215   predicate(UseSSE == 0);
 10216   match(Set dst (CmpF3 src1 zero));
 10217   effect(KILL cr, KILL rax);
 10218   ins_cost(280);
 10219   format %{ "FTSTF  $dst,$src1" %}
 10220   opcode(0xE4, 0xD9);
 10221   ins_encode( Push_Reg_DPR(src1),
 10222               OpcS, OpcP, PopFPU,
 10223               CmpF_Result(dst));
 10224   ins_pipe( pipe_slow );
 10225 %}
 10227 // Compare into -1,0,1
 10228 instruct cmpFPR_reg(rRegI dst, regFPR src1, regFPR src2, eAXRegI rax, eFlagsReg cr) %{
 10229   predicate(UseSSE == 0);
 10230   match(Set dst (CmpF3 src1 src2));
 10231   effect(KILL cr, KILL rax);
 10232   ins_cost(300);
 10233   format %{ "FCMPF  $dst,$src1,$src2" %}
 10234   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 10235   ins_encode( Push_Reg_DPR(src1),
 10236               OpcP, RegOpc(src2),
 10237               CmpF_Result(dst));
 10238   ins_pipe( pipe_slow );
 10239 %}
 10241 // float compare and set condition codes in EFLAGS by XMM regs
 10242 instruct cmpF_cc(eFlagsRegU cr, regF src1, regF src2) %{
 10243   predicate(UseSSE>=1);
 10244   match(Set cr (CmpF src1 src2));
 10245   ins_cost(145);
 10246   format %{ "UCOMISS $src1,$src2\n\t"
 10247             "JNP,s   exit\n\t"
 10248             "PUSHF\t# saw NaN, set CF\n\t"
 10249             "AND     [rsp], #0xffffff2b\n\t"
 10250             "POPF\n"
 10251     "exit:" %}
 10252   ins_encode %{
 10253     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
 10254     emit_cmpfp_fixup(_masm);
 10255   %}
 10256   ins_pipe( pipe_slow );
 10257 %}
 10259 instruct cmpF_ccCF(eFlagsRegUCF cr, regF src1, regF src2) %{
 10260   predicate(UseSSE>=1);
 10261   match(Set cr (CmpF src1 src2));
 10262   ins_cost(100);
 10263   format %{ "UCOMISS $src1,$src2" %}
 10264   ins_encode %{
 10265     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
 10266   %}
 10267   ins_pipe( pipe_slow );
 10268 %}
 10270 // float compare and set condition codes in EFLAGS by XMM regs
 10271 instruct cmpF_ccmem(eFlagsRegU cr, regF src1, memory src2) %{
 10272   predicate(UseSSE>=1);
 10273   match(Set cr (CmpF src1 (LoadF src2)));
 10274   ins_cost(165);
 10275   format %{ "UCOMISS $src1,$src2\n\t"
 10276             "JNP,s   exit\n\t"
 10277             "PUSHF\t# saw NaN, set CF\n\t"
 10278             "AND     [rsp], #0xffffff2b\n\t"
 10279             "POPF\n"
 10280     "exit:" %}
 10281   ins_encode %{
 10282     __ ucomiss($src1$$XMMRegister, $src2$$Address);
 10283     emit_cmpfp_fixup(_masm);
 10284   %}
 10285   ins_pipe( pipe_slow );
 10286 %}
 10288 instruct cmpF_ccmemCF(eFlagsRegUCF cr, regF src1, memory src2) %{
 10289   predicate(UseSSE>=1);
 10290   match(Set cr (CmpF src1 (LoadF src2)));
 10291   ins_cost(100);
 10292   format %{ "UCOMISS $src1,$src2" %}
 10293   ins_encode %{
 10294     __ ucomiss($src1$$XMMRegister, $src2$$Address);
 10295   %}
 10296   ins_pipe( pipe_slow );
 10297 %}
 10299 // Compare into -1,0,1 in XMM
 10300 instruct cmpF_reg(xRegI dst, regF src1, regF src2, eFlagsReg cr) %{
 10301   predicate(UseSSE>=1);
 10302   match(Set dst (CmpF3 src1 src2));
 10303   effect(KILL cr);
 10304   ins_cost(255);
 10305   format %{ "UCOMISS $src1, $src2\n\t"
 10306             "MOV     $dst, #-1\n\t"
 10307             "JP,s    done\n\t"
 10308             "JB,s    done\n\t"
 10309             "SETNE   $dst\n\t"
 10310             "MOVZB   $dst, $dst\n"
 10311     "done:" %}
 10312   ins_encode %{
 10313     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
 10314     emit_cmpfp3(_masm, $dst$$Register);
 10315   %}
 10316   ins_pipe( pipe_slow );
 10317 %}
 10319 // Compare into -1,0,1 in XMM and memory
 10320 instruct cmpF_regmem(xRegI dst, regF src1, memory src2, eFlagsReg cr) %{
 10321   predicate(UseSSE>=1);
 10322   match(Set dst (CmpF3 src1 (LoadF src2)));
 10323   effect(KILL cr);
 10324   ins_cost(275);
 10325   format %{ "UCOMISS $src1, $src2\n\t"
 10326             "MOV     $dst, #-1\n\t"
 10327             "JP,s    done\n\t"
 10328             "JB,s    done\n\t"
 10329             "SETNE   $dst\n\t"
 10330             "MOVZB   $dst, $dst\n"
 10331     "done:" %}
 10332   ins_encode %{
 10333     __ ucomiss($src1$$XMMRegister, $src2$$Address);
 10334     emit_cmpfp3(_masm, $dst$$Register);
 10335   %}
 10336   ins_pipe( pipe_slow );
 10337 %}
 10339 // Spill to obtain 24-bit precision
 10340 instruct subFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
 10341   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10342   match(Set dst (SubF src1 src2));
 10344   format %{ "FSUB   $dst,$src1 - $src2" %}
 10345   opcode(0xD8, 0x4); /* D8 E0+i or D8 /4 mod==0x3 ;; result in TOS */
 10346   ins_encode( Push_Reg_FPR(src1),
 10347               OpcReg_FPR(src2),
 10348               Pop_Mem_FPR(dst) );
 10349   ins_pipe( fpu_mem_reg_reg );
 10350 %}
 10351 //
 10352 // This instruction does not round to 24-bits
 10353 instruct subFPR_reg(regFPR dst, regFPR src) %{
 10354   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10355   match(Set dst (SubF dst src));
 10357   format %{ "FSUB   $dst,$src" %}
 10358   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
 10359   ins_encode( Push_Reg_FPR(src),
 10360               OpcP, RegOpc(dst) );
 10361   ins_pipe( fpu_reg_reg );
 10362 %}
 10364 // Spill to obtain 24-bit precision
 10365 instruct addFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
 10366   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10367   match(Set dst (AddF src1 src2));
 10369   format %{ "FADD   $dst,$src1,$src2" %}
 10370   opcode(0xD8, 0x0); /* D8 C0+i */
 10371   ins_encode( Push_Reg_FPR(src2),
 10372               OpcReg_FPR(src1),
 10373               Pop_Mem_FPR(dst) );
 10374   ins_pipe( fpu_mem_reg_reg );
 10375 %}
 10376 //
 10377 // This instruction does not round to 24-bits
 10378 instruct addFPR_reg(regFPR dst, regFPR src) %{
 10379   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10380   match(Set dst (AddF dst src));
 10382   format %{ "FLD    $src\n\t"
 10383             "FADDp  $dst,ST" %}
 10384   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
 10385   ins_encode( Push_Reg_FPR(src),
 10386               OpcP, RegOpc(dst) );
 10387   ins_pipe( fpu_reg_reg );
 10388 %}
 10390 instruct absFPR_reg(regFPR1 dst, regFPR1 src) %{
 10391   predicate(UseSSE==0);
 10392   match(Set dst (AbsF src));
 10393   ins_cost(100);
 10394   format %{ "FABS" %}
 10395   opcode(0xE1, 0xD9);
 10396   ins_encode( OpcS, OpcP );
 10397   ins_pipe( fpu_reg_reg );
 10398 %}
 10400 instruct negFPR_reg(regFPR1 dst, regFPR1 src) %{
 10401   predicate(UseSSE==0);
 10402   match(Set dst (NegF src));
 10403   ins_cost(100);
 10404   format %{ "FCHS" %}
 10405   opcode(0xE0, 0xD9);
 10406   ins_encode( OpcS, OpcP );
 10407   ins_pipe( fpu_reg_reg );
 10408 %}
 10410 // Cisc-alternate to addFPR_reg
 10411 // Spill to obtain 24-bit precision
 10412 instruct addFPR24_reg_mem(stackSlotF dst, regFPR src1, memory src2) %{
 10413   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10414   match(Set dst (AddF src1 (LoadF src2)));
 10416   format %{ "FLD    $src2\n\t"
 10417             "FADD   ST,$src1\n\t"
 10418             "FSTP_S $dst" %}
 10419   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 10420   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10421               OpcReg_FPR(src1),
 10422               Pop_Mem_FPR(dst) );
 10423   ins_pipe( fpu_mem_reg_mem );
 10424 %}
 10425 //
 10426 // Cisc-alternate to addFPR_reg
 10427 // This instruction does not round to 24-bits
 10428 instruct addFPR_reg_mem(regFPR dst, memory src) %{
 10429   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10430   match(Set dst (AddF dst (LoadF src)));
 10432   format %{ "FADD   $dst,$src" %}
 10433   opcode(0xDE, 0x0, 0xD9); /* DE C0+i or DE /0*/  /* LoadF  D9 /0 */
 10434   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
 10435               OpcP, RegOpc(dst) );
 10436   ins_pipe( fpu_reg_mem );
 10437 %}
 10439 // // Following two instructions for _222_mpegaudio
 10440 // Spill to obtain 24-bit precision
 10441 instruct addFPR24_mem_reg(stackSlotF dst, regFPR src2, memory src1 ) %{
 10442   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10443   match(Set dst (AddF src1 src2));
 10445   format %{ "FADD   $dst,$src1,$src2" %}
 10446   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 10447   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src1),
 10448               OpcReg_FPR(src2),
 10449               Pop_Mem_FPR(dst) );
 10450   ins_pipe( fpu_mem_reg_mem );
 10451 %}
 10453 // Cisc-spill variant
 10454 // Spill to obtain 24-bit precision
 10455 instruct addFPR24_mem_cisc(stackSlotF dst, memory src1, memory src2) %{
 10456   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10457   match(Set dst (AddF src1 (LoadF src2)));
 10459   format %{ "FADD   $dst,$src1,$src2 cisc" %}
 10460   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 10461   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10462               set_instruction_start,
 10463               OpcP, RMopc_Mem(secondary,src1),
 10464               Pop_Mem_FPR(dst) );
 10465   ins_pipe( fpu_mem_mem_mem );
 10466 %}
 10468 // Spill to obtain 24-bit precision
 10469 instruct addFPR24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
 10470   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10471   match(Set dst (AddF src1 src2));
 10473   format %{ "FADD   $dst,$src1,$src2" %}
 10474   opcode(0xD8, 0x0, 0xD9); /* D8 /0 */  /* LoadF  D9 /0 */
 10475   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10476               set_instruction_start,
 10477               OpcP, RMopc_Mem(secondary,src1),
 10478               Pop_Mem_FPR(dst) );
 10479   ins_pipe( fpu_mem_mem_mem );
 10480 %}
 10483 // Spill to obtain 24-bit precision
 10484 instruct addFPR24_reg_imm(stackSlotF dst, regFPR src, immFPR con) %{
 10485   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10486   match(Set dst (AddF src con));
 10487   format %{ "FLD    $src\n\t"
 10488             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 10489             "FSTP_S $dst"  %}
 10490   ins_encode %{
 10491     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 10492     __ fadd_s($constantaddress($con));
 10493     __ fstp_s(Address(rsp, $dst$$disp));
 10494   %}
 10495   ins_pipe(fpu_mem_reg_con);
 10496 %}
 10497 //
 10498 // This instruction does not round to 24-bits
 10499 instruct addFPR_reg_imm(regFPR dst, regFPR src, immFPR con) %{
 10500   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10501   match(Set dst (AddF src con));
 10502   format %{ "FLD    $src\n\t"
 10503             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 10504             "FSTP   $dst"  %}
 10505   ins_encode %{
 10506     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 10507     __ fadd_s($constantaddress($con));
 10508     __ fstp_d($dst$$reg);
 10509   %}
 10510   ins_pipe(fpu_reg_reg_con);
 10511 %}
 10513 // Spill to obtain 24-bit precision
 10514 instruct mulFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
 10515   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10516   match(Set dst (MulF src1 src2));
 10518   format %{ "FLD    $src1\n\t"
 10519             "FMUL   $src2\n\t"
 10520             "FSTP_S $dst"  %}
 10521   opcode(0xD8, 0x1); /* D8 C8+i or D8 /1 ;; result in TOS */
 10522   ins_encode( Push_Reg_FPR(src1),
 10523               OpcReg_FPR(src2),
 10524               Pop_Mem_FPR(dst) );
 10525   ins_pipe( fpu_mem_reg_reg );
 10526 %}
 10527 //
 10528 // This instruction does not round to 24-bits
 10529 instruct mulFPR_reg(regFPR dst, regFPR src1, regFPR src2) %{
 10530   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10531   match(Set dst (MulF src1 src2));
 10533   format %{ "FLD    $src1\n\t"
 10534             "FMUL   $src2\n\t"
 10535             "FSTP_S $dst"  %}
 10536   opcode(0xD8, 0x1); /* D8 C8+i */
 10537   ins_encode( Push_Reg_FPR(src2),
 10538               OpcReg_FPR(src1),
 10539               Pop_Reg_FPR(dst) );
 10540   ins_pipe( fpu_reg_reg_reg );
 10541 %}
 10544 // Spill to obtain 24-bit precision
 10545 // Cisc-alternate to reg-reg multiply
 10546 instruct mulFPR24_reg_mem(stackSlotF dst, regFPR src1, memory src2) %{
 10547   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10548   match(Set dst (MulF src1 (LoadF src2)));
 10550   format %{ "FLD_S  $src2\n\t"
 10551             "FMUL   $src1\n\t"
 10552             "FSTP_S $dst"  %}
 10553   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or DE /1*/  /* LoadF D9 /0 */
 10554   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10555               OpcReg_FPR(src1),
 10556               Pop_Mem_FPR(dst) );
 10557   ins_pipe( fpu_mem_reg_mem );
 10558 %}
 10559 //
 10560 // This instruction does not round to 24-bits
 10561 // Cisc-alternate to reg-reg multiply
 10562 instruct mulFPR_reg_mem(regFPR dst, regFPR src1, memory src2) %{
 10563   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10564   match(Set dst (MulF src1 (LoadF src2)));
 10566   format %{ "FMUL   $dst,$src1,$src2" %}
 10567   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadF D9 /0 */
 10568   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10569               OpcReg_FPR(src1),
 10570               Pop_Reg_FPR(dst) );
 10571   ins_pipe( fpu_reg_reg_mem );
 10572 %}
 10574 // Spill to obtain 24-bit precision
 10575 instruct mulFPR24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
 10576   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10577   match(Set dst (MulF src1 src2));
 10579   format %{ "FMUL   $dst,$src1,$src2" %}
 10580   opcode(0xD8, 0x1, 0xD9); /* D8 /1 */  /* LoadF D9 /0 */
 10581   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 10582               set_instruction_start,
 10583               OpcP, RMopc_Mem(secondary,src1),
 10584               Pop_Mem_FPR(dst) );
 10585   ins_pipe( fpu_mem_mem_mem );
 10586 %}
 10588 // Spill to obtain 24-bit precision
 10589 instruct mulFPR24_reg_imm(stackSlotF dst, regFPR src, immFPR con) %{
 10590   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10591   match(Set dst (MulF src con));
 10593   format %{ "FLD    $src\n\t"
 10594             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 10595             "FSTP_S $dst"  %}
 10596   ins_encode %{
 10597     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 10598     __ fmul_s($constantaddress($con));
 10599     __ fstp_s(Address(rsp, $dst$$disp));
 10600   %}
 10601   ins_pipe(fpu_mem_reg_con);
 10602 %}
 10603 //
 10604 // This instruction does not round to 24-bits
 10605 instruct mulFPR_reg_imm(regFPR dst, regFPR src, immFPR con) %{
 10606   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10607   match(Set dst (MulF src con));
 10609   format %{ "FLD    $src\n\t"
 10610             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 10611             "FSTP   $dst"  %}
 10612   ins_encode %{
 10613     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 10614     __ fmul_s($constantaddress($con));
 10615     __ fstp_d($dst$$reg);
 10616   %}
 10617   ins_pipe(fpu_reg_reg_con);
 10618 %}
 10621 //
 10622 // MACRO1 -- subsume unshared load into mulFPR
 10623 // This instruction does not round to 24-bits
 10624 instruct mulFPR_reg_load1(regFPR dst, regFPR src, memory mem1 ) %{
 10625   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10626   match(Set dst (MulF (LoadF mem1) src));
 10628   format %{ "FLD    $mem1    ===MACRO1===\n\t"
 10629             "FMUL   ST,$src\n\t"
 10630             "FSTP   $dst" %}
 10631   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or D8 /1 */  /* LoadF D9 /0 */
 10632   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem1),
 10633               OpcReg_FPR(src),
 10634               Pop_Reg_FPR(dst) );
 10635   ins_pipe( fpu_reg_reg_mem );
 10636 %}
 10637 //
 10638 // MACRO2 -- addFPR a mulFPR which subsumed an unshared load
 10639 // This instruction does not round to 24-bits
 10640 instruct addFPR_mulFPR_reg_load1(regFPR dst, memory mem1, regFPR src1, regFPR src2) %{
 10641   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10642   match(Set dst (AddF (MulF (LoadF mem1) src1) src2));
 10643   ins_cost(95);
 10645   format %{ "FLD    $mem1     ===MACRO2===\n\t"
 10646             "FMUL   ST,$src1  subsume mulFPR left load\n\t"
 10647             "FADD   ST,$src2\n\t"
 10648             "FSTP   $dst" %}
 10649   opcode(0xD9); /* LoadF D9 /0 */
 10650   ins_encode( OpcP, RMopc_Mem(0x00,mem1),
 10651               FMul_ST_reg(src1),
 10652               FAdd_ST_reg(src2),
 10653               Pop_Reg_FPR(dst) );
 10654   ins_pipe( fpu_reg_mem_reg_reg );
 10655 %}
 10657 // MACRO3 -- addFPR a mulFPR
 10658 // This instruction does not round to 24-bits.  It is a '2-address'
 10659 // instruction in that the result goes back to src2.  This eliminates
 10660 // a move from the macro; possibly the register allocator will have
 10661 // to add it back (and maybe not).
 10662 instruct addFPR_mulFPR_reg(regFPR src2, regFPR src1, regFPR src0) %{
 10663   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10664   match(Set src2 (AddF (MulF src0 src1) src2));
 10666   format %{ "FLD    $src0     ===MACRO3===\n\t"
 10667             "FMUL   ST,$src1\n\t"
 10668             "FADDP  $src2,ST" %}
 10669   opcode(0xD9); /* LoadF D9 /0 */
 10670   ins_encode( Push_Reg_FPR(src0),
 10671               FMul_ST_reg(src1),
 10672               FAddP_reg_ST(src2) );
 10673   ins_pipe( fpu_reg_reg_reg );
 10674 %}
 10676 // MACRO4 -- divFPR subFPR
 10677 // This instruction does not round to 24-bits
 10678 instruct subFPR_divFPR_reg(regFPR dst, regFPR src1, regFPR src2, regFPR src3) %{
 10679   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10680   match(Set dst (DivF (SubF src2 src1) src3));
 10682   format %{ "FLD    $src2   ===MACRO4===\n\t"
 10683             "FSUB   ST,$src1\n\t"
 10684             "FDIV   ST,$src3\n\t"
 10685             "FSTP  $dst" %}
 10686   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 10687   ins_encode( Push_Reg_FPR(src2),
 10688               subFPR_divFPR_encode(src1,src3),
 10689               Pop_Reg_FPR(dst) );
 10690   ins_pipe( fpu_reg_reg_reg_reg );
 10691 %}
 10693 // Spill to obtain 24-bit precision
 10694 instruct divFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2) %{
 10695   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 10696   match(Set dst (DivF src1 src2));
 10698   format %{ "FDIV   $dst,$src1,$src2" %}
 10699   opcode(0xD8, 0x6); /* D8 F0+i or DE /6*/
 10700   ins_encode( Push_Reg_FPR(src1),
 10701               OpcReg_FPR(src2),
 10702               Pop_Mem_FPR(dst) );
 10703   ins_pipe( fpu_mem_reg_reg );
 10704 %}
 10705 //
 10706 // This instruction does not round to 24-bits
 10707 instruct divFPR_reg(regFPR dst, regFPR src) %{
 10708   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10709   match(Set dst (DivF dst src));
 10711   format %{ "FDIV   $dst,$src" %}
 10712   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 10713   ins_encode( Push_Reg_FPR(src),
 10714               OpcP, RegOpc(dst) );
 10715   ins_pipe( fpu_reg_reg );
 10716 %}
 10719 // Spill to obtain 24-bit precision
 10720 instruct modFPR24_reg(stackSlotF dst, regFPR src1, regFPR src2, eAXRegI rax, eFlagsReg cr) %{
 10721   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 10722   match(Set dst (ModF src1 src2));
 10723   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
 10725   format %{ "FMOD   $dst,$src1,$src2" %}
 10726   ins_encode( Push_Reg_Mod_DPR(src1, src2),
 10727               emitModDPR(),
 10728               Push_Result_Mod_DPR(src2),
 10729               Pop_Mem_FPR(dst));
 10730   ins_pipe( pipe_slow );
 10731 %}
 10732 //
 10733 // This instruction does not round to 24-bits
 10734 instruct modFPR_reg(regFPR dst, regFPR src, eAXRegI rax, eFlagsReg cr) %{
 10735   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 10736   match(Set dst (ModF dst src));
 10737   effect(KILL rax, KILL cr); // emitModDPR() uses EAX and EFLAGS
 10739   format %{ "FMOD   $dst,$src" %}
 10740   ins_encode(Push_Reg_Mod_DPR(dst, src),
 10741               emitModDPR(),
 10742               Push_Result_Mod_DPR(src),
 10743               Pop_Reg_FPR(dst));
 10744   ins_pipe( pipe_slow );
 10745 %}
 10747 instruct modF_reg(regF dst, regF src0, regF src1, eAXRegI rax, eFlagsReg cr) %{
 10748   predicate(UseSSE>=1);
 10749   match(Set dst (ModF src0 src1));
 10750   effect(KILL rax, KILL cr);
 10751   format %{ "SUB    ESP,4\t # FMOD\n"
 10752           "\tMOVSS  [ESP+0],$src1\n"
 10753           "\tFLD_S  [ESP+0]\n"
 10754           "\tMOVSS  [ESP+0],$src0\n"
 10755           "\tFLD_S  [ESP+0]\n"
 10756      "loop:\tFPREM\n"
 10757           "\tFWAIT\n"
 10758           "\tFNSTSW AX\n"
 10759           "\tSAHF\n"
 10760           "\tJP     loop\n"
 10761           "\tFSTP_S [ESP+0]\n"
 10762           "\tMOVSS  $dst,[ESP+0]\n"
 10763           "\tADD    ESP,4\n"
 10764           "\tFSTP   ST0\t # Restore FPU Stack"
 10765     %}
 10766   ins_cost(250);
 10767   ins_encode( Push_ModF_encoding(src0, src1), emitModDPR(), Push_ResultF(dst,0x4), PopFPU);
 10768   ins_pipe( pipe_slow );
 10769 %}
 10772 //----------Arithmetic Conversion Instructions---------------------------------
 10773 // The conversions operations are all Alpha sorted.  Please keep it that way!
 10775 instruct roundFloat_mem_reg(stackSlotF dst, regFPR src) %{
 10776   predicate(UseSSE==0);
 10777   match(Set dst (RoundFloat src));
 10778   ins_cost(125);
 10779   format %{ "FST_S  $dst,$src\t# F-round" %}
 10780   ins_encode( Pop_Mem_Reg_FPR(dst, src) );
 10781   ins_pipe( fpu_mem_reg );
 10782 %}
 10784 instruct roundDouble_mem_reg(stackSlotD dst, regDPR src) %{
 10785   predicate(UseSSE<=1);
 10786   match(Set dst (RoundDouble src));
 10787   ins_cost(125);
 10788   format %{ "FST_D  $dst,$src\t# D-round" %}
 10789   ins_encode( Pop_Mem_Reg_DPR(dst, src) );
 10790   ins_pipe( fpu_mem_reg );
 10791 %}
 10793 // Force rounding to 24-bit precision and 6-bit exponent
 10794 instruct convDPR2FPR_reg(stackSlotF dst, regDPR src) %{
 10795   predicate(UseSSE==0);
 10796   match(Set dst (ConvD2F src));
 10797   format %{ "FST_S  $dst,$src\t# F-round" %}
 10798   expand %{
 10799     roundFloat_mem_reg(dst,src);
 10800   %}
 10801 %}
 10803 // Force rounding to 24-bit precision and 6-bit exponent
 10804 instruct convDPR2F_reg(regF dst, regDPR src, eFlagsReg cr) %{
 10805   predicate(UseSSE==1);
 10806   match(Set dst (ConvD2F src));
 10807   effect( KILL cr );
 10808   format %{ "SUB    ESP,4\n\t"
 10809             "FST_S  [ESP],$src\t# F-round\n\t"
 10810             "MOVSS  $dst,[ESP]\n\t"
 10811             "ADD ESP,4" %}
 10812   ins_encode %{
 10813     __ subptr(rsp, 4);
 10814     if ($src$$reg != FPR1L_enc) {
 10815       __ fld_s($src$$reg-1);
 10816       __ fstp_s(Address(rsp, 0));
 10817     } else {
 10818       __ fst_s(Address(rsp, 0));
 10820     __ movflt($dst$$XMMRegister, Address(rsp, 0));
 10821     __ addptr(rsp, 4);
 10822   %}
 10823   ins_pipe( pipe_slow );
 10824 %}
 10826 // Force rounding double precision to single precision
 10827 instruct convD2F_reg(regF dst, regD src) %{
 10828   predicate(UseSSE>=2);
 10829   match(Set dst (ConvD2F src));
 10830   format %{ "CVTSD2SS $dst,$src\t# F-round" %}
 10831   ins_encode %{
 10832     __ cvtsd2ss ($dst$$XMMRegister, $src$$XMMRegister);
 10833   %}
 10834   ins_pipe( pipe_slow );
 10835 %}
 10837 instruct convFPR2DPR_reg_reg(regDPR dst, regFPR src) %{
 10838   predicate(UseSSE==0);
 10839   match(Set dst (ConvF2D src));
 10840   format %{ "FST_S  $dst,$src\t# D-round" %}
 10841   ins_encode( Pop_Reg_Reg_DPR(dst, src));
 10842   ins_pipe( fpu_reg_reg );
 10843 %}
 10845 instruct convFPR2D_reg(stackSlotD dst, regFPR src) %{
 10846   predicate(UseSSE==1);
 10847   match(Set dst (ConvF2D src));
 10848   format %{ "FST_D  $dst,$src\t# D-round" %}
 10849   expand %{
 10850     roundDouble_mem_reg(dst,src);
 10851   %}
 10852 %}
 10854 instruct convF2DPR_reg(regDPR dst, regF src, eFlagsReg cr) %{
 10855   predicate(UseSSE==1);
 10856   match(Set dst (ConvF2D src));
 10857   effect( KILL cr );
 10858   format %{ "SUB    ESP,4\n\t"
 10859             "MOVSS  [ESP] $src\n\t"
 10860             "FLD_S  [ESP]\n\t"
 10861             "ADD    ESP,4\n\t"
 10862             "FSTP   $dst\t# D-round" %}
 10863   ins_encode %{
 10864     __ subptr(rsp, 4);
 10865     __ movflt(Address(rsp, 0), $src$$XMMRegister);
 10866     __ fld_s(Address(rsp, 0));
 10867     __ addptr(rsp, 4);
 10868     __ fstp_d($dst$$reg);
 10869   %}
 10870   ins_pipe( pipe_slow );
 10871 %}
 10873 instruct convF2D_reg(regD dst, regF src) %{
 10874   predicate(UseSSE>=2);
 10875   match(Set dst (ConvF2D src));
 10876   format %{ "CVTSS2SD $dst,$src\t# D-round" %}
 10877   ins_encode %{
 10878     __ cvtss2sd ($dst$$XMMRegister, $src$$XMMRegister);
 10879   %}
 10880   ins_pipe( pipe_slow );
 10881 %}
 10883 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
 10884 instruct convDPR2I_reg_reg( eAXRegI dst, eDXRegI tmp, regDPR src, eFlagsReg cr ) %{
 10885   predicate(UseSSE<=1);
 10886   match(Set dst (ConvD2I src));
 10887   effect( KILL tmp, KILL cr );
 10888   format %{ "FLD    $src\t# Convert double to int \n\t"
 10889             "FLDCW  trunc mode\n\t"
 10890             "SUB    ESP,4\n\t"
 10891             "FISTp  [ESP + #0]\n\t"
 10892             "FLDCW  std/24-bit mode\n\t"
 10893             "POP    EAX\n\t"
 10894             "CMP    EAX,0x80000000\n\t"
 10895             "JNE,s  fast\n\t"
 10896             "FLD_D  $src\n\t"
 10897             "CALL   d2i_wrapper\n"
 10898       "fast:" %}
 10899   ins_encode( Push_Reg_DPR(src), DPR2I_encoding(src) );
 10900   ins_pipe( pipe_slow );
 10901 %}
 10903 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
 10904 instruct convD2I_reg_reg( eAXRegI dst, eDXRegI tmp, regD src, eFlagsReg cr ) %{
 10905   predicate(UseSSE>=2);
 10906   match(Set dst (ConvD2I src));
 10907   effect( KILL tmp, KILL cr );
 10908   format %{ "CVTTSD2SI $dst, $src\n\t"
 10909             "CMP    $dst,0x80000000\n\t"
 10910             "JNE,s  fast\n\t"
 10911             "SUB    ESP, 8\n\t"
 10912             "MOVSD  [ESP], $src\n\t"
 10913             "FLD_D  [ESP]\n\t"
 10914             "ADD    ESP, 8\n\t"
 10915             "CALL   d2i_wrapper\n"
 10916       "fast:" %}
 10917   ins_encode %{
 10918     Label fast;
 10919     __ cvttsd2sil($dst$$Register, $src$$XMMRegister);
 10920     __ cmpl($dst$$Register, 0x80000000);
 10921     __ jccb(Assembler::notEqual, fast);
 10922     __ subptr(rsp, 8);
 10923     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
 10924     __ fld_d(Address(rsp, 0));
 10925     __ addptr(rsp, 8);
 10926     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2i_wrapper())));
 10927     __ bind(fast);
 10928   %}
 10929   ins_pipe( pipe_slow );
 10930 %}
 10932 instruct convDPR2L_reg_reg( eADXRegL dst, regDPR src, eFlagsReg cr ) %{
 10933   predicate(UseSSE<=1);
 10934   match(Set dst (ConvD2L src));
 10935   effect( KILL cr );
 10936   format %{ "FLD    $src\t# Convert double to long\n\t"
 10937             "FLDCW  trunc mode\n\t"
 10938             "SUB    ESP,8\n\t"
 10939             "FISTp  [ESP + #0]\n\t"
 10940             "FLDCW  std/24-bit mode\n\t"
 10941             "POP    EAX\n\t"
 10942             "POP    EDX\n\t"
 10943             "CMP    EDX,0x80000000\n\t"
 10944             "JNE,s  fast\n\t"
 10945             "TEST   EAX,EAX\n\t"
 10946             "JNE,s  fast\n\t"
 10947             "FLD    $src\n\t"
 10948             "CALL   d2l_wrapper\n"
 10949       "fast:" %}
 10950   ins_encode( Push_Reg_DPR(src),  DPR2L_encoding(src) );
 10951   ins_pipe( pipe_slow );
 10952 %}
 10954 // XMM lacks a float/double->long conversion, so use the old FPU stack.
 10955 instruct convD2L_reg_reg( eADXRegL dst, regD src, eFlagsReg cr ) %{
 10956   predicate (UseSSE>=2);
 10957   match(Set dst (ConvD2L src));
 10958   effect( KILL cr );
 10959   format %{ "SUB    ESP,8\t# Convert double to long\n\t"
 10960             "MOVSD  [ESP],$src\n\t"
 10961             "FLD_D  [ESP]\n\t"
 10962             "FLDCW  trunc mode\n\t"
 10963             "FISTp  [ESP + #0]\n\t"
 10964             "FLDCW  std/24-bit mode\n\t"
 10965             "POP    EAX\n\t"
 10966             "POP    EDX\n\t"
 10967             "CMP    EDX,0x80000000\n\t"
 10968             "JNE,s  fast\n\t"
 10969             "TEST   EAX,EAX\n\t"
 10970             "JNE,s  fast\n\t"
 10971             "SUB    ESP,8\n\t"
 10972             "MOVSD  [ESP],$src\n\t"
 10973             "FLD_D  [ESP]\n\t"
 10974             "ADD    ESP,8\n\t"
 10975             "CALL   d2l_wrapper\n"
 10976       "fast:" %}
 10977   ins_encode %{
 10978     Label fast;
 10979     __ subptr(rsp, 8);
 10980     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
 10981     __ fld_d(Address(rsp, 0));
 10982     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_trunc()));
 10983     __ fistp_d(Address(rsp, 0));
 10984     // Restore the rounding mode, mask the exception
 10985     if (Compile::current()->in_24_bit_fp_mode()) {
 10986       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
 10987     } else {
 10988       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
 10990     // Load the converted long, adjust CPU stack
 10991     __ pop(rax);
 10992     __ pop(rdx);
 10993     __ cmpl(rdx, 0x80000000);
 10994     __ jccb(Assembler::notEqual, fast);
 10995     __ testl(rax, rax);
 10996     __ jccb(Assembler::notEqual, fast);
 10997     __ subptr(rsp, 8);
 10998     __ movdbl(Address(rsp, 0), $src$$XMMRegister);
 10999     __ fld_d(Address(rsp, 0));
 11000     __ addptr(rsp, 8);
 11001     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2l_wrapper())));
 11002     __ bind(fast);
 11003   %}
 11004   ins_pipe( pipe_slow );
 11005 %}
 11007 // Convert a double to an int.  Java semantics require we do complex
 11008 // manglations in the corner cases.  So we set the rounding mode to
 11009 // 'zero', store the darned double down as an int, and reset the
 11010 // rounding mode to 'nearest'.  The hardware stores a flag value down
 11011 // if we would overflow or converted a NAN; we check for this and
 11012 // and go the slow path if needed.
 11013 instruct convFPR2I_reg_reg(eAXRegI dst, eDXRegI tmp, regFPR src, eFlagsReg cr ) %{
 11014   predicate(UseSSE==0);
 11015   match(Set dst (ConvF2I src));
 11016   effect( KILL tmp, KILL cr );
 11017   format %{ "FLD    $src\t# Convert float to int \n\t"
 11018             "FLDCW  trunc mode\n\t"
 11019             "SUB    ESP,4\n\t"
 11020             "FISTp  [ESP + #0]\n\t"
 11021             "FLDCW  std/24-bit mode\n\t"
 11022             "POP    EAX\n\t"
 11023             "CMP    EAX,0x80000000\n\t"
 11024             "JNE,s  fast\n\t"
 11025             "FLD    $src\n\t"
 11026             "CALL   d2i_wrapper\n"
 11027       "fast:" %}
 11028   // DPR2I_encoding works for FPR2I
 11029   ins_encode( Push_Reg_FPR(src), DPR2I_encoding(src) );
 11030   ins_pipe( pipe_slow );
 11031 %}
 11033 // Convert a float in xmm to an int reg.
 11034 instruct convF2I_reg(eAXRegI dst, eDXRegI tmp, regF src, eFlagsReg cr ) %{
 11035   predicate(UseSSE>=1);
 11036   match(Set dst (ConvF2I src));
 11037   effect( KILL tmp, KILL cr );
 11038   format %{ "CVTTSS2SI $dst, $src\n\t"
 11039             "CMP    $dst,0x80000000\n\t"
 11040             "JNE,s  fast\n\t"
 11041             "SUB    ESP, 4\n\t"
 11042             "MOVSS  [ESP], $src\n\t"
 11043             "FLD    [ESP]\n\t"
 11044             "ADD    ESP, 4\n\t"
 11045             "CALL   d2i_wrapper\n"
 11046       "fast:" %}
 11047   ins_encode %{
 11048     Label fast;
 11049     __ cvttss2sil($dst$$Register, $src$$XMMRegister);
 11050     __ cmpl($dst$$Register, 0x80000000);
 11051     __ jccb(Assembler::notEqual, fast);
 11052     __ subptr(rsp, 4);
 11053     __ movflt(Address(rsp, 0), $src$$XMMRegister);
 11054     __ fld_s(Address(rsp, 0));
 11055     __ addptr(rsp, 4);
 11056     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2i_wrapper())));
 11057     __ bind(fast);
 11058   %}
 11059   ins_pipe( pipe_slow );
 11060 %}
 11062 instruct convFPR2L_reg_reg( eADXRegL dst, regFPR src, eFlagsReg cr ) %{
 11063   predicate(UseSSE==0);
 11064   match(Set dst (ConvF2L src));
 11065   effect( KILL cr );
 11066   format %{ "FLD    $src\t# Convert float to long\n\t"
 11067             "FLDCW  trunc mode\n\t"
 11068             "SUB    ESP,8\n\t"
 11069             "FISTp  [ESP + #0]\n\t"
 11070             "FLDCW  std/24-bit mode\n\t"
 11071             "POP    EAX\n\t"
 11072             "POP    EDX\n\t"
 11073             "CMP    EDX,0x80000000\n\t"
 11074             "JNE,s  fast\n\t"
 11075             "TEST   EAX,EAX\n\t"
 11076             "JNE,s  fast\n\t"
 11077             "FLD    $src\n\t"
 11078             "CALL   d2l_wrapper\n"
 11079       "fast:" %}
 11080   // DPR2L_encoding works for FPR2L
 11081   ins_encode( Push_Reg_FPR(src), DPR2L_encoding(src) );
 11082   ins_pipe( pipe_slow );
 11083 %}
 11085 // XMM lacks a float/double->long conversion, so use the old FPU stack.
 11086 instruct convF2L_reg_reg( eADXRegL dst, regF src, eFlagsReg cr ) %{
 11087   predicate (UseSSE>=1);
 11088   match(Set dst (ConvF2L src));
 11089   effect( KILL cr );
 11090   format %{ "SUB    ESP,8\t# Convert float to long\n\t"
 11091             "MOVSS  [ESP],$src\n\t"
 11092             "FLD_S  [ESP]\n\t"
 11093             "FLDCW  trunc mode\n\t"
 11094             "FISTp  [ESP + #0]\n\t"
 11095             "FLDCW  std/24-bit mode\n\t"
 11096             "POP    EAX\n\t"
 11097             "POP    EDX\n\t"
 11098             "CMP    EDX,0x80000000\n\t"
 11099             "JNE,s  fast\n\t"
 11100             "TEST   EAX,EAX\n\t"
 11101             "JNE,s  fast\n\t"
 11102             "SUB    ESP,4\t# Convert float to long\n\t"
 11103             "MOVSS  [ESP],$src\n\t"
 11104             "FLD_S  [ESP]\n\t"
 11105             "ADD    ESP,4\n\t"
 11106             "CALL   d2l_wrapper\n"
 11107       "fast:" %}
 11108   ins_encode %{
 11109     Label fast;
 11110     __ subptr(rsp, 8);
 11111     __ movflt(Address(rsp, 0), $src$$XMMRegister);
 11112     __ fld_s(Address(rsp, 0));
 11113     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_trunc()));
 11114     __ fistp_d(Address(rsp, 0));
 11115     // Restore the rounding mode, mask the exception
 11116     if (Compile::current()->in_24_bit_fp_mode()) {
 11117       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
 11118     } else {
 11119       __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
 11121     // Load the converted long, adjust CPU stack
 11122     __ pop(rax);
 11123     __ pop(rdx);
 11124     __ cmpl(rdx, 0x80000000);
 11125     __ jccb(Assembler::notEqual, fast);
 11126     __ testl(rax, rax);
 11127     __ jccb(Assembler::notEqual, fast);
 11128     __ subptr(rsp, 4);
 11129     __ movflt(Address(rsp, 0), $src$$XMMRegister);
 11130     __ fld_s(Address(rsp, 0));
 11131     __ addptr(rsp, 4);
 11132     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::d2l_wrapper())));
 11133     __ bind(fast);
 11134   %}
 11135   ins_pipe( pipe_slow );
 11136 %}
 11138 instruct convI2DPR_reg(regDPR dst, stackSlotI src) %{
 11139   predicate( UseSSE<=1 );
 11140   match(Set dst (ConvI2D src));
 11141   format %{ "FILD   $src\n\t"
 11142             "FSTP   $dst" %}
 11143   opcode(0xDB, 0x0);  /* DB /0 */
 11144   ins_encode(Push_Mem_I(src), Pop_Reg_DPR(dst));
 11145   ins_pipe( fpu_reg_mem );
 11146 %}
 11148 instruct convI2D_reg(regD dst, rRegI src) %{
 11149   predicate( UseSSE>=2 && !UseXmmI2D );
 11150   match(Set dst (ConvI2D src));
 11151   format %{ "CVTSI2SD $dst,$src" %}
 11152   ins_encode %{
 11153     __ cvtsi2sdl ($dst$$XMMRegister, $src$$Register);
 11154   %}
 11155   ins_pipe( pipe_slow );
 11156 %}
 11158 instruct convI2D_mem(regD dst, memory mem) %{
 11159   predicate( UseSSE>=2 );
 11160   match(Set dst (ConvI2D (LoadI mem)));
 11161   format %{ "CVTSI2SD $dst,$mem" %}
 11162   ins_encode %{
 11163     __ cvtsi2sdl ($dst$$XMMRegister, $mem$$Address);
 11164   %}
 11165   ins_pipe( pipe_slow );
 11166 %}
 11168 instruct convXI2D_reg(regD dst, rRegI src)
 11169 %{
 11170   predicate( UseSSE>=2 && UseXmmI2D );
 11171   match(Set dst (ConvI2D src));
 11173   format %{ "MOVD  $dst,$src\n\t"
 11174             "CVTDQ2PD $dst,$dst\t# i2d" %}
 11175   ins_encode %{
 11176     __ movdl($dst$$XMMRegister, $src$$Register);
 11177     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
 11178   %}
 11179   ins_pipe(pipe_slow); // XXX
 11180 %}
 11182 instruct convI2DPR_mem(regDPR dst, memory mem) %{
 11183   predicate( UseSSE<=1 && !Compile::current()->select_24_bit_instr());
 11184   match(Set dst (ConvI2D (LoadI mem)));
 11185   format %{ "FILD   $mem\n\t"
 11186             "FSTP   $dst" %}
 11187   opcode(0xDB);      /* DB /0 */
 11188   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 11189               Pop_Reg_DPR(dst));
 11190   ins_pipe( fpu_reg_mem );
 11191 %}
 11193 // Convert a byte to a float; no rounding step needed.
 11194 instruct conv24I2FPR_reg(regFPR dst, stackSlotI src) %{
 11195   predicate( UseSSE==0 && n->in(1)->Opcode() == Op_AndI && n->in(1)->in(2)->is_Con() && n->in(1)->in(2)->get_int() == 255 );
 11196   match(Set dst (ConvI2F src));
 11197   format %{ "FILD   $src\n\t"
 11198             "FSTP   $dst" %}
 11200   opcode(0xDB, 0x0);  /* DB /0 */
 11201   ins_encode(Push_Mem_I(src), Pop_Reg_FPR(dst));
 11202   ins_pipe( fpu_reg_mem );
 11203 %}
 11205 // In 24-bit mode, force exponent rounding by storing back out
 11206 instruct convI2FPR_SSF(stackSlotF dst, stackSlotI src) %{
 11207   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 11208   match(Set dst (ConvI2F src));
 11209   ins_cost(200);
 11210   format %{ "FILD   $src\n\t"
 11211             "FSTP_S $dst" %}
 11212   opcode(0xDB, 0x0);  /* DB /0 */
 11213   ins_encode( Push_Mem_I(src),
 11214               Pop_Mem_FPR(dst));
 11215   ins_pipe( fpu_mem_mem );
 11216 %}
 11218 // In 24-bit mode, force exponent rounding by storing back out
 11219 instruct convI2FPR_SSF_mem(stackSlotF dst, memory mem) %{
 11220   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 11221   match(Set dst (ConvI2F (LoadI mem)));
 11222   ins_cost(200);
 11223   format %{ "FILD   $mem\n\t"
 11224             "FSTP_S $dst" %}
 11225   opcode(0xDB);  /* DB /0 */
 11226   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 11227               Pop_Mem_FPR(dst));
 11228   ins_pipe( fpu_mem_mem );
 11229 %}
 11231 // This instruction does not round to 24-bits
 11232 instruct convI2FPR_reg(regFPR dst, stackSlotI src) %{
 11233   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11234   match(Set dst (ConvI2F src));
 11235   format %{ "FILD   $src\n\t"
 11236             "FSTP   $dst" %}
 11237   opcode(0xDB, 0x0);  /* DB /0 */
 11238   ins_encode( Push_Mem_I(src),
 11239               Pop_Reg_FPR(dst));
 11240   ins_pipe( fpu_reg_mem );
 11241 %}
 11243 // This instruction does not round to 24-bits
 11244 instruct convI2FPR_mem(regFPR dst, memory mem) %{
 11245   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11246   match(Set dst (ConvI2F (LoadI mem)));
 11247   format %{ "FILD   $mem\n\t"
 11248             "FSTP   $dst" %}
 11249   opcode(0xDB);      /* DB /0 */
 11250   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 11251               Pop_Reg_FPR(dst));
 11252   ins_pipe( fpu_reg_mem );
 11253 %}
 11255 // Convert an int to a float in xmm; no rounding step needed.
 11256 instruct convI2F_reg(regF dst, rRegI src) %{
 11257   predicate( UseSSE==1 || UseSSE>=2 && !UseXmmI2F );
 11258   match(Set dst (ConvI2F src));
 11259   format %{ "CVTSI2SS $dst, $src" %}
 11260   ins_encode %{
 11261     __ cvtsi2ssl ($dst$$XMMRegister, $src$$Register);
 11262   %}
 11263   ins_pipe( pipe_slow );
 11264 %}
 11266  instruct convXI2F_reg(regF dst, rRegI src)
 11267 %{
 11268   predicate( UseSSE>=2 && UseXmmI2F );
 11269   match(Set dst (ConvI2F src));
 11271   format %{ "MOVD  $dst,$src\n\t"
 11272             "CVTDQ2PS $dst,$dst\t# i2f" %}
 11273   ins_encode %{
 11274     __ movdl($dst$$XMMRegister, $src$$Register);
 11275     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
 11276   %}
 11277   ins_pipe(pipe_slow); // XXX
 11278 %}
 11280 instruct convI2L_reg( eRegL dst, rRegI src, eFlagsReg cr) %{
 11281   match(Set dst (ConvI2L src));
 11282   effect(KILL cr);
 11283   ins_cost(375);
 11284   format %{ "MOV    $dst.lo,$src\n\t"
 11285             "MOV    $dst.hi,$src\n\t"
 11286             "SAR    $dst.hi,31" %}
 11287   ins_encode(convert_int_long(dst,src));
 11288   ins_pipe( ialu_reg_reg_long );
 11289 %}
 11291 // Zero-extend convert int to long
 11292 instruct convI2L_reg_zex(eRegL dst, rRegI src, immL_32bits mask, eFlagsReg flags ) %{
 11293   match(Set dst (AndL (ConvI2L src) mask) );
 11294   effect( KILL flags );
 11295   ins_cost(250);
 11296   format %{ "MOV    $dst.lo,$src\n\t"
 11297             "XOR    $dst.hi,$dst.hi" %}
 11298   opcode(0x33); // XOR
 11299   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
 11300   ins_pipe( ialu_reg_reg_long );
 11301 %}
 11303 // Zero-extend long
 11304 instruct zerox_long(eRegL dst, eRegL src, immL_32bits mask, eFlagsReg flags ) %{
 11305   match(Set dst (AndL src mask) );
 11306   effect( KILL flags );
 11307   ins_cost(250);
 11308   format %{ "MOV    $dst.lo,$src.lo\n\t"
 11309             "XOR    $dst.hi,$dst.hi\n\t" %}
 11310   opcode(0x33); // XOR
 11311   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
 11312   ins_pipe( ialu_reg_reg_long );
 11313 %}
 11315 instruct convL2DPR_reg( stackSlotD dst, eRegL src, eFlagsReg cr) %{
 11316   predicate (UseSSE<=1);
 11317   match(Set dst (ConvL2D src));
 11318   effect( KILL cr );
 11319   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
 11320             "PUSH   $src.lo\n\t"
 11321             "FILD   ST,[ESP + #0]\n\t"
 11322             "ADD    ESP,8\n\t"
 11323             "FSTP_D $dst\t# D-round" %}
 11324   opcode(0xDF, 0x5);  /* DF /5 */
 11325   ins_encode(convert_long_double(src), Pop_Mem_DPR(dst));
 11326   ins_pipe( pipe_slow );
 11327 %}
 11329 instruct convL2D_reg( regD dst, eRegL src, eFlagsReg cr) %{
 11330   predicate (UseSSE>=2);
 11331   match(Set dst (ConvL2D src));
 11332   effect( KILL cr );
 11333   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
 11334             "PUSH   $src.lo\n\t"
 11335             "FILD_D [ESP]\n\t"
 11336             "FSTP_D [ESP]\n\t"
 11337             "MOVSD  $dst,[ESP]\n\t"
 11338             "ADD    ESP,8" %}
 11339   opcode(0xDF, 0x5);  /* DF /5 */
 11340   ins_encode(convert_long_double2(src), Push_ResultD(dst));
 11341   ins_pipe( pipe_slow );
 11342 %}
 11344 instruct convL2F_reg( regF dst, eRegL src, eFlagsReg cr) %{
 11345   predicate (UseSSE>=1);
 11346   match(Set dst (ConvL2F src));
 11347   effect( KILL cr );
 11348   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
 11349             "PUSH   $src.lo\n\t"
 11350             "FILD_D [ESP]\n\t"
 11351             "FSTP_S [ESP]\n\t"
 11352             "MOVSS  $dst,[ESP]\n\t"
 11353             "ADD    ESP,8" %}
 11354   opcode(0xDF, 0x5);  /* DF /5 */
 11355   ins_encode(convert_long_double2(src), Push_ResultF(dst,0x8));
 11356   ins_pipe( pipe_slow );
 11357 %}
 11359 instruct convL2FPR_reg( stackSlotF dst, eRegL src, eFlagsReg cr) %{
 11360   match(Set dst (ConvL2F src));
 11361   effect( KILL cr );
 11362   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
 11363             "PUSH   $src.lo\n\t"
 11364             "FILD   ST,[ESP + #0]\n\t"
 11365             "ADD    ESP,8\n\t"
 11366             "FSTP_S $dst\t# F-round" %}
 11367   opcode(0xDF, 0x5);  /* DF /5 */
 11368   ins_encode(convert_long_double(src), Pop_Mem_FPR(dst));
 11369   ins_pipe( pipe_slow );
 11370 %}
 11372 instruct convL2I_reg( rRegI dst, eRegL src ) %{
 11373   match(Set dst (ConvL2I src));
 11374   effect( DEF dst, USE src );
 11375   format %{ "MOV    $dst,$src.lo" %}
 11376   ins_encode(enc_CopyL_Lo(dst,src));
 11377   ins_pipe( ialu_reg_reg );
 11378 %}
 11381 instruct MoveF2I_stack_reg(rRegI dst, stackSlotF src) %{
 11382   match(Set dst (MoveF2I src));
 11383   effect( DEF dst, USE src );
 11384   ins_cost(100);
 11385   format %{ "MOV    $dst,$src\t# MoveF2I_stack_reg" %}
 11386   ins_encode %{
 11387     __ movl($dst$$Register, Address(rsp, $src$$disp));
 11388   %}
 11389   ins_pipe( ialu_reg_mem );
 11390 %}
 11392 instruct MoveFPR2I_reg_stack(stackSlotI dst, regFPR src) %{
 11393   predicate(UseSSE==0);
 11394   match(Set dst (MoveF2I src));
 11395   effect( DEF dst, USE src );
 11397   ins_cost(125);
 11398   format %{ "FST_S  $dst,$src\t# MoveF2I_reg_stack" %}
 11399   ins_encode( Pop_Mem_Reg_FPR(dst, src) );
 11400   ins_pipe( fpu_mem_reg );
 11401 %}
 11403 instruct MoveF2I_reg_stack_sse(stackSlotI dst, regF src) %{
 11404   predicate(UseSSE>=1);
 11405   match(Set dst (MoveF2I src));
 11406   effect( DEF dst, USE src );
 11408   ins_cost(95);
 11409   format %{ "MOVSS  $dst,$src\t# MoveF2I_reg_stack_sse" %}
 11410   ins_encode %{
 11411     __ movflt(Address(rsp, $dst$$disp), $src$$XMMRegister);
 11412   %}
 11413   ins_pipe( pipe_slow );
 11414 %}
 11416 instruct MoveF2I_reg_reg_sse(rRegI dst, regF src) %{
 11417   predicate(UseSSE>=2);
 11418   match(Set dst (MoveF2I src));
 11419   effect( DEF dst, USE src );
 11420   ins_cost(85);
 11421   format %{ "MOVD   $dst,$src\t# MoveF2I_reg_reg_sse" %}
 11422   ins_encode %{
 11423     __ movdl($dst$$Register, $src$$XMMRegister);
 11424   %}
 11425   ins_pipe( pipe_slow );
 11426 %}
 11428 instruct MoveI2F_reg_stack(stackSlotF dst, rRegI src) %{
 11429   match(Set dst (MoveI2F src));
 11430   effect( DEF dst, USE src );
 11432   ins_cost(100);
 11433   format %{ "MOV    $dst,$src\t# MoveI2F_reg_stack" %}
 11434   ins_encode %{
 11435     __ movl(Address(rsp, $dst$$disp), $src$$Register);
 11436   %}
 11437   ins_pipe( ialu_mem_reg );
 11438 %}
 11441 instruct MoveI2FPR_stack_reg(regFPR dst, stackSlotI src) %{
 11442   predicate(UseSSE==0);
 11443   match(Set dst (MoveI2F src));
 11444   effect(DEF dst, USE src);
 11446   ins_cost(125);
 11447   format %{ "FLD_S  $src\n\t"
 11448             "FSTP   $dst\t# MoveI2F_stack_reg" %}
 11449   opcode(0xD9);               /* D9 /0, FLD m32real */
 11450   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
 11451               Pop_Reg_FPR(dst) );
 11452   ins_pipe( fpu_reg_mem );
 11453 %}
 11455 instruct MoveI2F_stack_reg_sse(regF dst, stackSlotI src) %{
 11456   predicate(UseSSE>=1);
 11457   match(Set dst (MoveI2F src));
 11458   effect( DEF dst, USE src );
 11460   ins_cost(95);
 11461   format %{ "MOVSS  $dst,$src\t# MoveI2F_stack_reg_sse" %}
 11462   ins_encode %{
 11463     __ movflt($dst$$XMMRegister, Address(rsp, $src$$disp));
 11464   %}
 11465   ins_pipe( pipe_slow );
 11466 %}
 11468 instruct MoveI2F_reg_reg_sse(regF dst, rRegI src) %{
 11469   predicate(UseSSE>=2);
 11470   match(Set dst (MoveI2F src));
 11471   effect( DEF dst, USE src );
 11473   ins_cost(85);
 11474   format %{ "MOVD   $dst,$src\t# MoveI2F_reg_reg_sse" %}
 11475   ins_encode %{
 11476     __ movdl($dst$$XMMRegister, $src$$Register);
 11477   %}
 11478   ins_pipe( pipe_slow );
 11479 %}
 11481 instruct MoveD2L_stack_reg(eRegL dst, stackSlotD src) %{
 11482   match(Set dst (MoveD2L src));
 11483   effect(DEF dst, USE src);
 11485   ins_cost(250);
 11486   format %{ "MOV    $dst.lo,$src\n\t"
 11487             "MOV    $dst.hi,$src+4\t# MoveD2L_stack_reg" %}
 11488   opcode(0x8B, 0x8B);
 11489   ins_encode( OpcP, RegMem(dst,src), OpcS, RegMem_Hi(dst,src));
 11490   ins_pipe( ialu_mem_long_reg );
 11491 %}
 11493 instruct MoveDPR2L_reg_stack(stackSlotL dst, regDPR src) %{
 11494   predicate(UseSSE<=1);
 11495   match(Set dst (MoveD2L src));
 11496   effect(DEF dst, USE src);
 11498   ins_cost(125);
 11499   format %{ "FST_D  $dst,$src\t# MoveD2L_reg_stack" %}
 11500   ins_encode( Pop_Mem_Reg_DPR(dst, src) );
 11501   ins_pipe( fpu_mem_reg );
 11502 %}
 11504 instruct MoveD2L_reg_stack_sse(stackSlotL dst, regD src) %{
 11505   predicate(UseSSE>=2);
 11506   match(Set dst (MoveD2L src));
 11507   effect(DEF dst, USE src);
 11508   ins_cost(95);
 11509   format %{ "MOVSD  $dst,$src\t# MoveD2L_reg_stack_sse" %}
 11510   ins_encode %{
 11511     __ movdbl(Address(rsp, $dst$$disp), $src$$XMMRegister);
 11512   %}
 11513   ins_pipe( pipe_slow );
 11514 %}
 11516 instruct MoveD2L_reg_reg_sse(eRegL dst, regD src, regD tmp) %{
 11517   predicate(UseSSE>=2);
 11518   match(Set dst (MoveD2L src));
 11519   effect(DEF dst, USE src, TEMP tmp);
 11520   ins_cost(85);
 11521   format %{ "MOVD   $dst.lo,$src\n\t"
 11522             "PSHUFLW $tmp,$src,0x4E\n\t"
 11523             "MOVD   $dst.hi,$tmp\t# MoveD2L_reg_reg_sse" %}
 11524   ins_encode %{
 11525     __ movdl($dst$$Register, $src$$XMMRegister);
 11526     __ pshuflw($tmp$$XMMRegister, $src$$XMMRegister, 0x4e);
 11527     __ movdl(HIGH_FROM_LOW($dst$$Register), $tmp$$XMMRegister);
 11528   %}
 11529   ins_pipe( pipe_slow );
 11530 %}
 11532 instruct MoveL2D_reg_stack(stackSlotD dst, eRegL src) %{
 11533   match(Set dst (MoveL2D src));
 11534   effect(DEF dst, USE src);
 11536   ins_cost(200);
 11537   format %{ "MOV    $dst,$src.lo\n\t"
 11538             "MOV    $dst+4,$src.hi\t# MoveL2D_reg_stack" %}
 11539   opcode(0x89, 0x89);
 11540   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
 11541   ins_pipe( ialu_mem_long_reg );
 11542 %}
 11545 instruct MoveL2DPR_stack_reg(regDPR dst, stackSlotL src) %{
 11546   predicate(UseSSE<=1);
 11547   match(Set dst (MoveL2D src));
 11548   effect(DEF dst, USE src);
 11549   ins_cost(125);
 11551   format %{ "FLD_D  $src\n\t"
 11552             "FSTP   $dst\t# MoveL2D_stack_reg" %}
 11553   opcode(0xDD);               /* DD /0, FLD m64real */
 11554   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
 11555               Pop_Reg_DPR(dst) );
 11556   ins_pipe( fpu_reg_mem );
 11557 %}
 11560 instruct MoveL2D_stack_reg_sse(regD dst, stackSlotL src) %{
 11561   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
 11562   match(Set dst (MoveL2D src));
 11563   effect(DEF dst, USE src);
 11565   ins_cost(95);
 11566   format %{ "MOVSD  $dst,$src\t# MoveL2D_stack_reg_sse" %}
 11567   ins_encode %{
 11568     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
 11569   %}
 11570   ins_pipe( pipe_slow );
 11571 %}
 11573 instruct MoveL2D_stack_reg_sse_partial(regD dst, stackSlotL src) %{
 11574   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
 11575   match(Set dst (MoveL2D src));
 11576   effect(DEF dst, USE src);
 11578   ins_cost(95);
 11579   format %{ "MOVLPD $dst,$src\t# MoveL2D_stack_reg_sse" %}
 11580   ins_encode %{
 11581     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
 11582   %}
 11583   ins_pipe( pipe_slow );
 11584 %}
 11586 instruct MoveL2D_reg_reg_sse(regD dst, eRegL src, regD tmp) %{
 11587   predicate(UseSSE>=2);
 11588   match(Set dst (MoveL2D src));
 11589   effect(TEMP dst, USE src, TEMP tmp);
 11590   ins_cost(85);
 11591   format %{ "MOVD   $dst,$src.lo\n\t"
 11592             "MOVD   $tmp,$src.hi\n\t"
 11593             "PUNPCKLDQ $dst,$tmp\t# MoveL2D_reg_reg_sse" %}
 11594   ins_encode %{
 11595     __ movdl($dst$$XMMRegister, $src$$Register);
 11596     __ movdl($tmp$$XMMRegister, HIGH_FROM_LOW($src$$Register));
 11597     __ punpckldq($dst$$XMMRegister, $tmp$$XMMRegister);
 11598   %}
 11599   ins_pipe( pipe_slow );
 11600 %}
 11603 // =======================================================================
 11604 // fast clearing of an array
 11605 instruct rep_stos(eCXRegI cnt, eDIRegP base, eAXRegI zero, Universe dummy, eFlagsReg cr) %{
 11606   predicate(!UseFastStosb);
 11607   match(Set dummy (ClearArray cnt base));
 11608   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
 11609   format %{ "XOR    EAX,EAX\t# ClearArray:\n\t"
 11610             "SHL    ECX,1\t# Convert doublewords to words\n\t"
 11611             "REP STOS\t# store EAX into [EDI++] while ECX--" %}
 11612   ins_encode %{ 
 11613     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register);
 11614   %}
 11615   ins_pipe( pipe_slow );
 11616 %}
 11618 instruct rep_fast_stosb(eCXRegI cnt, eDIRegP base, eAXRegI zero, Universe dummy, eFlagsReg cr) %{
 11619   predicate(UseFastStosb);
 11620   match(Set dummy (ClearArray cnt base));
 11621   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
 11622   format %{ "XOR    EAX,EAX\t# ClearArray:\n\t"
 11623             "SHL    ECX,3\t# Convert doublewords to bytes\n\t"
 11624             "REP STOSB\t# store EAX into [EDI++] while ECX--" %}
 11625   ins_encode %{ 
 11626     __ clear_mem($base$$Register, $cnt$$Register, $zero$$Register);
 11627   %}
 11628   ins_pipe( pipe_slow );
 11629 %}
 11631 instruct string_compare(eDIRegP str1, eCXRegI cnt1, eSIRegP str2, eDXRegI cnt2,
 11632                         eAXRegI result, regD tmp1, eFlagsReg cr) %{
 11633   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
 11634   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
 11636   format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
 11637   ins_encode %{
 11638     __ string_compare($str1$$Register, $str2$$Register,
 11639                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
 11640                       $tmp1$$XMMRegister);
 11641   %}
 11642   ins_pipe( pipe_slow );
 11643 %}
 11645 // fast string equals
 11646 instruct string_equals(eDIRegP str1, eSIRegP str2, eCXRegI cnt, eAXRegI result,
 11647                        regD tmp1, regD tmp2, eBXRegI tmp3, eFlagsReg cr) %{
 11648   match(Set result (StrEquals (Binary str1 str2) cnt));
 11649   effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
 11651   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
 11652   ins_encode %{
 11653     __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
 11654                           $cnt$$Register, $result$$Register, $tmp3$$Register,
 11655                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
 11656   %}
 11657   ins_pipe( pipe_slow );
 11658 %}
 11660 // fast search of substring with known size.
 11661 instruct string_indexof_con(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, immI int_cnt2,
 11662                             eBXRegI result, regD vec, eAXRegI cnt2, eCXRegI tmp, eFlagsReg cr) %{
 11663   predicate(UseSSE42Intrinsics);
 11664   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
 11665   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
 11667   format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $vec, $cnt1, $cnt2, $tmp" %}
 11668   ins_encode %{
 11669     int icnt2 = (int)$int_cnt2$$constant;
 11670     if (icnt2 >= 8) {
 11671       // IndexOf for constant substrings with size >= 8 elements
 11672       // which don't need to be loaded through stack.
 11673       __ string_indexofC8($str1$$Register, $str2$$Register,
 11674                           $cnt1$$Register, $cnt2$$Register,
 11675                           icnt2, $result$$Register,
 11676                           $vec$$XMMRegister, $tmp$$Register);
 11677     } else {
 11678       // Small strings are loaded through stack if they cross page boundary.
 11679       __ string_indexof($str1$$Register, $str2$$Register,
 11680                         $cnt1$$Register, $cnt2$$Register,
 11681                         icnt2, $result$$Register,
 11682                         $vec$$XMMRegister, $tmp$$Register);
 11684   %}
 11685   ins_pipe( pipe_slow );
 11686 %}
 11688 instruct string_indexof(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, eAXRegI cnt2,
 11689                         eBXRegI result, regD vec, eCXRegI tmp, eFlagsReg cr) %{
 11690   predicate(UseSSE42Intrinsics);
 11691   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
 11692   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
 11694   format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
 11695   ins_encode %{
 11696     __ string_indexof($str1$$Register, $str2$$Register,
 11697                       $cnt1$$Register, $cnt2$$Register,
 11698                       (-1), $result$$Register,
 11699                       $vec$$XMMRegister, $tmp$$Register);
 11700   %}
 11701   ins_pipe( pipe_slow );
 11702 %}
 11704 // fast array equals
 11705 instruct array_equals(eDIRegP ary1, eSIRegP ary2, eAXRegI result,
 11706                       regD tmp1, regD tmp2, eCXRegI tmp3, eBXRegI tmp4, eFlagsReg cr)
 11707 %{
 11708   match(Set result (AryEq ary1 ary2));
 11709   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
 11710   //ins_cost(300);
 11712   format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
 11713   ins_encode %{
 11714     __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
 11715                           $tmp3$$Register, $result$$Register, $tmp4$$Register,
 11716                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
 11717   %}
 11718   ins_pipe( pipe_slow );
 11719 %}
 11721 // encode char[] to byte[] in ISO_8859_1
 11722 instruct encode_iso_array(eSIRegP src, eDIRegP dst, eDXRegI len,
 11723                           regD tmp1, regD tmp2, regD tmp3, regD tmp4,
 11724                           eCXRegI tmp5, eAXRegI result, eFlagsReg cr) %{
 11725   match(Set result (EncodeISOArray src (Binary dst len)));
 11726   effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, USE_KILL src, USE_KILL dst, USE_KILL len, KILL tmp5, KILL cr);
 11728   format %{ "Encode array $src,$dst,$len -> $result    // KILL ECX, EDX, $tmp1, $tmp2, $tmp3, $tmp4, ESI, EDI " %}
 11729   ins_encode %{
 11730     __ encode_iso_array($src$$Register, $dst$$Register, $len$$Register,
 11731                         $tmp1$$XMMRegister, $tmp2$$XMMRegister, $tmp3$$XMMRegister,
 11732                         $tmp4$$XMMRegister, $tmp5$$Register, $result$$Register);
 11733   %}
 11734   ins_pipe( pipe_slow );
 11735 %}
 11738 //----------Control Flow Instructions------------------------------------------
 11739 // Signed compare Instructions
 11740 instruct compI_eReg(eFlagsReg cr, rRegI op1, rRegI op2) %{
 11741   match(Set cr (CmpI op1 op2));
 11742   effect( DEF cr, USE op1, USE op2 );
 11743   format %{ "CMP    $op1,$op2" %}
 11744   opcode(0x3B);  /* Opcode 3B /r */
 11745   ins_encode( OpcP, RegReg( op1, op2) );
 11746   ins_pipe( ialu_cr_reg_reg );
 11747 %}
 11749 instruct compI_eReg_imm(eFlagsReg cr, rRegI op1, immI op2) %{
 11750   match(Set cr (CmpI op1 op2));
 11751   effect( DEF cr, USE op1 );
 11752   format %{ "CMP    $op1,$op2" %}
 11753   opcode(0x81,0x07);  /* Opcode 81 /7 */
 11754   // ins_encode( RegImm( op1, op2) );  /* Was CmpImm */
 11755   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 11756   ins_pipe( ialu_cr_reg_imm );
 11757 %}
 11759 // Cisc-spilled version of cmpI_eReg
 11760 instruct compI_eReg_mem(eFlagsReg cr, rRegI op1, memory op2) %{
 11761   match(Set cr (CmpI op1 (LoadI op2)));
 11763   format %{ "CMP    $op1,$op2" %}
 11764   ins_cost(500);
 11765   opcode(0x3B);  /* Opcode 3B /r */
 11766   ins_encode( OpcP, RegMem( op1, op2) );
 11767   ins_pipe( ialu_cr_reg_mem );
 11768 %}
 11770 instruct testI_reg( eFlagsReg cr, rRegI src, immI0 zero ) %{
 11771   match(Set cr (CmpI src zero));
 11772   effect( DEF cr, USE src );
 11774   format %{ "TEST   $src,$src" %}
 11775   opcode(0x85);
 11776   ins_encode( OpcP, RegReg( src, src ) );
 11777   ins_pipe( ialu_cr_reg_imm );
 11778 %}
 11780 instruct testI_reg_imm( eFlagsReg cr, rRegI src, immI con, immI0 zero ) %{
 11781   match(Set cr (CmpI (AndI src con) zero));
 11783   format %{ "TEST   $src,$con" %}
 11784   opcode(0xF7,0x00);
 11785   ins_encode( OpcP, RegOpc(src), Con32(con) );
 11786   ins_pipe( ialu_cr_reg_imm );
 11787 %}
 11789 instruct testI_reg_mem( eFlagsReg cr, rRegI src, memory mem, immI0 zero ) %{
 11790   match(Set cr (CmpI (AndI src mem) zero));
 11792   format %{ "TEST   $src,$mem" %}
 11793   opcode(0x85);
 11794   ins_encode( OpcP, RegMem( src, mem ) );
 11795   ins_pipe( ialu_cr_reg_mem );
 11796 %}
 11798 // Unsigned compare Instructions; really, same as signed except they
 11799 // produce an eFlagsRegU instead of eFlagsReg.
 11800 instruct compU_eReg(eFlagsRegU cr, rRegI op1, rRegI op2) %{
 11801   match(Set cr (CmpU op1 op2));
 11803   format %{ "CMPu   $op1,$op2" %}
 11804   opcode(0x3B);  /* Opcode 3B /r */
 11805   ins_encode( OpcP, RegReg( op1, op2) );
 11806   ins_pipe( ialu_cr_reg_reg );
 11807 %}
 11809 instruct compU_eReg_imm(eFlagsRegU cr, rRegI op1, immI op2) %{
 11810   match(Set cr (CmpU op1 op2));
 11812   format %{ "CMPu   $op1,$op2" %}
 11813   opcode(0x81,0x07);  /* Opcode 81 /7 */
 11814   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 11815   ins_pipe( ialu_cr_reg_imm );
 11816 %}
 11818 // // Cisc-spilled version of cmpU_eReg
 11819 instruct compU_eReg_mem(eFlagsRegU cr, rRegI op1, memory op2) %{
 11820   match(Set cr (CmpU op1 (LoadI op2)));
 11822   format %{ "CMPu   $op1,$op2" %}
 11823   ins_cost(500);
 11824   opcode(0x3B);  /* Opcode 3B /r */
 11825   ins_encode( OpcP, RegMem( op1, op2) );
 11826   ins_pipe( ialu_cr_reg_mem );
 11827 %}
 11829 // // Cisc-spilled version of cmpU_eReg
 11830 //instruct compU_mem_eReg(eFlagsRegU cr, memory op1, rRegI op2) %{
 11831 //  match(Set cr (CmpU (LoadI op1) op2));
 11832 //
 11833 //  format %{ "CMPu   $op1,$op2" %}
 11834 //  ins_cost(500);
 11835 //  opcode(0x39);  /* Opcode 39 /r */
 11836 //  ins_encode( OpcP, RegMem( op1, op2) );
 11837 //%}
 11839 instruct testU_reg( eFlagsRegU cr, rRegI src, immI0 zero ) %{
 11840   match(Set cr (CmpU src zero));
 11842   format %{ "TESTu  $src,$src" %}
 11843   opcode(0x85);
 11844   ins_encode( OpcP, RegReg( src, src ) );
 11845   ins_pipe( ialu_cr_reg_imm );
 11846 %}
 11848 // Unsigned pointer compare Instructions
 11849 instruct compP_eReg(eFlagsRegU cr, eRegP op1, eRegP op2) %{
 11850   match(Set cr (CmpP op1 op2));
 11852   format %{ "CMPu   $op1,$op2" %}
 11853   opcode(0x3B);  /* Opcode 3B /r */
 11854   ins_encode( OpcP, RegReg( op1, op2) );
 11855   ins_pipe( ialu_cr_reg_reg );
 11856 %}
 11858 instruct compP_eReg_imm(eFlagsRegU cr, eRegP op1, immP op2) %{
 11859   match(Set cr (CmpP op1 op2));
 11861   format %{ "CMPu   $op1,$op2" %}
 11862   opcode(0x81,0x07);  /* Opcode 81 /7 */
 11863   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 11864   ins_pipe( ialu_cr_reg_imm );
 11865 %}
 11867 // // Cisc-spilled version of cmpP_eReg
 11868 instruct compP_eReg_mem(eFlagsRegU cr, eRegP op1, memory op2) %{
 11869   match(Set cr (CmpP op1 (LoadP op2)));
 11871   format %{ "CMPu   $op1,$op2" %}
 11872   ins_cost(500);
 11873   opcode(0x3B);  /* Opcode 3B /r */
 11874   ins_encode( OpcP, RegMem( op1, op2) );
 11875   ins_pipe( ialu_cr_reg_mem );
 11876 %}
 11878 // // Cisc-spilled version of cmpP_eReg
 11879 //instruct compP_mem_eReg(eFlagsRegU cr, memory op1, eRegP op2) %{
 11880 //  match(Set cr (CmpP (LoadP op1) op2));
 11881 //
 11882 //  format %{ "CMPu   $op1,$op2" %}
 11883 //  ins_cost(500);
 11884 //  opcode(0x39);  /* Opcode 39 /r */
 11885 //  ins_encode( OpcP, RegMem( op1, op2) );
 11886 //%}
 11888 // Compare raw pointer (used in out-of-heap check).
 11889 // Only works because non-oop pointers must be raw pointers
 11890 // and raw pointers have no anti-dependencies.
 11891 instruct compP_mem_eReg( eFlagsRegU cr, eRegP op1, memory op2 ) %{
 11892   predicate( n->in(2)->in(2)->bottom_type()->reloc() == relocInfo::none );
 11893   match(Set cr (CmpP op1 (LoadP op2)));
 11895   format %{ "CMPu   $op1,$op2" %}
 11896   opcode(0x3B);  /* Opcode 3B /r */
 11897   ins_encode( OpcP, RegMem( op1, op2) );
 11898   ins_pipe( ialu_cr_reg_mem );
 11899 %}
 11901 //
 11902 // This will generate a signed flags result. This should be ok
 11903 // since any compare to a zero should be eq/neq.
 11904 instruct testP_reg( eFlagsReg cr, eRegP src, immP0 zero ) %{
 11905   match(Set cr (CmpP src zero));
 11907   format %{ "TEST   $src,$src" %}
 11908   opcode(0x85);
 11909   ins_encode( OpcP, RegReg( src, src ) );
 11910   ins_pipe( ialu_cr_reg_imm );
 11911 %}
 11913 // Cisc-spilled version of testP_reg
 11914 // This will generate a signed flags result. This should be ok
 11915 // since any compare to a zero should be eq/neq.
 11916 instruct testP_Reg_mem( eFlagsReg cr, memory op, immI0 zero ) %{
 11917   match(Set cr (CmpP (LoadP op) zero));
 11919   format %{ "TEST   $op,0xFFFFFFFF" %}
 11920   ins_cost(500);
 11921   opcode(0xF7);               /* Opcode F7 /0 */
 11922   ins_encode( OpcP, RMopc_Mem(0x00,op), Con_d32(0xFFFFFFFF) );
 11923   ins_pipe( ialu_cr_reg_imm );
 11924 %}
 11926 // Yanked all unsigned pointer compare operations.
 11927 // Pointer compares are done with CmpP which is already unsigned.
 11929 //----------Max and Min--------------------------------------------------------
 11930 // Min Instructions
 11931 ////
 11932 //   *** Min and Max using the conditional move are slower than the
 11933 //   *** branch version on a Pentium III.
 11934 // // Conditional move for min
 11935 //instruct cmovI_reg_lt( rRegI op2, rRegI op1, eFlagsReg cr ) %{
 11936 //  effect( USE_DEF op2, USE op1, USE cr );
 11937 //  format %{ "CMOVlt $op2,$op1\t! min" %}
 11938 //  opcode(0x4C,0x0F);
 11939 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
 11940 //  ins_pipe( pipe_cmov_reg );
 11941 //%}
 11942 //
 11943 //// Min Register with Register (P6 version)
 11944 //instruct minI_eReg_p6( rRegI op1, rRegI op2 ) %{
 11945 //  predicate(VM_Version::supports_cmov() );
 11946 //  match(Set op2 (MinI op1 op2));
 11947 //  ins_cost(200);
 11948 //  expand %{
 11949 //    eFlagsReg cr;
 11950 //    compI_eReg(cr,op1,op2);
 11951 //    cmovI_reg_lt(op2,op1,cr);
 11952 //  %}
 11953 //%}
 11955 // Min Register with Register (generic version)
 11956 instruct minI_eReg(rRegI dst, rRegI src, eFlagsReg flags) %{
 11957   match(Set dst (MinI dst src));
 11958   effect(KILL flags);
 11959   ins_cost(300);
 11961   format %{ "MIN    $dst,$src" %}
 11962   opcode(0xCC);
 11963   ins_encode( min_enc(dst,src) );
 11964   ins_pipe( pipe_slow );
 11965 %}
 11967 // Max Register with Register
 11968 //   *** Min and Max using the conditional move are slower than the
 11969 //   *** branch version on a Pentium III.
 11970 // // Conditional move for max
 11971 //instruct cmovI_reg_gt( rRegI op2, rRegI op1, eFlagsReg cr ) %{
 11972 //  effect( USE_DEF op2, USE op1, USE cr );
 11973 //  format %{ "CMOVgt $op2,$op1\t! max" %}
 11974 //  opcode(0x4F,0x0F);
 11975 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
 11976 //  ins_pipe( pipe_cmov_reg );
 11977 //%}
 11978 //
 11979 // // Max Register with Register (P6 version)
 11980 //instruct maxI_eReg_p6( rRegI op1, rRegI op2 ) %{
 11981 //  predicate(VM_Version::supports_cmov() );
 11982 //  match(Set op2 (MaxI op1 op2));
 11983 //  ins_cost(200);
 11984 //  expand %{
 11985 //    eFlagsReg cr;
 11986 //    compI_eReg(cr,op1,op2);
 11987 //    cmovI_reg_gt(op2,op1,cr);
 11988 //  %}
 11989 //%}
 11991 // Max Register with Register (generic version)
 11992 instruct maxI_eReg(rRegI dst, rRegI src, eFlagsReg flags) %{
 11993   match(Set dst (MaxI dst src));
 11994   effect(KILL flags);
 11995   ins_cost(300);
 11997   format %{ "MAX    $dst,$src" %}
 11998   opcode(0xCC);
 11999   ins_encode( max_enc(dst,src) );
 12000   ins_pipe( pipe_slow );
 12001 %}
 12003 // ============================================================================
 12004 // Counted Loop limit node which represents exact final iterator value.
 12005 // Note: the resulting value should fit into integer range since
 12006 // counted loops have limit check on overflow.
 12007 instruct loopLimit_eReg(eAXRegI limit, nadxRegI init, immI stride, eDXRegI limit_hi, nadxRegI tmp, eFlagsReg flags) %{
 12008   match(Set limit (LoopLimit (Binary init limit) stride));
 12009   effect(TEMP limit_hi, TEMP tmp, KILL flags);
 12010   ins_cost(300);
 12012   format %{ "loopLimit $init,$limit,$stride  # $limit = $init + $stride *( $limit - $init + $stride -1)/ $stride, kills $limit_hi" %}
 12013   ins_encode %{
 12014     int strd = (int)$stride$$constant;
 12015     assert(strd != 1 && strd != -1, "sanity");
 12016     int m1 = (strd > 0) ? 1 : -1;
 12017     // Convert limit to long (EAX:EDX)
 12018     __ cdql();
 12019     // Convert init to long (init:tmp)
 12020     __ movl($tmp$$Register, $init$$Register);
 12021     __ sarl($tmp$$Register, 31);
 12022     // $limit - $init
 12023     __ subl($limit$$Register, $init$$Register);
 12024     __ sbbl($limit_hi$$Register, $tmp$$Register);
 12025     // + ($stride - 1)
 12026     if (strd > 0) {
 12027       __ addl($limit$$Register, (strd - 1));
 12028       __ adcl($limit_hi$$Register, 0);
 12029       __ movl($tmp$$Register, strd);
 12030     } else {
 12031       __ addl($limit$$Register, (strd + 1));
 12032       __ adcl($limit_hi$$Register, -1);
 12033       __ lneg($limit_hi$$Register, $limit$$Register);
 12034       __ movl($tmp$$Register, -strd);
 12036     // signed devision: (EAX:EDX) / pos_stride
 12037     __ idivl($tmp$$Register);
 12038     if (strd < 0) {
 12039       // restore sign
 12040       __ negl($tmp$$Register);
 12042     // (EAX) * stride
 12043     __ mull($tmp$$Register);
 12044     // + init (ignore upper bits)
 12045     __ addl($limit$$Register, $init$$Register);
 12046   %}
 12047   ins_pipe( pipe_slow );
 12048 %}
 12050 // ============================================================================
 12051 // Branch Instructions
 12052 // Jump Table
 12053 instruct jumpXtnd(rRegI switch_val) %{
 12054   match(Jump switch_val);
 12055   ins_cost(350);
 12056   format %{  "JMP    [$constantaddress](,$switch_val,1)\n\t" %}
 12057   ins_encode %{
 12058     // Jump to Address(table_base + switch_reg)
 12059     Address index(noreg, $switch_val$$Register, Address::times_1);
 12060     __ jump(ArrayAddress($constantaddress, index));
 12061   %}
 12062   ins_pipe(pipe_jmp);
 12063 %}
 12065 // Jump Direct - Label defines a relative address from JMP+1
 12066 instruct jmpDir(label labl) %{
 12067   match(Goto);
 12068   effect(USE labl);
 12070   ins_cost(300);
 12071   format %{ "JMP    $labl" %}
 12072   size(5);
 12073   ins_encode %{
 12074     Label* L = $labl$$label;
 12075     __ jmp(*L, false); // Always long jump
 12076   %}
 12077   ins_pipe( pipe_jmp );
 12078 %}
 12080 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12081 instruct jmpCon(cmpOp cop, eFlagsReg cr, label labl) %{
 12082   match(If cop cr);
 12083   effect(USE labl);
 12085   ins_cost(300);
 12086   format %{ "J$cop    $labl" %}
 12087   size(6);
 12088   ins_encode %{
 12089     Label* L = $labl$$label;
 12090     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12091   %}
 12092   ins_pipe( pipe_jcc );
 12093 %}
 12095 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12096 instruct jmpLoopEnd(cmpOp cop, eFlagsReg cr, label labl) %{
 12097   match(CountedLoopEnd cop cr);
 12098   effect(USE labl);
 12100   ins_cost(300);
 12101   format %{ "J$cop    $labl\t# Loop end" %}
 12102   size(6);
 12103   ins_encode %{
 12104     Label* L = $labl$$label;
 12105     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12106   %}
 12107   ins_pipe( pipe_jcc );
 12108 %}
 12110 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12111 instruct jmpLoopEndU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 12112   match(CountedLoopEnd cop cmp);
 12113   effect(USE labl);
 12115   ins_cost(300);
 12116   format %{ "J$cop,u  $labl\t# Loop end" %}
 12117   size(6);
 12118   ins_encode %{
 12119     Label* L = $labl$$label;
 12120     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12121   %}
 12122   ins_pipe( pipe_jcc );
 12123 %}
 12125 instruct jmpLoopEndUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 12126   match(CountedLoopEnd cop cmp);
 12127   effect(USE labl);
 12129   ins_cost(200);
 12130   format %{ "J$cop,u  $labl\t# Loop end" %}
 12131   size(6);
 12132   ins_encode %{
 12133     Label* L = $labl$$label;
 12134     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12135   %}
 12136   ins_pipe( pipe_jcc );
 12137 %}
 12139 // Jump Direct Conditional - using unsigned comparison
 12140 instruct jmpConU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 12141   match(If cop cmp);
 12142   effect(USE labl);
 12144   ins_cost(300);
 12145   format %{ "J$cop,u  $labl" %}
 12146   size(6);
 12147   ins_encode %{
 12148     Label* L = $labl$$label;
 12149     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12150   %}
 12151   ins_pipe(pipe_jcc);
 12152 %}
 12154 instruct jmpConUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 12155   match(If cop cmp);
 12156   effect(USE labl);
 12158   ins_cost(200);
 12159   format %{ "J$cop,u  $labl" %}
 12160   size(6);
 12161   ins_encode %{
 12162     Label* L = $labl$$label;
 12163     __ jcc((Assembler::Condition)($cop$$cmpcode), *L, false); // Always long jump
 12164   %}
 12165   ins_pipe(pipe_jcc);
 12166 %}
 12168 instruct jmpConUCF2(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
 12169   match(If cop cmp);
 12170   effect(USE labl);
 12172   ins_cost(200);
 12173   format %{ $$template
 12174     if ($cop$$cmpcode == Assembler::notEqual) {
 12175       $$emit$$"JP,u   $labl\n\t"
 12176       $$emit$$"J$cop,u   $labl"
 12177     } else {
 12178       $$emit$$"JP,u   done\n\t"
 12179       $$emit$$"J$cop,u   $labl\n\t"
 12180       $$emit$$"done:"
 12182   %}
 12183   ins_encode %{
 12184     Label* l = $labl$$label;
 12185     if ($cop$$cmpcode == Assembler::notEqual) {
 12186       __ jcc(Assembler::parity, *l, false);
 12187       __ jcc(Assembler::notEqual, *l, false);
 12188     } else if ($cop$$cmpcode == Assembler::equal) {
 12189       Label done;
 12190       __ jccb(Assembler::parity, done);
 12191       __ jcc(Assembler::equal, *l, false);
 12192       __ bind(done);
 12193     } else {
 12194        ShouldNotReachHere();
 12196   %}
 12197   ins_pipe(pipe_jcc);
 12198 %}
 12200 // ============================================================================
 12201 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary superklass
 12202 // array for an instance of the superklass.  Set a hidden internal cache on a
 12203 // hit (cache is checked with exposed code in gen_subtype_check()).  Return
 12204 // NZ for a miss or zero for a hit.  The encoding ALSO sets flags.
 12205 instruct partialSubtypeCheck( eDIRegP result, eSIRegP sub, eAXRegP super, eCXRegI rcx, eFlagsReg cr ) %{
 12206   match(Set result (PartialSubtypeCheck sub super));
 12207   effect( KILL rcx, KILL cr );
 12209   ins_cost(1100);  // slightly larger than the next version
 12210   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
 12211             "MOV    ECX,[EDI+ArrayKlass::length]\t# length to scan\n\t"
 12212             "ADD    EDI,ArrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
 12213             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
 12214             "JNE,s  miss\t\t# Missed: EDI not-zero\n\t"
 12215             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache\n\t"
 12216             "XOR    $result,$result\t\t Hit: EDI zero\n\t"
 12217      "miss:\t" %}
 12219   opcode(0x1); // Force a XOR of EDI
 12220   ins_encode( enc_PartialSubtypeCheck() );
 12221   ins_pipe( pipe_slow );
 12222 %}
 12224 instruct partialSubtypeCheck_vs_Zero( eFlagsReg cr, eSIRegP sub, eAXRegP super, eCXRegI rcx, eDIRegP result, immP0 zero ) %{
 12225   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
 12226   effect( KILL rcx, KILL result );
 12228   ins_cost(1000);
 12229   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
 12230             "MOV    ECX,[EDI+ArrayKlass::length]\t# length to scan\n\t"
 12231             "ADD    EDI,ArrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
 12232             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
 12233             "JNE,s  miss\t\t# Missed: flags NZ\n\t"
 12234             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache, flags Z\n\t"
 12235      "miss:\t" %}
 12237   opcode(0x0);  // No need to XOR EDI
 12238   ins_encode( enc_PartialSubtypeCheck() );
 12239   ins_pipe( pipe_slow );
 12240 %}
 12242 // ============================================================================
 12243 // Branch Instructions -- short offset versions
 12244 //
 12245 // These instructions are used to replace jumps of a long offset (the default
 12246 // match) with jumps of a shorter offset.  These instructions are all tagged
 12247 // with the ins_short_branch attribute, which causes the ADLC to suppress the
 12248 // match rules in general matching.  Instead, the ADLC generates a conversion
 12249 // method in the MachNode which can be used to do in-place replacement of the
 12250 // long variant with the shorter variant.  The compiler will determine if a
 12251 // branch can be taken by the is_short_branch_offset() predicate in the machine
 12252 // specific code section of the file.
 12254 // Jump Direct - Label defines a relative address from JMP+1
 12255 instruct jmpDir_short(label labl) %{
 12256   match(Goto);
 12257   effect(USE labl);
 12259   ins_cost(300);
 12260   format %{ "JMP,s  $labl" %}
 12261   size(2);
 12262   ins_encode %{
 12263     Label* L = $labl$$label;
 12264     __ jmpb(*L);
 12265   %}
 12266   ins_pipe( pipe_jmp );
 12267   ins_short_branch(1);
 12268 %}
 12270 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12271 instruct jmpCon_short(cmpOp cop, eFlagsReg cr, label labl) %{
 12272   match(If cop cr);
 12273   effect(USE labl);
 12275   ins_cost(300);
 12276   format %{ "J$cop,s  $labl" %}
 12277   size(2);
 12278   ins_encode %{
 12279     Label* L = $labl$$label;
 12280     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12281   %}
 12282   ins_pipe( pipe_jcc );
 12283   ins_short_branch(1);
 12284 %}
 12286 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12287 instruct jmpLoopEnd_short(cmpOp cop, eFlagsReg cr, label labl) %{
 12288   match(CountedLoopEnd cop cr);
 12289   effect(USE labl);
 12291   ins_cost(300);
 12292   format %{ "J$cop,s  $labl\t# Loop end" %}
 12293   size(2);
 12294   ins_encode %{
 12295     Label* L = $labl$$label;
 12296     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12297   %}
 12298   ins_pipe( pipe_jcc );
 12299   ins_short_branch(1);
 12300 %}
 12302 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 12303 instruct jmpLoopEndU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 12304   match(CountedLoopEnd cop cmp);
 12305   effect(USE labl);
 12307   ins_cost(300);
 12308   format %{ "J$cop,us $labl\t# Loop end" %}
 12309   size(2);
 12310   ins_encode %{
 12311     Label* L = $labl$$label;
 12312     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12313   %}
 12314   ins_pipe( pipe_jcc );
 12315   ins_short_branch(1);
 12316 %}
 12318 instruct jmpLoopEndUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 12319   match(CountedLoopEnd cop cmp);
 12320   effect(USE labl);
 12322   ins_cost(300);
 12323   format %{ "J$cop,us $labl\t# Loop end" %}
 12324   size(2);
 12325   ins_encode %{
 12326     Label* L = $labl$$label;
 12327     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12328   %}
 12329   ins_pipe( pipe_jcc );
 12330   ins_short_branch(1);
 12331 %}
 12333 // Jump Direct Conditional - using unsigned comparison
 12334 instruct jmpConU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 12335   match(If cop cmp);
 12336   effect(USE labl);
 12338   ins_cost(300);
 12339   format %{ "J$cop,us $labl" %}
 12340   size(2);
 12341   ins_encode %{
 12342     Label* L = $labl$$label;
 12343     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12344   %}
 12345   ins_pipe( pipe_jcc );
 12346   ins_short_branch(1);
 12347 %}
 12349 instruct jmpConUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 12350   match(If cop cmp);
 12351   effect(USE labl);
 12353   ins_cost(300);
 12354   format %{ "J$cop,us $labl" %}
 12355   size(2);
 12356   ins_encode %{
 12357     Label* L = $labl$$label;
 12358     __ jccb((Assembler::Condition)($cop$$cmpcode), *L);
 12359   %}
 12360   ins_pipe( pipe_jcc );
 12361   ins_short_branch(1);
 12362 %}
 12364 instruct jmpConUCF2_short(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
 12365   match(If cop cmp);
 12366   effect(USE labl);
 12368   ins_cost(300);
 12369   format %{ $$template
 12370     if ($cop$$cmpcode == Assembler::notEqual) {
 12371       $$emit$$"JP,u,s   $labl\n\t"
 12372       $$emit$$"J$cop,u,s   $labl"
 12373     } else {
 12374       $$emit$$"JP,u,s   done\n\t"
 12375       $$emit$$"J$cop,u,s  $labl\n\t"
 12376       $$emit$$"done:"
 12378   %}
 12379   size(4);
 12380   ins_encode %{
 12381     Label* l = $labl$$label;
 12382     if ($cop$$cmpcode == Assembler::notEqual) {
 12383       __ jccb(Assembler::parity, *l);
 12384       __ jccb(Assembler::notEqual, *l);
 12385     } else if ($cop$$cmpcode == Assembler::equal) {
 12386       Label done;
 12387       __ jccb(Assembler::parity, done);
 12388       __ jccb(Assembler::equal, *l);
 12389       __ bind(done);
 12390     } else {
 12391        ShouldNotReachHere();
 12393   %}
 12394   ins_pipe(pipe_jcc);
 12395   ins_short_branch(1);
 12396 %}
 12398 // ============================================================================
 12399 // Long Compare
 12400 //
 12401 // Currently we hold longs in 2 registers.  Comparing such values efficiently
 12402 // is tricky.  The flavor of compare used depends on whether we are testing
 12403 // for LT, LE, or EQ.  For a simple LT test we can check just the sign bit.
 12404 // The GE test is the negated LT test.  The LE test can be had by commuting
 12405 // the operands (yielding a GE test) and then negating; negate again for the
 12406 // GT test.  The EQ test is done by ORcc'ing the high and low halves, and the
 12407 // NE test is negated from that.
 12409 // Due to a shortcoming in the ADLC, it mixes up expressions like:
 12410 // (foo (CmpI (CmpL X Y) 0)) and (bar (CmpI (CmpL X 0L) 0)).  Note the
 12411 // difference between 'Y' and '0L'.  The tree-matches for the CmpI sections
 12412 // are collapsed internally in the ADLC's dfa-gen code.  The match for
 12413 // (CmpI (CmpL X Y) 0) is silently replaced with (CmpI (CmpL X 0L) 0) and the
 12414 // foo match ends up with the wrong leaf.  One fix is to not match both
 12415 // reg-reg and reg-zero forms of long-compare.  This is unfortunate because
 12416 // both forms beat the trinary form of long-compare and both are very useful
 12417 // on Intel which has so few registers.
 12419 // Manifest a CmpL result in an integer register.  Very painful.
 12420 // This is the test to avoid.
 12421 instruct cmpL3_reg_reg(eSIRegI dst, eRegL src1, eRegL src2, eFlagsReg flags ) %{
 12422   match(Set dst (CmpL3 src1 src2));
 12423   effect( KILL flags );
 12424   ins_cost(1000);
 12425   format %{ "XOR    $dst,$dst\n\t"
 12426             "CMP    $src1.hi,$src2.hi\n\t"
 12427             "JLT,s  m_one\n\t"
 12428             "JGT,s  p_one\n\t"
 12429             "CMP    $src1.lo,$src2.lo\n\t"
 12430             "JB,s   m_one\n\t"
 12431             "JEQ,s  done\n"
 12432     "p_one:\tINC    $dst\n\t"
 12433             "JMP,s  done\n"
 12434     "m_one:\tDEC    $dst\n"
 12435      "done:" %}
 12436   ins_encode %{
 12437     Label p_one, m_one, done;
 12438     __ xorptr($dst$$Register, $dst$$Register);
 12439     __ cmpl(HIGH_FROM_LOW($src1$$Register), HIGH_FROM_LOW($src2$$Register));
 12440     __ jccb(Assembler::less,    m_one);
 12441     __ jccb(Assembler::greater, p_one);
 12442     __ cmpl($src1$$Register, $src2$$Register);
 12443     __ jccb(Assembler::below,   m_one);
 12444     __ jccb(Assembler::equal,   done);
 12445     __ bind(p_one);
 12446     __ incrementl($dst$$Register);
 12447     __ jmpb(done);
 12448     __ bind(m_one);
 12449     __ decrementl($dst$$Register);
 12450     __ bind(done);
 12451   %}
 12452   ins_pipe( pipe_slow );
 12453 %}
 12455 //======
 12456 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
 12457 // compares.  Can be used for LE or GT compares by reversing arguments.
 12458 // NOT GOOD FOR EQ/NE tests.
 12459 instruct cmpL_zero_flags_LTGE( flagsReg_long_LTGE flags, eRegL src, immL0 zero ) %{
 12460   match( Set flags (CmpL src zero ));
 12461   ins_cost(100);
 12462   format %{ "TEST   $src.hi,$src.hi" %}
 12463   opcode(0x85);
 12464   ins_encode( OpcP, RegReg_Hi2( src, src ) );
 12465   ins_pipe( ialu_cr_reg_reg );
 12466 %}
 12468 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
 12469 // compares.  Can be used for LE or GT compares by reversing arguments.
 12470 // NOT GOOD FOR EQ/NE tests.
 12471 instruct cmpL_reg_flags_LTGE( flagsReg_long_LTGE flags, eRegL src1, eRegL src2, rRegI tmp ) %{
 12472   match( Set flags (CmpL src1 src2 ));
 12473   effect( TEMP tmp );
 12474   ins_cost(300);
 12475   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
 12476             "MOV    $tmp,$src1.hi\n\t"
 12477             "SBB    $tmp,$src2.hi\t! Compute flags for long compare" %}
 12478   ins_encode( long_cmp_flags2( src1, src2, tmp ) );
 12479   ins_pipe( ialu_cr_reg_reg );
 12480 %}
 12482 // Long compares reg < zero/req OR reg >= zero/req.
 12483 // Just a wrapper for a normal branch, plus the predicate test.
 12484 instruct cmpL_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, label labl) %{
 12485   match(If cmp flags);
 12486   effect(USE labl);
 12487   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
 12488   expand %{
 12489     jmpCon(cmp,flags,labl);    // JLT or JGE...
 12490   %}
 12491 %}
 12493 // Compare 2 longs and CMOVE longs.
 12494 instruct cmovLL_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, eRegL src) %{
 12495   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 12496   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 ));
 12497   ins_cost(400);
 12498   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12499             "CMOV$cmp $dst.hi,$src.hi" %}
 12500   opcode(0x0F,0x40);
 12501   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 12502   ins_pipe( pipe_cmov_reg_long );
 12503 %}
 12505 instruct cmovLL_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, load_long_memory src) %{
 12506   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 12507   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 ));
 12508   ins_cost(500);
 12509   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12510             "CMOV$cmp $dst.hi,$src.hi" %}
 12511   opcode(0x0F,0x40);
 12512   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 12513   ins_pipe( pipe_cmov_reg_long );
 12514 %}
 12516 // Compare 2 longs and CMOVE ints.
 12517 instruct cmovII_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, rRegI dst, rRegI src) %{
 12518   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 ));
 12519   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 12520   ins_cost(200);
 12521   format %{ "CMOV$cmp $dst,$src" %}
 12522   opcode(0x0F,0x40);
 12523   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12524   ins_pipe( pipe_cmov_reg );
 12525 %}
 12527 instruct cmovII_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, rRegI dst, memory src) %{
 12528   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 ));
 12529   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 12530   ins_cost(250);
 12531   format %{ "CMOV$cmp $dst,$src" %}
 12532   opcode(0x0F,0x40);
 12533   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 12534   ins_pipe( pipe_cmov_mem );
 12535 %}
 12537 // Compare 2 longs and CMOVE ints.
 12538 instruct cmovPP_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegP dst, eRegP src) %{
 12539   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 ));
 12540   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 12541   ins_cost(200);
 12542   format %{ "CMOV$cmp $dst,$src" %}
 12543   opcode(0x0F,0x40);
 12544   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12545   ins_pipe( pipe_cmov_reg );
 12546 %}
 12548 // Compare 2 longs and CMOVE doubles
 12549 instruct cmovDDPR_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regDPR dst, regDPR src) %{
 12550   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 );
 12551   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12552   ins_cost(200);
 12553   expand %{
 12554     fcmovDPR_regS(cmp,flags,dst,src);
 12555   %}
 12556 %}
 12558 // Compare 2 longs and CMOVE doubles
 12559 instruct cmovDD_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regD dst, regD src) %{
 12560   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 );
 12561   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12562   ins_cost(200);
 12563   expand %{
 12564     fcmovD_regS(cmp,flags,dst,src);
 12565   %}
 12566 %}
 12568 instruct cmovFFPR_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regFPR dst, regFPR src) %{
 12569   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 );
 12570   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12571   ins_cost(200);
 12572   expand %{
 12573     fcmovFPR_regS(cmp,flags,dst,src);
 12574   %}
 12575 %}
 12577 instruct cmovFF_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regF dst, regF src) %{
 12578   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 );
 12579   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12580   ins_cost(200);
 12581   expand %{
 12582     fcmovF_regS(cmp,flags,dst,src);
 12583   %}
 12584 %}
 12586 //======
 12587 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
 12588 instruct cmpL_zero_flags_EQNE( flagsReg_long_EQNE flags, eRegL src, immL0 zero, rRegI tmp ) %{
 12589   match( Set flags (CmpL src zero ));
 12590   effect(TEMP tmp);
 12591   ins_cost(200);
 12592   format %{ "MOV    $tmp,$src.lo\n\t"
 12593             "OR     $tmp,$src.hi\t! Long is EQ/NE 0?" %}
 12594   ins_encode( long_cmp_flags0( src, tmp ) );
 12595   ins_pipe( ialu_reg_reg_long );
 12596 %}
 12598 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
 12599 instruct cmpL_reg_flags_EQNE( flagsReg_long_EQNE flags, eRegL src1, eRegL src2 ) %{
 12600   match( Set flags (CmpL src1 src2 ));
 12601   ins_cost(200+300);
 12602   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
 12603             "JNE,s  skip\n\t"
 12604             "CMP    $src1.hi,$src2.hi\n\t"
 12605      "skip:\t" %}
 12606   ins_encode( long_cmp_flags1( src1, src2 ) );
 12607   ins_pipe( ialu_cr_reg_reg );
 12608 %}
 12610 // Long compare reg == zero/reg OR reg != zero/reg
 12611 // Just a wrapper for a normal branch, plus the predicate test.
 12612 instruct cmpL_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, label labl) %{
 12613   match(If cmp flags);
 12614   effect(USE labl);
 12615   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
 12616   expand %{
 12617     jmpCon(cmp,flags,labl);    // JEQ or JNE...
 12618   %}
 12619 %}
 12621 // Compare 2 longs and CMOVE longs.
 12622 instruct cmovLL_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, eRegL src) %{
 12623   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 12624   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 ));
 12625   ins_cost(400);
 12626   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12627             "CMOV$cmp $dst.hi,$src.hi" %}
 12628   opcode(0x0F,0x40);
 12629   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 12630   ins_pipe( pipe_cmov_reg_long );
 12631 %}
 12633 instruct cmovLL_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, load_long_memory src) %{
 12634   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 12635   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 ));
 12636   ins_cost(500);
 12637   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12638             "CMOV$cmp $dst.hi,$src.hi" %}
 12639   opcode(0x0F,0x40);
 12640   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 12641   ins_pipe( pipe_cmov_reg_long );
 12642 %}
 12644 // Compare 2 longs and CMOVE ints.
 12645 instruct cmovII_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, rRegI dst, rRegI src) %{
 12646   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 ));
 12647   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 12648   ins_cost(200);
 12649   format %{ "CMOV$cmp $dst,$src" %}
 12650   opcode(0x0F,0x40);
 12651   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12652   ins_pipe( pipe_cmov_reg );
 12653 %}
 12655 instruct cmovII_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, rRegI dst, memory src) %{
 12656   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 ));
 12657   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 12658   ins_cost(250);
 12659   format %{ "CMOV$cmp $dst,$src" %}
 12660   opcode(0x0F,0x40);
 12661   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 12662   ins_pipe( pipe_cmov_mem );
 12663 %}
 12665 // Compare 2 longs and CMOVE ints.
 12666 instruct cmovPP_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegP dst, eRegP src) %{
 12667   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 ));
 12668   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 12669   ins_cost(200);
 12670   format %{ "CMOV$cmp $dst,$src" %}
 12671   opcode(0x0F,0x40);
 12672   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12673   ins_pipe( pipe_cmov_reg );
 12674 %}
 12676 // Compare 2 longs and CMOVE doubles
 12677 instruct cmovDDPR_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regDPR dst, regDPR src) %{
 12678   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 );
 12679   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12680   ins_cost(200);
 12681   expand %{
 12682     fcmovDPR_regS(cmp,flags,dst,src);
 12683   %}
 12684 %}
 12686 // Compare 2 longs and CMOVE doubles
 12687 instruct cmovDD_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regD dst, regD src) %{
 12688   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 );
 12689   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12690   ins_cost(200);
 12691   expand %{
 12692     fcmovD_regS(cmp,flags,dst,src);
 12693   %}
 12694 %}
 12696 instruct cmovFFPR_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regFPR dst, regFPR src) %{
 12697   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 );
 12698   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12699   ins_cost(200);
 12700   expand %{
 12701     fcmovFPR_regS(cmp,flags,dst,src);
 12702   %}
 12703 %}
 12705 instruct cmovFF_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regF dst, regF src) %{
 12706   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 );
 12707   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12708   ins_cost(200);
 12709   expand %{
 12710     fcmovF_regS(cmp,flags,dst,src);
 12711   %}
 12712 %}
 12714 //======
 12715 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
 12716 // Same as cmpL_reg_flags_LEGT except must negate src
 12717 instruct cmpL_zero_flags_LEGT( flagsReg_long_LEGT flags, eRegL src, immL0 zero, rRegI tmp ) %{
 12718   match( Set flags (CmpL src zero ));
 12719   effect( TEMP tmp );
 12720   ins_cost(300);
 12721   format %{ "XOR    $tmp,$tmp\t# Long compare for -$src < 0, use commuted test\n\t"
 12722             "CMP    $tmp,$src.lo\n\t"
 12723             "SBB    $tmp,$src.hi\n\t" %}
 12724   ins_encode( long_cmp_flags3(src, tmp) );
 12725   ins_pipe( ialu_reg_reg_long );
 12726 %}
 12728 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
 12729 // Same as cmpL_reg_flags_LTGE except operands swapped.  Swapping operands
 12730 // requires a commuted test to get the same result.
 12731 instruct cmpL_reg_flags_LEGT( flagsReg_long_LEGT flags, eRegL src1, eRegL src2, rRegI tmp ) %{
 12732   match( Set flags (CmpL src1 src2 ));
 12733   effect( TEMP tmp );
 12734   ins_cost(300);
 12735   format %{ "CMP    $src2.lo,$src1.lo\t! Long compare, swapped operands, use with commuted test\n\t"
 12736             "MOV    $tmp,$src2.hi\n\t"
 12737             "SBB    $tmp,$src1.hi\t! Compute flags for long compare" %}
 12738   ins_encode( long_cmp_flags2( src2, src1, tmp ) );
 12739   ins_pipe( ialu_cr_reg_reg );
 12740 %}
 12742 // Long compares reg < zero/req OR reg >= zero/req.
 12743 // Just a wrapper for a normal branch, plus the predicate test
 12744 instruct cmpL_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, label labl) %{
 12745   match(If cmp flags);
 12746   effect(USE labl);
 12747   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le );
 12748   ins_cost(300);
 12749   expand %{
 12750     jmpCon(cmp,flags,labl);    // JGT or JLE...
 12751   %}
 12752 %}
 12754 // Compare 2 longs and CMOVE longs.
 12755 instruct cmovLL_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, eRegL src) %{
 12756   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 12757   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 ));
 12758   ins_cost(400);
 12759   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12760             "CMOV$cmp $dst.hi,$src.hi" %}
 12761   opcode(0x0F,0x40);
 12762   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 12763   ins_pipe( pipe_cmov_reg_long );
 12764 %}
 12766 instruct cmovLL_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, load_long_memory src) %{
 12767   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 12768   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 ));
 12769   ins_cost(500);
 12770   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 12771             "CMOV$cmp $dst.hi,$src.hi+4" %}
 12772   opcode(0x0F,0x40);
 12773   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 12774   ins_pipe( pipe_cmov_reg_long );
 12775 %}
 12777 // Compare 2 longs and CMOVE ints.
 12778 instruct cmovII_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, rRegI dst, rRegI src) %{
 12779   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 ));
 12780   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 12781   ins_cost(200);
 12782   format %{ "CMOV$cmp $dst,$src" %}
 12783   opcode(0x0F,0x40);
 12784   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12785   ins_pipe( pipe_cmov_reg );
 12786 %}
 12788 instruct cmovII_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, rRegI dst, memory src) %{
 12789   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 ));
 12790   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 12791   ins_cost(250);
 12792   format %{ "CMOV$cmp $dst,$src" %}
 12793   opcode(0x0F,0x40);
 12794   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 12795   ins_pipe( pipe_cmov_mem );
 12796 %}
 12798 // Compare 2 longs and CMOVE ptrs.
 12799 instruct cmovPP_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegP dst, eRegP src) %{
 12800   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 ));
 12801   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 12802   ins_cost(200);
 12803   format %{ "CMOV$cmp $dst,$src" %}
 12804   opcode(0x0F,0x40);
 12805   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 12806   ins_pipe( pipe_cmov_reg );
 12807 %}
 12809 // Compare 2 longs and CMOVE doubles
 12810 instruct cmovDDPR_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regDPR dst, regDPR src) %{
 12811   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 );
 12812   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12813   ins_cost(200);
 12814   expand %{
 12815     fcmovDPR_regS(cmp,flags,dst,src);
 12816   %}
 12817 %}
 12819 // Compare 2 longs and CMOVE doubles
 12820 instruct cmovDD_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regD dst, regD src) %{
 12821   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 );
 12822   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 12823   ins_cost(200);
 12824   expand %{
 12825     fcmovD_regS(cmp,flags,dst,src);
 12826   %}
 12827 %}
 12829 instruct cmovFFPR_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regFPR dst, regFPR src) %{
 12830   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 );
 12831   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12832   ins_cost(200);
 12833   expand %{
 12834     fcmovFPR_regS(cmp,flags,dst,src);
 12835   %}
 12836 %}
 12839 instruct cmovFF_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regF dst, regF src) %{
 12840   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 );
 12841   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 12842   ins_cost(200);
 12843   expand %{
 12844     fcmovF_regS(cmp,flags,dst,src);
 12845   %}
 12846 %}
 12849 // ============================================================================
 12850 // Procedure Call/Return Instructions
 12851 // Call Java Static Instruction
 12852 // Note: If this code changes, the corresponding ret_addr_offset() and
 12853 //       compute_padding() functions will have to be adjusted.
 12854 instruct CallStaticJavaDirect(method meth) %{
 12855   match(CallStaticJava);
 12856   predicate(! ((CallStaticJavaNode*)n)->is_method_handle_invoke());
 12857   effect(USE meth);
 12859   ins_cost(300);
 12860   format %{ "CALL,static " %}
 12861   opcode(0xE8); /* E8 cd */
 12862   ins_encode( pre_call_resets,
 12863               Java_Static_Call( meth ),
 12864               call_epilog,
 12865               post_call_FPU );
 12866   ins_pipe( pipe_slow );
 12867   ins_alignment(4);
 12868 %}
 12870 // Call Java Static Instruction (method handle version)
 12871 // Note: If this code changes, the corresponding ret_addr_offset() and
 12872 //       compute_padding() functions will have to be adjusted.
 12873 instruct CallStaticJavaHandle(method meth, eBPRegP ebp_mh_SP_save) %{
 12874   match(CallStaticJava);
 12875   predicate(((CallStaticJavaNode*)n)->is_method_handle_invoke());
 12876   effect(USE meth);
 12877   // EBP is saved by all callees (for interpreter stack correction).
 12878   // We use it here for a similar purpose, in {preserve,restore}_SP.
 12880   ins_cost(300);
 12881   format %{ "CALL,static/MethodHandle " %}
 12882   opcode(0xE8); /* E8 cd */
 12883   ins_encode( pre_call_resets,
 12884               preserve_SP,
 12885               Java_Static_Call( meth ),
 12886               restore_SP,
 12887               call_epilog,
 12888               post_call_FPU );
 12889   ins_pipe( pipe_slow );
 12890   ins_alignment(4);
 12891 %}
 12893 // Call Java Dynamic Instruction
 12894 // Note: If this code changes, the corresponding ret_addr_offset() and
 12895 //       compute_padding() functions will have to be adjusted.
 12896 instruct CallDynamicJavaDirect(method meth) %{
 12897   match(CallDynamicJava);
 12898   effect(USE meth);
 12900   ins_cost(300);
 12901   format %{ "MOV    EAX,(oop)-1\n\t"
 12902             "CALL,dynamic" %}
 12903   opcode(0xE8); /* E8 cd */
 12904   ins_encode( pre_call_resets,
 12905               Java_Dynamic_Call( meth ),
 12906               call_epilog,
 12907               post_call_FPU );
 12908   ins_pipe( pipe_slow );
 12909   ins_alignment(4);
 12910 %}
 12912 // Call Runtime Instruction
 12913 instruct CallRuntimeDirect(method meth) %{
 12914   match(CallRuntime );
 12915   effect(USE meth);
 12917   ins_cost(300);
 12918   format %{ "CALL,runtime " %}
 12919   opcode(0xE8); /* E8 cd */
 12920   // Use FFREEs to clear entries in float stack
 12921   ins_encode( pre_call_resets,
 12922               FFree_Float_Stack_All,
 12923               Java_To_Runtime( meth ),
 12924               post_call_FPU );
 12925   ins_pipe( pipe_slow );
 12926 %}
 12928 // Call runtime without safepoint
 12929 instruct CallLeafDirect(method meth) %{
 12930   match(CallLeaf);
 12931   effect(USE meth);
 12933   ins_cost(300);
 12934   format %{ "CALL_LEAF,runtime " %}
 12935   opcode(0xE8); /* E8 cd */
 12936   ins_encode( pre_call_resets,
 12937               FFree_Float_Stack_All,
 12938               Java_To_Runtime( meth ),
 12939               Verify_FPU_For_Leaf, post_call_FPU );
 12940   ins_pipe( pipe_slow );
 12941 %}
 12943 instruct CallLeafNoFPDirect(method meth) %{
 12944   match(CallLeafNoFP);
 12945   effect(USE meth);
 12947   ins_cost(300);
 12948   format %{ "CALL_LEAF_NOFP,runtime " %}
 12949   opcode(0xE8); /* E8 cd */
 12950   ins_encode(Java_To_Runtime(meth));
 12951   ins_pipe( pipe_slow );
 12952 %}
 12955 // Return Instruction
 12956 // Remove the return address & jump to it.
 12957 instruct Ret() %{
 12958   match(Return);
 12959   format %{ "RET" %}
 12960   opcode(0xC3);
 12961   ins_encode(OpcP);
 12962   ins_pipe( pipe_jmp );
 12963 %}
 12965 // Tail Call; Jump from runtime stub to Java code.
 12966 // Also known as an 'interprocedural jump'.
 12967 // Target of jump will eventually return to caller.
 12968 // TailJump below removes the return address.
 12969 instruct TailCalljmpInd(eRegP_no_EBP jump_target, eBXRegP method_oop) %{
 12970   match(TailCall jump_target method_oop );
 12971   ins_cost(300);
 12972   format %{ "JMP    $jump_target \t# EBX holds method oop" %}
 12973   opcode(0xFF, 0x4);  /* Opcode FF /4 */
 12974   ins_encode( OpcP, RegOpc(jump_target) );
 12975   ins_pipe( pipe_jmp );
 12976 %}
 12979 // Tail Jump; remove the return address; jump to target.
 12980 // TailCall above leaves the return address around.
 12981 instruct tailjmpInd(eRegP_no_EBP jump_target, eAXRegP ex_oop) %{
 12982   match( TailJump jump_target ex_oop );
 12983   ins_cost(300);
 12984   format %{ "POP    EDX\t# pop return address into dummy\n\t"
 12985             "JMP    $jump_target " %}
 12986   opcode(0xFF, 0x4);  /* Opcode FF /4 */
 12987   ins_encode( enc_pop_rdx,
 12988               OpcP, RegOpc(jump_target) );
 12989   ins_pipe( pipe_jmp );
 12990 %}
 12992 // Create exception oop: created by stack-crawling runtime code.
 12993 // Created exception is now available to this handler, and is setup
 12994 // just prior to jumping to this handler.  No code emitted.
 12995 instruct CreateException( eAXRegP ex_oop )
 12996 %{
 12997   match(Set ex_oop (CreateEx));
 12999   size(0);
 13000   // use the following format syntax
 13001   format %{ "# exception oop is in EAX; no code emitted" %}
 13002   ins_encode();
 13003   ins_pipe( empty );
 13004 %}
 13007 // Rethrow exception:
 13008 // The exception oop will come in the first argument position.
 13009 // Then JUMP (not call) to the rethrow stub code.
 13010 instruct RethrowException()
 13011 %{
 13012   match(Rethrow);
 13014   // use the following format syntax
 13015   format %{ "JMP    rethrow_stub" %}
 13016   ins_encode(enc_rethrow);
 13017   ins_pipe( pipe_jmp );
 13018 %}
 13020 // inlined locking and unlocking
 13023 instruct cmpFastLock( eFlagsReg cr, eRegP object, eBXRegP box, eAXRegI tmp, eRegP scr) %{
 13024   match( Set cr (FastLock object box) );
 13025   effect( TEMP tmp, TEMP scr, USE_KILL box );
 13026   ins_cost(300);
 13027   format %{ "FASTLOCK $object,$box\t! kills $box,$tmp,$scr" %}
 13028   ins_encode( Fast_Lock(object,box,tmp,scr) );
 13029   ins_pipe( pipe_slow );
 13030 %}
 13032 instruct cmpFastUnlock( eFlagsReg cr, eRegP object, eAXRegP box, eRegP tmp ) %{
 13033   match( Set cr (FastUnlock object box) );
 13034   effect( TEMP tmp, USE_KILL box );
 13035   ins_cost(300);
 13036   format %{ "FASTUNLOCK $object,$box\t! kills $box,$tmp" %}
 13037   ins_encode( Fast_Unlock(object,box,tmp) );
 13038   ins_pipe( pipe_slow );
 13039 %}
 13043 // ============================================================================
 13044 // Safepoint Instruction
 13045 instruct safePoint_poll(eFlagsReg cr) %{
 13046   match(SafePoint);
 13047   effect(KILL cr);
 13049   // TODO-FIXME: we currently poll at offset 0 of the safepoint polling page.
 13050   // On SPARC that might be acceptable as we can generate the address with
 13051   // just a sethi, saving an or.  By polling at offset 0 we can end up
 13052   // putting additional pressure on the index-0 in the D$.  Because of
 13053   // alignment (just like the situation at hand) the lower indices tend
 13054   // to see more traffic.  It'd be better to change the polling address
 13055   // to offset 0 of the last $line in the polling page.
 13057   format %{ "TSTL   #polladdr,EAX\t! Safepoint: poll for GC" %}
 13058   ins_cost(125);
 13059   size(6) ;
 13060   ins_encode( Safepoint_Poll() );
 13061   ins_pipe( ialu_reg_mem );
 13062 %}
 13065 // ============================================================================
 13066 // This name is KNOWN by the ADLC and cannot be changed.
 13067 // The ADLC forces a 'TypeRawPtr::BOTTOM' output type
 13068 // for this guy.
 13069 instruct tlsLoadP(eRegP dst, eFlagsReg cr) %{
 13070   match(Set dst (ThreadLocal));
 13071   effect(DEF dst, KILL cr);
 13073   format %{ "MOV    $dst, Thread::current()" %}
 13074   ins_encode %{
 13075     Register dstReg = as_Register($dst$$reg);
 13076     __ get_thread(dstReg);
 13077   %}
 13078   ins_pipe( ialu_reg_fat );
 13079 %}
 13083 //----------PEEPHOLE RULES-----------------------------------------------------
 13084 // These must follow all instruction definitions as they use the names
 13085 // defined in the instructions definitions.
 13086 //
 13087 // peepmatch ( root_instr_name [preceding_instruction]* );
 13088 //
 13089 // peepconstraint %{
 13090 // (instruction_number.operand_name relational_op instruction_number.operand_name
 13091 //  [, ...] );
 13092 // // instruction numbers are zero-based using left to right order in peepmatch
 13093 //
 13094 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
 13095 // // provide an instruction_number.operand_name for each operand that appears
 13096 // // in the replacement instruction's match rule
 13097 //
 13098 // ---------VM FLAGS---------------------------------------------------------
 13099 //
 13100 // All peephole optimizations can be turned off using -XX:-OptoPeephole
 13101 //
 13102 // Each peephole rule is given an identifying number starting with zero and
 13103 // increasing by one in the order seen by the parser.  An individual peephole
 13104 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
 13105 // on the command-line.
 13106 //
 13107 // ---------CURRENT LIMITATIONS----------------------------------------------
 13108 //
 13109 // Only match adjacent instructions in same basic block
 13110 // Only equality constraints
 13111 // Only constraints between operands, not (0.dest_reg == EAX_enc)
 13112 // Only one replacement instruction
 13113 //
 13114 // ---------EXAMPLE----------------------------------------------------------
 13115 //
 13116 // // pertinent parts of existing instructions in architecture description
 13117 // instruct movI(rRegI dst, rRegI src) %{
 13118 //   match(Set dst (CopyI src));
 13119 // %}
 13120 //
 13121 // instruct incI_eReg(rRegI dst, immI1 src, eFlagsReg cr) %{
 13122 //   match(Set dst (AddI dst src));
 13123 //   effect(KILL cr);
 13124 // %}
 13125 //
 13126 // // Change (inc mov) to lea
 13127 // peephole %{
 13128 //   // increment preceeded by register-register move
 13129 //   peepmatch ( incI_eReg movI );
 13130 //   // require that the destination register of the increment
 13131 //   // match the destination register of the move
 13132 //   peepconstraint ( 0.dst == 1.dst );
 13133 //   // construct a replacement instruction that sets
 13134 //   // the destination to ( move's source register + one )
 13135 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 13136 // %}
 13137 //
 13138 // Implementation no longer uses movX instructions since
 13139 // machine-independent system no longer uses CopyX nodes.
 13140 //
 13141 // peephole %{
 13142 //   peepmatch ( incI_eReg movI );
 13143 //   peepconstraint ( 0.dst == 1.dst );
 13144 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 13145 // %}
 13146 //
 13147 // peephole %{
 13148 //   peepmatch ( decI_eReg movI );
 13149 //   peepconstraint ( 0.dst == 1.dst );
 13150 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 13151 // %}
 13152 //
 13153 // peephole %{
 13154 //   peepmatch ( addI_eReg_imm movI );
 13155 //   peepconstraint ( 0.dst == 1.dst );
 13156 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 13157 // %}
 13158 //
 13159 // peephole %{
 13160 //   peepmatch ( addP_eReg_imm movP );
 13161 //   peepconstraint ( 0.dst == 1.dst );
 13162 //   peepreplace ( leaP_eReg_immI( 0.dst 1.src 0.src ) );
 13163 // %}
 13165 // // Change load of spilled value to only a spill
 13166 // instruct storeI(memory mem, rRegI src) %{
 13167 //   match(Set mem (StoreI mem src));
 13168 // %}
 13169 //
 13170 // instruct loadI(rRegI dst, memory mem) %{
 13171 //   match(Set dst (LoadI mem));
 13172 // %}
 13173 //
 13174 peephole %{
 13175   peepmatch ( loadI storeI );
 13176   peepconstraint ( 1.src == 0.dst, 1.mem == 0.mem );
 13177   peepreplace ( storeI( 1.mem 1.mem 1.src ) );
 13178 %}
 13180 //----------SMARTSPILL RULES---------------------------------------------------
 13181 // These must follow all instruction definitions as they use the names
 13182 // defined in the instructions definitions.

mercurial