src/cpu/x86/vm/x86_64.ad

Thu, 29 May 2008 16:22:09 -0700

author
rasbold
date
Thu, 29 May 2008 16:22:09 -0700
changeset 604
9148c65abefc
parent 603
7793bd37a336
child 617
44abbb0d4c18
permissions
-rw-r--r--

6695049: (coll) Create an x86 intrinsic for Arrays.equals
Summary: Intrinsify java/util/Arrays.equals(char[], char[])
Reviewed-by: kvn, never

     1 //
     2 // Copyright 2003-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20 // CA 95054 USA or visit www.sun.com if you need additional information or
    21 // have any questions.
    22 //
    23 //
    25 // AMD64 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 // R8-R15 must be encoded with REX.  (RSP, RBP, RSI, RDI need REX when
    64 // used as byte registers)
    66 // Previously set RBX, RSI, and RDI as save-on-entry for java code
    67 // Turn off SOE in java-code due to frequent use of uncommon-traps.
    68 // Now that allocator is better, turn on RSI and RDI as SOE registers.
    70 reg_def RAX  (SOC, SOC, Op_RegI,  0, rax->as_VMReg());
    71 reg_def RAX_H(SOC, SOC, Op_RegI,  0, rax->as_VMReg()->next());
    73 reg_def RCX  (SOC, SOC, Op_RegI,  1, rcx->as_VMReg());
    74 reg_def RCX_H(SOC, SOC, Op_RegI,  1, rcx->as_VMReg()->next());
    76 reg_def RDX  (SOC, SOC, Op_RegI,  2, rdx->as_VMReg());
    77 reg_def RDX_H(SOC, SOC, Op_RegI,  2, rdx->as_VMReg()->next());
    79 reg_def RBX  (SOC, SOE, Op_RegI,  3, rbx->as_VMReg());
    80 reg_def RBX_H(SOC, SOE, Op_RegI,  3, rbx->as_VMReg()->next());
    82 reg_def RSP  (NS,  NS,  Op_RegI,  4, rsp->as_VMReg());
    83 reg_def RSP_H(NS,  NS,  Op_RegI,  4, rsp->as_VMReg()->next());
    85 // now that adapter frames are gone RBP is always saved and restored by the prolog/epilog code
    86 reg_def RBP  (NS, SOE, Op_RegI,  5, rbp->as_VMReg());
    87 reg_def RBP_H(NS, SOE, Op_RegI,  5, rbp->as_VMReg()->next());
    89 #ifdef _WIN64
    91 reg_def RSI  (SOC, SOE, Op_RegI,  6, rsi->as_VMReg());
    92 reg_def RSI_H(SOC, SOE, Op_RegI,  6, rsi->as_VMReg()->next());
    94 reg_def RDI  (SOC, SOE, Op_RegI,  7, rdi->as_VMReg());
    95 reg_def RDI_H(SOC, SOE, Op_RegI,  7, rdi->as_VMReg()->next());
    97 #else
    99 reg_def RSI  (SOC, SOC, Op_RegI,  6, rsi->as_VMReg());
   100 reg_def RSI_H(SOC, SOC, Op_RegI,  6, rsi->as_VMReg()->next());
   102 reg_def RDI  (SOC, SOC, Op_RegI,  7, rdi->as_VMReg());
   103 reg_def RDI_H(SOC, SOC, Op_RegI,  7, rdi->as_VMReg()->next());
   105 #endif
   107 reg_def R8   (SOC, SOC, Op_RegI,  8, r8->as_VMReg());
   108 reg_def R8_H (SOC, SOC, Op_RegI,  8, r8->as_VMReg()->next());
   110 reg_def R9   (SOC, SOC, Op_RegI,  9, r9->as_VMReg());
   111 reg_def R9_H (SOC, SOC, Op_RegI,  9, r9->as_VMReg()->next());
   113 reg_def R10  (SOC, SOC, Op_RegI, 10, r10->as_VMReg());
   114 reg_def R10_H(SOC, SOC, Op_RegI, 10, r10->as_VMReg()->next());
   116 reg_def R11  (SOC, SOC, Op_RegI, 11, r11->as_VMReg());
   117 reg_def R11_H(SOC, SOC, Op_RegI, 11, r11->as_VMReg()->next());
   119 reg_def R12  (SOC, SOE, Op_RegI, 12, r12->as_VMReg());
   120 reg_def R12_H(SOC, SOE, Op_RegI, 12, r12->as_VMReg()->next());
   122 reg_def R13  (SOC, SOE, Op_RegI, 13, r13->as_VMReg());
   123 reg_def R13_H(SOC, SOE, Op_RegI, 13, r13->as_VMReg()->next());
   125 reg_def R14  (SOC, SOE, Op_RegI, 14, r14->as_VMReg());
   126 reg_def R14_H(SOC, SOE, Op_RegI, 14, r14->as_VMReg()->next());
   128 reg_def R15  (SOC, SOE, Op_RegI, 15, r15->as_VMReg());
   129 reg_def R15_H(SOC, SOE, Op_RegI, 15, r15->as_VMReg()->next());
   132 // Floating Point Registers
   134 // XMM registers.  128-bit registers or 4 words each, labeled (a)-d.
   135 // Word a in each register holds a Float, words ab hold a Double.  We
   136 // currently do not use the SIMD capabilities, so registers cd are
   137 // unused at the moment.
   138 // XMM8-XMM15 must be encoded with REX.
   139 // Linux ABI:   No register preserved across function calls
   140 //              XMM0-XMM7 might hold parameters
   141 // Windows ABI: XMM6-XMM15 preserved across function calls
   142 //              XMM0-XMM3 might hold parameters
   144 reg_def XMM0   (SOC, SOC, Op_RegF,  0, xmm0->as_VMReg());
   145 reg_def XMM0_H (SOC, SOC, Op_RegF,  0, xmm0->as_VMReg()->next());
   147 reg_def XMM1   (SOC, SOC, Op_RegF,  1, xmm1->as_VMReg());
   148 reg_def XMM1_H (SOC, SOC, Op_RegF,  1, xmm1->as_VMReg()->next());
   150 reg_def XMM2   (SOC, SOC, Op_RegF,  2, xmm2->as_VMReg());
   151 reg_def XMM2_H (SOC, SOC, Op_RegF,  2, xmm2->as_VMReg()->next());
   153 reg_def XMM3   (SOC, SOC, Op_RegF,  3, xmm3->as_VMReg());
   154 reg_def XMM3_H (SOC, SOC, Op_RegF,  3, xmm3->as_VMReg()->next());
   156 reg_def XMM4   (SOC, SOC, Op_RegF,  4, xmm4->as_VMReg());
   157 reg_def XMM4_H (SOC, SOC, Op_RegF,  4, xmm4->as_VMReg()->next());
   159 reg_def XMM5   (SOC, SOC, Op_RegF,  5, xmm5->as_VMReg());
   160 reg_def XMM5_H (SOC, SOC, Op_RegF,  5, xmm5->as_VMReg()->next());
   162 #ifdef _WIN64
   164 reg_def XMM6   (SOC, SOE, Op_RegF,  6, xmm6->as_VMReg());
   165 reg_def XMM6_H (SOC, SOE, Op_RegF,  6, xmm6->as_VMReg()->next());
   167 reg_def XMM7   (SOC, SOE, Op_RegF,  7, xmm7->as_VMReg());
   168 reg_def XMM7_H (SOC, SOE, Op_RegF,  7, xmm7->as_VMReg()->next());
   170 reg_def XMM8   (SOC, SOE, Op_RegF,  8, xmm8->as_VMReg());
   171 reg_def XMM8_H (SOC, SOE, Op_RegF,  8, xmm8->as_VMReg()->next());
   173 reg_def XMM9   (SOC, SOE, Op_RegF,  9, xmm9->as_VMReg());
   174 reg_def XMM9_H (SOC, SOE, Op_RegF,  9, xmm9->as_VMReg()->next());
   176 reg_def XMM10  (SOC, SOE, Op_RegF, 10, xmm10->as_VMReg());
   177 reg_def XMM10_H(SOC, SOE, Op_RegF, 10, xmm10->as_VMReg()->next());
   179 reg_def XMM11  (SOC, SOE, Op_RegF, 11, xmm11->as_VMReg());
   180 reg_def XMM11_H(SOC, SOE, Op_RegF, 11, xmm11->as_VMReg()->next());
   182 reg_def XMM12  (SOC, SOE, Op_RegF, 12, xmm12->as_VMReg());
   183 reg_def XMM12_H(SOC, SOE, Op_RegF, 12, xmm12->as_VMReg()->next());
   185 reg_def XMM13  (SOC, SOE, Op_RegF, 13, xmm13->as_VMReg());
   186 reg_def XMM13_H(SOC, SOE, Op_RegF, 13, xmm13->as_VMReg()->next());
   188 reg_def XMM14  (SOC, SOE, Op_RegF, 14, xmm14->as_VMReg());
   189 reg_def XMM14_H(SOC, SOE, Op_RegF, 14, xmm14->as_VMReg()->next());
   191 reg_def XMM15  (SOC, SOE, Op_RegF, 15, xmm15->as_VMReg());
   192 reg_def XMM15_H(SOC, SOE, Op_RegF, 15, xmm15->as_VMReg()->next());
   194 #else
   196 reg_def XMM6   (SOC, SOC, Op_RegF,  6, xmm6->as_VMReg());
   197 reg_def XMM6_H (SOC, SOC, Op_RegF,  6, xmm6->as_VMReg()->next());
   199 reg_def XMM7   (SOC, SOC, Op_RegF,  7, xmm7->as_VMReg());
   200 reg_def XMM7_H (SOC, SOC, Op_RegF,  7, xmm7->as_VMReg()->next());
   202 reg_def XMM8   (SOC, SOC, Op_RegF,  8, xmm8->as_VMReg());
   203 reg_def XMM8_H (SOC, SOC, Op_RegF,  8, xmm8->as_VMReg()->next());
   205 reg_def XMM9   (SOC, SOC, Op_RegF,  9, xmm9->as_VMReg());
   206 reg_def XMM9_H (SOC, SOC, Op_RegF,  9, xmm9->as_VMReg()->next());
   208 reg_def XMM10  (SOC, SOC, Op_RegF, 10, xmm10->as_VMReg());
   209 reg_def XMM10_H(SOC, SOC, Op_RegF, 10, xmm10->as_VMReg()->next());
   211 reg_def XMM11  (SOC, SOC, Op_RegF, 11, xmm11->as_VMReg());
   212 reg_def XMM11_H(SOC, SOC, Op_RegF, 11, xmm11->as_VMReg()->next());
   214 reg_def XMM12  (SOC, SOC, Op_RegF, 12, xmm12->as_VMReg());
   215 reg_def XMM12_H(SOC, SOC, Op_RegF, 12, xmm12->as_VMReg()->next());
   217 reg_def XMM13  (SOC, SOC, Op_RegF, 13, xmm13->as_VMReg());
   218 reg_def XMM13_H(SOC, SOC, Op_RegF, 13, xmm13->as_VMReg()->next());
   220 reg_def XMM14  (SOC, SOC, Op_RegF, 14, xmm14->as_VMReg());
   221 reg_def XMM14_H(SOC, SOC, Op_RegF, 14, xmm14->as_VMReg()->next());
   223 reg_def XMM15  (SOC, SOC, Op_RegF, 15, xmm15->as_VMReg());
   224 reg_def XMM15_H(SOC, SOC, Op_RegF, 15, xmm15->as_VMReg()->next());
   226 #endif // _WIN64
   228 reg_def RFLAGS(SOC, SOC, 0, 16, VMRegImpl::Bad());
   230 // Specify priority of register selection within phases of register
   231 // allocation.  Highest priority is first.  A useful heuristic is to
   232 // give registers a low priority when they are required by machine
   233 // instructions, like EAX and EDX on I486, and choose no-save registers
   234 // before save-on-call, & save-on-call before save-on-entry.  Registers
   235 // which participate in fixed calling sequences should come last.
   236 // Registers which are used as pairs must fall on an even boundary.
   238 alloc_class chunk0(R10,         R10_H,
   239                    R11,         R11_H,
   240                    R8,          R8_H,
   241                    R9,          R9_H,
   242                    R12,         R12_H,
   243                    RCX,         RCX_H,
   244                    RBX,         RBX_H,
   245                    RDI,         RDI_H,
   246                    RDX,         RDX_H,
   247                    RSI,         RSI_H,
   248                    RAX,         RAX_H,
   249                    RBP,         RBP_H,
   250                    R13,         R13_H,
   251                    R14,         R14_H,
   252                    R15,         R15_H,
   253                    RSP,         RSP_H);
   255 // XXX probably use 8-15 first on Linux
   256 alloc_class chunk1(XMM0,  XMM0_H,
   257                    XMM1,  XMM1_H,
   258                    XMM2,  XMM2_H,
   259                    XMM3,  XMM3_H,
   260                    XMM4,  XMM4_H,
   261                    XMM5,  XMM5_H,
   262                    XMM6,  XMM6_H,
   263                    XMM7,  XMM7_H,
   264                    XMM8,  XMM8_H,
   265                    XMM9,  XMM9_H,
   266                    XMM10, XMM10_H,
   267                    XMM11, XMM11_H,
   268                    XMM12, XMM12_H,
   269                    XMM13, XMM13_H,
   270                    XMM14, XMM14_H,
   271                    XMM15, XMM15_H);
   273 alloc_class chunk2(RFLAGS);
   276 //----------Architecture Description Register Classes--------------------------
   277 // Several register classes are automatically defined based upon information in
   278 // this architecture description.
   279 // 1) reg_class inline_cache_reg           ( /* as def'd in frame section */ )
   280 // 2) reg_class compiler_method_oop_reg    ( /* as def'd in frame section */ )
   281 // 2) reg_class interpreter_method_oop_reg ( /* as def'd in frame section */ )
   282 // 3) reg_class stack_slots( /* one chunk of stack-based "registers" */ )
   283 //
   285 // Class for all pointer registers (including RSP)
   286 reg_class any_reg(RAX, RAX_H,
   287                   RDX, RDX_H,
   288                   RBP, RBP_H,
   289                   RDI, RDI_H,
   290                   RSI, RSI_H,
   291                   RCX, RCX_H,
   292                   RBX, RBX_H,
   293                   RSP, RSP_H,
   294                   R8,  R8_H,
   295                   R9,  R9_H,
   296                   R10, R10_H,
   297                   R11, R11_H,
   298                   R12, R12_H,
   299                   R13, R13_H,
   300                   R14, R14_H,
   301                   R15, R15_H);
   303 // Class for all pointer registers except RSP
   304 reg_class ptr_reg(RAX, RAX_H,
   305                   RDX, RDX_H,
   306                   RBP, RBP_H,
   307                   RDI, RDI_H,
   308                   RSI, RSI_H,
   309                   RCX, RCX_H,
   310                   RBX, RBX_H,
   311                   R8,  R8_H,
   312                   R9,  R9_H,
   313                   R10, R10_H,
   314                   R11, R11_H,
   315                   R13, R13_H,
   316                   R14, R14_H);
   318 // Class for all pointer registers except RAX and RSP
   319 reg_class ptr_no_rax_reg(RDX, RDX_H,
   320                          RBP, RBP_H,
   321                          RDI, RDI_H,
   322                          RSI, RSI_H,
   323                          RCX, RCX_H,
   324                          RBX, RBX_H,
   325                          R8,  R8_H,
   326                          R9,  R9_H,
   327                          R10, R10_H,
   328                          R11, R11_H,
   329                          R12, R12_H,
   330                          R13, R13_H,
   331                          R14, R14_H);
   333 reg_class ptr_no_rbp_reg(RDX, RDX_H,
   334                          RAX, RAX_H,
   335                          RDI, RDI_H,
   336                          RSI, RSI_H,
   337                          RCX, RCX_H,
   338                          RBX, RBX_H,
   339                          R8,  R8_H,
   340                          R9,  R9_H,
   341                          R10, R10_H,
   342                          R11, R11_H,
   343                          R12, R12_H,
   344                          R13, R13_H,
   345                          R14, R14_H);
   347 // Class for all pointer registers except RAX, RBX and RSP
   348 reg_class ptr_no_rax_rbx_reg(RDX, RDX_H,
   349                              RBP, RBP_H,
   350                              RDI, RDI_H,
   351                              RSI, RSI_H,
   352                              RCX, RCX_H,
   353                              R8,  R8_H,
   354                              R9,  R9_H,
   355                              R10, R10_H,
   356                              R11, R11_H,
   357                              R12, R12_H,
   358                              R13, R13_H,
   359                              R14, R14_H);
   361 // Singleton class for RAX pointer register
   362 reg_class ptr_rax_reg(RAX, RAX_H);
   364 // Singleton class for RBX pointer register
   365 reg_class ptr_rbx_reg(RBX, RBX_H);
   367 // Singleton class for RSI pointer register
   368 reg_class ptr_rsi_reg(RSI, RSI_H);
   370 // Singleton class for RDI pointer register
   371 reg_class ptr_rdi_reg(RDI, RDI_H);
   373 // Singleton class for RBP pointer register
   374 reg_class ptr_rbp_reg(RBP, RBP_H);
   376 // Singleton class for stack pointer
   377 reg_class ptr_rsp_reg(RSP, RSP_H);
   379 // Singleton class for TLS pointer
   380 reg_class ptr_r15_reg(R15, R15_H);
   382 // Class for all long registers (except RSP)
   383 reg_class long_reg(RAX, RAX_H,
   384                    RDX, RDX_H,
   385                    RBP, RBP_H,
   386                    RDI, RDI_H,
   387                    RSI, RSI_H,
   388                    RCX, RCX_H,
   389                    RBX, RBX_H,
   390                    R8,  R8_H,
   391                    R9,  R9_H,
   392                    R10, R10_H,
   393                    R11, R11_H,
   394                    R13, R13_H,
   395                    R14, R14_H);
   397 // Class for all long registers except RAX, RDX (and RSP)
   398 reg_class long_no_rax_rdx_reg(RBP, RBP_H,
   399                               RDI, RDI_H,
   400                               RSI, RSI_H,
   401                               RCX, RCX_H,
   402                               RBX, RBX_H,
   403                               R8,  R8_H,
   404                               R9,  R9_H,
   405                               R10, R10_H,
   406                               R11, R11_H,
   407                               R13, R13_H,
   408                               R14, R14_H);
   410 // Class for all long registers except RCX (and RSP)
   411 reg_class long_no_rcx_reg(RBP, RBP_H,
   412                           RDI, RDI_H,
   413                           RSI, RSI_H,
   414                           RAX, RAX_H,
   415                           RDX, RDX_H,
   416                           RBX, RBX_H,
   417                           R8,  R8_H,
   418                           R9,  R9_H,
   419                           R10, R10_H,
   420                           R11, R11_H,
   421                           R13, R13_H,
   422                           R14, R14_H);
   424 // Class for all long registers except RAX (and RSP)
   425 reg_class long_no_rax_reg(RBP, RBP_H,
   426                           RDX, RDX_H,
   427                           RDI, RDI_H,
   428                           RSI, RSI_H,
   429                           RCX, RCX_H,
   430                           RBX, RBX_H,
   431                           R8,  R8_H,
   432                           R9,  R9_H,
   433                           R10, R10_H,
   434                           R11, R11_H,
   435                           R13, R13_H,
   436                           R14, R14_H);
   438 // Singleton class for RAX long register
   439 reg_class long_rax_reg(RAX, RAX_H);
   441 // Singleton class for RCX long register
   442 reg_class long_rcx_reg(RCX, RCX_H);
   444 // Singleton class for RDX long register
   445 reg_class long_rdx_reg(RDX, RDX_H);
   447 // Singleton class for R12 long register
   448 reg_class long_r12_reg(R12, R12_H);
   450 // Class for all int registers (except RSP)
   451 reg_class int_reg(RAX,
   452                   RDX,
   453                   RBP,
   454                   RDI,
   455                   RSI,
   456                   RCX,
   457                   RBX,
   458                   R8,
   459                   R9,
   460                   R10,
   461                   R11,
   462                   R13,
   463                   R14);
   465 // Class for all int registers except RCX (and RSP)
   466 reg_class int_no_rcx_reg(RAX,
   467                          RDX,
   468                          RBP,
   469                          RDI,
   470                          RSI,
   471                          RBX,
   472                          R8,
   473                          R9,
   474                          R10,
   475                          R11,
   476                          R13,
   477                          R14);
   479 // Class for all int registers except RAX, RDX (and RSP)
   480 reg_class int_no_rax_rdx_reg(RBP,
   481                              RDI
   482                              RSI,
   483                              RCX,
   484                              RBX,
   485                              R8,
   486                              R9,
   487                              R10,
   488                              R11,
   489                              R13,
   490                              R14);
   492 // Singleton class for RAX int register
   493 reg_class int_rax_reg(RAX);
   495 // Singleton class for RBX int register
   496 reg_class int_rbx_reg(RBX);
   498 // Singleton class for RCX int register
   499 reg_class int_rcx_reg(RCX);
   501 // Singleton class for RCX int register
   502 reg_class int_rdx_reg(RDX);
   504 // Singleton class for RCX int register
   505 reg_class int_rdi_reg(RDI);
   507 // Singleton class for instruction pointer
   508 // reg_class ip_reg(RIP);
   510 // Singleton class for condition codes
   511 reg_class int_flags(RFLAGS);
   513 // Class for all float registers
   514 reg_class float_reg(XMM0,
   515                     XMM1,
   516                     XMM2,
   517                     XMM3,
   518                     XMM4,
   519                     XMM5,
   520                     XMM6,
   521                     XMM7,
   522                     XMM8,
   523                     XMM9,
   524                     XMM10,
   525                     XMM11,
   526                     XMM12,
   527                     XMM13,
   528                     XMM14,
   529                     XMM15);
   531 // Class for all double registers
   532 reg_class double_reg(XMM0,  XMM0_H,
   533                      XMM1,  XMM1_H,
   534                      XMM2,  XMM2_H,
   535                      XMM3,  XMM3_H,
   536                      XMM4,  XMM4_H,
   537                      XMM5,  XMM5_H,
   538                      XMM6,  XMM6_H,
   539                      XMM7,  XMM7_H,
   540                      XMM8,  XMM8_H,
   541                      XMM9,  XMM9_H,
   542                      XMM10, XMM10_H,
   543                      XMM11, XMM11_H,
   544                      XMM12, XMM12_H,
   545                      XMM13, XMM13_H,
   546                      XMM14, XMM14_H,
   547                      XMM15, XMM15_H);
   548 %}
   551 //----------SOURCE BLOCK-------------------------------------------------------
   552 // This is a block of C++ code which provides values, functions, and
   553 // definitions necessary in the rest of the architecture description
   554 source %{
   555 #define   RELOC_IMM64    Assembler::imm64_operand
   556 #define   RELOC_DISP32   Assembler::disp32_operand
   558 #define __ _masm.
   560 // !!!!! Special hack to get all types of calls to specify the byte offset
   561 //       from the start of the call to the point where the return address
   562 //       will point.
   563 int MachCallStaticJavaNode::ret_addr_offset()
   564 {
   565   return 5; // 5 bytes from start of call to where return address points
   566 }
   568 int MachCallDynamicJavaNode::ret_addr_offset()
   569 {
   570   return 15; // 15 bytes from start of call to where return address points
   571 }
   573 // In os_cpu .ad file
   574 // int MachCallRuntimeNode::ret_addr_offset()
   576 // Indicate if the safepoint node needs the polling page as an input.
   577 // Since amd64 does not have absolute addressing but RIP-relative
   578 // addressing and the polling page is within 2G, it doesn't.
   579 bool SafePointNode::needs_polling_address_input()
   580 {
   581   return false;
   582 }
   584 //
   585 // Compute padding required for nodes which need alignment
   586 //
   588 // The address of the call instruction needs to be 4-byte aligned to
   589 // ensure that it does not span a cache line so that it can be patched.
   590 int CallStaticJavaDirectNode::compute_padding(int current_offset) const
   591 {
   592   current_offset += 1; // skip call opcode byte
   593   return round_to(current_offset, alignment_required()) - current_offset;
   594 }
   596 // The address of the call instruction needs to be 4-byte aligned to
   597 // ensure that it does not span a cache line so that it can be patched.
   598 int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
   599 {
   600   current_offset += 11; // skip movq instruction + call opcode byte
   601   return round_to(current_offset, alignment_required()) - current_offset;
   602 }
   604 #ifndef PRODUCT
   605 void MachBreakpointNode::format(PhaseRegAlloc*, outputStream* st) const
   606 {
   607   st->print("INT3");
   608 }
   609 #endif
   611 // EMIT_RM()
   612 void emit_rm(CodeBuffer &cbuf, int f1, int f2, int f3)
   613 {
   614   unsigned char c = (unsigned char) ((f1 << 6) | (f2 << 3) | f3);
   615   *(cbuf.code_end()) = c;
   616   cbuf.set_code_end(cbuf.code_end() + 1);
   617 }
   619 // EMIT_CC()
   620 void emit_cc(CodeBuffer &cbuf, int f1, int f2)
   621 {
   622   unsigned char c = (unsigned char) (f1 | f2);
   623   *(cbuf.code_end()) = c;
   624   cbuf.set_code_end(cbuf.code_end() + 1);
   625 }
   627 // EMIT_OPCODE()
   628 void emit_opcode(CodeBuffer &cbuf, int code)
   629 {
   630   *(cbuf.code_end()) = (unsigned char) code;
   631   cbuf.set_code_end(cbuf.code_end() + 1);
   632 }
   634 // EMIT_OPCODE() w/ relocation information
   635 void emit_opcode(CodeBuffer &cbuf,
   636                  int code, relocInfo::relocType reloc, int offset, int format)
   637 {
   638   cbuf.relocate(cbuf.inst_mark() + offset, reloc, format);
   639   emit_opcode(cbuf, code);
   640 }
   642 // EMIT_D8()
   643 void emit_d8(CodeBuffer &cbuf, int d8)
   644 {
   645   *(cbuf.code_end()) = (unsigned char) d8;
   646   cbuf.set_code_end(cbuf.code_end() + 1);
   647 }
   649 // EMIT_D16()
   650 void emit_d16(CodeBuffer &cbuf, int d16)
   651 {
   652   *((short *)(cbuf.code_end())) = d16;
   653   cbuf.set_code_end(cbuf.code_end() + 2);
   654 }
   656 // EMIT_D32()
   657 void emit_d32(CodeBuffer &cbuf, int d32)
   658 {
   659   *((int *)(cbuf.code_end())) = d32;
   660   cbuf.set_code_end(cbuf.code_end() + 4);
   661 }
   663 // EMIT_D64()
   664 void emit_d64(CodeBuffer &cbuf, int64_t d64)
   665 {
   666   *((int64_t*) (cbuf.code_end())) = d64;
   667   cbuf.set_code_end(cbuf.code_end() + 8);
   668 }
   670 // emit 32 bit value and construct relocation entry from relocInfo::relocType
   671 void emit_d32_reloc(CodeBuffer& cbuf,
   672                     int d32,
   673                     relocInfo::relocType reloc,
   674                     int format)
   675 {
   676   assert(reloc != relocInfo::external_word_type, "use 2-arg emit_d32_reloc");
   677   cbuf.relocate(cbuf.inst_mark(), reloc, format);
   679   *((int*) (cbuf.code_end())) = d32;
   680   cbuf.set_code_end(cbuf.code_end() + 4);
   681 }
   683 // emit 32 bit value and construct relocation entry from RelocationHolder
   684 void emit_d32_reloc(CodeBuffer& cbuf,
   685                     int d32,
   686                     RelocationHolder const& rspec,
   687                     int format)
   688 {
   689 #ifdef ASSERT
   690   if (rspec.reloc()->type() == relocInfo::oop_type &&
   691       d32 != 0 && d32 != (intptr_t) Universe::non_oop_word()) {
   692     assert(oop((intptr_t)d32)->is_oop() && oop((intptr_t)d32)->is_perm(), "cannot embed non-perm oops in code");
   693   }
   694 #endif
   695   cbuf.relocate(cbuf.inst_mark(), rspec, format);
   697   *((int* )(cbuf.code_end())) = d32;
   698   cbuf.set_code_end(cbuf.code_end() + 4);
   699 }
   701 void emit_d32_reloc(CodeBuffer& cbuf, address addr) {
   702   address next_ip = cbuf.code_end() + 4;
   703   emit_d32_reloc(cbuf, (int) (addr - next_ip),
   704                  external_word_Relocation::spec(addr),
   705                  RELOC_DISP32);
   706 }
   709 // emit 64 bit value and construct relocation entry from relocInfo::relocType
   710 void emit_d64_reloc(CodeBuffer& cbuf,
   711                     int64_t d64,
   712                     relocInfo::relocType reloc,
   713                     int format)
   714 {
   715   cbuf.relocate(cbuf.inst_mark(), reloc, format);
   717   *((int64_t*) (cbuf.code_end())) = d64;
   718   cbuf.set_code_end(cbuf.code_end() + 8);
   719 }
   721 // emit 64 bit value and construct relocation entry from RelocationHolder
   722 void emit_d64_reloc(CodeBuffer& cbuf,
   723                     int64_t d64,
   724                     RelocationHolder const& rspec,
   725                     int format)
   726 {
   727 #ifdef ASSERT
   728   if (rspec.reloc()->type() == relocInfo::oop_type &&
   729       d64 != 0 && d64 != (int64_t) Universe::non_oop_word()) {
   730     assert(oop(d64)->is_oop() && oop(d64)->is_perm(),
   731            "cannot embed non-perm oops in code");
   732   }
   733 #endif
   734   cbuf.relocate(cbuf.inst_mark(), rspec, format);
   736   *((int64_t*) (cbuf.code_end())) = d64;
   737   cbuf.set_code_end(cbuf.code_end() + 8);
   738 }
   740 // Access stack slot for load or store
   741 void store_to_stackslot(CodeBuffer &cbuf, int opcode, int rm_field, int disp)
   742 {
   743   emit_opcode(cbuf, opcode);                  // (e.g., FILD   [RSP+src])
   744   if (-0x80 <= disp && disp < 0x80) {
   745     emit_rm(cbuf, 0x01, rm_field, RSP_enc);   // R/M byte
   746     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
   747     emit_d8(cbuf, disp);     // Displacement  // R/M byte
   748   } else {
   749     emit_rm(cbuf, 0x02, rm_field, RSP_enc);   // R/M byte
   750     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
   751     emit_d32(cbuf, disp);     // Displacement // R/M byte
   752   }
   753 }
   755    // rRegI ereg, memory mem) %{    // emit_reg_mem
   756 void encode_RegMem(CodeBuffer &cbuf,
   757                    int reg,
   758                    int base, int index, int scale, int disp, bool disp_is_oop)
   759 {
   760   assert(!disp_is_oop, "cannot have disp");
   761   int regenc = reg & 7;
   762   int baseenc = base & 7;
   763   int indexenc = index & 7;
   765   // There is no index & no scale, use form without SIB byte
   766   if (index == 0x4 && scale == 0 && base != RSP_enc && base != R12_enc) {
   767     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
   768     if (disp == 0 && base != RBP_enc && base != R13_enc) {
   769       emit_rm(cbuf, 0x0, regenc, baseenc); // *
   770     } else if (-0x80 <= disp && disp < 0x80 && !disp_is_oop) {
   771       // If 8-bit displacement, mode 0x1
   772       emit_rm(cbuf, 0x1, regenc, baseenc); // *
   773       emit_d8(cbuf, disp);
   774     } else {
   775       // If 32-bit displacement
   776       if (base == -1) { // Special flag for absolute address
   777         emit_rm(cbuf, 0x0, regenc, 0x5); // *
   778         if (disp_is_oop) {
   779           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
   780         } else {
   781           emit_d32(cbuf, disp);
   782         }
   783       } else {
   784         // Normal base + offset
   785         emit_rm(cbuf, 0x2, regenc, baseenc); // *
   786         if (disp_is_oop) {
   787           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
   788         } else {
   789           emit_d32(cbuf, disp);
   790         }
   791       }
   792     }
   793   } else {
   794     // Else, encode with the SIB byte
   795     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
   796     if (disp == 0 && base != RBP_enc && base != R13_enc) {
   797       // If no displacement
   798       emit_rm(cbuf, 0x0, regenc, 0x4); // *
   799       emit_rm(cbuf, scale, indexenc, baseenc);
   800     } else {
   801       if (-0x80 <= disp && disp < 0x80 && !disp_is_oop) {
   802         // If 8-bit displacement, mode 0x1
   803         emit_rm(cbuf, 0x1, regenc, 0x4); // *
   804         emit_rm(cbuf, scale, indexenc, baseenc);
   805         emit_d8(cbuf, disp);
   806       } else {
   807         // If 32-bit displacement
   808         if (base == 0x04 ) {
   809           emit_rm(cbuf, 0x2, regenc, 0x4);
   810           emit_rm(cbuf, scale, indexenc, 0x04); // XXX is this valid???
   811         } else {
   812           emit_rm(cbuf, 0x2, regenc, 0x4);
   813           emit_rm(cbuf, scale, indexenc, baseenc); // *
   814         }
   815         if (disp_is_oop) {
   816           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
   817         } else {
   818           emit_d32(cbuf, disp);
   819         }
   820       }
   821     }
   822   }
   823 }
   825 void encode_copy(CodeBuffer &cbuf, int dstenc, int srcenc)
   826 {
   827   if (dstenc != srcenc) {
   828     if (dstenc < 8) {
   829       if (srcenc >= 8) {
   830         emit_opcode(cbuf, Assembler::REX_B);
   831         srcenc -= 8;
   832       }
   833     } else {
   834       if (srcenc < 8) {
   835         emit_opcode(cbuf, Assembler::REX_R);
   836       } else {
   837         emit_opcode(cbuf, Assembler::REX_RB);
   838         srcenc -= 8;
   839       }
   840       dstenc -= 8;
   841     }
   843     emit_opcode(cbuf, 0x8B);
   844     emit_rm(cbuf, 0x3, dstenc, srcenc);
   845   }
   846 }
   848 void encode_CopyXD( CodeBuffer &cbuf, int dst_encoding, int src_encoding ) {
   849   if( dst_encoding == src_encoding ) {
   850     // reg-reg copy, use an empty encoding
   851   } else {
   852     MacroAssembler _masm(&cbuf);
   854     __ movdqa(as_XMMRegister(dst_encoding), as_XMMRegister(src_encoding));
   855   }
   856 }
   859 //=============================================================================
   860 #ifndef PRODUCT
   861 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const
   862 {
   863   Compile* C = ra_->C;
   865   int framesize = C->frame_slots() << LogBytesPerInt;
   866   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   867   // Remove wordSize for return adr already pushed
   868   // and another for the RBP we are going to save
   869   framesize -= 2*wordSize;
   870   bool need_nop = true;
   872   // Calls to C2R adapters often do not accept exceptional returns.
   873   // We require that their callers must bang for them.  But be
   874   // careful, because some VM calls (such as call site linkage) can
   875   // use several kilobytes of stack.  But the stack safety zone should
   876   // account for that.  See bugs 4446381, 4468289, 4497237.
   877   if (C->need_stack_bang(framesize)) {
   878     st->print_cr("# stack bang"); st->print("\t");
   879     need_nop = false;
   880   }
   881   st->print_cr("pushq   rbp"); st->print("\t");
   883   if (VerifyStackAtCalls) {
   884     // Majik cookie to verify stack depth
   885     st->print_cr("pushq   0xffffffffbadb100d"
   886                   "\t# Majik cookie for stack depth check");
   887     st->print("\t");
   888     framesize -= wordSize; // Remove 2 for cookie
   889     need_nop = false;
   890   }
   892   if (framesize) {
   893     st->print("subq    rsp, #%d\t# Create frame", framesize);
   894     if (framesize < 0x80 && need_nop) {
   895       st->print("\n\tnop\t# nop for patch_verified_entry");
   896     }
   897   }
   898 }
   899 #endif
   901 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const
   902 {
   903   Compile* C = ra_->C;
   905   // WARNING: Initial instruction MUST be 5 bytes or longer so that
   906   // NativeJump::patch_verified_entry will be able to patch out the entry
   907   // code safely. The fldcw is ok at 6 bytes, the push to verify stack
   908   // depth is ok at 5 bytes, the frame allocation can be either 3 or
   909   // 6 bytes. So if we don't do the fldcw or the push then we must
   910   // use the 6 byte frame allocation even if we have no frame. :-(
   911   // If method sets FPU control word do it now
   913   int framesize = C->frame_slots() << LogBytesPerInt;
   914   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   915   // Remove wordSize for return adr already pushed
   916   // and another for the RBP we are going to save
   917   framesize -= 2*wordSize;
   918   bool need_nop = true;
   920   // Calls to C2R adapters often do not accept exceptional returns.
   921   // We require that their callers must bang for them.  But be
   922   // careful, because some VM calls (such as call site linkage) can
   923   // use several kilobytes of stack.  But the stack safety zone should
   924   // account for that.  See bugs 4446381, 4468289, 4497237.
   925   if (C->need_stack_bang(framesize)) {
   926     MacroAssembler masm(&cbuf);
   927     masm.generate_stack_overflow_check(framesize);
   928     need_nop = false;
   929   }
   931   // We always push rbp so that on return to interpreter rbp will be
   932   // restored correctly and we can correct the stack.
   933   emit_opcode(cbuf, 0x50 | RBP_enc);
   935   if (VerifyStackAtCalls) {
   936     // Majik cookie to verify stack depth
   937     emit_opcode(cbuf, 0x68); // pushq (sign-extended) 0xbadb100d
   938     emit_d32(cbuf, 0xbadb100d);
   939     framesize -= wordSize; // Remove 2 for cookie
   940     need_nop = false;
   941   }
   943   if (framesize) {
   944     emit_opcode(cbuf, Assembler::REX_W);
   945     if (framesize < 0x80) {
   946       emit_opcode(cbuf, 0x83);   // sub  SP,#framesize
   947       emit_rm(cbuf, 0x3, 0x05, RSP_enc);
   948       emit_d8(cbuf, framesize);
   949       if (need_nop) {
   950         emit_opcode(cbuf, 0x90); // nop
   951       }
   952     } else {
   953       emit_opcode(cbuf, 0x81);   // sub  SP,#framesize
   954       emit_rm(cbuf, 0x3, 0x05, RSP_enc);
   955       emit_d32(cbuf, framesize);
   956     }
   957   }
   959   C->set_frame_complete(cbuf.code_end() - cbuf.code_begin());
   961 #ifdef ASSERT
   962   if (VerifyStackAtCalls) {
   963     Label L;
   964     MacroAssembler masm(&cbuf);
   965     masm.pushq(rax);
   966     masm.movq(rax, rsp);
   967     masm.andq(rax, StackAlignmentInBytes-1);
   968     masm.cmpq(rax, StackAlignmentInBytes-wordSize);
   969     masm.popq(rax);
   970     masm.jcc(Assembler::equal, L);
   971     masm.stop("Stack is not properly aligned!");
   972     masm.bind(L);
   973   }
   974 #endif
   975 }
   977 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
   978 {
   979   return MachNode::size(ra_); // too many variables; just compute it
   980                               // the hard way
   981 }
   983 int MachPrologNode::reloc() const
   984 {
   985   return 0; // a large enough number
   986 }
   988 //=============================================================================
   989 #ifndef PRODUCT
   990 void MachEpilogNode::format(PhaseRegAlloc* ra_, outputStream* st) const
   991 {
   992   Compile* C = ra_->C;
   993   int framesize = C->frame_slots() << LogBytesPerInt;
   994   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   995   // Remove word for return adr already pushed
   996   // and RBP
   997   framesize -= 2*wordSize;
   999   if (framesize) {
  1000     st->print_cr("addq\trsp, %d\t# Destroy frame", framesize);
  1001     st->print("\t");
  1004   st->print_cr("popq\trbp");
  1005   if (do_polling() && C->is_method_compilation()) {
  1006     st->print_cr("\ttestl\trax, [rip + #offset_to_poll_page]\t"
  1007                   "# Safepoint: poll for GC");
  1008     st->print("\t");
  1011 #endif
  1013 void MachEpilogNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
  1015   Compile* C = ra_->C;
  1016   int framesize = C->frame_slots() << LogBytesPerInt;
  1017   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
  1018   // Remove word for return adr already pushed
  1019   // and RBP
  1020   framesize -= 2*wordSize;
  1022   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
  1024   if (framesize) {
  1025     emit_opcode(cbuf, Assembler::REX_W);
  1026     if (framesize < 0x80) {
  1027       emit_opcode(cbuf, 0x83); // addq rsp, #framesize
  1028       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
  1029       emit_d8(cbuf, framesize);
  1030     } else {
  1031       emit_opcode(cbuf, 0x81); // addq rsp, #framesize
  1032       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
  1033       emit_d32(cbuf, framesize);
  1037   // popq rbp
  1038   emit_opcode(cbuf, 0x58 | RBP_enc);
  1040   if (do_polling() && C->is_method_compilation()) {
  1041     // testl %rax, off(%rip) // Opcode + ModRM + Disp32 == 6 bytes
  1042     // XXX reg_mem doesn't support RIP-relative addressing yet
  1043     cbuf.set_inst_mark();
  1044     cbuf.relocate(cbuf.inst_mark(), relocInfo::poll_return_type, 0); // XXX
  1045     emit_opcode(cbuf, 0x85); // testl
  1046     emit_rm(cbuf, 0x0, RAX_enc, 0x5); // 00 rax 101 == 0x5
  1047     // cbuf.inst_mark() is beginning of instruction
  1048     emit_d32_reloc(cbuf, os::get_polling_page());
  1049 //                    relocInfo::poll_return_type,
  1053 uint MachEpilogNode::size(PhaseRegAlloc* ra_) const
  1055   Compile* C = ra_->C;
  1056   int framesize = C->frame_slots() << LogBytesPerInt;
  1057   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
  1058   // Remove word for return adr already pushed
  1059   // and RBP
  1060   framesize -= 2*wordSize;
  1062   uint size = 0;
  1064   if (do_polling() && C->is_method_compilation()) {
  1065     size += 6;
  1068   // count popq rbp
  1069   size++;
  1071   if (framesize) {
  1072     if (framesize < 0x80) {
  1073       size += 4;
  1074     } else if (framesize) {
  1075       size += 7;
  1079   return size;
  1082 int MachEpilogNode::reloc() const
  1084   return 2; // a large enough number
  1087 const Pipeline* MachEpilogNode::pipeline() const
  1089   return MachNode::pipeline_class();
  1092 int MachEpilogNode::safepoint_offset() const
  1094   return 0;
  1097 //=============================================================================
  1099 enum RC {
  1100   rc_bad,
  1101   rc_int,
  1102   rc_float,
  1103   rc_stack
  1104 };
  1106 static enum RC rc_class(OptoReg::Name reg)
  1108   if( !OptoReg::is_valid(reg)  ) return rc_bad;
  1110   if (OptoReg::is_stack(reg)) return rc_stack;
  1112   VMReg r = OptoReg::as_VMReg(reg);
  1114   if (r->is_Register()) return rc_int;
  1116   assert(r->is_XMMRegister(), "must be");
  1117   return rc_float;
  1120 uint MachSpillCopyNode::implementation(CodeBuffer* cbuf,
  1121                                        PhaseRegAlloc* ra_,
  1122                                        bool do_size,
  1123                                        outputStream* st) const
  1126   // Get registers to move
  1127   OptoReg::Name src_second = ra_->get_reg_second(in(1));
  1128   OptoReg::Name src_first = ra_->get_reg_first(in(1));
  1129   OptoReg::Name dst_second = ra_->get_reg_second(this);
  1130   OptoReg::Name dst_first = ra_->get_reg_first(this);
  1132   enum RC src_second_rc = rc_class(src_second);
  1133   enum RC src_first_rc = rc_class(src_first);
  1134   enum RC dst_second_rc = rc_class(dst_second);
  1135   enum RC dst_first_rc = rc_class(dst_first);
  1137   assert(OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first),
  1138          "must move at least 1 register" );
  1140   if (src_first == dst_first && src_second == dst_second) {
  1141     // Self copy, no move
  1142     return 0;
  1143   } else if (src_first_rc == rc_stack) {
  1144     // mem ->
  1145     if (dst_first_rc == rc_stack) {
  1146       // mem -> mem
  1147       assert(src_second != dst_first, "overlap");
  1148       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1149           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1150         // 64-bit
  1151         int src_offset = ra_->reg2offset(src_first);
  1152         int dst_offset = ra_->reg2offset(dst_first);
  1153         if (cbuf) {
  1154           emit_opcode(*cbuf, 0xFF);
  1155           encode_RegMem(*cbuf, RSI_enc, RSP_enc, 0x4, 0, src_offset, false);
  1157           emit_opcode(*cbuf, 0x8F);
  1158           encode_RegMem(*cbuf, RAX_enc, RSP_enc, 0x4, 0, dst_offset, false);
  1160 #ifndef PRODUCT
  1161         } else if (!do_size) {
  1162           st->print("pushq   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
  1163                      "popq    [rsp + #%d]",
  1164                      src_offset,
  1165                      dst_offset);
  1166 #endif
  1168         return
  1169           3 + ((src_offset == 0) ? 0 : (src_offset < 0x80 ? 1 : 4)) +
  1170           3 + ((dst_offset == 0) ? 0 : (dst_offset < 0x80 ? 1 : 4));
  1171       } else {
  1172         // 32-bit
  1173         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1174         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1175         // No pushl/popl, so:
  1176         int src_offset = ra_->reg2offset(src_first);
  1177         int dst_offset = ra_->reg2offset(dst_first);
  1178         if (cbuf) {
  1179           emit_opcode(*cbuf, Assembler::REX_W);
  1180           emit_opcode(*cbuf, 0x89);
  1181           emit_opcode(*cbuf, 0x44);
  1182           emit_opcode(*cbuf, 0x24);
  1183           emit_opcode(*cbuf, 0xF8);
  1185           emit_opcode(*cbuf, 0x8B);
  1186           encode_RegMem(*cbuf,
  1187                         RAX_enc,
  1188                         RSP_enc, 0x4, 0, src_offset,
  1189                         false);
  1191           emit_opcode(*cbuf, 0x89);
  1192           encode_RegMem(*cbuf,
  1193                         RAX_enc,
  1194                         RSP_enc, 0x4, 0, dst_offset,
  1195                         false);
  1197           emit_opcode(*cbuf, Assembler::REX_W);
  1198           emit_opcode(*cbuf, 0x8B);
  1199           emit_opcode(*cbuf, 0x44);
  1200           emit_opcode(*cbuf, 0x24);
  1201           emit_opcode(*cbuf, 0xF8);
  1203 #ifndef PRODUCT
  1204         } else if (!do_size) {
  1205           st->print("movq    [rsp - #8], rax\t# 32-bit mem-mem spill\n\t"
  1206                      "movl    rax, [rsp + #%d]\n\t"
  1207                      "movl    [rsp + #%d], rax\n\t"
  1208                      "movq    rax, [rsp - #8]",
  1209                      src_offset,
  1210                      dst_offset);
  1211 #endif
  1213         return
  1214           5 + // movq
  1215           3 + ((src_offset == 0) ? 0 : (src_offset < 0x80 ? 1 : 4)) + // movl
  1216           3 + ((dst_offset == 0) ? 0 : (dst_offset < 0x80 ? 1 : 4)) + // movl
  1217           5; // movq
  1219     } else if (dst_first_rc == rc_int) {
  1220       // mem -> gpr
  1221       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1222           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1223         // 64-bit
  1224         int offset = ra_->reg2offset(src_first);
  1225         if (cbuf) {
  1226           if (Matcher::_regEncode[dst_first] < 8) {
  1227             emit_opcode(*cbuf, Assembler::REX_W);
  1228           } else {
  1229             emit_opcode(*cbuf, Assembler::REX_WR);
  1231           emit_opcode(*cbuf, 0x8B);
  1232           encode_RegMem(*cbuf,
  1233                         Matcher::_regEncode[dst_first],
  1234                         RSP_enc, 0x4, 0, offset,
  1235                         false);
  1236 #ifndef PRODUCT
  1237         } else if (!do_size) {
  1238           st->print("movq    %s, [rsp + #%d]\t# spill",
  1239                      Matcher::regName[dst_first],
  1240                      offset);
  1241 #endif
  1243         return
  1244           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) + 4; // REX
  1245       } else {
  1246         // 32-bit
  1247         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1248         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1249         int offset = ra_->reg2offset(src_first);
  1250         if (cbuf) {
  1251           if (Matcher::_regEncode[dst_first] >= 8) {
  1252             emit_opcode(*cbuf, Assembler::REX_R);
  1254           emit_opcode(*cbuf, 0x8B);
  1255           encode_RegMem(*cbuf,
  1256                         Matcher::_regEncode[dst_first],
  1257                         RSP_enc, 0x4, 0, offset,
  1258                         false);
  1259 #ifndef PRODUCT
  1260         } else if (!do_size) {
  1261           st->print("movl    %s, [rsp + #%d]\t# spill",
  1262                      Matcher::regName[dst_first],
  1263                      offset);
  1264 #endif
  1266         return
  1267           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1268           ((Matcher::_regEncode[dst_first] < 8)
  1269            ? 3
  1270            : 4); // REX
  1272     } else if (dst_first_rc == rc_float) {
  1273       // mem-> xmm
  1274       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1275           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1276         // 64-bit
  1277         int offset = ra_->reg2offset(src_first);
  1278         if (cbuf) {
  1279           emit_opcode(*cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  1280           if (Matcher::_regEncode[dst_first] >= 8) {
  1281             emit_opcode(*cbuf, Assembler::REX_R);
  1283           emit_opcode(*cbuf, 0x0F);
  1284           emit_opcode(*cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  1285           encode_RegMem(*cbuf,
  1286                         Matcher::_regEncode[dst_first],
  1287                         RSP_enc, 0x4, 0, offset,
  1288                         false);
  1289 #ifndef PRODUCT
  1290         } else if (!do_size) {
  1291           st->print("%s  %s, [rsp + #%d]\t# spill",
  1292                      UseXmmLoadAndClearUpper ? "movsd " : "movlpd",
  1293                      Matcher::regName[dst_first],
  1294                      offset);
  1295 #endif
  1297         return
  1298           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1299           ((Matcher::_regEncode[dst_first] < 8)
  1300            ? 5
  1301            : 6); // REX
  1302       } else {
  1303         // 32-bit
  1304         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1305         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1306         int offset = ra_->reg2offset(src_first);
  1307         if (cbuf) {
  1308           emit_opcode(*cbuf, 0xF3);
  1309           if (Matcher::_regEncode[dst_first] >= 8) {
  1310             emit_opcode(*cbuf, Assembler::REX_R);
  1312           emit_opcode(*cbuf, 0x0F);
  1313           emit_opcode(*cbuf, 0x10);
  1314           encode_RegMem(*cbuf,
  1315                         Matcher::_regEncode[dst_first],
  1316                         RSP_enc, 0x4, 0, offset,
  1317                         false);
  1318 #ifndef PRODUCT
  1319         } else if (!do_size) {
  1320           st->print("movss   %s, [rsp + #%d]\t# spill",
  1321                      Matcher::regName[dst_first],
  1322                      offset);
  1323 #endif
  1325         return
  1326           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1327           ((Matcher::_regEncode[dst_first] < 8)
  1328            ? 5
  1329            : 6); // REX
  1332   } else if (src_first_rc == rc_int) {
  1333     // gpr ->
  1334     if (dst_first_rc == rc_stack) {
  1335       // gpr -> mem
  1336       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1337           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1338         // 64-bit
  1339         int offset = ra_->reg2offset(dst_first);
  1340         if (cbuf) {
  1341           if (Matcher::_regEncode[src_first] < 8) {
  1342             emit_opcode(*cbuf, Assembler::REX_W);
  1343           } else {
  1344             emit_opcode(*cbuf, Assembler::REX_WR);
  1346           emit_opcode(*cbuf, 0x89);
  1347           encode_RegMem(*cbuf,
  1348                         Matcher::_regEncode[src_first],
  1349                         RSP_enc, 0x4, 0, offset,
  1350                         false);
  1351 #ifndef PRODUCT
  1352         } else if (!do_size) {
  1353           st->print("movq    [rsp + #%d], %s\t# spill",
  1354                      offset,
  1355                      Matcher::regName[src_first]);
  1356 #endif
  1358         return ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) + 4; // REX
  1359       } else {
  1360         // 32-bit
  1361         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1362         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1363         int offset = ra_->reg2offset(dst_first);
  1364         if (cbuf) {
  1365           if (Matcher::_regEncode[src_first] >= 8) {
  1366             emit_opcode(*cbuf, Assembler::REX_R);
  1368           emit_opcode(*cbuf, 0x89);
  1369           encode_RegMem(*cbuf,
  1370                         Matcher::_regEncode[src_first],
  1371                         RSP_enc, 0x4, 0, offset,
  1372                         false);
  1373 #ifndef PRODUCT
  1374         } else if (!do_size) {
  1375           st->print("movl    [rsp + #%d], %s\t# spill",
  1376                      offset,
  1377                      Matcher::regName[src_first]);
  1378 #endif
  1380         return
  1381           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1382           ((Matcher::_regEncode[src_first] < 8)
  1383            ? 3
  1384            : 4); // REX
  1386     } else if (dst_first_rc == rc_int) {
  1387       // gpr -> gpr
  1388       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1389           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1390         // 64-bit
  1391         if (cbuf) {
  1392           if (Matcher::_regEncode[dst_first] < 8) {
  1393             if (Matcher::_regEncode[src_first] < 8) {
  1394               emit_opcode(*cbuf, Assembler::REX_W);
  1395             } else {
  1396               emit_opcode(*cbuf, Assembler::REX_WB);
  1398           } else {
  1399             if (Matcher::_regEncode[src_first] < 8) {
  1400               emit_opcode(*cbuf, Assembler::REX_WR);
  1401             } else {
  1402               emit_opcode(*cbuf, Assembler::REX_WRB);
  1405           emit_opcode(*cbuf, 0x8B);
  1406           emit_rm(*cbuf, 0x3,
  1407                   Matcher::_regEncode[dst_first] & 7,
  1408                   Matcher::_regEncode[src_first] & 7);
  1409 #ifndef PRODUCT
  1410         } else if (!do_size) {
  1411           st->print("movq    %s, %s\t# spill",
  1412                      Matcher::regName[dst_first],
  1413                      Matcher::regName[src_first]);
  1414 #endif
  1416         return 3; // REX
  1417       } else {
  1418         // 32-bit
  1419         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1420         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1421         if (cbuf) {
  1422           if (Matcher::_regEncode[dst_first] < 8) {
  1423             if (Matcher::_regEncode[src_first] >= 8) {
  1424               emit_opcode(*cbuf, Assembler::REX_B);
  1426           } else {
  1427             if (Matcher::_regEncode[src_first] < 8) {
  1428               emit_opcode(*cbuf, Assembler::REX_R);
  1429             } else {
  1430               emit_opcode(*cbuf, Assembler::REX_RB);
  1433           emit_opcode(*cbuf, 0x8B);
  1434           emit_rm(*cbuf, 0x3,
  1435                   Matcher::_regEncode[dst_first] & 7,
  1436                   Matcher::_regEncode[src_first] & 7);
  1437 #ifndef PRODUCT
  1438         } else if (!do_size) {
  1439           st->print("movl    %s, %s\t# spill",
  1440                      Matcher::regName[dst_first],
  1441                      Matcher::regName[src_first]);
  1442 #endif
  1444         return
  1445           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
  1446           ? 2
  1447           : 3; // REX
  1449     } else if (dst_first_rc == rc_float) {
  1450       // gpr -> xmm
  1451       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1452           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1453         // 64-bit
  1454         if (cbuf) {
  1455           emit_opcode(*cbuf, 0x66);
  1456           if (Matcher::_regEncode[dst_first] < 8) {
  1457             if (Matcher::_regEncode[src_first] < 8) {
  1458               emit_opcode(*cbuf, Assembler::REX_W);
  1459             } else {
  1460               emit_opcode(*cbuf, Assembler::REX_WB);
  1462           } else {
  1463             if (Matcher::_regEncode[src_first] < 8) {
  1464               emit_opcode(*cbuf, Assembler::REX_WR);
  1465             } else {
  1466               emit_opcode(*cbuf, Assembler::REX_WRB);
  1469           emit_opcode(*cbuf, 0x0F);
  1470           emit_opcode(*cbuf, 0x6E);
  1471           emit_rm(*cbuf, 0x3,
  1472                   Matcher::_regEncode[dst_first] & 7,
  1473                   Matcher::_regEncode[src_first] & 7);
  1474 #ifndef PRODUCT
  1475         } else if (!do_size) {
  1476           st->print("movdq   %s, %s\t# spill",
  1477                      Matcher::regName[dst_first],
  1478                      Matcher::regName[src_first]);
  1479 #endif
  1481         return 5; // REX
  1482       } else {
  1483         // 32-bit
  1484         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1485         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1486         if (cbuf) {
  1487           emit_opcode(*cbuf, 0x66);
  1488           if (Matcher::_regEncode[dst_first] < 8) {
  1489             if (Matcher::_regEncode[src_first] >= 8) {
  1490               emit_opcode(*cbuf, Assembler::REX_B);
  1492           } else {
  1493             if (Matcher::_regEncode[src_first] < 8) {
  1494               emit_opcode(*cbuf, Assembler::REX_R);
  1495             } else {
  1496               emit_opcode(*cbuf, Assembler::REX_RB);
  1499           emit_opcode(*cbuf, 0x0F);
  1500           emit_opcode(*cbuf, 0x6E);
  1501           emit_rm(*cbuf, 0x3,
  1502                   Matcher::_regEncode[dst_first] & 7,
  1503                   Matcher::_regEncode[src_first] & 7);
  1504 #ifndef PRODUCT
  1505         } else if (!do_size) {
  1506           st->print("movdl   %s, %s\t# spill",
  1507                      Matcher::regName[dst_first],
  1508                      Matcher::regName[src_first]);
  1509 #endif
  1511         return
  1512           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
  1513           ? 4
  1514           : 5; // REX
  1517   } else if (src_first_rc == rc_float) {
  1518     // xmm ->
  1519     if (dst_first_rc == rc_stack) {
  1520       // xmm -> mem
  1521       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1522           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1523         // 64-bit
  1524         int offset = ra_->reg2offset(dst_first);
  1525         if (cbuf) {
  1526           emit_opcode(*cbuf, 0xF2);
  1527           if (Matcher::_regEncode[src_first] >= 8) {
  1528               emit_opcode(*cbuf, Assembler::REX_R);
  1530           emit_opcode(*cbuf, 0x0F);
  1531           emit_opcode(*cbuf, 0x11);
  1532           encode_RegMem(*cbuf,
  1533                         Matcher::_regEncode[src_first],
  1534                         RSP_enc, 0x4, 0, offset,
  1535                         false);
  1536 #ifndef PRODUCT
  1537         } else if (!do_size) {
  1538           st->print("movsd   [rsp + #%d], %s\t# spill",
  1539                      offset,
  1540                      Matcher::regName[src_first]);
  1541 #endif
  1543         return
  1544           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1545           ((Matcher::_regEncode[src_first] < 8)
  1546            ? 5
  1547            : 6); // REX
  1548       } else {
  1549         // 32-bit
  1550         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1551         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1552         int offset = ra_->reg2offset(dst_first);
  1553         if (cbuf) {
  1554           emit_opcode(*cbuf, 0xF3);
  1555           if (Matcher::_regEncode[src_first] >= 8) {
  1556               emit_opcode(*cbuf, Assembler::REX_R);
  1558           emit_opcode(*cbuf, 0x0F);
  1559           emit_opcode(*cbuf, 0x11);
  1560           encode_RegMem(*cbuf,
  1561                         Matcher::_regEncode[src_first],
  1562                         RSP_enc, 0x4, 0, offset,
  1563                         false);
  1564 #ifndef PRODUCT
  1565         } else if (!do_size) {
  1566           st->print("movss   [rsp + #%d], %s\t# spill",
  1567                      offset,
  1568                      Matcher::regName[src_first]);
  1569 #endif
  1571         return
  1572           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
  1573           ((Matcher::_regEncode[src_first] < 8)
  1574            ? 5
  1575            : 6); // REX
  1577     } else if (dst_first_rc == rc_int) {
  1578       // xmm -> gpr
  1579       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1580           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1581         // 64-bit
  1582         if (cbuf) {
  1583           emit_opcode(*cbuf, 0x66);
  1584           if (Matcher::_regEncode[dst_first] < 8) {
  1585             if (Matcher::_regEncode[src_first] < 8) {
  1586               emit_opcode(*cbuf, Assembler::REX_W);
  1587             } else {
  1588               emit_opcode(*cbuf, Assembler::REX_WR); // attention!
  1590           } else {
  1591             if (Matcher::_regEncode[src_first] < 8) {
  1592               emit_opcode(*cbuf, Assembler::REX_WB); // attention!
  1593             } else {
  1594               emit_opcode(*cbuf, Assembler::REX_WRB);
  1597           emit_opcode(*cbuf, 0x0F);
  1598           emit_opcode(*cbuf, 0x7E);
  1599           emit_rm(*cbuf, 0x3,
  1600                   Matcher::_regEncode[dst_first] & 7,
  1601                   Matcher::_regEncode[src_first] & 7);
  1602 #ifndef PRODUCT
  1603         } else if (!do_size) {
  1604           st->print("movdq   %s, %s\t# spill",
  1605                      Matcher::regName[dst_first],
  1606                      Matcher::regName[src_first]);
  1607 #endif
  1609         return 5; // REX
  1610       } else {
  1611         // 32-bit
  1612         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1613         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1614         if (cbuf) {
  1615           emit_opcode(*cbuf, 0x66);
  1616           if (Matcher::_regEncode[dst_first] < 8) {
  1617             if (Matcher::_regEncode[src_first] >= 8) {
  1618               emit_opcode(*cbuf, Assembler::REX_R); // attention!
  1620           } else {
  1621             if (Matcher::_regEncode[src_first] < 8) {
  1622               emit_opcode(*cbuf, Assembler::REX_B); // attention!
  1623             } else {
  1624               emit_opcode(*cbuf, Assembler::REX_RB);
  1627           emit_opcode(*cbuf, 0x0F);
  1628           emit_opcode(*cbuf, 0x7E);
  1629           emit_rm(*cbuf, 0x3,
  1630                   Matcher::_regEncode[dst_first] & 7,
  1631                   Matcher::_regEncode[src_first] & 7);
  1632 #ifndef PRODUCT
  1633         } else if (!do_size) {
  1634           st->print("movdl   %s, %s\t# spill",
  1635                      Matcher::regName[dst_first],
  1636                      Matcher::regName[src_first]);
  1637 #endif
  1639         return
  1640           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
  1641           ? 4
  1642           : 5; // REX
  1644     } else if (dst_first_rc == rc_float) {
  1645       // xmm -> xmm
  1646       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
  1647           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
  1648         // 64-bit
  1649         if (cbuf) {
  1650           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x66 : 0xF2);
  1651           if (Matcher::_regEncode[dst_first] < 8) {
  1652             if (Matcher::_regEncode[src_first] >= 8) {
  1653               emit_opcode(*cbuf, Assembler::REX_B);
  1655           } else {
  1656             if (Matcher::_regEncode[src_first] < 8) {
  1657               emit_opcode(*cbuf, Assembler::REX_R);
  1658             } else {
  1659               emit_opcode(*cbuf, Assembler::REX_RB);
  1662           emit_opcode(*cbuf, 0x0F);
  1663           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
  1664           emit_rm(*cbuf, 0x3,
  1665                   Matcher::_regEncode[dst_first] & 7,
  1666                   Matcher::_regEncode[src_first] & 7);
  1667 #ifndef PRODUCT
  1668         } else if (!do_size) {
  1669           st->print("%s  %s, %s\t# spill",
  1670                      UseXmmRegToRegMoveAll ? "movapd" : "movsd ",
  1671                      Matcher::regName[dst_first],
  1672                      Matcher::regName[src_first]);
  1673 #endif
  1675         return
  1676           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
  1677           ? 4
  1678           : 5; // REX
  1679       } else {
  1680         // 32-bit
  1681         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
  1682         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
  1683         if (cbuf) {
  1684           if (!UseXmmRegToRegMoveAll)
  1685             emit_opcode(*cbuf, 0xF3);
  1686           if (Matcher::_regEncode[dst_first] < 8) {
  1687             if (Matcher::_regEncode[src_first] >= 8) {
  1688               emit_opcode(*cbuf, Assembler::REX_B);
  1690           } else {
  1691             if (Matcher::_regEncode[src_first] < 8) {
  1692               emit_opcode(*cbuf, Assembler::REX_R);
  1693             } else {
  1694               emit_opcode(*cbuf, Assembler::REX_RB);
  1697           emit_opcode(*cbuf, 0x0F);
  1698           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
  1699           emit_rm(*cbuf, 0x3,
  1700                   Matcher::_regEncode[dst_first] & 7,
  1701                   Matcher::_regEncode[src_first] & 7);
  1702 #ifndef PRODUCT
  1703         } else if (!do_size) {
  1704           st->print("%s  %s, %s\t# spill",
  1705                      UseXmmRegToRegMoveAll ? "movaps" : "movss ",
  1706                      Matcher::regName[dst_first],
  1707                      Matcher::regName[src_first]);
  1708 #endif
  1710         return
  1711           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
  1712           ? (UseXmmRegToRegMoveAll ? 3 : 4)
  1713           : (UseXmmRegToRegMoveAll ? 4 : 5); // REX
  1718   assert(0," foo ");
  1719   Unimplemented();
  1721   return 0;
  1724 #ifndef PRODUCT
  1725 void MachSpillCopyNode::format(PhaseRegAlloc *ra_, outputStream* st) const
  1727   implementation(NULL, ra_, false, st);
  1729 #endif
  1731 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const
  1733   implementation(&cbuf, ra_, false, NULL);
  1736 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const
  1738   return implementation(NULL, ra_, true, NULL);
  1741 //=============================================================================
  1742 #ifndef PRODUCT
  1743 void MachNopNode::format(PhaseRegAlloc*, outputStream* st) const
  1745   st->print("nop \t# %d bytes pad for loops and calls", _count);
  1747 #endif
  1749 void MachNopNode::emit(CodeBuffer &cbuf, PhaseRegAlloc*) const
  1751   MacroAssembler _masm(&cbuf);
  1752   __ nop(_count);
  1755 uint MachNopNode::size(PhaseRegAlloc*) const
  1757   return _count;
  1761 //=============================================================================
  1762 #ifndef PRODUCT
  1763 void BoxLockNode::format(PhaseRegAlloc* ra_, outputStream* st) const
  1765   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1766   int reg = ra_->get_reg_first(this);
  1767   st->print("leaq    %s, [rsp + #%d]\t# box lock",
  1768             Matcher::regName[reg], offset);
  1770 #endif
  1772 void BoxLockNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
  1774   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1775   int reg = ra_->get_encode(this);
  1776   if (offset >= 0x80) {
  1777     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
  1778     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
  1779     emit_rm(cbuf, 0x2, reg & 7, 0x04);
  1780     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
  1781     emit_d32(cbuf, offset);
  1782   } else {
  1783     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
  1784     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
  1785     emit_rm(cbuf, 0x1, reg & 7, 0x04);
  1786     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
  1787     emit_d8(cbuf, offset);
  1791 uint BoxLockNode::size(PhaseRegAlloc *ra_) const
  1793   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
  1794   return (offset < 0x80) ? 5 : 8; // REX
  1797 //=============================================================================
  1799 // emit call stub, compiled java to interpreter
  1800 void emit_java_to_interp(CodeBuffer& cbuf)
  1802   // Stub is fixed up when the corresponding call is converted from
  1803   // calling compiled code to calling interpreted code.
  1804   // movq rbx, 0
  1805   // jmp -5 # to self
  1807   address mark = cbuf.inst_mark();  // get mark within main instrs section
  1809   // Note that the code buffer's inst_mark is always relative to insts.
  1810   // That's why we must use the macroassembler to generate a stub.
  1811   MacroAssembler _masm(&cbuf);
  1813   address base =
  1814   __ start_a_stub(Compile::MAX_stubs_size);
  1815   if (base == NULL)  return;  // CodeBuffer::expand failed
  1816   // static stub relocation stores the instruction address of the call
  1817   __ relocate(static_stub_Relocation::spec(mark), RELOC_IMM64);
  1818   // static stub relocation also tags the methodOop in the code-stream.
  1819   __ movoop(rbx, (jobject) NULL);  // method is zapped till fixup time
  1820   __ jump(RuntimeAddress(__ pc()));
  1822   // Update current stubs pointer and restore code_end.
  1823   __ end_a_stub();
  1826 // size of call stub, compiled java to interpretor
  1827 uint size_java_to_interp()
  1829   return 15;  // movq (1+1+8); jmp (1+4)
  1832 // relocation entries for call stub, compiled java to interpretor
  1833 uint reloc_java_to_interp()
  1835   return 4; // 3 in emit_java_to_interp + 1 in Java_Static_Call
  1838 //=============================================================================
  1839 #ifndef PRODUCT
  1840 void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
  1842   if (UseCompressedOops) {
  1843     st->print_cr("movl    rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes() #%d]\t", oopDesc::klass_offset_in_bytes());
  1844     st->print_cr("leaq    rscratch1, [r12_heapbase, r, Address::times_8, 0]");
  1845     st->print_cr("cmpq    rax, rscratch1\t # Inline cache check");
  1846   } else {
  1847     st->print_cr("cmpq    rax, [j_rarg0 + oopDesc::klass_offset_in_bytes() #%d]\t"
  1848                  "# Inline cache check", oopDesc::klass_offset_in_bytes());
  1850   st->print_cr("\tjne     SharedRuntime::_ic_miss_stub");
  1851   st->print_cr("\tnop");
  1852   if (!OptoBreakpoint) {
  1853     st->print_cr("\tnop");
  1856 #endif
  1858 void MachUEPNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
  1860   MacroAssembler masm(&cbuf);
  1861 #ifdef ASSERT
  1862   uint code_size = cbuf.code_size();
  1863 #endif
  1864   if (UseCompressedOops) {
  1865     masm.load_klass(rscratch1, j_rarg0);
  1866     masm.cmpq(rax, rscratch1);
  1867   } else {
  1868     masm.cmpq(rax, Address(j_rarg0, oopDesc::klass_offset_in_bytes()));
  1871   masm.jump_cc(Assembler::notEqual, RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
  1873   /* WARNING these NOPs are critical so that verified entry point is properly
  1874      aligned for patching by NativeJump::patch_verified_entry() */
  1875   int nops_cnt = 1;
  1876   if (!OptoBreakpoint) {
  1877     // Leave space for int3
  1878      nops_cnt += 1;
  1880   if (UseCompressedOops) {
  1881     // ??? divisible by 4 is aligned?
  1882     nops_cnt += 1;
  1884   masm.nop(nops_cnt);
  1886   assert(cbuf.code_size() - code_size == size(ra_),
  1887          "checking code size of inline cache node");
  1890 uint MachUEPNode::size(PhaseRegAlloc* ra_) const
  1892   if (UseCompressedOops) {
  1893     return OptoBreakpoint ? 19 : 20;
  1894   } else {
  1895     return OptoBreakpoint ? 11 : 12;
  1900 //=============================================================================
  1901 uint size_exception_handler()
  1903   // NativeCall instruction size is the same as NativeJump.
  1904   // Note that this value is also credited (in output.cpp) to
  1905   // the size of the code section.
  1906   return NativeJump::instruction_size;
  1909 // Emit exception handler code.
  1910 int emit_exception_handler(CodeBuffer& cbuf)
  1913   // Note that the code buffer's inst_mark is always relative to insts.
  1914   // That's why we must use the macroassembler to generate a handler.
  1915   MacroAssembler _masm(&cbuf);
  1916   address base =
  1917   __ start_a_stub(size_exception_handler());
  1918   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1919   int offset = __ offset();
  1920   __ jump(RuntimeAddress(OptoRuntime::exception_blob()->instructions_begin()));
  1921   assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
  1922   __ end_a_stub();
  1923   return offset;
  1926 uint size_deopt_handler()
  1928   // three 5 byte instructions
  1929   return 15;
  1932 // Emit deopt handler code.
  1933 int emit_deopt_handler(CodeBuffer& cbuf)
  1936   // Note that the code buffer's inst_mark is always relative to insts.
  1937   // That's why we must use the macroassembler to generate a handler.
  1938   MacroAssembler _masm(&cbuf);
  1939   address base =
  1940   __ start_a_stub(size_deopt_handler());
  1941   if (base == NULL)  return 0;  // CodeBuffer::expand failed
  1942   int offset = __ offset();
  1943   address the_pc = (address) __ pc();
  1944   Label next;
  1945   // push a "the_pc" on the stack without destroying any registers
  1946   // as they all may be live.
  1948   // push address of "next"
  1949   __ call(next, relocInfo::none); // reloc none is fine since it is a disp32
  1950   __ bind(next);
  1951   // adjust it so it matches "the_pc"
  1952   __ subq(Address(rsp, 0), __ offset() - offset);
  1953   __ jump(RuntimeAddress(SharedRuntime::deopt_blob()->unpack()));
  1954   assert(__ offset() - offset <= (int) size_deopt_handler(), "overflow");
  1955   __ end_a_stub();
  1956   return offset;
  1959 static void emit_double_constant(CodeBuffer& cbuf, double x) {
  1960   int mark = cbuf.insts()->mark_off();
  1961   MacroAssembler _masm(&cbuf);
  1962   address double_address = __ double_constant(x);
  1963   cbuf.insts()->set_mark_off(mark);  // preserve mark across masm shift
  1964   emit_d32_reloc(cbuf,
  1965                  (int) (double_address - cbuf.code_end() - 4),
  1966                  internal_word_Relocation::spec(double_address),
  1967                  RELOC_DISP32);
  1970 static void emit_float_constant(CodeBuffer& cbuf, float x) {
  1971   int mark = cbuf.insts()->mark_off();
  1972   MacroAssembler _masm(&cbuf);
  1973   address float_address = __ float_constant(x);
  1974   cbuf.insts()->set_mark_off(mark);  // preserve mark across masm shift
  1975   emit_d32_reloc(cbuf,
  1976                  (int) (float_address - cbuf.code_end() - 4),
  1977                  internal_word_Relocation::spec(float_address),
  1978                  RELOC_DISP32);
  1982 int Matcher::regnum_to_fpu_offset(int regnum)
  1984   return regnum - 32; // The FP registers are in the second chunk
  1987 // This is UltraSparc specific, true just means we have fast l2f conversion
  1988 const bool Matcher::convL2FSupported(void) {
  1989   return true;
  1992 // Vector width in bytes
  1993 const uint Matcher::vector_width_in_bytes(void) {
  1994   return 8;
  1997 // Vector ideal reg
  1998 const uint Matcher::vector_ideal_reg(void) {
  1999   return Op_RegD;
  2002 // Is this branch offset short enough that a short branch can be used?
  2003 //
  2004 // NOTE: If the platform does not provide any short branch variants, then
  2005 //       this method should return false for offset 0.
  2006 bool Matcher::is_short_branch_offset(int offset)
  2008   return -0x80 <= offset && offset < 0x80;
  2011 const bool Matcher::isSimpleConstant64(jlong value) {
  2012   // Will one (StoreL ConL) be cheaper than two (StoreI ConI)?.
  2013   //return value == (int) value;  // Cf. storeImmL and immL32.
  2015   // Probably always true, even if a temp register is required.
  2016   return true;
  2019 // The ecx parameter to rep stosq for the ClearArray node is in words.
  2020 const bool Matcher::init_array_count_is_in_bytes = false;
  2022 // Threshold size for cleararray.
  2023 const int Matcher::init_array_short_size = 8 * BytesPerLong;
  2025 // Should the Matcher clone shifts on addressing modes, expecting them
  2026 // to be subsumed into complex addressing expressions or compute them
  2027 // into registers?  True for Intel but false for most RISCs
  2028 const bool Matcher::clone_shift_expressions = true;
  2030 // Is it better to copy float constants, or load them directly from
  2031 // memory?  Intel can load a float constant from a direct address,
  2032 // requiring no extra registers.  Most RISCs will have to materialize
  2033 // an address into a register first, so they would do better to copy
  2034 // the constant from stack.
  2035 const bool Matcher::rematerialize_float_constants = true; // XXX
  2037 // If CPU can load and store mis-aligned doubles directly then no
  2038 // fixup is needed.  Else we split the double into 2 integer pieces
  2039 // and move it piece-by-piece.  Only happens when passing doubles into
  2040 // C code as the Java calling convention forces doubles to be aligned.
  2041 const bool Matcher::misaligned_doubles_ok = true;
  2043 // No-op on amd64
  2044 void Matcher::pd_implicit_null_fixup(MachNode *node, uint idx) {}
  2046 // Advertise here if the CPU requires explicit rounding operations to
  2047 // implement the UseStrictFP mode.
  2048 const bool Matcher::strict_fp_requires_explicit_rounding = true;
  2050 // Do floats take an entire double register or just half?
  2051 const bool Matcher::float_in_double = true;
  2052 // Do ints take an entire long register or just half?
  2053 const bool Matcher::int_in_long = true;
  2055 // Return whether or not this register is ever used as an argument.
  2056 // This function is used on startup to build the trampoline stubs in
  2057 // generateOptoStub.  Registers not mentioned will be killed by the VM
  2058 // call in the trampoline, and arguments in those registers not be
  2059 // available to the callee.
  2060 bool Matcher::can_be_java_arg(int reg)
  2062   return
  2063     reg ==  RDI_num || reg ==  RDI_H_num ||
  2064     reg ==  RSI_num || reg ==  RSI_H_num ||
  2065     reg ==  RDX_num || reg ==  RDX_H_num ||
  2066     reg ==  RCX_num || reg ==  RCX_H_num ||
  2067     reg ==   R8_num || reg ==   R8_H_num ||
  2068     reg ==   R9_num || reg ==   R9_H_num ||
  2069     reg ==  R12_num || reg ==  R12_H_num ||
  2070     reg == XMM0_num || reg == XMM0_H_num ||
  2071     reg == XMM1_num || reg == XMM1_H_num ||
  2072     reg == XMM2_num || reg == XMM2_H_num ||
  2073     reg == XMM3_num || reg == XMM3_H_num ||
  2074     reg == XMM4_num || reg == XMM4_H_num ||
  2075     reg == XMM5_num || reg == XMM5_H_num ||
  2076     reg == XMM6_num || reg == XMM6_H_num ||
  2077     reg == XMM7_num || reg == XMM7_H_num;
  2080 bool Matcher::is_spillable_arg(int reg)
  2082   return can_be_java_arg(reg);
  2085 // Register for DIVI projection of divmodI
  2086 RegMask Matcher::divI_proj_mask() {
  2087   return INT_RAX_REG_mask;
  2090 // Register for MODI projection of divmodI
  2091 RegMask Matcher::modI_proj_mask() {
  2092   return INT_RDX_REG_mask;
  2095 // Register for DIVL projection of divmodL
  2096 RegMask Matcher::divL_proj_mask() {
  2097   return LONG_RAX_REG_mask;
  2100 // Register for MODL projection of divmodL
  2101 RegMask Matcher::modL_proj_mask() {
  2102   return LONG_RDX_REG_mask;
  2105 static Address build_address(int b, int i, int s, int d) {
  2106   Register index = as_Register(i);
  2107   Address::ScaleFactor scale = (Address::ScaleFactor)s;
  2108   if (index == rsp) {
  2109     index = noreg;
  2110     scale = Address::no_scale;
  2112   Address addr(as_Register(b), index, scale, d);
  2113   return addr;
  2116 %}
  2118 //----------ENCODING BLOCK-----------------------------------------------------
  2119 // This block specifies the encoding classes used by the compiler to
  2120 // output byte streams.  Encoding classes are parameterized macros
  2121 // used by Machine Instruction Nodes in order to generate the bit
  2122 // encoding of the instruction.  Operands specify their base encoding
  2123 // interface with the interface keyword.  There are currently
  2124 // supported four interfaces, REG_INTER, CONST_INTER, MEMORY_INTER, &
  2125 // COND_INTER.  REG_INTER causes an operand to generate a function
  2126 // which returns its register number when queried.  CONST_INTER causes
  2127 // an operand to generate a function which returns the value of the
  2128 // constant when queried.  MEMORY_INTER causes an operand to generate
  2129 // four functions which return the Base Register, the Index Register,
  2130 // the Scale Value, and the Offset Value of the operand when queried.
  2131 // COND_INTER causes an operand to generate six functions which return
  2132 // the encoding code (ie - encoding bits for the instruction)
  2133 // associated with each basic boolean condition for a conditional
  2134 // instruction.
  2135 //
  2136 // Instructions specify two basic values for encoding.  Again, a
  2137 // function is available to check if the constant displacement is an
  2138 // oop. They use the ins_encode keyword to specify their encoding
  2139 // classes (which must be a sequence of enc_class names, and their
  2140 // parameters, specified in the encoding block), and they use the
  2141 // opcode keyword to specify, in order, their primary, secondary, and
  2142 // tertiary opcode.  Only the opcode sections which a particular
  2143 // instruction needs for encoding need to be specified.
  2144 encode %{
  2145   // Build emit functions for each basic byte or larger field in the
  2146   // intel encoding scheme (opcode, rm, sib, immediate), and call them
  2147   // from C++ code in the enc_class source block.  Emit functions will
  2148   // live in the main source block for now.  In future, we can
  2149   // generalize this by adding a syntax that specifies the sizes of
  2150   // fields in an order, so that the adlc can build the emit functions
  2151   // automagically
  2153   // Emit primary opcode
  2154   enc_class OpcP
  2155   %{
  2156     emit_opcode(cbuf, $primary);
  2157   %}
  2159   // Emit secondary opcode
  2160   enc_class OpcS
  2161   %{
  2162     emit_opcode(cbuf, $secondary);
  2163   %}
  2165   // Emit tertiary opcode
  2166   enc_class OpcT
  2167   %{
  2168     emit_opcode(cbuf, $tertiary);
  2169   %}
  2171   // Emit opcode directly
  2172   enc_class Opcode(immI d8)
  2173   %{
  2174     emit_opcode(cbuf, $d8$$constant);
  2175   %}
  2177   // Emit size prefix
  2178   enc_class SizePrefix
  2179   %{
  2180     emit_opcode(cbuf, 0x66);
  2181   %}
  2183   enc_class reg(rRegI reg)
  2184   %{
  2185     emit_rm(cbuf, 0x3, 0, $reg$$reg & 7);
  2186   %}
  2188   enc_class reg_reg(rRegI dst, rRegI src)
  2189   %{
  2190     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
  2191   %}
  2193   enc_class opc_reg_reg(immI opcode, rRegI dst, rRegI src)
  2194   %{
  2195     emit_opcode(cbuf, $opcode$$constant);
  2196     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
  2197   %}
  2199   enc_class cmpfp_fixup()
  2200   %{
  2201     // jnp,s exit
  2202     emit_opcode(cbuf, 0x7B);
  2203     emit_d8(cbuf, 0x0A);
  2205     // pushfq
  2206     emit_opcode(cbuf, 0x9C);
  2208     // andq $0xffffff2b, (%rsp)
  2209     emit_opcode(cbuf, Assembler::REX_W);
  2210     emit_opcode(cbuf, 0x81);
  2211     emit_opcode(cbuf, 0x24);
  2212     emit_opcode(cbuf, 0x24);
  2213     emit_d32(cbuf, 0xffffff2b);
  2215     // popfq
  2216     emit_opcode(cbuf, 0x9D);
  2218     // nop (target for branch to avoid branch to branch)
  2219     emit_opcode(cbuf, 0x90);
  2220   %}
  2222   enc_class cmpfp3(rRegI dst)
  2223   %{
  2224     int dstenc = $dst$$reg;
  2226     // movl $dst, -1
  2227     if (dstenc >= 8) {
  2228       emit_opcode(cbuf, Assembler::REX_B);
  2230     emit_opcode(cbuf, 0xB8 | (dstenc & 7));
  2231     emit_d32(cbuf, -1);
  2233     // jp,s done
  2234     emit_opcode(cbuf, 0x7A);
  2235     emit_d8(cbuf, dstenc < 4 ? 0x08 : 0x0A);
  2237     // jb,s done
  2238     emit_opcode(cbuf, 0x72);
  2239     emit_d8(cbuf, dstenc < 4 ? 0x06 : 0x08);
  2241     // setne $dst
  2242     if (dstenc >= 4) {
  2243       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_B);
  2245     emit_opcode(cbuf, 0x0F);
  2246     emit_opcode(cbuf, 0x95);
  2247     emit_opcode(cbuf, 0xC0 | (dstenc & 7));
  2249     // movzbl $dst, $dst
  2250     if (dstenc >= 4) {
  2251       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_RB);
  2253     emit_opcode(cbuf, 0x0F);
  2254     emit_opcode(cbuf, 0xB6);
  2255     emit_rm(cbuf, 0x3, dstenc & 7, dstenc & 7);
  2256   %}
  2258   enc_class cdql_enc(no_rax_rdx_RegI div)
  2259   %{
  2260     // Full implementation of Java idiv and irem; checks for
  2261     // special case as described in JVM spec., p.243 & p.271.
  2262     //
  2263     //         normal case                           special case
  2264     //
  2265     // input : rax: dividend                         min_int
  2266     //         reg: divisor                          -1
  2267     //
  2268     // output: rax: quotient  (= rax idiv reg)       min_int
  2269     //         rdx: remainder (= rax irem reg)       0
  2270     //
  2271     //  Code sequnce:
  2272     //
  2273     //    0:   3d 00 00 00 80          cmp    $0x80000000,%eax
  2274     //    5:   75 07/08                jne    e <normal>
  2275     //    7:   33 d2                   xor    %edx,%edx
  2276     //  [div >= 8 -> offset + 1]
  2277     //  [REX_B]
  2278     //    9:   83 f9 ff                cmp    $0xffffffffffffffff,$div
  2279     //    c:   74 03/04                je     11 <done>
  2280     // 000000000000000e <normal>:
  2281     //    e:   99                      cltd
  2282     //  [div >= 8 -> offset + 1]
  2283     //  [REX_B]
  2284     //    f:   f7 f9                   idiv   $div
  2285     // 0000000000000011 <done>:
  2287     // cmp    $0x80000000,%eax
  2288     emit_opcode(cbuf, 0x3d);
  2289     emit_d8(cbuf, 0x00);
  2290     emit_d8(cbuf, 0x00);
  2291     emit_d8(cbuf, 0x00);
  2292     emit_d8(cbuf, 0x80);
  2294     // jne    e <normal>
  2295     emit_opcode(cbuf, 0x75);
  2296     emit_d8(cbuf, $div$$reg < 8 ? 0x07 : 0x08);
  2298     // xor    %edx,%edx
  2299     emit_opcode(cbuf, 0x33);
  2300     emit_d8(cbuf, 0xD2);
  2302     // cmp    $0xffffffffffffffff,%ecx
  2303     if ($div$$reg >= 8) {
  2304       emit_opcode(cbuf, Assembler::REX_B);
  2306     emit_opcode(cbuf, 0x83);
  2307     emit_rm(cbuf, 0x3, 0x7, $div$$reg & 7);
  2308     emit_d8(cbuf, 0xFF);
  2310     // je     11 <done>
  2311     emit_opcode(cbuf, 0x74);
  2312     emit_d8(cbuf, $div$$reg < 8 ? 0x03 : 0x04);
  2314     // <normal>
  2315     // cltd
  2316     emit_opcode(cbuf, 0x99);
  2318     // idivl (note: must be emitted by the user of this rule)
  2319     // <done>
  2320   %}
  2322   enc_class cdqq_enc(no_rax_rdx_RegL div)
  2323   %{
  2324     // Full implementation of Java ldiv and lrem; checks for
  2325     // special case as described in JVM spec., p.243 & p.271.
  2326     //
  2327     //         normal case                           special case
  2328     //
  2329     // input : rax: dividend                         min_long
  2330     //         reg: divisor                          -1
  2331     //
  2332     // output: rax: quotient  (= rax idiv reg)       min_long
  2333     //         rdx: remainder (= rax irem reg)       0
  2334     //
  2335     //  Code sequnce:
  2336     //
  2337     //    0:   48 ba 00 00 00 00 00    mov    $0x8000000000000000,%rdx
  2338     //    7:   00 00 80
  2339     //    a:   48 39 d0                cmp    %rdx,%rax
  2340     //    d:   75 08                   jne    17 <normal>
  2341     //    f:   33 d2                   xor    %edx,%edx
  2342     //   11:   48 83 f9 ff             cmp    $0xffffffffffffffff,$div
  2343     //   15:   74 05                   je     1c <done>
  2344     // 0000000000000017 <normal>:
  2345     //   17:   48 99                   cqto
  2346     //   19:   48 f7 f9                idiv   $div
  2347     // 000000000000001c <done>:
  2349     // mov    $0x8000000000000000,%rdx
  2350     emit_opcode(cbuf, Assembler::REX_W);
  2351     emit_opcode(cbuf, 0xBA);
  2352     emit_d8(cbuf, 0x00);
  2353     emit_d8(cbuf, 0x00);
  2354     emit_d8(cbuf, 0x00);
  2355     emit_d8(cbuf, 0x00);
  2356     emit_d8(cbuf, 0x00);
  2357     emit_d8(cbuf, 0x00);
  2358     emit_d8(cbuf, 0x00);
  2359     emit_d8(cbuf, 0x80);
  2361     // cmp    %rdx,%rax
  2362     emit_opcode(cbuf, Assembler::REX_W);
  2363     emit_opcode(cbuf, 0x39);
  2364     emit_d8(cbuf, 0xD0);
  2366     // jne    17 <normal>
  2367     emit_opcode(cbuf, 0x75);
  2368     emit_d8(cbuf, 0x08);
  2370     // xor    %edx,%edx
  2371     emit_opcode(cbuf, 0x33);
  2372     emit_d8(cbuf, 0xD2);
  2374     // cmp    $0xffffffffffffffff,$div
  2375     emit_opcode(cbuf, $div$$reg < 8 ? Assembler::REX_W : Assembler::REX_WB);
  2376     emit_opcode(cbuf, 0x83);
  2377     emit_rm(cbuf, 0x3, 0x7, $div$$reg & 7);
  2378     emit_d8(cbuf, 0xFF);
  2380     // je     1e <done>
  2381     emit_opcode(cbuf, 0x74);
  2382     emit_d8(cbuf, 0x05);
  2384     // <normal>
  2385     // cqto
  2386     emit_opcode(cbuf, Assembler::REX_W);
  2387     emit_opcode(cbuf, 0x99);
  2389     // idivq (note: must be emitted by the user of this rule)
  2390     // <done>
  2391   %}
  2393   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
  2394   enc_class OpcSE(immI imm)
  2395   %{
  2396     // Emit primary opcode and set sign-extend bit
  2397     // Check for 8-bit immediate, and set sign extend bit in opcode
  2398     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
  2399       emit_opcode(cbuf, $primary | 0x02);
  2400     } else {
  2401       // 32-bit immediate
  2402       emit_opcode(cbuf, $primary);
  2404   %}
  2406   enc_class OpcSErm(rRegI dst, immI imm)
  2407   %{
  2408     // OpcSEr/m
  2409     int dstenc = $dst$$reg;
  2410     if (dstenc >= 8) {
  2411       emit_opcode(cbuf, Assembler::REX_B);
  2412       dstenc -= 8;
  2414     // Emit primary opcode and set sign-extend bit
  2415     // Check for 8-bit immediate, and set sign extend bit in opcode
  2416     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
  2417       emit_opcode(cbuf, $primary | 0x02);
  2418     } else {
  2419       // 32-bit immediate
  2420       emit_opcode(cbuf, $primary);
  2422     // Emit r/m byte with secondary opcode, after primary opcode.
  2423     emit_rm(cbuf, 0x3, $secondary, dstenc);
  2424   %}
  2426   enc_class OpcSErm_wide(rRegL dst, immI imm)
  2427   %{
  2428     // OpcSEr/m
  2429     int dstenc = $dst$$reg;
  2430     if (dstenc < 8) {
  2431       emit_opcode(cbuf, Assembler::REX_W);
  2432     } else {
  2433       emit_opcode(cbuf, Assembler::REX_WB);
  2434       dstenc -= 8;
  2436     // Emit primary opcode and set sign-extend bit
  2437     // Check for 8-bit immediate, and set sign extend bit in opcode
  2438     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
  2439       emit_opcode(cbuf, $primary | 0x02);
  2440     } else {
  2441       // 32-bit immediate
  2442       emit_opcode(cbuf, $primary);
  2444     // Emit r/m byte with secondary opcode, after primary opcode.
  2445     emit_rm(cbuf, 0x3, $secondary, dstenc);
  2446   %}
  2448   enc_class Con8or32(immI imm)
  2449   %{
  2450     // Check for 8-bit immediate, and set sign extend bit in opcode
  2451     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
  2452       $$$emit8$imm$$constant;
  2453     } else {
  2454       // 32-bit immediate
  2455       $$$emit32$imm$$constant;
  2457   %}
  2459   enc_class Lbl(label labl)
  2460   %{
  2461     // JMP, CALL
  2462     Label* l = $labl$$label;
  2463     emit_d32(cbuf, l ? (l->loc_pos() - (cbuf.code_size() + 4)) : 0);
  2464   %}
  2466   enc_class LblShort(label labl)
  2467   %{
  2468     // JMP, CALL
  2469     Label* l = $labl$$label;
  2470     int disp = l ? (l->loc_pos() - (cbuf.code_size() + 1)) : 0;
  2471     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
  2472     emit_d8(cbuf, disp);
  2473   %}
  2475   enc_class opc2_reg(rRegI dst)
  2476   %{
  2477     // BSWAP
  2478     emit_cc(cbuf, $secondary, $dst$$reg);
  2479   %}
  2481   enc_class opc3_reg(rRegI dst)
  2482   %{
  2483     // BSWAP
  2484     emit_cc(cbuf, $tertiary, $dst$$reg);
  2485   %}
  2487   enc_class reg_opc(rRegI div)
  2488   %{
  2489     // INC, DEC, IDIV, IMOD, JMP indirect, ...
  2490     emit_rm(cbuf, 0x3, $secondary, $div$$reg & 7);
  2491   %}
  2493   enc_class Jcc(cmpOp cop, label labl)
  2494   %{
  2495     // JCC
  2496     Label* l = $labl$$label;
  2497     $$$emit8$primary;
  2498     emit_cc(cbuf, $secondary, $cop$$cmpcode);
  2499     emit_d32(cbuf, l ? (l->loc_pos() - (cbuf.code_size() + 4)) : 0);
  2500   %}
  2502   enc_class JccShort (cmpOp cop, label labl)
  2503   %{
  2504   // JCC
  2505     Label *l = $labl$$label;
  2506     emit_cc(cbuf, $primary, $cop$$cmpcode);
  2507     int disp = l ? (l->loc_pos() - (cbuf.code_size() + 1)) : 0;
  2508     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
  2509     emit_d8(cbuf, disp);
  2510   %}
  2512   enc_class enc_cmov(cmpOp cop)
  2513   %{
  2514     // CMOV
  2515     $$$emit8$primary;
  2516     emit_cc(cbuf, $secondary, $cop$$cmpcode);
  2517   %}
  2519   enc_class enc_cmovf_branch(cmpOp cop, regF dst, regF src)
  2520   %{
  2521     // Invert sense of branch from sense of cmov
  2522     emit_cc(cbuf, 0x70, $cop$$cmpcode ^ 1);
  2523     emit_d8(cbuf, ($dst$$reg < 8 && $src$$reg < 8)
  2524                   ? (UseXmmRegToRegMoveAll ? 3 : 4)
  2525                   : (UseXmmRegToRegMoveAll ? 4 : 5) ); // REX
  2526     // UseXmmRegToRegMoveAll ? movaps(dst, src) : movss(dst, src)
  2527     if (!UseXmmRegToRegMoveAll) emit_opcode(cbuf, 0xF3);
  2528     if ($dst$$reg < 8) {
  2529       if ($src$$reg >= 8) {
  2530         emit_opcode(cbuf, Assembler::REX_B);
  2532     } else {
  2533       if ($src$$reg < 8) {
  2534         emit_opcode(cbuf, Assembler::REX_R);
  2535       } else {
  2536         emit_opcode(cbuf, Assembler::REX_RB);
  2539     emit_opcode(cbuf, 0x0F);
  2540     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
  2541     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
  2542   %}
  2544   enc_class enc_cmovd_branch(cmpOp cop, regD dst, regD src)
  2545   %{
  2546     // Invert sense of branch from sense of cmov
  2547     emit_cc(cbuf, 0x70, $cop$$cmpcode ^ 1);
  2548     emit_d8(cbuf, $dst$$reg < 8 && $src$$reg < 8 ? 4 : 5); // REX
  2550     //  UseXmmRegToRegMoveAll ? movapd(dst, src) : movsd(dst, src)
  2551     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x66 : 0xF2);
  2552     if ($dst$$reg < 8) {
  2553       if ($src$$reg >= 8) {
  2554         emit_opcode(cbuf, Assembler::REX_B);
  2556     } else {
  2557       if ($src$$reg < 8) {
  2558         emit_opcode(cbuf, Assembler::REX_R);
  2559       } else {
  2560         emit_opcode(cbuf, Assembler::REX_RB);
  2563     emit_opcode(cbuf, 0x0F);
  2564     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
  2565     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
  2566   %}
  2568   enc_class enc_PartialSubtypeCheck()
  2569   %{
  2570     Register Rrdi = as_Register(RDI_enc); // result register
  2571     Register Rrax = as_Register(RAX_enc); // super class
  2572     Register Rrcx = as_Register(RCX_enc); // killed
  2573     Register Rrsi = as_Register(RSI_enc); // sub class
  2574     Label hit, miss, cmiss;
  2576     MacroAssembler _masm(&cbuf);
  2577     // Compare super with sub directly, since super is not in its own SSA.
  2578     // The compiler used to emit this test, but we fold it in here,
  2579     // to allow platform-specific tweaking on sparc.
  2580     __ cmpq(Rrax, Rrsi);
  2581     __ jcc(Assembler::equal, hit);
  2582 #ifndef PRODUCT
  2583     __ lea(Rrcx, ExternalAddress((address)&SharedRuntime::_partial_subtype_ctr));
  2584     __ incrementl(Address(Rrcx, 0));
  2585 #endif //PRODUCT
  2586     __ movq(Rrdi, Address(Rrsi,
  2587                           sizeof(oopDesc) +
  2588                           Klass::secondary_supers_offset_in_bytes()));
  2589     __ movl(Rrcx, Address(Rrdi, arrayOopDesc::length_offset_in_bytes()));
  2590     __ addq(Rrdi, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
  2591     if (UseCompressedOops) {
  2592       __ encode_heap_oop(Rrax);
  2593       __ repne_scanl();
  2594       __ jcc(Assembler::notEqual, cmiss);
  2595       __ decode_heap_oop(Rrax);
  2596       __ movq(Address(Rrsi,
  2597                       sizeof(oopDesc) +
  2598                       Klass::secondary_super_cache_offset_in_bytes()),
  2599               Rrax);
  2600       __ jmp(hit);
  2601       __ bind(cmiss);
  2602       __ decode_heap_oop(Rrax);
  2603       __ jmp(miss);
  2604     } else {
  2605       __ repne_scanq();
  2606       __ jcc(Assembler::notEqual, miss);
  2607       __ movq(Address(Rrsi,
  2608                       sizeof(oopDesc) +
  2609                       Klass::secondary_super_cache_offset_in_bytes()),
  2610               Rrax);
  2612     __ bind(hit);
  2613     if ($primary) {
  2614       __ xorq(Rrdi, Rrdi);
  2616     __ bind(miss);
  2617   %}
  2619   enc_class Java_To_Interpreter(method meth)
  2620   %{
  2621     // CALL Java_To_Interpreter
  2622     // This is the instruction starting address for relocation info.
  2623     cbuf.set_inst_mark();
  2624     $$$emit8$primary;
  2625     // CALL directly to the runtime
  2626     emit_d32_reloc(cbuf,
  2627                    (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
  2628                    runtime_call_Relocation::spec(),
  2629                    RELOC_DISP32);
  2630   %}
  2632   enc_class Java_Static_Call(method meth)
  2633   %{
  2634     // JAVA STATIC CALL
  2635     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to
  2636     // determine who we intended to call.
  2637     cbuf.set_inst_mark();
  2638     $$$emit8$primary;
  2640     if (!_method) {
  2641       emit_d32_reloc(cbuf,
  2642                      (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
  2643                      runtime_call_Relocation::spec(),
  2644                      RELOC_DISP32);
  2645     } else if (_optimized_virtual) {
  2646       emit_d32_reloc(cbuf,
  2647                      (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
  2648                      opt_virtual_call_Relocation::spec(),
  2649                      RELOC_DISP32);
  2650     } else {
  2651       emit_d32_reloc(cbuf,
  2652                      (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
  2653                      static_call_Relocation::spec(),
  2654                      RELOC_DISP32);
  2656     if (_method) {
  2657       // Emit stub for static call
  2658       emit_java_to_interp(cbuf);
  2660   %}
  2662   enc_class Java_Dynamic_Call(method meth)
  2663   %{
  2664     // JAVA DYNAMIC CALL
  2665     // !!!!!
  2666     // Generate  "movq rax, -1", placeholder instruction to load oop-info
  2667     // emit_call_dynamic_prologue( cbuf );
  2668     cbuf.set_inst_mark();
  2670     // movq rax, -1
  2671     emit_opcode(cbuf, Assembler::REX_W);
  2672     emit_opcode(cbuf, 0xB8 | RAX_enc);
  2673     emit_d64_reloc(cbuf,
  2674                    (int64_t) Universe::non_oop_word(),
  2675                    oop_Relocation::spec_for_immediate(), RELOC_IMM64);
  2676     address virtual_call_oop_addr = cbuf.inst_mark();
  2677     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
  2678     // who we intended to call.
  2679     cbuf.set_inst_mark();
  2680     $$$emit8$primary;
  2681     emit_d32_reloc(cbuf,
  2682                    (int) ($meth$$method - ((intptr_t) cbuf.code_end()) - 4),
  2683                    virtual_call_Relocation::spec(virtual_call_oop_addr),
  2684                    RELOC_DISP32);
  2685   %}
  2687   enc_class Java_Compiled_Call(method meth)
  2688   %{
  2689     // JAVA COMPILED CALL
  2690     int disp = in_bytes(methodOopDesc:: from_compiled_offset());
  2692     // XXX XXX offset is 128 is 1.5 NON-PRODUCT !!!
  2693     // assert(-0x80 <= disp && disp < 0x80, "compiled_code_offset isn't small");
  2695     // callq *disp(%rax)
  2696     cbuf.set_inst_mark();
  2697     $$$emit8$primary;
  2698     if (disp < 0x80) {
  2699       emit_rm(cbuf, 0x01, $secondary, RAX_enc); // R/M byte
  2700       emit_d8(cbuf, disp); // Displacement
  2701     } else {
  2702       emit_rm(cbuf, 0x02, $secondary, RAX_enc); // R/M byte
  2703       emit_d32(cbuf, disp); // Displacement
  2705   %}
  2707   enc_class reg_opc_imm(rRegI dst, immI8 shift)
  2708   %{
  2709     // SAL, SAR, SHR
  2710     int dstenc = $dst$$reg;
  2711     if (dstenc >= 8) {
  2712       emit_opcode(cbuf, Assembler::REX_B);
  2713       dstenc -= 8;
  2715     $$$emit8$primary;
  2716     emit_rm(cbuf, 0x3, $secondary, dstenc);
  2717     $$$emit8$shift$$constant;
  2718   %}
  2720   enc_class reg_opc_imm_wide(rRegL dst, immI8 shift)
  2721   %{
  2722     // SAL, SAR, SHR
  2723     int dstenc = $dst$$reg;
  2724     if (dstenc < 8) {
  2725       emit_opcode(cbuf, Assembler::REX_W);
  2726     } else {
  2727       emit_opcode(cbuf, Assembler::REX_WB);
  2728       dstenc -= 8;
  2730     $$$emit8$primary;
  2731     emit_rm(cbuf, 0x3, $secondary, dstenc);
  2732     $$$emit8$shift$$constant;
  2733   %}
  2735   enc_class load_immI(rRegI dst, immI src)
  2736   %{
  2737     int dstenc = $dst$$reg;
  2738     if (dstenc >= 8) {
  2739       emit_opcode(cbuf, Assembler::REX_B);
  2740       dstenc -= 8;
  2742     emit_opcode(cbuf, 0xB8 | dstenc);
  2743     $$$emit32$src$$constant;
  2744   %}
  2746   enc_class load_immL(rRegL dst, immL src)
  2747   %{
  2748     int dstenc = $dst$$reg;
  2749     if (dstenc < 8) {
  2750       emit_opcode(cbuf, Assembler::REX_W);
  2751     } else {
  2752       emit_opcode(cbuf, Assembler::REX_WB);
  2753       dstenc -= 8;
  2755     emit_opcode(cbuf, 0xB8 | dstenc);
  2756     emit_d64(cbuf, $src$$constant);
  2757   %}
  2759   enc_class load_immUL32(rRegL dst, immUL32 src)
  2760   %{
  2761     // same as load_immI, but this time we care about zeroes in the high word
  2762     int dstenc = $dst$$reg;
  2763     if (dstenc >= 8) {
  2764       emit_opcode(cbuf, Assembler::REX_B);
  2765       dstenc -= 8;
  2767     emit_opcode(cbuf, 0xB8 | dstenc);
  2768     $$$emit32$src$$constant;
  2769   %}
  2771   enc_class load_immL32(rRegL dst, immL32 src)
  2772   %{
  2773     int dstenc = $dst$$reg;
  2774     if (dstenc < 8) {
  2775       emit_opcode(cbuf, Assembler::REX_W);
  2776     } else {
  2777       emit_opcode(cbuf, Assembler::REX_WB);
  2778       dstenc -= 8;
  2780     emit_opcode(cbuf, 0xC7);
  2781     emit_rm(cbuf, 0x03, 0x00, dstenc);
  2782     $$$emit32$src$$constant;
  2783   %}
  2785   enc_class load_immP31(rRegP dst, immP32 src)
  2786   %{
  2787     // same as load_immI, but this time we care about zeroes in the high word
  2788     int dstenc = $dst$$reg;
  2789     if (dstenc >= 8) {
  2790       emit_opcode(cbuf, Assembler::REX_B);
  2791       dstenc -= 8;
  2793     emit_opcode(cbuf, 0xB8 | dstenc);
  2794     $$$emit32$src$$constant;
  2795   %}
  2797   enc_class load_immP(rRegP dst, immP src)
  2798   %{
  2799     int dstenc = $dst$$reg;
  2800     if (dstenc < 8) {
  2801       emit_opcode(cbuf, Assembler::REX_W);
  2802     } else {
  2803       emit_opcode(cbuf, Assembler::REX_WB);
  2804       dstenc -= 8;
  2806     emit_opcode(cbuf, 0xB8 | dstenc);
  2807     // This next line should be generated from ADLC
  2808     if ($src->constant_is_oop()) {
  2809       emit_d64_reloc(cbuf, $src$$constant, relocInfo::oop_type, RELOC_IMM64);
  2810     } else {
  2811       emit_d64(cbuf, $src$$constant);
  2813   %}
  2815   enc_class load_immF(regF dst, immF con)
  2816   %{
  2817     // XXX reg_mem doesn't support RIP-relative addressing yet
  2818     emit_rm(cbuf, 0x0, $dst$$reg & 7, 0x5); // 00 reg 101
  2819     emit_float_constant(cbuf, $con$$constant);
  2820   %}
  2822   enc_class load_immD(regD dst, immD con)
  2823   %{
  2824     // XXX reg_mem doesn't support RIP-relative addressing yet
  2825     emit_rm(cbuf, 0x0, $dst$$reg & 7, 0x5); // 00 reg 101
  2826     emit_double_constant(cbuf, $con$$constant);
  2827   %}
  2829   enc_class load_conF (regF dst, immF con) %{    // Load float constant
  2830     emit_opcode(cbuf, 0xF3);
  2831     if ($dst$$reg >= 8) {
  2832       emit_opcode(cbuf, Assembler::REX_R);
  2834     emit_opcode(cbuf, 0x0F);
  2835     emit_opcode(cbuf, 0x10);
  2836     emit_rm(cbuf, 0x0, $dst$$reg & 7, 0x5); // 00 reg 101
  2837     emit_float_constant(cbuf, $con$$constant);
  2838   %}
  2840   enc_class load_conD (regD dst, immD con) %{    // Load double constant
  2841     // UseXmmLoadAndClearUpper ? movsd(dst, con) : movlpd(dst, con)
  2842     emit_opcode(cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  2843     if ($dst$$reg >= 8) {
  2844       emit_opcode(cbuf, Assembler::REX_R);
  2846     emit_opcode(cbuf, 0x0F);
  2847     emit_opcode(cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12);
  2848     emit_rm(cbuf, 0x0, $dst$$reg & 7, 0x5); // 00 reg 101
  2849     emit_double_constant(cbuf, $con$$constant);
  2850   %}
  2852   // Encode a reg-reg copy.  If it is useless, then empty encoding.
  2853   enc_class enc_copy(rRegI dst, rRegI src)
  2854   %{
  2855     encode_copy(cbuf, $dst$$reg, $src$$reg);
  2856   %}
  2858   // Encode xmm reg-reg copy.  If it is useless, then empty encoding.
  2859   enc_class enc_CopyXD( RegD dst, RegD src ) %{
  2860     encode_CopyXD( cbuf, $dst$$reg, $src$$reg );
  2861   %}
  2863   enc_class enc_copy_always(rRegI dst, rRegI src)
  2864   %{
  2865     int srcenc = $src$$reg;
  2866     int dstenc = $dst$$reg;
  2868     if (dstenc < 8) {
  2869       if (srcenc >= 8) {
  2870         emit_opcode(cbuf, Assembler::REX_B);
  2871         srcenc -= 8;
  2873     } else {
  2874       if (srcenc < 8) {
  2875         emit_opcode(cbuf, Assembler::REX_R);
  2876       } else {
  2877         emit_opcode(cbuf, Assembler::REX_RB);
  2878         srcenc -= 8;
  2880       dstenc -= 8;
  2883     emit_opcode(cbuf, 0x8B);
  2884     emit_rm(cbuf, 0x3, dstenc, srcenc);
  2885   %}
  2887   enc_class enc_copy_wide(rRegL dst, rRegL src)
  2888   %{
  2889     int srcenc = $src$$reg;
  2890     int dstenc = $dst$$reg;
  2892     if (dstenc != srcenc) {
  2893       if (dstenc < 8) {
  2894         if (srcenc < 8) {
  2895           emit_opcode(cbuf, Assembler::REX_W);
  2896         } else {
  2897           emit_opcode(cbuf, Assembler::REX_WB);
  2898           srcenc -= 8;
  2900       } else {
  2901         if (srcenc < 8) {
  2902           emit_opcode(cbuf, Assembler::REX_WR);
  2903         } else {
  2904           emit_opcode(cbuf, Assembler::REX_WRB);
  2905           srcenc -= 8;
  2907         dstenc -= 8;
  2909       emit_opcode(cbuf, 0x8B);
  2910       emit_rm(cbuf, 0x3, dstenc, srcenc);
  2912   %}
  2914   enc_class Con32(immI src)
  2915   %{
  2916     // Output immediate
  2917     $$$emit32$src$$constant;
  2918   %}
  2920   enc_class Con64(immL src)
  2921   %{
  2922     // Output immediate
  2923     emit_d64($src$$constant);
  2924   %}
  2926   enc_class Con32F_as_bits(immF src)
  2927   %{
  2928     // Output Float immediate bits
  2929     jfloat jf = $src$$constant;
  2930     jint jf_as_bits = jint_cast(jf);
  2931     emit_d32(cbuf, jf_as_bits);
  2932   %}
  2934   enc_class Con16(immI src)
  2935   %{
  2936     // Output immediate
  2937     $$$emit16$src$$constant;
  2938   %}
  2940   // How is this different from Con32??? XXX
  2941   enc_class Con_d32(immI src)
  2942   %{
  2943     emit_d32(cbuf,$src$$constant);
  2944   %}
  2946   enc_class conmemref (rRegP t1) %{    // Con32(storeImmI)
  2947     // Output immediate memory reference
  2948     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
  2949     emit_d32(cbuf, 0x00);
  2950   %}
  2952   enc_class jump_enc(rRegL switch_val, rRegI dest) %{
  2953     MacroAssembler masm(&cbuf);
  2955     Register switch_reg = as_Register($switch_val$$reg);
  2956     Register dest_reg   = as_Register($dest$$reg);
  2957     address table_base  = masm.address_table_constant(_index2label);
  2959     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
  2960     // to do that and the compiler is using that register as one it can allocate.
  2961     // So we build it all by hand.
  2962     // Address index(noreg, switch_reg, Address::times_1);
  2963     // ArrayAddress dispatch(table, index);
  2965     Address dispatch(dest_reg, switch_reg, Address::times_1);
  2967     masm.lea(dest_reg, InternalAddress(table_base));
  2968     masm.jmp(dispatch);
  2969   %}
  2971   enc_class jump_enc_addr(rRegL switch_val, immI2 shift, immL32 offset, rRegI dest) %{
  2972     MacroAssembler masm(&cbuf);
  2974     Register switch_reg = as_Register($switch_val$$reg);
  2975     Register dest_reg   = as_Register($dest$$reg);
  2976     address table_base  = masm.address_table_constant(_index2label);
  2978     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
  2979     // to do that and the compiler is using that register as one it can allocate.
  2980     // So we build it all by hand.
  2981     // Address index(noreg, switch_reg, (Address::ScaleFactor)$shift$$constant, (int)$offset$$constant);
  2982     // ArrayAddress dispatch(table, index);
  2984     Address dispatch(dest_reg, switch_reg, (Address::ScaleFactor)$shift$$constant, (int)$offset$$constant);
  2986     masm.lea(dest_reg, InternalAddress(table_base));
  2987     masm.jmp(dispatch);
  2988   %}
  2990   enc_class jump_enc_offset(rRegL switch_val, immI2 shift, rRegI dest) %{
  2991     MacroAssembler masm(&cbuf);
  2993     Register switch_reg = as_Register($switch_val$$reg);
  2994     Register dest_reg   = as_Register($dest$$reg);
  2995     address table_base  = masm.address_table_constant(_index2label);
  2997     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
  2998     // to do that and the compiler is using that register as one it can allocate.
  2999     // So we build it all by hand.
  3000     // Address index(noreg, switch_reg, (Address::ScaleFactor)$shift$$constant);
  3001     // ArrayAddress dispatch(table, index);
  3003     Address dispatch(dest_reg, switch_reg, (Address::ScaleFactor)$shift$$constant);
  3004     masm.lea(dest_reg, InternalAddress(table_base));
  3005     masm.jmp(dispatch);
  3007   %}
  3009   enc_class lock_prefix()
  3010   %{
  3011     if (os::is_MP()) {
  3012       emit_opcode(cbuf, 0xF0); // lock
  3014   %}
  3016   enc_class REX_mem(memory mem)
  3017   %{
  3018     if ($mem$$base >= 8) {
  3019       if ($mem$$index < 8) {
  3020         emit_opcode(cbuf, Assembler::REX_B);
  3021       } else {
  3022         emit_opcode(cbuf, Assembler::REX_XB);
  3024     } else {
  3025       if ($mem$$index >= 8) {
  3026         emit_opcode(cbuf, Assembler::REX_X);
  3029   %}
  3031   enc_class REX_mem_wide(memory mem)
  3032   %{
  3033     if ($mem$$base >= 8) {
  3034       if ($mem$$index < 8) {
  3035         emit_opcode(cbuf, Assembler::REX_WB);
  3036       } else {
  3037         emit_opcode(cbuf, Assembler::REX_WXB);
  3039     } else {
  3040       if ($mem$$index < 8) {
  3041         emit_opcode(cbuf, Assembler::REX_W);
  3042       } else {
  3043         emit_opcode(cbuf, Assembler::REX_WX);
  3046   %}
  3048   // for byte regs
  3049   enc_class REX_breg(rRegI reg)
  3050   %{
  3051     if ($reg$$reg >= 4) {
  3052       emit_opcode(cbuf, $reg$$reg < 8 ? Assembler::REX : Assembler::REX_B);
  3054   %}
  3056   // for byte regs
  3057   enc_class REX_reg_breg(rRegI dst, rRegI src)
  3058   %{
  3059     if ($dst$$reg < 8) {
  3060       if ($src$$reg >= 4) {
  3061         emit_opcode(cbuf, $src$$reg < 8 ? Assembler::REX : Assembler::REX_B);
  3063     } else {
  3064       if ($src$$reg < 8) {
  3065         emit_opcode(cbuf, Assembler::REX_R);
  3066       } else {
  3067         emit_opcode(cbuf, Assembler::REX_RB);
  3070   %}
  3072   // for byte regs
  3073   enc_class REX_breg_mem(rRegI reg, memory mem)
  3074   %{
  3075     if ($reg$$reg < 8) {
  3076       if ($mem$$base < 8) {
  3077         if ($mem$$index >= 8) {
  3078           emit_opcode(cbuf, Assembler::REX_X);
  3079         } else if ($reg$$reg >= 4) {
  3080           emit_opcode(cbuf, Assembler::REX);
  3082       } else {
  3083         if ($mem$$index < 8) {
  3084           emit_opcode(cbuf, Assembler::REX_B);
  3085         } else {
  3086           emit_opcode(cbuf, Assembler::REX_XB);
  3089     } else {
  3090       if ($mem$$base < 8) {
  3091         if ($mem$$index < 8) {
  3092           emit_opcode(cbuf, Assembler::REX_R);
  3093         } else {
  3094           emit_opcode(cbuf, Assembler::REX_RX);
  3096       } else {
  3097         if ($mem$$index < 8) {
  3098           emit_opcode(cbuf, Assembler::REX_RB);
  3099         } else {
  3100           emit_opcode(cbuf, Assembler::REX_RXB);
  3104   %}
  3106   enc_class REX_reg(rRegI reg)
  3107   %{
  3108     if ($reg$$reg >= 8) {
  3109       emit_opcode(cbuf, Assembler::REX_B);
  3111   %}
  3113   enc_class REX_reg_wide(rRegI reg)
  3114   %{
  3115     if ($reg$$reg < 8) {
  3116       emit_opcode(cbuf, Assembler::REX_W);
  3117     } else {
  3118       emit_opcode(cbuf, Assembler::REX_WB);
  3120   %}
  3122   enc_class REX_reg_reg(rRegI dst, rRegI src)
  3123   %{
  3124     if ($dst$$reg < 8) {
  3125       if ($src$$reg >= 8) {
  3126         emit_opcode(cbuf, Assembler::REX_B);
  3128     } else {
  3129       if ($src$$reg < 8) {
  3130         emit_opcode(cbuf, Assembler::REX_R);
  3131       } else {
  3132         emit_opcode(cbuf, Assembler::REX_RB);
  3135   %}
  3137   enc_class REX_reg_reg_wide(rRegI dst, rRegI src)
  3138   %{
  3139     if ($dst$$reg < 8) {
  3140       if ($src$$reg < 8) {
  3141         emit_opcode(cbuf, Assembler::REX_W);
  3142       } else {
  3143         emit_opcode(cbuf, Assembler::REX_WB);
  3145     } else {
  3146       if ($src$$reg < 8) {
  3147         emit_opcode(cbuf, Assembler::REX_WR);
  3148       } else {
  3149         emit_opcode(cbuf, Assembler::REX_WRB);
  3152   %}
  3154   enc_class REX_reg_mem(rRegI reg, memory mem)
  3155   %{
  3156     if ($reg$$reg < 8) {
  3157       if ($mem$$base < 8) {
  3158         if ($mem$$index >= 8) {
  3159           emit_opcode(cbuf, Assembler::REX_X);
  3161       } else {
  3162         if ($mem$$index < 8) {
  3163           emit_opcode(cbuf, Assembler::REX_B);
  3164         } else {
  3165           emit_opcode(cbuf, Assembler::REX_XB);
  3168     } else {
  3169       if ($mem$$base < 8) {
  3170         if ($mem$$index < 8) {
  3171           emit_opcode(cbuf, Assembler::REX_R);
  3172         } else {
  3173           emit_opcode(cbuf, Assembler::REX_RX);
  3175       } else {
  3176         if ($mem$$index < 8) {
  3177           emit_opcode(cbuf, Assembler::REX_RB);
  3178         } else {
  3179           emit_opcode(cbuf, Assembler::REX_RXB);
  3183   %}
  3185   enc_class REX_reg_mem_wide(rRegL reg, memory mem)
  3186   %{
  3187     if ($reg$$reg < 8) {
  3188       if ($mem$$base < 8) {
  3189         if ($mem$$index < 8) {
  3190           emit_opcode(cbuf, Assembler::REX_W);
  3191         } else {
  3192           emit_opcode(cbuf, Assembler::REX_WX);
  3194       } else {
  3195         if ($mem$$index < 8) {
  3196           emit_opcode(cbuf, Assembler::REX_WB);
  3197         } else {
  3198           emit_opcode(cbuf, Assembler::REX_WXB);
  3201     } else {
  3202       if ($mem$$base < 8) {
  3203         if ($mem$$index < 8) {
  3204           emit_opcode(cbuf, Assembler::REX_WR);
  3205         } else {
  3206           emit_opcode(cbuf, Assembler::REX_WRX);
  3208       } else {
  3209         if ($mem$$index < 8) {
  3210           emit_opcode(cbuf, Assembler::REX_WRB);
  3211         } else {
  3212           emit_opcode(cbuf, Assembler::REX_WRXB);
  3216   %}
  3218   enc_class reg_mem(rRegI ereg, memory mem)
  3219   %{
  3220     // High registers handle in encode_RegMem
  3221     int reg = $ereg$$reg;
  3222     int base = $mem$$base;
  3223     int index = $mem$$index;
  3224     int scale = $mem$$scale;
  3225     int disp = $mem$$disp;
  3226     bool disp_is_oop = $mem->disp_is_oop();
  3228     encode_RegMem(cbuf, reg, base, index, scale, disp, disp_is_oop);
  3229   %}
  3231   enc_class RM_opc_mem(immI rm_opcode, memory mem)
  3232   %{
  3233     int rm_byte_opcode = $rm_opcode$$constant;
  3235     // High registers handle in encode_RegMem
  3236     int base = $mem$$base;
  3237     int index = $mem$$index;
  3238     int scale = $mem$$scale;
  3239     int displace = $mem$$disp;
  3241     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when
  3242                                             // working with static
  3243                                             // globals
  3244     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace,
  3245                   disp_is_oop);
  3246   %}
  3248   enc_class reg_lea(rRegI dst, rRegI src0, immI src1)
  3249   %{
  3250     int reg_encoding = $dst$$reg;
  3251     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
  3252     int index        = 0x04;            // 0x04 indicates no index
  3253     int scale        = 0x00;            // 0x00 indicates no scale
  3254     int displace     = $src1$$constant; // 0x00 indicates no displacement
  3255     bool disp_is_oop = false;
  3256     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace,
  3257                   disp_is_oop);
  3258   %}
  3260   enc_class neg_reg(rRegI dst)
  3261   %{
  3262     int dstenc = $dst$$reg;
  3263     if (dstenc >= 8) {
  3264       emit_opcode(cbuf, Assembler::REX_B);
  3265       dstenc -= 8;
  3267     // NEG $dst
  3268     emit_opcode(cbuf, 0xF7);
  3269     emit_rm(cbuf, 0x3, 0x03, dstenc);
  3270   %}
  3272   enc_class neg_reg_wide(rRegI dst)
  3273   %{
  3274     int dstenc = $dst$$reg;
  3275     if (dstenc < 8) {
  3276       emit_opcode(cbuf, Assembler::REX_W);
  3277     } else {
  3278       emit_opcode(cbuf, Assembler::REX_WB);
  3279       dstenc -= 8;
  3281     // NEG $dst
  3282     emit_opcode(cbuf, 0xF7);
  3283     emit_rm(cbuf, 0x3, 0x03, dstenc);
  3284   %}
  3286   enc_class setLT_reg(rRegI dst)
  3287   %{
  3288     int dstenc = $dst$$reg;
  3289     if (dstenc >= 8) {
  3290       emit_opcode(cbuf, Assembler::REX_B);
  3291       dstenc -= 8;
  3292     } else if (dstenc >= 4) {
  3293       emit_opcode(cbuf, Assembler::REX);
  3295     // SETLT $dst
  3296     emit_opcode(cbuf, 0x0F);
  3297     emit_opcode(cbuf, 0x9C);
  3298     emit_rm(cbuf, 0x3, 0x0, dstenc);
  3299   %}
  3301   enc_class setNZ_reg(rRegI dst)
  3302   %{
  3303     int dstenc = $dst$$reg;
  3304     if (dstenc >= 8) {
  3305       emit_opcode(cbuf, Assembler::REX_B);
  3306       dstenc -= 8;
  3307     } else if (dstenc >= 4) {
  3308       emit_opcode(cbuf, Assembler::REX);
  3310     // SETNZ $dst
  3311     emit_opcode(cbuf, 0x0F);
  3312     emit_opcode(cbuf, 0x95);
  3313     emit_rm(cbuf, 0x3, 0x0, dstenc);
  3314   %}
  3316   enc_class enc_cmpLTP(no_rcx_RegI p, no_rcx_RegI q, no_rcx_RegI y,
  3317                        rcx_RegI tmp)
  3318   %{
  3319     // cadd_cmpLT
  3321     int tmpReg = $tmp$$reg;
  3323     int penc = $p$$reg;
  3324     int qenc = $q$$reg;
  3325     int yenc = $y$$reg;
  3327     // subl $p,$q
  3328     if (penc < 8) {
  3329       if (qenc >= 8) {
  3330         emit_opcode(cbuf, Assembler::REX_B);
  3332     } else {
  3333       if (qenc < 8) {
  3334         emit_opcode(cbuf, Assembler::REX_R);
  3335       } else {
  3336         emit_opcode(cbuf, Assembler::REX_RB);
  3339     emit_opcode(cbuf, 0x2B);
  3340     emit_rm(cbuf, 0x3, penc & 7, qenc & 7);
  3342     // sbbl $tmp, $tmp
  3343     emit_opcode(cbuf, 0x1B);
  3344     emit_rm(cbuf, 0x3, tmpReg, tmpReg);
  3346     // andl $tmp, $y
  3347     if (yenc >= 8) {
  3348       emit_opcode(cbuf, Assembler::REX_B);
  3350     emit_opcode(cbuf, 0x23);
  3351     emit_rm(cbuf, 0x3, tmpReg, yenc & 7);
  3353     // addl $p,$tmp
  3354     if (penc >= 8) {
  3355         emit_opcode(cbuf, Assembler::REX_R);
  3357     emit_opcode(cbuf, 0x03);
  3358     emit_rm(cbuf, 0x3, penc & 7, tmpReg);
  3359   %}
  3361   // Compare the lonogs and set -1, 0, or 1 into dst
  3362   enc_class cmpl3_flag(rRegL src1, rRegL src2, rRegI dst)
  3363   %{
  3364     int src1enc = $src1$$reg;
  3365     int src2enc = $src2$$reg;
  3366     int dstenc = $dst$$reg;
  3368     // cmpq $src1, $src2
  3369     if (src1enc < 8) {
  3370       if (src2enc < 8) {
  3371         emit_opcode(cbuf, Assembler::REX_W);
  3372       } else {
  3373         emit_opcode(cbuf, Assembler::REX_WB);
  3375     } else {
  3376       if (src2enc < 8) {
  3377         emit_opcode(cbuf, Assembler::REX_WR);
  3378       } else {
  3379         emit_opcode(cbuf, Assembler::REX_WRB);
  3382     emit_opcode(cbuf, 0x3B);
  3383     emit_rm(cbuf, 0x3, src1enc & 7, src2enc & 7);
  3385     // movl $dst, -1
  3386     if (dstenc >= 8) {
  3387       emit_opcode(cbuf, Assembler::REX_B);
  3389     emit_opcode(cbuf, 0xB8 | (dstenc & 7));
  3390     emit_d32(cbuf, -1);
  3392     // jl,s done
  3393     emit_opcode(cbuf, 0x7C);
  3394     emit_d8(cbuf, dstenc < 4 ? 0x06 : 0x08);
  3396     // setne $dst
  3397     if (dstenc >= 4) {
  3398       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_B);
  3400     emit_opcode(cbuf, 0x0F);
  3401     emit_opcode(cbuf, 0x95);
  3402     emit_opcode(cbuf, 0xC0 | (dstenc & 7));
  3404     // movzbl $dst, $dst
  3405     if (dstenc >= 4) {
  3406       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_RB);
  3408     emit_opcode(cbuf, 0x0F);
  3409     emit_opcode(cbuf, 0xB6);
  3410     emit_rm(cbuf, 0x3, dstenc & 7, dstenc & 7);
  3411   %}
  3413   enc_class Push_ResultXD(regD dst) %{
  3414     int dstenc = $dst$$reg;
  3416     store_to_stackslot( cbuf, 0xDD, 0x03, 0 ); //FSTP [RSP]
  3418     // UseXmmLoadAndClearUpper ? movsd dst,[rsp] : movlpd dst,[rsp]
  3419     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
  3420     if (dstenc >= 8) {
  3421       emit_opcode(cbuf, Assembler::REX_R);
  3423     emit_opcode  (cbuf, 0x0F );
  3424     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12 );
  3425     encode_RegMem(cbuf, dstenc, RSP_enc, 0x4, 0, 0, false);
  3427     // add rsp,8
  3428     emit_opcode(cbuf, Assembler::REX_W);
  3429     emit_opcode(cbuf,0x83);
  3430     emit_rm(cbuf,0x3, 0x0, RSP_enc);
  3431     emit_d8(cbuf,0x08);
  3432   %}
  3434   enc_class Push_SrcXD(regD src) %{
  3435     int srcenc = $src$$reg;
  3437     // subq rsp,#8
  3438     emit_opcode(cbuf, Assembler::REX_W);
  3439     emit_opcode(cbuf, 0x83);
  3440     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
  3441     emit_d8(cbuf, 0x8);
  3443     // movsd [rsp],src
  3444     emit_opcode(cbuf, 0xF2);
  3445     if (srcenc >= 8) {
  3446       emit_opcode(cbuf, Assembler::REX_R);
  3448     emit_opcode(cbuf, 0x0F);
  3449     emit_opcode(cbuf, 0x11);
  3450     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false);
  3452     // fldd [rsp]
  3453     emit_opcode(cbuf, 0x66);
  3454     emit_opcode(cbuf, 0xDD);
  3455     encode_RegMem(cbuf, 0x0, RSP_enc, 0x4, 0, 0, false);
  3456   %}
  3459   enc_class movq_ld(regD dst, memory mem) %{
  3460     MacroAssembler _masm(&cbuf);
  3461     Address madr = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
  3462     __ movq(as_XMMRegister($dst$$reg), madr);
  3463   %}
  3465   enc_class movq_st(memory mem, regD src) %{
  3466     MacroAssembler _masm(&cbuf);
  3467     Address madr = Address::make_raw($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
  3468     __ movq(madr, as_XMMRegister($src$$reg));
  3469   %}
  3471   enc_class pshufd_8x8(regF dst, regF src) %{
  3472     MacroAssembler _masm(&cbuf);
  3474     encode_CopyXD(cbuf, $dst$$reg, $src$$reg);
  3475     __ punpcklbw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg));
  3476     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg), 0x00);
  3477   %}
  3479   enc_class pshufd_4x16(regF dst, regF src) %{
  3480     MacroAssembler _masm(&cbuf);
  3482     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), 0x00);
  3483   %}
  3485   enc_class pshufd(regD dst, regD src, int mode) %{
  3486     MacroAssembler _masm(&cbuf);
  3488     __ pshufd(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), $mode);
  3489   %}
  3491   enc_class pxor(regD dst, regD src) %{
  3492     MacroAssembler _masm(&cbuf);
  3494     __ pxor(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg));
  3495   %}
  3497   enc_class mov_i2x(regD dst, rRegI src) %{
  3498     MacroAssembler _masm(&cbuf);
  3500     __ movdl(as_XMMRegister($dst$$reg), as_Register($src$$reg));
  3501   %}
  3503   // obj: object to lock
  3504   // box: box address (header location) -- killed
  3505   // tmp: rax -- killed
  3506   // scr: rbx -- killed
  3507   //
  3508   // What follows is a direct transliteration of fast_lock() and fast_unlock()
  3509   // from i486.ad.  See that file for comments.
  3510   // TODO: where possible switch from movq (r, 0) to movl(r,0) and
  3511   // use the shorter encoding.  (Movl clears the high-order 32-bits).
  3514   enc_class Fast_Lock(rRegP obj, rRegP box, rax_RegI tmp, rRegP scr)
  3515   %{
  3516     Register objReg = as_Register((int)$obj$$reg);
  3517     Register boxReg = as_Register((int)$box$$reg);
  3518     Register tmpReg = as_Register($tmp$$reg);
  3519     Register scrReg = as_Register($scr$$reg);
  3520     MacroAssembler masm(&cbuf);
  3522     // Verify uniqueness of register assignments -- necessary but not sufficient
  3523     assert (objReg != boxReg && objReg != tmpReg &&
  3524             objReg != scrReg && tmpReg != scrReg, "invariant") ;
  3526     if (_counters != NULL) {
  3527       masm.atomic_incl(ExternalAddress((address) _counters->total_entry_count_addr()));
  3529     if (EmitSync & 1) {
  3530         masm.movptr (Address(boxReg, 0), intptr_t(markOopDesc::unused_mark())) ;
  3531         masm.cmpq   (rsp, 0) ;
  3532     } else
  3533     if (EmitSync & 2) {
  3534         Label DONE_LABEL;
  3535         if (UseBiasedLocking) {
  3536            // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument.
  3537           masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
  3539         masm.movl(tmpReg, 0x1);
  3540         masm.orq(tmpReg, Address(objReg, 0));
  3541         masm.movq(Address(boxReg, 0), tmpReg);
  3542         if (os::is_MP()) {
  3543           masm.lock();
  3545         masm.cmpxchgq(boxReg, Address(objReg, 0)); // Updates tmpReg
  3546         masm.jcc(Assembler::equal, DONE_LABEL);
  3548         // Recursive locking
  3549         masm.subq(tmpReg, rsp);
  3550         masm.andq(tmpReg, 7 - os::vm_page_size());
  3551         masm.movq(Address(boxReg, 0), tmpReg);
  3553         masm.bind(DONE_LABEL);
  3554         masm.nop(); // avoid branch to branch
  3555     } else {
  3556         Label DONE_LABEL, IsInflated, Egress;
  3558         masm.movq  (tmpReg, Address(objReg, 0)) ;
  3559         masm.testq (tmpReg, 0x02) ;         // inflated vs stack-locked|neutral|biased
  3560         masm.jcc   (Assembler::notZero, IsInflated) ;
  3562         // it's stack-locked, biased or neutral
  3563         // TODO: optimize markword triage order to reduce the number of
  3564         // conditional branches in the most common cases.
  3565         // Beware -- there's a subtle invariant that fetch of the markword
  3566         // at [FETCH], below, will never observe a biased encoding (*101b).
  3567         // If this invariant is not held we'll suffer exclusion (safety) failure.
  3569         if (UseBiasedLocking) {
  3570           masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, true, DONE_LABEL, NULL, _counters);
  3571           masm.movq  (tmpReg, Address(objReg, 0)) ;        // [FETCH]
  3574         masm.orq   (tmpReg, 1) ;
  3575         masm.movq  (Address(boxReg, 0), tmpReg) ;
  3576         if (os::is_MP()) { masm.lock(); }
  3577         masm.cmpxchgq(boxReg, Address(objReg, 0)); // Updates tmpReg
  3578         if (_counters != NULL) {
  3579            masm.cond_inc32(Assembler::equal,
  3580                            ExternalAddress((address) _counters->fast_path_entry_count_addr()));
  3582         masm.jcc   (Assembler::equal, DONE_LABEL);
  3584         // Recursive locking
  3585         masm.subq  (tmpReg, rsp);
  3586         masm.andq  (tmpReg, 7 - os::vm_page_size());
  3587         masm.movq  (Address(boxReg, 0), tmpReg);
  3588         if (_counters != NULL) {
  3589            masm.cond_inc32(Assembler::equal,
  3590                            ExternalAddress((address) _counters->fast_path_entry_count_addr()));
  3592         masm.jmp   (DONE_LABEL) ;
  3594         masm.bind  (IsInflated) ;
  3595         // It's inflated
  3597         // TODO: someday avoid the ST-before-CAS penalty by
  3598         // relocating (deferring) the following ST.
  3599         // We should also think about trying a CAS without having
  3600         // fetched _owner.  If the CAS is successful we may
  3601         // avoid an RTO->RTS upgrade on the $line.
  3602         masm.movptr(Address(boxReg, 0), intptr_t(markOopDesc::unused_mark())) ;
  3604         masm.movq  (boxReg, tmpReg) ;
  3605         masm.movq  (tmpReg, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
  3606         masm.testq (tmpReg, tmpReg) ;
  3607         masm.jcc   (Assembler::notZero, DONE_LABEL) ;
  3609         // It's inflated and appears unlocked
  3610         if (os::is_MP()) { masm.lock(); }
  3611         masm.cmpxchgq(r15_thread, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
  3612         // Intentional fall-through into DONE_LABEL ...
  3614         masm.bind  (DONE_LABEL) ;
  3615         masm.nop   () ;                 // avoid jmp to jmp
  3617   %}
  3619   // obj: object to unlock
  3620   // box: box address (displaced header location), killed
  3621   // RBX: killed tmp; cannot be obj nor box
  3622   enc_class Fast_Unlock(rRegP obj, rax_RegP box, rRegP tmp)
  3623   %{
  3625     Register objReg = as_Register($obj$$reg);
  3626     Register boxReg = as_Register($box$$reg);
  3627     Register tmpReg = as_Register($tmp$$reg);
  3628     MacroAssembler masm(&cbuf);
  3630     if (EmitSync & 4) {
  3631        masm.cmpq  (rsp, 0) ;
  3632     } else
  3633     if (EmitSync & 8) {
  3634        Label DONE_LABEL;
  3635        if (UseBiasedLocking) {
  3636          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3639        // Check whether the displaced header is 0
  3640        //(=> recursive unlock)
  3641        masm.movq(tmpReg, Address(boxReg, 0));
  3642        masm.testq(tmpReg, tmpReg);
  3643        masm.jcc(Assembler::zero, DONE_LABEL);
  3645        // If not recursive lock, reset the header to displaced header
  3646        if (os::is_MP()) {
  3647          masm.lock();
  3649        masm.cmpxchgq(tmpReg, Address(objReg, 0)); // Uses RAX which is box
  3650        masm.bind(DONE_LABEL);
  3651        masm.nop(); // avoid branch to branch
  3652     } else {
  3653        Label DONE_LABEL, Stacked, CheckSucc ;
  3655        if (UseBiasedLocking) {
  3656          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
  3659        masm.movq  (tmpReg, Address(objReg, 0)) ;
  3660        masm.cmpq  (Address(boxReg, 0), (int)NULL_WORD) ;
  3661        masm.jcc   (Assembler::zero, DONE_LABEL) ;
  3662        masm.testq (tmpReg, 0x02) ;
  3663        masm.jcc   (Assembler::zero, Stacked) ;
  3665        // It's inflated
  3666        masm.movq  (boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
  3667        masm.xorq  (boxReg, r15_thread) ;
  3668        masm.orq   (boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
  3669        masm.jcc   (Assembler::notZero, DONE_LABEL) ;
  3670        masm.movq  (boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ;
  3671        masm.orq   (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ;
  3672        masm.jcc   (Assembler::notZero, CheckSucc) ;
  3673        masm.mov64 (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int)NULL_WORD) ;
  3674        masm.jmp   (DONE_LABEL) ;
  3676        if ((EmitSync & 65536) == 0) {
  3677          Label LSuccess, LGoSlowPath ;
  3678          masm.bind  (CheckSucc) ;
  3679          masm.cmpq  (Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), (int)NULL_WORD) ;
  3680          masm.jcc   (Assembler::zero, LGoSlowPath) ;
  3682          // I'd much rather use lock:andl m->_owner, 0 as it's faster than the
  3683          // the explicit ST;MEMBAR combination, but masm doesn't currently support
  3684          // "ANDQ M,IMM".  Don't use MFENCE here.  lock:add to TOS, xchg, etc
  3685          // are all faster when the write buffer is populated.
  3686          masm.movptr (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int)NULL_WORD) ;
  3687          if (os::is_MP()) {
  3688             masm.lock () ; masm.addq (Address(rsp, 0), 0) ;
  3690          masm.cmpq  (Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), (int)NULL_WORD) ;
  3691          masm.jcc   (Assembler::notZero, LSuccess) ;
  3693          masm.movptr (boxReg, (int)NULL_WORD) ;                   // box is really EAX
  3694          if (os::is_MP()) { masm.lock(); }
  3695          masm.cmpxchgq (r15_thread, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2));
  3696          masm.jcc   (Assembler::notEqual, LSuccess) ;
  3697          // Intentional fall-through into slow-path
  3699          masm.bind  (LGoSlowPath) ;
  3700          masm.orl   (boxReg, 1) ;                      // set ICC.ZF=0 to indicate failure
  3701          masm.jmp   (DONE_LABEL) ;
  3703          masm.bind  (LSuccess) ;
  3704          masm.testl (boxReg, 0) ;                      // set ICC.ZF=1 to indicate success
  3705          masm.jmp   (DONE_LABEL) ;
  3708        masm.bind  (Stacked) ;
  3709        masm.movq  (tmpReg, Address (boxReg, 0)) ;      // re-fetch
  3710        if (os::is_MP()) { masm.lock(); }
  3711        masm.cmpxchgq(tmpReg, Address(objReg, 0)); // Uses RAX which is box
  3713        if (EmitSync & 65536) {
  3714           masm.bind (CheckSucc) ;
  3716        masm.bind(DONE_LABEL);
  3717        if (EmitSync & 32768) {
  3718           masm.nop();                      // avoid branch to branch
  3721   %}
  3723   enc_class enc_String_Compare()
  3724   %{
  3725     Label RCX_GOOD_LABEL, LENGTH_DIFF_LABEL,
  3726           POP_LABEL, DONE_LABEL, CONT_LABEL,
  3727           WHILE_HEAD_LABEL;
  3728     MacroAssembler masm(&cbuf);
  3730     // Get the first character position in both strings
  3731     //         [8] char array, [12] offset, [16] count
  3732     int value_offset  = java_lang_String::value_offset_in_bytes();
  3733     int offset_offset = java_lang_String::offset_offset_in_bytes();
  3734     int count_offset  = java_lang_String::count_offset_in_bytes();
  3735     int base_offset   = arrayOopDesc::base_offset_in_bytes(T_CHAR);
  3737     masm.load_heap_oop(rax, Address(rsi, value_offset));
  3738     masm.movl(rcx, Address(rsi, offset_offset));
  3739     masm.leaq(rax, Address(rax, rcx, Address::times_2, base_offset));
  3740     masm.load_heap_oop(rbx, Address(rdi, value_offset));
  3741     masm.movl(rcx, Address(rdi, offset_offset));
  3742     masm.leaq(rbx, Address(rbx, rcx, Address::times_2, base_offset));
  3744     // Compute the minimum of the string lengths(rsi) and the
  3745     // difference of the string lengths (stack)
  3747     masm.movl(rdi, Address(rdi, count_offset));
  3748     masm.movl(rsi, Address(rsi, count_offset));
  3749     masm.movl(rcx, rdi);
  3750     masm.subl(rdi, rsi);
  3751     masm.pushq(rdi);
  3752     masm.cmovl(Assembler::lessEqual, rsi, rcx);
  3754     // Is the minimum length zero?
  3755     masm.bind(RCX_GOOD_LABEL);
  3756     masm.testl(rsi, rsi);
  3757     masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
  3759     // Load first characters
  3760     masm.load_unsigned_word(rcx, Address(rbx, 0));
  3761     masm.load_unsigned_word(rdi, Address(rax, 0));
  3763     // Compare first characters
  3764     masm.subl(rcx, rdi);
  3765     masm.jcc(Assembler::notZero,  POP_LABEL);
  3766     masm.decrementl(rsi);
  3767     masm.jcc(Assembler::zero, LENGTH_DIFF_LABEL);
  3770       // Check after comparing first character to see if strings are equivalent
  3771       Label LSkip2;
  3772       // Check if the strings start at same location
  3773       masm.cmpq(rbx, rax);
  3774       masm.jcc(Assembler::notEqual, LSkip2);
  3776       // Check if the length difference is zero (from stack)
  3777       masm.cmpl(Address(rsp, 0), 0x0);
  3778       masm.jcc(Assembler::equal,  LENGTH_DIFF_LABEL);
  3780       // Strings might not be equivalent
  3781       masm.bind(LSkip2);
  3784     // Shift RAX and RBX to the end of the arrays, negate min
  3785     masm.leaq(rax, Address(rax, rsi, Address::times_2, 2));
  3786     masm.leaq(rbx, Address(rbx, rsi, Address::times_2, 2));
  3787     masm.negq(rsi);
  3789     // Compare the rest of the characters
  3790     masm.bind(WHILE_HEAD_LABEL);
  3791     masm.load_unsigned_word(rcx, Address(rbx, rsi, Address::times_2, 0));
  3792     masm.load_unsigned_word(rdi, Address(rax, rsi, Address::times_2, 0));
  3793     masm.subl(rcx, rdi);
  3794     masm.jcc(Assembler::notZero, POP_LABEL);
  3795     masm.incrementq(rsi);
  3796     masm.jcc(Assembler::notZero, WHILE_HEAD_LABEL);
  3798     // Strings are equal up to min length.  Return the length difference.
  3799     masm.bind(LENGTH_DIFF_LABEL);
  3800     masm.popq(rcx);
  3801     masm.jmp(DONE_LABEL);
  3803     // Discard the stored length difference
  3804     masm.bind(POP_LABEL);
  3805     masm.addq(rsp, 8);
  3807     // That's it
  3808     masm.bind(DONE_LABEL);
  3809   %}
  3811   enc_class enc_Array_Equals(rdi_RegP ary1, rsi_RegP ary2, rax_RegI tmp1, rbx_RegI tmp2, rcx_RegI result) %{
  3812     Label TRUE_LABEL, FALSE_LABEL, DONE_LABEL, COMPARE_LOOP_HDR, COMPARE_LOOP;
  3813     MacroAssembler masm(&cbuf);
  3815     Register ary1Reg   = as_Register($ary1$$reg);
  3816     Register ary2Reg   = as_Register($ary2$$reg);
  3817     Register tmp1Reg   = as_Register($tmp1$$reg);
  3818     Register tmp2Reg   = as_Register($tmp2$$reg);
  3819     Register resultReg = as_Register($result$$reg);
  3821     int length_offset  = arrayOopDesc::length_offset_in_bytes();
  3822     int base_offset    = arrayOopDesc::base_offset_in_bytes(T_CHAR);
  3824     // Check the input args
  3825     masm.cmpq(ary1Reg, ary2Reg);                        
  3826     masm.jcc(Assembler::equal, TRUE_LABEL);
  3827     masm.testq(ary1Reg, ary1Reg);                       
  3828     masm.jcc(Assembler::zero, FALSE_LABEL);
  3829     masm.testq(ary2Reg, ary2Reg);                       
  3830     masm.jcc(Assembler::zero, FALSE_LABEL);
  3832     // Check the lengths
  3833     masm.movl(tmp2Reg, Address(ary1Reg, length_offset));
  3834     masm.movl(resultReg, Address(ary2Reg, length_offset));
  3835     masm.cmpl(tmp2Reg, resultReg);
  3836     masm.jcc(Assembler::notEqual, FALSE_LABEL);
  3837     masm.testl(resultReg, resultReg);
  3838     masm.jcc(Assembler::zero, TRUE_LABEL);
  3840     // Get the number of 4 byte vectors to compare
  3841     masm.shrl(resultReg, 1);
  3843     // Check for odd-length arrays
  3844     masm.andl(tmp2Reg, 1);
  3845     masm.testl(tmp2Reg, tmp2Reg);
  3846     masm.jcc(Assembler::zero, COMPARE_LOOP_HDR);
  3848     // Compare 2-byte "tail" at end of arrays
  3849     masm.load_unsigned_word(tmp1Reg, Address(ary1Reg, resultReg, Address::times_4, base_offset));
  3850     masm.load_unsigned_word(tmp2Reg, Address(ary2Reg, resultReg, Address::times_4, base_offset));
  3851     masm.cmpl(tmp1Reg, tmp2Reg);
  3852     masm.jcc(Assembler::notEqual, FALSE_LABEL);
  3853     masm.testl(resultReg, resultReg);
  3854     masm.jcc(Assembler::zero, TRUE_LABEL);
  3856     // Setup compare loop
  3857     masm.bind(COMPARE_LOOP_HDR);
  3858     // Shift tmp1Reg and tmp2Reg to the last 4-byte boundary of the arrays
  3859     masm.leaq(tmp1Reg, Address(ary1Reg, resultReg, Address::times_4, base_offset));
  3860     masm.leaq(tmp2Reg, Address(ary2Reg, resultReg, Address::times_4, base_offset));
  3861     masm.negq(resultReg);
  3863     // 4-byte-wide compare loop
  3864     masm.bind(COMPARE_LOOP);
  3865     masm.movl(ary1Reg, Address(tmp1Reg, resultReg, Address::times_4, 0));
  3866     masm.movl(ary2Reg, Address(tmp2Reg, resultReg, Address::times_4, 0));
  3867     masm.cmpl(ary1Reg, ary2Reg);
  3868     masm.jcc(Assembler::notEqual, FALSE_LABEL);
  3869     masm.incrementq(resultReg);
  3870     masm.jcc(Assembler::notZero, COMPARE_LOOP);
  3872     masm.bind(TRUE_LABEL);
  3873     masm.movl(resultReg, 1);   // return true
  3874     masm.jmp(DONE_LABEL);
  3876     masm.bind(FALSE_LABEL);
  3877     masm.xorl(resultReg, resultReg); // return false
  3879     // That's it
  3880     masm.bind(DONE_LABEL);
  3881   %}
  3883   enc_class enc_rethrow()
  3884   %{
  3885     cbuf.set_inst_mark();
  3886     emit_opcode(cbuf, 0xE9); // jmp entry
  3887     emit_d32_reloc(cbuf,
  3888                    (int) (OptoRuntime::rethrow_stub() - cbuf.code_end() - 4),
  3889                    runtime_call_Relocation::spec(),
  3890                    RELOC_DISP32);
  3891   %}
  3893   enc_class absF_encoding(regF dst)
  3894   %{
  3895     int dstenc = $dst$$reg;
  3896     address signmask_address = (address) StubRoutines::amd64::float_sign_mask();
  3898     cbuf.set_inst_mark();
  3899     if (dstenc >= 8) {
  3900       emit_opcode(cbuf, Assembler::REX_R);
  3901       dstenc -= 8;
  3903     // XXX reg_mem doesn't support RIP-relative addressing yet
  3904     emit_opcode(cbuf, 0x0F);
  3905     emit_opcode(cbuf, 0x54);
  3906     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
  3907     emit_d32_reloc(cbuf, signmask_address);
  3908   %}
  3910   enc_class absD_encoding(regD dst)
  3911   %{
  3912     int dstenc = $dst$$reg;
  3913     address signmask_address = (address) StubRoutines::amd64::double_sign_mask();
  3915     cbuf.set_inst_mark();
  3916     emit_opcode(cbuf, 0x66);
  3917     if (dstenc >= 8) {
  3918       emit_opcode(cbuf, Assembler::REX_R);
  3919       dstenc -= 8;
  3921     // XXX reg_mem doesn't support RIP-relative addressing yet
  3922     emit_opcode(cbuf, 0x0F);
  3923     emit_opcode(cbuf, 0x54);
  3924     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
  3925     emit_d32_reloc(cbuf, signmask_address);
  3926   %}
  3928   enc_class negF_encoding(regF dst)
  3929   %{
  3930     int dstenc = $dst$$reg;
  3931     address signflip_address = (address) StubRoutines::amd64::float_sign_flip();
  3933     cbuf.set_inst_mark();
  3934     if (dstenc >= 8) {
  3935       emit_opcode(cbuf, Assembler::REX_R);
  3936       dstenc -= 8;
  3938     // XXX reg_mem doesn't support RIP-relative addressing yet
  3939     emit_opcode(cbuf, 0x0F);
  3940     emit_opcode(cbuf, 0x57);
  3941     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
  3942     emit_d32_reloc(cbuf, signflip_address);
  3943   %}
  3945   enc_class negD_encoding(regD dst)
  3946   %{
  3947     int dstenc = $dst$$reg;
  3948     address signflip_address = (address) StubRoutines::amd64::double_sign_flip();
  3950     cbuf.set_inst_mark();
  3951     emit_opcode(cbuf, 0x66);
  3952     if (dstenc >= 8) {
  3953       emit_opcode(cbuf, Assembler::REX_R);
  3954       dstenc -= 8;
  3956     // XXX reg_mem doesn't support RIP-relative addressing yet
  3957     emit_opcode(cbuf, 0x0F);
  3958     emit_opcode(cbuf, 0x57);
  3959     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
  3960     emit_d32_reloc(cbuf, signflip_address);
  3961   %}
  3963   enc_class f2i_fixup(rRegI dst, regF src)
  3964   %{
  3965     int dstenc = $dst$$reg;
  3966     int srcenc = $src$$reg;
  3968     // cmpl $dst, #0x80000000
  3969     if (dstenc >= 8) {
  3970       emit_opcode(cbuf, Assembler::REX_B);
  3972     emit_opcode(cbuf, 0x81);
  3973     emit_rm(cbuf, 0x3, 0x7, dstenc & 7);
  3974     emit_d32(cbuf, 0x80000000);
  3976     // jne,s done
  3977     emit_opcode(cbuf, 0x75);
  3978     if (srcenc < 8 && dstenc < 8) {
  3979       emit_d8(cbuf, 0xF);
  3980     } else if (srcenc >= 8 && dstenc >= 8) {
  3981       emit_d8(cbuf, 0x11);
  3982     } else {
  3983       emit_d8(cbuf, 0x10);
  3986     // subq rsp, #8
  3987     emit_opcode(cbuf, Assembler::REX_W);
  3988     emit_opcode(cbuf, 0x83);
  3989     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
  3990     emit_d8(cbuf, 8);
  3992     // movss [rsp], $src
  3993     emit_opcode(cbuf, 0xF3);
  3994     if (srcenc >= 8) {
  3995       emit_opcode(cbuf, Assembler::REX_R);
  3997     emit_opcode(cbuf, 0x0F);
  3998     emit_opcode(cbuf, 0x11);
  3999     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
  4001     // call f2i_fixup
  4002     cbuf.set_inst_mark();
  4003     emit_opcode(cbuf, 0xE8);
  4004     emit_d32_reloc(cbuf,
  4005                    (int)
  4006                    (StubRoutines::amd64::f2i_fixup() - cbuf.code_end() - 4),
  4007                    runtime_call_Relocation::spec(),
  4008                    RELOC_DISP32);
  4010     // popq $dst
  4011     if (dstenc >= 8) {
  4012       emit_opcode(cbuf, Assembler::REX_B);
  4014     emit_opcode(cbuf, 0x58 | (dstenc & 7));
  4016     // done:
  4017   %}
  4019   enc_class f2l_fixup(rRegL dst, regF src)
  4020   %{
  4021     int dstenc = $dst$$reg;
  4022     int srcenc = $src$$reg;
  4023     address const_address = (address) StubRoutines::amd64::double_sign_flip();
  4025     // cmpq $dst, [0x8000000000000000]
  4026     cbuf.set_inst_mark();
  4027     emit_opcode(cbuf, dstenc < 8 ? Assembler::REX_W : Assembler::REX_WR);
  4028     emit_opcode(cbuf, 0x39);
  4029     // XXX reg_mem doesn't support RIP-relative addressing yet
  4030     emit_rm(cbuf, 0x0, dstenc & 7, 0x5); // 00 reg 101
  4031     emit_d32_reloc(cbuf, const_address);
  4034     // jne,s done
  4035     emit_opcode(cbuf, 0x75);
  4036     if (srcenc < 8 && dstenc < 8) {
  4037       emit_d8(cbuf, 0xF);
  4038     } else if (srcenc >= 8 && dstenc >= 8) {
  4039       emit_d8(cbuf, 0x11);
  4040     } else {
  4041       emit_d8(cbuf, 0x10);
  4044     // subq rsp, #8
  4045     emit_opcode(cbuf, Assembler::REX_W);
  4046     emit_opcode(cbuf, 0x83);
  4047     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
  4048     emit_d8(cbuf, 8);
  4050     // movss [rsp], $src
  4051     emit_opcode(cbuf, 0xF3);
  4052     if (srcenc >= 8) {
  4053       emit_opcode(cbuf, Assembler::REX_R);
  4055     emit_opcode(cbuf, 0x0F);
  4056     emit_opcode(cbuf, 0x11);
  4057     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
  4059     // call f2l_fixup
  4060     cbuf.set_inst_mark();
  4061     emit_opcode(cbuf, 0xE8);
  4062     emit_d32_reloc(cbuf,
  4063                    (int)
  4064                    (StubRoutines::amd64::f2l_fixup() - cbuf.code_end() - 4),
  4065                    runtime_call_Relocation::spec(),
  4066                    RELOC_DISP32);
  4068     // popq $dst
  4069     if (dstenc >= 8) {
  4070       emit_opcode(cbuf, Assembler::REX_B);
  4072     emit_opcode(cbuf, 0x58 | (dstenc & 7));
  4074     // done:
  4075   %}
  4077   enc_class d2i_fixup(rRegI dst, regD src)
  4078   %{
  4079     int dstenc = $dst$$reg;
  4080     int srcenc = $src$$reg;
  4082     // cmpl $dst, #0x80000000
  4083     if (dstenc >= 8) {
  4084       emit_opcode(cbuf, Assembler::REX_B);
  4086     emit_opcode(cbuf, 0x81);
  4087     emit_rm(cbuf, 0x3, 0x7, dstenc & 7);
  4088     emit_d32(cbuf, 0x80000000);
  4090     // jne,s done
  4091     emit_opcode(cbuf, 0x75);
  4092     if (srcenc < 8 && dstenc < 8) {
  4093       emit_d8(cbuf, 0xF);
  4094     } else if (srcenc >= 8 && dstenc >= 8) {
  4095       emit_d8(cbuf, 0x11);
  4096     } else {
  4097       emit_d8(cbuf, 0x10);
  4100     // subq rsp, #8
  4101     emit_opcode(cbuf, Assembler::REX_W);
  4102     emit_opcode(cbuf, 0x83);
  4103     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
  4104     emit_d8(cbuf, 8);
  4106     // movsd [rsp], $src
  4107     emit_opcode(cbuf, 0xF2);
  4108     if (srcenc >= 8) {
  4109       emit_opcode(cbuf, Assembler::REX_R);
  4111     emit_opcode(cbuf, 0x0F);
  4112     emit_opcode(cbuf, 0x11);
  4113     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
  4115     // call d2i_fixup
  4116     cbuf.set_inst_mark();
  4117     emit_opcode(cbuf, 0xE8);
  4118     emit_d32_reloc(cbuf,
  4119                    (int)
  4120                    (StubRoutines::amd64::d2i_fixup() - cbuf.code_end() - 4),
  4121                    runtime_call_Relocation::spec(),
  4122                    RELOC_DISP32);
  4124     // popq $dst
  4125     if (dstenc >= 8) {
  4126       emit_opcode(cbuf, Assembler::REX_B);
  4128     emit_opcode(cbuf, 0x58 | (dstenc & 7));
  4130     // done:
  4131   %}
  4133   enc_class d2l_fixup(rRegL dst, regD src)
  4134   %{
  4135     int dstenc = $dst$$reg;
  4136     int srcenc = $src$$reg;
  4137     address const_address = (address) StubRoutines::amd64::double_sign_flip();
  4139     // cmpq $dst, [0x8000000000000000]
  4140     cbuf.set_inst_mark();
  4141     emit_opcode(cbuf, dstenc < 8 ? Assembler::REX_W : Assembler::REX_WR);
  4142     emit_opcode(cbuf, 0x39);
  4143     // XXX reg_mem doesn't support RIP-relative addressing yet
  4144     emit_rm(cbuf, 0x0, dstenc & 7, 0x5); // 00 reg 101
  4145     emit_d32_reloc(cbuf, const_address);
  4148     // jne,s done
  4149     emit_opcode(cbuf, 0x75);
  4150     if (srcenc < 8 && dstenc < 8) {
  4151       emit_d8(cbuf, 0xF);
  4152     } else if (srcenc >= 8 && dstenc >= 8) {
  4153       emit_d8(cbuf, 0x11);
  4154     } else {
  4155       emit_d8(cbuf, 0x10);
  4158     // subq rsp, #8
  4159     emit_opcode(cbuf, Assembler::REX_W);
  4160     emit_opcode(cbuf, 0x83);
  4161     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
  4162     emit_d8(cbuf, 8);
  4164     // movsd [rsp], $src
  4165     emit_opcode(cbuf, 0xF2);
  4166     if (srcenc >= 8) {
  4167       emit_opcode(cbuf, Assembler::REX_R);
  4169     emit_opcode(cbuf, 0x0F);
  4170     emit_opcode(cbuf, 0x11);
  4171     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
  4173     // call d2l_fixup
  4174     cbuf.set_inst_mark();
  4175     emit_opcode(cbuf, 0xE8);
  4176     emit_d32_reloc(cbuf,
  4177                    (int)
  4178                    (StubRoutines::amd64::d2l_fixup() - cbuf.code_end() - 4),
  4179                    runtime_call_Relocation::spec(),
  4180                    RELOC_DISP32);
  4182     // popq $dst
  4183     if (dstenc >= 8) {
  4184       emit_opcode(cbuf, Assembler::REX_B);
  4186     emit_opcode(cbuf, 0x58 | (dstenc & 7));
  4188     // done:
  4189   %}
  4191   enc_class enc_membar_acquire
  4192   %{
  4193     // [jk] not needed currently, if you enable this and it really
  4194     // emits code don't forget to the remove the "size(0)" line in
  4195     // membar_acquire()
  4196     // MacroAssembler masm(&cbuf);
  4197     // masm.membar(Assembler::Membar_mask_bits(Assembler::LoadStore |
  4198     //                                         Assembler::LoadLoad));
  4199   %}
  4201   enc_class enc_membar_release
  4202   %{
  4203     // [jk] not needed currently, if you enable this and it really
  4204     // emits code don't forget to the remove the "size(0)" line in
  4205     // membar_release()
  4206     // MacroAssembler masm(&cbuf);
  4207     // masm.membar(Assembler::Membar_mask_bits(Assembler::LoadStore |
  4208     //                                         Assembler::StoreStore));
  4209   %}
  4211   enc_class enc_membar_volatile
  4212   %{
  4213     MacroAssembler masm(&cbuf);
  4214     masm.membar(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  4215                                             Assembler::StoreStore));
  4216   %}
  4218   // Safepoint Poll.  This polls the safepoint page, and causes an
  4219   // exception if it is not readable. Unfortunately, it kills
  4220   // RFLAGS in the process.
  4221   enc_class enc_safepoint_poll
  4222   %{
  4223     // testl %rax, off(%rip) // Opcode + ModRM + Disp32 == 6 bytes
  4224     // XXX reg_mem doesn't support RIP-relative addressing yet
  4225     cbuf.set_inst_mark();
  4226     cbuf.relocate(cbuf.inst_mark(), relocInfo::poll_type, 0); // XXX
  4227     emit_opcode(cbuf, 0x85); // testl
  4228     emit_rm(cbuf, 0x0, RAX_enc, 0x5); // 00 rax 101 == 0x5
  4229     // cbuf.inst_mark() is beginning of instruction
  4230     emit_d32_reloc(cbuf, os::get_polling_page());
  4231 //                    relocInfo::poll_type,
  4232   %}
  4233 %}
  4237 //----------FRAME--------------------------------------------------------------
  4238 // Definition of frame structure and management information.
  4239 //
  4240 //  S T A C K   L A Y O U T    Allocators stack-slot number
  4241 //                             |   (to get allocators register number
  4242 //  G  Owned by    |        |  v    add OptoReg::stack0())
  4243 //  r   CALLER     |        |
  4244 //  o     |        +--------+      pad to even-align allocators stack-slot
  4245 //  w     V        |  pad0  |        numbers; owned by CALLER
  4246 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
  4247 //  h     ^        |   in   |  5
  4248 //        |        |  args  |  4   Holes in incoming args owned by SELF
  4249 //  |     |        |        |  3
  4250 //  |     |        +--------+
  4251 //  V     |        | old out|      Empty on Intel, window on Sparc
  4252 //        |    old |preserve|      Must be even aligned.
  4253 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
  4254 //        |        |   in   |  3   area for Intel ret address
  4255 //     Owned by    |preserve|      Empty on Sparc.
  4256 //       SELF      +--------+
  4257 //        |        |  pad2  |  2   pad to align old SP
  4258 //        |        +--------+  1
  4259 //        |        | locks  |  0
  4260 //        |        +--------+----> OptoReg::stack0(), even aligned
  4261 //        |        |  pad1  | 11   pad to align new SP
  4262 //        |        +--------+
  4263 //        |        |        | 10
  4264 //        |        | spills |  9   spills
  4265 //        V        |        |  8   (pad0 slot for callee)
  4266 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
  4267 //        ^        |  out   |  7
  4268 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
  4269 //     Owned by    +--------+
  4270 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
  4271 //        |    new |preserve|      Must be even-aligned.
  4272 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
  4273 //        |        |        |
  4274 //
  4275 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
  4276 //         known from SELF's arguments and the Java calling convention.
  4277 //         Region 6-7 is determined per call site.
  4278 // Note 2: If the calling convention leaves holes in the incoming argument
  4279 //         area, those holes are owned by SELF.  Holes in the outgoing area
  4280 //         are owned by the CALLEE.  Holes should not be nessecary in the
  4281 //         incoming area, as the Java calling convention is completely under
  4282 //         the control of the AD file.  Doubles can be sorted and packed to
  4283 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
  4284 //         varargs C calling conventions.
  4285 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
  4286 //         even aligned with pad0 as needed.
  4287 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
  4288 //         region 6-11 is even aligned; it may be padded out more so that
  4289 //         the region from SP to FP meets the minimum stack alignment.
  4290 // Note 4: For I2C adapters, the incoming FP may not meet the minimum stack
  4291 //         alignment.  Region 11, pad1, may be dynamically extended so that
  4292 //         SP meets the minimum alignment.
  4294 frame
  4295 %{
  4296   // What direction does stack grow in (assumed to be same for C & Java)
  4297   stack_direction(TOWARDS_LOW);
  4299   // These three registers define part of the calling convention
  4300   // between compiled code and the interpreter.
  4301   inline_cache_reg(RAX);                // Inline Cache Register
  4302   interpreter_method_oop_reg(RBX);      // Method Oop Register when
  4303                                         // calling interpreter
  4305   // Optional: name the operand used by cisc-spilling to access
  4306   // [stack_pointer + offset]
  4307   cisc_spilling_operand_name(indOffset32);
  4309   // Number of stack slots consumed by locking an object
  4310   sync_stack_slots(2);
  4312   // Compiled code's Frame Pointer
  4313   frame_pointer(RSP);
  4315   // Interpreter stores its frame pointer in a register which is
  4316   // stored to the stack by I2CAdaptors.
  4317   // I2CAdaptors convert from interpreted java to compiled java.
  4318   interpreter_frame_pointer(RBP);
  4320   // Stack alignment requirement
  4321   stack_alignment(StackAlignmentInBytes); // Alignment size in bytes (128-bit -> 16 bytes)
  4323   // Number of stack slots between incoming argument block and the start of
  4324   // a new frame.  The PROLOG must add this many slots to the stack.  The
  4325   // EPILOG must remove this many slots.  amd64 needs two slots for
  4326   // return address.
  4327   in_preserve_stack_slots(4 + 2 * VerifyStackAtCalls);
  4329   // Number of outgoing stack slots killed above the out_preserve_stack_slots
  4330   // for calls to C.  Supports the var-args backing area for register parms.
  4331   varargs_C_out_slots_killed(frame::arg_reg_save_area_bytes/BytesPerInt);
  4333   // The after-PROLOG location of the return address.  Location of
  4334   // return address specifies a type (REG or STACK) and a number
  4335   // representing the register number (i.e. - use a register name) or
  4336   // stack slot.
  4337   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
  4338   // Otherwise, it is above the locks and verification slot and alignment word
  4339   return_addr(STACK - 2 +
  4340               round_to(2 + 2 * VerifyStackAtCalls +
  4341                        Compile::current()->fixed_slots(),
  4342                        WordsPerLong * 2));
  4344   // Body of function which returns an integer array locating
  4345   // arguments either in registers or in stack slots.  Passed an array
  4346   // of ideal registers called "sig" and a "length" count.  Stack-slot
  4347   // offsets are based on outgoing arguments, i.e. a CALLER setting up
  4348   // arguments for a CALLEE.  Incoming stack arguments are
  4349   // automatically biased by the preserve_stack_slots field above.
  4351   calling_convention
  4352   %{
  4353     // No difference between ingoing/outgoing just pass false
  4354     SharedRuntime::java_calling_convention(sig_bt, regs, length, false);
  4355   %}
  4357   c_calling_convention
  4358   %{
  4359     // This is obviously always outgoing
  4360     (void) SharedRuntime::c_calling_convention(sig_bt, regs, length);
  4361   %}
  4363   // Location of compiled Java return values.  Same as C for now.
  4364   return_value
  4365   %{
  4366     assert(ideal_reg >= Op_RegI && ideal_reg <= Op_RegL,
  4367            "only return normal values");
  4369     static const int lo[Op_RegL + 1] = {
  4370       0,
  4371       0,
  4372       RAX_num,  // Op_RegN
  4373       RAX_num,  // Op_RegI
  4374       RAX_num,  // Op_RegP
  4375       XMM0_num, // Op_RegF
  4376       XMM0_num, // Op_RegD
  4377       RAX_num   // Op_RegL
  4378     };
  4379     static const int hi[Op_RegL + 1] = {
  4380       0,
  4381       0,
  4382       OptoReg::Bad, // Op_RegN
  4383       OptoReg::Bad, // Op_RegI
  4384       RAX_H_num,    // Op_RegP
  4385       OptoReg::Bad, // Op_RegF
  4386       XMM0_H_num,   // Op_RegD
  4387       RAX_H_num     // Op_RegL
  4388     };
  4389     assert(ARRAY_SIZE(hi) == _last_machine_leaf - 1, "missing type");
  4390     return OptoRegPair(hi[ideal_reg], lo[ideal_reg]);
  4391   %}
  4392 %}
  4394 //----------ATTRIBUTES---------------------------------------------------------
  4395 //----------Operand Attributes-------------------------------------------------
  4396 op_attrib op_cost(0);        // Required cost attribute
  4398 //----------Instruction Attributes---------------------------------------------
  4399 ins_attrib ins_cost(100);       // Required cost attribute
  4400 ins_attrib ins_size(8);         // Required size attribute (in bits)
  4401 ins_attrib ins_pc_relative(0);  // Required PC Relative flag
  4402 ins_attrib ins_short_branch(0); // Required flag: is this instruction
  4403                                 // a non-matching short branch variant
  4404                                 // of some long branch?
  4405 ins_attrib ins_alignment(1);    // Required alignment attribute (must
  4406                                 // be a power of 2) specifies the
  4407                                 // alignment that some part of the
  4408                                 // instruction (not necessarily the
  4409                                 // start) requires.  If > 1, a
  4410                                 // compute_padding() function must be
  4411                                 // provided for the instruction
  4413 //----------OPERANDS-----------------------------------------------------------
  4414 // Operand definitions must precede instruction definitions for correct parsing
  4415 // in the ADLC because operands constitute user defined types which are used in
  4416 // instruction definitions.
  4418 //----------Simple Operands----------------------------------------------------
  4419 // Immediate Operands
  4420 // Integer Immediate
  4421 operand immI()
  4422 %{
  4423   match(ConI);
  4425   op_cost(10);
  4426   format %{ %}
  4427   interface(CONST_INTER);
  4428 %}
  4430 // Constant for test vs zero
  4431 operand immI0()
  4432 %{
  4433   predicate(n->get_int() == 0);
  4434   match(ConI);
  4436   op_cost(0);
  4437   format %{ %}
  4438   interface(CONST_INTER);
  4439 %}
  4441 // Constant for increment
  4442 operand immI1()
  4443 %{
  4444   predicate(n->get_int() == 1);
  4445   match(ConI);
  4447   op_cost(0);
  4448   format %{ %}
  4449   interface(CONST_INTER);
  4450 %}
  4452 // Constant for decrement
  4453 operand immI_M1()
  4454 %{
  4455   predicate(n->get_int() == -1);
  4456   match(ConI);
  4458   op_cost(0);
  4459   format %{ %}
  4460   interface(CONST_INTER);
  4461 %}
  4463 // Valid scale values for addressing modes
  4464 operand immI2()
  4465 %{
  4466   predicate(0 <= n->get_int() && (n->get_int() <= 3));
  4467   match(ConI);
  4469   format %{ %}
  4470   interface(CONST_INTER);
  4471 %}
  4473 operand immI8()
  4474 %{
  4475   predicate((-0x80 <= n->get_int()) && (n->get_int() < 0x80));
  4476   match(ConI);
  4478   op_cost(5);
  4479   format %{ %}
  4480   interface(CONST_INTER);
  4481 %}
  4483 operand immI16()
  4484 %{
  4485   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
  4486   match(ConI);
  4488   op_cost(10);
  4489   format %{ %}
  4490   interface(CONST_INTER);
  4491 %}
  4493 // Constant for long shifts
  4494 operand immI_32()
  4495 %{
  4496   predicate( n->get_int() == 32 );
  4497   match(ConI);
  4499   op_cost(0);
  4500   format %{ %}
  4501   interface(CONST_INTER);
  4502 %}
  4504 // Constant for long shifts
  4505 operand immI_64()
  4506 %{
  4507   predicate( n->get_int() == 64 );
  4508   match(ConI);
  4510   op_cost(0);
  4511   format %{ %}
  4512   interface(CONST_INTER);
  4513 %}
  4515 // Pointer Immediate
  4516 operand immP()
  4517 %{
  4518   match(ConP);
  4520   op_cost(10);
  4521   format %{ %}
  4522   interface(CONST_INTER);
  4523 %}
  4525 // NULL Pointer Immediate
  4526 operand immP0()
  4527 %{
  4528   predicate(n->get_ptr() == 0);
  4529   match(ConP);
  4531   op_cost(5);
  4532   format %{ %}
  4533   interface(CONST_INTER);
  4534 %}
  4536 // Pointer Immediate
  4537 operand immN() %{
  4538   match(ConN);
  4540   op_cost(10);
  4541   format %{ %}
  4542   interface(CONST_INTER);
  4543 %}
  4545 // NULL Pointer Immediate
  4546 operand immN0() %{
  4547   predicate(n->get_narrowcon() == 0);
  4548   match(ConN);
  4550   op_cost(5);
  4551   format %{ %}
  4552   interface(CONST_INTER);
  4553 %}
  4555 operand immP31()
  4556 %{
  4557   predicate(!n->as_Type()->type()->isa_oopptr()
  4558             && (n->get_ptr() >> 31) == 0);
  4559   match(ConP);
  4561   op_cost(5);
  4562   format %{ %}
  4563   interface(CONST_INTER);
  4564 %}
  4567 // Long Immediate
  4568 operand immL()
  4569 %{
  4570   match(ConL);
  4572   op_cost(20);
  4573   format %{ %}
  4574   interface(CONST_INTER);
  4575 %}
  4577 // Long Immediate 8-bit
  4578 operand immL8()
  4579 %{
  4580   predicate(-0x80L <= n->get_long() && n->get_long() < 0x80L);
  4581   match(ConL);
  4583   op_cost(5);
  4584   format %{ %}
  4585   interface(CONST_INTER);
  4586 %}
  4588 // Long Immediate 32-bit unsigned
  4589 operand immUL32()
  4590 %{
  4591   predicate(n->get_long() == (unsigned int) (n->get_long()));
  4592   match(ConL);
  4594   op_cost(10);
  4595   format %{ %}
  4596   interface(CONST_INTER);
  4597 %}
  4599 // Long Immediate 32-bit signed
  4600 operand immL32()
  4601 %{
  4602   predicate(n->get_long() == (int) (n->get_long()));
  4603   match(ConL);
  4605   op_cost(15);
  4606   format %{ %}
  4607   interface(CONST_INTER);
  4608 %}
  4610 // Long Immediate zero
  4611 operand immL0()
  4612 %{
  4613   predicate(n->get_long() == 0L);
  4614   match(ConL);
  4616   op_cost(10);
  4617   format %{ %}
  4618   interface(CONST_INTER);
  4619 %}
  4621 // Constant for increment
  4622 operand immL1()
  4623 %{
  4624   predicate(n->get_long() == 1);
  4625   match(ConL);
  4627   format %{ %}
  4628   interface(CONST_INTER);
  4629 %}
  4631 // Constant for decrement
  4632 operand immL_M1()
  4633 %{
  4634   predicate(n->get_long() == -1);
  4635   match(ConL);
  4637   format %{ %}
  4638   interface(CONST_INTER);
  4639 %}
  4641 // Long Immediate: the value 10
  4642 operand immL10()
  4643 %{
  4644   predicate(n->get_long() == 10);
  4645   match(ConL);
  4647   format %{ %}
  4648   interface(CONST_INTER);
  4649 %}
  4651 // Long immediate from 0 to 127.
  4652 // Used for a shorter form of long mul by 10.
  4653 operand immL_127()
  4654 %{
  4655   predicate(0 <= n->get_long() && n->get_long() < 0x80);
  4656   match(ConL);
  4658   op_cost(10);
  4659   format %{ %}
  4660   interface(CONST_INTER);
  4661 %}
  4663 // Long Immediate: low 32-bit mask
  4664 operand immL_32bits()
  4665 %{
  4666   predicate(n->get_long() == 0xFFFFFFFFL);
  4667   match(ConL);
  4668   op_cost(20);
  4670   format %{ %}
  4671   interface(CONST_INTER);
  4672 %}
  4674 // Float Immediate zero
  4675 operand immF0()
  4676 %{
  4677   predicate(jint_cast(n->getf()) == 0);
  4678   match(ConF);
  4680   op_cost(5);
  4681   format %{ %}
  4682   interface(CONST_INTER);
  4683 %}
  4685 // Float Immediate
  4686 operand immF()
  4687 %{
  4688   match(ConF);
  4690   op_cost(15);
  4691   format %{ %}
  4692   interface(CONST_INTER);
  4693 %}
  4695 // Double Immediate zero
  4696 operand immD0()
  4697 %{
  4698   predicate(jlong_cast(n->getd()) == 0);
  4699   match(ConD);
  4701   op_cost(5);
  4702   format %{ %}
  4703   interface(CONST_INTER);
  4704 %}
  4706 // Double Immediate
  4707 operand immD()
  4708 %{
  4709   match(ConD);
  4711   op_cost(15);
  4712   format %{ %}
  4713   interface(CONST_INTER);
  4714 %}
  4716 // Immediates for special shifts (sign extend)
  4718 // Constants for increment
  4719 operand immI_16()
  4720 %{
  4721   predicate(n->get_int() == 16);
  4722   match(ConI);
  4724   format %{ %}
  4725   interface(CONST_INTER);
  4726 %}
  4728 operand immI_24()
  4729 %{
  4730   predicate(n->get_int() == 24);
  4731   match(ConI);
  4733   format %{ %}
  4734   interface(CONST_INTER);
  4735 %}
  4737 // Constant for byte-wide masking
  4738 operand immI_255()
  4739 %{
  4740   predicate(n->get_int() == 255);
  4741   match(ConI);
  4743   format %{ %}
  4744   interface(CONST_INTER);
  4745 %}
  4747 // Constant for short-wide masking
  4748 operand immI_65535()
  4749 %{
  4750   predicate(n->get_int() == 65535);
  4751   match(ConI);
  4753   format %{ %}
  4754   interface(CONST_INTER);
  4755 %}
  4757 // Constant for byte-wide masking
  4758 operand immL_255()
  4759 %{
  4760   predicate(n->get_long() == 255);
  4761   match(ConL);
  4763   format %{ %}
  4764   interface(CONST_INTER);
  4765 %}
  4767 // Constant for short-wide masking
  4768 operand immL_65535()
  4769 %{
  4770   predicate(n->get_long() == 65535);
  4771   match(ConL);
  4773   format %{ %}
  4774   interface(CONST_INTER);
  4775 %}
  4777 // Register Operands
  4778 // Integer Register
  4779 operand rRegI()
  4780 %{
  4781   constraint(ALLOC_IN_RC(int_reg));
  4782   match(RegI);
  4784   match(rax_RegI);
  4785   match(rbx_RegI);
  4786   match(rcx_RegI);
  4787   match(rdx_RegI);
  4788   match(rdi_RegI);
  4790   format %{ %}
  4791   interface(REG_INTER);
  4792 %}
  4794 // Special Registers
  4795 operand rax_RegI()
  4796 %{
  4797   constraint(ALLOC_IN_RC(int_rax_reg));
  4798   match(RegI);
  4799   match(rRegI);
  4801   format %{ "RAX" %}
  4802   interface(REG_INTER);
  4803 %}
  4805 // Special Registers
  4806 operand rbx_RegI()
  4807 %{
  4808   constraint(ALLOC_IN_RC(int_rbx_reg));
  4809   match(RegI);
  4810   match(rRegI);
  4812   format %{ "RBX" %}
  4813   interface(REG_INTER);
  4814 %}
  4816 operand rcx_RegI()
  4817 %{
  4818   constraint(ALLOC_IN_RC(int_rcx_reg));
  4819   match(RegI);
  4820   match(rRegI);
  4822   format %{ "RCX" %}
  4823   interface(REG_INTER);
  4824 %}
  4826 operand rdx_RegI()
  4827 %{
  4828   constraint(ALLOC_IN_RC(int_rdx_reg));
  4829   match(RegI);
  4830   match(rRegI);
  4832   format %{ "RDX" %}
  4833   interface(REG_INTER);
  4834 %}
  4836 operand rdi_RegI()
  4837 %{
  4838   constraint(ALLOC_IN_RC(int_rdi_reg));
  4839   match(RegI);
  4840   match(rRegI);
  4842   format %{ "RDI" %}
  4843   interface(REG_INTER);
  4844 %}
  4846 operand no_rcx_RegI()
  4847 %{
  4848   constraint(ALLOC_IN_RC(int_no_rcx_reg));
  4849   match(RegI);
  4850   match(rax_RegI);
  4851   match(rbx_RegI);
  4852   match(rdx_RegI);
  4853   match(rdi_RegI);
  4855   format %{ %}
  4856   interface(REG_INTER);
  4857 %}
  4859 operand no_rax_rdx_RegI()
  4860 %{
  4861   constraint(ALLOC_IN_RC(int_no_rax_rdx_reg));
  4862   match(RegI);
  4863   match(rbx_RegI);
  4864   match(rcx_RegI);
  4865   match(rdi_RegI);
  4867   format %{ %}
  4868   interface(REG_INTER);
  4869 %}
  4871 // Pointer Register
  4872 operand any_RegP()
  4873 %{
  4874   constraint(ALLOC_IN_RC(any_reg));
  4875   match(RegP);
  4876   match(rax_RegP);
  4877   match(rbx_RegP);
  4878   match(rdi_RegP);
  4879   match(rsi_RegP);
  4880   match(rbp_RegP);
  4881   match(r15_RegP);
  4882   match(rRegP);
  4884   format %{ %}
  4885   interface(REG_INTER);
  4886 %}
  4888 operand rRegP()
  4889 %{
  4890   constraint(ALLOC_IN_RC(ptr_reg));
  4891   match(RegP);
  4892   match(rax_RegP);
  4893   match(rbx_RegP);
  4894   match(rdi_RegP);
  4895   match(rsi_RegP);
  4896   match(rbp_RegP);
  4897   match(r15_RegP);  // See Q&A below about r15_RegP.
  4899   format %{ %}
  4900   interface(REG_INTER);
  4901 %}
  4904 operand r12RegL() %{
  4905   constraint(ALLOC_IN_RC(long_r12_reg));
  4906   match(RegL);
  4908   format %{ %}
  4909   interface(REG_INTER);
  4910 %}
  4912 operand rRegN() %{
  4913   constraint(ALLOC_IN_RC(int_reg));
  4914   match(RegN);
  4916   format %{ %}
  4917   interface(REG_INTER);
  4918 %}
  4920 // Question: Why is r15_RegP (the read-only TLS register) a match for rRegP?
  4921 // Answer: Operand match rules govern the DFA as it processes instruction inputs.
  4922 // It's fine for an instruction input which expects rRegP to match a r15_RegP.
  4923 // The output of an instruction is controlled by the allocator, which respects
  4924 // register class masks, not match rules.  Unless an instruction mentions
  4925 // r15_RegP or any_RegP explicitly as its output, r15 will not be considered
  4926 // by the allocator as an input.
  4928 operand no_rax_RegP()
  4929 %{
  4930   constraint(ALLOC_IN_RC(ptr_no_rax_reg));
  4931   match(RegP);
  4932   match(rbx_RegP);
  4933   match(rsi_RegP);
  4934   match(rdi_RegP);
  4936   format %{ %}
  4937   interface(REG_INTER);
  4938 %}
  4940 operand no_rbp_RegP()
  4941 %{
  4942   constraint(ALLOC_IN_RC(ptr_no_rbp_reg));
  4943   match(RegP);
  4944   match(rbx_RegP);
  4945   match(rsi_RegP);
  4946   match(rdi_RegP);
  4948   format %{ %}
  4949   interface(REG_INTER);
  4950 %}
  4952 operand no_rax_rbx_RegP()
  4953 %{
  4954   constraint(ALLOC_IN_RC(ptr_no_rax_rbx_reg));
  4955   match(RegP);
  4956   match(rsi_RegP);
  4957   match(rdi_RegP);
  4959   format %{ %}
  4960   interface(REG_INTER);
  4961 %}
  4963 // Special Registers
  4964 // Return a pointer value
  4965 operand rax_RegP()
  4966 %{
  4967   constraint(ALLOC_IN_RC(ptr_rax_reg));
  4968   match(RegP);
  4969   match(rRegP);
  4971   format %{ %}
  4972   interface(REG_INTER);
  4973 %}
  4975 // Special Registers
  4976 // Return a compressed pointer value
  4977 operand rax_RegN()
  4978 %{
  4979   constraint(ALLOC_IN_RC(int_rax_reg));
  4980   match(RegN);
  4981   match(rRegN);
  4983   format %{ %}
  4984   interface(REG_INTER);
  4985 %}
  4987 // Used in AtomicAdd
  4988 operand rbx_RegP()
  4989 %{
  4990   constraint(ALLOC_IN_RC(ptr_rbx_reg));
  4991   match(RegP);
  4992   match(rRegP);
  4994   format %{ %}
  4995   interface(REG_INTER);
  4996 %}
  4998 operand rsi_RegP()
  4999 %{
  5000   constraint(ALLOC_IN_RC(ptr_rsi_reg));
  5001   match(RegP);
  5002   match(rRegP);
  5004   format %{ %}
  5005   interface(REG_INTER);
  5006 %}
  5008 // Used in rep stosq
  5009 operand rdi_RegP()
  5010 %{
  5011   constraint(ALLOC_IN_RC(ptr_rdi_reg));
  5012   match(RegP);
  5013   match(rRegP);
  5015   format %{ %}
  5016   interface(REG_INTER);
  5017 %}
  5019 operand rbp_RegP()
  5020 %{
  5021   constraint(ALLOC_IN_RC(ptr_rbp_reg));
  5022   match(RegP);
  5023   match(rRegP);
  5025   format %{ %}
  5026   interface(REG_INTER);
  5027 %}
  5029 operand r15_RegP()
  5030 %{
  5031   constraint(ALLOC_IN_RC(ptr_r15_reg));
  5032   match(RegP);
  5033   match(rRegP);
  5035   format %{ %}
  5036   interface(REG_INTER);
  5037 %}
  5039 operand rRegL()
  5040 %{
  5041   constraint(ALLOC_IN_RC(long_reg));
  5042   match(RegL);
  5043   match(rax_RegL);
  5044   match(rdx_RegL);
  5046   format %{ %}
  5047   interface(REG_INTER);
  5048 %}
  5050 // Special Registers
  5051 operand no_rax_rdx_RegL()
  5052 %{
  5053   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
  5054   match(RegL);
  5055   match(rRegL);
  5057   format %{ %}
  5058   interface(REG_INTER);
  5059 %}
  5061 operand no_rax_RegL()
  5062 %{
  5063   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
  5064   match(RegL);
  5065   match(rRegL);
  5066   match(rdx_RegL);
  5068   format %{ %}
  5069   interface(REG_INTER);
  5070 %}
  5072 operand no_rcx_RegL()
  5073 %{
  5074   constraint(ALLOC_IN_RC(long_no_rcx_reg));
  5075   match(RegL);
  5076   match(rRegL);
  5078   format %{ %}
  5079   interface(REG_INTER);
  5080 %}
  5082 operand rax_RegL()
  5083 %{
  5084   constraint(ALLOC_IN_RC(long_rax_reg));
  5085   match(RegL);
  5086   match(rRegL);
  5088   format %{ "RAX" %}
  5089   interface(REG_INTER);
  5090 %}
  5092 operand rcx_RegL()
  5093 %{
  5094   constraint(ALLOC_IN_RC(long_rcx_reg));
  5095   match(RegL);
  5096   match(rRegL);
  5098   format %{ %}
  5099   interface(REG_INTER);
  5100 %}
  5102 operand rdx_RegL()
  5103 %{
  5104   constraint(ALLOC_IN_RC(long_rdx_reg));
  5105   match(RegL);
  5106   match(rRegL);
  5108   format %{ %}
  5109   interface(REG_INTER);
  5110 %}
  5112 // Flags register, used as output of compare instructions
  5113 operand rFlagsReg()
  5114 %{
  5115   constraint(ALLOC_IN_RC(int_flags));
  5116   match(RegFlags);
  5118   format %{ "RFLAGS" %}
  5119   interface(REG_INTER);
  5120 %}
  5122 // Flags register, used as output of FLOATING POINT compare instructions
  5123 operand rFlagsRegU()
  5124 %{
  5125   constraint(ALLOC_IN_RC(int_flags));
  5126   match(RegFlags);
  5128   format %{ "RFLAGS_U" %}
  5129   interface(REG_INTER);
  5130 %}
  5132 // Float register operands
  5133 operand regF()
  5134 %{
  5135   constraint(ALLOC_IN_RC(float_reg));
  5136   match(RegF);
  5138   format %{ %}
  5139   interface(REG_INTER);
  5140 %}
  5142 // Double register operands
  5143 operand regD()
  5144 %{
  5145   constraint(ALLOC_IN_RC(double_reg));
  5146   match(RegD);
  5148   format %{ %}
  5149   interface(REG_INTER);
  5150 %}
  5153 //----------Memory Operands----------------------------------------------------
  5154 // Direct Memory Operand
  5155 // operand direct(immP addr)
  5156 // %{
  5157 //   match(addr);
  5159 //   format %{ "[$addr]" %}
  5160 //   interface(MEMORY_INTER) %{
  5161 //     base(0xFFFFFFFF);
  5162 //     index(0x4);
  5163 //     scale(0x0);
  5164 //     disp($addr);
  5165 //   %}
  5166 // %}
  5168 // Indirect Memory Operand
  5169 operand indirect(any_RegP reg)
  5170 %{
  5171   constraint(ALLOC_IN_RC(ptr_reg));
  5172   match(reg);
  5174   format %{ "[$reg]" %}
  5175   interface(MEMORY_INTER) %{
  5176     base($reg);
  5177     index(0x4);
  5178     scale(0x0);
  5179     disp(0x0);
  5180   %}
  5181 %}
  5183 // Indirect Memory Plus Short Offset Operand
  5184 operand indOffset8(any_RegP reg, immL8 off)
  5185 %{
  5186   constraint(ALLOC_IN_RC(ptr_reg));
  5187   match(AddP reg off);
  5189   format %{ "[$reg + $off (8-bit)]" %}
  5190   interface(MEMORY_INTER) %{
  5191     base($reg);
  5192     index(0x4);
  5193     scale(0x0);
  5194     disp($off);
  5195   %}
  5196 %}
  5198 // Indirect Memory Plus Long Offset Operand
  5199 operand indOffset32(any_RegP reg, immL32 off)
  5200 %{
  5201   constraint(ALLOC_IN_RC(ptr_reg));
  5202   match(AddP reg off);
  5204   format %{ "[$reg + $off (32-bit)]" %}
  5205   interface(MEMORY_INTER) %{
  5206     base($reg);
  5207     index(0x4);
  5208     scale(0x0);
  5209     disp($off);
  5210   %}
  5211 %}
  5213 // Indirect Memory Plus Index Register Plus Offset Operand
  5214 operand indIndexOffset(any_RegP reg, rRegL lreg, immL32 off)
  5215 %{
  5216   constraint(ALLOC_IN_RC(ptr_reg));
  5217   match(AddP (AddP reg lreg) off);
  5219   op_cost(10);
  5220   format %{"[$reg + $off + $lreg]" %}
  5221   interface(MEMORY_INTER) %{
  5222     base($reg);
  5223     index($lreg);
  5224     scale(0x0);
  5225     disp($off);
  5226   %}
  5227 %}
  5229 // Indirect Memory Plus Index Register Plus Offset Operand
  5230 operand indIndex(any_RegP reg, rRegL lreg)
  5231 %{
  5232   constraint(ALLOC_IN_RC(ptr_reg));
  5233   match(AddP reg lreg);
  5235   op_cost(10);
  5236   format %{"[$reg + $lreg]" %}
  5237   interface(MEMORY_INTER) %{
  5238     base($reg);
  5239     index($lreg);
  5240     scale(0x0);
  5241     disp(0x0);
  5242   %}
  5243 %}
  5245 // Indirect Memory Times Scale Plus Index Register
  5246 operand indIndexScale(any_RegP reg, rRegL lreg, immI2 scale)
  5247 %{
  5248   constraint(ALLOC_IN_RC(ptr_reg));
  5249   match(AddP reg (LShiftL lreg scale));
  5251   op_cost(10);
  5252   format %{"[$reg + $lreg << $scale]" %}
  5253   interface(MEMORY_INTER) %{
  5254     base($reg);
  5255     index($lreg);
  5256     scale($scale);
  5257     disp(0x0);
  5258   %}
  5259 %}
  5261 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
  5262 operand indIndexScaleOffset(any_RegP reg, immL32 off, rRegL lreg, immI2 scale)
  5263 %{
  5264   constraint(ALLOC_IN_RC(ptr_reg));
  5265   match(AddP (AddP reg (LShiftL lreg scale)) off);
  5267   op_cost(10);
  5268   format %{"[$reg + $off + $lreg << $scale]" %}
  5269   interface(MEMORY_INTER) %{
  5270     base($reg);
  5271     index($lreg);
  5272     scale($scale);
  5273     disp($off);
  5274   %}
  5275 %}
  5277 // Indirect Narrow Oop Plus Offset Operand
  5278 operand indNarrowOopOffset(rRegN src, immL32 off) %{
  5279   constraint(ALLOC_IN_RC(ptr_reg));
  5280   match(AddP (DecodeN src) off);
  5282   op_cost(10);
  5283   format %{"[R12 + $src << 3 + $off] (compressed oop addressing)" %}
  5284   interface(MEMORY_INTER) %{
  5285     base(0xc); // R12
  5286     index($src);
  5287     scale(0x3);
  5288     disp($off);
  5289   %}
  5290 %}
  5292 // Indirect Memory Times Scale Plus Positive Index Register Plus Offset Operand
  5293 operand indPosIndexScaleOffset(any_RegP reg, immL32 off, rRegI idx, immI2 scale)
  5294 %{
  5295   constraint(ALLOC_IN_RC(ptr_reg));
  5296   predicate(n->in(2)->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
  5297   match(AddP (AddP reg (LShiftL (ConvI2L idx) scale)) off);
  5299   op_cost(10);
  5300   format %{"[$reg + $off + $idx << $scale]" %}
  5301   interface(MEMORY_INTER) %{
  5302     base($reg);
  5303     index($idx);
  5304     scale($scale);
  5305     disp($off);
  5306   %}
  5307 %}
  5309 //----------Special Memory Operands--------------------------------------------
  5310 // Stack Slot Operand - This operand is used for loading and storing temporary
  5311 //                      values on the stack where a match requires a value to
  5312 //                      flow through memory.
  5313 operand stackSlotP(sRegP reg)
  5314 %{
  5315   constraint(ALLOC_IN_RC(stack_slots));
  5316   // No match rule because this operand is only generated in matching
  5318   format %{ "[$reg]" %}
  5319   interface(MEMORY_INTER) %{
  5320     base(0x4);   // RSP
  5321     index(0x4);  // No Index
  5322     scale(0x0);  // No Scale
  5323     disp($reg);  // Stack Offset
  5324   %}
  5325 %}
  5327 operand stackSlotI(sRegI reg)
  5328 %{
  5329   constraint(ALLOC_IN_RC(stack_slots));
  5330   // No match rule because this operand is only generated in matching
  5332   format %{ "[$reg]" %}
  5333   interface(MEMORY_INTER) %{
  5334     base(0x4);   // RSP
  5335     index(0x4);  // No Index
  5336     scale(0x0);  // No Scale
  5337     disp($reg);  // Stack Offset
  5338   %}
  5339 %}
  5341 operand stackSlotF(sRegF reg)
  5342 %{
  5343   constraint(ALLOC_IN_RC(stack_slots));
  5344   // No match rule because this operand is only generated in matching
  5346   format %{ "[$reg]" %}
  5347   interface(MEMORY_INTER) %{
  5348     base(0x4);   // RSP
  5349     index(0x4);  // No Index
  5350     scale(0x0);  // No Scale
  5351     disp($reg);  // Stack Offset
  5352   %}
  5353 %}
  5355 operand stackSlotD(sRegD reg)
  5356 %{
  5357   constraint(ALLOC_IN_RC(stack_slots));
  5358   // No match rule because this operand is only generated in matching
  5360   format %{ "[$reg]" %}
  5361   interface(MEMORY_INTER) %{
  5362     base(0x4);   // RSP
  5363     index(0x4);  // No Index
  5364     scale(0x0);  // No Scale
  5365     disp($reg);  // Stack Offset
  5366   %}
  5367 %}
  5368 operand stackSlotL(sRegL reg)
  5369 %{
  5370   constraint(ALLOC_IN_RC(stack_slots));
  5371   // No match rule because this operand is only generated in matching
  5373   format %{ "[$reg]" %}
  5374   interface(MEMORY_INTER) %{
  5375     base(0x4);   // RSP
  5376     index(0x4);  // No Index
  5377     scale(0x0);  // No Scale
  5378     disp($reg);  // Stack Offset
  5379   %}
  5380 %}
  5382 //----------Conditional Branch Operands----------------------------------------
  5383 // Comparison Op  - This is the operation of the comparison, and is limited to
  5384 //                  the following set of codes:
  5385 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
  5386 //
  5387 // Other attributes of the comparison, such as unsignedness, are specified
  5388 // by the comparison instruction that sets a condition code flags register.
  5389 // That result is represented by a flags operand whose subtype is appropriate
  5390 // to the unsignedness (etc.) of the comparison.
  5391 //
  5392 // Later, the instruction which matches both the Comparison Op (a Bool) and
  5393 // the flags (produced by the Cmp) specifies the coding of the comparison op
  5394 // by matching a specific subtype of Bool operand below, such as cmpOpU.
  5396 // Comparision Code
  5397 operand cmpOp()
  5398 %{
  5399   match(Bool);
  5401   format %{ "" %}
  5402   interface(COND_INTER) %{
  5403     equal(0x4);
  5404     not_equal(0x5);
  5405     less(0xC);
  5406     greater_equal(0xD);
  5407     less_equal(0xE);
  5408     greater(0xF);
  5409   %}
  5410 %}
  5412 // Comparison Code, unsigned compare.  Used by FP also, with
  5413 // C2 (unordered) turned into GT or LT already.  The other bits
  5414 // C0 and C3 are turned into Carry & Zero flags.
  5415 operand cmpOpU()
  5416 %{
  5417   match(Bool);
  5419   format %{ "" %}
  5420   interface(COND_INTER) %{
  5421     equal(0x4);
  5422     not_equal(0x5);
  5423     less(0x2);
  5424     greater_equal(0x3);
  5425     less_equal(0x6);
  5426     greater(0x7);
  5427   %}
  5428 %}
  5431 //----------OPERAND CLASSES----------------------------------------------------
  5432 // Operand Classes are groups of operands that are used as to simplify
  5433 // instruction definitions by not requiring the AD writer to specify seperate
  5434 // instructions for every form of operand when the instruction accepts
  5435 // multiple operand types with the same basic encoding and format.  The classic
  5436 // case of this is memory operands.
  5438 opclass memory(indirect, indOffset8, indOffset32, indIndexOffset, indIndex,
  5439                indIndexScale, indIndexScaleOffset, indPosIndexScaleOffset,
  5440                indNarrowOopOffset);
  5442 //----------PIPELINE-----------------------------------------------------------
  5443 // Rules which define the behavior of the target architectures pipeline.
  5444 pipeline %{
  5446 //----------ATTRIBUTES---------------------------------------------------------
  5447 attributes %{
  5448   variable_size_instructions;        // Fixed size instructions
  5449   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
  5450   instruction_unit_size = 1;         // An instruction is 1 bytes long
  5451   instruction_fetch_unit_size = 16;  // The processor fetches one line
  5452   instruction_fetch_units = 1;       // of 16 bytes
  5454   // List of nop instructions
  5455   nops( MachNop );
  5456 %}
  5458 //----------RESOURCES----------------------------------------------------------
  5459 // Resources are the functional units available to the machine
  5461 // Generic P2/P3 pipeline
  5462 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
  5463 // 3 instructions decoded per cycle.
  5464 // 2 load/store ops per cycle, 1 branch, 1 FPU,
  5465 // 3 ALU op, only ALU0 handles mul instructions.
  5466 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
  5467            MS0, MS1, MS2, MEM = MS0 | MS1 | MS2,
  5468            BR, FPU,
  5469            ALU0, ALU1, ALU2, ALU = ALU0 | ALU1 | ALU2);
  5471 //----------PIPELINE DESCRIPTION-----------------------------------------------
  5472 // Pipeline Description specifies the stages in the machine's pipeline
  5474 // Generic P2/P3 pipeline
  5475 pipe_desc(S0, S1, S2, S3, S4, S5);
  5477 //----------PIPELINE CLASSES---------------------------------------------------
  5478 // Pipeline Classes describe the stages in which input and output are
  5479 // referenced by the hardware pipeline.
  5481 // Naming convention: ialu or fpu
  5482 // Then: _reg
  5483 // Then: _reg if there is a 2nd register
  5484 // Then: _long if it's a pair of instructions implementing a long
  5485 // Then: _fat if it requires the big decoder
  5486 //   Or: _mem if it requires the big decoder and a memory unit.
  5488 // Integer ALU reg operation
  5489 pipe_class ialu_reg(rRegI dst)
  5490 %{
  5491     single_instruction;
  5492     dst    : S4(write);
  5493     dst    : S3(read);
  5494     DECODE : S0;        // any decoder
  5495     ALU    : S3;        // any alu
  5496 %}
  5498 // Long ALU reg operation
  5499 pipe_class ialu_reg_long(rRegL dst)
  5500 %{
  5501     instruction_count(2);
  5502     dst    : S4(write);
  5503     dst    : S3(read);
  5504     DECODE : S0(2);     // any 2 decoders
  5505     ALU    : S3(2);     // both alus
  5506 %}
  5508 // Integer ALU reg operation using big decoder
  5509 pipe_class ialu_reg_fat(rRegI dst)
  5510 %{
  5511     single_instruction;
  5512     dst    : S4(write);
  5513     dst    : S3(read);
  5514     D0     : S0;        // big decoder only
  5515     ALU    : S3;        // any alu
  5516 %}
  5518 // Long ALU reg operation using big decoder
  5519 pipe_class ialu_reg_long_fat(rRegL dst)
  5520 %{
  5521     instruction_count(2);
  5522     dst    : S4(write);
  5523     dst    : S3(read);
  5524     D0     : S0(2);     // big decoder only; twice
  5525     ALU    : S3(2);     // any 2 alus
  5526 %}
  5528 // Integer ALU reg-reg operation
  5529 pipe_class ialu_reg_reg(rRegI dst, rRegI src)
  5530 %{
  5531     single_instruction;
  5532     dst    : S4(write);
  5533     src    : S3(read);
  5534     DECODE : S0;        // any decoder
  5535     ALU    : S3;        // any alu
  5536 %}
  5538 // Long ALU reg-reg operation
  5539 pipe_class ialu_reg_reg_long(rRegL dst, rRegL src)
  5540 %{
  5541     instruction_count(2);
  5542     dst    : S4(write);
  5543     src    : S3(read);
  5544     DECODE : S0(2);     // any 2 decoders
  5545     ALU    : S3(2);     // both alus
  5546 %}
  5548 // Integer ALU reg-reg operation
  5549 pipe_class ialu_reg_reg_fat(rRegI dst, memory src)
  5550 %{
  5551     single_instruction;
  5552     dst    : S4(write);
  5553     src    : S3(read);
  5554     D0     : S0;        // big decoder only
  5555     ALU    : S3;        // any alu
  5556 %}
  5558 // Long ALU reg-reg operation
  5559 pipe_class ialu_reg_reg_long_fat(rRegL dst, rRegL src)
  5560 %{
  5561     instruction_count(2);
  5562     dst    : S4(write);
  5563     src    : S3(read);
  5564     D0     : S0(2);     // big decoder only; twice
  5565     ALU    : S3(2);     // both alus
  5566 %}
  5568 // Integer ALU reg-mem operation
  5569 pipe_class ialu_reg_mem(rRegI dst, memory mem)
  5570 %{
  5571     single_instruction;
  5572     dst    : S5(write);
  5573     mem    : S3(read);
  5574     D0     : S0;        // big decoder only
  5575     ALU    : S4;        // any alu
  5576     MEM    : S3;        // any mem
  5577 %}
  5579 // Integer mem operation (prefetch)
  5580 pipe_class ialu_mem(memory mem)
  5581 %{
  5582     single_instruction;
  5583     mem    : S3(read);
  5584     D0     : S0;        // big decoder only
  5585     MEM    : S3;        // any mem
  5586 %}
  5588 // Integer Store to Memory
  5589 pipe_class ialu_mem_reg(memory mem, rRegI src)
  5590 %{
  5591     single_instruction;
  5592     mem    : S3(read);
  5593     src    : S5(read);
  5594     D0     : S0;        // big decoder only
  5595     ALU    : S4;        // any alu
  5596     MEM    : S3;
  5597 %}
  5599 // // Long Store to Memory
  5600 // pipe_class ialu_mem_long_reg(memory mem, rRegL src)
  5601 // %{
  5602 //     instruction_count(2);
  5603 //     mem    : S3(read);
  5604 //     src    : S5(read);
  5605 //     D0     : S0(2);          // big decoder only; twice
  5606 //     ALU    : S4(2);     // any 2 alus
  5607 //     MEM    : S3(2);  // Both mems
  5608 // %}
  5610 // Integer Store to Memory
  5611 pipe_class ialu_mem_imm(memory mem)
  5612 %{
  5613     single_instruction;
  5614     mem    : S3(read);
  5615     D0     : S0;        // big decoder only
  5616     ALU    : S4;        // any alu
  5617     MEM    : S3;
  5618 %}
  5620 // Integer ALU0 reg-reg operation
  5621 pipe_class ialu_reg_reg_alu0(rRegI dst, rRegI src)
  5622 %{
  5623     single_instruction;
  5624     dst    : S4(write);
  5625     src    : S3(read);
  5626     D0     : S0;        // Big decoder only
  5627     ALU0   : S3;        // only alu0
  5628 %}
  5630 // Integer ALU0 reg-mem operation
  5631 pipe_class ialu_reg_mem_alu0(rRegI dst, memory mem)
  5632 %{
  5633     single_instruction;
  5634     dst    : S5(write);
  5635     mem    : S3(read);
  5636     D0     : S0;        // big decoder only
  5637     ALU0   : S4;        // ALU0 only
  5638     MEM    : S3;        // any mem
  5639 %}
  5641 // Integer ALU reg-reg operation
  5642 pipe_class ialu_cr_reg_reg(rFlagsReg cr, rRegI src1, rRegI src2)
  5643 %{
  5644     single_instruction;
  5645     cr     : S4(write);
  5646     src1   : S3(read);
  5647     src2   : S3(read);
  5648     DECODE : S0;        // any decoder
  5649     ALU    : S3;        // any alu
  5650 %}
  5652 // Integer ALU reg-imm operation
  5653 pipe_class ialu_cr_reg_imm(rFlagsReg cr, rRegI src1)
  5654 %{
  5655     single_instruction;
  5656     cr     : S4(write);
  5657     src1   : S3(read);
  5658     DECODE : S0;        // any decoder
  5659     ALU    : S3;        // any alu
  5660 %}
  5662 // Integer ALU reg-mem operation
  5663 pipe_class ialu_cr_reg_mem(rFlagsReg cr, rRegI src1, memory src2)
  5664 %{
  5665     single_instruction;
  5666     cr     : S4(write);
  5667     src1   : S3(read);
  5668     src2   : S3(read);
  5669     D0     : S0;        // big decoder only
  5670     ALU    : S4;        // any alu
  5671     MEM    : S3;
  5672 %}
  5674 // Conditional move reg-reg
  5675 pipe_class pipe_cmplt( rRegI p, rRegI q, rRegI y)
  5676 %{
  5677     instruction_count(4);
  5678     y      : S4(read);
  5679     q      : S3(read);
  5680     p      : S3(read);
  5681     DECODE : S0(4);     // any decoder
  5682 %}
  5684 // Conditional move reg-reg
  5685 pipe_class pipe_cmov_reg( rRegI dst, rRegI src, rFlagsReg cr)
  5686 %{
  5687     single_instruction;
  5688     dst    : S4(write);
  5689     src    : S3(read);
  5690     cr     : S3(read);
  5691     DECODE : S0;        // any decoder
  5692 %}
  5694 // Conditional move reg-mem
  5695 pipe_class pipe_cmov_mem( rFlagsReg cr, rRegI dst, memory src)
  5696 %{
  5697     single_instruction;
  5698     dst    : S4(write);
  5699     src    : S3(read);
  5700     cr     : S3(read);
  5701     DECODE : S0;        // any decoder
  5702     MEM    : S3;
  5703 %}
  5705 // Conditional move reg-reg long
  5706 pipe_class pipe_cmov_reg_long( rFlagsReg cr, rRegL dst, rRegL src)
  5707 %{
  5708     single_instruction;
  5709     dst    : S4(write);
  5710     src    : S3(read);
  5711     cr     : S3(read);
  5712     DECODE : S0(2);     // any 2 decoders
  5713 %}
  5715 // XXX
  5716 // // Conditional move double reg-reg
  5717 // pipe_class pipe_cmovD_reg( rFlagsReg cr, regDPR1 dst, regD src)
  5718 // %{
  5719 //     single_instruction;
  5720 //     dst    : S4(write);
  5721 //     src    : S3(read);
  5722 //     cr     : S3(read);
  5723 //     DECODE : S0;     // any decoder
  5724 // %}
  5726 // Float reg-reg operation
  5727 pipe_class fpu_reg(regD dst)
  5728 %{
  5729     instruction_count(2);
  5730     dst    : S3(read);
  5731     DECODE : S0(2);     // any 2 decoders
  5732     FPU    : S3;
  5733 %}
  5735 // Float reg-reg operation
  5736 pipe_class fpu_reg_reg(regD dst, regD src)
  5737 %{
  5738     instruction_count(2);
  5739     dst    : S4(write);
  5740     src    : S3(read);
  5741     DECODE : S0(2);     // any 2 decoders
  5742     FPU    : S3;
  5743 %}
  5745 // Float reg-reg operation
  5746 pipe_class fpu_reg_reg_reg(regD dst, regD src1, regD src2)
  5747 %{
  5748     instruction_count(3);
  5749     dst    : S4(write);
  5750     src1   : S3(read);
  5751     src2   : S3(read);
  5752     DECODE : S0(3);     // any 3 decoders
  5753     FPU    : S3(2);
  5754 %}
  5756 // Float reg-reg operation
  5757 pipe_class fpu_reg_reg_reg_reg(regD dst, regD src1, regD src2, regD src3)
  5758 %{
  5759     instruction_count(4);
  5760     dst    : S4(write);
  5761     src1   : S3(read);
  5762     src2   : S3(read);
  5763     src3   : S3(read);
  5764     DECODE : S0(4);     // any 3 decoders
  5765     FPU    : S3(2);
  5766 %}
  5768 // Float reg-reg operation
  5769 pipe_class fpu_reg_mem_reg_reg(regD dst, memory src1, regD src2, regD src3)
  5770 %{
  5771     instruction_count(4);
  5772     dst    : S4(write);
  5773     src1   : S3(read);
  5774     src2   : S3(read);
  5775     src3   : S3(read);
  5776     DECODE : S1(3);     // any 3 decoders
  5777     D0     : S0;        // Big decoder only
  5778     FPU    : S3(2);
  5779     MEM    : S3;
  5780 %}
  5782 // Float reg-mem operation
  5783 pipe_class fpu_reg_mem(regD dst, memory mem)
  5784 %{
  5785     instruction_count(2);
  5786     dst    : S5(write);
  5787     mem    : S3(read);
  5788     D0     : S0;        // big decoder only
  5789     DECODE : S1;        // any decoder for FPU POP
  5790     FPU    : S4;
  5791     MEM    : S3;        // any mem
  5792 %}
  5794 // Float reg-mem operation
  5795 pipe_class fpu_reg_reg_mem(regD dst, regD src1, memory mem)
  5796 %{
  5797     instruction_count(3);
  5798     dst    : S5(write);
  5799     src1   : S3(read);
  5800     mem    : S3(read);
  5801     D0     : S0;        // big decoder only
  5802     DECODE : S1(2);     // any decoder for FPU POP
  5803     FPU    : S4;
  5804     MEM    : S3;        // any mem
  5805 %}
  5807 // Float mem-reg operation
  5808 pipe_class fpu_mem_reg(memory mem, regD src)
  5809 %{
  5810     instruction_count(2);
  5811     src    : S5(read);
  5812     mem    : S3(read);
  5813     DECODE : S0;        // any decoder for FPU PUSH
  5814     D0     : S1;        // big decoder only
  5815     FPU    : S4;
  5816     MEM    : S3;        // any mem
  5817 %}
  5819 pipe_class fpu_mem_reg_reg(memory mem, regD src1, regD src2)
  5820 %{
  5821     instruction_count(3);
  5822     src1   : S3(read);
  5823     src2   : S3(read);
  5824     mem    : S3(read);
  5825     DECODE : S0(2);     // any decoder for FPU PUSH
  5826     D0     : S1;        // big decoder only
  5827     FPU    : S4;
  5828     MEM    : S3;        // any mem
  5829 %}
  5831 pipe_class fpu_mem_reg_mem(memory mem, regD src1, memory src2)
  5832 %{
  5833     instruction_count(3);
  5834     src1   : S3(read);
  5835     src2   : S3(read);
  5836     mem    : S4(read);
  5837     DECODE : S0;        // any decoder for FPU PUSH
  5838     D0     : S0(2);     // big decoder only
  5839     FPU    : S4;
  5840     MEM    : S3(2);     // any mem
  5841 %}
  5843 pipe_class fpu_mem_mem(memory dst, memory src1)
  5844 %{
  5845     instruction_count(2);
  5846     src1   : S3(read);
  5847     dst    : S4(read);
  5848     D0     : S0(2);     // big decoder only
  5849     MEM    : S3(2);     // any mem
  5850 %}
  5852 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2)
  5853 %{
  5854     instruction_count(3);
  5855     src1   : S3(read);
  5856     src2   : S3(read);
  5857     dst    : S4(read);
  5858     D0     : S0(3);     // big decoder only
  5859     FPU    : S4;
  5860     MEM    : S3(3);     // any mem
  5861 %}
  5863 pipe_class fpu_mem_reg_con(memory mem, regD src1)
  5864 %{
  5865     instruction_count(3);
  5866     src1   : S4(read);
  5867     mem    : S4(read);
  5868     DECODE : S0;        // any decoder for FPU PUSH
  5869     D0     : S0(2);     // big decoder only
  5870     FPU    : S4;
  5871     MEM    : S3(2);     // any mem
  5872 %}
  5874 // Float load constant
  5875 pipe_class fpu_reg_con(regD dst)
  5876 %{
  5877     instruction_count(2);
  5878     dst    : S5(write);
  5879     D0     : S0;        // big decoder only for the load
  5880     DECODE : S1;        // any decoder for FPU POP
  5881     FPU    : S4;
  5882     MEM    : S3;        // any mem
  5883 %}
  5885 // Float load constant
  5886 pipe_class fpu_reg_reg_con(regD dst, regD src)
  5887 %{
  5888     instruction_count(3);
  5889     dst    : S5(write);
  5890     src    : S3(read);
  5891     D0     : S0;        // big decoder only for the load
  5892     DECODE : S1(2);     // any decoder for FPU POP
  5893     FPU    : S4;
  5894     MEM    : S3;        // any mem
  5895 %}
  5897 // UnConditional branch
  5898 pipe_class pipe_jmp(label labl)
  5899 %{
  5900     single_instruction;
  5901     BR   : S3;
  5902 %}
  5904 // Conditional branch
  5905 pipe_class pipe_jcc(cmpOp cmp, rFlagsReg cr, label labl)
  5906 %{
  5907     single_instruction;
  5908     cr    : S1(read);
  5909     BR    : S3;
  5910 %}
  5912 // Allocation idiom
  5913 pipe_class pipe_cmpxchg(rRegP dst, rRegP heap_ptr)
  5914 %{
  5915     instruction_count(1); force_serialization;
  5916     fixed_latency(6);
  5917     heap_ptr : S3(read);
  5918     DECODE   : S0(3);
  5919     D0       : S2;
  5920     MEM      : S3;
  5921     ALU      : S3(2);
  5922     dst      : S5(write);
  5923     BR       : S5;
  5924 %}
  5926 // Generic big/slow expanded idiom
  5927 pipe_class pipe_slow()
  5928 %{
  5929     instruction_count(10); multiple_bundles; force_serialization;
  5930     fixed_latency(100);
  5931     D0  : S0(2);
  5932     MEM : S3(2);
  5933 %}
  5935 // The real do-nothing guy
  5936 pipe_class empty()
  5937 %{
  5938     instruction_count(0);
  5939 %}
  5941 // Define the class for the Nop node
  5942 define
  5943 %{
  5944    MachNop = empty;
  5945 %}
  5947 %}
  5949 //----------INSTRUCTIONS-------------------------------------------------------
  5950 //
  5951 // match      -- States which machine-independent subtree may be replaced
  5952 //               by this instruction.
  5953 // ins_cost   -- The estimated cost of this instruction is used by instruction
  5954 //               selection to identify a minimum cost tree of machine
  5955 //               instructions that matches a tree of machine-independent
  5956 //               instructions.
  5957 // format     -- A string providing the disassembly for this instruction.
  5958 //               The value of an instruction's operand may be inserted
  5959 //               by referring to it with a '$' prefix.
  5960 // opcode     -- Three instruction opcodes may be provided.  These are referred
  5961 //               to within an encode class as $primary, $secondary, and $tertiary
  5962 //               rrspectively.  The primary opcode is commonly used to
  5963 //               indicate the type of machine instruction, while secondary
  5964 //               and tertiary are often used for prefix options or addressing
  5965 //               modes.
  5966 // ins_encode -- A list of encode classes with parameters. The encode class
  5967 //               name must have been defined in an 'enc_class' specification
  5968 //               in the encode section of the architecture description.
  5971 //----------Load/Store/Move Instructions---------------------------------------
  5972 //----------Load Instructions--------------------------------------------------
  5974 // Load Byte (8 bit signed)
  5975 instruct loadB(rRegI dst, memory mem)
  5976 %{
  5977   match(Set dst (LoadB mem));
  5979   ins_cost(125);
  5980   format %{ "movsbl  $dst, $mem\t# byte" %}
  5981   opcode(0x0F, 0xBE);
  5982   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  5983   ins_pipe(ialu_reg_mem);
  5984 %}
  5986 // Load Byte (8 bit signed) into long
  5987 // instruct loadB2L(rRegL dst, memory mem)
  5988 // %{
  5989 //   match(Set dst (ConvI2L (LoadB mem)));
  5991 //   ins_cost(125);
  5992 //   format %{ "movsbq  $dst, $mem\t# byte -> long" %}
  5993 //   opcode(0x0F, 0xBE);
  5994 //   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  5995 //   ins_pipe(ialu_reg_mem);
  5996 // %}
  5998 // Load Byte (8 bit UNsigned)
  5999 instruct loadUB(rRegI dst, memory mem, immI_255 bytemask)
  6000 %{
  6001   match(Set dst (AndI (LoadB mem) bytemask));
  6003   ins_cost(125);
  6004   format %{ "movzbl  $dst, $mem\t# ubyte" %}
  6005   opcode(0x0F, 0xB6);
  6006   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6007   ins_pipe(ialu_reg_mem);
  6008 %}
  6010 // Load Byte (8 bit UNsigned) into long
  6011 // instruct loadUB2L(rRegL dst, memory mem, immI_255 bytemask)
  6012 // %{
  6013 //   match(Set dst (ConvI2L (AndI (LoadB mem) bytemask)));
  6015 //   ins_cost(125);
  6016 //   format %{ "movzbl  $dst, $mem\t# ubyte -> long" %}
  6017 //   opcode(0x0F, 0xB6);
  6018 //   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6019 //   ins_pipe(ialu_reg_mem);
  6020 // %}
  6022 // Load Short (16 bit signed)
  6023 instruct loadS(rRegI dst, memory mem)
  6024 %{
  6025   match(Set dst (LoadS mem));
  6027   ins_cost(125); // XXX
  6028   format %{ "movswl $dst, $mem\t# short" %}
  6029   opcode(0x0F, 0xBF);
  6030   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6031   ins_pipe(ialu_reg_mem);
  6032 %}
  6034 // Load Short (16 bit signed) into long
  6035 // instruct loadS2L(rRegL dst, memory mem)
  6036 // %{
  6037 //   match(Set dst (ConvI2L (LoadS mem)));
  6039 //   ins_cost(125); // XXX
  6040 //   format %{ "movswq $dst, $mem\t# short -> long" %}
  6041 //   opcode(0x0F, 0xBF);
  6042 //   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6043 //   ins_pipe(ialu_reg_mem);
  6044 // %}
  6046 // Load Char (16 bit UNsigned)
  6047 instruct loadC(rRegI dst, memory mem)
  6048 %{
  6049   match(Set dst (LoadC mem));
  6051   ins_cost(125);
  6052   format %{ "movzwl  $dst, $mem\t# char" %}
  6053   opcode(0x0F, 0xB7);
  6054   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6055   ins_pipe(ialu_reg_mem);
  6056 %}
  6058 // Load Char (16 bit UNsigned) into long
  6059 // instruct loadC2L(rRegL dst, memory mem)
  6060 // %{
  6061 //   match(Set dst (ConvI2L (LoadC mem)));
  6063 //   ins_cost(125);
  6064 //   format %{ "movzwl  $dst, $mem\t# char -> long" %}
  6065 //   opcode(0x0F, 0xB7);
  6066 //   ins_encode(REX_reg_mem(dst, mem), OpcP, OpcS, reg_mem(dst, mem));
  6067 //   ins_pipe(ialu_reg_mem);
  6068 // %}
  6070 // Load Integer
  6071 instruct loadI(rRegI dst, memory mem)
  6072 %{
  6073   match(Set dst (LoadI mem));
  6075   ins_cost(125); // XXX
  6076   format %{ "movl    $dst, $mem\t# int" %}
  6077   opcode(0x8B);
  6078   ins_encode(REX_reg_mem(dst, mem), OpcP, reg_mem(dst, mem));
  6079   ins_pipe(ialu_reg_mem);
  6080 %}
  6082 // Load Long
  6083 instruct loadL(rRegL dst, memory mem)
  6084 %{
  6085   match(Set dst (LoadL mem));
  6087   ins_cost(125); // XXX
  6088   format %{ "movq    $dst, $mem\t# long" %}
  6089   opcode(0x8B);
  6090   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6091   ins_pipe(ialu_reg_mem); // XXX
  6092 %}
  6094 // Load Range
  6095 instruct loadRange(rRegI dst, memory mem)
  6096 %{
  6097   match(Set dst (LoadRange mem));
  6099   ins_cost(125); // XXX
  6100   format %{ "movl    $dst, $mem\t# range" %}
  6101   opcode(0x8B);
  6102   ins_encode(REX_reg_mem(dst, mem), OpcP, reg_mem(dst, mem));
  6103   ins_pipe(ialu_reg_mem);
  6104 %}
  6106 // Load Pointer
  6107 instruct loadP(rRegP dst, memory mem)
  6108 %{
  6109   match(Set dst (LoadP mem));
  6111   ins_cost(125); // XXX
  6112   format %{ "movq    $dst, $mem\t# ptr" %}
  6113   opcode(0x8B);
  6114   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6115   ins_pipe(ialu_reg_mem); // XXX
  6116 %}
  6118 // Load Compressed Pointer
  6119 instruct loadN(rRegN dst, memory mem)
  6120 %{
  6121    match(Set dst (LoadN mem));
  6123    ins_cost(125); // XXX
  6124    format %{ "movl    $dst, $mem\t# compressed ptr" %}
  6125    ins_encode %{
  6126      Address addr = build_address($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
  6127      Register dst = as_Register($dst$$reg);
  6128      __ movl(dst, addr);
  6129    %}
  6130    ins_pipe(ialu_reg_mem); // XXX
  6131 %}
  6134 // Load Klass Pointer
  6135 instruct loadKlass(rRegP dst, memory mem)
  6136 %{
  6137   match(Set dst (LoadKlass mem));
  6139   ins_cost(125); // XXX
  6140   format %{ "movq    $dst, $mem\t# class" %}
  6141   opcode(0x8B);
  6142   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6143   ins_pipe(ialu_reg_mem); // XXX
  6144 %}
  6146 // Load narrow Klass Pointer
  6147 instruct loadNKlass(rRegN dst, memory mem)
  6148 %{
  6149   match(Set dst (LoadNKlass mem));
  6151   ins_cost(125); // XXX
  6152   format %{ "movl    $dst, $mem\t# compressed klass ptr\n\t" %}
  6153   ins_encode %{
  6154     Address addr = build_address($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
  6155     Register dst = as_Register($dst$$reg);
  6156     __ movl(dst, addr);
  6157   %}
  6158   ins_pipe(ialu_reg_mem); // XXX
  6159 %}
  6161 // Load Float
  6162 instruct loadF(regF dst, memory mem)
  6163 %{
  6164   match(Set dst (LoadF mem));
  6166   ins_cost(145); // XXX
  6167   format %{ "movss   $dst, $mem\t# float" %}
  6168   opcode(0xF3, 0x0F, 0x10);
  6169   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
  6170   ins_pipe(pipe_slow); // XXX
  6171 %}
  6173 // Load Double
  6174 instruct loadD_partial(regD dst, memory mem)
  6175 %{
  6176   predicate(!UseXmmLoadAndClearUpper);
  6177   match(Set dst (LoadD mem));
  6179   ins_cost(145); // XXX
  6180   format %{ "movlpd  $dst, $mem\t# double" %}
  6181   opcode(0x66, 0x0F, 0x12);
  6182   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
  6183   ins_pipe(pipe_slow); // XXX
  6184 %}
  6186 instruct loadD(regD dst, memory mem)
  6187 %{
  6188   predicate(UseXmmLoadAndClearUpper);
  6189   match(Set dst (LoadD mem));
  6191   ins_cost(145); // XXX
  6192   format %{ "movsd   $dst, $mem\t# double" %}
  6193   opcode(0xF2, 0x0F, 0x10);
  6194   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
  6195   ins_pipe(pipe_slow); // XXX
  6196 %}
  6198 // Load Aligned Packed Byte to XMM register
  6199 instruct loadA8B(regD dst, memory mem) %{
  6200   match(Set dst (Load8B mem));
  6201   ins_cost(125);
  6202   format %{ "MOVQ  $dst,$mem\t! packed8B" %}
  6203   ins_encode( movq_ld(dst, mem));
  6204   ins_pipe( pipe_slow );
  6205 %}
  6207 // Load Aligned Packed Short to XMM register
  6208 instruct loadA4S(regD dst, memory mem) %{
  6209   match(Set dst (Load4S mem));
  6210   ins_cost(125);
  6211   format %{ "MOVQ  $dst,$mem\t! packed4S" %}
  6212   ins_encode( movq_ld(dst, mem));
  6213   ins_pipe( pipe_slow );
  6214 %}
  6216 // Load Aligned Packed Char to XMM register
  6217 instruct loadA4C(regD dst, memory mem) %{
  6218   match(Set dst (Load4C mem));
  6219   ins_cost(125);
  6220   format %{ "MOVQ  $dst,$mem\t! packed4C" %}
  6221   ins_encode( movq_ld(dst, mem));
  6222   ins_pipe( pipe_slow );
  6223 %}
  6225 // Load Aligned Packed Integer to XMM register
  6226 instruct load2IU(regD dst, memory mem) %{
  6227   match(Set dst (Load2I mem));
  6228   ins_cost(125);
  6229   format %{ "MOVQ  $dst,$mem\t! packed2I" %}
  6230   ins_encode( movq_ld(dst, mem));
  6231   ins_pipe( pipe_slow );
  6232 %}
  6234 // Load Aligned Packed Single to XMM
  6235 instruct loadA2F(regD dst, memory mem) %{
  6236   match(Set dst (Load2F mem));
  6237   ins_cost(145);
  6238   format %{ "MOVQ  $dst,$mem\t! packed2F" %}
  6239   ins_encode( movq_ld(dst, mem));
  6240   ins_pipe( pipe_slow );
  6241 %}
  6243 // Load Effective Address
  6244 instruct leaP8(rRegP dst, indOffset8 mem)
  6245 %{
  6246   match(Set dst mem);
  6248   ins_cost(110); // XXX
  6249   format %{ "leaq    $dst, $mem\t# ptr 8" %}
  6250   opcode(0x8D);
  6251   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6252   ins_pipe(ialu_reg_reg_fat);
  6253 %}
  6255 instruct leaP32(rRegP dst, indOffset32 mem)
  6256 %{
  6257   match(Set dst mem);
  6259   ins_cost(110);
  6260   format %{ "leaq    $dst, $mem\t# ptr 32" %}
  6261   opcode(0x8D);
  6262   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6263   ins_pipe(ialu_reg_reg_fat);
  6264 %}
  6266 // instruct leaPIdx(rRegP dst, indIndex mem)
  6267 // %{
  6268 //   match(Set dst mem);
  6270 //   ins_cost(110);
  6271 //   format %{ "leaq    $dst, $mem\t# ptr idx" %}
  6272 //   opcode(0x8D);
  6273 //   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6274 //   ins_pipe(ialu_reg_reg_fat);
  6275 // %}
  6277 instruct leaPIdxOff(rRegP dst, indIndexOffset mem)
  6278 %{
  6279   match(Set dst mem);
  6281   ins_cost(110);
  6282   format %{ "leaq    $dst, $mem\t# ptr idxoff" %}
  6283   opcode(0x8D);
  6284   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6285   ins_pipe(ialu_reg_reg_fat);
  6286 %}
  6288 instruct leaPIdxScale(rRegP dst, indIndexScale mem)
  6289 %{
  6290   match(Set dst mem);
  6292   ins_cost(110);
  6293   format %{ "leaq    $dst, $mem\t# ptr idxscale" %}
  6294   opcode(0x8D);
  6295   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6296   ins_pipe(ialu_reg_reg_fat);
  6297 %}
  6299 instruct leaPIdxScaleOff(rRegP dst, indIndexScaleOffset mem)
  6300 %{
  6301   match(Set dst mem);
  6303   ins_cost(110);
  6304   format %{ "leaq    $dst, $mem\t# ptr idxscaleoff" %}
  6305   opcode(0x8D);
  6306   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  6307   ins_pipe(ialu_reg_reg_fat);
  6308 %}
  6310 instruct loadConI(rRegI dst, immI src)
  6311 %{
  6312   match(Set dst src);
  6314   format %{ "movl    $dst, $src\t# int" %}
  6315   ins_encode(load_immI(dst, src));
  6316   ins_pipe(ialu_reg_fat); // XXX
  6317 %}
  6319 instruct loadConI0(rRegI dst, immI0 src, rFlagsReg cr)
  6320 %{
  6321   match(Set dst src);
  6322   effect(KILL cr);
  6324   ins_cost(50);
  6325   format %{ "xorl    $dst, $dst\t# int" %}
  6326   opcode(0x33); /* + rd */
  6327   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
  6328   ins_pipe(ialu_reg);
  6329 %}
  6331 instruct loadConL(rRegL dst, immL src)
  6332 %{
  6333   match(Set dst src);
  6335   ins_cost(150);
  6336   format %{ "movq    $dst, $src\t# long" %}
  6337   ins_encode(load_immL(dst, src));
  6338   ins_pipe(ialu_reg);
  6339 %}
  6341 instruct loadConL0(rRegL dst, immL0 src, rFlagsReg cr)
  6342 %{
  6343   match(Set dst src);
  6344   effect(KILL cr);
  6346   ins_cost(50);
  6347   format %{ "xorl    $dst, $dst\t# long" %}
  6348   opcode(0x33); /* + rd */
  6349   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
  6350   ins_pipe(ialu_reg); // XXX
  6351 %}
  6353 instruct loadConUL32(rRegL dst, immUL32 src)
  6354 %{
  6355   match(Set dst src);
  6357   ins_cost(60);
  6358   format %{ "movl    $dst, $src\t# long (unsigned 32-bit)" %}
  6359   ins_encode(load_immUL32(dst, src));
  6360   ins_pipe(ialu_reg);
  6361 %}
  6363 instruct loadConL32(rRegL dst, immL32 src)
  6364 %{
  6365   match(Set dst src);
  6367   ins_cost(70);
  6368   format %{ "movq    $dst, $src\t# long (32-bit)" %}
  6369   ins_encode(load_immL32(dst, src));
  6370   ins_pipe(ialu_reg);
  6371 %}
  6373 instruct loadConP(rRegP dst, immP src)
  6374 %{
  6375   match(Set dst src);
  6377   format %{ "movq    $dst, $src\t# ptr" %}
  6378   ins_encode(load_immP(dst, src));
  6379   ins_pipe(ialu_reg_fat); // XXX
  6380 %}
  6382 instruct loadConP0(rRegP dst, immP0 src, rFlagsReg cr)
  6383 %{
  6384   match(Set dst src);
  6385   effect(KILL cr);
  6387   ins_cost(50);
  6388   format %{ "xorl    $dst, $dst\t# ptr" %}
  6389   opcode(0x33); /* + rd */
  6390   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
  6391   ins_pipe(ialu_reg);
  6392 %}
  6394 instruct loadConP31(rRegP dst, immP31 src, rFlagsReg cr)
  6395 %{
  6396   match(Set dst src);
  6397   effect(KILL cr);
  6399   ins_cost(60);
  6400   format %{ "movl    $dst, $src\t# ptr (positive 32-bit)" %}
  6401   ins_encode(load_immP31(dst, src));
  6402   ins_pipe(ialu_reg);
  6403 %}
  6405 instruct loadConF(regF dst, immF src)
  6406 %{
  6407   match(Set dst src);
  6408   ins_cost(125);
  6410   format %{ "movss   $dst, [$src]" %}
  6411   ins_encode(load_conF(dst, src));
  6412   ins_pipe(pipe_slow);
  6413 %}
  6415 instruct loadConN0(rRegN dst, immN0 src, rFlagsReg cr) %{
  6416   match(Set dst src);
  6417   effect(KILL cr);
  6418   format %{ "xorq    $dst, $src\t# compressed NULL ptr" %}
  6419   ins_encode %{
  6420     Register dst = $dst$$Register;
  6421     __ xorq(dst, dst);
  6422   %}
  6423   ins_pipe(ialu_reg);
  6424 %}
  6426 instruct loadConN(rRegN dst, immN src) %{
  6427   match(Set dst src);
  6429   ins_cost(125);
  6430   format %{ "movl    $dst, $src\t# compressed ptr" %}
  6431   ins_encode %{
  6432     address con = (address)$src$$constant;
  6433     Register dst = $dst$$Register;
  6434     if (con == NULL) {
  6435       ShouldNotReachHere();
  6436     } else {
  6437       __ set_narrow_oop(dst, (jobject)$src$$constant);
  6439   %}
  6440   ins_pipe(ialu_reg_fat); // XXX
  6441 %}
  6443 instruct loadConF0(regF dst, immF0 src)
  6444 %{
  6445   match(Set dst src);
  6446   ins_cost(100);
  6448   format %{ "xorps   $dst, $dst\t# float 0.0" %}
  6449   opcode(0x0F, 0x57);
  6450   ins_encode(REX_reg_reg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
  6451   ins_pipe(pipe_slow);
  6452 %}
  6454 // Use the same format since predicate() can not be used here.
  6455 instruct loadConD(regD dst, immD src)
  6456 %{
  6457   match(Set dst src);
  6458   ins_cost(125);
  6460   format %{ "movsd   $dst, [$src]" %}
  6461   ins_encode(load_conD(dst, src));
  6462   ins_pipe(pipe_slow);
  6463 %}
  6465 instruct loadConD0(regD dst, immD0 src)
  6466 %{
  6467   match(Set dst src);
  6468   ins_cost(100);
  6470   format %{ "xorpd   $dst, $dst\t# double 0.0" %}
  6471   opcode(0x66, 0x0F, 0x57);
  6472   ins_encode(OpcP, REX_reg_reg(dst, dst), OpcS, OpcT, reg_reg(dst, dst));
  6473   ins_pipe(pipe_slow);
  6474 %}
  6476 instruct loadSSI(rRegI dst, stackSlotI src)
  6477 %{
  6478   match(Set dst src);
  6480   ins_cost(125);
  6481   format %{ "movl    $dst, $src\t# int stk" %}
  6482   opcode(0x8B);
  6483   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  6484   ins_pipe(ialu_reg_mem);
  6485 %}
  6487 instruct loadSSL(rRegL dst, stackSlotL src)
  6488 %{
  6489   match(Set dst src);
  6491   ins_cost(125);
  6492   format %{ "movq    $dst, $src\t# long stk" %}
  6493   opcode(0x8B);
  6494   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  6495   ins_pipe(ialu_reg_mem);
  6496 %}
  6498 instruct loadSSP(rRegP dst, stackSlotP src)
  6499 %{
  6500   match(Set dst src);
  6502   ins_cost(125);
  6503   format %{ "movq    $dst, $src\t# ptr stk" %}
  6504   opcode(0x8B);
  6505   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  6506   ins_pipe(ialu_reg_mem);
  6507 %}
  6509 instruct loadSSF(regF dst, stackSlotF src)
  6510 %{
  6511   match(Set dst src);
  6513   ins_cost(125);
  6514   format %{ "movss   $dst, $src\t# float stk" %}
  6515   opcode(0xF3, 0x0F, 0x10);
  6516   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
  6517   ins_pipe(pipe_slow); // XXX
  6518 %}
  6520 // Use the same format since predicate() can not be used here.
  6521 instruct loadSSD(regD dst, stackSlotD src)
  6522 %{
  6523   match(Set dst src);
  6525   ins_cost(125);
  6526   format %{ "movsd   $dst, $src\t# double stk" %}
  6527   ins_encode  %{
  6528     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
  6529   %}
  6530   ins_pipe(pipe_slow); // XXX
  6531 %}
  6533 // Prefetch instructions.
  6534 // Must be safe to execute with invalid address (cannot fault).
  6536 instruct prefetchr( memory mem ) %{
  6537   predicate(ReadPrefetchInstr==3);
  6538   match(PrefetchRead mem);
  6539   ins_cost(125);
  6541   format %{ "PREFETCHR $mem\t# Prefetch into level 1 cache" %}
  6542   opcode(0x0F, 0x0D);     /* Opcode 0F 0D /0 */
  6543   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
  6544   ins_pipe(ialu_mem);
  6545 %}
  6547 instruct prefetchrNTA( memory mem ) %{
  6548   predicate(ReadPrefetchInstr==0);
  6549   match(PrefetchRead mem);
  6550   ins_cost(125);
  6552   format %{ "PREFETCHNTA $mem\t# Prefetch into non-temporal cache for read" %}
  6553   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
  6554   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
  6555   ins_pipe(ialu_mem);
  6556 %}
  6558 instruct prefetchrT0( memory mem ) %{
  6559   predicate(ReadPrefetchInstr==1);
  6560   match(PrefetchRead mem);
  6561   ins_cost(125);
  6563   format %{ "PREFETCHT0 $mem\t# prefetch into L1 and L2 caches for read" %}
  6564   opcode(0x0F, 0x18); /* Opcode 0F 18 /1 */
  6565   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
  6566   ins_pipe(ialu_mem);
  6567 %}
  6569 instruct prefetchrT2( memory mem ) %{
  6570   predicate(ReadPrefetchInstr==2);
  6571   match(PrefetchRead mem);
  6572   ins_cost(125);
  6574   format %{ "PREFETCHT2 $mem\t# prefetch into L2 caches for read" %}
  6575   opcode(0x0F, 0x18); /* Opcode 0F 18 /3 */
  6576   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x03, mem));
  6577   ins_pipe(ialu_mem);
  6578 %}
  6580 instruct prefetchw( memory mem ) %{
  6581   predicate(AllocatePrefetchInstr==3);
  6582   match(PrefetchWrite mem);
  6583   ins_cost(125);
  6585   format %{ "PREFETCHW $mem\t# Prefetch into level 1 cache and mark modified" %}
  6586   opcode(0x0F, 0x0D);     /* Opcode 0F 0D /1 */
  6587   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
  6588   ins_pipe(ialu_mem);
  6589 %}
  6591 instruct prefetchwNTA( memory mem ) %{
  6592   predicate(AllocatePrefetchInstr==0);
  6593   match(PrefetchWrite mem);
  6594   ins_cost(125);
  6596   format %{ "PREFETCHNTA $mem\t# Prefetch to non-temporal cache for write" %}
  6597   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
  6598   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
  6599   ins_pipe(ialu_mem);
  6600 %}
  6602 instruct prefetchwT0( memory mem ) %{
  6603   predicate(AllocatePrefetchInstr==1);
  6604   match(PrefetchWrite mem);
  6605   ins_cost(125);
  6607   format %{ "PREFETCHT0 $mem\t# Prefetch to level 1 and 2 caches for write" %}
  6608   opcode(0x0F, 0x18);     /* Opcode 0F 18 /1 */
  6609   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
  6610   ins_pipe(ialu_mem);
  6611 %}
  6613 instruct prefetchwT2( memory mem ) %{
  6614   predicate(AllocatePrefetchInstr==2);
  6615   match(PrefetchWrite mem);
  6616   ins_cost(125);
  6618   format %{ "PREFETCHT2 $mem\t# Prefetch to level 2 cache for write" %}
  6619   opcode(0x0F, 0x18);     /* Opcode 0F 18 /3 */
  6620   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x03, mem));
  6621   ins_pipe(ialu_mem);
  6622 %}
  6624 //----------Store Instructions-------------------------------------------------
  6626 // Store Byte
  6627 instruct storeB(memory mem, rRegI src)
  6628 %{
  6629   match(Set mem (StoreB mem src));
  6631   ins_cost(125); // XXX
  6632   format %{ "movb    $mem, $src\t# byte" %}
  6633   opcode(0x88);
  6634   ins_encode(REX_breg_mem(src, mem), OpcP, reg_mem(src, mem));
  6635   ins_pipe(ialu_mem_reg);
  6636 %}
  6638 // Store Char/Short
  6639 instruct storeC(memory mem, rRegI src)
  6640 %{
  6641   match(Set mem (StoreC mem src));
  6643   ins_cost(125); // XXX
  6644   format %{ "movw    $mem, $src\t# char/short" %}
  6645   opcode(0x89);
  6646   ins_encode(SizePrefix, REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
  6647   ins_pipe(ialu_mem_reg);
  6648 %}
  6650 // Store Integer
  6651 instruct storeI(memory mem, rRegI src)
  6652 %{
  6653   match(Set mem (StoreI mem src));
  6655   ins_cost(125); // XXX
  6656   format %{ "movl    $mem, $src\t# int" %}
  6657   opcode(0x89);
  6658   ins_encode(REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
  6659   ins_pipe(ialu_mem_reg);
  6660 %}
  6662 // Store Long
  6663 instruct storeL(memory mem, rRegL src)
  6664 %{
  6665   match(Set mem (StoreL mem src));
  6667   ins_cost(125); // XXX
  6668   format %{ "movq    $mem, $src\t# long" %}
  6669   opcode(0x89);
  6670   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
  6671   ins_pipe(ialu_mem_reg); // XXX
  6672 %}
  6674 // Store Pointer
  6675 instruct storeP(memory mem, any_RegP src)
  6676 %{
  6677   match(Set mem (StoreP mem src));
  6679   ins_cost(125); // XXX
  6680   format %{ "movq    $mem, $src\t# ptr" %}
  6681   opcode(0x89);
  6682   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
  6683   ins_pipe(ialu_mem_reg);
  6684 %}
  6686 // Store NULL Pointer, mark word, or other simple pointer constant.
  6687 instruct storeImmP(memory mem, immP31 src)
  6688 %{
  6689   match(Set mem (StoreP mem src));
  6691   ins_cost(125); // XXX
  6692   format %{ "movq    $mem, $src\t# ptr" %}
  6693   opcode(0xC7); /* C7 /0 */
  6694   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
  6695   ins_pipe(ialu_mem_imm);
  6696 %}
  6698 // Store Compressed Pointer
  6699 instruct storeN(memory mem, rRegN src)
  6700 %{
  6701   match(Set mem (StoreN mem src));
  6703   ins_cost(125); // XXX
  6704   format %{ "movl    $mem, $src\t# compressed ptr" %}
  6705   ins_encode %{
  6706     Address addr = build_address($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
  6707     Register src = as_Register($src$$reg);
  6708     __ movl(addr, src);
  6709   %}
  6710   ins_pipe(ialu_mem_reg);
  6711 %}
  6713 // Store Integer Immediate
  6714 instruct storeImmI(memory mem, immI src)
  6715 %{
  6716   match(Set mem (StoreI mem src));
  6718   ins_cost(150);
  6719   format %{ "movl    $mem, $src\t# int" %}
  6720   opcode(0xC7); /* C7 /0 */
  6721   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
  6722   ins_pipe(ialu_mem_imm);
  6723 %}
  6725 // Store Long Immediate
  6726 instruct storeImmL(memory mem, immL32 src)
  6727 %{
  6728   match(Set mem (StoreL mem src));
  6730   ins_cost(150);
  6731   format %{ "movq    $mem, $src\t# long" %}
  6732   opcode(0xC7); /* C7 /0 */
  6733   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
  6734   ins_pipe(ialu_mem_imm);
  6735 %}
  6737 // Store Short/Char Immediate
  6738 instruct storeImmI16(memory mem, immI16 src)
  6739 %{
  6740   predicate(UseStoreImmI16);
  6741   match(Set mem (StoreC mem src));
  6743   ins_cost(150);
  6744   format %{ "movw    $mem, $src\t# short/char" %}
  6745   opcode(0xC7); /* C7 /0 Same as 32 store immediate with prefix */
  6746   ins_encode(SizePrefix, REX_mem(mem), OpcP, RM_opc_mem(0x00, mem),Con16(src));
  6747   ins_pipe(ialu_mem_imm);
  6748 %}
  6750 // Store Byte Immediate
  6751 instruct storeImmB(memory mem, immI8 src)
  6752 %{
  6753   match(Set mem (StoreB mem src));
  6755   ins_cost(150); // XXX
  6756   format %{ "movb    $mem, $src\t# byte" %}
  6757   opcode(0xC6); /* C6 /0 */
  6758   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con8or32(src));
  6759   ins_pipe(ialu_mem_imm);
  6760 %}
  6762 // Store Aligned Packed Byte XMM register to memory
  6763 instruct storeA8B(memory mem, regD src) %{
  6764   match(Set mem (Store8B mem src));
  6765   ins_cost(145);
  6766   format %{ "MOVQ  $mem,$src\t! packed8B" %}
  6767   ins_encode( movq_st(mem, src));
  6768   ins_pipe( pipe_slow );
  6769 %}
  6771 // Store Aligned Packed Char/Short XMM register to memory
  6772 instruct storeA4C(memory mem, regD src) %{
  6773   match(Set mem (Store4C mem src));
  6774   ins_cost(145);
  6775   format %{ "MOVQ  $mem,$src\t! packed4C" %}
  6776   ins_encode( movq_st(mem, src));
  6777   ins_pipe( pipe_slow );
  6778 %}
  6780 // Store Aligned Packed Integer XMM register to memory
  6781 instruct storeA2I(memory mem, regD src) %{
  6782   match(Set mem (Store2I mem src));
  6783   ins_cost(145);
  6784   format %{ "MOVQ  $mem,$src\t! packed2I" %}
  6785   ins_encode( movq_st(mem, src));
  6786   ins_pipe( pipe_slow );
  6787 %}
  6789 // Store CMS card-mark Immediate
  6790 instruct storeImmCM0(memory mem, immI0 src)
  6791 %{
  6792   match(Set mem (StoreCM mem src));
  6794   ins_cost(150); // XXX
  6795   format %{ "movb    $mem, $src\t# CMS card-mark byte 0" %}
  6796   opcode(0xC6); /* C6 /0 */
  6797   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con8or32(src));
  6798   ins_pipe(ialu_mem_imm);
  6799 %}
  6801 // Store Aligned Packed Single Float XMM register to memory
  6802 instruct storeA2F(memory mem, regD src) %{
  6803   match(Set mem (Store2F mem src));
  6804   ins_cost(145);
  6805   format %{ "MOVQ  $mem,$src\t! packed2F" %}
  6806   ins_encode( movq_st(mem, src));
  6807   ins_pipe( pipe_slow );
  6808 %}
  6810 // Store Float
  6811 instruct storeF(memory mem, regF src)
  6812 %{
  6813   match(Set mem (StoreF mem src));
  6815   ins_cost(95); // XXX
  6816   format %{ "movss   $mem, $src\t# float" %}
  6817   opcode(0xF3, 0x0F, 0x11);
  6818   ins_encode(OpcP, REX_reg_mem(src, mem), OpcS, OpcT, reg_mem(src, mem));
  6819   ins_pipe(pipe_slow); // XXX
  6820 %}
  6822 // Store immediate Float value (it is faster than store from XMM register)
  6823 instruct storeF_imm(memory mem, immF src)
  6824 %{
  6825   match(Set mem (StoreF mem src));
  6827   ins_cost(50);
  6828   format %{ "movl    $mem, $src\t# float" %}
  6829   opcode(0xC7); /* C7 /0 */
  6830   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con32F_as_bits(src));
  6831   ins_pipe(ialu_mem_imm);
  6832 %}
  6834 // Store Double
  6835 instruct storeD(memory mem, regD src)
  6836 %{
  6837   match(Set mem (StoreD mem src));
  6839   ins_cost(95); // XXX
  6840   format %{ "movsd   $mem, $src\t# double" %}
  6841   opcode(0xF2, 0x0F, 0x11);
  6842   ins_encode(OpcP, REX_reg_mem(src, mem), OpcS, OpcT, reg_mem(src, mem));
  6843   ins_pipe(pipe_slow); // XXX
  6844 %}
  6846 // Store immediate double 0.0 (it is faster than store from XMM register)
  6847 instruct storeD0_imm(memory mem, immD0 src)
  6848 %{
  6849   match(Set mem (StoreD mem src));
  6851   ins_cost(50);
  6852   format %{ "movq    $mem, $src\t# double 0." %}
  6853   opcode(0xC7); /* C7 /0 */
  6854   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32F_as_bits(src));
  6855   ins_pipe(ialu_mem_imm);
  6856 %}
  6858 instruct storeSSI(stackSlotI dst, rRegI src)
  6859 %{
  6860   match(Set dst src);
  6862   ins_cost(100);
  6863   format %{ "movl    $dst, $src\t# int stk" %}
  6864   opcode(0x89);
  6865   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  6866   ins_pipe( ialu_mem_reg );
  6867 %}
  6869 instruct storeSSL(stackSlotL dst, rRegL src)
  6870 %{
  6871   match(Set dst src);
  6873   ins_cost(100);
  6874   format %{ "movq    $dst, $src\t# long stk" %}
  6875   opcode(0x89);
  6876   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  6877   ins_pipe(ialu_mem_reg);
  6878 %}
  6880 instruct storeSSP(stackSlotP dst, rRegP src)
  6881 %{
  6882   match(Set dst src);
  6884   ins_cost(100);
  6885   format %{ "movq    $dst, $src\t# ptr stk" %}
  6886   opcode(0x89);
  6887   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  6888   ins_pipe(ialu_mem_reg);
  6889 %}
  6891 instruct storeSSF(stackSlotF dst, regF src)
  6892 %{
  6893   match(Set dst src);
  6895   ins_cost(95); // XXX
  6896   format %{ "movss   $dst, $src\t# float stk" %}
  6897   opcode(0xF3, 0x0F, 0x11);
  6898   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
  6899   ins_pipe(pipe_slow); // XXX
  6900 %}
  6902 instruct storeSSD(stackSlotD dst, regD src)
  6903 %{
  6904   match(Set dst src);
  6906   ins_cost(95); // XXX
  6907   format %{ "movsd   $dst, $src\t# double stk" %}
  6908   opcode(0xF2, 0x0F, 0x11);
  6909   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
  6910   ins_pipe(pipe_slow); // XXX
  6911 %}
  6913 //----------BSWAP Instructions-------------------------------------------------
  6914 instruct bytes_reverse_int(rRegI dst) %{
  6915   match(Set dst (ReverseBytesI dst));
  6917   format %{ "bswapl  $dst" %}
  6918   opcode(0x0F, 0xC8);  /*Opcode 0F /C8 */
  6919   ins_encode( REX_reg(dst), OpcP, opc2_reg(dst) );
  6920   ins_pipe( ialu_reg );
  6921 %}
  6923 instruct bytes_reverse_long(rRegL dst) %{
  6924   match(Set dst (ReverseBytesL dst));
  6926   format %{ "bswapq  $dst" %}
  6928   opcode(0x0F, 0xC8); /* Opcode 0F /C8 */
  6929   ins_encode( REX_reg_wide(dst), OpcP, opc2_reg(dst) );
  6930   ins_pipe( ialu_reg);
  6931 %}
  6933 instruct loadI_reversed(rRegI dst, memory src) %{
  6934   match(Set dst (ReverseBytesI (LoadI src)));
  6936   format %{ "bswap_movl $dst, $src" %}
  6937   opcode(0x8B, 0x0F, 0xC8); /* Opcode 8B 0F C8 */
  6938   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src), REX_reg(dst), OpcS, opc3_reg(dst));
  6939   ins_pipe( ialu_reg_mem );
  6940 %}
  6942 instruct loadL_reversed(rRegL dst, memory src) %{
  6943   match(Set dst (ReverseBytesL (LoadL src)));
  6945   format %{ "bswap_movq $dst, $src" %}
  6946   opcode(0x8B, 0x0F, 0xC8); /* Opcode 8B 0F C8 */
  6947   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src), REX_reg_wide(dst), OpcS, opc3_reg(dst));
  6948   ins_pipe( ialu_reg_mem );
  6949 %}
  6951 instruct storeI_reversed(memory dst, rRegI src) %{
  6952   match(Set dst (StoreI dst (ReverseBytesI  src)));
  6954   format %{ "movl_bswap $dst, $src" %}
  6955   opcode(0x0F, 0xC8, 0x89); /* Opcode 0F C8 89 */
  6956   ins_encode( REX_reg(src), OpcP, opc2_reg(src), REX_reg_mem(src, dst), OpcT, reg_mem(src, dst) );
  6957   ins_pipe( ialu_mem_reg );
  6958 %}
  6960 instruct storeL_reversed(memory dst, rRegL src) %{
  6961   match(Set dst (StoreL dst (ReverseBytesL  src)));
  6963   format %{ "movq_bswap $dst, $src" %}
  6964   opcode(0x0F, 0xC8, 0x89); /* Opcode 0F C8 89 */
  6965   ins_encode( REX_reg_wide(src), OpcP, opc2_reg(src), REX_reg_mem_wide(src, dst), OpcT, reg_mem(src, dst) );
  6966   ins_pipe( ialu_mem_reg );
  6967 %}
  6969 //----------MemBar Instructions-----------------------------------------------
  6970 // Memory barrier flavors
  6972 instruct membar_acquire()
  6973 %{
  6974   match(MemBarAcquire);
  6975   ins_cost(0);
  6977   size(0);
  6978   format %{ "MEMBAR-acquire" %}
  6979   ins_encode();
  6980   ins_pipe(empty);
  6981 %}
  6983 instruct membar_acquire_lock()
  6984 %{
  6985   match(MemBarAcquire);
  6986   predicate(Matcher::prior_fast_lock(n));
  6987   ins_cost(0);
  6989   size(0);
  6990   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
  6991   ins_encode();
  6992   ins_pipe(empty);
  6993 %}
  6995 instruct membar_release()
  6996 %{
  6997   match(MemBarRelease);
  6998   ins_cost(0);
  7000   size(0);
  7001   format %{ "MEMBAR-release" %}
  7002   ins_encode();
  7003   ins_pipe(empty);
  7004 %}
  7006 instruct membar_release_lock()
  7007 %{
  7008   match(MemBarRelease);
  7009   predicate(Matcher::post_fast_unlock(n));
  7010   ins_cost(0);
  7012   size(0);
  7013   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
  7014   ins_encode();
  7015   ins_pipe(empty);
  7016 %}
  7018 instruct membar_volatile()
  7019 %{
  7020   match(MemBarVolatile);
  7021   ins_cost(400);
  7023   format %{ "MEMBAR-volatile" %}
  7024   ins_encode(enc_membar_volatile);
  7025   ins_pipe(pipe_slow);
  7026 %}
  7028 instruct unnecessary_membar_volatile()
  7029 %{
  7030   match(MemBarVolatile);
  7031   predicate(Matcher::post_store_load_barrier(n));
  7032   ins_cost(0);
  7034   size(0);
  7035   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
  7036   ins_encode();
  7037   ins_pipe(empty);
  7038 %}
  7040 //----------Move Instructions--------------------------------------------------
  7042 instruct castX2P(rRegP dst, rRegL src)
  7043 %{
  7044   match(Set dst (CastX2P src));
  7046   format %{ "movq    $dst, $src\t# long->ptr" %}
  7047   ins_encode(enc_copy_wide(dst, src));
  7048   ins_pipe(ialu_reg_reg); // XXX
  7049 %}
  7051 instruct castP2X(rRegL dst, rRegP src)
  7052 %{
  7053   match(Set dst (CastP2X src));
  7055   format %{ "movq    $dst, $src\t# ptr -> long" %}
  7056   ins_encode(enc_copy_wide(dst, src));
  7057   ins_pipe(ialu_reg_reg); // XXX
  7058 %}
  7061 // Convert oop pointer into compressed form
  7062 instruct encodeHeapOop(rRegN dst, rRegP src, rFlagsReg cr) %{
  7063   predicate(n->bottom_type()->is_narrowoop()->make_oopptr()->ptr() != TypePtr::NotNull);
  7064   match(Set dst (EncodeP src));
  7065   effect(KILL cr);
  7066   format %{ "encode_heap_oop $dst,$src" %}
  7067   ins_encode %{
  7068     Register s = $src$$Register;
  7069     Register d = $dst$$Register;
  7070     if (s != d) {
  7071       __ movq(d, s);
  7073     __ encode_heap_oop(d);
  7074   %}
  7075   ins_pipe(ialu_reg_long);
  7076 %}
  7078 instruct encodeHeapOop_not_null(rRegN dst, rRegP src, rFlagsReg cr) %{
  7079   predicate(n->bottom_type()->is_narrowoop()->make_oopptr()->ptr() == TypePtr::NotNull);
  7080   match(Set dst (EncodeP src));
  7081   effect(KILL cr);
  7082   format %{ "encode_heap_oop_not_null $dst,$src" %}
  7083   ins_encode %{
  7084     Register s = $src$$Register;
  7085     Register d = $dst$$Register;
  7086     __ encode_heap_oop_not_null(d, s);
  7087   %}
  7088   ins_pipe(ialu_reg_long);
  7089 %}
  7091 instruct decodeHeapOop(rRegP dst, rRegN src, rFlagsReg cr) %{
  7092   predicate(n->bottom_type()->is_oopptr()->ptr() != TypePtr::NotNull);
  7093   match(Set dst (DecodeN src));
  7094   effect(KILL cr);
  7095   format %{ "decode_heap_oop $dst,$src" %}
  7096   ins_encode %{
  7097     Register s = $src$$Register;
  7098     Register d = $dst$$Register;
  7099     if (s != d) {
  7100       __ movq(d, s);
  7102     __ decode_heap_oop(d);
  7103   %}
  7104   ins_pipe(ialu_reg_long);
  7105 %}
  7107 instruct decodeHeapOop_not_null(rRegP dst, rRegN src) %{
  7108   predicate(n->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull);
  7109   match(Set dst (DecodeN src));
  7110   format %{ "decode_heap_oop_not_null $dst,$src" %}
  7111   ins_encode %{
  7112     Register s = $src$$Register;
  7113     Register d = $dst$$Register;
  7114     __ decode_heap_oop_not_null(d, s);
  7115   %}
  7116   ins_pipe(ialu_reg_long);
  7117 %}
  7120 //----------Conditional Move---------------------------------------------------
  7121 // Jump
  7122 // dummy instruction for generating temp registers
  7123 instruct jumpXtnd_offset(rRegL switch_val, immI2 shift, rRegI dest) %{
  7124   match(Jump (LShiftL switch_val shift));
  7125   ins_cost(350);
  7126   predicate(false);
  7127   effect(TEMP dest);
  7129   format %{ "leaq    $dest, table_base\n\t"
  7130             "jmp     [$dest + $switch_val << $shift]\n\t" %}
  7131   ins_encode(jump_enc_offset(switch_val, shift, dest));
  7132   ins_pipe(pipe_jmp);
  7133   ins_pc_relative(1);
  7134 %}
  7136 instruct jumpXtnd_addr(rRegL switch_val, immI2 shift, immL32 offset, rRegI dest) %{
  7137   match(Jump (AddL (LShiftL switch_val shift) offset));
  7138   ins_cost(350);
  7139   effect(TEMP dest);
  7141   format %{ "leaq    $dest, table_base\n\t"
  7142             "jmp     [$dest + $switch_val << $shift + $offset]\n\t" %}
  7143   ins_encode(jump_enc_addr(switch_val, shift, offset, dest));
  7144   ins_pipe(pipe_jmp);
  7145   ins_pc_relative(1);
  7146 %}
  7148 instruct jumpXtnd(rRegL switch_val, rRegI dest) %{
  7149   match(Jump switch_val);
  7150   ins_cost(350);
  7151   effect(TEMP dest);
  7153   format %{ "leaq    $dest, table_base\n\t"
  7154             "jmp     [$dest + $switch_val]\n\t" %}
  7155   ins_encode(jump_enc(switch_val, dest));
  7156   ins_pipe(pipe_jmp);
  7157   ins_pc_relative(1);
  7158 %}
  7160 // Conditional move
  7161 instruct cmovI_reg(rRegI dst, rRegI src, rFlagsReg cr, cmpOp cop)
  7162 %{
  7163   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7165   ins_cost(200); // XXX
  7166   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
  7167   opcode(0x0F, 0x40);
  7168   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7169   ins_pipe(pipe_cmov_reg);
  7170 %}
  7172 instruct cmovI_regU(rRegI dst, rRegI src, rFlagsRegU cr, cmpOpU cop)
  7173 %{
  7174   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
  7176   ins_cost(200); // XXX
  7177   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
  7178   opcode(0x0F, 0x40);
  7179   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7180   ins_pipe(pipe_cmov_reg);
  7181 %}
  7183 // Conditional move
  7184 instruct cmovI_mem(cmpOp cop, rFlagsReg cr, rRegI dst, memory src)
  7185 %{
  7186   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7188   ins_cost(250); // XXX
  7189   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
  7190   opcode(0x0F, 0x40);
  7191   ins_encode(REX_reg_mem(dst, src), enc_cmov(cop), reg_mem(dst, src));
  7192   ins_pipe(pipe_cmov_mem);
  7193 %}
  7195 // Conditional move
  7196 instruct cmovI_memU(cmpOpU cop, rFlagsRegU cr, rRegI dst, memory src)
  7197 %{
  7198   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
  7200   ins_cost(250); // XXX
  7201   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
  7202   opcode(0x0F, 0x40);
  7203   ins_encode(REX_reg_mem(dst, src), enc_cmov(cop), reg_mem(dst, src));
  7204   ins_pipe(pipe_cmov_mem);
  7205 %}
  7207 // Conditional move
  7208 instruct cmovN_reg(rRegN dst, rRegN src, rFlagsReg cr, cmpOp cop)
  7209 %{
  7210   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
  7212   ins_cost(200); // XXX
  7213   format %{ "cmovl$cop $dst, $src\t# signed, compressed ptr" %}
  7214   opcode(0x0F, 0x40);
  7215   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7216   ins_pipe(pipe_cmov_reg);
  7217 %}
  7219 // Conditional move
  7220 instruct cmovN_regU(rRegN dst, rRegN src, rFlagsRegU cr, cmpOpU cop)
  7221 %{
  7222   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
  7224   ins_cost(200); // XXX
  7225   format %{ "cmovl$cop $dst, $src\t# unsigned, compressed ptr" %}
  7226   opcode(0x0F, 0x40);
  7227   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7228   ins_pipe(pipe_cmov_reg);
  7229 %}
  7231 // Conditional move
  7232 instruct cmovP_reg(rRegP dst, rRegP src, rFlagsReg cr, cmpOp cop)
  7233 %{
  7234   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7236   ins_cost(200); // XXX
  7237   format %{ "cmovq$cop $dst, $src\t# signed, ptr" %}
  7238   opcode(0x0F, 0x40);
  7239   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7240   ins_pipe(pipe_cmov_reg);  // XXX
  7241 %}
  7243 // Conditional move
  7244 instruct cmovP_regU(rRegP dst, rRegP src, rFlagsRegU cr, cmpOpU cop)
  7245 %{
  7246   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
  7248   ins_cost(200); // XXX
  7249   format %{ "cmovq$cop $dst, $src\t# unsigned, ptr" %}
  7250   opcode(0x0F, 0x40);
  7251   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7252   ins_pipe(pipe_cmov_reg); // XXX
  7253 %}
  7255 // DISABLED: Requires the ADLC to emit a bottom_type call that
  7256 // correctly meets the two pointer arguments; one is an incoming
  7257 // register but the other is a memory operand.  ALSO appears to
  7258 // be buggy with implicit null checks.
  7259 //
  7260 //// Conditional move
  7261 //instruct cmovP_mem(cmpOp cop, rFlagsReg cr, rRegP dst, memory src)
  7262 //%{
  7263 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  7264 //  ins_cost(250);
  7265 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7266 //  opcode(0x0F,0x40);
  7267 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
  7268 //  ins_pipe( pipe_cmov_mem );
  7269 //%}
  7270 //
  7271 //// Conditional move
  7272 //instruct cmovP_memU(cmpOpU cop, rFlagsRegU cr, rRegP dst, memory src)
  7273 //%{
  7274 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
  7275 //  ins_cost(250);
  7276 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
  7277 //  opcode(0x0F,0x40);
  7278 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
  7279 //  ins_pipe( pipe_cmov_mem );
  7280 //%}
  7282 instruct cmovL_reg(cmpOp cop, rFlagsReg cr, rRegL dst, rRegL src)
  7283 %{
  7284   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  7286   ins_cost(200); // XXX
  7287   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
  7288   opcode(0x0F, 0x40);
  7289   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7290   ins_pipe(pipe_cmov_reg);  // XXX
  7291 %}
  7293 instruct cmovL_mem(cmpOp cop, rFlagsReg cr, rRegL dst, memory src)
  7294 %{
  7295   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
  7297   ins_cost(200); // XXX
  7298   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
  7299   opcode(0x0F, 0x40);
  7300   ins_encode(REX_reg_mem_wide(dst, src), enc_cmov(cop), reg_mem(dst, src));
  7301   ins_pipe(pipe_cmov_mem);  // XXX
  7302 %}
  7304 instruct cmovL_regU(cmpOpU cop, rFlagsRegU cr, rRegL dst, rRegL src)
  7305 %{
  7306   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
  7308   ins_cost(200); // XXX
  7309   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
  7310   opcode(0x0F, 0x40);
  7311   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
  7312   ins_pipe(pipe_cmov_reg); // XXX
  7313 %}
  7315 instruct cmovL_memU(cmpOpU cop, rFlagsRegU cr, rRegL dst, memory src)
  7316 %{
  7317   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
  7319   ins_cost(200); // XXX
  7320   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
  7321   opcode(0x0F, 0x40);
  7322   ins_encode(REX_reg_mem_wide(dst, src), enc_cmov(cop), reg_mem(dst, src));
  7323   ins_pipe(pipe_cmov_mem); // XXX
  7324 %}
  7326 instruct cmovF_reg(cmpOp cop, rFlagsReg cr, regF dst, regF src)
  7327 %{
  7328   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7330   ins_cost(200); // XXX
  7331   format %{ "jn$cop    skip\t# signed cmove float\n\t"
  7332             "movss     $dst, $src\n"
  7333     "skip:" %}
  7334   ins_encode(enc_cmovf_branch(cop, dst, src));
  7335   ins_pipe(pipe_slow);
  7336 %}
  7338 // instruct cmovF_mem(cmpOp cop, rFlagsReg cr, regF dst, memory src)
  7339 // %{
  7340 //   match(Set dst (CMoveF (Binary cop cr) (Binary dst (LoadL src))));
  7342 //   ins_cost(200); // XXX
  7343 //   format %{ "jn$cop    skip\t# signed cmove float\n\t"
  7344 //             "movss     $dst, $src\n"
  7345 //     "skip:" %}
  7346 //   ins_encode(enc_cmovf_mem_branch(cop, dst, src));
  7347 //   ins_pipe(pipe_slow);
  7348 // %}
  7350 instruct cmovF_regU(cmpOpU cop, rFlagsRegU cr, regF dst, regF src)
  7351 %{
  7352   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
  7354   ins_cost(200); // XXX
  7355   format %{ "jn$cop    skip\t# unsigned cmove float\n\t"
  7356             "movss     $dst, $src\n"
  7357     "skip:" %}
  7358   ins_encode(enc_cmovf_branch(cop, dst, src));
  7359   ins_pipe(pipe_slow);
  7360 %}
  7362 instruct cmovD_reg(cmpOp cop, rFlagsReg cr, regD dst, regD src)
  7363 %{
  7364   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7366   ins_cost(200); // XXX
  7367   format %{ "jn$cop    skip\t# signed cmove double\n\t"
  7368             "movsd     $dst, $src\n"
  7369     "skip:" %}
  7370   ins_encode(enc_cmovd_branch(cop, dst, src));
  7371   ins_pipe(pipe_slow);
  7372 %}
  7374 instruct cmovD_regU(cmpOpU cop, rFlagsRegU cr, regD dst, regD src)
  7375 %{
  7376   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
  7378   ins_cost(200); // XXX
  7379   format %{ "jn$cop    skip\t# unsigned cmove double\n\t"
  7380             "movsd     $dst, $src\n"
  7381     "skip:" %}
  7382   ins_encode(enc_cmovd_branch(cop, dst, src));
  7383   ins_pipe(pipe_slow);
  7384 %}
  7386 //----------Arithmetic Instructions--------------------------------------------
  7387 //----------Addition Instructions----------------------------------------------
  7389 instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  7390 %{
  7391   match(Set dst (AddI dst src));
  7392   effect(KILL cr);
  7394   format %{ "addl    $dst, $src\t# int" %}
  7395   opcode(0x03);
  7396   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
  7397   ins_pipe(ialu_reg_reg);
  7398 %}
  7400 instruct addI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
  7401 %{
  7402   match(Set dst (AddI dst src));
  7403   effect(KILL cr);
  7405   format %{ "addl    $dst, $src\t# int" %}
  7406   opcode(0x81, 0x00); /* /0 id */
  7407   ins_encode(OpcSErm(dst, src), Con8or32(src));
  7408   ins_pipe( ialu_reg );
  7409 %}
  7411 instruct addI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
  7412 %{
  7413   match(Set dst (AddI dst (LoadI src)));
  7414   effect(KILL cr);
  7416   ins_cost(125); // XXX
  7417   format %{ "addl    $dst, $src\t# int" %}
  7418   opcode(0x03);
  7419   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  7420   ins_pipe(ialu_reg_mem);
  7421 %}
  7423 instruct addI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
  7424 %{
  7425   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7426   effect(KILL cr);
  7428   ins_cost(150); // XXX
  7429   format %{ "addl    $dst, $src\t# int" %}
  7430   opcode(0x01); /* Opcode 01 /r */
  7431   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  7432   ins_pipe(ialu_mem_reg);
  7433 %}
  7435 instruct addI_mem_imm(memory dst, immI src, rFlagsReg cr)
  7436 %{
  7437   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7438   effect(KILL cr);
  7440   ins_cost(125); // XXX
  7441   format %{ "addl    $dst, $src\t# int" %}
  7442   opcode(0x81); /* Opcode 81 /0 id */
  7443   ins_encode(REX_mem(dst), OpcSE(src), RM_opc_mem(0x00, dst), Con8or32(src));
  7444   ins_pipe(ialu_mem_imm);
  7445 %}
  7447 instruct incI_rReg(rRegI dst, immI1 src, rFlagsReg cr)
  7448 %{
  7449   predicate(UseIncDec);
  7450   match(Set dst (AddI dst src));
  7451   effect(KILL cr);
  7453   format %{ "incl    $dst\t# int" %}
  7454   opcode(0xFF, 0x00); // FF /0
  7455   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  7456   ins_pipe(ialu_reg);
  7457 %}
  7459 instruct incI_mem(memory dst, immI1 src, rFlagsReg cr)
  7460 %{
  7461   predicate(UseIncDec);
  7462   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7463   effect(KILL cr);
  7465   ins_cost(125); // XXX
  7466   format %{ "incl    $dst\t# int" %}
  7467   opcode(0xFF); /* Opcode FF /0 */
  7468   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(0x00, dst));
  7469   ins_pipe(ialu_mem_imm);
  7470 %}
  7472 // XXX why does that use AddI
  7473 instruct decI_rReg(rRegI dst, immI_M1 src, rFlagsReg cr)
  7474 %{
  7475   predicate(UseIncDec);
  7476   match(Set dst (AddI dst src));
  7477   effect(KILL cr);
  7479   format %{ "decl    $dst\t# int" %}
  7480   opcode(0xFF, 0x01); // FF /1
  7481   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  7482   ins_pipe(ialu_reg);
  7483 %}
  7485 // XXX why does that use AddI
  7486 instruct decI_mem(memory dst, immI_M1 src, rFlagsReg cr)
  7487 %{
  7488   predicate(UseIncDec);
  7489   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
  7490   effect(KILL cr);
  7492   ins_cost(125); // XXX
  7493   format %{ "decl    $dst\t# int" %}
  7494   opcode(0xFF); /* Opcode FF /1 */
  7495   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(0x01, dst));
  7496   ins_pipe(ialu_mem_imm);
  7497 %}
  7499 instruct leaI_rReg_immI(rRegI dst, rRegI src0, immI src1)
  7500 %{
  7501   match(Set dst (AddI src0 src1));
  7503   ins_cost(110);
  7504   format %{ "addr32 leal $dst, [$src0 + $src1]\t# int" %}
  7505   opcode(0x8D); /* 0x8D /r */
  7506   ins_encode(Opcode(0x67), REX_reg_reg(dst, src0), OpcP, reg_lea(dst, src0, src1)); // XXX
  7507   ins_pipe(ialu_reg_reg);
  7508 %}
  7510 instruct addL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  7511 %{
  7512   match(Set dst (AddL dst src));
  7513   effect(KILL cr);
  7515   format %{ "addq    $dst, $src\t# long" %}
  7516   opcode(0x03);
  7517   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  7518   ins_pipe(ialu_reg_reg);
  7519 %}
  7521 instruct addL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
  7522 %{
  7523   match(Set dst (AddL dst src));
  7524   effect(KILL cr);
  7526   format %{ "addq    $dst, $src\t# long" %}
  7527   opcode(0x81, 0x00); /* /0 id */
  7528   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  7529   ins_pipe( ialu_reg );
  7530 %}
  7532 instruct addL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
  7533 %{
  7534   match(Set dst (AddL dst (LoadL src)));
  7535   effect(KILL cr);
  7537   ins_cost(125); // XXX
  7538   format %{ "addq    $dst, $src\t# long" %}
  7539   opcode(0x03);
  7540   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  7541   ins_pipe(ialu_reg_mem);
  7542 %}
  7544 instruct addL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
  7545 %{
  7546   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
  7547   effect(KILL cr);
  7549   ins_cost(150); // XXX
  7550   format %{ "addq    $dst, $src\t# long" %}
  7551   opcode(0x01); /* Opcode 01 /r */
  7552   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  7553   ins_pipe(ialu_mem_reg);
  7554 %}
  7556 instruct addL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
  7557 %{
  7558   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
  7559   effect(KILL cr);
  7561   ins_cost(125); // XXX
  7562   format %{ "addq    $dst, $src\t# long" %}
  7563   opcode(0x81); /* Opcode 81 /0 id */
  7564   ins_encode(REX_mem_wide(dst),
  7565              OpcSE(src), RM_opc_mem(0x00, dst), Con8or32(src));
  7566   ins_pipe(ialu_mem_imm);
  7567 %}
  7569 instruct incL_rReg(rRegI dst, immL1 src, rFlagsReg cr)
  7570 %{
  7571   predicate(UseIncDec);
  7572   match(Set dst (AddL dst src));
  7573   effect(KILL cr);
  7575   format %{ "incq    $dst\t# long" %}
  7576   opcode(0xFF, 0x00); // FF /0
  7577   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  7578   ins_pipe(ialu_reg);
  7579 %}
  7581 instruct incL_mem(memory dst, immL1 src, rFlagsReg cr)
  7582 %{
  7583   predicate(UseIncDec);
  7584   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
  7585   effect(KILL cr);
  7587   ins_cost(125); // XXX
  7588   format %{ "incq    $dst\t# long" %}
  7589   opcode(0xFF); /* Opcode FF /0 */
  7590   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(0x00, dst));
  7591   ins_pipe(ialu_mem_imm);
  7592 %}
  7594 // XXX why does that use AddL
  7595 instruct decL_rReg(rRegL dst, immL_M1 src, rFlagsReg cr)
  7596 %{
  7597   predicate(UseIncDec);
  7598   match(Set dst (AddL dst src));
  7599   effect(KILL cr);
  7601   format %{ "decq    $dst\t# long" %}
  7602   opcode(0xFF, 0x01); // FF /1
  7603   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  7604   ins_pipe(ialu_reg);
  7605 %}
  7607 // XXX why does that use AddL
  7608 instruct decL_mem(memory dst, immL_M1 src, rFlagsReg cr)
  7609 %{
  7610   predicate(UseIncDec);
  7611   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
  7612   effect(KILL cr);
  7614   ins_cost(125); // XXX
  7615   format %{ "decq    $dst\t# long" %}
  7616   opcode(0xFF); /* Opcode FF /1 */
  7617   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(0x01, dst));
  7618   ins_pipe(ialu_mem_imm);
  7619 %}
  7621 instruct leaL_rReg_immL(rRegL dst, rRegL src0, immL32 src1)
  7622 %{
  7623   match(Set dst (AddL src0 src1));
  7625   ins_cost(110);
  7626   format %{ "leaq    $dst, [$src0 + $src1]\t# long" %}
  7627   opcode(0x8D); /* 0x8D /r */
  7628   ins_encode(REX_reg_reg_wide(dst, src0), OpcP, reg_lea(dst, src0, src1)); // XXX
  7629   ins_pipe(ialu_reg_reg);
  7630 %}
  7632 instruct addP_rReg(rRegP dst, rRegL src, rFlagsReg cr)
  7633 %{
  7634   match(Set dst (AddP dst src));
  7635   effect(KILL cr);
  7637   format %{ "addq    $dst, $src\t# ptr" %}
  7638   opcode(0x03);
  7639   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  7640   ins_pipe(ialu_reg_reg);
  7641 %}
  7643 instruct addP_rReg_imm(rRegP dst, immL32 src, rFlagsReg cr)
  7644 %{
  7645   match(Set dst (AddP dst src));
  7646   effect(KILL cr);
  7648   format %{ "addq    $dst, $src\t# ptr" %}
  7649   opcode(0x81, 0x00); /* /0 id */
  7650   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  7651   ins_pipe( ialu_reg );
  7652 %}
  7654 // XXX addP mem ops ????
  7656 instruct leaP_rReg_imm(rRegP dst, rRegP src0, immL32 src1)
  7657 %{
  7658   match(Set dst (AddP src0 src1));
  7660   ins_cost(110);
  7661   format %{ "leaq    $dst, [$src0 + $src1]\t# ptr" %}
  7662   opcode(0x8D); /* 0x8D /r */
  7663   ins_encode(REX_reg_reg_wide(dst, src0), OpcP, reg_lea(dst, src0, src1));// XXX
  7664   ins_pipe(ialu_reg_reg);
  7665 %}
  7667 instruct checkCastPP(rRegP dst)
  7668 %{
  7669   match(Set dst (CheckCastPP dst));
  7671   size(0);
  7672   format %{ "# checkcastPP of $dst" %}
  7673   ins_encode(/* empty encoding */);
  7674   ins_pipe(empty);
  7675 %}
  7677 instruct castPP(rRegP dst)
  7678 %{
  7679   match(Set dst (CastPP dst));
  7681   size(0);
  7682   format %{ "# castPP of $dst" %}
  7683   ins_encode(/* empty encoding */);
  7684   ins_pipe(empty);
  7685 %}
  7687 instruct castII(rRegI dst)
  7688 %{
  7689   match(Set dst (CastII dst));
  7691   size(0);
  7692   format %{ "# castII of $dst" %}
  7693   ins_encode(/* empty encoding */);
  7694   ins_cost(0);
  7695   ins_pipe(empty);
  7696 %}
  7698 // LoadP-locked same as a regular LoadP when used with compare-swap
  7699 instruct loadPLocked(rRegP dst, memory mem)
  7700 %{
  7701   match(Set dst (LoadPLocked mem));
  7703   ins_cost(125); // XXX
  7704   format %{ "movq    $dst, $mem\t# ptr locked" %}
  7705   opcode(0x8B);
  7706   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  7707   ins_pipe(ialu_reg_mem); // XXX
  7708 %}
  7710 // LoadL-locked - same as a regular LoadL when used with compare-swap
  7711 instruct loadLLocked(rRegL dst, memory mem)
  7712 %{
  7713   match(Set dst (LoadLLocked mem));
  7715   ins_cost(125); // XXX
  7716   format %{ "movq    $dst, $mem\t# long locked" %}
  7717   opcode(0x8B);
  7718   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
  7719   ins_pipe(ialu_reg_mem); // XXX
  7720 %}
  7722 // Conditional-store of the updated heap-top.
  7723 // Used during allocation of the shared heap.
  7724 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
  7726 instruct storePConditional(memory heap_top_ptr,
  7727                            rax_RegP oldval, rRegP newval,
  7728                            rFlagsReg cr)
  7729 %{
  7730   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
  7732   format %{ "cmpxchgq $heap_top_ptr, $newval\t# (ptr) "
  7733             "If rax == $heap_top_ptr then store $newval into $heap_top_ptr" %}
  7734   opcode(0x0F, 0xB1);
  7735   ins_encode(lock_prefix,
  7736              REX_reg_mem_wide(newval, heap_top_ptr),
  7737              OpcP, OpcS,
  7738              reg_mem(newval, heap_top_ptr));
  7739   ins_pipe(pipe_cmpxchg);
  7740 %}
  7742 // Conditional-store of a long value
  7743 // Returns a boolean value (0/1) on success.  Implemented with a
  7744 // CMPXCHG8 on Intel.  mem_ptr can actually be in either RSI or RDI
  7746 instruct storeLConditional(rRegI res,
  7747                            memory mem_ptr,
  7748                            rax_RegL oldval, rRegL newval,
  7749                            rFlagsReg cr)
  7750 %{
  7751   match(Set res (StoreLConditional mem_ptr (Binary oldval newval)));
  7752   effect(KILL cr);
  7754   format %{ "cmpxchgq $mem_ptr, $newval\t# (long) "
  7755             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
  7756             "sete    $res\n\t"
  7757             "movzbl  $res, $res" %}
  7758   opcode(0x0F, 0xB1);
  7759   ins_encode(lock_prefix,
  7760              REX_reg_mem_wide(newval, mem_ptr),
  7761              OpcP, OpcS,
  7762              reg_mem(newval, mem_ptr),
  7763              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
  7764              REX_reg_breg(res, res), // movzbl
  7765              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
  7766   ins_pipe(pipe_cmpxchg);
  7767 %}
  7769 // Conditional-store of a long value
  7770 // ZF flag is set on success, reset otherwise. Implemented with a
  7771 // CMPXCHG8 on Intel.  mem_ptr can actually be in either RSI or RDI
  7772 instruct storeLConditional_flags(memory mem_ptr,
  7773                                  rax_RegL oldval, rRegL newval,
  7774                                  rFlagsReg cr,
  7775                                  immI0 zero)
  7776 %{
  7777   match(Set cr (CmpI (StoreLConditional mem_ptr (Binary oldval newval)) zero));
  7779   format %{ "cmpxchgq $mem_ptr, $newval\t# (long) "
  7780             "If rax == $mem_ptr then store $newval into $mem_ptr" %}
  7781   opcode(0x0F, 0xB1);
  7782   ins_encode(lock_prefix,
  7783              REX_reg_mem_wide(newval, mem_ptr),
  7784              OpcP, OpcS,
  7785              reg_mem(newval, mem_ptr));
  7786   ins_pipe(pipe_cmpxchg);
  7787 %}
  7789 instruct compareAndSwapP(rRegI res,
  7790                          memory mem_ptr,
  7791                          rax_RegP oldval, rRegP newval,
  7792                          rFlagsReg cr)
  7793 %{
  7794   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
  7795   effect(KILL cr, KILL oldval);
  7797   format %{ "cmpxchgq $mem_ptr,$newval\t# "
  7798             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
  7799             "sete    $res\n\t"
  7800             "movzbl  $res, $res" %}
  7801   opcode(0x0F, 0xB1);
  7802   ins_encode(lock_prefix,
  7803              REX_reg_mem_wide(newval, mem_ptr),
  7804              OpcP, OpcS,
  7805              reg_mem(newval, mem_ptr),
  7806              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
  7807              REX_reg_breg(res, res), // movzbl
  7808              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
  7809   ins_pipe( pipe_cmpxchg );
  7810 %}
  7812 // XXX No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
  7813 instruct compareAndSwapL(rRegI res,
  7814                          memory mem_ptr,
  7815                          rax_RegL oldval, rRegL newval,
  7816                          rFlagsReg cr)
  7817 %{
  7818   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
  7819   effect(KILL cr, KILL oldval);
  7821   format %{ "cmpxchgq $mem_ptr,$newval\t# "
  7822             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
  7823             "sete    $res\n\t"
  7824             "movzbl  $res, $res" %}
  7825   opcode(0x0F, 0xB1);
  7826   ins_encode(lock_prefix,
  7827              REX_reg_mem_wide(newval, mem_ptr),
  7828              OpcP, OpcS,
  7829              reg_mem(newval, mem_ptr),
  7830              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
  7831              REX_reg_breg(res, res), // movzbl
  7832              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
  7833   ins_pipe( pipe_cmpxchg );
  7834 %}
  7836 instruct compareAndSwapI(rRegI res,
  7837                          memory mem_ptr,
  7838                          rax_RegI oldval, rRegI newval,
  7839                          rFlagsReg cr)
  7840 %{
  7841   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
  7842   effect(KILL cr, KILL oldval);
  7844   format %{ "cmpxchgl $mem_ptr,$newval\t# "
  7845             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
  7846             "sete    $res\n\t"
  7847             "movzbl  $res, $res" %}
  7848   opcode(0x0F, 0xB1);
  7849   ins_encode(lock_prefix,
  7850              REX_reg_mem(newval, mem_ptr),
  7851              OpcP, OpcS,
  7852              reg_mem(newval, mem_ptr),
  7853              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
  7854              REX_reg_breg(res, res), // movzbl
  7855              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
  7856   ins_pipe( pipe_cmpxchg );
  7857 %}
  7860 instruct compareAndSwapN(rRegI res,
  7861                           memory mem_ptr,
  7862                           rax_RegN oldval, rRegN newval,
  7863                           rFlagsReg cr) %{
  7864   match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval)));
  7865   effect(KILL cr, KILL oldval);
  7867   format %{ "cmpxchgl $mem_ptr,$newval\t# "
  7868             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
  7869             "sete    $res\n\t"
  7870             "movzbl  $res, $res" %}
  7871   opcode(0x0F, 0xB1);
  7872   ins_encode(lock_prefix,
  7873              REX_reg_mem(newval, mem_ptr),
  7874              OpcP, OpcS,
  7875              reg_mem(newval, mem_ptr),
  7876              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
  7877              REX_reg_breg(res, res), // movzbl
  7878              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
  7879   ins_pipe( pipe_cmpxchg );
  7880 %}
  7882 //----------Subtraction Instructions-------------------------------------------
  7884 // Integer Subtraction Instructions
  7885 instruct subI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  7886 %{
  7887   match(Set dst (SubI dst src));
  7888   effect(KILL cr);
  7890   format %{ "subl    $dst, $src\t# int" %}
  7891   opcode(0x2B);
  7892   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
  7893   ins_pipe(ialu_reg_reg);
  7894 %}
  7896 instruct subI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
  7897 %{
  7898   match(Set dst (SubI dst src));
  7899   effect(KILL cr);
  7901   format %{ "subl    $dst, $src\t# int" %}
  7902   opcode(0x81, 0x05);  /* Opcode 81 /5 */
  7903   ins_encode(OpcSErm(dst, src), Con8or32(src));
  7904   ins_pipe(ialu_reg);
  7905 %}
  7907 instruct subI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
  7908 %{
  7909   match(Set dst (SubI dst (LoadI src)));
  7910   effect(KILL cr);
  7912   ins_cost(125);
  7913   format %{ "subl    $dst, $src\t# int" %}
  7914   opcode(0x2B);
  7915   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  7916   ins_pipe(ialu_reg_mem);
  7917 %}
  7919 instruct subI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
  7920 %{
  7921   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
  7922   effect(KILL cr);
  7924   ins_cost(150);
  7925   format %{ "subl    $dst, $src\t# int" %}
  7926   opcode(0x29); /* Opcode 29 /r */
  7927   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  7928   ins_pipe(ialu_mem_reg);
  7929 %}
  7931 instruct subI_mem_imm(memory dst, immI src, rFlagsReg cr)
  7932 %{
  7933   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
  7934   effect(KILL cr);
  7936   ins_cost(125); // XXX
  7937   format %{ "subl    $dst, $src\t# int" %}
  7938   opcode(0x81); /* Opcode 81 /5 id */
  7939   ins_encode(REX_mem(dst), OpcSE(src), RM_opc_mem(0x05, dst), Con8or32(src));
  7940   ins_pipe(ialu_mem_imm);
  7941 %}
  7943 instruct subL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  7944 %{
  7945   match(Set dst (SubL dst src));
  7946   effect(KILL cr);
  7948   format %{ "subq    $dst, $src\t# long" %}
  7949   opcode(0x2B);
  7950   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  7951   ins_pipe(ialu_reg_reg);
  7952 %}
  7954 instruct subL_rReg_imm(rRegI dst, immL32 src, rFlagsReg cr)
  7955 %{
  7956   match(Set dst (SubL dst src));
  7957   effect(KILL cr);
  7959   format %{ "subq    $dst, $src\t# long" %}
  7960   opcode(0x81, 0x05);  /* Opcode 81 /5 */
  7961   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  7962   ins_pipe(ialu_reg);
  7963 %}
  7965 instruct subL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
  7966 %{
  7967   match(Set dst (SubL dst (LoadL src)));
  7968   effect(KILL cr);
  7970   ins_cost(125);
  7971   format %{ "subq    $dst, $src\t# long" %}
  7972   opcode(0x2B);
  7973   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  7974   ins_pipe(ialu_reg_mem);
  7975 %}
  7977 instruct subL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
  7978 %{
  7979   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
  7980   effect(KILL cr);
  7982   ins_cost(150);
  7983   format %{ "subq    $dst, $src\t# long" %}
  7984   opcode(0x29); /* Opcode 29 /r */
  7985   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  7986   ins_pipe(ialu_mem_reg);
  7987 %}
  7989 instruct subL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
  7990 %{
  7991   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
  7992   effect(KILL cr);
  7994   ins_cost(125); // XXX
  7995   format %{ "subq    $dst, $src\t# long" %}
  7996   opcode(0x81); /* Opcode 81 /5 id */
  7997   ins_encode(REX_mem_wide(dst),
  7998              OpcSE(src), RM_opc_mem(0x05, dst), Con8or32(src));
  7999   ins_pipe(ialu_mem_imm);
  8000 %}
  8002 // Subtract from a pointer
  8003 // XXX hmpf???
  8004 instruct subP_rReg(rRegP dst, rRegI src, immI0 zero, rFlagsReg cr)
  8005 %{
  8006   match(Set dst (AddP dst (SubI zero src)));
  8007   effect(KILL cr);
  8009   format %{ "subq    $dst, $src\t# ptr - int" %}
  8010   opcode(0x2B);
  8011   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  8012   ins_pipe(ialu_reg_reg);
  8013 %}
  8015 instruct negI_rReg(rRegI dst, immI0 zero, rFlagsReg cr)
  8016 %{
  8017   match(Set dst (SubI zero dst));
  8018   effect(KILL cr);
  8020   format %{ "negl    $dst\t# int" %}
  8021   opcode(0xF7, 0x03);  // Opcode F7 /3
  8022   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8023   ins_pipe(ialu_reg);
  8024 %}
  8026 instruct negI_mem(memory dst, immI0 zero, rFlagsReg cr)
  8027 %{
  8028   match(Set dst (StoreI dst (SubI zero (LoadI dst))));
  8029   effect(KILL cr);
  8031   format %{ "negl    $dst\t# int" %}
  8032   opcode(0xF7, 0x03);  // Opcode F7 /3
  8033   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8034   ins_pipe(ialu_reg);
  8035 %}
  8037 instruct negL_rReg(rRegL dst, immL0 zero, rFlagsReg cr)
  8038 %{
  8039   match(Set dst (SubL zero dst));
  8040   effect(KILL cr);
  8042   format %{ "negq    $dst\t# long" %}
  8043   opcode(0xF7, 0x03);  // Opcode F7 /3
  8044   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8045   ins_pipe(ialu_reg);
  8046 %}
  8048 instruct negL_mem(memory dst, immL0 zero, rFlagsReg cr)
  8049 %{
  8050   match(Set dst (StoreL dst (SubL zero (LoadL dst))));
  8051   effect(KILL cr);
  8053   format %{ "negq    $dst\t# long" %}
  8054   opcode(0xF7, 0x03);  // Opcode F7 /3
  8055   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8056   ins_pipe(ialu_reg);
  8057 %}
  8060 //----------Multiplication/Division Instructions-------------------------------
  8061 // Integer Multiplication Instructions
  8062 // Multiply Register
  8064 instruct mulI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  8065 %{
  8066   match(Set dst (MulI dst src));
  8067   effect(KILL cr);
  8069   ins_cost(300);
  8070   format %{ "imull   $dst, $src\t# int" %}
  8071   opcode(0x0F, 0xAF);
  8072   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
  8073   ins_pipe(ialu_reg_reg_alu0);
  8074 %}
  8076 instruct mulI_rReg_imm(rRegI dst, rRegI src, immI imm, rFlagsReg cr)
  8077 %{
  8078   match(Set dst (MulI src imm));
  8079   effect(KILL cr);
  8081   ins_cost(300);
  8082   format %{ "imull   $dst, $src, $imm\t# int" %}
  8083   opcode(0x69); /* 69 /r id */
  8084   ins_encode(REX_reg_reg(dst, src),
  8085              OpcSE(imm), reg_reg(dst, src), Con8or32(imm));
  8086   ins_pipe(ialu_reg_reg_alu0);
  8087 %}
  8089 instruct mulI_mem(rRegI dst, memory src, rFlagsReg cr)
  8090 %{
  8091   match(Set dst (MulI dst (LoadI src)));
  8092   effect(KILL cr);
  8094   ins_cost(350);
  8095   format %{ "imull   $dst, $src\t# int" %}
  8096   opcode(0x0F, 0xAF);
  8097   ins_encode(REX_reg_mem(dst, src), OpcP, OpcS, reg_mem(dst, src));
  8098   ins_pipe(ialu_reg_mem_alu0);
  8099 %}
  8101 instruct mulI_mem_imm(rRegI dst, memory src, immI imm, rFlagsReg cr)
  8102 %{
  8103   match(Set dst (MulI (LoadI src) imm));
  8104   effect(KILL cr);
  8106   ins_cost(300);
  8107   format %{ "imull   $dst, $src, $imm\t# int" %}
  8108   opcode(0x69); /* 69 /r id */
  8109   ins_encode(REX_reg_mem(dst, src),
  8110              OpcSE(imm), reg_mem(dst, src), Con8or32(imm));
  8111   ins_pipe(ialu_reg_mem_alu0);
  8112 %}
  8114 instruct mulL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  8115 %{
  8116   match(Set dst (MulL dst src));
  8117   effect(KILL cr);
  8119   ins_cost(300);
  8120   format %{ "imulq   $dst, $src\t# long" %}
  8121   opcode(0x0F, 0xAF);
  8122   ins_encode(REX_reg_reg_wide(dst, src), OpcP, OpcS, reg_reg(dst, src));
  8123   ins_pipe(ialu_reg_reg_alu0);
  8124 %}
  8126 instruct mulL_rReg_imm(rRegL dst, rRegL src, immL32 imm, rFlagsReg cr)
  8127 %{
  8128   match(Set dst (MulL src imm));
  8129   effect(KILL cr);
  8131   ins_cost(300);
  8132   format %{ "imulq   $dst, $src, $imm\t# long" %}
  8133   opcode(0x69); /* 69 /r id */
  8134   ins_encode(REX_reg_reg_wide(dst, src),
  8135              OpcSE(imm), reg_reg(dst, src), Con8or32(imm));
  8136   ins_pipe(ialu_reg_reg_alu0);
  8137 %}
  8139 instruct mulL_mem(rRegL dst, memory src, rFlagsReg cr)
  8140 %{
  8141   match(Set dst (MulL dst (LoadL src)));
  8142   effect(KILL cr);
  8144   ins_cost(350);
  8145   format %{ "imulq   $dst, $src\t# long" %}
  8146   opcode(0x0F, 0xAF);
  8147   ins_encode(REX_reg_mem_wide(dst, src), OpcP, OpcS, reg_mem(dst, src));
  8148   ins_pipe(ialu_reg_mem_alu0);
  8149 %}
  8151 instruct mulL_mem_imm(rRegL dst, memory src, immL32 imm, rFlagsReg cr)
  8152 %{
  8153   match(Set dst (MulL (LoadL src) imm));
  8154   effect(KILL cr);
  8156   ins_cost(300);
  8157   format %{ "imulq   $dst, $src, $imm\t# long" %}
  8158   opcode(0x69); /* 69 /r id */
  8159   ins_encode(REX_reg_mem_wide(dst, src),
  8160              OpcSE(imm), reg_mem(dst, src), Con8or32(imm));
  8161   ins_pipe(ialu_reg_mem_alu0);
  8162 %}
  8164 instruct mulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
  8165 %{
  8166   match(Set dst (MulHiL src rax));
  8167   effect(USE_KILL rax, KILL cr);
  8169   ins_cost(300);
  8170   format %{ "imulq   RDX:RAX, RAX, $src\t# mulhi" %}
  8171   opcode(0xF7, 0x5); /* Opcode F7 /5 */
  8172   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src));
  8173   ins_pipe(ialu_reg_reg_alu0);
  8174 %}
  8176 instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
  8177                    rFlagsReg cr)
  8178 %{
  8179   match(Set rax (DivI rax div));
  8180   effect(KILL rdx, KILL cr);
  8182   ins_cost(30*100+10*100); // XXX
  8183   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
  8184             "jne,s   normal\n\t"
  8185             "xorl    rdx, rdx\n\t"
  8186             "cmpl    $div, -1\n\t"
  8187             "je,s    done\n"
  8188     "normal: cdql\n\t"
  8189             "idivl   $div\n"
  8190     "done:"        %}
  8191   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8192   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
  8193   ins_pipe(ialu_reg_reg_alu0);
  8194 %}
  8196 instruct divL_rReg(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
  8197                    rFlagsReg cr)
  8198 %{
  8199   match(Set rax (DivL rax div));
  8200   effect(KILL rdx, KILL cr);
  8202   ins_cost(30*100+10*100); // XXX
  8203   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
  8204             "cmpq    rax, rdx\n\t"
  8205             "jne,s   normal\n\t"
  8206             "xorl    rdx, rdx\n\t"
  8207             "cmpq    $div, -1\n\t"
  8208             "je,s    done\n"
  8209     "normal: cdqq\n\t"
  8210             "idivq   $div\n"
  8211     "done:"        %}
  8212   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8213   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
  8214   ins_pipe(ialu_reg_reg_alu0);
  8215 %}
  8217 // Integer DIVMOD with Register, both quotient and mod results
  8218 instruct divModI_rReg_divmod(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
  8219                              rFlagsReg cr)
  8220 %{
  8221   match(DivModI rax div);
  8222   effect(KILL cr);
  8224   ins_cost(30*100+10*100); // XXX
  8225   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
  8226             "jne,s   normal\n\t"
  8227             "xorl    rdx, rdx\n\t"
  8228             "cmpl    $div, -1\n\t"
  8229             "je,s    done\n"
  8230     "normal: cdql\n\t"
  8231             "idivl   $div\n"
  8232     "done:"        %}
  8233   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8234   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
  8235   ins_pipe(pipe_slow);
  8236 %}
  8238 // Long DIVMOD with Register, both quotient and mod results
  8239 instruct divModL_rReg_divmod(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
  8240                              rFlagsReg cr)
  8241 %{
  8242   match(DivModL rax div);
  8243   effect(KILL cr);
  8245   ins_cost(30*100+10*100); // XXX
  8246   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
  8247             "cmpq    rax, rdx\n\t"
  8248             "jne,s   normal\n\t"
  8249             "xorl    rdx, rdx\n\t"
  8250             "cmpq    $div, -1\n\t"
  8251             "je,s    done\n"
  8252     "normal: cdqq\n\t"
  8253             "idivq   $div\n"
  8254     "done:"        %}
  8255   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8256   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
  8257   ins_pipe(pipe_slow);
  8258 %}
  8260 //----------- DivL-By-Constant-Expansions--------------------------------------
  8261 // DivI cases are handled by the compiler
  8263 // Magic constant, reciprical of 10
  8264 instruct loadConL_0x6666666666666667(rRegL dst)
  8265 %{
  8266   effect(DEF dst);
  8268   format %{ "movq    $dst, #0x666666666666667\t# Used in div-by-10" %}
  8269   ins_encode(load_immL(dst, 0x6666666666666667));
  8270   ins_pipe(ialu_reg);
  8271 %}
  8273 instruct mul_hi(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
  8274 %{
  8275   effect(DEF dst, USE src, USE_KILL rax, KILL cr);
  8277   format %{ "imulq   rdx:rax, rax, $src\t# Used in div-by-10" %}
  8278   opcode(0xF7, 0x5); /* Opcode F7 /5 */
  8279   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src));
  8280   ins_pipe(ialu_reg_reg_alu0);
  8281 %}
  8283 instruct sarL_rReg_63(rRegL dst, rFlagsReg cr)
  8284 %{
  8285   effect(USE_DEF dst, KILL cr);
  8287   format %{ "sarq    $dst, #63\t# Used in div-by-10" %}
  8288   opcode(0xC1, 0x7); /* C1 /7 ib */
  8289   ins_encode(reg_opc_imm_wide(dst, 0x3F));
  8290   ins_pipe(ialu_reg);
  8291 %}
  8293 instruct sarL_rReg_2(rRegL dst, rFlagsReg cr)
  8294 %{
  8295   effect(USE_DEF dst, KILL cr);
  8297   format %{ "sarq    $dst, #2\t# Used in div-by-10" %}
  8298   opcode(0xC1, 0x7); /* C1 /7 ib */
  8299   ins_encode(reg_opc_imm_wide(dst, 0x2));
  8300   ins_pipe(ialu_reg);
  8301 %}
  8303 instruct divL_10(rdx_RegL dst, no_rax_RegL src, immL10 div)
  8304 %{
  8305   match(Set dst (DivL src div));
  8307   ins_cost((5+8)*100);
  8308   expand %{
  8309     rax_RegL rax;                     // Killed temp
  8310     rFlagsReg cr;                     // Killed
  8311     loadConL_0x6666666666666667(rax); // movq  rax, 0x6666666666666667
  8312     mul_hi(dst, src, rax, cr);        // mulq  rdx:rax <= rax * $src
  8313     sarL_rReg_63(src, cr);            // sarq  src, 63
  8314     sarL_rReg_2(dst, cr);             // sarq  rdx, 2
  8315     subL_rReg(dst, src, cr);          // subl  rdx, src
  8316   %}
  8317 %}
  8319 //-----------------------------------------------------------------------------
  8321 instruct modI_rReg(rdx_RegI rdx, rax_RegI rax, no_rax_rdx_RegI div,
  8322                    rFlagsReg cr)
  8323 %{
  8324   match(Set rdx (ModI rax div));
  8325   effect(KILL rax, KILL cr);
  8327   ins_cost(300); // XXX
  8328   format %{ "cmpl    rax, 0x80000000\t# irem\n\t"
  8329             "jne,s   normal\n\t"
  8330             "xorl    rdx, rdx\n\t"
  8331             "cmpl    $div, -1\n\t"
  8332             "je,s    done\n"
  8333     "normal: cdql\n\t"
  8334             "idivl   $div\n"
  8335     "done:"        %}
  8336   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8337   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
  8338   ins_pipe(ialu_reg_reg_alu0);
  8339 %}
  8341 instruct modL_rReg(rdx_RegL rdx, rax_RegL rax, no_rax_rdx_RegL div,
  8342                    rFlagsReg cr)
  8343 %{
  8344   match(Set rdx (ModL rax div));
  8345   effect(KILL rax, KILL cr);
  8347   ins_cost(300); // XXX
  8348   format %{ "movq    rdx, 0x8000000000000000\t# lrem\n\t"
  8349             "cmpq    rax, rdx\n\t"
  8350             "jne,s   normal\n\t"
  8351             "xorl    rdx, rdx\n\t"
  8352             "cmpq    $div, -1\n\t"
  8353             "je,s    done\n"
  8354     "normal: cdqq\n\t"
  8355             "idivq   $div\n"
  8356     "done:"        %}
  8357   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
  8358   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
  8359   ins_pipe(ialu_reg_reg_alu0);
  8360 %}
  8362 // Integer Shift Instructions
  8363 // Shift Left by one
  8364 instruct salI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
  8365 %{
  8366   match(Set dst (LShiftI dst shift));
  8367   effect(KILL cr);
  8369   format %{ "sall    $dst, $shift" %}
  8370   opcode(0xD1, 0x4); /* D1 /4 */
  8371   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8372   ins_pipe(ialu_reg);
  8373 %}
  8375 // Shift Left by one
  8376 instruct salI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8377 %{
  8378   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
  8379   effect(KILL cr);
  8381   format %{ "sall    $dst, $shift\t" %}
  8382   opcode(0xD1, 0x4); /* D1 /4 */
  8383   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8384   ins_pipe(ialu_mem_imm);
  8385 %}
  8387 // Shift Left by 8-bit immediate
  8388 instruct salI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
  8389 %{
  8390   match(Set dst (LShiftI dst shift));
  8391   effect(KILL cr);
  8393   format %{ "sall    $dst, $shift" %}
  8394   opcode(0xC1, 0x4); /* C1 /4 ib */
  8395   ins_encode(reg_opc_imm(dst, shift));
  8396   ins_pipe(ialu_reg);
  8397 %}
  8399 // Shift Left by 8-bit immediate
  8400 instruct salI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8401 %{
  8402   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
  8403   effect(KILL cr);
  8405   format %{ "sall    $dst, $shift" %}
  8406   opcode(0xC1, 0x4); /* C1 /4 ib */
  8407   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
  8408   ins_pipe(ialu_mem_imm);
  8409 %}
  8411 // Shift Left by variable
  8412 instruct salI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
  8413 %{
  8414   match(Set dst (LShiftI dst shift));
  8415   effect(KILL cr);
  8417   format %{ "sall    $dst, $shift" %}
  8418   opcode(0xD3, 0x4); /* D3 /4 */
  8419   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8420   ins_pipe(ialu_reg_reg);
  8421 %}
  8423 // Shift Left by variable
  8424 instruct salI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8425 %{
  8426   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
  8427   effect(KILL cr);
  8429   format %{ "sall    $dst, $shift" %}
  8430   opcode(0xD3, 0x4); /* D3 /4 */
  8431   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8432   ins_pipe(ialu_mem_reg);
  8433 %}
  8435 // Arithmetic shift right by one
  8436 instruct sarI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
  8437 %{
  8438   match(Set dst (RShiftI dst shift));
  8439   effect(KILL cr);
  8441   format %{ "sarl    $dst, $shift" %}
  8442   opcode(0xD1, 0x7); /* D1 /7 */
  8443   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8444   ins_pipe(ialu_reg);
  8445 %}
  8447 // Arithmetic shift right by one
  8448 instruct sarI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8449 %{
  8450   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  8451   effect(KILL cr);
  8453   format %{ "sarl    $dst, $shift" %}
  8454   opcode(0xD1, 0x7); /* D1 /7 */
  8455   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8456   ins_pipe(ialu_mem_imm);
  8457 %}
  8459 // Arithmetic Shift Right by 8-bit immediate
  8460 instruct sarI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
  8461 %{
  8462   match(Set dst (RShiftI dst shift));
  8463   effect(KILL cr);
  8465   format %{ "sarl    $dst, $shift" %}
  8466   opcode(0xC1, 0x7); /* C1 /7 ib */
  8467   ins_encode(reg_opc_imm(dst, shift));
  8468   ins_pipe(ialu_mem_imm);
  8469 %}
  8471 // Arithmetic Shift Right by 8-bit immediate
  8472 instruct sarI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8473 %{
  8474   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  8475   effect(KILL cr);
  8477   format %{ "sarl    $dst, $shift" %}
  8478   opcode(0xC1, 0x7); /* C1 /7 ib */
  8479   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
  8480   ins_pipe(ialu_mem_imm);
  8481 %}
  8483 // Arithmetic Shift Right by variable
  8484 instruct sarI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
  8485 %{
  8486   match(Set dst (RShiftI dst shift));
  8487   effect(KILL cr);
  8489   format %{ "sarl    $dst, $shift" %}
  8490   opcode(0xD3, 0x7); /* D3 /7 */
  8491   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8492   ins_pipe(ialu_reg_reg);
  8493 %}
  8495 // Arithmetic Shift Right by variable
  8496 instruct sarI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8497 %{
  8498   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
  8499   effect(KILL cr);
  8501   format %{ "sarl    $dst, $shift" %}
  8502   opcode(0xD3, 0x7); /* D3 /7 */
  8503   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8504   ins_pipe(ialu_mem_reg);
  8505 %}
  8507 // Logical shift right by one
  8508 instruct shrI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
  8509 %{
  8510   match(Set dst (URShiftI dst shift));
  8511   effect(KILL cr);
  8513   format %{ "shrl    $dst, $shift" %}
  8514   opcode(0xD1, 0x5); /* D1 /5 */
  8515   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8516   ins_pipe(ialu_reg);
  8517 %}
  8519 // Logical shift right by one
  8520 instruct shrI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8521 %{
  8522   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
  8523   effect(KILL cr);
  8525   format %{ "shrl    $dst, $shift" %}
  8526   opcode(0xD1, 0x5); /* D1 /5 */
  8527   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8528   ins_pipe(ialu_mem_imm);
  8529 %}
  8531 // Logical Shift Right by 8-bit immediate
  8532 instruct shrI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
  8533 %{
  8534   match(Set dst (URShiftI dst shift));
  8535   effect(KILL cr);
  8537   format %{ "shrl    $dst, $shift" %}
  8538   opcode(0xC1, 0x5); /* C1 /5 ib */
  8539   ins_encode(reg_opc_imm(dst, shift));
  8540   ins_pipe(ialu_reg);
  8541 %}
  8543 // Logical Shift Right by 8-bit immediate
  8544 instruct shrI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8545 %{
  8546   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
  8547   effect(KILL cr);
  8549   format %{ "shrl    $dst, $shift" %}
  8550   opcode(0xC1, 0x5); /* C1 /5 ib */
  8551   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
  8552   ins_pipe(ialu_mem_imm);
  8553 %}
  8555 // Logical Shift Right by variable
  8556 instruct shrI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
  8557 %{
  8558   match(Set dst (URShiftI dst shift));
  8559   effect(KILL cr);
  8561   format %{ "shrl    $dst, $shift" %}
  8562   opcode(0xD3, 0x5); /* D3 /5 */
  8563   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8564   ins_pipe(ialu_reg_reg);
  8565 %}
  8567 // Logical Shift Right by variable
  8568 instruct shrI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8569 %{
  8570   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
  8571   effect(KILL cr);
  8573   format %{ "shrl    $dst, $shift" %}
  8574   opcode(0xD3, 0x5); /* D3 /5 */
  8575   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
  8576   ins_pipe(ialu_mem_reg);
  8577 %}
  8579 // Long Shift Instructions
  8580 // Shift Left by one
  8581 instruct salL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
  8582 %{
  8583   match(Set dst (LShiftL dst shift));
  8584   effect(KILL cr);
  8586   format %{ "salq    $dst, $shift" %}
  8587   opcode(0xD1, 0x4); /* D1 /4 */
  8588   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8589   ins_pipe(ialu_reg);
  8590 %}
  8592 // Shift Left by one
  8593 instruct salL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8594 %{
  8595   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
  8596   effect(KILL cr);
  8598   format %{ "salq    $dst, $shift" %}
  8599   opcode(0xD1, 0x4); /* D1 /4 */
  8600   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8601   ins_pipe(ialu_mem_imm);
  8602 %}
  8604 // Shift Left by 8-bit immediate
  8605 instruct salL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
  8606 %{
  8607   match(Set dst (LShiftL dst shift));
  8608   effect(KILL cr);
  8610   format %{ "salq    $dst, $shift" %}
  8611   opcode(0xC1, 0x4); /* C1 /4 ib */
  8612   ins_encode(reg_opc_imm_wide(dst, shift));
  8613   ins_pipe(ialu_reg);
  8614 %}
  8616 // Shift Left by 8-bit immediate
  8617 instruct salL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8618 %{
  8619   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
  8620   effect(KILL cr);
  8622   format %{ "salq    $dst, $shift" %}
  8623   opcode(0xC1, 0x4); /* C1 /4 ib */
  8624   ins_encode(REX_mem_wide(dst), OpcP,
  8625              RM_opc_mem(secondary, dst), Con8or32(shift));
  8626   ins_pipe(ialu_mem_imm);
  8627 %}
  8629 // Shift Left by variable
  8630 instruct salL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
  8631 %{
  8632   match(Set dst (LShiftL dst shift));
  8633   effect(KILL cr);
  8635   format %{ "salq    $dst, $shift" %}
  8636   opcode(0xD3, 0x4); /* D3 /4 */
  8637   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8638   ins_pipe(ialu_reg_reg);
  8639 %}
  8641 // Shift Left by variable
  8642 instruct salL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8643 %{
  8644   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
  8645   effect(KILL cr);
  8647   format %{ "salq    $dst, $shift" %}
  8648   opcode(0xD3, 0x4); /* D3 /4 */
  8649   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8650   ins_pipe(ialu_mem_reg);
  8651 %}
  8653 // Arithmetic shift right by one
  8654 instruct sarL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
  8655 %{
  8656   match(Set dst (RShiftL dst shift));
  8657   effect(KILL cr);
  8659   format %{ "sarq    $dst, $shift" %}
  8660   opcode(0xD1, 0x7); /* D1 /7 */
  8661   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8662   ins_pipe(ialu_reg);
  8663 %}
  8665 // Arithmetic shift right by one
  8666 instruct sarL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8667 %{
  8668   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
  8669   effect(KILL cr);
  8671   format %{ "sarq    $dst, $shift" %}
  8672   opcode(0xD1, 0x7); /* D1 /7 */
  8673   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8674   ins_pipe(ialu_mem_imm);
  8675 %}
  8677 // Arithmetic Shift Right by 8-bit immediate
  8678 instruct sarL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
  8679 %{
  8680   match(Set dst (RShiftL dst shift));
  8681   effect(KILL cr);
  8683   format %{ "sarq    $dst, $shift" %}
  8684   opcode(0xC1, 0x7); /* C1 /7 ib */
  8685   ins_encode(reg_opc_imm_wide(dst, shift));
  8686   ins_pipe(ialu_mem_imm);
  8687 %}
  8689 // Arithmetic Shift Right by 8-bit immediate
  8690 instruct sarL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8691 %{
  8692   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
  8693   effect(KILL cr);
  8695   format %{ "sarq    $dst, $shift" %}
  8696   opcode(0xC1, 0x7); /* C1 /7 ib */
  8697   ins_encode(REX_mem_wide(dst), OpcP,
  8698              RM_opc_mem(secondary, dst), Con8or32(shift));
  8699   ins_pipe(ialu_mem_imm);
  8700 %}
  8702 // Arithmetic Shift Right by variable
  8703 instruct sarL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
  8704 %{
  8705   match(Set dst (RShiftL dst shift));
  8706   effect(KILL cr);
  8708   format %{ "sarq    $dst, $shift" %}
  8709   opcode(0xD3, 0x7); /* D3 /7 */
  8710   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8711   ins_pipe(ialu_reg_reg);
  8712 %}
  8714 // Arithmetic Shift Right by variable
  8715 instruct sarL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8716 %{
  8717   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
  8718   effect(KILL cr);
  8720   format %{ "sarq    $dst, $shift" %}
  8721   opcode(0xD3, 0x7); /* D3 /7 */
  8722   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8723   ins_pipe(ialu_mem_reg);
  8724 %}
  8726 // Logical shift right by one
  8727 instruct shrL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
  8728 %{
  8729   match(Set dst (URShiftL dst shift));
  8730   effect(KILL cr);
  8732   format %{ "shrq    $dst, $shift" %}
  8733   opcode(0xD1, 0x5); /* D1 /5 */
  8734   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst ));
  8735   ins_pipe(ialu_reg);
  8736 %}
  8738 // Logical shift right by one
  8739 instruct shrL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
  8740 %{
  8741   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
  8742   effect(KILL cr);
  8744   format %{ "shrq    $dst, $shift" %}
  8745   opcode(0xD1, 0x5); /* D1 /5 */
  8746   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8747   ins_pipe(ialu_mem_imm);
  8748 %}
  8750 // Logical Shift Right by 8-bit immediate
  8751 instruct shrL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
  8752 %{
  8753   match(Set dst (URShiftL dst shift));
  8754   effect(KILL cr);
  8756   format %{ "shrq    $dst, $shift" %}
  8757   opcode(0xC1, 0x5); /* C1 /5 ib */
  8758   ins_encode(reg_opc_imm_wide(dst, shift));
  8759   ins_pipe(ialu_reg);
  8760 %}
  8762 // Logical Shift Right by 8-bit immediate
  8763 instruct shrL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
  8764 %{
  8765   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
  8766   effect(KILL cr);
  8768   format %{ "shrq    $dst, $shift" %}
  8769   opcode(0xC1, 0x5); /* C1 /5 ib */
  8770   ins_encode(REX_mem_wide(dst), OpcP,
  8771              RM_opc_mem(secondary, dst), Con8or32(shift));
  8772   ins_pipe(ialu_mem_imm);
  8773 %}
  8775 // Logical Shift Right by variable
  8776 instruct shrL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
  8777 %{
  8778   match(Set dst (URShiftL dst shift));
  8779   effect(KILL cr);
  8781   format %{ "shrq    $dst, $shift" %}
  8782   opcode(0xD3, 0x5); /* D3 /5 */
  8783   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8784   ins_pipe(ialu_reg_reg);
  8785 %}
  8787 // Logical Shift Right by variable
  8788 instruct shrL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
  8789 %{
  8790   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
  8791   effect(KILL cr);
  8793   format %{ "shrq    $dst, $shift" %}
  8794   opcode(0xD3, 0x5); /* D3 /5 */
  8795   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
  8796   ins_pipe(ialu_mem_reg);
  8797 %}
  8799 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
  8800 // This idiom is used by the compiler for the i2b bytecode.
  8801 instruct i2b(rRegI dst, rRegI src, immI_24 twentyfour)
  8802 %{
  8803   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
  8805   format %{ "movsbl  $dst, $src\t# i2b" %}
  8806   opcode(0x0F, 0xBE);
  8807   ins_encode(REX_reg_breg(dst, src), OpcP, OpcS, reg_reg(dst, src));
  8808   ins_pipe(ialu_reg_reg);
  8809 %}
  8811 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
  8812 // This idiom is used by the compiler the i2s bytecode.
  8813 instruct i2s(rRegI dst, rRegI src, immI_16 sixteen)
  8814 %{
  8815   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
  8817   format %{ "movswl  $dst, $src\t# i2s" %}
  8818   opcode(0x0F, 0xBF);
  8819   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
  8820   ins_pipe(ialu_reg_reg);
  8821 %}
  8823 // ROL/ROR instructions
  8825 // ROL expand
  8826 instruct rolI_rReg_imm1(rRegI dst, rFlagsReg cr) %{
  8827   effect(KILL cr, USE_DEF dst);
  8829   format %{ "roll    $dst" %}
  8830   opcode(0xD1, 0x0); /* Opcode  D1 /0 */
  8831   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8832   ins_pipe(ialu_reg);
  8833 %}
  8835 instruct rolI_rReg_imm8(rRegI dst, immI8 shift, rFlagsReg cr) %{
  8836   effect(USE_DEF dst, USE shift, KILL cr);
  8838   format %{ "roll    $dst, $shift" %}
  8839   opcode(0xC1, 0x0); /* Opcode C1 /0 ib */
  8840   ins_encode( reg_opc_imm(dst, shift) );
  8841   ins_pipe(ialu_reg);
  8842 %}
  8844 instruct rolI_rReg_CL(no_rcx_RegI dst, rcx_RegI shift, rFlagsReg cr)
  8845 %{
  8846   effect(USE_DEF dst, USE shift, KILL cr);
  8848   format %{ "roll    $dst, $shift" %}
  8849   opcode(0xD3, 0x0); /* Opcode D3 /0 */
  8850   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8851   ins_pipe(ialu_reg_reg);
  8852 %}
  8853 // end of ROL expand
  8855 // Rotate Left by one
  8856 instruct rolI_rReg_i1(rRegI dst, immI1 lshift, immI_M1 rshift, rFlagsReg cr)
  8857 %{
  8858   match(Set dst (OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  8860   expand %{
  8861     rolI_rReg_imm1(dst, cr);
  8862   %}
  8863 %}
  8865 // Rotate Left by 8-bit immediate
  8866 instruct rolI_rReg_i8(rRegI dst, immI8 lshift, immI8 rshift, rFlagsReg cr)
  8867 %{
  8868   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  8869   match(Set dst (OrI (LShiftI dst lshift) (URShiftI dst rshift)));
  8871   expand %{
  8872     rolI_rReg_imm8(dst, lshift, cr);
  8873   %}
  8874 %}
  8876 // Rotate Left by variable
  8877 instruct rolI_rReg_Var_C0(no_rcx_RegI dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
  8878 %{
  8879   match(Set dst (OrI (LShiftI dst shift) (URShiftI dst (SubI zero shift))));
  8881   expand %{
  8882     rolI_rReg_CL(dst, shift, cr);
  8883   %}
  8884 %}
  8886 // Rotate Left by variable
  8887 instruct rolI_rReg_Var_C32(no_rcx_RegI dst, rcx_RegI shift, immI_32 c32, rFlagsReg cr)
  8888 %{
  8889   match(Set dst (OrI (LShiftI dst shift) (URShiftI dst (SubI c32 shift))));
  8891   expand %{
  8892     rolI_rReg_CL(dst, shift, cr);
  8893   %}
  8894 %}
  8896 // ROR expand
  8897 instruct rorI_rReg_imm1(rRegI dst, rFlagsReg cr)
  8898 %{
  8899   effect(USE_DEF dst, KILL cr);
  8901   format %{ "rorl    $dst" %}
  8902   opcode(0xD1, 0x1); /* D1 /1 */
  8903   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8904   ins_pipe(ialu_reg);
  8905 %}
  8907 instruct rorI_rReg_imm8(rRegI dst, immI8 shift, rFlagsReg cr)
  8908 %{
  8909   effect(USE_DEF dst, USE shift, KILL cr);
  8911   format %{ "rorl    $dst, $shift" %}
  8912   opcode(0xC1, 0x1); /* C1 /1 ib */
  8913   ins_encode(reg_opc_imm(dst, shift));
  8914   ins_pipe(ialu_reg);
  8915 %}
  8917 instruct rorI_rReg_CL(no_rcx_RegI dst, rcx_RegI shift, rFlagsReg cr)
  8918 %{
  8919   effect(USE_DEF dst, USE shift, KILL cr);
  8921   format %{ "rorl    $dst, $shift" %}
  8922   opcode(0xD3, 0x1); /* D3 /1 */
  8923   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
  8924   ins_pipe(ialu_reg_reg);
  8925 %}
  8926 // end of ROR expand
  8928 // Rotate Right by one
  8929 instruct rorI_rReg_i1(rRegI dst, immI1 rshift, immI_M1 lshift, rFlagsReg cr)
  8930 %{
  8931   match(Set dst (OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  8933   expand %{
  8934     rorI_rReg_imm1(dst, cr);
  8935   %}
  8936 %}
  8938 // Rotate Right by 8-bit immediate
  8939 instruct rorI_rReg_i8(rRegI dst, immI8 rshift, immI8 lshift, rFlagsReg cr)
  8940 %{
  8941   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
  8942   match(Set dst (OrI (URShiftI dst rshift) (LShiftI dst lshift)));
  8944   expand %{
  8945     rorI_rReg_imm8(dst, rshift, cr);
  8946   %}
  8947 %}
  8949 // Rotate Right by variable
  8950 instruct rorI_rReg_Var_C0(no_rcx_RegI dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
  8951 %{
  8952   match(Set dst (OrI (URShiftI dst shift) (LShiftI dst (SubI zero shift))));
  8954   expand %{
  8955     rorI_rReg_CL(dst, shift, cr);
  8956   %}
  8957 %}
  8959 // Rotate Right by variable
  8960 instruct rorI_rReg_Var_C32(no_rcx_RegI dst, rcx_RegI shift, immI_32 c32, rFlagsReg cr)
  8961 %{
  8962   match(Set dst (OrI (URShiftI dst shift) (LShiftI dst (SubI c32 shift))));
  8964   expand %{
  8965     rorI_rReg_CL(dst, shift, cr);
  8966   %}
  8967 %}
  8969 // for long rotate
  8970 // ROL expand
  8971 instruct rolL_rReg_imm1(rRegL dst, rFlagsReg cr) %{
  8972   effect(USE_DEF dst, KILL cr);
  8974   format %{ "rolq    $dst" %}
  8975   opcode(0xD1, 0x0); /* Opcode  D1 /0 */
  8976   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8977   ins_pipe(ialu_reg);
  8978 %}
  8980 instruct rolL_rReg_imm8(rRegL dst, immI8 shift, rFlagsReg cr) %{
  8981   effect(USE_DEF dst, USE shift, KILL cr);
  8983   format %{ "rolq    $dst, $shift" %}
  8984   opcode(0xC1, 0x0); /* Opcode C1 /0 ib */
  8985   ins_encode( reg_opc_imm_wide(dst, shift) );
  8986   ins_pipe(ialu_reg);
  8987 %}
  8989 instruct rolL_rReg_CL(no_rcx_RegL dst, rcx_RegI shift, rFlagsReg cr)
  8990 %{
  8991   effect(USE_DEF dst, USE shift, KILL cr);
  8993   format %{ "rolq    $dst, $shift" %}
  8994   opcode(0xD3, 0x0); /* Opcode D3 /0 */
  8995   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  8996   ins_pipe(ialu_reg_reg);
  8997 %}
  8998 // end of ROL expand
  9000 // Rotate Left by one
  9001 instruct rolL_rReg_i1(rRegL dst, immI1 lshift, immI_M1 rshift, rFlagsReg cr)
  9002 %{
  9003   match(Set dst (OrL (LShiftL dst lshift) (URShiftL dst rshift)));
  9005   expand %{
  9006     rolL_rReg_imm1(dst, cr);
  9007   %}
  9008 %}
  9010 // Rotate Left by 8-bit immediate
  9011 instruct rolL_rReg_i8(rRegL dst, immI8 lshift, immI8 rshift, rFlagsReg cr)
  9012 %{
  9013   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x3f));
  9014   match(Set dst (OrL (LShiftL dst lshift) (URShiftL dst rshift)));
  9016   expand %{
  9017     rolL_rReg_imm8(dst, lshift, cr);
  9018   %}
  9019 %}
  9021 // Rotate Left by variable
  9022 instruct rolL_rReg_Var_C0(no_rcx_RegL dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
  9023 %{
  9024   match(Set dst (OrL (LShiftL dst shift) (URShiftL dst (SubI zero shift))));
  9026   expand %{
  9027     rolL_rReg_CL(dst, shift, cr);
  9028   %}
  9029 %}
  9031 // Rotate Left by variable
  9032 instruct rolL_rReg_Var_C64(no_rcx_RegL dst, rcx_RegI shift, immI_64 c64, rFlagsReg cr)
  9033 %{
  9034   match(Set dst (OrL (LShiftL dst shift) (URShiftL dst (SubI c64 shift))));
  9036   expand %{
  9037     rolL_rReg_CL(dst, shift, cr);
  9038   %}
  9039 %}
  9041 // ROR expand
  9042 instruct rorL_rReg_imm1(rRegL dst, rFlagsReg cr)
  9043 %{
  9044   effect(USE_DEF dst, KILL cr);
  9046   format %{ "rorq    $dst" %}
  9047   opcode(0xD1, 0x1); /* D1 /1 */
  9048   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  9049   ins_pipe(ialu_reg);
  9050 %}
  9052 instruct rorL_rReg_imm8(rRegL dst, immI8 shift, rFlagsReg cr)
  9053 %{
  9054   effect(USE_DEF dst, USE shift, KILL cr);
  9056   format %{ "rorq    $dst, $shift" %}
  9057   opcode(0xC1, 0x1); /* C1 /1 ib */
  9058   ins_encode(reg_opc_imm_wide(dst, shift));
  9059   ins_pipe(ialu_reg);
  9060 %}
  9062 instruct rorL_rReg_CL(no_rcx_RegL dst, rcx_RegI shift, rFlagsReg cr)
  9063 %{
  9064   effect(USE_DEF dst, USE shift, KILL cr);
  9066   format %{ "rorq    $dst, $shift" %}
  9067   opcode(0xD3, 0x1); /* D3 /1 */
  9068   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
  9069   ins_pipe(ialu_reg_reg);
  9070 %}
  9071 // end of ROR expand
  9073 // Rotate Right by one
  9074 instruct rorL_rReg_i1(rRegL dst, immI1 rshift, immI_M1 lshift, rFlagsReg cr)
  9075 %{
  9076   match(Set dst (OrL (URShiftL dst rshift) (LShiftL dst lshift)));
  9078   expand %{
  9079     rorL_rReg_imm1(dst, cr);
  9080   %}
  9081 %}
  9083 // Rotate Right by 8-bit immediate
  9084 instruct rorL_rReg_i8(rRegL dst, immI8 rshift, immI8 lshift, rFlagsReg cr)
  9085 %{
  9086   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x3f));
  9087   match(Set dst (OrL (URShiftL dst rshift) (LShiftL dst lshift)));
  9089   expand %{
  9090     rorL_rReg_imm8(dst, rshift, cr);
  9091   %}
  9092 %}
  9094 // Rotate Right by variable
  9095 instruct rorL_rReg_Var_C0(no_rcx_RegL dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
  9096 %{
  9097   match(Set dst (OrL (URShiftL dst shift) (LShiftL dst (SubI zero shift))));
  9099   expand %{
  9100     rorL_rReg_CL(dst, shift, cr);
  9101   %}
  9102 %}
  9104 // Rotate Right by variable
  9105 instruct rorL_rReg_Var_C64(no_rcx_RegL dst, rcx_RegI shift, immI_64 c64, rFlagsReg cr)
  9106 %{
  9107   match(Set dst (OrL (URShiftL dst shift) (LShiftL dst (SubI c64 shift))));
  9109   expand %{
  9110     rorL_rReg_CL(dst, shift, cr);
  9111   %}
  9112 %}
  9114 // Logical Instructions
  9116 // Integer Logical Instructions
  9118 // And Instructions
  9119 // And Register with Register
  9120 instruct andI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  9121 %{
  9122   match(Set dst (AndI dst src));
  9123   effect(KILL cr);
  9125   format %{ "andl    $dst, $src\t# int" %}
  9126   opcode(0x23);
  9127   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
  9128   ins_pipe(ialu_reg_reg);
  9129 %}
  9131 // And Register with Immediate 255
  9132 instruct andI_rReg_imm255(rRegI dst, immI_255 src)
  9133 %{
  9134   match(Set dst (AndI dst src));
  9136   format %{ "movzbl  $dst, $dst\t# int & 0xFF" %}
  9137   opcode(0x0F, 0xB6);
  9138   ins_encode(REX_reg_breg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
  9139   ins_pipe(ialu_reg);
  9140 %}
  9142 // And Register with Immediate 255 and promote to long
  9143 instruct andI2L_rReg_imm255(rRegL dst, rRegI src, immI_255 mask)
  9144 %{
  9145   match(Set dst (ConvI2L (AndI src mask)));
  9147   format %{ "movzbl  $dst, $src\t# int & 0xFF -> long" %}
  9148   opcode(0x0F, 0xB6);
  9149   ins_encode(REX_reg_breg(dst, src), OpcP, OpcS, reg_reg(dst, src));
  9150   ins_pipe(ialu_reg);
  9151 %}
  9153 // And Register with Immediate 65535
  9154 instruct andI_rReg_imm65535(rRegI dst, immI_65535 src)
  9155 %{
  9156   match(Set dst (AndI dst src));
  9158   format %{ "movzwl  $dst, $dst\t# int & 0xFFFF" %}
  9159   opcode(0x0F, 0xB7);
  9160   ins_encode(REX_reg_reg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
  9161   ins_pipe(ialu_reg);
  9162 %}
  9164 // And Register with Immediate 65535 and promote to long
  9165 instruct andI2L_rReg_imm65535(rRegL dst, rRegI src, immI_65535 mask)
  9166 %{
  9167   match(Set dst (ConvI2L (AndI src mask)));
  9169   format %{ "movzwl  $dst, $src\t# int & 0xFFFF -> long" %}
  9170   opcode(0x0F, 0xB7);
  9171   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
  9172   ins_pipe(ialu_reg);
  9173 %}
  9175 // And Register with Immediate
  9176 instruct andI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
  9177 %{
  9178   match(Set dst (AndI dst src));
  9179   effect(KILL cr);
  9181   format %{ "andl    $dst, $src\t# int" %}
  9182   opcode(0x81, 0x04); /* Opcode 81 /4 */
  9183   ins_encode(OpcSErm(dst, src), Con8or32(src));
  9184   ins_pipe(ialu_reg);
  9185 %}
  9187 // And Register with Memory
  9188 instruct andI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
  9189 %{
  9190   match(Set dst (AndI dst (LoadI src)));
  9191   effect(KILL cr);
  9193   ins_cost(125);
  9194   format %{ "andl    $dst, $src\t# int" %}
  9195   opcode(0x23);
  9196   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  9197   ins_pipe(ialu_reg_mem);
  9198 %}
  9200 // And Memory with Register
  9201 instruct andI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
  9202 %{
  9203   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  9204   effect(KILL cr);
  9206   ins_cost(150);
  9207   format %{ "andl    $dst, $src\t# int" %}
  9208   opcode(0x21); /* Opcode 21 /r */
  9209   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  9210   ins_pipe(ialu_mem_reg);
  9211 %}
  9213 // And Memory with Immediate
  9214 instruct andI_mem_imm(memory dst, immI src, rFlagsReg cr)
  9215 %{
  9216   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
  9217   effect(KILL cr);
  9219   ins_cost(125);
  9220   format %{ "andl    $dst, $src\t# int" %}
  9221   opcode(0x81, 0x4); /* Opcode 81 /4 id */
  9222   ins_encode(REX_mem(dst), OpcSE(src),
  9223              RM_opc_mem(secondary, dst), Con8or32(src));
  9224   ins_pipe(ialu_mem_imm);
  9225 %}
  9227 // Or Instructions
  9228 // Or Register with Register
  9229 instruct orI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  9230 %{
  9231   match(Set dst (OrI dst src));
  9232   effect(KILL cr);
  9234   format %{ "orl     $dst, $src\t# int" %}
  9235   opcode(0x0B);
  9236   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
  9237   ins_pipe(ialu_reg_reg);
  9238 %}
  9240 // Or Register with Immediate
  9241 instruct orI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
  9242 %{
  9243   match(Set dst (OrI dst src));
  9244   effect(KILL cr);
  9246   format %{ "orl     $dst, $src\t# int" %}
  9247   opcode(0x81, 0x01); /* Opcode 81 /1 id */
  9248   ins_encode(OpcSErm(dst, src), Con8or32(src));
  9249   ins_pipe(ialu_reg);
  9250 %}
  9252 // Or Register with Memory
  9253 instruct orI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
  9254 %{
  9255   match(Set dst (OrI dst (LoadI src)));
  9256   effect(KILL cr);
  9258   ins_cost(125);
  9259   format %{ "orl     $dst, $src\t# int" %}
  9260   opcode(0x0B);
  9261   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  9262   ins_pipe(ialu_reg_mem);
  9263 %}
  9265 // Or Memory with Register
  9266 instruct orI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
  9267 %{
  9268   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  9269   effect(KILL cr);
  9271   ins_cost(150);
  9272   format %{ "orl     $dst, $src\t# int" %}
  9273   opcode(0x09); /* Opcode 09 /r */
  9274   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  9275   ins_pipe(ialu_mem_reg);
  9276 %}
  9278 // Or Memory with Immediate
  9279 instruct orI_mem_imm(memory dst, immI src, rFlagsReg cr)
  9280 %{
  9281   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
  9282   effect(KILL cr);
  9284   ins_cost(125);
  9285   format %{ "orl     $dst, $src\t# int" %}
  9286   opcode(0x81, 0x1); /* Opcode 81 /1 id */
  9287   ins_encode(REX_mem(dst), OpcSE(src),
  9288              RM_opc_mem(secondary, dst), Con8or32(src));
  9289   ins_pipe(ialu_mem_imm);
  9290 %}
  9292 // Xor Instructions
  9293 // Xor Register with Register
  9294 instruct xorI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
  9295 %{
  9296   match(Set dst (XorI dst src));
  9297   effect(KILL cr);
  9299   format %{ "xorl    $dst, $src\t# int" %}
  9300   opcode(0x33);
  9301   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
  9302   ins_pipe(ialu_reg_reg);
  9303 %}
  9305 // Xor Register with Immediate
  9306 instruct xorI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
  9307 %{
  9308   match(Set dst (XorI dst src));
  9309   effect(KILL cr);
  9311   format %{ "xorl    $dst, $src\t# int" %}
  9312   opcode(0x81, 0x06); /* Opcode 81 /6 id */
  9313   ins_encode(OpcSErm(dst, src), Con8or32(src));
  9314   ins_pipe(ialu_reg);
  9315 %}
  9317 // Xor Register with Memory
  9318 instruct xorI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
  9319 %{
  9320   match(Set dst (XorI dst (LoadI src)));
  9321   effect(KILL cr);
  9323   ins_cost(125);
  9324   format %{ "xorl    $dst, $src\t# int" %}
  9325   opcode(0x33);
  9326   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
  9327   ins_pipe(ialu_reg_mem);
  9328 %}
  9330 // Xor Memory with Register
  9331 instruct xorI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
  9332 %{
  9333   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  9334   effect(KILL cr);
  9336   ins_cost(150);
  9337   format %{ "xorl    $dst, $src\t# int" %}
  9338   opcode(0x31); /* Opcode 31 /r */
  9339   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
  9340   ins_pipe(ialu_mem_reg);
  9341 %}
  9343 // Xor Memory with Immediate
  9344 instruct xorI_mem_imm(memory dst, immI src, rFlagsReg cr)
  9345 %{
  9346   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
  9347   effect(KILL cr);
  9349   ins_cost(125);
  9350   format %{ "xorl    $dst, $src\t# int" %}
  9351   opcode(0x81, 0x6); /* Opcode 81 /6 id */
  9352   ins_encode(REX_mem(dst), OpcSE(src),
  9353              RM_opc_mem(secondary, dst), Con8or32(src));
  9354   ins_pipe(ialu_mem_imm);
  9355 %}
  9358 // Long Logical Instructions
  9360 // And Instructions
  9361 // And Register with Register
  9362 instruct andL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  9363 %{
  9364   match(Set dst (AndL dst src));
  9365   effect(KILL cr);
  9367   format %{ "andq    $dst, $src\t# long" %}
  9368   opcode(0x23);
  9369   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  9370   ins_pipe(ialu_reg_reg);
  9371 %}
  9373 // And Register with Immediate 255
  9374 instruct andL_rReg_imm255(rRegL dst, immL_255 src)
  9375 %{
  9376   match(Set dst (AndL dst src));
  9378   format %{ "movzbq  $dst, $src\t# long & 0xFF" %}
  9379   opcode(0x0F, 0xB6);
  9380   ins_encode(REX_reg_reg_wide(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
  9381   ins_pipe(ialu_reg);
  9382 %}
  9384 // And Register with Immediate 65535
  9385 instruct andL_rReg_imm65535(rRegI dst, immL_65535 src)
  9386 %{
  9387   match(Set dst (AndL dst src));
  9389   format %{ "movzwq  $dst, $dst\t# long & 0xFFFF" %}
  9390   opcode(0x0F, 0xB7);
  9391   ins_encode(REX_reg_reg_wide(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
  9392   ins_pipe(ialu_reg);
  9393 %}
  9395 // And Register with Immediate
  9396 instruct andL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
  9397 %{
  9398   match(Set dst (AndL dst src));
  9399   effect(KILL cr);
  9401   format %{ "andq    $dst, $src\t# long" %}
  9402   opcode(0x81, 0x04); /* Opcode 81 /4 */
  9403   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  9404   ins_pipe(ialu_reg);
  9405 %}
  9407 // And Register with Memory
  9408 instruct andL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
  9409 %{
  9410   match(Set dst (AndL dst (LoadL src)));
  9411   effect(KILL cr);
  9413   ins_cost(125);
  9414   format %{ "andq    $dst, $src\t# long" %}
  9415   opcode(0x23);
  9416   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  9417   ins_pipe(ialu_reg_mem);
  9418 %}
  9420 // And Memory with Register
  9421 instruct andL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
  9422 %{
  9423   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
  9424   effect(KILL cr);
  9426   ins_cost(150);
  9427   format %{ "andq    $dst, $src\t# long" %}
  9428   opcode(0x21); /* Opcode 21 /r */
  9429   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  9430   ins_pipe(ialu_mem_reg);
  9431 %}
  9433 // And Memory with Immediate
  9434 instruct andL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
  9435 %{
  9436   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
  9437   effect(KILL cr);
  9439   ins_cost(125);
  9440   format %{ "andq    $dst, $src\t# long" %}
  9441   opcode(0x81, 0x4); /* Opcode 81 /4 id */
  9442   ins_encode(REX_mem_wide(dst), OpcSE(src),
  9443              RM_opc_mem(secondary, dst), Con8or32(src));
  9444   ins_pipe(ialu_mem_imm);
  9445 %}
  9447 // Or Instructions
  9448 // Or Register with Register
  9449 instruct orL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  9450 %{
  9451   match(Set dst (OrL dst src));
  9452   effect(KILL cr);
  9454   format %{ "orq     $dst, $src\t# long" %}
  9455   opcode(0x0B);
  9456   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  9457   ins_pipe(ialu_reg_reg);
  9458 %}
  9460 // Or Register with Immediate
  9461 instruct orL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
  9462 %{
  9463   match(Set dst (OrL dst src));
  9464   effect(KILL cr);
  9466   format %{ "orq     $dst, $src\t# long" %}
  9467   opcode(0x81, 0x01); /* Opcode 81 /1 id */
  9468   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  9469   ins_pipe(ialu_reg);
  9470 %}
  9472 // Or Register with Memory
  9473 instruct orL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
  9474 %{
  9475   match(Set dst (OrL dst (LoadL src)));
  9476   effect(KILL cr);
  9478   ins_cost(125);
  9479   format %{ "orq     $dst, $src\t# long" %}
  9480   opcode(0x0B);
  9481   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  9482   ins_pipe(ialu_reg_mem);
  9483 %}
  9485 // Or Memory with Register
  9486 instruct orL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
  9487 %{
  9488   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
  9489   effect(KILL cr);
  9491   ins_cost(150);
  9492   format %{ "orq     $dst, $src\t# long" %}
  9493   opcode(0x09); /* Opcode 09 /r */
  9494   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  9495   ins_pipe(ialu_mem_reg);
  9496 %}
  9498 // Or Memory with Immediate
  9499 instruct orL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
  9500 %{
  9501   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
  9502   effect(KILL cr);
  9504   ins_cost(125);
  9505   format %{ "orq     $dst, $src\t# long" %}
  9506   opcode(0x81, 0x1); /* Opcode 81 /1 id */
  9507   ins_encode(REX_mem_wide(dst), OpcSE(src),
  9508              RM_opc_mem(secondary, dst), Con8or32(src));
  9509   ins_pipe(ialu_mem_imm);
  9510 %}
  9512 // Xor Instructions
  9513 // Xor Register with Register
  9514 instruct xorL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
  9515 %{
  9516   match(Set dst (XorL dst src));
  9517   effect(KILL cr);
  9519   format %{ "xorq    $dst, $src\t# long" %}
  9520   opcode(0x33);
  9521   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
  9522   ins_pipe(ialu_reg_reg);
  9523 %}
  9525 // Xor Register with Immediate
  9526 instruct xorL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
  9527 %{
  9528   match(Set dst (XorL dst src));
  9529   effect(KILL cr);
  9531   format %{ "xorq    $dst, $src\t# long" %}
  9532   opcode(0x81, 0x06); /* Opcode 81 /6 id */
  9533   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
  9534   ins_pipe(ialu_reg);
  9535 %}
  9537 // Xor Register with Memory
  9538 instruct xorL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
  9539 %{
  9540   match(Set dst (XorL dst (LoadL src)));
  9541   effect(KILL cr);
  9543   ins_cost(125);
  9544   format %{ "xorq    $dst, $src\t# long" %}
  9545   opcode(0x33);
  9546   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
  9547   ins_pipe(ialu_reg_mem);
  9548 %}
  9550 // Xor Memory with Register
  9551 instruct xorL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
  9552 %{
  9553   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
  9554   effect(KILL cr);
  9556   ins_cost(150);
  9557   format %{ "xorq    $dst, $src\t# long" %}
  9558   opcode(0x31); /* Opcode 31 /r */
  9559   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
  9560   ins_pipe(ialu_mem_reg);
  9561 %}
  9563 // Xor Memory with Immediate
  9564 instruct xorL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
  9565 %{
  9566   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
  9567   effect(KILL cr);
  9569   ins_cost(125);
  9570   format %{ "xorq    $dst, $src\t# long" %}
  9571   opcode(0x81, 0x6); /* Opcode 81 /6 id */
  9572   ins_encode(REX_mem_wide(dst), OpcSE(src),
  9573              RM_opc_mem(secondary, dst), Con8or32(src));
  9574   ins_pipe(ialu_mem_imm);
  9575 %}
  9577 // Convert Int to Boolean
  9578 instruct convI2B(rRegI dst, rRegI src, rFlagsReg cr)
  9579 %{
  9580   match(Set dst (Conv2B src));
  9581   effect(KILL cr);
  9583   format %{ "testl   $src, $src\t# ci2b\n\t"
  9584             "setnz   $dst\n\t"
  9585             "movzbl  $dst, $dst" %}
  9586   ins_encode(REX_reg_reg(src, src), opc_reg_reg(0x85, src, src), // testl
  9587              setNZ_reg(dst),
  9588              REX_reg_breg(dst, dst), // movzbl
  9589              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst));
  9590   ins_pipe(pipe_slow); // XXX
  9591 %}
  9593 // Convert Pointer to Boolean
  9594 instruct convP2B(rRegI dst, rRegP src, rFlagsReg cr)
  9595 %{
  9596   match(Set dst (Conv2B src));
  9597   effect(KILL cr);
  9599   format %{ "testq   $src, $src\t# cp2b\n\t"
  9600             "setnz   $dst\n\t"
  9601             "movzbl  $dst, $dst" %}
  9602   ins_encode(REX_reg_reg_wide(src, src), opc_reg_reg(0x85, src, src), // testq
  9603              setNZ_reg(dst),
  9604              REX_reg_breg(dst, dst), // movzbl
  9605              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst));
  9606   ins_pipe(pipe_slow); // XXX
  9607 %}
  9609 instruct cmpLTMask(rRegI dst, rRegI p, rRegI q, rFlagsReg cr)
  9610 %{
  9611   match(Set dst (CmpLTMask p q));
  9612   effect(KILL cr);
  9614   ins_cost(400); // XXX
  9615   format %{ "cmpl    $p, $q\t# cmpLTMask\n\t"
  9616             "setlt   $dst\n\t"
  9617             "movzbl  $dst, $dst\n\t"
  9618             "negl    $dst" %}
  9619   ins_encode(REX_reg_reg(p, q), opc_reg_reg(0x3B, p, q), // cmpl
  9620              setLT_reg(dst),
  9621              REX_reg_breg(dst, dst), // movzbl
  9622              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst),
  9623              neg_reg(dst));
  9624   ins_pipe(pipe_slow);
  9625 %}
  9627 instruct cmpLTMask0(rRegI dst, immI0 zero, rFlagsReg cr)
  9628 %{
  9629   match(Set dst (CmpLTMask dst zero));
  9630   effect(KILL cr);
  9632   ins_cost(100); // XXX
  9633   format %{ "sarl    $dst, #31\t# cmpLTMask0" %}
  9634   opcode(0xC1, 0x7);  /* C1 /7 ib */
  9635   ins_encode(reg_opc_imm(dst, 0x1F));
  9636   ins_pipe(ialu_reg);
  9637 %}
  9640 instruct cadd_cmpLTMask(rRegI p, rRegI q, rRegI y,
  9641                          rRegI tmp,
  9642                          rFlagsReg cr)
  9643 %{
  9644   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
  9645   effect(TEMP tmp, KILL cr);
  9647   ins_cost(400); // XXX
  9648   format %{ "subl    $p, $q\t# cadd_cmpLTMask1\n\t"
  9649             "sbbl    $tmp, $tmp\n\t"
  9650             "andl    $tmp, $y\n\t"
  9651             "addl    $p, $tmp" %}
  9652   ins_encode(enc_cmpLTP(p, q, y, tmp));
  9653   ins_pipe(pipe_cmplt);
  9654 %}
  9656 /* If I enable this, I encourage spilling in the inner loop of compress.
  9657 instruct cadd_cmpLTMask_mem( rRegI p, rRegI q, memory y, rRegI tmp, rFlagsReg cr )
  9658 %{
  9659   match(Set p (AddI (AndI (CmpLTMask p q) (LoadI y)) (SubI p q)));
  9660   effect( TEMP tmp, KILL cr );
  9661   ins_cost(400);
  9663   format %{ "SUB    $p,$q\n\t"
  9664             "SBB    RCX,RCX\n\t"
  9665             "AND    RCX,$y\n\t"
  9666             "ADD    $p,RCX" %}
  9667   ins_encode( enc_cmpLTP_mem(p,q,y,tmp) );
  9668 %}
  9669 */
  9671 //---------- FP Instructions------------------------------------------------
  9673 instruct cmpF_cc_reg(rFlagsRegU cr, regF src1, regF src2)
  9674 %{
  9675   match(Set cr (CmpF src1 src2));
  9677   ins_cost(145);
  9678   format %{ "ucomiss $src1, $src2\n\t"
  9679             "jnp,s   exit\n\t"
  9680             "pushfq\t# saw NaN, set CF\n\t"
  9681             "andq    [rsp], #0xffffff2b\n\t"
  9682             "popfq\n"
  9683     "exit:   nop\t# avoid branch to branch" %}
  9684   opcode(0x0F, 0x2E);
  9685   ins_encode(REX_reg_reg(src1, src2), OpcP, OpcS, reg_reg(src1, src2),
  9686              cmpfp_fixup);
  9687   ins_pipe(pipe_slow);
  9688 %}
  9690 instruct cmpF_cc_mem(rFlagsRegU cr, regF src1, memory src2)
  9691 %{
  9692   match(Set cr (CmpF src1 (LoadF src2)));
  9694   ins_cost(145);
  9695   format %{ "ucomiss $src1, $src2\n\t"
  9696             "jnp,s   exit\n\t"
  9697             "pushfq\t# saw NaN, set CF\n\t"
  9698             "andq    [rsp], #0xffffff2b\n\t"
  9699             "popfq\n"
  9700     "exit:   nop\t# avoid branch to branch" %}
  9701   opcode(0x0F, 0x2E);
  9702   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, reg_mem(src1, src2),
  9703              cmpfp_fixup);
  9704   ins_pipe(pipe_slow);
  9705 %}
  9707 instruct cmpF_cc_imm(rFlagsRegU cr, regF src1, immF src2)
  9708 %{
  9709   match(Set cr (CmpF src1 src2));
  9711   ins_cost(145);
  9712   format %{ "ucomiss $src1, $src2\n\t"
  9713             "jnp,s   exit\n\t"
  9714             "pushfq\t# saw NaN, set CF\n\t"
  9715             "andq    [rsp], #0xffffff2b\n\t"
  9716             "popfq\n"
  9717     "exit:   nop\t# avoid branch to branch" %}
  9718   opcode(0x0F, 0x2E);
  9719   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, load_immF(src1, src2),
  9720              cmpfp_fixup);
  9721   ins_pipe(pipe_slow);
  9722 %}
  9724 instruct cmpD_cc_reg(rFlagsRegU cr, regD src1, regD src2)
  9725 %{
  9726   match(Set cr (CmpD src1 src2));
  9728   ins_cost(145);
  9729   format %{ "ucomisd $src1, $src2\n\t"
  9730             "jnp,s   exit\n\t"
  9731             "pushfq\t# saw NaN, set CF\n\t"
  9732             "andq    [rsp], #0xffffff2b\n\t"
  9733             "popfq\n"
  9734     "exit:   nop\t# avoid branch to branch" %}
  9735   opcode(0x66, 0x0F, 0x2E);
  9736   ins_encode(OpcP, REX_reg_reg(src1, src2), OpcS, OpcT, reg_reg(src1, src2),
  9737              cmpfp_fixup);
  9738   ins_pipe(pipe_slow);
  9739 %}
  9741 instruct cmpD_cc_mem(rFlagsRegU cr, regD src1, memory src2)
  9742 %{
  9743   match(Set cr (CmpD src1 (LoadD src2)));
  9745   ins_cost(145);
  9746   format %{ "ucomisd $src1, $src2\n\t"
  9747             "jnp,s   exit\n\t"
  9748             "pushfq\t# saw NaN, set CF\n\t"
  9749             "andq    [rsp], #0xffffff2b\n\t"
  9750             "popfq\n"
  9751     "exit:   nop\t# avoid branch to branch" %}
  9752   opcode(0x66, 0x0F, 0x2E);
  9753   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, reg_mem(src1, src2),
  9754              cmpfp_fixup);
  9755   ins_pipe(pipe_slow);
  9756 %}
  9758 instruct cmpD_cc_imm(rFlagsRegU cr, regD src1, immD src2)
  9759 %{
  9760   match(Set cr (CmpD src1 src2));
  9762   ins_cost(145);
  9763   format %{ "ucomisd $src1, [$src2]\n\t"
  9764             "jnp,s   exit\n\t"
  9765             "pushfq\t# saw NaN, set CF\n\t"
  9766             "andq    [rsp], #0xffffff2b\n\t"
  9767             "popfq\n"
  9768     "exit:   nop\t# avoid branch to branch" %}
  9769   opcode(0x66, 0x0F, 0x2E);
  9770   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, load_immD(src1, src2),
  9771              cmpfp_fixup);
  9772   ins_pipe(pipe_slow);
  9773 %}
  9775 // Compare into -1,0,1
  9776 instruct cmpF_reg(rRegI dst, regF src1, regF src2, rFlagsReg cr)
  9777 %{
  9778   match(Set dst (CmpF3 src1 src2));
  9779   effect(KILL cr);
  9781   ins_cost(275);
  9782   format %{ "ucomiss $src1, $src2\n\t"
  9783             "movl    $dst, #-1\n\t"
  9784             "jp,s    done\n\t"
  9785             "jb,s    done\n\t"
  9786             "setne   $dst\n\t"
  9787             "movzbl  $dst, $dst\n"
  9788     "done:" %}
  9790   opcode(0x0F, 0x2E);
  9791   ins_encode(REX_reg_reg(src1, src2), OpcP, OpcS, reg_reg(src1, src2),
  9792              cmpfp3(dst));
  9793   ins_pipe(pipe_slow);
  9794 %}
  9796 // Compare into -1,0,1
  9797 instruct cmpF_mem(rRegI dst, regF src1, memory src2, rFlagsReg cr)
  9798 %{
  9799   match(Set dst (CmpF3 src1 (LoadF src2)));
  9800   effect(KILL cr);
  9802   ins_cost(275);
  9803   format %{ "ucomiss $src1, $src2\n\t"
  9804             "movl    $dst, #-1\n\t"
  9805             "jp,s    done\n\t"
  9806             "jb,s    done\n\t"
  9807             "setne   $dst\n\t"
  9808             "movzbl  $dst, $dst\n"
  9809     "done:" %}
  9811   opcode(0x0F, 0x2E);
  9812   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, reg_mem(src1, src2),
  9813              cmpfp3(dst));
  9814   ins_pipe(pipe_slow);
  9815 %}
  9817 // Compare into -1,0,1
  9818 instruct cmpF_imm(rRegI dst, regF src1, immF src2, rFlagsReg cr)
  9819 %{
  9820   match(Set dst (CmpF3 src1 src2));
  9821   effect(KILL cr);
  9823   ins_cost(275);
  9824   format %{ "ucomiss $src1, [$src2]\n\t"
  9825             "movl    $dst, #-1\n\t"
  9826             "jp,s    done\n\t"
  9827             "jb,s    done\n\t"
  9828             "setne   $dst\n\t"
  9829             "movzbl  $dst, $dst\n"
  9830     "done:" %}
  9832   opcode(0x0F, 0x2E);
  9833   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, load_immF(src1, src2),
  9834              cmpfp3(dst));
  9835   ins_pipe(pipe_slow);
  9836 %}
  9838 // Compare into -1,0,1
  9839 instruct cmpD_reg(rRegI dst, regD src1, regD src2, rFlagsReg cr)
  9840 %{
  9841   match(Set dst (CmpD3 src1 src2));
  9842   effect(KILL cr);
  9844   ins_cost(275);
  9845   format %{ "ucomisd $src1, $src2\n\t"
  9846             "movl    $dst, #-1\n\t"
  9847             "jp,s    done\n\t"
  9848             "jb,s    done\n\t"
  9849             "setne   $dst\n\t"
  9850             "movzbl  $dst, $dst\n"
  9851     "done:" %}
  9853   opcode(0x66, 0x0F, 0x2E);
  9854   ins_encode(OpcP, REX_reg_reg(src1, src2), OpcS, OpcT, reg_reg(src1, src2),
  9855              cmpfp3(dst));
  9856   ins_pipe(pipe_slow);
  9857 %}
  9859 // Compare into -1,0,1
  9860 instruct cmpD_mem(rRegI dst, regD src1, memory src2, rFlagsReg cr)
  9861 %{
  9862   match(Set dst (CmpD3 src1 (LoadD src2)));
  9863   effect(KILL cr);
  9865   ins_cost(275);
  9866   format %{ "ucomisd $src1, $src2\n\t"
  9867             "movl    $dst, #-1\n\t"
  9868             "jp,s    done\n\t"
  9869             "jb,s    done\n\t"
  9870             "setne   $dst\n\t"
  9871             "movzbl  $dst, $dst\n"
  9872     "done:" %}
  9874   opcode(0x66, 0x0F, 0x2E);
  9875   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, reg_mem(src1, src2),
  9876              cmpfp3(dst));
  9877   ins_pipe(pipe_slow);
  9878 %}
  9880 // Compare into -1,0,1
  9881 instruct cmpD_imm(rRegI dst, regD src1, immD src2, rFlagsReg cr)
  9882 %{
  9883   match(Set dst (CmpD3 src1 src2));
  9884   effect(KILL cr);
  9886   ins_cost(275);
  9887   format %{ "ucomisd $src1, [$src2]\n\t"
  9888             "movl    $dst, #-1\n\t"
  9889             "jp,s    done\n\t"
  9890             "jb,s    done\n\t"
  9891             "setne   $dst\n\t"
  9892             "movzbl  $dst, $dst\n"
  9893     "done:" %}
  9895   opcode(0x66, 0x0F, 0x2E);
  9896   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, load_immD(src1, src2),
  9897              cmpfp3(dst));
  9898   ins_pipe(pipe_slow);
  9899 %}
  9901 instruct addF_reg(regF dst, regF src)
  9902 %{
  9903   match(Set dst (AddF dst src));
  9905   format %{ "addss   $dst, $src" %}
  9906   ins_cost(150); // XXX
  9907   opcode(0xF3, 0x0F, 0x58);
  9908   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
  9909   ins_pipe(pipe_slow);
  9910 %}
  9912 instruct addF_mem(regF dst, memory src)
  9913 %{
  9914   match(Set dst (AddF dst (LoadF src)));
  9916   format %{ "addss   $dst, $src" %}
  9917   ins_cost(150); // XXX
  9918   opcode(0xF3, 0x0F, 0x58);
  9919   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
  9920   ins_pipe(pipe_slow);
  9921 %}
  9923 instruct addF_imm(regF dst, immF src)
  9924 %{
  9925   match(Set dst (AddF dst src));
  9927   format %{ "addss   $dst, [$src]" %}
  9928   ins_cost(150); // XXX
  9929   opcode(0xF3, 0x0F, 0x58);
  9930   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immF(dst, src));
  9931   ins_pipe(pipe_slow);
  9932 %}
  9934 instruct addD_reg(regD dst, regD src)
  9935 %{
  9936   match(Set dst (AddD dst src));
  9938   format %{ "addsd   $dst, $src" %}
  9939   ins_cost(150); // XXX
  9940   opcode(0xF2, 0x0F, 0x58);
  9941   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
  9942   ins_pipe(pipe_slow);
  9943 %}
  9945 instruct addD_mem(regD dst, memory src)
  9946 %{
  9947   match(Set dst (AddD dst (LoadD src)));
  9949   format %{ "addsd   $dst, $src" %}
  9950   ins_cost(150); // XXX
  9951   opcode(0xF2, 0x0F, 0x58);
  9952   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
  9953   ins_pipe(pipe_slow);
  9954 %}
  9956 instruct addD_imm(regD dst, immD src)
  9957 %{
  9958   match(Set dst (AddD dst src));
  9960   format %{ "addsd   $dst, [$src]" %}
  9961   ins_cost(150); // XXX
  9962   opcode(0xF2, 0x0F, 0x58);
  9963   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immD(dst, src));
  9964   ins_pipe(pipe_slow);
  9965 %}
  9967 instruct subF_reg(regF dst, regF src)
  9968 %{
  9969   match(Set dst (SubF dst src));
  9971   format %{ "subss   $dst, $src" %}
  9972   ins_cost(150); // XXX
  9973   opcode(0xF3, 0x0F, 0x5C);
  9974   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
  9975   ins_pipe(pipe_slow);
  9976 %}
  9978 instruct subF_mem(regF dst, memory src)
  9979 %{
  9980   match(Set dst (SubF dst (LoadF src)));
  9982   format %{ "subss   $dst, $src" %}
  9983   ins_cost(150); // XXX
  9984   opcode(0xF3, 0x0F, 0x5C);
  9985   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
  9986   ins_pipe(pipe_slow);
  9987 %}
  9989 instruct subF_imm(regF dst, immF src)
  9990 %{
  9991   match(Set dst (SubF dst src));
  9993   format %{ "subss   $dst, [$src]" %}
  9994   ins_cost(150); // XXX
  9995   opcode(0xF3, 0x0F, 0x5C);
  9996   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immF(dst, src));
  9997   ins_pipe(pipe_slow);
  9998 %}
 10000 instruct subD_reg(regD dst, regD src)
 10001 %{
 10002   match(Set dst (SubD dst src));
 10004   format %{ "subsd   $dst, $src" %}
 10005   ins_cost(150); // XXX
 10006   opcode(0xF2, 0x0F, 0x5C);
 10007   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10008   ins_pipe(pipe_slow);
 10009 %}
 10011 instruct subD_mem(regD dst, memory src)
 10012 %{
 10013   match(Set dst (SubD dst (LoadD src)));
 10015   format %{ "subsd   $dst, $src" %}
 10016   ins_cost(150); // XXX
 10017   opcode(0xF2, 0x0F, 0x5C);
 10018   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10019   ins_pipe(pipe_slow);
 10020 %}
 10022 instruct subD_imm(regD dst, immD src)
 10023 %{
 10024   match(Set dst (SubD dst src));
 10026   format %{ "subsd   $dst, [$src]" %}
 10027   ins_cost(150); // XXX
 10028   opcode(0xF2, 0x0F, 0x5C);
 10029   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immD(dst, src));
 10030   ins_pipe(pipe_slow);
 10031 %}
 10033 instruct mulF_reg(regF dst, regF src)
 10034 %{
 10035   match(Set dst (MulF dst src));
 10037   format %{ "mulss   $dst, $src" %}
 10038   ins_cost(150); // XXX
 10039   opcode(0xF3, 0x0F, 0x59);
 10040   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10041   ins_pipe(pipe_slow);
 10042 %}
 10044 instruct mulF_mem(regF dst, memory src)
 10045 %{
 10046   match(Set dst (MulF dst (LoadF src)));
 10048   format %{ "mulss   $dst, $src" %}
 10049   ins_cost(150); // XXX
 10050   opcode(0xF3, 0x0F, 0x59);
 10051   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10052   ins_pipe(pipe_slow);
 10053 %}
 10055 instruct mulF_imm(regF dst, immF src)
 10056 %{
 10057   match(Set dst (MulF dst src));
 10059   format %{ "mulss   $dst, [$src]" %}
 10060   ins_cost(150); // XXX
 10061   opcode(0xF3, 0x0F, 0x59);
 10062   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immF(dst, src));
 10063   ins_pipe(pipe_slow);
 10064 %}
 10066 instruct mulD_reg(regD dst, regD src)
 10067 %{
 10068   match(Set dst (MulD dst src));
 10070   format %{ "mulsd   $dst, $src" %}
 10071   ins_cost(150); // XXX
 10072   opcode(0xF2, 0x0F, 0x59);
 10073   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10074   ins_pipe(pipe_slow);
 10075 %}
 10077 instruct mulD_mem(regD dst, memory src)
 10078 %{
 10079   match(Set dst (MulD dst (LoadD src)));
 10081   format %{ "mulsd   $dst, $src" %}
 10082   ins_cost(150); // XXX
 10083   opcode(0xF2, 0x0F, 0x59);
 10084   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10085   ins_pipe(pipe_slow);
 10086 %}
 10088 instruct mulD_imm(regD dst, immD src)
 10089 %{
 10090   match(Set dst (MulD dst src));
 10092   format %{ "mulsd   $dst, [$src]" %}
 10093   ins_cost(150); // XXX
 10094   opcode(0xF2, 0x0F, 0x59);
 10095   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immD(dst, src));
 10096   ins_pipe(pipe_slow);
 10097 %}
 10099 instruct divF_reg(regF dst, regF src)
 10100 %{
 10101   match(Set dst (DivF dst src));
 10103   format %{ "divss   $dst, $src" %}
 10104   ins_cost(150); // XXX
 10105   opcode(0xF3, 0x0F, 0x5E);
 10106   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10107   ins_pipe(pipe_slow);
 10108 %}
 10110 instruct divF_mem(regF dst, memory src)
 10111 %{
 10112   match(Set dst (DivF dst (LoadF src)));
 10114   format %{ "divss   $dst, $src" %}
 10115   ins_cost(150); // XXX
 10116   opcode(0xF3, 0x0F, 0x5E);
 10117   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10118   ins_pipe(pipe_slow);
 10119 %}
 10121 instruct divF_imm(regF dst, immF src)
 10122 %{
 10123   match(Set dst (DivF dst src));
 10125   format %{ "divss   $dst, [$src]" %}
 10126   ins_cost(150); // XXX
 10127   opcode(0xF3, 0x0F, 0x5E);
 10128   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immF(dst, src));
 10129   ins_pipe(pipe_slow);
 10130 %}
 10132 instruct divD_reg(regD dst, regD src)
 10133 %{
 10134   match(Set dst (DivD dst src));
 10136   format %{ "divsd   $dst, $src" %}
 10137   ins_cost(150); // XXX
 10138   opcode(0xF2, 0x0F, 0x5E);
 10139   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10140   ins_pipe(pipe_slow);
 10141 %}
 10143 instruct divD_mem(regD dst, memory src)
 10144 %{
 10145   match(Set dst (DivD dst (LoadD src)));
 10147   format %{ "divsd   $dst, $src" %}
 10148   ins_cost(150); // XXX
 10149   opcode(0xF2, 0x0F, 0x5E);
 10150   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10151   ins_pipe(pipe_slow);
 10152 %}
 10154 instruct divD_imm(regD dst, immD src)
 10155 %{
 10156   match(Set dst (DivD dst src));
 10158   format %{ "divsd   $dst, [$src]" %}
 10159   ins_cost(150); // XXX
 10160   opcode(0xF2, 0x0F, 0x5E);
 10161   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immD(dst, src));
 10162   ins_pipe(pipe_slow);
 10163 %}
 10165 instruct sqrtF_reg(regF dst, regF src)
 10166 %{
 10167   match(Set dst (ConvD2F (SqrtD (ConvF2D src))));
 10169   format %{ "sqrtss  $dst, $src" %}
 10170   ins_cost(150); // XXX
 10171   opcode(0xF3, 0x0F, 0x51);
 10172   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10173   ins_pipe(pipe_slow);
 10174 %}
 10176 instruct sqrtF_mem(regF dst, memory src)
 10177 %{
 10178   match(Set dst (ConvD2F (SqrtD (ConvF2D (LoadF src)))));
 10180   format %{ "sqrtss  $dst, $src" %}
 10181   ins_cost(150); // XXX
 10182   opcode(0xF3, 0x0F, 0x51);
 10183   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10184   ins_pipe(pipe_slow);
 10185 %}
 10187 instruct sqrtF_imm(regF dst, immF src)
 10188 %{
 10189   match(Set dst (ConvD2F (SqrtD (ConvF2D src))));
 10191   format %{ "sqrtss  $dst, [$src]" %}
 10192   ins_cost(150); // XXX
 10193   opcode(0xF3, 0x0F, 0x51);
 10194   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immF(dst, src));
 10195   ins_pipe(pipe_slow);
 10196 %}
 10198 instruct sqrtD_reg(regD dst, regD src)
 10199 %{
 10200   match(Set dst (SqrtD src));
 10202   format %{ "sqrtsd  $dst, $src" %}
 10203   ins_cost(150); // XXX
 10204   opcode(0xF2, 0x0F, 0x51);
 10205   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10206   ins_pipe(pipe_slow);
 10207 %}
 10209 instruct sqrtD_mem(regD dst, memory src)
 10210 %{
 10211   match(Set dst (SqrtD (LoadD src)));
 10213   format %{ "sqrtsd  $dst, $src" %}
 10214   ins_cost(150); // XXX
 10215   opcode(0xF2, 0x0F, 0x51);
 10216   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10217   ins_pipe(pipe_slow);
 10218 %}
 10220 instruct sqrtD_imm(regD dst, immD src)
 10221 %{
 10222   match(Set dst (SqrtD src));
 10224   format %{ "sqrtsd  $dst, [$src]" %}
 10225   ins_cost(150); // XXX
 10226   opcode(0xF2, 0x0F, 0x51);
 10227   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, load_immD(dst, src));
 10228   ins_pipe(pipe_slow);
 10229 %}
 10231 instruct absF_reg(regF dst)
 10232 %{
 10233   match(Set dst (AbsF dst));
 10235   format %{ "andps   $dst, [0x7fffffff]\t# abs float by sign masking" %}
 10236   ins_encode(absF_encoding(dst));
 10237   ins_pipe(pipe_slow);
 10238 %}
 10240 instruct absD_reg(regD dst)
 10241 %{
 10242   match(Set dst (AbsD dst));
 10244   format %{ "andpd   $dst, [0x7fffffffffffffff]\t"
 10245             "# abs double by sign masking" %}
 10246   ins_encode(absD_encoding(dst));
 10247   ins_pipe(pipe_slow);
 10248 %}
 10250 instruct negF_reg(regF dst)
 10251 %{
 10252   match(Set dst (NegF dst));
 10254   format %{ "xorps   $dst, [0x80000000]\t# neg float by sign flipping" %}
 10255   ins_encode(negF_encoding(dst));
 10256   ins_pipe(pipe_slow);
 10257 %}
 10259 instruct negD_reg(regD dst)
 10260 %{
 10261   match(Set dst (NegD dst));
 10263   format %{ "xorpd   $dst, [0x8000000000000000]\t"
 10264             "# neg double by sign flipping" %}
 10265   ins_encode(negD_encoding(dst));
 10266   ins_pipe(pipe_slow);
 10267 %}
 10269 // -----------Trig and Trancendental Instructions------------------------------
 10270 instruct cosD_reg(regD dst) %{
 10271   match(Set dst (CosD dst));
 10273   format %{ "dcos   $dst\n\t" %}
 10274   opcode(0xD9, 0xFF);
 10275   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
 10276   ins_pipe( pipe_slow );
 10277 %}
 10279 instruct sinD_reg(regD dst) %{
 10280   match(Set dst (SinD dst));
 10282   format %{ "dsin   $dst\n\t" %}
 10283   opcode(0xD9, 0xFE);
 10284   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
 10285   ins_pipe( pipe_slow );
 10286 %}
 10288 instruct tanD_reg(regD dst) %{
 10289   match(Set dst (TanD dst));
 10291   format %{ "dtan   $dst\n\t" %}
 10292   ins_encode( Push_SrcXD(dst),
 10293               Opcode(0xD9), Opcode(0xF2),   //fptan
 10294               Opcode(0xDD), Opcode(0xD8),   //fstp st
 10295               Push_ResultXD(dst) );
 10296   ins_pipe( pipe_slow );
 10297 %}
 10299 instruct log10D_reg(regD dst) %{
 10300   // The source and result Double operands in XMM registers
 10301   match(Set dst (Log10D dst));
 10302   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
 10303   // fyl2x        ; compute log_10(2) * log_2(x)
 10304   format %{ "fldlg2\t\t\t#Log10\n\t"
 10305             "fyl2x\t\t\t# Q=Log10*Log_2(x)\n\t"
 10306          %}
 10307    ins_encode(Opcode(0xD9), Opcode(0xEC),   // fldlg2
 10308               Push_SrcXD(dst),
 10309               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10310               Push_ResultXD(dst));
 10312   ins_pipe( pipe_slow );
 10313 %}
 10315 instruct logD_reg(regD dst) %{
 10316   // The source and result Double operands in XMM registers
 10317   match(Set dst (LogD dst));
 10318   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
 10319   // fyl2x        ; compute log_e(2) * log_2(x)
 10320   format %{ "fldln2\t\t\t#Log_e\n\t"
 10321             "fyl2x\t\t\t# Q=Log_e*Log_2(x)\n\t"
 10322          %}
 10323   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
 10324               Push_SrcXD(dst),
 10325               Opcode(0xD9), Opcode(0xF1),   // fyl2x
 10326               Push_ResultXD(dst));
 10327   ins_pipe( pipe_slow );
 10328 %}
 10332 //----------Arithmetic Conversion Instructions---------------------------------
 10334 instruct roundFloat_nop(regF dst)
 10335 %{
 10336   match(Set dst (RoundFloat dst));
 10338   ins_cost(0);
 10339   ins_encode();
 10340   ins_pipe(empty);
 10341 %}
 10343 instruct roundDouble_nop(regD dst)
 10344 %{
 10345   match(Set dst (RoundDouble dst));
 10347   ins_cost(0);
 10348   ins_encode();
 10349   ins_pipe(empty);
 10350 %}
 10352 instruct convF2D_reg_reg(regD dst, regF src)
 10353 %{
 10354   match(Set dst (ConvF2D src));
 10356   format %{ "cvtss2sd $dst, $src" %}
 10357   opcode(0xF3, 0x0F, 0x5A);
 10358   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10359   ins_pipe(pipe_slow); // XXX
 10360 %}
 10362 instruct convF2D_reg_mem(regD dst, memory src)
 10363 %{
 10364   match(Set dst (ConvF2D (LoadF src)));
 10366   format %{ "cvtss2sd $dst, $src" %}
 10367   opcode(0xF3, 0x0F, 0x5A);
 10368   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10369   ins_pipe(pipe_slow); // XXX
 10370 %}
 10372 instruct convD2F_reg_reg(regF dst, regD src)
 10373 %{
 10374   match(Set dst (ConvD2F src));
 10376   format %{ "cvtsd2ss $dst, $src" %}
 10377   opcode(0xF2, 0x0F, 0x5A);
 10378   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10379   ins_pipe(pipe_slow); // XXX
 10380 %}
 10382 instruct convD2F_reg_mem(regF dst, memory src)
 10383 %{
 10384   match(Set dst (ConvD2F (LoadD src)));
 10386   format %{ "cvtsd2ss $dst, $src" %}
 10387   opcode(0xF2, 0x0F, 0x5A);
 10388   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10389   ins_pipe(pipe_slow); // XXX
 10390 %}
 10392 // XXX do mem variants
 10393 instruct convF2I_reg_reg(rRegI dst, regF src, rFlagsReg cr)
 10394 %{
 10395   match(Set dst (ConvF2I src));
 10396   effect(KILL cr);
 10398   format %{ "cvttss2sil $dst, $src\t# f2i\n\t"
 10399             "cmpl    $dst, #0x80000000\n\t"
 10400             "jne,s   done\n\t"
 10401             "subq    rsp, #8\n\t"
 10402             "movss   [rsp], $src\n\t"
 10403             "call    f2i_fixup\n\t"
 10404             "popq    $dst\n"
 10405     "done:   "%}
 10406   opcode(0xF3, 0x0F, 0x2C);
 10407   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src),
 10408              f2i_fixup(dst, src));
 10409   ins_pipe(pipe_slow);
 10410 %}
 10412 instruct convF2L_reg_reg(rRegL dst, regF src, rFlagsReg cr)
 10413 %{
 10414   match(Set dst (ConvF2L src));
 10415   effect(KILL cr);
 10417   format %{ "cvttss2siq $dst, $src\t# f2l\n\t"
 10418             "cmpq    $dst, [0x8000000000000000]\n\t"
 10419             "jne,s   done\n\t"
 10420             "subq    rsp, #8\n\t"
 10421             "movss   [rsp], $src\n\t"
 10422             "call    f2l_fixup\n\t"
 10423             "popq    $dst\n"
 10424     "done:   "%}
 10425   opcode(0xF3, 0x0F, 0x2C);
 10426   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src),
 10427              f2l_fixup(dst, src));
 10428   ins_pipe(pipe_slow);
 10429 %}
 10431 instruct convD2I_reg_reg(rRegI dst, regD src, rFlagsReg cr)
 10432 %{
 10433   match(Set dst (ConvD2I src));
 10434   effect(KILL cr);
 10436   format %{ "cvttsd2sil $dst, $src\t# d2i\n\t"
 10437             "cmpl    $dst, #0x80000000\n\t"
 10438             "jne,s   done\n\t"
 10439             "subq    rsp, #8\n\t"
 10440             "movsd   [rsp], $src\n\t"
 10441             "call    d2i_fixup\n\t"
 10442             "popq    $dst\n"
 10443     "done:   "%}
 10444   opcode(0xF2, 0x0F, 0x2C);
 10445   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src),
 10446              d2i_fixup(dst, src));
 10447   ins_pipe(pipe_slow);
 10448 %}
 10450 instruct convD2L_reg_reg(rRegL dst, regD src, rFlagsReg cr)
 10451 %{
 10452   match(Set dst (ConvD2L src));
 10453   effect(KILL cr);
 10455   format %{ "cvttsd2siq $dst, $src\t# d2l\n\t"
 10456             "cmpq    $dst, [0x8000000000000000]\n\t"
 10457             "jne,s   done\n\t"
 10458             "subq    rsp, #8\n\t"
 10459             "movsd   [rsp], $src\n\t"
 10460             "call    d2l_fixup\n\t"
 10461             "popq    $dst\n"
 10462     "done:   "%}
 10463   opcode(0xF2, 0x0F, 0x2C);
 10464   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src),
 10465              d2l_fixup(dst, src));
 10466   ins_pipe(pipe_slow);
 10467 %}
 10469 instruct convI2F_reg_reg(regF dst, rRegI src)
 10470 %{
 10471   predicate(!UseXmmI2F);
 10472   match(Set dst (ConvI2F src));
 10474   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
 10475   opcode(0xF3, 0x0F, 0x2A);
 10476   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10477   ins_pipe(pipe_slow); // XXX
 10478 %}
 10480 instruct convI2F_reg_mem(regF dst, memory src)
 10481 %{
 10482   match(Set dst (ConvI2F (LoadI src)));
 10484   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
 10485   opcode(0xF3, 0x0F, 0x2A);
 10486   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10487   ins_pipe(pipe_slow); // XXX
 10488 %}
 10490 instruct convI2D_reg_reg(regD dst, rRegI src)
 10491 %{
 10492   predicate(!UseXmmI2D);
 10493   match(Set dst (ConvI2D src));
 10495   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
 10496   opcode(0xF2, 0x0F, 0x2A);
 10497   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10498   ins_pipe(pipe_slow); // XXX
 10499 %}
 10501 instruct convI2D_reg_mem(regD dst, memory src)
 10502 %{
 10503   match(Set dst (ConvI2D (LoadI src)));
 10505   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
 10506   opcode(0xF2, 0x0F, 0x2A);
 10507   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10508   ins_pipe(pipe_slow); // XXX
 10509 %}
 10511 instruct convXI2F_reg(regF dst, rRegI src)
 10512 %{
 10513   predicate(UseXmmI2F);
 10514   match(Set dst (ConvI2F src));
 10516   format %{ "movdl $dst, $src\n\t"
 10517             "cvtdq2psl $dst, $dst\t# i2f" %}
 10518   ins_encode %{
 10519     __ movdl($dst$$XMMRegister, $src$$Register);
 10520     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
 10521   %}
 10522   ins_pipe(pipe_slow); // XXX
 10523 %}
 10525 instruct convXI2D_reg(regD dst, rRegI src)
 10526 %{
 10527   predicate(UseXmmI2D);
 10528   match(Set dst (ConvI2D src));
 10530   format %{ "movdl $dst, $src\n\t"
 10531             "cvtdq2pdl $dst, $dst\t# i2d" %}
 10532   ins_encode %{
 10533     __ movdl($dst$$XMMRegister, $src$$Register);
 10534     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
 10535   %}
 10536   ins_pipe(pipe_slow); // XXX
 10537 %}
 10539 instruct convL2F_reg_reg(regF dst, rRegL src)
 10540 %{
 10541   match(Set dst (ConvL2F src));
 10543   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
 10544   opcode(0xF3, 0x0F, 0x2A);
 10545   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10546   ins_pipe(pipe_slow); // XXX
 10547 %}
 10549 instruct convL2F_reg_mem(regF dst, memory src)
 10550 %{
 10551   match(Set dst (ConvL2F (LoadL src)));
 10553   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
 10554   opcode(0xF3, 0x0F, 0x2A);
 10555   ins_encode(OpcP, REX_reg_mem_wide(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10556   ins_pipe(pipe_slow); // XXX
 10557 %}
 10559 instruct convL2D_reg_reg(regD dst, rRegL src)
 10560 %{
 10561   match(Set dst (ConvL2D src));
 10563   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
 10564   opcode(0xF2, 0x0F, 0x2A);
 10565   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src));
 10566   ins_pipe(pipe_slow); // XXX
 10567 %}
 10569 instruct convL2D_reg_mem(regD dst, memory src)
 10570 %{
 10571   match(Set dst (ConvL2D (LoadL src)));
 10573   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
 10574   opcode(0xF2, 0x0F, 0x2A);
 10575   ins_encode(OpcP, REX_reg_mem_wide(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10576   ins_pipe(pipe_slow); // XXX
 10577 %}
 10579 instruct convI2L_reg_reg(rRegL dst, rRegI src)
 10580 %{
 10581   match(Set dst (ConvI2L src));
 10583   ins_cost(125);
 10584   format %{ "movslq  $dst, $src\t# i2l" %}
 10585   opcode(0x63); // needs REX.W
 10586   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst,src));
 10587   ins_pipe(ialu_reg_reg);
 10588 %}
 10590 // instruct convI2L_reg_reg_foo(rRegL dst, rRegI src)
 10591 // %{
 10592 //   match(Set dst (ConvI2L src));
 10593 // //   predicate(_kids[0]->_leaf->as_Type()->type()->is_int()->_lo >= 0 &&
 10594 // //             _kids[0]->_leaf->as_Type()->type()->is_int()->_hi >= 0);
 10595 //   predicate(((const TypeNode*) n)->type()->is_long()->_hi ==
 10596 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_hi &&
 10597 //             ((const TypeNode*) n)->type()->is_long()->_lo ==
 10598 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_lo);
 10600 //   format %{ "movl    $dst, $src\t# unsigned i2l" %}
 10601 //   ins_encode(enc_copy(dst, src));
 10602 // //   opcode(0x63); // needs REX.W
 10603 // //   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst,src));
 10604 //   ins_pipe(ialu_reg_reg);
 10605 // %}
 10607 instruct convI2L_reg_mem(rRegL dst, memory src)
 10608 %{
 10609   match(Set dst (ConvI2L (LoadI src)));
 10611   format %{ "movslq  $dst, $src\t# i2l" %}
 10612   opcode(0x63); // needs REX.W
 10613   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst,src));
 10614   ins_pipe(ialu_reg_mem);
 10615 %}
 10617 // Zero-extend convert int to long
 10618 instruct convI2L_reg_reg_zex(rRegL dst, rRegI src, immL_32bits mask)
 10619 %{
 10620   match(Set dst (AndL (ConvI2L src) mask));
 10622   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
 10623   ins_encode(enc_copy(dst, src));
 10624   ins_pipe(ialu_reg_reg);
 10625 %}
 10627 // Zero-extend convert int to long
 10628 instruct convI2L_reg_mem_zex(rRegL dst, memory src, immL_32bits mask)
 10629 %{
 10630   match(Set dst (AndL (ConvI2L (LoadI src)) mask));
 10632   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
 10633   opcode(0x8B);
 10634   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
 10635   ins_pipe(ialu_reg_mem);
 10636 %}
 10638 instruct zerox_long_reg_reg(rRegL dst, rRegL src, immL_32bits mask)
 10639 %{
 10640   match(Set dst (AndL src mask));
 10642   format %{ "movl    $dst, $src\t# zero-extend long" %}
 10643   ins_encode(enc_copy_always(dst, src));
 10644   ins_pipe(ialu_reg_reg);
 10645 %}
 10647 instruct convL2I_reg_reg(rRegI dst, rRegL src)
 10648 %{
 10649   match(Set dst (ConvL2I src));
 10651   format %{ "movl    $dst, $src\t# l2i" %}
 10652   ins_encode(enc_copy_always(dst, src));
 10653   ins_pipe(ialu_reg_reg);
 10654 %}
 10657 instruct MoveF2I_stack_reg(rRegI dst, stackSlotF src) %{
 10658   match(Set dst (MoveF2I src));
 10659   effect(DEF dst, USE src);
 10661   ins_cost(125);
 10662   format %{ "movl    $dst, $src\t# MoveF2I_stack_reg" %}
 10663   opcode(0x8B);
 10664   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
 10665   ins_pipe(ialu_reg_mem);
 10666 %}
 10668 instruct MoveI2F_stack_reg(regF dst, stackSlotI src) %{
 10669   match(Set dst (MoveI2F src));
 10670   effect(DEF dst, USE src);
 10672   ins_cost(125);
 10673   format %{ "movss   $dst, $src\t# MoveI2F_stack_reg" %}
 10674   opcode(0xF3, 0x0F, 0x10);
 10675   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10676   ins_pipe(pipe_slow);
 10677 %}
 10679 instruct MoveD2L_stack_reg(rRegL dst, stackSlotD src) %{
 10680   match(Set dst (MoveD2L src));
 10681   effect(DEF dst, USE src);
 10683   ins_cost(125);
 10684   format %{ "movq    $dst, $src\t# MoveD2L_stack_reg" %}
 10685   opcode(0x8B);
 10686   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
 10687   ins_pipe(ialu_reg_mem);
 10688 %}
 10690 instruct MoveL2D_stack_reg_partial(regD dst, stackSlotL src) %{
 10691   predicate(!UseXmmLoadAndClearUpper);
 10692   match(Set dst (MoveL2D src));
 10693   effect(DEF dst, USE src);
 10695   ins_cost(125);
 10696   format %{ "movlpd  $dst, $src\t# MoveL2D_stack_reg" %}
 10697   opcode(0x66, 0x0F, 0x12);
 10698   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10699   ins_pipe(pipe_slow);
 10700 %}
 10702 instruct MoveL2D_stack_reg(regD dst, stackSlotL src) %{
 10703   predicate(UseXmmLoadAndClearUpper);
 10704   match(Set dst (MoveL2D src));
 10705   effect(DEF dst, USE src);
 10707   ins_cost(125);
 10708   format %{ "movsd   $dst, $src\t# MoveL2D_stack_reg" %}
 10709   opcode(0xF2, 0x0F, 0x10);
 10710   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
 10711   ins_pipe(pipe_slow);
 10712 %}
 10715 instruct MoveF2I_reg_stack(stackSlotI dst, regF src) %{
 10716   match(Set dst (MoveF2I src));
 10717   effect(DEF dst, USE src);
 10719   ins_cost(95); // XXX
 10720   format %{ "movss   $dst, $src\t# MoveF2I_reg_stack" %}
 10721   opcode(0xF3, 0x0F, 0x11);
 10722   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
 10723   ins_pipe(pipe_slow);
 10724 %}
 10726 instruct MoveI2F_reg_stack(stackSlotF dst, rRegI src) %{
 10727   match(Set dst (MoveI2F src));
 10728   effect(DEF dst, USE src);
 10730   ins_cost(100);
 10731   format %{ "movl    $dst, $src\t# MoveI2F_reg_stack" %}
 10732   opcode(0x89);
 10733   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
 10734   ins_pipe( ialu_mem_reg );
 10735 %}
 10737 instruct MoveD2L_reg_stack(stackSlotL dst, regD src) %{
 10738   match(Set dst (MoveD2L src));
 10739   effect(DEF dst, USE src);
 10741   ins_cost(95); // XXX
 10742   format %{ "movsd   $dst, $src\t# MoveL2D_reg_stack" %}
 10743   opcode(0xF2, 0x0F, 0x11);
 10744   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
 10745   ins_pipe(pipe_slow);
 10746 %}
 10748 instruct MoveL2D_reg_stack(stackSlotD dst, rRegL src) %{
 10749   match(Set dst (MoveL2D src));
 10750   effect(DEF dst, USE src);
 10752   ins_cost(100);
 10753   format %{ "movq    $dst, $src\t# MoveL2D_reg_stack" %}
 10754   opcode(0x89);
 10755   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
 10756   ins_pipe(ialu_mem_reg);
 10757 %}
 10759 instruct MoveF2I_reg_reg(rRegI dst, regF src) %{
 10760   match(Set dst (MoveF2I src));
 10761   effect(DEF dst, USE src);
 10762   ins_cost(85);
 10763   format %{ "movd    $dst,$src\t# MoveF2I" %}
 10764   ins_encode %{ __ movdl($dst$$Register, $src$$XMMRegister); %}
 10765   ins_pipe( pipe_slow );
 10766 %}
 10768 instruct MoveD2L_reg_reg(rRegL dst, regD src) %{
 10769   match(Set dst (MoveD2L src));
 10770   effect(DEF dst, USE src);
 10771   ins_cost(85);
 10772   format %{ "movd    $dst,$src\t# MoveD2L" %}
 10773   ins_encode %{ __ movdq($dst$$Register, $src$$XMMRegister); %}
 10774   ins_pipe( pipe_slow );
 10775 %}
 10777 // The next instructions have long latency and use Int unit. Set high cost.
 10778 instruct MoveI2F_reg_reg(regF dst, rRegI src) %{
 10779   match(Set dst (MoveI2F src));
 10780   effect(DEF dst, USE src);
 10781   ins_cost(300);
 10782   format %{ "movd    $dst,$src\t# MoveI2F" %}
 10783   ins_encode %{ __ movdl($dst$$XMMRegister, $src$$Register); %}
 10784   ins_pipe( pipe_slow );
 10785 %}
 10787 instruct MoveL2D_reg_reg(regD dst, rRegL src) %{
 10788   match(Set dst (MoveL2D src));
 10789   effect(DEF dst, USE src);
 10790   ins_cost(300);
 10791   format %{ "movd    $dst,$src\t# MoveL2D" %}
 10792   ins_encode %{ __ movdq($dst$$XMMRegister, $src$$Register); %}
 10793   ins_pipe( pipe_slow );
 10794 %}
 10796 // Replicate scalar to packed byte (1 byte) values in xmm
 10797 instruct Repl8B_reg(regD dst, regD src) %{
 10798   match(Set dst (Replicate8B src));
 10799   format %{ "MOVDQA  $dst,$src\n\t"
 10800             "PUNPCKLBW $dst,$dst\n\t"
 10801             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
 10802   ins_encode( pshufd_8x8(dst, src));
 10803   ins_pipe( pipe_slow );
 10804 %}
 10806 // Replicate scalar to packed byte (1 byte) values in xmm
 10807 instruct Repl8B_rRegI(regD dst, rRegI src) %{
 10808   match(Set dst (Replicate8B src));
 10809   format %{ "MOVD    $dst,$src\n\t"
 10810             "PUNPCKLBW $dst,$dst\n\t"
 10811             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
 10812   ins_encode( mov_i2x(dst, src), pshufd_8x8(dst, dst));
 10813   ins_pipe( pipe_slow );
 10814 %}
 10816 // Replicate scalar zero to packed byte (1 byte) values in xmm
 10817 instruct Repl8B_immI0(regD dst, immI0 zero) %{
 10818   match(Set dst (Replicate8B zero));
 10819   format %{ "PXOR  $dst,$dst\t! replicate8B" %}
 10820   ins_encode( pxor(dst, dst));
 10821   ins_pipe( fpu_reg_reg );
 10822 %}
 10824 // Replicate scalar to packed shore (2 byte) values in xmm
 10825 instruct Repl4S_reg(regD dst, regD src) %{
 10826   match(Set dst (Replicate4S src));
 10827   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4S" %}
 10828   ins_encode( pshufd_4x16(dst, src));
 10829   ins_pipe( fpu_reg_reg );
 10830 %}
 10832 // Replicate scalar to packed shore (2 byte) values in xmm
 10833 instruct Repl4S_rRegI(regD dst, rRegI src) %{
 10834   match(Set dst (Replicate4S src));
 10835   format %{ "MOVD    $dst,$src\n\t"
 10836             "PSHUFLW $dst,$dst,0x00\t! replicate4S" %}
 10837   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
 10838   ins_pipe( fpu_reg_reg );
 10839 %}
 10841 // Replicate scalar zero to packed short (2 byte) values in xmm
 10842 instruct Repl4S_immI0(regD dst, immI0 zero) %{
 10843   match(Set dst (Replicate4S zero));
 10844   format %{ "PXOR  $dst,$dst\t! replicate4S" %}
 10845   ins_encode( pxor(dst, dst));
 10846   ins_pipe( fpu_reg_reg );
 10847 %}
 10849 // Replicate scalar to packed char (2 byte) values in xmm
 10850 instruct Repl4C_reg(regD dst, regD src) %{
 10851   match(Set dst (Replicate4C src));
 10852   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4C" %}
 10853   ins_encode( pshufd_4x16(dst, src));
 10854   ins_pipe( fpu_reg_reg );
 10855 %}
 10857 // Replicate scalar to packed char (2 byte) values in xmm
 10858 instruct Repl4C_rRegI(regD dst, rRegI src) %{
 10859   match(Set dst (Replicate4C src));
 10860   format %{ "MOVD    $dst,$src\n\t"
 10861             "PSHUFLW $dst,$dst,0x00\t! replicate4C" %}
 10862   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
 10863   ins_pipe( fpu_reg_reg );
 10864 %}
 10866 // Replicate scalar zero to packed char (2 byte) values in xmm
 10867 instruct Repl4C_immI0(regD dst, immI0 zero) %{
 10868   match(Set dst (Replicate4C zero));
 10869   format %{ "PXOR  $dst,$dst\t! replicate4C" %}
 10870   ins_encode( pxor(dst, dst));
 10871   ins_pipe( fpu_reg_reg );
 10872 %}
 10874 // Replicate scalar to packed integer (4 byte) values in xmm
 10875 instruct Repl2I_reg(regD dst, regD src) %{
 10876   match(Set dst (Replicate2I src));
 10877   format %{ "PSHUFD $dst,$src,0x00\t! replicate2I" %}
 10878   ins_encode( pshufd(dst, src, 0x00));
 10879   ins_pipe( fpu_reg_reg );
 10880 %}
 10882 // Replicate scalar to packed integer (4 byte) values in xmm
 10883 instruct Repl2I_rRegI(regD dst, rRegI src) %{
 10884   match(Set dst (Replicate2I src));
 10885   format %{ "MOVD   $dst,$src\n\t"
 10886             "PSHUFD $dst,$dst,0x00\t! replicate2I" %}
 10887   ins_encode( mov_i2x(dst, src), pshufd(dst, dst, 0x00));
 10888   ins_pipe( fpu_reg_reg );
 10889 %}
 10891 // Replicate scalar zero to packed integer (2 byte) values in xmm
 10892 instruct Repl2I_immI0(regD dst, immI0 zero) %{
 10893   match(Set dst (Replicate2I zero));
 10894   format %{ "PXOR  $dst,$dst\t! replicate2I" %}
 10895   ins_encode( pxor(dst, dst));
 10896   ins_pipe( fpu_reg_reg );
 10897 %}
 10899 // Replicate scalar to packed single precision floating point values in xmm
 10900 instruct Repl2F_reg(regD dst, regD src) %{
 10901   match(Set dst (Replicate2F src));
 10902   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
 10903   ins_encode( pshufd(dst, src, 0xe0));
 10904   ins_pipe( fpu_reg_reg );
 10905 %}
 10907 // Replicate scalar to packed single precision floating point values in xmm
 10908 instruct Repl2F_regF(regD dst, regF src) %{
 10909   match(Set dst (Replicate2F src));
 10910   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
 10911   ins_encode( pshufd(dst, src, 0xe0));
 10912   ins_pipe( fpu_reg_reg );
 10913 %}
 10915 // Replicate scalar to packed single precision floating point values in xmm
 10916 instruct Repl2F_immF0(regD dst, immF0 zero) %{
 10917   match(Set dst (Replicate2F zero));
 10918   format %{ "PXOR  $dst,$dst\t! replicate2F" %}
 10919   ins_encode( pxor(dst, dst));
 10920   ins_pipe( fpu_reg_reg );
 10921 %}
 10924 // =======================================================================
 10925 // fast clearing of an array
 10926 instruct rep_stos(rcx_RegL cnt, rdi_RegP base, rax_RegI zero, Universe dummy,
 10927                   rFlagsReg cr)
 10928 %{
 10929   match(Set dummy (ClearArray cnt base));
 10930   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
 10932   format %{ "xorl    rax, rax\t# ClearArray:\n\t"
 10933             "rep stosq\t# Store rax to *rdi++ while rcx--" %}
 10934   ins_encode(opc_reg_reg(0x33, RAX, RAX), // xorl %eax, %eax
 10935              Opcode(0xF3), Opcode(0x48), Opcode(0xAB)); // rep REX_W stos
 10936   ins_pipe(pipe_slow);
 10937 %}
 10939 instruct string_compare(rdi_RegP str1, rsi_RegP str2, rax_RegI tmp1,
 10940                         rbx_RegI tmp2, rcx_RegI result, rFlagsReg cr)
 10941 %{
 10942   match(Set result (StrComp str1 str2));
 10943   effect(USE_KILL str1, USE_KILL str2, KILL tmp1, KILL tmp2, KILL cr);
 10944   //ins_cost(300);
 10946   format %{ "String Compare $str1, $str2 -> $result    // XXX KILL RAX, RBX" %}
 10947   ins_encode( enc_String_Compare() );
 10948   ins_pipe( pipe_slow );
 10949 %}
 10951 // fast array equals
 10952 instruct array_equals(rdi_RegP ary1, rsi_RegP ary2, rax_RegI tmp1, 
 10953                       rbx_RegI tmp2, rcx_RegI result, rFlagsReg cr) %{
 10954   match(Set result (AryEq ary1 ary2));
 10955   effect(USE_KILL ary1, USE_KILL ary2, KILL tmp1, KILL tmp2, KILL cr);
 10956   //ins_cost(300);
 10958   format %{ "Array Equals $ary1,$ary2 -> $result    // KILL RAX, RBX" %}
 10959   ins_encode( enc_Array_Equals(ary1, ary2, tmp1, tmp2, result) );
 10960   ins_pipe( pipe_slow );
 10961 %}
 10963 //----------Control Flow Instructions------------------------------------------
 10964 // Signed compare Instructions
 10966 // XXX more variants!!
 10967 instruct compI_rReg(rFlagsReg cr, rRegI op1, rRegI op2)
 10968 %{
 10969   match(Set cr (CmpI op1 op2));
 10970   effect(DEF cr, USE op1, USE op2);
 10972   format %{ "cmpl    $op1, $op2" %}
 10973   opcode(0x3B);  /* Opcode 3B /r */
 10974   ins_encode(REX_reg_reg(op1, op2), OpcP, reg_reg(op1, op2));
 10975   ins_pipe(ialu_cr_reg_reg);
 10976 %}
 10978 instruct compI_rReg_imm(rFlagsReg cr, rRegI op1, immI op2)
 10979 %{
 10980   match(Set cr (CmpI op1 op2));
 10982   format %{ "cmpl    $op1, $op2" %}
 10983   opcode(0x81, 0x07); /* Opcode 81 /7 */
 10984   ins_encode(OpcSErm(op1, op2), Con8or32(op2));
 10985   ins_pipe(ialu_cr_reg_imm);
 10986 %}
 10988 instruct compI_rReg_mem(rFlagsReg cr, rRegI op1, memory op2)
 10989 %{
 10990   match(Set cr (CmpI op1 (LoadI op2)));
 10992   ins_cost(500); // XXX
 10993   format %{ "cmpl    $op1, $op2" %}
 10994   opcode(0x3B); /* Opcode 3B /r */
 10995   ins_encode(REX_reg_mem(op1, op2), OpcP, reg_mem(op1, op2));
 10996   ins_pipe(ialu_cr_reg_mem);
 10997 %}
 10999 instruct testI_reg(rFlagsReg cr, rRegI src, immI0 zero)
 11000 %{
 11001   match(Set cr (CmpI src zero));
 11003   format %{ "testl   $src, $src" %}
 11004   opcode(0x85);
 11005   ins_encode(REX_reg_reg(src, src), OpcP, reg_reg(src, src));
 11006   ins_pipe(ialu_cr_reg_imm);
 11007 %}
 11009 instruct testI_reg_imm(rFlagsReg cr, rRegI src, immI con, immI0 zero)
 11010 %{
 11011   match(Set cr (CmpI (AndI src con) zero));
 11013   format %{ "testl   $src, $con" %}
 11014   opcode(0xF7, 0x00);
 11015   ins_encode(REX_reg(src), OpcP, reg_opc(src), Con32(con));
 11016   ins_pipe(ialu_cr_reg_imm);
 11017 %}
 11019 instruct testI_reg_mem(rFlagsReg cr, rRegI src, memory mem, immI0 zero)
 11020 %{
 11021   match(Set cr (CmpI (AndI src (LoadI mem)) zero));
 11023   format %{ "testl   $src, $mem" %}
 11024   opcode(0x85);
 11025   ins_encode(REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
 11026   ins_pipe(ialu_cr_reg_mem);
 11027 %}
 11029 // Unsigned compare Instructions; really, same as signed except they
 11030 // produce an rFlagsRegU instead of rFlagsReg.
 11031 instruct compU_rReg(rFlagsRegU cr, rRegI op1, rRegI op2)
 11032 %{
 11033   match(Set cr (CmpU op1 op2));
 11035   format %{ "cmpl    $op1, $op2\t# unsigned" %}
 11036   opcode(0x3B); /* Opcode 3B /r */
 11037   ins_encode(REX_reg_reg(op1, op2), OpcP, reg_reg(op1, op2));
 11038   ins_pipe(ialu_cr_reg_reg);
 11039 %}
 11041 instruct compU_rReg_imm(rFlagsRegU cr, rRegI op1, immI op2)
 11042 %{
 11043   match(Set cr (CmpU op1 op2));
 11045   format %{ "cmpl    $op1, $op2\t# unsigned" %}
 11046   opcode(0x81,0x07); /* Opcode 81 /7 */
 11047   ins_encode(OpcSErm(op1, op2), Con8or32(op2));
 11048   ins_pipe(ialu_cr_reg_imm);
 11049 %}
 11051 instruct compU_rReg_mem(rFlagsRegU cr, rRegI op1, memory op2)
 11052 %{
 11053   match(Set cr (CmpU op1 (LoadI op2)));
 11055   ins_cost(500); // XXX
 11056   format %{ "cmpl    $op1, $op2\t# unsigned" %}
 11057   opcode(0x3B); /* Opcode 3B /r */
 11058   ins_encode(REX_reg_mem(op1, op2), OpcP, reg_mem(op1, op2));
 11059   ins_pipe(ialu_cr_reg_mem);
 11060 %}
 11062 // // // Cisc-spilled version of cmpU_rReg
 11063 // //instruct compU_mem_rReg(rFlagsRegU cr, memory op1, rRegI op2)
 11064 // //%{
 11065 // //  match(Set cr (CmpU (LoadI op1) op2));
 11066 // //
 11067 // //  format %{ "CMPu   $op1,$op2" %}
 11068 // //  ins_cost(500);
 11069 // //  opcode(0x39);  /* Opcode 39 /r */
 11070 // //  ins_encode( OpcP, reg_mem( op1, op2) );
 11071 // //%}
 11073 instruct testU_reg(rFlagsRegU cr, rRegI src, immI0 zero)
 11074 %{
 11075   match(Set cr (CmpU src zero));
 11077   format %{ "testl  $src, $src\t# unsigned" %}
 11078   opcode(0x85);
 11079   ins_encode(REX_reg_reg(src, src), OpcP, reg_reg(src, src));
 11080   ins_pipe(ialu_cr_reg_imm);
 11081 %}
 11083 instruct compP_rReg(rFlagsRegU cr, rRegP op1, rRegP op2)
 11084 %{
 11085   match(Set cr (CmpP op1 op2));
 11087   format %{ "cmpq    $op1, $op2\t# ptr" %}
 11088   opcode(0x3B); /* Opcode 3B /r */
 11089   ins_encode(REX_reg_reg_wide(op1, op2), OpcP, reg_reg(op1, op2));
 11090   ins_pipe(ialu_cr_reg_reg);
 11091 %}
 11093 instruct compP_rReg_mem(rFlagsRegU cr, rRegP op1, memory op2)
 11094 %{
 11095   match(Set cr (CmpP op1 (LoadP op2)));
 11097   ins_cost(500); // XXX
 11098   format %{ "cmpq    $op1, $op2\t# ptr" %}
 11099   opcode(0x3B); /* Opcode 3B /r */
 11100   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
 11101   ins_pipe(ialu_cr_reg_mem);
 11102 %}
 11104 // // // Cisc-spilled version of cmpP_rReg
 11105 // //instruct compP_mem_rReg(rFlagsRegU cr, memory op1, rRegP op2)
 11106 // //%{
 11107 // //  match(Set cr (CmpP (LoadP op1) op2));
 11108 // //
 11109 // //  format %{ "CMPu   $op1,$op2" %}
 11110 // //  ins_cost(500);
 11111 // //  opcode(0x39);  /* Opcode 39 /r */
 11112 // //  ins_encode( OpcP, reg_mem( op1, op2) );
 11113 // //%}
 11115 // XXX this is generalized by compP_rReg_mem???
 11116 // Compare raw pointer (used in out-of-heap check).
 11117 // Only works because non-oop pointers must be raw pointers
 11118 // and raw pointers have no anti-dependencies.
 11119 instruct compP_mem_rReg(rFlagsRegU cr, rRegP op1, memory op2)
 11120 %{
 11121   predicate(!n->in(2)->in(2)->bottom_type()->isa_oop_ptr());
 11122   match(Set cr (CmpP op1 (LoadP op2)));
 11124   format %{ "cmpq    $op1, $op2\t# raw ptr" %}
 11125   opcode(0x3B); /* Opcode 3B /r */
 11126   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
 11127   ins_pipe(ialu_cr_reg_mem);
 11128 %}
 11130 // This will generate a signed flags result. This should be OK since
 11131 // any compare to a zero should be eq/neq.
 11132 instruct testP_reg(rFlagsReg cr, rRegP src, immP0 zero)
 11133 %{
 11134   match(Set cr (CmpP src zero));
 11136   format %{ "testq   $src, $src\t# ptr" %}
 11137   opcode(0x85);
 11138   ins_encode(REX_reg_reg_wide(src, src), OpcP, reg_reg(src, src));
 11139   ins_pipe(ialu_cr_reg_imm);
 11140 %}
 11142 // This will generate a signed flags result. This should be OK since
 11143 // any compare to a zero should be eq/neq.
 11144 instruct testP_reg_mem(rFlagsReg cr, memory op, immP0 zero)
 11145 %{
 11146   match(Set cr (CmpP (LoadP op) zero));
 11148   ins_cost(500); // XXX
 11149   format %{ "testq   $op, 0xffffffffffffffff\t# ptr" %}
 11150   opcode(0xF7); /* Opcode F7 /0 */
 11151   ins_encode(REX_mem_wide(op),
 11152              OpcP, RM_opc_mem(0x00, op), Con_d32(0xFFFFFFFF));
 11153   ins_pipe(ialu_cr_reg_imm);
 11154 %}
 11157 instruct compN_rReg(rFlagsRegU cr, rRegN op1, rRegN op2)
 11158 %{
 11159   match(Set cr (CmpN op1 op2));
 11161   format %{ "cmpl    $op1, $op2\t# compressed ptr" %}
 11162   ins_encode %{ __ cmpl(as_Register($op1$$reg), as_Register($op2$$reg)); %}
 11163   ins_pipe(ialu_cr_reg_reg);
 11164 %}
 11166 instruct compN_rReg_mem(rFlagsRegU cr, rRegN src, memory mem)
 11167 %{
 11168   match(Set cr (CmpN src (LoadN mem)));
 11170   ins_cost(500); // XXX
 11171   format %{ "cmpl    $src, mem\t# compressed ptr" %}
 11172   ins_encode %{
 11173     Address adr = build_address($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
 11174     __ cmpl(as_Register($src$$reg), adr);
 11175   %}
 11176   ins_pipe(ialu_cr_reg_mem);
 11177 %}
 11179 instruct testN_reg(rFlagsReg cr, rRegN src, immN0 zero) %{
 11180   match(Set cr (CmpN src zero));
 11182   format %{ "testl   $src, $src\t# compressed ptr" %}
 11183   ins_encode %{ __ testl($src$$Register, $src$$Register); %}
 11184   ins_pipe(ialu_cr_reg_imm);
 11185 %}
 11187 instruct testN_reg_mem(rFlagsReg cr, memory mem, immN0 zero)
 11188 %{
 11189   match(Set cr (CmpN (LoadN mem) zero));
 11191   ins_cost(500); // XXX
 11192   format %{ "testl   $mem, 0xffffffff\t# compressed ptr" %}
 11193   ins_encode %{
 11194     Address addr = build_address($mem$$base, $mem$$index, $mem$$scale, $mem$$disp);
 11195     __ cmpl(addr, (int)0xFFFFFFFF);
 11196   %}
 11197   ins_pipe(ialu_cr_reg_mem);
 11198 %}
 11200 // Yanked all unsigned pointer compare operations.
 11201 // Pointer compares are done with CmpP which is already unsigned.
 11203 instruct compL_rReg(rFlagsReg cr, rRegL op1, rRegL op2)
 11204 %{
 11205   match(Set cr (CmpL op1 op2));
 11207   format %{ "cmpq    $op1, $op2" %}
 11208   opcode(0x3B);  /* Opcode 3B /r */
 11209   ins_encode(REX_reg_reg_wide(op1, op2), OpcP, reg_reg(op1, op2));
 11210   ins_pipe(ialu_cr_reg_reg);
 11211 %}
 11213 instruct compL_rReg_imm(rFlagsReg cr, rRegL op1, immL32 op2)
 11214 %{
 11215   match(Set cr (CmpL op1 op2));
 11217   format %{ "cmpq    $op1, $op2" %}
 11218   opcode(0x81, 0x07); /* Opcode 81 /7 */
 11219   ins_encode(OpcSErm_wide(op1, op2), Con8or32(op2));
 11220   ins_pipe(ialu_cr_reg_imm);
 11221 %}
 11223 instruct compL_rReg_mem(rFlagsReg cr, rRegL op1, memory op2)
 11224 %{
 11225   match(Set cr (CmpL op1 (LoadL op2)));
 11227   ins_cost(500); // XXX
 11228   format %{ "cmpq    $op1, $op2" %}
 11229   opcode(0x3B); /* Opcode 3B /r */
 11230   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
 11231   ins_pipe(ialu_cr_reg_mem);
 11232 %}
 11234 instruct testL_reg(rFlagsReg cr, rRegL src, immL0 zero)
 11235 %{
 11236   match(Set cr (CmpL src zero));
 11238   format %{ "testq   $src, $src" %}
 11239   opcode(0x85);
 11240   ins_encode(REX_reg_reg_wide(src, src), OpcP, reg_reg(src, src));
 11241   ins_pipe(ialu_cr_reg_imm);
 11242 %}
 11244 instruct testL_reg_imm(rFlagsReg cr, rRegL src, immL32 con, immL0 zero)
 11245 %{
 11246   match(Set cr (CmpL (AndL src con) zero));
 11248   format %{ "testq   $src, $con\t# long" %}
 11249   opcode(0xF7, 0x00);
 11250   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src), Con32(con));
 11251   ins_pipe(ialu_cr_reg_imm);
 11252 %}
 11254 instruct testL_reg_mem(rFlagsReg cr, rRegL src, memory mem, immL0 zero)
 11255 %{
 11256   match(Set cr (CmpL (AndL src (LoadL mem)) zero));
 11258   format %{ "testq   $src, $mem" %}
 11259   opcode(0x85);
 11260   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
 11261   ins_pipe(ialu_cr_reg_mem);
 11262 %}
 11264 // Manifest a CmpL result in an integer register.  Very painful.
 11265 // This is the test to avoid.
 11266 instruct cmpL3_reg_reg(rRegI dst, rRegL src1, rRegL src2, rFlagsReg flags)
 11267 %{
 11268   match(Set dst (CmpL3 src1 src2));
 11269   effect(KILL flags);
 11271   ins_cost(275); // XXX
 11272   format %{ "cmpq    $src1, $src2\t# CmpL3\n\t"
 11273             "movl    $dst, -1\n\t"
 11274             "jl,s    done\n\t"
 11275             "setne   $dst\n\t"
 11276             "movzbl  $dst, $dst\n\t"
 11277     "done:" %}
 11278   ins_encode(cmpl3_flag(src1, src2, dst));
 11279   ins_pipe(pipe_slow);
 11280 %}
 11282 //----------Max and Min--------------------------------------------------------
 11283 // Min Instructions
 11285 instruct cmovI_reg_g(rRegI dst, rRegI src, rFlagsReg cr)
 11286 %{
 11287   effect(USE_DEF dst, USE src, USE cr);
 11289   format %{ "cmovlgt $dst, $src\t# min" %}
 11290   opcode(0x0F, 0x4F);
 11291   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
 11292   ins_pipe(pipe_cmov_reg);
 11293 %}
 11296 instruct minI_rReg(rRegI dst, rRegI src)
 11297 %{
 11298   match(Set dst (MinI dst src));
 11300   ins_cost(200);
 11301   expand %{
 11302     rFlagsReg cr;
 11303     compI_rReg(cr, dst, src);
 11304     cmovI_reg_g(dst, src, cr);
 11305   %}
 11306 %}
 11308 instruct cmovI_reg_l(rRegI dst, rRegI src, rFlagsReg cr)
 11309 %{
 11310   effect(USE_DEF dst, USE src, USE cr);
 11312   format %{ "cmovllt $dst, $src\t# max" %}
 11313   opcode(0x0F, 0x4C);
 11314   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
 11315   ins_pipe(pipe_cmov_reg);
 11316 %}
 11319 instruct maxI_rReg(rRegI dst, rRegI src)
 11320 %{
 11321   match(Set dst (MaxI dst src));
 11323   ins_cost(200);
 11324   expand %{
 11325     rFlagsReg cr;
 11326     compI_rReg(cr, dst, src);
 11327     cmovI_reg_l(dst, src, cr);
 11328   %}
 11329 %}
 11331 // ============================================================================
 11332 // Branch Instructions
 11334 // Jump Direct - Label defines a relative address from JMP+1
 11335 instruct jmpDir(label labl)
 11336 %{
 11337   match(Goto);
 11338   effect(USE labl);
 11340   ins_cost(300);
 11341   format %{ "jmp     $labl" %}
 11342   size(5);
 11343   opcode(0xE9);
 11344   ins_encode(OpcP, Lbl(labl));
 11345   ins_pipe(pipe_jmp);
 11346   ins_pc_relative(1);
 11347 %}
 11349 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11350 instruct jmpCon(cmpOp cop, rFlagsReg cr, label labl)
 11351 %{
 11352   match(If cop cr);
 11353   effect(USE labl);
 11355   ins_cost(300);
 11356   format %{ "j$cop     $labl" %}
 11357   size(6);
 11358   opcode(0x0F, 0x80);
 11359   ins_encode(Jcc(cop, labl));
 11360   ins_pipe(pipe_jcc);
 11361   ins_pc_relative(1);
 11362 %}
 11364 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11365 instruct jmpLoopEnd(cmpOp cop, rFlagsReg cr, label labl)
 11366 %{
 11367   match(CountedLoopEnd cop cr);
 11368   effect(USE labl);
 11370   ins_cost(300);
 11371   format %{ "j$cop     $labl\t# loop end" %}
 11372   size(6);
 11373   opcode(0x0F, 0x80);
 11374   ins_encode(Jcc(cop, labl));
 11375   ins_pipe(pipe_jcc);
 11376   ins_pc_relative(1);
 11377 %}
 11379 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11380 instruct jmpLoopEndU(cmpOpU cop, rFlagsRegU cmp, label labl)
 11381 %{
 11382   match(CountedLoopEnd cop cmp);
 11383   effect(USE labl);
 11385   ins_cost(300);
 11386   format %{ "j$cop,u   $labl\t# loop end" %}
 11387   size(6);
 11388   opcode(0x0F, 0x80);
 11389   ins_encode(Jcc(cop, labl));
 11390   ins_pipe(pipe_jcc);
 11391   ins_pc_relative(1);
 11392 %}
 11394 // Jump Direct Conditional - using unsigned comparison
 11395 instruct jmpConU(cmpOpU cop, rFlagsRegU cmp, label labl)
 11396 %{
 11397   match(If cop cmp);
 11398   effect(USE labl);
 11400   ins_cost(300);
 11401   format %{ "j$cop,u   $labl" %}
 11402   size(6);
 11403   opcode(0x0F, 0x80);
 11404   ins_encode(Jcc(cop, labl));
 11405   ins_pipe(pipe_jcc);
 11406   ins_pc_relative(1);
 11407 %}
 11409 // ============================================================================
 11410 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary
 11411 // superklass array for an instance of the superklass.  Set a hidden
 11412 // internal cache on a hit (cache is checked with exposed code in
 11413 // gen_subtype_check()).  Return NZ for a miss or zero for a hit.  The
 11414 // encoding ALSO sets flags.
 11416 instruct partialSubtypeCheck(rdi_RegP result,
 11417                              rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
 11418                              rFlagsReg cr)
 11419 %{
 11420   match(Set result (PartialSubtypeCheck sub super));
 11421   effect(KILL rcx, KILL cr);
 11423   ins_cost(1100);  // slightly larger than the next version
 11424   format %{ "cmpq    rax, rsi\n\t"
 11425             "jeq,s   hit\n\t"
 11426             "movq    rdi, [$sub + (sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes())]\n\t"
 11427             "movl    rcx, [rdi + arrayOopDesc::length_offset_in_bytes()]\t# length to scan\n\t"
 11428             "addq    rdi, arrayOopDex::base_offset_in_bytes(T_OBJECT)\t# Skip to start of data; set NZ in case count is zero\n\t"
 11429             "repne   scasq\t# Scan *rdi++ for a match with rax while rcx--\n\t"
 11430             "jne,s   miss\t\t# Missed: rdi not-zero\n\t"
 11431             "movq    [$sub + (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes())], $super\t# Hit: update cache\n\t"
 11432     "hit:\n\t"
 11433             "xorq    $result, $result\t\t Hit: rdi zero\n\t"
 11434     "miss:\t" %}
 11436   opcode(0x1); // Force a XOR of RDI
 11437   ins_encode(enc_PartialSubtypeCheck());
 11438   ins_pipe(pipe_slow);
 11439 %}
 11441 instruct partialSubtypeCheck_vs_Zero(rFlagsReg cr,
 11442                                      rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
 11443                                      immP0 zero,
 11444                                      rdi_RegP result)
 11445 %{
 11446   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
 11447   predicate(!UseCompressedOops); // decoding oop kills condition codes
 11448   effect(KILL rcx, KILL result);
 11450   ins_cost(1000);
 11451   format %{ "cmpq    rax, rsi\n\t"
 11452             "jeq,s   miss\t# Actually a hit; we are done.\n\t"
 11453             "movq    rdi, [$sub + (sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes())]\n\t"
 11454             "movl    rcx, [rdi + arrayOopDesc::length_offset_in_bytes()]\t# length to scan\n\t"
 11455             "addq    rdi, arrayOopDex::base_offset_in_bytes(T_OBJECT)\t# Skip to start of data; set NZ in case count is zero\n\t"
 11456             "repne   scasq\t# Scan *rdi++ for a match with rax while cx-- != 0\n\t"
 11457             "jne,s   miss\t\t# Missed: flags nz\n\t"
 11458             "movq    [$sub + (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes())], $super\t# Hit: update cache\n\t"
 11459     "miss:\t" %}
 11461   opcode(0x0); // No need to XOR RDI
 11462   ins_encode(enc_PartialSubtypeCheck());
 11463   ins_pipe(pipe_slow);
 11464 %}
 11466 // ============================================================================
 11467 // Branch Instructions -- short offset versions
 11468 //
 11469 // These instructions are used to replace jumps of a long offset (the default
 11470 // match) with jumps of a shorter offset.  These instructions are all tagged
 11471 // with the ins_short_branch attribute, which causes the ADLC to suppress the
 11472 // match rules in general matching.  Instead, the ADLC generates a conversion
 11473 // method in the MachNode which can be used to do in-place replacement of the
 11474 // long variant with the shorter variant.  The compiler will determine if a
 11475 // branch can be taken by the is_short_branch_offset() predicate in the machine
 11476 // specific code section of the file.
 11478 // Jump Direct - Label defines a relative address from JMP+1
 11479 instruct jmpDir_short(label labl)
 11480 %{
 11481   match(Goto);
 11482   effect(USE labl);
 11484   ins_cost(300);
 11485   format %{ "jmp,s   $labl" %}
 11486   size(2);
 11487   opcode(0xEB);
 11488   ins_encode(OpcP, LblShort(labl));
 11489   ins_pipe(pipe_jmp);
 11490   ins_pc_relative(1);
 11491   ins_short_branch(1);
 11492 %}
 11494 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11495 instruct jmpCon_short(cmpOp cop, rFlagsReg cr, label labl)
 11496 %{
 11497   match(If cop cr);
 11498   effect(USE labl);
 11500   ins_cost(300);
 11501   format %{ "j$cop,s   $labl" %}
 11502   size(2);
 11503   opcode(0x70);
 11504   ins_encode(JccShort(cop, labl));
 11505   ins_pipe(pipe_jcc);
 11506   ins_pc_relative(1);
 11507   ins_short_branch(1);
 11508 %}
 11510 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11511 instruct jmpLoopEnd_short(cmpOp cop, rFlagsReg cr, label labl)
 11512 %{
 11513   match(CountedLoopEnd cop cr);
 11514   effect(USE labl);
 11516   ins_cost(300);
 11517   format %{ "j$cop,s   $labl" %}
 11518   size(2);
 11519   opcode(0x70);
 11520   ins_encode(JccShort(cop, labl));
 11521   ins_pipe(pipe_jcc);
 11522   ins_pc_relative(1);
 11523   ins_short_branch(1);
 11524 %}
 11526 // Jump Direct Conditional - Label defines a relative address from Jcc+1
 11527 instruct jmpLoopEndU_short(cmpOpU cop, rFlagsRegU cmp, label labl)
 11528 %{
 11529   match(CountedLoopEnd cop cmp);
 11530   effect(USE labl);
 11532   ins_cost(300);
 11533   format %{ "j$cop,us  $labl" %}
 11534   size(2);
 11535   opcode(0x70);
 11536   ins_encode(JccShort(cop, labl));
 11537   ins_pipe(pipe_jcc);
 11538   ins_pc_relative(1);
 11539   ins_short_branch(1);
 11540 %}
 11542 // Jump Direct Conditional - using unsigned comparison
 11543 instruct jmpConU_short(cmpOpU cop, rFlagsRegU cmp, label labl)
 11544 %{
 11545   match(If cop cmp);
 11546   effect(USE labl);
 11548   ins_cost(300);
 11549   format %{ "j$cop,us  $labl" %}
 11550   size(2);
 11551   opcode(0x70);
 11552   ins_encode(JccShort(cop, labl));
 11553   ins_pipe(pipe_jcc);
 11554   ins_pc_relative(1);
 11555   ins_short_branch(1);
 11556 %}
 11558 // ============================================================================
 11559 // inlined locking and unlocking
 11561 instruct cmpFastLock(rFlagsReg cr,
 11562                      rRegP object, rRegP box, rax_RegI tmp, rRegP scr)
 11563 %{
 11564   match(Set cr (FastLock object box));
 11565   effect(TEMP tmp, TEMP scr);
 11567   ins_cost(300);
 11568   format %{ "fastlock $object,$box,$tmp,$scr" %}
 11569   ins_encode(Fast_Lock(object, box, tmp, scr));
 11570   ins_pipe(pipe_slow);
 11571   ins_pc_relative(1);
 11572 %}
 11574 instruct cmpFastUnlock(rFlagsReg cr,
 11575                        rRegP object, rax_RegP box, rRegP tmp)
 11576 %{
 11577   match(Set cr (FastUnlock object box));
 11578   effect(TEMP tmp);
 11580   ins_cost(300);
 11581   format %{ "fastunlock $object, $box, $tmp" %}
 11582   ins_encode(Fast_Unlock(object, box, tmp));
 11583   ins_pipe(pipe_slow);
 11584   ins_pc_relative(1);
 11585 %}
 11588 // ============================================================================
 11589 // Safepoint Instructions
 11590 instruct safePoint_poll(rFlagsReg cr)
 11591 %{
 11592   match(SafePoint);
 11593   effect(KILL cr);
 11595   format %{ "testl   rax, [rip + #offset_to_poll_page]\t"
 11596             "# Safepoint: poll for GC" %}
 11597   size(6); // Opcode + ModRM + Disp32 == 6 bytes
 11598   ins_cost(125);
 11599   ins_encode(enc_safepoint_poll);
 11600   ins_pipe(ialu_reg_mem);
 11601 %}
 11603 // ============================================================================
 11604 // Procedure Call/Return Instructions
 11605 // Call Java Static Instruction
 11606 // Note: If this code changes, the corresponding ret_addr_offset() and
 11607 //       compute_padding() functions will have to be adjusted.
 11608 instruct CallStaticJavaDirect(method meth)
 11609 %{
 11610   match(CallStaticJava);
 11611   effect(USE meth);
 11613   ins_cost(300);
 11614   format %{ "call,static " %}
 11615   opcode(0xE8); /* E8 cd */
 11616   ins_encode(Java_Static_Call(meth), call_epilog);
 11617   ins_pipe(pipe_slow);
 11618   ins_pc_relative(1);
 11619   ins_alignment(4);
 11620 %}
 11622 // Call Java Dynamic Instruction
 11623 // Note: If this code changes, the corresponding ret_addr_offset() and
 11624 //       compute_padding() functions will have to be adjusted.
 11625 instruct CallDynamicJavaDirect(method meth)
 11626 %{
 11627   match(CallDynamicJava);
 11628   effect(USE meth);
 11630   ins_cost(300);
 11631   format %{ "movq    rax, #Universe::non_oop_word()\n\t"
 11632             "call,dynamic " %}
 11633   opcode(0xE8); /* E8 cd */
 11634   ins_encode(Java_Dynamic_Call(meth), call_epilog);
 11635   ins_pipe(pipe_slow);
 11636   ins_pc_relative(1);
 11637   ins_alignment(4);
 11638 %}
 11640 // Call Runtime Instruction
 11641 instruct CallRuntimeDirect(method meth)
 11642 %{
 11643   match(CallRuntime);
 11644   effect(USE meth);
 11646   ins_cost(300);
 11647   format %{ "call,runtime " %}
 11648   opcode(0xE8); /* E8 cd */
 11649   ins_encode(Java_To_Runtime(meth));
 11650   ins_pipe(pipe_slow);
 11651   ins_pc_relative(1);
 11652 %}
 11654 // Call runtime without safepoint
 11655 instruct CallLeafDirect(method meth)
 11656 %{
 11657   match(CallLeaf);
 11658   effect(USE meth);
 11660   ins_cost(300);
 11661   format %{ "call_leaf,runtime " %}
 11662   opcode(0xE8); /* E8 cd */
 11663   ins_encode(Java_To_Runtime(meth));
 11664   ins_pipe(pipe_slow);
 11665   ins_pc_relative(1);
 11666 %}
 11668 // Call runtime without safepoint
 11669 instruct CallLeafNoFPDirect(method meth)
 11670 %{
 11671   match(CallLeafNoFP);
 11672   effect(USE meth);
 11674   ins_cost(300);
 11675   format %{ "call_leaf_nofp,runtime " %}
 11676   opcode(0xE8); /* E8 cd */
 11677   ins_encode(Java_To_Runtime(meth));
 11678   ins_pipe(pipe_slow);
 11679   ins_pc_relative(1);
 11680 %}
 11682 // Return Instruction
 11683 // Remove the return address & jump to it.
 11684 // Notice: We always emit a nop after a ret to make sure there is room
 11685 // for safepoint patching
 11686 instruct Ret()
 11687 %{
 11688   match(Return);
 11690   format %{ "ret" %}
 11691   opcode(0xC3);
 11692   ins_encode(OpcP);
 11693   ins_pipe(pipe_jmp);
 11694 %}
 11696 // Tail Call; Jump from runtime stub to Java code.
 11697 // Also known as an 'interprocedural jump'.
 11698 // Target of jump will eventually return to caller.
 11699 // TailJump below removes the return address.
 11700 instruct TailCalljmpInd(no_rbp_RegP jump_target, rbx_RegP method_oop)
 11701 %{
 11702   match(TailCall jump_target method_oop);
 11704   ins_cost(300);
 11705   format %{ "jmp     $jump_target\t# rbx holds method oop" %}
 11706   opcode(0xFF, 0x4); /* Opcode FF /4 */
 11707   ins_encode(REX_reg(jump_target), OpcP, reg_opc(jump_target));
 11708   ins_pipe(pipe_jmp);
 11709 %}
 11711 // Tail Jump; remove the return address; jump to target.
 11712 // TailCall above leaves the return address around.
 11713 instruct tailjmpInd(no_rbp_RegP jump_target, rax_RegP ex_oop)
 11714 %{
 11715   match(TailJump jump_target ex_oop);
 11717   ins_cost(300);
 11718   format %{ "popq    rdx\t# pop return address\n\t"
 11719             "jmp     $jump_target" %}
 11720   opcode(0xFF, 0x4); /* Opcode FF /4 */
 11721   ins_encode(Opcode(0x5a), // popq rdx
 11722              REX_reg(jump_target), OpcP, reg_opc(jump_target));
 11723   ins_pipe(pipe_jmp);
 11724 %}
 11726 // Create exception oop: created by stack-crawling runtime code.
 11727 // Created exception is now available to this handler, and is setup
 11728 // just prior to jumping to this handler.  No code emitted.
 11729 instruct CreateException(rax_RegP ex_oop)
 11730 %{
 11731   match(Set ex_oop (CreateEx));
 11733   size(0);
 11734   // use the following format syntax
 11735   format %{ "# exception oop is in rax; no code emitted" %}
 11736   ins_encode();
 11737   ins_pipe(empty);
 11738 %}
 11740 // Rethrow exception:
 11741 // The exception oop will come in the first argument position.
 11742 // Then JUMP (not call) to the rethrow stub code.
 11743 instruct RethrowException()
 11744 %{
 11745   match(Rethrow);
 11747   // use the following format syntax
 11748   format %{ "jmp     rethrow_stub" %}
 11749   ins_encode(enc_rethrow);
 11750   ins_pipe(pipe_jmp);
 11751 %}
 11754 //----------PEEPHOLE RULES-----------------------------------------------------
 11755 // These must follow all instruction definitions as they use the names
 11756 // defined in the instructions definitions.
 11757 //
 11758 // peepmatch ( root_instr_name [precerding_instruction]* );
 11759 //
 11760 // peepconstraint %{
 11761 // (instruction_number.operand_name relational_op instruction_number.operand_name
 11762 //  [, ...] );
 11763 // // instruction numbers are zero-based using left to right order in peepmatch
 11764 //
 11765 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
 11766 // // provide an instruction_number.operand_name for each operand that appears
 11767 // // in the replacement instruction's match rule
 11768 //
 11769 // ---------VM FLAGS---------------------------------------------------------
 11770 //
 11771 // All peephole optimizations can be turned off using -XX:-OptoPeephole
 11772 //
 11773 // Each peephole rule is given an identifying number starting with zero and
 11774 // increasing by one in the order seen by the parser.  An individual peephole
 11775 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
 11776 // on the command-line.
 11777 //
 11778 // ---------CURRENT LIMITATIONS----------------------------------------------
 11779 //
 11780 // Only match adjacent instructions in same basic block
 11781 // Only equality constraints
 11782 // Only constraints between operands, not (0.dest_reg == RAX_enc)
 11783 // Only one replacement instruction
 11784 //
 11785 // ---------EXAMPLE----------------------------------------------------------
 11786 //
 11787 // // pertinent parts of existing instructions in architecture description
 11788 // instruct movI(rRegI dst, rRegI src)
 11789 // %{
 11790 //   match(Set dst (CopyI src));
 11791 // %}
 11792 //
 11793 // instruct incI_rReg(rRegI dst, immI1 src, rFlagsReg cr)
 11794 // %{
 11795 //   match(Set dst (AddI dst src));
 11796 //   effect(KILL cr);
 11797 // %}
 11798 //
 11799 // // Change (inc mov) to lea
 11800 // peephole %{
 11801 //   // increment preceeded by register-register move
 11802 //   peepmatch ( incI_rReg movI );
 11803 //   // require that the destination register of the increment
 11804 //   // match the destination register of the move
 11805 //   peepconstraint ( 0.dst == 1.dst );
 11806 //   // construct a replacement instruction that sets
 11807 //   // the destination to ( move's source register + one )
 11808 //   peepreplace ( leaI_rReg_immI( 0.dst 1.src 0.src ) );
 11809 // %}
 11810 //
 11812 // Implementation no longer uses movX instructions since
 11813 // machine-independent system no longer uses CopyX nodes.
 11814 //
 11815 // peephole
 11816 // %{
 11817 //   peepmatch (incI_rReg movI);
 11818 //   peepconstraint (0.dst == 1.dst);
 11819 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
 11820 // %}
 11822 // peephole
 11823 // %{
 11824 //   peepmatch (decI_rReg movI);
 11825 //   peepconstraint (0.dst == 1.dst);
 11826 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
 11827 // %}
 11829 // peephole
 11830 // %{
 11831 //   peepmatch (addI_rReg_imm movI);
 11832 //   peepconstraint (0.dst == 1.dst);
 11833 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
 11834 // %}
 11836 // peephole
 11837 // %{
 11838 //   peepmatch (incL_rReg movL);
 11839 //   peepconstraint (0.dst == 1.dst);
 11840 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
 11841 // %}
 11843 // peephole
 11844 // %{
 11845 //   peepmatch (decL_rReg movL);
 11846 //   peepconstraint (0.dst == 1.dst);
 11847 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
 11848 // %}
 11850 // peephole
 11851 // %{
 11852 //   peepmatch (addL_rReg_imm movL);
 11853 //   peepconstraint (0.dst == 1.dst);
 11854 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
 11855 // %}
 11857 // peephole
 11858 // %{
 11859 //   peepmatch (addP_rReg_imm movP);
 11860 //   peepconstraint (0.dst == 1.dst);
 11861 //   peepreplace (leaP_rReg_imm(0.dst 1.src 0.src));
 11862 // %}
 11864 // // Change load of spilled value to only a spill
 11865 // instruct storeI(memory mem, rRegI src)
 11866 // %{
 11867 //   match(Set mem (StoreI mem src));
 11868 // %}
 11869 //
 11870 // instruct loadI(rRegI dst, memory mem)
 11871 // %{
 11872 //   match(Set dst (LoadI mem));
 11873 // %}
 11874 //
 11876 peephole
 11877 %{
 11878   peepmatch (loadI storeI);
 11879   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
 11880   peepreplace (storeI(1.mem 1.mem 1.src));
 11881 %}
 11883 peephole
 11884 %{
 11885   peepmatch (loadL storeL);
 11886   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
 11887   peepreplace (storeL(1.mem 1.mem 1.src));
 11888 %}
 11890 //----------SMARTSPILL RULES---------------------------------------------------
 11891 // These must follow all instruction definitions as they use the names
 11892 // defined in the instructions definitions.

mercurial