src/cpu/x86/vm/x86_32.ad

Tue, 02 Aug 2011 18:36:40 +0200

author
roland
date
Tue, 02 Aug 2011 18:36:40 +0200
changeset 3047
f1c12354c3f7
parent 3040
c7b60b601eb4
child 3049
95134e034042
permissions
-rw-r--r--

7074017: Introduce MemBarAcquireLock/MemBarReleaseLock nodes for monitor enter/exit code paths
Summary: replace MemBarAcquire/MemBarRelease nodes on the monitor enter/exit code paths with new MemBarAcquireLock/MemBarReleaseLock nodes
Reviewed-by: kvn, twisti

     1 //
     2 // Copyright (c) 1997, 2011, 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 // Special Registers
    78 reg_def EFLAGS(SOC, SOC, 0, 8, VMRegImpl::Bad());
    80 // Float registers.  We treat TOS/FPR0 special.  It is invisible to the
    81 // allocator, and only shows up in the encodings.
    82 reg_def FPR0L( SOC, SOC, Op_RegF, 0, VMRegImpl::Bad());
    83 reg_def FPR0H( SOC, SOC, Op_RegF, 0, VMRegImpl::Bad());
    84 // Ok so here's the trick FPR1 is really st(0) except in the midst
    85 // of emission of assembly for a machnode. During the emission the fpu stack
    86 // is pushed making FPR1 == st(1) temporarily. However at any safepoint
    87 // the stack will not have this element so FPR1 == st(0) from the
    88 // oopMap viewpoint. This same weirdness with numbering causes
    89 // instruction encoding to have to play games with the register
    90 // encode to correct for this 0/1 issue. See MachSpillCopyNode::implementation
    91 // where it does flt->flt moves to see an example
    92 //
    93 reg_def FPR1L( SOC, SOC, Op_RegF, 1, as_FloatRegister(0)->as_VMReg());
    94 reg_def FPR1H( SOC, SOC, Op_RegF, 1, as_FloatRegister(0)->as_VMReg()->next());
    95 reg_def FPR2L( SOC, SOC, Op_RegF, 2, as_FloatRegister(1)->as_VMReg());
    96 reg_def FPR2H( SOC, SOC, Op_RegF, 2, as_FloatRegister(1)->as_VMReg()->next());
    97 reg_def FPR3L( SOC, SOC, Op_RegF, 3, as_FloatRegister(2)->as_VMReg());
    98 reg_def FPR3H( SOC, SOC, Op_RegF, 3, as_FloatRegister(2)->as_VMReg()->next());
    99 reg_def FPR4L( SOC, SOC, Op_RegF, 4, as_FloatRegister(3)->as_VMReg());
   100 reg_def FPR4H( SOC, SOC, Op_RegF, 4, as_FloatRegister(3)->as_VMReg()->next());
   101 reg_def FPR5L( SOC, SOC, Op_RegF, 5, as_FloatRegister(4)->as_VMReg());
   102 reg_def FPR5H( SOC, SOC, Op_RegF, 5, as_FloatRegister(4)->as_VMReg()->next());
   103 reg_def FPR6L( SOC, SOC, Op_RegF, 6, as_FloatRegister(5)->as_VMReg());
   104 reg_def FPR6H( SOC, SOC, Op_RegF, 6, as_FloatRegister(5)->as_VMReg()->next());
   105 reg_def FPR7L( SOC, SOC, Op_RegF, 7, as_FloatRegister(6)->as_VMReg());
   106 reg_def FPR7H( SOC, SOC, Op_RegF, 7, as_FloatRegister(6)->as_VMReg()->next());
   108 // XMM registers.  128-bit registers or 4 words each, labeled a-d.
   109 // Word a in each register holds a Float, words ab hold a Double.
   110 // We currently do not use the SIMD capabilities, so registers cd
   111 // are unused at the moment.
   112 reg_def XMM0a( SOC, SOC, Op_RegF, 0, xmm0->as_VMReg());
   113 reg_def XMM0b( SOC, SOC, Op_RegF, 0, xmm0->as_VMReg()->next());
   114 reg_def XMM1a( SOC, SOC, Op_RegF, 1, xmm1->as_VMReg());
   115 reg_def XMM1b( SOC, SOC, Op_RegF, 1, xmm1->as_VMReg()->next());
   116 reg_def XMM2a( SOC, SOC, Op_RegF, 2, xmm2->as_VMReg());
   117 reg_def XMM2b( SOC, SOC, Op_RegF, 2, xmm2->as_VMReg()->next());
   118 reg_def XMM3a( SOC, SOC, Op_RegF, 3, xmm3->as_VMReg());
   119 reg_def XMM3b( SOC, SOC, Op_RegF, 3, xmm3->as_VMReg()->next());
   120 reg_def XMM4a( SOC, SOC, Op_RegF, 4, xmm4->as_VMReg());
   121 reg_def XMM4b( SOC, SOC, Op_RegF, 4, xmm4->as_VMReg()->next());
   122 reg_def XMM5a( SOC, SOC, Op_RegF, 5, xmm5->as_VMReg());
   123 reg_def XMM5b( SOC, SOC, Op_RegF, 5, xmm5->as_VMReg()->next());
   124 reg_def XMM6a( SOC, SOC, Op_RegF, 6, xmm6->as_VMReg());
   125 reg_def XMM6b( SOC, SOC, Op_RegF, 6, xmm6->as_VMReg()->next());
   126 reg_def XMM7a( SOC, SOC, Op_RegF, 7, xmm7->as_VMReg());
   127 reg_def XMM7b( SOC, SOC, Op_RegF, 7, xmm7->as_VMReg()->next());
   129 // Specify priority of register selection within phases of register
   130 // allocation.  Highest priority is first.  A useful heuristic is to
   131 // give registers a low priority when they are required by machine
   132 // instructions, like EAX and EDX.  Registers which are used as
   133 // pairs must fall on an even boundary (witness the FPR#L's in this list).
   134 // For the Intel integer registers, the equivalent Long pairs are
   135 // EDX:EAX, EBX:ECX, and EDI:EBP.
   136 alloc_class chunk0( ECX,   EBX,   EBP,   EDI,   EAX,   EDX,   ESI, ESP,
   137                     FPR0L, FPR0H, FPR1L, FPR1H, FPR2L, FPR2H,
   138                     FPR3L, FPR3H, FPR4L, FPR4H, FPR5L, FPR5H,
   139                     FPR6L, FPR6H, FPR7L, FPR7H );
   141 alloc_class chunk1( XMM0a, XMM0b,
   142                     XMM1a, XMM1b,
   143                     XMM2a, XMM2b,
   144                     XMM3a, XMM3b,
   145                     XMM4a, XMM4b,
   146                     XMM5a, XMM5b,
   147                     XMM6a, XMM6b,
   148                     XMM7a, XMM7b, EFLAGS);
   151 //----------Architecture Description Register Classes--------------------------
   152 // Several register classes are automatically defined based upon information in
   153 // this architecture description.
   154 // 1) reg_class inline_cache_reg           ( /* as def'd in frame section */ )
   155 // 2) reg_class compiler_method_oop_reg    ( /* as def'd in frame section */ )
   156 // 2) reg_class interpreter_method_oop_reg ( /* as def'd in frame section */ )
   157 // 3) reg_class stack_slots( /* one chunk of stack-based "registers" */ )
   158 //
   159 // Class for all registers
   160 reg_class any_reg(EAX, EDX, EBP, EDI, ESI, ECX, EBX, ESP);
   161 // Class for general registers
   162 reg_class e_reg(EAX, EDX, EBP, EDI, ESI, ECX, EBX);
   163 // Class for general registers which may be used for implicit null checks on win95
   164 // Also safe for use by tailjump. We don't want to allocate in rbp,
   165 reg_class e_reg_no_rbp(EAX, EDX, EDI, ESI, ECX, EBX);
   166 // Class of "X" registers
   167 reg_class x_reg(EBX, ECX, EDX, EAX);
   168 // Class of registers that can appear in an address with no offset.
   169 // EBP and ESP require an extra instruction byte for zero offset.
   170 // Used in fast-unlock
   171 reg_class p_reg(EDX, EDI, ESI, EBX);
   172 // Class for general registers not including ECX
   173 reg_class ncx_reg(EAX, EDX, EBP, EDI, ESI, EBX);
   174 // Class for general registers not including EAX
   175 reg_class nax_reg(EDX, EDI, ESI, ECX, EBX);
   176 // Class for general registers not including EAX or EBX.
   177 reg_class nabx_reg(EDX, EDI, ESI, ECX, EBP);
   178 // Class of EAX (for multiply and divide operations)
   179 reg_class eax_reg(EAX);
   180 // Class of EBX (for atomic add)
   181 reg_class ebx_reg(EBX);
   182 // Class of ECX (for shift and JCXZ operations and cmpLTMask)
   183 reg_class ecx_reg(ECX);
   184 // Class of EDX (for multiply and divide operations)
   185 reg_class edx_reg(EDX);
   186 // Class of EDI (for synchronization)
   187 reg_class edi_reg(EDI);
   188 // Class of ESI (for synchronization)
   189 reg_class esi_reg(ESI);
   190 // Singleton class for interpreter's stack pointer
   191 reg_class ebp_reg(EBP);
   192 // Singleton class for stack pointer
   193 reg_class sp_reg(ESP);
   194 // Singleton class for instruction pointer
   195 // reg_class ip_reg(EIP);
   196 // Singleton class for condition codes
   197 reg_class int_flags(EFLAGS);
   198 // Class of integer register pairs
   199 reg_class long_reg( EAX,EDX, ECX,EBX, EBP,EDI );
   200 // Class of integer register pairs that aligns with calling convention
   201 reg_class eadx_reg( EAX,EDX );
   202 reg_class ebcx_reg( ECX,EBX );
   203 // Not AX or DX, used in divides
   204 reg_class nadx_reg( EBX,ECX,ESI,EDI,EBP );
   206 // Floating point registers.  Notice FPR0 is not a choice.
   207 // FPR0 is not ever allocated; we use clever encodings to fake
   208 // a 2-address instructions out of Intels FP stack.
   209 reg_class flt_reg( FPR1L,FPR2L,FPR3L,FPR4L,FPR5L,FPR6L,FPR7L );
   211 // make a register class for SSE registers
   212 reg_class xmm_reg(XMM0a, XMM1a, XMM2a, XMM3a, XMM4a, XMM5a, XMM6a, XMM7a);
   214 // make a double register class for SSE2 registers
   215 reg_class xdb_reg(XMM0a,XMM0b, XMM1a,XMM1b, XMM2a,XMM2b, XMM3a,XMM3b,
   216                   XMM4a,XMM4b, XMM5a,XMM5b, XMM6a,XMM6b, XMM7a,XMM7b );
   218 reg_class dbl_reg( FPR1L,FPR1H, FPR2L,FPR2H, FPR3L,FPR3H,
   219                    FPR4L,FPR4H, FPR5L,FPR5H, FPR6L,FPR6H,
   220                    FPR7L,FPR7H );
   222 reg_class flt_reg0( FPR1L );
   223 reg_class dbl_reg0( FPR1L,FPR1H );
   224 reg_class dbl_reg1( FPR2L,FPR2H );
   225 reg_class dbl_notreg0( FPR2L,FPR2H, FPR3L,FPR3H, FPR4L,FPR4H,
   226                        FPR5L,FPR5H, FPR6L,FPR6H, FPR7L,FPR7H );
   228 // XMM6 and XMM7 could be used as temporary registers for long, float and
   229 // double values for SSE2.
   230 reg_class xdb_reg6( XMM6a,XMM6b );
   231 reg_class xdb_reg7( XMM7a,XMM7b );
   232 %}
   235 //----------SOURCE BLOCK-------------------------------------------------------
   236 // This is a block of C++ code which provides values, functions, and
   237 // definitions necessary in the rest of the architecture description
   238 source_hpp %{
   239 // Must be visible to the DFA in dfa_x86_32.cpp
   240 extern bool is_operand_hi32_zero(Node* n);
   241 %}
   243 source %{
   244 #define   RELOC_IMM32    Assembler::imm_operand
   245 #define   RELOC_DISP32   Assembler::disp32_operand
   247 #define __ _masm.
   249 // How to find the high register of a Long pair, given the low register
   250 #define   HIGH_FROM_LOW(x) ((x)+2)
   252 // These masks are used to provide 128-bit aligned bitmasks to the XMM
   253 // instructions, to allow sign-masking or sign-bit flipping.  They allow
   254 // fast versions of NegF/NegD and AbsF/AbsD.
   256 // Note: 'double' and 'long long' have 32-bits alignment on x86.
   257 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) {
   258   // Use the expression (adr)&(~0xF) to provide 128-bits aligned address
   259   // of 128-bits operands for SSE instructions.
   260   jlong *operand = (jlong*)(((uintptr_t)adr)&((uintptr_t)(~0xF)));
   261   // Store the value to a 128-bits operand.
   262   operand[0] = lo;
   263   operand[1] = hi;
   264   return operand;
   265 }
   267 // Buffer for 128-bits masks used by SSE instructions.
   268 static jlong fp_signmask_pool[(4+1)*2]; // 4*128bits(data) + 128bits(alignment)
   270 // Static initialization during VM startup.
   271 static jlong *float_signmask_pool  = double_quadword(&fp_signmask_pool[1*2], CONST64(0x7FFFFFFF7FFFFFFF), CONST64(0x7FFFFFFF7FFFFFFF));
   272 static jlong *double_signmask_pool = double_quadword(&fp_signmask_pool[2*2], CONST64(0x7FFFFFFFFFFFFFFF), CONST64(0x7FFFFFFFFFFFFFFF));
   273 static jlong *float_signflip_pool  = double_quadword(&fp_signmask_pool[3*2], CONST64(0x8000000080000000), CONST64(0x8000000080000000));
   274 static jlong *double_signflip_pool = double_quadword(&fp_signmask_pool[4*2], CONST64(0x8000000000000000), CONST64(0x8000000000000000));
   276 // Offset hacking within calls.
   277 static int pre_call_FPU_size() {
   278   if (Compile::current()->in_24_bit_fp_mode())
   279     return 6; // fldcw
   280   return 0;
   281 }
   283 static int preserve_SP_size() {
   284   return LP64_ONLY(1 +) 2;  // [rex,] op, rm(reg/reg)
   285 }
   287 // !!!!! Special hack to get all type of calls to specify the byte offset
   288 //       from the start of the call to the point where the return address
   289 //       will point.
   290 int MachCallStaticJavaNode::ret_addr_offset() {
   291   int offset = 5 + pre_call_FPU_size();  // 5 bytes from start of call to where return address points
   292   if (_method_handle_invoke)
   293     offset += preserve_SP_size();
   294   return offset;
   295 }
   297 int MachCallDynamicJavaNode::ret_addr_offset() {
   298   return 10 + pre_call_FPU_size();  // 10 bytes from start of call to where return address points
   299 }
   301 static int sizeof_FFree_Float_Stack_All = -1;
   303 int MachCallRuntimeNode::ret_addr_offset() {
   304   assert(sizeof_FFree_Float_Stack_All != -1, "must have been emitted already");
   305   return sizeof_FFree_Float_Stack_All + 5 + pre_call_FPU_size();
   306 }
   308 // Indicate if the safepoint node needs the polling page as an input.
   309 // Since x86 does have absolute addressing, it doesn't.
   310 bool SafePointNode::needs_polling_address_input() {
   311   return false;
   312 }
   314 //
   315 // Compute padding required for nodes which need alignment
   316 //
   318 // The address of the call instruction needs to be 4-byte aligned to
   319 // ensure that it does not span a cache line so that it can be patched.
   320 int CallStaticJavaDirectNode::compute_padding(int current_offset) const {
   321   current_offset += pre_call_FPU_size();  // skip fldcw, if any
   322   current_offset += 1;      // skip call opcode byte
   323   return round_to(current_offset, alignment_required()) - current_offset;
   324 }
   326 // The address of the call instruction needs to be 4-byte aligned to
   327 // ensure that it does not span a cache line so that it can be patched.
   328 int CallStaticJavaHandleNode::compute_padding(int current_offset) const {
   329   current_offset += pre_call_FPU_size();  // skip fldcw, if any
   330   current_offset += preserve_SP_size();   // skip mov rbp, rsp
   331   current_offset += 1;      // skip call opcode byte
   332   return round_to(current_offset, alignment_required()) - current_offset;
   333 }
   335 // The address of the call instruction needs to be 4-byte aligned to
   336 // ensure that it does not span a cache line so that it can be patched.
   337 int CallDynamicJavaDirectNode::compute_padding(int current_offset) const {
   338   current_offset += pre_call_FPU_size();  // skip fldcw, if any
   339   current_offset += 5;      // skip MOV instruction
   340   current_offset += 1;      // skip call opcode byte
   341   return round_to(current_offset, alignment_required()) - current_offset;
   342 }
   344 #ifndef PRODUCT
   345 void MachBreakpointNode::format( PhaseRegAlloc *, outputStream* st ) const {
   346   st->print("INT3");
   347 }
   348 #endif
   350 // EMIT_RM()
   351 void emit_rm(CodeBuffer &cbuf, int f1, int f2, int f3) {
   352   unsigned char c = (unsigned char)((f1 << 6) | (f2 << 3) | f3);
   353   cbuf.insts()->emit_int8(c);
   354 }
   356 // EMIT_CC()
   357 void emit_cc(CodeBuffer &cbuf, int f1, int f2) {
   358   unsigned char c = (unsigned char)( f1 | f2 );
   359   cbuf.insts()->emit_int8(c);
   360 }
   362 // EMIT_OPCODE()
   363 void emit_opcode(CodeBuffer &cbuf, int code) {
   364   cbuf.insts()->emit_int8((unsigned char) code);
   365 }
   367 // EMIT_OPCODE() w/ relocation information
   368 void emit_opcode(CodeBuffer &cbuf, int code, relocInfo::relocType reloc, int offset = 0) {
   369   cbuf.relocate(cbuf.insts_mark() + offset, reloc);
   370   emit_opcode(cbuf, code);
   371 }
   373 // EMIT_D8()
   374 void emit_d8(CodeBuffer &cbuf, int d8) {
   375   cbuf.insts()->emit_int8((unsigned char) d8);
   376 }
   378 // EMIT_D16()
   379 void emit_d16(CodeBuffer &cbuf, int d16) {
   380   cbuf.insts()->emit_int16(d16);
   381 }
   383 // EMIT_D32()
   384 void emit_d32(CodeBuffer &cbuf, int d32) {
   385   cbuf.insts()->emit_int32(d32);
   386 }
   388 // emit 32 bit value and construct relocation entry from relocInfo::relocType
   389 void emit_d32_reloc(CodeBuffer &cbuf, int d32, relocInfo::relocType reloc,
   390         int format) {
   391   cbuf.relocate(cbuf.insts_mark(), reloc, format);
   392   cbuf.insts()->emit_int32(d32);
   393 }
   395 // emit 32 bit value and construct relocation entry from RelocationHolder
   396 void emit_d32_reloc(CodeBuffer &cbuf, int d32, RelocationHolder const& rspec,
   397         int format) {
   398 #ifdef ASSERT
   399   if (rspec.reloc()->type() == relocInfo::oop_type && d32 != 0 && d32 != (int)Universe::non_oop_word()) {
   400     assert(oop(d32)->is_oop() && (ScavengeRootsInCode || !oop(d32)->is_scavengable()), "cannot embed scavengable oops in code");
   401   }
   402 #endif
   403   cbuf.relocate(cbuf.insts_mark(), rspec, format);
   404   cbuf.insts()->emit_int32(d32);
   405 }
   407 // Access stack slot for load or store
   408 void store_to_stackslot(CodeBuffer &cbuf, int opcode, int rm_field, int disp) {
   409   emit_opcode( cbuf, opcode );               // (e.g., FILD   [ESP+src])
   410   if( -128 <= disp && disp <= 127 ) {
   411     emit_rm( cbuf, 0x01, rm_field, ESP_enc );  // R/M byte
   412     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);    // SIB byte
   413     emit_d8 (cbuf, disp);     // Displacement  // R/M byte
   414   } else {
   415     emit_rm( cbuf, 0x02, rm_field, ESP_enc );  // R/M byte
   416     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);    // SIB byte
   417     emit_d32(cbuf, disp);     // Displacement  // R/M byte
   418   }
   419 }
   421    // eRegI ereg, memory mem) %{    // emit_reg_mem
   422 void encode_RegMem( CodeBuffer &cbuf, int reg_encoding, int base, int index, int scale, int displace, bool displace_is_oop ) {
   423   // There is no index & no scale, use form without SIB byte
   424   if ((index == 0x4) &&
   425       (scale == 0) && (base != ESP_enc)) {
   426     // If no displacement, mode is 0x0; unless base is [EBP]
   427     if ( (displace == 0) && (base != EBP_enc) ) {
   428       emit_rm(cbuf, 0x0, reg_encoding, base);
   429     }
   430     else {                    // If 8-bit displacement, mode 0x1
   431       if ((displace >= -128) && (displace <= 127)
   432           && !(displace_is_oop) ) {
   433         emit_rm(cbuf, 0x1, reg_encoding, base);
   434         emit_d8(cbuf, displace);
   435       }
   436       else {                  // If 32-bit displacement
   437         if (base == -1) { // Special flag for absolute address
   438           emit_rm(cbuf, 0x0, reg_encoding, 0x5);
   439           // (manual lies; no SIB needed here)
   440           if ( displace_is_oop ) {
   441             emit_d32_reloc(cbuf, displace, relocInfo::oop_type, 1);
   442           } else {
   443             emit_d32      (cbuf, displace);
   444           }
   445         }
   446         else {                // Normal base + offset
   447           emit_rm(cbuf, 0x2, reg_encoding, base);
   448           if ( displace_is_oop ) {
   449             emit_d32_reloc(cbuf, displace, relocInfo::oop_type, 1);
   450           } else {
   451             emit_d32      (cbuf, displace);
   452           }
   453         }
   454       }
   455     }
   456   }
   457   else {                      // Else, encode with the SIB byte
   458     // If no displacement, mode is 0x0; unless base is [EBP]
   459     if (displace == 0 && (base != EBP_enc)) {  // If no displacement
   460       emit_rm(cbuf, 0x0, reg_encoding, 0x4);
   461       emit_rm(cbuf, scale, index, base);
   462     }
   463     else {                    // If 8-bit displacement, mode 0x1
   464       if ((displace >= -128) && (displace <= 127)
   465           && !(displace_is_oop) ) {
   466         emit_rm(cbuf, 0x1, reg_encoding, 0x4);
   467         emit_rm(cbuf, scale, index, base);
   468         emit_d8(cbuf, displace);
   469       }
   470       else {                  // If 32-bit displacement
   471         if (base == 0x04 ) {
   472           emit_rm(cbuf, 0x2, reg_encoding, 0x4);
   473           emit_rm(cbuf, scale, index, 0x04);
   474         } else {
   475           emit_rm(cbuf, 0x2, reg_encoding, 0x4);
   476           emit_rm(cbuf, scale, index, base);
   477         }
   478         if ( displace_is_oop ) {
   479           emit_d32_reloc(cbuf, displace, relocInfo::oop_type, 1);
   480         } else {
   481           emit_d32      (cbuf, displace);
   482         }
   483       }
   484     }
   485   }
   486 }
   489 void encode_Copy( CodeBuffer &cbuf, int dst_encoding, int src_encoding ) {
   490   if( dst_encoding == src_encoding ) {
   491     // reg-reg copy, use an empty encoding
   492   } else {
   493     emit_opcode( cbuf, 0x8B );
   494     emit_rm(cbuf, 0x3, dst_encoding, src_encoding );
   495   }
   496 }
   498 void encode_CopyXD( CodeBuffer &cbuf, int dst_encoding, int src_encoding ) {
   499   if( dst_encoding == src_encoding ) {
   500     // reg-reg copy, use an empty encoding
   501   } else {
   502     MacroAssembler _masm(&cbuf);
   504     __ movdqa(as_XMMRegister(dst_encoding), as_XMMRegister(src_encoding));
   505   }
   506 }
   509 //=============================================================================
   510 const bool Matcher::constant_table_absolute_addressing = true;
   511 const RegMask& MachConstantBaseNode::_out_RegMask = RegMask::Empty;
   513 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
   514   // Empty encoding
   515 }
   517 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
   518   return 0;
   519 }
   521 #ifndef PRODUCT
   522 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
   523   st->print("# MachConstantBaseNode (empty encoding)");
   524 }
   525 #endif
   528 //=============================================================================
   529 #ifndef PRODUCT
   530 void MachPrologNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
   531   Compile* C = ra_->C;
   532   if( C->in_24_bit_fp_mode() ) {
   533     st->print("FLDCW  24 bit fpu control word");
   534     st->print_cr(""); st->print("\t");
   535   }
   537   int framesize = C->frame_slots() << LogBytesPerInt;
   538   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   539   // Remove two words for return addr and rbp,
   540   framesize -= 2*wordSize;
   542   // Calls to C2R adapters often do not accept exceptional returns.
   543   // We require that their callers must bang for them.  But be careful, because
   544   // some VM calls (such as call site linkage) can use several kilobytes of
   545   // stack.  But the stack safety zone should account for that.
   546   // See bugs 4446381, 4468289, 4497237.
   547   if (C->need_stack_bang(framesize)) {
   548     st->print_cr("# stack bang"); st->print("\t");
   549   }
   550   st->print_cr("PUSHL  EBP"); st->print("\t");
   552   if( VerifyStackAtCalls ) { // Majik cookie to verify stack depth
   553     st->print("PUSH   0xBADB100D\t# Majik cookie for stack depth check");
   554     st->print_cr(""); st->print("\t");
   555     framesize -= wordSize;
   556   }
   558   if ((C->in_24_bit_fp_mode() || VerifyStackAtCalls ) && framesize < 128 ) {
   559     if (framesize) {
   560       st->print("SUB    ESP,%d\t# Create frame",framesize);
   561     }
   562   } else {
   563     st->print("SUB    ESP,%d\t# Create frame",framesize);
   564   }
   565 }
   566 #endif
   569 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
   570   Compile* C = ra_->C;
   572   if (UseSSE >= 2 && VerifyFPU) {
   573     MacroAssembler masm(&cbuf);
   574     masm.verify_FPU(0, "FPU stack must be clean on entry");
   575   }
   577   // WARNING: Initial instruction MUST be 5 bytes or longer so that
   578   // NativeJump::patch_verified_entry will be able to patch out the entry
   579   // code safely. The fldcw is ok at 6 bytes, the push to verify stack
   580   // depth is ok at 5 bytes, the frame allocation can be either 3 or
   581   // 6 bytes. So if we don't do the fldcw or the push then we must
   582   // use the 6 byte frame allocation even if we have no frame. :-(
   583   // If method sets FPU control word do it now
   584   if( C->in_24_bit_fp_mode() ) {
   585     MacroAssembler masm(&cbuf);
   586     masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
   587   }
   589   int framesize = C->frame_slots() << LogBytesPerInt;
   590   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   591   // Remove two words for return addr and rbp,
   592   framesize -= 2*wordSize;
   594   // Calls to C2R adapters often do not accept exceptional returns.
   595   // We require that their callers must bang for them.  But be careful, because
   596   // some VM calls (such as call site linkage) can use several kilobytes of
   597   // stack.  But the stack safety zone should account for that.
   598   // See bugs 4446381, 4468289, 4497237.
   599   if (C->need_stack_bang(framesize)) {
   600     MacroAssembler masm(&cbuf);
   601     masm.generate_stack_overflow_check(framesize);
   602   }
   604   // We always push rbp, so that on return to interpreter rbp, will be
   605   // restored correctly and we can correct the stack.
   606   emit_opcode(cbuf, 0x50 | EBP_enc);
   608   if( VerifyStackAtCalls ) { // Majik cookie to verify stack depth
   609     emit_opcode(cbuf, 0x68); // push 0xbadb100d
   610     emit_d32(cbuf, 0xbadb100d);
   611     framesize -= wordSize;
   612   }
   614   if ((C->in_24_bit_fp_mode() || VerifyStackAtCalls ) && framesize < 128 ) {
   615     if (framesize) {
   616       emit_opcode(cbuf, 0x83);   // sub  SP,#framesize
   617       emit_rm(cbuf, 0x3, 0x05, ESP_enc);
   618       emit_d8(cbuf, framesize);
   619     }
   620   } else {
   621     emit_opcode(cbuf, 0x81);   // sub  SP,#framesize
   622     emit_rm(cbuf, 0x3, 0x05, ESP_enc);
   623     emit_d32(cbuf, framesize);
   624   }
   625   C->set_frame_complete(cbuf.insts_size());
   627 #ifdef ASSERT
   628   if (VerifyStackAtCalls) {
   629     Label L;
   630     MacroAssembler masm(&cbuf);
   631     masm.push(rax);
   632     masm.mov(rax, rsp);
   633     masm.andptr(rax, StackAlignmentInBytes-1);
   634     masm.cmpptr(rax, StackAlignmentInBytes-wordSize);
   635     masm.pop(rax);
   636     masm.jcc(Assembler::equal, L);
   637     masm.stop("Stack is not properly aligned!");
   638     masm.bind(L);
   639   }
   640 #endif
   642 }
   644 uint MachPrologNode::size(PhaseRegAlloc *ra_) const {
   645   return MachNode::size(ra_); // too many variables; just compute it the hard way
   646 }
   648 int MachPrologNode::reloc() const {
   649   return 0; // a large enough number
   650 }
   652 //=============================================================================
   653 #ifndef PRODUCT
   654 void MachEpilogNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
   655   Compile *C = ra_->C;
   656   int framesize = C->frame_slots() << LogBytesPerInt;
   657   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   658   // Remove two words for return addr and rbp,
   659   framesize -= 2*wordSize;
   661   if( C->in_24_bit_fp_mode() ) {
   662     st->print("FLDCW  standard control word");
   663     st->cr(); st->print("\t");
   664   }
   665   if( framesize ) {
   666     st->print("ADD    ESP,%d\t# Destroy frame",framesize);
   667     st->cr(); st->print("\t");
   668   }
   669   st->print_cr("POPL   EBP"); st->print("\t");
   670   if( do_polling() && C->is_method_compilation() ) {
   671     st->print("TEST   PollPage,EAX\t! Poll Safepoint");
   672     st->cr(); st->print("\t");
   673   }
   674 }
   675 #endif
   677 void MachEpilogNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
   678   Compile *C = ra_->C;
   680   // If method set FPU control word, restore to standard control word
   681   if( C->in_24_bit_fp_mode() ) {
   682     MacroAssembler masm(&cbuf);
   683     masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
   684   }
   686   int framesize = C->frame_slots() << LogBytesPerInt;
   687   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   688   // Remove two words for return addr and rbp,
   689   framesize -= 2*wordSize;
   691   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
   693   if( framesize >= 128 ) {
   694     emit_opcode(cbuf, 0x81); // add  SP, #framesize
   695     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
   696     emit_d32(cbuf, framesize);
   697   }
   698   else if( framesize ) {
   699     emit_opcode(cbuf, 0x83); // add  SP, #framesize
   700     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
   701     emit_d8(cbuf, framesize);
   702   }
   704   emit_opcode(cbuf, 0x58 | EBP_enc);
   706   if( do_polling() && C->is_method_compilation() ) {
   707     cbuf.relocate(cbuf.insts_end(), relocInfo::poll_return_type, 0);
   708     emit_opcode(cbuf,0x85);
   709     emit_rm(cbuf, 0x0, EAX_enc, 0x5); // EAX
   710     emit_d32(cbuf, (intptr_t)os::get_polling_page());
   711   }
   712 }
   714 uint MachEpilogNode::size(PhaseRegAlloc *ra_) const {
   715   Compile *C = ra_->C;
   716   // If method set FPU control word, restore to standard control word
   717   int size = C->in_24_bit_fp_mode() ? 6 : 0;
   718   if( do_polling() && C->is_method_compilation() ) size += 6;
   720   int framesize = C->frame_slots() << LogBytesPerInt;
   721   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   722   // Remove two words for return addr and rbp,
   723   framesize -= 2*wordSize;
   725   size++; // popl rbp,
   727   if( framesize >= 128 ) {
   728     size += 6;
   729   } else {
   730     size += framesize ? 3 : 0;
   731   }
   732   return size;
   733 }
   735 int MachEpilogNode::reloc() const {
   736   return 0; // a large enough number
   737 }
   739 const Pipeline * MachEpilogNode::pipeline() const {
   740   return MachNode::pipeline_class();
   741 }
   743 int MachEpilogNode::safepoint_offset() const { return 0; }
   745 //=============================================================================
   747 enum RC { rc_bad, rc_int, rc_float, rc_xmm, rc_stack };
   748 static enum RC rc_class( OptoReg::Name reg ) {
   750   if( !OptoReg::is_valid(reg)  ) return rc_bad;
   751   if (OptoReg::is_stack(reg)) return rc_stack;
   753   VMReg r = OptoReg::as_VMReg(reg);
   754   if (r->is_Register()) return rc_int;
   755   if (r->is_FloatRegister()) {
   756     assert(UseSSE < 2, "shouldn't be used in SSE2+ mode");
   757     return rc_float;
   758   }
   759   assert(r->is_XMMRegister(), "must be");
   760   return rc_xmm;
   761 }
   763 static int impl_helper( CodeBuffer *cbuf, bool do_size, bool is_load, int offset, int reg,
   764                         int opcode, const char *op_str, int size, outputStream* st ) {
   765   if( cbuf ) {
   766     emit_opcode  (*cbuf, opcode );
   767     encode_RegMem(*cbuf, Matcher::_regEncode[reg], ESP_enc, 0x4, 0, offset, false);
   768 #ifndef PRODUCT
   769   } else if( !do_size ) {
   770     if( size != 0 ) st->print("\n\t");
   771     if( opcode == 0x8B || opcode == 0x89 ) { // MOV
   772       if( is_load ) st->print("%s   %s,[ESP + #%d]",op_str,Matcher::regName[reg],offset);
   773       else          st->print("%s   [ESP + #%d],%s",op_str,offset,Matcher::regName[reg]);
   774     } else { // FLD, FST, PUSH, POP
   775       st->print("%s [ESP + #%d]",op_str,offset);
   776     }
   777 #endif
   778   }
   779   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
   780   return size+3+offset_size;
   781 }
   783 // Helper for XMM registers.  Extra opcode bits, limited syntax.
   784 static int impl_x_helper( CodeBuffer *cbuf, bool do_size, bool is_load,
   785                          int offset, int reg_lo, int reg_hi, int size, outputStream* st ) {
   786   if( cbuf ) {
   787     if( reg_lo+1 == reg_hi ) { // double move?
   788       if( is_load && !UseXmmLoadAndClearUpper )
   789         emit_opcode(*cbuf, 0x66 ); // use 'movlpd' for load
   790       else
   791         emit_opcode(*cbuf, 0xF2 ); // use 'movsd' otherwise
   792     } else {
   793       emit_opcode(*cbuf, 0xF3 );
   794     }
   795     emit_opcode(*cbuf, 0x0F );
   796     if( reg_lo+1 == reg_hi && is_load && !UseXmmLoadAndClearUpper )
   797       emit_opcode(*cbuf, 0x12 );   // use 'movlpd' for load
   798     else
   799       emit_opcode(*cbuf, is_load ? 0x10 : 0x11 );
   800     encode_RegMem(*cbuf, Matcher::_regEncode[reg_lo], ESP_enc, 0x4, 0, offset, false);
   801 #ifndef PRODUCT
   802   } else if( !do_size ) {
   803     if( size != 0 ) st->print("\n\t");
   804     if( reg_lo+1 == reg_hi ) { // double move?
   805       if( is_load ) st->print("%s %s,[ESP + #%d]",
   806                                UseXmmLoadAndClearUpper ? "MOVSD " : "MOVLPD",
   807                                Matcher::regName[reg_lo], offset);
   808       else          st->print("MOVSD  [ESP + #%d],%s",
   809                                offset, Matcher::regName[reg_lo]);
   810     } else {
   811       if( is_load ) st->print("MOVSS  %s,[ESP + #%d]",
   812                                Matcher::regName[reg_lo], offset);
   813       else          st->print("MOVSS  [ESP + #%d],%s",
   814                                offset, Matcher::regName[reg_lo]);
   815     }
   816 #endif
   817   }
   818   int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
   819   return size+5+offset_size;
   820 }
   823 static int impl_movx_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   824                             int src_hi, int dst_hi, int size, outputStream* st ) {
   825   if( UseXmmRegToRegMoveAll ) {//Use movaps,movapd to move between xmm registers
   826     if( cbuf ) {
   827       if( (src_lo+1 == src_hi && dst_lo+1 == dst_hi) ) {
   828         emit_opcode(*cbuf, 0x66 );
   829       }
   830       emit_opcode(*cbuf, 0x0F );
   831       emit_opcode(*cbuf, 0x28 );
   832       emit_rm    (*cbuf, 0x3, Matcher::_regEncode[dst_lo], Matcher::_regEncode[src_lo] );
   833 #ifndef PRODUCT
   834     } else if( !do_size ) {
   835       if( size != 0 ) st->print("\n\t");
   836       if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double move?
   837         st->print("MOVAPD %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   838       } else {
   839         st->print("MOVAPS %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   840       }
   841 #endif
   842     }
   843     return size + ((src_lo+1 == src_hi && dst_lo+1 == dst_hi) ? 4 : 3);
   844   } else {
   845     if( cbuf ) {
   846       emit_opcode(*cbuf, (src_lo+1 == src_hi && dst_lo+1 == dst_hi) ? 0xF2 : 0xF3 );
   847       emit_opcode(*cbuf, 0x0F );
   848       emit_opcode(*cbuf, 0x10 );
   849       emit_rm    (*cbuf, 0x3, Matcher::_regEncode[dst_lo], Matcher::_regEncode[src_lo] );
   850 #ifndef PRODUCT
   851     } else if( !do_size ) {
   852       if( size != 0 ) st->print("\n\t");
   853       if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double move?
   854         st->print("MOVSD  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   855       } else {
   856         st->print("MOVSS  %s,%s",Matcher::regName[dst_lo],Matcher::regName[src_lo]);
   857       }
   858 #endif
   859     }
   860     return size+4;
   861   }
   862 }
   864 static int impl_movgpr2x_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   865                             int src_hi, int dst_hi, int size, outputStream* st ) {
   866   // 32-bit
   867   if (cbuf) {
   868     emit_opcode(*cbuf, 0x66);
   869     emit_opcode(*cbuf, 0x0F);
   870     emit_opcode(*cbuf, 0x6E);
   871     emit_rm(*cbuf, 0x3, Matcher::_regEncode[dst_lo] & 7, Matcher::_regEncode[src_lo] & 7);
   872 #ifndef PRODUCT
   873   } else if (!do_size) {
   874     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
   875 #endif
   876   }
   877   return 4;
   878 }
   881 static int impl_movx2gpr_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int dst_lo,
   882                                  int src_hi, int dst_hi, int size, outputStream* st ) {
   883   // 32-bit
   884   if (cbuf) {
   885     emit_opcode(*cbuf, 0x66);
   886     emit_opcode(*cbuf, 0x0F);
   887     emit_opcode(*cbuf, 0x7E);
   888     emit_rm(*cbuf, 0x3, Matcher::_regEncode[src_lo] & 7, Matcher::_regEncode[dst_lo] & 7);
   889 #ifndef PRODUCT
   890   } else if (!do_size) {
   891     st->print("movdl   %s, %s\t# spill", Matcher::regName[dst_lo], Matcher::regName[src_lo]);
   892 #endif
   893   }
   894   return 4;
   895 }
   897 static int impl_mov_helper( CodeBuffer *cbuf, bool do_size, int src, int dst, int size, outputStream* st ) {
   898   if( cbuf ) {
   899     emit_opcode(*cbuf, 0x8B );
   900     emit_rm    (*cbuf, 0x3, Matcher::_regEncode[dst], Matcher::_regEncode[src] );
   901 #ifndef PRODUCT
   902   } else if( !do_size ) {
   903     if( size != 0 ) st->print("\n\t");
   904     st->print("MOV    %s,%s",Matcher::regName[dst],Matcher::regName[src]);
   905 #endif
   906   }
   907   return size+2;
   908 }
   910 static int impl_fp_store_helper( CodeBuffer *cbuf, bool do_size, int src_lo, int src_hi, int dst_lo, int dst_hi,
   911                                  int offset, int size, outputStream* st ) {
   912   if( src_lo != FPR1L_num ) {      // Move value to top of FP stack, if not already there
   913     if( cbuf ) {
   914       emit_opcode( *cbuf, 0xD9 );  // FLD (i.e., push it)
   915       emit_d8( *cbuf, 0xC0-1+Matcher::_regEncode[src_lo] );
   916 #ifndef PRODUCT
   917     } else if( !do_size ) {
   918       if( size != 0 ) st->print("\n\t");
   919       st->print("FLD    %s",Matcher::regName[src_lo]);
   920 #endif
   921     }
   922     size += 2;
   923   }
   925   int st_op = (src_lo != FPR1L_num) ? EBX_num /*store & pop*/ : EDX_num /*store no pop*/;
   926   const char *op_str;
   927   int op;
   928   if( src_lo+1 == src_hi && dst_lo+1 == dst_hi ) { // double store?
   929     op_str = (src_lo != FPR1L_num) ? "FSTP_D" : "FST_D ";
   930     op = 0xDD;
   931   } else {                   // 32-bit store
   932     op_str = (src_lo != FPR1L_num) ? "FSTP_S" : "FST_S ";
   933     op = 0xD9;
   934     assert( !OptoReg::is_valid(src_hi) && !OptoReg::is_valid(dst_hi), "no non-adjacent float-stores" );
   935   }
   937   return impl_helper(cbuf,do_size,false,offset,st_op,op,op_str,size, st);
   938 }
   940 uint MachSpillCopyNode::implementation( CodeBuffer *cbuf, PhaseRegAlloc *ra_, bool do_size, outputStream* st ) const {
   941   // Get registers to move
   942   OptoReg::Name src_second = ra_->get_reg_second(in(1));
   943   OptoReg::Name src_first = ra_->get_reg_first(in(1));
   944   OptoReg::Name dst_second = ra_->get_reg_second(this );
   945   OptoReg::Name dst_first = ra_->get_reg_first(this );
   947   enum RC src_second_rc = rc_class(src_second);
   948   enum RC src_first_rc = rc_class(src_first);
   949   enum RC dst_second_rc = rc_class(dst_second);
   950   enum RC dst_first_rc = rc_class(dst_first);
   952   assert( OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first), "must move at least 1 register" );
   954   // Generate spill code!
   955   int size = 0;
   957   if( src_first == dst_first && src_second == dst_second )
   958     return size;            // Self copy, no move
   960   // --------------------------------------
   961   // Check for mem-mem move.  push/pop to move.
   962   if( src_first_rc == rc_stack && dst_first_rc == rc_stack ) {
   963     if( src_second == dst_first ) { // overlapping stack copy ranges
   964       assert( src_second_rc == rc_stack && dst_second_rc == rc_stack, "we only expect a stk-stk copy here" );
   965       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
   966       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
   967       src_second_rc = dst_second_rc = rc_bad;  // flag as already moved the second bits
   968     }
   969     // move low bits
   970     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),ESI_num,0xFF,"PUSH  ",size, st);
   971     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),EAX_num,0x8F,"POP   ",size, st);
   972     if( src_second_rc == rc_stack && dst_second_rc == rc_stack ) { // mov second bits
   973       size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),ESI_num,0xFF,"PUSH  ",size, st);
   974       size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),EAX_num,0x8F,"POP   ",size, st);
   975     }
   976     return size;
   977   }
   979   // --------------------------------------
   980   // Check for integer reg-reg copy
   981   if( src_first_rc == rc_int && dst_first_rc == rc_int )
   982     size = impl_mov_helper(cbuf,do_size,src_first,dst_first,size, st);
   984   // Check for integer store
   985   if( src_first_rc == rc_int && dst_first_rc == rc_stack )
   986     size = impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first,0x89,"MOV ",size, st);
   988   // Check for integer load
   989   if( dst_first_rc == rc_int && src_first_rc == rc_stack )
   990     size = impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first,0x8B,"MOV ",size, st);
   992   // Check for integer reg-xmm reg copy
   993   if( src_first_rc == rc_int && dst_first_rc == rc_xmm ) {
   994     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
   995             "no 64 bit integer-float reg moves" );
   996     return impl_movgpr2x_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
   997   }
   998   // --------------------------------------
   999   // Check for float reg-reg copy
  1000   if( src_first_rc == rc_float && dst_first_rc == rc_float ) {
  1001     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
  1002             (src_first+1 == src_second && dst_first+1 == dst_second), "no non-adjacent float-moves" );
  1003     if( cbuf ) {
  1005       // Note the mucking with the register encode to compensate for the 0/1
  1006       // indexing issue mentioned in a comment in the reg_def sections
  1007       // for FPR registers many lines above here.
  1009       if( src_first != FPR1L_num ) {
  1010         emit_opcode  (*cbuf, 0xD9 );           // FLD    ST(i)
  1011         emit_d8      (*cbuf, 0xC0+Matcher::_regEncode[src_first]-1 );
  1012         emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
  1013         emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
  1014      } else {
  1015         emit_opcode  (*cbuf, 0xDD );           // FST    ST(i)
  1016         emit_d8      (*cbuf, 0xD0+Matcher::_regEncode[dst_first]-1 );
  1018 #ifndef PRODUCT
  1019     } else if( !do_size ) {
  1020       if( size != 0 ) st->print("\n\t");
  1021       if( src_first != FPR1L_num ) st->print("FLD    %s\n\tFSTP   %s",Matcher::regName[src_first],Matcher::regName[dst_first]);
  1022       else                      st->print(             "FST    %s",                            Matcher::regName[dst_first]);
  1023 #endif
  1025     return size + ((src_first != FPR1L_num) ? 2+2 : 2);
  1028   // Check for float store
  1029   if( src_first_rc == rc_float && dst_first_rc == rc_stack ) {
  1030     return impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,ra_->reg2offset(dst_first),size, st);
  1033   // Check for float load
  1034   if( dst_first_rc == rc_float && src_first_rc == rc_stack ) {
  1035     int offset = ra_->reg2offset(src_first);
  1036     const char *op_str;
  1037     int op;
  1038     if( src_first+1 == src_second && dst_first+1 == dst_second ) { // double load?
  1039       op_str = "FLD_D";
  1040       op = 0xDD;
  1041     } else {                   // 32-bit load
  1042       op_str = "FLD_S";
  1043       op = 0xD9;
  1044       assert( src_second_rc == rc_bad && dst_second_rc == rc_bad, "no non-adjacent float-loads" );
  1046     if( cbuf ) {
  1047       emit_opcode  (*cbuf, op );
  1048       encode_RegMem(*cbuf, 0x0, ESP_enc, 0x4, 0, offset, false);
  1049       emit_opcode  (*cbuf, 0xDD );           // FSTP   ST(i)
  1050       emit_d8      (*cbuf, 0xD8+Matcher::_regEncode[dst_first] );
  1051 #ifndef PRODUCT
  1052     } else if( !do_size ) {
  1053       if( size != 0 ) st->print("\n\t");
  1054       st->print("%s  ST,[ESP + #%d]\n\tFSTP   %s",op_str, offset,Matcher::regName[dst_first]);
  1055 #endif
  1057     int offset_size = (offset == 0) ? 0 : ((offset <= 127) ? 1 : 4);
  1058     return size + 3+offset_size+2;
  1061   // Check for xmm reg-reg copy
  1062   if( src_first_rc == rc_xmm && dst_first_rc == rc_xmm ) {
  1063     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad) ||
  1064             (src_first+1 == src_second && dst_first+1 == dst_second),
  1065             "no non-adjacent float-moves" );
  1066     return impl_movx_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
  1069   // Check for xmm reg-integer reg copy
  1070   if( src_first_rc == rc_xmm && dst_first_rc == rc_int ) {
  1071     assert( (src_second_rc == rc_bad && dst_second_rc == rc_bad),
  1072             "no 64 bit float-integer reg moves" );
  1073     return impl_movx2gpr_helper(cbuf,do_size,src_first,dst_first,src_second, dst_second, size, st);
  1076   // Check for xmm store
  1077   if( src_first_rc == rc_xmm && dst_first_rc == rc_stack ) {
  1078     return impl_x_helper(cbuf,do_size,false,ra_->reg2offset(dst_first),src_first, src_second, size, st);
  1081   // Check for float xmm load
  1082   if( dst_first_rc == rc_xmm && src_first_rc == rc_stack ) {
  1083     return impl_x_helper(cbuf,do_size,true ,ra_->reg2offset(src_first),dst_first, dst_second, size, st);
  1086   // Copy from float reg to xmm reg
  1087   if( dst_first_rc == rc_xmm && src_first_rc == rc_float ) {
  1088     // copy to the top of stack from floating point reg
  1089     // and use LEA to preserve flags
  1090     if( cbuf ) {
  1091       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP-8]
  1092       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
  1093       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
  1094       emit_d8(*cbuf,0xF8);
  1095 #ifndef PRODUCT
  1096     } else if( !do_size ) {
  1097       if( size != 0 ) st->print("\n\t");
  1098       st->print("LEA    ESP,[ESP-8]");
  1099 #endif
  1101     size += 4;
  1103     size = impl_fp_store_helper(cbuf,do_size,src_first,src_second,dst_first,dst_second,0,size, st);
  1105     // Copy from the temp memory to the xmm reg.
  1106     size = impl_x_helper(cbuf,do_size,true ,0,dst_first, dst_second, size, st);
  1108     if( cbuf ) {
  1109       emit_opcode(*cbuf,0x8D);  // LEA  ESP,[ESP+8]
  1110       emit_rm(*cbuf, 0x1, ESP_enc, 0x04);
  1111       emit_rm(*cbuf, 0x0, 0x04, ESP_enc);
  1112       emit_d8(*cbuf,0x08);
  1113 #ifndef PRODUCT
  1114     } else if( !do_size ) {
  1115       if( size != 0 ) st->print("\n\t");
  1116       st->print("LEA    ESP,[ESP+8]");
  1117 #endif
  1119     size += 4;
  1120     return size;
  1123   assert( size > 0, "missed a case" );
  1125   // --------------------------------------------------------------------
  1126   // Check for second bits still needing moving.
  1127   if( src_second == dst_second )
  1128     return size;               // Self copy; no move
  1129   assert( src_second_rc != rc_bad && dst_second_rc != rc_bad, "src_second & dst_second cannot be Bad" );
  1131   // Check for second word int-int move
  1132   if( src_second_rc == rc_int && dst_second_rc == rc_int )
  1133     return impl_mov_helper(cbuf,do_size,src_second,dst_second,size, st);
  1135   // Check for second word integer store
  1136   if( src_second_rc == rc_int && dst_second_rc == rc_stack )
  1137     return impl_helper(cbuf,do_size,false,ra_->reg2offset(dst_second),src_second,0x89,"MOV ",size, st);
  1139   // Check for second word integer load
  1140   if( dst_second_rc == rc_int && src_second_rc == rc_stack )
  1141     return impl_helper(cbuf,do_size,true ,ra_->reg2offset(src_second),dst_second,0x8B,"MOV ",size, st);
  1144   Unimplemented();
  1147 #ifndef PRODUCT
  1148 void MachSpillCopyNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
  1149   implementation( NULL, ra_, false, st );
  1151 #endif
  1153 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1154   implementation( &cbuf, ra_, false, NULL );
  1157 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const {
  1158   return implementation( NULL, ra_, true, NULL );
  1161 //=============================================================================
  1162 #ifndef PRODUCT
  1163 void MachNopNode::format( PhaseRegAlloc *, outputStream* st ) const {
  1164   st->print("NOP \t# %d bytes pad for loops and calls", _count);
  1166 #endif
  1168 void MachNopNode::emit(CodeBuffer &cbuf, PhaseRegAlloc * ) const {
  1169   MacroAssembler _masm(&cbuf);
  1170   __ nop(_count);
  1173 uint MachNopNode::size(PhaseRegAlloc *) const {
  1174   return _count;
  1178 //=============================================================================
  1179 #ifndef PRODUCT
  1180 void BoxLockNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
  1181   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1182   int reg = ra_->get_reg_first(this);
  1183   st->print("LEA    %s,[ESP + #%d]",Matcher::regName[reg],offset);
  1185 #endif
  1187 void BoxLockNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1188   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1189   int reg = ra_->get_encode(this);
  1190   if( offset >= 128 ) {
  1191     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
  1192     emit_rm(cbuf, 0x2, reg, 0x04);
  1193     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
  1194     emit_d32(cbuf, offset);
  1196   else {
  1197     emit_opcode(cbuf, 0x8D);      // LEA  reg,[SP+offset]
  1198     emit_rm(cbuf, 0x1, reg, 0x04);
  1199     emit_rm(cbuf, 0x0, 0x04, ESP_enc);
  1200     emit_d8(cbuf, offset);
  1204 uint BoxLockNode::size(PhaseRegAlloc *ra_) const {
  1205   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1206   if( offset >= 128 ) {
  1207     return 7;
  1209   else {
  1210     return 4;
  1214 //=============================================================================
  1216 // emit call stub, compiled java to interpreter
  1217 void emit_java_to_interp(CodeBuffer &cbuf ) {
  1218   // Stub is fixed up when the corresponding call is converted from calling
  1219   // compiled code to calling interpreted code.
  1220   // mov rbx,0
  1221   // jmp -1
  1223   address mark = cbuf.insts_mark();  // get mark within main instrs section
  1225   // Note that the code buffer's insts_mark is always relative to insts.
  1226   // That's why we must use the macroassembler to generate a stub.
  1227   MacroAssembler _masm(&cbuf);
  1229   address base =
  1230   __ start_a_stub(Compile::MAX_stubs_size);
  1231   if (base == NULL)  return;  // CodeBuffer::expand failed
  1232   // static stub relocation stores the instruction address of the call
  1233   __ relocate(static_stub_Relocation::spec(mark), RELOC_IMM32);
  1234   // static stub relocation also tags the methodOop in the code-stream.
  1235   __ movoop(rbx, (jobject)NULL);  // method is zapped till fixup time
  1236   // This is recognized as unresolved by relocs/nativeInst/ic code
  1237   __ jump(RuntimeAddress(__ pc()));
  1239   __ end_a_stub();
  1240   // Update current stubs pointer and restore insts_end.
  1242 // size of call stub, compiled java to interpretor
  1243 uint size_java_to_interp() {
  1244   return 10;  // movl; jmp
  1246 // relocation entries for call stub, compiled java to interpretor
  1247 uint reloc_java_to_interp() {
  1248   return 4;  // 3 in emit_java_to_interp + 1 in Java_Static_Call
  1251 //=============================================================================
  1252 #ifndef PRODUCT
  1253 void MachUEPNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
  1254   st->print_cr(  "CMP    EAX,[ECX+4]\t# Inline cache check");
  1255   st->print_cr("\tJNE    SharedRuntime::handle_ic_miss_stub");
  1256   st->print_cr("\tNOP");
  1257   st->print_cr("\tNOP");
  1258   if( !OptoBreakpoint )
  1259     st->print_cr("\tNOP");
  1261 #endif
  1263 void MachUEPNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
  1264   MacroAssembler masm(&cbuf);
  1265 #ifdef ASSERT
  1266   uint insts_size = cbuf.insts_size();
  1267 #endif
  1268   masm.cmpptr(rax, Address(rcx, oopDesc::klass_offset_in_bytes()));
  1269   masm.jump_cc(Assembler::notEqual,
  1270                RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
  1271   /* WARNING these NOPs are critical so that verified entry point is properly
  1272      aligned for patching by NativeJump::patch_verified_entry() */
  1273   int nops_cnt = 2;
  1274   if( !OptoBreakpoint ) // Leave space for int3
  1275      nops_cnt += 1;
  1276   masm.nop(nops_cnt);
  1278   assert(cbuf.insts_size() - insts_size == size(ra_), "checking code size of inline cache node");
  1281 uint MachUEPNode::size(PhaseRegAlloc *ra_) const {
  1282   return OptoBreakpoint ? 11 : 12;
  1286 //=============================================================================
  1287 uint size_exception_handler() {
  1288   // NativeCall instruction size is the same as NativeJump.
  1289   // exception handler starts out as jump and can be patched to
  1290   // a call be deoptimization.  (4932387)
  1291   // Note that this value is also credited (in output.cpp) to
  1292   // the size of the code section.
  1293   return NativeJump::instruction_size;
  1296 // Emit exception handler code.  Stuff framesize into a register
  1297 // and call a VM stub routine.
  1298 int emit_exception_handler(CodeBuffer& cbuf) {
  1300   // Note that the code buffer's insts_mark is always relative to insts.
  1301   // That's why we must use the macroassembler to generate a handler.
  1302   MacroAssembler _masm(&cbuf);
  1303   address base =
  1304   __ start_a_stub(size_exception_handler());
  1305   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1306   int offset = __ offset();
  1307   __ jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
  1308   assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
  1309   __ end_a_stub();
  1310   return offset;
  1313 uint size_deopt_handler() {
  1314   // NativeCall instruction size is the same as NativeJump.
  1315   // exception handler starts out as jump and can be patched to
  1316   // a call be deoptimization.  (4932387)
  1317   // Note that this value is also credited (in output.cpp) to
  1318   // the size of the code section.
  1319   return 5 + NativeJump::instruction_size; // pushl(); jmp;
  1322 // Emit deopt handler code.
  1323 int emit_deopt_handler(CodeBuffer& cbuf) {
  1325   // Note that the code buffer's insts_mark is always relative to insts.
  1326   // That's why we must use the macroassembler to generate a handler.
  1327   MacroAssembler _masm(&cbuf);
  1328   address base =
  1329   __ start_a_stub(size_exception_handler());
  1330   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1331   int offset = __ offset();
  1332   InternalAddress here(__ pc());
  1333   __ pushptr(here.addr());
  1335   __ jump(RuntimeAddress(SharedRuntime::deopt_blob()->unpack()));
  1336   assert(__ offset() - offset <= (int) size_deopt_handler(), "overflow");
  1337   __ end_a_stub();
  1338   return offset;
  1342 const bool Matcher::match_rule_supported(int opcode) {
  1343   if (!has_match_rule(opcode))
  1344     return false;
  1346   return true;  // Per default match rules are supported.
  1349 int Matcher::regnum_to_fpu_offset(int regnum) {
  1350   return regnum - 32; // The FP registers are in the second chunk
  1353 // This is UltraSparc specific, true just means we have fast l2f conversion
  1354 const bool Matcher::convL2FSupported(void) {
  1355   return true;
  1358 // Vector width in bytes
  1359 const uint Matcher::vector_width_in_bytes(void) {
  1360   return UseSSE >= 2 ? 8 : 0;
  1363 // Vector ideal reg
  1364 const uint Matcher::vector_ideal_reg(void) {
  1365   return Op_RegD;
  1368 // Is this branch offset short enough that a short branch can be used?
  1369 //
  1370 // NOTE: If the platform does not provide any short branch variants, then
  1371 //       this method should return false for offset 0.
  1372 bool Matcher::is_short_branch_offset(int rule, int offset) {
  1373   // the short version of jmpConUCF2 contains multiple branches,
  1374   // making the reach slightly less
  1375   if (rule == jmpConUCF2_rule)
  1376     return (-126 <= offset && offset <= 125);
  1377   return (-128 <= offset && offset <= 127);
  1380 const bool Matcher::isSimpleConstant64(jlong value) {
  1381   // Will one (StoreL ConL) be cheaper than two (StoreI ConI)?.
  1382   return false;
  1385 // The ecx parameter to rep stos for the ClearArray node is in dwords.
  1386 const bool Matcher::init_array_count_is_in_bytes = false;
  1388 // Threshold size for cleararray.
  1389 const int Matcher::init_array_short_size = 8 * BytesPerLong;
  1391 // Should the Matcher clone shifts on addressing modes, expecting them to
  1392 // be subsumed into complex addressing expressions or compute them into
  1393 // registers?  True for Intel but false for most RISCs
  1394 const bool Matcher::clone_shift_expressions = true;
  1396 // Do we need to mask the count passed to shift instructions or does
  1397 // the cpu only look at the lower 5/6 bits anyway?
  1398 const bool Matcher::need_masked_shift_count = false;
  1400 bool Matcher::narrow_oop_use_complex_address() {
  1401   ShouldNotCallThis();
  1402   return true;
  1406 // Is it better to copy float constants, or load them directly from memory?
  1407 // Intel can load a float constant from a direct address, requiring no
  1408 // extra registers.  Most RISCs will have to materialize an address into a
  1409 // register first, so they would do better to copy the constant from stack.
  1410 const bool Matcher::rematerialize_float_constants = true;
  1412 // If CPU can load and store mis-aligned doubles directly then no fixup is
  1413 // needed.  Else we split the double into 2 integer pieces and move it
  1414 // piece-by-piece.  Only happens when passing doubles into C code as the
  1415 // Java calling convention forces doubles to be aligned.
  1416 const bool Matcher::misaligned_doubles_ok = true;
  1419 void Matcher::pd_implicit_null_fixup(MachNode *node, uint idx) {
  1420   // Get the memory operand from the node
  1421   uint numopnds = node->num_opnds();        // Virtual call for number of operands
  1422   uint skipped  = node->oper_input_base();  // Sum of leaves skipped so far
  1423   assert( idx >= skipped, "idx too low in pd_implicit_null_fixup" );
  1424   uint opcnt     = 1;                 // First operand
  1425   uint num_edges = node->_opnds[1]->num_edges(); // leaves for first operand
  1426   while( idx >= skipped+num_edges ) {
  1427     skipped += num_edges;
  1428     opcnt++;                          // Bump operand count
  1429     assert( opcnt < numopnds, "Accessing non-existent operand" );
  1430     num_edges = node->_opnds[opcnt]->num_edges(); // leaves for next operand
  1433   MachOper *memory = node->_opnds[opcnt];
  1434   MachOper *new_memory = NULL;
  1435   switch (memory->opcode()) {
  1436   case DIRECT:
  1437   case INDOFFSET32X:
  1438     // No transformation necessary.
  1439     return;
  1440   case INDIRECT:
  1441     new_memory = new (C) indirect_win95_safeOper( );
  1442     break;
  1443   case INDOFFSET8:
  1444     new_memory = new (C) indOffset8_win95_safeOper(memory->disp(NULL, NULL, 0));
  1445     break;
  1446   case INDOFFSET32:
  1447     new_memory = new (C) indOffset32_win95_safeOper(memory->disp(NULL, NULL, 0));
  1448     break;
  1449   case INDINDEXOFFSET:
  1450     new_memory = new (C) indIndexOffset_win95_safeOper(memory->disp(NULL, NULL, 0));
  1451     break;
  1452   case INDINDEXSCALE:
  1453     new_memory = new (C) indIndexScale_win95_safeOper(memory->scale());
  1454     break;
  1455   case INDINDEXSCALEOFFSET:
  1456     new_memory = new (C) indIndexScaleOffset_win95_safeOper(memory->scale(), memory->disp(NULL, NULL, 0));
  1457     break;
  1458   case LOAD_LONG_INDIRECT:
  1459   case LOAD_LONG_INDOFFSET32:
  1460     // Does not use EBP as address register, use { EDX, EBX, EDI, ESI}
  1461     return;
  1462   default:
  1463     assert(false, "unexpected memory operand in pd_implicit_null_fixup()");
  1464     return;
  1466   node->_opnds[opcnt] = new_memory;
  1469 // Advertise here if the CPU requires explicit rounding operations
  1470 // to implement the UseStrictFP mode.
  1471 const bool Matcher::strict_fp_requires_explicit_rounding = true;
  1473 // Are floats conerted to double when stored to stack during deoptimization?
  1474 // On x32 it is stored with convertion only when FPU is used for floats.
  1475 bool Matcher::float_in_double() { return (UseSSE == 0); }
  1477 // Do ints take an entire long register or just half?
  1478 const bool Matcher::int_in_long = false;
  1480 // Return whether or not this register is ever used as an argument.  This
  1481 // function is used on startup to build the trampoline stubs in generateOptoStub.
  1482 // Registers not mentioned will be killed by the VM call in the trampoline, and
  1483 // arguments in those registers not be available to the callee.
  1484 bool Matcher::can_be_java_arg( int reg ) {
  1485   if(  reg == ECX_num   || reg == EDX_num   ) return true;
  1486   if( (reg == XMM0a_num || reg == XMM1a_num) && UseSSE>=1 ) return true;
  1487   if( (reg == XMM0b_num || reg == XMM1b_num) && UseSSE>=2 ) return true;
  1488   return false;
  1491 bool Matcher::is_spillable_arg( int reg ) {
  1492   return can_be_java_arg(reg);
  1495 bool Matcher::use_asm_for_ldiv_by_con( jlong divisor ) {
  1496   // Use hardware integer DIV instruction when
  1497   // it is faster than a code which use multiply.
  1498   // Only when constant divisor fits into 32 bit
  1499   // (min_jint is excluded to get only correct
  1500   // positive 32 bit values from negative).
  1501   return VM_Version::has_fast_idiv() &&
  1502          (divisor == (int)divisor && divisor != min_jint);
  1505 // Register for DIVI projection of divmodI
  1506 RegMask Matcher::divI_proj_mask() {
  1507   return EAX_REG_mask;
  1510 // Register for MODI projection of divmodI
  1511 RegMask Matcher::modI_proj_mask() {
  1512   return EDX_REG_mask;
  1515 // Register for DIVL projection of divmodL
  1516 RegMask Matcher::divL_proj_mask() {
  1517   ShouldNotReachHere();
  1518   return RegMask();
  1521 // Register for MODL projection of divmodL
  1522 RegMask Matcher::modL_proj_mask() {
  1523   ShouldNotReachHere();
  1524   return RegMask();
  1527 const RegMask Matcher::method_handle_invoke_SP_save_mask() {
  1528   return EBP_REG_mask;
  1531 // Returns true if the high 32 bits of the value is known to be zero.
  1532 bool is_operand_hi32_zero(Node* n) {
  1533   int opc = n->Opcode();
  1534   if (opc == Op_LoadUI2L) {
  1535     return true;
  1537   if (opc == Op_AndL) {
  1538     Node* o2 = n->in(2);
  1539     if (o2->is_Con() && (o2->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
  1540       return true;
  1543   if (opc == Op_ConL && (n->get_long() & 0xFFFFFFFF00000000LL) == 0LL) {
  1544     return true;
  1546   return false;
  1549 %}
  1551 //----------ENCODING BLOCK-----------------------------------------------------
  1552 // This block specifies the encoding classes used by the compiler to output
  1553 // byte streams.  Encoding classes generate functions which are called by
  1554 // Machine Instruction Nodes in order to generate the bit encoding of the
  1555 // instruction.  Operands specify their base encoding interface with the
  1556 // interface keyword.  There are currently supported four interfaces,
  1557 // REG_INTER, CONST_INTER, MEMORY_INTER, & COND_INTER.  REG_INTER causes an
  1558 // operand to generate a function which returns its register number when
  1559 // queried.   CONST_INTER causes an operand to generate a function which
  1560 // returns the value of the constant when queried.  MEMORY_INTER causes an
  1561 // operand to generate four functions which return the Base Register, the
  1562 // Index Register, the Scale Value, and the Offset Value of the operand when
  1563 // queried.  COND_INTER causes an operand to generate six functions which
  1564 // return the encoding code (ie - encoding bits for the instruction)
  1565 // associated with each basic boolean condition for a conditional instruction.
  1566 // Instructions specify two basic values for encoding.  They use the
  1567 // ins_encode keyword to specify their encoding class (which must be one of
  1568 // the class names specified in the encoding block), and they use the
  1569 // opcode keyword to specify, in order, their primary, secondary, and
  1570 // tertiary opcode.  Only the opcode sections which a particular instruction
  1571 // needs for encoding need to be specified.
  1572 encode %{
  1573   // Build emit functions for each basic byte or larger field in the intel
  1574   // encoding scheme (opcode, rm, sib, immediate), and call them from C++
  1575   // code in the enc_class source block.  Emit functions will live in the
  1576   // main source block for now.  In future, we can generalize this by
  1577   // adding a syntax that specifies the sizes of fields in an order,
  1578   // so that the adlc can build the emit functions automagically
  1580   // Emit primary opcode
  1581   enc_class OpcP %{
  1582     emit_opcode(cbuf, $primary);
  1583   %}
  1585   // Emit secondary opcode
  1586   enc_class OpcS %{
  1587     emit_opcode(cbuf, $secondary);
  1588   %}
  1590   // Emit opcode directly
  1591   enc_class Opcode(immI d8) %{
  1592     emit_opcode(cbuf, $d8$$constant);
  1593   %}
  1595   enc_class SizePrefix %{
  1596     emit_opcode(cbuf,0x66);
  1597   %}
  1599   enc_class RegReg (eRegI dst, eRegI src) %{    // RegReg(Many)
  1600     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  1601   %}
  1603   enc_class OpcRegReg (immI opcode, eRegI dst, eRegI src) %{    // OpcRegReg(Many)
  1604     emit_opcode(cbuf,$opcode$$constant);
  1605     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  1606   %}
  1608   enc_class mov_r32_imm0( eRegI dst ) %{
  1609     emit_opcode( cbuf, 0xB8 + $dst$$reg ); // 0xB8+ rd   -- MOV r32  ,imm32
  1610     emit_d32   ( cbuf, 0x0  );             //                         imm32==0x0
  1611   %}
  1613   enc_class cdq_enc %{
  1614     // Full implementation of Java idiv and irem; checks for
  1615     // special case as described in JVM spec., p.243 & p.271.
  1616     //
  1617     //         normal case                           special case
  1618     //
  1619     // input : rax,: dividend                         min_int
  1620     //         reg: divisor                          -1
  1621     //
  1622     // output: rax,: quotient  (= rax, idiv reg)       min_int
  1623     //         rdx: remainder (= rax, irem reg)       0
  1624     //
  1625     //  Code sequnce:
  1626     //
  1627     //  81 F8 00 00 00 80    cmp         rax,80000000h
  1628     //  0F 85 0B 00 00 00    jne         normal_case
  1629     //  33 D2                xor         rdx,edx
  1630     //  83 F9 FF             cmp         rcx,0FFh
  1631     //  0F 84 03 00 00 00    je          done
  1632     //                  normal_case:
  1633     //  99                   cdq
  1634     //  F7 F9                idiv        rax,ecx
  1635     //                  done:
  1636     //
  1637     emit_opcode(cbuf,0x81); emit_d8(cbuf,0xF8);
  1638     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);
  1639     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x80);                     // cmp rax,80000000h
  1640     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x85);
  1641     emit_opcode(cbuf,0x0B); emit_d8(cbuf,0x00);
  1642     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // jne normal_case
  1643     emit_opcode(cbuf,0x33); emit_d8(cbuf,0xD2);                     // xor rdx,edx
  1644     emit_opcode(cbuf,0x83); emit_d8(cbuf,0xF9); emit_d8(cbuf,0xFF); // cmp rcx,0FFh
  1645     emit_opcode(cbuf,0x0F); emit_d8(cbuf,0x84);
  1646     emit_opcode(cbuf,0x03); emit_d8(cbuf,0x00);
  1647     emit_opcode(cbuf,0x00); emit_d8(cbuf,0x00);                     // je done
  1648     // normal_case:
  1649     emit_opcode(cbuf,0x99);                                         // cdq
  1650     // idiv (note: must be emitted by the user of this rule)
  1651     // normal:
  1652   %}
  1654   // Dense encoding for older common ops
  1655   enc_class Opc_plus(immI opcode, eRegI reg) %{
  1656     emit_opcode(cbuf, $opcode$$constant + $reg$$reg);
  1657   %}
  1660   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
  1661   enc_class OpcSE (immI imm) %{ // Emit primary opcode and set sign-extend bit
  1662     // Check for 8-bit immediate, and set sign extend bit in opcode
  1663     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1664       emit_opcode(cbuf, $primary | 0x02);
  1666     else {                          // If 32-bit immediate
  1667       emit_opcode(cbuf, $primary);
  1669   %}
  1671   enc_class OpcSErm (eRegI dst, immI imm) %{    // OpcSEr/m
  1672     // Emit primary opcode and set sign-extend bit
  1673     // Check for 8-bit immediate, and set sign extend bit in opcode
  1674     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1675       emit_opcode(cbuf, $primary | 0x02);    }
  1676     else {                          // If 32-bit immediate
  1677       emit_opcode(cbuf, $primary);
  1679     // Emit r/m byte with secondary opcode, after primary opcode.
  1680     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1681   %}
  1683   enc_class Con8or32 (immI imm) %{    // Con8or32(storeImmI), 8 or 32 bits
  1684     // Check for 8-bit immediate, and set sign extend bit in opcode
  1685     if (($imm$$constant >= -128) && ($imm$$constant <= 127)) {
  1686       $$$emit8$imm$$constant;
  1688     else {                          // If 32-bit immediate
  1689       // Output immediate
  1690       $$$emit32$imm$$constant;
  1692   %}
  1694   enc_class Long_OpcSErm_Lo(eRegL dst, immL imm) %{
  1695     // Emit primary opcode and set sign-extend bit
  1696     // Check for 8-bit immediate, and set sign extend bit in opcode
  1697     int con = (int)$imm$$constant; // Throw away top bits
  1698     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
  1699     // Emit r/m byte with secondary opcode, after primary opcode.
  1700     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1701     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
  1702     else                               emit_d32(cbuf,con);
  1703   %}
  1705   enc_class Long_OpcSErm_Hi(eRegL dst, immL imm) %{
  1706     // Emit primary opcode and set sign-extend bit
  1707     // Check for 8-bit immediate, and set sign extend bit in opcode
  1708     int con = (int)($imm$$constant >> 32); // Throw away bottom bits
  1709     emit_opcode(cbuf, ((con >= -128) && (con <= 127)) ? ($primary | 0x02) : $primary);
  1710     // Emit r/m byte with tertiary opcode, after primary opcode.
  1711     emit_rm(cbuf, 0x3, $tertiary, HIGH_FROM_LOW($dst$$reg));
  1712     if ((con >= -128) && (con <= 127)) emit_d8 (cbuf,con);
  1713     else                               emit_d32(cbuf,con);
  1714   %}
  1716   enc_class Lbl (label labl) %{ // GOTO
  1717     Label *l = $labl$$label;
  1718     emit_d32(cbuf, (l->loc_pos() - (cbuf.insts_size()+4)));
  1719   %}
  1721   enc_class LblShort (label labl) %{ // GOTO
  1722     Label *l = $labl$$label;
  1723     int disp = l->loc_pos() - (cbuf.insts_size()+1);
  1724     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
  1725     emit_d8(cbuf, disp);
  1726   %}
  1728   enc_class OpcSReg (eRegI dst) %{    // BSWAP
  1729     emit_cc(cbuf, $secondary, $dst$$reg );
  1730   %}
  1732   enc_class bswap_long_bytes(eRegL dst) %{ // BSWAP
  1733     int destlo = $dst$$reg;
  1734     int desthi = HIGH_FROM_LOW(destlo);
  1735     // bswap lo
  1736     emit_opcode(cbuf, 0x0F);
  1737     emit_cc(cbuf, 0xC8, destlo);
  1738     // bswap hi
  1739     emit_opcode(cbuf, 0x0F);
  1740     emit_cc(cbuf, 0xC8, desthi);
  1741     // xchg lo and hi
  1742     emit_opcode(cbuf, 0x87);
  1743     emit_rm(cbuf, 0x3, destlo, desthi);
  1744   %}
  1746   enc_class RegOpc (eRegI div) %{    // IDIV, IMOD, JMP indirect, ...
  1747     emit_rm(cbuf, 0x3, $secondary, $div$$reg );
  1748   %}
  1750   enc_class Jcc (cmpOp cop, label labl) %{    // JCC
  1751     Label *l = $labl$$label;
  1752     $$$emit8$primary;
  1753     emit_cc(cbuf, $secondary, $cop$$cmpcode);
  1754     emit_d32(cbuf, (l->loc_pos() - (cbuf.insts_size()+4)));
  1755   %}
  1757   enc_class JccShort (cmpOp cop, label labl) %{    // JCC
  1758     Label *l = $labl$$label;
  1759     emit_cc(cbuf, $primary, $cop$$cmpcode);
  1760     int disp = l->loc_pos() - (cbuf.insts_size()+1);
  1761     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
  1762     emit_d8(cbuf, disp);
  1763   %}
  1765   enc_class enc_cmov(cmpOp cop ) %{ // CMOV
  1766     $$$emit8$primary;
  1767     emit_cc(cbuf, $secondary, $cop$$cmpcode);
  1768   %}
  1770   enc_class enc_cmov_d(cmpOp cop, regD src ) %{ // CMOV
  1771     int op = 0xDA00 + $cop$$cmpcode + ($src$$reg-1);
  1772     emit_d8(cbuf, op >> 8 );
  1773     emit_d8(cbuf, op & 255);
  1774   %}
  1776   // emulate a CMOV with a conditional branch around a MOV
  1777   enc_class enc_cmov_branch( cmpOp cop, immI brOffs ) %{ // CMOV
  1778     // Invert sense of branch from sense of CMOV
  1779     emit_cc( cbuf, 0x70, ($cop$$cmpcode^1) );
  1780     emit_d8( cbuf, $brOffs$$constant );
  1781   %}
  1783   enc_class enc_PartialSubtypeCheck( ) %{
  1784     Register Redi = as_Register(EDI_enc); // result register
  1785     Register Reax = as_Register(EAX_enc); // super class
  1786     Register Recx = as_Register(ECX_enc); // killed
  1787     Register Resi = as_Register(ESI_enc); // sub class
  1788     Label miss;
  1790     MacroAssembler _masm(&cbuf);
  1791     __ check_klass_subtype_slow_path(Resi, Reax, Recx, Redi,
  1792                                      NULL, &miss,
  1793                                      /*set_cond_codes:*/ true);
  1794     if ($primary) {
  1795       __ xorptr(Redi, Redi);
  1797     __ bind(miss);
  1798   %}
  1800   enc_class FFree_Float_Stack_All %{    // Free_Float_Stack_All
  1801     MacroAssembler masm(&cbuf);
  1802     int start = masm.offset();
  1803     if (UseSSE >= 2) {
  1804       if (VerifyFPU) {
  1805         masm.verify_FPU(0, "must be empty in SSE2+ mode");
  1807     } else {
  1808       // External c_calling_convention expects the FPU stack to be 'clean'.
  1809       // Compiled code leaves it dirty.  Do cleanup now.
  1810       masm.empty_FPU_stack();
  1812     if (sizeof_FFree_Float_Stack_All == -1) {
  1813       sizeof_FFree_Float_Stack_All = masm.offset() - start;
  1814     } else {
  1815       assert(masm.offset() - start == sizeof_FFree_Float_Stack_All, "wrong size");
  1817   %}
  1819   enc_class Verify_FPU_For_Leaf %{
  1820     if( VerifyFPU ) {
  1821       MacroAssembler masm(&cbuf);
  1822       masm.verify_FPU( -3, "Returning from Runtime Leaf call");
  1824   %}
  1826   enc_class Java_To_Runtime (method meth) %{    // CALL Java_To_Runtime, Java_To_Runtime_Leaf
  1827     // This is the instruction starting address for relocation info.
  1828     cbuf.set_insts_mark();
  1829     $$$emit8$primary;
  1830     // CALL directly to the runtime
  1831     emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1832                 runtime_call_Relocation::spec(), RELOC_IMM32 );
  1834     if (UseSSE >= 2) {
  1835       MacroAssembler _masm(&cbuf);
  1836       BasicType rt = tf()->return_type();
  1838       if ((rt == T_FLOAT || rt == T_DOUBLE) && !return_value_is_used()) {
  1839         // A C runtime call where the return value is unused.  In SSE2+
  1840         // mode the result needs to be removed from the FPU stack.  It's
  1841         // likely that this function call could be removed by the
  1842         // optimizer if the C function is a pure function.
  1843         __ ffree(0);
  1844       } else if (rt == T_FLOAT) {
  1845         __ lea(rsp, Address(rsp, -4));
  1846         __ fstp_s(Address(rsp, 0));
  1847         __ movflt(xmm0, Address(rsp, 0));
  1848         __ lea(rsp, Address(rsp,  4));
  1849       } else if (rt == T_DOUBLE) {
  1850         __ lea(rsp, Address(rsp, -8));
  1851         __ fstp_d(Address(rsp, 0));
  1852         __ movdbl(xmm0, Address(rsp, 0));
  1853         __ lea(rsp, Address(rsp,  8));
  1856   %}
  1859   enc_class pre_call_FPU %{
  1860     // If method sets FPU control word restore it here
  1861     debug_only(int off0 = cbuf.insts_size());
  1862     if( Compile::current()->in_24_bit_fp_mode() ) {
  1863       MacroAssembler masm(&cbuf);
  1864       masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
  1866     debug_only(int off1 = cbuf.insts_size());
  1867     assert(off1 - off0 == pre_call_FPU_size(), "correct size prediction");
  1868   %}
  1870   enc_class post_call_FPU %{
  1871     // If method sets FPU control word do it here also
  1872     if( Compile::current()->in_24_bit_fp_mode() ) {
  1873       MacroAssembler masm(&cbuf);
  1874       masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
  1876   %}
  1878   enc_class preserve_SP %{
  1879     debug_only(int off0 = cbuf.insts_size());
  1880     MacroAssembler _masm(&cbuf);
  1881     // RBP is preserved across all calls, even compiled calls.
  1882     // Use it to preserve RSP in places where the callee might change the SP.
  1883     __ movptr(rbp_mh_SP_save, rsp);
  1884     debug_only(int off1 = cbuf.insts_size());
  1885     assert(off1 - off0 == preserve_SP_size(), "correct size prediction");
  1886   %}
  1888   enc_class restore_SP %{
  1889     MacroAssembler _masm(&cbuf);
  1890     __ movptr(rsp, rbp_mh_SP_save);
  1891   %}
  1893   enc_class Java_Static_Call (method meth) %{    // JAVA STATIC CALL
  1894     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
  1895     // who we intended to call.
  1896     cbuf.set_insts_mark();
  1897     $$$emit8$primary;
  1898     if ( !_method ) {
  1899       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1900                      runtime_call_Relocation::spec(), RELOC_IMM32 );
  1901     } else if(_optimized_virtual) {
  1902       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1903                      opt_virtual_call_Relocation::spec(), RELOC_IMM32 );
  1904     } else {
  1905       emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1906                      static_call_Relocation::spec(), RELOC_IMM32 );
  1908     if( _method ) {  // Emit stub for static call
  1909       emit_java_to_interp(cbuf);
  1911   %}
  1913   enc_class Java_Dynamic_Call (method meth) %{    // JAVA DYNAMIC CALL
  1914     // !!!!!
  1915     // Generate  "Mov EAX,0x00", placeholder instruction to load oop-info
  1916     // emit_call_dynamic_prologue( cbuf );
  1917     cbuf.set_insts_mark();
  1918     emit_opcode(cbuf, 0xB8 + EAX_enc);        // mov    EAX,-1
  1919     emit_d32_reloc(cbuf, (int)Universe::non_oop_word(), oop_Relocation::spec_for_immediate(), RELOC_IMM32);
  1920     address  virtual_call_oop_addr = cbuf.insts_mark();
  1921     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
  1922     // who we intended to call.
  1923     cbuf.set_insts_mark();
  1924     $$$emit8$primary;
  1925     emit_d32_reloc(cbuf, ($meth$$method - (int)(cbuf.insts_end()) - 4),
  1926                 virtual_call_Relocation::spec(virtual_call_oop_addr), RELOC_IMM32 );
  1927   %}
  1929   enc_class Java_Compiled_Call (method meth) %{    // JAVA COMPILED CALL
  1930     int disp = in_bytes(methodOopDesc::from_compiled_offset());
  1931     assert( -128 <= disp && disp <= 127, "compiled_code_offset isn't small");
  1933     // CALL *[EAX+in_bytes(methodOopDesc::from_compiled_code_entry_point_offset())]
  1934     cbuf.set_insts_mark();
  1935     $$$emit8$primary;
  1936     emit_rm(cbuf, 0x01, $secondary, EAX_enc );  // R/M byte
  1937     emit_d8(cbuf, disp);             // Displacement
  1939   %}
  1941   enc_class Xor_Reg (eRegI dst) %{
  1942     emit_opcode(cbuf, 0x33);
  1943     emit_rm(cbuf, 0x3, $dst$$reg, $dst$$reg);
  1944   %}
  1946 //   Following encoding is no longer used, but may be restored if calling
  1947 //   convention changes significantly.
  1948 //   Became: Xor_Reg(EBP), Java_To_Runtime( labl )
  1949 //
  1950 //   enc_class Java_Interpreter_Call (label labl) %{    // JAVA INTERPRETER CALL
  1951 //     // int ic_reg     = Matcher::inline_cache_reg();
  1952 //     // int ic_encode  = Matcher::_regEncode[ic_reg];
  1953 //     // int imo_reg    = Matcher::interpreter_method_oop_reg();
  1954 //     // int imo_encode = Matcher::_regEncode[imo_reg];
  1955 //
  1956 //     // // Interpreter expects method_oop in EBX, currently a callee-saved register,
  1957 //     // // so we load it immediately before the call
  1958 //     // emit_opcode(cbuf, 0x8B);                     // MOV    imo_reg,ic_reg  # method_oop
  1959 //     // emit_rm(cbuf, 0x03, imo_encode, ic_encode ); // R/M byte
  1960 //
  1961 //     // xor rbp,ebp
  1962 //     emit_opcode(cbuf, 0x33);
  1963 //     emit_rm(cbuf, 0x3, EBP_enc, EBP_enc);
  1964 //
  1965 //     // CALL to interpreter.
  1966 //     cbuf.set_insts_mark();
  1967 //     $$$emit8$primary;
  1968 //     emit_d32_reloc(cbuf, ($labl$$label - (int)(cbuf.insts_end()) - 4),
  1969 //                 runtime_call_Relocation::spec(), RELOC_IMM32 );
  1970 //   %}
  1972   enc_class RegOpcImm (eRegI dst, immI8 shift) %{    // SHL, SAR, SHR
  1973     $$$emit8$primary;
  1974     emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  1975     $$$emit8$shift$$constant;
  1976   %}
  1978   enc_class LdImmI (eRegI dst, immI src) %{    // Load Immediate
  1979     // Load immediate does not have a zero or sign extended version
  1980     // for 8-bit immediates
  1981     emit_opcode(cbuf, 0xB8 + $dst$$reg);
  1982     $$$emit32$src$$constant;
  1983   %}
  1985   enc_class LdImmP (eRegI dst, immI src) %{    // Load Immediate
  1986     // Load immediate does not have a zero or sign extended version
  1987     // for 8-bit immediates
  1988     emit_opcode(cbuf, $primary + $dst$$reg);
  1989     $$$emit32$src$$constant;
  1990   %}
  1992   enc_class LdImmL_Lo( eRegL dst, immL src) %{    // Load Immediate
  1993     // Load immediate does not have a zero or sign extended version
  1994     // for 8-bit immediates
  1995     int dst_enc = $dst$$reg;
  1996     int src_con = $src$$constant & 0x0FFFFFFFFL;
  1997     if (src_con == 0) {
  1998       // xor dst, dst
  1999       emit_opcode(cbuf, 0x33);
  2000       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
  2001     } else {
  2002       emit_opcode(cbuf, $primary + dst_enc);
  2003       emit_d32(cbuf, src_con);
  2005   %}
  2007   enc_class LdImmL_Hi( eRegL dst, immL src) %{    // Load Immediate
  2008     // Load immediate does not have a zero or sign extended version
  2009     // for 8-bit immediates
  2010     int dst_enc = $dst$$reg + 2;
  2011     int src_con = ((julong)($src$$constant)) >> 32;
  2012     if (src_con == 0) {
  2013       // xor dst, dst
  2014       emit_opcode(cbuf, 0x33);
  2015       emit_rm(cbuf, 0x3, dst_enc, dst_enc);
  2016     } else {
  2017       emit_opcode(cbuf, $primary + dst_enc);
  2018       emit_d32(cbuf, src_con);
  2020   %}
  2023   enc_class MovI2X_reg(regX dst, eRegI src) %{
  2024     emit_opcode(cbuf, 0x66 );     // MOVD dst,src
  2025     emit_opcode(cbuf, 0x0F );
  2026     emit_opcode(cbuf, 0x6E );
  2027     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2028   %}
  2030   enc_class MovX2I_reg(eRegI dst, regX src) %{
  2031     emit_opcode(cbuf, 0x66 );     // MOVD dst,src
  2032     emit_opcode(cbuf, 0x0F );
  2033     emit_opcode(cbuf, 0x7E );
  2034     emit_rm(cbuf, 0x3, $src$$reg, $dst$$reg);
  2035   %}
  2037   enc_class MovL2XD_reg(regXD dst, eRegL src, regXD tmp) %{
  2038     { // MOVD $dst,$src.lo
  2039       emit_opcode(cbuf,0x66);
  2040       emit_opcode(cbuf,0x0F);
  2041       emit_opcode(cbuf,0x6E);
  2042       emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2044     { // MOVD $tmp,$src.hi
  2045       emit_opcode(cbuf,0x66);
  2046       emit_opcode(cbuf,0x0F);
  2047       emit_opcode(cbuf,0x6E);
  2048       emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg));
  2050     { // PUNPCKLDQ $dst,$tmp
  2051       emit_opcode(cbuf,0x66);
  2052       emit_opcode(cbuf,0x0F);
  2053       emit_opcode(cbuf,0x62);
  2054       emit_rm(cbuf, 0x3, $dst$$reg, $tmp$$reg);
  2056   %}
  2058   enc_class MovXD2L_reg(eRegL dst, regXD src, regXD tmp) %{
  2059     { // MOVD $dst.lo,$src
  2060       emit_opcode(cbuf,0x66);
  2061       emit_opcode(cbuf,0x0F);
  2062       emit_opcode(cbuf,0x7E);
  2063       emit_rm(cbuf, 0x3, $src$$reg, $dst$$reg);
  2065     { // PSHUFLW $tmp,$src,0x4E  (01001110b)
  2066       emit_opcode(cbuf,0xF2);
  2067       emit_opcode(cbuf,0x0F);
  2068       emit_opcode(cbuf,0x70);
  2069       emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg);
  2070       emit_d8(cbuf, 0x4E);
  2072     { // MOVD $dst.hi,$tmp
  2073       emit_opcode(cbuf,0x66);
  2074       emit_opcode(cbuf,0x0F);
  2075       emit_opcode(cbuf,0x7E);
  2076       emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg));
  2078   %}
  2081   // Encode a reg-reg copy.  If it is useless, then empty encoding.
  2082   enc_class enc_Copy( eRegI dst, eRegI src ) %{
  2083     encode_Copy( cbuf, $dst$$reg, $src$$reg );
  2084   %}
  2086   enc_class enc_CopyL_Lo( eRegI dst, eRegL src ) %{
  2087     encode_Copy( cbuf, $dst$$reg, $src$$reg );
  2088   %}
  2090   // Encode xmm reg-reg copy.  If it is useless, then empty encoding.
  2091   enc_class enc_CopyXD( RegXD dst, RegXD src ) %{
  2092     encode_CopyXD( cbuf, $dst$$reg, $src$$reg );
  2093   %}
  2095   enc_class RegReg (eRegI dst, eRegI src) %{    // RegReg(Many)
  2096     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2097   %}
  2099   enc_class RegReg_Lo(eRegL dst, eRegL src) %{    // RegReg(Many)
  2100     $$$emit8$primary;
  2101     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2102   %}
  2104   enc_class RegReg_Hi(eRegL dst, eRegL src) %{    // RegReg(Many)
  2105     $$$emit8$secondary;
  2106     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
  2107   %}
  2109   enc_class RegReg_Lo2(eRegL dst, eRegL src) %{    // RegReg(Many)
  2110     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2111   %}
  2113   enc_class RegReg_Hi2(eRegL dst, eRegL src) %{    // RegReg(Many)
  2114     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg));
  2115   %}
  2117   enc_class RegReg_HiLo( eRegL src, eRegI dst ) %{
  2118     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($src$$reg));
  2119   %}
  2121   enc_class Con32 (immI src) %{    // Con32(storeImmI)
  2122     // Output immediate
  2123     $$$emit32$src$$constant;
  2124   %}
  2126   enc_class Con32F_as_bits(immF src) %{        // storeF_imm
  2127     // Output Float immediate bits
  2128     jfloat jf = $src$$constant;
  2129     int    jf_as_bits = jint_cast( jf );
  2130     emit_d32(cbuf, jf_as_bits);
  2131   %}
  2133   enc_class Con32XF_as_bits(immXF src) %{      // storeX_imm
  2134     // Output Float immediate bits
  2135     jfloat jf = $src$$constant;
  2136     int    jf_as_bits = jint_cast( jf );
  2137     emit_d32(cbuf, jf_as_bits);
  2138   %}
  2140   enc_class Con16 (immI src) %{    // Con16(storeImmI)
  2141     // Output immediate
  2142     $$$emit16$src$$constant;
  2143   %}
  2145   enc_class Con_d32(immI src) %{
  2146     emit_d32(cbuf,$src$$constant);
  2147   %}
  2149   enc_class conmemref (eRegP t1) %{    // Con32(storeImmI)
  2150     // Output immediate memory reference
  2151     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
  2152     emit_d32(cbuf, 0x00);
  2153   %}
  2155   enc_class lock_prefix( ) %{
  2156     if( os::is_MP() )
  2157       emit_opcode(cbuf,0xF0);         // [Lock]
  2158   %}
  2160   // Cmp-xchg long value.
  2161   // Note: we need to swap rbx, and rcx before and after the
  2162   //       cmpxchg8 instruction because the instruction uses
  2163   //       rcx as the high order word of the new value to store but
  2164   //       our register encoding uses rbx,.
  2165   enc_class enc_cmpxchg8(eSIRegP mem_ptr) %{
  2167     // XCHG  rbx,ecx
  2168     emit_opcode(cbuf,0x87);
  2169     emit_opcode(cbuf,0xD9);
  2170     // [Lock]
  2171     if( os::is_MP() )
  2172       emit_opcode(cbuf,0xF0);
  2173     // CMPXCHG8 [Eptr]
  2174     emit_opcode(cbuf,0x0F);
  2175     emit_opcode(cbuf,0xC7);
  2176     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
  2177     // XCHG  rbx,ecx
  2178     emit_opcode(cbuf,0x87);
  2179     emit_opcode(cbuf,0xD9);
  2180   %}
  2182   enc_class enc_cmpxchg(eSIRegP mem_ptr) %{
  2183     // [Lock]
  2184     if( os::is_MP() )
  2185       emit_opcode(cbuf,0xF0);
  2187     // CMPXCHG [Eptr]
  2188     emit_opcode(cbuf,0x0F);
  2189     emit_opcode(cbuf,0xB1);
  2190     emit_rm( cbuf, 0x0, 1, $mem_ptr$$reg );
  2191   %}
  2193   enc_class enc_flags_ne_to_boolean( iRegI res ) %{
  2194     int res_encoding = $res$$reg;
  2196     // MOV  res,0
  2197     emit_opcode( cbuf, 0xB8 + res_encoding);
  2198     emit_d32( cbuf, 0 );
  2199     // JNE,s  fail
  2200     emit_opcode(cbuf,0x75);
  2201     emit_d8(cbuf, 5 );
  2202     // MOV  res,1
  2203     emit_opcode( cbuf, 0xB8 + res_encoding);
  2204     emit_d32( cbuf, 1 );
  2205     // fail:
  2206   %}
  2208   enc_class set_instruction_start( ) %{
  2209     cbuf.set_insts_mark();            // Mark start of opcode for reloc info in mem operand
  2210   %}
  2212   enc_class RegMem (eRegI ereg, memory mem) %{    // emit_reg_mem
  2213     int reg_encoding = $ereg$$reg;
  2214     int base  = $mem$$base;
  2215     int index = $mem$$index;
  2216     int scale = $mem$$scale;
  2217     int displace = $mem$$disp;
  2218     bool disp_is_oop = $mem->disp_is_oop();
  2219     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_is_oop);
  2220   %}
  2222   enc_class RegMem_Hi(eRegL ereg, memory mem) %{    // emit_reg_mem
  2223     int reg_encoding = HIGH_FROM_LOW($ereg$$reg);  // Hi register of pair, computed from lo
  2224     int base  = $mem$$base;
  2225     int index = $mem$$index;
  2226     int scale = $mem$$scale;
  2227     int displace = $mem$$disp + 4;      // Offset is 4 further in memory
  2228     assert( !$mem->disp_is_oop(), "Cannot add 4 to oop" );
  2229     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, false/*disp_is_oop*/);
  2230   %}
  2232   enc_class move_long_small_shift( eRegL dst, immI_1_31 cnt ) %{
  2233     int r1, r2;
  2234     if( $tertiary == 0xA4 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
  2235     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
  2236     emit_opcode(cbuf,0x0F);
  2237     emit_opcode(cbuf,$tertiary);
  2238     emit_rm(cbuf, 0x3, r1, r2);
  2239     emit_d8(cbuf,$cnt$$constant);
  2240     emit_d8(cbuf,$primary);
  2241     emit_rm(cbuf, 0x3, $secondary, r1);
  2242     emit_d8(cbuf,$cnt$$constant);
  2243   %}
  2245   enc_class move_long_big_shift_sign( eRegL dst, immI_32_63 cnt ) %{
  2246     emit_opcode( cbuf, 0x8B ); // Move
  2247     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
  2248     if( $cnt$$constant > 32 ) { // Shift, if not by zero
  2249       emit_d8(cbuf,$primary);
  2250       emit_rm(cbuf, 0x3, $secondary, $dst$$reg);
  2251       emit_d8(cbuf,$cnt$$constant-32);
  2253     emit_d8(cbuf,$primary);
  2254     emit_rm(cbuf, 0x3, $secondary, HIGH_FROM_LOW($dst$$reg));
  2255     emit_d8(cbuf,31);
  2256   %}
  2258   enc_class move_long_big_shift_clr( eRegL dst, immI_32_63 cnt ) %{
  2259     int r1, r2;
  2260     if( $secondary == 0x5 ) { r1 = $dst$$reg;  r2 = HIGH_FROM_LOW($dst$$reg); }
  2261     else                    { r2 = $dst$$reg;  r1 = HIGH_FROM_LOW($dst$$reg); }
  2263     emit_opcode( cbuf, 0x8B ); // Move r1,r2
  2264     emit_rm(cbuf, 0x3, r1, r2);
  2265     if( $cnt$$constant > 32 ) { // Shift, if not by zero
  2266       emit_opcode(cbuf,$primary);
  2267       emit_rm(cbuf, 0x3, $secondary, r1);
  2268       emit_d8(cbuf,$cnt$$constant-32);
  2270     emit_opcode(cbuf,0x33);  // XOR r2,r2
  2271     emit_rm(cbuf, 0x3, r2, r2);
  2272   %}
  2274   // Clone of RegMem but accepts an extra parameter to access each
  2275   // half of a double in memory; it never needs relocation info.
  2276   enc_class Mov_MemD_half_to_Reg (immI opcode, memory mem, immI disp_for_half, eRegI rm_reg) %{
  2277     emit_opcode(cbuf,$opcode$$constant);
  2278     int reg_encoding = $rm_reg$$reg;
  2279     int base     = $mem$$base;
  2280     int index    = $mem$$index;
  2281     int scale    = $mem$$scale;
  2282     int displace = $mem$$disp + $disp_for_half$$constant;
  2283     bool disp_is_oop = false;
  2284     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_is_oop);
  2285   %}
  2287   // !!!!! Special Custom Code used by MemMove, and stack access instructions !!!!!
  2288   //
  2289   // Clone of RegMem except the RM-byte's reg/opcode field is an ADLC-time constant
  2290   // and it never needs relocation information.
  2291   // Frequently used to move data between FPU's Stack Top and memory.
  2292   enc_class RMopc_Mem_no_oop (immI rm_opcode, memory mem) %{
  2293     int rm_byte_opcode = $rm_opcode$$constant;
  2294     int base     = $mem$$base;
  2295     int index    = $mem$$index;
  2296     int scale    = $mem$$scale;
  2297     int displace = $mem$$disp;
  2298     assert( !$mem->disp_is_oop(), "No oops here because no relo info allowed" );
  2299     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, false);
  2300   %}
  2302   enc_class RMopc_Mem (immI rm_opcode, memory mem) %{
  2303     int rm_byte_opcode = $rm_opcode$$constant;
  2304     int base     = $mem$$base;
  2305     int index    = $mem$$index;
  2306     int scale    = $mem$$scale;
  2307     int displace = $mem$$disp;
  2308     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  2309     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_is_oop);
  2310   %}
  2312   enc_class RegLea (eRegI dst, eRegI src0, immI src1 ) %{    // emit_reg_lea
  2313     int reg_encoding = $dst$$reg;
  2314     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
  2315     int index        = 0x04;            // 0x04 indicates no index
  2316     int scale        = 0x00;            // 0x00 indicates no scale
  2317     int displace     = $src1$$constant; // 0x00 indicates no displacement
  2318     bool disp_is_oop = false;
  2319     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_is_oop);
  2320   %}
  2322   enc_class min_enc (eRegI dst, eRegI src) %{    // MIN
  2323     // Compare dst,src
  2324     emit_opcode(cbuf,0x3B);
  2325     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2326     // jmp dst < src around move
  2327     emit_opcode(cbuf,0x7C);
  2328     emit_d8(cbuf,2);
  2329     // move dst,src
  2330     emit_opcode(cbuf,0x8B);
  2331     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2332   %}
  2334   enc_class max_enc (eRegI dst, eRegI src) %{    // MAX
  2335     // Compare dst,src
  2336     emit_opcode(cbuf,0x3B);
  2337     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2338     // jmp dst > src around move
  2339     emit_opcode(cbuf,0x7F);
  2340     emit_d8(cbuf,2);
  2341     // move dst,src
  2342     emit_opcode(cbuf,0x8B);
  2343     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  2344   %}
  2346   enc_class enc_FP_store(memory mem, regD src) %{
  2347     // If src is FPR1, we can just FST to store it.
  2348     // Else we need to FLD it to FPR1, then FSTP to store/pop it.
  2349     int reg_encoding = 0x2; // Just store
  2350     int base  = $mem$$base;
  2351     int index = $mem$$index;
  2352     int scale = $mem$$scale;
  2353     int displace = $mem$$disp;
  2354     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  2355     if( $src$$reg != FPR1L_enc ) {
  2356       reg_encoding = 0x3;  // Store & pop
  2357       emit_opcode( cbuf, 0xD9 ); // FLD (i.e., push it)
  2358       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2360     cbuf.set_insts_mark();       // Mark start of opcode for reloc info in mem operand
  2361     emit_opcode(cbuf,$primary);
  2362     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_is_oop);
  2363   %}
  2365   enc_class neg_reg(eRegI dst) %{
  2366     // NEG $dst
  2367     emit_opcode(cbuf,0xF7);
  2368     emit_rm(cbuf, 0x3, 0x03, $dst$$reg );
  2369   %}
  2371   enc_class setLT_reg(eCXRegI dst) %{
  2372     // SETLT $dst
  2373     emit_opcode(cbuf,0x0F);
  2374     emit_opcode(cbuf,0x9C);
  2375     emit_rm( cbuf, 0x3, 0x4, $dst$$reg );
  2376   %}
  2378   enc_class enc_cmpLTP(ncxRegI p, ncxRegI q, ncxRegI y, eCXRegI tmp) %{    // cadd_cmpLT
  2379     int tmpReg = $tmp$$reg;
  2381     // SUB $p,$q
  2382     emit_opcode(cbuf,0x2B);
  2383     emit_rm(cbuf, 0x3, $p$$reg, $q$$reg);
  2384     // SBB $tmp,$tmp
  2385     emit_opcode(cbuf,0x1B);
  2386     emit_rm(cbuf, 0x3, tmpReg, tmpReg);
  2387     // AND $tmp,$y
  2388     emit_opcode(cbuf,0x23);
  2389     emit_rm(cbuf, 0x3, tmpReg, $y$$reg);
  2390     // ADD $p,$tmp
  2391     emit_opcode(cbuf,0x03);
  2392     emit_rm(cbuf, 0x3, $p$$reg, tmpReg);
  2393   %}
  2395   enc_class enc_cmpLTP_mem(eRegI p, eRegI q, memory mem, eCXRegI tmp) %{    // cadd_cmpLT
  2396     int tmpReg = $tmp$$reg;
  2398     // SUB $p,$q
  2399     emit_opcode(cbuf,0x2B);
  2400     emit_rm(cbuf, 0x3, $p$$reg, $q$$reg);
  2401     // SBB $tmp,$tmp
  2402     emit_opcode(cbuf,0x1B);
  2403     emit_rm(cbuf, 0x3, tmpReg, tmpReg);
  2404     // AND $tmp,$y
  2405     cbuf.set_insts_mark();       // Mark start of opcode for reloc info in mem operand
  2406     emit_opcode(cbuf,0x23);
  2407     int reg_encoding = tmpReg;
  2408     int base  = $mem$$base;
  2409     int index = $mem$$index;
  2410     int scale = $mem$$scale;
  2411     int displace = $mem$$disp;
  2412     bool disp_is_oop = $mem->disp_is_oop();
  2413     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace, disp_is_oop);
  2414     // ADD $p,$tmp
  2415     emit_opcode(cbuf,0x03);
  2416     emit_rm(cbuf, 0x3, $p$$reg, tmpReg);
  2417   %}
  2419   enc_class shift_left_long( eRegL dst, eCXRegI shift ) %{
  2420     // TEST shift,32
  2421     emit_opcode(cbuf,0xF7);
  2422     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2423     emit_d32(cbuf,0x20);
  2424     // JEQ,s small
  2425     emit_opcode(cbuf, 0x74);
  2426     emit_d8(cbuf, 0x04);
  2427     // MOV    $dst.hi,$dst.lo
  2428     emit_opcode( cbuf, 0x8B );
  2429     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
  2430     // CLR    $dst.lo
  2431     emit_opcode(cbuf, 0x33);
  2432     emit_rm(cbuf, 0x3, $dst$$reg, $dst$$reg);
  2433 // small:
  2434     // SHLD   $dst.hi,$dst.lo,$shift
  2435     emit_opcode(cbuf,0x0F);
  2436     emit_opcode(cbuf,0xA5);
  2437     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg));
  2438     // SHL    $dst.lo,$shift"
  2439     emit_opcode(cbuf,0xD3);
  2440     emit_rm(cbuf, 0x3, 0x4, $dst$$reg );
  2441   %}
  2443   enc_class shift_right_long( eRegL dst, eCXRegI shift ) %{
  2444     // TEST shift,32
  2445     emit_opcode(cbuf,0xF7);
  2446     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2447     emit_d32(cbuf,0x20);
  2448     // JEQ,s small
  2449     emit_opcode(cbuf, 0x74);
  2450     emit_d8(cbuf, 0x04);
  2451     // MOV    $dst.lo,$dst.hi
  2452     emit_opcode( cbuf, 0x8B );
  2453     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
  2454     // CLR    $dst.hi
  2455     emit_opcode(cbuf, 0x33);
  2456     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($dst$$reg));
  2457 // small:
  2458     // SHRD   $dst.lo,$dst.hi,$shift
  2459     emit_opcode(cbuf,0x0F);
  2460     emit_opcode(cbuf,0xAD);
  2461     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
  2462     // SHR    $dst.hi,$shift"
  2463     emit_opcode(cbuf,0xD3);
  2464     emit_rm(cbuf, 0x3, 0x5, HIGH_FROM_LOW($dst$$reg) );
  2465   %}
  2467   enc_class shift_right_arith_long( eRegL dst, eCXRegI shift ) %{
  2468     // TEST shift,32
  2469     emit_opcode(cbuf,0xF7);
  2470     emit_rm(cbuf, 0x3, 0, ECX_enc);
  2471     emit_d32(cbuf,0x20);
  2472     // JEQ,s small
  2473     emit_opcode(cbuf, 0x74);
  2474     emit_d8(cbuf, 0x05);
  2475     // MOV    $dst.lo,$dst.hi
  2476     emit_opcode( cbuf, 0x8B );
  2477     emit_rm(cbuf, 0x3, $dst$$reg, HIGH_FROM_LOW($dst$$reg) );
  2478     // SAR    $dst.hi,31
  2479     emit_opcode(cbuf, 0xC1);
  2480     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW($dst$$reg) );
  2481     emit_d8(cbuf, 0x1F );
  2482 // small:
  2483     // SHRD   $dst.lo,$dst.hi,$shift
  2484     emit_opcode(cbuf,0x0F);
  2485     emit_opcode(cbuf,0xAD);
  2486     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg);
  2487     // SAR    $dst.hi,$shift"
  2488     emit_opcode(cbuf,0xD3);
  2489     emit_rm(cbuf, 0x3, 0x7, HIGH_FROM_LOW($dst$$reg) );
  2490   %}
  2493   // ----------------- Encodings for floating point unit -----------------
  2494   // May leave result in FPU-TOS or FPU reg depending on opcodes
  2495   enc_class OpcReg_F (regF src) %{    // FMUL, FDIV
  2496     $$$emit8$primary;
  2497     emit_rm(cbuf, 0x3, $secondary, $src$$reg );
  2498   %}
  2500   // Pop argument in FPR0 with FSTP ST(0)
  2501   enc_class PopFPU() %{
  2502     emit_opcode( cbuf, 0xDD );
  2503     emit_d8( cbuf, 0xD8 );
  2504   %}
  2506   // !!!!! equivalent to Pop_Reg_F
  2507   enc_class Pop_Reg_D( regD dst ) %{
  2508     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
  2509     emit_d8( cbuf, 0xD8+$dst$$reg );
  2510   %}
  2512   enc_class Push_Reg_D( regD dst ) %{
  2513     emit_opcode( cbuf, 0xD9 );
  2514     emit_d8( cbuf, 0xC0-1+$dst$$reg );   // FLD ST(i-1)
  2515   %}
  2517   enc_class strictfp_bias1( regD dst ) %{
  2518     emit_opcode( cbuf, 0xDB );           // FLD m80real
  2519     emit_opcode( cbuf, 0x2D );
  2520     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias1() );
  2521     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
  2522     emit_opcode( cbuf, 0xC8+$dst$$reg );
  2523   %}
  2525   enc_class strictfp_bias2( regD dst ) %{
  2526     emit_opcode( cbuf, 0xDB );           // FLD m80real
  2527     emit_opcode( cbuf, 0x2D );
  2528     emit_d32( cbuf, (int)StubRoutines::addr_fpu_subnormal_bias2() );
  2529     emit_opcode( cbuf, 0xDE );           // FMULP ST(dst), ST0
  2530     emit_opcode( cbuf, 0xC8+$dst$$reg );
  2531   %}
  2533   // Special case for moving an integer register to a stack slot.
  2534   enc_class OpcPRegSS( stackSlotI dst, eRegI src ) %{ // RegSS
  2535     store_to_stackslot( cbuf, $primary, $src$$reg, $dst$$disp );
  2536   %}
  2538   // Special case for moving a register to a stack slot.
  2539   enc_class RegSS( stackSlotI dst, eRegI src ) %{ // RegSS
  2540     // Opcode already emitted
  2541     emit_rm( cbuf, 0x02, $src$$reg, ESP_enc );   // R/M byte
  2542     emit_rm( cbuf, 0x00, ESP_enc, ESP_enc);          // SIB byte
  2543     emit_d32(cbuf, $dst$$disp);   // Displacement
  2544   %}
  2546   // Push the integer in stackSlot 'src' onto FP-stack
  2547   enc_class Push_Mem_I( memory src ) %{    // FILD   [ESP+src]
  2548     store_to_stackslot( cbuf, $primary, $secondary, $src$$disp );
  2549   %}
  2551   // Push the float in stackSlot 'src' onto FP-stack
  2552   enc_class Push_Mem_F( memory src ) %{    // FLD_S   [ESP+src]
  2553     store_to_stackslot( cbuf, 0xD9, 0x00, $src$$disp );
  2554   %}
  2556   // Push the double in stackSlot 'src' onto FP-stack
  2557   enc_class Push_Mem_D( memory src ) %{    // FLD_D   [ESP+src]
  2558     store_to_stackslot( cbuf, 0xDD, 0x00, $src$$disp );
  2559   %}
  2561   // Push FPU's TOS float to a stack-slot, and pop FPU-stack
  2562   enc_class Pop_Mem_F( stackSlotF dst ) %{ // FSTP_S [ESP+dst]
  2563     store_to_stackslot( cbuf, 0xD9, 0x03, $dst$$disp );
  2564   %}
  2566   // Same as Pop_Mem_F except for opcode
  2567   // Push FPU's TOS double to a stack-slot, and pop FPU-stack
  2568   enc_class Pop_Mem_D( stackSlotD dst ) %{ // FSTP_D [ESP+dst]
  2569     store_to_stackslot( cbuf, 0xDD, 0x03, $dst$$disp );
  2570   %}
  2572   enc_class Pop_Reg_F( regF dst ) %{
  2573     emit_opcode( cbuf, 0xDD );           // FSTP   ST(i)
  2574     emit_d8( cbuf, 0xD8+$dst$$reg );
  2575   %}
  2577   enc_class Push_Reg_F( regF dst ) %{
  2578     emit_opcode( cbuf, 0xD9 );           // FLD    ST(i-1)
  2579     emit_d8( cbuf, 0xC0-1+$dst$$reg );
  2580   %}
  2582   // Push FPU's float to a stack-slot, and pop FPU-stack
  2583   enc_class Pop_Mem_Reg_F( stackSlotF dst, regF src ) %{
  2584     int pop = 0x02;
  2585     if ($src$$reg != FPR1L_enc) {
  2586       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
  2587       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2588       pop = 0x03;
  2590     store_to_stackslot( cbuf, 0xD9, pop, $dst$$disp ); // FST<P>_S  [ESP+dst]
  2591   %}
  2593   // Push FPU's double to a stack-slot, and pop FPU-stack
  2594   enc_class Pop_Mem_Reg_D( stackSlotD dst, regD src ) %{
  2595     int pop = 0x02;
  2596     if ($src$$reg != FPR1L_enc) {
  2597       emit_opcode( cbuf, 0xD9 );         // FLD    ST(i-1)
  2598       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2599       pop = 0x03;
  2601     store_to_stackslot( cbuf, 0xDD, pop, $dst$$disp ); // FST<P>_D  [ESP+dst]
  2602   %}
  2604   // Push FPU's double to a FPU-stack-slot, and pop FPU-stack
  2605   enc_class Pop_Reg_Reg_D( regD dst, regF src ) %{
  2606     int pop = 0xD0 - 1; // -1 since we skip FLD
  2607     if ($src$$reg != FPR1L_enc) {
  2608       emit_opcode( cbuf, 0xD9 );         // FLD    ST(src-1)
  2609       emit_d8( cbuf, 0xC0-1+$src$$reg );
  2610       pop = 0xD8;
  2612     emit_opcode( cbuf, 0xDD );
  2613     emit_d8( cbuf, pop+$dst$$reg );      // FST<P> ST(i)
  2614   %}
  2617   enc_class Mul_Add_F( regF dst, regF src, regF src1, regF src2 ) %{
  2618     MacroAssembler masm(&cbuf);
  2619     masm.fld_s(  $src1$$reg-1);   // nothing at TOS, load TOS from src1.reg
  2620     masm.fmul(   $src2$$reg+0);   // value at TOS
  2621     masm.fadd(   $src$$reg+0);    // value at TOS
  2622     masm.fstp_d( $dst$$reg+0);    // value at TOS, popped off after store
  2623   %}
  2626   enc_class Push_Reg_Mod_D( regD dst, regD src) %{
  2627     // load dst in FPR0
  2628     emit_opcode( cbuf, 0xD9 );
  2629     emit_d8( cbuf, 0xC0-1+$dst$$reg );
  2630     if ($src$$reg != FPR1L_enc) {
  2631       // fincstp
  2632       emit_opcode (cbuf, 0xD9);
  2633       emit_opcode (cbuf, 0xF7);
  2634       // swap src with FPR1:
  2635       // FXCH FPR1 with src
  2636       emit_opcode(cbuf, 0xD9);
  2637       emit_d8(cbuf, 0xC8-1+$src$$reg );
  2638       // fdecstp
  2639       emit_opcode (cbuf, 0xD9);
  2640       emit_opcode (cbuf, 0xF6);
  2642   %}
  2644   enc_class Push_ModD_encoding( regXD src0, regXD src1) %{
  2645     // Allocate a word
  2646     emit_opcode(cbuf,0x83);            // SUB ESP,8
  2647     emit_opcode(cbuf,0xEC);
  2648     emit_d8(cbuf,0x08);
  2650     emit_opcode  (cbuf, 0xF2 );     // MOVSD [ESP], src1
  2651     emit_opcode  (cbuf, 0x0F );
  2652     emit_opcode  (cbuf, 0x11 );
  2653     encode_RegMem(cbuf, $src1$$reg, ESP_enc, 0x4, 0, 0, false);
  2655     emit_opcode(cbuf,0xDD );      // FLD_D [ESP]
  2656     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2658     emit_opcode  (cbuf, 0xF2 );     // MOVSD [ESP], src0
  2659     emit_opcode  (cbuf, 0x0F );
  2660     emit_opcode  (cbuf, 0x11 );
  2661     encode_RegMem(cbuf, $src0$$reg, ESP_enc, 0x4, 0, 0, false);
  2663     emit_opcode(cbuf,0xDD );      // FLD_D [ESP]
  2664     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2666   %}
  2668   enc_class Push_ModX_encoding( regX src0, regX src1) %{
  2669     // Allocate a word
  2670     emit_opcode(cbuf,0x83);            // SUB ESP,4
  2671     emit_opcode(cbuf,0xEC);
  2672     emit_d8(cbuf,0x04);
  2674     emit_opcode  (cbuf, 0xF3 );     // MOVSS [ESP], src1
  2675     emit_opcode  (cbuf, 0x0F );
  2676     emit_opcode  (cbuf, 0x11 );
  2677     encode_RegMem(cbuf, $src1$$reg, ESP_enc, 0x4, 0, 0, false);
  2679     emit_opcode(cbuf,0xD9 );      // FLD [ESP]
  2680     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2682     emit_opcode  (cbuf, 0xF3 );     // MOVSS [ESP], src0
  2683     emit_opcode  (cbuf, 0x0F );
  2684     emit_opcode  (cbuf, 0x11 );
  2685     encode_RegMem(cbuf, $src0$$reg, ESP_enc, 0x4, 0, 0, false);
  2687     emit_opcode(cbuf,0xD9 );      // FLD [ESP]
  2688     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2690   %}
  2692   enc_class Push_ResultXD(regXD dst) %{
  2693     store_to_stackslot( cbuf, 0xDD, 0x03, 0 ); //FSTP [ESP]
  2695     // UseXmmLoadAndClearUpper ? movsd dst,[esp] : movlpd dst,[esp]
  2696     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  2697     emit_opcode  (cbuf, 0x0F );
  2698     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  2699     encode_RegMem(cbuf, $dst$$reg, ESP_enc, 0x4, 0, 0, false);
  2701     emit_opcode(cbuf,0x83);    // ADD ESP,8
  2702     emit_opcode(cbuf,0xC4);
  2703     emit_d8(cbuf,0x08);
  2704   %}
  2706   enc_class Push_ResultX(regX dst, immI d8) %{
  2707     store_to_stackslot( cbuf, 0xD9, 0x03, 0 ); //FSTP_S [ESP]
  2709     emit_opcode  (cbuf, 0xF3 );     // MOVSS dst(xmm), [ESP]
  2710     emit_opcode  (cbuf, 0x0F );
  2711     emit_opcode  (cbuf, 0x10 );
  2712     encode_RegMem(cbuf, $dst$$reg, ESP_enc, 0x4, 0, 0, false);
  2714     emit_opcode(cbuf,0x83);    // ADD ESP,d8 (4 or 8)
  2715     emit_opcode(cbuf,0xC4);
  2716     emit_d8(cbuf,$d8$$constant);
  2717   %}
  2719   enc_class Push_SrcXD(regXD src) %{
  2720     // Allocate a word
  2721     emit_opcode(cbuf,0x83);            // SUB ESP,8
  2722     emit_opcode(cbuf,0xEC);
  2723     emit_d8(cbuf,0x08);
  2725     emit_opcode  (cbuf, 0xF2 );     // MOVSD [ESP], src
  2726     emit_opcode  (cbuf, 0x0F );
  2727     emit_opcode  (cbuf, 0x11 );
  2728     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  2730     emit_opcode(cbuf,0xDD );      // FLD_D [ESP]
  2731     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2732   %}
  2734   enc_class push_stack_temp_qword() %{
  2735     emit_opcode(cbuf,0x83);     // SUB ESP,8
  2736     emit_opcode(cbuf,0xEC);
  2737     emit_d8    (cbuf,0x08);
  2738   %}
  2740   enc_class pop_stack_temp_qword() %{
  2741     emit_opcode(cbuf,0x83);     // ADD ESP,8
  2742     emit_opcode(cbuf,0xC4);
  2743     emit_d8    (cbuf,0x08);
  2744   %}
  2746   enc_class push_xmm_to_fpr1( regXD xmm_src ) %{
  2747     emit_opcode  (cbuf, 0xF2 );     // MOVSD [ESP], xmm_src
  2748     emit_opcode  (cbuf, 0x0F );
  2749     emit_opcode  (cbuf, 0x11 );
  2750     encode_RegMem(cbuf, $xmm_src$$reg, ESP_enc, 0x4, 0, 0, false);
  2752     emit_opcode(cbuf,0xDD );      // FLD_D [ESP]
  2753     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2754   %}
  2756   // Compute X^Y using Intel's fast hardware instructions, if possible.
  2757   // Otherwise return a NaN.
  2758   enc_class pow_exp_core_encoding %{
  2759     // FPR1 holds Y*ln2(X).  Compute FPR1 = 2^(Y*ln2(X))
  2760     emit_opcode(cbuf,0xD9); emit_opcode(cbuf,0xC0);  // fdup = fld st(0)          Q       Q
  2761     emit_opcode(cbuf,0xD9); emit_opcode(cbuf,0xFC);  // frndint               int(Q)      Q
  2762     emit_opcode(cbuf,0xDC); emit_opcode(cbuf,0xE9);  // fsub st(1) -= st(0);  int(Q) frac(Q)
  2763     emit_opcode(cbuf,0xDB);                          // FISTP [ESP]           frac(Q)
  2764     emit_opcode(cbuf,0x1C);
  2765     emit_d8(cbuf,0x24);
  2766     emit_opcode(cbuf,0xD9); emit_opcode(cbuf,0xF0);  // f2xm1                 2^frac(Q)-1
  2767     emit_opcode(cbuf,0xD9); emit_opcode(cbuf,0xE8);  // fld1                  1 2^frac(Q)-1
  2768     emit_opcode(cbuf,0xDE); emit_opcode(cbuf,0xC1);  // faddp                 2^frac(Q)
  2769     emit_opcode(cbuf,0x8B);                          // mov rax,[esp+0]=int(Q)
  2770     encode_RegMem(cbuf, EAX_enc, ESP_enc, 0x4, 0, 0, false);
  2771     emit_opcode(cbuf,0xC7);                          // mov rcx,0xFFFFF800 - overflow mask
  2772     emit_rm(cbuf, 0x3, 0x0, ECX_enc);
  2773     emit_d32(cbuf,0xFFFFF800);
  2774     emit_opcode(cbuf,0x81);                          // add rax,1023 - the double exponent bias
  2775     emit_rm(cbuf, 0x3, 0x0, EAX_enc);
  2776     emit_d32(cbuf,1023);
  2777     emit_opcode(cbuf,0x8B);                          // mov rbx,eax
  2778     emit_rm(cbuf, 0x3, EBX_enc, EAX_enc);
  2779     emit_opcode(cbuf,0xC1);                          // shl rax,20 - Slide to exponent position
  2780     emit_rm(cbuf,0x3,0x4,EAX_enc);
  2781     emit_d8(cbuf,20);
  2782     emit_opcode(cbuf,0x85);                          // test rbx,ecx - check for overflow
  2783     emit_rm(cbuf, 0x3, EBX_enc, ECX_enc);
  2784     emit_opcode(cbuf,0x0F); emit_opcode(cbuf,0x45);  // CMOVne rax,ecx - overflow; stuff NAN into EAX
  2785     emit_rm(cbuf, 0x3, EAX_enc, ECX_enc);
  2786     emit_opcode(cbuf,0x89);                          // mov [esp+4],eax - Store as part of double word
  2787     encode_RegMem(cbuf, EAX_enc, ESP_enc, 0x4, 0, 4, false);
  2788     emit_opcode(cbuf,0xC7);                          // mov [esp+0],0   - [ESP] = (double)(1<<int(Q)) = 2^int(Q)
  2789     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  2790     emit_d32(cbuf,0);
  2791     emit_opcode(cbuf,0xDC);                          // fmul dword st(0),[esp+0]; FPR1 = 2^int(Q)*2^frac(Q) = 2^Q
  2792     encode_RegMem(cbuf, 0x1, ESP_enc, 0x4, 0, 0, false);
  2793   %}
  2795 //   enc_class Pop_Reg_Mod_D( regD dst, regD src)
  2796 //   was replaced by Push_Result_Mod_D followed by Pop_Reg_X() or Pop_Mem_X()
  2798   enc_class Push_Result_Mod_D( regD src) %{
  2799     if ($src$$reg != FPR1L_enc) {
  2800       // fincstp
  2801       emit_opcode (cbuf, 0xD9);
  2802       emit_opcode (cbuf, 0xF7);
  2803       // FXCH FPR1 with src
  2804       emit_opcode(cbuf, 0xD9);
  2805       emit_d8(cbuf, 0xC8-1+$src$$reg );
  2806       // fdecstp
  2807       emit_opcode (cbuf, 0xD9);
  2808       emit_opcode (cbuf, 0xF6);
  2810     // // following asm replaced with Pop_Reg_F or Pop_Mem_F
  2811     // // FSTP   FPR$dst$$reg
  2812     // emit_opcode( cbuf, 0xDD );
  2813     // emit_d8( cbuf, 0xD8+$dst$$reg );
  2814   %}
  2816   enc_class fnstsw_sahf_skip_parity() %{
  2817     // fnstsw ax
  2818     emit_opcode( cbuf, 0xDF );
  2819     emit_opcode( cbuf, 0xE0 );
  2820     // sahf
  2821     emit_opcode( cbuf, 0x9E );
  2822     // jnp  ::skip
  2823     emit_opcode( cbuf, 0x7B );
  2824     emit_opcode( cbuf, 0x05 );
  2825   %}
  2827   enc_class emitModD() %{
  2828     // fprem must be iterative
  2829     // :: loop
  2830     // fprem
  2831     emit_opcode( cbuf, 0xD9 );
  2832     emit_opcode( cbuf, 0xF8 );
  2833     // wait
  2834     emit_opcode( cbuf, 0x9b );
  2835     // fnstsw ax
  2836     emit_opcode( cbuf, 0xDF );
  2837     emit_opcode( cbuf, 0xE0 );
  2838     // sahf
  2839     emit_opcode( cbuf, 0x9E );
  2840     // jp  ::loop
  2841     emit_opcode( cbuf, 0x0F );
  2842     emit_opcode( cbuf, 0x8A );
  2843     emit_opcode( cbuf, 0xF4 );
  2844     emit_opcode( cbuf, 0xFF );
  2845     emit_opcode( cbuf, 0xFF );
  2846     emit_opcode( cbuf, 0xFF );
  2847   %}
  2849   enc_class fpu_flags() %{
  2850     // fnstsw_ax
  2851     emit_opcode( cbuf, 0xDF);
  2852     emit_opcode( cbuf, 0xE0);
  2853     // test ax,0x0400
  2854     emit_opcode( cbuf, 0x66 );   // operand-size prefix for 16-bit immediate
  2855     emit_opcode( cbuf, 0xA9 );
  2856     emit_d16   ( cbuf, 0x0400 );
  2857     // // // This sequence works, but stalls for 12-16 cycles on PPro
  2858     // // test rax,0x0400
  2859     // emit_opcode( cbuf, 0xA9 );
  2860     // emit_d32   ( cbuf, 0x00000400 );
  2861     //
  2862     // jz exit (no unordered comparison)
  2863     emit_opcode( cbuf, 0x74 );
  2864     emit_d8    ( cbuf, 0x02 );
  2865     // mov ah,1 - treat as LT case (set carry flag)
  2866     emit_opcode( cbuf, 0xB4 );
  2867     emit_d8    ( cbuf, 0x01 );
  2868     // sahf
  2869     emit_opcode( cbuf, 0x9E);
  2870   %}
  2872   enc_class cmpF_P6_fixup() %{
  2873     // Fixup the integer flags in case comparison involved a NaN
  2874     //
  2875     // JNP exit (no unordered comparison, P-flag is set by NaN)
  2876     emit_opcode( cbuf, 0x7B );
  2877     emit_d8    ( cbuf, 0x03 );
  2878     // MOV AH,1 - treat as LT case (set carry flag)
  2879     emit_opcode( cbuf, 0xB4 );
  2880     emit_d8    ( cbuf, 0x01 );
  2881     // SAHF
  2882     emit_opcode( cbuf, 0x9E);
  2883     // NOP     // target for branch to avoid branch to branch
  2884     emit_opcode( cbuf, 0x90);
  2885   %}
  2887 //     fnstsw_ax();
  2888 //     sahf();
  2889 //     movl(dst, nan_result);
  2890 //     jcc(Assembler::parity, exit);
  2891 //     movl(dst, less_result);
  2892 //     jcc(Assembler::below, exit);
  2893 //     movl(dst, equal_result);
  2894 //     jcc(Assembler::equal, exit);
  2895 //     movl(dst, greater_result);
  2897 // less_result     =  1;
  2898 // greater_result  = -1;
  2899 // equal_result    = 0;
  2900 // nan_result      = -1;
  2902   enc_class CmpF_Result(eRegI dst) %{
  2903     // fnstsw_ax();
  2904     emit_opcode( cbuf, 0xDF);
  2905     emit_opcode( cbuf, 0xE0);
  2906     // sahf
  2907     emit_opcode( cbuf, 0x9E);
  2908     // movl(dst, nan_result);
  2909     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2910     emit_d32( cbuf, -1 );
  2911     // jcc(Assembler::parity, exit);
  2912     emit_opcode( cbuf, 0x7A );
  2913     emit_d8    ( cbuf, 0x13 );
  2914     // movl(dst, less_result);
  2915     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2916     emit_d32( cbuf, -1 );
  2917     // jcc(Assembler::below, exit);
  2918     emit_opcode( cbuf, 0x72 );
  2919     emit_d8    ( cbuf, 0x0C );
  2920     // movl(dst, equal_result);
  2921     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2922     emit_d32( cbuf, 0 );
  2923     // jcc(Assembler::equal, exit);
  2924     emit_opcode( cbuf, 0x74 );
  2925     emit_d8    ( cbuf, 0x05 );
  2926     // movl(dst, greater_result);
  2927     emit_opcode( cbuf, 0xB8 + $dst$$reg);
  2928     emit_d32( cbuf, 1 );
  2929   %}
  2932   // XMM version of CmpF_Result. Because the XMM compare
  2933   // instructions set the EFLAGS directly. It becomes simpler than
  2934   // the float version above.
  2935   enc_class CmpX_Result(eRegI dst) %{
  2936     MacroAssembler _masm(&cbuf);
  2937     Label nan, inc, done;
  2939     __ jccb(Assembler::parity, nan);
  2940     __ jccb(Assembler::equal,  done);
  2941     __ jccb(Assembler::above,  inc);
  2942     __ bind(nan);
  2943     __ decrement(as_Register($dst$$reg)); // NO L qqq
  2944     __ jmpb(done);
  2945     __ bind(inc);
  2946     __ increment(as_Register($dst$$reg)); // NO L qqq
  2947     __ bind(done);
  2948   %}
  2950   // Compare the longs and set flags
  2951   // BROKEN!  Do Not use as-is
  2952   enc_class cmpl_test( eRegL src1, eRegL src2 ) %{
  2953     // CMP    $src1.hi,$src2.hi
  2954     emit_opcode( cbuf, 0x3B );
  2955     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
  2956     // JNE,s  done
  2957     emit_opcode(cbuf,0x75);
  2958     emit_d8(cbuf, 2 );
  2959     // CMP    $src1.lo,$src2.lo
  2960     emit_opcode( cbuf, 0x3B );
  2961     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  2962 // done:
  2963   %}
  2965   enc_class convert_int_long( regL dst, eRegI src ) %{
  2966     // mov $dst.lo,$src
  2967     int dst_encoding = $dst$$reg;
  2968     int src_encoding = $src$$reg;
  2969     encode_Copy( cbuf, dst_encoding  , src_encoding );
  2970     // mov $dst.hi,$src
  2971     encode_Copy( cbuf, HIGH_FROM_LOW(dst_encoding), src_encoding );
  2972     // sar $dst.hi,31
  2973     emit_opcode( cbuf, 0xC1 );
  2974     emit_rm(cbuf, 0x3, 7, HIGH_FROM_LOW(dst_encoding) );
  2975     emit_d8(cbuf, 0x1F );
  2976   %}
  2978   enc_class convert_long_double( eRegL src ) %{
  2979     // push $src.hi
  2980     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
  2981     // push $src.lo
  2982     emit_opcode(cbuf, 0x50+$src$$reg  );
  2983     // fild 64-bits at [SP]
  2984     emit_opcode(cbuf,0xdf);
  2985     emit_d8(cbuf, 0x6C);
  2986     emit_d8(cbuf, 0x24);
  2987     emit_d8(cbuf, 0x00);
  2988     // pop stack
  2989     emit_opcode(cbuf, 0x83); // add  SP, #8
  2990     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  2991     emit_d8(cbuf, 0x8);
  2992   %}
  2994   enc_class multiply_con_and_shift_high( eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr ) %{
  2995     // IMUL   EDX:EAX,$src1
  2996     emit_opcode( cbuf, 0xF7 );
  2997     emit_rm( cbuf, 0x3, 0x5, $src1$$reg );
  2998     // SAR    EDX,$cnt-32
  2999     int shift_count = ((int)$cnt$$constant) - 32;
  3000     if (shift_count > 0) {
  3001       emit_opcode(cbuf, 0xC1);
  3002       emit_rm(cbuf, 0x3, 7, $dst$$reg );
  3003       emit_d8(cbuf, shift_count);
  3005   %}
  3007   // this version doesn't have add sp, 8
  3008   enc_class convert_long_double2( eRegL src ) %{
  3009     // push $src.hi
  3010     emit_opcode(cbuf, 0x50+HIGH_FROM_LOW($src$$reg));
  3011     // push $src.lo
  3012     emit_opcode(cbuf, 0x50+$src$$reg  );
  3013     // fild 64-bits at [SP]
  3014     emit_opcode(cbuf,0xdf);
  3015     emit_d8(cbuf, 0x6C);
  3016     emit_d8(cbuf, 0x24);
  3017     emit_d8(cbuf, 0x00);
  3018   %}
  3020   enc_class long_int_multiply( eADXRegL dst, nadxRegI src) %{
  3021     // Basic idea: long = (long)int * (long)int
  3022     // IMUL EDX:EAX, src
  3023     emit_opcode( cbuf, 0xF7 );
  3024     emit_rm( cbuf, 0x3, 0x5, $src$$reg);
  3025   %}
  3027   enc_class long_uint_multiply( eADXRegL dst, nadxRegI src) %{
  3028     // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
  3029     // MUL EDX:EAX, src
  3030     emit_opcode( cbuf, 0xF7 );
  3031     emit_rm( cbuf, 0x3, 0x4, $src$$reg);
  3032   %}
  3034   enc_class long_multiply( eADXRegL dst, eRegL src, eRegI tmp ) %{
  3035     // Basic idea: lo(result) = lo(x_lo * y_lo)
  3036     //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
  3037     // MOV    $tmp,$src.lo
  3038     encode_Copy( cbuf, $tmp$$reg, $src$$reg );
  3039     // IMUL   $tmp,EDX
  3040     emit_opcode( cbuf, 0x0F );
  3041     emit_opcode( cbuf, 0xAF );
  3042     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  3043     // MOV    EDX,$src.hi
  3044     encode_Copy( cbuf, HIGH_FROM_LOW($dst$$reg), HIGH_FROM_LOW($src$$reg) );
  3045     // IMUL   EDX,EAX
  3046     emit_opcode( cbuf, 0x0F );
  3047     emit_opcode( cbuf, 0xAF );
  3048     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $dst$$reg );
  3049     // ADD    $tmp,EDX
  3050     emit_opcode( cbuf, 0x03 );
  3051     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  3052     // MUL   EDX:EAX,$src.lo
  3053     emit_opcode( cbuf, 0xF7 );
  3054     emit_rm( cbuf, 0x3, 0x4, $src$$reg );
  3055     // ADD    EDX,ESI
  3056     emit_opcode( cbuf, 0x03 );
  3057     emit_rm( cbuf, 0x3, HIGH_FROM_LOW($dst$$reg), $tmp$$reg );
  3058   %}
  3060   enc_class long_multiply_con( eADXRegL dst, immL_127 src, eRegI tmp ) %{
  3061     // Basic idea: lo(result) = lo(src * y_lo)
  3062     //             hi(result) = hi(src * y_lo) + lo(src * y_hi)
  3063     // IMUL   $tmp,EDX,$src
  3064     emit_opcode( cbuf, 0x6B );
  3065     emit_rm( cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg) );
  3066     emit_d8( cbuf, (int)$src$$constant );
  3067     // MOV    EDX,$src
  3068     emit_opcode(cbuf, 0xB8 + EDX_enc);
  3069     emit_d32( cbuf, (int)$src$$constant );
  3070     // MUL   EDX:EAX,EDX
  3071     emit_opcode( cbuf, 0xF7 );
  3072     emit_rm( cbuf, 0x3, 0x4, EDX_enc );
  3073     // ADD    EDX,ESI
  3074     emit_opcode( cbuf, 0x03 );
  3075     emit_rm( cbuf, 0x3, EDX_enc, $tmp$$reg );
  3076   %}
  3078   enc_class long_div( eRegL src1, eRegL src2 ) %{
  3079     // PUSH src1.hi
  3080     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
  3081     // PUSH src1.lo
  3082     emit_opcode(cbuf,               0x50+$src1$$reg  );
  3083     // PUSH src2.hi
  3084     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
  3085     // PUSH src2.lo
  3086     emit_opcode(cbuf,               0x50+$src2$$reg  );
  3087     // CALL directly to the runtime
  3088     cbuf.set_insts_mark();
  3089     emit_opcode(cbuf,0xE8);       // Call into runtime
  3090     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::ldiv) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3091     // Restore stack
  3092     emit_opcode(cbuf, 0x83); // add  SP, #framesize
  3093     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  3094     emit_d8(cbuf, 4*4);
  3095   %}
  3097   enc_class long_mod( eRegL src1, eRegL src2 ) %{
  3098     // PUSH src1.hi
  3099     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src1$$reg) );
  3100     // PUSH src1.lo
  3101     emit_opcode(cbuf,               0x50+$src1$$reg  );
  3102     // PUSH src2.hi
  3103     emit_opcode(cbuf, HIGH_FROM_LOW(0x50+$src2$$reg) );
  3104     // PUSH src2.lo
  3105     emit_opcode(cbuf,               0x50+$src2$$reg  );
  3106     // CALL directly to the runtime
  3107     cbuf.set_insts_mark();
  3108     emit_opcode(cbuf,0xE8);       // Call into runtime
  3109     emit_d32_reloc(cbuf, (CAST_FROM_FN_PTR(address, SharedRuntime::lrem ) - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3110     // Restore stack
  3111     emit_opcode(cbuf, 0x83); // add  SP, #framesize
  3112     emit_rm(cbuf, 0x3, 0x00, ESP_enc);
  3113     emit_d8(cbuf, 4*4);
  3114   %}
  3116   enc_class long_cmp_flags0( eRegL src, eRegI tmp ) %{
  3117     // MOV   $tmp,$src.lo
  3118     emit_opcode(cbuf, 0x8B);
  3119     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg);
  3120     // OR    $tmp,$src.hi
  3121     emit_opcode(cbuf, 0x0B);
  3122     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg));
  3123   %}
  3125   enc_class long_cmp_flags1( eRegL src1, eRegL src2 ) %{
  3126     // CMP    $src1.lo,$src2.lo
  3127     emit_opcode( cbuf, 0x3B );
  3128     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  3129     // JNE,s  skip
  3130     emit_cc(cbuf, 0x70, 0x5);
  3131     emit_d8(cbuf,2);
  3132     // CMP    $src1.hi,$src2.hi
  3133     emit_opcode( cbuf, 0x3B );
  3134     emit_rm(cbuf, 0x3, HIGH_FROM_LOW($src1$$reg), HIGH_FROM_LOW($src2$$reg) );
  3135   %}
  3137   enc_class long_cmp_flags2( eRegL src1, eRegL src2, eRegI tmp ) %{
  3138     // CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits
  3139     emit_opcode( cbuf, 0x3B );
  3140     emit_rm(cbuf, 0x3, $src1$$reg, $src2$$reg );
  3141     // MOV    $tmp,$src1.hi
  3142     emit_opcode( cbuf, 0x8B );
  3143     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src1$$reg) );
  3144     // SBB   $tmp,$src2.hi\t! Compute flags for long compare
  3145     emit_opcode( cbuf, 0x1B );
  3146     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src2$$reg) );
  3147   %}
  3149   enc_class long_cmp_flags3( eRegL src, eRegI tmp ) %{
  3150     // XOR    $tmp,$tmp
  3151     emit_opcode(cbuf,0x33);  // XOR
  3152     emit_rm(cbuf,0x3, $tmp$$reg, $tmp$$reg);
  3153     // CMP    $tmp,$src.lo
  3154     emit_opcode( cbuf, 0x3B );
  3155     emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg );
  3156     // SBB    $tmp,$src.hi
  3157     emit_opcode( cbuf, 0x1B );
  3158     emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($src$$reg) );
  3159   %}
  3161  // Sniff, sniff... smells like Gnu Superoptimizer
  3162   enc_class neg_long( eRegL dst ) %{
  3163     emit_opcode(cbuf,0xF7);    // NEG hi
  3164     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
  3165     emit_opcode(cbuf,0xF7);    // NEG lo
  3166     emit_rm    (cbuf,0x3, 0x3,               $dst$$reg );
  3167     emit_opcode(cbuf,0x83);    // SBB hi,0
  3168     emit_rm    (cbuf,0x3, 0x3, HIGH_FROM_LOW($dst$$reg));
  3169     emit_d8    (cbuf,0 );
  3170   %}
  3172   enc_class movq_ld(regXD dst, memory mem) %{
  3173     MacroAssembler _masm(&cbuf);
  3174     __ movq($dst$$XMMRegister, $mem$$Address);
  3175   %}
  3177   enc_class movq_st(memory mem, regXD src) %{
  3178     MacroAssembler _masm(&cbuf);
  3179     __ movq($mem$$Address, $src$$XMMRegister);
  3180   %}
  3182   enc_class pshufd_8x8(regX dst, regX src) %{
  3183     MacroAssembler _masm(&cbuf);
  3185     encode_CopyXD(cbuf, $dst$$reg, $src$$reg);
  3186     __ punpcklbw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg));
  3187     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg), 0x00);
  3188   %}
  3190   enc_class pshufd_4x16(regX dst, regX src) %{
  3191     MacroAssembler _masm(&cbuf);
  3193     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), 0x00);
  3194   %}
  3196   enc_class pshufd(regXD dst, regXD src, int mode) %{
  3197     MacroAssembler _masm(&cbuf);
  3199     __ pshufd(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), $mode);
  3200   %}
  3202   enc_class pxor(regXD dst, regXD src) %{
  3203     MacroAssembler _masm(&cbuf);
  3205     __ pxor(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg));
  3206   %}
  3208   enc_class mov_i2x(regXD dst, eRegI src) %{
  3209     MacroAssembler _masm(&cbuf);
  3211     __ movdl(as_XMMRegister($dst$$reg), as_Register($src$$reg));
  3212   %}
  3215   // Because the transitions from emitted code to the runtime
  3216   // monitorenter/exit helper stubs are so slow it's critical that
  3217   // we inline both the stack-locking fast-path and the inflated fast path.
  3218   //
  3219   // See also: cmpFastLock and cmpFastUnlock.
  3220   //
  3221   // What follows is a specialized inline transliteration of the code
  3222   // in slow_enter() and slow_exit().  If we're concerned about I$ bloat
  3223   // another option would be to emit TrySlowEnter and TrySlowExit methods
  3224   // at startup-time.  These methods would accept arguments as
  3225   // (rax,=Obj, rbx=Self, rcx=box, rdx=Scratch) and return success-failure
  3226   // indications in the icc.ZFlag.  Fast_Lock and Fast_Unlock would simply
  3227   // marshal the arguments and emit calls to TrySlowEnter and TrySlowExit.
  3228   // In practice, however, the # of lock sites is bounded and is usually small.
  3229   // Besides the call overhead, TrySlowEnter and TrySlowExit might suffer
  3230   // if the processor uses simple bimodal branch predictors keyed by EIP
  3231   // Since the helper routines would be called from multiple synchronization
  3232   // sites.
  3233   //
  3234   // An even better approach would be write "MonitorEnter()" and "MonitorExit()"
  3235   // in java - using j.u.c and unsafe - and just bind the lock and unlock sites
  3236   // to those specialized methods.  That'd give us a mostly platform-independent
  3237   // implementation that the JITs could optimize and inline at their pleasure.
  3238   // Done correctly, the only time we'd need to cross to native could would be
  3239   // to park() or unpark() threads.  We'd also need a few more unsafe operators
  3240   // to (a) prevent compiler-JIT reordering of non-volatile accesses, and
  3241   // (b) explicit barriers or fence operations.
  3242   //
  3243   // TODO:
  3244   //
  3245   // *  Arrange for C2 to pass "Self" into Fast_Lock and Fast_Unlock in one of the registers (scr).
  3246   //    This avoids manifesting the Self pointer in the Fast_Lock and Fast_Unlock terminals.
  3247   //    Given TLAB allocation, Self is usually manifested in a register, so passing it into
  3248   //    the lock operators would typically be faster than reifying Self.
  3249   //
  3250   // *  Ideally I'd define the primitives as:
  3251   //       fast_lock   (nax Obj, nax box, EAX tmp, nax scr) where box, tmp and scr are KILLED.
  3252   //       fast_unlock (nax Obj, EAX box, nax tmp) where box and tmp are KILLED
  3253   //    Unfortunately ADLC bugs prevent us from expressing the ideal form.
  3254   //    Instead, we're stuck with a rather awkward and brittle register assignments below.
  3255   //    Furthermore the register assignments are overconstrained, possibly resulting in
  3256   //    sub-optimal code near the synchronization site.
  3257   //
  3258   // *  Eliminate the sp-proximity tests and just use "== Self" tests instead.
  3259   //    Alternately, use a better sp-proximity test.
  3260   //
  3261   // *  Currently ObjectMonitor._Owner can hold either an sp value or a (THREAD *) value.
  3262   //    Either one is sufficient to uniquely identify a thread.
  3263   //    TODO: eliminate use of sp in _owner and use get_thread(tr) instead.
  3264   //
  3265   // *  Intrinsify notify() and notifyAll() for the common cases where the
  3266   //    object is locked by the calling thread but the waitlist is empty.
  3267   //    avoid the expensive JNI call to JVM_Notify() and JVM_NotifyAll().
  3268   //
  3269   // *  use jccb and jmpb instead of jcc and jmp to improve code density.
  3270   //    But beware of excessive branch density on AMD Opterons.
  3271   //
  3272   // *  Both Fast_Lock and Fast_Unlock set the ICC.ZF to indicate success
  3273   //    or failure of the fast-path.  If the fast-path fails then we pass
  3274   //    control to the slow-path, typically in C.  In Fast_Lock and
  3275   //    Fast_Unlock we often branch to DONE_LABEL, just to find that C2
  3276   //    will emit a conditional branch immediately after the node.
  3277   //    So we have branches to branches and lots of ICC.ZF games.
  3278   //    Instead, it might be better to have C2 pass a "FailureLabel"
  3279   //    into Fast_Lock and Fast_Unlock.  In the case of success, control
  3280   //    will drop through the node.  ICC.ZF is undefined at exit.
  3281   //    In the case of failure, the node will branch directly to the
  3282   //    FailureLabel
  3285   // obj: object to lock
  3286   // box: on-stack box address (displaced header location) - KILLED
  3287   // rax,: tmp -- KILLED
  3288   // scr: tmp -- KILLED
  3289   enc_class Fast_Lock( eRegP obj, eRegP box, eAXRegI tmp, eRegP scr ) %{
  3291     Register objReg = as_Register($obj$$reg);
  3292     Register boxReg = as_Register($box$$reg);
  3293     Register tmpReg = as_Register($tmp$$reg);
  3294     Register scrReg = as_Register($scr$$reg);
  3296     // Ensure the register assignents are disjoint
  3297     guarantee (objReg != boxReg, "") ;
  3298     guarantee (objReg != tmpReg, "") ;
  3299     guarantee (objReg != scrReg, "") ;
  3300     guarantee (boxReg != tmpReg, "") ;
  3301     guarantee (boxReg != scrReg, "") ;
  3302     guarantee (tmpReg == as_Register(EAX_enc), "") ;
  3304     MacroAssembler masm(&cbuf);
  3306     if (_counters != NULL) {
  3307       masm.atomic_incl(ExternalAddress((address) _counters->total_entry_count_addr()));
  3309     if (EmitSync & 1) {
  3310         // set box->dhw = unused_mark (3)
  3311         // Force all sync thru slow-path: slow_enter() and slow_exit() 
  3312         masm.movptr (Address(boxReg, 0), int32_t(markOopDesc::unused_mark())) ;             
  3313         masm.cmpptr (rsp, (int32_t)0) ;                        
  3314     } else 
  3315     if (EmitSync & 2) { 
  3316         Label DONE_LABEL ;           
  3317         if (UseBiasedLocking) {
  3318            // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument.
  3319            masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
  3322         masm.movptr(tmpReg, Address(objReg, 0)) ;          // fetch markword 
  3323         masm.orptr (tmpReg, 0x1);
  3324         masm.movptr(Address(boxReg, 0), tmpReg);           // Anticipate successful CAS 
  3325         if (os::is_MP()) { masm.lock();  }
  3326         masm.cmpxchgptr(boxReg, Address(objReg, 0));          // Updates tmpReg
  3327         masm.jcc(Assembler::equal, DONE_LABEL);
  3328         // Recursive locking
  3329         masm.subptr(tmpReg, rsp);
  3330         masm.andptr(tmpReg, (int32_t) 0xFFFFF003 );
  3331         masm.movptr(Address(boxReg, 0), tmpReg);
  3332         masm.bind(DONE_LABEL) ; 
  3333     } else {  
  3334       // Possible cases that we'll encounter in fast_lock 
  3335       // ------------------------------------------------
  3336       // * Inflated
  3337       //    -- unlocked
  3338       //    -- Locked
  3339       //       = by self
  3340       //       = by other
  3341       // * biased
  3342       //    -- by Self
  3343       //    -- by other
  3344       // * neutral
  3345       // * stack-locked
  3346       //    -- by self
  3347       //       = sp-proximity test hits
  3348       //       = sp-proximity test generates false-negative
  3349       //    -- by other
  3350       //
  3352       Label IsInflated, DONE_LABEL, PopDone ;
  3354       // TODO: optimize away redundant LDs of obj->mark and improve the markword triage
  3355       // order to reduce the number of conditional branches in the most common cases.
  3356       // Beware -- there's a subtle invariant that fetch of the markword
  3357       // at [FETCH], below, will never observe a biased encoding (*101b).
  3358       // If this invariant is not held we risk exclusion (safety) failure.
  3359       if (UseBiasedLocking && !UseOptoBiasInlining) {
  3360         masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
  3363       masm.movptr(tmpReg, Address(objReg, 0)) ;         // [FETCH]
  3364       masm.testptr(tmpReg, 0x02) ;                      // Inflated v (Stack-locked or neutral)
  3365       masm.jccb  (Assembler::notZero, IsInflated) ;
  3367       // Attempt stack-locking ...
  3368       masm.orptr (tmpReg, 0x1);
  3369       masm.movptr(Address(boxReg, 0), tmpReg);          // Anticipate successful CAS
  3370       if (os::is_MP()) { masm.lock();  }
  3371       masm.cmpxchgptr(boxReg, Address(objReg, 0));           // Updates tmpReg
  3372       if (_counters != NULL) {
  3373         masm.cond_inc32(Assembler::equal,
  3374                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
  3376       masm.jccb (Assembler::equal, DONE_LABEL);
  3378       // Recursive locking
  3379       masm.subptr(tmpReg, rsp);
  3380       masm.andptr(tmpReg, 0xFFFFF003 );
  3381       masm.movptr(Address(boxReg, 0), tmpReg);
  3382       if (_counters != NULL) {
  3383         masm.cond_inc32(Assembler::equal,
  3384                         ExternalAddress((address)_counters->fast_path_entry_count_addr()));
  3386       masm.jmp  (DONE_LABEL) ;
  3388       masm.bind (IsInflated) ;
  3390       // The object is inflated.
  3391       //
  3392       // TODO-FIXME: eliminate the ugly use of manifest constants:
  3393       //   Use markOopDesc::monitor_value instead of "2".
  3394       //   use markOop::unused_mark() instead of "3".
  3395       // The tmpReg value is an objectMonitor reference ORed with
  3396       // markOopDesc::monitor_value (2).   We can either convert tmpReg to an
  3397       // objectmonitor pointer by masking off the "2" bit or we can just
  3398       // use tmpReg as an objectmonitor pointer but bias the objectmonitor
  3399       // field offsets with "-2" to compensate for and annul the low-order tag bit.
  3400       //
  3401       // I use the latter as it avoids AGI stalls.
  3402       // As such, we write "mov r, [tmpReg+OFFSETOF(Owner)-2]"
  3403       // instead of "mov r, [tmpReg+OFFSETOF(Owner)]".
  3404       //
  3405       #define OFFSET_SKEWED(f) ((ObjectMonitor::f ## _offset_in_bytes())-2)
  3407       // boxReg refers to the on-stack BasicLock in the current frame.
  3408       // We'd like to write:
  3409       //   set box->_displaced_header = markOop::unused_mark().  Any non-0 value suffices.
  3410       // This is convenient but results a ST-before-CAS penalty.  The following CAS suffers
  3411       // additional latency as we have another ST in the store buffer that must drain.
  3413       if (EmitSync & 8192) { 
  3414          masm.movptr(Address(boxReg, 0), 3) ;            // results in ST-before-CAS penalty
  3415          masm.get_thread (scrReg) ; 
  3416          masm.movptr(boxReg, tmpReg);                    // consider: LEA box, [tmp-2] 
  3417          masm.movptr(tmpReg, NULL_WORD);                 // consider: xor vs mov
  3418          if (os::is_MP()) { masm.lock(); } 
  3419          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
  3420       } else 
  3421       if ((EmitSync & 128) == 0) {                      // avoid ST-before-CAS
  3422          masm.movptr(scrReg, boxReg) ; 
  3423          masm.movptr(boxReg, tmpReg);                   // consider: LEA box, [tmp-2] 
  3425          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
  3426          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3427             // prefetchw [eax + Offset(_owner)-2]
  3428             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
  3431          if ((EmitSync & 64) == 0) {
  3432            // Optimistic form: consider XORL tmpReg,tmpReg
  3433            masm.movptr(tmpReg, NULL_WORD) ; 
  3434          } else { 
  3435            // Can suffer RTS->RTO upgrades on shared or cold $ lines
  3436            // Test-And-CAS instead of CAS
  3437            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
  3438            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
  3439            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
  3442          // Appears unlocked - try to swing _owner from null to non-null.
  3443          // Ideally, I'd manifest "Self" with get_thread and then attempt
  3444          // to CAS the register containing Self into m->Owner.
  3445          // But we don't have enough registers, so instead we can either try to CAS
  3446          // rsp or the address of the box (in scr) into &m->owner.  If the CAS succeeds
  3447          // we later store "Self" into m->Owner.  Transiently storing a stack address
  3448          // (rsp or the address of the box) into  m->owner is harmless.
  3449          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
  3450          if (os::is_MP()) { masm.lock();  }
  3451          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
  3452          masm.movptr(Address(scrReg, 0), 3) ;          // box->_displaced_header = 3
  3453          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3454          masm.get_thread (scrReg) ;                    // beware: clobbers ICCs
  3455          masm.movptr(Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2), scrReg) ; 
  3456          masm.xorptr(boxReg, boxReg) ;                 // set icc.ZFlag = 1 to indicate success
  3458          // If the CAS fails we can either retry or pass control to the slow-path.  
  3459          // We use the latter tactic.  
  3460          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
  3461          // If the CAS was successful ...
  3462          //   Self has acquired the lock
  3463          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
  3464          // Intentional fall-through into DONE_LABEL ...
  3465       } else {
  3466          masm.movptr(Address(boxReg, 0), 3) ;       // results in ST-before-CAS penalty
  3467          masm.movptr(boxReg, tmpReg) ; 
  3469          // Using a prefetchw helps avoid later RTS->RTO upgrades and cache probes
  3470          if ((EmitSync & 2048) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3471             // prefetchw [eax + Offset(_owner)-2]
  3472             masm.prefetchw(Address(rax, ObjectMonitor::owner_offset_in_bytes()-2));
  3475          if ((EmitSync & 64) == 0) {
  3476            // Optimistic form
  3477            masm.xorptr  (tmpReg, tmpReg) ; 
  3478          } else { 
  3479            // Can suffer RTS->RTO upgrades on shared or cold $ lines
  3480            masm.movptr(tmpReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;   // rax, = m->_owner
  3481            masm.testptr(tmpReg, tmpReg) ;                   // Locked ? 
  3482            masm.jccb  (Assembler::notZero, DONE_LABEL) ;                   
  3485          // Appears unlocked - try to swing _owner from null to non-null.
  3486          // Use either "Self" (in scr) or rsp as thread identity in _owner.
  3487          // Invariant: tmpReg == 0.  tmpReg is EAX which is the implicit cmpxchg comparand.
  3488          masm.get_thread (scrReg) ;
  3489          if (os::is_MP()) { masm.lock(); }
  3490          masm.cmpxchgptr(scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
  3492          // If the CAS fails we can either retry or pass control to the slow-path.
  3493          // We use the latter tactic.
  3494          // Pass the CAS result in the icc.ZFlag into DONE_LABEL
  3495          // If the CAS was successful ...
  3496          //   Self has acquired the lock
  3497          //   Invariant: m->_recursions should already be 0, so we don't need to explicitly set it.
  3498          // Intentional fall-through into DONE_LABEL ...
  3501       // DONE_LABEL is a hot target - we'd really like to place it at the
  3502       // start of cache line by padding with NOPs.
  3503       // See the AMD and Intel software optimization manuals for the
  3504       // most efficient "long" NOP encodings.
  3505       // Unfortunately none of our alignment mechanisms suffice.
  3506       masm.bind(DONE_LABEL);
  3508       // Avoid branch-to-branch on AMD processors
  3509       // This appears to be superstition.
  3510       if (EmitSync & 32) masm.nop() ;
  3513       // At DONE_LABEL the icc ZFlag is set as follows ...
  3514       // Fast_Unlock uses the same protocol.
  3515       // ZFlag == 1 -> Success
  3516       // ZFlag == 0 -> Failure - force control through the slow-path
  3518   %}
  3520   // obj: object to unlock
  3521   // box: box address (displaced header location), killed.  Must be EAX.
  3522   // rbx,: killed tmp; cannot be obj nor box.
  3523   //
  3524   // Some commentary on balanced locking:
  3525   //
  3526   // Fast_Lock and Fast_Unlock are emitted only for provably balanced lock sites.
  3527   // Methods that don't have provably balanced locking are forced to run in the
  3528   // interpreter - such methods won't be compiled to use fast_lock and fast_unlock.
  3529   // The interpreter provides two properties:
  3530   // I1:  At return-time the interpreter automatically and quietly unlocks any
  3531   //      objects acquired the current activation (frame).  Recall that the
  3532   //      interpreter maintains an on-stack list of locks currently held by
  3533   //      a frame.
  3534   // I2:  If a method attempts to unlock an object that is not held by the
  3535   //      the frame the interpreter throws IMSX.
  3536   //
  3537   // Lets say A(), which has provably balanced locking, acquires O and then calls B().
  3538   // B() doesn't have provably balanced locking so it runs in the interpreter.
  3539   // Control returns to A() and A() unlocks O.  By I1 and I2, above, we know that O
  3540   // is still locked by A().
  3541   //
  3542   // The only other source of unbalanced locking would be JNI.  The "Java Native Interface:
  3543   // Programmer's Guide and Specification" claims that an object locked by jni_monitorenter
  3544   // should not be unlocked by "normal" java-level locking and vice-versa.  The specification
  3545   // doesn't specify what will occur if a program engages in such mixed-mode locking, however.
  3547   enc_class Fast_Unlock( nabxRegP obj, eAXRegP box, eRegP tmp) %{
  3549     Register objReg = as_Register($obj$$reg);
  3550     Register boxReg = as_Register($box$$reg);
  3551     Register tmpReg = as_Register($tmp$$reg);
  3553     guarantee (objReg != boxReg, "") ;
  3554     guarantee (objReg != tmpReg, "") ;
  3555     guarantee (boxReg != tmpReg, "") ;
  3556     guarantee (boxReg == as_Register(EAX_enc), "") ;
  3557     MacroAssembler masm(&cbuf);
  3559     if (EmitSync & 4) {
  3560       // Disable - inhibit all inlining.  Force control through the slow-path
  3561       masm.cmpptr (rsp, 0) ; 
  3562     } else 
  3563     if (EmitSync & 8) {
  3564       Label DONE_LABEL ;
  3565       if (UseBiasedLocking) {
  3566          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3568       // classic stack-locking code ...
  3569       masm.movptr(tmpReg, Address(boxReg, 0)) ;
  3570       masm.testptr(tmpReg, tmpReg) ;
  3571       masm.jcc   (Assembler::zero, DONE_LABEL) ;
  3572       if (os::is_MP()) { masm.lock(); }
  3573       masm.cmpxchgptr(tmpReg, Address(objReg, 0));          // Uses EAX which is box
  3574       masm.bind(DONE_LABEL);
  3575     } else {
  3576       Label DONE_LABEL, Stacked, CheckSucc, Inflated ;
  3578       // Critically, the biased locking test must have precedence over
  3579       // and appear before the (box->dhw == 0) recursive stack-lock test.
  3580       if (UseBiasedLocking && !UseOptoBiasInlining) {
  3581          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3584       masm.cmpptr(Address(boxReg, 0), 0) ;            // Examine the displaced header
  3585       masm.movptr(tmpReg, Address(objReg, 0)) ;       // Examine the object's markword
  3586       masm.jccb  (Assembler::zero, DONE_LABEL) ;      // 0 indicates recursive stack-lock
  3588       masm.testptr(tmpReg, 0x02) ;                     // Inflated? 
  3589       masm.jccb  (Assembler::zero, Stacked) ;
  3591       masm.bind  (Inflated) ;
  3592       // It's inflated.
  3593       // Despite our balanced locking property we still check that m->_owner == Self
  3594       // as java routines or native JNI code called by this thread might
  3595       // have released the lock.
  3596       // Refer to the comments in synchronizer.cpp for how we might encode extra
  3597       // state in _succ so we can avoid fetching EntryList|cxq.
  3598       //
  3599       // I'd like to add more cases in fast_lock() and fast_unlock() --
  3600       // such as recursive enter and exit -- but we have to be wary of
  3601       // I$ bloat, T$ effects and BP$ effects.
  3602       //
  3603       // If there's no contention try a 1-0 exit.  That is, exit without
  3604       // a costly MEMBAR or CAS.  See synchronizer.cpp for details on how
  3605       // we detect and recover from the race that the 1-0 exit admits.
  3606       //
  3607       // Conceptually Fast_Unlock() must execute a STST|LDST "release" barrier
  3608       // before it STs null into _owner, releasing the lock.  Updates
  3609       // to data protected by the critical section must be visible before
  3610       // we drop the lock (and thus before any other thread could acquire
  3611       // the lock and observe the fields protected by the lock).
  3612       // IA32's memory-model is SPO, so STs are ordered with respect to
  3613       // each other and there's no need for an explicit barrier (fence).
  3614       // See also http://gee.cs.oswego.edu/dl/jmm/cookbook.html.
  3616       masm.get_thread (boxReg) ;
  3617       if ((EmitSync & 4096) && VM_Version::supports_3dnow_prefetch() && os::is_MP()) {
  3618         // prefetchw [ebx + Offset(_owner)-2]
  3619         masm.prefetchw(Address(rbx, ObjectMonitor::owner_offset_in_bytes()-2));
  3622       // Note that we could employ various encoding schemes to reduce
  3623       // the number of loads below (currently 4) to just 2 or 3.
  3624       // Refer to the comments in synchronizer.cpp.
  3625       // In practice the chain of fetches doesn't seem to impact performance, however.
  3626       if ((EmitSync & 65536) == 0 && (EmitSync & 256)) {
  3627          // Attempt to reduce branch density - AMD's branch predictor.
  3628          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
  3629          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
  3630          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
  3631          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
  3632          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3633          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3634          masm.jmpb  (DONE_LABEL) ; 
  3635       } else { 
  3636          masm.xorptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;  
  3637          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
  3638          masm.jccb  (Assembler::notZero, DONE_LABEL) ; 
  3639          masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; 
  3640          masm.orptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; 
  3641          masm.jccb  (Assembler::notZero, CheckSucc) ; 
  3642          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3643          masm.jmpb  (DONE_LABEL) ; 
  3646       // The Following code fragment (EmitSync & 65536) improves the performance of
  3647       // contended applications and contended synchronization microbenchmarks.
  3648       // Unfortunately the emission of the code - even though not executed - causes regressions
  3649       // in scimark and jetstream, evidently because of $ effects.  Replacing the code
  3650       // with an equal number of never-executed NOPs results in the same regression.
  3651       // We leave it off by default.
  3653       if ((EmitSync & 65536) != 0) {
  3654          Label LSuccess, LGoSlowPath ;
  3656          masm.bind  (CheckSucc) ;
  3658          // Optional pre-test ... it's safe to elide this
  3659          if ((EmitSync & 16) == 0) { 
  3660             masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
  3661             masm.jccb  (Assembler::zero, LGoSlowPath) ; 
  3664          // We have a classic Dekker-style idiom:
  3665          //    ST m->_owner = 0 ; MEMBAR; LD m->_succ
  3666          // There are a number of ways to implement the barrier:
  3667          // (1) lock:andl &m->_owner, 0
  3668          //     is fast, but mask doesn't currently support the "ANDL M,IMM32" form.
  3669          //     LOCK: ANDL [ebx+Offset(_Owner)-2], 0
  3670          //     Encodes as 81 31 OFF32 IMM32 or 83 63 OFF8 IMM8
  3671          // (2) If supported, an explicit MFENCE is appealing.
  3672          //     In older IA32 processors MFENCE is slower than lock:add or xchg
  3673          //     particularly if the write-buffer is full as might be the case if
  3674          //     if stores closely precede the fence or fence-equivalent instruction.
  3675          //     In more modern implementations MFENCE appears faster, however.
  3676          // (3) In lieu of an explicit fence, use lock:addl to the top-of-stack
  3677          //     The $lines underlying the top-of-stack should be in M-state.
  3678          //     The locked add instruction is serializing, of course.
  3679          // (4) Use xchg, which is serializing
  3680          //     mov boxReg, 0; xchgl boxReg, [tmpReg + Offset(_owner)-2] also works
  3681          // (5) ST m->_owner = 0 and then execute lock:orl &m->_succ, 0.
  3682          //     The integer condition codes will tell us if succ was 0.
  3683          //     Since _succ and _owner should reside in the same $line and
  3684          //     we just stored into _owner, it's likely that the $line
  3685          //     remains in M-state for the lock:orl.
  3686          //
  3687          // We currently use (3), although it's likely that switching to (2)
  3688          // is correct for the future.
  3690          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ; 
  3691          if (os::is_MP()) { 
  3692             if (VM_Version::supports_sse2() && 1 == FenceInstruction) { 
  3693               masm.mfence();
  3694             } else { 
  3695               masm.lock () ; masm.addptr(Address(rsp, 0), 0) ; 
  3698          // Ratify _succ remains non-null
  3699          masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), 0) ; 
  3700          masm.jccb  (Assembler::notZero, LSuccess) ; 
  3702          masm.xorptr(boxReg, boxReg) ;                  // box is really EAX
  3703          if (os::is_MP()) { masm.lock(); }
  3704          masm.cmpxchgptr(rsp, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2));
  3705          masm.jccb  (Assembler::notEqual, LSuccess) ;
  3706          // Since we're low on registers we installed rsp as a placeholding in _owner.
  3707          // Now install Self over rsp.  This is safe as we're transitioning from
  3708          // non-null to non=null
  3709          masm.get_thread (boxReg) ;
  3710          masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), boxReg) ;
  3711          // Intentional fall-through into LGoSlowPath ...
  3713          masm.bind  (LGoSlowPath) ; 
  3714          masm.orptr(boxReg, 1) ;                      // set ICC.ZF=0 to indicate failure
  3715          masm.jmpb  (DONE_LABEL) ; 
  3717          masm.bind  (LSuccess) ; 
  3718          masm.xorptr(boxReg, boxReg) ;                 // set ICC.ZF=1 to indicate success
  3719          masm.jmpb  (DONE_LABEL) ; 
  3722       masm.bind (Stacked) ;
  3723       // It's not inflated and it's not recursively stack-locked and it's not biased.
  3724       // It must be stack-locked.
  3725       // Try to reset the header to displaced header.
  3726       // The "box" value on the stack is stable, so we can reload
  3727       // and be assured we observe the same value as above.
  3728       masm.movptr(tmpReg, Address(boxReg, 0)) ;
  3729       if (os::is_MP()) {   masm.lock();    }
  3730       masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses EAX which is box
  3731       // Intention fall-thru into DONE_LABEL
  3734       // DONE_LABEL is a hot target - we'd really like to place it at the
  3735       // start of cache line by padding with NOPs.
  3736       // See the AMD and Intel software optimization manuals for the
  3737       // most efficient "long" NOP encodings.
  3738       // Unfortunately none of our alignment mechanisms suffice.
  3739       if ((EmitSync & 65536) == 0) {
  3740          masm.bind (CheckSucc) ;
  3742       masm.bind(DONE_LABEL);
  3744       // Avoid branch to branch on AMD processors
  3745       if (EmitSync & 32768) { masm.nop() ; }
  3747   %}
  3750   enc_class enc_pop_rdx() %{
  3751     emit_opcode(cbuf,0x5A);
  3752   %}
  3754   enc_class enc_rethrow() %{
  3755     cbuf.set_insts_mark();
  3756     emit_opcode(cbuf, 0xE9);        // jmp    entry
  3757     emit_d32_reloc(cbuf, (int)OptoRuntime::rethrow_stub() - ((int)cbuf.insts_end())-4,
  3758                    runtime_call_Relocation::spec(), RELOC_IMM32 );
  3759   %}
  3762   // Convert a double to an int.  Java semantics require we do complex
  3763   // manglelations in the corner cases.  So we set the rounding mode to
  3764   // 'zero', store the darned double down as an int, and reset the
  3765   // rounding mode to 'nearest'.  The hardware throws an exception which
  3766   // patches up the correct value directly to the stack.
  3767   enc_class D2I_encoding( regD src ) %{
  3768     // Flip to round-to-zero mode.  We attempted to allow invalid-op
  3769     // exceptions here, so that a NAN or other corner-case value will
  3770     // thrown an exception (but normal values get converted at full speed).
  3771     // However, I2C adapters and other float-stack manglers leave pending
  3772     // invalid-op exceptions hanging.  We would have to clear them before
  3773     // enabling them and that is more expensive than just testing for the
  3774     // invalid value Intel stores down in the corner cases.
  3775     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
  3776     emit_opcode(cbuf,0x2D);
  3777     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3778     // Allocate a word
  3779     emit_opcode(cbuf,0x83);            // SUB ESP,4
  3780     emit_opcode(cbuf,0xEC);
  3781     emit_d8(cbuf,0x04);
  3782     // Encoding assumes a double has been pushed into FPR0.
  3783     // Store down the double as an int, popping the FPU stack
  3784     emit_opcode(cbuf,0xDB);            // FISTP [ESP]
  3785     emit_opcode(cbuf,0x1C);
  3786     emit_d8(cbuf,0x24);
  3787     // Restore the rounding mode; mask the exception
  3788     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
  3789     emit_opcode(cbuf,0x2D);
  3790     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3791         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3792         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3794     // Load the converted int; adjust CPU stack
  3795     emit_opcode(cbuf,0x58);       // POP EAX
  3796     emit_opcode(cbuf,0x3D);       // CMP EAX,imm
  3797     emit_d32   (cbuf,0x80000000); //         0x80000000
  3798     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3799     emit_d8    (cbuf,0x07);       // Size of slow_call
  3800     // Push src onto stack slow-path
  3801     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
  3802     emit_d8    (cbuf,0xC0-1+$src$$reg );
  3803     // CALL directly to the runtime
  3804     cbuf.set_insts_mark();
  3805     emit_opcode(cbuf,0xE8);       // Call into runtime
  3806     emit_d32_reloc(cbuf, (StubRoutines::d2i_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3807     // Carry on here...
  3808   %}
  3810   enc_class D2L_encoding( regD src ) %{
  3811     emit_opcode(cbuf,0xD9);            // FLDCW  trunc
  3812     emit_opcode(cbuf,0x2D);
  3813     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3814     // Allocate a word
  3815     emit_opcode(cbuf,0x83);            // SUB ESP,8
  3816     emit_opcode(cbuf,0xEC);
  3817     emit_d8(cbuf,0x08);
  3818     // Encoding assumes a double has been pushed into FPR0.
  3819     // Store down the double as a long, popping the FPU stack
  3820     emit_opcode(cbuf,0xDF);            // FISTP [ESP]
  3821     emit_opcode(cbuf,0x3C);
  3822     emit_d8(cbuf,0x24);
  3823     // Restore the rounding mode; mask the exception
  3824     emit_opcode(cbuf,0xD9);            // FLDCW   std/24-bit mode
  3825     emit_opcode(cbuf,0x2D);
  3826     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3827         ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3828         : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3830     // Load the converted int; adjust CPU stack
  3831     emit_opcode(cbuf,0x58);       // POP EAX
  3832     emit_opcode(cbuf,0x5A);       // POP EDX
  3833     emit_opcode(cbuf,0x81);       // CMP EDX,imm
  3834     emit_d8    (cbuf,0xFA);       // rdx
  3835     emit_d32   (cbuf,0x80000000); //         0x80000000
  3836     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3837     emit_d8    (cbuf,0x07+4);     // Size of slow_call
  3838     emit_opcode(cbuf,0x85);       // TEST EAX,EAX
  3839     emit_opcode(cbuf,0xC0);       // 2/rax,/rax,
  3840     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  3841     emit_d8    (cbuf,0x07);       // Size of slow_call
  3842     // Push src onto stack slow-path
  3843     emit_opcode(cbuf,0xD9 );      // FLD     ST(i)
  3844     emit_d8    (cbuf,0xC0-1+$src$$reg );
  3845     // CALL directly to the runtime
  3846     cbuf.set_insts_mark();
  3847     emit_opcode(cbuf,0xE8);       // Call into runtime
  3848     emit_d32_reloc(cbuf, (StubRoutines::d2l_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3849     // Carry on here...
  3850   %}
  3852   enc_class X2L_encoding( regX src ) %{
  3853     // Allocate a word
  3854     emit_opcode(cbuf,0x83);      // SUB ESP,8
  3855     emit_opcode(cbuf,0xEC);
  3856     emit_d8(cbuf,0x08);
  3858     emit_opcode  (cbuf, 0xF3 );  // MOVSS [ESP], src
  3859     emit_opcode  (cbuf, 0x0F );
  3860     emit_opcode  (cbuf, 0x11 );
  3861     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  3863     emit_opcode(cbuf,0xD9 );     // FLD_S [ESP]
  3864     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  3866     emit_opcode(cbuf,0xD9);      // FLDCW  trunc
  3867     emit_opcode(cbuf,0x2D);
  3868     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3870     // Encoding assumes a double has been pushed into FPR0.
  3871     // Store down the double as a long, popping the FPU stack
  3872     emit_opcode(cbuf,0xDF);      // FISTP [ESP]
  3873     emit_opcode(cbuf,0x3C);
  3874     emit_d8(cbuf,0x24);
  3876     // Restore the rounding mode; mask the exception
  3877     emit_opcode(cbuf,0xD9);      // FLDCW   std/24-bit mode
  3878     emit_opcode(cbuf,0x2D);
  3879     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3880       ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3881       : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3883     // Load the converted int; adjust CPU stack
  3884     emit_opcode(cbuf,0x58);      // POP EAX
  3886     emit_opcode(cbuf,0x5A);      // POP EDX
  3888     emit_opcode(cbuf,0x81);      // CMP EDX,imm
  3889     emit_d8    (cbuf,0xFA);      // rdx
  3890     emit_d32   (cbuf,0x80000000);//         0x80000000
  3892     emit_opcode(cbuf,0x75);      // JNE around_slow_call
  3893     emit_d8    (cbuf,0x13+4);    // Size of slow_call
  3895     emit_opcode(cbuf,0x85);      // TEST EAX,EAX
  3896     emit_opcode(cbuf,0xC0);      // 2/rax,/rax,
  3898     emit_opcode(cbuf,0x75);      // JNE around_slow_call
  3899     emit_d8    (cbuf,0x13);      // Size of slow_call
  3901     // Allocate a word
  3902     emit_opcode(cbuf,0x83);      // SUB ESP,4
  3903     emit_opcode(cbuf,0xEC);
  3904     emit_d8(cbuf,0x04);
  3906     emit_opcode  (cbuf, 0xF3 );  // MOVSS [ESP], src
  3907     emit_opcode  (cbuf, 0x0F );
  3908     emit_opcode  (cbuf, 0x11 );
  3909     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  3911     emit_opcode(cbuf,0xD9 );     // FLD_S [ESP]
  3912     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  3914     emit_opcode(cbuf,0x83);      // ADD ESP,4
  3915     emit_opcode(cbuf,0xC4);
  3916     emit_d8(cbuf,0x04);
  3918     // CALL directly to the runtime
  3919     cbuf.set_insts_mark();
  3920     emit_opcode(cbuf,0xE8);       // Call into runtime
  3921     emit_d32_reloc(cbuf, (StubRoutines::d2l_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3922     // Carry on here...
  3923   %}
  3925   enc_class XD2L_encoding( regXD src ) %{
  3926     // Allocate a word
  3927     emit_opcode(cbuf,0x83);      // SUB ESP,8
  3928     emit_opcode(cbuf,0xEC);
  3929     emit_d8(cbuf,0x08);
  3931     emit_opcode  (cbuf, 0xF2 );  // MOVSD [ESP], src
  3932     emit_opcode  (cbuf, 0x0F );
  3933     emit_opcode  (cbuf, 0x11 );
  3934     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  3936     emit_opcode(cbuf,0xDD );     // FLD_D [ESP]
  3937     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  3939     emit_opcode(cbuf,0xD9);      // FLDCW  trunc
  3940     emit_opcode(cbuf,0x2D);
  3941     emit_d32(cbuf,(int)StubRoutines::addr_fpu_cntrl_wrd_trunc());
  3943     // Encoding assumes a double has been pushed into FPR0.
  3944     // Store down the double as a long, popping the FPU stack
  3945     emit_opcode(cbuf,0xDF);      // FISTP [ESP]
  3946     emit_opcode(cbuf,0x3C);
  3947     emit_d8(cbuf,0x24);
  3949     // Restore the rounding mode; mask the exception
  3950     emit_opcode(cbuf,0xD9);      // FLDCW   std/24-bit mode
  3951     emit_opcode(cbuf,0x2D);
  3952     emit_d32( cbuf, Compile::current()->in_24_bit_fp_mode()
  3953       ? (int)StubRoutines::addr_fpu_cntrl_wrd_24()
  3954       : (int)StubRoutines::addr_fpu_cntrl_wrd_std());
  3956     // Load the converted int; adjust CPU stack
  3957     emit_opcode(cbuf,0x58);      // POP EAX
  3959     emit_opcode(cbuf,0x5A);      // POP EDX
  3961     emit_opcode(cbuf,0x81);      // CMP EDX,imm
  3962     emit_d8    (cbuf,0xFA);      // rdx
  3963     emit_d32   (cbuf,0x80000000); //         0x80000000
  3965     emit_opcode(cbuf,0x75);      // JNE around_slow_call
  3966     emit_d8    (cbuf,0x13+4);    // Size of slow_call
  3968     emit_opcode(cbuf,0x85);      // TEST EAX,EAX
  3969     emit_opcode(cbuf,0xC0);      // 2/rax,/rax,
  3971     emit_opcode(cbuf,0x75);      // JNE around_slow_call
  3972     emit_d8    (cbuf,0x13);      // Size of slow_call
  3974     // Push src onto stack slow-path
  3975     // Allocate a word
  3976     emit_opcode(cbuf,0x83);      // SUB ESP,8
  3977     emit_opcode(cbuf,0xEC);
  3978     emit_d8(cbuf,0x08);
  3980     emit_opcode  (cbuf, 0xF2 );  // MOVSD [ESP], src
  3981     emit_opcode  (cbuf, 0x0F );
  3982     emit_opcode  (cbuf, 0x11 );
  3983     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  3985     emit_opcode(cbuf,0xDD );     // FLD_D [ESP]
  3986     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  3988     emit_opcode(cbuf,0x83);      // ADD ESP,8
  3989     emit_opcode(cbuf,0xC4);
  3990     emit_d8(cbuf,0x08);
  3992     // CALL directly to the runtime
  3993     cbuf.set_insts_mark();
  3994     emit_opcode(cbuf,0xE8);      // Call into runtime
  3995     emit_d32_reloc(cbuf, (StubRoutines::d2l_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  3996     // Carry on here...
  3997   %}
  3999   enc_class D2X_encoding( regX dst, regD src ) %{
  4000     // Allocate a word
  4001     emit_opcode(cbuf,0x83);            // SUB ESP,4
  4002     emit_opcode(cbuf,0xEC);
  4003     emit_d8(cbuf,0x04);
  4004     int pop = 0x02;
  4005     if ($src$$reg != FPR1L_enc) {
  4006       emit_opcode( cbuf, 0xD9 );       // FLD    ST(i-1)
  4007       emit_d8( cbuf, 0xC0-1+$src$$reg );
  4008       pop = 0x03;
  4010     store_to_stackslot( cbuf, 0xD9, pop, 0 ); // FST<P>_S  [ESP]
  4012     emit_opcode  (cbuf, 0xF3 );        // MOVSS dst(xmm), [ESP]
  4013     emit_opcode  (cbuf, 0x0F );
  4014     emit_opcode  (cbuf, 0x10 );
  4015     encode_RegMem(cbuf, $dst$$reg, ESP_enc, 0x4, 0, 0, false);
  4017     emit_opcode(cbuf,0x83);            // ADD ESP,4
  4018     emit_opcode(cbuf,0xC4);
  4019     emit_d8(cbuf,0x04);
  4020     // Carry on here...
  4021   %}
  4023   enc_class FX2I_encoding( regX src, eRegI dst ) %{
  4024     emit_rm(cbuf, 0x3, $dst$$reg, $src$$reg);
  4026     // Compare the result to see if we need to go to the slow path
  4027     emit_opcode(cbuf,0x81);       // CMP dst,imm
  4028     emit_rm    (cbuf,0x3,0x7,$dst$$reg);
  4029     emit_d32   (cbuf,0x80000000); //         0x80000000
  4031     emit_opcode(cbuf,0x75);       // JNE around_slow_call
  4032     emit_d8    (cbuf,0x13);       // Size of slow_call
  4033     // Store xmm to a temp memory
  4034     // location and push it onto stack.
  4036     emit_opcode(cbuf,0x83);  // SUB ESP,4
  4037     emit_opcode(cbuf,0xEC);
  4038     emit_d8(cbuf, $primary ? 0x8 : 0x4);
  4040     emit_opcode  (cbuf, $primary ? 0xF2 : 0xF3 );   // MOVSS [ESP], xmm
  4041     emit_opcode  (cbuf, 0x0F );
  4042     emit_opcode  (cbuf, 0x11 );
  4043     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  4045     emit_opcode(cbuf, $primary ? 0xDD : 0xD9 );      // FLD [ESP]
  4046     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  4048     emit_opcode(cbuf,0x83);    // ADD ESP,4
  4049     emit_opcode(cbuf,0xC4);
  4050     emit_d8(cbuf, $primary ? 0x8 : 0x4);
  4052     // CALL directly to the runtime
  4053     cbuf.set_insts_mark();
  4054     emit_opcode(cbuf,0xE8);       // Call into runtime
  4055     emit_d32_reloc(cbuf, (StubRoutines::d2i_wrapper() - cbuf.insts_end()) - 4, runtime_call_Relocation::spec(), RELOC_IMM32 );
  4057     // Carry on here...
  4058   %}
  4060   enc_class X2D_encoding( regD dst, regX src ) %{
  4061     // Allocate a word
  4062     emit_opcode(cbuf,0x83);     // SUB ESP,4
  4063     emit_opcode(cbuf,0xEC);
  4064     emit_d8(cbuf,0x04);
  4066     emit_opcode  (cbuf, 0xF3 ); // MOVSS [ESP], xmm
  4067     emit_opcode  (cbuf, 0x0F );
  4068     emit_opcode  (cbuf, 0x11 );
  4069     encode_RegMem(cbuf, $src$$reg, ESP_enc, 0x4, 0, 0, false);
  4071     emit_opcode(cbuf,0xD9 );    // FLD_S [ESP]
  4072     encode_RegMem(cbuf, 0x0, ESP_enc, 0x4, 0, 0, false);
  4074     emit_opcode(cbuf,0x83);     // ADD ESP,4
  4075     emit_opcode(cbuf,0xC4);
  4076     emit_d8(cbuf,0x04);
  4078     // Carry on here...
  4079   %}
  4081   enc_class AbsXF_encoding(regX dst) %{
  4082     address signmask_address=(address)float_signmask_pool;
  4083     // andpd:\tANDPS  $dst,[signconst]
  4084     emit_opcode(cbuf, 0x0F);
  4085     emit_opcode(cbuf, 0x54);
  4086     emit_rm(cbuf, 0x0, $dst$$reg, 0x5);
  4087     emit_d32(cbuf, (int)signmask_address);
  4088   %}
  4090   enc_class AbsXD_encoding(regXD dst) %{
  4091     address signmask_address=(address)double_signmask_pool;
  4092     // andpd:\tANDPD  $dst,[signconst]
  4093     emit_opcode(cbuf, 0x66);
  4094     emit_opcode(cbuf, 0x0F);
  4095     emit_opcode(cbuf, 0x54);
  4096     emit_rm(cbuf, 0x0, $dst$$reg, 0x5);
  4097     emit_d32(cbuf, (int)signmask_address);
  4098   %}
  4100   enc_class NegXF_encoding(regX dst) %{
  4101     address signmask_address=(address)float_signflip_pool;
  4102     // andpd:\tXORPS  $dst,[signconst]
  4103     emit_opcode(cbuf, 0x0F);
  4104     emit_opcode(cbuf, 0x57);
  4105     emit_rm(cbuf, 0x0, $dst$$reg, 0x5);
  4106     emit_d32(cbuf, (int)signmask_address);
  4107   %}
  4109   enc_class NegXD_encoding(regXD dst) %{
  4110     address signmask_address=(address)double_signflip_pool;
  4111     // andpd:\tXORPD  $dst,[signconst]
  4112     emit_opcode(cbuf, 0x66);
  4113     emit_opcode(cbuf, 0x0F);
  4114     emit_opcode(cbuf, 0x57);
  4115     emit_rm(cbuf, 0x0, $dst$$reg, 0x5);
  4116     emit_d32(cbuf, (int)signmask_address);
  4117   %}
  4119   enc_class FMul_ST_reg( eRegF src1 ) %{
  4120     // Operand was loaded from memory into fp ST (stack top)
  4121     // FMUL   ST,$src  /* D8 C8+i */
  4122     emit_opcode(cbuf, 0xD8);
  4123     emit_opcode(cbuf, 0xC8 + $src1$$reg);
  4124   %}
  4126   enc_class FAdd_ST_reg( eRegF src2 ) %{
  4127     // FADDP  ST,src2  /* D8 C0+i */
  4128     emit_opcode(cbuf, 0xD8);
  4129     emit_opcode(cbuf, 0xC0 + $src2$$reg);
  4130     //could use FADDP  src2,fpST  /* DE C0+i */
  4131   %}
  4133   enc_class FAddP_reg_ST( eRegF src2 ) %{
  4134     // FADDP  src2,ST  /* DE C0+i */
  4135     emit_opcode(cbuf, 0xDE);
  4136     emit_opcode(cbuf, 0xC0 + $src2$$reg);
  4137   %}
  4139   enc_class subF_divF_encode( eRegF src1, eRegF src2) %{
  4140     // Operand has been loaded into fp ST (stack top)
  4141       // FSUB   ST,$src1
  4142       emit_opcode(cbuf, 0xD8);
  4143       emit_opcode(cbuf, 0xE0 + $src1$$reg);
  4145       // FDIV
  4146       emit_opcode(cbuf, 0xD8);
  4147       emit_opcode(cbuf, 0xF0 + $src2$$reg);
  4148   %}
  4150   enc_class MulFAddF (eRegF src1, eRegF src2) %{
  4151     // Operand was loaded from memory into fp ST (stack top)
  4152     // FADD   ST,$src  /* D8 C0+i */
  4153     emit_opcode(cbuf, 0xD8);
  4154     emit_opcode(cbuf, 0xC0 + $src1$$reg);
  4156     // FMUL  ST,src2  /* D8 C*+i */
  4157     emit_opcode(cbuf, 0xD8);
  4158     emit_opcode(cbuf, 0xC8 + $src2$$reg);
  4159   %}
  4162   enc_class MulFAddFreverse (eRegF src1, eRegF src2) %{
  4163     // Operand was loaded from memory into fp ST (stack top)
  4164     // FADD   ST,$src  /* D8 C0+i */
  4165     emit_opcode(cbuf, 0xD8);
  4166     emit_opcode(cbuf, 0xC0 + $src1$$reg);
  4168     // FMULP  src2,ST  /* DE C8+i */
  4169     emit_opcode(cbuf, 0xDE);
  4170     emit_opcode(cbuf, 0xC8 + $src2$$reg);
  4171   %}
  4173   // Atomically load the volatile long
  4174   enc_class enc_loadL_volatile( memory mem, stackSlotL dst ) %{
  4175     emit_opcode(cbuf,0xDF);
  4176     int rm_byte_opcode = 0x05;
  4177     int base     = $mem$$base;
  4178     int index    = $mem$$index;
  4179     int scale    = $mem$$scale;
  4180     int displace = $mem$$disp;
  4181     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4182     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_is_oop);
  4183     store_to_stackslot( cbuf, 0x0DF, 0x07, $dst$$disp );
  4184   %}
  4186   enc_class enc_loadLX_volatile( memory mem, stackSlotL dst, regXD tmp ) %{
  4187     { // Atomic long load
  4188       // UseXmmLoadAndClearUpper ? movsd $tmp,$mem : movlpd $tmp,$mem
  4189       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  4190       emit_opcode(cbuf,0x0F);
  4191       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  4192       int base     = $mem$$base;
  4193       int index    = $mem$$index;
  4194       int scale    = $mem$$scale;
  4195       int displace = $mem$$disp;
  4196       bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4197       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4199     { // MOVSD $dst,$tmp ! atomic long store
  4200       emit_opcode(cbuf,0xF2);
  4201       emit_opcode(cbuf,0x0F);
  4202       emit_opcode(cbuf,0x11);
  4203       int base     = $dst$$base;
  4204       int index    = $dst$$index;
  4205       int scale    = $dst$$scale;
  4206       int displace = $dst$$disp;
  4207       bool disp_is_oop = $dst->disp_is_oop(); // disp-as-oop when working with static globals
  4208       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4210   %}
  4212   enc_class enc_loadLX_reg_volatile( memory mem, eRegL dst, regXD tmp ) %{
  4213     { // Atomic long load
  4214       // UseXmmLoadAndClearUpper ? movsd $tmp,$mem : movlpd $tmp,$mem
  4215       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  4216       emit_opcode(cbuf,0x0F);
  4217       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  4218       int base     = $mem$$base;
  4219       int index    = $mem$$index;
  4220       int scale    = $mem$$scale;
  4221       int displace = $mem$$disp;
  4222       bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4223       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4225     { // MOVD $dst.lo,$tmp
  4226       emit_opcode(cbuf,0x66);
  4227       emit_opcode(cbuf,0x0F);
  4228       emit_opcode(cbuf,0x7E);
  4229       emit_rm(cbuf, 0x3, $tmp$$reg, $dst$$reg);
  4231     { // PSRLQ $tmp,32
  4232       emit_opcode(cbuf,0x66);
  4233       emit_opcode(cbuf,0x0F);
  4234       emit_opcode(cbuf,0x73);
  4235       emit_rm(cbuf, 0x3, 0x02, $tmp$$reg);
  4236       emit_d8(cbuf, 0x20);
  4238     { // MOVD $dst.hi,$tmp
  4239       emit_opcode(cbuf,0x66);
  4240       emit_opcode(cbuf,0x0F);
  4241       emit_opcode(cbuf,0x7E);
  4242       emit_rm(cbuf, 0x3, $tmp$$reg, HIGH_FROM_LOW($dst$$reg));
  4244   %}
  4246   // Volatile Store Long.  Must be atomic, so move it into
  4247   // the FP TOS and then do a 64-bit FIST.  Has to probe the
  4248   // target address before the store (for null-ptr checks)
  4249   // so the memory operand is used twice in the encoding.
  4250   enc_class enc_storeL_volatile( memory mem, stackSlotL src ) %{
  4251     store_to_stackslot( cbuf, 0x0DF, 0x05, $src$$disp );
  4252     cbuf.set_insts_mark();            // Mark start of FIST in case $mem has an oop
  4253     emit_opcode(cbuf,0xDF);
  4254     int rm_byte_opcode = 0x07;
  4255     int base     = $mem$$base;
  4256     int index    = $mem$$index;
  4257     int scale    = $mem$$scale;
  4258     int displace = $mem$$disp;
  4259     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4260     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace, disp_is_oop);
  4261   %}
  4263   enc_class enc_storeLX_volatile( memory mem, stackSlotL src, regXD tmp) %{
  4264     { // Atomic long load
  4265       // UseXmmLoadAndClearUpper ? movsd $tmp,[$src] : movlpd $tmp,[$src]
  4266       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  4267       emit_opcode(cbuf,0x0F);
  4268       emit_opcode(cbuf,UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  4269       int base     = $src$$base;
  4270       int index    = $src$$index;
  4271       int scale    = $src$$scale;
  4272       int displace = $src$$disp;
  4273       bool disp_is_oop = $src->disp_is_oop(); // disp-as-oop when working with static globals
  4274       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4276     cbuf.set_insts_mark();            // Mark start of MOVSD in case $mem has an oop
  4277     { // MOVSD $mem,$tmp ! atomic long store
  4278       emit_opcode(cbuf,0xF2);
  4279       emit_opcode(cbuf,0x0F);
  4280       emit_opcode(cbuf,0x11);
  4281       int base     = $mem$$base;
  4282       int index    = $mem$$index;
  4283       int scale    = $mem$$scale;
  4284       int displace = $mem$$disp;
  4285       bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4286       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4288   %}
  4290   enc_class enc_storeLX_reg_volatile( memory mem, eRegL src, regXD tmp, regXD tmp2) %{
  4291     { // MOVD $tmp,$src.lo
  4292       emit_opcode(cbuf,0x66);
  4293       emit_opcode(cbuf,0x0F);
  4294       emit_opcode(cbuf,0x6E);
  4295       emit_rm(cbuf, 0x3, $tmp$$reg, $src$$reg);
  4297     { // MOVD $tmp2,$src.hi
  4298       emit_opcode(cbuf,0x66);
  4299       emit_opcode(cbuf,0x0F);
  4300       emit_opcode(cbuf,0x6E);
  4301       emit_rm(cbuf, 0x3, $tmp2$$reg, HIGH_FROM_LOW($src$$reg));
  4303     { // PUNPCKLDQ $tmp,$tmp2
  4304       emit_opcode(cbuf,0x66);
  4305       emit_opcode(cbuf,0x0F);
  4306       emit_opcode(cbuf,0x62);
  4307       emit_rm(cbuf, 0x3, $tmp$$reg, $tmp2$$reg);
  4309     cbuf.set_insts_mark();            // Mark start of MOVSD in case $mem has an oop
  4310     { // MOVSD $mem,$tmp ! atomic long store
  4311       emit_opcode(cbuf,0xF2);
  4312       emit_opcode(cbuf,0x0F);
  4313       emit_opcode(cbuf,0x11);
  4314       int base     = $mem$$base;
  4315       int index    = $mem$$index;
  4316       int scale    = $mem$$scale;
  4317       int displace = $mem$$disp;
  4318       bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when working with static globals
  4319       encode_RegMem(cbuf, $tmp$$reg, base, index, scale, displace, disp_is_oop);
  4321   %}
  4323   // Safepoint Poll.  This polls the safepoint page, and causes an
  4324   // exception if it is not readable. Unfortunately, it kills the condition code
  4325   // in the process
  4326   // We current use TESTL [spp],EDI
  4327   // A better choice might be TESTB [spp + pagesize() - CacheLineSize()],0
  4329   enc_class Safepoint_Poll() %{
  4330     cbuf.relocate(cbuf.insts_mark(), relocInfo::poll_type, 0);
  4331     emit_opcode(cbuf,0x85);
  4332     emit_rm (cbuf, 0x0, 0x7, 0x5);
  4333     emit_d32(cbuf, (intptr_t)os::get_polling_page());
  4334   %}
  4335 %}
  4338 //----------FRAME--------------------------------------------------------------
  4339 // Definition of frame structure and management information.
  4340 //
  4341 //  S T A C K   L A Y O U T    Allocators stack-slot number
  4342 //                             |   (to get allocators register number
  4343 //  G  Owned by    |        |  v    add OptoReg::stack0())
  4344 //  r   CALLER     |        |
  4345 //  o     |        +--------+      pad to even-align allocators stack-slot
  4346 //  w     V        |  pad0  |        numbers; owned by CALLER
  4347 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
  4348 //  h     ^        |   in   |  5
  4349 //        |        |  args  |  4   Holes in incoming args owned by SELF
  4350 //  |     |        |        |  3
  4351 //  |     |        +--------+
  4352 //  V     |        | old out|      Empty on Intel, window on Sparc
  4353 //        |    old |preserve|      Must be even aligned.
  4354 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
  4355 //        |        |   in   |  3   area for Intel ret address
  4356 //     Owned by    |preserve|      Empty on Sparc.
  4357 //       SELF      +--------+
  4358 //        |        |  pad2  |  2   pad to align old SP
  4359 //        |        +--------+  1
  4360 //        |        | locks  |  0
  4361 //        |        +--------+----> OptoReg::stack0(), even aligned
  4362 //        |        |  pad1  | 11   pad to align new SP
  4363 //        |        +--------+
  4364 //        |        |        | 10
  4365 //        |        | spills |  9   spills
  4366 //        V        |        |  8   (pad0 slot for callee)
  4367 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
  4368 //        ^        |  out   |  7
  4369 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
  4370 //     Owned by    +--------+
  4371 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
  4372 //        |    new |preserve|      Must be even-aligned.
  4373 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
  4374 //        |        |        |
  4375 //
  4376 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
  4377 //         known from SELF's arguments and the Java calling convention.
  4378 //         Region 6-7 is determined per call site.
  4379 // Note 2: If the calling convention leaves holes in the incoming argument
  4380 //         area, those holes are owned by SELF.  Holes in the outgoing area
  4381 //         are owned by the CALLEE.  Holes should not be nessecary in the
  4382 //         incoming area, as the Java calling convention is completely under
  4383 //         the control of the AD file.  Doubles can be sorted and packed to
  4384 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
  4385 //         varargs C calling conventions.
  4386 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
  4387 //         even aligned with pad0 as needed.
  4388 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
  4389 //         region 6-11 is even aligned; it may be padded out more so that
  4390 //         the region from SP to FP meets the minimum stack alignment.
  4392 frame %{
  4393   // What direction does stack grow in (assumed to be same for C & Java)
  4394   stack_direction(TOWARDS_LOW);
  4396   // These three registers define part of the calling convention
  4397   // between compiled code and the interpreter.
  4398   inline_cache_reg(EAX);                // Inline Cache Register
  4399   interpreter_method_oop_reg(EBX);      // Method Oop Register when calling interpreter
  4401   // Optional: name the operand used by cisc-spilling to access [stack_pointer + offset]
  4402   cisc_spilling_operand_name(indOffset32);
  4404   // Number of stack slots consumed by locking an object
  4405   sync_stack_slots(1);
  4407   // Compiled code's Frame Pointer
  4408   frame_pointer(ESP);
  4409   // Interpreter stores its frame pointer in a register which is
  4410   // stored to the stack by I2CAdaptors.
  4411   // I2CAdaptors convert from interpreted java to compiled java.
  4412   interpreter_frame_pointer(EBP);
  4414   // Stack alignment requirement
  4415   // Alignment size in bytes (128-bit -> 16 bytes)
  4416   stack_alignment(StackAlignmentInBytes);
  4418   // Number of stack slots between incoming argument block and the start of
  4419   // a new frame.  The PROLOG must add this many slots to the stack.  The
  4420   // EPILOG must remove this many slots.  Intel needs one slot for
  4421   // return address and one for rbp, (must save rbp)
  4422   in_preserve_stack_slots(2+VerifyStackAtCalls);
  4424   // Number of outgoing stack slots killed above the out_preserve_stack_slots
  4425   // for calls to C.  Supports the var-args backing area for register parms.
  4426   varargs_C_out_slots_killed(0);
  4428   // The after-PROLOG location of the return address.  Location of
  4429   // return address specifies a type (REG or STACK) and a number
  4430   // representing the register number (i.e. - use a register name) or
  4431   // stack slot.
  4432   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
  4433   // Otherwise, it is above the locks and verification slot and alignment word
  4434   return_addr(STACK - 1 +
  4435               round_to(1+VerifyStackAtCalls+
  4436               Compile::current()->fixed_slots(),
  4437               (StackAlignmentInBytes/wordSize)));
  4439   // Body of function which returns an integer array locating
  4440   // arguments either in registers or in stack slots.  Passed an array
  4441   // of ideal registers called "sig" and a "length" count.  Stack-slot
  4442   // offsets are based on outgoing arguments, i.e. a CALLER setting up
  4443   // arguments for a CALLEE.  Incoming stack arguments are
  4444   // automatically biased by the preserve_stack_slots field above.
  4445   calling_convention %{
  4446     // No difference between ingoing/outgoing just pass false
  4447     SharedRuntime::java_calling_convention(sig_bt, regs, length, false);
  4448   %}
  4451   // Body of function which returns an integer array locating
  4452   // arguments either in registers or in stack slots.  Passed an array
  4453   // of ideal registers called "sig" and a "length" count.  Stack-slot
  4454   // offsets are based on outgoing arguments, i.e. a CALLER setting up
  4455   // arguments for a CALLEE.  Incoming stack arguments are
  4456   // automatically biased by the preserve_stack_slots field above.
  4457   c_calling_convention %{
  4458     // This is obviously always outgoing
  4459     (void) SharedRuntime::c_calling_convention(sig_bt, regs, length);
  4460   %}
  4462   // Location of C & interpreter return values
  4463   c_return_value %{
  4464     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
  4465     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
  4466     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
  4468     // in SSE2+ mode we want to keep the FPU stack clean so pretend
  4469     // that C functions return float and double results in XMM0.
  4470     if( ideal_reg == Op_RegD && UseSSE>=2 )
  4471       return OptoRegPair(XMM0b_num,XMM0a_num);
  4472     if( ideal_reg == Op_RegF && UseSSE>=2 )
  4473       return OptoRegPair(OptoReg::Bad,XMM0a_num);
  4475     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
  4476   %}
  4478   // Location of return values
  4479   return_value %{
  4480     assert( ideal_reg >= Op_RegI && ideal_reg <= Op_RegL, "only return normal values" );
  4481     static int lo[Op_RegL+1] = { 0, 0, OptoReg::Bad, EAX_num,      EAX_num,      FPR1L_num,    FPR1L_num, EAX_num };
  4482     static int hi[Op_RegL+1] = { 0, 0, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, OptoReg::Bad, FPR1H_num, EDX_num };
  4483     if( ideal_reg == Op_RegD && UseSSE>=2 )
  4484       return OptoRegPair(XMM0b_num,XMM0a_num);
  4485     if( ideal_reg == Op_RegF && UseSSE>=1 )
  4486       return OptoRegPair(OptoReg::Bad,XMM0a_num);
  4487     return OptoRegPair(hi[ideal_reg],lo[ideal_reg]);
  4488   %}
  4490 %}
  4492 //----------ATTRIBUTES---------------------------------------------------------
  4493 //----------Operand Attributes-------------------------------------------------
  4494 op_attrib op_cost(0);        // Required cost attribute
  4496 //----------Instruction Attributes---------------------------------------------
  4497 ins_attrib ins_cost(100);       // Required cost attribute
  4498 ins_attrib ins_size(8);         // Required size attribute (in bits)
  4499 ins_attrib ins_short_branch(0); // Required flag: is this instruction a
  4500                                 // non-matching short branch variant of some
  4501                                                             // long branch?
  4502 ins_attrib ins_alignment(1);    // Required alignment attribute (must be a power of 2)
  4503                                 // specifies the alignment that some part of the instruction (not
  4504                                 // necessarily the start) requires.  If > 1, a compute_padding()
  4505                                 // function must be provided for the instruction
  4507 //----------OPERANDS-----------------------------------------------------------
  4508 // Operand definitions must precede instruction definitions for correct parsing
  4509 // in the ADLC because operands constitute user defined types which are used in
  4510 // instruction definitions.
  4512 //----------Simple Operands----------------------------------------------------
  4513 // Immediate Operands
  4514 // Integer Immediate
  4515 operand immI() %{
  4516   match(ConI);
  4518   op_cost(10);
  4519   format %{ %}
  4520   interface(CONST_INTER);
  4521 %}
  4523 // Constant for test vs zero
  4524 operand immI0() %{
  4525   predicate(n->get_int() == 0);
  4526   match(ConI);
  4528   op_cost(0);
  4529   format %{ %}
  4530   interface(CONST_INTER);
  4531 %}
  4533 // Constant for increment
  4534 operand immI1() %{
  4535   predicate(n->get_int() == 1);
  4536   match(ConI);
  4538   op_cost(0);
  4539   format %{ %}
  4540   interface(CONST_INTER);
  4541 %}
  4543 // Constant for decrement
  4544 operand immI_M1() %{
  4545   predicate(n->get_int() == -1);
  4546   match(ConI);
  4548   op_cost(0);
  4549   format %{ %}
  4550   interface(CONST_INTER);
  4551 %}
  4553 // Valid scale values for addressing modes
  4554 operand immI2() %{
  4555   predicate(0 <= n->get_int() && (n->get_int() <= 3));
  4556   match(ConI);
  4558   format %{ %}
  4559   interface(CONST_INTER);
  4560 %}
  4562 operand immI8() %{
  4563   predicate((-128 <= n->get_int()) && (n->get_int() <= 127));
  4564   match(ConI);
  4566   op_cost(5);
  4567   format %{ %}
  4568   interface(CONST_INTER);
  4569 %}
  4571 operand immI16() %{
  4572   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
  4573   match(ConI);
  4575   op_cost(10);
  4576   format %{ %}
  4577   interface(CONST_INTER);
  4578 %}
  4580 // Constant for long shifts
  4581 operand immI_32() %{
  4582   predicate( n->get_int() == 32 );
  4583   match(ConI);
  4585   op_cost(0);
  4586   format %{ %}
  4587   interface(CONST_INTER);
  4588 %}
  4590 operand immI_1_31() %{
  4591   predicate( n->get_int() >= 1 && n->get_int() <= 31 );
  4592   match(ConI);
  4594   op_cost(0);
  4595   format %{ %}
  4596   interface(CONST_INTER);
  4597 %}
  4599 operand immI_32_63() %{
  4600   predicate( n->get_int() >= 32 && n->get_int() <= 63 );
  4601   match(ConI);
  4602   op_cost(0);
  4604   format %{ %}
  4605   interface(CONST_INTER);
  4606 %}
  4608 operand immI_1() %{
  4609   predicate( n->get_int() == 1 );
  4610   match(ConI);
  4612   op_cost(0);
  4613   format %{ %}
  4614   interface(CONST_INTER);
  4615 %}
  4617 operand immI_2() %{
  4618   predicate( n->get_int() == 2 );
  4619   match(ConI);
  4621   op_cost(0);
  4622   format %{ %}
  4623   interface(CONST_INTER);
  4624 %}
  4626 operand immI_3() %{
  4627   predicate( n->get_int() == 3 );
  4628   match(ConI);
  4630   op_cost(0);
  4631   format %{ %}
  4632   interface(CONST_INTER);
  4633 %}
  4635 // Pointer Immediate
  4636 operand immP() %{
  4637   match(ConP);
  4639   op_cost(10);
  4640   format %{ %}
  4641   interface(CONST_INTER);
  4642 %}
  4644 // NULL Pointer Immediate
  4645 operand immP0() %{
  4646   predicate( n->get_ptr() == 0 );
  4647   match(ConP);
  4648   op_cost(0);
  4650   format %{ %}
  4651   interface(CONST_INTER);
  4652 %}
  4654 // Long Immediate
  4655 operand immL() %{
  4656   match(ConL);
  4658   op_cost(20);
  4659   format %{ %}
  4660   interface(CONST_INTER);
  4661 %}
  4663 // Long Immediate zero
  4664 operand immL0() %{
  4665   predicate( n->get_long() == 0L );
  4666   match(ConL);
  4667   op_cost(0);
  4669   format %{ %}
  4670   interface(CONST_INTER);
  4671 %}
  4673 // Long Immediate zero
  4674 operand immL_M1() %{
  4675   predicate( n->get_long() == -1L );
  4676   match(ConL);
  4677   op_cost(0);
  4679   format %{ %}
  4680   interface(CONST_INTER);
  4681 %}
  4683 // Long immediate from 0 to 127.
  4684 // Used for a shorter form of long mul by 10.
  4685 operand immL_127() %{
  4686   predicate((0 <= n->get_long()) && (n->get_long() <= 127));
  4687   match(ConL);
  4688   op_cost(0);
  4690   format %{ %}
  4691   interface(CONST_INTER);
  4692 %}
  4694 // Long Immediate: low 32-bit mask
  4695 operand immL_32bits() %{
  4696   predicate(n->get_long() == 0xFFFFFFFFL);
  4697   match(ConL);
  4698   op_cost(0);
  4700   format %{ %}
  4701   interface(CONST_INTER);
  4702 %}
  4704 // Long Immediate: low 32-bit mask
  4705 operand immL32() %{
  4706   predicate(n->get_long() == (int)(n->get_long()));
  4707   match(ConL);
  4708   op_cost(20);
  4710   format %{ %}
  4711   interface(CONST_INTER);
  4712 %}
  4714 //Double Immediate zero
  4715 operand immD0() %{
  4716   // Do additional (and counter-intuitive) test against NaN to work around VC++
  4717   // bug that generates code such that NaNs compare equal to 0.0
  4718   predicate( UseSSE<=1 && n->getd() == 0.0 && !g_isnan(n->getd()) );
  4719   match(ConD);
  4721   op_cost(5);
  4722   format %{ %}
  4723   interface(CONST_INTER);
  4724 %}
  4726 // Double Immediate one
  4727 operand immD1() %{
  4728   predicate( UseSSE<=1 && n->getd() == 1.0 );
  4729   match(ConD);
  4731   op_cost(5);
  4732   format %{ %}
  4733   interface(CONST_INTER);
  4734 %}
  4736 // Double Immediate
  4737 operand immD() %{
  4738   predicate(UseSSE<=1);
  4739   match(ConD);
  4741   op_cost(5);
  4742   format %{ %}
  4743   interface(CONST_INTER);
  4744 %}
  4746 operand immXD() %{
  4747   predicate(UseSSE>=2);
  4748   match(ConD);
  4750   op_cost(5);
  4751   format %{ %}
  4752   interface(CONST_INTER);
  4753 %}
  4755 // Double Immediate zero
  4756 operand immXD0() %{
  4757   // Do additional (and counter-intuitive) test against NaN to work around VC++
  4758   // bug that generates code such that NaNs compare equal to 0.0 AND do not
  4759   // compare equal to -0.0.
  4760   predicate( UseSSE>=2 && jlong_cast(n->getd()) == 0 );
  4761   match(ConD);
  4763   format %{ %}
  4764   interface(CONST_INTER);
  4765 %}
  4767 // Float Immediate zero
  4768 operand immF0() %{
  4769   predicate(UseSSE == 0 && n->getf() == 0.0F);
  4770   match(ConF);
  4772   op_cost(5);
  4773   format %{ %}
  4774   interface(CONST_INTER);
  4775 %}
  4777 // Float Immediate one
  4778 operand immF1() %{
  4779   predicate(UseSSE == 0 && n->getf() == 1.0F);
  4780   match(ConF);
  4782   op_cost(5);
  4783   format %{ %}
  4784   interface(CONST_INTER);
  4785 %}
  4787 // Float Immediate
  4788 operand immF() %{
  4789   predicate( UseSSE == 0 );
  4790   match(ConF);
  4792   op_cost(5);
  4793   format %{ %}
  4794   interface(CONST_INTER);
  4795 %}
  4797 // Float Immediate
  4798 operand immXF() %{
  4799   predicate(UseSSE >= 1);
  4800   match(ConF);
  4802   op_cost(5);
  4803   format %{ %}
  4804   interface(CONST_INTER);
  4805 %}
  4807 // Float Immediate zero.  Zero and not -0.0
  4808 operand immXF0() %{
  4809   predicate( UseSSE >= 1 && jint_cast(n->getf()) == 0 );
  4810   match(ConF);
  4812   op_cost(5);
  4813   format %{ %}
  4814   interface(CONST_INTER);
  4815 %}
  4817 // Immediates for special shifts (sign extend)
  4819 // Constants for increment
  4820 operand immI_16() %{
  4821   predicate( n->get_int() == 16 );
  4822   match(ConI);
  4824   format %{ %}
  4825   interface(CONST_INTER);
  4826 %}
  4828 operand immI_24() %{
  4829   predicate( n->get_int() == 24 );
  4830   match(ConI);
  4832   format %{ %}
  4833   interface(CONST_INTER);
  4834 %}
  4836 // Constant for byte-wide masking
  4837 operand immI_255() %{
  4838   predicate( n->get_int() == 255 );
  4839   match(ConI);
  4841   format %{ %}
  4842   interface(CONST_INTER);
  4843 %}
  4845 // Constant for short-wide masking
  4846 operand immI_65535() %{
  4847   predicate(n->get_int() == 65535);
  4848   match(ConI);
  4850   format %{ %}
  4851   interface(CONST_INTER);
  4852 %}
  4854 // Register Operands
  4855 // Integer Register
  4856 operand eRegI() %{
  4857   constraint(ALLOC_IN_RC(e_reg));
  4858   match(RegI);
  4859   match(xRegI);
  4860   match(eAXRegI);
  4861   match(eBXRegI);
  4862   match(eCXRegI);
  4863   match(eDXRegI);
  4864   match(eDIRegI);
  4865   match(eSIRegI);
  4867   format %{ %}
  4868   interface(REG_INTER);
  4869 %}
  4871 // Subset of Integer Register
  4872 operand xRegI(eRegI reg) %{
  4873   constraint(ALLOC_IN_RC(x_reg));
  4874   match(reg);
  4875   match(eAXRegI);
  4876   match(eBXRegI);
  4877   match(eCXRegI);
  4878   match(eDXRegI);
  4880   format %{ %}
  4881   interface(REG_INTER);
  4882 %}
  4884 // Special Registers
  4885 operand eAXRegI(xRegI reg) %{
  4886   constraint(ALLOC_IN_RC(eax_reg));
  4887   match(reg);
  4888   match(eRegI);
  4890   format %{ "EAX" %}
  4891   interface(REG_INTER);
  4892 %}
  4894 // Special Registers
  4895 operand eBXRegI(xRegI reg) %{
  4896   constraint(ALLOC_IN_RC(ebx_reg));
  4897   match(reg);
  4898   match(eRegI);
  4900   format %{ "EBX" %}
  4901   interface(REG_INTER);
  4902 %}
  4904 operand eCXRegI(xRegI reg) %{
  4905   constraint(ALLOC_IN_RC(ecx_reg));
  4906   match(reg);
  4907   match(eRegI);
  4909   format %{ "ECX" %}
  4910   interface(REG_INTER);
  4911 %}
  4913 operand eDXRegI(xRegI reg) %{
  4914   constraint(ALLOC_IN_RC(edx_reg));
  4915   match(reg);
  4916   match(eRegI);
  4918   format %{ "EDX" %}
  4919   interface(REG_INTER);
  4920 %}
  4922 operand eDIRegI(xRegI reg) %{
  4923   constraint(ALLOC_IN_RC(edi_reg));
  4924   match(reg);
  4925   match(eRegI);
  4927   format %{ "EDI" %}
  4928   interface(REG_INTER);
  4929 %}
  4931 operand naxRegI() %{
  4932   constraint(ALLOC_IN_RC(nax_reg));
  4933   match(RegI);
  4934   match(eCXRegI);
  4935   match(eDXRegI);
  4936   match(eSIRegI);
  4937   match(eDIRegI);
  4939   format %{ %}
  4940   interface(REG_INTER);
  4941 %}
  4943 operand nadxRegI() %{
  4944   constraint(ALLOC_IN_RC(nadx_reg));
  4945   match(RegI);
  4946   match(eBXRegI);
  4947   match(eCXRegI);
  4948   match(eSIRegI);
  4949   match(eDIRegI);
  4951   format %{ %}
  4952   interface(REG_INTER);
  4953 %}
  4955 operand ncxRegI() %{
  4956   constraint(ALLOC_IN_RC(ncx_reg));
  4957   match(RegI);
  4958   match(eAXRegI);
  4959   match(eDXRegI);
  4960   match(eSIRegI);
  4961   match(eDIRegI);
  4963   format %{ %}
  4964   interface(REG_INTER);
  4965 %}
  4967 // // This operand was used by cmpFastUnlock, but conflicted with 'object' reg
  4968 // //
  4969 operand eSIRegI(xRegI reg) %{
  4970    constraint(ALLOC_IN_RC(esi_reg));
  4971    match(reg);
  4972    match(eRegI);
  4974    format %{ "ESI" %}
  4975    interface(REG_INTER);
  4976 %}
  4978 // Pointer Register
  4979 operand anyRegP() %{
  4980   constraint(ALLOC_IN_RC(any_reg));
  4981   match(RegP);
  4982   match(eAXRegP);
  4983   match(eBXRegP);
  4984   match(eCXRegP);
  4985   match(eDIRegP);
  4986   match(eRegP);
  4988   format %{ %}
  4989   interface(REG_INTER);
  4990 %}
  4992 operand eRegP() %{
  4993   constraint(ALLOC_IN_RC(e_reg));
  4994   match(RegP);
  4995   match(eAXRegP);
  4996   match(eBXRegP);
  4997   match(eCXRegP);
  4998   match(eDIRegP);
  5000   format %{ %}
  5001   interface(REG_INTER);
  5002 %}
  5004 // On windows95, EBP is not safe to use for implicit null tests.
  5005 operand eRegP_no_EBP() %{
  5006   constraint(ALLOC_IN_RC(e_reg_no_rbp));
  5007   match(RegP);
  5008   match(eAXRegP);
  5009   match(eBXRegP);
  5010   match(eCXRegP);
  5011   match(eDIRegP);
  5013   op_cost(100);
  5014   format %{ %}
  5015   interface(REG_INTER);
  5016 %}
  5018 operand naxRegP() %{
  5019   constraint(ALLOC_IN_RC(nax_reg));
  5020   match(RegP);
  5021   match(eBXRegP);
  5022   match(eDXRegP);
  5023   match(eCXRegP);
  5024   match(eSIRegP);
  5025   match(eDIRegP);
  5027   format %{ %}
  5028   interface(REG_INTER);
  5029 %}
  5031 operand nabxRegP() %{
  5032   constraint(ALLOC_IN_RC(nabx_reg));
  5033   match(RegP);
  5034   match(eCXRegP);
  5035   match(eDXRegP);
  5036   match(eSIRegP);
  5037   match(eDIRegP);
  5039   format %{ %}
  5040   interface(REG_INTER);
  5041 %}
  5043 operand pRegP() %{
  5044   constraint(ALLOC_IN_RC(p_reg));
  5045   match(RegP);
  5046   match(eBXRegP);
  5047   match(eDXRegP);
  5048   match(eSIRegP);
  5049   match(eDIRegP);
  5051   format %{ %}
  5052   interface(REG_INTER);
  5053 %}
  5055 // Special Registers
  5056 // Return a pointer value
  5057 operand eAXRegP(eRegP reg) %{
  5058   constraint(ALLOC_IN_RC(eax_reg));
  5059   match(reg);
  5060   format %{ "EAX" %}
  5061   interface(REG_INTER);
  5062 %}
  5064 // Used in AtomicAdd
  5065 operand eBXRegP(eRegP reg) %{
  5066   constraint(ALLOC_IN_RC(ebx_reg));
  5067   match(reg);
  5068   format %{ "EBX" %}
  5069   interface(REG_INTER);
  5070 %}
  5072 // Tail-call (interprocedural jump) to interpreter
  5073 operand eCXRegP(eRegP reg) %{
  5074   constraint(ALLOC_IN_RC(ecx_reg));
  5075   match(reg);
  5076   format %{ "ECX" %}
  5077   interface(REG_INTER);
  5078 %}
  5080 operand eSIRegP(eRegP reg) %{
  5081   constraint(ALLOC_IN_RC(esi_reg));
  5082   match(reg);
  5083   format %{ "ESI" %}
  5084   interface(REG_INTER);
  5085 %}
  5087 // Used in rep stosw
  5088 operand eDIRegP(eRegP reg) %{
  5089   constraint(ALLOC_IN_RC(edi_reg));
  5090   match(reg);
  5091   format %{ "EDI" %}
  5092   interface(REG_INTER);
  5093 %}
  5095 operand eBPRegP() %{
  5096   constraint(ALLOC_IN_RC(ebp_reg));
  5097   match(RegP);
  5098   format %{ "EBP" %}
  5099   interface(REG_INTER);
  5100 %}
  5102 operand eRegL() %{
  5103   constraint(ALLOC_IN_RC(long_reg));
  5104   match(RegL);
  5105   match(eADXRegL);
  5107   format %{ %}
  5108   interface(REG_INTER);
  5109 %}
  5111 operand eADXRegL( eRegL reg ) %{
  5112   constraint(ALLOC_IN_RC(eadx_reg));
  5113   match(reg);
  5115   format %{ "EDX:EAX" %}
  5116   interface(REG_INTER);
  5117 %}
  5119 operand eBCXRegL( eRegL reg ) %{
  5120   constraint(ALLOC_IN_RC(ebcx_reg));
  5121   match(reg);
  5123   format %{ "EBX:ECX" %}
  5124   interface(REG_INTER);
  5125 %}
  5127 // Special case for integer high multiply
  5128 operand eADXRegL_low_only() %{
  5129   constraint(ALLOC_IN_RC(eadx_reg));
  5130   match(RegL);
  5132   format %{ "EAX" %}
  5133   interface(REG_INTER);
  5134 %}
  5136 // Flags register, used as output of compare instructions
  5137 operand eFlagsReg() %{
  5138   constraint(ALLOC_IN_RC(int_flags));
  5139   match(RegFlags);
  5141   format %{ "EFLAGS" %}
  5142   interface(REG_INTER);
  5143 %}
  5145 // Flags register, used as output of FLOATING POINT compare instructions
  5146 operand eFlagsRegU() %{
  5147   constraint(ALLOC_IN_RC(int_flags));
  5148   match(RegFlags);
  5150   format %{ "EFLAGS_U" %}
  5151   interface(REG_INTER);
  5152 %}
  5154 operand eFlagsRegUCF() %{
  5155   constraint(ALLOC_IN_RC(int_flags));
  5156   match(RegFlags);
  5157   predicate(false);
  5159   format %{ "EFLAGS_U_CF" %}
  5160   interface(REG_INTER);
  5161 %}
  5163 // Condition Code Register used by long compare
  5164 operand flagsReg_long_LTGE() %{
  5165   constraint(ALLOC_IN_RC(int_flags));
  5166   match(RegFlags);
  5167   format %{ "FLAGS_LTGE" %}
  5168   interface(REG_INTER);
  5169 %}
  5170 operand flagsReg_long_EQNE() %{
  5171   constraint(ALLOC_IN_RC(int_flags));
  5172   match(RegFlags);
  5173   format %{ "FLAGS_EQNE" %}
  5174   interface(REG_INTER);
  5175 %}
  5176 operand flagsReg_long_LEGT() %{
  5177   constraint(ALLOC_IN_RC(int_flags));
  5178   match(RegFlags);
  5179   format %{ "FLAGS_LEGT" %}
  5180   interface(REG_INTER);
  5181 %}
  5183 // Float register operands
  5184 operand regD() %{
  5185   predicate( UseSSE < 2 );
  5186   constraint(ALLOC_IN_RC(dbl_reg));
  5187   match(RegD);
  5188   match(regDPR1);
  5189   match(regDPR2);
  5190   format %{ %}
  5191   interface(REG_INTER);
  5192 %}
  5194 operand regDPR1(regD reg) %{
  5195   predicate( UseSSE < 2 );
  5196   constraint(ALLOC_IN_RC(dbl_reg0));
  5197   match(reg);
  5198   format %{ "FPR1" %}
  5199   interface(REG_INTER);
  5200 %}
  5202 operand regDPR2(regD reg) %{
  5203   predicate( UseSSE < 2 );
  5204   constraint(ALLOC_IN_RC(dbl_reg1));
  5205   match(reg);
  5206   format %{ "FPR2" %}
  5207   interface(REG_INTER);
  5208 %}
  5210 operand regnotDPR1(regD reg) %{
  5211   predicate( UseSSE < 2 );
  5212   constraint(ALLOC_IN_RC(dbl_notreg0));
  5213   match(reg);
  5214   format %{ %}
  5215   interface(REG_INTER);
  5216 %}
  5218 // XMM Double register operands
  5219 operand regXD() %{
  5220   predicate( UseSSE>=2 );
  5221   constraint(ALLOC_IN_RC(xdb_reg));
  5222   match(RegD);
  5223   match(regXD6);
  5224   match(regXD7);
  5225   format %{ %}
  5226   interface(REG_INTER);
  5227 %}
  5229 // XMM6 double register operands
  5230 operand regXD6(regXD reg) %{
  5231   predicate( UseSSE>=2 );
  5232   constraint(ALLOC_IN_RC(xdb_reg6));
  5233   match(reg);
  5234   format %{ "XMM6" %}
  5235   interface(REG_INTER);
  5236 %}
  5238 // XMM7 double register operands
  5239 operand regXD7(regXD reg) %{
  5240   predicate( UseSSE>=2 );
  5241   constraint(ALLOC_IN_RC(xdb_reg7));
  5242   match(reg);
  5243   format %{ "XMM7" %}
  5244   interface(REG_INTER);
  5245 %}
  5247 // Float register operands
  5248 operand regF() %{
  5249   predicate( UseSSE < 2 );
  5250   constraint(ALLOC_IN_RC(flt_reg));
  5251   match(RegF);
  5252   match(regFPR1);
  5253   format %{ %}
  5254   interface(REG_INTER);
  5255 %}
  5257 // Float register operands
  5258 operand regFPR1(regF reg) %{
  5259   predicate( UseSSE < 2 );
  5260   constraint(ALLOC_IN_RC(flt_reg0));
  5261   match(reg);
  5262   format %{ "FPR1" %}
  5263   interface(REG_INTER);
  5264 %}
  5266 // XMM register operands
  5267 operand regX() %{
  5268   predicate( UseSSE>=1 );
  5269   constraint(ALLOC_IN_RC(xmm_reg));
  5270   match(RegF);
  5271   format %{ %}
  5272   interface(REG_INTER);
  5273 %}
  5276 //----------Memory Operands----------------------------------------------------
  5277 // Direct Memory Operand
  5278 operand direct(immP addr) %{
  5279   match(addr);
  5281   format %{ "[$addr]" %}
  5282   interface(MEMORY_INTER) %{
  5283     base(0xFFFFFFFF);
  5284     index(0x4);
  5285     scale(0x0);
  5286     disp($addr);
  5287   %}
  5288 %}
  5290 // Indirect Memory Operand
  5291 operand indirect(eRegP reg) %{
  5292   constraint(ALLOC_IN_RC(e_reg));
  5293   match(reg);
  5295   format %{ "[$reg]" %}
  5296   interface(MEMORY_INTER) %{
  5297     base($reg);
  5298     index(0x4);
  5299     scale(0x0);
  5300     disp(0x0);
  5301   %}
  5302 %}
  5304 // Indirect Memory Plus Short Offset Operand
  5305 operand indOffset8(eRegP reg, immI8 off) %{
  5306   match(AddP reg off);
  5308   format %{ "[$reg + $off]" %}
  5309   interface(MEMORY_INTER) %{
  5310     base($reg);
  5311     index(0x4);
  5312     scale(0x0);
  5313     disp($off);
  5314   %}
  5315 %}
  5317 // Indirect Memory Plus Long Offset Operand
  5318 operand indOffset32(eRegP reg, immI off) %{
  5319   match(AddP reg off);
  5321   format %{ "[$reg + $off]" %}
  5322   interface(MEMORY_INTER) %{
  5323     base($reg);
  5324     index(0x4);
  5325     scale(0x0);
  5326     disp($off);
  5327   %}
  5328 %}
  5330 // Indirect Memory Plus Long Offset Operand
  5331 operand indOffset32X(eRegI reg, immP off) %{
  5332   match(AddP off reg);
  5334   format %{ "[$reg + $off]" %}
  5335   interface(MEMORY_INTER) %{
  5336     base($reg);
  5337     index(0x4);
  5338     scale(0x0);
  5339     disp($off);
  5340   %}
  5341 %}
  5343 // Indirect Memory Plus Index Register Plus Offset Operand
  5344 operand indIndexOffset(eRegP reg, eRegI ireg, immI off) %{
  5345   match(AddP (AddP reg ireg) off);
  5347   op_cost(10);
  5348   format %{"[$reg + $off + $ireg]" %}
  5349   interface(MEMORY_INTER) %{
  5350     base($reg);
  5351     index($ireg);
  5352     scale(0x0);
  5353     disp($off);
  5354   %}
  5355 %}
  5357 // Indirect Memory Plus Index Register Plus Offset Operand
  5358 operand indIndex(eRegP reg, eRegI ireg) %{
  5359   match(AddP reg ireg);
  5361   op_cost(10);
  5362   format %{"[$reg + $ireg]" %}
  5363   interface(MEMORY_INTER) %{
  5364     base($reg);
  5365     index($ireg);
  5366     scale(0x0);
  5367     disp(0x0);
  5368   %}
  5369 %}
  5371 // // -------------------------------------------------------------------------
  5372 // // 486 architecture doesn't support "scale * index + offset" with out a base
  5373 // // -------------------------------------------------------------------------
  5374 // // Scaled Memory Operands
  5375 // // Indirect Memory Times Scale Plus Offset Operand
  5376 // operand indScaleOffset(immP off, eRegI ireg, immI2 scale) %{
  5377 //   match(AddP off (LShiftI ireg scale));
  5378 //
  5379 //   op_cost(10);
  5380 //   format %{"[$off + $ireg << $scale]" %}
  5381 //   interface(MEMORY_INTER) %{
  5382 //     base(0x4);
  5383 //     index($ireg);
  5384 //     scale($scale);
  5385 //     disp($off);
  5386 //   %}
  5387 // %}
  5389 // Indirect Memory Times Scale Plus Index Register
  5390 operand indIndexScale(eRegP reg, eRegI ireg, immI2 scale) %{
  5391   match(AddP reg (LShiftI ireg scale));
  5393   op_cost(10);
  5394   format %{"[$reg + $ireg << $scale]" %}
  5395   interface(MEMORY_INTER) %{
  5396     base($reg);
  5397     index($ireg);
  5398     scale($scale);
  5399     disp(0x0);
  5400   %}
  5401 %}
  5403 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
  5404 operand indIndexScaleOffset(eRegP reg, immI off, eRegI ireg, immI2 scale) %{
  5405   match(AddP (AddP reg (LShiftI ireg scale)) off);
  5407   op_cost(10);
  5408   format %{"[$reg + $off + $ireg << $scale]" %}
  5409   interface(MEMORY_INTER) %{
  5410     base($reg);
  5411     index($ireg);
  5412     scale($scale);
  5413     disp($off);
  5414   %}
  5415 %}
  5417 //----------Load Long Memory Operands------------------------------------------
  5418 // The load-long idiom will use it's address expression again after loading
  5419 // the first word of the long.  If the load-long destination overlaps with
  5420 // registers used in the addressing expression, the 2nd half will be loaded
  5421 // from a clobbered address.  Fix this by requiring that load-long use
  5422 // address registers that do not overlap with the load-long target.
  5424 // load-long support
  5425 operand load_long_RegP() %{
  5426   constraint(ALLOC_IN_RC(esi_reg));
  5427   match(RegP);
  5428   match(eSIRegP);
  5429   op_cost(100);
  5430   format %{  %}
  5431   interface(REG_INTER);
  5432 %}
  5434 // Indirect Memory Operand Long
  5435 operand load_long_indirect(load_long_RegP reg) %{
  5436   constraint(ALLOC_IN_RC(esi_reg));
  5437   match(reg);
  5439   format %{ "[$reg]" %}
  5440   interface(MEMORY_INTER) %{
  5441     base($reg);
  5442     index(0x4);
  5443     scale(0x0);
  5444     disp(0x0);
  5445   %}
  5446 %}
  5448 // Indirect Memory Plus Long Offset Operand
  5449 operand load_long_indOffset32(load_long_RegP reg, immI off) %{
  5450   match(AddP reg off);
  5452   format %{ "[$reg + $off]" %}
  5453   interface(MEMORY_INTER) %{
  5454     base($reg);
  5455     index(0x4);
  5456     scale(0x0);
  5457     disp($off);
  5458   %}
  5459 %}
  5461 opclass load_long_memory(load_long_indirect, load_long_indOffset32);
  5464 //----------Special Memory Operands--------------------------------------------
  5465 // Stack Slot Operand - This operand is used for loading and storing temporary
  5466 //                      values on the stack where a match requires a value to
  5467 //                      flow through memory.
  5468 operand stackSlotP(sRegP reg) %{
  5469   constraint(ALLOC_IN_RC(stack_slots));
  5470   // No match rule because this operand is only generated in matching
  5471   format %{ "[$reg]" %}
  5472   interface(MEMORY_INTER) %{
  5473     base(0x4);   // ESP
  5474     index(0x4);  // No Index
  5475     scale(0x0);  // No Scale
  5476     disp($reg);  // Stack Offset
  5477   %}
  5478 %}
  5480 operand stackSlotI(sRegI reg) %{
  5481   constraint(ALLOC_IN_RC(stack_slots));
  5482   // No match rule because this operand is only generated in matching
  5483   format %{ "[$reg]" %}
  5484   interface(MEMORY_INTER) %{
  5485     base(0x4);   // ESP
  5486     index(0x4);  // No Index
  5487     scale(0x0);  // No Scale
  5488     disp($reg);  // Stack Offset
  5489   %}
  5490 %}
  5492 operand stackSlotF(sRegF reg) %{
  5493   constraint(ALLOC_IN_RC(stack_slots));
  5494   // No match rule because this operand is only generated in matching
  5495   format %{ "[$reg]" %}
  5496   interface(MEMORY_INTER) %{
  5497     base(0x4);   // ESP
  5498     index(0x4);  // No Index
  5499     scale(0x0);  // No Scale
  5500     disp($reg);  // Stack Offset
  5501   %}
  5502 %}
  5504 operand stackSlotD(sRegD reg) %{
  5505   constraint(ALLOC_IN_RC(stack_slots));
  5506   // No match rule because this operand is only generated in matching
  5507   format %{ "[$reg]" %}
  5508   interface(MEMORY_INTER) %{
  5509     base(0x4);   // ESP
  5510     index(0x4);  // No Index
  5511     scale(0x0);  // No Scale
  5512     disp($reg);  // Stack Offset
  5513   %}
  5514 %}
  5516 operand stackSlotL(sRegL reg) %{
  5517   constraint(ALLOC_IN_RC(stack_slots));
  5518   // No match rule because this operand is only generated in matching
  5519   format %{ "[$reg]" %}
  5520   interface(MEMORY_INTER) %{
  5521     base(0x4);   // ESP
  5522     index(0x4);  // No Index
  5523     scale(0x0);  // No Scale
  5524     disp($reg);  // Stack Offset
  5525   %}
  5526 %}
  5528 //----------Memory Operands - Win95 Implicit Null Variants----------------
  5529 // Indirect Memory Operand
  5530 operand indirect_win95_safe(eRegP_no_EBP reg)
  5531 %{
  5532   constraint(ALLOC_IN_RC(e_reg));
  5533   match(reg);
  5535   op_cost(100);
  5536   format %{ "[$reg]" %}
  5537   interface(MEMORY_INTER) %{
  5538     base($reg);
  5539     index(0x4);
  5540     scale(0x0);
  5541     disp(0x0);
  5542   %}
  5543 %}
  5545 // Indirect Memory Plus Short Offset Operand
  5546 operand indOffset8_win95_safe(eRegP_no_EBP reg, immI8 off)
  5547 %{
  5548   match(AddP reg off);
  5550   op_cost(100);
  5551   format %{ "[$reg + $off]" %}
  5552   interface(MEMORY_INTER) %{
  5553     base($reg);
  5554     index(0x4);
  5555     scale(0x0);
  5556     disp($off);
  5557   %}
  5558 %}
  5560 // Indirect Memory Plus Long Offset Operand
  5561 operand indOffset32_win95_safe(eRegP_no_EBP reg, immI off)
  5562 %{
  5563   match(AddP reg off);
  5565   op_cost(100);
  5566   format %{ "[$reg + $off]" %}
  5567   interface(MEMORY_INTER) %{
  5568     base($reg);
  5569     index(0x4);
  5570     scale(0x0);
  5571     disp($off);
  5572   %}
  5573 %}
  5575 // Indirect Memory Plus Index Register Plus Offset Operand
  5576 operand indIndexOffset_win95_safe(eRegP_no_EBP reg, eRegI ireg, immI off)
  5577 %{
  5578   match(AddP (AddP reg ireg) off);
  5580   op_cost(100);
  5581   format %{"[$reg + $off + $ireg]" %}
  5582   interface(MEMORY_INTER) %{
  5583     base($reg);
  5584     index($ireg);
  5585     scale(0x0);
  5586     disp($off);
  5587   %}
  5588 %}
  5590 // Indirect Memory Times Scale Plus Index Register
  5591 operand indIndexScale_win95_safe(eRegP_no_EBP reg, eRegI ireg, immI2 scale)
  5592 %{
  5593   match(AddP reg (LShiftI ireg scale));
  5595   op_cost(100);
  5596   format %{"[$reg + $ireg << $scale]" %}
  5597   interface(MEMORY_INTER) %{
  5598     base($reg);
  5599     index($ireg);
  5600     scale($scale);
  5601     disp(0x0);
  5602   %}
  5603 %}
  5605 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
  5606 operand indIndexScaleOffset_win95_safe(eRegP_no_EBP reg, immI off, eRegI ireg, immI2 scale)
  5607 %{
  5608   match(AddP (AddP reg (LShiftI ireg scale)) off);
  5610   op_cost(100);
  5611   format %{"[$reg + $off + $ireg << $scale]" %}
  5612   interface(MEMORY_INTER) %{
  5613     base($reg);
  5614     index($ireg);
  5615     scale($scale);
  5616     disp($off);
  5617   %}
  5618 %}
  5620 //----------Conditional Branch Operands----------------------------------------
  5621 // Comparison Op  - This is the operation of the comparison, and is limited to
  5622 //                  the following set of codes:
  5623 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
  5624 //
  5625 // Other attributes of the comparison, such as unsignedness, are specified
  5626 // by the comparison instruction that sets a condition code flags register.
  5627 // That result is represented by a flags operand whose subtype is appropriate
  5628 // to the unsignedness (etc.) of the comparison.
  5629 //
  5630 // Later, the instruction which matches both the Comparison Op (a Bool) and
  5631 // the flags (produced by the Cmp) specifies the coding of the comparison op
  5632 // by matching a specific subtype of Bool operand below, such as cmpOpU.
  5634 // Comparision Code
  5635 operand cmpOp() %{
  5636   match(Bool);
  5638   format %{ "" %}
  5639   interface(COND_INTER) %{
  5640     equal(0x4, "e");
  5641     not_equal(0x5, "ne");
  5642     less(0xC, "l");
  5643     greater_equal(0xD, "ge");
  5644     less_equal(0xE, "le");
  5645     greater(0xF, "g");
  5646   %}
  5647 %}
  5649 // Comparison Code, unsigned compare.  Used by FP also, with
  5650 // C2 (unordered) turned into GT or LT already.  The other bits
  5651 // C0 and C3 are turned into Carry & Zero flags.
  5652 operand cmpOpU() %{
  5653   match(Bool);
  5655   format %{ "" %}
  5656   interface(COND_INTER) %{
  5657     equal(0x4, "e");
  5658     not_equal(0x5, "ne");
  5659     less(0x2, "b");
  5660     greater_equal(0x3, "nb");
  5661     less_equal(0x6, "be");
  5662     greater(0x7, "nbe");
  5663   %}
  5664 %}
  5666 // Floating comparisons that don't require any fixup for the unordered case
  5667 operand cmpOpUCF() %{
  5668   match(Bool);
  5669   predicate(n->as_Bool()->_test._test == BoolTest::lt ||
  5670             n->as_Bool()->_test._test == BoolTest::ge ||
  5671             n->as_Bool()->_test._test == BoolTest::le ||
  5672             n->as_Bool()->_test._test == BoolTest::gt);
  5673   format %{ "" %}
  5674   interface(COND_INTER) %{
  5675     equal(0x4, "e");
  5676     not_equal(0x5, "ne");
  5677     less(0x2, "b");
  5678     greater_equal(0x3, "nb");
  5679     less_equal(0x6, "be");
  5680     greater(0x7, "nbe");
  5681   %}
  5682 %}
  5685 // Floating comparisons that can be fixed up with extra conditional jumps
  5686 operand cmpOpUCF2() %{
  5687   match(Bool);
  5688   predicate(n->as_Bool()->_test._test == BoolTest::ne ||
  5689             n->as_Bool()->_test._test == BoolTest::eq);
  5690   format %{ "" %}
  5691   interface(COND_INTER) %{
  5692     equal(0x4, "e");
  5693     not_equal(0x5, "ne");
  5694     less(0x2, "b");
  5695     greater_equal(0x3, "nb");
  5696     less_equal(0x6, "be");
  5697     greater(0x7, "nbe");
  5698   %}
  5699 %}
  5701 // Comparison Code for FP conditional move
  5702 operand cmpOp_fcmov() %{
  5703   match(Bool);
  5705   format %{ "" %}
  5706   interface(COND_INTER) %{
  5707     equal        (0x0C8);
  5708     not_equal    (0x1C8);
  5709     less         (0x0C0);
  5710     greater_equal(0x1C0);
  5711     less_equal   (0x0D0);
  5712     greater      (0x1D0);
  5713   %}
  5714 %}
  5716 // Comparision Code used in long compares
  5717 operand cmpOp_commute() %{
  5718   match(Bool);
  5720   format %{ "" %}
  5721   interface(COND_INTER) %{
  5722     equal(0x4, "e");
  5723     not_equal(0x5, "ne");
  5724     less(0xF, "g");
  5725     greater_equal(0xE, "le");
  5726     less_equal(0xD, "ge");
  5727     greater(0xC, "l");
  5728   %}
  5729 %}
  5731 //----------OPERAND CLASSES----------------------------------------------------
  5732 // Operand Classes are groups of operands that are used as to simplify
  5733 // instruction definitions by not requiring the AD writer to specify separate
  5734 // instructions for every form of operand when the instruction accepts
  5735 // multiple operand types with the same basic encoding and format.  The classic
  5736 // case of this is memory operands.
  5738 opclass memory(direct, indirect, indOffset8, indOffset32, indOffset32X, indIndexOffset,
  5739                indIndex, indIndexScale, indIndexScaleOffset);
  5741 // Long memory operations are encoded in 2 instructions and a +4 offset.
  5742 // This means some kind of offset is always required and you cannot use
  5743 // an oop as the offset (done when working on static globals).
  5744 opclass long_memory(direct, indirect, indOffset8, indOffset32, indIndexOffset,
  5745                     indIndex, indIndexScale, indIndexScaleOffset);
  5748 //----------PIPELINE-----------------------------------------------------------
  5749 // Rules which define the behavior of the target architectures pipeline.
  5750 pipeline %{
  5752 //----------ATTRIBUTES---------------------------------------------------------
  5753 attributes %{
  5754   variable_size_instructions;        // Fixed size instructions
  5755   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
  5756   instruction_unit_size = 1;         // An instruction is 1 bytes long
  5757   instruction_fetch_unit_size = 16;  // The processor fetches one line
  5758   instruction_fetch_units = 1;       // of 16 bytes
  5760   // List of nop instructions
  5761   nops( MachNop );
  5762 %}
  5764 //----------RESOURCES----------------------------------------------------------
  5765 // Resources are the functional units available to the machine
  5767 // Generic P2/P3 pipeline
  5768 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
  5769 // 3 instructions decoded per cycle.
  5770 // 2 load/store ops per cycle, 1 branch, 1 FPU,
  5771 // 2 ALU op, only ALU0 handles mul/div instructions.
  5772 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
  5773            MS0, MS1, MEM = MS0 | MS1,
  5774            BR, FPU,
  5775            ALU0, ALU1, ALU = ALU0 | ALU1 );
  5777 //----------PIPELINE DESCRIPTION-----------------------------------------------
  5778 // Pipeline Description specifies the stages in the machine's pipeline
  5780 // Generic P2/P3 pipeline
  5781 pipe_desc(S0, S1, S2, S3, S4, S5);
  5783 //----------PIPELINE CLASSES---------------------------------------------------
  5784 // Pipeline Classes describe the stages in which input and output are
  5785 // referenced by the hardware pipeline.
  5787 // Naming convention: ialu or fpu
  5788 // Then: _reg
  5789 // Then: _reg if there is a 2nd register
  5790 // Then: _long if it's a pair of instructions implementing a long
  5791 // Then: _fat if it requires the big decoder
  5792 //   Or: _mem if it requires the big decoder and a memory unit.
  5794 // Integer ALU reg operation
  5795 pipe_class ialu_reg(eRegI dst) %{
  5796     single_instruction;
  5797     dst    : S4(write);
  5798     dst    : S3(read);
  5799     DECODE : S0;        // any decoder
  5800     ALU    : S3;        // any alu
  5801 %}
  5803 // Long ALU reg operation
  5804 pipe_class ialu_reg_long(eRegL dst) %{
  5805     instruction_count(2);
  5806     dst    : S4(write);
  5807     dst    : S3(read);
  5808     DECODE : S0(2);     // any 2 decoders
  5809     ALU    : S3(2);     // both alus
  5810 %}
  5812 // Integer ALU reg operation using big decoder
  5813 pipe_class ialu_reg_fat(eRegI dst) %{
  5814     single_instruction;
  5815     dst    : S4(write);
  5816     dst    : S3(read);
  5817     D0     : S0;        // big decoder only
  5818     ALU    : S3;        // any alu
  5819 %}
  5821 // Long ALU reg operation using big decoder
  5822 pipe_class ialu_reg_long_fat(eRegL dst) %{
  5823     instruction_count(2);
  5824     dst    : S4(write);
  5825     dst    : S3(read);
  5826     D0     : S0(2);     // big decoder only; twice
  5827     ALU    : S3(2);     // any 2 alus
  5828 %}
  5830 // Integer ALU reg-reg operation
  5831 pipe_class ialu_reg_reg(eRegI dst, eRegI src) %{
  5832     single_instruction;
  5833     dst    : S4(write);
  5834     src    : S3(read);
  5835     DECODE : S0;        // any decoder
  5836     ALU    : S3;        // any alu
  5837 %}
  5839 // Long ALU reg-reg operation
  5840 pipe_class ialu_reg_reg_long(eRegL dst, eRegL src) %{
  5841     instruction_count(2);
  5842     dst    : S4(write);
  5843     src    : S3(read);
  5844     DECODE : S0(2);     // any 2 decoders
  5845     ALU    : S3(2);     // both alus
  5846 %}
  5848 // Integer ALU reg-reg operation
  5849 pipe_class ialu_reg_reg_fat(eRegI dst, memory src) %{
  5850     single_instruction;
  5851     dst    : S4(write);
  5852     src    : S3(read);
  5853     D0     : S0;        // big decoder only
  5854     ALU    : S3;        // any alu
  5855 %}
  5857 // Long ALU reg-reg operation
  5858 pipe_class ialu_reg_reg_long_fat(eRegL dst, eRegL src) %{
  5859     instruction_count(2);
  5860     dst    : S4(write);
  5861     src    : S3(read);
  5862     D0     : S0(2);     // big decoder only; twice
  5863     ALU    : S3(2);     // both alus
  5864 %}
  5866 // Integer ALU reg-mem operation
  5867 pipe_class ialu_reg_mem(eRegI dst, memory mem) %{
  5868     single_instruction;
  5869     dst    : S5(write);
  5870     mem    : S3(read);
  5871     D0     : S0;        // big decoder only
  5872     ALU    : S4;        // any alu
  5873     MEM    : S3;        // any mem
  5874 %}
  5876 // Long ALU reg-mem operation
  5877 pipe_class ialu_reg_long_mem(eRegL dst, load_long_memory mem) %{
  5878     instruction_count(2);
  5879     dst    : S5(write);
  5880     mem    : S3(read);
  5881     D0     : S0(2);     // big decoder only; twice
  5882     ALU    : S4(2);     // any 2 alus
  5883     MEM    : S3(2);     // both mems
  5884 %}
  5886 // Integer mem operation (prefetch)
  5887 pipe_class ialu_mem(memory mem)
  5888 %{
  5889     single_instruction;
  5890     mem    : S3(read);
  5891     D0     : S0;        // big decoder only
  5892     MEM    : S3;        // any mem
  5893 %}
  5895 // Integer Store to Memory
  5896 pipe_class ialu_mem_reg(memory mem, eRegI src) %{
  5897     single_instruction;
  5898     mem    : S3(read);
  5899     src    : S5(read);
  5900     D0     : S0;        // big decoder only
  5901     ALU    : S4;        // any alu
  5902     MEM    : S3;
  5903 %}
  5905 // Long Store to Memory
  5906 pipe_class ialu_mem_long_reg(memory mem, eRegL src) %{
  5907     instruction_count(2);
  5908     mem    : S3(read);
  5909     src    : S5(read);
  5910     D0     : S0(2);     // big decoder only; twice
  5911     ALU    : S4(2);     // any 2 alus
  5912     MEM    : S3(2);     // Both mems
  5913 %}
  5915 // Integer Store to Memory
  5916 pipe_class ialu_mem_imm(memory mem) %{
  5917     single_instruction;
  5918     mem    : S3(read);
  5919     D0     : S0;        // big decoder only
  5920     ALU    : S4;        // any alu
  5921     MEM    : S3;
  5922 %}
  5924 // Integer ALU0 reg-reg operation
  5925 pipe_class ialu_reg_reg_alu0(eRegI dst, eRegI src) %{
  5926     single_instruction;
  5927     dst    : S4(write);
  5928     src    : S3(read);
  5929     D0     : S0;        // Big decoder only
  5930     ALU0   : S3;        // only alu0
  5931 %}
  5933 // Integer ALU0 reg-mem operation
  5934 pipe_class ialu_reg_mem_alu0(eRegI dst, memory mem) %{
  5935     single_instruction;
  5936     dst    : S5(write);
  5937     mem    : S3(read);
  5938     D0     : S0;        // big decoder only
  5939     ALU0   : S4;        // ALU0 only
  5940     MEM    : S3;        // any mem
  5941 %}
  5943 // Integer ALU reg-reg operation
  5944 pipe_class ialu_cr_reg_reg(eFlagsReg cr, eRegI src1, eRegI src2) %{
  5945     single_instruction;
  5946     cr     : S4(write);
  5947     src1   : S3(read);
  5948     src2   : S3(read);
  5949     DECODE : S0;        // any decoder
  5950     ALU    : S3;        // any alu
  5951 %}
  5953 // Integer ALU reg-imm operation
  5954 pipe_class ialu_cr_reg_imm(eFlagsReg cr, eRegI src1) %{
  5955     single_instruction;
  5956     cr     : S4(write);
  5957     src1   : S3(read);
  5958     DECODE : S0;        // any decoder
  5959     ALU    : S3;        // any alu
  5960 %}
  5962 // Integer ALU reg-mem operation
  5963 pipe_class ialu_cr_reg_mem(eFlagsReg cr, eRegI src1, memory src2) %{
  5964     single_instruction;
  5965     cr     : S4(write);
  5966     src1   : S3(read);
  5967     src2   : S3(read);
  5968     D0     : S0;        // big decoder only
  5969     ALU    : S4;        // any alu
  5970     MEM    : S3;
  5971 %}
  5973 // Conditional move reg-reg
  5974 pipe_class pipe_cmplt( eRegI p, eRegI q, eRegI y ) %{
  5975     instruction_count(4);
  5976     y      : S4(read);
  5977     q      : S3(read);
  5978     p      : S3(read);
  5979     DECODE : S0(4);     // any decoder
  5980 %}
  5982 // Conditional move reg-reg
  5983 pipe_class pipe_cmov_reg( eRegI dst, eRegI src, eFlagsReg cr ) %{
  5984     single_instruction;
  5985     dst    : S4(write);
  5986     src    : S3(read);
  5987     cr     : S3(read);
  5988     DECODE : S0;        // any decoder
  5989 %}
  5991 // Conditional move reg-mem
  5992 pipe_class pipe_cmov_mem( eFlagsReg cr, eRegI dst, memory src) %{
  5993     single_instruction;
  5994     dst    : S4(write);
  5995     src    : S3(read);
  5996     cr     : S3(read);
  5997     DECODE : S0;        // any decoder
  5998     MEM    : S3;
  5999 %}
  6001 // Conditional move reg-reg long
  6002 pipe_class pipe_cmov_reg_long( eFlagsReg cr, eRegL dst, eRegL src) %{
  6003     single_instruction;
  6004     dst    : S4(write);
  6005     src    : S3(read);
  6006     cr     : S3(read);
  6007     DECODE : S0(2);     // any 2 decoders
  6008 %}
  6010 // Conditional move double reg-reg
  6011 pipe_class pipe_cmovD_reg( eFlagsReg cr, regDPR1 dst, regD src) %{
  6012     single_instruction;
  6013     dst    : S4(write);
  6014     src    : S3(read);
  6015     cr     : S3(read);
  6016     DECODE : S0;        // any decoder
  6017 %}
  6019 // Float reg-reg operation
  6020 pipe_class fpu_reg(regD dst) %{
  6021     instruction_count(2);
  6022     dst    : S3(read);
  6023     DECODE : S0(2);     // any 2 decoders
  6024     FPU    : S3;
  6025 %}
  6027 // Float reg-reg operation
  6028 pipe_class fpu_reg_reg(regD dst, regD src) %{
  6029     instruction_count(2);
  6030     dst    : S4(write);
  6031     src    : S3(read);
  6032     DECODE : S0(2);     // any 2 decoders
  6033     FPU    : S3;
  6034 %}
  6036 // Float reg-reg operation
  6037 pipe_class fpu_reg_reg_reg(regD dst, regD src1, regD src2) %{
  6038     instruction_count(3);
  6039     dst    : S4(write);
  6040     src1   : S3(read);
  6041     src2   : S3(read);
  6042     DECODE : S0(3);     // any 3 decoders
  6043     FPU    : S3(2);
  6044 %}
  6046 // Float reg-reg operation
  6047 pipe_class fpu_reg_reg_reg_reg(regD dst, regD src1, regD src2, regD src3) %{
  6048     instruction_count(4);
  6049     dst    : S4(write);
  6050     src1   : S3(read);
  6051     src2   : S3(read);
  6052     src3   : S3(read);
  6053     DECODE : S0(4);     // any 3 decoders
  6054     FPU    : S3(2);
  6055 %}
  6057 // Float reg-reg operation
  6058 pipe_class fpu_reg_mem_reg_reg(regD dst, memory src1, regD src2, regD src3) %{
  6059     instruction_count(4);
  6060     dst    : S4(write);
  6061     src1   : S3(read);
  6062     src2   : S3(read);
  6063     src3   : S3(read);
  6064     DECODE : S1(3);     // any 3 decoders
  6065     D0     : S0;        // Big decoder only
  6066     FPU    : S3(2);
  6067     MEM    : S3;
  6068 %}
  6070 // Float reg-mem operation
  6071 pipe_class fpu_reg_mem(regD dst, memory mem) %{
  6072     instruction_count(2);
  6073     dst    : S5(write);
  6074     mem    : S3(read);
  6075     D0     : S0;        // big decoder only
  6076     DECODE : S1;        // any decoder for FPU POP
  6077     FPU    : S4;
  6078     MEM    : S3;        // any mem
  6079 %}
  6081 // Float reg-mem operation
  6082 pipe_class fpu_reg_reg_mem(regD dst, regD src1, memory mem) %{
  6083     instruction_count(3);
  6084     dst    : S5(write);
  6085     src1   : S3(read);
  6086     mem    : S3(read);
  6087     D0     : S0;        // big decoder only
  6088     DECODE : S1(2);     // any decoder for FPU POP
  6089     FPU    : S4;
  6090     MEM    : S3;        // any mem
  6091 %}
  6093 // Float mem-reg operation
  6094 pipe_class fpu_mem_reg(memory mem, regD src) %{
  6095     instruction_count(2);
  6096     src    : S5(read);
  6097     mem    : S3(read);
  6098     DECODE : S0;        // any decoder for FPU PUSH
  6099     D0     : S1;        // big decoder only
  6100     FPU    : S4;
  6101     MEM    : S3;        // any mem
  6102 %}
  6104 pipe_class fpu_mem_reg_reg(memory mem, regD src1, regD src2) %{
  6105     instruction_count(3);
  6106     src1   : S3(read);
  6107     src2   : S3(read);
  6108     mem    : S3(read);
  6109     DECODE : S0(2);     // any decoder for FPU PUSH
  6110     D0     : S1;        // big decoder only
  6111     FPU    : S4;
  6112     MEM    : S3;        // any mem
  6113 %}
  6115 pipe_class fpu_mem_reg_mem(memory mem, regD src1, memory src2) %{
  6116     instruction_count(3);
  6117     src1   : S3(read);
  6118     src2   : S3(read);
  6119     mem    : S4(read);
  6120     DECODE : S0;        // any decoder for FPU PUSH
  6121     D0     : S0(2);     // big decoder only
  6122     FPU    : S4;
  6123     MEM    : S3(2);     // any mem
  6124 %}
  6126 pipe_class fpu_mem_mem(memory dst, memory src1) %{
  6127     instruction_count(2);
  6128     src1   : S3(read);
  6129     dst    : S4(read);
  6130     D0     : S0(2);     // big decoder only
  6131     MEM    : S3(2);     // any mem
  6132 %}
  6134 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2) %{
  6135     instruction_count(3);
  6136     src1   : S3(read);
  6137     src2   : S3(read);
  6138     dst    : S4(read);
  6139     D0     : S0(3);     // big decoder only
  6140     FPU    : S4;
  6141     MEM    : S3(3);     // any mem
  6142 %}
  6144 pipe_class fpu_mem_reg_con(memory mem, regD src1) %{
  6145     instruction_count(3);
  6146     src1   : S4(read);
  6147     mem    : S4(read);
  6148     DECODE : S0;        // any decoder for FPU PUSH
  6149     D0     : S0(2);     // big decoder only
  6150     FPU    : S4;
  6151     MEM    : S3(2);     // any mem
  6152 %}
  6154 // Float load constant
  6155 pipe_class fpu_reg_con(regD dst) %{
  6156     instruction_count(2);
  6157     dst    : S5(write);
  6158     D0     : S0;        // big decoder only for the load
  6159     DECODE : S1;        // any decoder for FPU POP
  6160     FPU    : S4;
  6161     MEM    : S3;        // any mem
  6162 %}
  6164 // Float load constant
  6165 pipe_class fpu_reg_reg_con(regD dst, regD src) %{
  6166     instruction_count(3);
  6167     dst    : S5(write);
  6168     src    : S3(read);
  6169     D0     : S0;        // big decoder only for the load
  6170     DECODE : S1(2);     // any decoder for FPU POP
  6171     FPU    : S4;
  6172     MEM    : S3;        // any mem
  6173 %}
  6175 // UnConditional branch
  6176 pipe_class pipe_jmp( label labl ) %{
  6177     single_instruction;
  6178     BR   : S3;
  6179 %}
  6181 // Conditional branch
  6182 pipe_class pipe_jcc( cmpOp cmp, eFlagsReg cr, label labl ) %{
  6183     single_instruction;
  6184     cr    : S1(read);
  6185     BR    : S3;
  6186 %}
  6188 // Allocation idiom
  6189 pipe_class pipe_cmpxchg( eRegP dst, eRegP heap_ptr ) %{
  6190     instruction_count(1); force_serialization;
  6191     fixed_latency(6);
  6192     heap_ptr : S3(read);
  6193     DECODE   : S0(3);
  6194     D0       : S2;
  6195     MEM      : S3;
  6196     ALU      : S3(2);
  6197     dst      : S5(write);
  6198     BR       : S5;
  6199 %}
  6201 // Generic big/slow expanded idiom
  6202 pipe_class pipe_slow(  ) %{
  6203     instruction_count(10); multiple_bundles; force_serialization;
  6204     fixed_latency(100);
  6205     D0  : S0(2);
  6206     MEM : S3(2);
  6207 %}
  6209 // The real do-nothing guy
  6210 pipe_class empty( ) %{
  6211     instruction_count(0);
  6212 %}
  6214 // Define the class for the Nop node
  6215 define %{
  6216    MachNop = empty;
  6217 %}
  6219 %}
  6221 //----------INSTRUCTIONS-------------------------------------------------------
  6222 //
  6223 // match      -- States which machine-independent subtree may be replaced
  6224 //               by this instruction.
  6225 // ins_cost   -- The estimated cost of this instruction is used by instruction
  6226 //               selection to identify a minimum cost tree of machine
  6227 //               instructions that matches a tree of machine-independent
  6228 //               instructions.
  6229 // format     -- A string providing the disassembly for this instruction.
  6230 //               The value of an instruction's operand may be inserted
  6231 //               by referring to it with a '$' prefix.
  6232 // opcode     -- Three instruction opcodes may be provided.  These are referred
  6233 //               to within an encode class as $primary, $secondary, and $tertiary
  6234 //               respectively.  The primary opcode is commonly used to
  6235 //               indicate the type of machine instruction, while secondary
  6236 //               and tertiary are often used for prefix options or addressing
  6237 //               modes.
  6238 // ins_encode -- A list of encode classes with parameters. The encode class
  6239 //               name must have been defined in an 'enc_class' specification
  6240 //               in the encode section of the architecture description.
  6242 //----------BSWAP-Instruction--------------------------------------------------
  6243 instruct bytes_reverse_int(eRegI dst) %{
  6244   match(Set dst (ReverseBytesI dst));
  6246   format %{ "BSWAP  $dst" %}
  6247   opcode(0x0F, 0xC8);
  6248   ins_encode( OpcP, OpcSReg(dst) );
  6249   ins_pipe( ialu_reg );
  6250 %}
  6252 instruct bytes_reverse_long(eRegL dst) %{
  6253   match(Set dst (ReverseBytesL dst));
  6255   format %{ "BSWAP  $dst.lo\n\t"
  6256             "BSWAP  $dst.hi\n\t"
  6257             "XCHG   $dst.lo $dst.hi" %}
  6259   ins_cost(125);
  6260   ins_encode( bswap_long_bytes(dst) );
  6261   ins_pipe( ialu_reg_reg);
  6262 %}
  6264 instruct bytes_reverse_unsigned_short(eRegI dst) %{
  6265   match(Set dst (ReverseBytesUS dst));
  6267   format %{ "BSWAP  $dst\n\t" 
  6268             "SHR    $dst,16\n\t" %}
  6269   ins_encode %{
  6270     __ bswapl($dst$$Register);
  6271     __ shrl($dst$$Register, 16); 
  6272   %}
  6273   ins_pipe( ialu_reg );
  6274 %}
  6276 instruct bytes_reverse_short(eRegI dst) %{
  6277   match(Set dst (ReverseBytesS dst));
  6279   format %{ "BSWAP  $dst\n\t" 
  6280             "SAR    $dst,16\n\t" %}
  6281   ins_encode %{
  6282     __ bswapl($dst$$Register);
  6283     __ sarl($dst$$Register, 16); 
  6284   %}
  6285   ins_pipe( ialu_reg );
  6286 %}
  6289 //---------- Zeros Count Instructions ------------------------------------------
  6291 instruct countLeadingZerosI(eRegI dst, eRegI src, eFlagsReg cr) %{
  6292   predicate(UseCountLeadingZerosInstruction);
  6293   match(Set dst (CountLeadingZerosI src));
  6294   effect(KILL cr);
  6296   format %{ "LZCNT  $dst, $src\t# count leading zeros (int)" %}
  6297   ins_encode %{
  6298     __ lzcntl($dst$$Register, $src$$Register);
  6299   %}
  6300   ins_pipe(ialu_reg);
  6301 %}
  6303 instruct countLeadingZerosI_bsr(eRegI dst, eRegI src, eFlagsReg cr) %{
  6304   predicate(!UseCountLeadingZerosInstruction);
  6305   match(Set dst (CountLeadingZerosI src));
  6306   effect(KILL cr);
  6308   format %{ "BSR    $dst, $src\t# count leading zeros (int)\n\t"
  6309             "JNZ    skip\n\t"
  6310             "MOV    $dst, -1\n"
  6311       "skip:\n\t"
  6312             "NEG    $dst\n\t"
  6313             "ADD    $dst, 31" %}
  6314   ins_encode %{
  6315     Register Rdst = $dst$$Register;
  6316     Register Rsrc = $src$$Register;
  6317     Label skip;
  6318     __ bsrl(Rdst, Rsrc);
  6319     __ jccb(Assembler::notZero, skip);
  6320     __ movl(Rdst, -1);
  6321     __ bind(skip);
  6322     __ negl(Rdst);
  6323     __ addl(Rdst, BitsPerInt - 1);
  6324   %}
  6325   ins_pipe(ialu_reg);
  6326 %}
  6328 instruct countLeadingZerosL(eRegI dst, eRegL src, eFlagsReg cr) %{
  6329   predicate(UseCountLeadingZerosInstruction);
  6330   match(Set dst (CountLeadingZerosL src));
  6331   effect(TEMP dst, KILL cr);
  6333   format %{ "LZCNT  $dst, $src.hi\t# count leading zeros (long)\n\t"
  6334             "JNC    done\n\t"
  6335             "LZCNT  $dst, $src.lo\n\t"
  6336             "ADD    $dst, 32\n"
  6337       "done:" %}
  6338   ins_encode %{
  6339     Register Rdst = $dst$$Register;
  6340     Register Rsrc = $src$$Register;
  6341     Label done;
  6342     __ lzcntl(Rdst, HIGH_FROM_LOW(Rsrc));
  6343     __ jccb(Assembler::carryClear, done);
  6344     __ lzcntl(Rdst, Rsrc);
  6345     __ addl(Rdst, BitsPerInt);
  6346     __ bind(done);
  6347   %}
  6348   ins_pipe(ialu_reg);
  6349 %}
  6351 instruct countLeadingZerosL_bsr(eRegI dst, eRegL src, eFlagsReg cr) %{
  6352   predicate(!UseCountLeadingZerosInstruction);
  6353   match(Set dst (CountLeadingZerosL src));
  6354   effect(TEMP dst, KILL cr);
  6356   format %{ "BSR    $dst, $src.hi\t# count leading zeros (long)\n\t"
  6357             "JZ     msw_is_zero\n\t"
  6358             "ADD    $dst, 32\n\t"
  6359             "JMP    not_zero\n"
  6360       "msw_is_zero:\n\t"
  6361             "BSR    $dst, $src.lo\n\t"
  6362             "JNZ    not_zero\n\t"
  6363             "MOV    $dst, -1\n"
  6364       "not_zero:\n\t"
  6365             "NEG    $dst\n\t"
  6366             "ADD    $dst, 63\n" %}
  6367  ins_encode %{
  6368     Register Rdst = $dst$$Register;
  6369     Register Rsrc = $src$$Register;
  6370     Label msw_is_zero;
  6371     Label not_zero;
  6372     __ bsrl(Rdst, HIGH_FROM_LOW(Rsrc));
  6373     __ jccb(Assembler::zero, msw_is_zero);
  6374     __ addl(Rdst, BitsPerInt);
  6375     __ jmpb(not_zero);
  6376     __ bind(msw_is_zero);
  6377     __ bsrl(Rdst, Rsrc);
  6378     __ jccb(Assembler::notZero, not_zero);
  6379     __ movl(Rdst, -1);
  6380     __ bind(not_zero);
  6381     __ negl(Rdst);
  6382     __ addl(Rdst, BitsPerLong - 1);
  6383   %}
  6384   ins_pipe(ialu_reg);
  6385 %}
  6387 instruct countTrailingZerosI(eRegI dst, eRegI src, eFlagsReg cr) %{
  6388   match(Set dst (CountTrailingZerosI src));
  6389   effect(KILL cr);
  6391   format %{ "BSF    $dst, $src\t# count trailing zeros (int)\n\t"
  6392             "JNZ    done\n\t"
  6393             "MOV    $dst, 32\n"
  6394       "done:" %}
  6395   ins_encode %{
  6396     Register Rdst = $dst$$Register;
  6397     Label done;
  6398     __ bsfl(Rdst, $src$$Register);
  6399     __ jccb(Assembler::notZero, done);
  6400     __ movl(Rdst, BitsPerInt);
  6401     __ bind(done);
  6402   %}
  6403   ins_pipe(ialu_reg);
  6404 %}
  6406 instruct countTrailingZerosL(eRegI dst, eRegL src, eFlagsReg cr) %{
  6407   match(Set dst (CountTrailingZerosL src));
  6408   effect(TEMP dst, KILL cr);
  6410   format %{ "BSF    $dst, $src.lo\t# count trailing zeros (long)\n\t"
  6411             "JNZ    done\n\t"
  6412             "BSF    $dst, $src.hi\n\t"
  6413             "JNZ    msw_not_zero\n\t"
  6414             "MOV    $dst, 32\n"
  6415       "msw_not_zero:\n\t"
  6416             "ADD    $dst, 32\n"
  6417       "done:" %}
  6418   ins_encode %{
  6419     Register Rdst = $dst$$Register;
  6420     Register Rsrc = $src$$Register;
  6421     Label msw_not_zero;
  6422     Label done;
  6423     __ bsfl(Rdst, Rsrc);
  6424     __ jccb(Assembler::notZero, done);
  6425     __ bsfl(Rdst, HIGH_FROM_LOW(Rsrc));
  6426     __ jccb(Assembler::notZero, msw_not_zero);
  6427     __ movl(Rdst, BitsPerInt);
  6428     __ bind(msw_not_zero);
  6429     __ addl(Rdst, BitsPerInt);
  6430     __ bind(done);
  6431   %}
  6432   ins_pipe(ialu_reg);
  6433 %}
  6436 //---------- Population Count Instructions -------------------------------------
  6438 instruct popCountI(eRegI dst, eRegI src) %{
  6439   predicate(UsePopCountInstruction);
  6440   match(Set dst (PopCountI src));
  6442   format %{ "POPCNT $dst, $src" %}
  6443   ins_encode %{
  6444     __ popcntl($dst$$Register, $src$$Register);
  6445   %}
  6446   ins_pipe(ialu_reg);
  6447 %}
  6449 instruct popCountI_mem(eRegI dst, memory mem) %{
  6450   predicate(UsePopCountInstruction);
  6451   match(Set dst (PopCountI (LoadI mem)));
  6453   format %{ "POPCNT $dst, $mem" %}
  6454   ins_encode %{
  6455     __ popcntl($dst$$Register, $mem$$Address);
  6456   %}
  6457   ins_pipe(ialu_reg);
  6458 %}
  6460 // Note: Long.bitCount(long) returns an int.
  6461 instruct popCountL(eRegI dst, eRegL src, eRegI tmp, eFlagsReg cr) %{
  6462   predicate(UsePopCountInstruction);
  6463   match(Set dst (PopCountL src));
  6464   effect(KILL cr, TEMP tmp, TEMP dst);
  6466   format %{ "POPCNT $dst, $src.lo\n\t"
  6467             "POPCNT $tmp, $src.hi\n\t"
  6468             "ADD    $dst, $tmp" %}
  6469   ins_encode %{
  6470     __ popcntl($dst$$Register, $src$$Register);
  6471     __ popcntl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
  6472     __ addl($dst$$Register, $tmp$$Register);
  6473   %}
  6474   ins_pipe(ialu_reg);
  6475 %}
  6477 // Note: Long.bitCount(long) returns an int.
  6478 instruct popCountL_mem(eRegI dst, memory mem, eRegI tmp, eFlagsReg cr) %{
  6479   predicate(UsePopCountInstruction);
  6480   match(Set dst (PopCountL (LoadL mem)));
  6481   effect(KILL cr, TEMP tmp, TEMP dst);
  6483   format %{ "POPCNT $dst, $mem\n\t"
  6484             "POPCNT $tmp, $mem+4\n\t"
  6485             "ADD    $dst, $tmp" %}
  6486   ins_encode %{
  6487     //__ popcntl($dst$$Register, $mem$$Address$$first);
  6488     //__ popcntl($tmp$$Register, $mem$$Address$$second);
  6489     __ popcntl($dst$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, false));
  6490     __ popcntl($tmp$$Register, Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, false));
  6491     __ addl($dst$$Register, $tmp$$Register);
  6492   %}
  6493   ins_pipe(ialu_reg);
  6494 %}
  6497 //----------Load/Store/Move Instructions---------------------------------------
  6498 //----------Load Instructions--------------------------------------------------
  6499 // Load Byte (8bit signed)
  6500 instruct loadB(xRegI dst, memory mem) %{
  6501   match(Set dst (LoadB mem));
  6503   ins_cost(125);
  6504   format %{ "MOVSX8 $dst,$mem\t# byte" %}
  6506   ins_encode %{
  6507     __ movsbl($dst$$Register, $mem$$Address);
  6508   %}
  6510   ins_pipe(ialu_reg_mem);
  6511 %}
  6513 // Load Byte (8bit signed) into Long Register
  6514 instruct loadB2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6515   match(Set dst (ConvI2L (LoadB mem)));
  6516   effect(KILL cr);
  6518   ins_cost(375);
  6519   format %{ "MOVSX8 $dst.lo,$mem\t# byte -> long\n\t"
  6520             "MOV    $dst.hi,$dst.lo\n\t"
  6521             "SAR    $dst.hi,7" %}
  6523   ins_encode %{
  6524     __ movsbl($dst$$Register, $mem$$Address);
  6525     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  6526     __ sarl(HIGH_FROM_LOW($dst$$Register), 7); // 24+1 MSB are already signed extended.
  6527   %}
  6529   ins_pipe(ialu_reg_mem);
  6530 %}
  6532 // Load Unsigned Byte (8bit UNsigned)
  6533 instruct loadUB(xRegI dst, memory mem) %{
  6534   match(Set dst (LoadUB mem));
  6536   ins_cost(125);
  6537   format %{ "MOVZX8 $dst,$mem\t# ubyte -> int" %}
  6539   ins_encode %{
  6540     __ movzbl($dst$$Register, $mem$$Address);
  6541   %}
  6543   ins_pipe(ialu_reg_mem);
  6544 %}
  6546 // Load Unsigned Byte (8 bit UNsigned) into Long Register
  6547 instruct loadUB2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6548   match(Set dst (ConvI2L (LoadUB mem)));
  6549   effect(KILL cr);
  6551   ins_cost(250);
  6552   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte -> long\n\t"
  6553             "XOR    $dst.hi,$dst.hi" %}
  6555   ins_encode %{
  6556     Register Rdst = $dst$$Register;
  6557     __ movzbl(Rdst, $mem$$Address);
  6558     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6559   %}
  6561   ins_pipe(ialu_reg_mem);
  6562 %}
  6564 // Load Unsigned Byte (8 bit UNsigned) with mask into Long Register
  6565 instruct loadUB2L_immI8(eRegL dst, memory mem, immI8 mask, eFlagsReg cr) %{
  6566   match(Set dst (ConvI2L (AndI (LoadUB mem) mask)));
  6567   effect(KILL cr);
  6569   format %{ "MOVZX8 $dst.lo,$mem\t# ubyte & 8-bit mask -> long\n\t"
  6570             "XOR    $dst.hi,$dst.hi\n\t"
  6571             "AND    $dst.lo,$mask" %}
  6572   ins_encode %{
  6573     Register Rdst = $dst$$Register;
  6574     __ movzbl(Rdst, $mem$$Address);
  6575     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6576     __ andl(Rdst, $mask$$constant);
  6577   %}
  6578   ins_pipe(ialu_reg_mem);
  6579 %}
  6581 // Load Short (16bit signed)
  6582 instruct loadS(eRegI dst, memory mem) %{
  6583   match(Set dst (LoadS mem));
  6585   ins_cost(125);
  6586   format %{ "MOVSX  $dst,$mem\t# short" %}
  6588   ins_encode %{
  6589     __ movswl($dst$$Register, $mem$$Address);
  6590   %}
  6592   ins_pipe(ialu_reg_mem);
  6593 %}
  6595 // Load Short (16 bit signed) to Byte (8 bit signed)
  6596 instruct loadS2B(eRegI dst, memory mem, immI_24 twentyfour) %{
  6597   match(Set dst (RShiftI (LShiftI (LoadS mem) twentyfour) twentyfour));
  6599   ins_cost(125);
  6600   format %{ "MOVSX  $dst, $mem\t# short -> byte" %}
  6601   ins_encode %{
  6602     __ movsbl($dst$$Register, $mem$$Address);
  6603   %}
  6604   ins_pipe(ialu_reg_mem);
  6605 %}
  6607 // Load Short (16bit signed) into Long Register
  6608 instruct loadS2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6609   match(Set dst (ConvI2L (LoadS mem)));
  6610   effect(KILL cr);
  6612   ins_cost(375);
  6613   format %{ "MOVSX  $dst.lo,$mem\t# short -> long\n\t"
  6614             "MOV    $dst.hi,$dst.lo\n\t"
  6615             "SAR    $dst.hi,15" %}
  6617   ins_encode %{
  6618     __ movswl($dst$$Register, $mem$$Address);
  6619     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  6620     __ sarl(HIGH_FROM_LOW($dst$$Register), 15); // 16+1 MSB are already signed extended.
  6621   %}
  6623   ins_pipe(ialu_reg_mem);
  6624 %}
  6626 // Load Unsigned Short/Char (16bit unsigned)
  6627 instruct loadUS(eRegI dst, memory mem) %{
  6628   match(Set dst (LoadUS mem));
  6630   ins_cost(125);
  6631   format %{ "MOVZX  $dst,$mem\t# ushort/char -> int" %}
  6633   ins_encode %{
  6634     __ movzwl($dst$$Register, $mem$$Address);
  6635   %}
  6637   ins_pipe(ialu_reg_mem);
  6638 %}
  6640 // Load Unsigned Short/Char (16 bit UNsigned) to Byte (8 bit signed)
  6641 instruct loadUS2B(eRegI dst, memory mem, immI_24 twentyfour) %{
  6642   match(Set dst (RShiftI (LShiftI (LoadUS mem) twentyfour) twentyfour));
  6644   ins_cost(125);
  6645   format %{ "MOVSX  $dst, $mem\t# ushort -> byte" %}
  6646   ins_encode %{
  6647     __ movsbl($dst$$Register, $mem$$Address);
  6648   %}
  6649   ins_pipe(ialu_reg_mem);
  6650 %}
  6652 // Load Unsigned Short/Char (16 bit UNsigned) into Long Register
  6653 instruct loadUS2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6654   match(Set dst (ConvI2L (LoadUS mem)));
  6655   effect(KILL cr);
  6657   ins_cost(250);
  6658   format %{ "MOVZX  $dst.lo,$mem\t# ushort/char -> long\n\t"
  6659             "XOR    $dst.hi,$dst.hi" %}
  6661   ins_encode %{
  6662     __ movzwl($dst$$Register, $mem$$Address);
  6663     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
  6664   %}
  6666   ins_pipe(ialu_reg_mem);
  6667 %}
  6669 // Load Unsigned Short/Char (16 bit UNsigned) with mask 0xFF into Long Register
  6670 instruct loadUS2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
  6671   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
  6672   effect(KILL cr);
  6674   format %{ "MOVZX8 $dst.lo,$mem\t# ushort/char & 0xFF -> long\n\t"
  6675             "XOR    $dst.hi,$dst.hi" %}
  6676   ins_encode %{
  6677     Register Rdst = $dst$$Register;
  6678     __ movzbl(Rdst, $mem$$Address);
  6679     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6680   %}
  6681   ins_pipe(ialu_reg_mem);
  6682 %}
  6684 // Load Unsigned Short/Char (16 bit UNsigned) with a 16-bit mask into Long Register
  6685 instruct loadUS2L_immI16(eRegL dst, memory mem, immI16 mask, eFlagsReg cr) %{
  6686   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
  6687   effect(KILL cr);
  6689   format %{ "MOVZX  $dst.lo, $mem\t# ushort/char & 16-bit mask -> long\n\t"
  6690             "XOR    $dst.hi,$dst.hi\n\t"
  6691             "AND    $dst.lo,$mask" %}
  6692   ins_encode %{
  6693     Register Rdst = $dst$$Register;
  6694     __ movzwl(Rdst, $mem$$Address);
  6695     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6696     __ andl(Rdst, $mask$$constant);
  6697   %}
  6698   ins_pipe(ialu_reg_mem);
  6699 %}
  6701 // Load Integer
  6702 instruct loadI(eRegI dst, memory mem) %{
  6703   match(Set dst (LoadI mem));
  6705   ins_cost(125);
  6706   format %{ "MOV    $dst,$mem\t# int" %}
  6708   ins_encode %{
  6709     __ movl($dst$$Register, $mem$$Address);
  6710   %}
  6712   ins_pipe(ialu_reg_mem);
  6713 %}
  6715 // Load Integer (32 bit signed) to Byte (8 bit signed)
  6716 instruct loadI2B(eRegI dst, memory mem, immI_24 twentyfour) %{
  6717   match(Set dst (RShiftI (LShiftI (LoadI mem) twentyfour) twentyfour));
  6719   ins_cost(125);
  6720   format %{ "MOVSX  $dst, $mem\t# int -> byte" %}
  6721   ins_encode %{
  6722     __ movsbl($dst$$Register, $mem$$Address);
  6723   %}
  6724   ins_pipe(ialu_reg_mem);
  6725 %}
  6727 // Load Integer (32 bit signed) to Unsigned Byte (8 bit UNsigned)
  6728 instruct loadI2UB(eRegI dst, memory mem, immI_255 mask) %{
  6729   match(Set dst (AndI (LoadI mem) mask));
  6731   ins_cost(125);
  6732   format %{ "MOVZX  $dst, $mem\t# int -> ubyte" %}
  6733   ins_encode %{
  6734     __ movzbl($dst$$Register, $mem$$Address);
  6735   %}
  6736   ins_pipe(ialu_reg_mem);
  6737 %}
  6739 // Load Integer (32 bit signed) to Short (16 bit signed)
  6740 instruct loadI2S(eRegI dst, memory mem, immI_16 sixteen) %{
  6741   match(Set dst (RShiftI (LShiftI (LoadI mem) sixteen) sixteen));
  6743   ins_cost(125);
  6744   format %{ "MOVSX  $dst, $mem\t# int -> short" %}
  6745   ins_encode %{
  6746     __ movswl($dst$$Register, $mem$$Address);
  6747   %}
  6748   ins_pipe(ialu_reg_mem);
  6749 %}
  6751 // Load Integer (32 bit signed) to Unsigned Short/Char (16 bit UNsigned)
  6752 instruct loadI2US(eRegI dst, memory mem, immI_65535 mask) %{
  6753   match(Set dst (AndI (LoadI mem) mask));
  6755   ins_cost(125);
  6756   format %{ "MOVZX  $dst, $mem\t# int -> ushort/char" %}
  6757   ins_encode %{
  6758     __ movzwl($dst$$Register, $mem$$Address);
  6759   %}
  6760   ins_pipe(ialu_reg_mem);
  6761 %}
  6763 // Load Integer into Long Register
  6764 instruct loadI2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6765   match(Set dst (ConvI2L (LoadI mem)));
  6766   effect(KILL cr);
  6768   ins_cost(375);
  6769   format %{ "MOV    $dst.lo,$mem\t# int -> long\n\t"
  6770             "MOV    $dst.hi,$dst.lo\n\t"
  6771             "SAR    $dst.hi,31" %}
  6773   ins_encode %{
  6774     __ movl($dst$$Register, $mem$$Address);
  6775     __ movl(HIGH_FROM_LOW($dst$$Register), $dst$$Register); // This is always a different register.
  6776     __ sarl(HIGH_FROM_LOW($dst$$Register), 31);
  6777   %}
  6779   ins_pipe(ialu_reg_mem);
  6780 %}
  6782 // Load Integer with mask 0xFF into Long Register
  6783 instruct loadI2L_immI_255(eRegL dst, memory mem, immI_255 mask, eFlagsReg cr) %{
  6784   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6785   effect(KILL cr);
  6787   format %{ "MOVZX8 $dst.lo,$mem\t# int & 0xFF -> long\n\t"
  6788             "XOR    $dst.hi,$dst.hi" %}
  6789   ins_encode %{
  6790     Register Rdst = $dst$$Register;
  6791     __ movzbl(Rdst, $mem$$Address);
  6792     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6793   %}
  6794   ins_pipe(ialu_reg_mem);
  6795 %}
  6797 // Load Integer with mask 0xFFFF into Long Register
  6798 instruct loadI2L_immI_65535(eRegL dst, memory mem, immI_65535 mask, eFlagsReg cr) %{
  6799   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6800   effect(KILL cr);
  6802   format %{ "MOVZX  $dst.lo,$mem\t# int & 0xFFFF -> long\n\t"
  6803             "XOR    $dst.hi,$dst.hi" %}
  6804   ins_encode %{
  6805     Register Rdst = $dst$$Register;
  6806     __ movzwl(Rdst, $mem$$Address);
  6807     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6808   %}
  6809   ins_pipe(ialu_reg_mem);
  6810 %}
  6812 // Load Integer with 32-bit mask into Long Register
  6813 instruct loadI2L_immI(eRegL dst, memory mem, immI mask, eFlagsReg cr) %{
  6814   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
  6815   effect(KILL cr);
  6817   format %{ "MOV    $dst.lo,$mem\t# int & 32-bit mask -> long\n\t"
  6818             "XOR    $dst.hi,$dst.hi\n\t"
  6819             "AND    $dst.lo,$mask" %}
  6820   ins_encode %{
  6821     Register Rdst = $dst$$Register;
  6822     __ movl(Rdst, $mem$$Address);
  6823     __ xorl(HIGH_FROM_LOW(Rdst), HIGH_FROM_LOW(Rdst));
  6824     __ andl(Rdst, $mask$$constant);
  6825   %}
  6826   ins_pipe(ialu_reg_mem);
  6827 %}
  6829 // Load Unsigned Integer into Long Register
  6830 instruct loadUI2L(eRegL dst, memory mem, eFlagsReg cr) %{
  6831   match(Set dst (LoadUI2L mem));
  6832   effect(KILL cr);
  6834   ins_cost(250);
  6835   format %{ "MOV    $dst.lo,$mem\t# uint -> long\n\t"
  6836             "XOR    $dst.hi,$dst.hi" %}
  6838   ins_encode %{
  6839     __ movl($dst$$Register, $mem$$Address);
  6840     __ xorl(HIGH_FROM_LOW($dst$$Register), HIGH_FROM_LOW($dst$$Register));
  6841   %}
  6843   ins_pipe(ialu_reg_mem);
  6844 %}
  6846 // Load Long.  Cannot clobber address while loading, so restrict address
  6847 // register to ESI
  6848 instruct loadL(eRegL dst, load_long_memory mem) %{
  6849   predicate(!((LoadLNode*)n)->require_atomic_access());
  6850   match(Set dst (LoadL mem));
  6852   ins_cost(250);
  6853   format %{ "MOV    $dst.lo,$mem\t# long\n\t"
  6854             "MOV    $dst.hi,$mem+4" %}
  6856   ins_encode %{
  6857     Address Amemlo = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp, false);
  6858     Address Amemhi = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp + 4, false);
  6859     __ movl($dst$$Register, Amemlo);
  6860     __ movl(HIGH_FROM_LOW($dst$$Register), Amemhi);
  6861   %}
  6863   ins_pipe(ialu_reg_long_mem);
  6864 %}
  6866 // Volatile Load Long.  Must be atomic, so do 64-bit FILD
  6867 // then store it down to the stack and reload on the int
  6868 // side.
  6869 instruct loadL_volatile(stackSlotL dst, memory mem) %{
  6870   predicate(UseSSE<=1 && ((LoadLNode*)n)->require_atomic_access());
  6871   match(Set dst (LoadL mem));
  6873   ins_cost(200);
  6874   format %{ "FILD   $mem\t# Atomic volatile long load\n\t"
  6875             "FISTp  $dst" %}
  6876   ins_encode(enc_loadL_volatile(mem,dst));
  6877   ins_pipe( fpu_reg_mem );
  6878 %}
  6880 instruct loadLX_volatile(stackSlotL dst, memory mem, regXD tmp) %{
  6881   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
  6882   match(Set dst (LoadL mem));
  6883   effect(TEMP tmp);
  6884   ins_cost(180);
  6885   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  6886             "MOVSD  $dst,$tmp" %}
  6887   ins_encode(enc_loadLX_volatile(mem, dst, tmp));
  6888   ins_pipe( pipe_slow );
  6889 %}
  6891 instruct loadLX_reg_volatile(eRegL dst, memory mem, regXD tmp) %{
  6892   predicate(UseSSE>=2 && ((LoadLNode*)n)->require_atomic_access());
  6893   match(Set dst (LoadL mem));
  6894   effect(TEMP tmp);
  6895   ins_cost(160);
  6896   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  6897             "MOVD   $dst.lo,$tmp\n\t"
  6898             "PSRLQ  $tmp,32\n\t"
  6899             "MOVD   $dst.hi,$tmp" %}
  6900   ins_encode(enc_loadLX_reg_volatile(mem, dst, tmp));
  6901   ins_pipe( pipe_slow );
  6902 %}
  6904 // Load Range
  6905 instruct loadRange(eRegI dst, memory mem) %{
  6906   match(Set dst (LoadRange mem));
  6908   ins_cost(125);
  6909   format %{ "MOV    $dst,$mem" %}
  6910   opcode(0x8B);
  6911   ins_encode( OpcP, RegMem(dst,mem));
  6912   ins_pipe( ialu_reg_mem );
  6913 %}
  6916 // Load Pointer
  6917 instruct loadP(eRegP dst, memory mem) %{
  6918   match(Set dst (LoadP mem));
  6920   ins_cost(125);
  6921   format %{ "MOV    $dst,$mem" %}
  6922   opcode(0x8B);
  6923   ins_encode( OpcP, RegMem(dst,mem));
  6924   ins_pipe( ialu_reg_mem );
  6925 %}
  6927 // Load Klass Pointer
  6928 instruct loadKlass(eRegP dst, memory mem) %{
  6929   match(Set dst (LoadKlass mem));
  6931   ins_cost(125);
  6932   format %{ "MOV    $dst,$mem" %}
  6933   opcode(0x8B);
  6934   ins_encode( OpcP, RegMem(dst,mem));
  6935   ins_pipe( ialu_reg_mem );
  6936 %}
  6938 // Load Double
  6939 instruct loadD(regD dst, memory mem) %{
  6940   predicate(UseSSE<=1);
  6941   match(Set dst (LoadD mem));
  6943   ins_cost(150);
  6944   format %{ "FLD_D  ST,$mem\n\t"
  6945             "FSTP   $dst" %}
  6946   opcode(0xDD);               /* DD /0 */
  6947   ins_encode( OpcP, RMopc_Mem(0x00,mem),
  6948               Pop_Reg_D(dst) );
  6949   ins_pipe( fpu_reg_mem );
  6950 %}
  6952 // Load Double to XMM
  6953 instruct loadXD(regXD dst, memory mem) %{
  6954   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
  6955   match(Set dst (LoadD mem));
  6956   ins_cost(145);
  6957   format %{ "MOVSD  $dst,$mem" %}
  6958   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x10), RegMem(dst,mem));
  6959   ins_pipe( pipe_slow );
  6960 %}
  6962 instruct loadXD_partial(regXD dst, memory mem) %{
  6963   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
  6964   match(Set dst (LoadD mem));
  6965   ins_cost(145);
  6966   format %{ "MOVLPD $dst,$mem" %}
  6967   ins_encode( Opcode(0x66), Opcode(0x0F), Opcode(0x12), RegMem(dst,mem));
  6968   ins_pipe( pipe_slow );
  6969 %}
  6971 // Load to XMM register (single-precision floating point)
  6972 // MOVSS instruction
  6973 instruct loadX(regX dst, memory mem) %{
  6974   predicate(UseSSE>=1);
  6975   match(Set dst (LoadF mem));
  6976   ins_cost(145);
  6977   format %{ "MOVSS  $dst,$mem" %}
  6978   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x10), RegMem(dst,mem));
  6979   ins_pipe( pipe_slow );
  6980 %}
  6982 // Load Float
  6983 instruct loadF(regF dst, memory mem) %{
  6984   predicate(UseSSE==0);
  6985   match(Set dst (LoadF mem));
  6987   ins_cost(150);
  6988   format %{ "FLD_S  ST,$mem\n\t"
  6989             "FSTP   $dst" %}
  6990   opcode(0xD9);               /* D9 /0 */
  6991   ins_encode( OpcP, RMopc_Mem(0x00,mem),
  6992               Pop_Reg_F(dst) );
  6993   ins_pipe( fpu_reg_mem );
  6994 %}
  6996 // Load Aligned Packed Byte to XMM register
  6997 instruct loadA8B(regXD dst, memory mem) %{
  6998   predicate(UseSSE>=1);
  6999   match(Set dst (Load8B mem));
  7000   ins_cost(125);
  7001   format %{ "MOVQ  $dst,$mem\t! packed8B" %}
  7002   ins_encode( movq_ld(dst, mem));
  7003   ins_pipe( pipe_slow );
  7004 %}
  7006 // Load Aligned Packed Short to XMM register
  7007 instruct loadA4S(regXD dst, memory mem) %{
  7008   predicate(UseSSE>=1);
  7009   match(Set dst (Load4S mem));
  7010   ins_cost(125);
  7011   format %{ "MOVQ  $dst,$mem\t! packed4S" %}
  7012   ins_encode( movq_ld(dst, mem));
  7013   ins_pipe( pipe_slow );
  7014 %}
  7016 // Load Aligned Packed Char to XMM register
  7017 instruct loadA4C(regXD dst, memory mem) %{
  7018   predicate(UseSSE>=1);
  7019   match(Set dst (Load4C mem));
  7020   ins_cost(125);
  7021   format %{ "MOVQ  $dst,$mem\t! packed4C" %}
  7022   ins_encode( movq_ld(dst, mem));
  7023   ins_pipe( pipe_slow );
  7024 %}
  7026 // Load Aligned Packed Integer to XMM register
  7027 instruct load2IU(regXD dst, memory mem) %{
  7028   predicate(UseSSE>=1);
  7029   match(Set dst (Load2I mem));
  7030   ins_cost(125);
  7031   format %{ "MOVQ  $dst,$mem\t! packed2I" %}
  7032   ins_encode( movq_ld(dst, mem));
  7033   ins_pipe( pipe_slow );
  7034 %}
  7036 // Load Aligned Packed Single to XMM
  7037 instruct loadA2F(regXD dst, memory mem) %{
  7038   predicate(UseSSE>=1);
  7039   match(Set dst (Load2F mem));
  7040   ins_cost(145);
  7041   format %{ "MOVQ  $dst,$mem\t! packed2F" %}
  7042   ins_encode( movq_ld(dst, mem));
  7043   ins_pipe( pipe_slow );
  7044 %}
  7046 // Load Effective Address
  7047 instruct leaP8(eRegP dst, indOffset8 mem) %{
  7048   match(Set dst mem);
  7050   ins_cost(110);
  7051   format %{ "LEA    $dst,$mem" %}
  7052   opcode(0x8D);
  7053   ins_encode( OpcP, RegMem(dst,mem));
  7054   ins_pipe( ialu_reg_reg_fat );
  7055 %}
  7057 instruct leaP32(eRegP dst, indOffset32 mem) %{
  7058   match(Set dst mem);
  7060   ins_cost(110);
  7061   format %{ "LEA    $dst,$mem" %}
  7062   opcode(0x8D);
  7063   ins_encode( OpcP, RegMem(dst,mem));
  7064   ins_pipe( ialu_reg_reg_fat );
  7065 %}
  7067 instruct leaPIdxOff(eRegP dst, indIndexOffset mem) %{
  7068   match(Set dst mem);
  7070   ins_cost(110);
  7071   format %{ "LEA    $dst,$mem" %}
  7072   opcode(0x8D);
  7073   ins_encode( OpcP, RegMem(dst,mem));
  7074   ins_pipe( ialu_reg_reg_fat );
  7075 %}
  7077 instruct leaPIdxScale(eRegP dst, indIndexScale mem) %{
  7078   match(Set dst mem);
  7080   ins_cost(110);
  7081   format %{ "LEA    $dst,$mem" %}
  7082   opcode(0x8D);
  7083   ins_encode( OpcP, RegMem(dst,mem));
  7084   ins_pipe( ialu_reg_reg_fat );
  7085 %}
  7087 instruct leaPIdxScaleOff(eRegP dst, indIndexScaleOffset mem) %{
  7088   match(Set dst mem);
  7090   ins_cost(110);
  7091   format %{ "LEA    $dst,$mem" %}
  7092   opcode(0x8D);
  7093   ins_encode( OpcP, RegMem(dst,mem));
  7094   ins_pipe( ialu_reg_reg_fat );
  7095 %}
  7097 // Load Constant
  7098 instruct loadConI(eRegI dst, immI src) %{
  7099   match(Set dst src);
  7101   format %{ "MOV    $dst,$src" %}
  7102   ins_encode( LdImmI(dst, src) );
  7103   ins_pipe( ialu_reg_fat );
  7104 %}
  7106 // Load Constant zero
  7107 instruct loadConI0(eRegI dst, immI0 src, eFlagsReg cr) %{
  7108   match(Set dst src);
  7109   effect(KILL cr);
  7111   ins_cost(50);
  7112   format %{ "XOR    $dst,$dst" %}
  7113   opcode(0x33);  /* + rd */
  7114   ins_encode( OpcP, RegReg( dst, dst ) );
  7115   ins_pipe( ialu_reg );
  7116 %}
  7118 instruct loadConP(eRegP dst, immP src) %{
  7119   match(Set dst src);
  7121   format %{ "MOV    $dst,$src" %}
  7122   opcode(0xB8);  /* + rd */
  7123   ins_encode( LdImmP(dst, src) );
  7124   ins_pipe( ialu_reg_fat );
  7125 %}
  7127 instruct loadConL(eRegL dst, immL src, eFlagsReg cr) %{
  7128   match(Set dst src);
  7129   effect(KILL cr);
  7130   ins_cost(200);
  7131   format %{ "MOV    $dst.lo,$src.lo\n\t"
  7132             "MOV    $dst.hi,$src.hi" %}
  7133   opcode(0xB8);
  7134   ins_encode( LdImmL_Lo(dst, src), LdImmL_Hi(dst, src) );
  7135   ins_pipe( ialu_reg_long_fat );
  7136 %}
  7138 instruct loadConL0(eRegL dst, immL0 src, eFlagsReg cr) %{
  7139   match(Set dst src);
  7140   effect(KILL cr);
  7141   ins_cost(150);
  7142   format %{ "XOR    $dst.lo,$dst.lo\n\t"
  7143             "XOR    $dst.hi,$dst.hi" %}
  7144   opcode(0x33,0x33);
  7145   ins_encode( RegReg_Lo(dst,dst), RegReg_Hi(dst, dst) );
  7146   ins_pipe( ialu_reg_long );
  7147 %}
  7149 // The instruction usage is guarded by predicate in operand immF().
  7150 instruct loadConF(regF dst, immF con) %{
  7151   match(Set dst con);
  7152   ins_cost(125);
  7153   format %{ "FLD_S  ST,[$constantaddress]\t# load from constant table: float=$con\n\t"
  7154             "FSTP   $dst" %}
  7155   ins_encode %{
  7156     __ fld_s($constantaddress($con));
  7157     __ fstp_d($dst$$reg);
  7158   %}
  7159   ins_pipe(fpu_reg_con);
  7160 %}
  7162 // The instruction usage is guarded by predicate in operand immF0().
  7163 instruct loadConF0(regF dst, immF0 con) %{
  7164   match(Set dst con);
  7165   ins_cost(125);
  7166   format %{ "FLDZ   ST\n\t"
  7167             "FSTP   $dst" %}
  7168   ins_encode %{
  7169     __ fldz();
  7170     __ fstp_d($dst$$reg);
  7171   %}
  7172   ins_pipe(fpu_reg_con);
  7173 %}
  7175 // The instruction usage is guarded by predicate in operand immF1().
  7176 instruct loadConF1(regF dst, immF1 con) %{
  7177   match(Set dst con);
  7178   ins_cost(125);
  7179   format %{ "FLD1   ST\n\t"
  7180             "FSTP   $dst" %}
  7181   ins_encode %{
  7182     __ fld1();
  7183     __ fstp_d($dst$$reg);
  7184   %}
  7185   ins_pipe(fpu_reg_con);
  7186 %}
  7188 // The instruction usage is guarded by predicate in operand immXF().
  7189 instruct loadConX(regX dst, immXF con) %{
  7190   match(Set dst con);
  7191   ins_cost(125);
  7192   format %{ "MOVSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
  7193   ins_encode %{
  7194     __ movflt($dst$$XMMRegister, $constantaddress($con));
  7195   %}
  7196   ins_pipe(pipe_slow);
  7197 %}
  7199 // The instruction usage is guarded by predicate in operand immXF0().
  7200 instruct loadConX0(regX dst, immXF0 src) %{
  7201   match(Set dst src);
  7202   ins_cost(100);
  7203   format %{ "XORPS  $dst,$dst\t# float 0.0" %}
  7204   ins_encode %{
  7205     __ xorps($dst$$XMMRegister, $dst$$XMMRegister);
  7206   %}
  7207   ins_pipe(pipe_slow);
  7208 %}
  7210 // The instruction usage is guarded by predicate in operand immD().
  7211 instruct loadConD(regD dst, immD con) %{
  7212   match(Set dst con);
  7213   ins_cost(125);
  7215   format %{ "FLD_D  ST,[$constantaddress]\t# load from constant table: double=$con\n\t"
  7216             "FSTP   $dst" %}
  7217   ins_encode %{
  7218     __ fld_d($constantaddress($con));
  7219     __ fstp_d($dst$$reg);
  7220   %}
  7221   ins_pipe(fpu_reg_con);
  7222 %}
  7224 // The instruction usage is guarded by predicate in operand immD0().
  7225 instruct loadConD0(regD dst, immD0 con) %{
  7226   match(Set dst con);
  7227   ins_cost(125);
  7229   format %{ "FLDZ   ST\n\t"
  7230             "FSTP   $dst" %}
  7231   ins_encode %{
  7232     __ fldz();
  7233     __ fstp_d($dst$$reg);
  7234   %}
  7235   ins_pipe(fpu_reg_con);
  7236 %}
  7238 // The instruction usage is guarded by predicate in operand immD1().
  7239 instruct loadConD1(regD dst, immD1 con) %{
  7240   match(Set dst con);
  7241   ins_cost(125);
  7243   format %{ "FLD1   ST\n\t"
  7244             "FSTP   $dst" %}
  7245   ins_encode %{
  7246     __ fld1();
  7247     __ fstp_d($dst$$reg);
  7248   %}
  7249   ins_pipe(fpu_reg_con);
  7250 %}
  7252 // The instruction usage is guarded by predicate in operand immXD().
  7253 instruct loadConXD(regXD dst, immXD con) %{
  7254   match(Set dst con);
  7255   ins_cost(125);
  7256   format %{ "MOVSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
  7257   ins_encode %{
  7258     __ movdbl($dst$$XMMRegister, $constantaddress($con));
  7259   %}
  7260   ins_pipe(pipe_slow);
  7261 %}
  7263 // The instruction usage is guarded by predicate in operand immXD0().
  7264 instruct loadConXD0(regXD dst, immXD0 src) %{
  7265   match(Set dst src);
  7266   ins_cost(100);
  7267   format %{ "XORPD  $dst,$dst\t# double 0.0" %}
  7268   ins_encode( Opcode(0x66), Opcode(0x0F), Opcode(0x57), RegReg(dst,dst));
  7269   ins_pipe( pipe_slow );
  7270 %}
  7272 // Load Stack Slot
  7273 instruct loadSSI(eRegI dst, stackSlotI src) %{
  7274   match(Set dst src);
  7275   ins_cost(125);
  7277   format %{ "MOV    $dst,$src" %}
  7278   opcode(0x8B);
  7279   ins_encode( OpcP, RegMem(dst,src));
  7280   ins_pipe( ialu_reg_mem );
  7281 %}
  7283 instruct loadSSL(eRegL dst, stackSlotL src) %{
  7284   match(Set dst src);
  7286   ins_cost(200);
  7287   format %{ "MOV    $dst,$src.lo\n\t"
  7288             "MOV    $dst+4,$src.hi" %}
  7289   opcode(0x8B, 0x8B);
  7290   ins_encode( OpcP, RegMem( dst, src ), OpcS, RegMem_Hi( dst, src ) );
  7291   ins_pipe( ialu_mem_long_reg );
  7292 %}
  7294 // Load Stack Slot
  7295 instruct loadSSP(eRegP dst, stackSlotP src) %{
  7296   match(Set dst src);
  7297   ins_cost(125);
  7299   format %{ "MOV    $dst,$src" %}
  7300   opcode(0x8B);
  7301   ins_encode( OpcP, RegMem(dst,src));
  7302   ins_pipe( ialu_reg_mem );
  7303 %}
  7305 // Load Stack Slot
  7306 instruct loadSSF(regF dst, stackSlotF src) %{
  7307   match(Set dst src);
  7308   ins_cost(125);
  7310   format %{ "FLD_S  $src\n\t"
  7311             "FSTP   $dst" %}
  7312   opcode(0xD9);               /* D9 /0, FLD m32real */
  7313   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
  7314               Pop_Reg_F(dst) );
  7315   ins_pipe( fpu_reg_mem );
  7316 %}
  7318 // Load Stack Slot
  7319 instruct loadSSD(regD dst, stackSlotD src) %{
  7320   match(Set dst src);
  7321   ins_cost(125);
  7323   format %{ "FLD_D  $src\n\t"
  7324             "FSTP   $dst" %}
  7325   opcode(0xDD);               /* DD /0, FLD m64real */
  7326   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
  7327               Pop_Reg_D(dst) );
  7328   ins_pipe( fpu_reg_mem );
  7329 %}
  7331 // Prefetch instructions.
  7332 // Must be safe to execute with invalid address (cannot fault).
  7334 instruct prefetchr0( memory mem ) %{
  7335   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
  7336   match(PrefetchRead mem);
  7337   ins_cost(0);
  7338   size(0);
  7339   format %{ "PREFETCHR (non-SSE is empty encoding)" %}
  7340   ins_encode();
  7341   ins_pipe(empty);
  7342 %}
  7344 instruct prefetchr( memory mem ) %{
  7345   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch() || ReadPrefetchInstr==3);
  7346   match(PrefetchRead mem);
  7347   ins_cost(100);
  7349   format %{ "PREFETCHR $mem\t! Prefetch into level 1 cache for read" %}
  7350   opcode(0x0F, 0x0d);     /* Opcode 0F 0d /0 */
  7351   ins_encode(OpcP, OpcS, RMopc_Mem(0x00,mem));
  7352   ins_pipe(ialu_mem);
  7353 %}
  7355 instruct prefetchrNTA( memory mem ) %{
  7356   predicate(UseSSE>=1 && ReadPrefetchInstr==0);
  7357   match(PrefetchRead mem);
  7358   ins_cost(100);
  7360   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for read" %}
  7361   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
  7362   ins_encode(OpcP, OpcS, RMopc_Mem(0x00,mem));
  7363   ins_pipe(ialu_mem);
  7364 %}
  7366 instruct prefetchrT0( memory mem ) %{
  7367   predicate(UseSSE>=1 && ReadPrefetchInstr==1);
  7368   match(PrefetchRead mem);
  7369   ins_cost(100);
  7371   format %{ "PREFETCHT0 $mem\t! Prefetch into L1 and L2 caches for read" %}
  7372   opcode(0x0F, 0x18);     /* Opcode 0F 18 /1 */
  7373   ins_encode(OpcP, OpcS, RMopc_Mem(0x01,mem));
  7374   ins_pipe(ialu_mem);
  7375 %}
  7377 instruct prefetchrT2( memory mem ) %{
  7378   predicate(UseSSE>=1 && ReadPrefetchInstr==2);
  7379   match(PrefetchRead mem);
  7380   ins_cost(100);
  7382   format %{ "PREFETCHT2 $mem\t! Prefetch into L2 cache for read" %}
  7383   opcode(0x0F, 0x18);     /* Opcode 0F 18 /3 */
  7384   ins_encode(OpcP, OpcS, RMopc_Mem(0x03,mem));
  7385   ins_pipe(ialu_mem);
  7386 %}
  7388 instruct prefetchw0( memory mem ) %{
  7389   predicate(UseSSE==0 && !VM_Version::supports_3dnow_prefetch());
  7390   match(PrefetchWrite mem);
  7391   ins_cost(0);
  7392   size(0);
  7393   format %{ "Prefetch (non-SSE is empty encoding)" %}
  7394   ins_encode();
  7395   ins_pipe(empty);
  7396 %}
  7398 instruct prefetchw( memory mem ) %{
  7399   predicate(UseSSE==0 && VM_Version::supports_3dnow_prefetch() || AllocatePrefetchInstr==3);
  7400   match( PrefetchWrite mem );
  7401   ins_cost(100);
  7403   format %{ "PREFETCHW $mem\t! Prefetch into L1 cache and mark modified" %}
  7404   opcode(0x0F, 0x0D);     /* Opcode 0F 0D /1 */
  7405   ins_encode(OpcP, OpcS, RMopc_Mem(0x01,mem));
  7406   ins_pipe(ialu_mem);
  7407 %}
  7409 instruct prefetchwNTA( memory mem ) %{
  7410   predicate(UseSSE>=1 && AllocatePrefetchInstr==0);
  7411   match(PrefetchWrite mem);
  7412   ins_cost(100);
  7414   format %{ "PREFETCHNTA $mem\t! Prefetch into non-temporal cache for write" %}
  7415   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
  7416   ins_encode(OpcP, OpcS, RMopc_Mem(0x00,mem));
  7417   ins_pipe(ialu_mem);
  7418 %}
  7420 instruct prefetchwT0( memory mem ) %{
  7421   predicate(UseSSE>=1 && AllocatePrefetchInstr==1);
  7422   match(PrefetchWrite mem);
  7423   ins_cost(100);
  7425   format %{ "PREFETCHT0 $mem\t! Prefetch into L1 and L2 caches for write" %}
  7426   opcode(0x0F, 0x18);     /* Opcode 0F 18 /1 */
  7427   ins_encode(OpcP, OpcS, RMopc_Mem(0x01,mem));
  7428   ins_pipe(ialu_mem);
  7429 %}
  7431 instruct prefetchwT2( memory mem ) %{
  7432   predicate(UseSSE>=1 && AllocatePrefetchInstr==2);
  7433   match(PrefetchWrite mem);
  7434   ins_cost(100);
  7436   format %{ "PREFETCHT2 $mem\t! Prefetch into L2 cache for write" %}
  7437   opcode(0x0F, 0x18);     /* Opcode 0F 18 /3 */
  7438   ins_encode(OpcP, OpcS, RMopc_Mem(0x03,mem));
  7439   ins_pipe(ialu_mem);
  7440 %}
  7442 //----------Store Instructions-------------------------------------------------
  7444 // Store Byte
  7445 instruct storeB(memory mem, xRegI src) %{
  7446   match(Set mem (StoreB mem src));
  7448   ins_cost(125);
  7449   format %{ "MOV8   $mem,$src" %}
  7450   opcode(0x88);
  7451   ins_encode( OpcP, RegMem( src, mem ) );
  7452   ins_pipe( ialu_mem_reg );
  7453 %}
  7455 // Store Char/Short
  7456 instruct storeC(memory mem, eRegI src) %{
  7457   match(Set mem (StoreC mem src));
  7459   ins_cost(125);
  7460   format %{ "MOV16  $mem,$src" %}
  7461   opcode(0x89, 0x66);
  7462   ins_encode( OpcS, OpcP, RegMem( src, mem ) );
  7463   ins_pipe( ialu_mem_reg );
  7464 %}
  7466 // Store Integer
  7467 instruct storeI(memory mem, eRegI src) %{
  7468   match(Set mem (StoreI mem src));
  7470   ins_cost(125);
  7471   format %{ "MOV    $mem,$src" %}
  7472   opcode(0x89);
  7473   ins_encode( OpcP, RegMem( src, mem ) );
  7474   ins_pipe( ialu_mem_reg );
  7475 %}
  7477 // Store Long
  7478 instruct storeL(long_memory mem, eRegL src) %{
  7479   predicate(!((StoreLNode*)n)->require_atomic_access());
  7480   match(Set mem (StoreL mem src));
  7482   ins_cost(200);
  7483   format %{ "MOV    $mem,$src.lo\n\t"
  7484             "MOV    $mem+4,$src.hi" %}
  7485   opcode(0x89, 0x89);
  7486   ins_encode( OpcP, RegMem( src, mem ), OpcS, RegMem_Hi( src, mem ) );
  7487   ins_pipe( ialu_mem_long_reg );
  7488 %}
  7490 // Store Long to Integer
  7491 instruct storeL2I(memory mem, eRegL src) %{
  7492   match(Set mem (StoreI mem (ConvL2I src)));
  7494   format %{ "MOV    $mem,$src.lo\t# long -> int" %}
  7495   ins_encode %{
  7496     __ movl($mem$$Address, $src$$Register);
  7497   %}
  7498   ins_pipe(ialu_mem_reg);
  7499 %}
  7501 // Volatile Store Long.  Must be atomic, so move it into
  7502 // the FP TOS and then do a 64-bit FIST.  Has to probe the
  7503 // target address before the store (for null-ptr checks)
  7504 // so the memory operand is used twice in the encoding.
  7505 instruct storeL_volatile(memory mem, stackSlotL src, eFlagsReg cr ) %{
  7506   predicate(UseSSE<=1 && ((StoreLNode*)n)->require_atomic_access());
  7507   match(Set mem (StoreL mem src));
  7508   effect( KILL cr );
  7509   ins_cost(400);
  7510   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  7511             "FILD   $src\n\t"
  7512             "FISTp  $mem\t # 64-bit atomic volatile long store" %}
  7513   opcode(0x3B);
  7514   ins_encode( OpcP, RegMem( EAX, mem ), enc_storeL_volatile(mem,src));
  7515   ins_pipe( fpu_reg_mem );
  7516 %}
  7518 instruct storeLX_volatile(memory mem, stackSlotL src, regXD tmp, eFlagsReg cr) %{
  7519   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
  7520   match(Set mem (StoreL mem src));
  7521   effect( TEMP tmp, KILL cr );
  7522   ins_cost(380);
  7523   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  7524             "MOVSD  $tmp,$src\n\t"
  7525             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
  7526   opcode(0x3B);
  7527   ins_encode( OpcP, RegMem( EAX, mem ), enc_storeLX_volatile(mem, src, tmp));
  7528   ins_pipe( pipe_slow );
  7529 %}
  7531 instruct storeLX_reg_volatile(memory mem, eRegL src, regXD tmp2, regXD tmp, eFlagsReg cr) %{
  7532   predicate(UseSSE>=2 && ((StoreLNode*)n)->require_atomic_access());
  7533   match(Set mem (StoreL mem src));
  7534   effect( TEMP tmp2 , TEMP tmp, KILL cr );
  7535   ins_cost(360);
  7536   format %{ "CMP    $mem,EAX\t# Probe address for implicit null check\n\t"
  7537             "MOVD   $tmp,$src.lo\n\t"
  7538             "MOVD   $tmp2,$src.hi\n\t"
  7539             "PUNPCKLDQ $tmp,$tmp2\n\t"
  7540             "MOVSD  $mem,$tmp\t # 64-bit atomic volatile long store" %}
  7541   opcode(0x3B);
  7542   ins_encode( OpcP, RegMem( EAX, mem ), enc_storeLX_reg_volatile(mem, src, tmp, tmp2));
  7543   ins_pipe( pipe_slow );
  7544 %}
  7546 // Store Pointer; for storing unknown oops and raw pointers
  7547 instruct storeP(memory mem, anyRegP src) %{
  7548   match(Set mem (StoreP mem src));
  7550   ins_cost(125);
  7551   format %{ "MOV    $mem,$src" %}
  7552   opcode(0x89);
  7553   ins_encode( OpcP, RegMem( src, mem ) );
  7554   ins_pipe( ialu_mem_reg );
  7555 %}
  7557 // Store Integer Immediate
  7558 instruct storeImmI(memory mem, immI src) %{
  7559   match(Set mem (StoreI mem src));
  7561   ins_cost(150);
  7562   format %{ "MOV    $mem,$src" %}
  7563   opcode(0xC7);               /* C7 /0 */
  7564   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
  7565   ins_pipe( ialu_mem_imm );
  7566 %}
  7568 // Store Short/Char Immediate
  7569 instruct storeImmI16(memory mem, immI16 src) %{
  7570   predicate(UseStoreImmI16);
  7571   match(Set mem (StoreC mem src));
  7573   ins_cost(150);
  7574   format %{ "MOV16  $mem,$src" %}
  7575   opcode(0xC7);     /* C7 /0 Same as 32 store immediate with prefix */
  7576   ins_encode( SizePrefix, OpcP, RMopc_Mem(0x00,mem),  Con16( src ));
  7577   ins_pipe( ialu_mem_imm );
  7578 %}
  7580 // Store Pointer Immediate; null pointers or constant oops that do not
  7581 // need card-mark barriers.
  7582 instruct storeImmP(memory mem, immP src) %{
  7583   match(Set mem (StoreP mem src));
  7585   ins_cost(150);
  7586   format %{ "MOV    $mem,$src" %}
  7587   opcode(0xC7);               /* C7 /0 */
  7588   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32( src ));
  7589   ins_pipe( ialu_mem_imm );
  7590 %}
  7592 // Store Byte Immediate
  7593 instruct storeImmB(memory mem, immI8 src) %{
  7594   match(Set mem (StoreB mem src));
  7596   ins_cost(150);
  7597   format %{ "MOV8   $mem,$src" %}
  7598   opcode(0xC6);               /* C6 /0 */
  7599   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
  7600   ins_pipe( ialu_mem_imm );
  7601 %}
  7603 // Store Aligned Packed Byte XMM register to memory
  7604 instruct storeA8B(memory mem, regXD src) %{
  7605   predicate(UseSSE>=1);
  7606   match(Set mem (Store8B mem src));
  7607   ins_cost(145);
  7608   format %{ "MOVQ  $mem,$src\t! packed8B" %}
  7609   ins_encode( movq_st(mem, src));
  7610   ins_pipe( pipe_slow );
  7611 %}
  7613 // Store Aligned Packed Char/Short XMM register to memory
  7614 instruct storeA4C(memory mem, regXD src) %{
  7615   predicate(UseSSE>=1);
  7616   match(Set mem (Store4C mem src));
  7617   ins_cost(145);
  7618   format %{ "MOVQ  $mem,$src\t! packed4C" %}
  7619   ins_encode( movq_st(mem, src));
  7620   ins_pipe( pipe_slow );
  7621 %}
  7623 // Store Aligned Packed Integer XMM register to memory
  7624 instruct storeA2I(memory mem, regXD src) %{
  7625   predicate(UseSSE>=1);
  7626   match(Set mem (Store2I mem src));
  7627   ins_cost(145);
  7628   format %{ "MOVQ  $mem,$src\t! packed2I" %}
  7629   ins_encode( movq_st(mem, src));
  7630   ins_pipe( pipe_slow );
  7631 %}
  7633 // Store CMS card-mark Immediate
  7634 instruct storeImmCM(memory mem, immI8 src) %{
  7635   match(Set mem (StoreCM mem src));
  7637   ins_cost(150);
  7638   format %{ "MOV8   $mem,$src\t! CMS card-mark imm0" %}
  7639   opcode(0xC6);               /* C6 /0 */
  7640   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con8or32( src ));
  7641   ins_pipe( ialu_mem_imm );
  7642 %}
  7644 // Store Double
  7645 instruct storeD( memory mem, regDPR1 src) %{
  7646   predicate(UseSSE<=1);
  7647   match(Set mem (StoreD mem src));
  7649   ins_cost(100);
  7650   format %{ "FST_D  $mem,$src" %}
  7651   opcode(0xDD);       /* DD /2 */
  7652   ins_encode( enc_FP_store(mem,src) );
  7653   ins_pipe( fpu_mem_reg );
  7654 %}
  7656 // Store double does rounding on x86
  7657 instruct storeD_rounded( memory mem, regDPR1 src) %{
  7658   predicate(UseSSE<=1);
  7659   match(Set mem (StoreD mem (RoundDouble src)));
  7661   ins_cost(100);
  7662   format %{ "FST_D  $mem,$src\t# round" %}
  7663   opcode(0xDD);       /* DD /2 */
  7664   ins_encode( enc_FP_store(mem,src) );
  7665   ins_pipe( fpu_mem_reg );
  7666 %}
  7668 // Store XMM register to memory (double-precision floating points)
  7669 // MOVSD instruction
  7670 instruct storeXD(memory mem, regXD src) %{
  7671   predicate(UseSSE>=2);
  7672   match(Set mem (StoreD mem src));
  7673   ins_cost(95);
  7674   format %{ "MOVSD  $mem,$src" %}
  7675   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x11), RegMem(src, mem));
  7676   ins_pipe( pipe_slow );
  7677 %}
  7679 // Store XMM register to memory (single-precision floating point)
  7680 // MOVSS instruction
  7681 instruct storeX(memory mem, regX src) %{
  7682   predicate(UseSSE>=1);
  7683   match(Set mem (StoreF mem src));
  7684   ins_cost(95);
  7685   format %{ "MOVSS  $mem,$src" %}
  7686   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x11), RegMem(src, mem));
  7687   ins_pipe( pipe_slow );
  7688 %}
  7690 // Store Aligned Packed Single Float XMM register to memory
  7691 instruct storeA2F(memory mem, regXD src) %{
  7692   predicate(UseSSE>=1);
  7693   match(Set mem (Store2F mem src));
  7694   ins_cost(145);
  7695   format %{ "MOVQ  $mem,$src\t! packed2F" %}
  7696   ins_encode( movq_st(mem, src));
  7697   ins_pipe( pipe_slow );
  7698 %}
  7700 // Store Float
  7701 instruct storeF( memory mem, regFPR1 src) %{
  7702   predicate(UseSSE==0);
  7703   match(Set mem (StoreF mem src));
  7705   ins_cost(100);
  7706   format %{ "FST_S  $mem,$src" %}
  7707   opcode(0xD9);       /* D9 /2 */
  7708   ins_encode( enc_FP_store(mem,src) );
  7709   ins_pipe( fpu_mem_reg );
  7710 %}
  7712 // Store Float does rounding on x86
  7713 instruct storeF_rounded( memory mem, regFPR1 src) %{
  7714   predicate(UseSSE==0);
  7715   match(Set mem (StoreF mem (RoundFloat src)));
  7717   ins_cost(100);
  7718   format %{ "FST_S  $mem,$src\t# round" %}
  7719   opcode(0xD9);       /* D9 /2 */
  7720   ins_encode( enc_FP_store(mem,src) );
  7721   ins_pipe( fpu_mem_reg );
  7722 %}
  7724 // Store Float does rounding on x86
  7725 instruct storeF_Drounded( memory mem, regDPR1 src) %{
  7726   predicate(UseSSE<=1);
  7727   match(Set mem (StoreF mem (ConvD2F src)));
  7729   ins_cost(100);
  7730   format %{ "FST_S  $mem,$src\t# D-round" %}
  7731   opcode(0xD9);       /* D9 /2 */
  7732   ins_encode( enc_FP_store(mem,src) );
  7733   ins_pipe( fpu_mem_reg );
  7734 %}
  7736 // Store immediate Float value (it is faster than store from FPU register)
  7737 // The instruction usage is guarded by predicate in operand immF().
  7738 instruct storeF_imm( memory mem, immF src) %{
  7739   match(Set mem (StoreF mem src));
  7741   ins_cost(50);
  7742   format %{ "MOV    $mem,$src\t# store float" %}
  7743   opcode(0xC7);               /* C7 /0 */
  7744   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32F_as_bits( src ));
  7745   ins_pipe( ialu_mem_imm );
  7746 %}
  7748 // Store immediate Float value (it is faster than store from XMM register)
  7749 // The instruction usage is guarded by predicate in operand immXF().
  7750 instruct storeX_imm( memory mem, immXF src) %{
  7751   match(Set mem (StoreF mem src));
  7753   ins_cost(50);
  7754   format %{ "MOV    $mem,$src\t# store float" %}
  7755   opcode(0xC7);               /* C7 /0 */
  7756   ins_encode( OpcP, RMopc_Mem(0x00,mem),  Con32XF_as_bits( src ));
  7757   ins_pipe( ialu_mem_imm );
  7758 %}
  7760 // Store Integer to stack slot
  7761 instruct storeSSI(stackSlotI dst, eRegI src) %{
  7762   match(Set dst src);
  7764   ins_cost(100);
  7765   format %{ "MOV    $dst,$src" %}
  7766   opcode(0x89);
  7767   ins_encode( OpcPRegSS( dst, src ) );
  7768   ins_pipe( ialu_mem_reg );
  7769 %}
  7771 // Store Integer to stack slot
  7772 instruct storeSSP(stackSlotP dst, eRegP src) %{
  7773   match(Set dst src);
  7775   ins_cost(100);
  7776   format %{ "MOV    $dst,$src" %}
  7777   opcode(0x89);
  7778   ins_encode( OpcPRegSS( dst, src ) );
  7779   ins_pipe( ialu_mem_reg );
  7780 %}
  7782 // Store Long to stack slot
  7783 instruct storeSSL(stackSlotL dst, eRegL src) %{
  7784   match(Set dst src);
  7786   ins_cost(200);
  7787   format %{ "MOV    $dst,$src.lo\n\t"
  7788             "MOV    $dst+4,$src.hi" %}
  7789   opcode(0x89, 0x89);
  7790   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
  7791   ins_pipe( ialu_mem_long_reg );
  7792 %}
  7794 //----------MemBar Instructions-----------------------------------------------
  7795 // Memory barrier flavors
  7797 instruct membar_acquire() %{
  7798   match(MemBarAcquire);
  7799   ins_cost(400);
  7801   size(0);
  7802   format %{ "MEMBAR-acquire ! (empty encoding)" %}
  7803   ins_encode();
  7804   ins_pipe(empty);
  7805 %}
  7807 instruct membar_acquire_lock() %{
  7808   match(MemBarAcquireLock);
  7809   ins_cost(0);
  7811   size(0);
  7812   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
  7813   ins_encode( );
  7814   ins_pipe(empty);
  7815 %}
  7817 instruct membar_release() %{
  7818   match(MemBarRelease);
  7819   ins_cost(400);
  7821   size(0);
  7822   format %{ "MEMBAR-release ! (empty encoding)" %}
  7823   ins_encode( );
  7824   ins_pipe(empty);
  7825 %}
  7827 instruct membar_release_lock() %{
  7828   match(MemBarReleaseLock);
  7829   ins_cost(0);
  7831   size(0);
  7832   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
  7833   ins_encode( );
  7834   ins_pipe(empty);
  7835 %}
  7837 instruct membar_volatile(eFlagsReg cr) %{
  7838   match(MemBarVolatile);
  7839   effect(KILL cr);
  7840   ins_cost(400);
  7842   format %{ 
  7843     $$template
  7844     if (os::is_MP()) {
  7845       $$emit$$"LOCK ADDL [ESP + #0], 0\t! membar_volatile"
  7846     } else {
  7847       $$emit$$"MEMBAR-volatile ! (empty encoding)"
  7849   %}
  7850   ins_encode %{
  7851     __ membar(Assembler::StoreLoad);
  7852   %}
  7853   ins_pipe(pipe_slow);
  7854 %}
  7856 instruct unnecessary_membar_volatile() %{
  7857   match(MemBarVolatile);
  7858   predicate(Matcher::post_store_load_barrier(n));
  7859   ins_cost(0);
  7861   size(0);
  7862   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
  7863   ins_encode( );
  7864   ins_pipe(empty);
  7865 %}
  7867 //----------Move Instructions--------------------------------------------------
  7868 instruct castX2P(eAXRegP dst, eAXRegI src) %{
  7869   match(Set dst (CastX2P src));
  7870   format %{ "# X2P  $dst, $src" %}
  7871   ins_encode( /*empty encoding*/ );
  7872   ins_cost(0);
  7873   ins_pipe(empty);
  7874 %}
  7876 instruct castP2X(eRegI dst, eRegP src ) %{
  7877   match(Set dst (CastP2X src));
  7878   ins_cost(50);
  7879   format %{ "MOV    $dst, $src\t# CastP2X" %}
  7880   ins_encode( enc_Copy( dst, src) );
  7881   ins_pipe( ialu_reg_reg );
  7882 %}
  7884 //----------Conditional Move---------------------------------------------------
  7885 // Conditional move
  7886 instruct cmovI_reg(eRegI dst, eRegI src, eFlagsReg cr, cmpOp cop ) %{
  7887   predicate(VM_Version::supports_cmov() );
  7888   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7889   ins_cost(200);
  7890   format %{ "CMOV$cop $dst,$src" %}
  7891   opcode(0x0F,0x40);
  7892   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7893   ins_pipe( pipe_cmov_reg );
  7894 %}
  7896 instruct cmovI_regU( cmpOpU cop, eFlagsRegU cr, eRegI dst, eRegI src ) %{
  7897   predicate(VM_Version::supports_cmov() );
  7898   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7899   ins_cost(200);
  7900   format %{ "CMOV$cop $dst,$src" %}
  7901   opcode(0x0F,0x40);
  7902   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7903   ins_pipe( pipe_cmov_reg );
  7904 %}
  7906 instruct cmovI_regUCF( cmpOpUCF cop, eFlagsRegUCF cr, eRegI dst, eRegI src ) %{
  7907   predicate(VM_Version::supports_cmov() );
  7908   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7909   ins_cost(200);
  7910   expand %{
  7911     cmovI_regU(cop, cr, dst, src);
  7912   %}
  7913 %}
  7915 // Conditional move
  7916 instruct cmovI_mem(cmpOp cop, eFlagsReg cr, eRegI dst, memory src) %{
  7917   predicate(VM_Version::supports_cmov() );
  7918   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7919   ins_cost(250);
  7920   format %{ "CMOV$cop $dst,$src" %}
  7921   opcode(0x0F,0x40);
  7922   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7923   ins_pipe( pipe_cmov_mem );
  7924 %}
  7926 // Conditional move
  7927 instruct cmovI_memU(cmpOpU cop, eFlagsRegU cr, eRegI dst, memory src) %{
  7928   predicate(VM_Version::supports_cmov() );
  7929   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7930   ins_cost(250);
  7931   format %{ "CMOV$cop $dst,$src" %}
  7932   opcode(0x0F,0x40);
  7933   ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  7934   ins_pipe( pipe_cmov_mem );
  7935 %}
  7937 instruct cmovI_memUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegI dst, memory src) %{
  7938   predicate(VM_Version::supports_cmov() );
  7939   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7940   ins_cost(250);
  7941   expand %{
  7942     cmovI_memU(cop, cr, dst, src);
  7943   %}
  7944 %}
  7946 // Conditional move
  7947 instruct cmovP_reg(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
  7948   predicate(VM_Version::supports_cmov() );
  7949   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7950   ins_cost(200);
  7951   format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7952   opcode(0x0F,0x40);
  7953   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7954   ins_pipe( pipe_cmov_reg );
  7955 %}
  7957 // Conditional move (non-P6 version)
  7958 // Note:  a CMoveP is generated for  stubs and native wrappers
  7959 //        regardless of whether we are on a P6, so we
  7960 //        emulate a cmov here
  7961 instruct cmovP_reg_nonP6(eRegP dst, eRegP src, eFlagsReg cr, cmpOp cop ) %{
  7962   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7963   ins_cost(300);
  7964   format %{ "Jn$cop   skip\n\t"
  7965           "MOV    $dst,$src\t# pointer\n"
  7966       "skip:" %}
  7967   opcode(0x8b);
  7968   ins_encode( enc_cmov_branch(cop, 0x2), OpcP, RegReg(dst, src));
  7969   ins_pipe( pipe_cmov_reg );
  7970 %}
  7972 // Conditional move
  7973 instruct cmovP_regU(cmpOpU cop, eFlagsRegU cr, eRegP dst, eRegP src ) %{
  7974   predicate(VM_Version::supports_cmov() );
  7975   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7976   ins_cost(200);
  7977   format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7978   opcode(0x0F,0x40);
  7979   ins_encode( enc_cmov(cop), RegReg( dst, src ) );
  7980   ins_pipe( pipe_cmov_reg );
  7981 %}
  7983 instruct cmovP_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegP dst, eRegP src ) %{
  7984   predicate(VM_Version::supports_cmov() );
  7985   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7986   ins_cost(200);
  7987   expand %{
  7988     cmovP_regU(cop, cr, dst, src);
  7989   %}
  7990 %}
  7992 // DISABLED: Requires the ADLC to emit a bottom_type call that
  7993 // correctly meets the two pointer arguments; one is an incoming
  7994 // register but the other is a memory operand.  ALSO appears to
  7995 // be buggy with implicit null checks.
  7996 //
  7997 //// Conditional move
  7998 //instruct cmovP_mem(cmpOp cop, eFlagsReg cr, eRegP dst, memory src) %{
  7999 //  predicate(VM_Version::supports_cmov() );
  8000 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  8001 //  ins_cost(250);
  8002 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  8003 //  opcode(0x0F,0x40);
  8004 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  8005 //  ins_pipe( pipe_cmov_mem );
  8006 //%}
  8007 //
  8008 //// Conditional move
  8009 //instruct cmovP_memU(cmpOpU cop, eFlagsRegU cr, eRegP dst, memory src) %{
  8010 //  predicate(VM_Version::supports_cmov() );
  8011 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  8012 //  ins_cost(250);
  8013 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  8014 //  opcode(0x0F,0x40);
  8015 //  ins_encode( enc_cmov(cop), RegMem( dst, src ) );
  8016 //  ins_pipe( pipe_cmov_mem );
  8017 //%}
  8019 // Conditional move
  8020 instruct fcmovD_regU(cmpOp_fcmov cop, eFlagsRegU cr, regDPR1 dst, regD src) %{
  8021   predicate(UseSSE<=1);
  8022   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  8023   ins_cost(200);
  8024   format %{ "FCMOV$cop $dst,$src\t# double" %}
  8025   opcode(0xDA);
  8026   ins_encode( enc_cmov_d(cop,src) );
  8027   ins_pipe( pipe_cmovD_reg );
  8028 %}
  8030 // Conditional move
  8031 instruct fcmovF_regU(cmpOp_fcmov cop, eFlagsRegU cr, regFPR1 dst, regF src) %{
  8032   predicate(UseSSE==0);
  8033   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  8034   ins_cost(200);
  8035   format %{ "FCMOV$cop $dst,$src\t# float" %}
  8036   opcode(0xDA);
  8037   ins_encode( enc_cmov_d(cop,src) );
  8038   ins_pipe( pipe_cmovD_reg );
  8039 %}
  8041 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
  8042 instruct fcmovD_regS(cmpOp cop, eFlagsReg cr, regD dst, regD src) %{
  8043   predicate(UseSSE<=1);
  8044   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  8045   ins_cost(200);
  8046   format %{ "Jn$cop   skip\n\t"
  8047             "MOV    $dst,$src\t# double\n"
  8048       "skip:" %}
  8049   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
  8050   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_D(src), OpcP, RegOpc(dst) );
  8051   ins_pipe( pipe_cmovD_reg );
  8052 %}
  8054 // Float CMOV on Intel doesn't handle *signed* compares, only unsigned.
  8055 instruct fcmovF_regS(cmpOp cop, eFlagsReg cr, regF dst, regF src) %{
  8056   predicate(UseSSE==0);
  8057   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  8058   ins_cost(200);
  8059   format %{ "Jn$cop    skip\n\t"
  8060             "MOV    $dst,$src\t# float\n"
  8061       "skip:" %}
  8062   opcode (0xdd, 0x3);     /* DD D8+i or DD /3 */
  8063   ins_encode( enc_cmov_branch( cop, 0x4 ), Push_Reg_F(src), OpcP, RegOpc(dst) );
  8064   ins_pipe( pipe_cmovD_reg );
  8065 %}
  8067 // No CMOVE with SSE/SSE2
  8068 instruct fcmovX_regS(cmpOp cop, eFlagsReg cr, regX dst, regX src) %{
  8069   predicate (UseSSE>=1);
  8070   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  8071   ins_cost(200);
  8072   format %{ "Jn$cop   skip\n\t"
  8073             "MOVSS  $dst,$src\t# float\n"
  8074       "skip:" %}
  8075   ins_encode %{
  8076     Label skip;
  8077     // Invert sense of branch from sense of CMOV
  8078     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  8079     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
  8080     __ bind(skip);
  8081   %}
  8082   ins_pipe( pipe_slow );
  8083 %}
  8085 // No CMOVE with SSE/SSE2
  8086 instruct fcmovXD_regS(cmpOp cop, eFlagsReg cr, regXD dst, regXD src) %{
  8087   predicate (UseSSE>=2);
  8088   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  8089   ins_cost(200);
  8090   format %{ "Jn$cop   skip\n\t"
  8091             "MOVSD  $dst,$src\t# float\n"
  8092       "skip:" %}
  8093   ins_encode %{
  8094     Label skip;
  8095     // Invert sense of branch from sense of CMOV
  8096     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  8097     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
  8098     __ bind(skip);
  8099   %}
  8100   ins_pipe( pipe_slow );
  8101 %}
  8103 // unsigned version
  8104 instruct fcmovX_regU(cmpOpU cop, eFlagsRegU cr, regX dst, regX src) %{
  8105   predicate (UseSSE>=1);
  8106   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  8107   ins_cost(200);
  8108   format %{ "Jn$cop   skip\n\t"
  8109             "MOVSS  $dst,$src\t# float\n"
  8110       "skip:" %}
  8111   ins_encode %{
  8112     Label skip;
  8113     // Invert sense of branch from sense of CMOV
  8114     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  8115     __ movflt($dst$$XMMRegister, $src$$XMMRegister);
  8116     __ bind(skip);
  8117   %}
  8118   ins_pipe( pipe_slow );
  8119 %}
  8121 instruct fcmovX_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regX dst, regX src) %{
  8122   predicate (UseSSE>=1);
  8123   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  8124   ins_cost(200);
  8125   expand %{
  8126     fcmovX_regU(cop, cr, dst, src);
  8127   %}
  8128 %}
  8130 // unsigned version
  8131 instruct fcmovXD_regU(cmpOpU cop, eFlagsRegU cr, regXD dst, regXD src) %{
  8132   predicate (UseSSE>=2);
  8133   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  8134   ins_cost(200);
  8135   format %{ "Jn$cop   skip\n\t"
  8136             "MOVSD  $dst,$src\t# float\n"
  8137       "skip:" %}
  8138   ins_encode %{
  8139     Label skip;
  8140     // Invert sense of branch from sense of CMOV
  8141     __ jccb((Assembler::Condition)($cop$$cmpcode^1), skip);
  8142     __ movdbl($dst$$XMMRegister, $src$$XMMRegister);
  8143     __ bind(skip);
  8144   %}
  8145   ins_pipe( pipe_slow );
  8146 %}
  8148 instruct fcmovXD_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, regXD dst, regXD src) %{
  8149   predicate (UseSSE>=2);
  8150   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  8151   ins_cost(200);
  8152   expand %{
  8153     fcmovXD_regU(cop, cr, dst, src);
  8154   %}
  8155 %}
  8157 instruct cmovL_reg(cmpOp cop, eFlagsReg cr, eRegL dst, eRegL src) %{
  8158   predicate(VM_Version::supports_cmov() );
  8159   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  8160   ins_cost(200);
  8161   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
  8162             "CMOV$cop $dst.hi,$src.hi" %}
  8163   opcode(0x0F,0x40);
  8164   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
  8165   ins_pipe( pipe_cmov_reg_long );
  8166 %}
  8168 instruct cmovL_regU(cmpOpU cop, eFlagsRegU cr, eRegL dst, eRegL src) %{
  8169   predicate(VM_Version::supports_cmov() );
  8170   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  8171   ins_cost(200);
  8172   format %{ "CMOV$cop $dst.lo,$src.lo\n\t"
  8173             "CMOV$cop $dst.hi,$src.hi" %}
  8174   opcode(0x0F,0x40);
  8175   ins_encode( enc_cmov(cop), RegReg_Lo2( dst, src ), enc_cmov(cop), RegReg_Hi2( dst, src ) );
  8176   ins_pipe( pipe_cmov_reg_long );
  8177 %}
  8179 instruct cmovL_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegL dst, eRegL src) %{
  8180   predicate(VM_Version::supports_cmov() );
  8181   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  8182   ins_cost(200);
  8183   expand %{
  8184     cmovL_regU(cop, cr, dst, src);
  8185   %}
  8186 %}
  8188 //----------Arithmetic Instructions--------------------------------------------
  8189 //----------Addition Instructions----------------------------------------------
  8190 // Integer Addition Instructions
  8191 instruct addI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  8192   match(Set dst (AddI dst src));
  8193   effect(KILL cr);
  8195   size(2);
  8196   format %{ "ADD    $dst,$src" %}
  8197   opcode(0x03);
  8198   ins_encode( OpcP, RegReg( dst, src) );
  8199   ins_pipe( ialu_reg_reg );
  8200 %}
  8202 instruct addI_eReg_imm(eRegI dst, immI src, eFlagsReg cr) %{
  8203   match(Set dst (AddI dst src));
  8204   effect(KILL cr);
  8206   format %{ "ADD    $dst,$src" %}
  8207   opcode(0x81, 0x00); /* /0 id */
  8208   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8209   ins_pipe( ialu_reg );
  8210 %}
  8212 instruct incI_eReg(eRegI dst, immI1 src, eFlagsReg cr) %{
  8213   predicate(UseIncDec);
  8214   match(Set dst (AddI dst src));
  8215   effect(KILL cr);
  8217   size(1);
  8218   format %{ "INC    $dst" %}
  8219   opcode(0x40); /*  */
  8220   ins_encode( Opc_plus( primary, dst ) );
  8221   ins_pipe( ialu_reg );
  8222 %}
  8224 instruct leaI_eReg_immI(eRegI dst, eRegI src0, immI src1) %{
  8225   match(Set dst (AddI src0 src1));
  8226   ins_cost(110);
  8228   format %{ "LEA    $dst,[$src0 + $src1]" %}
  8229   opcode(0x8D); /* 0x8D /r */
  8230   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
  8231   ins_pipe( ialu_reg_reg );
  8232 %}
  8234 instruct leaP_eReg_immI(eRegP dst, eRegP src0, immI src1) %{
  8235   match(Set dst (AddP src0 src1));
  8236   ins_cost(110);
  8238   format %{ "LEA    $dst,[$src0 + $src1]\t# ptr" %}
  8239   opcode(0x8D); /* 0x8D /r */
  8240   ins_encode( OpcP, RegLea( dst, src0, src1 ) );
  8241   ins_pipe( ialu_reg_reg );
  8242 %}
  8244 instruct decI_eReg(eRegI dst, immI_M1 src, eFlagsReg cr) %{
  8245   predicate(UseIncDec);
  8246   match(Set dst (AddI dst src));
  8247   effect(KILL cr);
  8249   size(1);
  8250   format %{ "DEC    $dst" %}
  8251   opcode(0x48); /*  */
  8252   ins_encode( Opc_plus( primary, dst ) );
  8253   ins_pipe( ialu_reg );
  8254 %}
  8256 instruct addP_eReg(eRegP dst, eRegI src, eFlagsReg cr) %{
  8257   match(Set dst (AddP dst src));
  8258   effect(KILL cr);
  8260   size(2);
  8261   format %{ "ADD    $dst,$src" %}
  8262   opcode(0x03);
  8263   ins_encode( OpcP, RegReg( dst, src) );
  8264   ins_pipe( ialu_reg_reg );
  8265 %}
  8267 instruct addP_eReg_imm(eRegP dst, immI src, eFlagsReg cr) %{
  8268   match(Set dst (AddP dst src));
  8269   effect(KILL cr);
  8271   format %{ "ADD    $dst,$src" %}
  8272   opcode(0x81,0x00); /* Opcode 81 /0 id */
  8273   // ins_encode( RegImm( dst, src) );
  8274   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8275   ins_pipe( ialu_reg );
  8276 %}
  8278 instruct addI_eReg_mem(eRegI dst, memory src, eFlagsReg cr) %{
  8279   match(Set dst (AddI dst (LoadI src)));
  8280   effect(KILL cr);
  8282   ins_cost(125);
  8283   format %{ "ADD    $dst,$src" %}
  8284   opcode(0x03);
  8285   ins_encode( OpcP, RegMem( dst, src) );
  8286   ins_pipe( ialu_reg_mem );
  8287 %}
  8289 instruct addI_mem_eReg(memory dst, eRegI src, eFlagsReg cr) %{
  8290   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  8291   effect(KILL cr);
  8293   ins_cost(150);
  8294   format %{ "ADD    $dst,$src" %}
  8295   opcode(0x01);  /* Opcode 01 /r */
  8296   ins_encode( OpcP, RegMem( src, dst ) );
  8297   ins_pipe( ialu_mem_reg );
  8298 %}
  8300 // Add Memory with Immediate
  8301 instruct addI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  8302   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  8303   effect(KILL cr);
  8305   ins_cost(125);
  8306   format %{ "ADD    $dst,$src" %}
  8307   opcode(0x81);               /* Opcode 81 /0 id */
  8308   ins_encode( OpcSE( src ), RMopc_Mem(0x00,dst), Con8or32( src ) );
  8309   ins_pipe( ialu_mem_imm );
  8310 %}
  8312 instruct incI_mem(memory dst, immI1 src, eFlagsReg cr) %{
  8313   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  8314   effect(KILL cr);
  8316   ins_cost(125);
  8317   format %{ "INC    $dst" %}
  8318   opcode(0xFF);               /* Opcode FF /0 */
  8319   ins_encode( OpcP, RMopc_Mem(0x00,dst));
  8320   ins_pipe( ialu_mem_imm );
  8321 %}
  8323 instruct decI_mem(memory dst, immI_M1 src, eFlagsReg cr) %{
  8324   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  8325   effect(KILL cr);
  8327   ins_cost(125);
  8328   format %{ "DEC    $dst" %}
  8329   opcode(0xFF);               /* Opcode FF /1 */
  8330   ins_encode( OpcP, RMopc_Mem(0x01,dst));
  8331   ins_pipe( ialu_mem_imm );
  8332 %}
  8335 instruct checkCastPP( eRegP dst ) %{
  8336   match(Set dst (CheckCastPP dst));
  8338   size(0);
  8339   format %{ "#checkcastPP of $dst" %}
  8340   ins_encode( /*empty encoding*/ );
  8341   ins_pipe( empty );
  8342 %}
  8344 instruct castPP( eRegP dst ) %{
  8345   match(Set dst (CastPP dst));
  8346   format %{ "#castPP of $dst" %}
  8347   ins_encode( /*empty encoding*/ );
  8348   ins_pipe( empty );
  8349 %}
  8351 instruct castII( eRegI dst ) %{
  8352   match(Set dst (CastII dst));
  8353   format %{ "#castII of $dst" %}
  8354   ins_encode( /*empty encoding*/ );
  8355   ins_cost(0);
  8356   ins_pipe( empty );
  8357 %}
  8360 // Load-locked - same as a regular pointer load when used with compare-swap
  8361 instruct loadPLocked(eRegP dst, memory mem) %{
  8362   match(Set dst (LoadPLocked mem));
  8364   ins_cost(125);
  8365   format %{ "MOV    $dst,$mem\t# Load ptr. locked" %}
  8366   opcode(0x8B);
  8367   ins_encode( OpcP, RegMem(dst,mem));
  8368   ins_pipe( ialu_reg_mem );
  8369 %}
  8371 // LoadLong-locked - same as a volatile long load when used with compare-swap
  8372 instruct loadLLocked(stackSlotL dst, load_long_memory mem) %{
  8373   predicate(UseSSE<=1);
  8374   match(Set dst (LoadLLocked mem));
  8376   ins_cost(200);
  8377   format %{ "FILD   $mem\t# Atomic volatile long load\n\t"
  8378             "FISTp  $dst" %}
  8379   ins_encode(enc_loadL_volatile(mem,dst));
  8380   ins_pipe( fpu_reg_mem );
  8381 %}
  8383 instruct loadLX_Locked(stackSlotL dst, load_long_memory mem, regXD tmp) %{
  8384   predicate(UseSSE>=2);
  8385   match(Set dst (LoadLLocked mem));
  8386   effect(TEMP tmp);
  8387   ins_cost(180);
  8388   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  8389             "MOVSD  $dst,$tmp" %}
  8390   ins_encode(enc_loadLX_volatile(mem, dst, tmp));
  8391   ins_pipe( pipe_slow );
  8392 %}
  8394 instruct loadLX_reg_Locked(eRegL dst, load_long_memory mem, regXD tmp) %{
  8395   predicate(UseSSE>=2);
  8396   match(Set dst (LoadLLocked mem));
  8397   effect(TEMP tmp);
  8398   ins_cost(160);
  8399   format %{ "MOVSD  $tmp,$mem\t# Atomic volatile long load\n\t"
  8400             "MOVD   $dst.lo,$tmp\n\t"
  8401             "PSRLQ  $tmp,32\n\t"
  8402             "MOVD   $dst.hi,$tmp" %}
  8403   ins_encode(enc_loadLX_reg_volatile(mem, dst, tmp));
  8404   ins_pipe( pipe_slow );
  8405 %}
  8407 // Conditional-store of the updated heap-top.
  8408 // Used during allocation of the shared heap.
  8409 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
  8410 instruct storePConditional( memory heap_top_ptr, eAXRegP oldval, eRegP newval, eFlagsReg cr ) %{
  8411   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
  8412   // EAX is killed if there is contention, but then it's also unused.
  8413   // In the common case of no contention, EAX holds the new oop address.
  8414   format %{ "CMPXCHG $heap_top_ptr,$newval\t# If EAX==$heap_top_ptr Then store $newval into $heap_top_ptr" %}
  8415   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval,heap_top_ptr) );
  8416   ins_pipe( pipe_cmpxchg );
  8417 %}
  8419 // Conditional-store of an int value.
  8420 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG on Intel.
  8421 instruct storeIConditional( memory mem, eAXRegI oldval, eRegI newval, eFlagsReg cr ) %{
  8422   match(Set cr (StoreIConditional mem (Binary oldval newval)));
  8423   effect(KILL oldval);
  8424   format %{ "CMPXCHG $mem,$newval\t# If EAX==$mem Then store $newval into $mem" %}
  8425   ins_encode( lock_prefix, Opcode(0x0F), Opcode(0xB1), RegMem(newval, mem) );
  8426   ins_pipe( pipe_cmpxchg );
  8427 %}
  8429 // Conditional-store of a long value.
  8430 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG8 on Intel.
  8431 instruct storeLConditional( memory mem, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
  8432   match(Set cr (StoreLConditional mem (Binary oldval newval)));
  8433   effect(KILL oldval);
  8434   format %{ "XCHG   EBX,ECX\t# correct order for CMPXCHG8 instruction\n\t"
  8435             "CMPXCHG8 $mem,ECX:EBX\t# If EDX:EAX==$mem Then store ECX:EBX into $mem\n\t"
  8436             "XCHG   EBX,ECX"
  8437   %}
  8438   ins_encode %{
  8439     // Note: we need to swap rbx, and rcx before and after the
  8440     //       cmpxchg8 instruction because the instruction uses
  8441     //       rcx as the high order word of the new value to store but
  8442     //       our register encoding uses rbx.
  8443     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
  8444     if( os::is_MP() )
  8445       __ lock();
  8446     __ cmpxchg8($mem$$Address);
  8447     __ xchgl(as_Register(EBX_enc), as_Register(ECX_enc));
  8448   %}
  8449   ins_pipe( pipe_cmpxchg );
  8450 %}
  8452 // No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
  8454 instruct compareAndSwapL( eRegI res, eSIRegP mem_ptr, eADXRegL oldval, eBCXRegL newval, eFlagsReg cr ) %{
  8455   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
  8456   effect(KILL cr, KILL oldval);
  8457   format %{ "CMPXCHG8 [$mem_ptr],$newval\t# If EDX:EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  8458             "MOV    $res,0\n\t"
  8459             "JNE,s  fail\n\t"
  8460             "MOV    $res,1\n"
  8461           "fail:" %}
  8462   ins_encode( enc_cmpxchg8(mem_ptr),
  8463               enc_flags_ne_to_boolean(res) );
  8464   ins_pipe( pipe_cmpxchg );
  8465 %}
  8467 instruct compareAndSwapP( eRegI res,  pRegP mem_ptr, eAXRegP oldval, eCXRegP newval, eFlagsReg cr) %{
  8468   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
  8469   effect(KILL cr, KILL oldval);
  8470   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  8471             "MOV    $res,0\n\t"
  8472             "JNE,s  fail\n\t"
  8473             "MOV    $res,1\n"
  8474           "fail:" %}
  8475   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
  8476   ins_pipe( pipe_cmpxchg );
  8477 %}
  8479 instruct compareAndSwapI( eRegI res, pRegP mem_ptr, eAXRegI oldval, eCXRegI newval, eFlagsReg cr) %{
  8480   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
  8481   effect(KILL cr, KILL oldval);
  8482   format %{ "CMPXCHG [$mem_ptr],$newval\t# If EAX==[$mem_ptr] Then store $newval into [$mem_ptr]\n\t"
  8483             "MOV    $res,0\n\t"
  8484             "JNE,s  fail\n\t"
  8485             "MOV    $res,1\n"
  8486           "fail:" %}
  8487   ins_encode( enc_cmpxchg(mem_ptr), enc_flags_ne_to_boolean(res) );
  8488   ins_pipe( pipe_cmpxchg );
  8489 %}
  8491 //----------Subtraction Instructions-------------------------------------------
  8492 // Integer Subtraction Instructions
  8493 instruct subI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  8494   match(Set dst (SubI dst src));
  8495   effect(KILL cr);
  8497   size(2);
  8498   format %{ "SUB    $dst,$src" %}
  8499   opcode(0x2B);
  8500   ins_encode( OpcP, RegReg( dst, src) );
  8501   ins_pipe( ialu_reg_reg );
  8502 %}
  8504 instruct subI_eReg_imm(eRegI dst, immI src, eFlagsReg cr) %{
  8505   match(Set dst (SubI dst src));
  8506   effect(KILL cr);
  8508   format %{ "SUB    $dst,$src" %}
  8509   opcode(0x81,0x05);  /* Opcode 81 /5 */
  8510   // ins_encode( RegImm( dst, src) );
  8511   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  8512   ins_pipe( ialu_reg );
  8513 %}
  8515 instruct subI_eReg_mem(eRegI dst, memory src, eFlagsReg cr) %{
  8516   match(Set dst (SubI dst (LoadI src)));
  8517   effect(KILL cr);
  8519   ins_cost(125);
  8520   format %{ "SUB    $dst,$src" %}
  8521   opcode(0x2B);
  8522   ins_encode( OpcP, RegMem( dst, src) );
  8523   ins_pipe( ialu_reg_mem );
  8524 %}
  8526 instruct subI_mem_eReg(memory dst, eRegI src, eFlagsReg cr) %{
  8527   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
  8528   effect(KILL cr);
  8530   ins_cost(150);
  8531   format %{ "SUB    $dst,$src" %}
  8532   opcode(0x29);  /* Opcode 29 /r */
  8533   ins_encode( OpcP, RegMem( src, dst ) );
  8534   ins_pipe( ialu_mem_reg );
  8535 %}
  8537 // Subtract from a pointer
  8538 instruct subP_eReg(eRegP dst, eRegI src, immI0 zero, eFlagsReg cr) %{
  8539   match(Set dst (AddP dst (SubI zero src)));
  8540   effect(KILL cr);
  8542   size(2);
  8543   format %{ "SUB    $dst,$src" %}
  8544   opcode(0x2B);
  8545   ins_encode( OpcP, RegReg( dst, src) );
  8546   ins_pipe( ialu_reg_reg );
  8547 %}
  8549 instruct negI_eReg(eRegI dst, immI0 zero, eFlagsReg cr) %{
  8550   match(Set dst (SubI zero dst));
  8551   effect(KILL cr);
  8553   size(2);
  8554   format %{ "NEG    $dst" %}
  8555   opcode(0xF7,0x03);  // Opcode F7 /3
  8556   ins_encode( OpcP, RegOpc( dst ) );
  8557   ins_pipe( ialu_reg );
  8558 %}
  8561 //----------Multiplication/Division Instructions-------------------------------
  8562 // Integer Multiplication Instructions
  8563 // Multiply Register
  8564 instruct mulI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  8565   match(Set dst (MulI dst src));
  8566   effect(KILL cr);
  8568   size(3);
  8569   ins_cost(300);
  8570   format %{ "IMUL   $dst,$src" %}
  8571   opcode(0xAF, 0x0F);
  8572   ins_encode( OpcS, OpcP, RegReg( dst, src) );
  8573   ins_pipe( ialu_reg_reg_alu0 );
  8574 %}
  8576 // Multiply 32-bit Immediate
  8577 instruct mulI_eReg_imm(eRegI dst, eRegI src, immI imm, eFlagsReg cr) %{
  8578   match(Set dst (MulI src imm));
  8579   effect(KILL cr);
  8581   ins_cost(300);
  8582   format %{ "IMUL   $dst,$src,$imm" %}
  8583   opcode(0x69);  /* 69 /r id */
  8584   ins_encode( OpcSE(imm), RegReg( dst, src ), Con8or32( imm ) );
  8585   ins_pipe( ialu_reg_reg_alu0 );
  8586 %}
  8588 instruct loadConL_low_only(eADXRegL_low_only dst, immL32 src, eFlagsReg cr) %{
  8589   match(Set dst src);
  8590   effect(KILL cr);
  8592   // Note that this is artificially increased to make it more expensive than loadConL
  8593   ins_cost(250);
  8594   format %{ "MOV    EAX,$src\t// low word only" %}
  8595   opcode(0xB8);
  8596   ins_encode( LdImmL_Lo(dst, src) );
  8597   ins_pipe( ialu_reg_fat );
  8598 %}
  8600 // Multiply by 32-bit Immediate, taking the shifted high order results
  8601 //  (special case for shift by 32)
  8602 instruct mulI_imm_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32 cnt, eFlagsReg cr) %{
  8603   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
  8604   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
  8605              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
  8606              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
  8607   effect(USE src1, KILL cr);
  8609   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
  8610   ins_cost(0*100 + 1*400 - 150);
  8611   format %{ "IMUL   EDX:EAX,$src1" %}
  8612   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
  8613   ins_pipe( pipe_slow );
  8614 %}
  8616 // Multiply by 32-bit Immediate, taking the shifted high order results
  8617 instruct mulI_imm_RShift_high(eDXRegI dst, nadxRegI src1, eADXRegL_low_only src2, immI_32_63 cnt, eFlagsReg cr) %{
  8618   match(Set dst (ConvL2I (RShiftL (MulL (ConvI2L src1) src2) cnt)));
  8619   predicate( _kids[0]->_kids[0]->_kids[1]->_leaf->Opcode() == Op_ConL &&
  8620              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() >= min_jint &&
  8621              _kids[0]->_kids[0]->_kids[1]->_leaf->as_Type()->type()->is_long()->get_con() <= max_jint );
  8622   effect(USE src1, KILL cr);
  8624   // Note that this is adjusted by 150 to compensate for the overcosting of loadConL_low_only
  8625   ins_cost(1*100 + 1*400 - 150);
  8626   format %{ "IMUL   EDX:EAX,$src1\n\t"
  8627             "SAR    EDX,$cnt-32" %}
  8628   ins_encode( multiply_con_and_shift_high( dst, src1, src2, cnt, cr ) );
  8629   ins_pipe( pipe_slow );
  8630 %}
  8632 // Multiply Memory 32-bit Immediate
  8633 instruct mulI_mem_imm(eRegI dst, memory src, immI imm, eFlagsReg cr) %{
  8634   match(Set dst (MulI (LoadI src) imm));
  8635   effect(KILL cr);
  8637   ins_cost(300);
  8638   format %{ "IMUL   $dst,$src,$imm" %}
  8639   opcode(0x69);  /* 69 /r id */
  8640   ins_encode( OpcSE(imm), RegMem( dst, src ), Con8or32( imm ) );
  8641   ins_pipe( ialu_reg_mem_alu0 );
  8642 %}
  8644 // Multiply Memory
  8645 instruct mulI(eRegI dst, memory src, eFlagsReg cr) %{
  8646   match(Set dst (MulI dst (LoadI src)));
  8647   effect(KILL cr);
  8649   ins_cost(350);
  8650   format %{ "IMUL   $dst,$src" %}
  8651   opcode(0xAF, 0x0F);
  8652   ins_encode( OpcS, OpcP, RegMem( dst, src) );
  8653   ins_pipe( ialu_reg_mem_alu0 );
  8654 %}
  8656 // Multiply Register Int to Long
  8657 instruct mulI2L(eADXRegL dst, eAXRegI src, nadxRegI src1, eFlagsReg flags) %{
  8658   // Basic Idea: long = (long)int * (long)int
  8659   match(Set dst (MulL (ConvI2L src) (ConvI2L src1)));
  8660   effect(DEF dst, USE src, USE src1, KILL flags);
  8662   ins_cost(300);
  8663   format %{ "IMUL   $dst,$src1" %}
  8665   ins_encode( long_int_multiply( dst, src1 ) );
  8666   ins_pipe( ialu_reg_reg_alu0 );
  8667 %}
  8669 instruct mulIS_eReg(eADXRegL dst, immL_32bits mask, eFlagsReg flags, eAXRegI src, nadxRegI src1) %{
  8670   // Basic Idea:  long = (int & 0xffffffffL) * (int & 0xffffffffL)
  8671   match(Set dst (MulL (AndL (ConvI2L src) mask) (AndL (ConvI2L src1) mask)));
  8672   effect(KILL flags);
  8674   ins_cost(300);
  8675   format %{ "MUL    $dst,$src1" %}
  8677   ins_encode( long_uint_multiply(dst, src1) );
  8678   ins_pipe( ialu_reg_reg_alu0 );
  8679 %}
  8681 // Multiply Register Long
  8682 instruct mulL_eReg(eADXRegL dst, eRegL src, eRegI tmp, eFlagsReg cr) %{
  8683   match(Set dst (MulL dst src));
  8684   effect(KILL cr, TEMP tmp);
  8685   ins_cost(4*100+3*400);
  8686 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8687 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
  8688   format %{ "MOV    $tmp,$src.lo\n\t"
  8689             "IMUL   $tmp,EDX\n\t"
  8690             "MOV    EDX,$src.hi\n\t"
  8691             "IMUL   EDX,EAX\n\t"
  8692             "ADD    $tmp,EDX\n\t"
  8693             "MUL    EDX:EAX,$src.lo\n\t"
  8694             "ADD    EDX,$tmp" %}
  8695   ins_encode( long_multiply( dst, src, tmp ) );
  8696   ins_pipe( pipe_slow );
  8697 %}
  8699 // Multiply Register Long where the left operand's high 32 bits are zero
  8700 instruct mulL_eReg_lhi0(eADXRegL dst, eRegL src, eRegI tmp, eFlagsReg cr) %{
  8701   predicate(is_operand_hi32_zero(n->in(1)));
  8702   match(Set dst (MulL dst src));
  8703   effect(KILL cr, TEMP tmp);
  8704   ins_cost(2*100+2*400);
  8705 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8706 //             hi(result) = hi(x_lo * y_lo) + lo(x_lo * y_hi) where lo(x_hi * y_lo) = 0 because x_hi = 0
  8707   format %{ "MOV    $tmp,$src.hi\n\t"
  8708             "IMUL   $tmp,EAX\n\t"
  8709             "MUL    EDX:EAX,$src.lo\n\t"
  8710             "ADD    EDX,$tmp" %}
  8711   ins_encode %{
  8712     __ movl($tmp$$Register, HIGH_FROM_LOW($src$$Register));
  8713     __ imull($tmp$$Register, rax);
  8714     __ mull($src$$Register);
  8715     __ addl(rdx, $tmp$$Register);
  8716   %}
  8717   ins_pipe( pipe_slow );
  8718 %}
  8720 // Multiply Register Long where the right operand's high 32 bits are zero
  8721 instruct mulL_eReg_rhi0(eADXRegL dst, eRegL src, eRegI tmp, eFlagsReg cr) %{
  8722   predicate(is_operand_hi32_zero(n->in(2)));
  8723   match(Set dst (MulL dst src));
  8724   effect(KILL cr, TEMP tmp);
  8725   ins_cost(2*100+2*400);
  8726 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8727 //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) where lo(x_lo * y_hi) = 0 because y_hi = 0
  8728   format %{ "MOV    $tmp,$src.lo\n\t"
  8729             "IMUL   $tmp,EDX\n\t"
  8730             "MUL    EDX:EAX,$src.lo\n\t"
  8731             "ADD    EDX,$tmp" %}
  8732   ins_encode %{
  8733     __ movl($tmp$$Register, $src$$Register);
  8734     __ imull($tmp$$Register, rdx);
  8735     __ mull($src$$Register);
  8736     __ addl(rdx, $tmp$$Register);
  8737   %}
  8738   ins_pipe( pipe_slow );
  8739 %}
  8741 // Multiply Register Long where the left and the right operands' high 32 bits are zero
  8742 instruct mulL_eReg_hi0(eADXRegL dst, eRegL src, eFlagsReg cr) %{
  8743   predicate(is_operand_hi32_zero(n->in(1)) && is_operand_hi32_zero(n->in(2)));
  8744   match(Set dst (MulL dst src));
  8745   effect(KILL cr);
  8746   ins_cost(1*400);
  8747 // Basic idea: lo(result) = lo(x_lo * y_lo)
  8748 //             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
  8749   format %{ "MUL    EDX:EAX,$src.lo\n\t" %}
  8750   ins_encode %{
  8751     __ mull($src$$Register);
  8752   %}
  8753   ins_pipe( pipe_slow );
  8754 %}
  8756 // Multiply Register Long by small constant
  8757 instruct mulL_eReg_con(eADXRegL dst, immL_127 src, eRegI tmp, eFlagsReg cr) %{
  8758   match(Set dst (MulL dst src));
  8759   effect(KILL cr, TEMP tmp);
  8760   ins_cost(2*100+2*400);
  8761   size(12);
  8762 // Basic idea: lo(result) = lo(src * EAX)
  8763 //             hi(result) = hi(src * EAX) + lo(src * EDX)
  8764   format %{ "IMUL   $tmp,EDX,$src\n\t"
  8765             "MOV    EDX,$src\n\t"
  8766             "MUL    EDX\t# EDX*EAX -> EDX:EAX\n\t"
  8767             "ADD    EDX,$tmp" %}
  8768   ins_encode( long_multiply_con( dst, src, tmp ) );
  8769   ins_pipe( pipe_slow );
  8770 %}
  8772 // Integer DIV with Register
  8773 instruct divI_eReg(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
  8774   match(Set rax (DivI rax div));
  8775   effect(KILL rdx, KILL cr);
  8776   size(26);
  8777   ins_cost(30*100+10*100);
  8778   format %{ "CMP    EAX,0x80000000\n\t"
  8779             "JNE,s  normal\n\t"
  8780             "XOR    EDX,EDX\n\t"
  8781             "CMP    ECX,-1\n\t"
  8782             "JE,s   done\n"
  8783     "normal: CDQ\n\t"
  8784             "IDIV   $div\n\t"
  8785     "done:"        %}
  8786   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8787   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8788   ins_pipe( ialu_reg_reg_alu0 );
  8789 %}
  8791 // Divide Register Long
  8792 instruct divL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
  8793   match(Set dst (DivL src1 src2));
  8794   effect( KILL cr, KILL cx, KILL bx );
  8795   ins_cost(10000);
  8796   format %{ "PUSH   $src1.hi\n\t"
  8797             "PUSH   $src1.lo\n\t"
  8798             "PUSH   $src2.hi\n\t"
  8799             "PUSH   $src2.lo\n\t"
  8800             "CALL   SharedRuntime::ldiv\n\t"
  8801             "ADD    ESP,16" %}
  8802   ins_encode( long_div(src1,src2) );
  8803   ins_pipe( pipe_slow );
  8804 %}
  8806 // Integer DIVMOD with Register, both quotient and mod results
  8807 instruct divModI_eReg_divmod(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
  8808   match(DivModI rax div);
  8809   effect(KILL cr);
  8810   size(26);
  8811   ins_cost(30*100+10*100);
  8812   format %{ "CMP    EAX,0x80000000\n\t"
  8813             "JNE,s  normal\n\t"
  8814             "XOR    EDX,EDX\n\t"
  8815             "CMP    ECX,-1\n\t"
  8816             "JE,s   done\n"
  8817     "normal: CDQ\n\t"
  8818             "IDIV   $div\n\t"
  8819     "done:"        %}
  8820   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8821   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8822   ins_pipe( pipe_slow );
  8823 %}
  8825 // Integer MOD with Register
  8826 instruct modI_eReg(eDXRegI rdx, eAXRegI rax, eCXRegI div, eFlagsReg cr) %{
  8827   match(Set rdx (ModI rax div));
  8828   effect(KILL rax, KILL cr);
  8830   size(26);
  8831   ins_cost(300);
  8832   format %{ "CDQ\n\t"
  8833             "IDIV   $div" %}
  8834   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8835   ins_encode( cdq_enc, OpcP, RegOpc(div) );
  8836   ins_pipe( ialu_reg_reg_alu0 );
  8837 %}
  8839 // Remainder Register Long
  8840 instruct modL_eReg( eADXRegL dst, eRegL src1, eRegL src2, eFlagsReg cr, eCXRegI cx, eBXRegI bx ) %{
  8841   match(Set dst (ModL src1 src2));
  8842   effect( KILL cr, KILL cx, KILL bx );
  8843   ins_cost(10000);
  8844   format %{ "PUSH   $src1.hi\n\t"
  8845             "PUSH   $src1.lo\n\t"
  8846             "PUSH   $src2.hi\n\t"
  8847             "PUSH   $src2.lo\n\t"
  8848             "CALL   SharedRuntime::lrem\n\t"
  8849             "ADD    ESP,16" %}
  8850   ins_encode( long_mod(src1,src2) );
  8851   ins_pipe( pipe_slow );
  8852 %}
  8854 // Divide Register Long (no special case since divisor != -1)
  8855 instruct divL_eReg_imm32( eADXRegL dst, immL32 imm, eRegI tmp, eRegI tmp2, eFlagsReg cr ) %{
  8856   match(Set dst (DivL dst imm));
  8857   effect( TEMP tmp, TEMP tmp2, KILL cr );
  8858   ins_cost(1000);
  8859   format %{ "MOV    $tmp,abs($imm) # ldiv EDX:EAX,$imm\n\t"
  8860             "XOR    $tmp2,$tmp2\n\t"
  8861             "CMP    $tmp,EDX\n\t"
  8862             "JA,s   fast\n\t"
  8863             "MOV    $tmp2,EAX\n\t"
  8864             "MOV    EAX,EDX\n\t"
  8865             "MOV    EDX,0\n\t"
  8866             "JLE,s  pos\n\t"
  8867             "LNEG   EAX : $tmp2\n\t"
  8868             "DIV    $tmp # unsigned division\n\t"
  8869             "XCHG   EAX,$tmp2\n\t"
  8870             "DIV    $tmp\n\t"
  8871             "LNEG   $tmp2 : EAX\n\t"
  8872             "JMP,s  done\n"
  8873     "pos:\n\t"
  8874             "DIV    $tmp\n\t"
  8875             "XCHG   EAX,$tmp2\n"
  8876     "fast:\n\t"
  8877             "DIV    $tmp\n"
  8878     "done:\n\t"
  8879             "MOV    EDX,$tmp2\n\t"
  8880             "NEG    EDX:EAX # if $imm < 0" %}
  8881   ins_encode %{
  8882     int con = (int)$imm$$constant;
  8883     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
  8884     int pcon = (con > 0) ? con : -con;
  8885     Label Lfast, Lpos, Ldone;
  8887     __ movl($tmp$$Register, pcon);
  8888     __ xorl($tmp2$$Register,$tmp2$$Register);
  8889     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
  8890     __ jccb(Assembler::above, Lfast); // result fits into 32 bit
  8892     __ movl($tmp2$$Register, $dst$$Register); // save
  8893     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8894     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
  8895     __ jccb(Assembler::lessEqual, Lpos); // result is positive
  8897     // Negative dividend.
  8898     // convert value to positive to use unsigned division
  8899     __ lneg($dst$$Register, $tmp2$$Register);
  8900     __ divl($tmp$$Register);
  8901     __ xchgl($dst$$Register, $tmp2$$Register);
  8902     __ divl($tmp$$Register);
  8903     // revert result back to negative
  8904     __ lneg($tmp2$$Register, $dst$$Register);
  8905     __ jmpb(Ldone);
  8907     __ bind(Lpos);
  8908     __ divl($tmp$$Register); // Use unsigned division
  8909     __ xchgl($dst$$Register, $tmp2$$Register);
  8910     // Fallthrow for final divide, tmp2 has 32 bit hi result
  8912     __ bind(Lfast);
  8913     // fast path: src is positive
  8914     __ divl($tmp$$Register); // Use unsigned division
  8916     __ bind(Ldone);
  8917     __ movl(HIGH_FROM_LOW($dst$$Register),$tmp2$$Register);
  8918     if (con < 0) {
  8919       __ lneg(HIGH_FROM_LOW($dst$$Register), $dst$$Register);
  8921   %}
  8922   ins_pipe( pipe_slow );
  8923 %}
  8925 // Remainder Register Long (remainder fit into 32 bits)
  8926 instruct modL_eReg_imm32( eADXRegL dst, immL32 imm, eRegI tmp, eRegI tmp2, eFlagsReg cr ) %{
  8927   match(Set dst (ModL dst imm));
  8928   effect( TEMP tmp, TEMP tmp2, KILL cr );
  8929   ins_cost(1000);
  8930   format %{ "MOV    $tmp,abs($imm) # lrem EDX:EAX,$imm\n\t"
  8931             "CMP    $tmp,EDX\n\t"
  8932             "JA,s   fast\n\t"
  8933             "MOV    $tmp2,EAX\n\t"
  8934             "MOV    EAX,EDX\n\t"
  8935             "MOV    EDX,0\n\t"
  8936             "JLE,s  pos\n\t"
  8937             "LNEG   EAX : $tmp2\n\t"
  8938             "DIV    $tmp # unsigned division\n\t"
  8939             "MOV    EAX,$tmp2\n\t"
  8940             "DIV    $tmp\n\t"
  8941             "NEG    EDX\n\t"
  8942             "JMP,s  done\n"
  8943     "pos:\n\t"
  8944             "DIV    $tmp\n\t"
  8945             "MOV    EAX,$tmp2\n"
  8946     "fast:\n\t"
  8947             "DIV    $tmp\n"
  8948     "done:\n\t"
  8949             "MOV    EAX,EDX\n\t"
  8950             "SAR    EDX,31\n\t" %}
  8951   ins_encode %{
  8952     int con = (int)$imm$$constant;
  8953     assert(con != 0 && con != -1 && con != min_jint, "wrong divisor");
  8954     int pcon = (con > 0) ? con : -con;
  8955     Label  Lfast, Lpos, Ldone;
  8957     __ movl($tmp$$Register, pcon);
  8958     __ cmpl($tmp$$Register, HIGH_FROM_LOW($dst$$Register));
  8959     __ jccb(Assembler::above, Lfast); // src is positive and result fits into 32 bit
  8961     __ movl($tmp2$$Register, $dst$$Register); // save
  8962     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8963     __ movl(HIGH_FROM_LOW($dst$$Register),0); // preserve flags
  8964     __ jccb(Assembler::lessEqual, Lpos); // result is positive
  8966     // Negative dividend.
  8967     // convert value to positive to use unsigned division
  8968     __ lneg($dst$$Register, $tmp2$$Register);
  8969     __ divl($tmp$$Register);
  8970     __ movl($dst$$Register, $tmp2$$Register);
  8971     __ divl($tmp$$Register);
  8972     // revert remainder back to negative
  8973     __ negl(HIGH_FROM_LOW($dst$$Register));
  8974     __ jmpb(Ldone);
  8976     __ bind(Lpos);
  8977     __ divl($tmp$$Register);
  8978     __ movl($dst$$Register, $tmp2$$Register);
  8980     __ bind(Lfast);
  8981     // fast path: src is positive
  8982     __ divl($tmp$$Register);
  8984     __ bind(Ldone);
  8985     __ movl($dst$$Register, HIGH_FROM_LOW($dst$$Register));
  8986     __ sarl(HIGH_FROM_LOW($dst$$Register), 31); // result sign
  8988   %}
  8989   ins_pipe( pipe_slow );
  8990 %}
  8992 // Integer Shift Instructions
  8993 // Shift Left by one
  8994 instruct shlI_eReg_1(eRegI dst, immI1 shift, eFlagsReg cr) %{
  8995   match(Set dst (LShiftI dst shift));
  8996   effect(KILL cr);
  8998   size(2);
  8999   format %{ "SHL    $dst,$shift" %}
  9000   opcode(0xD1, 0x4);  /* D1 /4 */
  9001   ins_encode( OpcP, RegOpc( dst ) );
  9002   ins_pipe( ialu_reg );
  9003 %}
  9005 // Shift Left by 8-bit immediate
  9006 instruct salI_eReg_imm(eRegI dst, immI8 shift, eFlagsReg cr) %{
  9007   match(Set dst (LShiftI dst shift));
  9008   effect(KILL cr);
  9010   size(3);
  9011   format %{ "SHL    $dst,$shift" %}
  9012   opcode(0xC1, 0x4);  /* C1 /4 ib */
  9013   ins_encode( RegOpcImm( dst, shift) );
  9014   ins_pipe( ialu_reg );
  9015 %}
  9017 // Shift Left by variable
  9018 instruct salI_eReg_CL(eRegI dst, eCXRegI shift, eFlagsReg cr) %{
  9019   match(Set dst (LShiftI dst shift));
  9020   effect(KILL cr);
  9022   size(2);
  9023   format %{ "SHL    $dst,$shift" %}
  9024   opcode(0xD3, 0x4);  /* D3 /4 */
  9025   ins_encode( OpcP, RegOpc( dst ) );
  9026   ins_pipe( ialu_reg_reg );
  9027 %}
  9029 // Arithmetic shift right by one
  9030 instruct sarI_eReg_1(eRegI dst, immI1 shift, eFlagsReg cr) %{
  9031   match(Set dst (RShiftI dst shift));
  9032   effect(KILL cr);
  9034   size(2);
  9035   format %{ "SAR    $dst,$shift" %}
  9036   opcode(0xD1, 0x7);  /* D1 /7 */
  9037   ins_encode( OpcP, RegOpc( dst ) );
  9038   ins_pipe( ialu_reg );
  9039 %}
  9041 // Arithmetic shift right by one
  9042 instruct sarI_mem_1(memory dst, immI1 shift, eFlagsReg cr) %{
  9043   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  9044   effect(KILL cr);
  9045   format %{ "SAR    $dst,$shift" %}
  9046   opcode(0xD1, 0x7);  /* D1 /7 */
  9047   ins_encode( OpcP, RMopc_Mem(secondary,dst) );
  9048   ins_pipe( ialu_mem_imm );
  9049 %}
  9051 // Arithmetic Shift Right by 8-bit immediate
  9052 instruct sarI_eReg_imm(eRegI dst, immI8 shift, eFlagsReg cr) %{
  9053   match(Set dst (RShiftI dst shift));
  9054   effect(KILL cr);
  9056   size(3);
  9057   format %{ "SAR    $dst,$shift" %}
  9058   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9059   ins_encode( RegOpcImm( dst, shift ) );
  9060   ins_pipe( ialu_mem_imm );
  9061 %}
  9063 // Arithmetic Shift Right by 8-bit immediate
  9064 instruct sarI_mem_imm(memory dst, immI8 shift, eFlagsReg cr) %{
  9065   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  9066   effect(KILL cr);
  9068   format %{ "SAR    $dst,$shift" %}
  9069   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9070   ins_encode( OpcP, RMopc_Mem(secondary, dst ), Con8or32( shift ) );
  9071   ins_pipe( ialu_mem_imm );
  9072 %}
  9074 // Arithmetic Shift Right by variable
  9075 instruct sarI_eReg_CL(eRegI dst, eCXRegI shift, eFlagsReg cr) %{
  9076   match(Set dst (RShiftI dst shift));
  9077   effect(KILL cr);
  9079   size(2);
  9080   format %{ "SAR    $dst,$shift" %}
  9081   opcode(0xD3, 0x7);  /* D3 /7 */
  9082   ins_encode( OpcP, RegOpc( dst ) );
  9083   ins_pipe( ialu_reg_reg );
  9084 %}
  9086 // Logical shift right by one
  9087 instruct shrI_eReg_1(eRegI dst, immI1 shift, eFlagsReg cr) %{
  9088   match(Set dst (URShiftI dst shift));
  9089   effect(KILL cr);
  9091   size(2);
  9092   format %{ "SHR    $dst,$shift" %}
  9093   opcode(0xD1, 0x5);  /* D1 /5 */
  9094   ins_encode( OpcP, RegOpc( dst ) );
  9095   ins_pipe( ialu_reg );
  9096 %}
  9098 // Logical Shift Right by 8-bit immediate
  9099 instruct shrI_eReg_imm(eRegI dst, immI8 shift, eFlagsReg cr) %{
  9100   match(Set dst (URShiftI dst shift));
  9101   effect(KILL cr);
  9103   size(3);
  9104   format %{ "SHR    $dst,$shift" %}
  9105   opcode(0xC1, 0x5);  /* C1 /5 ib */
  9106   ins_encode( RegOpcImm( dst, shift) );
  9107   ins_pipe( ialu_reg );
  9108 %}
  9111 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
  9112 // This idiom is used by the compiler for the i2b bytecode.
  9113 instruct i2b(eRegI dst, xRegI src, immI_24 twentyfour) %{
  9114   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
  9116   size(3);
  9117   format %{ "MOVSX  $dst,$src :8" %}
  9118   ins_encode %{
  9119     __ movsbl($dst$$Register, $src$$Register);
  9120   %}
  9121   ins_pipe(ialu_reg_reg);
  9122 %}
  9124 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
  9125 // This idiom is used by the compiler the i2s bytecode.
  9126 instruct i2s(eRegI dst, xRegI src, immI_16 sixteen) %{
  9127   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
  9129   size(3);
  9130   format %{ "MOVSX  $dst,$src :16" %}
  9131   ins_encode %{
  9132     __ movswl($dst$$Register, $src$$Register);
  9133   %}
  9134   ins_pipe(ialu_reg_reg);
  9135 %}
  9138 // Logical Shift Right by variable
  9139 instruct shrI_eReg_CL(eRegI dst, eCXRegI shift, eFlagsReg cr) %{
  9140   match(Set dst (URShiftI dst shift));
  9141   effect(KILL cr);
  9143   size(2);
  9144   format %{ "SHR    $dst,$shift" %}
  9145   opcode(0xD3, 0x5);  /* D3 /5 */
  9146   ins_encode( OpcP, RegOpc( dst ) );
  9147   ins_pipe( ialu_reg_reg );
  9148 %}
  9151 //----------Logical Instructions-----------------------------------------------
  9152 //----------Integer Logical Instructions---------------------------------------
  9153 // And Instructions
  9154 // And Register with Register
  9155 instruct andI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  9156   match(Set dst (AndI dst src));
  9157   effect(KILL cr);
  9159   size(2);
  9160   format %{ "AND    $dst,$src" %}
  9161   opcode(0x23);
  9162   ins_encode( OpcP, RegReg( dst, src) );
  9163   ins_pipe( ialu_reg_reg );
  9164 %}
  9166 // And Register with Immediate
  9167 instruct andI_eReg_imm(eRegI dst, immI src, eFlagsReg cr) %{
  9168   match(Set dst (AndI dst src));
  9169   effect(KILL cr);
  9171   format %{ "AND    $dst,$src" %}
  9172   opcode(0x81,0x04);  /* Opcode 81 /4 */
  9173   // ins_encode( RegImm( dst, src) );
  9174   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  9175   ins_pipe( ialu_reg );
  9176 %}
  9178 // And Register with Memory
  9179 instruct andI_eReg_mem(eRegI dst, memory src, eFlagsReg cr) %{
  9180   match(Set dst (AndI dst (LoadI src)));
  9181   effect(KILL cr);
  9183   ins_cost(125);
  9184   format %{ "AND    $dst,$src" %}
  9185   opcode(0x23);
  9186   ins_encode( OpcP, RegMem( dst, src) );
  9187   ins_pipe( ialu_reg_mem );
  9188 %}
  9190 // And Memory with Register
  9191 instruct andI_mem_eReg(memory dst, eRegI src, eFlagsReg cr) %{
  9192   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  9193   effect(KILL cr);
  9195   ins_cost(150);
  9196   format %{ "AND    $dst,$src" %}
  9197   opcode(0x21);  /* Opcode 21 /r */
  9198   ins_encode( OpcP, RegMem( src, dst ) );
  9199   ins_pipe( ialu_mem_reg );
  9200 %}
  9202 // And Memory with Immediate
  9203 instruct andI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  9204   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  9205   effect(KILL cr);
  9207   ins_cost(125);
  9208   format %{ "AND    $dst,$src" %}
  9209   opcode(0x81, 0x4);  /* Opcode 81 /4 id */
  9210   // ins_encode( MemImm( dst, src) );
  9211   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  9212   ins_pipe( ialu_mem_imm );
  9213 %}
  9215 // Or Instructions
  9216 // Or Register with Register
  9217 instruct orI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  9218   match(Set dst (OrI dst src));
  9219   effect(KILL cr);
  9221   size(2);
  9222   format %{ "OR     $dst,$src" %}
  9223   opcode(0x0B);
  9224   ins_encode( OpcP, RegReg( dst, src) );
  9225   ins_pipe( ialu_reg_reg );
  9226 %}
  9228 instruct orI_eReg_castP2X(eRegI dst, eRegP src, eFlagsReg cr) %{
  9229   match(Set dst (OrI dst (CastP2X src)));
  9230   effect(KILL cr);
  9232   size(2);
  9233   format %{ "OR     $dst,$src" %}
  9234   opcode(0x0B);
  9235   ins_encode( OpcP, RegReg( dst, src) );
  9236   ins_pipe( ialu_reg_reg );
  9237 %}
  9240 // Or Register with Immediate
  9241 instruct orI_eReg_imm(eRegI dst, immI src, eFlagsReg cr) %{
  9242   match(Set dst (OrI dst src));
  9243   effect(KILL cr);
  9245   format %{ "OR     $dst,$src" %}
  9246   opcode(0x81,0x01);  /* Opcode 81 /1 id */
  9247   // ins_encode( RegImm( dst, src) );
  9248   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  9249   ins_pipe( ialu_reg );
  9250 %}
  9252 // Or Register with Memory
  9253 instruct orI_eReg_mem(eRegI dst, memory src, eFlagsReg cr) %{
  9254   match(Set dst (OrI dst (LoadI src)));
  9255   effect(KILL cr);
  9257   ins_cost(125);
  9258   format %{ "OR     $dst,$src" %}
  9259   opcode(0x0B);
  9260   ins_encode( OpcP, RegMem( dst, src) );
  9261   ins_pipe( ialu_reg_mem );
  9262 %}
  9264 // Or Memory with Register
  9265 instruct orI_mem_eReg(memory dst, eRegI src, eFlagsReg cr) %{
  9266   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  9267   effect(KILL cr);
  9269   ins_cost(150);
  9270   format %{ "OR     $dst,$src" %}
  9271   opcode(0x09);  /* Opcode 09 /r */
  9272   ins_encode( OpcP, RegMem( src, dst ) );
  9273   ins_pipe( ialu_mem_reg );
  9274 %}
  9276 // Or Memory with Immediate
  9277 instruct orI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  9278   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  9279   effect(KILL cr);
  9281   ins_cost(125);
  9282   format %{ "OR     $dst,$src" %}
  9283   opcode(0x81,0x1);  /* Opcode 81 /1 id */
  9284   // ins_encode( MemImm( dst, src) );
  9285   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  9286   ins_pipe( ialu_mem_imm );
  9287 %}
  9289 // ROL/ROR
  9290 // ROL expand
  9291 instruct rolI_eReg_imm1(eRegI dst, immI1 shift, eFlagsReg cr) %{
  9292   effect(USE_DEF dst, USE shift, KILL cr);
  9294   format %{ "ROL    $dst, $shift" %}
  9295   opcode(0xD1, 0x0); /* Opcode D1 /0 */
  9296   ins_encode( OpcP, RegOpc( dst ));
  9297   ins_pipe( ialu_reg );
  9298 %}
  9300 instruct rolI_eReg_imm8(eRegI dst, immI8 shift, eFlagsReg cr) %{
  9301   effect(USE_DEF dst, USE shift, KILL cr);
  9303   format %{ "ROL    $dst, $shift" %}
  9304   opcode(0xC1, 0x0); /*Opcode /C1  /0  */
  9305   ins_encode( RegOpcImm(dst, shift) );
  9306   ins_pipe(ialu_reg);
  9307 %}
  9309 instruct rolI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr) %{
  9310   effect(USE_DEF dst, USE shift, KILL cr);
  9312   format %{ "ROL    $dst, $shift" %}
  9313   opcode(0xD3, 0x0);    /* Opcode D3 /0 */
  9314   ins_encode(OpcP, RegOpc(dst));
  9315   ins_pipe( ialu_reg_reg );
  9316 %}
  9317 // end of ROL expand
  9319 // ROL 32bit by one once
  9320 instruct rolI_eReg_i1(eRegI dst, immI1 lshift, immI_M1 rshift, eFlagsReg cr) %{
  9321   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  9323   expand %{
  9324     rolI_eReg_imm1(dst, lshift, cr);
  9325   %}
  9326 %}
  9328 // ROL 32bit var by imm8 once
  9329 instruct rolI_eReg_i8(eRegI dst, immI8 lshift, immI8 rshift, eFlagsReg cr) %{
  9330   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  9331   match(Set dst ( OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  9333   expand %{
  9334     rolI_eReg_imm8(dst, lshift, cr);
  9335   %}
  9336 %}
  9338 // ROL 32bit var by var once
  9339 instruct rolI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
  9340   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI zero shift))));
  9342   expand %{
  9343     rolI_eReg_CL(dst, shift, cr);
  9344   %}
  9345 %}
  9347 // ROL 32bit var by var once
  9348 instruct rolI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
  9349   match(Set dst ( OrI (LShiftI dst shift) (URShiftI dst (SubI c32 shift))));
  9351   expand %{
  9352     rolI_eReg_CL(dst, shift, cr);
  9353   %}
  9354 %}
  9356 // ROR expand
  9357 instruct rorI_eReg_imm1(eRegI dst, immI1 shift, eFlagsReg cr) %{
  9358   effect(USE_DEF dst, USE shift, KILL cr);
  9360   format %{ "ROR    $dst, $shift" %}
  9361   opcode(0xD1,0x1);  /* Opcode D1 /1 */
  9362   ins_encode( OpcP, RegOpc( dst ) );
  9363   ins_pipe( ialu_reg );
  9364 %}
  9366 instruct rorI_eReg_imm8(eRegI dst, immI8 shift, eFlagsReg cr) %{
  9367   effect (USE_DEF dst, USE shift, KILL cr);
  9369   format %{ "ROR    $dst, $shift" %}
  9370   opcode(0xC1, 0x1); /* Opcode /C1 /1 ib */
  9371   ins_encode( RegOpcImm(dst, shift) );
  9372   ins_pipe( ialu_reg );
  9373 %}
  9375 instruct rorI_eReg_CL(ncxRegI dst, eCXRegI shift, eFlagsReg cr)%{
  9376   effect(USE_DEF dst, USE shift, KILL cr);
  9378   format %{ "ROR    $dst, $shift" %}
  9379   opcode(0xD3, 0x1);    /* Opcode D3 /1 */
  9380   ins_encode(OpcP, RegOpc(dst));
  9381   ins_pipe( ialu_reg_reg );
  9382 %}
  9383 // end of ROR expand
  9385 // ROR right once
  9386 instruct rorI_eReg_i1(eRegI dst, immI1 rshift, immI_M1 lshift, eFlagsReg cr) %{
  9387   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  9389   expand %{
  9390     rorI_eReg_imm1(dst, rshift, cr);
  9391   %}
  9392 %}
  9394 // ROR 32bit by immI8 once
  9395 instruct rorI_eReg_i8(eRegI dst, immI8 rshift, immI8 lshift, eFlagsReg cr) %{
  9396   predicate(  0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  9397   match(Set dst ( OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  9399   expand %{
  9400     rorI_eReg_imm8(dst, rshift, cr);
  9401   %}
  9402 %}
  9404 // ROR 32bit var by var once
  9405 instruct rorI_eReg_Var_C0(ncxRegI dst, eCXRegI shift, immI0 zero, eFlagsReg cr) %{
  9406   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI zero shift))));
  9408   expand %{
  9409     rorI_eReg_CL(dst, shift, cr);
  9410   %}
  9411 %}
  9413 // ROR 32bit var by var once
  9414 instruct rorI_eReg_Var_C32(ncxRegI dst, eCXRegI shift, immI_32 c32, eFlagsReg cr) %{
  9415   match(Set dst ( OrI (URShiftI dst shift) (LShiftI dst (SubI c32 shift))));
  9417   expand %{
  9418     rorI_eReg_CL(dst, shift, cr);
  9419   %}
  9420 %}
  9422 // Xor Instructions
  9423 // Xor Register with Register
  9424 instruct xorI_eReg(eRegI dst, eRegI src, eFlagsReg cr) %{
  9425   match(Set dst (XorI dst src));
  9426   effect(KILL cr);
  9428   size(2);
  9429   format %{ "XOR    $dst,$src" %}
  9430   opcode(0x33);
  9431   ins_encode( OpcP, RegReg( dst, src) );
  9432   ins_pipe( ialu_reg_reg );
  9433 %}
  9435 // Xor Register with Immediate -1
  9436 instruct xorI_eReg_im1(eRegI dst, immI_M1 imm) %{
  9437   match(Set dst (XorI dst imm));  
  9439   size(2);
  9440   format %{ "NOT    $dst" %}  
  9441   ins_encode %{
  9442      __ notl($dst$$Register);
  9443   %}
  9444   ins_pipe( ialu_reg );
  9445 %}
  9447 // Xor Register with Immediate
  9448 instruct xorI_eReg_imm(eRegI dst, immI src, eFlagsReg cr) %{
  9449   match(Set dst (XorI dst src));
  9450   effect(KILL cr);
  9452   format %{ "XOR    $dst,$src" %}
  9453   opcode(0x81,0x06);  /* Opcode 81 /6 id */
  9454   // ins_encode( RegImm( dst, src) );
  9455   ins_encode( OpcSErm( dst, src ), Con8or32( src ) );
  9456   ins_pipe( ialu_reg );
  9457 %}
  9459 // Xor Register with Memory
  9460 instruct xorI_eReg_mem(eRegI dst, memory src, eFlagsReg cr) %{
  9461   match(Set dst (XorI dst (LoadI src)));
  9462   effect(KILL cr);
  9464   ins_cost(125);
  9465   format %{ "XOR    $dst,$src" %}
  9466   opcode(0x33);
  9467   ins_encode( OpcP, RegMem(dst, src) );
  9468   ins_pipe( ialu_reg_mem );
  9469 %}
  9471 // Xor Memory with Register
  9472 instruct xorI_mem_eReg(memory dst, eRegI src, eFlagsReg cr) %{
  9473   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  9474   effect(KILL cr);
  9476   ins_cost(150);
  9477   format %{ "XOR    $dst,$src" %}
  9478   opcode(0x31);  /* Opcode 31 /r */
  9479   ins_encode( OpcP, RegMem( src, dst ) );
  9480   ins_pipe( ialu_mem_reg );
  9481 %}
  9483 // Xor Memory with Immediate
  9484 instruct xorI_mem_imm(memory dst, immI src, eFlagsReg cr) %{
  9485   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  9486   effect(KILL cr);
  9488   ins_cost(125);
  9489   format %{ "XOR    $dst,$src" %}
  9490   opcode(0x81,0x6);  /* Opcode 81 /6 id */
  9491   ins_encode( OpcSE( src ), RMopc_Mem(secondary, dst ), Con8or32( src ) );
  9492   ins_pipe( ialu_mem_imm );
  9493 %}
  9495 //----------Convert Int to Boolean---------------------------------------------
  9497 instruct movI_nocopy(eRegI dst, eRegI src) %{
  9498   effect( DEF dst, USE src );
  9499   format %{ "MOV    $dst,$src" %}
  9500   ins_encode( enc_Copy( dst, src) );
  9501   ins_pipe( ialu_reg_reg );
  9502 %}
  9504 instruct ci2b( eRegI dst, eRegI src, eFlagsReg cr ) %{
  9505   effect( USE_DEF dst, USE src, KILL cr );
  9507   size(4);
  9508   format %{ "NEG    $dst\n\t"
  9509             "ADC    $dst,$src" %}
  9510   ins_encode( neg_reg(dst),
  9511               OpcRegReg(0x13,dst,src) );
  9512   ins_pipe( ialu_reg_reg_long );
  9513 %}
  9515 instruct convI2B( eRegI dst, eRegI src, eFlagsReg cr ) %{
  9516   match(Set dst (Conv2B src));
  9518   expand %{
  9519     movI_nocopy(dst,src);
  9520     ci2b(dst,src,cr);
  9521   %}
  9522 %}
  9524 instruct movP_nocopy(eRegI dst, eRegP src) %{
  9525   effect( DEF dst, USE src );
  9526   format %{ "MOV    $dst,$src" %}
  9527   ins_encode( enc_Copy( dst, src) );
  9528   ins_pipe( ialu_reg_reg );
  9529 %}
  9531 instruct cp2b( eRegI dst, eRegP src, eFlagsReg cr ) %{
  9532   effect( USE_DEF dst, USE src, KILL cr );
  9533   format %{ "NEG    $dst\n\t"
  9534             "ADC    $dst,$src" %}
  9535   ins_encode( neg_reg(dst),
  9536               OpcRegReg(0x13,dst,src) );
  9537   ins_pipe( ialu_reg_reg_long );
  9538 %}
  9540 instruct convP2B( eRegI dst, eRegP src, eFlagsReg cr ) %{
  9541   match(Set dst (Conv2B src));
  9543   expand %{
  9544     movP_nocopy(dst,src);
  9545     cp2b(dst,src,cr);
  9546   %}
  9547 %}
  9549 instruct cmpLTMask( eCXRegI dst, ncxRegI p, ncxRegI q, eFlagsReg cr ) %{
  9550   match(Set dst (CmpLTMask p q));
  9551   effect( KILL cr );
  9552   ins_cost(400);
  9554   // SETlt can only use low byte of EAX,EBX, ECX, or EDX as destination
  9555   format %{ "XOR    $dst,$dst\n\t"
  9556             "CMP    $p,$q\n\t"
  9557             "SETlt  $dst\n\t"
  9558             "NEG    $dst" %}
  9559   ins_encode( OpcRegReg(0x33,dst,dst),
  9560               OpcRegReg(0x3B,p,q),
  9561               setLT_reg(dst), neg_reg(dst) );
  9562   ins_pipe( pipe_slow );
  9563 %}
  9565 instruct cmpLTMask0( eRegI dst, immI0 zero, eFlagsReg cr ) %{
  9566   match(Set dst (CmpLTMask dst zero));
  9567   effect( DEF dst, KILL cr );
  9568   ins_cost(100);
  9570   format %{ "SAR    $dst,31" %}
  9571   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9572   ins_encode( RegOpcImm( dst, 0x1F ) );
  9573   ins_pipe( ialu_reg );
  9574 %}
  9577 instruct cadd_cmpLTMask( ncxRegI p, ncxRegI q, ncxRegI y, eCXRegI tmp, eFlagsReg cr ) %{
  9578   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
  9579   effect( KILL tmp, KILL cr );
  9580   ins_cost(400);
  9581   // annoyingly, $tmp has no edges so you cant ask for it in
  9582   // any format or encoding
  9583   format %{ "SUB    $p,$q\n\t"
  9584             "SBB    ECX,ECX\n\t"
  9585             "AND    ECX,$y\n\t"
  9586             "ADD    $p,ECX" %}
  9587   ins_encode( enc_cmpLTP(p,q,y,tmp) );
  9588   ins_pipe( pipe_cmplt );
  9589 %}
  9591 /* If I enable this, I encourage spilling in the inner loop of compress.
  9592 instruct cadd_cmpLTMask_mem( ncxRegI p, ncxRegI q, memory y, eCXRegI tmp, eFlagsReg cr ) %{
  9593   match(Set p (AddI (AndI (CmpLTMask p q) (LoadI y)) (SubI p q)));
  9594   effect( USE_KILL tmp, KILL cr );
  9595   ins_cost(400);
  9597   format %{ "SUB    $p,$q\n\t"
  9598             "SBB    ECX,ECX\n\t"
  9599             "AND    ECX,$y\n\t"
  9600             "ADD    $p,ECX" %}
  9601   ins_encode( enc_cmpLTP_mem(p,q,y,tmp) );
  9602 %}
  9603 */
  9605 //----------Long Instructions------------------------------------------------
  9606 // Add Long Register with Register
  9607 instruct addL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9608   match(Set dst (AddL dst src));
  9609   effect(KILL cr);
  9610   ins_cost(200);
  9611   format %{ "ADD    $dst.lo,$src.lo\n\t"
  9612             "ADC    $dst.hi,$src.hi" %}
  9613   opcode(0x03, 0x13);
  9614   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
  9615   ins_pipe( ialu_reg_reg_long );
  9616 %}
  9618 // Add Long Register with Immediate
  9619 instruct addL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9620   match(Set dst (AddL dst src));
  9621   effect(KILL cr);
  9622   format %{ "ADD    $dst.lo,$src.lo\n\t"
  9623             "ADC    $dst.hi,$src.hi" %}
  9624   opcode(0x81,0x00,0x02);  /* Opcode 81 /0, 81 /2 */
  9625   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9626   ins_pipe( ialu_reg_long );
  9627 %}
  9629 // Add Long Register with Memory
  9630 instruct addL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9631   match(Set dst (AddL dst (LoadL mem)));
  9632   effect(KILL cr);
  9633   ins_cost(125);
  9634   format %{ "ADD    $dst.lo,$mem\n\t"
  9635             "ADC    $dst.hi,$mem+4" %}
  9636   opcode(0x03, 0x13);
  9637   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9638   ins_pipe( ialu_reg_long_mem );
  9639 %}
  9641 // Subtract Long Register with Register.
  9642 instruct subL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9643   match(Set dst (SubL dst src));
  9644   effect(KILL cr);
  9645   ins_cost(200);
  9646   format %{ "SUB    $dst.lo,$src.lo\n\t"
  9647             "SBB    $dst.hi,$src.hi" %}
  9648   opcode(0x2B, 0x1B);
  9649   ins_encode( RegReg_Lo(dst, src), RegReg_Hi(dst,src) );
  9650   ins_pipe( ialu_reg_reg_long );
  9651 %}
  9653 // Subtract Long Register with Immediate
  9654 instruct subL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9655   match(Set dst (SubL dst src));
  9656   effect(KILL cr);
  9657   format %{ "SUB    $dst.lo,$src.lo\n\t"
  9658             "SBB    $dst.hi,$src.hi" %}
  9659   opcode(0x81,0x05,0x03);  /* Opcode 81 /5, 81 /3 */
  9660   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9661   ins_pipe( ialu_reg_long );
  9662 %}
  9664 // Subtract Long Register with Memory
  9665 instruct subL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9666   match(Set dst (SubL dst (LoadL mem)));
  9667   effect(KILL cr);
  9668   ins_cost(125);
  9669   format %{ "SUB    $dst.lo,$mem\n\t"
  9670             "SBB    $dst.hi,$mem+4" %}
  9671   opcode(0x2B, 0x1B);
  9672   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9673   ins_pipe( ialu_reg_long_mem );
  9674 %}
  9676 instruct negL_eReg(eRegL dst, immL0 zero, eFlagsReg cr) %{
  9677   match(Set dst (SubL zero dst));
  9678   effect(KILL cr);
  9679   ins_cost(300);
  9680   format %{ "NEG    $dst.hi\n\tNEG    $dst.lo\n\tSBB    $dst.hi,0" %}
  9681   ins_encode( neg_long(dst) );
  9682   ins_pipe( ialu_reg_reg_long );
  9683 %}
  9685 // And Long Register with Register
  9686 instruct andL_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9687   match(Set dst (AndL dst src));
  9688   effect(KILL cr);
  9689   format %{ "AND    $dst.lo,$src.lo\n\t"
  9690             "AND    $dst.hi,$src.hi" %}
  9691   opcode(0x23,0x23);
  9692   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9693   ins_pipe( ialu_reg_reg_long );
  9694 %}
  9696 // And Long Register with Immediate
  9697 instruct andL_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9698   match(Set dst (AndL dst src));
  9699   effect(KILL cr);
  9700   format %{ "AND    $dst.lo,$src.lo\n\t"
  9701             "AND    $dst.hi,$src.hi" %}
  9702   opcode(0x81,0x04,0x04);  /* Opcode 81 /4, 81 /4 */
  9703   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9704   ins_pipe( ialu_reg_long );
  9705 %}
  9707 // And Long Register with Memory
  9708 instruct andL_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9709   match(Set dst (AndL dst (LoadL mem)));
  9710   effect(KILL cr);
  9711   ins_cost(125);
  9712   format %{ "AND    $dst.lo,$mem\n\t"
  9713             "AND    $dst.hi,$mem+4" %}
  9714   opcode(0x23, 0x23);
  9715   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9716   ins_pipe( ialu_reg_long_mem );
  9717 %}
  9719 // Or Long Register with Register
  9720 instruct orl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9721   match(Set dst (OrL dst src));
  9722   effect(KILL cr);
  9723   format %{ "OR     $dst.lo,$src.lo\n\t"
  9724             "OR     $dst.hi,$src.hi" %}
  9725   opcode(0x0B,0x0B);
  9726   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9727   ins_pipe( ialu_reg_reg_long );
  9728 %}
  9730 // Or Long Register with Immediate
  9731 instruct orl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9732   match(Set dst (OrL dst src));
  9733   effect(KILL cr);
  9734   format %{ "OR     $dst.lo,$src.lo\n\t"
  9735             "OR     $dst.hi,$src.hi" %}
  9736   opcode(0x81,0x01,0x01);  /* Opcode 81 /1, 81 /1 */
  9737   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9738   ins_pipe( ialu_reg_long );
  9739 %}
  9741 // Or Long Register with Memory
  9742 instruct orl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9743   match(Set dst (OrL dst (LoadL mem)));
  9744   effect(KILL cr);
  9745   ins_cost(125);
  9746   format %{ "OR     $dst.lo,$mem\n\t"
  9747             "OR     $dst.hi,$mem+4" %}
  9748   opcode(0x0B,0x0B);
  9749   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9750   ins_pipe( ialu_reg_long_mem );
  9751 %}
  9753 // Xor Long Register with Register
  9754 instruct xorl_eReg(eRegL dst, eRegL src, eFlagsReg cr) %{
  9755   match(Set dst (XorL dst src));
  9756   effect(KILL cr);
  9757   format %{ "XOR    $dst.lo,$src.lo\n\t"
  9758             "XOR    $dst.hi,$src.hi" %}
  9759   opcode(0x33,0x33);
  9760   ins_encode( RegReg_Lo( dst, src), RegReg_Hi( dst, src) );
  9761   ins_pipe( ialu_reg_reg_long );
  9762 %}
  9764 // Xor Long Register with Immediate -1
  9765 instruct xorl_eReg_im1(eRegL dst, immL_M1 imm) %{
  9766   match(Set dst (XorL dst imm));  
  9767   format %{ "NOT    $dst.lo\n\t"
  9768             "NOT    $dst.hi" %}
  9769   ins_encode %{
  9770      __ notl($dst$$Register);
  9771      __ notl(HIGH_FROM_LOW($dst$$Register));
  9772   %}
  9773   ins_pipe( ialu_reg_long );
  9774 %}
  9776 // Xor Long Register with Immediate
  9777 instruct xorl_eReg_imm(eRegL dst, immL src, eFlagsReg cr) %{
  9778   match(Set dst (XorL dst src));
  9779   effect(KILL cr);
  9780   format %{ "XOR    $dst.lo,$src.lo\n\t"
  9781             "XOR    $dst.hi,$src.hi" %}
  9782   opcode(0x81,0x06,0x06);  /* Opcode 81 /6, 81 /6 */
  9783   ins_encode( Long_OpcSErm_Lo( dst, src ), Long_OpcSErm_Hi( dst, src ) );
  9784   ins_pipe( ialu_reg_long );
  9785 %}
  9787 // Xor Long Register with Memory
  9788 instruct xorl_eReg_mem(eRegL dst, load_long_memory mem, eFlagsReg cr) %{
  9789   match(Set dst (XorL dst (LoadL mem)));
  9790   effect(KILL cr);
  9791   ins_cost(125);
  9792   format %{ "XOR    $dst.lo,$mem\n\t"
  9793             "XOR    $dst.hi,$mem+4" %}
  9794   opcode(0x33,0x33);
  9795   ins_encode( OpcP, RegMem( dst, mem), OpcS, RegMem_Hi(dst,mem) );
  9796   ins_pipe( ialu_reg_long_mem );
  9797 %}
  9799 // Shift Left Long by 1
  9800 instruct shlL_eReg_1(eRegL dst, immI_1 cnt, eFlagsReg cr) %{
  9801   predicate(UseNewLongLShift);
  9802   match(Set dst (LShiftL dst cnt));
  9803   effect(KILL cr);
  9804   ins_cost(100);
  9805   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9806             "ADC    $dst.hi,$dst.hi" %}
  9807   ins_encode %{
  9808     __ addl($dst$$Register,$dst$$Register);
  9809     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9810   %}
  9811   ins_pipe( ialu_reg_long );
  9812 %}
  9814 // Shift Left Long by 2
  9815 instruct shlL_eReg_2(eRegL dst, immI_2 cnt, eFlagsReg cr) %{
  9816   predicate(UseNewLongLShift);
  9817   match(Set dst (LShiftL dst cnt));
  9818   effect(KILL cr);
  9819   ins_cost(100);
  9820   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9821             "ADC    $dst.hi,$dst.hi\n\t" 
  9822             "ADD    $dst.lo,$dst.lo\n\t"
  9823             "ADC    $dst.hi,$dst.hi" %}
  9824   ins_encode %{
  9825     __ addl($dst$$Register,$dst$$Register);
  9826     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9827     __ addl($dst$$Register,$dst$$Register);
  9828     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9829   %}
  9830   ins_pipe( ialu_reg_long );
  9831 %}
  9833 // Shift Left Long by 3
  9834 instruct shlL_eReg_3(eRegL dst, immI_3 cnt, eFlagsReg cr) %{
  9835   predicate(UseNewLongLShift);
  9836   match(Set dst (LShiftL dst cnt));
  9837   effect(KILL cr);
  9838   ins_cost(100);
  9839   format %{ "ADD    $dst.lo,$dst.lo\n\t"
  9840             "ADC    $dst.hi,$dst.hi\n\t" 
  9841             "ADD    $dst.lo,$dst.lo\n\t"
  9842             "ADC    $dst.hi,$dst.hi\n\t" 
  9843             "ADD    $dst.lo,$dst.lo\n\t"
  9844             "ADC    $dst.hi,$dst.hi" %}
  9845   ins_encode %{
  9846     __ addl($dst$$Register,$dst$$Register);
  9847     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9848     __ addl($dst$$Register,$dst$$Register);
  9849     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9850     __ addl($dst$$Register,$dst$$Register);
  9851     __ adcl(HIGH_FROM_LOW($dst$$Register),HIGH_FROM_LOW($dst$$Register));
  9852   %}
  9853   ins_pipe( ialu_reg_long );
  9854 %}
  9856 // Shift Left Long by 1-31
  9857 instruct shlL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9858   match(Set dst (LShiftL dst cnt));
  9859   effect(KILL cr);
  9860   ins_cost(200);
  9861   format %{ "SHLD   $dst.hi,$dst.lo,$cnt\n\t"
  9862             "SHL    $dst.lo,$cnt" %}
  9863   opcode(0xC1, 0x4, 0xA4);  /* 0F/A4, then C1 /4 ib */
  9864   ins_encode( move_long_small_shift(dst,cnt) );
  9865   ins_pipe( ialu_reg_long );
  9866 %}
  9868 // Shift Left Long by 32-63
  9869 instruct shlL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9870   match(Set dst (LShiftL dst cnt));
  9871   effect(KILL cr);
  9872   ins_cost(300);
  9873   format %{ "MOV    $dst.hi,$dst.lo\n"
  9874           "\tSHL    $dst.hi,$cnt-32\n"
  9875           "\tXOR    $dst.lo,$dst.lo" %}
  9876   opcode(0xC1, 0x4);  /* C1 /4 ib */
  9877   ins_encode( move_long_big_shift_clr(dst,cnt) );
  9878   ins_pipe( ialu_reg_long );
  9879 %}
  9881 // Shift Left Long by variable
  9882 instruct salL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9883   match(Set dst (LShiftL dst shift));
  9884   effect(KILL cr);
  9885   ins_cost(500+200);
  9886   size(17);
  9887   format %{ "TEST   $shift,32\n\t"
  9888             "JEQ,s  small\n\t"
  9889             "MOV    $dst.hi,$dst.lo\n\t"
  9890             "XOR    $dst.lo,$dst.lo\n"
  9891     "small:\tSHLD   $dst.hi,$dst.lo,$shift\n\t"
  9892             "SHL    $dst.lo,$shift" %}
  9893   ins_encode( shift_left_long( dst, shift ) );
  9894   ins_pipe( pipe_slow );
  9895 %}
  9897 // Shift Right Long by 1-31
  9898 instruct shrL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9899   match(Set dst (URShiftL dst cnt));
  9900   effect(KILL cr);
  9901   ins_cost(200);
  9902   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
  9903             "SHR    $dst.hi,$cnt" %}
  9904   opcode(0xC1, 0x5, 0xAC);  /* 0F/AC, then C1 /5 ib */
  9905   ins_encode( move_long_small_shift(dst,cnt) );
  9906   ins_pipe( ialu_reg_long );
  9907 %}
  9909 // Shift Right Long by 32-63
  9910 instruct shrL_eReg_32_63(eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9911   match(Set dst (URShiftL dst cnt));
  9912   effect(KILL cr);
  9913   ins_cost(300);
  9914   format %{ "MOV    $dst.lo,$dst.hi\n"
  9915           "\tSHR    $dst.lo,$cnt-32\n"
  9916           "\tXOR    $dst.hi,$dst.hi" %}
  9917   opcode(0xC1, 0x5);  /* C1 /5 ib */
  9918   ins_encode( move_long_big_shift_clr(dst,cnt) );
  9919   ins_pipe( ialu_reg_long );
  9920 %}
  9922 // Shift Right Long by variable
  9923 instruct shrL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9924   match(Set dst (URShiftL dst shift));
  9925   effect(KILL cr);
  9926   ins_cost(600);
  9927   size(17);
  9928   format %{ "TEST   $shift,32\n\t"
  9929             "JEQ,s  small\n\t"
  9930             "MOV    $dst.lo,$dst.hi\n\t"
  9931             "XOR    $dst.hi,$dst.hi\n"
  9932     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
  9933             "SHR    $dst.hi,$shift" %}
  9934   ins_encode( shift_right_long( dst, shift ) );
  9935   ins_pipe( pipe_slow );
  9936 %}
  9938 // Shift Right Long by 1-31
  9939 instruct sarL_eReg_1_31(eRegL dst, immI_1_31 cnt, eFlagsReg cr) %{
  9940   match(Set dst (RShiftL dst cnt));
  9941   effect(KILL cr);
  9942   ins_cost(200);
  9943   format %{ "SHRD   $dst.lo,$dst.hi,$cnt\n\t"
  9944             "SAR    $dst.hi,$cnt" %}
  9945   opcode(0xC1, 0x7, 0xAC);  /* 0F/AC, then C1 /7 ib */
  9946   ins_encode( move_long_small_shift(dst,cnt) );
  9947   ins_pipe( ialu_reg_long );
  9948 %}
  9950 // Shift Right Long by 32-63
  9951 instruct sarL_eReg_32_63( eRegL dst, immI_32_63 cnt, eFlagsReg cr) %{
  9952   match(Set dst (RShiftL dst cnt));
  9953   effect(KILL cr);
  9954   ins_cost(300);
  9955   format %{ "MOV    $dst.lo,$dst.hi\n"
  9956           "\tSAR    $dst.lo,$cnt-32\n"
  9957           "\tSAR    $dst.hi,31" %}
  9958   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9959   ins_encode( move_long_big_shift_sign(dst,cnt) );
  9960   ins_pipe( ialu_reg_long );
  9961 %}
  9963 // Shift Right arithmetic Long by variable
  9964 instruct sarL_eReg_CL(eRegL dst, eCXRegI shift, eFlagsReg cr) %{
  9965   match(Set dst (RShiftL dst shift));
  9966   effect(KILL cr);
  9967   ins_cost(600);
  9968   size(18);
  9969   format %{ "TEST   $shift,32\n\t"
  9970             "JEQ,s  small\n\t"
  9971             "MOV    $dst.lo,$dst.hi\n\t"
  9972             "SAR    $dst.hi,31\n"
  9973     "small:\tSHRD   $dst.lo,$dst.hi,$shift\n\t"
  9974             "SAR    $dst.hi,$shift" %}
  9975   ins_encode( shift_right_arith_long( dst, shift ) );
  9976   ins_pipe( pipe_slow );
  9977 %}
  9980 //----------Double Instructions------------------------------------------------
  9981 // Double Math
  9983 // Compare & branch
  9985 // P6 version of float compare, sets condition codes in EFLAGS
  9986 instruct cmpD_cc_P6(eFlagsRegU cr, regD src1, regD src2, eAXRegI rax) %{
  9987   predicate(VM_Version::supports_cmov() && UseSSE <=1);
  9988   match(Set cr (CmpD src1 src2));
  9989   effect(KILL rax);
  9990   ins_cost(150);
  9991   format %{ "FLD    $src1\n\t"
  9992             "FUCOMIP ST,$src2  // P6 instruction\n\t"
  9993             "JNP    exit\n\t"
  9994             "MOV    ah,1       // saw a NaN, set CF\n\t"
  9995             "SAHF\n"
  9996      "exit:\tNOP               // avoid branch to branch" %}
  9997   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
  9998   ins_encode( Push_Reg_D(src1),
  9999               OpcP, RegOpc(src2),
 10000               cmpF_P6_fixup );
 10001   ins_pipe( pipe_slow );
 10002 %}
 10004 instruct cmpD_cc_P6CF(eFlagsRegUCF cr, regD src1, regD src2) %{
 10005   predicate(VM_Version::supports_cmov() && UseSSE <=1);
 10006   match(Set cr (CmpD src1 src2));
 10007   ins_cost(150);
 10008   format %{ "FLD    $src1\n\t"
 10009             "FUCOMIP ST,$src2  // P6 instruction" %}
 10010   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
 10011   ins_encode( Push_Reg_D(src1),
 10012               OpcP, RegOpc(src2));
 10013   ins_pipe( pipe_slow );
 10014 %}
 10016 // Compare & branch
 10017 instruct cmpD_cc(eFlagsRegU cr, regD src1, regD src2, eAXRegI rax) %{
 10018   predicate(UseSSE<=1);
 10019   match(Set cr (CmpD src1 src2));
 10020   effect(KILL rax);
 10021   ins_cost(200);
 10022   format %{ "FLD    $src1\n\t"
 10023             "FCOMp  $src2\n\t"
 10024             "FNSTSW AX\n\t"
 10025             "TEST   AX,0x400\n\t"
 10026             "JZ,s   flags\n\t"
 10027             "MOV    AH,1\t# unordered treat as LT\n"
 10028     "flags:\tSAHF" %}
 10029   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 10030   ins_encode( Push_Reg_D(src1),
 10031               OpcP, RegOpc(src2),
 10032               fpu_flags);
 10033   ins_pipe( pipe_slow );
 10034 %}
 10036 // Compare vs zero into -1,0,1
 10037 instruct cmpD_0(eRegI dst, regD src1, immD0 zero, eAXRegI rax, eFlagsReg cr) %{
 10038   predicate(UseSSE<=1);
 10039   match(Set dst (CmpD3 src1 zero));
 10040   effect(KILL cr, KILL rax);
 10041   ins_cost(280);
 10042   format %{ "FTSTD  $dst,$src1" %}
 10043   opcode(0xE4, 0xD9);
 10044   ins_encode( Push_Reg_D(src1),
 10045               OpcS, OpcP, PopFPU,
 10046               CmpF_Result(dst));
 10047   ins_pipe( pipe_slow );
 10048 %}
 10050 // Compare into -1,0,1
 10051 instruct cmpD_reg(eRegI dst, regD src1, regD src2, eAXRegI rax, eFlagsReg cr) %{
 10052   predicate(UseSSE<=1);
 10053   match(Set dst (CmpD3 src1 src2));
 10054   effect(KILL cr, KILL rax);
 10055   ins_cost(300);
 10056   format %{ "FCMPD  $dst,$src1,$src2" %}
 10057   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 10058   ins_encode( Push_Reg_D(src1),
 10059               OpcP, RegOpc(src2),
 10060               CmpF_Result(dst));
 10061   ins_pipe( pipe_slow );
 10062 %}
 10064 // float compare and set condition codes in EFLAGS by XMM regs
 10065 instruct cmpXD_cc(eFlagsRegU cr, regXD dst, regXD src, eAXRegI rax) %{
 10066   predicate(UseSSE>=2);
 10067   match(Set cr (CmpD dst src));
 10068   effect(KILL rax);
 10069   ins_cost(125);
 10070   format %{ "COMISD $dst,$src\n"
 10071           "\tJNP    exit\n"
 10072           "\tMOV    ah,1       // saw a NaN, set CF\n"
 10073           "\tSAHF\n"
 10074      "exit:\tNOP               // avoid branch to branch" %}
 10075   opcode(0x66, 0x0F, 0x2F);
 10076   ins_encode(OpcP, OpcS, Opcode(tertiary), RegReg(dst, src), cmpF_P6_fixup);
 10077   ins_pipe( pipe_slow );
 10078 %}
 10080 instruct cmpXD_ccCF(eFlagsRegUCF cr, regXD dst, regXD src) %{
 10081   predicate(UseSSE>=2);
 10082   match(Set cr (CmpD dst src));
 10083   ins_cost(100);
 10084   format %{ "COMISD $dst,$src" %}
 10085   opcode(0x66, 0x0F, 0x2F);
 10086   ins_encode(OpcP, OpcS, Opcode(tertiary), RegReg(dst, src));
 10087   ins_pipe( pipe_slow );
 10088 %}
 10090 // float compare and set condition codes in EFLAGS by XMM regs
 10091 instruct cmpXD_ccmem(eFlagsRegU cr, regXD dst, memory src, eAXRegI rax) %{
 10092   predicate(UseSSE>=2);
 10093   match(Set cr (CmpD dst (LoadD src)));
 10094   effect(KILL rax);
 10095   ins_cost(145);
 10096   format %{ "COMISD $dst,$src\n"
 10097           "\tJNP    exit\n"
 10098           "\tMOV    ah,1       // saw a NaN, set CF\n"
 10099           "\tSAHF\n"
 10100      "exit:\tNOP               // avoid branch to branch" %}
 10101   opcode(0x66, 0x0F, 0x2F);
 10102   ins_encode(OpcP, OpcS, Opcode(tertiary), RegMem(dst, src), cmpF_P6_fixup);
 10103   ins_pipe( pipe_slow );
 10104 %}
 10106 instruct cmpXD_ccmemCF(eFlagsRegUCF cr, regXD dst, memory src) %{
 10107   predicate(UseSSE>=2);
 10108   match(Set cr (CmpD dst (LoadD src)));
 10109   ins_cost(100);
 10110   format %{ "COMISD $dst,$src" %}
 10111   opcode(0x66, 0x0F, 0x2F);
 10112   ins_encode(OpcP, OpcS, Opcode(tertiary), RegMem(dst, src));
 10113   ins_pipe( pipe_slow );
 10114 %}
 10116 // Compare into -1,0,1 in XMM
 10117 instruct cmpXD_reg(eRegI dst, regXD src1, regXD src2, eFlagsReg cr) %{
 10118   predicate(UseSSE>=2);
 10119   match(Set dst (CmpD3 src1 src2));
 10120   effect(KILL cr);
 10121   ins_cost(255);
 10122   format %{ "XOR    $dst,$dst\n"
 10123           "\tCOMISD $src1,$src2\n"
 10124           "\tJP,s   nan\n"
 10125           "\tJEQ,s  exit\n"
 10126           "\tJA,s   inc\n"
 10127       "nan:\tDEC    $dst\n"
 10128           "\tJMP,s  exit\n"
 10129       "inc:\tINC    $dst\n"
 10130       "exit:"
 10131                 %}
 10132   opcode(0x66, 0x0F, 0x2F);
 10133   ins_encode(Xor_Reg(dst), OpcP, OpcS, Opcode(tertiary), RegReg(src1, src2),
 10134              CmpX_Result(dst));
 10135   ins_pipe( pipe_slow );
 10136 %}
 10138 // Compare into -1,0,1 in XMM and memory
 10139 instruct cmpXD_regmem(eRegI dst, regXD src1, memory mem, eFlagsReg cr) %{
 10140   predicate(UseSSE>=2);
 10141   match(Set dst (CmpD3 src1 (LoadD mem)));
 10142   effect(KILL cr);
 10143   ins_cost(275);
 10144   format %{ "COMISD $src1,$mem\n"
 10145           "\tMOV    $dst,0\t\t# do not blow flags\n"
 10146           "\tJP,s   nan\n"
 10147           "\tJEQ,s  exit\n"
 10148           "\tJA,s   inc\n"
 10149       "nan:\tDEC    $dst\n"
 10150           "\tJMP,s  exit\n"
 10151       "inc:\tINC    $dst\n"
 10152       "exit:"
 10153                 %}
 10154   opcode(0x66, 0x0F, 0x2F);
 10155   ins_encode(OpcP, OpcS, Opcode(tertiary), RegMem(src1, mem),
 10156              LdImmI(dst,0x0), CmpX_Result(dst));
 10157   ins_pipe( pipe_slow );
 10158 %}
 10161 instruct subD_reg(regD dst, regD src) %{
 10162   predicate (UseSSE <=1);
 10163   match(Set dst (SubD dst src));
 10165   format %{ "FLD    $src\n\t"
 10166             "DSUBp  $dst,ST" %}
 10167   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
 10168   ins_cost(150);
 10169   ins_encode( Push_Reg_D(src),
 10170               OpcP, RegOpc(dst) );
 10171   ins_pipe( fpu_reg_reg );
 10172 %}
 10174 instruct subD_reg_round(stackSlotD dst, regD src1, regD src2) %{
 10175   predicate (UseSSE <=1);
 10176   match(Set dst (RoundDouble (SubD src1 src2)));
 10177   ins_cost(250);
 10179   format %{ "FLD    $src2\n\t"
 10180             "DSUB   ST,$src1\n\t"
 10181             "FSTP_D $dst\t# D-round" %}
 10182   opcode(0xD8, 0x5);
 10183   ins_encode( Push_Reg_D(src2),
 10184               OpcP, RegOpc(src1), Pop_Mem_D(dst) );
 10185   ins_pipe( fpu_mem_reg_reg );
 10186 %}
 10189 instruct subD_reg_mem(regD dst, memory src) %{
 10190   predicate (UseSSE <=1);
 10191   match(Set dst (SubD dst (LoadD src)));
 10192   ins_cost(150);
 10194   format %{ "FLD    $src\n\t"
 10195             "DSUBp  $dst,ST" %}
 10196   opcode(0xDE, 0x5, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
 10197   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
 10198               OpcP, RegOpc(dst) );
 10199   ins_pipe( fpu_reg_mem );
 10200 %}
 10202 instruct absD_reg(regDPR1 dst, regDPR1 src) %{
 10203   predicate (UseSSE<=1);
 10204   match(Set dst (AbsD src));
 10205   ins_cost(100);
 10206   format %{ "FABS" %}
 10207   opcode(0xE1, 0xD9);
 10208   ins_encode( OpcS, OpcP );
 10209   ins_pipe( fpu_reg_reg );
 10210 %}
 10212 instruct absXD_reg( regXD dst ) %{
 10213   predicate(UseSSE>=2);
 10214   match(Set dst (AbsD dst));
 10215   format %{ "ANDPD  $dst,[0x7FFFFFFFFFFFFFFF]\t# ABS D by sign masking" %}
 10216   ins_encode( AbsXD_encoding(dst));
 10217   ins_pipe( pipe_slow );
 10218 %}
 10220 instruct negD_reg(regDPR1 dst, regDPR1 src) %{
 10221   predicate(UseSSE<=1);
 10222   match(Set dst (NegD src));
 10223   ins_cost(100);
 10224   format %{ "FCHS" %}
 10225   opcode(0xE0, 0xD9);
 10226   ins_encode( OpcS, OpcP );
 10227   ins_pipe( fpu_reg_reg );
 10228 %}
 10230 instruct negXD_reg( regXD dst ) %{
 10231   predicate(UseSSE>=2);
 10232   match(Set dst (NegD dst));
 10233   format %{ "XORPD  $dst,[0x8000000000000000]\t# CHS D by sign flipping" %}
 10234   ins_encode %{
 10235      __ xorpd($dst$$XMMRegister,
 10236               ExternalAddress((address)double_signflip_pool));
 10237   %}
 10238   ins_pipe( pipe_slow );
 10239 %}
 10241 instruct addD_reg(regD dst, regD src) %{
 10242   predicate(UseSSE<=1);
 10243   match(Set dst (AddD dst src));
 10244   format %{ "FLD    $src\n\t"
 10245             "DADD   $dst,ST" %}
 10246   size(4);
 10247   ins_cost(150);
 10248   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
 10249   ins_encode( Push_Reg_D(src),
 10250               OpcP, RegOpc(dst) );
 10251   ins_pipe( fpu_reg_reg );
 10252 %}
 10255 instruct addD_reg_round(stackSlotD dst, regD src1, regD src2) %{
 10256   predicate(UseSSE<=1);
 10257   match(Set dst (RoundDouble (AddD src1 src2)));
 10258   ins_cost(250);
 10260   format %{ "FLD    $src2\n\t"
 10261             "DADD   ST,$src1\n\t"
 10262             "FSTP_D $dst\t# D-round" %}
 10263   opcode(0xD8, 0x0); /* D8 C0+i or D8 /0*/
 10264   ins_encode( Push_Reg_D(src2),
 10265               OpcP, RegOpc(src1), Pop_Mem_D(dst) );
 10266   ins_pipe( fpu_mem_reg_reg );
 10267 %}
 10270 instruct addD_reg_mem(regD dst, memory src) %{
 10271   predicate(UseSSE<=1);
 10272   match(Set dst (AddD dst (LoadD src)));
 10273   ins_cost(150);
 10275   format %{ "FLD    $src\n\t"
 10276             "DADDp  $dst,ST" %}
 10277   opcode(0xDE, 0x0, 0xDD); /* DE C0+i */  /* LoadD  DD /0 */
 10278   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
 10279               OpcP, RegOpc(dst) );
 10280   ins_pipe( fpu_reg_mem );
 10281 %}
 10283 // add-to-memory
 10284 instruct addD_mem_reg(memory dst, regD src) %{
 10285   predicate(UseSSE<=1);
 10286   match(Set dst (StoreD dst (RoundDouble (AddD (LoadD dst) src))));
 10287   ins_cost(150);
 10289   format %{ "FLD_D  $dst\n\t"
 10290             "DADD   ST,$src\n\t"
 10291             "FST_D  $dst" %}
 10292   opcode(0xDD, 0x0);
 10293   ins_encode( Opcode(0xDD), RMopc_Mem(0x00,dst),
 10294               Opcode(0xD8), RegOpc(src),
 10295               set_instruction_start,
 10296               Opcode(0xDD), RMopc_Mem(0x03,dst) );
 10297   ins_pipe( fpu_reg_mem );
 10298 %}
 10300 instruct addD_reg_imm1(regD dst, immD1 con) %{
 10301   predicate(UseSSE<=1);
 10302   match(Set dst (AddD dst con));
 10303   ins_cost(125);
 10304   format %{ "FLD1\n\t"
 10305             "DADDp  $dst,ST" %}
 10306   ins_encode %{
 10307     __ fld1();
 10308     __ faddp($dst$$reg);
 10309   %}
 10310   ins_pipe(fpu_reg);
 10311 %}
 10313 instruct addD_reg_imm(regD dst, immD con) %{
 10314   predicate(UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
 10315   match(Set dst (AddD dst con));
 10316   ins_cost(200);
 10317   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
 10318             "DADDp  $dst,ST" %}
 10319   ins_encode %{
 10320     __ fld_d($constantaddress($con));
 10321     __ faddp($dst$$reg);
 10322   %}
 10323   ins_pipe(fpu_reg_mem);
 10324 %}
 10326 instruct addD_reg_imm_round(stackSlotD dst, regD src, immD con) %{
 10327   predicate(UseSSE<=1 && _kids[0]->_kids[1]->_leaf->getd() != 0.0 && _kids[0]->_kids[1]->_leaf->getd() != 1.0 );
 10328   match(Set dst (RoundDouble (AddD src con)));
 10329   ins_cost(200);
 10330   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
 10331             "DADD   ST,$src\n\t"
 10332             "FSTP_D $dst\t# D-round" %}
 10333   ins_encode %{
 10334     __ fld_d($constantaddress($con));
 10335     __ fadd($src$$reg);
 10336     __ fstp_d(Address(rsp, $dst$$disp));
 10337   %}
 10338   ins_pipe(fpu_mem_reg_con);
 10339 %}
 10341 // Add two double precision floating point values in xmm
 10342 instruct addXD_reg(regXD dst, regXD src) %{
 10343   predicate(UseSSE>=2);
 10344   match(Set dst (AddD dst src));
 10345   format %{ "ADDSD  $dst,$src" %}
 10346   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x58), RegReg(dst, src));
 10347   ins_pipe( pipe_slow );
 10348 %}
 10350 instruct addXD_imm(regXD dst, immXD con) %{
 10351   predicate(UseSSE>=2);
 10352   match(Set dst (AddD dst con));
 10353   format %{ "ADDSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
 10354   ins_encode %{
 10355     __ addsd($dst$$XMMRegister, $constantaddress($con));
 10356   %}
 10357   ins_pipe(pipe_slow);
 10358 %}
 10360 instruct addXD_mem(regXD dst, memory mem) %{
 10361   predicate(UseSSE>=2);
 10362   match(Set dst (AddD dst (LoadD mem)));
 10363   format %{ "ADDSD  $dst,$mem" %}
 10364   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x58), RegMem(dst,mem));
 10365   ins_pipe( pipe_slow );
 10366 %}
 10368 // Sub two double precision floating point values in xmm
 10369 instruct subXD_reg(regXD dst, regXD src) %{
 10370   predicate(UseSSE>=2);
 10371   match(Set dst (SubD dst src));
 10372   format %{ "SUBSD  $dst,$src" %}
 10373   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x5C), RegReg(dst, src));
 10374   ins_pipe( pipe_slow );
 10375 %}
 10377 instruct subXD_imm(regXD dst, immXD con) %{
 10378   predicate(UseSSE>=2);
 10379   match(Set dst (SubD dst con));
 10380   format %{ "SUBSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
 10381   ins_encode %{
 10382     __ subsd($dst$$XMMRegister, $constantaddress($con));
 10383   %}
 10384   ins_pipe(pipe_slow);
 10385 %}
 10387 instruct subXD_mem(regXD dst, memory mem) %{
 10388   predicate(UseSSE>=2);
 10389   match(Set dst (SubD dst (LoadD mem)));
 10390   format %{ "SUBSD  $dst,$mem" %}
 10391   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x5C), RegMem(dst,mem));
 10392   ins_pipe( pipe_slow );
 10393 %}
 10395 // Mul two double precision floating point values in xmm
 10396 instruct mulXD_reg(regXD dst, regXD src) %{
 10397   predicate(UseSSE>=2);
 10398   match(Set dst (MulD dst src));
 10399   format %{ "MULSD  $dst,$src" %}
 10400   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x59), RegReg(dst, src));
 10401   ins_pipe( pipe_slow );
 10402 %}
 10404 instruct mulXD_imm(regXD dst, immXD con) %{
 10405   predicate(UseSSE>=2);
 10406   match(Set dst (MulD dst con));
 10407   format %{ "MULSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
 10408   ins_encode %{
 10409     __ mulsd($dst$$XMMRegister, $constantaddress($con));
 10410   %}
 10411   ins_pipe(pipe_slow);
 10412 %}
 10414 instruct mulXD_mem(regXD dst, memory mem) %{
 10415   predicate(UseSSE>=2);
 10416   match(Set dst (MulD dst (LoadD mem)));
 10417   format %{ "MULSD  $dst,$mem" %}
 10418   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x59), RegMem(dst,mem));
 10419   ins_pipe( pipe_slow );
 10420 %}
 10422 // Div two double precision floating point values in xmm
 10423 instruct divXD_reg(regXD dst, regXD src) %{
 10424   predicate(UseSSE>=2);
 10425   match(Set dst (DivD dst src));
 10426   format %{ "DIVSD  $dst,$src" %}
 10427   opcode(0xF2, 0x0F, 0x5E);
 10428   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x5E), RegReg(dst, src));
 10429   ins_pipe( pipe_slow );
 10430 %}
 10432 instruct divXD_imm(regXD dst, immXD con) %{
 10433   predicate(UseSSE>=2);
 10434   match(Set dst (DivD dst con));
 10435   format %{ "DIVSD  $dst,[$constantaddress]\t# load from constant table: double=$con" %}
 10436   ins_encode %{
 10437     __ divsd($dst$$XMMRegister, $constantaddress($con));
 10438   %}
 10439   ins_pipe(pipe_slow);
 10440 %}
 10442 instruct divXD_mem(regXD dst, memory mem) %{
 10443   predicate(UseSSE>=2);
 10444   match(Set dst (DivD dst (LoadD mem)));
 10445   format %{ "DIVSD  $dst,$mem" %}
 10446   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x5E), RegMem(dst,mem));
 10447   ins_pipe( pipe_slow );
 10448 %}
 10451 instruct mulD_reg(regD dst, regD src) %{
 10452   predicate(UseSSE<=1);
 10453   match(Set dst (MulD dst src));
 10454   format %{ "FLD    $src\n\t"
 10455             "DMULp  $dst,ST" %}
 10456   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
 10457   ins_cost(150);
 10458   ins_encode( Push_Reg_D(src),
 10459               OpcP, RegOpc(dst) );
 10460   ins_pipe( fpu_reg_reg );
 10461 %}
 10463 // Strict FP instruction biases argument before multiply then
 10464 // biases result to avoid double rounding of subnormals.
 10465 //
 10466 // scale arg1 by multiplying arg1 by 2^(-15360)
 10467 // load arg2
 10468 // multiply scaled arg1 by arg2
 10469 // rescale product by 2^(15360)
 10470 //
 10471 instruct strictfp_mulD_reg(regDPR1 dst, regnotDPR1 src) %{
 10472   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
 10473   match(Set dst (MulD dst src));
 10474   ins_cost(1);   // Select this instruction for all strict FP double multiplies
 10476   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
 10477             "DMULp  $dst,ST\n\t"
 10478             "FLD    $src\n\t"
 10479             "DMULp  $dst,ST\n\t"
 10480             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
 10481             "DMULp  $dst,ST\n\t" %}
 10482   opcode(0xDE, 0x1); /* DE C8+i or DE /1*/
 10483   ins_encode( strictfp_bias1(dst),
 10484               Push_Reg_D(src),
 10485               OpcP, RegOpc(dst),
 10486               strictfp_bias2(dst) );
 10487   ins_pipe( fpu_reg_reg );
 10488 %}
 10490 instruct mulD_reg_imm(regD dst, immD con) %{
 10491   predicate( UseSSE<=1 && _kids[1]->_leaf->getd() != 0.0 && _kids[1]->_leaf->getd() != 1.0 );
 10492   match(Set dst (MulD dst con));
 10493   ins_cost(200);
 10494   format %{ "FLD_D  [$constantaddress]\t# load from constant table: double=$con\n\t"
 10495             "DMULp  $dst,ST" %}
 10496   ins_encode %{
 10497     __ fld_d($constantaddress($con));
 10498     __ fmulp($dst$$reg);
 10499   %}
 10500   ins_pipe(fpu_reg_mem);
 10501 %}
 10504 instruct mulD_reg_mem(regD dst, memory src) %{
 10505   predicate( UseSSE<=1 );
 10506   match(Set dst (MulD dst (LoadD src)));
 10507   ins_cost(200);
 10508   format %{ "FLD_D  $src\n\t"
 10509             "DMULp  $dst,ST" %}
 10510   opcode(0xDE, 0x1, 0xDD); /* DE C8+i or DE /1*/  /* LoadD  DD /0 */
 10511   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
 10512               OpcP, RegOpc(dst) );
 10513   ins_pipe( fpu_reg_mem );
 10514 %}
 10516 //
 10517 // Cisc-alternate to reg-reg multiply
 10518 instruct mulD_reg_mem_cisc(regD dst, regD src, memory mem) %{
 10519   predicate( UseSSE<=1 );
 10520   match(Set dst (MulD src (LoadD mem)));
 10521   ins_cost(250);
 10522   format %{ "FLD_D  $mem\n\t"
 10523             "DMUL   ST,$src\n\t"
 10524             "FSTP_D $dst" %}
 10525   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadD D9 /0 */
 10526   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem),
 10527               OpcReg_F(src),
 10528               Pop_Reg_D(dst) );
 10529   ins_pipe( fpu_reg_reg_mem );
 10530 %}
 10533 // MACRO3 -- addD a mulD
 10534 // This instruction is a '2-address' instruction in that the result goes
 10535 // back to src2.  This eliminates a move from the macro; possibly the
 10536 // register allocator will have to add it back (and maybe not).
 10537 instruct addD_mulD_reg(regD src2, regD src1, regD src0) %{
 10538   predicate( UseSSE<=1 );
 10539   match(Set src2 (AddD (MulD src0 src1) src2));
 10540   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
 10541             "DMUL   ST,$src1\n\t"
 10542             "DADDp  $src2,ST" %}
 10543   ins_cost(250);
 10544   opcode(0xDD); /* LoadD DD /0 */
 10545   ins_encode( Push_Reg_F(src0),
 10546               FMul_ST_reg(src1),
 10547               FAddP_reg_ST(src2) );
 10548   ins_pipe( fpu_reg_reg_reg );
 10549 %}
 10552 // MACRO3 -- subD a mulD
 10553 instruct subD_mulD_reg(regD src2, regD src1, regD src0) %{
 10554   predicate( UseSSE<=1 );
 10555   match(Set src2 (SubD (MulD src0 src1) src2));
 10556   format %{ "FLD    $src0\t# ===MACRO3d===\n\t"
 10557             "DMUL   ST,$src1\n\t"
 10558             "DSUBRp $src2,ST" %}
 10559   ins_cost(250);
 10560   ins_encode( Push_Reg_F(src0),
 10561               FMul_ST_reg(src1),
 10562               Opcode(0xDE), Opc_plus(0xE0,src2));
 10563   ins_pipe( fpu_reg_reg_reg );
 10564 %}
 10567 instruct divD_reg(regD dst, regD src) %{
 10568   predicate( UseSSE<=1 );
 10569   match(Set dst (DivD dst src));
 10571   format %{ "FLD    $src\n\t"
 10572             "FDIVp  $dst,ST" %}
 10573   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 10574   ins_cost(150);
 10575   ins_encode( Push_Reg_D(src),
 10576               OpcP, RegOpc(dst) );
 10577   ins_pipe( fpu_reg_reg );
 10578 %}
 10580 // Strict FP instruction biases argument before division then
 10581 // biases result, to avoid double rounding of subnormals.
 10582 //
 10583 // scale dividend by multiplying dividend by 2^(-15360)
 10584 // load divisor
 10585 // divide scaled dividend by divisor
 10586 // rescale quotient by 2^(15360)
 10587 //
 10588 instruct strictfp_divD_reg(regDPR1 dst, regnotDPR1 src) %{
 10589   predicate (UseSSE<=1);
 10590   match(Set dst (DivD dst src));
 10591   predicate( UseSSE<=1 && Compile::current()->has_method() && Compile::current()->method()->is_strict() );
 10592   ins_cost(01);
 10594   format %{ "FLD    StubRoutines::_fpu_subnormal_bias1\n\t"
 10595             "DMULp  $dst,ST\n\t"
 10596             "FLD    $src\n\t"
 10597             "FDIVp  $dst,ST\n\t"
 10598             "FLD    StubRoutines::_fpu_subnormal_bias2\n\t"
 10599             "DMULp  $dst,ST\n\t" %}
 10600   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 10601   ins_encode( strictfp_bias1(dst),
 10602               Push_Reg_D(src),
 10603               OpcP, RegOpc(dst),
 10604               strictfp_bias2(dst) );
 10605   ins_pipe( fpu_reg_reg );
 10606 %}
 10608 instruct divD_reg_round(stackSlotD dst, regD src1, regD src2) %{
 10609   predicate( UseSSE<=1 && !(Compile::current()->has_method() && Compile::current()->method()->is_strict()) );
 10610   match(Set dst (RoundDouble (DivD src1 src2)));
 10612   format %{ "FLD    $src1\n\t"
 10613             "FDIV   ST,$src2\n\t"
 10614             "FSTP_D $dst\t# D-round" %}
 10615   opcode(0xD8, 0x6); /* D8 F0+i or D8 /6 */
 10616   ins_encode( Push_Reg_D(src1),
 10617               OpcP, RegOpc(src2), Pop_Mem_D(dst) );
 10618   ins_pipe( fpu_mem_reg_reg );
 10619 %}
 10622 instruct modD_reg(regD dst, regD src, eAXRegI rax, eFlagsReg cr) %{
 10623   predicate(UseSSE<=1);
 10624   match(Set dst (ModD dst src));
 10625   effect(KILL rax, KILL cr); // emitModD() uses EAX and EFLAGS
 10627   format %{ "DMOD   $dst,$src" %}
 10628   ins_cost(250);
 10629   ins_encode(Push_Reg_Mod_D(dst, src),
 10630               emitModD(),
 10631               Push_Result_Mod_D(src),
 10632               Pop_Reg_D(dst));
 10633   ins_pipe( pipe_slow );
 10634 %}
 10636 instruct modXD_reg(regXD dst, regXD src0, regXD src1, eAXRegI rax, eFlagsReg cr) %{
 10637   predicate(UseSSE>=2);
 10638   match(Set dst (ModD src0 src1));
 10639   effect(KILL rax, KILL cr);
 10641   format %{ "SUB    ESP,8\t # DMOD\n"
 10642           "\tMOVSD  [ESP+0],$src1\n"
 10643           "\tFLD_D  [ESP+0]\n"
 10644           "\tMOVSD  [ESP+0],$src0\n"
 10645           "\tFLD_D  [ESP+0]\n"
 10646      "loop:\tFPREM\n"
 10647           "\tFWAIT\n"
 10648           "\tFNSTSW AX\n"
 10649           "\tSAHF\n"
 10650           "\tJP     loop\n"
 10651           "\tFSTP_D [ESP+0]\n"
 10652           "\tMOVSD  $dst,[ESP+0]\n"
 10653           "\tADD    ESP,8\n"
 10654           "\tFSTP   ST0\t # Restore FPU Stack"
 10655     %}
 10656   ins_cost(250);
 10657   ins_encode( Push_ModD_encoding(src0, src1), emitModD(), Push_ResultXD(dst), PopFPU);
 10658   ins_pipe( pipe_slow );
 10659 %}
 10661 instruct sinD_reg(regDPR1 dst, regDPR1 src) %{
 10662   predicate (UseSSE<=1);
 10663   match(Set dst (SinD src));
 10664   ins_cost(1800);
 10665   format %{ "DSIN   $dst" %}
 10666   opcode(0xD9, 0xFE);
 10667   ins_encode( OpcP, OpcS );
 10668   ins_pipe( pipe_slow );
 10669 %}
 10671 instruct sinXD_reg(regXD dst, eFlagsReg cr) %{
 10672   predicate (UseSSE>=2);
 10673   match(Set dst (SinD dst));
 10674   effect(KILL cr); // Push_{Src|Result}XD() uses "{SUB|ADD} ESP,8"
 10675   ins_cost(1800);
 10676   format %{ "DSIN   $dst" %}
 10677   opcode(0xD9, 0xFE);
 10678   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
 10679   ins_pipe( pipe_slow );
 10680 %}
 10682 instruct cosD_reg(regDPR1 dst, regDPR1 src) %{
 10683   predicate (UseSSE<=1);
 10684   match(Set dst (CosD src));
 10685   ins_cost(1800);
 10686   format %{ "DCOS   $dst" %}
 10687   opcode(0xD9, 0xFF);
 10688   ins_encode( OpcP, OpcS );
 10689   ins_pipe( pipe_slow );
 10690 %}
 10692 instruct cosXD_reg(regXD dst, eFlagsReg cr) %{
 10693   predicate (UseSSE>=2);
 10694   match(Set dst (CosD dst));
 10695   effect(KILL cr); // Push_{Src|Result}XD() uses "{SUB|ADD} ESP,8"
 10696   ins_cost(1800);
 10697   format %{ "DCOS   $dst" %}
 10698   opcode(0xD9, 0xFF);
 10699   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
 10700   ins_pipe( pipe_slow );
 10701 %}
 10703 instruct tanD_reg(regDPR1 dst, regDPR1 src) %{
 10704   predicate (UseSSE<=1);
 10705   match(Set dst(TanD src));
 10706   format %{ "DTAN   $dst" %}
 10707   ins_encode( Opcode(0xD9), Opcode(0xF2),    // fptan
 10708               Opcode(0xDD), Opcode(0xD8));   // fstp st
 10709   ins_pipe( pipe_slow );
 10710 %}
 10712 instruct tanXD_reg(regXD dst, eFlagsReg cr) %{
 10713   predicate (UseSSE>=2);
 10714   match(Set dst(TanD dst));
 10715   effect(KILL cr); // Push_{Src|Result}XD() uses "{SUB|ADD} ESP,8"
 10716   format %{ "DTAN   $dst" %}
 10717   ins_encode( Push_SrcXD(dst),
 10718               Opcode(0xD9), Opcode(0xF2),    // fptan
 10719               Opcode(0xDD), Opcode(0xD8),   // fstp st
 10720               Push_ResultXD(dst) );
 10721   ins_pipe( pipe_slow );
 10722 %}
 10724 instruct atanD_reg(regD dst, regD src) %{
 10725   predicate (UseSSE<=1);
 10726   match(Set dst(AtanD dst src));
 10727   format %{ "DATA   $dst,$src" %}
 10728   opcode(0xD9, 0xF3);
 10729   ins_encode( Push_Reg_D(src),
 10730               OpcP, OpcS, RegOpc(dst) );
 10731   ins_pipe( pipe_slow );
 10732 %}
 10734 instruct atanXD_reg(regXD dst, regXD src, eFlagsReg cr) %{
 10735   predicate (UseSSE>=2);
 10736   match(Set dst(AtanD dst src));
 10737   effect(KILL cr); // Push_{Src|Result}XD() uses "{SUB|ADD} ESP,8"
 10738   format %{ "DATA   $dst,$src" %}
 10739   opcode(0xD9, 0xF3);
 10740   ins_encode( Push_SrcXD(src),
 10741               OpcP, OpcS, Push_ResultXD(dst) );
 10742   ins_pipe( pipe_slow );
 10743 %}
 10745 instruct sqrtD_reg(regD dst, regD src) %{
 10746   predicate (UseSSE<=1);
 10747   match(Set dst (SqrtD src));
 10748   format %{ "DSQRT  $dst,$src" %}
 10749   opcode(0xFA, 0xD9);
 10750   ins_encode( Push_Reg_D(src),
 10751               OpcS, OpcP, Pop_Reg_D(dst) );
 10752   ins_pipe( pipe_slow );
 10753 %}
 10755 instruct powD_reg(regD X, regDPR1 Y, eAXRegI rax, eBXRegI rbx, eCXRegI rcx) %{
 10756   predicate (UseSSE<=1);
 10757   match(Set Y (PowD X Y));  // Raise X to the Yth power
 10758   effect(KILL rax, KILL rbx, KILL rcx);
 10759   format %{ "SUB    ESP,8\t\t# Fast-path POW encoding\n\t"
 10760             "FLD_D  $X\n\t"
 10761             "FYL2X  \t\t\t# Q=Y*ln2(X)\n\t"
 10763             "FDUP   \t\t\t# Q Q\n\t"
 10764             "FRNDINT\t\t\t# int(Q) Q\n\t"
 10765             "FSUB   ST(1),ST(0)\t# int(Q) frac(Q)\n\t"
 10766             "FISTP  dword [ESP]\n\t"
 10767             "F2XM1  \t\t\t# 2^frac(Q)-1 int(Q)\n\t"
 10768             "FLD1   \t\t\t# 1 2^frac(Q)-1 int(Q)\n\t"
 10769             "FADDP  \t\t\t# 2^frac(Q) int(Q)\n\t" // could use FADD [1.000] instead
 10770             "MOV    EAX,[ESP]\t# Pick up int(Q)\n\t"
 10771             "MOV    ECX,0xFFFFF800\t# Overflow mask\n\t"
 10772             "ADD    EAX,1023\t\t# Double exponent bias\n\t"
 10773             "MOV    EBX,EAX\t\t# Preshifted biased expo\n\t"
 10774             "SHL    EAX,20\t\t# Shift exponent into place\n\t"
 10775             "TEST   EBX,ECX\t\t# Check for overflow\n\t"
 10776             "CMOVne EAX,ECX\t\t# If overflow, stuff NaN into EAX\n\t"
 10777             "MOV    [ESP+4],EAX\t# Marshal 64-bit scaling double\n\t"
 10778             "MOV    [ESP+0],0\n\t"
 10779             "FMUL   ST(0),[ESP+0]\t# Scale\n\t"
 10781             "ADD    ESP,8"
 10782              %}
 10783   ins_encode( push_stack_temp_qword,
 10784               Push_Reg_D(X),
 10785               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10786               pow_exp_core_encoding,
 10787               pop_stack_temp_qword);
 10788   ins_pipe( pipe_slow );
 10789 %}
 10791 instruct powXD_reg(regXD dst, regXD src0, regXD src1, regDPR1 tmp1, eAXRegI rax, eBXRegI rbx, eCXRegI rcx ) %{
 10792   predicate (UseSSE>=2);
 10793   match(Set dst (PowD src0 src1));  // Raise src0 to the src1'th power
 10794   effect(KILL tmp1, KILL rax, KILL rbx, KILL rcx );
 10795   format %{ "SUB    ESP,8\t\t# Fast-path POW encoding\n\t"
 10796             "MOVSD  [ESP],$src1\n\t"
 10797             "FLD    FPR1,$src1\n\t"
 10798             "MOVSD  [ESP],$src0\n\t"
 10799             "FLD    FPR1,$src0\n\t"
 10800             "FYL2X  \t\t\t# Q=Y*ln2(X)\n\t"
 10802             "FDUP   \t\t\t# Q Q\n\t"
 10803             "FRNDINT\t\t\t# int(Q) Q\n\t"
 10804             "FSUB   ST(1),ST(0)\t# int(Q) frac(Q)\n\t"
 10805             "FISTP  dword [ESP]\n\t"
 10806             "F2XM1  \t\t\t# 2^frac(Q)-1 int(Q)\n\t"
 10807             "FLD1   \t\t\t# 1 2^frac(Q)-1 int(Q)\n\t"
 10808             "FADDP  \t\t\t# 2^frac(Q) int(Q)\n\t" // could use FADD [1.000] instead
 10809             "MOV    EAX,[ESP]\t# Pick up int(Q)\n\t"
 10810             "MOV    ECX,0xFFFFF800\t# Overflow mask\n\t"
 10811             "ADD    EAX,1023\t\t# Double exponent bias\n\t"
 10812             "MOV    EBX,EAX\t\t# Preshifted biased expo\n\t"
 10813             "SHL    EAX,20\t\t# Shift exponent into place\n\t"
 10814             "TEST   EBX,ECX\t\t# Check for overflow\n\t"
 10815             "CMOVne EAX,ECX\t\t# If overflow, stuff NaN into EAX\n\t"
 10816             "MOV    [ESP+4],EAX\t# Marshal 64-bit scaling double\n\t"
 10817             "MOV    [ESP+0],0\n\t"
 10818             "FMUL   ST(0),[ESP+0]\t# Scale\n\t"
 10820             "FST_D  [ESP]\n\t"
 10821             "MOVSD  $dst,[ESP]\n\t"
 10822             "ADD    ESP,8"
 10823              %}
 10824   ins_encode( push_stack_temp_qword,
 10825               push_xmm_to_fpr1(src1),
 10826               push_xmm_to_fpr1(src0),
 10827               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10828               pow_exp_core_encoding,
 10829               Push_ResultXD(dst) );
 10830   ins_pipe( pipe_slow );
 10831 %}
 10834 instruct expD_reg(regDPR1 dpr1, eAXRegI rax, eBXRegI rbx, eCXRegI rcx) %{
 10835   predicate (UseSSE<=1);
 10836   match(Set dpr1 (ExpD dpr1));
 10837   effect(KILL rax, KILL rbx, KILL rcx);
 10838   format %{ "SUB    ESP,8\t\t# Fast-path EXP encoding"
 10839             "FLDL2E \t\t\t# Ld log2(e) X\n\t"
 10840             "FMULP  \t\t\t# Q=X*log2(e)\n\t"
 10842             "FDUP   \t\t\t# Q Q\n\t"
 10843             "FRNDINT\t\t\t# int(Q) Q\n\t"
 10844             "FSUB   ST(1),ST(0)\t# int(Q) frac(Q)\n\t"
 10845             "FISTP  dword [ESP]\n\t"
 10846             "F2XM1  \t\t\t# 2^frac(Q)-1 int(Q)\n\t"
 10847             "FLD1   \t\t\t# 1 2^frac(Q)-1 int(Q)\n\t"
 10848             "FADDP  \t\t\t# 2^frac(Q) int(Q)\n\t" // could use FADD [1.000] instead
 10849             "MOV    EAX,[ESP]\t# Pick up int(Q)\n\t"
 10850             "MOV    ECX,0xFFFFF800\t# Overflow mask\n\t"
 10851             "ADD    EAX,1023\t\t# Double exponent bias\n\t"
 10852             "MOV    EBX,EAX\t\t# Preshifted biased expo\n\t"
 10853             "SHL    EAX,20\t\t# Shift exponent into place\n\t"
 10854             "TEST   EBX,ECX\t\t# Check for overflow\n\t"
 10855             "CMOVne EAX,ECX\t\t# If overflow, stuff NaN into EAX\n\t"
 10856             "MOV    [ESP+4],EAX\t# Marshal 64-bit scaling double\n\t"
 10857             "MOV    [ESP+0],0\n\t"
 10858             "FMUL   ST(0),[ESP+0]\t# Scale\n\t"
 10860             "ADD    ESP,8"
 10861              %}
 10862   ins_encode( push_stack_temp_qword,
 10863               Opcode(0xD9), Opcode(0xEA),   // fldl2e
 10864               Opcode(0xDE), Opcode(0xC9),   // fmulp
 10865               pow_exp_core_encoding,
 10866               pop_stack_temp_qword);
 10867   ins_pipe( pipe_slow );
 10868 %}
 10870 instruct expXD_reg(regXD dst, regXD src, regDPR1 tmp1, eAXRegI rax, eBXRegI rbx, eCXRegI rcx) %{
 10871   predicate (UseSSE>=2);
 10872   match(Set dst (ExpD src));
 10873   effect(KILL tmp1, KILL rax, KILL rbx, KILL rcx);
 10874   format %{ "SUB    ESP,8\t\t# Fast-path EXP encoding\n\t"
 10875             "MOVSD  [ESP],$src\n\t"
 10876             "FLDL2E \t\t\t# Ld log2(e) X\n\t"
 10877             "FMULP  \t\t\t# Q=X*log2(e) X\n\t"
 10879             "FDUP   \t\t\t# Q Q\n\t"
 10880             "FRNDINT\t\t\t# int(Q) Q\n\t"
 10881             "FSUB   ST(1),ST(0)\t# int(Q) frac(Q)\n\t"
 10882             "FISTP  dword [ESP]\n\t"
 10883             "F2XM1  \t\t\t# 2^frac(Q)-1 int(Q)\n\t"
 10884             "FLD1   \t\t\t# 1 2^frac(Q)-1 int(Q)\n\t"
 10885             "FADDP  \t\t\t# 2^frac(Q) int(Q)\n\t" // could use FADD [1.000] instead
 10886             "MOV    EAX,[ESP]\t# Pick up int(Q)\n\t"
 10887             "MOV    ECX,0xFFFFF800\t# Overflow mask\n\t"
 10888             "ADD    EAX,1023\t\t# Double exponent bias\n\t"
 10889             "MOV    EBX,EAX\t\t# Preshifted biased expo\n\t"
 10890             "SHL    EAX,20\t\t# Shift exponent into place\n\t"
 10891             "TEST   EBX,ECX\t\t# Check for overflow\n\t"
 10892             "CMOVne EAX,ECX\t\t# If overflow, stuff NaN into EAX\n\t"
 10893             "MOV    [ESP+4],EAX\t# Marshal 64-bit scaling double\n\t"
 10894             "MOV    [ESP+0],0\n\t"
 10895             "FMUL   ST(0),[ESP+0]\t# Scale\n\t"
 10897             "FST_D  [ESP]\n\t"
 10898             "MOVSD  $dst,[ESP]\n\t"
 10899             "ADD    ESP,8"
 10900              %}
 10901   ins_encode( Push_SrcXD(src),
 10902               Opcode(0xD9), Opcode(0xEA),   // fldl2e
 10903               Opcode(0xDE), Opcode(0xC9),   // fmulp
 10904               pow_exp_core_encoding,
 10905               Push_ResultXD(dst) );
 10906   ins_pipe( pipe_slow );
 10907 %}
 10911 instruct log10D_reg(regDPR1 dst, regDPR1 src) %{
 10912   predicate (UseSSE<=1);
 10913   // The source Double operand on FPU stack
 10914   match(Set dst (Log10D src));
 10915   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
 10916   // fxch         ; swap ST(0) with ST(1)
 10917   // fyl2x        ; compute log_10(2) * log_2(x)
 10918   format %{ "FLDLG2 \t\t\t#Log10\n\t"
 10919             "FXCH   \n\t"
 10920             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
 10921          %}
 10922   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
 10923               Opcode(0xD9), Opcode(0xC9),   // fxch
 10924               Opcode(0xD9), Opcode(0xF1));  // fyl2x
 10926   ins_pipe( pipe_slow );
 10927 %}
 10929 instruct log10XD_reg(regXD dst, regXD src, eFlagsReg cr) %{
 10930   predicate (UseSSE>=2);
 10931   effect(KILL cr);
 10932   match(Set dst (Log10D src));
 10933   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
 10934   // fyl2x        ; compute log_10(2) * log_2(x)
 10935   format %{ "FLDLG2 \t\t\t#Log10\n\t"
 10936             "FYL2X  \t\t\t# Q=Log10*Log_2(x)"
 10937          %}
 10938   ins_encode( Opcode(0xD9), Opcode(0xEC),   // fldlg2
 10939               Push_SrcXD(src),
 10940               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10941               Push_ResultXD(dst));
 10943   ins_pipe( pipe_slow );
 10944 %}
 10946 instruct logD_reg(regDPR1 dst, regDPR1 src) %{
 10947   predicate (UseSSE<=1);
 10948   // The source Double operand on FPU stack
 10949   match(Set dst (LogD src));
 10950   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
 10951   // fxch         ; swap ST(0) with ST(1)
 10952   // fyl2x        ; compute log_e(2) * log_2(x)
 10953   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
 10954             "FXCH   \n\t"
 10955             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
 10956          %}
 10957   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
 10958               Opcode(0xD9), Opcode(0xC9),   // fxch
 10959               Opcode(0xD9), Opcode(0xF1));  // fyl2x
 10961   ins_pipe( pipe_slow );
 10962 %}
 10964 instruct logXD_reg(regXD dst, regXD src, eFlagsReg cr) %{
 10965   predicate (UseSSE>=2);
 10966   effect(KILL cr);
 10967   // The source and result Double operands in XMM registers
 10968   match(Set dst (LogD src));
 10969   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
 10970   // fyl2x        ; compute log_e(2) * log_2(x)
 10971   format %{ "FLDLN2 \t\t\t#Log_e\n\t"
 10972             "FYL2X  \t\t\t# Q=Log_e*Log_2(x)"
 10973          %}
 10974   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
 10975               Push_SrcXD(src),
 10976               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10977               Push_ResultXD(dst));
 10978   ins_pipe( pipe_slow );
 10979 %}
 10981 //-------------Float Instructions-------------------------------
 10982 // Float Math
 10984 // Code for float compare:
 10985 //     fcompp();
 10986 //     fwait(); fnstsw_ax();
 10987 //     sahf();
 10988 //     movl(dst, unordered_result);
 10989 //     jcc(Assembler::parity, exit);
 10990 //     movl(dst, less_result);
 10991 //     jcc(Assembler::below, exit);
 10992 //     movl(dst, equal_result);
 10993 //     jcc(Assembler::equal, exit);
 10994 //     movl(dst, greater_result);
 10995 //   exit:
 10997 // P6 version of float compare, sets condition codes in EFLAGS
 10998 instruct cmpF_cc_P6(eFlagsRegU cr, regF src1, regF src2, eAXRegI rax) %{
 10999   predicate(VM_Version::supports_cmov() && UseSSE == 0);
 11000   match(Set cr (CmpF src1 src2));
 11001   effect(KILL rax);
 11002   ins_cost(150);
 11003   format %{ "FLD    $src1\n\t"
 11004             "FUCOMIP ST,$src2  // P6 instruction\n\t"
 11005             "JNP    exit\n\t"
 11006             "MOV    ah,1       // saw a NaN, set CF (treat as LT)\n\t"
 11007             "SAHF\n"
 11008      "exit:\tNOP               // avoid branch to branch" %}
 11009   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
 11010   ins_encode( Push_Reg_D(src1),
 11011               OpcP, RegOpc(src2),
 11012               cmpF_P6_fixup );
 11013   ins_pipe( pipe_slow );
 11014 %}
 11016 instruct cmpF_cc_P6CF(eFlagsRegUCF cr, regF src1, regF src2) %{
 11017   predicate(VM_Version::supports_cmov() && UseSSE == 0);
 11018   match(Set cr (CmpF src1 src2));
 11019   ins_cost(100);
 11020   format %{ "FLD    $src1\n\t"
 11021             "FUCOMIP ST,$src2  // P6 instruction" %}
 11022   opcode(0xDF, 0x05); /* DF E8+i or DF /5 */
 11023   ins_encode( Push_Reg_D(src1),
 11024               OpcP, RegOpc(src2));
 11025   ins_pipe( pipe_slow );
 11026 %}
 11029 // Compare & branch
 11030 instruct cmpF_cc(eFlagsRegU cr, regF src1, regF src2, eAXRegI rax) %{
 11031   predicate(UseSSE == 0);
 11032   match(Set cr (CmpF src1 src2));
 11033   effect(KILL rax);
 11034   ins_cost(200);
 11035   format %{ "FLD    $src1\n\t"
 11036             "FCOMp  $src2\n\t"
 11037             "FNSTSW AX\n\t"
 11038             "TEST   AX,0x400\n\t"
 11039             "JZ,s   flags\n\t"
 11040             "MOV    AH,1\t# unordered treat as LT\n"
 11041     "flags:\tSAHF" %}
 11042   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 11043   ins_encode( Push_Reg_D(src1),
 11044               OpcP, RegOpc(src2),
 11045               fpu_flags);
 11046   ins_pipe( pipe_slow );
 11047 %}
 11049 // Compare vs zero into -1,0,1
 11050 instruct cmpF_0(eRegI dst, regF src1, immF0 zero, eAXRegI rax, eFlagsReg cr) %{
 11051   predicate(UseSSE == 0);
 11052   match(Set dst (CmpF3 src1 zero));
 11053   effect(KILL cr, KILL rax);
 11054   ins_cost(280);
 11055   format %{ "FTSTF  $dst,$src1" %}
 11056   opcode(0xE4, 0xD9);
 11057   ins_encode( Push_Reg_D(src1),
 11058               OpcS, OpcP, PopFPU,
 11059               CmpF_Result(dst));
 11060   ins_pipe( pipe_slow );
 11061 %}
 11063 // Compare into -1,0,1
 11064 instruct cmpF_reg(eRegI dst, regF src1, regF src2, eAXRegI rax, eFlagsReg cr) %{
 11065   predicate(UseSSE == 0);
 11066   match(Set dst (CmpF3 src1 src2));
 11067   effect(KILL cr, KILL rax);
 11068   ins_cost(300);
 11069   format %{ "FCMPF  $dst,$src1,$src2" %}
 11070   opcode(0xD8, 0x3); /* D8 D8+i or D8 /3 */
 11071   ins_encode( Push_Reg_D(src1),
 11072               OpcP, RegOpc(src2),
 11073               CmpF_Result(dst));
 11074   ins_pipe( pipe_slow );
 11075 %}
 11077 // float compare and set condition codes in EFLAGS by XMM regs
 11078 instruct cmpX_cc(eFlagsRegU cr, regX dst, regX src, eAXRegI rax) %{
 11079   predicate(UseSSE>=1);
 11080   match(Set cr (CmpF dst src));
 11081   effect(KILL rax);
 11082   ins_cost(145);
 11083   format %{ "COMISS $dst,$src\n"
 11084           "\tJNP    exit\n"
 11085           "\tMOV    ah,1       // saw a NaN, set CF\n"
 11086           "\tSAHF\n"
 11087      "exit:\tNOP               // avoid branch to branch" %}
 11088   opcode(0x0F, 0x2F);
 11089   ins_encode(OpcP, OpcS, RegReg(dst, src), cmpF_P6_fixup);
 11090   ins_pipe( pipe_slow );
 11091 %}
 11093 instruct cmpX_ccCF(eFlagsRegUCF cr, regX dst, regX src) %{
 11094   predicate(UseSSE>=1);
 11095   match(Set cr (CmpF dst src));
 11096   ins_cost(100);
 11097   format %{ "COMISS $dst,$src" %}
 11098   opcode(0x0F, 0x2F);
 11099   ins_encode(OpcP, OpcS, RegReg(dst, src));
 11100   ins_pipe( pipe_slow );
 11101 %}
 11103 // float compare and set condition codes in EFLAGS by XMM regs
 11104 instruct cmpX_ccmem(eFlagsRegU cr, regX dst, memory src, eAXRegI rax) %{
 11105   predicate(UseSSE>=1);
 11106   match(Set cr (CmpF dst (LoadF src)));
 11107   effect(KILL rax);
 11108   ins_cost(165);
 11109   format %{ "COMISS $dst,$src\n"
 11110           "\tJNP    exit\n"
 11111           "\tMOV    ah,1       // saw a NaN, set CF\n"
 11112           "\tSAHF\n"
 11113      "exit:\tNOP               // avoid branch to branch" %}
 11114   opcode(0x0F, 0x2F);
 11115   ins_encode(OpcP, OpcS, RegMem(dst, src), cmpF_P6_fixup);
 11116   ins_pipe( pipe_slow );
 11117 %}
 11119 instruct cmpX_ccmemCF(eFlagsRegUCF cr, regX dst, memory src) %{
 11120   predicate(UseSSE>=1);
 11121   match(Set cr (CmpF dst (LoadF src)));
 11122   ins_cost(100);
 11123   format %{ "COMISS $dst,$src" %}
 11124   opcode(0x0F, 0x2F);
 11125   ins_encode(OpcP, OpcS, RegMem(dst, src));
 11126   ins_pipe( pipe_slow );
 11127 %}
 11129 // Compare into -1,0,1 in XMM
 11130 instruct cmpX_reg(eRegI dst, regX src1, regX src2, eFlagsReg cr) %{
 11131   predicate(UseSSE>=1);
 11132   match(Set dst (CmpF3 src1 src2));
 11133   effect(KILL cr);
 11134   ins_cost(255);
 11135   format %{ "XOR    $dst,$dst\n"
 11136           "\tCOMISS $src1,$src2\n"
 11137           "\tJP,s   nan\n"
 11138           "\tJEQ,s  exit\n"
 11139           "\tJA,s   inc\n"
 11140       "nan:\tDEC    $dst\n"
 11141           "\tJMP,s  exit\n"
 11142       "inc:\tINC    $dst\n"
 11143       "exit:"
 11144                 %}
 11145   opcode(0x0F, 0x2F);
 11146   ins_encode(Xor_Reg(dst), OpcP, OpcS, RegReg(src1, src2), CmpX_Result(dst));
 11147   ins_pipe( pipe_slow );
 11148 %}
 11150 // Compare into -1,0,1 in XMM and memory
 11151 instruct cmpX_regmem(eRegI dst, regX src1, memory mem, eFlagsReg cr) %{
 11152   predicate(UseSSE>=1);
 11153   match(Set dst (CmpF3 src1 (LoadF mem)));
 11154   effect(KILL cr);
 11155   ins_cost(275);
 11156   format %{ "COMISS $src1,$mem\n"
 11157           "\tMOV    $dst,0\t\t# do not blow flags\n"
 11158           "\tJP,s   nan\n"
 11159           "\tJEQ,s  exit\n"
 11160           "\tJA,s   inc\n"
 11161       "nan:\tDEC    $dst\n"
 11162           "\tJMP,s  exit\n"
 11163       "inc:\tINC    $dst\n"
 11164       "exit:"
 11165                 %}
 11166   opcode(0x0F, 0x2F);
 11167   ins_encode(OpcP, OpcS, RegMem(src1, mem), LdImmI(dst,0x0), CmpX_Result(dst));
 11168   ins_pipe( pipe_slow );
 11169 %}
 11171 // Spill to obtain 24-bit precision
 11172 instruct subF24_reg(stackSlotF dst, regF src1, regF src2) %{
 11173   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11174   match(Set dst (SubF src1 src2));
 11176   format %{ "FSUB   $dst,$src1 - $src2" %}
 11177   opcode(0xD8, 0x4); /* D8 E0+i or D8 /4 mod==0x3 ;; result in TOS */
 11178   ins_encode( Push_Reg_F(src1),
 11179               OpcReg_F(src2),
 11180               Pop_Mem_F(dst) );
 11181   ins_pipe( fpu_mem_reg_reg );
 11182 %}
 11183 //
 11184 // This instruction does not round to 24-bits
 11185 instruct subF_reg(regF dst, regF src) %{
 11186   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11187   match(Set dst (SubF dst src));
 11189   format %{ "FSUB   $dst,$src" %}
 11190   opcode(0xDE, 0x5); /* DE E8+i  or DE /5 */
 11191   ins_encode( Push_Reg_F(src),
 11192               OpcP, RegOpc(dst) );
 11193   ins_pipe( fpu_reg_reg );
 11194 %}
 11196 // Spill to obtain 24-bit precision
 11197 instruct addF24_reg(stackSlotF dst, regF src1, regF src2) %{
 11198   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11199   match(Set dst (AddF src1 src2));
 11201   format %{ "FADD   $dst,$src1,$src2" %}
 11202   opcode(0xD8, 0x0); /* D8 C0+i */
 11203   ins_encode( Push_Reg_F(src2),
 11204               OpcReg_F(src1),
 11205               Pop_Mem_F(dst) );
 11206   ins_pipe( fpu_mem_reg_reg );
 11207 %}
 11208 //
 11209 // This instruction does not round to 24-bits
 11210 instruct addF_reg(regF dst, regF src) %{
 11211   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11212   match(Set dst (AddF dst src));
 11214   format %{ "FLD    $src\n\t"
 11215             "FADDp  $dst,ST" %}
 11216   opcode(0xDE, 0x0); /* DE C0+i or DE /0*/
 11217   ins_encode( Push_Reg_F(src),
 11218               OpcP, RegOpc(dst) );
 11219   ins_pipe( fpu_reg_reg );
 11220 %}
 11222 // Add two single precision floating point values in xmm
 11223 instruct addX_reg(regX dst, regX src) %{
 11224   predicate(UseSSE>=1);
 11225   match(Set dst (AddF dst src));
 11226   format %{ "ADDSS  $dst,$src" %}
 11227   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x58), RegReg(dst, src));
 11228   ins_pipe( pipe_slow );
 11229 %}
 11231 instruct addX_imm(regX dst, immXF con) %{
 11232   predicate(UseSSE>=1);
 11233   match(Set dst (AddF dst con));
 11234   format %{ "ADDSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
 11235   ins_encode %{
 11236     __ addss($dst$$XMMRegister, $constantaddress($con));
 11237   %}
 11238   ins_pipe(pipe_slow);
 11239 %}
 11241 instruct addX_mem(regX dst, memory mem) %{
 11242   predicate(UseSSE>=1);
 11243   match(Set dst (AddF dst (LoadF mem)));
 11244   format %{ "ADDSS  $dst,$mem" %}
 11245   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x58), RegMem(dst, mem));
 11246   ins_pipe( pipe_slow );
 11247 %}
 11249 // Subtract two single precision floating point values in xmm
 11250 instruct subX_reg(regX dst, regX src) %{
 11251   predicate(UseSSE>=1);
 11252   match(Set dst (SubF dst src));
 11253   format %{ "SUBSS  $dst,$src" %}
 11254   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x5C), RegReg(dst, src));
 11255   ins_pipe( pipe_slow );
 11256 %}
 11258 instruct subX_imm(regX dst, immXF con) %{
 11259   predicate(UseSSE>=1);
 11260   match(Set dst (SubF dst con));
 11261   format %{ "SUBSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
 11262   ins_encode %{
 11263     __ subss($dst$$XMMRegister, $constantaddress($con));
 11264   %}
 11265   ins_pipe(pipe_slow);
 11266 %}
 11268 instruct subX_mem(regX dst, memory mem) %{
 11269   predicate(UseSSE>=1);
 11270   match(Set dst (SubF dst (LoadF mem)));
 11271   format %{ "SUBSS  $dst,$mem" %}
 11272   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x5C), RegMem(dst,mem));
 11273   ins_pipe( pipe_slow );
 11274 %}
 11276 // Multiply two single precision floating point values in xmm
 11277 instruct mulX_reg(regX dst, regX src) %{
 11278   predicate(UseSSE>=1);
 11279   match(Set dst (MulF dst src));
 11280   format %{ "MULSS  $dst,$src" %}
 11281   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x59), RegReg(dst, src));
 11282   ins_pipe( pipe_slow );
 11283 %}
 11285 instruct mulX_imm(regX dst, immXF con) %{
 11286   predicate(UseSSE>=1);
 11287   match(Set dst (MulF dst con));
 11288   format %{ "MULSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
 11289   ins_encode %{
 11290     __ mulss($dst$$XMMRegister, $constantaddress($con));
 11291   %}
 11292   ins_pipe(pipe_slow);
 11293 %}
 11295 instruct mulX_mem(regX dst, memory mem) %{
 11296   predicate(UseSSE>=1);
 11297   match(Set dst (MulF dst (LoadF mem)));
 11298   format %{ "MULSS  $dst,$mem" %}
 11299   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x59), RegMem(dst,mem));
 11300   ins_pipe( pipe_slow );
 11301 %}
 11303 // Divide two single precision floating point values in xmm
 11304 instruct divX_reg(regX dst, regX src) %{
 11305   predicate(UseSSE>=1);
 11306   match(Set dst (DivF dst src));
 11307   format %{ "DIVSS  $dst,$src" %}
 11308   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x5E), RegReg(dst, src));
 11309   ins_pipe( pipe_slow );
 11310 %}
 11312 instruct divX_imm(regX dst, immXF con) %{
 11313   predicate(UseSSE>=1);
 11314   match(Set dst (DivF dst con));
 11315   format %{ "DIVSS  $dst,[$constantaddress]\t# load from constant table: float=$con" %}
 11316   ins_encode %{
 11317     __ divss($dst$$XMMRegister, $constantaddress($con));
 11318   %}
 11319   ins_pipe(pipe_slow);
 11320 %}
 11322 instruct divX_mem(regX dst, memory mem) %{
 11323   predicate(UseSSE>=1);
 11324   match(Set dst (DivF dst (LoadF mem)));
 11325   format %{ "DIVSS  $dst,$mem" %}
 11326   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x5E), RegMem(dst,mem));
 11327   ins_pipe( pipe_slow );
 11328 %}
 11330 // Get the square root of a single precision floating point values in xmm
 11331 instruct sqrtX_reg(regX dst, regX src) %{
 11332   predicate(UseSSE>=1);
 11333   match(Set dst (ConvD2F (SqrtD (ConvF2D src))));
 11334   format %{ "SQRTSS $dst,$src" %}
 11335   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x51), RegReg(dst, src));
 11336   ins_pipe( pipe_slow );
 11337 %}
 11339 instruct sqrtX_mem(regX dst, memory mem) %{
 11340   predicate(UseSSE>=1);
 11341   match(Set dst (ConvD2F (SqrtD (ConvF2D (LoadF mem)))));
 11342   format %{ "SQRTSS $dst,$mem" %}
 11343   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x51), RegMem(dst, mem));
 11344   ins_pipe( pipe_slow );
 11345 %}
 11347 // Get the square root of a double precision floating point values in xmm
 11348 instruct sqrtXD_reg(regXD dst, regXD src) %{
 11349   predicate(UseSSE>=2);
 11350   match(Set dst (SqrtD src));
 11351   format %{ "SQRTSD $dst,$src" %}
 11352   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x51), RegReg(dst, src));
 11353   ins_pipe( pipe_slow );
 11354 %}
 11356 instruct sqrtXD_mem(regXD dst, memory mem) %{
 11357   predicate(UseSSE>=2);
 11358   match(Set dst (SqrtD (LoadD mem)));
 11359   format %{ "SQRTSD $dst,$mem" %}
 11360   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x51), RegMem(dst, mem));
 11361   ins_pipe( pipe_slow );
 11362 %}
 11364 instruct absF_reg(regFPR1 dst, regFPR1 src) %{
 11365   predicate(UseSSE==0);
 11366   match(Set dst (AbsF src));
 11367   ins_cost(100);
 11368   format %{ "FABS" %}
 11369   opcode(0xE1, 0xD9);
 11370   ins_encode( OpcS, OpcP );
 11371   ins_pipe( fpu_reg_reg );
 11372 %}
 11374 instruct absX_reg(regX dst ) %{
 11375   predicate(UseSSE>=1);
 11376   match(Set dst (AbsF dst));
 11377   format %{ "ANDPS  $dst,[0x7FFFFFFF]\t# ABS F by sign masking" %}
 11378   ins_encode( AbsXF_encoding(dst));
 11379   ins_pipe( pipe_slow );
 11380 %}
 11382 instruct negF_reg(regFPR1 dst, regFPR1 src) %{
 11383   predicate(UseSSE==0);
 11384   match(Set dst (NegF src));
 11385   ins_cost(100);
 11386   format %{ "FCHS" %}
 11387   opcode(0xE0, 0xD9);
 11388   ins_encode( OpcS, OpcP );
 11389   ins_pipe( fpu_reg_reg );
 11390 %}
 11392 instruct negX_reg( regX dst ) %{
 11393   predicate(UseSSE>=1);
 11394   match(Set dst (NegF dst));
 11395   format %{ "XORPS  $dst,[0x80000000]\t# CHS F by sign flipping" %}
 11396   ins_encode( NegXF_encoding(dst));
 11397   ins_pipe( pipe_slow );
 11398 %}
 11400 // Cisc-alternate to addF_reg
 11401 // Spill to obtain 24-bit precision
 11402 instruct addF24_reg_mem(stackSlotF dst, regF src1, memory src2) %{
 11403   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11404   match(Set dst (AddF src1 (LoadF src2)));
 11406   format %{ "FLD    $src2\n\t"
 11407             "FADD   ST,$src1\n\t"
 11408             "FSTP_S $dst" %}
 11409   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 11410   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11411               OpcReg_F(src1),
 11412               Pop_Mem_F(dst) );
 11413   ins_pipe( fpu_mem_reg_mem );
 11414 %}
 11415 //
 11416 // Cisc-alternate to addF_reg
 11417 // This instruction does not round to 24-bits
 11418 instruct addF_reg_mem(regF dst, memory src) %{
 11419   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11420   match(Set dst (AddF dst (LoadF src)));
 11422   format %{ "FADD   $dst,$src" %}
 11423   opcode(0xDE, 0x0, 0xD9); /* DE C0+i or DE /0*/  /* LoadF  D9 /0 */
 11424   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src),
 11425               OpcP, RegOpc(dst) );
 11426   ins_pipe( fpu_reg_mem );
 11427 %}
 11429 // // Following two instructions for _222_mpegaudio
 11430 // Spill to obtain 24-bit precision
 11431 instruct addF24_mem_reg(stackSlotF dst, regF src2, memory src1 ) %{
 11432   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11433   match(Set dst (AddF src1 src2));
 11435   format %{ "FADD   $dst,$src1,$src2" %}
 11436   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 11437   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src1),
 11438               OpcReg_F(src2),
 11439               Pop_Mem_F(dst) );
 11440   ins_pipe( fpu_mem_reg_mem );
 11441 %}
 11443 // Cisc-spill variant
 11444 // Spill to obtain 24-bit precision
 11445 instruct addF24_mem_cisc(stackSlotF dst, memory src1, memory src2) %{
 11446   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11447   match(Set dst (AddF src1 (LoadF src2)));
 11449   format %{ "FADD   $dst,$src1,$src2 cisc" %}
 11450   opcode(0xD8, 0x0, 0xD9); /* D8 C0+i */  /* LoadF  D9 /0 */
 11451   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11452               set_instruction_start,
 11453               OpcP, RMopc_Mem(secondary,src1),
 11454               Pop_Mem_F(dst) );
 11455   ins_pipe( fpu_mem_mem_mem );
 11456 %}
 11458 // Spill to obtain 24-bit precision
 11459 instruct addF24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
 11460   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11461   match(Set dst (AddF src1 src2));
 11463   format %{ "FADD   $dst,$src1,$src2" %}
 11464   opcode(0xD8, 0x0, 0xD9); /* D8 /0 */  /* LoadF  D9 /0 */
 11465   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11466               set_instruction_start,
 11467               OpcP, RMopc_Mem(secondary,src1),
 11468               Pop_Mem_F(dst) );
 11469   ins_pipe( fpu_mem_mem_mem );
 11470 %}
 11473 // Spill to obtain 24-bit precision
 11474 instruct addF24_reg_imm(stackSlotF dst, regF src, immF con) %{
 11475   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11476   match(Set dst (AddF src con));
 11477   format %{ "FLD    $src\n\t"
 11478             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 11479             "FSTP_S $dst"  %}
 11480   ins_encode %{
 11481     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 11482     __ fadd_s($constantaddress($con));
 11483     __ fstp_s(Address(rsp, $dst$$disp));
 11484   %}
 11485   ins_pipe(fpu_mem_reg_con);
 11486 %}
 11487 //
 11488 // This instruction does not round to 24-bits
 11489 instruct addF_reg_imm(regF dst, regF src, immF con) %{
 11490   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11491   match(Set dst (AddF src con));
 11492   format %{ "FLD    $src\n\t"
 11493             "FADD_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 11494             "FSTP   $dst"  %}
 11495   ins_encode %{
 11496     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 11497     __ fadd_s($constantaddress($con));
 11498     __ fstp_d($dst$$reg);
 11499   %}
 11500   ins_pipe(fpu_reg_reg_con);
 11501 %}
 11503 // Spill to obtain 24-bit precision
 11504 instruct mulF24_reg(stackSlotF dst, regF src1, regF src2) %{
 11505   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11506   match(Set dst (MulF src1 src2));
 11508   format %{ "FLD    $src1\n\t"
 11509             "FMUL   $src2\n\t"
 11510             "FSTP_S $dst"  %}
 11511   opcode(0xD8, 0x1); /* D8 C8+i or D8 /1 ;; result in TOS */
 11512   ins_encode( Push_Reg_F(src1),
 11513               OpcReg_F(src2),
 11514               Pop_Mem_F(dst) );
 11515   ins_pipe( fpu_mem_reg_reg );
 11516 %}
 11517 //
 11518 // This instruction does not round to 24-bits
 11519 instruct mulF_reg(regF dst, regF src1, regF src2) %{
 11520   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11521   match(Set dst (MulF src1 src2));
 11523   format %{ "FLD    $src1\n\t"
 11524             "FMUL   $src2\n\t"
 11525             "FSTP_S $dst"  %}
 11526   opcode(0xD8, 0x1); /* D8 C8+i */
 11527   ins_encode( Push_Reg_F(src2),
 11528               OpcReg_F(src1),
 11529               Pop_Reg_F(dst) );
 11530   ins_pipe( fpu_reg_reg_reg );
 11531 %}
 11534 // Spill to obtain 24-bit precision
 11535 // Cisc-alternate to reg-reg multiply
 11536 instruct mulF24_reg_mem(stackSlotF dst, regF src1, memory src2) %{
 11537   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11538   match(Set dst (MulF src1 (LoadF src2)));
 11540   format %{ "FLD_S  $src2\n\t"
 11541             "FMUL   $src1\n\t"
 11542             "FSTP_S $dst"  %}
 11543   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or DE /1*/  /* LoadF D9 /0 */
 11544   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11545               OpcReg_F(src1),
 11546               Pop_Mem_F(dst) );
 11547   ins_pipe( fpu_mem_reg_mem );
 11548 %}
 11549 //
 11550 // This instruction does not round to 24-bits
 11551 // Cisc-alternate to reg-reg multiply
 11552 instruct mulF_reg_mem(regF dst, regF src1, memory src2) %{
 11553   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11554   match(Set dst (MulF src1 (LoadF src2)));
 11556   format %{ "FMUL   $dst,$src1,$src2" %}
 11557   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i */  /* LoadF D9 /0 */
 11558   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11559               OpcReg_F(src1),
 11560               Pop_Reg_F(dst) );
 11561   ins_pipe( fpu_reg_reg_mem );
 11562 %}
 11564 // Spill to obtain 24-bit precision
 11565 instruct mulF24_mem_mem(stackSlotF dst, memory src1, memory src2) %{
 11566   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11567   match(Set dst (MulF src1 src2));
 11569   format %{ "FMUL   $dst,$src1,$src2" %}
 11570   opcode(0xD8, 0x1, 0xD9); /* D8 /1 */  /* LoadF D9 /0 */
 11571   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,src2),
 11572               set_instruction_start,
 11573               OpcP, RMopc_Mem(secondary,src1),
 11574               Pop_Mem_F(dst) );
 11575   ins_pipe( fpu_mem_mem_mem );
 11576 %}
 11578 // Spill to obtain 24-bit precision
 11579 instruct mulF24_reg_imm(stackSlotF dst, regF src, immF con) %{
 11580   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11581   match(Set dst (MulF src con));
 11583   format %{ "FLD    $src\n\t"
 11584             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 11585             "FSTP_S $dst"  %}
 11586   ins_encode %{
 11587     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 11588     __ fmul_s($constantaddress($con));
 11589     __ fstp_s(Address(rsp, $dst$$disp));
 11590   %}
 11591   ins_pipe(fpu_mem_reg_con);
 11592 %}
 11593 //
 11594 // This instruction does not round to 24-bits
 11595 instruct mulF_reg_imm(regF dst, regF src, immF con) %{
 11596   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11597   match(Set dst (MulF src con));
 11599   format %{ "FLD    $src\n\t"
 11600             "FMUL_S [$constantaddress]\t# load from constant table: float=$con\n\t"
 11601             "FSTP   $dst"  %}
 11602   ins_encode %{
 11603     __ fld_s($src$$reg - 1);  // FLD ST(i-1)
 11604     __ fmul_s($constantaddress($con));
 11605     __ fstp_d($dst$$reg);
 11606   %}
 11607   ins_pipe(fpu_reg_reg_con);
 11608 %}
 11611 //
 11612 // MACRO1 -- subsume unshared load into mulF
 11613 // This instruction does not round to 24-bits
 11614 instruct mulF_reg_load1(regF dst, regF src, memory mem1 ) %{
 11615   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11616   match(Set dst (MulF (LoadF mem1) src));
 11618   format %{ "FLD    $mem1    ===MACRO1===\n\t"
 11619             "FMUL   ST,$src\n\t"
 11620             "FSTP   $dst" %}
 11621   opcode(0xD8, 0x1, 0xD9); /* D8 C8+i or D8 /1 */  /* LoadF D9 /0 */
 11622   ins_encode( Opcode(tertiary), RMopc_Mem(0x00,mem1),
 11623               OpcReg_F(src),
 11624               Pop_Reg_F(dst) );
 11625   ins_pipe( fpu_reg_reg_mem );
 11626 %}
 11627 //
 11628 // MACRO2 -- addF a mulF which subsumed an unshared load
 11629 // This instruction does not round to 24-bits
 11630 instruct addF_mulF_reg_load1(regF dst, memory mem1, regF src1, regF src2) %{
 11631   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11632   match(Set dst (AddF (MulF (LoadF mem1) src1) src2));
 11633   ins_cost(95);
 11635   format %{ "FLD    $mem1     ===MACRO2===\n\t"
 11636             "FMUL   ST,$src1  subsume mulF left load\n\t"
 11637             "FADD   ST,$src2\n\t"
 11638             "FSTP   $dst" %}
 11639   opcode(0xD9); /* LoadF D9 /0 */
 11640   ins_encode( OpcP, RMopc_Mem(0x00,mem1),
 11641               FMul_ST_reg(src1),
 11642               FAdd_ST_reg(src2),
 11643               Pop_Reg_F(dst) );
 11644   ins_pipe( fpu_reg_mem_reg_reg );
 11645 %}
 11647 // MACRO3 -- addF a mulF
 11648 // This instruction does not round to 24-bits.  It is a '2-address'
 11649 // instruction in that the result goes back to src2.  This eliminates
 11650 // a move from the macro; possibly the register allocator will have
 11651 // to add it back (and maybe not).
 11652 instruct addF_mulF_reg(regF src2, regF src1, regF src0) %{
 11653   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11654   match(Set src2 (AddF (MulF src0 src1) src2));
 11656   format %{ "FLD    $src0     ===MACRO3===\n\t"
 11657             "FMUL   ST,$src1\n\t"
 11658             "FADDP  $src2,ST" %}
 11659   opcode(0xD9); /* LoadF D9 /0 */
 11660   ins_encode( Push_Reg_F(src0),
 11661               FMul_ST_reg(src1),
 11662               FAddP_reg_ST(src2) );
 11663   ins_pipe( fpu_reg_reg_reg );
 11664 %}
 11666 // MACRO4 -- divF subF
 11667 // This instruction does not round to 24-bits
 11668 instruct subF_divF_reg(regF dst, regF src1, regF src2, regF src3) %{
 11669   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11670   match(Set dst (DivF (SubF src2 src1) src3));
 11672   format %{ "FLD    $src2   ===MACRO4===\n\t"
 11673             "FSUB   ST,$src1\n\t"
 11674             "FDIV   ST,$src3\n\t"
 11675             "FSTP  $dst" %}
 11676   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 11677   ins_encode( Push_Reg_F(src2),
 11678               subF_divF_encode(src1,src3),
 11679               Pop_Reg_F(dst) );
 11680   ins_pipe( fpu_reg_reg_reg_reg );
 11681 %}
 11683 // Spill to obtain 24-bit precision
 11684 instruct divF24_reg(stackSlotF dst, regF src1, regF src2) %{
 11685   predicate(UseSSE==0 && Compile::current()->select_24_bit_instr());
 11686   match(Set dst (DivF src1 src2));
 11688   format %{ "FDIV   $dst,$src1,$src2" %}
 11689   opcode(0xD8, 0x6); /* D8 F0+i or DE /6*/
 11690   ins_encode( Push_Reg_F(src1),
 11691               OpcReg_F(src2),
 11692               Pop_Mem_F(dst) );
 11693   ins_pipe( fpu_mem_reg_reg );
 11694 %}
 11695 //
 11696 // This instruction does not round to 24-bits
 11697 instruct divF_reg(regF dst, regF src) %{
 11698   predicate(UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11699   match(Set dst (DivF dst src));
 11701   format %{ "FDIV   $dst,$src" %}
 11702   opcode(0xDE, 0x7); /* DE F8+i or DE /7*/
 11703   ins_encode( Push_Reg_F(src),
 11704               OpcP, RegOpc(dst) );
 11705   ins_pipe( fpu_reg_reg );
 11706 %}
 11709 // Spill to obtain 24-bit precision
 11710 instruct modF24_reg(stackSlotF dst, regF src1, regF src2, eAXRegI rax, eFlagsReg cr) %{
 11711   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 11712   match(Set dst (ModF src1 src2));
 11713   effect(KILL rax, KILL cr); // emitModD() uses EAX and EFLAGS
 11715   format %{ "FMOD   $dst,$src1,$src2" %}
 11716   ins_encode( Push_Reg_Mod_D(src1, src2),
 11717               emitModD(),
 11718               Push_Result_Mod_D(src2),
 11719               Pop_Mem_F(dst));
 11720   ins_pipe( pipe_slow );
 11721 %}
 11722 //
 11723 // This instruction does not round to 24-bits
 11724 instruct modF_reg(regF dst, regF src, eAXRegI rax, eFlagsReg cr) %{
 11725   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 11726   match(Set dst (ModF dst src));
 11727   effect(KILL rax, KILL cr); // emitModD() uses EAX and EFLAGS
 11729   format %{ "FMOD   $dst,$src" %}
 11730   ins_encode(Push_Reg_Mod_D(dst, src),
 11731               emitModD(),
 11732               Push_Result_Mod_D(src),
 11733               Pop_Reg_F(dst));
 11734   ins_pipe( pipe_slow );
 11735 %}
 11737 instruct modX_reg(regX dst, regX src0, regX src1, eAXRegI rax, eFlagsReg cr) %{
 11738   predicate(UseSSE>=1);
 11739   match(Set dst (ModF src0 src1));
 11740   effect(KILL rax, KILL cr);
 11741   format %{ "SUB    ESP,4\t # FMOD\n"
 11742           "\tMOVSS  [ESP+0],$src1\n"
 11743           "\tFLD_S  [ESP+0]\n"
 11744           "\tMOVSS  [ESP+0],$src0\n"
 11745           "\tFLD_S  [ESP+0]\n"
 11746      "loop:\tFPREM\n"
 11747           "\tFWAIT\n"
 11748           "\tFNSTSW AX\n"
 11749           "\tSAHF\n"
 11750           "\tJP     loop\n"
 11751           "\tFSTP_S [ESP+0]\n"
 11752           "\tMOVSS  $dst,[ESP+0]\n"
 11753           "\tADD    ESP,4\n"
 11754           "\tFSTP   ST0\t # Restore FPU Stack"
 11755     %}
 11756   ins_cost(250);
 11757   ins_encode( Push_ModX_encoding(src0, src1), emitModD(), Push_ResultX(dst,0x4), PopFPU);
 11758   ins_pipe( pipe_slow );
 11759 %}
 11762 //----------Arithmetic Conversion Instructions---------------------------------
 11763 // The conversions operations are all Alpha sorted.  Please keep it that way!
 11765 instruct roundFloat_mem_reg(stackSlotF dst, regF src) %{
 11766   predicate(UseSSE==0);
 11767   match(Set dst (RoundFloat src));
 11768   ins_cost(125);
 11769   format %{ "FST_S  $dst,$src\t# F-round" %}
 11770   ins_encode( Pop_Mem_Reg_F(dst, src) );
 11771   ins_pipe( fpu_mem_reg );
 11772 %}
 11774 instruct roundDouble_mem_reg(stackSlotD dst, regD src) %{
 11775   predicate(UseSSE<=1);
 11776   match(Set dst (RoundDouble src));
 11777   ins_cost(125);
 11778   format %{ "FST_D  $dst,$src\t# D-round" %}
 11779   ins_encode( Pop_Mem_Reg_D(dst, src) );
 11780   ins_pipe( fpu_mem_reg );
 11781 %}
 11783 // Force rounding to 24-bit precision and 6-bit exponent
 11784 instruct convD2F_reg(stackSlotF dst, regD src) %{
 11785   predicate(UseSSE==0);
 11786   match(Set dst (ConvD2F src));
 11787   format %{ "FST_S  $dst,$src\t# F-round" %}
 11788   expand %{
 11789     roundFloat_mem_reg(dst,src);
 11790   %}
 11791 %}
 11793 // Force rounding to 24-bit precision and 6-bit exponent
 11794 instruct convD2X_reg(regX dst, regD src, eFlagsReg cr) %{
 11795   predicate(UseSSE==1);
 11796   match(Set dst (ConvD2F src));
 11797   effect( KILL cr );
 11798   format %{ "SUB    ESP,4\n\t"
 11799             "FST_S  [ESP],$src\t# F-round\n\t"
 11800             "MOVSS  $dst,[ESP]\n\t"
 11801             "ADD ESP,4" %}
 11802   ins_encode( D2X_encoding(dst, src) );
 11803   ins_pipe( pipe_slow );
 11804 %}
 11806 // Force rounding double precision to single precision
 11807 instruct convXD2X_reg(regX dst, regXD src) %{
 11808   predicate(UseSSE>=2);
 11809   match(Set dst (ConvD2F src));
 11810   format %{ "CVTSD2SS $dst,$src\t# F-round" %}
 11811   opcode(0xF2, 0x0F, 0x5A);
 11812   ins_encode( OpcP, OpcS, Opcode(tertiary), RegReg(dst, src));
 11813   ins_pipe( pipe_slow );
 11814 %}
 11816 instruct convF2D_reg_reg(regD dst, regF src) %{
 11817   predicate(UseSSE==0);
 11818   match(Set dst (ConvF2D src));
 11819   format %{ "FST_S  $dst,$src\t# D-round" %}
 11820   ins_encode( Pop_Reg_Reg_D(dst, src));
 11821   ins_pipe( fpu_reg_reg );
 11822 %}
 11824 instruct convF2D_reg(stackSlotD dst, regF src) %{
 11825   predicate(UseSSE==1);
 11826   match(Set dst (ConvF2D src));
 11827   format %{ "FST_D  $dst,$src\t# D-round" %}
 11828   expand %{
 11829     roundDouble_mem_reg(dst,src);
 11830   %}
 11831 %}
 11833 instruct convX2D_reg(regD dst, regX src, eFlagsReg cr) %{
 11834   predicate(UseSSE==1);
 11835   match(Set dst (ConvF2D src));
 11836   effect( KILL cr );
 11837   format %{ "SUB    ESP,4\n\t"
 11838             "MOVSS  [ESP] $src\n\t"
 11839             "FLD_S  [ESP]\n\t"
 11840             "ADD    ESP,4\n\t"
 11841             "FSTP   $dst\t# D-round" %}
 11842   ins_encode( X2D_encoding(dst, src), Pop_Reg_D(dst));
 11843   ins_pipe( pipe_slow );
 11844 %}
 11846 instruct convX2XD_reg(regXD dst, regX src) %{
 11847   predicate(UseSSE>=2);
 11848   match(Set dst (ConvF2D src));
 11849   format %{ "CVTSS2SD $dst,$src\t# D-round" %}
 11850   opcode(0xF3, 0x0F, 0x5A);
 11851   ins_encode( OpcP, OpcS, Opcode(tertiary), RegReg(dst, src));
 11852   ins_pipe( pipe_slow );
 11853 %}
 11855 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
 11856 instruct convD2I_reg_reg( eAXRegI dst, eDXRegI tmp, regD src, eFlagsReg cr ) %{
 11857   predicate(UseSSE<=1);
 11858   match(Set dst (ConvD2I src));
 11859   effect( KILL tmp, KILL cr );
 11860   format %{ "FLD    $src\t# Convert double to int \n\t"
 11861             "FLDCW  trunc mode\n\t"
 11862             "SUB    ESP,4\n\t"
 11863             "FISTp  [ESP + #0]\n\t"
 11864             "FLDCW  std/24-bit mode\n\t"
 11865             "POP    EAX\n\t"
 11866             "CMP    EAX,0x80000000\n\t"
 11867             "JNE,s  fast\n\t"
 11868             "FLD_D  $src\n\t"
 11869             "CALL   d2i_wrapper\n"
 11870       "fast:" %}
 11871   ins_encode( Push_Reg_D(src), D2I_encoding(src) );
 11872   ins_pipe( pipe_slow );
 11873 %}
 11875 // Convert a double to an int.  If the double is a NAN, stuff a zero in instead.
 11876 instruct convXD2I_reg_reg( eAXRegI dst, eDXRegI tmp, regXD src, eFlagsReg cr ) %{
 11877   predicate(UseSSE>=2);
 11878   match(Set dst (ConvD2I src));
 11879   effect( KILL tmp, KILL cr );
 11880   format %{ "CVTTSD2SI $dst, $src\n\t"
 11881             "CMP    $dst,0x80000000\n\t"
 11882             "JNE,s  fast\n\t"
 11883             "SUB    ESP, 8\n\t"
 11884             "MOVSD  [ESP], $src\n\t"
 11885             "FLD_D  [ESP]\n\t"
 11886             "ADD    ESP, 8\n\t"
 11887             "CALL   d2i_wrapper\n"
 11888       "fast:" %}
 11889   opcode(0x1); // double-precision conversion
 11890   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x2C), FX2I_encoding(src,dst));
 11891   ins_pipe( pipe_slow );
 11892 %}
 11894 instruct convD2L_reg_reg( eADXRegL dst, regD src, eFlagsReg cr ) %{
 11895   predicate(UseSSE<=1);
 11896   match(Set dst (ConvD2L src));
 11897   effect( KILL cr );
 11898   format %{ "FLD    $src\t# Convert double to long\n\t"
 11899             "FLDCW  trunc mode\n\t"
 11900             "SUB    ESP,8\n\t"
 11901             "FISTp  [ESP + #0]\n\t"
 11902             "FLDCW  std/24-bit mode\n\t"
 11903             "POP    EAX\n\t"
 11904             "POP    EDX\n\t"
 11905             "CMP    EDX,0x80000000\n\t"
 11906             "JNE,s  fast\n\t"
 11907             "TEST   EAX,EAX\n\t"
 11908             "JNE,s  fast\n\t"
 11909             "FLD    $src\n\t"
 11910             "CALL   d2l_wrapper\n"
 11911       "fast:" %}
 11912   ins_encode( Push_Reg_D(src),  D2L_encoding(src) );
 11913   ins_pipe( pipe_slow );
 11914 %}
 11916 // XMM lacks a float/double->long conversion, so use the old FPU stack.
 11917 instruct convXD2L_reg_reg( eADXRegL dst, regXD src, eFlagsReg cr ) %{
 11918   predicate (UseSSE>=2);
 11919   match(Set dst (ConvD2L src));
 11920   effect( KILL cr );
 11921   format %{ "SUB    ESP,8\t# Convert double to long\n\t"
 11922             "MOVSD  [ESP],$src\n\t"
 11923             "FLD_D  [ESP]\n\t"
 11924             "FLDCW  trunc mode\n\t"
 11925             "FISTp  [ESP + #0]\n\t"
 11926             "FLDCW  std/24-bit mode\n\t"
 11927             "POP    EAX\n\t"
 11928             "POP    EDX\n\t"
 11929             "CMP    EDX,0x80000000\n\t"
 11930             "JNE,s  fast\n\t"
 11931             "TEST   EAX,EAX\n\t"
 11932             "JNE,s  fast\n\t"
 11933             "SUB    ESP,8\n\t"
 11934             "MOVSD  [ESP],$src\n\t"
 11935             "FLD_D  [ESP]\n\t"
 11936             "CALL   d2l_wrapper\n"
 11937       "fast:" %}
 11938   ins_encode( XD2L_encoding(src) );
 11939   ins_pipe( pipe_slow );
 11940 %}
 11942 // Convert a double to an int.  Java semantics require we do complex
 11943 // manglations in the corner cases.  So we set the rounding mode to
 11944 // 'zero', store the darned double down as an int, and reset the
 11945 // rounding mode to 'nearest'.  The hardware stores a flag value down
 11946 // if we would overflow or converted a NAN; we check for this and
 11947 // and go the slow path if needed.
 11948 instruct convF2I_reg_reg(eAXRegI dst, eDXRegI tmp, regF src, eFlagsReg cr ) %{
 11949   predicate(UseSSE==0);
 11950   match(Set dst (ConvF2I src));
 11951   effect( KILL tmp, KILL cr );
 11952   format %{ "FLD    $src\t# Convert float to int \n\t"
 11953             "FLDCW  trunc mode\n\t"
 11954             "SUB    ESP,4\n\t"
 11955             "FISTp  [ESP + #0]\n\t"
 11956             "FLDCW  std/24-bit mode\n\t"
 11957             "POP    EAX\n\t"
 11958             "CMP    EAX,0x80000000\n\t"
 11959             "JNE,s  fast\n\t"
 11960             "FLD    $src\n\t"
 11961             "CALL   d2i_wrapper\n"
 11962       "fast:" %}
 11963   // D2I_encoding works for F2I
 11964   ins_encode( Push_Reg_F(src), D2I_encoding(src) );
 11965   ins_pipe( pipe_slow );
 11966 %}
 11968 // Convert a float in xmm to an int reg.
 11969 instruct convX2I_reg(eAXRegI dst, eDXRegI tmp, regX src, eFlagsReg cr ) %{
 11970   predicate(UseSSE>=1);
 11971   match(Set dst (ConvF2I src));
 11972   effect( KILL tmp, KILL cr );
 11973   format %{ "CVTTSS2SI $dst, $src\n\t"
 11974             "CMP    $dst,0x80000000\n\t"
 11975             "JNE,s  fast\n\t"
 11976             "SUB    ESP, 4\n\t"
 11977             "MOVSS  [ESP], $src\n\t"
 11978             "FLD    [ESP]\n\t"
 11979             "ADD    ESP, 4\n\t"
 11980             "CALL   d2i_wrapper\n"
 11981       "fast:" %}
 11982   opcode(0x0); // single-precision conversion
 11983   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x2C), FX2I_encoding(src,dst));
 11984   ins_pipe( pipe_slow );
 11985 %}
 11987 instruct convF2L_reg_reg( eADXRegL dst, regF src, eFlagsReg cr ) %{
 11988   predicate(UseSSE==0);
 11989   match(Set dst (ConvF2L src));
 11990   effect( KILL cr );
 11991   format %{ "FLD    $src\t# Convert float to long\n\t"
 11992             "FLDCW  trunc mode\n\t"
 11993             "SUB    ESP,8\n\t"
 11994             "FISTp  [ESP + #0]\n\t"
 11995             "FLDCW  std/24-bit mode\n\t"
 11996             "POP    EAX\n\t"
 11997             "POP    EDX\n\t"
 11998             "CMP    EDX,0x80000000\n\t"
 11999             "JNE,s  fast\n\t"
 12000             "TEST   EAX,EAX\n\t"
 12001             "JNE,s  fast\n\t"
 12002             "FLD    $src\n\t"
 12003             "CALL   d2l_wrapper\n"
 12004       "fast:" %}
 12005   // D2L_encoding works for F2L
 12006   ins_encode( Push_Reg_F(src), D2L_encoding(src) );
 12007   ins_pipe( pipe_slow );
 12008 %}
 12010 // XMM lacks a float/double->long conversion, so use the old FPU stack.
 12011 instruct convX2L_reg_reg( eADXRegL dst, regX src, eFlagsReg cr ) %{
 12012   predicate (UseSSE>=1);
 12013   match(Set dst (ConvF2L src));
 12014   effect( KILL cr );
 12015   format %{ "SUB    ESP,8\t# Convert float to long\n\t"
 12016             "MOVSS  [ESP],$src\n\t"
 12017             "FLD_S  [ESP]\n\t"
 12018             "FLDCW  trunc mode\n\t"
 12019             "FISTp  [ESP + #0]\n\t"
 12020             "FLDCW  std/24-bit mode\n\t"
 12021             "POP    EAX\n\t"
 12022             "POP    EDX\n\t"
 12023             "CMP    EDX,0x80000000\n\t"
 12024             "JNE,s  fast\n\t"
 12025             "TEST   EAX,EAX\n\t"
 12026             "JNE,s  fast\n\t"
 12027             "SUB    ESP,4\t# Convert float to long\n\t"
 12028             "MOVSS  [ESP],$src\n\t"
 12029             "FLD_S  [ESP]\n\t"
 12030             "ADD    ESP,4\n\t"
 12031             "CALL   d2l_wrapper\n"
 12032       "fast:" %}
 12033   ins_encode( X2L_encoding(src) );
 12034   ins_pipe( pipe_slow );
 12035 %}
 12037 instruct convI2D_reg(regD dst, stackSlotI src) %{
 12038   predicate( UseSSE<=1 );
 12039   match(Set dst (ConvI2D src));
 12040   format %{ "FILD   $src\n\t"
 12041             "FSTP   $dst" %}
 12042   opcode(0xDB, 0x0);  /* DB /0 */
 12043   ins_encode(Push_Mem_I(src), Pop_Reg_D(dst));
 12044   ins_pipe( fpu_reg_mem );
 12045 %}
 12047 instruct convI2XD_reg(regXD dst, eRegI src) %{
 12048   predicate( UseSSE>=2 && !UseXmmI2D );
 12049   match(Set dst (ConvI2D src));
 12050   format %{ "CVTSI2SD $dst,$src" %}
 12051   opcode(0xF2, 0x0F, 0x2A);
 12052   ins_encode( OpcP, OpcS, Opcode(tertiary), RegReg(dst, src));
 12053   ins_pipe( pipe_slow );
 12054 %}
 12056 instruct convI2XD_mem(regXD dst, memory mem) %{
 12057   predicate( UseSSE>=2 );
 12058   match(Set dst (ConvI2D (LoadI mem)));
 12059   format %{ "CVTSI2SD $dst,$mem" %}
 12060   opcode(0xF2, 0x0F, 0x2A);
 12061   ins_encode( OpcP, OpcS, Opcode(tertiary), RegMem(dst, mem));
 12062   ins_pipe( pipe_slow );
 12063 %}
 12065 instruct convXI2XD_reg(regXD dst, eRegI src)
 12066 %{
 12067   predicate( UseSSE>=2 && UseXmmI2D );
 12068   match(Set dst (ConvI2D src));
 12070   format %{ "MOVD  $dst,$src\n\t"
 12071             "CVTDQ2PD $dst,$dst\t# i2d" %}
 12072   ins_encode %{
 12073     __ movdl($dst$$XMMRegister, $src$$Register);
 12074     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
 12075   %}
 12076   ins_pipe(pipe_slow); // XXX
 12077 %}
 12079 instruct convI2D_mem(regD dst, memory mem) %{
 12080   predicate( UseSSE<=1 && !Compile::current()->select_24_bit_instr());
 12081   match(Set dst (ConvI2D (LoadI mem)));
 12082   format %{ "FILD   $mem\n\t"
 12083             "FSTP   $dst" %}
 12084   opcode(0xDB);      /* DB /0 */
 12085   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 12086               Pop_Reg_D(dst));
 12087   ins_pipe( fpu_reg_mem );
 12088 %}
 12090 // Convert a byte to a float; no rounding step needed.
 12091 instruct conv24I2F_reg(regF dst, stackSlotI src) %{
 12092   predicate( UseSSE==0 && n->in(1)->Opcode() == Op_AndI && n->in(1)->in(2)->is_Con() && n->in(1)->in(2)->get_int() == 255 );
 12093   match(Set dst (ConvI2F src));
 12094   format %{ "FILD   $src\n\t"
 12095             "FSTP   $dst" %}
 12097   opcode(0xDB, 0x0);  /* DB /0 */
 12098   ins_encode(Push_Mem_I(src), Pop_Reg_F(dst));
 12099   ins_pipe( fpu_reg_mem );
 12100 %}
 12102 // In 24-bit mode, force exponent rounding by storing back out
 12103 instruct convI2F_SSF(stackSlotF dst, stackSlotI src) %{
 12104   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 12105   match(Set dst (ConvI2F src));
 12106   ins_cost(200);
 12107   format %{ "FILD   $src\n\t"
 12108             "FSTP_S $dst" %}
 12109   opcode(0xDB, 0x0);  /* DB /0 */
 12110   ins_encode( Push_Mem_I(src),
 12111               Pop_Mem_F(dst));
 12112   ins_pipe( fpu_mem_mem );
 12113 %}
 12115 // In 24-bit mode, force exponent rounding by storing back out
 12116 instruct convI2F_SSF_mem(stackSlotF dst, memory mem) %{
 12117   predicate( UseSSE==0 && Compile::current()->select_24_bit_instr());
 12118   match(Set dst (ConvI2F (LoadI mem)));
 12119   ins_cost(200);
 12120   format %{ "FILD   $mem\n\t"
 12121             "FSTP_S $dst" %}
 12122   opcode(0xDB);  /* DB /0 */
 12123   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 12124               Pop_Mem_F(dst));
 12125   ins_pipe( fpu_mem_mem );
 12126 %}
 12128 // This instruction does not round to 24-bits
 12129 instruct convI2F_reg(regF dst, stackSlotI src) %{
 12130   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 12131   match(Set dst (ConvI2F src));
 12132   format %{ "FILD   $src\n\t"
 12133             "FSTP   $dst" %}
 12134   opcode(0xDB, 0x0);  /* DB /0 */
 12135   ins_encode( Push_Mem_I(src),
 12136               Pop_Reg_F(dst));
 12137   ins_pipe( fpu_reg_mem );
 12138 %}
 12140 // This instruction does not round to 24-bits
 12141 instruct convI2F_mem(regF dst, memory mem) %{
 12142   predicate( UseSSE==0 && !Compile::current()->select_24_bit_instr());
 12143   match(Set dst (ConvI2F (LoadI mem)));
 12144   format %{ "FILD   $mem\n\t"
 12145             "FSTP   $dst" %}
 12146   opcode(0xDB);      /* DB /0 */
 12147   ins_encode( OpcP, RMopc_Mem(0x00,mem),
 12148               Pop_Reg_F(dst));
 12149   ins_pipe( fpu_reg_mem );
 12150 %}
 12152 // Convert an int to a float in xmm; no rounding step needed.
 12153 instruct convI2X_reg(regX dst, eRegI src) %{
 12154   predicate( UseSSE==1 || UseSSE>=2 && !UseXmmI2F );
 12155   match(Set dst (ConvI2F src));
 12156   format %{ "CVTSI2SS $dst, $src" %}
 12158   opcode(0xF3, 0x0F, 0x2A);  /* F3 0F 2A /r */
 12159   ins_encode( OpcP, OpcS, Opcode(tertiary), RegReg(dst, src));
 12160   ins_pipe( pipe_slow );
 12161 %}
 12163  instruct convXI2X_reg(regX dst, eRegI src)
 12164 %{
 12165   predicate( UseSSE>=2 && UseXmmI2F );
 12166   match(Set dst (ConvI2F src));
 12168   format %{ "MOVD  $dst,$src\n\t"
 12169             "CVTDQ2PS $dst,$dst\t# i2f" %}
 12170   ins_encode %{
 12171     __ movdl($dst$$XMMRegister, $src$$Register);
 12172     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
 12173   %}
 12174   ins_pipe(pipe_slow); // XXX
 12175 %}
 12177 instruct convI2L_reg( eRegL dst, eRegI src, eFlagsReg cr) %{
 12178   match(Set dst (ConvI2L src));
 12179   effect(KILL cr);
 12180   ins_cost(375);
 12181   format %{ "MOV    $dst.lo,$src\n\t"
 12182             "MOV    $dst.hi,$src\n\t"
 12183             "SAR    $dst.hi,31" %}
 12184   ins_encode(convert_int_long(dst,src));
 12185   ins_pipe( ialu_reg_reg_long );
 12186 %}
 12188 // Zero-extend convert int to long
 12189 instruct convI2L_reg_zex(eRegL dst, eRegI src, immL_32bits mask, eFlagsReg flags ) %{
 12190   match(Set dst (AndL (ConvI2L src) mask) );
 12191   effect( KILL flags );
 12192   ins_cost(250);
 12193   format %{ "MOV    $dst.lo,$src\n\t"
 12194             "XOR    $dst.hi,$dst.hi" %}
 12195   opcode(0x33); // XOR
 12196   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
 12197   ins_pipe( ialu_reg_reg_long );
 12198 %}
 12200 // Zero-extend long
 12201 instruct zerox_long(eRegL dst, eRegL src, immL_32bits mask, eFlagsReg flags ) %{
 12202   match(Set dst (AndL src mask) );
 12203   effect( KILL flags );
 12204   ins_cost(250);
 12205   format %{ "MOV    $dst.lo,$src.lo\n\t"
 12206             "XOR    $dst.hi,$dst.hi\n\t" %}
 12207   opcode(0x33); // XOR
 12208   ins_encode(enc_Copy(dst,src), OpcP, RegReg_Hi2(dst,dst) );
 12209   ins_pipe( ialu_reg_reg_long );
 12210 %}
 12212 instruct convL2D_reg( stackSlotD dst, eRegL src, eFlagsReg cr) %{
 12213   predicate (UseSSE<=1);
 12214   match(Set dst (ConvL2D src));
 12215   effect( KILL cr );
 12216   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
 12217             "PUSH   $src.lo\n\t"
 12218             "FILD   ST,[ESP + #0]\n\t"
 12219             "ADD    ESP,8\n\t"
 12220             "FSTP_D $dst\t# D-round" %}
 12221   opcode(0xDF, 0x5);  /* DF /5 */
 12222   ins_encode(convert_long_double(src), Pop_Mem_D(dst));
 12223   ins_pipe( pipe_slow );
 12224 %}
 12226 instruct convL2XD_reg( regXD dst, eRegL src, eFlagsReg cr) %{
 12227   predicate (UseSSE>=2);
 12228   match(Set dst (ConvL2D src));
 12229   effect( KILL cr );
 12230   format %{ "PUSH   $src.hi\t# Convert long to double\n\t"
 12231             "PUSH   $src.lo\n\t"
 12232             "FILD_D [ESP]\n\t"
 12233             "FSTP_D [ESP]\n\t"
 12234             "MOVSD  $dst,[ESP]\n\t"
 12235             "ADD    ESP,8" %}
 12236   opcode(0xDF, 0x5);  /* DF /5 */
 12237   ins_encode(convert_long_double2(src), Push_ResultXD(dst));
 12238   ins_pipe( pipe_slow );
 12239 %}
 12241 instruct convL2X_reg( regX dst, eRegL src, eFlagsReg cr) %{
 12242   predicate (UseSSE>=1);
 12243   match(Set dst (ConvL2F src));
 12244   effect( KILL cr );
 12245   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
 12246             "PUSH   $src.lo\n\t"
 12247             "FILD_D [ESP]\n\t"
 12248             "FSTP_S [ESP]\n\t"
 12249             "MOVSS  $dst,[ESP]\n\t"
 12250             "ADD    ESP,8" %}
 12251   opcode(0xDF, 0x5);  /* DF /5 */
 12252   ins_encode(convert_long_double2(src), Push_ResultX(dst,0x8));
 12253   ins_pipe( pipe_slow );
 12254 %}
 12256 instruct convL2F_reg( stackSlotF dst, eRegL src, eFlagsReg cr) %{
 12257   match(Set dst (ConvL2F src));
 12258   effect( KILL cr );
 12259   format %{ "PUSH   $src.hi\t# Convert long to single float\n\t"
 12260             "PUSH   $src.lo\n\t"
 12261             "FILD   ST,[ESP + #0]\n\t"
 12262             "ADD    ESP,8\n\t"
 12263             "FSTP_S $dst\t# F-round" %}
 12264   opcode(0xDF, 0x5);  /* DF /5 */
 12265   ins_encode(convert_long_double(src), Pop_Mem_F(dst));
 12266   ins_pipe( pipe_slow );
 12267 %}
 12269 instruct convL2I_reg( eRegI dst, eRegL src ) %{
 12270   match(Set dst (ConvL2I src));
 12271   effect( DEF dst, USE src );
 12272   format %{ "MOV    $dst,$src.lo" %}
 12273   ins_encode(enc_CopyL_Lo(dst,src));
 12274   ins_pipe( ialu_reg_reg );
 12275 %}
 12278 instruct MoveF2I_stack_reg(eRegI dst, stackSlotF src) %{
 12279   match(Set dst (MoveF2I src));
 12280   effect( DEF dst, USE src );
 12281   ins_cost(100);
 12282   format %{ "MOV    $dst,$src\t# MoveF2I_stack_reg" %}
 12283   opcode(0x8B);
 12284   ins_encode( OpcP, RegMem(dst,src));
 12285   ins_pipe( ialu_reg_mem );
 12286 %}
 12288 instruct MoveF2I_reg_stack(stackSlotI dst, regF src) %{
 12289   predicate(UseSSE==0);
 12290   match(Set dst (MoveF2I src));
 12291   effect( DEF dst, USE src );
 12293   ins_cost(125);
 12294   format %{ "FST_S  $dst,$src\t# MoveF2I_reg_stack" %}
 12295   ins_encode( Pop_Mem_Reg_F(dst, src) );
 12296   ins_pipe( fpu_mem_reg );
 12297 %}
 12299 instruct MoveF2I_reg_stack_sse(stackSlotI dst, regX src) %{
 12300   predicate(UseSSE>=1);
 12301   match(Set dst (MoveF2I src));
 12302   effect( DEF dst, USE src );
 12304   ins_cost(95);
 12305   format %{ "MOVSS  $dst,$src\t# MoveF2I_reg_stack_sse" %}
 12306   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x11), RegMem(src, dst));
 12307   ins_pipe( pipe_slow );
 12308 %}
 12310 instruct MoveF2I_reg_reg_sse(eRegI dst, regX src) %{
 12311   predicate(UseSSE>=2);
 12312   match(Set dst (MoveF2I src));
 12313   effect( DEF dst, USE src );
 12314   ins_cost(85);
 12315   format %{ "MOVD   $dst,$src\t# MoveF2I_reg_reg_sse" %}
 12316   ins_encode( MovX2I_reg(dst, src));
 12317   ins_pipe( pipe_slow );
 12318 %}
 12320 instruct MoveI2F_reg_stack(stackSlotF dst, eRegI src) %{
 12321   match(Set dst (MoveI2F src));
 12322   effect( DEF dst, USE src );
 12324   ins_cost(100);
 12325   format %{ "MOV    $dst,$src\t# MoveI2F_reg_stack" %}
 12326   opcode(0x89);
 12327   ins_encode( OpcPRegSS( dst, src ) );
 12328   ins_pipe( ialu_mem_reg );
 12329 %}
 12332 instruct MoveI2F_stack_reg(regF dst, stackSlotI src) %{
 12333   predicate(UseSSE==0);
 12334   match(Set dst (MoveI2F src));
 12335   effect(DEF dst, USE src);
 12337   ins_cost(125);
 12338   format %{ "FLD_S  $src\n\t"
 12339             "FSTP   $dst\t# MoveI2F_stack_reg" %}
 12340   opcode(0xD9);               /* D9 /0, FLD m32real */
 12341   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
 12342               Pop_Reg_F(dst) );
 12343   ins_pipe( fpu_reg_mem );
 12344 %}
 12346 instruct MoveI2F_stack_reg_sse(regX dst, stackSlotI src) %{
 12347   predicate(UseSSE>=1);
 12348   match(Set dst (MoveI2F src));
 12349   effect( DEF dst, USE src );
 12351   ins_cost(95);
 12352   format %{ "MOVSS  $dst,$src\t# MoveI2F_stack_reg_sse" %}
 12353   ins_encode( Opcode(0xF3), Opcode(0x0F), Opcode(0x10), RegMem(dst,src));
 12354   ins_pipe( pipe_slow );
 12355 %}
 12357 instruct MoveI2F_reg_reg_sse(regX dst, eRegI src) %{
 12358   predicate(UseSSE>=2);
 12359   match(Set dst (MoveI2F src));
 12360   effect( DEF dst, USE src );
 12362   ins_cost(85);
 12363   format %{ "MOVD   $dst,$src\t# MoveI2F_reg_reg_sse" %}
 12364   ins_encode( MovI2X_reg(dst, src) );
 12365   ins_pipe( pipe_slow );
 12366 %}
 12368 instruct MoveD2L_stack_reg(eRegL dst, stackSlotD src) %{
 12369   match(Set dst (MoveD2L src));
 12370   effect(DEF dst, USE src);
 12372   ins_cost(250);
 12373   format %{ "MOV    $dst.lo,$src\n\t"
 12374             "MOV    $dst.hi,$src+4\t# MoveD2L_stack_reg" %}
 12375   opcode(0x8B, 0x8B);
 12376   ins_encode( OpcP, RegMem(dst,src), OpcS, RegMem_Hi(dst,src));
 12377   ins_pipe( ialu_mem_long_reg );
 12378 %}
 12380 instruct MoveD2L_reg_stack(stackSlotL dst, regD src) %{
 12381   predicate(UseSSE<=1);
 12382   match(Set dst (MoveD2L src));
 12383   effect(DEF dst, USE src);
 12385   ins_cost(125);
 12386   format %{ "FST_D  $dst,$src\t# MoveD2L_reg_stack" %}
 12387   ins_encode( Pop_Mem_Reg_D(dst, src) );
 12388   ins_pipe( fpu_mem_reg );
 12389 %}
 12391 instruct MoveD2L_reg_stack_sse(stackSlotL dst, regXD src) %{
 12392   predicate(UseSSE>=2);
 12393   match(Set dst (MoveD2L src));
 12394   effect(DEF dst, USE src);
 12395   ins_cost(95);
 12397   format %{ "MOVSD  $dst,$src\t# MoveD2L_reg_stack_sse" %}
 12398   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x11), RegMem(src,dst));
 12399   ins_pipe( pipe_slow );
 12400 %}
 12402 instruct MoveD2L_reg_reg_sse(eRegL dst, regXD src, regXD tmp) %{
 12403   predicate(UseSSE>=2);
 12404   match(Set dst (MoveD2L src));
 12405   effect(DEF dst, USE src, TEMP tmp);
 12406   ins_cost(85);
 12407   format %{ "MOVD   $dst.lo,$src\n\t"
 12408             "PSHUFLW $tmp,$src,0x4E\n\t"
 12409             "MOVD   $dst.hi,$tmp\t# MoveD2L_reg_reg_sse" %}
 12410   ins_encode( MovXD2L_reg(dst, src, tmp) );
 12411   ins_pipe( pipe_slow );
 12412 %}
 12414 instruct MoveL2D_reg_stack(stackSlotD dst, eRegL src) %{
 12415   match(Set dst (MoveL2D src));
 12416   effect(DEF dst, USE src);
 12418   ins_cost(200);
 12419   format %{ "MOV    $dst,$src.lo\n\t"
 12420             "MOV    $dst+4,$src.hi\t# MoveL2D_reg_stack" %}
 12421   opcode(0x89, 0x89);
 12422   ins_encode( OpcP, RegMem( src, dst ), OpcS, RegMem_Hi( src, dst ) );
 12423   ins_pipe( ialu_mem_long_reg );
 12424 %}
 12427 instruct MoveL2D_stack_reg(regD dst, stackSlotL src) %{
 12428   predicate(UseSSE<=1);
 12429   match(Set dst (MoveL2D src));
 12430   effect(DEF dst, USE src);
 12431   ins_cost(125);
 12433   format %{ "FLD_D  $src\n\t"
 12434             "FSTP   $dst\t# MoveL2D_stack_reg" %}
 12435   opcode(0xDD);               /* DD /0, FLD m64real */
 12436   ins_encode( OpcP, RMopc_Mem_no_oop(0x00,src),
 12437               Pop_Reg_D(dst) );
 12438   ins_pipe( fpu_reg_mem );
 12439 %}
 12442 instruct MoveL2D_stack_reg_sse(regXD dst, stackSlotL src) %{
 12443   predicate(UseSSE>=2 && UseXmmLoadAndClearUpper);
 12444   match(Set dst (MoveL2D src));
 12445   effect(DEF dst, USE src);
 12447   ins_cost(95);
 12448   format %{ "MOVSD  $dst,$src\t# MoveL2D_stack_reg_sse" %}
 12449   ins_encode( Opcode(0xF2), Opcode(0x0F), Opcode(0x10), RegMem(dst,src));
 12450   ins_pipe( pipe_slow );
 12451 %}
 12453 instruct MoveL2D_stack_reg_sse_partial(regXD dst, stackSlotL src) %{
 12454   predicate(UseSSE>=2 && !UseXmmLoadAndClearUpper);
 12455   match(Set dst (MoveL2D src));
 12456   effect(DEF dst, USE src);
 12458   ins_cost(95);
 12459   format %{ "MOVLPD $dst,$src\t# MoveL2D_stack_reg_sse" %}
 12460   ins_encode( Opcode(0x66), Opcode(0x0F), Opcode(0x12), RegMem(dst,src));
 12461   ins_pipe( pipe_slow );
 12462 %}
 12464 instruct MoveL2D_reg_reg_sse(regXD dst, eRegL src, regXD tmp) %{
 12465   predicate(UseSSE>=2);
 12466   match(Set dst (MoveL2D src));
 12467   effect(TEMP dst, USE src, TEMP tmp);
 12468   ins_cost(85);
 12469   format %{ "MOVD   $dst,$src.lo\n\t"
 12470             "MOVD   $tmp,$src.hi\n\t"
 12471             "PUNPCKLDQ $dst,$tmp\t# MoveL2D_reg_reg_sse" %}
 12472   ins_encode( MovL2XD_reg(dst, src, tmp) );
 12473   ins_pipe( pipe_slow );
 12474 %}
 12476 // Replicate scalar to packed byte (1 byte) values in xmm
 12477 instruct Repl8B_reg(regXD dst, regXD src) %{
 12478   predicate(UseSSE>=2);
 12479   match(Set dst (Replicate8B src));
 12480   format %{ "MOVDQA  $dst,$src\n\t"
 12481             "PUNPCKLBW $dst,$dst\n\t"
 12482             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
 12483   ins_encode( pshufd_8x8(dst, src));
 12484   ins_pipe( pipe_slow );
 12485 %}
 12487 // Replicate scalar to packed byte (1 byte) values in xmm
 12488 instruct Repl8B_eRegI(regXD dst, eRegI src) %{
 12489   predicate(UseSSE>=2);
 12490   match(Set dst (Replicate8B src));
 12491   format %{ "MOVD    $dst,$src\n\t"
 12492             "PUNPCKLBW $dst,$dst\n\t"
 12493             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
 12494   ins_encode( mov_i2x(dst, src), pshufd_8x8(dst, dst));
 12495   ins_pipe( pipe_slow );
 12496 %}
 12498 // Replicate scalar zero to packed byte (1 byte) values in xmm
 12499 instruct Repl8B_immI0(regXD dst, immI0 zero) %{
 12500   predicate(UseSSE>=2);
 12501   match(Set dst (Replicate8B zero));
 12502   format %{ "PXOR  $dst,$dst\t! replicate8B" %}
 12503   ins_encode( pxor(dst, dst));
 12504   ins_pipe( fpu_reg_reg );
 12505 %}
 12507 // Replicate scalar to packed shore (2 byte) values in xmm
 12508 instruct Repl4S_reg(regXD dst, regXD src) %{
 12509   predicate(UseSSE>=2);
 12510   match(Set dst (Replicate4S src));
 12511   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4S" %}
 12512   ins_encode( pshufd_4x16(dst, src));
 12513   ins_pipe( fpu_reg_reg );
 12514 %}
 12516 // Replicate scalar to packed shore (2 byte) values in xmm
 12517 instruct Repl4S_eRegI(regXD dst, eRegI src) %{
 12518   predicate(UseSSE>=2);
 12519   match(Set dst (Replicate4S src));
 12520   format %{ "MOVD    $dst,$src\n\t"
 12521             "PSHUFLW $dst,$dst,0x00\t! replicate4S" %}
 12522   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
 12523   ins_pipe( fpu_reg_reg );
 12524 %}
 12526 // Replicate scalar zero to packed short (2 byte) values in xmm
 12527 instruct Repl4S_immI0(regXD dst, immI0 zero) %{
 12528   predicate(UseSSE>=2);
 12529   match(Set dst (Replicate4S zero));
 12530   format %{ "PXOR  $dst,$dst\t! replicate4S" %}
 12531   ins_encode( pxor(dst, dst));
 12532   ins_pipe( fpu_reg_reg );
 12533 %}
 12535 // Replicate scalar to packed char (2 byte) values in xmm
 12536 instruct Repl4C_reg(regXD dst, regXD src) %{
 12537   predicate(UseSSE>=2);
 12538   match(Set dst (Replicate4C src));
 12539   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4C" %}
 12540   ins_encode( pshufd_4x16(dst, src));
 12541   ins_pipe( fpu_reg_reg );
 12542 %}
 12544 // Replicate scalar to packed char (2 byte) values in xmm
 12545 instruct Repl4C_eRegI(regXD dst, eRegI src) %{
 12546   predicate(UseSSE>=2);
 12547   match(Set dst (Replicate4C src));
 12548   format %{ "MOVD    $dst,$src\n\t"
 12549             "PSHUFLW $dst,$dst,0x00\t! replicate4C" %}
 12550   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
 12551   ins_pipe( fpu_reg_reg );
 12552 %}
 12554 // Replicate scalar zero to packed char (2 byte) values in xmm
 12555 instruct Repl4C_immI0(regXD dst, immI0 zero) %{
 12556   predicate(UseSSE>=2);
 12557   match(Set dst (Replicate4C zero));
 12558   format %{ "PXOR  $dst,$dst\t! replicate4C" %}
 12559   ins_encode( pxor(dst, dst));
 12560   ins_pipe( fpu_reg_reg );
 12561 %}
 12563 // Replicate scalar to packed integer (4 byte) values in xmm
 12564 instruct Repl2I_reg(regXD dst, regXD src) %{
 12565   predicate(UseSSE>=2);
 12566   match(Set dst (Replicate2I src));
 12567   format %{ "PSHUFD $dst,$src,0x00\t! replicate2I" %}
 12568   ins_encode( pshufd(dst, src, 0x00));
 12569   ins_pipe( fpu_reg_reg );
 12570 %}
 12572 // Replicate scalar to packed integer (4 byte) values in xmm
 12573 instruct Repl2I_eRegI(regXD dst, eRegI src) %{
 12574   predicate(UseSSE>=2);
 12575   match(Set dst (Replicate2I src));
 12576   format %{ "MOVD   $dst,$src\n\t"
 12577             "PSHUFD $dst,$dst,0x00\t! replicate2I" %}
 12578   ins_encode( mov_i2x(dst, src), pshufd(dst, dst, 0x00));
 12579   ins_pipe( fpu_reg_reg );
 12580 %}
 12582 // Replicate scalar zero to packed integer (2 byte) values in xmm
 12583 instruct Repl2I_immI0(regXD dst, immI0 zero) %{
 12584   predicate(UseSSE>=2);
 12585   match(Set dst (Replicate2I zero));
 12586   format %{ "PXOR  $dst,$dst\t! replicate2I" %}
 12587   ins_encode( pxor(dst, dst));
 12588   ins_pipe( fpu_reg_reg );
 12589 %}
 12591 // Replicate scalar to packed single precision floating point values in xmm
 12592 instruct Repl2F_reg(regXD dst, regXD src) %{
 12593   predicate(UseSSE>=2);
 12594   match(Set dst (Replicate2F src));
 12595   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
 12596   ins_encode( pshufd(dst, src, 0xe0));
 12597   ins_pipe( fpu_reg_reg );
 12598 %}
 12600 // Replicate scalar to packed single precision floating point values in xmm
 12601 instruct Repl2F_regX(regXD dst, regX src) %{
 12602   predicate(UseSSE>=2);
 12603   match(Set dst (Replicate2F src));
 12604   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
 12605   ins_encode( pshufd(dst, src, 0xe0));
 12606   ins_pipe( fpu_reg_reg );
 12607 %}
 12609 // Replicate scalar to packed single precision floating point values in xmm
 12610 instruct Repl2F_immXF0(regXD dst, immXF0 zero) %{
 12611   predicate(UseSSE>=2);
 12612   match(Set dst (Replicate2F zero));
 12613   format %{ "PXOR  $dst,$dst\t! replicate2F" %}
 12614   ins_encode( pxor(dst, dst));
 12615   ins_pipe( fpu_reg_reg );
 12616 %}
 12618 // =======================================================================
 12619 // fast clearing of an array
 12620 instruct rep_stos(eCXRegI cnt, eDIRegP base, eAXRegI zero, Universe dummy, eFlagsReg cr) %{
 12621   match(Set dummy (ClearArray cnt base));
 12622   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
 12623   format %{ "SHL    ECX,1\t# Convert doublewords to words\n\t"
 12624             "XOR    EAX,EAX\n\t"
 12625             "REP STOS\t# store EAX into [EDI++] while ECX--" %}
 12626   opcode(0,0x4);
 12627   ins_encode( Opcode(0xD1), RegOpc(ECX),
 12628               OpcRegReg(0x33,EAX,EAX),
 12629               Opcode(0xF3), Opcode(0xAB) );
 12630   ins_pipe( pipe_slow );
 12631 %}
 12633 instruct string_compare(eDIRegP str1, eCXRegI cnt1, eSIRegP str2, eDXRegI cnt2,
 12634                         eAXRegI result, regXD tmp1, eFlagsReg cr) %{
 12635   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
 12636   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
 12638   format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
 12639   ins_encode %{
 12640     __ string_compare($str1$$Register, $str2$$Register,
 12641                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
 12642                       $tmp1$$XMMRegister);
 12643   %}
 12644   ins_pipe( pipe_slow );
 12645 %}
 12647 // fast string equals
 12648 instruct string_equals(eDIRegP str1, eSIRegP str2, eCXRegI cnt, eAXRegI result,
 12649                        regXD tmp1, regXD tmp2, eBXRegI tmp3, eFlagsReg cr) %{
 12650   match(Set result (StrEquals (Binary str1 str2) cnt));
 12651   effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
 12653   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
 12654   ins_encode %{
 12655     __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
 12656                           $cnt$$Register, $result$$Register, $tmp3$$Register,
 12657                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
 12658   %}
 12659   ins_pipe( pipe_slow );
 12660 %}
 12662 // fast search of substring with known size.
 12663 instruct string_indexof_con(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, immI int_cnt2,
 12664                             eBXRegI result, regXD vec, eAXRegI cnt2, eCXRegI tmp, eFlagsReg cr) %{
 12665   predicate(UseSSE42Intrinsics);
 12666   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
 12667   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
 12669   format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $vec, $cnt1, $cnt2, $tmp" %}
 12670   ins_encode %{
 12671     int icnt2 = (int)$int_cnt2$$constant;
 12672     if (icnt2 >= 8) {
 12673       // IndexOf for constant substrings with size >= 8 elements
 12674       // which don't need to be loaded through stack.
 12675       __ string_indexofC8($str1$$Register, $str2$$Register,
 12676                           $cnt1$$Register, $cnt2$$Register,
 12677                           icnt2, $result$$Register,
 12678                           $vec$$XMMRegister, $tmp$$Register);
 12679     } else {
 12680       // Small strings are loaded through stack if they cross page boundary.
 12681       __ string_indexof($str1$$Register, $str2$$Register,
 12682                         $cnt1$$Register, $cnt2$$Register,
 12683                         icnt2, $result$$Register,
 12684                         $vec$$XMMRegister, $tmp$$Register);
 12686   %}
 12687   ins_pipe( pipe_slow );
 12688 %}
 12690 instruct string_indexof(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, eAXRegI cnt2,
 12691                         eBXRegI result, regXD vec, eCXRegI tmp, eFlagsReg cr) %{
 12692   predicate(UseSSE42Intrinsics);
 12693   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
 12694   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
 12696   format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
 12697   ins_encode %{
 12698     __ string_indexof($str1$$Register, $str2$$Register,
 12699                       $cnt1$$Register, $cnt2$$Register,
 12700                       (-1), $result$$Register,
 12701                       $vec$$XMMRegister, $tmp$$Register);
 12702   %}
 12703   ins_pipe( pipe_slow );
 12704 %}
 12706 // fast array equals
 12707 instruct array_equals(eDIRegP ary1, eSIRegP ary2, eAXRegI result,
 12708                       regXD tmp1, regXD tmp2, eCXRegI tmp3, eBXRegI tmp4, eFlagsReg cr)
 12709 %{
 12710   match(Set result (AryEq ary1 ary2));
 12711   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
 12712   //ins_cost(300);
 12714   format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
 12715   ins_encode %{
 12716     __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
 12717                           $tmp3$$Register, $result$$Register, $tmp4$$Register,
 12718                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
 12719   %}
 12720   ins_pipe( pipe_slow );
 12721 %}
 12723 //----------Control Flow Instructions------------------------------------------
 12724 // Signed compare Instructions
 12725 instruct compI_eReg(eFlagsReg cr, eRegI op1, eRegI op2) %{
 12726   match(Set cr (CmpI op1 op2));
 12727   effect( DEF cr, USE op1, USE op2 );
 12728   format %{ "CMP    $op1,$op2" %}
 12729   opcode(0x3B);  /* Opcode 3B /r */
 12730   ins_encode( OpcP, RegReg( op1, op2) );
 12731   ins_pipe( ialu_cr_reg_reg );
 12732 %}
 12734 instruct compI_eReg_imm(eFlagsReg cr, eRegI op1, immI op2) %{
 12735   match(Set cr (CmpI op1 op2));
 12736   effect( DEF cr, USE op1 );
 12737   format %{ "CMP    $op1,$op2" %}
 12738   opcode(0x81,0x07);  /* Opcode 81 /7 */
 12739   // ins_encode( RegImm( op1, op2) );  /* Was CmpImm */
 12740   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 12741   ins_pipe( ialu_cr_reg_imm );
 12742 %}
 12744 // Cisc-spilled version of cmpI_eReg
 12745 instruct compI_eReg_mem(eFlagsReg cr, eRegI op1, memory op2) %{
 12746   match(Set cr (CmpI op1 (LoadI op2)));
 12748   format %{ "CMP    $op1,$op2" %}
 12749   ins_cost(500);
 12750   opcode(0x3B);  /* Opcode 3B /r */
 12751   ins_encode( OpcP, RegMem( op1, op2) );
 12752   ins_pipe( ialu_cr_reg_mem );
 12753 %}
 12755 instruct testI_reg( eFlagsReg cr, eRegI src, immI0 zero ) %{
 12756   match(Set cr (CmpI src zero));
 12757   effect( DEF cr, USE src );
 12759   format %{ "TEST   $src,$src" %}
 12760   opcode(0x85);
 12761   ins_encode( OpcP, RegReg( src, src ) );
 12762   ins_pipe( ialu_cr_reg_imm );
 12763 %}
 12765 instruct testI_reg_imm( eFlagsReg cr, eRegI src, immI con, immI0 zero ) %{
 12766   match(Set cr (CmpI (AndI src con) zero));
 12768   format %{ "TEST   $src,$con" %}
 12769   opcode(0xF7,0x00);
 12770   ins_encode( OpcP, RegOpc(src), Con32(con) );
 12771   ins_pipe( ialu_cr_reg_imm );
 12772 %}
 12774 instruct testI_reg_mem( eFlagsReg cr, eRegI src, memory mem, immI0 zero ) %{
 12775   match(Set cr (CmpI (AndI src mem) zero));
 12777   format %{ "TEST   $src,$mem" %}
 12778   opcode(0x85);
 12779   ins_encode( OpcP, RegMem( src, mem ) );
 12780   ins_pipe( ialu_cr_reg_mem );
 12781 %}
 12783 // Unsigned compare Instructions; really, same as signed except they
 12784 // produce an eFlagsRegU instead of eFlagsReg.
 12785 instruct compU_eReg(eFlagsRegU cr, eRegI op1, eRegI op2) %{
 12786   match(Set cr (CmpU op1 op2));
 12788   format %{ "CMPu   $op1,$op2" %}
 12789   opcode(0x3B);  /* Opcode 3B /r */
 12790   ins_encode( OpcP, RegReg( op1, op2) );
 12791   ins_pipe( ialu_cr_reg_reg );
 12792 %}
 12794 instruct compU_eReg_imm(eFlagsRegU cr, eRegI op1, immI op2) %{
 12795   match(Set cr (CmpU op1 op2));
 12797   format %{ "CMPu   $op1,$op2" %}
 12798   opcode(0x81,0x07);  /* Opcode 81 /7 */
 12799   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 12800   ins_pipe( ialu_cr_reg_imm );
 12801 %}
 12803 // // Cisc-spilled version of cmpU_eReg
 12804 instruct compU_eReg_mem(eFlagsRegU cr, eRegI op1, memory op2) %{
 12805   match(Set cr (CmpU op1 (LoadI op2)));
 12807   format %{ "CMPu   $op1,$op2" %}
 12808   ins_cost(500);
 12809   opcode(0x3B);  /* Opcode 3B /r */
 12810   ins_encode( OpcP, RegMem( op1, op2) );
 12811   ins_pipe( ialu_cr_reg_mem );
 12812 %}
 12814 // // Cisc-spilled version of cmpU_eReg
 12815 //instruct compU_mem_eReg(eFlagsRegU cr, memory op1, eRegI op2) %{
 12816 //  match(Set cr (CmpU (LoadI op1) op2));
 12817 //
 12818 //  format %{ "CMPu   $op1,$op2" %}
 12819 //  ins_cost(500);
 12820 //  opcode(0x39);  /* Opcode 39 /r */
 12821 //  ins_encode( OpcP, RegMem( op1, op2) );
 12822 //%}
 12824 instruct testU_reg( eFlagsRegU cr, eRegI src, immI0 zero ) %{
 12825   match(Set cr (CmpU src zero));
 12827   format %{ "TESTu  $src,$src" %}
 12828   opcode(0x85);
 12829   ins_encode( OpcP, RegReg( src, src ) );
 12830   ins_pipe( ialu_cr_reg_imm );
 12831 %}
 12833 // Unsigned pointer compare Instructions
 12834 instruct compP_eReg(eFlagsRegU cr, eRegP op1, eRegP op2) %{
 12835   match(Set cr (CmpP op1 op2));
 12837   format %{ "CMPu   $op1,$op2" %}
 12838   opcode(0x3B);  /* Opcode 3B /r */
 12839   ins_encode( OpcP, RegReg( op1, op2) );
 12840   ins_pipe( ialu_cr_reg_reg );
 12841 %}
 12843 instruct compP_eReg_imm(eFlagsRegU cr, eRegP op1, immP op2) %{
 12844   match(Set cr (CmpP op1 op2));
 12846   format %{ "CMPu   $op1,$op2" %}
 12847   opcode(0x81,0x07);  /* Opcode 81 /7 */
 12848   ins_encode( OpcSErm( op1, op2 ), Con8or32( op2 ) );
 12849   ins_pipe( ialu_cr_reg_imm );
 12850 %}
 12852 // // Cisc-spilled version of cmpP_eReg
 12853 instruct compP_eReg_mem(eFlagsRegU cr, eRegP op1, memory op2) %{
 12854   match(Set cr (CmpP op1 (LoadP op2)));
 12856   format %{ "CMPu   $op1,$op2" %}
 12857   ins_cost(500);
 12858   opcode(0x3B);  /* Opcode 3B /r */
 12859   ins_encode( OpcP, RegMem( op1, op2) );
 12860   ins_pipe( ialu_cr_reg_mem );
 12861 %}
 12863 // // Cisc-spilled version of cmpP_eReg
 12864 //instruct compP_mem_eReg(eFlagsRegU cr, memory op1, eRegP op2) %{
 12865 //  match(Set cr (CmpP (LoadP op1) op2));
 12866 //
 12867 //  format %{ "CMPu   $op1,$op2" %}
 12868 //  ins_cost(500);
 12869 //  opcode(0x39);  /* Opcode 39 /r */
 12870 //  ins_encode( OpcP, RegMem( op1, op2) );
 12871 //%}
 12873 // Compare raw pointer (used in out-of-heap check).
 12874 // Only works because non-oop pointers must be raw pointers
 12875 // and raw pointers have no anti-dependencies.
 12876 instruct compP_mem_eReg( eFlagsRegU cr, eRegP op1, memory op2 ) %{
 12877   predicate( !n->in(2)->in(2)->bottom_type()->isa_oop_ptr() );
 12878   match(Set cr (CmpP op1 (LoadP op2)));
 12880   format %{ "CMPu   $op1,$op2" %}
 12881   opcode(0x3B);  /* Opcode 3B /r */
 12882   ins_encode( OpcP, RegMem( op1, op2) );
 12883   ins_pipe( ialu_cr_reg_mem );
 12884 %}
 12886 //
 12887 // This will generate a signed flags result. This should be ok
 12888 // since any compare to a zero should be eq/neq.
 12889 instruct testP_reg( eFlagsReg cr, eRegP src, immP0 zero ) %{
 12890   match(Set cr (CmpP src zero));
 12892   format %{ "TEST   $src,$src" %}
 12893   opcode(0x85);
 12894   ins_encode( OpcP, RegReg( src, src ) );
 12895   ins_pipe( ialu_cr_reg_imm );
 12896 %}
 12898 // Cisc-spilled version of testP_reg
 12899 // This will generate a signed flags result. This should be ok
 12900 // since any compare to a zero should be eq/neq.
 12901 instruct testP_Reg_mem( eFlagsReg cr, memory op, immI0 zero ) %{
 12902   match(Set cr (CmpP (LoadP op) zero));
 12904   format %{ "TEST   $op,0xFFFFFFFF" %}
 12905   ins_cost(500);
 12906   opcode(0xF7);               /* Opcode F7 /0 */
 12907   ins_encode( OpcP, RMopc_Mem(0x00,op), Con_d32(0xFFFFFFFF) );
 12908   ins_pipe( ialu_cr_reg_imm );
 12909 %}
 12911 // Yanked all unsigned pointer compare operations.
 12912 // Pointer compares are done with CmpP which is already unsigned.
 12914 //----------Max and Min--------------------------------------------------------
 12915 // Min Instructions
 12916 ////
 12917 //   *** Min and Max using the conditional move are slower than the
 12918 //   *** branch version on a Pentium III.
 12919 // // Conditional move for min
 12920 //instruct cmovI_reg_lt( eRegI op2, eRegI op1, eFlagsReg cr ) %{
 12921 //  effect( USE_DEF op2, USE op1, USE cr );
 12922 //  format %{ "CMOVlt $op2,$op1\t! min" %}
 12923 //  opcode(0x4C,0x0F);
 12924 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
 12925 //  ins_pipe( pipe_cmov_reg );
 12926 //%}
 12927 //
 12928 //// Min Register with Register (P6 version)
 12929 //instruct minI_eReg_p6( eRegI op1, eRegI op2 ) %{
 12930 //  predicate(VM_Version::supports_cmov() );
 12931 //  match(Set op2 (MinI op1 op2));
 12932 //  ins_cost(200);
 12933 //  expand %{
 12934 //    eFlagsReg cr;
 12935 //    compI_eReg(cr,op1,op2);
 12936 //    cmovI_reg_lt(op2,op1,cr);
 12937 //  %}
 12938 //%}
 12940 // Min Register with Register (generic version)
 12941 instruct minI_eReg(eRegI dst, eRegI src, eFlagsReg flags) %{
 12942   match(Set dst (MinI dst src));
 12943   effect(KILL flags);
 12944   ins_cost(300);
 12946   format %{ "MIN    $dst,$src" %}
 12947   opcode(0xCC);
 12948   ins_encode( min_enc(dst,src) );
 12949   ins_pipe( pipe_slow );
 12950 %}
 12952 // Max Register with Register
 12953 //   *** Min and Max using the conditional move are slower than the
 12954 //   *** branch version on a Pentium III.
 12955 // // Conditional move for max
 12956 //instruct cmovI_reg_gt( eRegI op2, eRegI op1, eFlagsReg cr ) %{
 12957 //  effect( USE_DEF op2, USE op1, USE cr );
 12958 //  format %{ "CMOVgt $op2,$op1\t! max" %}
 12959 //  opcode(0x4F,0x0F);
 12960 //  ins_encode( OpcS, OpcP, RegReg( op2, op1 ) );
 12961 //  ins_pipe( pipe_cmov_reg );
 12962 //%}
 12963 //
 12964 // // Max Register with Register (P6 version)
 12965 //instruct maxI_eReg_p6( eRegI op1, eRegI op2 ) %{
 12966 //  predicate(VM_Version::supports_cmov() );
 12967 //  match(Set op2 (MaxI op1 op2));
 12968 //  ins_cost(200);
 12969 //  expand %{
 12970 //    eFlagsReg cr;
 12971 //    compI_eReg(cr,op1,op2);
 12972 //    cmovI_reg_gt(op2,op1,cr);
 12973 //  %}
 12974 //%}
 12976 // Max Register with Register (generic version)
 12977 instruct maxI_eReg(eRegI dst, eRegI src, eFlagsReg flags) %{
 12978   match(Set dst (MaxI dst src));
 12979   effect(KILL flags);
 12980   ins_cost(300);
 12982   format %{ "MAX    $dst,$src" %}
 12983   opcode(0xCC);
 12984   ins_encode( max_enc(dst,src) );
 12985   ins_pipe( pipe_slow );
 12986 %}
 12988 // ============================================================================
 12989 // Counted Loop limit node which represents exact final iterator value.
 12990 // Note: the resulting value should fit into integer range since
 12991 // counted loops have limit check on overflow.
 12992 instruct loopLimit_eReg(eAXRegI limit, nadxRegI init, immI stride, eDXRegI limit_hi, nadxRegI tmp, eFlagsReg flags) %{
 12993   match(Set limit (LoopLimit (Binary init limit) stride));
 12994   effect(TEMP limit_hi, TEMP tmp, KILL flags);
 12995   ins_cost(300);
 12997   format %{ "loopLimit $init,$limit,$stride  # $limit = $init + $stride *( $limit - $init + $stride -1)/ $stride, kills $limit_hi" %}
 12998   ins_encode %{
 12999     int strd = (int)$stride$$constant;
 13000     assert(strd != 1 && strd != -1, "sanity");
 13001     int m1 = (strd > 0) ? 1 : -1;
 13002     // Convert limit to long (EAX:EDX)
 13003     __ cdql();
 13004     // Convert init to long (init:tmp)
 13005     __ movl($tmp$$Register, $init$$Register);
 13006     __ sarl($tmp$$Register, 31);
 13007     // $limit - $init
 13008     __ subl($limit$$Register, $init$$Register);
 13009     __ sbbl($limit_hi$$Register, $tmp$$Register);
 13010     // + ($stride - 1)
 13011     if (strd > 0) {
 13012       __ addl($limit$$Register, (strd - 1));
 13013       __ adcl($limit_hi$$Register, 0);
 13014       __ movl($tmp$$Register, strd);
 13015     } else {
 13016       __ addl($limit$$Register, (strd + 1));
 13017       __ adcl($limit_hi$$Register, -1);
 13018       __ lneg($limit_hi$$Register, $limit$$Register);
 13019       __ movl($tmp$$Register, -strd);
 13021     // signed devision: (EAX:EDX) / pos_stride
 13022     __ idivl($tmp$$Register);
 13023     if (strd < 0) {
 13024       // restore sign
 13025       __ negl($tmp$$Register);
 13027     // (EAX) * stride
 13028     __ mull($tmp$$Register);
 13029     // + init (ignore upper bits)
 13030     __ addl($limit$$Register, $init$$Register);
 13031   %}
 13032   ins_pipe( pipe_slow );
 13033 %}
 13035 // ============================================================================
 13036 // Branch Instructions
 13037 // Jump Table
 13038 instruct jumpXtnd(eRegI switch_val) %{
 13039   match(Jump switch_val);
 13040   ins_cost(350);
 13041   format %{  "JMP    [$constantaddress](,$switch_val,1)\n\t" %}
 13042   ins_encode %{
 13043     // Jump to Address(table_base + switch_reg)
 13044     Address index(noreg, $switch_val$$Register, Address::times_1);
 13045     __ jump(ArrayAddress($constantaddress, index));
 13046   %}
 13047   ins_pipe(pipe_jmp);
 13048 %}
 13050 // Jump Direct - Label defines a relative address from JMP+1
 13051 instruct jmpDir(label labl) %{
 13052   match(Goto);
 13053   effect(USE labl);
 13055   ins_cost(300);
 13056   format %{ "JMP    $labl" %}
 13057   size(5);
 13058   opcode(0xE9);
 13059   ins_encode( OpcP, Lbl( labl ) );
 13060   ins_pipe( pipe_jmp );
 13061 %}
 13063 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13064 instruct jmpCon(cmpOp cop, eFlagsReg cr, label labl) %{
 13065   match(If cop cr);
 13066   effect(USE labl);
 13068   ins_cost(300);
 13069   format %{ "J$cop    $labl" %}
 13070   size(6);
 13071   opcode(0x0F, 0x80);
 13072   ins_encode( Jcc( cop, labl) );
 13073   ins_pipe( pipe_jcc );
 13074 %}
 13076 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13077 instruct jmpLoopEnd(cmpOp cop, eFlagsReg cr, label labl) %{
 13078   match(CountedLoopEnd cop cr);
 13079   effect(USE labl);
 13081   ins_cost(300);
 13082   format %{ "J$cop    $labl\t# Loop end" %}
 13083   size(6);
 13084   opcode(0x0F, 0x80);
 13085   ins_encode( Jcc( cop, labl) );
 13086   ins_pipe( pipe_jcc );
 13087 %}
 13089 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13090 instruct jmpLoopEndU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 13091   match(CountedLoopEnd cop cmp);
 13092   effect(USE labl);
 13094   ins_cost(300);
 13095   format %{ "J$cop,u  $labl\t# Loop end" %}
 13096   size(6);
 13097   opcode(0x0F, 0x80);
 13098   ins_encode( Jcc( cop, labl) );
 13099   ins_pipe( pipe_jcc );
 13100 %}
 13102 instruct jmpLoopEndUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 13103   match(CountedLoopEnd cop cmp);
 13104   effect(USE labl);
 13106   ins_cost(200);
 13107   format %{ "J$cop,u  $labl\t# Loop end" %}
 13108   size(6);
 13109   opcode(0x0F, 0x80);
 13110   ins_encode( Jcc( cop, labl) );
 13111   ins_pipe( pipe_jcc );
 13112 %}
 13114 // Jump Direct Conditional - using unsigned comparison
 13115 instruct jmpConU(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 13116   match(If cop cmp);
 13117   effect(USE labl);
 13119   ins_cost(300);
 13120   format %{ "J$cop,u  $labl" %}
 13121   size(6);
 13122   opcode(0x0F, 0x80);
 13123   ins_encode(Jcc(cop, labl));
 13124   ins_pipe(pipe_jcc);
 13125 %}
 13127 instruct jmpConUCF(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 13128   match(If cop cmp);
 13129   effect(USE labl);
 13131   ins_cost(200);
 13132   format %{ "J$cop,u  $labl" %}
 13133   size(6);
 13134   opcode(0x0F, 0x80);
 13135   ins_encode(Jcc(cop, labl));
 13136   ins_pipe(pipe_jcc);
 13137 %}
 13139 instruct jmpConUCF2(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
 13140   match(If cop cmp);
 13141   effect(USE labl);
 13143   ins_cost(200);
 13144   format %{ $$template
 13145     if ($cop$$cmpcode == Assembler::notEqual) {
 13146       $$emit$$"JP,u   $labl\n\t"
 13147       $$emit$$"J$cop,u   $labl"
 13148     } else {
 13149       $$emit$$"JP,u   done\n\t"
 13150       $$emit$$"J$cop,u   $labl\n\t"
 13151       $$emit$$"done:"
 13153   %}
 13154   size(12);
 13155   opcode(0x0F, 0x80);
 13156   ins_encode %{
 13157     Label* l = $labl$$label;
 13158     $$$emit8$primary;
 13159     emit_cc(cbuf, $secondary, Assembler::parity);
 13160     int parity_disp = -1;
 13161     bool ok = false;
 13162     if ($cop$$cmpcode == Assembler::notEqual) {
 13163        // the two jumps 6 bytes apart so the jump distances are too
 13164        parity_disp = l->loc_pos() - (cbuf.insts_size() + 4);
 13165     } else if ($cop$$cmpcode == Assembler::equal) {
 13166        parity_disp = 6;
 13167        ok = true;
 13168     } else {
 13169        ShouldNotReachHere();
 13171     emit_d32(cbuf, parity_disp);
 13172     $$$emit8$primary;
 13173     emit_cc(cbuf, $secondary, $cop$$cmpcode);
 13174     int disp = l->loc_pos() - (cbuf.insts_size() + 4);
 13175     emit_d32(cbuf, disp);
 13176   %}
 13177   ins_pipe(pipe_jcc);
 13178 %}
 13180 // ============================================================================
 13181 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary superklass
 13182 // array for an instance of the superklass.  Set a hidden internal cache on a
 13183 // hit (cache is checked with exposed code in gen_subtype_check()).  Return
 13184 // NZ for a miss or zero for a hit.  The encoding ALSO sets flags.
 13185 instruct partialSubtypeCheck( eDIRegP result, eSIRegP sub, eAXRegP super, eCXRegI rcx, eFlagsReg cr ) %{
 13186   match(Set result (PartialSubtypeCheck sub super));
 13187   effect( KILL rcx, KILL cr );
 13189   ins_cost(1100);  // slightly larger than the next version
 13190   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
 13191             "MOV    ECX,[EDI+arrayKlass::length]\t# length to scan\n\t"
 13192             "ADD    EDI,arrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
 13193             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
 13194             "JNE,s  miss\t\t# Missed: EDI not-zero\n\t"
 13195             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache\n\t"
 13196             "XOR    $result,$result\t\t Hit: EDI zero\n\t"
 13197      "miss:\t" %}
 13199   opcode(0x1); // Force a XOR of EDI
 13200   ins_encode( enc_PartialSubtypeCheck() );
 13201   ins_pipe( pipe_slow );
 13202 %}
 13204 instruct partialSubtypeCheck_vs_Zero( eFlagsReg cr, eSIRegP sub, eAXRegP super, eCXRegI rcx, eDIRegP result, immP0 zero ) %{
 13205   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
 13206   effect( KILL rcx, KILL result );
 13208   ins_cost(1000);
 13209   format %{ "MOV    EDI,[$sub+Klass::secondary_supers]\n\t"
 13210             "MOV    ECX,[EDI+arrayKlass::length]\t# length to scan\n\t"
 13211             "ADD    EDI,arrayKlass::base_offset\t# Skip to start of data; set NZ in case count is zero\n\t"
 13212             "REPNE SCASD\t# Scan *EDI++ for a match with EAX while CX-- != 0\n\t"
 13213             "JNE,s  miss\t\t# Missed: flags NZ\n\t"
 13214             "MOV    [$sub+Klass::secondary_super_cache],$super\t# Hit: update cache, flags Z\n\t"
 13215      "miss:\t" %}
 13217   opcode(0x0);  // No need to XOR EDI
 13218   ins_encode( enc_PartialSubtypeCheck() );
 13219   ins_pipe( pipe_slow );
 13220 %}
 13222 // ============================================================================
 13223 // Branch Instructions -- short offset versions
 13224 //
 13225 // These instructions are used to replace jumps of a long offset (the default
 13226 // match) with jumps of a shorter offset.  These instructions are all tagged
 13227 // with the ins_short_branch attribute, which causes the ADLC to suppress the
 13228 // match rules in general matching.  Instead, the ADLC generates a conversion
 13229 // method in the MachNode which can be used to do in-place replacement of the
 13230 // long variant with the shorter variant.  The compiler will determine if a
 13231 // branch can be taken by the is_short_branch_offset() predicate in the machine
 13232 // specific code section of the file.
 13234 // Jump Direct - Label defines a relative address from JMP+1
 13235 instruct jmpDir_short(label labl) %{
 13236   match(Goto);
 13237   effect(USE labl);
 13239   ins_cost(300);
 13240   format %{ "JMP,s  $labl" %}
 13241   size(2);
 13242   opcode(0xEB);
 13243   ins_encode( OpcP, LblShort( labl ) );
 13244   ins_pipe( pipe_jmp );
 13245   ins_short_branch(1);
 13246 %}
 13248 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13249 instruct jmpCon_short(cmpOp cop, eFlagsReg cr, label labl) %{
 13250   match(If cop cr);
 13251   effect(USE labl);
 13253   ins_cost(300);
 13254   format %{ "J$cop,s  $labl" %}
 13255   size(2);
 13256   opcode(0x70);
 13257   ins_encode( JccShort( cop, labl) );
 13258   ins_pipe( pipe_jcc );
 13259   ins_short_branch(1);
 13260 %}
 13262 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13263 instruct jmpLoopEnd_short(cmpOp cop, eFlagsReg cr, label labl) %{
 13264   match(CountedLoopEnd cop cr);
 13265   effect(USE labl);
 13267   ins_cost(300);
 13268   format %{ "J$cop,s  $labl\t# Loop end" %}
 13269   size(2);
 13270   opcode(0x70);
 13271   ins_encode( JccShort( cop, labl) );
 13272   ins_pipe( pipe_jcc );
 13273   ins_short_branch(1);
 13274 %}
 13276 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 13277 instruct jmpLoopEndU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 13278   match(CountedLoopEnd cop cmp);
 13279   effect(USE labl);
 13281   ins_cost(300);
 13282   format %{ "J$cop,us $labl\t# Loop end" %}
 13283   size(2);
 13284   opcode(0x70);
 13285   ins_encode( JccShort( cop, labl) );
 13286   ins_pipe( pipe_jcc );
 13287   ins_short_branch(1);
 13288 %}
 13290 instruct jmpLoopEndUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 13291   match(CountedLoopEnd cop cmp);
 13292   effect(USE labl);
 13294   ins_cost(300);
 13295   format %{ "J$cop,us $labl\t# Loop end" %}
 13296   size(2);
 13297   opcode(0x70);
 13298   ins_encode( JccShort( cop, labl) );
 13299   ins_pipe( pipe_jcc );
 13300   ins_short_branch(1);
 13301 %}
 13303 // Jump Direct Conditional - using unsigned comparison
 13304 instruct jmpConU_short(cmpOpU cop, eFlagsRegU cmp, label labl) %{
 13305   match(If cop cmp);
 13306   effect(USE labl);
 13308   ins_cost(300);
 13309   format %{ "J$cop,us $labl" %}
 13310   size(2);
 13311   opcode(0x70);
 13312   ins_encode( JccShort( cop, labl) );
 13313   ins_pipe( pipe_jcc );
 13314   ins_short_branch(1);
 13315 %}
 13317 instruct jmpConUCF_short(cmpOpUCF cop, eFlagsRegUCF cmp, label labl) %{
 13318   match(If cop cmp);
 13319   effect(USE labl);
 13321   ins_cost(300);
 13322   format %{ "J$cop,us $labl" %}
 13323   size(2);
 13324   opcode(0x70);
 13325   ins_encode( JccShort( cop, labl) );
 13326   ins_pipe( pipe_jcc );
 13327   ins_short_branch(1);
 13328 %}
 13330 instruct jmpConUCF2_short(cmpOpUCF2 cop, eFlagsRegUCF cmp, label labl) %{
 13331   match(If cop cmp);
 13332   effect(USE labl);
 13334   ins_cost(300);
 13335   format %{ $$template
 13336     if ($cop$$cmpcode == Assembler::notEqual) {
 13337       $$emit$$"JP,u,s   $labl\n\t"
 13338       $$emit$$"J$cop,u,s   $labl"
 13339     } else {
 13340       $$emit$$"JP,u,s   done\n\t"
 13341       $$emit$$"J$cop,u,s  $labl\n\t"
 13342       $$emit$$"done:"
 13344   %}
 13345   size(4);
 13346   opcode(0x70);
 13347   ins_encode %{
 13348     Label* l = $labl$$label;
 13349     emit_cc(cbuf, $primary, Assembler::parity);
 13350     int parity_disp = -1;
 13351     if ($cop$$cmpcode == Assembler::notEqual) {
 13352       parity_disp = l->loc_pos() - (cbuf.insts_size() + 1);
 13353     } else if ($cop$$cmpcode == Assembler::equal) {
 13354       parity_disp = 2;
 13355     } else {
 13356       ShouldNotReachHere();
 13358     emit_d8(cbuf, parity_disp);
 13359     emit_cc(cbuf, $primary, $cop$$cmpcode);
 13360     int disp = l->loc_pos() - (cbuf.insts_size() + 1);
 13361     emit_d8(cbuf, disp);
 13362     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
 13363     assert(-128 <= parity_disp && parity_disp <= 127, "Displacement too large for short jmp");
 13364   %}
 13365   ins_pipe(pipe_jcc);
 13366   ins_short_branch(1);
 13367 %}
 13369 // ============================================================================
 13370 // Long Compare
 13371 //
 13372 // Currently we hold longs in 2 registers.  Comparing such values efficiently
 13373 // is tricky.  The flavor of compare used depends on whether we are testing
 13374 // for LT, LE, or EQ.  For a simple LT test we can check just the sign bit.
 13375 // The GE test is the negated LT test.  The LE test can be had by commuting
 13376 // the operands (yielding a GE test) and then negating; negate again for the
 13377 // GT test.  The EQ test is done by ORcc'ing the high and low halves, and the
 13378 // NE test is negated from that.
 13380 // Due to a shortcoming in the ADLC, it mixes up expressions like:
 13381 // (foo (CmpI (CmpL X Y) 0)) and (bar (CmpI (CmpL X 0L) 0)).  Note the
 13382 // difference between 'Y' and '0L'.  The tree-matches for the CmpI sections
 13383 // are collapsed internally in the ADLC's dfa-gen code.  The match for
 13384 // (CmpI (CmpL X Y) 0) is silently replaced with (CmpI (CmpL X 0L) 0) and the
 13385 // foo match ends up with the wrong leaf.  One fix is to not match both
 13386 // reg-reg and reg-zero forms of long-compare.  This is unfortunate because
 13387 // both forms beat the trinary form of long-compare and both are very useful
 13388 // on Intel which has so few registers.
 13390 // Manifest a CmpL result in an integer register.  Very painful.
 13391 // This is the test to avoid.
 13392 instruct cmpL3_reg_reg(eSIRegI dst, eRegL src1, eRegL src2, eFlagsReg flags ) %{
 13393   match(Set dst (CmpL3 src1 src2));
 13394   effect( KILL flags );
 13395   ins_cost(1000);
 13396   format %{ "XOR    $dst,$dst\n\t"
 13397             "CMP    $src1.hi,$src2.hi\n\t"
 13398             "JLT,s  m_one\n\t"
 13399             "JGT,s  p_one\n\t"
 13400             "CMP    $src1.lo,$src2.lo\n\t"
 13401             "JB,s   m_one\n\t"
 13402             "JEQ,s  done\n"
 13403     "p_one:\tINC    $dst\n\t"
 13404             "JMP,s  done\n"
 13405     "m_one:\tDEC    $dst\n"
 13406      "done:" %}
 13407   ins_encode %{
 13408     Label p_one, m_one, done;
 13409     __ xorptr($dst$$Register, $dst$$Register);
 13410     __ cmpl(HIGH_FROM_LOW($src1$$Register), HIGH_FROM_LOW($src2$$Register));
 13411     __ jccb(Assembler::less,    m_one);
 13412     __ jccb(Assembler::greater, p_one);
 13413     __ cmpl($src1$$Register, $src2$$Register);
 13414     __ jccb(Assembler::below,   m_one);
 13415     __ jccb(Assembler::equal,   done);
 13416     __ bind(p_one);
 13417     __ incrementl($dst$$Register);
 13418     __ jmpb(done);
 13419     __ bind(m_one);
 13420     __ decrementl($dst$$Register);
 13421     __ bind(done);
 13422   %}
 13423   ins_pipe( pipe_slow );
 13424 %}
 13426 //======
 13427 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
 13428 // compares.  Can be used for LE or GT compares by reversing arguments.
 13429 // NOT GOOD FOR EQ/NE tests.
 13430 instruct cmpL_zero_flags_LTGE( flagsReg_long_LTGE flags, eRegL src, immL0 zero ) %{
 13431   match( Set flags (CmpL src zero ));
 13432   ins_cost(100);
 13433   format %{ "TEST   $src.hi,$src.hi" %}
 13434   opcode(0x85);
 13435   ins_encode( OpcP, RegReg_Hi2( src, src ) );
 13436   ins_pipe( ialu_cr_reg_reg );
 13437 %}
 13439 // Manifest a CmpL result in the normal flags.  Only good for LT or GE
 13440 // compares.  Can be used for LE or GT compares by reversing arguments.
 13441 // NOT GOOD FOR EQ/NE tests.
 13442 instruct cmpL_reg_flags_LTGE( flagsReg_long_LTGE flags, eRegL src1, eRegL src2, eRegI tmp ) %{
 13443   match( Set flags (CmpL src1 src2 ));
 13444   effect( TEMP tmp );
 13445   ins_cost(300);
 13446   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
 13447             "MOV    $tmp,$src1.hi\n\t"
 13448             "SBB    $tmp,$src2.hi\t! Compute flags for long compare" %}
 13449   ins_encode( long_cmp_flags2( src1, src2, tmp ) );
 13450   ins_pipe( ialu_cr_reg_reg );
 13451 %}
 13453 // Long compares reg < zero/req OR reg >= zero/req.
 13454 // Just a wrapper for a normal branch, plus the predicate test.
 13455 instruct cmpL_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, label labl) %{
 13456   match(If cmp flags);
 13457   effect(USE labl);
 13458   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::lt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ge );
 13459   expand %{
 13460     jmpCon(cmp,flags,labl);    // JLT or JGE...
 13461   %}
 13462 %}
 13464 // Compare 2 longs and CMOVE longs.
 13465 instruct cmovLL_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, eRegL src) %{
 13466   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 13467   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 ));
 13468   ins_cost(400);
 13469   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13470             "CMOV$cmp $dst.hi,$src.hi" %}
 13471   opcode(0x0F,0x40);
 13472   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 13473   ins_pipe( pipe_cmov_reg_long );
 13474 %}
 13476 instruct cmovLL_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegL dst, load_long_memory src) %{
 13477   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 13478   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 ));
 13479   ins_cost(500);
 13480   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13481             "CMOV$cmp $dst.hi,$src.hi" %}
 13482   opcode(0x0F,0x40);
 13483   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 13484   ins_pipe( pipe_cmov_reg_long );
 13485 %}
 13487 // Compare 2 longs and CMOVE ints.
 13488 instruct cmovII_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegI dst, eRegI src) %{
 13489   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 ));
 13490   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 13491   ins_cost(200);
 13492   format %{ "CMOV$cmp $dst,$src" %}
 13493   opcode(0x0F,0x40);
 13494   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13495   ins_pipe( pipe_cmov_reg );
 13496 %}
 13498 instruct cmovII_mem_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegI dst, memory src) %{
 13499   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 ));
 13500   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 13501   ins_cost(250);
 13502   format %{ "CMOV$cmp $dst,$src" %}
 13503   opcode(0x0F,0x40);
 13504   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 13505   ins_pipe( pipe_cmov_mem );
 13506 %}
 13508 // Compare 2 longs and CMOVE ints.
 13509 instruct cmovPP_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, eRegP dst, eRegP src) %{
 13510   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 ));
 13511   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 13512   ins_cost(200);
 13513   format %{ "CMOV$cmp $dst,$src" %}
 13514   opcode(0x0F,0x40);
 13515   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13516   ins_pipe( pipe_cmov_reg );
 13517 %}
 13519 // Compare 2 longs and CMOVE doubles
 13520 instruct cmovDD_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regD dst, regD src) %{
 13521   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 );
 13522   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13523   ins_cost(200);
 13524   expand %{
 13525     fcmovD_regS(cmp,flags,dst,src);
 13526   %}
 13527 %}
 13529 // Compare 2 longs and CMOVE doubles
 13530 instruct cmovXDD_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regXD dst, regXD src) %{
 13531   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 );
 13532   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13533   ins_cost(200);
 13534   expand %{
 13535     fcmovXD_regS(cmp,flags,dst,src);
 13536   %}
 13537 %}
 13539 instruct cmovFF_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regF dst, regF src) %{
 13540   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 );
 13541   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13542   ins_cost(200);
 13543   expand %{
 13544     fcmovF_regS(cmp,flags,dst,src);
 13545   %}
 13546 %}
 13548 instruct cmovXX_reg_LTGE(cmpOp cmp, flagsReg_long_LTGE flags, regX dst, regX src) %{
 13549   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 );
 13550   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13551   ins_cost(200);
 13552   expand %{
 13553     fcmovX_regS(cmp,flags,dst,src);
 13554   %}
 13555 %}
 13557 //======
 13558 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
 13559 instruct cmpL_zero_flags_EQNE( flagsReg_long_EQNE flags, eRegL src, immL0 zero, eRegI tmp ) %{
 13560   match( Set flags (CmpL src zero ));
 13561   effect(TEMP tmp);
 13562   ins_cost(200);
 13563   format %{ "MOV    $tmp,$src.lo\n\t"
 13564             "OR     $tmp,$src.hi\t! Long is EQ/NE 0?" %}
 13565   ins_encode( long_cmp_flags0( src, tmp ) );
 13566   ins_pipe( ialu_reg_reg_long );
 13567 %}
 13569 // Manifest a CmpL result in the normal flags.  Only good for EQ/NE compares.
 13570 instruct cmpL_reg_flags_EQNE( flagsReg_long_EQNE flags, eRegL src1, eRegL src2 ) %{
 13571   match( Set flags (CmpL src1 src2 ));
 13572   ins_cost(200+300);
 13573   format %{ "CMP    $src1.lo,$src2.lo\t! Long compare; set flags for low bits\n\t"
 13574             "JNE,s  skip\n\t"
 13575             "CMP    $src1.hi,$src2.hi\n\t"
 13576      "skip:\t" %}
 13577   ins_encode( long_cmp_flags1( src1, src2 ) );
 13578   ins_pipe( ialu_cr_reg_reg );
 13579 %}
 13581 // Long compare reg == zero/reg OR reg != zero/reg
 13582 // Just a wrapper for a normal branch, plus the predicate test.
 13583 instruct cmpL_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, label labl) %{
 13584   match(If cmp flags);
 13585   effect(USE labl);
 13586   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::eq || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::ne );
 13587   expand %{
 13588     jmpCon(cmp,flags,labl);    // JEQ or JNE...
 13589   %}
 13590 %}
 13592 // Compare 2 longs and CMOVE longs.
 13593 instruct cmovLL_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, eRegL src) %{
 13594   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 13595   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 ));
 13596   ins_cost(400);
 13597   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13598             "CMOV$cmp $dst.hi,$src.hi" %}
 13599   opcode(0x0F,0x40);
 13600   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 13601   ins_pipe( pipe_cmov_reg_long );
 13602 %}
 13604 instruct cmovLL_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegL dst, load_long_memory src) %{
 13605   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 13606   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 ));
 13607   ins_cost(500);
 13608   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13609             "CMOV$cmp $dst.hi,$src.hi" %}
 13610   opcode(0x0F,0x40);
 13611   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 13612   ins_pipe( pipe_cmov_reg_long );
 13613 %}
 13615 // Compare 2 longs and CMOVE ints.
 13616 instruct cmovII_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegI dst, eRegI src) %{
 13617   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 ));
 13618   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 13619   ins_cost(200);
 13620   format %{ "CMOV$cmp $dst,$src" %}
 13621   opcode(0x0F,0x40);
 13622   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13623   ins_pipe( pipe_cmov_reg );
 13624 %}
 13626 instruct cmovII_mem_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegI dst, memory src) %{
 13627   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 ));
 13628   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 13629   ins_cost(250);
 13630   format %{ "CMOV$cmp $dst,$src" %}
 13631   opcode(0x0F,0x40);
 13632   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 13633   ins_pipe( pipe_cmov_mem );
 13634 %}
 13636 // Compare 2 longs and CMOVE ints.
 13637 instruct cmovPP_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, eRegP dst, eRegP src) %{
 13638   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 ));
 13639   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 13640   ins_cost(200);
 13641   format %{ "CMOV$cmp $dst,$src" %}
 13642   opcode(0x0F,0x40);
 13643   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13644   ins_pipe( pipe_cmov_reg );
 13645 %}
 13647 // Compare 2 longs and CMOVE doubles
 13648 instruct cmovDD_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regD dst, regD src) %{
 13649   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 );
 13650   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13651   ins_cost(200);
 13652   expand %{
 13653     fcmovD_regS(cmp,flags,dst,src);
 13654   %}
 13655 %}
 13657 // Compare 2 longs and CMOVE doubles
 13658 instruct cmovXDD_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regXD dst, regXD src) %{
 13659   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 );
 13660   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13661   ins_cost(200);
 13662   expand %{
 13663     fcmovXD_regS(cmp,flags,dst,src);
 13664   %}
 13665 %}
 13667 instruct cmovFF_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regF dst, regF src) %{
 13668   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 );
 13669   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13670   ins_cost(200);
 13671   expand %{
 13672     fcmovF_regS(cmp,flags,dst,src);
 13673   %}
 13674 %}
 13676 instruct cmovXX_reg_EQNE(cmpOp cmp, flagsReg_long_EQNE flags, regX dst, regX src) %{
 13677   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 );
 13678   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13679   ins_cost(200);
 13680   expand %{
 13681     fcmovX_regS(cmp,flags,dst,src);
 13682   %}
 13683 %}
 13685 //======
 13686 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
 13687 // Same as cmpL_reg_flags_LEGT except must negate src
 13688 instruct cmpL_zero_flags_LEGT( flagsReg_long_LEGT flags, eRegL src, immL0 zero, eRegI tmp ) %{
 13689   match( Set flags (CmpL src zero ));
 13690   effect( TEMP tmp );
 13691   ins_cost(300);
 13692   format %{ "XOR    $tmp,$tmp\t# Long compare for -$src < 0, use commuted test\n\t"
 13693             "CMP    $tmp,$src.lo\n\t"
 13694             "SBB    $tmp,$src.hi\n\t" %}
 13695   ins_encode( long_cmp_flags3(src, tmp) );
 13696   ins_pipe( ialu_reg_reg_long );
 13697 %}
 13699 // Manifest a CmpL result in the normal flags.  Only good for LE or GT compares.
 13700 // Same as cmpL_reg_flags_LTGE except operands swapped.  Swapping operands
 13701 // requires a commuted test to get the same result.
 13702 instruct cmpL_reg_flags_LEGT( flagsReg_long_LEGT flags, eRegL src1, eRegL src2, eRegI tmp ) %{
 13703   match( Set flags (CmpL src1 src2 ));
 13704   effect( TEMP tmp );
 13705   ins_cost(300);
 13706   format %{ "CMP    $src2.lo,$src1.lo\t! Long compare, swapped operands, use with commuted test\n\t"
 13707             "MOV    $tmp,$src2.hi\n\t"
 13708             "SBB    $tmp,$src1.hi\t! Compute flags for long compare" %}
 13709   ins_encode( long_cmp_flags2( src2, src1, tmp ) );
 13710   ins_pipe( ialu_cr_reg_reg );
 13711 %}
 13713 // Long compares reg < zero/req OR reg >= zero/req.
 13714 // Just a wrapper for a normal branch, plus the predicate test
 13715 instruct cmpL_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, label labl) %{
 13716   match(If cmp flags);
 13717   effect(USE labl);
 13718   predicate( _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::gt || _kids[0]->_leaf->as_Bool()->_test._test == BoolTest::le );
 13719   ins_cost(300);
 13720   expand %{
 13721     jmpCon(cmp,flags,labl);    // JGT or JLE...
 13722   %}
 13723 %}
 13725 // Compare 2 longs and CMOVE longs.
 13726 instruct cmovLL_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, eRegL src) %{
 13727   match(Set dst (CMoveL (Binary cmp flags) (Binary dst src)));
 13728   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 ));
 13729   ins_cost(400);
 13730   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13731             "CMOV$cmp $dst.hi,$src.hi" %}
 13732   opcode(0x0F,0x40);
 13733   ins_encode( enc_cmov(cmp), RegReg_Lo2( dst, src ), enc_cmov(cmp), RegReg_Hi2( dst, src ) );
 13734   ins_pipe( pipe_cmov_reg_long );
 13735 %}
 13737 instruct cmovLL_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegL dst, load_long_memory src) %{
 13738   match(Set dst (CMoveL (Binary cmp flags) (Binary dst (LoadL src))));
 13739   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 ));
 13740   ins_cost(500);
 13741   format %{ "CMOV$cmp $dst.lo,$src.lo\n\t"
 13742             "CMOV$cmp $dst.hi,$src.hi+4" %}
 13743   opcode(0x0F,0x40);
 13744   ins_encode( enc_cmov(cmp), RegMem(dst, src), enc_cmov(cmp), RegMem_Hi(dst, src) );
 13745   ins_pipe( pipe_cmov_reg_long );
 13746 %}
 13748 // Compare 2 longs and CMOVE ints.
 13749 instruct cmovII_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegI dst, eRegI src) %{
 13750   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 ));
 13751   match(Set dst (CMoveI (Binary cmp flags) (Binary dst src)));
 13752   ins_cost(200);
 13753   format %{ "CMOV$cmp $dst,$src" %}
 13754   opcode(0x0F,0x40);
 13755   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13756   ins_pipe( pipe_cmov_reg );
 13757 %}
 13759 instruct cmovII_mem_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegI dst, memory src) %{
 13760   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 ));
 13761   match(Set dst (CMoveI (Binary cmp flags) (Binary dst (LoadI src))));
 13762   ins_cost(250);
 13763   format %{ "CMOV$cmp $dst,$src" %}
 13764   opcode(0x0F,0x40);
 13765   ins_encode( enc_cmov(cmp), RegMem( dst, src ) );
 13766   ins_pipe( pipe_cmov_mem );
 13767 %}
 13769 // Compare 2 longs and CMOVE ptrs.
 13770 instruct cmovPP_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, eRegP dst, eRegP src) %{
 13771   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 ));
 13772   match(Set dst (CMoveP (Binary cmp flags) (Binary dst src)));
 13773   ins_cost(200);
 13774   format %{ "CMOV$cmp $dst,$src" %}
 13775   opcode(0x0F,0x40);
 13776   ins_encode( enc_cmov(cmp), RegReg( dst, src ) );
 13777   ins_pipe( pipe_cmov_reg );
 13778 %}
 13780 // Compare 2 longs and CMOVE doubles
 13781 instruct cmovDD_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regD dst, regD src) %{
 13782   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 );
 13783   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13784   ins_cost(200);
 13785   expand %{
 13786     fcmovD_regS(cmp,flags,dst,src);
 13787   %}
 13788 %}
 13790 // Compare 2 longs and CMOVE doubles
 13791 instruct cmovXDD_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regXD dst, regXD src) %{
 13792   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 );
 13793   match(Set dst (CMoveD (Binary cmp flags) (Binary dst src)));
 13794   ins_cost(200);
 13795   expand %{
 13796     fcmovXD_regS(cmp,flags,dst,src);
 13797   %}
 13798 %}
 13800 instruct cmovFF_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regF dst, regF src) %{
 13801   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 );
 13802   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13803   ins_cost(200);
 13804   expand %{
 13805     fcmovF_regS(cmp,flags,dst,src);
 13806   %}
 13807 %}
 13810 instruct cmovXX_reg_LEGT(cmpOp_commute cmp, flagsReg_long_LEGT flags, regX dst, regX src) %{
 13811   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 );
 13812   match(Set dst (CMoveF (Binary cmp flags) (Binary dst src)));
 13813   ins_cost(200);
 13814   expand %{
 13815     fcmovX_regS(cmp,flags,dst,src);
 13816   %}
 13817 %}
 13820 // ============================================================================
 13821 // Procedure Call/Return Instructions
 13822 // Call Java Static Instruction
 13823 // Note: If this code changes, the corresponding ret_addr_offset() and
 13824 //       compute_padding() functions will have to be adjusted.
 13825 instruct CallStaticJavaDirect(method meth) %{
 13826   match(CallStaticJava);
 13827   predicate(! ((CallStaticJavaNode*)n)->is_method_handle_invoke());
 13828   effect(USE meth);
 13830   ins_cost(300);
 13831   format %{ "CALL,static " %}
 13832   opcode(0xE8); /* E8 cd */
 13833   ins_encode( pre_call_FPU,
 13834               Java_Static_Call( meth ),
 13835               call_epilog,
 13836               post_call_FPU );
 13837   ins_pipe( pipe_slow );
 13838   ins_alignment(4);
 13839 %}
 13841 // Call Java Static Instruction (method handle version)
 13842 // Note: If this code changes, the corresponding ret_addr_offset() and
 13843 //       compute_padding() functions will have to be adjusted.
 13844 instruct CallStaticJavaHandle(method meth, eBPRegP ebp_mh_SP_save) %{
 13845   match(CallStaticJava);
 13846   predicate(((CallStaticJavaNode*)n)->is_method_handle_invoke());
 13847   effect(USE meth);
 13848   // EBP is saved by all callees (for interpreter stack correction).
 13849   // We use it here for a similar purpose, in {preserve,restore}_SP.
 13851   ins_cost(300);
 13852   format %{ "CALL,static/MethodHandle " %}
 13853   opcode(0xE8); /* E8 cd */
 13854   ins_encode( pre_call_FPU,
 13855               preserve_SP,
 13856               Java_Static_Call( meth ),
 13857               restore_SP,
 13858               call_epilog,
 13859               post_call_FPU );
 13860   ins_pipe( pipe_slow );
 13861   ins_alignment(4);
 13862 %}
 13864 // Call Java Dynamic Instruction
 13865 // Note: If this code changes, the corresponding ret_addr_offset() and
 13866 //       compute_padding() functions will have to be adjusted.
 13867 instruct CallDynamicJavaDirect(method meth) %{
 13868   match(CallDynamicJava);
 13869   effect(USE meth);
 13871   ins_cost(300);
 13872   format %{ "MOV    EAX,(oop)-1\n\t"
 13873             "CALL,dynamic" %}
 13874   opcode(0xE8); /* E8 cd */
 13875   ins_encode( pre_call_FPU,
 13876               Java_Dynamic_Call( meth ),
 13877               call_epilog,
 13878               post_call_FPU );
 13879   ins_pipe( pipe_slow );
 13880   ins_alignment(4);
 13881 %}
 13883 // Call Runtime Instruction
 13884 instruct CallRuntimeDirect(method meth) %{
 13885   match(CallRuntime );
 13886   effect(USE meth);
 13888   ins_cost(300);
 13889   format %{ "CALL,runtime " %}
 13890   opcode(0xE8); /* E8 cd */
 13891   // Use FFREEs to clear entries in float stack
 13892   ins_encode( pre_call_FPU,
 13893               FFree_Float_Stack_All,
 13894               Java_To_Runtime( meth ),
 13895               post_call_FPU );
 13896   ins_pipe( pipe_slow );
 13897 %}
 13899 // Call runtime without safepoint
 13900 instruct CallLeafDirect(method meth) %{
 13901   match(CallLeaf);
 13902   effect(USE meth);
 13904   ins_cost(300);
 13905   format %{ "CALL_LEAF,runtime " %}
 13906   opcode(0xE8); /* E8 cd */
 13907   ins_encode( pre_call_FPU,
 13908               FFree_Float_Stack_All,
 13909               Java_To_Runtime( meth ),
 13910               Verify_FPU_For_Leaf, post_call_FPU );
 13911   ins_pipe( pipe_slow );
 13912 %}
 13914 instruct CallLeafNoFPDirect(method meth) %{
 13915   match(CallLeafNoFP);
 13916   effect(USE meth);
 13918   ins_cost(300);
 13919   format %{ "CALL_LEAF_NOFP,runtime " %}
 13920   opcode(0xE8); /* E8 cd */
 13921   ins_encode(Java_To_Runtime(meth));
 13922   ins_pipe( pipe_slow );
 13923 %}
 13926 // Return Instruction
 13927 // Remove the return address & jump to it.
 13928 instruct Ret() %{
 13929   match(Return);
 13930   format %{ "RET" %}
 13931   opcode(0xC3);
 13932   ins_encode(OpcP);
 13933   ins_pipe( pipe_jmp );
 13934 %}
 13936 // Tail Call; Jump from runtime stub to Java code.
 13937 // Also known as an 'interprocedural jump'.
 13938 // Target of jump will eventually return to caller.
 13939 // TailJump below removes the return address.
 13940 instruct TailCalljmpInd(eRegP_no_EBP jump_target, eBXRegP method_oop) %{
 13941   match(TailCall jump_target method_oop );
 13942   ins_cost(300);
 13943   format %{ "JMP    $jump_target \t# EBX holds method oop" %}
 13944   opcode(0xFF, 0x4);  /* Opcode FF /4 */
 13945   ins_encode( OpcP, RegOpc(jump_target) );
 13946   ins_pipe( pipe_jmp );
 13947 %}
 13950 // Tail Jump; remove the return address; jump to target.
 13951 // TailCall above leaves the return address around.
 13952 instruct tailjmpInd(eRegP_no_EBP jump_target, eAXRegP ex_oop) %{
 13953   match( TailJump jump_target ex_oop );
 13954   ins_cost(300);
 13955   format %{ "POP    EDX\t# pop return address into dummy\n\t"
 13956             "JMP    $jump_target " %}
 13957   opcode(0xFF, 0x4);  /* Opcode FF /4 */
 13958   ins_encode( enc_pop_rdx,
 13959               OpcP, RegOpc(jump_target) );
 13960   ins_pipe( pipe_jmp );
 13961 %}
 13963 // Create exception oop: created by stack-crawling runtime code.
 13964 // Created exception is now available to this handler, and is setup
 13965 // just prior to jumping to this handler.  No code emitted.
 13966 instruct CreateException( eAXRegP ex_oop )
 13967 %{
 13968   match(Set ex_oop (CreateEx));
 13970   size(0);
 13971   // use the following format syntax
 13972   format %{ "# exception oop is in EAX; no code emitted" %}
 13973   ins_encode();
 13974   ins_pipe( empty );
 13975 %}
 13978 // Rethrow exception:
 13979 // The exception oop will come in the first argument position.
 13980 // Then JUMP (not call) to the rethrow stub code.
 13981 instruct RethrowException()
 13982 %{
 13983   match(Rethrow);
 13985   // use the following format syntax
 13986   format %{ "JMP    rethrow_stub" %}
 13987   ins_encode(enc_rethrow);
 13988   ins_pipe( pipe_jmp );
 13989 %}
 13991 // inlined locking and unlocking
 13994 instruct cmpFastLock( eFlagsReg cr, eRegP object, eRegP box, eAXRegI tmp, eRegP scr) %{
 13995   match( Set cr (FastLock object box) );
 13996   effect( TEMP tmp, TEMP scr );
 13997   ins_cost(300);
 13998   format %{ "FASTLOCK $object, $box KILLS $tmp,$scr" %}
 13999   ins_encode( Fast_Lock(object,box,tmp,scr) );
 14000   ins_pipe( pipe_slow );
 14001 %}
 14003 instruct cmpFastUnlock( eFlagsReg cr, eRegP object, eAXRegP box, eRegP tmp ) %{
 14004   match( Set cr (FastUnlock object box) );
 14005   effect( TEMP tmp );
 14006   ins_cost(300);
 14007   format %{ "FASTUNLOCK $object, $box, $tmp" %}
 14008   ins_encode( Fast_Unlock(object,box,tmp) );
 14009   ins_pipe( pipe_slow );
 14010 %}
 14014 // ============================================================================
 14015 // Safepoint Instruction
 14016 instruct safePoint_poll(eFlagsReg cr) %{
 14017   match(SafePoint);
 14018   effect(KILL cr);
 14020   // TODO-FIXME: we currently poll at offset 0 of the safepoint polling page.
 14021   // On SPARC that might be acceptable as we can generate the address with
 14022   // just a sethi, saving an or.  By polling at offset 0 we can end up
 14023   // putting additional pressure on the index-0 in the D$.  Because of
 14024   // alignment (just like the situation at hand) the lower indices tend
 14025   // to see more traffic.  It'd be better to change the polling address
 14026   // to offset 0 of the last $line in the polling page.
 14028   format %{ "TSTL   #polladdr,EAX\t! Safepoint: poll for GC" %}
 14029   ins_cost(125);
 14030   size(6) ;
 14031   ins_encode( Safepoint_Poll() );
 14032   ins_pipe( ialu_reg_mem );
 14033 %}
 14035 //----------PEEPHOLE RULES-----------------------------------------------------
 14036 // These must follow all instruction definitions as they use the names
 14037 // defined in the instructions definitions.
 14038 //
 14039 // peepmatch ( root_instr_name [preceding_instruction]* );
 14040 //
 14041 // peepconstraint %{
 14042 // (instruction_number.operand_name relational_op instruction_number.operand_name
 14043 //  [, ...] );
 14044 // // instruction numbers are zero-based using left to right order in peepmatch
 14045 //
 14046 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
 14047 // // provide an instruction_number.operand_name for each operand that appears
 14048 // // in the replacement instruction's match rule
 14049 //
 14050 // ---------VM FLAGS---------------------------------------------------------
 14051 //
 14052 // All peephole optimizations can be turned off using -XX:-OptoPeephole
 14053 //
 14054 // Each peephole rule is given an identifying number starting with zero and
 14055 // increasing by one in the order seen by the parser.  An individual peephole
 14056 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
 14057 // on the command-line.
 14058 //
 14059 // ---------CURRENT LIMITATIONS----------------------------------------------
 14060 //
 14061 // Only match adjacent instructions in same basic block
 14062 // Only equality constraints
 14063 // Only constraints between operands, not (0.dest_reg == EAX_enc)
 14064 // Only one replacement instruction
 14065 //
 14066 // ---------EXAMPLE----------------------------------------------------------
 14067 //
 14068 // // pertinent parts of existing instructions in architecture description
 14069 // instruct movI(eRegI dst, eRegI src) %{
 14070 //   match(Set dst (CopyI src));
 14071 // %}
 14072 //
 14073 // instruct incI_eReg(eRegI dst, immI1 src, eFlagsReg cr) %{
 14074 //   match(Set dst (AddI dst src));
 14075 //   effect(KILL cr);
 14076 // %}
 14077 //
 14078 // // Change (inc mov) to lea
 14079 // peephole %{
 14080 //   // increment preceeded by register-register move
 14081 //   peepmatch ( incI_eReg movI );
 14082 //   // require that the destination register of the increment
 14083 //   // match the destination register of the move
 14084 //   peepconstraint ( 0.dst == 1.dst );
 14085 //   // construct a replacement instruction that sets
 14086 //   // the destination to ( move's source register + one )
 14087 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 14088 // %}
 14089 //
 14090 // Implementation no longer uses movX instructions since
 14091 // machine-independent system no longer uses CopyX nodes.
 14092 //
 14093 // peephole %{
 14094 //   peepmatch ( incI_eReg movI );
 14095 //   peepconstraint ( 0.dst == 1.dst );
 14096 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 14097 // %}
 14098 //
 14099 // peephole %{
 14100 //   peepmatch ( decI_eReg movI );
 14101 //   peepconstraint ( 0.dst == 1.dst );
 14102 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 14103 // %}
 14104 //
 14105 // peephole %{
 14106 //   peepmatch ( addI_eReg_imm movI );
 14107 //   peepconstraint ( 0.dst == 1.dst );
 14108 //   peepreplace ( leaI_eReg_immI( 0.dst 1.src 0.src ) );
 14109 // %}
 14110 //
 14111 // peephole %{
 14112 //   peepmatch ( addP_eReg_imm movP );
 14113 //   peepconstraint ( 0.dst == 1.dst );
 14114 //   peepreplace ( leaP_eReg_immI( 0.dst 1.src 0.src ) );
 14115 // %}
 14117 // // Change load of spilled value to only a spill
 14118 // instruct storeI(memory mem, eRegI src) %{
 14119 //   match(Set mem (StoreI mem src));
 14120 // %}
 14121 //
 14122 // instruct loadI(eRegI dst, memory mem) %{
 14123 //   match(Set dst (LoadI mem));
 14124 // %}
 14125 //
 14126 peephole %{
 14127   peepmatch ( loadI storeI );
 14128   peepconstraint ( 1.src == 0.dst, 1.mem == 0.mem );
 14129   peepreplace ( storeI( 1.mem 1.mem 1.src ) );
 14130 %}
 14132 //----------SMARTSPILL RULES---------------------------------------------------
 14133 // These must follow all instruction definitions as they use the names
 14134 // defined in the instructions definitions.

mercurial